sigelo-contact 0.1.11 → 0.1.13
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/carrier.mjs +18 -4
- package/package.json +2 -2
- package/test-carrier.mjs +26 -0
package/carrier.mjs
CHANGED
|
@@ -759,6 +759,13 @@ async function named(platform, ep, creds, err) {
|
|
|
759
759
|
const check = LOGIN_CHECKS.has(r.body.check) ? r.body.check : 'connect';
|
|
760
760
|
return new MsgError(check, `the relay refused the login (${relaySays(`${r.body.check}: ${r.body.detail}`)})${LOGIN_NEXT[check] ? `: ${LOGIN_NEXT[check]}` : ''}`, { cause: err, http: r.http });
|
|
761
761
|
}
|
|
762
|
+
// The relay took this very login (its outcome, kept under these credentials): its answer did not
|
|
763
|
+
// reach this client. A proof of work in it is the relay's now (#dial: proven, no search again).
|
|
764
|
+
if (r.body?.ok === true) {
|
|
765
|
+
const e = new MsgError('connect', `the relay at ${ep.mqtt} took the login, but its answer did not reach this client (${err.message}): try again; if it repeats, the network between drops it`, { cause: err, http: r.http });
|
|
766
|
+
e.accepted = true;
|
|
767
|
+
return e;
|
|
768
|
+
}
|
|
762
769
|
} catch {}
|
|
763
770
|
return err instanceof MsgError ? err : new MsgError('connect', `the relay at ${ep.mqtt} did not take the connection (${err.message}): check the network and SIGELO_RELAY / SIGELO_RELAY_ENDPOINTS, then try again`, { cause: err });
|
|
764
771
|
}
|
|
@@ -2130,7 +2137,7 @@ export class Carrier {
|
|
|
2130
2137
|
const at = (st.relays[relay] ??= { proven: false, claims: {} }), recent = (at.searches ?? []).filter((t) => t > now - DAY);
|
|
2131
2138
|
if (recent.length >= POW_SEARCHES) {
|
|
2132
2139
|
// Permanent like the bits above: no backoff loop; the hourly round asks again (#retry).
|
|
2133
|
-
const e = new MsgError('pow', `${recent.length} proof-of-work searches at ${relay} within 24 hours, the most this client spends: the next may begin after ${new Date((recent[0] + DAY) * 1000).toISOString()}`);
|
|
2140
|
+
const e = new MsgError('pow', `${recent.length} proof-of-work searches at ${relay} within 24 hours, the most this client spends: the next may begin after ${new Date((recent[0] + DAY) * 1000).toISOString()}; nothing is lost meanwhile, this client tries again then by itself (a search is spent once per identity, and again only when a login with it got no answer)`);
|
|
2134
2141
|
e.permanent = true;
|
|
2135
2142
|
throw e;
|
|
2136
2143
|
}
|
|
@@ -2193,11 +2200,18 @@ export class Carrier {
|
|
|
2193
2200
|
const onPacket = (packet) => this.#onPacket(link, packet);
|
|
2194
2201
|
const probe = this.transport === 'auto' && !FELL_BACK.has(ep.mqtt) && /^mqtts?:/.test(ep.mqtt);
|
|
2195
2202
|
let url = this.transport === 'wss' ? await wsEndpoint(this.platform, ep) : this.transport === 'auto' ? FELL_BACK.get(ep.mqtt) ?? ep.mqtt : ep.mqtt;
|
|
2196
|
-
// A cut connection is this client's own refusal: no POST /check may rename it.
|
|
2203
|
+
// A cut connection is this client's own refusal: no POST /check may rename it. A login the relay
|
|
2204
|
+
// took (POST /check: ok) whose answer was lost proved its work there: proven, so the next login
|
|
2205
|
+
// spends no search (POW_SEARCHES) on an identity the relay holds.
|
|
2206
|
+
const why = async (e) => {
|
|
2207
|
+
const n = await named(this.platform, ep, creds, e);
|
|
2208
|
+
if (n.accepted && creds.pow !== undefined) this.#locked(({ st }) => { (st.relays[relay] ??= { proven: false, claims: {} }).proven = true; });
|
|
2209
|
+
return n;
|
|
2210
|
+
};
|
|
2197
2211
|
try { await mqttConnect(this.platform, url, creds, link, onPacket, probe ? PROBE_MS : CONNECT_MS); } catch (e) {
|
|
2198
|
-
if (!probe || link.cut || typeof e.code === 'number') throw link.cut ?? await
|
|
2212
|
+
if (!probe || link.cut || typeof e.code === 'number') throw link.cut ?? await why(e);
|
|
2199
2213
|
url = await wsEndpoint(this.platform, ep);
|
|
2200
|
-
try { await mqttConnect(this.platform, url, creds, link, onPacket); } catch (e2) { throw link.cut ?? await
|
|
2214
|
+
try { await mqttConnect(this.platform, url, creds, link, onPacket); } catch (e2) { throw link.cut ?? await why(e2); }
|
|
2201
2215
|
FELL_BACK.set(ep.mqtt, url);
|
|
2202
2216
|
this.#emit({ type: 'transport', relay, transport: 'wss', detail: `${ep.mqtt} gave no CONNACK within ${PROBE_MS / 1000} s (${e.message}): MQTT over WebSocket at ${url} for the rest of this process` });
|
|
2203
2217
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sigelo-contact",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.13",
|
|
4
4
|
"private": false,
|
|
5
5
|
"description": "Agent contacts for sigelo identities: invite codes, a contact store, end-to-end encrypted envelopes with hybrid post-quantum key agreement, and an MQTT carrier. Client code (MIT); the relay server is csigelo/sigelo-relay (AGPL-3.0).",
|
|
6
6
|
"keywords": [
|
|
@@ -129,6 +129,6 @@
|
|
|
129
129
|
"@noble/hashes": "^2.4.0",
|
|
130
130
|
"@noble/post-quantum": "^0.7.1",
|
|
131
131
|
"mqtt": "^5.16.0",
|
|
132
|
-
"sigelo": "^0.1.
|
|
132
|
+
"sigelo": "^0.1.13"
|
|
133
133
|
}
|
|
134
134
|
}
|
package/test-carrier.mjs
CHANGED
|
@@ -542,6 +542,32 @@ try {
|
|
|
542
542
|
http.close();
|
|
543
543
|
}
|
|
544
544
|
|
|
545
|
+
// ================================================================ a login the relay took, its answer lost: no second proof of work
|
|
546
|
+
{
|
|
547
|
+
// mute.test takes every CONNECT, and the connection ends with no CONNACK read (a client that never
|
|
548
|
+
// acted on it reads the same); POST /check says the login was good. The proof in it is the relay's:
|
|
549
|
+
// the next login carries none, and no search of the day's three is spent on an identity it holds.
|
|
550
|
+
const proofs = [];
|
|
551
|
+
const mute = await fakeBroker((type, body, sock) => { if (type === 1) { proofs.push(body.includes('"pow":')); setTimeout(() => sock.destroy(), 50); } });
|
|
552
|
+
const http = createServer((req, res) => {
|
|
553
|
+
const url = new URL(req.url, 'http://x'), [, , what] = url.pathname.split('/');
|
|
554
|
+
res.writeHead(what === 'challenge' || what === 'check' ? 200 : 404, { 'content-type': 'application/json' });
|
|
555
|
+
if (what === 'check') { req.resume(); req.on('end', () => res.end('{"ok":true}')); return; }
|
|
556
|
+
if (what !== 'challenge') { res.end(); return; }
|
|
557
|
+
res.end(JSON.stringify({ challenge: { v: 'sigelo-relay/0', typ: 'relay-login', did: url.searchParams.get('did'), relay: 'mute.test', nonce: randomBytes(32).toString('base64url') }, pow_bits: 4 }));
|
|
558
|
+
});
|
|
559
|
+
await new Promise((r) => http.listen(0, '127.0.0.1', r));
|
|
560
|
+
const M = agent('mia'), mia = make(M, { relay: 'mute.test', transport: 'mqtts', endpoints: { 'mute.test': { mqtt: `mqtt://127.0.0.1:${mute.port}`, http: `http://127.0.0.1:${http.address().port}/mute.test` } } });
|
|
561
|
+
const r1 = await mia.inbox();
|
|
562
|
+
ok(r1.offline && /took the login, but its answer did not reach this client/.test(r1.offline) && stateOf(M).relays['mute.test']?.proven === true,
|
|
563
|
+
`no CONNACK, POST /check ok: said so, and the proof counted as the relay's (${r1.offline})`);
|
|
564
|
+
await mia.inbox();
|
|
565
|
+
ok(proofs.length === 2 && proofs[0] === true && proofs[1] === false && (stateOf(M).relays['mute.test'].searches ?? []).length === 1,
|
|
566
|
+
`the next login carries no proof of work: one search in all (${JSON.stringify(proofs)})`);
|
|
567
|
+
mute.close();
|
|
568
|
+
http.close();
|
|
569
|
+
}
|
|
570
|
+
|
|
545
571
|
// ================================================================ a 502 refuses nothing; a delivered answer outlives a refusal for good
|
|
546
572
|
{
|
|
547
573
|
// otto's own relay is home.test, so HOST is a stranger's relay to him. A proxy before HOST's
|