core-3nweb-client-lib 0.25.5 → 0.26.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/build/api-defs/files.d.ts +23 -20
- package/build/core/asmail/config/common.js +2 -2
- package/build/core/asmail/delivery/index.js +4 -3
- package/build/core/asmail/delivery/msg.js +5 -4
- package/build/core/asmail/delivery/per-recipient-wip.js +2 -2
- package/build/core/asmail/inbox/attachments/fs.js +6 -0
- package/build/core/asmail/inbox/cached-msgs.js +2 -2
- package/build/core/asmail/inbox/inbox-events.js +2 -1
- package/build/core/asmail/inbox/index.js +2 -2
- package/build/core/asmail/inbox/msg-downloader.js +2 -2
- package/build/core/asmail/inbox/msg-indexing.js +3 -3
- package/build/core/asmail/inbox/msg-on-disk.js +2 -2
- package/build/core/asmail/keyring/keyring-storage.js +2 -2
- package/build/core/asmail/sending-params/own-params.js +2 -2
- package/build/core/asmail/sending-params/params-from-others.js +2 -2
- package/build/core/id-manager.js +2 -2
- package/build/core/sign-in.d.ts +5 -4
- package/build/core/sign-in.js +9 -11
- package/build/core/sign-up.d.ts +1 -0
- package/build/core/sign-up.js +7 -3
- package/build/core/storage/common/json-saving.d.ts +21 -0
- package/build/core/storage/common/json-saving.js +82 -0
- package/build/core/storage/common/obj-info-file.d.ts +43 -0
- package/build/core/storage/common/obj-info-file.js +119 -3
- package/build/core/storage/index.js +1 -1
- package/build/core/storage/local/obj-files-gc.js +8 -6
- package/build/core/storage/local/obj-files.d.ts +3 -3
- package/build/core/storage/local/obj-files.js +9 -9
- package/build/core/storage/local/obj-status.d.ts +9 -25
- package/build/core/storage/local/obj-status.js +28 -110
- package/build/core/storage/local/storage.d.ts +8 -1
- package/build/core/storage/local/storage.js +10 -2
- package/build/core/storage/synced/downloader.js +6 -5
- package/build/core/storage/synced/obj-files-gc.d.ts +1 -0
- package/build/core/storage/synced/obj-files-gc.js +44 -5
- package/build/core/storage/synced/obj-files.d.ts +13 -20
- package/build/core/storage/synced/obj-files.js +70 -48
- package/build/core/storage/synced/obj-status.d.ts +74 -15
- package/build/core/storage/synced/obj-status.js +291 -107
- package/build/core/storage/synced/remote-events.js +32 -26
- package/build/core/storage/synced/storage.d.ts +11 -1
- package/build/core/storage/synced/storage.js +28 -3
- package/build/core/storage/synced/upsyncer.d.ts +8 -7
- package/build/core/storage/synced/upsyncer.js +211 -163
- package/build/ipc-via-protobuf/asmail-cap.js +17 -34
- package/build/ipc-via-protobuf/connector-clients-side.d.ts +2 -0
- package/build/ipc-via-protobuf/connector-clients-side.js +50 -12
- package/build/ipc-via-protobuf/file.js +26 -18
- package/build/ipc-via-protobuf/fs.js +33 -35
- package/build/ipc-via-protobuf/mailerid.js +3 -2
- package/build/ipc-via-protobuf/protobuf-msg.d.ts +2 -0
- package/build/ipc-via-protobuf/protobuf-msg.js +11 -1
- package/build/ipc-via-protobuf/startup-cap.js +5 -5
- package/build/lib-client/3nstorage/exceptions.d.ts +9 -8
- package/build/lib-client/3nstorage/exceptions.js +18 -9
- package/build/lib-client/3nstorage/service.js +10 -6
- package/build/lib-client/3nstorage/xsp-fs/common.d.ts +18 -4
- package/build/lib-client/3nstorage/xsp-fs/common.js +6 -1
- package/build/lib-client/3nstorage/xsp-fs/file-node.js +3 -3
- package/build/lib-client/3nstorage/xsp-fs/file.js +4 -1
- package/build/lib-client/3nstorage/xsp-fs/folder-node.js +27 -13
- package/build/lib-client/3nstorage/xsp-fs/fs.d.ts +11 -6
- package/build/lib-client/3nstorage/xsp-fs/fs.js +189 -58
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.d.ts +4 -0
- package/build/lib-client/3nstorage/xsp-fs/node-in-fs.js +51 -24
- package/build/lib-client/3nstorage/xsp-fs/node-persistence.js +2 -2
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v1.js +2 -2
- package/build/lib-client/3nstorage/xsp-fs/xsp-payload-v2.js +3 -3
- package/build/lib-client/cryptor/cryptor-in-worker.js +4 -4
- package/build/lib-client/cryptor/cryptor-wasm.js +1 -1
- package/build/lib-client/cryptor/cryptor.wasm +0 -0
- package/build/lib-client/cryptor/in-proc-wasm.js +2 -2
- package/build/lib-client/files.js +2 -0
- package/build/lib-client/fs-collection.js +3 -2
- package/build/lib-client/logging/log-to-file.js +4 -4
- package/build/lib-client/objs-on-disk/file-writing-proc.js +2 -2
- package/build/lib-client/objs-on-disk/obj-folders.js +2 -2
- package/build/lib-client/request-utils.js +2 -2
- package/build/lib-client/server-events.js +4 -3
- package/build/lib-client/ws-utils.js +2 -2
- package/build/lib-common/async-fs-node.js +4 -3
- package/build/lib-common/byte-streaming/wrapping.js +17 -17
- package/build/lib-common/exceptions/file.js +6 -1
- package/build/lib-common/ipc/generic-ipc.js +2 -2
- package/build/lib-common/json-utils.js +2 -1
- package/build/lib-common/objs-on-disk/obj-file.js +4 -3
- package/build/lib-common/objs-on-disk/utils.js +2 -2
- package/build/lib-common/processes/deferred.d.ts +6 -0
- package/build/lib-common/processes/deferred.js +30 -0
- package/build/lib-common/processes/labelled-exec-pools.d.ts +33 -0
- package/build/lib-common/processes/labelled-exec-pools.js +141 -0
- package/build/lib-common/processes/pressure.d.ts +7 -0
- package/build/lib-common/processes/pressure.js +56 -0
- package/build/lib-common/processes/sleep.d.ts +1 -0
- package/build/lib-common/processes/sleep.js +26 -0
- package/build/lib-common/{processes.d.ts → processes/synced.d.ts} +0 -40
- package/build/lib-common/{processes.js → processes/synced.js} +187 -204
- package/build/lib-common/processes/timeout.d.ts +1 -0
- package/build/lib-common/processes/timeout.js +51 -0
- package/build/lib-common/service-api/3nstorage/owner.d.ts +5 -4
- package/build/lib-common/service-api/3nstorage/owner.js +3 -2
- package/build/lib-common/utils-for-observables.d.ts +15 -1
- package/build/lib-common/utils-for-observables.js +68 -17
- package/build/protos/asmail.proto.js +404 -78
- package/build/protos/file.proto.js +370 -44
- package/build/protos/fs.proto.js +404 -78
- package/package.json +4 -4
- package/protos/file.proto +10 -2
- package/protos/fs.proto +2 -2
- package/build/core/storage/synced/upsync-status.d.ts +0 -41
- package/build/core/storage/synced/upsync-status.js +0 -158
package/README.md
CHANGED
|
@@ -10,9 +10,9 @@ After repository clone, bring down all NodeJS modules, by running in project's f
|
|
|
10
10
|
npm ci
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
Tests have some unit and integrated components. Integration test uses 3NWeb spec server.
|
|
13
|
+
Tests have some unit and integrated components. Integration test uses 3NWeb spec server. Integrated tests use server and dns mocking from `spec-3nweb-server`.
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
Build is done with
|
|
16
16
|
```
|
|
17
17
|
npm run build
|
|
18
18
|
```
|
|
@@ -40,6 +40,7 @@ declare namespace web3n.files {
|
|
|
40
40
|
attrsNotEnabledInFS?: true;
|
|
41
41
|
versionMismatch?: true;
|
|
42
42
|
isEndless?: true;
|
|
43
|
+
storageClosed?: true;
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
interface exceptionCode {
|
|
@@ -58,6 +59,7 @@ declare namespace web3n.files {
|
|
|
58
59
|
parsingError: 'parsing-error';
|
|
59
60
|
notImplemented: 'ENOSYS';
|
|
60
61
|
isEndless: 'is-endless';
|
|
62
|
+
storageClosed: 'storage-closed';
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/**
|
|
@@ -124,8 +126,22 @@ declare namespace web3n.files {
|
|
|
124
126
|
*/
|
|
125
127
|
version?: number;
|
|
126
128
|
|
|
129
|
+
/**
|
|
130
|
+
* This tells object's latest sync state.
|
|
131
|
+
* If such information cannot be provided, this field will be absent.
|
|
132
|
+
*/
|
|
133
|
+
sync?: {
|
|
134
|
+
state: SyncState;
|
|
135
|
+
latest?: number;
|
|
136
|
+
conflictingRemote?: number[];
|
|
137
|
+
remote?: number;
|
|
138
|
+
deletedOnRemote?: true;
|
|
139
|
+
};
|
|
140
|
+
|
|
127
141
|
}
|
|
128
142
|
|
|
143
|
+
type SyncState = 'synced' | 'behind' | 'unsynced' | 'conflicting';
|
|
144
|
+
|
|
129
145
|
interface FileByteSource {
|
|
130
146
|
|
|
131
147
|
/**
|
|
@@ -988,37 +1004,25 @@ declare namespace web3n.files {
|
|
|
988
1004
|
type: 'removed';
|
|
989
1005
|
}
|
|
990
1006
|
|
|
991
|
-
interface
|
|
992
|
-
type: '
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
interface SyncedEvent extends FSEvent {
|
|
996
|
-
type: 'synced';
|
|
1007
|
+
interface SyncUploadEvent extends FSEvent {
|
|
1008
|
+
type: 'sync-upload';
|
|
1009
|
+
uploaded: number;
|
|
997
1010
|
current: number;
|
|
998
1011
|
}
|
|
999
1012
|
|
|
1000
|
-
interface UnsyncedEvent extends FSEvent {
|
|
1001
|
-
type: 'unsynced';
|
|
1002
|
-
lastSynced: number;
|
|
1003
|
-
}
|
|
1004
|
-
|
|
1005
|
-
interface ConflictEvent extends FSEvent {
|
|
1006
|
-
type: 'conflicting';
|
|
1007
|
-
remoteVersion: number;
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
1013
|
type FolderEvent = EntryRemovalEvent | EntryAdditionEvent |
|
|
1011
|
-
EntryRenamingEvent | RemovedEvent |
|
|
1012
|
-
SyncedEvent | UnsyncedEvent | ConflictEvent;
|
|
1014
|
+
EntryRenamingEvent | RemovedEvent | SyncUploadEvent;
|
|
1013
1015
|
|
|
1014
1016
|
interface EntryRemovalEvent extends FSEvent {
|
|
1015
1017
|
type: 'entry-removal';
|
|
1016
1018
|
name: string;
|
|
1019
|
+
moveLabel?: number;
|
|
1017
1020
|
}
|
|
1018
1021
|
|
|
1019
1022
|
interface EntryAdditionEvent extends FSEvent {
|
|
1020
1023
|
type: 'entry-addition';
|
|
1021
1024
|
entry: ListingEntry;
|
|
1025
|
+
moveLabel?: number;
|
|
1022
1026
|
}
|
|
1023
1027
|
|
|
1024
1028
|
interface EntryRenamingEvent extends FSEvent {
|
|
@@ -1027,8 +1031,7 @@ declare namespace web3n.files {
|
|
|
1027
1031
|
newName: string;
|
|
1028
1032
|
}
|
|
1029
1033
|
|
|
1030
|
-
type FileEvent = FileChangeEvent | RemovedEvent |
|
|
1031
|
-
SyncedEvent | UnsyncedEvent | ConflictEvent;
|
|
1034
|
+
type FileEvent = FileChangeEvent | RemovedEvent | SyncUploadEvent;
|
|
1032
1035
|
|
|
1033
1036
|
interface FileChangeEvent extends FSEvent {
|
|
1034
1037
|
type: 'file-change';
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.ParamOnFileAndServer = void 0;
|
|
19
19
|
const json_utils_1 = require("../../../lib-common/json-utils");
|
|
20
20
|
const file_based_json_1 = require("../../../lib-client/3nstorage/util/file-based-json");
|
|
21
|
-
const
|
|
21
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
22
22
|
class ParamOnFileAndServer extends file_based_json_1.JsonFileProc {
|
|
23
23
|
constructor(paramPath, serviceConf) {
|
|
24
24
|
super();
|
|
@@ -27,7 +27,7 @@ class ParamOnFileAndServer extends file_based_json_1.JsonFileProc {
|
|
|
27
27
|
// XXX This should be done in a transactional style, with set on server
|
|
28
28
|
// first. FolderNode with its base class is an example of transactional
|
|
29
29
|
// mechanism implementation.
|
|
30
|
-
this.changesProc = new
|
|
30
|
+
this.changesProc = new synced_1.SingleProc();
|
|
31
31
|
}
|
|
32
32
|
async start(file) {
|
|
33
33
|
await super.start(file, async () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2016 - 2017, 2020 -
|
|
3
|
+
Copyright (C) 2016 - 2017, 2020 - 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -24,6 +24,7 @@ const common_1 = require("./common");
|
|
|
24
24
|
const json_utils_1 = require("../../../lib-common/json-utils");
|
|
25
25
|
const rxjs_1 = require("rxjs");
|
|
26
26
|
const operators_1 = require("rxjs/operators");
|
|
27
|
+
const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
|
|
27
28
|
const SMALL_MSG_SIZE = 1024 * 1024;
|
|
28
29
|
const MSGS_FOLDER = 'msgs';
|
|
29
30
|
function idToMsgFolder(id) {
|
|
@@ -120,11 +121,11 @@ class Delivery {
|
|
|
120
121
|
}
|
|
121
122
|
return () => { };
|
|
122
123
|
}
|
|
123
|
-
const subToProgress = msg.progress$.subscribe(observer);
|
|
124
|
+
const subToProgress = msg.progress$.subscribe(utils_for_observables_1.toRxObserver(observer));
|
|
124
125
|
return () => { subToProgress.unsubscribe(); };
|
|
125
126
|
}
|
|
126
127
|
observeAllDeliveries(observer) {
|
|
127
|
-
const subToProgress = this.allDeliveries$.subscribe(observer);
|
|
128
|
+
const subToProgress = this.allDeliveries$.subscribe(utils_for_observables_1.toRxObserver(observer));
|
|
128
129
|
return () => subToProgress.unsubscribe();
|
|
129
130
|
}
|
|
130
131
|
async preFlight(recipient) {
|
|
@@ -17,12 +17,13 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.Msg = void 0;
|
|
19
19
|
const packer_1 = require("../msg/packer");
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
21
21
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
22
22
|
const common_1 = require("./common");
|
|
23
23
|
const per_recipient_wip_1 = require("./per-recipient-wip");
|
|
24
24
|
const rxjs_1 = require("rxjs");
|
|
25
25
|
const json_utils_1 = require("../../../lib-common/json-utils");
|
|
26
|
+
const deferred_1 = require("../../../lib-common/processes/deferred");
|
|
26
27
|
const MAIN_OBJ_FILE_NAME = 'msg.json';
|
|
27
28
|
const PROGRESS_INFO_FILE_NAME = 'progress.json';
|
|
28
29
|
const WIPS_INFO_FILE_NAME = 'wips.json';
|
|
@@ -48,9 +49,9 @@ class Msg {
|
|
|
48
49
|
this.r = r;
|
|
49
50
|
this.progress = progress;
|
|
50
51
|
this.msgFS = msgFS;
|
|
51
|
-
this.sendingProc = new
|
|
52
|
+
this.sendingProc = new synced_1.SingleProc();
|
|
52
53
|
this.completionPromise = undefined;
|
|
53
|
-
this.progressSavingProc = new
|
|
54
|
+
this.progressSavingProc = new synced_1.SingleProc();
|
|
54
55
|
this.cancelled = false;
|
|
55
56
|
this.sender = undefined;
|
|
56
57
|
this.recipients = undefined;
|
|
@@ -197,7 +198,7 @@ class Msg {
|
|
|
197
198
|
throw new Error(`Message delivery has already completed.`);
|
|
198
199
|
}
|
|
199
200
|
if (!this.completionPromise) {
|
|
200
|
-
this.completionPromise =
|
|
201
|
+
this.completionPromise = deferred_1.defer();
|
|
201
202
|
}
|
|
202
203
|
return this.completionPromise.promise;
|
|
203
204
|
}
|
|
@@ -19,7 +19,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
19
19
|
exports.WIP = void 0;
|
|
20
20
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
21
21
|
const sender_1 = require("../../../lib-client/asmail/sender");
|
|
22
|
-
const
|
|
22
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
23
23
|
const key_verification_1 = require("../key-verification");
|
|
24
24
|
const MSG_SIZE_FOR_STATE_RECORDING = 1024 * 1024;
|
|
25
25
|
const EMPTY_BYTE_ARR = new Uint8Array(0);
|
|
@@ -34,7 +34,7 @@ class WIP {
|
|
|
34
34
|
this.msg = msg;
|
|
35
35
|
this.state = state;
|
|
36
36
|
this.cryptor = cryptor;
|
|
37
|
-
this.proc = new
|
|
37
|
+
this.proc = new synced_1.SingleProc();
|
|
38
38
|
this.sender = undefined;
|
|
39
39
|
this.packer = undefined;
|
|
40
40
|
this.currentObjIndInMeta = 0;
|
|
@@ -29,6 +29,12 @@ class AttachmentStore {
|
|
|
29
29
|
this.nodes = new common_1.NodesContainer();
|
|
30
30
|
Object.seal(this);
|
|
31
31
|
}
|
|
32
|
+
getNodeEvents() {
|
|
33
|
+
throw new Error(`Attachment's storage is readonly.`);
|
|
34
|
+
}
|
|
35
|
+
broadcastNodeEvent() {
|
|
36
|
+
throw new Error(`Attachment's storage is readonly.`);
|
|
37
|
+
}
|
|
32
38
|
storageForLinking(type, location) {
|
|
33
39
|
if (type === 'share') {
|
|
34
40
|
return this.getStorages('share', location);
|
|
@@ -20,12 +20,12 @@ exports.CachedMessages = void 0;
|
|
|
20
20
|
const msg_on_disk_1 = require("./msg-on-disk");
|
|
21
21
|
const timed_cache_1 = require("../../../lib-common/timed-cache");
|
|
22
22
|
const obj_folders_1 = require("../../../lib-client/objs-on-disk/obj-folders");
|
|
23
|
-
const
|
|
23
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
24
24
|
class CachedMessages {
|
|
25
25
|
constructor(folders, downloader) {
|
|
26
26
|
this.folders = folders;
|
|
27
27
|
this.downloader = downloader;
|
|
28
|
-
this.syncProc = new
|
|
28
|
+
this.syncProc = new synced_1.NamedProcs();
|
|
29
29
|
this.msgFiles = timed_cache_1.makeTimedCache(60 * 1000);
|
|
30
30
|
Object.freeze(this);
|
|
31
31
|
}
|
|
@@ -19,6 +19,7 @@ exports.InboxEvents = void 0;
|
|
|
19
19
|
const retrieval_1 = require("../../../lib-common/service-api/asmail/retrieval");
|
|
20
20
|
const server_events_1 = require("../../../lib-client/server-events");
|
|
21
21
|
const operators_1 = require("rxjs/operators");
|
|
22
|
+
const utils_for_observables_1 = require("../../../lib-common/utils-for-observables");
|
|
22
23
|
const SERVER_EVENTS_RESTART_WAIT_SECS = 30;
|
|
23
24
|
/**
|
|
24
25
|
* Instance of this class handles event subscription from UI side. It observes
|
|
@@ -38,7 +39,7 @@ class InboxEvents {
|
|
|
38
39
|
}
|
|
39
40
|
subscribe(event, observer) {
|
|
40
41
|
if (event === 'message') {
|
|
41
|
-
const subscription = this.newMsg$.subscribe(observer);
|
|
42
|
+
const subscription = this.newMsg$.subscribe(utils_for_observables_1.toRxObserver(observer));
|
|
42
43
|
return () => subscription.unsubscribe();
|
|
43
44
|
}
|
|
44
45
|
else {
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.InboxOnServer = void 0;
|
|
20
20
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
21
|
-
const
|
|
21
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
22
22
|
const recipient_1 = require("../../../lib-client/asmail/recipient");
|
|
23
23
|
const opener_1 = require("../msg/opener");
|
|
24
24
|
const msg_indexing_1 = require("./msg-indexing");
|
|
@@ -48,7 +48,7 @@ class InboxOnServer {
|
|
|
48
48
|
this.cache = cache;
|
|
49
49
|
this.index = index;
|
|
50
50
|
this.logError = logError;
|
|
51
|
-
this.procs = new
|
|
51
|
+
this.procs = new synced_1.NamedProcs();
|
|
52
52
|
this.recentlyOpenedMsgs = timed_cache_1.makeTimedCache(60 * 1000);
|
|
53
53
|
this.inboxEvents = new inbox_events_1.InboxEvents(this.msgReceiver, this.getMsg.bind(this), this.logError);
|
|
54
54
|
Object.seal(this);
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.MsgDownloader = void 0;
|
|
19
|
-
const
|
|
19
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
20
20
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
21
21
|
const MAX_GETTING_CHUNK = 512 * 1024;
|
|
22
22
|
const DOWNLOAD_START_CHUNK = 128 * 1024;
|
|
@@ -32,7 +32,7 @@ class MsgDownloader {
|
|
|
32
32
|
* When it comes to the download start, if chain exists, it means that
|
|
33
33
|
* process has already started.
|
|
34
34
|
*/
|
|
35
|
-
this.downloadProcs = new
|
|
35
|
+
this.downloadProcs = new synced_1.NamedProcs();
|
|
36
36
|
Object.freeze(this);
|
|
37
37
|
}
|
|
38
38
|
async sync(msgId, objId, action) {
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
19
|
exports.MsgIndex = void 0;
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
21
21
|
const buffer_utils_1 = require("../../../lib-common/buffer-utils");
|
|
22
22
|
const timed_cache_1 = require("../../../lib-common/timed-cache");
|
|
23
23
|
const LIMIT_RECORDS_PER_FILE = 200;
|
|
@@ -99,7 +99,7 @@ class MsgIndex {
|
|
|
99
99
|
this.latest = undefined;
|
|
100
100
|
this.cached = timed_cache_1.makeTimedCache(10 * 60 * 1000);
|
|
101
101
|
this.fileTSs = undefined;
|
|
102
|
-
this.fileProc = new
|
|
102
|
+
this.fileProc = new synced_1.SingleProc();
|
|
103
103
|
Object.seal(this);
|
|
104
104
|
}
|
|
105
105
|
static async makeWith(files) {
|
|
@@ -297,7 +297,7 @@ class MsgIndex {
|
|
|
297
297
|
}
|
|
298
298
|
if (msgFound) {
|
|
299
299
|
removeFrom(records, msgId);
|
|
300
|
-
if (
|
|
300
|
+
if (!!records.fileTS && (records.ordered.length === 0)) {
|
|
301
301
|
await this.files.deleteFile(records.fileTS + INDEX_EXT);
|
|
302
302
|
}
|
|
303
303
|
else {
|
|
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.MsgOnDisk = void 0;
|
|
19
19
|
const fs = require("../../../lib-common/async-fs-node");
|
|
20
20
|
const obj_on_disk_1 = require("../../../lib-client/objs-on-disk/obj-on-disk");
|
|
21
|
-
const
|
|
21
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
22
22
|
const error_1 = require("../../../lib-common/exceptions/error");
|
|
23
23
|
const path_1 = require("path");
|
|
24
24
|
const META_FNAME = 'meta.json';
|
|
@@ -39,7 +39,7 @@ class MsgOnDisk {
|
|
|
39
39
|
this.msgDownloader = msgDownloader;
|
|
40
40
|
this.status = status;
|
|
41
41
|
this.objsIds = objsIds;
|
|
42
|
-
this.syncProc = new
|
|
42
|
+
this.syncProc = new synced_1.SingleProc();
|
|
43
43
|
this.objs = new Map();
|
|
44
44
|
this.objDownloader = this.msgDownloader.getObjDownloader(msgId);
|
|
45
45
|
Object.freeze(this.objDownloader);
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>. */
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.makeKeyringStorage = void 0;
|
|
19
|
-
const
|
|
19
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
20
20
|
const KEYRING_FNAME = 'keyring.json';
|
|
21
21
|
function makeKeyringStorage(fs) {
|
|
22
|
-
const proc = new
|
|
22
|
+
const proc = new synced_1.SingleProc();
|
|
23
23
|
// initialization for code that works only with version 1
|
|
24
24
|
proc.start(async () => {
|
|
25
25
|
fs = await checkAndUpgradeDataToV1(fs);
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.OwnSendingParams = void 0;
|
|
19
19
|
const file_based_json_1 = require("../../../lib-client/3nstorage/util/file-based-json");
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
21
21
|
const json_utils_1 = require("../../../lib-common/json-utils");
|
|
22
22
|
const DEFAULT_INVITE_LABEL = 'Default';
|
|
23
23
|
const DEFAULT_INVITE_MAX_MSG_SIZE = 1024 * 1024 * 1024;
|
|
@@ -33,7 +33,7 @@ class OwnSendingParams extends file_based_json_1.JsonFileProc {
|
|
|
33
33
|
this.anonInvites = anonInvites;
|
|
34
34
|
this.params = new Map();
|
|
35
35
|
this.defaultParams = undefined;
|
|
36
|
-
this.changesProc = new
|
|
36
|
+
this.changesProc = new synced_1.SingleProc();
|
|
37
37
|
this.getFor = async (address) => {
|
|
38
38
|
let p = this.params.get(address);
|
|
39
39
|
if (p) {
|
|
@@ -17,12 +17,12 @@
|
|
|
17
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
18
|
exports.ParamsFromOthers = void 0;
|
|
19
19
|
const file_based_json_1 = require("../../../lib-client/3nstorage/util/file-based-json");
|
|
20
|
-
const
|
|
20
|
+
const synced_1 = require("../../../lib-common/processes/synced");
|
|
21
21
|
class ParamsFromOthers extends file_based_json_1.JsonFileProc {
|
|
22
22
|
constructor() {
|
|
23
23
|
super();
|
|
24
24
|
this.params = new Map();
|
|
25
|
-
this.changesProc = new
|
|
25
|
+
this.changesProc = new synced_1.SingleProc();
|
|
26
26
|
this.getFor = (address) => {
|
|
27
27
|
const p = this.params.get(address);
|
|
28
28
|
if (!p) {
|
package/build/core/id-manager.js
CHANGED
|
@@ -20,7 +20,7 @@ exports.IdManager = void 0;
|
|
|
20
20
|
const ecma_nacl_1 = require("ecma-nacl");
|
|
21
21
|
const provisioner_1 = require("../lib-client/mailer-id/provisioner");
|
|
22
22
|
const jwkeys_1 = require("../lib-common/jwkeys");
|
|
23
|
-
const
|
|
23
|
+
const synced_1 = require("../lib-common/processes/synced");
|
|
24
24
|
const login_1 = require("../lib-client/mailer-id/login");
|
|
25
25
|
const CERTIFICATE_DURATION_SECONDS = 16 * 60 * 60;
|
|
26
26
|
const ASSERTION_VALIDITY = 15 * 60;
|
|
@@ -36,7 +36,7 @@ class IdManager {
|
|
|
36
36
|
this.signer = undefined;
|
|
37
37
|
this.localFS = undefined;
|
|
38
38
|
this.syncedFS = undefined;
|
|
39
|
-
this.provisioningProc = new
|
|
39
|
+
this.provisioningProc = new synced_1.SingleProc();
|
|
40
40
|
this.getSigner = async () => {
|
|
41
41
|
if (!this.address) {
|
|
42
42
|
throw new Error('Address is not set in id manager');
|
package/build/core/sign-in.d.ts
CHANGED
|
@@ -20,10 +20,11 @@ export declare class SignIn {
|
|
|
20
20
|
exposedService(): SignInService;
|
|
21
21
|
private startLoginToRemoteStorage;
|
|
22
22
|
private completeLoginAndLocalSetup;
|
|
23
|
-
private doneBroadcast;
|
|
24
|
-
existingUser$: import("rxjs").Observable<IdManager>;
|
|
23
|
+
private readonly doneBroadcast;
|
|
24
|
+
readonly existingUser$: import("rxjs").Observable<IdManager>;
|
|
25
25
|
private useExistingStorage;
|
|
26
|
-
private
|
|
26
|
+
private logAndWrap;
|
|
27
27
|
}
|
|
28
|
-
export declare
|
|
28
|
+
export declare type ProgressCB = (p: number) => void;
|
|
29
|
+
export declare function makeKeyGenProgressCB(progressStart: number, progressEnd: number, progressCB: ProgressCB): ProgressCB;
|
|
29
30
|
export {};
|
package/build/core/sign-in.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2018, 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -34,8 +34,7 @@ class SignIn {
|
|
|
34
34
|
return !!this.completeInitWithoutCache;
|
|
35
35
|
}
|
|
36
36
|
catch (err) {
|
|
37
|
-
await this.
|
|
38
|
-
throw err;
|
|
37
|
+
throw await this.logAndWrap(err, 'Fail to start login to remote storage');
|
|
39
38
|
}
|
|
40
39
|
};
|
|
41
40
|
this.completeLoginAndLocalSetup = async (pass, progressCB) => {
|
|
@@ -46,7 +45,7 @@ class SignIn {
|
|
|
46
45
|
const midKeyProgressCB = makeKeyGenProgressCB(0, 50, progressCB);
|
|
47
46
|
const midKeyGen = async (params) => (await key_derivation_1.deriveMidKeyPair(this.cryptor, pass, params, midKeyProgressCB)).skey;
|
|
48
47
|
const storeKeyProgressCB = makeKeyGenProgressCB(51, 100, progressCB);
|
|
49
|
-
const storeKeyGen = params => key_derivation_1.deriveStorageSKey(this.cryptor, pass, params, storeKeyProgressCB);
|
|
48
|
+
const storeKeyGen = (params) => key_derivation_1.deriveStorageSKey(this.cryptor, pass, params, storeKeyProgressCB);
|
|
50
49
|
const idManager = await this.completeInitWithoutCache(midKeyGen, storeKeyGen);
|
|
51
50
|
if (!idManager) {
|
|
52
51
|
return false;
|
|
@@ -55,8 +54,7 @@ class SignIn {
|
|
|
55
54
|
return true;
|
|
56
55
|
}
|
|
57
56
|
catch (err) {
|
|
58
|
-
await this.
|
|
59
|
-
throw err;
|
|
57
|
+
throw await this.logAndWrap(err, 'Fail to initialize from a state without cache');
|
|
60
58
|
}
|
|
61
59
|
};
|
|
62
60
|
this.doneBroadcast = new rxjs_1.Subject();
|
|
@@ -84,8 +82,7 @@ class SignIn {
|
|
|
84
82
|
return true;
|
|
85
83
|
}
|
|
86
84
|
catch (err) {
|
|
87
|
-
await this.
|
|
88
|
-
throw err;
|
|
85
|
+
throw await this.logAndWrap(err, 'Failing to start in a state with cache');
|
|
89
86
|
}
|
|
90
87
|
};
|
|
91
88
|
Object.seal(this);
|
|
@@ -99,8 +96,9 @@ class SignIn {
|
|
|
99
96
|
};
|
|
100
97
|
return Object.freeze(service);
|
|
101
98
|
}
|
|
102
|
-
async
|
|
103
|
-
await this.logError(
|
|
99
|
+
async logAndWrap(err, msg) {
|
|
100
|
+
await this.logError(err, msg);
|
|
101
|
+
return error_1.errWithCause(err, msg);
|
|
104
102
|
}
|
|
105
103
|
}
|
|
106
104
|
exports.SignIn = SignIn;
|
|
@@ -113,7 +111,7 @@ function makeKeyGenProgressCB(progressStart, progressEnd, progressCB) {
|
|
|
113
111
|
let currentProgress = 0;
|
|
114
112
|
let totalProgress = progressStart;
|
|
115
113
|
const progressRange = progressEnd - progressStart;
|
|
116
|
-
return
|
|
114
|
+
return p => {
|
|
117
115
|
if (currentProgress >= p) {
|
|
118
116
|
return;
|
|
119
117
|
}
|
package/build/core/sign-up.d.ts
CHANGED
package/build/core/sign-up.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2020 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2020, 2022 3NSoft Inc.
|
|
4
4
|
|
|
5
5
|
This program is free software: you can redistribute it and/or modify it under
|
|
6
6
|
the terms of the GNU General Public License as published by the Free Software
|
|
@@ -27,6 +27,7 @@ const random = require("../lib-common/random-node");
|
|
|
27
27
|
const ecma_nacl_1 = require("ecma-nacl");
|
|
28
28
|
const sign_in_1 = require("./sign-in");
|
|
29
29
|
const rxjs_1 = require("rxjs");
|
|
30
|
+
const error_1 = require("../lib-common/exceptions/error");
|
|
30
31
|
/**
|
|
31
32
|
* With these parameters scrypt shall use memory around:
|
|
32
33
|
* (2^7)*r*N === (2^7)*(2^3)*(2^17) === 2^27 === (2^7)*(2^20) === 128MB
|
|
@@ -84,8 +85,7 @@ class SignUp {
|
|
|
84
85
|
storage: this.store.params,
|
|
85
86
|
signupToken
|
|
86
87
|
}).catch(async (err) => {
|
|
87
|
-
await this.
|
|
88
|
-
throw err;
|
|
88
|
+
throw await this.logAndWrap(err, `Failed to create user account ${address}.`);
|
|
89
89
|
});
|
|
90
90
|
if (!accountCreated) {
|
|
91
91
|
return false;
|
|
@@ -169,6 +169,10 @@ class SignUp {
|
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
171
|
}
|
|
172
|
+
async logAndWrap(err, msg) {
|
|
173
|
+
await this.logError(err, msg);
|
|
174
|
+
return error_1.errWithCause(err, msg);
|
|
175
|
+
}
|
|
172
176
|
forgetKeys() {
|
|
173
177
|
this.store = undefined;
|
|
174
178
|
this.mid = undefined;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export declare class JSONSavingProc<T> {
|
|
2
|
+
private readonly path;
|
|
3
|
+
private readonly getForSerialization;
|
|
4
|
+
private proc;
|
|
5
|
+
private jsonNeedsSaving;
|
|
6
|
+
/**
|
|
7
|
+
* @param path where json file is saved
|
|
8
|
+
* @param getForSerialization function that either returns something to
|
|
9
|
+
* jsonify and save, or undefined to remove the file.
|
|
10
|
+
* @param logError is an optional log function saving errors.
|
|
11
|
+
*/
|
|
12
|
+
constructor(path: string, getForSerialization: () => T | undefined);
|
|
13
|
+
/**
|
|
14
|
+
* This triggers saving. One may await returned promise, but doesn't have to.
|
|
15
|
+
* Several triggers can be done, but overlapping ones will save only the
|
|
16
|
+
* latest value.
|
|
17
|
+
*/
|
|
18
|
+
trigger(): Promise<void>;
|
|
19
|
+
isSaved(): boolean;
|
|
20
|
+
private save;
|
|
21
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
Copyright (C) 2022 3NSoft Inc.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify it under
|
|
6
|
+
the terms of the GNU General Public License as published by the Free Software
|
|
7
|
+
Foundation, either version 3 of the License, or (at your option) any later
|
|
8
|
+
version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful, but
|
|
11
|
+
WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
13
|
+
See the GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License along with
|
|
16
|
+
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
|
+
*/
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
exports.JSONSavingProc = void 0;
|
|
20
|
+
const async_fs_node_1 = require("../../../lib-common/async-fs-node");
|
|
21
|
+
class JSONSavingProc {
|
|
22
|
+
/**
|
|
23
|
+
* @param path where json file is saved
|
|
24
|
+
* @param getForSerialization function that either returns something to
|
|
25
|
+
* jsonify and save, or undefined to remove the file.
|
|
26
|
+
* @param logError is an optional log function saving errors.
|
|
27
|
+
*/
|
|
28
|
+
constructor(path, getForSerialization) {
|
|
29
|
+
this.path = path;
|
|
30
|
+
this.getForSerialization = getForSerialization;
|
|
31
|
+
this.proc = undefined;
|
|
32
|
+
this.jsonNeedsSaving = false;
|
|
33
|
+
Object.seal(this);
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* This triggers saving. One may await returned promise, but doesn't have to.
|
|
37
|
+
* Several triggers can be done, but overlapping ones will save only the
|
|
38
|
+
* latest value.
|
|
39
|
+
*/
|
|
40
|
+
trigger() {
|
|
41
|
+
if (!this.jsonNeedsSaving) {
|
|
42
|
+
this.jsonNeedsSaving = true;
|
|
43
|
+
if (!this.proc) {
|
|
44
|
+
this.proc = this.save();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return this.proc;
|
|
48
|
+
}
|
|
49
|
+
isSaved() {
|
|
50
|
+
return !this.jsonNeedsSaving;
|
|
51
|
+
}
|
|
52
|
+
async save() {
|
|
53
|
+
try {
|
|
54
|
+
this.jsonNeedsSaving = false;
|
|
55
|
+
const serialForm = this.getForSerialization();
|
|
56
|
+
if (serialForm === undefined) {
|
|
57
|
+
await async_fs_node_1.unlink(this.path)
|
|
58
|
+
.catch((e) => {
|
|
59
|
+
if (!e.notFound) {
|
|
60
|
+
throw e;
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const json = JSON.stringify(serialForm);
|
|
66
|
+
await async_fs_node_1.writeFile(this.path, json, { encoding: 'utf8' });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
finally {
|
|
70
|
+
if (this.jsonNeedsSaving) {
|
|
71
|
+
return this.save();
|
|
72
|
+
}
|
|
73
|
+
{
|
|
74
|
+
this.proc = undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
exports.JSONSavingProc = JSONSavingProc;
|
|
80
|
+
Object.freeze(JSONSavingProc.prototype);
|
|
81
|
+
Object.freeze(JSONSavingProc);
|
|
82
|
+
Object.freeze(exports);
|