core-3nweb-client-lib 0.49.8 → 0.50.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/build/api-defs/files.d.ts +1 -1
- package/build/core/asmail/delivery/per-recipient-wip.js +4 -0
- package/build/core/asmail/inbox/index.js +5 -1
- package/build/core/asmail/inbox/msg-indexing/index.js +8 -9
- package/build/core/asmail/index.js +3 -3
- package/build/core/asmail/sending-params/index.d.ts +13 -14
- package/build/core/asmail/sending-params/index.js +15 -35
- package/build/core/asmail/sending-params/invitations-anon.d.ts +7 -31
- package/build/core/asmail/sending-params/invitations-anon.js +77 -127
- package/build/core/asmail/sending-params/own-params.d.ts +5 -25
- package/build/core/asmail/sending-params/own-params.js +144 -97
- package/build/core/asmail/sending-params/params-from-others.d.ts +6 -16
- package/build/core/asmail/sending-params/params-from-others.js +88 -58
- package/build/core/index.d.ts +2 -1
- package/build/core/index.js +4 -4
- package/build/core/keyring/index.js +1 -1
- package/build/core/keyring/introductory-keys/published-intro-key.js +15 -15
- package/build/core/keyring/peer-keys/index.js +6 -7
- package/build/core/storage/index.d.ts +2 -1
- package/build/core/storage/index.js +4 -3
- package/build/core/storage/system-folders/index.d.ts +1 -2
- package/build/core/storage/system-folders/index.js +18 -22
- package/build/lib-client/fs-utils/fs-sync-utils.d.ts +1 -1
- package/build/lib-client/fs-utils/fs-sync-utils.js +21 -15
- package/build/lib-client/service-locator.js +17 -17
- package/build/lib-client/xsp-fs/util/file-based-json.js +1 -1
- package/build/lib-common/dataset-sync/per-device-json-array-logs.js +42 -27
- package/build/lib-common/dataset-sync/single-file.d.ts +4 -2
- package/build/lib-common/dataset-sync/single-file.js +27 -31
- package/build/lib-common/dataset-sync/utils.d.ts +16 -0
- package/build/lib-common/dataset-sync/utils.js +72 -0
- package/build/lib-common-on-node/device-fs-places.d.ts +3 -0
- package/build/lib-common-on-node/device-fs-places.js +39 -0
- package/build/tests/computer.3nweb.core/keyrings.js +2 -2
- package/build/tests/libs-for-tests/core-runner.js +2 -1
- package/package.json +1 -1
|
@@ -1172,7 +1172,7 @@ declare namespace web3n.files {
|
|
|
1172
1172
|
|
|
1173
1173
|
interface FileChangeEvent extends FSChangeEvent {
|
|
1174
1174
|
type: 'file-change';
|
|
1175
|
-
newVersion
|
|
1175
|
+
newVersion: number;
|
|
1176
1176
|
}
|
|
1177
1177
|
|
|
1178
1178
|
type RemoteEvent = RemoteVersionArchivalEvent | RemoteArchVerRemovalEvent |
|
|
@@ -132,9 +132,13 @@ class WIP {
|
|
|
132
132
|
const recipient = this.state.recipient;
|
|
133
133
|
const sp = this.msg.r.correspondents.paramsForSendingTo(recipient);
|
|
134
134
|
if (sp) {
|
|
135
|
+
// DEBUG
|
|
136
|
+
// console.log(`sending params for sending to ${recipient} invitation are`, sp);
|
|
135
137
|
this.sender = await sender_1.MailSender.fresh(this.msg.r.makeNet(), this.msg.r.asmailResolver, (sp.auth ? senderAddress : undefined), recipient, sp.invitation);
|
|
136
138
|
}
|
|
137
139
|
else {
|
|
140
|
+
// DEBUG
|
|
141
|
+
// console.log(`have no sending params to use for sending to ${recipient}`);
|
|
138
142
|
this.sender = await sender_1.MailSender.fresh(this.msg.r.makeNet(), this.msg.r.asmailResolver, undefined, recipient);
|
|
139
143
|
}
|
|
140
144
|
await this.sender.startSession();
|
|
@@ -36,7 +36,7 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
|
|
|
36
36
|
const recentlyOpenedMsgs = (0, timed_cache_1.makeTimedCache)(60 * 1000);
|
|
37
37
|
const { getStorages, cryptor, random, logError, } = r;
|
|
38
38
|
(0, file_1.ensureCorrectFS)(syncedFS, 'synced', true);
|
|
39
|
-
const indexSyncedFS = await (0, fs_sync_utils_1.
|
|
39
|
+
const indexSyncedFS = await (0, fs_sync_utils_1.getOrMakeDirOnInit)(syncedFS, MSG_INDEX_FOLDER);
|
|
40
40
|
const indexLocalFS = await localFS.writableSubRoot(MSG_INDEX_FOLDER);
|
|
41
41
|
const msgReceiver = new recipient_1.MailRecipient(r.address, r.getSigner, () => r.asmailResolver(r.address), r.makeNet());
|
|
42
42
|
const downloader = new msg_downloader_1.MsgDownloader(msgReceiver);
|
|
@@ -147,6 +147,8 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
|
|
|
147
147
|
}
|
|
148
148
|
}
|
|
149
149
|
async function markOwnParams(meta, sender) {
|
|
150
|
+
// DEBUG
|
|
151
|
+
// console.log(` markOwnParams (if invite used) ->`, {sender, 'meta.invite':meta.invite});
|
|
150
152
|
if (!meta.invite) {
|
|
151
153
|
return;
|
|
152
154
|
}
|
|
@@ -154,6 +156,8 @@ async function makeInboxOnServer(cachePath, syncedFS, localFS, r) {
|
|
|
154
156
|
}
|
|
155
157
|
async function absorbSendingParams(openedMsg) {
|
|
156
158
|
const sendingParams = openedMsg.nextSendingParams;
|
|
159
|
+
// DEBUG
|
|
160
|
+
// console.log(` openedMsg.nextSendingParams ->`, openedMsg.nextSendingParams);
|
|
157
161
|
if (!sendingParams) {
|
|
158
162
|
return;
|
|
159
163
|
}
|
|
@@ -27,9 +27,9 @@ const INDEX_DIR = 'index';
|
|
|
27
27
|
const NUM_OF_ENTRIES_TO_CHOP_DB = 200;
|
|
28
28
|
async function makeMsgIndex(syncedFS, localFS, logError) {
|
|
29
29
|
// file systems within dataset
|
|
30
|
-
const logsFS = await (0, fs_sync_utils_1.
|
|
30
|
+
const logsFS = await (0, fs_sync_utils_1.getOrMakeDirOnInit)(syncedFS, LOGS_DIR);
|
|
31
31
|
const localLogsFS = await localFS.writableSubRoot(LOGS_DIR);
|
|
32
|
-
const indexFS = await (0, fs_sync_utils_1.
|
|
32
|
+
const indexFS = await (0, fs_sync_utils_1.getOrMakeDirOnInit)(syncedFS, INDEX_DIR);
|
|
33
33
|
const logs = await (0, logs_1.makeRecentMsgIndexChangesLogs)(logsFS, localLogsFS, logError);
|
|
34
34
|
const indexed = await (0, sql_db_1.makeSqliteDBs)(indexFS);
|
|
35
35
|
async function add(msgInfo, decrInfo) {
|
|
@@ -45,13 +45,12 @@ async function makeMsgIndex(syncedFS, localFS, logError) {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
async function periodicCheckAndUploadOfData() {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// }
|
|
48
|
+
const shardTS = Date.now() - 10 * 60 * 1000;
|
|
49
|
+
const countBefore = indexed.numberOfRecordsInLatestBefore(shardTS);
|
|
50
|
+
if (countBefore >= NUM_OF_ENTRIES_TO_CHOP_DB) {
|
|
51
|
+
const syncedIndexDbVersion = await indexed.makeNewShardWithRecordsUpToTS(shardTS);
|
|
52
|
+
await logs.cutLogOnDatasetSyncAndUpload(syncedIndexDbVersion, { shardTS });
|
|
53
|
+
}
|
|
55
54
|
}
|
|
56
55
|
function millisBeforeNextRun() {
|
|
57
56
|
return 30 * 60 * 1000 + Math.floor(10 * 60 * 1000 * Math.random());
|
|
@@ -61,8 +61,8 @@ class ASMail {
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
async setupSendingParams(syncedFS) {
|
|
64
|
-
const fs = await (0, fs_sync_utils_1.
|
|
65
|
-
this.sendingParams = await sending_params_1.
|
|
64
|
+
const fs = await (0, fs_sync_utils_1.getOrMakeDirOnInit)(syncedFS, SEND_PARAMS_DATA_FOLDER);
|
|
65
|
+
this.sendingParams = await (0, sending_params_1.makeSendingParamsHolder)(fs, this.config.makeParamSetterAndGetter('anon-sender/invites'), this.random);
|
|
66
66
|
}
|
|
67
67
|
async setupDelivery(localFS, getSigner, makeResolver) {
|
|
68
68
|
const fs = await localFS.writableSubRoot(DELIVERY_DATA_FOLDER);
|
|
@@ -88,7 +88,7 @@ class ASMail {
|
|
|
88
88
|
}
|
|
89
89
|
async setupInbox(syncedFS, localFS, getSigner, getStorages, makeResolver) {
|
|
90
90
|
const cachePath = this.inboxPathForUser(this.address);
|
|
91
|
-
const inboxSyncedFS = await (0, fs_sync_utils_1.
|
|
91
|
+
const inboxSyncedFS = await (0, fs_sync_utils_1.getOrMakeDirOnInit)(syncedFS, INBOX_DATA_FOLDER);
|
|
92
92
|
const inboxLocalFS = await localFS.writableSubRoot(INBOX_DATA_FOLDER);
|
|
93
93
|
this.inbox = await (0, inbox_1.makeInboxOnServer)(cachePath, inboxSyncedFS, inboxLocalFS, {
|
|
94
94
|
address: this.address,
|
|
@@ -6,18 +6,17 @@ export { SendingParams } from './params-from-others';
|
|
|
6
6
|
type WritableFS = web3n.files.WritableFS;
|
|
7
7
|
type SendingResources = ResourcesForSending['correspondents'];
|
|
8
8
|
type ReceptionResources = ResourcesForReceiving['correspondents'];
|
|
9
|
-
export
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
readonly thisSide: {
|
|
13
|
-
getUpdated: SendingResources['newParamsForSendingReplies'];
|
|
14
|
-
setAsUsed: ReceptionResources['markOwnSendingParamsAsUsed'];
|
|
15
|
-
};
|
|
16
|
-
readonly otherSides: {
|
|
17
|
-
get: SendingResources['paramsForSendingTo'];
|
|
18
|
-
set: ReceptionResources['saveParamsForSendingTo'];
|
|
19
|
-
};
|
|
20
|
-
private constructor();
|
|
21
|
-
static makeAndInit(fs: WritableFS, anonInvitesOnServer: ParamOnServer<'anon-sender/invites'>, random: AsyncRNG): Promise<SendingParamsHolder>;
|
|
22
|
-
close(): Promise<void>;
|
|
9
|
+
export interface SendingParamsThisSide {
|
|
10
|
+
getUpdated: SendingResources['newParamsForSendingReplies'];
|
|
11
|
+
setAsUsed: ReceptionResources['markOwnSendingParamsAsUsed'];
|
|
23
12
|
}
|
|
13
|
+
export interface SendingParamsOtherSides {
|
|
14
|
+
get: SendingResources['paramsForSendingTo'];
|
|
15
|
+
set: ReceptionResources['saveParamsForSendingTo'];
|
|
16
|
+
}
|
|
17
|
+
export interface SendingParamsHolder {
|
|
18
|
+
thisSide: SendingParamsThisSide;
|
|
19
|
+
otherSides: SendingParamsOtherSides;
|
|
20
|
+
close: () => Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
export declare function makeSendingParamsHolder(fs: WritableFS, anonInvitesOnServer: ParamOnServer<'anon-sender/invites'>, random: AsyncRNG): Promise<SendingParamsHolder>;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2017 - 2018, 2025 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2017 - 2018, 2025 - 2026 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
|
|
@@ -16,46 +16,26 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
19
|
+
exports.makeSendingParamsHolder = makeSendingParamsHolder;
|
|
20
20
|
const params_from_others_1 = require("./params-from-others");
|
|
21
21
|
const own_params_1 = require("./own-params");
|
|
22
22
|
const invitations_anon_1 = require("./invitations-anon");
|
|
23
23
|
const PARAMS_FROM_OTHERS_FILE = 'params-from-others.json';
|
|
24
24
|
const OWN_PARAMS_FILE = 'own-params.json';
|
|
25
25
|
const ANONYM_INVITES_FILE = 'anonymous-invites.json';
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.thisSide = {
|
|
35
|
-
getUpdated: this.ownParams.getFor,
|
|
36
|
-
setAsUsed: this.ownParams.setAsInUse
|
|
37
|
-
};
|
|
38
|
-
Object.freeze(this);
|
|
39
|
-
}
|
|
40
|
-
static async makeAndInit(fs, anonInvitesOnServer, random) {
|
|
41
|
-
const [paramsFromOthers, ownParams] = await Promise.all([
|
|
42
|
-
fs.writableFile(PARAMS_FROM_OTHERS_FILE)
|
|
43
|
-
.then(f => params_from_others_1.ParamsFromOthers.makeAndInit(f)),
|
|
44
|
-
fs.writableFile(ANONYM_INVITES_FILE)
|
|
45
|
-
.then(async (anonInvitesFile) => {
|
|
46
|
-
const anonInvites = await invitations_anon_1.AnonymousInvites.makeAndInit(anonInvitesFile, anonInvitesOnServer, random);
|
|
47
|
-
return await own_params_1.OwnSendingParams.makeAndInit(await fs.writableFile(OWN_PARAMS_FILE), anonInvites);
|
|
48
|
-
})
|
|
49
|
-
]);
|
|
50
|
-
await fs.close();
|
|
51
|
-
return new SendingParamsHolder(paramsFromOthers, ownParams);
|
|
52
|
-
}
|
|
53
|
-
async close() {
|
|
54
|
-
await this.ownParams.close();
|
|
55
|
-
await this.paramsFromOthers.close();
|
|
26
|
+
async function makeSendingParamsHolder(fs, anonInvitesOnServer, random) {
|
|
27
|
+
const [otherSides, thisSide] = await Promise.all([
|
|
28
|
+
(0, params_from_others_1.makeParamsFromOthers)(fs, PARAMS_FROM_OTHERS_FILE),
|
|
29
|
+
(0, own_params_1.makeOwnSendingParams)(fs, OWN_PARAMS_FILE, await (0, invitations_anon_1.makeAnonymousInvites)(fs, ANONYM_INVITES_FILE, anonInvitesOnServer, random))
|
|
30
|
+
]);
|
|
31
|
+
async function close() {
|
|
32
|
+
await thisSide.close();
|
|
33
|
+
await otherSides.close();
|
|
56
34
|
}
|
|
35
|
+
return {
|
|
36
|
+
thisSide,
|
|
37
|
+
otherSides,
|
|
38
|
+
close
|
|
39
|
+
};
|
|
57
40
|
}
|
|
58
|
-
exports.SendingParamsHolder = SendingParamsHolder;
|
|
59
|
-
Object.freeze(SendingParamsHolder.prototype);
|
|
60
|
-
Object.freeze(SendingParamsHolder);
|
|
61
41
|
Object.freeze(exports);
|
|
@@ -1,37 +1,13 @@
|
|
|
1
1
|
import { ParamOnServer } from '../../../lib-client/asmail/service-config';
|
|
2
2
|
import { AsyncRNG } from '../../../lib-common/rng-def';
|
|
3
|
-
type
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
msgMaxSize: number;
|
|
9
|
-
};
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
export declare class AnonymousInvites {
|
|
13
|
-
private readonly anonInvitesOnServer;
|
|
14
|
-
private readonly random;
|
|
15
|
-
private invites;
|
|
16
|
-
private readonly fileProc;
|
|
17
|
-
private constructor();
|
|
18
|
-
static makeAndInit(file: WritableFile, anonInvitesOnServer: ParamOnServer<'anon-sender/invites'>, random: AsyncRNG): Promise<AnonymousInvites>;
|
|
19
|
-
private onFileEvent;
|
|
20
|
-
protected setFromJSON(json: InvitesJSON): void;
|
|
21
|
-
private toFileJSON;
|
|
22
|
-
private persist;
|
|
23
|
-
private absorbRemoteChanges;
|
|
24
|
-
private toServerParam;
|
|
25
|
-
private toServiceJSON;
|
|
26
|
-
private syncServiceSetting;
|
|
27
|
-
getAll(): Map<string, {
|
|
3
|
+
type WritableFS = web3n.files.WritableFS;
|
|
4
|
+
export type AnonymousInvites = Awaited<ReturnType<typeof makeAnonymousInvites>>;
|
|
5
|
+
export declare function makeAnonymousInvites(fs: WritableFS, fileName: string, anonInvitesOnServer: ParamOnServer<'anon-sender/invites'>, random: AsyncRNG): Promise<{
|
|
6
|
+
create: (label: string, msgMaxSize: number) => Promise<string>;
|
|
7
|
+
getAll: () => Map<string, {
|
|
28
8
|
invite: string;
|
|
29
9
|
msgMaxSize: number;
|
|
30
10
|
}>;
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
private findByLabel;
|
|
34
|
-
setMsgMaxSize(label: string, msgMaxSize: number): Promise<void>;
|
|
35
|
-
close(): Promise<void>;
|
|
36
|
-
}
|
|
11
|
+
close: () => Promise<void>;
|
|
12
|
+
}>;
|
|
37
13
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/*
|
|
3
|
-
Copyright (C) 2015 - 2018, 2025 3NSoft Inc.
|
|
3
|
+
Copyright (C) 2015 - 2018, 2025 - 2026 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
|
|
@@ -16,160 +16,110 @@
|
|
|
16
16
|
this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17
17
|
*/
|
|
18
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
-
exports.
|
|
20
|
-
const file_based_json_1 = require("../../../lib-client/xsp-fs/util/file-based-json");
|
|
21
|
-
const json_utils_1 = require("../../../lib-common/json-utils");
|
|
19
|
+
exports.makeAnonymousInvites = makeAnonymousInvites;
|
|
22
20
|
const rng_def_1 = require("../../../lib-common/rng-def");
|
|
21
|
+
const single_file_1 = require("../../../lib-common/dataset-sync/single-file");
|
|
23
22
|
const INVITE_TOKEN_LEN = 40;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
Object.seal(this);
|
|
31
|
-
}
|
|
32
|
-
static async makeAndInit(file, anonInvitesOnServer, random) {
|
|
33
|
-
const anonInvites = new AnonymousInvites(anonInvitesOnServer, random);
|
|
34
|
-
await anonInvites.fileProc.start(file, () => anonInvites.toFileJSON());
|
|
35
|
-
// XXX these are part of proper syncing logic
|
|
36
|
-
// await anonInvites.absorbRemoteChanges();
|
|
37
|
-
// await anonInvites.syncServiceSetting();
|
|
38
|
-
return anonInvites;
|
|
39
|
-
}
|
|
40
|
-
async onFileEvent(ev) {
|
|
41
|
-
if (ev.src === 'local') {
|
|
42
|
-
return;
|
|
23
|
+
async function makeAnonymousInvites(fs, fileName, anonInvitesOnServer, random) {
|
|
24
|
+
const { file: invitesFile, changeProc } = await (0, single_file_1.initSyncedFile)(fs, fileName, newFile => newFile.writeJSON({ invites: {} }));
|
|
25
|
+
function parseInvitesFromJSON(json) {
|
|
26
|
+
const invites = json.invites;
|
|
27
|
+
if (invites || (typeof invites === 'object')) {
|
|
28
|
+
return invites;
|
|
43
29
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
await this.fileProc.order.startOrChain(() => this.absorbRemoteChanges());
|
|
47
|
-
break;
|
|
48
|
-
case 'removed':
|
|
49
|
-
throw new Error(`Unexpected removal of file with parameter "anon-sender/invites"`);
|
|
50
|
-
default:
|
|
51
|
-
return;
|
|
30
|
+
else {
|
|
31
|
+
return {};
|
|
52
32
|
}
|
|
53
33
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
34
|
+
let invites = parseInvitesFromJSON(await invitesFile.readJSON());
|
|
35
|
+
async function onChangeFromOtherDevices(newVersion) {
|
|
36
|
+
changeProc.startOrChain(async () => {
|
|
37
|
+
const { version, json } = await invitesFile.v.readJSON();
|
|
38
|
+
if (version === newVersion) {
|
|
39
|
+
invites = parseInvitesFromJSON(json);
|
|
40
|
+
}
|
|
41
|
+
});
|
|
61
42
|
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
await
|
|
65
|
-
|
|
43
|
+
function doOnConflict() {
|
|
44
|
+
return changeProc.startOrChain(async () => {
|
|
45
|
+
const { remote, state } = await invitesFile.v.sync.status(false);
|
|
46
|
+
if ((state !== 'conflicting') || !(remote === null || remote === void 0 ? void 0 : remote.latest)) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const onRemote = (await invitesFile.v.readJSON({ remoteVersion: remote.latest })).json;
|
|
50
|
+
const numOfInvitesOnRemote = Object.keys(onRemote.invites).length;
|
|
51
|
+
const numOfCurrentInvites = Object.keys(invites).length;
|
|
52
|
+
const joined = { ...onRemote.invites, ...invites };
|
|
53
|
+
const numOfJoined = Object.keys(joined).length;
|
|
54
|
+
if ((numOfCurrentInvites === numOfInvitesOnRemote) && (numOfCurrentInvites === numOfJoined)) {
|
|
55
|
+
await invitesFile.v.sync.adoptRemote({ remoteVersion: remote.latest });
|
|
56
|
+
}
|
|
57
|
+
else {
|
|
58
|
+
invites = joined;
|
|
59
|
+
await invitesFile.writeJSON({ invites });
|
|
60
|
+
await invitesFile.v.sync.upload({ uploadVersion: remote.latest + 1 });
|
|
61
|
+
await anonInvitesOnServer.setOnServer(invitesToServerParamForm(invites));
|
|
62
|
+
}
|
|
66
63
|
});
|
|
67
64
|
}
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
// Code from pre-v.sync:
|
|
74
|
-
// const { json } = await this.fileProc.get();
|
|
75
|
-
// this.setFromJSON(json);
|
|
65
|
+
const { stopFileWatching, triggerUpload } = (0, single_file_1.watchAndApplyChangesFromOtherDevices)(invitesFile, changeProc, onChangeFromOtherDevices, doOnConflict);
|
|
66
|
+
async function persist() {
|
|
67
|
+
await anonInvitesOnServer.setOnServer(invitesToServerParamForm(invites));
|
|
68
|
+
await invitesFile.writeJSON({ invites });
|
|
69
|
+
triggerUpload();
|
|
76
70
|
}
|
|
77
|
-
|
|
71
|
+
function invitesToServerParamForm(invites) {
|
|
78
72
|
const serverParam = {};
|
|
79
|
-
for (const [invite, { msgMaxSize }] of Object.entries(
|
|
73
|
+
for (const [invite, { msgMaxSize }] of Object.entries(invites)) {
|
|
80
74
|
serverParam[invite] = msgMaxSize;
|
|
81
75
|
}
|
|
82
76
|
return serverParam;
|
|
83
77
|
}
|
|
84
|
-
|
|
85
|
-
const serverJSON = {};
|
|
86
|
-
Object.entries(this.invites)
|
|
87
|
-
.forEach(([invite, params]) => {
|
|
88
|
-
serverJSON[invite] = params.msgMaxSize;
|
|
89
|
-
});
|
|
90
|
-
return serverJSON;
|
|
91
|
-
}
|
|
92
|
-
async syncServiceSetting(rethrowConnectExc = false) {
|
|
93
|
-
// XXX we may have the following bug here:
|
|
94
|
-
// Device with older version of param gets to this point, and sets older
|
|
95
|
-
// value.
|
|
96
|
-
// To protect aginst this case, absorbing from file must ensure highest
|
|
97
|
-
// synced version is read.
|
|
98
|
-
try {
|
|
99
|
-
const infoOnServer = await this.anonInvitesOnServer.getFromServer()
|
|
100
|
-
.catch((exc) => {
|
|
101
|
-
if (exc.type === 'connect') {
|
|
102
|
-
return;
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
105
|
-
throw exc;
|
|
106
|
-
}
|
|
107
|
-
});
|
|
108
|
-
const currentVal = this.toServiceJSON();
|
|
109
|
-
if (!(0, json_utils_1.deepEqual)(infoOnServer, currentVal)) {
|
|
110
|
-
await this.anonInvitesOnServer.setOnServer(currentVal);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
catch (exc) {
|
|
114
|
-
if (!rethrowConnectExc
|
|
115
|
-
&& (exc.type === 'connect')) {
|
|
116
|
-
return;
|
|
117
|
-
}
|
|
118
|
-
throw exc;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
getAll() {
|
|
78
|
+
function getAll() {
|
|
122
79
|
const byLabel = new Map();
|
|
123
|
-
Object.entries(
|
|
80
|
+
Object.entries(invites)
|
|
124
81
|
.forEach(([invite, params]) => {
|
|
125
82
|
byLabel.set(params.label, { invite, msgMaxSize: params.msgMaxSize });
|
|
126
83
|
});
|
|
127
84
|
return byLabel;
|
|
128
85
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
86
|
+
function create(label, msgMaxSize) {
|
|
87
|
+
return changeProc.startOrChain(async () => {
|
|
88
|
+
const existingInvite = findByLabel(label);
|
|
89
|
+
if (existingInvite) {
|
|
90
|
+
throw new Error(`Anonymous sender invite already exists with label ${label}`);
|
|
91
|
+
}
|
|
92
|
+
const invite = await generateNewRandomInvite();
|
|
93
|
+
invites[invite] = { label, msgMaxSize };
|
|
94
|
+
try {
|
|
95
|
+
await persist();
|
|
96
|
+
return invite;
|
|
97
|
+
}
|
|
98
|
+
catch (exc) {
|
|
99
|
+
delete invites[invite];
|
|
100
|
+
throw exc;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
145
103
|
}
|
|
146
|
-
|
|
147
|
-
async generateNewRandomInvite() {
|
|
104
|
+
async function generateNewRandomInvite() {
|
|
148
105
|
let invite;
|
|
149
106
|
do {
|
|
150
|
-
invite = await (0, rng_def_1.stringOfB64Chars)(INVITE_TOKEN_LEN,
|
|
151
|
-
} while (
|
|
107
|
+
invite = await (0, rng_def_1.stringOfB64Chars)(INVITE_TOKEN_LEN, random);
|
|
108
|
+
} while (invites[invite]);
|
|
152
109
|
return invite;
|
|
153
110
|
}
|
|
154
|
-
findByLabel(label) {
|
|
155
|
-
const found = Object.entries(
|
|
111
|
+
function findByLabel(label) {
|
|
112
|
+
const found = Object.entries(invites)
|
|
156
113
|
.find(([_, params]) => (params.label === label));
|
|
157
114
|
return (found ? found[0] : undefined);
|
|
158
115
|
}
|
|
159
|
-
async
|
|
160
|
-
|
|
161
|
-
if (!invite) {
|
|
162
|
-
throw new Error(`There is no anonymous sender invite with label ${label}`);
|
|
163
|
-
}
|
|
164
|
-
this.invites[invite].msgMaxSize = msgMaxSize;
|
|
165
|
-
await this.persist();
|
|
166
|
-
}
|
|
167
|
-
;
|
|
168
|
-
async close() {
|
|
169
|
-
await this.fileProc.close();
|
|
116
|
+
async function close() {
|
|
117
|
+
stopFileWatching();
|
|
170
118
|
}
|
|
119
|
+
return {
|
|
120
|
+
create,
|
|
121
|
+
getAll,
|
|
122
|
+
close
|
|
123
|
+
};
|
|
171
124
|
}
|
|
172
|
-
exports.AnonymousInvites = AnonymousInvites;
|
|
173
|
-
Object.freeze(AnonymousInvites.prototype);
|
|
174
|
-
Object.freeze(AnonymousInvites);
|
|
175
125
|
Object.freeze(exports);
|
|
@@ -1,28 +1,8 @@
|
|
|
1
1
|
import { SendingParamsHolder } from './index';
|
|
2
2
|
import { AnonymousInvites } from './invitations-anon';
|
|
3
|
-
type
|
|
4
|
-
type
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* other correspondents for sending messages back. These parameters may have
|
|
9
|
-
* invitation tokens, and this class uses config service to register tokens on
|
|
10
|
-
* a server.
|
|
11
|
-
*/
|
|
12
|
-
export declare class OwnSendingParams {
|
|
13
|
-
private readonly anonInvites;
|
|
14
|
-
private readonly params;
|
|
15
|
-
private defaultParams;
|
|
16
|
-
private readonly fileProc;
|
|
17
|
-
private constructor();
|
|
18
|
-
static makeAndInit(file: WritableFile, anonInvites: AnonymousInvites): Promise<OwnSendingParams>;
|
|
19
|
-
private setDefaultParams;
|
|
20
|
-
private toFileJSON;
|
|
21
|
-
private persist;
|
|
22
|
-
private absorbChangesFromFile;
|
|
23
|
-
protected onFileEvent(ev: FileEvent): Promise<void>;
|
|
24
|
-
getFor: ExposedFuncs['getUpdated'];
|
|
25
|
-
setAsInUse: ExposedFuncs['setAsUsed'];
|
|
26
|
-
close(): Promise<void>;
|
|
27
|
-
}
|
|
3
|
+
type WritableFS = web3n.files.WritableFS;
|
|
4
|
+
export type OwnSendingParams = Awaited<ReturnType<typeof makeOwnSendingParams>>;
|
|
5
|
+
export declare function makeOwnSendingParams(fs: WritableFS, fileName: string, anonInvites: AnonymousInvites): Promise<SendingParamsHolder['thisSide'] & {
|
|
6
|
+
close: () => Promise<void>;
|
|
7
|
+
}>;
|
|
28
8
|
export {};
|