@joe-broadhead/messaging-bin-darwin-x64 0.9.6 → 0.9.7
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/bin/messagingd +2 -2
- package/lib/messagingd.mjs +408 -196
- package/package.json +1 -1
package/bin/messagingd
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
[diffend] Oversized file quarantined before diffing.
|
|
2
2
|
name: package/bin/messagingd
|
|
3
|
-
size:
|
|
4
|
-
sha256:
|
|
3
|
+
size: 80762672 bytes
|
|
4
|
+
sha256: c8d5137eeb6fbcd27fc8a6681490e955fb0d526da115f8817dd733d4f1ce19cc
|
package/lib/messagingd.mjs
CHANGED
|
@@ -9589,8 +9589,9 @@ var init_conv_frames = __esm(() => {
|
|
|
9589
9589
|
t: literal("conv.head"),
|
|
9590
9590
|
req: Req4,
|
|
9591
9591
|
cids: array(ConvId).min(1).max(LIMITS.convHeads).optional(),
|
|
9592
|
-
after: ConvId.optional()
|
|
9593
|
-
|
|
9592
|
+
after: ConvId.optional(),
|
|
9593
|
+
join: literal(true).optional()
|
|
9594
|
+
}).refine((f) => f.cids === undefined || f.after === undefined, { message: "cids or after, not both" }).refine((f) => f.join === undefined || f.cids !== undefined, { message: "join names the cids it is for" });
|
|
9594
9595
|
ConvCapsFrame = strictObject({ t: literal("conv.caps"), req: Req4, persons: array(PersonId).min(1).max(LIMITS.convOpParticipants), attest: literal(true).optional() });
|
|
9595
9596
|
ConvFeaturesFrame = strictObject({
|
|
9596
9597
|
t: literal("conv.features"),
|
|
@@ -10527,7 +10528,7 @@ var init_channel_card2 = __esm(() => {
|
|
|
10527
10528
|
});
|
|
10528
10529
|
|
|
10529
10530
|
// packages/core/dist/version.js
|
|
10530
|
-
var VERSION = "0.9.
|
|
10531
|
+
var VERSION = "0.9.7";
|
|
10531
10532
|
|
|
10532
10533
|
// packages/core/dist/wire.js
|
|
10533
10534
|
function parseWire(text, options = {}) {
|
|
@@ -21211,6 +21212,140 @@ var init_directory2 = __esm(() => {
|
|
|
21211
21212
|
FEATURES = ["tasks", "conversations", "reach", "read-state", "mention-wake", "turn-cancel", "attested-chains"];
|
|
21212
21213
|
});
|
|
21213
21214
|
|
|
21215
|
+
// packages/daemon/dist/log.js
|
|
21216
|
+
import { closeSync as closeSync7, constants as constants5, lstatSync as lstatSync9, renameSync as renameSync8, writeSync as writeSync4 } from "fs";
|
|
21217
|
+
function redactConversations(value) {
|
|
21218
|
+
if (typeof value === "string")
|
|
21219
|
+
return value.replace(CONVERSATION_ID, CONVERSATION_MARK);
|
|
21220
|
+
if (Array.isArray(value))
|
|
21221
|
+
return value.map(redactConversations);
|
|
21222
|
+
if (value !== null && typeof value === "object") {
|
|
21223
|
+
const out = {};
|
|
21224
|
+
for (const [name, inner] of Object.entries(value))
|
|
21225
|
+
out[name] = redactConversations(inner);
|
|
21226
|
+
return out;
|
|
21227
|
+
}
|
|
21228
|
+
return value;
|
|
21229
|
+
}
|
|
21230
|
+
function formatLine(level, event, fields = {}) {
|
|
21231
|
+
const record = { t: new Date().toISOString(), level, event };
|
|
21232
|
+
const kept = CATALOGUE_EVENTS.has(event) ? fields : redactConversations(fields);
|
|
21233
|
+
for (const [name, value] of Object.entries(kept))
|
|
21234
|
+
if (value !== undefined)
|
|
21235
|
+
record[Object.hasOwn(record, name) ? `${name}_` : name] = value;
|
|
21236
|
+
return `${JSON.stringify(record)}
|
|
21237
|
+
`;
|
|
21238
|
+
}
|
|
21239
|
+
function safeLine(level, event, fields) {
|
|
21240
|
+
try {
|
|
21241
|
+
return formatLine(level, event, fields);
|
|
21242
|
+
} catch (error) {
|
|
21243
|
+
return formatLine(level, event, { error: error instanceof Error ? error.name : typeof error });
|
|
21244
|
+
}
|
|
21245
|
+
}
|
|
21246
|
+
function logFailure(logger) {
|
|
21247
|
+
return failures.get(logger)?.();
|
|
21248
|
+
}
|
|
21249
|
+
function createLogger(options) {
|
|
21250
|
+
const min = RANK[options.level ?? "info"];
|
|
21251
|
+
const maxBytes = options.maxBytes ?? LOG_MAX_BYTES;
|
|
21252
|
+
const keep = options.keep ?? LOG_KEEP;
|
|
21253
|
+
const now = options.now ?? Date.now;
|
|
21254
|
+
let size;
|
|
21255
|
+
let failure;
|
|
21256
|
+
const logger = (level, event, fields) => {
|
|
21257
|
+
if (RANK[level] < min)
|
|
21258
|
+
return;
|
|
21259
|
+
const line = safeLine(level, event, fields);
|
|
21260
|
+
const file = options.file;
|
|
21261
|
+
if (file) {
|
|
21262
|
+
try {
|
|
21263
|
+
const bytes = Buffer.byteLength(line);
|
|
21264
|
+
size ??= currentSize(file);
|
|
21265
|
+
if (size > 0 && size + bytes > maxBytes) {
|
|
21266
|
+
rotate2(file, keep);
|
|
21267
|
+
size = 0;
|
|
21268
|
+
}
|
|
21269
|
+
const fd = openNoFollow(file, constants5.O_WRONLY | constants5.O_APPEND | constants5.O_CREAT, 384);
|
|
21270
|
+
try {
|
|
21271
|
+
writeSync4(fd, line);
|
|
21272
|
+
} finally {
|
|
21273
|
+
closeSync7(fd);
|
|
21274
|
+
}
|
|
21275
|
+
size += bytes;
|
|
21276
|
+
failure = undefined;
|
|
21277
|
+
} catch (error) {
|
|
21278
|
+
size = undefined;
|
|
21279
|
+
failure ??= { since: now(), code: String(error.code ?? "error").slice(0, 32) };
|
|
21280
|
+
}
|
|
21281
|
+
}
|
|
21282
|
+
if (options.stderr)
|
|
21283
|
+
process.stderr.write(line);
|
|
21284
|
+
};
|
|
21285
|
+
failures.set(logger, () => failure);
|
|
21286
|
+
return logger;
|
|
21287
|
+
}
|
|
21288
|
+
function currentSize(file) {
|
|
21289
|
+
try {
|
|
21290
|
+
return lstatSync9(file).size;
|
|
21291
|
+
} catch {
|
|
21292
|
+
return 0;
|
|
21293
|
+
}
|
|
21294
|
+
}
|
|
21295
|
+
function rotate2(file, keep) {
|
|
21296
|
+
for (let n = keep - 1;n >= 1; n--) {
|
|
21297
|
+
try {
|
|
21298
|
+
renameSync8(`${file}.${n}`, `${file}.${n + 1}`);
|
|
21299
|
+
} catch {}
|
|
21300
|
+
}
|
|
21301
|
+
renameSync8(file, `${file}.1`);
|
|
21302
|
+
}
|
|
21303
|
+
|
|
21304
|
+
class LogBudget {
|
|
21305
|
+
max;
|
|
21306
|
+
windowMs;
|
|
21307
|
+
#window = [];
|
|
21308
|
+
#suppressed = 0;
|
|
21309
|
+
constructor(max = 30, windowMs = 60000) {
|
|
21310
|
+
this.max = max;
|
|
21311
|
+
this.windowMs = windowMs;
|
|
21312
|
+
}
|
|
21313
|
+
take(now) {
|
|
21314
|
+
this.#window = this.#window.filter((at) => at > now - this.windowMs);
|
|
21315
|
+
if (this.#window.length >= this.max) {
|
|
21316
|
+
this.#suppressed++;
|
|
21317
|
+
return { ok: false, suppressed: 0 };
|
|
21318
|
+
}
|
|
21319
|
+
this.#window.push(now);
|
|
21320
|
+
const suppressed = this.#suppressed;
|
|
21321
|
+
this.#suppressed = 0;
|
|
21322
|
+
return { ok: true, suppressed };
|
|
21323
|
+
}
|
|
21324
|
+
drain() {
|
|
21325
|
+
const n = this.#suppressed;
|
|
21326
|
+
this.#suppressed = 0;
|
|
21327
|
+
return n;
|
|
21328
|
+
}
|
|
21329
|
+
}
|
|
21330
|
+
function codeOf(error) {
|
|
21331
|
+
const code = error?.code;
|
|
21332
|
+
return typeof code === "string" && /^[a-z_]{1,40}$/.test(code) ? code : "internal";
|
|
21333
|
+
}
|
|
21334
|
+
var RANK, LOG_MAX_BYTES, LOG_KEEP = 3, CONVERSATION_ID, CONVERSATION_MARK = "[conversation]", CATALOGUE_EVENTS, failures;
|
|
21335
|
+
var init_log2 = __esm(() => {
|
|
21336
|
+
init_dist2();
|
|
21337
|
+
RANK = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
21338
|
+
LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
21339
|
+
CONVERSATION_ID = /[ds]_[a-z2-7]{26}|c_[0-7][0-9A-HJKMNP-TV-Z]{25}/g;
|
|
21340
|
+
CATALOGUE_EVENTS = new Set([
|
|
21341
|
+
"conv.catalogue.card.rejected",
|
|
21342
|
+
"conv.catalogue.card.unbound",
|
|
21343
|
+
"conv.catalogue.withdrawn",
|
|
21344
|
+
"conv.catalogue.published"
|
|
21345
|
+
]);
|
|
21346
|
+
failures = new WeakMap;
|
|
21347
|
+
});
|
|
21348
|
+
|
|
21214
21349
|
// packages/daemon/dist/conv-catalogue.js
|
|
21215
21350
|
function available(deps) {
|
|
21216
21351
|
return deps.link.convCatalogue !== undefined && supports(deps.features(), "catalogue");
|
|
@@ -21224,25 +21359,53 @@ async function convCatalogue(deps, params) {
|
|
|
21224
21359
|
...params.limit !== undefined ? { limit: params.limit } : {}
|
|
21225
21360
|
});
|
|
21226
21361
|
const channels = [];
|
|
21227
|
-
|
|
21228
|
-
|
|
21362
|
+
const read = answer.channels.map((listing) => ({ listing, card: signedCard(deps, listing) }));
|
|
21363
|
+
const placed = await place(deps, read);
|
|
21364
|
+
for (const { listing, card } of read) {
|
|
21365
|
+
if (!card)
|
|
21366
|
+
continue;
|
|
21367
|
+
const row = rowOf(deps, listing, card, placed);
|
|
21229
21368
|
if (row)
|
|
21230
21369
|
channels.push(row);
|
|
21231
21370
|
}
|
|
21232
21371
|
const cursor = answer.channels.at(-1)?.card.cid;
|
|
21233
21372
|
return { channels, more: answer.more, ...answer.more && cursor !== undefined ? { cursor } : {} };
|
|
21234
21373
|
}
|
|
21235
|
-
function
|
|
21374
|
+
function signedCard(deps, listing) {
|
|
21236
21375
|
if (listing.card.realm !== deps.realm)
|
|
21237
21376
|
return;
|
|
21238
21377
|
try {
|
|
21239
|
-
verifyChannelCard(listing.card);
|
|
21378
|
+
return verifyChannelCard(listing.card);
|
|
21240
21379
|
} catch {
|
|
21241
21380
|
deps.log?.("conv.catalogue.card.rejected", { cid: listing.card.cid });
|
|
21242
21381
|
return;
|
|
21243
21382
|
}
|
|
21244
|
-
|
|
21245
|
-
|
|
21383
|
+
}
|
|
21384
|
+
async function place(deps, read) {
|
|
21385
|
+
const look = deps.place;
|
|
21386
|
+
if (!look)
|
|
21387
|
+
return new Map;
|
|
21388
|
+
const pairs = [];
|
|
21389
|
+
for (const { card } of read) {
|
|
21390
|
+
if (!card || deps.isDevice(card.by.person, card.by.device))
|
|
21391
|
+
continue;
|
|
21392
|
+
if (pairs.length >= LIMITS.cataloguePage)
|
|
21393
|
+
break;
|
|
21394
|
+
if (!pairs.some((pair) => pair.person === card.by.person && pair.device === card.by.device)) {
|
|
21395
|
+
pairs.push({ person: card.by.person, device: card.by.device });
|
|
21396
|
+
}
|
|
21397
|
+
}
|
|
21398
|
+
if (pairs.length === 0)
|
|
21399
|
+
return new Map;
|
|
21400
|
+
try {
|
|
21401
|
+
return await look(pairs);
|
|
21402
|
+
} catch (error) {
|
|
21403
|
+
deps.log?.("conv.catalogue.card.unplaced", { code: codeOf(error), count: pairs.length });
|
|
21404
|
+
return new Map;
|
|
21405
|
+
}
|
|
21406
|
+
}
|
|
21407
|
+
function rowOf(deps, listing, card, placed) {
|
|
21408
|
+
if (!deps.isDevice(card.by.person, card.by.device) && placed.get(card.by.device) !== card.by.person) {
|
|
21246
21409
|
deps.log?.("conv.catalogue.card.unbound", { cid: card.cid });
|
|
21247
21410
|
return;
|
|
21248
21411
|
}
|
|
@@ -21296,6 +21459,64 @@ async function convPublish(deps, cid, on) {
|
|
|
21296
21459
|
var NO_CATALOGUE = "this relay serves no channel catalogue; upgrade the relay, then try again";
|
|
21297
21460
|
var init_conv_catalogue = __esm(() => {
|
|
21298
21461
|
init_dist();
|
|
21462
|
+
init_log2();
|
|
21463
|
+
});
|
|
21464
|
+
|
|
21465
|
+
// packages/daemon/dist/conv-join.js
|
|
21466
|
+
async function joinUnheld(deps, cid) {
|
|
21467
|
+
if (!supports(deps.features(), "conv-join"))
|
|
21468
|
+
throw new MessagingError("relay_unavailable", NO_JOIN);
|
|
21469
|
+
if (deps.pending(cid))
|
|
21470
|
+
throw new MessagingError("conv_conflict", "a conversation event is still pending");
|
|
21471
|
+
for (let attempt = 1;; attempt++) {
|
|
21472
|
+
const answer = await deps.link.convHead({ cids: [cid], join: true });
|
|
21473
|
+
const view = answer.heads.find((head) => head.cid === cid);
|
|
21474
|
+
if (view === undefined)
|
|
21475
|
+
throw new MessagingError("not_found", "no such conversation");
|
|
21476
|
+
const now = deps.now();
|
|
21477
|
+
const identity = deps.identity();
|
|
21478
|
+
const event = signConvEvent(identity, {
|
|
21479
|
+
v: "messaging/1",
|
|
21480
|
+
realm: deps.realm,
|
|
21481
|
+
cid,
|
|
21482
|
+
id: ulid2(now),
|
|
21483
|
+
by: { person: deps.person, device: identity.machine },
|
|
21484
|
+
ts: now,
|
|
21485
|
+
opHead: view.opHead,
|
|
21486
|
+
class: "op",
|
|
21487
|
+
body: { op: "join" }
|
|
21488
|
+
});
|
|
21489
|
+
try {
|
|
21490
|
+
await deps.link.convAppend(event);
|
|
21491
|
+
} catch (error) {
|
|
21492
|
+
if (error instanceof MessagingError && error.code === "conv_conflict" && attempt < JOIN_TRIES) {
|
|
21493
|
+
deps.log?.("conversation.join.conflict", { attempt }, "info");
|
|
21494
|
+
continue;
|
|
21495
|
+
}
|
|
21496
|
+
if (error instanceof MessagingError && error.code === "invalid_state" && await alreadyJoined(deps, cid))
|
|
21497
|
+
return;
|
|
21498
|
+
throw error;
|
|
21499
|
+
}
|
|
21500
|
+
try {
|
|
21501
|
+
await deps.sync(cid);
|
|
21502
|
+
} catch (error) {
|
|
21503
|
+
const code = error instanceof MessagingError ? error.code : "internal";
|
|
21504
|
+
deps.log?.("conversation.join.sync", { code }, "warn");
|
|
21505
|
+
}
|
|
21506
|
+
return;
|
|
21507
|
+
}
|
|
21508
|
+
}
|
|
21509
|
+
async function alreadyJoined(deps, cid) {
|
|
21510
|
+
try {
|
|
21511
|
+
await deps.sync(cid);
|
|
21512
|
+
} catch {
|
|
21513
|
+
return false;
|
|
21514
|
+
}
|
|
21515
|
+
return deps.joined(cid);
|
|
21516
|
+
}
|
|
21517
|
+
var JOIN_TRIES = 3, NO_JOIN = "this relay cannot join a channel you don't hold yet; ask a member to add you";
|
|
21518
|
+
var init_conv_join = __esm(() => {
|
|
21519
|
+
init_dist();
|
|
21299
21520
|
});
|
|
21300
21521
|
|
|
21301
21522
|
// packages/daemon/dist/conv-context.js
|
|
@@ -23550,6 +23771,8 @@ class ConversationIpc {
|
|
|
23550
23771
|
if (method !== "conv.accept" && method !== "conv.join" && method !== "conv.seat")
|
|
23551
23772
|
this.#state(engine, p.cid, scope);
|
|
23552
23773
|
await this.#serial(p.cid, async () => {
|
|
23774
|
+
if (method === "conv.join" && !this.#heldAsParticipant(engine, p.cid))
|
|
23775
|
+
return this.#joinUnheld(engine, p.cid);
|
|
23553
23776
|
if (method === "conv.add") {
|
|
23554
23777
|
await this.options.fresh(p.participants.map((s) => participantPerson(s.p)));
|
|
23555
23778
|
const attested = engine.snapshot(p.cid)?.state?.attested !== undefined;
|
|
@@ -23583,6 +23806,35 @@ class ConversationIpc {
|
|
|
23583
23806
|
}
|
|
23584
23807
|
throw new MessagingError("invalid_request", "unknown conversation method");
|
|
23585
23808
|
}
|
|
23809
|
+
#heldAsParticipant(engine, cid) {
|
|
23810
|
+
const own = this.options.own().person;
|
|
23811
|
+
return engine.snapshot(cid)?.state?.participants.some((p) => p.person === own) ?? false;
|
|
23812
|
+
}
|
|
23813
|
+
async#joinUnheld(engine, cid) {
|
|
23814
|
+
const { realm, person, identities, link } = engine.options;
|
|
23815
|
+
await joinUnheld({
|
|
23816
|
+
realm,
|
|
23817
|
+
person,
|
|
23818
|
+
link,
|
|
23819
|
+
identity: () => {
|
|
23820
|
+
const device = this.options.own().device;
|
|
23821
|
+
const found = identities().find((identity) => identity.machine === device);
|
|
23822
|
+
if (!found)
|
|
23823
|
+
throw new MessagingError("no_identity", "this device has no identity to sign a join with");
|
|
23824
|
+
return found;
|
|
23825
|
+
},
|
|
23826
|
+
features: () => this.options.relayFeatures?.() ?? [],
|
|
23827
|
+
sync: (target) => engine.sync(target),
|
|
23828
|
+
pending: (target) => engine.options.store.convPending(target) !== undefined,
|
|
23829
|
+
joined: (target) => {
|
|
23830
|
+
const me = this.options.own().person;
|
|
23831
|
+
const member = engine.snapshot(target)?.state?.participants.some((p) => p.person === me && p.state === "member") ?? false;
|
|
23832
|
+
return member && engine.entries(target).some((entry) => entry.op === "join" && entry.author === me);
|
|
23833
|
+
},
|
|
23834
|
+
now: () => this.options.now(),
|
|
23835
|
+
log: (event, fields, level) => this.options.log?.(level ?? "info", event, fields)
|
|
23836
|
+
}, cid);
|
|
23837
|
+
}
|
|
23586
23838
|
#channelOrg(body) {
|
|
23587
23839
|
if (body.kind !== "channel")
|
|
23588
23840
|
return {};
|
|
@@ -23611,6 +23863,7 @@ class ConversationIpc {
|
|
|
23611
23863
|
},
|
|
23612
23864
|
features: () => this.options.relayFeatures?.() ?? [],
|
|
23613
23865
|
isDevice: (person, device) => engine.options.checks.isDevice?.(person, device) ?? false,
|
|
23866
|
+
...this.options.placeDevices !== undefined ? { place: (pairs) => this.options.placeDevices(pairs) } : {},
|
|
23614
23867
|
state: (cid) => engine.snapshot(cid)?.state,
|
|
23615
23868
|
metadata: (cid) => engine.metadata(cid),
|
|
23616
23869
|
now: () => this.options.now()
|
|
@@ -23963,6 +24216,7 @@ var init_conv_ipc = __esm(() => {
|
|
|
23963
24216
|
init_conv_project();
|
|
23964
24217
|
init_conv_catalogue();
|
|
23965
24218
|
init_conv_read();
|
|
24219
|
+
init_conv_join();
|
|
23966
24220
|
init_conv_context();
|
|
23967
24221
|
init_consumers();
|
|
23968
24222
|
init_conv_inbox();
|
|
@@ -24763,7 +25017,7 @@ var init_conv_maintenance = __esm(() => {
|
|
|
24763
25017
|
});
|
|
24764
25018
|
|
|
24765
25019
|
// packages/daemon/dist/conv-files.js
|
|
24766
|
-
import { closeSync as
|
|
25020
|
+
import { closeSync as closeSync8, constants as constants6, fsyncSync as fsyncSync3, lstatSync as lstatSync10, openSync as openSync6, readdirSync as readdirSync2, readFileSync as readFileSync12, readSync as readSync4, renameSync as renameSync9, unlinkSync as unlinkSync3, writeSync as writeSync5 } from "fs";
|
|
24767
25021
|
import { createHash as createHash20, randomBytes as randomBytes13 } from "crypto";
|
|
24768
25022
|
import { join as join11 } from "path";
|
|
24769
25023
|
function verifyFetched(plain, claimed) {
|
|
@@ -24779,7 +25033,7 @@ function verifyFetched(plain, claimed) {
|
|
|
24779
25033
|
}
|
|
24780
25034
|
}
|
|
24781
25035
|
function writeAt(fd, bytes, at) {
|
|
24782
|
-
return
|
|
25036
|
+
return writeSync5(fd, bytes, 0, bytes.length, at);
|
|
24783
25037
|
}
|
|
24784
25038
|
|
|
24785
25039
|
class ConvFiles {
|
|
@@ -25044,11 +25298,11 @@ class ConvFiles {
|
|
|
25044
25298
|
}
|
|
25045
25299
|
fsyncSync3(fd);
|
|
25046
25300
|
} catch (error) {
|
|
25047
|
-
|
|
25301
|
+
closeSync8(fd);
|
|
25048
25302
|
this.#unlink(part);
|
|
25049
25303
|
throw error;
|
|
25050
25304
|
}
|
|
25051
|
-
|
|
25305
|
+
closeSync8(fd);
|
|
25052
25306
|
const sealed = readFileSync12(part);
|
|
25053
25307
|
if (sealed.length !== most) {
|
|
25054
25308
|
this.#unlink(part);
|
|
@@ -25069,7 +25323,7 @@ class ConvFiles {
|
|
|
25069
25323
|
}
|
|
25070
25324
|
const now = this.#now();
|
|
25071
25325
|
try {
|
|
25072
|
-
|
|
25326
|
+
renameSync9(part, join11(this.#dir, request.blob));
|
|
25073
25327
|
} catch (error) {
|
|
25074
25328
|
this.#unlink(part);
|
|
25075
25329
|
throw error;
|
|
@@ -25204,11 +25458,11 @@ class ConvFiles {
|
|
|
25204
25458
|
writeAt(fd, p.data, 0);
|
|
25205
25459
|
fsyncSync3(fd);
|
|
25206
25460
|
} catch (error) {
|
|
25207
|
-
|
|
25461
|
+
closeSync8(fd);
|
|
25208
25462
|
this.#unlink(path);
|
|
25209
25463
|
throw internal("the file could not be written to this device");
|
|
25210
25464
|
}
|
|
25211
|
-
|
|
25465
|
+
closeSync8(fd);
|
|
25212
25466
|
try {
|
|
25213
25467
|
this.#store.blobInsert({
|
|
25214
25468
|
id,
|
|
@@ -25245,10 +25499,10 @@ class ConvFiles {
|
|
|
25245
25499
|
writeAt(fd, p.data, row.received);
|
|
25246
25500
|
fsyncSync3(fd);
|
|
25247
25501
|
} catch (error) {
|
|
25248
|
-
|
|
25502
|
+
closeSync8(fd);
|
|
25249
25503
|
throw internal("the file could not be written to this device");
|
|
25250
25504
|
}
|
|
25251
|
-
|
|
25505
|
+
closeSync8(fd);
|
|
25252
25506
|
const received = row.received + p.data.length;
|
|
25253
25507
|
this.#store.blobSetReceived(row.id, received);
|
|
25254
25508
|
if (received < row.bytes)
|
|
@@ -25280,7 +25534,7 @@ class ConvFiles {
|
|
|
25280
25534
|
readSync4(fd, out, 0, out.length, from);
|
|
25281
25535
|
return out;
|
|
25282
25536
|
} finally {
|
|
25283
|
-
|
|
25537
|
+
closeSync8(fd);
|
|
25284
25538
|
}
|
|
25285
25539
|
} catch {
|
|
25286
25540
|
return;
|
|
@@ -25326,19 +25580,19 @@ class ConvFiles {
|
|
|
25326
25580
|
const tag = seal.tag();
|
|
25327
25581
|
writeAt(fd, tag, written);
|
|
25328
25582
|
fsyncSync3(fd);
|
|
25329
|
-
|
|
25583
|
+
closeSync8(fd);
|
|
25330
25584
|
fd = undefined;
|
|
25331
|
-
|
|
25585
|
+
closeSync8(source);
|
|
25332
25586
|
source = undefined;
|
|
25333
|
-
|
|
25587
|
+
renameSync9(tmp, join11(this.#dir, blob));
|
|
25334
25588
|
this.#store.blobSetSealed(row.id);
|
|
25335
25589
|
this.#unlink(part);
|
|
25336
25590
|
return { upload: row.id, received: row.bytes, done: true };
|
|
25337
25591
|
} catch (error) {
|
|
25338
25592
|
if (fd !== undefined)
|
|
25339
|
-
|
|
25593
|
+
closeSync8(fd);
|
|
25340
25594
|
if (source !== undefined)
|
|
25341
|
-
|
|
25595
|
+
closeSync8(source);
|
|
25342
25596
|
this.#unlink(tmp);
|
|
25343
25597
|
this.#remove({ ...row, blob });
|
|
25344
25598
|
if (error instanceof MessagingError)
|
|
@@ -25358,7 +25612,7 @@ class ConvFiles {
|
|
|
25358
25612
|
hash.update(buffer.subarray(0, read));
|
|
25359
25613
|
}
|
|
25360
25614
|
} finally {
|
|
25361
|
-
|
|
25615
|
+
closeSync8(fd);
|
|
25362
25616
|
}
|
|
25363
25617
|
return hash.digest("base64url");
|
|
25364
25618
|
}
|
|
@@ -25373,7 +25627,7 @@ class ConvFiles {
|
|
|
25373
25627
|
#recover(row) {
|
|
25374
25628
|
if (row.blob !== undefined) {
|
|
25375
25629
|
try {
|
|
25376
|
-
if (
|
|
25630
|
+
if (lstatSync10(join11(this.#dir, row.blob)).size === row.bytes + BLOB_SEALED_OVERHEAD) {
|
|
25377
25631
|
this.#store.blobSetSealed(row.id);
|
|
25378
25632
|
this.#unlink(this.#partPath(row.id));
|
|
25379
25633
|
this.#log("warn", "conversation.files.recovered", { id: row.id });
|
|
@@ -25434,141 +25688,7 @@ var init_conv_files = __esm(() => {
|
|
|
25434
25688
|
init_dist();
|
|
25435
25689
|
OPENED_BYTES_MAX = 32 * 1024 * 1024;
|
|
25436
25690
|
FETCH_BACKOFF_MAX_MS = 15 * 60000;
|
|
25437
|
-
CREATE =
|
|
25438
|
-
});
|
|
25439
|
-
|
|
25440
|
-
// packages/daemon/dist/log.js
|
|
25441
|
-
import { closeSync as closeSync8, constants as constants6, lstatSync as lstatSync10, renameSync as renameSync9, writeSync as writeSync5 } from "fs";
|
|
25442
|
-
function redactConversations(value) {
|
|
25443
|
-
if (typeof value === "string")
|
|
25444
|
-
return value.replace(CONVERSATION_ID, CONVERSATION_MARK);
|
|
25445
|
-
if (Array.isArray(value))
|
|
25446
|
-
return value.map(redactConversations);
|
|
25447
|
-
if (value !== null && typeof value === "object") {
|
|
25448
|
-
const out = {};
|
|
25449
|
-
for (const [name, inner] of Object.entries(value))
|
|
25450
|
-
out[name] = redactConversations(inner);
|
|
25451
|
-
return out;
|
|
25452
|
-
}
|
|
25453
|
-
return value;
|
|
25454
|
-
}
|
|
25455
|
-
function formatLine(level, event, fields = {}) {
|
|
25456
|
-
const record = { t: new Date().toISOString(), level, event };
|
|
25457
|
-
const kept = CATALOGUE_EVENTS.has(event) ? fields : redactConversations(fields);
|
|
25458
|
-
for (const [name, value] of Object.entries(kept))
|
|
25459
|
-
if (value !== undefined)
|
|
25460
|
-
record[Object.hasOwn(record, name) ? `${name}_` : name] = value;
|
|
25461
|
-
return `${JSON.stringify(record)}
|
|
25462
|
-
`;
|
|
25463
|
-
}
|
|
25464
|
-
function safeLine(level, event, fields) {
|
|
25465
|
-
try {
|
|
25466
|
-
return formatLine(level, event, fields);
|
|
25467
|
-
} catch (error) {
|
|
25468
|
-
return formatLine(level, event, { error: error instanceof Error ? error.name : typeof error });
|
|
25469
|
-
}
|
|
25470
|
-
}
|
|
25471
|
-
function logFailure(logger) {
|
|
25472
|
-
return failures.get(logger)?.();
|
|
25473
|
-
}
|
|
25474
|
-
function createLogger(options) {
|
|
25475
|
-
const min = RANK[options.level ?? "info"];
|
|
25476
|
-
const maxBytes = options.maxBytes ?? LOG_MAX_BYTES;
|
|
25477
|
-
const keep = options.keep ?? LOG_KEEP;
|
|
25478
|
-
const now = options.now ?? Date.now;
|
|
25479
|
-
let size;
|
|
25480
|
-
let failure;
|
|
25481
|
-
const logger = (level, event, fields) => {
|
|
25482
|
-
if (RANK[level] < min)
|
|
25483
|
-
return;
|
|
25484
|
-
const line = safeLine(level, event, fields);
|
|
25485
|
-
const file = options.file;
|
|
25486
|
-
if (file) {
|
|
25487
|
-
try {
|
|
25488
|
-
const bytes = Buffer.byteLength(line);
|
|
25489
|
-
size ??= currentSize(file);
|
|
25490
|
-
if (size > 0 && size + bytes > maxBytes) {
|
|
25491
|
-
rotate2(file, keep);
|
|
25492
|
-
size = 0;
|
|
25493
|
-
}
|
|
25494
|
-
const fd = openNoFollow(file, constants6.O_WRONLY | constants6.O_APPEND | constants6.O_CREAT, 384);
|
|
25495
|
-
try {
|
|
25496
|
-
writeSync5(fd, line);
|
|
25497
|
-
} finally {
|
|
25498
|
-
closeSync8(fd);
|
|
25499
|
-
}
|
|
25500
|
-
size += bytes;
|
|
25501
|
-
failure = undefined;
|
|
25502
|
-
} catch (error) {
|
|
25503
|
-
size = undefined;
|
|
25504
|
-
failure ??= { since: now(), code: String(error.code ?? "error").slice(0, 32) };
|
|
25505
|
-
}
|
|
25506
|
-
}
|
|
25507
|
-
if (options.stderr)
|
|
25508
|
-
process.stderr.write(line);
|
|
25509
|
-
};
|
|
25510
|
-
failures.set(logger, () => failure);
|
|
25511
|
-
return logger;
|
|
25512
|
-
}
|
|
25513
|
-
function currentSize(file) {
|
|
25514
|
-
try {
|
|
25515
|
-
return lstatSync10(file).size;
|
|
25516
|
-
} catch {
|
|
25517
|
-
return 0;
|
|
25518
|
-
}
|
|
25519
|
-
}
|
|
25520
|
-
function rotate2(file, keep) {
|
|
25521
|
-
for (let n = keep - 1;n >= 1; n--) {
|
|
25522
|
-
try {
|
|
25523
|
-
renameSync9(`${file}.${n}`, `${file}.${n + 1}`);
|
|
25524
|
-
} catch {}
|
|
25525
|
-
}
|
|
25526
|
-
renameSync9(file, `${file}.1`);
|
|
25527
|
-
}
|
|
25528
|
-
|
|
25529
|
-
class LogBudget {
|
|
25530
|
-
max;
|
|
25531
|
-
windowMs;
|
|
25532
|
-
#window = [];
|
|
25533
|
-
#suppressed = 0;
|
|
25534
|
-
constructor(max = 30, windowMs = 60000) {
|
|
25535
|
-
this.max = max;
|
|
25536
|
-
this.windowMs = windowMs;
|
|
25537
|
-
}
|
|
25538
|
-
take(now) {
|
|
25539
|
-
this.#window = this.#window.filter((at) => at > now - this.windowMs);
|
|
25540
|
-
if (this.#window.length >= this.max) {
|
|
25541
|
-
this.#suppressed++;
|
|
25542
|
-
return { ok: false, suppressed: 0 };
|
|
25543
|
-
}
|
|
25544
|
-
this.#window.push(now);
|
|
25545
|
-
const suppressed = this.#suppressed;
|
|
25546
|
-
this.#suppressed = 0;
|
|
25547
|
-
return { ok: true, suppressed };
|
|
25548
|
-
}
|
|
25549
|
-
drain() {
|
|
25550
|
-
const n = this.#suppressed;
|
|
25551
|
-
this.#suppressed = 0;
|
|
25552
|
-
return n;
|
|
25553
|
-
}
|
|
25554
|
-
}
|
|
25555
|
-
function codeOf(error) {
|
|
25556
|
-
const code = error?.code;
|
|
25557
|
-
return typeof code === "string" && /^[a-z_]{1,40}$/.test(code) ? code : "internal";
|
|
25558
|
-
}
|
|
25559
|
-
var RANK, LOG_MAX_BYTES, LOG_KEEP = 3, CONVERSATION_ID, CONVERSATION_MARK = "[conversation]", CATALOGUE_EVENTS, failures;
|
|
25560
|
-
var init_log2 = __esm(() => {
|
|
25561
|
-
init_dist2();
|
|
25562
|
-
RANK = { debug: 0, info: 1, warn: 2, error: 3 };
|
|
25563
|
-
LOG_MAX_BYTES = 10 * 1024 * 1024;
|
|
25564
|
-
CONVERSATION_ID = /[ds]_[a-z2-7]{26}|c_[0-7][0-9A-HJKMNP-TV-Z]{25}/g;
|
|
25565
|
-
CATALOGUE_EVENTS = new Set([
|
|
25566
|
-
"conv.catalogue.card.rejected",
|
|
25567
|
-
"conv.catalogue.card.unbound",
|
|
25568
|
-
"conv.catalogue.withdrawn",
|
|
25569
|
-
"conv.catalogue.published"
|
|
25570
|
-
]);
|
|
25571
|
-
failures = new WeakMap;
|
|
25691
|
+
CREATE = constants6.O_WRONLY | constants6.O_CREAT | constants6.O_EXCL | (constants6.O_NOFOLLOW ?? 0);
|
|
25572
25692
|
});
|
|
25573
25693
|
|
|
25574
25694
|
// packages/daemon/dist/relay-refusals.js
|
|
@@ -39867,6 +39987,40 @@ class ListingCache {
|
|
|
39867
39987
|
this.#entries.clear();
|
|
39868
39988
|
}
|
|
39869
39989
|
}
|
|
39990
|
+
|
|
39991
|
+
class PlacedCache {
|
|
39992
|
+
#entries = new Map;
|
|
39993
|
+
#capacity;
|
|
39994
|
+
constructor(capacity = LIMITS.listingCache) {
|
|
39995
|
+
this.#capacity = Math.max(0, capacity);
|
|
39996
|
+
}
|
|
39997
|
+
get(person, size) {
|
|
39998
|
+
const held = this.#entries.get(person);
|
|
39999
|
+
if (!held || held.size !== size)
|
|
40000
|
+
return;
|
|
40001
|
+
this.#entries.delete(person);
|
|
40002
|
+
this.#entries.set(person, held);
|
|
40003
|
+
return held.devices;
|
|
40004
|
+
}
|
|
40005
|
+
set(person, size, devices) {
|
|
40006
|
+
if (this.#capacity === 0)
|
|
40007
|
+
return;
|
|
40008
|
+
this.#entries.delete(person);
|
|
40009
|
+
this.#entries.set(person, { size, devices });
|
|
40010
|
+
while (this.#entries.size > this.#capacity) {
|
|
40011
|
+
const oldest = this.#entries.keys().next().value;
|
|
40012
|
+
if (oldest === undefined)
|
|
40013
|
+
break;
|
|
40014
|
+
this.#entries.delete(oldest);
|
|
40015
|
+
}
|
|
40016
|
+
}
|
|
40017
|
+
get size() {
|
|
40018
|
+
return this.#entries.size;
|
|
40019
|
+
}
|
|
40020
|
+
clear() {
|
|
40021
|
+
this.#entries.clear();
|
|
40022
|
+
}
|
|
40023
|
+
}
|
|
39870
40024
|
var init_listing_cache = __esm(() => {
|
|
39871
40025
|
init_dist();
|
|
39872
40026
|
});
|
|
@@ -39885,6 +40039,7 @@ class DirectoryIdentity {
|
|
|
39885
40039
|
#head;
|
|
39886
40040
|
#persons = new Map;
|
|
39887
40041
|
#listed = new ListingCache;
|
|
40042
|
+
#placed = new PlacedCache;
|
|
39888
40043
|
#archiveForm;
|
|
39889
40044
|
#index = new Map;
|
|
39890
40045
|
#own;
|
|
@@ -40141,6 +40296,53 @@ class DirectoryIdentity {
|
|
|
40141
40296
|
this.#saveArchive();
|
|
40142
40297
|
return { people, more: answer.more, ...answer.more && answer.cursor !== undefined ? { cursor: answer.cursor } : {} };
|
|
40143
40298
|
}
|
|
40299
|
+
async placeDevices(pairs) {
|
|
40300
|
+
const asked = [...new Set(pairs.map((pair) => pair.person))].filter(isHosted);
|
|
40301
|
+
if (asked.length === 0)
|
|
40302
|
+
return new Map;
|
|
40303
|
+
if (asked.length > LIMITS.dirLookupPersons)
|
|
40304
|
+
throw new MessagingError("invalid_request", `one lookup places at most ${LIMITS.dirLookupPersons} persons`);
|
|
40305
|
+
if (!this.#head || this.#headOlderThan(LIMITS.dirFreshMs))
|
|
40306
|
+
await this.#latest();
|
|
40307
|
+
let head = this.#head;
|
|
40308
|
+
const need = asked.filter((person) => !this.#persons.has(person) && this.#placed.get(person, head.sth.size) === undefined);
|
|
40309
|
+
if (need.length > 0) {
|
|
40310
|
+
const ask = need.map((person) => ({ person }));
|
|
40311
|
+
let answer;
|
|
40312
|
+
try {
|
|
40313
|
+
answer = await this.#call((link) => link.lookup(ask, head.sth.size));
|
|
40314
|
+
} catch (error) {
|
|
40315
|
+
if (!(error instanceof MessagingError) || error.code !== "invalid_request")
|
|
40316
|
+
throw error;
|
|
40317
|
+
await this.#latest();
|
|
40318
|
+
head = this.#head;
|
|
40319
|
+
answer = await this.#call((link) => link.lookup(ask, head.sth.size));
|
|
40320
|
+
}
|
|
40321
|
+
if (answer.sth.size !== head.sth.size || answer.sth.root !== head.sth.root)
|
|
40322
|
+
throw new MessagingError("directory_inconsistent", "the directory answered at another tree head");
|
|
40323
|
+
for (const view of answer.persons) {
|
|
40324
|
+
if (!need.includes(view.person))
|
|
40325
|
+
continue;
|
|
40326
|
+
const state = await this.#verify(view, head, undefined);
|
|
40327
|
+
const devices = new Map;
|
|
40328
|
+
if (!state.erased) {
|
|
40329
|
+
for (const record of state.log.devices()) {
|
|
40330
|
+
if (record.current && state.keys.has(record.device))
|
|
40331
|
+
devices.set(record.device, view.person);
|
|
40332
|
+
}
|
|
40333
|
+
}
|
|
40334
|
+
this.#placed.set(view.person, head.sth.size, devices);
|
|
40335
|
+
}
|
|
40336
|
+
}
|
|
40337
|
+
const at = this.#head.sth.size;
|
|
40338
|
+
const placed = new Map;
|
|
40339
|
+
for (const { person, device } of pairs) {
|
|
40340
|
+
const owner = this.device(device)?.person ?? (isHosted(person) ? this.#placed.get(person, at)?.get(device) : undefined);
|
|
40341
|
+
if (owner === person)
|
|
40342
|
+
placed.set(device, person);
|
|
40343
|
+
}
|
|
40344
|
+
return placed;
|
|
40345
|
+
}
|
|
40144
40346
|
#atAdopted(sth) {
|
|
40145
40347
|
return this.#head !== undefined && this.#head.sth.size === sth.size && this.#head.sth.root === sth.root;
|
|
40146
40348
|
}
|
|
@@ -40739,6 +40941,7 @@ class DirectoryIdentity {
|
|
|
40739
40941
|
if (this.#alarm)
|
|
40740
40942
|
return;
|
|
40741
40943
|
this.#listed.clear();
|
|
40944
|
+
this.#placed.clear();
|
|
40742
40945
|
this.#alarm = alarm;
|
|
40743
40946
|
this.#cache.setAlarm(alarm);
|
|
40744
40947
|
for (const listener of [...this.#listeners.alarm])
|
|
@@ -43339,6 +43542,7 @@ class Daemon {
|
|
|
43339
43542
|
get: (key) => store.getKv(key),
|
|
43340
43543
|
put: (key, value) => store.setKv(key, value),
|
|
43341
43544
|
fresh: (people) => this.#outbox.withFresh(people, () => {}),
|
|
43545
|
+
placeDevices: (pairs) => this.#ctx.realm?.placeDevices?.(pairs) ?? Promise.resolve(new Map),
|
|
43342
43546
|
relayFeatures: () => this.#ctx.relayFeatures,
|
|
43343
43547
|
org: () => this.#ctx.realm?.org(),
|
|
43344
43548
|
refuseSecrets: (value) => this.#ctx.refuseSecrets(value, "conv.send", "conversation line"),
|
|
@@ -44414,56 +44618,59 @@ class RelayClient {
|
|
|
44414
44618
|
get requestMailbox() {
|
|
44415
44619
|
return this;
|
|
44416
44620
|
}
|
|
44417
|
-
|
|
44418
|
-
|
|
44419
|
-
|
|
44420
|
-
|
|
44421
|
-
|
|
44621
|
+
requestSettle(proof) {
|
|
44622
|
+
return observed(this.#conversation("request.settled", { t: "request.settle", ...proof }, RequestSettledFrame).then((reply) => {
|
|
44623
|
+
if (reply.id !== proof.descriptor.id || !reply.decision)
|
|
44624
|
+
throw new MessagingError("invalid_request", "request settlement does not name this request");
|
|
44625
|
+
return reply.decision;
|
|
44626
|
+
}));
|
|
44422
44627
|
}
|
|
44423
|
-
|
|
44424
|
-
|
|
44425
|
-
|
|
44426
|
-
|
|
44427
|
-
|
|
44628
|
+
requestState(descriptor) {
|
|
44629
|
+
return observed(this.#conversation("request.settled", { t: "request.state", descriptor }, RequestSettledFrame).then((reply) => {
|
|
44630
|
+
if (reply.id !== descriptor.id)
|
|
44631
|
+
throw new MessagingError("invalid_request", "request state does not name this request");
|
|
44632
|
+
return reply.decision;
|
|
44633
|
+
}));
|
|
44428
44634
|
}
|
|
44429
|
-
|
|
44635
|
+
convAppend(event) {
|
|
44430
44636
|
return this.#conversation("conv.ok", { t: "conv.append", event }, ConvOkFrame);
|
|
44431
44637
|
}
|
|
44432
|
-
|
|
44638
|
+
convShare(events) {
|
|
44433
44639
|
return this.#conversation("conv.shared", { t: "conv.share", events }, ConvSharedFrame);
|
|
44434
44640
|
}
|
|
44435
|
-
|
|
44641
|
+
convFetch(cid, after, options = {}) {
|
|
44436
44642
|
return this.#conversation("conv.entries", { t: "conv.fetch", cid, after, ...options }, ConvEntriesFrame);
|
|
44437
44643
|
}
|
|
44438
|
-
|
|
44644
|
+
convHead(options = {}) {
|
|
44439
44645
|
return this.#conversation("conv.heads", { t: "conv.head", ...options }, ConvHeadsFrame);
|
|
44440
44646
|
}
|
|
44441
|
-
|
|
44647
|
+
convFeatures(ask) {
|
|
44442
44648
|
return this.#conversation("conv.readers", { t: "conv.features", ...ask }, ConvReadersFrame);
|
|
44443
44649
|
}
|
|
44444
|
-
|
|
44650
|
+
putBlob(frame) {
|
|
44445
44651
|
return this.#conversation("conv.blob.ok", { t: "conv.blob.put", ...frame }, ConvBlobOkFrame);
|
|
44446
44652
|
}
|
|
44447
|
-
|
|
44653
|
+
getBlob(frame) {
|
|
44448
44654
|
return this.#conversation("conv.blob.chunk", { t: "conv.blob.get", ...frame }, ConvBlobChunkFrame);
|
|
44449
44655
|
}
|
|
44450
|
-
|
|
44656
|
+
dropBlob(frame) {
|
|
44451
44657
|
return this.#conversation("conv.blob.ok", { t: "conv.blob.drop", ...frame }, ConvBlobOkFrame);
|
|
44452
44658
|
}
|
|
44453
|
-
|
|
44659
|
+
convCaps(persons, options = {}) {
|
|
44454
44660
|
return this.#conversation("conv.capabilities", { t: "conv.caps", persons, ...options.attest ? { attest: true } : {} }, ConvCapabilitiesFrame);
|
|
44455
44661
|
}
|
|
44456
|
-
|
|
44662
|
+
convCatalogue(options = {}) {
|
|
44457
44663
|
return this.#conversation("conv.channels", { t: "conv.catalogue", ...options }, ConvChannelsFrame);
|
|
44458
44664
|
}
|
|
44459
|
-
|
|
44665
|
+
convPublish(body) {
|
|
44460
44666
|
return this.#conversation("conv.card", { t: "conv.publish", ...body }, ConvCardFrame);
|
|
44461
44667
|
}
|
|
44462
|
-
|
|
44463
|
-
|
|
44464
|
-
|
|
44465
|
-
|
|
44466
|
-
|
|
44668
|
+
#conversation(expect, frame, schema) {
|
|
44669
|
+
return observed(this.#call(expect, frame).then((raw) => {
|
|
44670
|
+
if (!schema.safeParse(raw).success)
|
|
44671
|
+
throw new MessagingError("invalid_request", "malformed conversation reply");
|
|
44672
|
+
return raw;
|
|
44673
|
+
}));
|
|
44467
44674
|
}
|
|
44468
44675
|
send(env) {
|
|
44469
44676
|
const id = env?.id;
|
|
@@ -44481,7 +44688,7 @@ class RelayClient {
|
|
|
44481
44688
|
const pending = deferred();
|
|
44482
44689
|
this.#sends.set(id, pending);
|
|
44483
44690
|
ws.send(text);
|
|
44484
|
-
return pending.promise;
|
|
44691
|
+
return observed(pending.promise);
|
|
44485
44692
|
}
|
|
44486
44693
|
presence(env) {
|
|
44487
44694
|
const ws = this.#socket();
|
|
@@ -44494,7 +44701,8 @@ class RelayClient {
|
|
|
44494
44701
|
}
|
|
44495
44702
|
syncRoster(after) {
|
|
44496
44703
|
const pages = Math.min(MAX_PAGES, Math.max(1, Math.ceil((this.#head - after) / LIMITS.rosterPageEntries)));
|
|
44497
|
-
|
|
44704
|
+
const walk = collectPages(after, pages, (from) => this.#request("roster", { t: "roster.sync", after: from }));
|
|
44705
|
+
return observed(walk);
|
|
44498
44706
|
}
|
|
44499
44707
|
dirAppend(entry) {
|
|
44500
44708
|
return this.#dir("dir.ok", { t: "dir.append", entry });
|
|
@@ -44537,17 +44745,17 @@ class RelayClient {
|
|
|
44537
44745
|
}
|
|
44538
44746
|
#dir(expect, frame) {
|
|
44539
44747
|
if (!this.#options.hosted)
|
|
44540
|
-
return Promise.reject(new MessagingError("invalid_request", "this relay link is not to a directory relay"));
|
|
44748
|
+
return observed(Promise.reject(new MessagingError("invalid_request", "this relay link is not to a directory relay")));
|
|
44541
44749
|
return this.#call(expect, frame);
|
|
44542
44750
|
}
|
|
44543
44751
|
#call(expect, frame) {
|
|
44544
44752
|
const ws = this.#socket();
|
|
44545
44753
|
if (!ws)
|
|
44546
|
-
return Promise.reject(unavailable2("not connected to the relay"));
|
|
44754
|
+
return observed(Promise.reject(unavailable2("not connected to the relay")));
|
|
44547
44755
|
const req = `r${++this.#req}`;
|
|
44548
44756
|
const text = frameText({ ...frame, req });
|
|
44549
44757
|
if (text instanceof MessagingError)
|
|
44550
|
-
return Promise.reject(text);
|
|
44758
|
+
return observed(Promise.reject(text));
|
|
44551
44759
|
const timer = setTimeout(() => {
|
|
44552
44760
|
const request = this.#dirRequests.get(req);
|
|
44553
44761
|
this.#dirRequests.delete(req);
|
|
@@ -44557,7 +44765,7 @@ class RelayClient {
|
|
|
44557
44765
|
const pending = deferred();
|
|
44558
44766
|
this.#dirRequests.set(req, { expect, pending, timer });
|
|
44559
44767
|
ws.send(text);
|
|
44560
|
-
return pending.promise;
|
|
44768
|
+
return observed(pending.promise);
|
|
44561
44769
|
}
|
|
44562
44770
|
#onDirectoryFrame(ws, raw) {
|
|
44563
44771
|
const parsed = DirectoryRelayFrame.safeParse(raw);
|
|
@@ -44838,17 +45046,17 @@ ${id}`;
|
|
|
44838
45046
|
#request(expect, frame) {
|
|
44839
45047
|
const ws = this.#socket();
|
|
44840
45048
|
if (!ws)
|
|
44841
|
-
return Promise.reject(unavailable2("not connected to the relay"));
|
|
45049
|
+
return observed(Promise.reject(unavailable2("not connected to the relay")));
|
|
44842
45050
|
const req = `r${++this.#req}`;
|
|
44843
45051
|
const text = frameText({ ...frame, req });
|
|
44844
45052
|
if (text instanceof MessagingError)
|
|
44845
|
-
return Promise.reject(text);
|
|
45053
|
+
return observed(Promise.reject(text));
|
|
44846
45054
|
const timer = setTimeout(() => this.#take(req)?.pending.reject(unavailable2("relay did not answer in time")), REQUEST_MS);
|
|
44847
45055
|
timer.unref();
|
|
44848
45056
|
const request = expect === "roster" ? { expect, pending: deferred(), timer } : { expect, pending: deferred(), timer };
|
|
44849
45057
|
this.#requests.set(req, request);
|
|
44850
45058
|
ws.send(text);
|
|
44851
|
-
return request.pending.promise;
|
|
45059
|
+
return observed(request.pending.promise);
|
|
44852
45060
|
}
|
|
44853
45061
|
#socket() {
|
|
44854
45062
|
return this.#connected && this.#ws?.readyState === WebSocket.OPEN ? this.#ws : undefined;
|
|
@@ -45124,6 +45332,10 @@ function frameText(frame, limit = LIMITS.frameBytes) {
|
|
|
45124
45332
|
function unavailable2(message) {
|
|
45125
45333
|
return new MessagingError("relay_unavailable", message);
|
|
45126
45334
|
}
|
|
45335
|
+
function observed(promise) {
|
|
45336
|
+
promise.catch(() => {});
|
|
45337
|
+
return promise;
|
|
45338
|
+
}
|
|
45127
45339
|
function deferred() {
|
|
45128
45340
|
let resolve;
|
|
45129
45341
|
let reject;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@joe-broadhead/messaging-bin-darwin-x64",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.7",
|
|
4
4
|
"description": "The self-contained messagingd executable for one platform: the Messaging daemon and its CLI (`messagingd cli …`, or invoked as `messaging`), with no Node.js, npm install or install script on the machine",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Joe Broadhead",
|