sigelo-contact 0.1.14 → 0.1.21
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 +13 -10
- package/call.mjs +831 -0
- package/carrier.mjs +1013 -112
- package/control.mjs +81 -22
- package/device.mjs +1 -1
- package/enrol.mjs +214 -35
- package/gen-carrier.mjs +4 -4
- package/gen-device.mjs +2 -2
- package/gen-envelope.mjs +3 -3
- package/gen-invite.mjs +3 -3
- package/gen-short.mjs +3 -3
- package/group.mjs +28 -9
- package/invite.mjs +63 -13
- package/kdf.mjs +1 -1
- package/link.mjs +1 -1
- package/package.json +34 -7
- package/page.mjs +1018 -81
- package/photo.mjs +37 -0
- package/platform-node.mjs +110 -13
- package/prekeys.mjs +10 -2
- package/public.mjs +93 -0
- package/relays.mjs +1 -1
- package/restore.mjs +3 -3
- package/rtc-web.mjs +109 -0
- package/short.mjs +19 -3
- package/store.mjs +126 -10
- package/test-carrier.mjs +121 -18
- package/test-device.mjs +1 -1
- package/test-enrol.mjs +123 -8
- package/test-envelope.mjs +16 -3
- package/test-file.mjs +5 -5
- package/test-group.mjs +48 -7
- package/test-invite.mjs +15 -2
- package/test-link.mjs +6 -6
- package/test-platform.mjs +5 -5
- package/test-presence.mjs +5 -5
- package/test-push.mjs +136 -0
- package/test-relay-lane.mjs +323 -0
- package/test-short.mjs +35 -12
- package/test-tier.mjs +6 -6
- package/test-transfer-web.mjs +313 -0
- package/test-transfer.mjs +51 -11
- package/test-voice.mjs +161 -0
- package/test-ws.mjs +5 -5
- package/transfer-engine.mjs +858 -0
- package/transfer-node.mjs +254 -641
- package/transfer-web.mjs +80 -0
- package/transfer.mjs +25 -6
- package/voice-web.mjs +113 -0
- package/voice.mjs +70 -0
- package/words-lock.mjs +25 -10
package/test-tier.mjs
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
// Contact tiers (store.mjs "Tiers", carrier.mjs "Operator hints"): the store part first (own by an
|
|
3
3
|
// operator attestation from this identity or its operators, friend by default, the owner's choice
|
|
4
4
|
// kept through a re-pair, a merge and a rename, refusals by name); then, with the relay checkout
|
|
5
|
-
// beside contact/ (SIGELO_RELAY_DIR, else
|
|
5
|
+
// beside apps/contact/ (SIGELO_RELAY_DIR, else ../../relay), on a loopback relay: two agents run by one
|
|
6
6
|
// operator find each other own, the operator and its agent too, a contact who knows none of the
|
|
7
7
|
// operators stays friend and learns nothing, accept with a tier, and inbox / peek / take by tier,
|
|
8
8
|
// in a session and without one (local).
|
|
9
|
-
// node contact/test-tier.mjs → ALL PASS (n)
|
|
9
|
+
// node apps/contact/test-tier.mjs → ALL PASS (n)
|
|
10
10
|
import { createHash } from 'node:crypto';
|
|
11
11
|
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
12
12
|
import { tmpdir } from 'node:os';
|
|
@@ -32,7 +32,7 @@ function agent(label) {
|
|
|
32
32
|
const k = keygen({ seed: seed(label), recovery: 'sha256:' + '0'.repeat(64), created: CREATED, nonce: seed(`${label} nonce`).slice(0, 16) });
|
|
33
33
|
return { label, did: k.did, secret: k.secret, genesis: k.genesis, bundle: { v: 'sigelo/0', typ: 'bundle', genesis: k.genesis, rotations: [], bindings: [], attestations: [], issuers: [] } };
|
|
34
34
|
}
|
|
35
|
-
// The operator attestation the UI signs into its agent's file (contact/enrol.mjs operatorAttestation; the page signs it at Enrol, /api/agents/enrol).
|
|
35
|
+
// The operator attestation the UI signs into its agent's file (apps/contact/enrol.mjs operatorAttestation; the page signs it at Enrol, /api/agents/enrol).
|
|
36
36
|
const operate = (op, a, days = 90, iat = now - 60) => {
|
|
37
37
|
a.bundle.attestations.push(attest({ secret: op.secret, iss: op.did, sub: a.did, iat, exp: iat + days * DAY, ctx: OPERATOR_CTX, admission: 'invite', admission_by: op.did, claims: { relay: 'relay.test' } }));
|
|
38
38
|
if (!a.bundle.issuers.some((g) => g === op.genesis)) a.bundle.issuers.push(op.genesis);
|
|
@@ -115,10 +115,10 @@ const chainOnly = (a) => ({ ...a.bundle, attestations: [], issuers: [] });
|
|
|
115
115
|
} finally { rmSync(dir, { recursive: true, force: true }); }
|
|
116
116
|
}
|
|
117
117
|
|
|
118
|
-
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', 'relay');
|
|
118
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
119
119
|
if (!existsSync(join(RELAY_DIR, 'server.mjs'))) {
|
|
120
120
|
report();
|
|
121
|
-
console.log(`ALL PASS (${count}): the store part; SKIP the rest, no relay checkout beside contact/ (the relay is its own AGPL package): set SIGELO_RELAY_DIR`);
|
|
121
|
+
console.log(`ALL PASS (${count}): the store part; SKIP the rest, no relay checkout beside apps/contact/ (the relay is its own AGPL package): set SIGELO_RELAY_DIR`);
|
|
122
122
|
process.exit(0);
|
|
123
123
|
}
|
|
124
124
|
|
|
@@ -131,7 +131,7 @@ setTimeout(() => { console.log(`FAIL the run did not finish in 300 s (${count} c
|
|
|
131
131
|
const HOST = 'relay.test';
|
|
132
132
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-tier-'));
|
|
133
133
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1,
|
|
134
|
-
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits:
|
|
134
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
135
135
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
136
136
|
const events = {};
|
|
137
137
|
const make = (a) => {
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
// Transfers in the phone app (design/transfer.md §10; transfer-engine.mjs, transfer-web.mjs, rtc-web.mjs,
|
|
3
|
+
// photo.mjs): the accept rule's table and who counts as known; a group's fan-out (paired, through the
|
|
4
|
+
// creator, offline, direct asked first) over a fake carrier; the preview's checks; the page's data
|
|
5
|
+
// channel over a fake RTCDataChannel (the 1 MiB low mark, binary frames only); then, with the relay
|
|
6
|
+
// checkout beside apps/contact/ and sigelo-transfer installed, a page engine (webIo over a fake shell:
|
|
7
|
+
// the bytes in the shell, the bitmap saved after every chunk) against a Node agent on a loopback relay,
|
|
8
|
+
// both ways, a drop midway resumed, and a Downloads write that fails said in the record.
|
|
9
|
+
// node apps/contact/test-transfer-web.mjs → ALL PASS (n)
|
|
10
|
+
import { createHash } from 'node:crypto';
|
|
11
|
+
import { existsSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
12
|
+
import { tmpdir } from 'node:os';
|
|
13
|
+
import { dirname, join } from 'node:path';
|
|
14
|
+
import { fileURLToPath, pathToFileURL } from 'node:url';
|
|
15
|
+
import { keygen } from 'sigelo';
|
|
16
|
+
import { CHUNK, LOW, acceptRule, chunkLength, chunksOf, noPath } from './transfer.mjs';
|
|
17
|
+
import * as E from './transfer-engine.mjs';
|
|
18
|
+
import { webIo, webTransfers } from './transfer-web.mjs';
|
|
19
|
+
import { channelOf, iceServers, noMdns, peer as webPeer } from './rtc-web.mjs';
|
|
20
|
+
import * as W from './rtc-web.mjs';
|
|
21
|
+
import { PHOTO_LABEL, PHOTO_MAX, checkPhoto, imageType } from './photo.mjs';
|
|
22
|
+
|
|
23
|
+
let count = 0;
|
|
24
|
+
const fails = [];
|
|
25
|
+
const ok = (cond, what, more) => { count++; if (!cond) fails.push(more === undefined ? what : `${what} (${String(more).slice(0, 600)})`); };
|
|
26
|
+
const checkOf = (f) => { try { f(); return 'accepted'; } catch (e) { return e.check ?? `exception ${e.constructor.name}: ${e.message}`; } };
|
|
27
|
+
const failure = async (f) => { try { await f(); return 'accepted'; } catch (e) { return e.check ?? `exception ${e.message}`; } };
|
|
28
|
+
const report = () => {
|
|
29
|
+
for (const f of fails) console.log('FAIL ' + f);
|
|
30
|
+
if (fails.length) { console.log(`${fails.length} FAILED, ${count - fails.length} passed`); process.exit(1); }
|
|
31
|
+
};
|
|
32
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
const sha = (b) => createHash('sha256').update(b).digest('hex');
|
|
34
|
+
const seeded = (seed, n) => {
|
|
35
|
+
const out = Buffer.alloc(n);
|
|
36
|
+
for (let i = 0, off = 0; off < n; i++, off += 32) createHash('sha256').update(`${seed}\n${i}`).digest().copy(out, off, 0, Math.min(32, n - off));
|
|
37
|
+
return new Uint8Array(out.buffer, out.byteOffset, n);
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/** The platform's files (sync, in memory) and a fake shell's big-file bridge, the bytes in memory as the shell keeps them on disk. */
|
|
41
|
+
export function fakeShell({ landFails = null } = {}) {
|
|
42
|
+
const m = new Map();
|
|
43
|
+
const files = { read: (n) => m.get(n) ?? null, write: (n, b) => { m.set(n, Uint8Array.from(b)); }, remove: (n) => { m.delete(n); }, names: () => [...m.keys()] };
|
|
44
|
+
const docs = new Map(), parts = new Map(), landed = [], ops = [];
|
|
45
|
+
let docN = 0;
|
|
46
|
+
const big = {
|
|
47
|
+
ops, docs, parts, landed, free: async () => 1e12,
|
|
48
|
+
add(name, bytes, mtime = 1000) { const doc = `d${++docN}`; docs.set(doc, { name, bytes, mtime }); return { doc, name, size: bytes.length, mtime }; },
|
|
49
|
+
pick: async () => null,
|
|
50
|
+
async hash(doc) {
|
|
51
|
+
const d = docs.get(doc); if (!d) throw Object.assign(new Error('no such doc'), { check: 'file' });
|
|
52
|
+
const n = chunksOf(d.bytes.length), hashes = new Uint8Array(n * 32);
|
|
53
|
+
for (let i = 0; i < n; i++) hashes.set(createHash('sha256').update(d.bytes.subarray(i * CHUNK, i * CHUNK + chunkLength(d.bytes.length, i))).digest(), i * 32);
|
|
54
|
+
return { name: d.name, size: d.bytes.length, mtime: d.mtime, sha256: sha(d.bytes), hashes };
|
|
55
|
+
},
|
|
56
|
+
async stat(doc) { const d = docs.get(doc); if (!d) throw Object.assign(new Error('gone'), { check: 'file_changed' }); return { size: d.bytes.length, mtime: d.mtime }; },
|
|
57
|
+
async read(doc, offset, length, want) {
|
|
58
|
+
ops.push('read');
|
|
59
|
+
const d = docs.get(doc);
|
|
60
|
+
if (!d || d.bytes.length !== want.size || d.mtime !== want.mtime) throw Object.assign(new Error('file_changed: moved'), { check: 'file_changed' });
|
|
61
|
+
return d.bytes.slice(offset, offset + length);
|
|
62
|
+
},
|
|
63
|
+
async write(part, offset, b) {
|
|
64
|
+
ops.push('write');
|
|
65
|
+
const p = parts.get(part) ?? new Uint8Array(0);
|
|
66
|
+
const need = offset + b.length, q = p.length >= need ? p : (() => { const x = new Uint8Array(need); x.set(p); return x; })();
|
|
67
|
+
q.set(b, offset); parts.set(part, q);
|
|
68
|
+
},
|
|
69
|
+
async flush() { ops.push('flush'); },
|
|
70
|
+
async sha256(part) { return sha(parts.get(part) ?? new Uint8Array(0)); },
|
|
71
|
+
async drop(part) { parts.delete(part); },
|
|
72
|
+
async land(part, name) {
|
|
73
|
+
if (landFails) throw Object.assign(new Error(landFails), { check: 'land' });
|
|
74
|
+
const bytes = parts.get(part); parts.delete(part);
|
|
75
|
+
landed.push({ name, bytes });
|
|
76
|
+
return { uri: `content://media/external/downloads/${landed.length}`, name };
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
return { files, big };
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ================================================================ the accept rule
|
|
83
|
+
{
|
|
84
|
+
const t = (o) => acceptRule({ size: 3e6, trust: 'own', ...o });
|
|
85
|
+
ok(t({}) === 'auto' && t({ trust: 'compared' }) === 'auto', 'own and compared, 3 MB under 25 MB: auto');
|
|
86
|
+
ok(t({ trust: 'other' }) === 'ask', 'words not compared, a public joiner, quiet (other): always asked');
|
|
87
|
+
ok(t({ size: 25e6 }) === 'auto' && t({ size: 25e6 + 1 }) === 'ask', '25 MB exactly lands; one byte more asks (MB = 10^6)');
|
|
88
|
+
ok(t({ limitMb: 0 }) === 'ask' && t({ limitMb: 2 }) === 'ask' && t({ limitMb: 4 }) === 'auto', 'the contact\'s own size wins: 0 always asks');
|
|
89
|
+
ok(t({ defaultMb: 0 }) === 'ask' && t({ defaultMb: 1, limitMb: 5 }) === 'auto', 'the default 0: always ask, unless the contact has its own');
|
|
90
|
+
ok(t({ direct: null }) === 'auto' && t({ direct: false }) === 'auto', 'the direct switch is not the rule\'s (2026-11-25): off or not asked, still auto (the lane falls to Tor or the relay)');
|
|
91
|
+
const c = (x) => ({ did: 'did:sigelo:zA', tier: 'friend', ...x });
|
|
92
|
+
ok(E.trustOf(c({ tier: 'own' })) === 'own' && E.trustOf(c({ ours: true })) === 'own', 'trustOf: own tier and ours are own');
|
|
93
|
+
ok(E.trustOf(c({}), () => true) === 'compared' && E.trustOf(c({}), () => false) === 'other', 'trustOf: a friend is known once the words were compared');
|
|
94
|
+
ok(E.trustOf(c({ via: { public: 'x' } }), () => true) === 'other' && E.trustOf(c({ tier: 'quiet' }), () => true) === 'other', 'trustOf: a public-code joiner and quiet are always other');
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// ================================================================ the preview
|
|
98
|
+
{
|
|
99
|
+
const jpeg = new Uint8Array([0xff, 0xd8, 0xff, 0xe0, 1, 2, 3, 4]), b64 = (b) => Buffer.from(b).toString('base64');
|
|
100
|
+
const p = { type: 'image/jpeg', data: b64(jpeg), w: 640, h: 480, sha256: 'ab'.repeat(32), size: 3_200_000, name: 'IMG_1.jpg' };
|
|
101
|
+
ok(PHOTO_LABEL === 'sigelo-photo/0' && PHOTO_MAX === 65536, 'label sigelo-photo/0, 64 KB at most');
|
|
102
|
+
ok(checkOf(() => checkPhoto(p)) === 'accepted' && imageType(jpeg) === 'image/jpeg', 'a JPEG preview: accepted');
|
|
103
|
+
ok(checkOf(() => checkPhoto({ ...p, type: 'image/webp' })) === 'photo', 'the type must be the bytes\' (JPEG called WebP): photo');
|
|
104
|
+
ok(checkOf(() => checkPhoto({ ...p, data: b64(new Uint8Array(PHOTO_MAX + 1).fill(0xff)) })) === 'photo', 'more than 64 KB: photo');
|
|
105
|
+
ok(checkOf(() => checkPhoto({ ...p, w: 0 })) === 'photo' && checkOf(() => checkPhoto({ ...p, extra: 1 })) === 'photo' && checkOf(() => checkPhoto({ ...p, sha256: 'x' })) === 'photo', 'w, unknown keys, sha256: photo');
|
|
106
|
+
ok(checkOf(() => checkPhoto({ ...p, type: 'image/png', data: b64(new Uint8Array([0x89, 0x50, 0x4e, 0x47])) })) === 'photo', 'PNG (or any other type): photo');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ================================================================ the page's data channel (fake RTCDataChannel)
|
|
110
|
+
{
|
|
111
|
+
const on = {}, sent = [];
|
|
112
|
+
const dc = { readyState: 'open', bufferedAmount: 0, addEventListener: (e, f) => { (on[e] ??= []).push(f); }, send: (f) => sent.push(f), close() { this.readyState = 'closed'; for (const f of on.close ?? []) f(); } };
|
|
113
|
+
const pcOn = {}, pc = { connectionState: 'connected', addEventListener: (e, f) => { (pcOn[e] ??= []).push(f); } };
|
|
114
|
+
const ch = channelOf(dc, pc), got = [], low = [], closed = [];
|
|
115
|
+
ch.on('frame', (f) => got.push(f)); ch.on('low', () => low.push(1)); ch.on('close', () => closed.push(1));
|
|
116
|
+
ok(dc.binaryType === 'arraybuffer' && dc.bufferedAmountLowThreshold === LOW && LOW === CHUNK, 'binary frames as ArrayBuffer; the low mark at 1 MiB');
|
|
117
|
+
on.message[0]({ data: new Uint8Array([1, 2, 3]).buffer }); on.message[0]({ data: 'text' });
|
|
118
|
+
ok(got.length === 1 && got[0] instanceof Uint8Array && got[0][2] === 3, 'a binary message is a frame; text is dropped');
|
|
119
|
+
on.bufferedamountlow[0](); ch.send(new Uint8Array([9]));
|
|
120
|
+
ok(low.length === 1 && sent.length === 1, 'bufferedamountlow → low; send goes to the channel');
|
|
121
|
+
pc.connectionState = 'failed'; pcOn.connectionstatechange[0]();
|
|
122
|
+
ok(closed.length === 1 && checkOf(() => ch.send(new Uint8Array(1))) !== 'accepted', 'the connection failed: closed once, send throws');
|
|
123
|
+
const sdp = 'v=0\r\na=candidate:1 1 udp 1 1f2e3d4c-aaaa.local 5000 typ host\r\na=candidate:2 1 udp 1 203.0.113.5 5000 typ srflx\r\n';
|
|
124
|
+
ok(!noMdns(sdp).includes('.local') && noMdns(sdp).includes('203.0.113.5'), 'a .local candidate is dropped, the public one kept');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
// ================================================================ a group's fan-out over a fake carrier
|
|
128
|
+
{
|
|
129
|
+
const sh = fakeShell(), io = webIo({ files: sh.files, big: sh.big }), X = webTransfers(io);
|
|
130
|
+
const contacts = [{ did: 'did:sigelo:zBob', name: 'bob', tier: 'own' }, { did: 'did:sigelo:zDan', name: 'dan', tier: 'friend' }, { did: 'did:sigelo:zEve', name: 'eve', tier: 'own' }];
|
|
131
|
+
const out = [];
|
|
132
|
+
const carrier = { clock: () => 1_800_000_000, contacts: () => ({ contacts }), async send(to, content, o) { out.push({ to, content, label: o.label }); return { status: to === 'did:sigelo:zEve' ? 'queued' : 'sent' }; } };
|
|
133
|
+
const f = await X.prepare({ doc: sh.big.add('IMG.jpg', seeded('photo', 3 * CHUNK + 7)).doc });
|
|
134
|
+
const members = [{ did: 'did:sigelo:zBob', name: 'bob', contact: true }, { did: 'did:sigelo:zDan', name: 'dan', contact: true }, { did: 'did:sigelo:zCarol', name: 'carol', contact: false }, { did: 'did:sigelo:zEve', name: 'eve', contact: true }];
|
|
135
|
+
ok(await failure(() => X.fanOut({ carrier, members, f, group: 'cd'.repeat(16) })) === 'direct_ask' && out.length === 0, 'dan\'s direct switch not set: direct_ask before anything is sent');
|
|
136
|
+
const r = await X.fanOut({ carrier, members, f, direct: true, group: 'cd'.repeat(16) });
|
|
137
|
+
ok(r.sent.map((x) => x.name).join() === 'bob,dan,eve' && r.unpaired.map((x) => x.name).join() === 'carol' && r.failed.length === 0, 'one transfer per paired member; carol (through the creator) unpaired', JSON.stringify(r));
|
|
138
|
+
const ms = out.filter((x) => x.content.typ === 'manifest');
|
|
139
|
+
ok(ms.length === 3 && new Set(ms.map((x) => x.content.id)).size === 3 && ms.every((x) => x.content.sha256 === f.whole && x.label === 'sigelo-transfer/0'), 'three manifests: own ids, one sha256');
|
|
140
|
+
const L = X.list({ carrier });
|
|
141
|
+
ok(L.out.length === 3 && L.out.every((x) => x.state === 'offered' && x.group === 'cd'.repeat(16)), 'eve offline (queued): her manifest waits at the relay; every record offered, named by the group');
|
|
142
|
+
ok(!sh.files.names().some((n) => n.endsWith('.part')) && sh.big.ops.length === 0, 'nothing read nor written yet: the bytes go when each member offers');
|
|
143
|
+
ok(X.settings({ patch: { keep_location: true } }).keep_location === true && X.settings({}).auto_mb === 25, 'settings: keep_location kept, auto_mb 25 by default');
|
|
144
|
+
ok(X.setAuto({ carrier, contact: 'bob', mb: 0 }).auto_mb === 0 && X.list({ carrier }).auto['did:sigelo:zBob'] === 0, 'setAuto: per contact, in the list');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// ================================================================ TURN (2026-11-26): the relay's credential at each attempt
|
|
148
|
+
const TURN = { urls: ['turn:relay.test:3478?transport=udp', 'turn:relay.test:3478?transport=tcp'], username: '1764200000:abcdefghijklmnop', credential: 'Y3JlZGVudGlhbA==', exp: 1764200000 };
|
|
149
|
+
{
|
|
150
|
+
ok(JSON.stringify(iceServers(['relay.test:3478'])) === '[{"urls":["stun:relay.test:3478"]}]' && JSON.stringify(iceServers([], null)) === '[]', 'the page\'s ICE servers without TURN: STUN alone, as before');
|
|
151
|
+
ok(JSON.stringify(iceServers(['relay.test:3478'], TURN)) === JSON.stringify([{ urls: ['stun:relay.test:3478'] }, { urls: TURN.urls, username: TURN.username, credential: TURN.credential }]), 'with TURN: the relay\'s turn: URIs, username, credential after STUN');
|
|
152
|
+
let cfg = null;
|
|
153
|
+
class R { constructor(c) { cfg = c; } addEventListener() {} close() {} }
|
|
154
|
+
const p = await webPeer({ stun: ['relay.test:3478'], turn: TURN, RTC: R });
|
|
155
|
+
ok(cfg.iceServers.length === 2 && cfg.iceServers[1].credential === TURN.credential && cfg.iceTransportPolicy === undefined, 'rtc-web peer(): the connection gets STUN and TURN; the policy stays "all" (a direct pair preferred)');
|
|
156
|
+
p.close();
|
|
157
|
+
const eng = (o, carrier) => new E.Engine({ carrier, io: {}, timer: false, ...o });
|
|
158
|
+
const asked = [];
|
|
159
|
+
const c1 = { turnServer: async () => { asked.push(1); return TURN; } };
|
|
160
|
+
ok((await eng({}, c1).turnOf(W))?.username === TURN.username && asked.length === 1, 'the engine asks carrier.turnServer() at each attempt');
|
|
161
|
+
ok(await eng({ turn: false }, c1).turnOf(W) === null && await eng({ env: { SIGELO_TURN: 'off' } }, c1).turnOf(W) === null && asked.length === 1, 'turn: false, or SIGELO_TURN=off: none, nothing asked');
|
|
162
|
+
ok(await eng({}, { turnServer: async () => { throw new Error('down'); } }).turnOf(W) === null && await eng({}, {}).turnOf(W) === null && await eng({}, { turnServer: async () => null }).turnOf(W) === null,
|
|
163
|
+
'a carrier that fails, has no turnServer, or whose relay gives none: null (STUN alone)');
|
|
164
|
+
ok(await eng({}, c1).turnOf({ peer() {} }) === null && await eng({}, c1).turnOf({ TURN_OK: false }) === null && asked.length === 1,
|
|
165
|
+
'a module that does not say TURN_OK true (werift without its handshake checks): no credential asked');
|
|
166
|
+
ok((await eng({}, c1).turnOf(await import('../transfer/rtc.mjs')))?.username === TURN.username && asked.length === 2,
|
|
167
|
+
'werift (apps/transfer/rtc.mjs) with its handshake checks in place: TURN_OK true, a credential asked');
|
|
168
|
+
// "Always relay my media" (design/calls.md §6): the policy, the page's peer under it, the engine's.
|
|
169
|
+
ok(eng({}, {}).policyNow() === 'all' && eng({ policy: () => 'relay' }, {}).policyNow() === 'relay' && eng({ env: { SIGELO_ICE_POLICY: 'relay' } }, {}).policyNow() === 'relay'
|
|
170
|
+
&& eng({ policy: () => { throw new Error('x'); } }, {}).policyNow() === 'all', 'the engine\'s policy: the setting (policy()) or SIGELO_ICE_POLICY=relay; else all');
|
|
171
|
+
ok(await failure(() => webPeer({ stun: ['relay.test:3478'], turn: null, RTC: R, policy: 'relay' })) === 'relay_only', 'rtc-web peer(): relay only without TURN: refused relay_only, no connection made');
|
|
172
|
+
cfg = null;
|
|
173
|
+
class RS { constructor(c) { cfg = c; this.iceGatheringState = 'complete'; this.localDescription = null; } addEventListener() {} createDataChannel() { return { readyState: 'connecting', addEventListener() {} }; }
|
|
174
|
+
async createOffer() { return { type: 'offer', sdp: '' }; } async setLocalDescription() { this.localDescription = { sdp: 'v=0\r\na=candidate:1 1 udp 1 192.0.2.7 5000 typ host\r\na=candidate:3 1 udp 1 198.51.100.4 49200 typ relay raddr 203.0.113.9 rport 6000\r\n' }; }
|
|
175
|
+
async getStats() { return new Map([['t', { id: 't', type: 'transport', selectedCandidatePairId: 'p' }], ['p', { id: 'p', type: 'candidate-pair', localCandidateId: 'l', remoteCandidateId: 'r' }], ['l', { id: 'l', candidateType: 'relay' }], ['r', { id: 'r', candidateType: 'srflx' }]]); } close() {} }
|
|
176
|
+
const pr = await webPeer({ stun: ['relay.test:3478'], turn: TURN, RTC: RS, policy: 'relay' }), o = await pr.offer('sigelo-transfer/0 x 1');
|
|
177
|
+
ok(cfg.iceTransportPolicy === 'relay' && cfg.iceServers.length === 1 && !/192\.0\.2\.7|203\.0\.113\.9/.test(o) && /typ relay raddr 0\.0\.0\.0 rport 0/.test(o),
|
|
178
|
+
'rtc-web peer() relay only: iceTransportPolicy relay, TURN alone, the SDP with the relayed candidate only, raddr zeroed', o);
|
|
179
|
+
ok(await pr.relayed() === true, 'rtc-web relayed(): the selected pair has a relayed candidate (call.mjs relayedOf, as the call screen)');
|
|
180
|
+
pr.close();
|
|
181
|
+
const W2 = await import('../transfer/rtc.mjs');
|
|
182
|
+
ok(await failure(() => W2.peer({ turn: null, policy: 'relay' })) === 'relay_only', 'werift peer(): relay only without TURN: relay_only');
|
|
183
|
+
const wr = await W2.peer({ turn: { ...TURN, urls: ['turn:127.0.0.1:9?transport=udp'] }, gatherMs: 300, policy: 'relay' }), wo = await wr.offer('sigelo-transfer/0 y 1');
|
|
184
|
+
ok(typeof wo === 'string' && !/typ (host|srflx)/.test(wo) && wr.pc.config?.iceTransportPolicy === 'relay', 'werift relay only (a TURN that answers nothing): no host or srflx candidate in the offer', wo);
|
|
185
|
+
ok(await wr.relayed() === null, 'werift relayed(): no pair selected yet: null');
|
|
186
|
+
wr.close();
|
|
187
|
+
ok(noPath('bob').startsWith('No direct path to bob from these two networks') && noPath('bob', true).startsWith('No path to bob from these two networks, not even through the relay host'),
|
|
188
|
+
'no path: the old words without TURN; "not even through the relay host" with it');
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
// ================================================================ a page engine against a Node agent on a loopback relay
|
|
192
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
193
|
+
if (!existsSync(join(RELAY_DIR, 'server.mjs')) || !existsSync(join(HERE, '..', 'transfer', 'node_modules', 'werift'))) {
|
|
194
|
+
report();
|
|
195
|
+
console.log(`ALL PASS (${count}): the unit part; SKIP the flows (the relay checkout or sigelo-transfer's node_modules missing)`);
|
|
196
|
+
process.exit(0);
|
|
197
|
+
}
|
|
198
|
+
const { startRelay } = await import(pathToFileURL(join(RELAY_DIR, 'server.mjs')).href);
|
|
199
|
+
const { relayPolicy } = await import(pathToFileURL(join(RELAY_DIR, 'allowance.mjs')).href);
|
|
200
|
+
const { Carrier, pathsFor } = await import('./carrier.mjs');
|
|
201
|
+
const X = await import('./transfer-node.mjs');
|
|
202
|
+
const rtc = await import(pathToFileURL(join(HERE, '..', 'transfer', 'rtc.mjs')).href);
|
|
203
|
+
setTimeout(() => { console.log(`FAIL the run did not finish in 900 s (${count} checks so far)`); process.exit(1); }, 900_000).unref();
|
|
204
|
+
const HOST = 'relay.test', now = Date.parse('2026-11-13T12:00:00Z') / 1000;
|
|
205
|
+
const dir = mkdtempSync(join(tmpdir(), 'sigelo-transfer-web-'));
|
|
206
|
+
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1,
|
|
207
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
208
|
+
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
209
|
+
const seed = (l) => new Uint8Array(createHash('sha256').update(`sigelo-transfer-web-test/0 ${l}`).digest());
|
|
210
|
+
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
211
|
+
const until = async (f, ms = 60000) => { const t = Date.now() + ms; while (Date.now() < t) { if (await f()) return true; await sleep(100); } return false; };
|
|
212
|
+
function carrierOf(label, onEvent) {
|
|
213
|
+
const k = keygen({ seed: seed(label), recovery: 'sha256:' + '0'.repeat(64), created: '2026-10-01T00:00:00Z', nonce: seed(`${label} nonce`).slice(0, 16) });
|
|
214
|
+
const identity = join(dir, `${label}.local.json`);
|
|
215
|
+
const bundle = { v: 'sigelo/0', typ: 'bundle', genesis: k.genesis, rotations: [], bindings: [], attestations: [], issuers: [] };
|
|
216
|
+
return { did: k.did, identity, c: new Carrier({ identity: () => ({ secret: k.secret, bundle }), ...pathsFor(identity), relay: HOST, endpoints, clock: () => now, keep: true, backoff: [100, 400], retentionDays: 7, onEvent }) };
|
|
217
|
+
}
|
|
218
|
+
let P = null, N = null;
|
|
219
|
+
const pEvents = [], nEvents = [];
|
|
220
|
+
const phone = carrierOf('phone', (e) => { if (e.type === 'transfer') P?.e.kick(); });
|
|
221
|
+
const node = carrierOf('node', (e) => { if (e.type === 'transfer') N?.e.kick(); });
|
|
222
|
+
const sh = fakeShell(), pio = webIo({ files: sh.files, big: sh.big }), PX = webTransfers(pio, { rtc });
|
|
223
|
+
// The page's peers recorded: this loopback relay gives no TURN, so every attempt goes with STUN alone, as before TURN.
|
|
224
|
+
const peers = [], rtcSeen = { ...rtc, peer: (o) => { peers.push(o); return rtc.peer(o); } };
|
|
225
|
+
{
|
|
226
|
+
ok(rtc.TURN_OK === true && JSON.stringify(rtc.iceServers([], TURN)) === JSON.stringify(iceServers([], TURN)), 'sigelo-transfer (werift, handshake checks in place): TURN_OK true, the same ICE servers as the page');
|
|
227
|
+
const w = await rtc.peer({ stun: [], turn: { ...TURN, urls: ['turn:127.0.0.1:9?transport=udp'] }, gatherMs: 200 });
|
|
228
|
+
ok(w.pc && typeof (await w.offer('sigelo-transfer/0 t 1')) === 'string', 'werift takes a TURN server (one that answers nothing: host candidates still offered)');
|
|
229
|
+
w.close();
|
|
230
|
+
}
|
|
231
|
+
P = { ...phone, X: PX, e: new E.Engine({ carrier: phone.c, io: pio, rtc: async () => rtcSeen, stun: [], maxServe: 2, retryMs: 300, onEvent: (e) => pEvents.push(e) }) };
|
|
232
|
+
N = { ...node, e: new X.Engine({ carrier: node.c, identity: node.identity, stun: [], tor: null, retryMs: 300, onEvent: (e) => nEvents.push(e) }) };
|
|
233
|
+
try {
|
|
234
|
+
const inv = await P.c.invite({ name: 'node' });
|
|
235
|
+
await N.c.accept(inv.code, { name: 'phone', wait: 0.3 });
|
|
236
|
+
await P.c.inbox(); await N.c.inbox(); await P.c.inbox();
|
|
237
|
+
P.c.setTier('node', 'own'); N.c.setTier('phone', 'own');
|
|
238
|
+
await P.c.start(); await N.c.start();
|
|
239
|
+
const pRec = (side, id) => PX.list({ carrier: P.c })[side].find((r) => r.id === id);
|
|
240
|
+
const nRec = (side, id) => X.list({ carrier: N.c, identity: N.identity })[side].find((r) => r.id === id);
|
|
241
|
+
|
|
242
|
+
// Phone → computer: a photo of 3 MB picked in the shell, read by range; under the computer's 25 MB: it lands unasked.
|
|
243
|
+
const shot = seeded('shot', 3 * CHUNK + 123), d1 = sh.big.add('IMG_20261113.jpg', shot);
|
|
244
|
+
const r1 = await PX.send({ carrier: P.c, to: 'node', doc: d1.doc });
|
|
245
|
+
ok(r1.state === 'offered' && r1.file === d1.doc && r1.sha256 === sha(shot), 'the phone offers a picked file by its doc, hashed in the shell');
|
|
246
|
+
ok(await until(() => nRec('in', r1.id)?.state === 'done', 120000), 'phone → computer, own contact, 3 MB: landed by the rule', JSON.stringify(nRec('in', r1.id)));
|
|
247
|
+
ok(sha(readFileSync(nRec('in', r1.id).saved)) === sha(shot) && nRec('in', r1.id).path_used === 'direct', 'whole, over the direct path (the page\'s engine, werift in this test)');
|
|
248
|
+
ok(await until(() => pRec('out', r1.id)?.state === 'done'), 'the phone\'s record: done');
|
|
249
|
+
ok(nRec('in', r1.id).relayed === false && pRec('out', r1.id).relayed === false, 'both records: relayed false (the selected pair is direct: the transfers list says "direct")', JSON.stringify([nRec('in', r1.id).relayed, pRec('out', r1.id).relayed]));
|
|
250
|
+
ok(sh.big.ops.filter((x) => x === 'read').length === 4, `read by range, one per chunk (${sh.big.ops.filter((x) => x === 'read').length})`);
|
|
251
|
+
|
|
252
|
+
// Computer → phone: 6 MB; it lands in Downloads through the shell; the bitmap saved after every chunk.
|
|
253
|
+
sh.big.ops.length = 0;
|
|
254
|
+
const film = seeded('film', 6 * CHUNK + 5);
|
|
255
|
+
writeFileSync(join(dir, 'film.bin'), film);
|
|
256
|
+
const r2 = await X.send({ carrier: N.c, identity: N.identity, to: 'phone', path: join(dir, 'film.bin') });
|
|
257
|
+
ok(await until(() => pRec('in', r2.id)?.state === 'done', 120000), 'computer → phone: landed', JSON.stringify(pRec('in', r2.id)));
|
|
258
|
+
ok(sh.big.landed.length === 1 && sha(sh.big.landed[0].bytes) === sha(film) && pRec('in', r2.id).saved === 'content://media/external/downloads/1', 'in Downloads whole (MediaStore\'s URI kept as saved)');
|
|
259
|
+
ok(sh.big.ops.filter((x) => x === 'flush').length >= 7, `a flush after every chunk (${sh.big.ops.filter((x) => x === 'flush').length} for 7 chunks)`);
|
|
260
|
+
ok(!sh.files.names().some((n) => n.includes(r2.id)), 'no bitmap nor list left in the page\'s files');
|
|
261
|
+
const item = (await P.c.inbox()).messages.find((m) => m.type === 'file' && m.transfer === r2.id);
|
|
262
|
+
ok(item?.path === pRec('in', r2.id).saved, 'one inbox item, its path the Downloads URI');
|
|
263
|
+
|
|
264
|
+
// A drop midway into the phone: interrupted, resumed with only the rest.
|
|
265
|
+
X.settings({ identity: N.identity });
|
|
266
|
+
const mid = seeded('mid', 12 * CHUNK); writeFileSync(join(dir, 'mid.bin'), mid);
|
|
267
|
+
const r3 = await X.send({ carrier: N.c, identity: N.identity, to: 'phone', path: join(dir, 'mid.bin') });
|
|
268
|
+
ok(await until(() => (P.e.progress(r3.id)?.got ?? 0) >= 3 * CHUNK, 120000), 'the third transfer is under way');
|
|
269
|
+
P.e.attempts.get(r3.id)?.channel?.close();
|
|
270
|
+
ok(await until(() => pRec('in', r3.id)?.state === 'done', 120000), 'cut midway: resumed and done', JSON.stringify(pRec('in', r3.id)));
|
|
271
|
+
ok(pRec('in', r3.id).attempt >= 2 && sha(sh.big.landed.at(-1).bytes) === sha(mid), 'a new attempt; the file whole');
|
|
272
|
+
|
|
273
|
+
// Downloads refuses (no storage permission, a full disk): said in the record, the partial kept; resume tries again.
|
|
274
|
+
const sh2 = sh.big.land;
|
|
275
|
+
sh.big.land = async () => { throw Object.assign(new Error('no permission to write to Downloads'), { check: 'land' }); };
|
|
276
|
+
const small = seeded('small', CHUNK + 1); writeFileSync(join(dir, 'small.bin'), small);
|
|
277
|
+
const r4 = await X.send({ carrier: N.c, identity: N.identity, to: 'phone', path: join(dir, 'small.bin') });
|
|
278
|
+
ok(await until(() => pRec('in', r4.id)?.reason === 'land', 120000), 'Downloads refused: failed, reason land', JSON.stringify(pRec('in', r4.id)));
|
|
279
|
+
ok(/could not be saved: no permission/.test(pRec('in', r4.id).detail) && sh.big.parts.has(r4.id), 'the reason said; the partial kept');
|
|
280
|
+
sh.big.land = sh2;
|
|
281
|
+
PX.resume({ carrier: P.c, id: r4.id }); P.e.kick();
|
|
282
|
+
ok(await until(() => pRec('in', r4.id)?.state === 'done', 60000), 'resume: saved again without the network', JSON.stringify(pRec('in', r4.id)));
|
|
283
|
+
ok(await until(() => nRec('out', r4.id)?.state === 'done', 60000), 'and the sender told done');
|
|
284
|
+
|
|
285
|
+
// The sender's file moved before the offer: file_changed.
|
|
286
|
+
const d5 = sh.big.add('moved.jpg', seeded('m5', 2000));
|
|
287
|
+
X.settings({ identity: N.identity, patch: { auto_mb: 0 } });
|
|
288
|
+
const r5 = await PX.send({ carrier: P.c, to: 'node', doc: d5.doc });
|
|
289
|
+
await until(() => nRec('in', r5.id)?.state === 'asked');
|
|
290
|
+
sh.big.docs.get(d5.doc).mtime = 2000;
|
|
291
|
+
X.accept({ carrier: N.c, identity: N.identity, id: r5.id }); N.e.kick();
|
|
292
|
+
ok(await until(() => pRec('out', r5.id)?.reason === 'file_changed' && nRec('in', r5.id)?.reason === 'file_changed'), 'the picked file changed after the offer: file_changed both sides');
|
|
293
|
+
|
|
294
|
+
// "Always relay my media" on the phone, and this relay offers no TURN: its direct lane left out at once, no peer made
|
|
295
|
+
// (nothing gathered), the record says the sentence; the sender is told no_path (its relay lane or Tor, as ever).
|
|
296
|
+
X.settings({ identity: N.identity, patch: { auto_mb: 25 } });
|
|
297
|
+
P.e.policy = () => 'relay';
|
|
298
|
+
const n0 = peers.length, ro = seeded('relayonly', 2000); writeFileSync(join(dir, 'ro.bin'), ro);
|
|
299
|
+
const r6 = await X.send({ carrier: N.c, identity: N.identity, to: 'phone', path: join(dir, 'ro.bin') });
|
|
300
|
+
ok(await until(() => pRec('in', r6.id)?.reason === 'relay_only' || pRec('in', r6.id)?.state === 'relayed', 60000) && peers.length === n0,
|
|
301
|
+
'relay only, no TURN: no peer made on the phone; failed relay_only (or relayed by the sender\'s relay lane)', JSON.stringify(pRec('in', r6.id)));
|
|
302
|
+
ok(pEvents.some((e) => e.what === 'no_direct' && e.id === r6.id && e.detail === E.RELAY_ONLY), `the phone's event says "${E.RELAY_ONLY}"`);
|
|
303
|
+
ok(await until(() => ['failed', 'relaying', 'done'].includes(nRec('out', r6.id)?.state), 60000) && nRec('out', r6.id)?.path_used !== 'direct', 'the sender told: not over the direct lane', JSON.stringify(nRec('out', r6.id)));
|
|
304
|
+
P.e.policy = () => 'all';
|
|
305
|
+
} finally {
|
|
306
|
+
await P.e.close().catch(() => {}); await N.e.close().catch(() => {});
|
|
307
|
+
await P.c.stop().catch(() => {}); await N.c.stop().catch(() => {});
|
|
308
|
+
await relay.close();
|
|
309
|
+
rmSync(dir, { recursive: true, force: true });
|
|
310
|
+
}
|
|
311
|
+
ok(peers.length > 0 && peers.every((o) => o.turn === null), `the relay gives no TURN: every attempt with STUN alone (${peers.length} peers)`);
|
|
312
|
+
report();
|
|
313
|
+
console.log(`ALL PASS (${count})`);
|
package/test-transfer.mjs
CHANGED
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
// Transfers (transfer.mjs, transfer-node.mjs, sigelo-transfer; design/transfer.md): the messages and
|
|
3
3
|
// frames; the chunk protocol over a fake channel (a whole file, a drop and the resume, a chunk altered
|
|
4
4
|
// once and always, the list altered, the 16 GiB cap, back-pressure); the path order; then with the
|
|
5
|
-
// relay checkout beside contact/ (SIGELO_RELAY_DIR, else
|
|
5
|
+
// relay checkout beside apps/contact/ (SIGELO_RELAY_DIR, else ../../relay) two agents on a loopback relay:
|
|
6
6
|
// consent (nothing written before yes; decline; busy past the caps), the direct switch, a 50 MB file
|
|
7
7
|
// over werift (MB/s printed), a drop and a resume, file_changed; and the Tor path against a fake tor
|
|
8
8
|
// (a control port that answers PROTOCOLINFO, AUTHENTICATE, ADD_ONION, ONION_CLIENT_AUTH_ADD and
|
|
9
9
|
// DEL_ONION, and a SOCKS5 port that connects the onion to the service's local port), or the real one
|
|
10
10
|
// when SIGELO_TEST_TOR names its control port. SIGELO_TEST_MB: the size of the direct file (default 50).
|
|
11
|
-
// node contact/test-transfer.mjs → ALL PASS (n)
|
|
11
|
+
// node apps/contact/test-transfer.mjs → ALL PASS (n)
|
|
12
12
|
import { createHash } from 'node:crypto';
|
|
13
|
-
import { existsSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
13
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, readdirSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
14
14
|
import net from 'node:net';
|
|
15
15
|
import { tmpdir } from 'node:os';
|
|
16
16
|
import { basename, dirname, join } from 'node:path';
|
|
@@ -204,17 +204,29 @@ export function attempt(bytes, m, hashes, { have, known = null, drop, alter, rea
|
|
|
204
204
|
ok(await ended === 'cancelled', 'a WANT past the file: the sender ends it');
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
|
|
207
|
+
// Where sigelo-transfer is looked for (transfer-node.mjs rtcDirs): the global layout `npm i -g sigelo-agent sigelo-transfer`
|
|
208
|
+
// makes (sigelo-contact inside sigelo-agent's node_modules, sigelo-transfer beside sigelo-agent) is found by name.
|
|
209
|
+
{
|
|
210
|
+
const { rtcDirs } = await import('./transfer-node.mjs');
|
|
211
|
+
const g = mkdtempSync(join(tmpdir(), 'sigelo-rtcdirs-')), lib = join(g, 'lib', 'node_modules'), from = join(lib, 'sigelo-agent', 'node_modules', 'sigelo-contact');
|
|
212
|
+
for (const d of [from, join(lib, 'sigelo-transfer')]) mkdirSync(d, { recursive: true });
|
|
213
|
+
writeFileSync(join(lib, 'sigelo-transfer', 'package.json'), JSON.stringify({ name: 'sigelo-transfer', exports: { './package.json': './package.json' } }));
|
|
214
|
+
const dirs = rtcDirs(from);
|
|
215
|
+
ok(dirs.includes(join(lib, 'sigelo-transfer')) && dirs[0] === join(lib, 'sigelo-agent', 'node_modules', 'transfer'), 'rtcDirs: a global sigelo-transfer beside sigelo-agent is found by name, after the fixed places', JSON.stringify(dirs));
|
|
216
|
+
rmSync(g, { recursive: true, force: true });
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const RELAY_DIR = process.env.SIGELO_RELAY_DIR ?? join(HERE, '..', '..', 'relay');
|
|
208
220
|
if (!existsSync(join(RELAY_DIR, 'server.mjs')) || !existsSync(join(RELAY_DIR, 'node_modules'))) {
|
|
209
221
|
report();
|
|
210
|
-
console.log(`ALL PASS (${count}): the unit part; SKIP the flows, no relay checkout with its dependencies beside contact/: set SIGELO_RELAY_DIR`);
|
|
222
|
+
console.log(`ALL PASS (${count}): the unit part; SKIP the flows, no relay checkout with its dependencies beside apps/contact/: set SIGELO_RELAY_DIR`);
|
|
211
223
|
process.exit(0);
|
|
212
224
|
}
|
|
213
225
|
|
|
214
|
-
// The direct path needs sigelo-transfer installed beside contact/ (npm ci in
|
|
215
|
-
if (!existsSync(join(HERE, '..', '
|
|
226
|
+
// The direct path needs sigelo-transfer installed beside apps/contact/ (npm ci in apps/transfer/).
|
|
227
|
+
if (!existsSync(join(HERE, '..', 'transfer', 'node_modules', 'werift'))) {
|
|
216
228
|
report();
|
|
217
|
-
console.log(`ALL PASS (${count}): the unit part; SKIP the flows, sigelo-transfer has no node_modules: npm ci in
|
|
229
|
+
console.log(`ALL PASS (${count}): the unit part; SKIP the flows, sigelo-transfer has no node_modules: npm ci in apps/transfer/`);
|
|
218
230
|
process.exit(0);
|
|
219
231
|
}
|
|
220
232
|
|
|
@@ -228,7 +240,7 @@ setTimeout(() => { console.log(`FAIL the run did not finish in 1500 s (${count}
|
|
|
228
240
|
const HOST = 'relay.test', now = NOW;
|
|
229
241
|
const dir = mkdtempSync(join(tmpdir(), 'sigelo-transfer-'));
|
|
230
242
|
const relay = await startRelay({ host: HOST, db: join(dir, 'relay.db'), tcpPort: 0, httpPort: 0, loginRate: 100000, verifyBudget: 1e9, clock: () => now, diskUsed: () => 0.1,
|
|
231
|
-
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits:
|
|
243
|
+
log: () => {}, policy: (ctx) => relayPolicy(ctx, { pow: { bits: 4, loadBits: 8, loadPerHour: 1000, cost: { m: 8, t: 1, p: 1 } } }) });
|
|
232
244
|
const endpoints = { [HOST]: { mqtt: `mqtt://127.0.0.1:${relay.ports.tcp}`, http: `http://127.0.0.1:${relay.ports.http}` } };
|
|
233
245
|
const seed = (l) => new Uint8Array(createHash('sha256').update(`sigelo-transfer-test/0 ${l}`).digest());
|
|
234
246
|
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
@@ -258,6 +270,8 @@ try {
|
|
|
258
270
|
ok(await failure(() => send(file('small.bin', seeded('s', 1000)))) === 'direct_ask', 'send to a friend contact, the direct switch not set: direct_ask');
|
|
259
271
|
ok(X.list({ carrier: A.c, identity: A.identity }).out.length === 0, 'and nothing was sent');
|
|
260
272
|
A.c.setTier('bob', 'own'); B.c.setTier('alice', 'own');
|
|
273
|
+
// The accept rule (design §10.2) would land small files from an own contact unasked: asked here until its own part below.
|
|
274
|
+
ok(X.settings({ identity: B.identity }).auto_mb === 25 && X.settings({ identity: B.identity, patch: { auto_mb: 0 } }).auto_mb === 0, 'the accept rule: 25 MB by default; 0 (always ask) kept');
|
|
261
275
|
ok(X.directFor({ direct: {} }, { tier: 'own' }) === true && X.directFor({ direct: {} }, { tier: 'friend' }) === null && X.directFor({ direct: { d: false } }, { did: 'd', tier: 'own' }) === false, 'directFor: own on, others asked (null), a kept choice wins');
|
|
262
276
|
|
|
263
277
|
// Consent: a manifest is a question; nothing is written before the yes; decline tells the sender.
|
|
@@ -320,14 +334,40 @@ try {
|
|
|
320
334
|
ok(await until(() => B.rec('in', r5.id)?.state === 'cancelled'), 'the sender cancels: cancelled at the receiver');
|
|
321
335
|
ok(await failure(() => X.accept({ carrier: B.c, identity: B.identity, id: r5.id })) === 'transfer_state', 'a cancelled transfer cannot be accepted');
|
|
322
336
|
|
|
337
|
+
// The accept rule (design §10.2): from an own contact, under the size set, it lands without a question.
|
|
338
|
+
X.settings({ identity: B.identity, patch: { auto_mb: 25 } });
|
|
339
|
+
const small = seeded('auto', 2 * CHUNK + 1), r9 = await send(file('auto.jpg', small));
|
|
340
|
+
ok(await until(() => B.rec('in', r9.id)?.state === 'done', 120000), 'own contact, 2 MB under 25 MB: landed with no accept', JSON.stringify(B.rec('in', r9.id)));
|
|
341
|
+
ok(B.rec('in', r9.id)?.by === 'rule' && B.events.some((e) => e.what === 'landing' && e.id === r9.id) && !B.events.some((e) => e.what === 'asked' && e.id === r9.id), 'by the rule: a landing event, no question');
|
|
342
|
+
ok(createHash('sha256').update(readFileSync(B.rec('in', r9.id).saved)).digest('hex') === createHash('sha256').update(small).digest('hex'), 'and whole');
|
|
343
|
+
X.setAuto({ carrier: B.c, identity: B.identity, contact: 'alice', mb: 0 });
|
|
344
|
+
const r10 = await send(file('ask.bin', seeded('ask', 10)));
|
|
345
|
+
ok(await until(() => B.rec('in', r10.id)?.state === 'asked'), 'the contact set to always ask: asked');
|
|
346
|
+
await X.decline({ carrier: B.c, identity: B.identity, id: r10.id });
|
|
347
|
+
X.setAuto({ carrier: B.c, identity: B.identity, contact: 'alice', mb: null });
|
|
348
|
+
X.settings({ identity: B.identity, patch: { auto_mb: 1 } });
|
|
349
|
+
const r11 = await send(file('big2.bin', seeded('big2', 2 * CHUNK)));
|
|
350
|
+
ok(await until(() => B.rec('in', r11.id)?.state === 'asked'), 'larger than the size set (2 MB over 1 MB): asked');
|
|
351
|
+
await X.decline({ carrier: B.c, identity: B.identity, id: r11.id });
|
|
352
|
+
// A group's file (design §10.3): one transfer per member paired with; one reached only through the creator: unpaired.
|
|
353
|
+
const gf = await X.prepare({ carrier: A.c, identity: A.identity, path: file('g.bin', seeded('g', 5000)) });
|
|
354
|
+
const fan = await X.fanOut({ carrier: A.c, identity: A.identity, members: [{ did: B.did, name: 'bob', contact: true }, { did: 'did:sigelo:zCarol', name: 'carol', contact: false }], f: gf, group: 'ab'.repeat(16) });
|
|
355
|
+
ok(fan.sent.length === 1 && fan.sent[0].did === B.did && fan.unpaired.length === 1 && fan.unpaired[0].name === 'carol' && fan.failed.length === 0, 'fanOut: bob sent, carol unpaired', JSON.stringify(fan));
|
|
356
|
+
ok(A.rec('out', fan.sent[0].id)?.group === 'ab'.repeat(16) && A.rec('out', fan.sent[0].id)?.sha256 === gf.whole, 'the record names the group and the one hash');
|
|
357
|
+
ok(await until(() => B.rec('in', fan.sent[0].id)?.state === 'done', 120000), 'and bob\'s copy lands by the rule (under 1 MB)');
|
|
358
|
+
X.settings({ identity: B.identity, patch: { auto_mb: 0 } });
|
|
359
|
+
|
|
323
360
|
// No path: direct off on the receiver, no Tor: no_path, the free refusal's words.
|
|
324
361
|
X.setDirect({ carrier: B.c, identity: B.identity, contact: 'alice', on: false });
|
|
325
362
|
X.settings({ identity: B.identity, patch: { tor: false } });
|
|
326
363
|
const r6 = await send(file('np.bin', seeded('np', 10)));
|
|
327
364
|
await until(() => B.rec('in', r6.id)?.state === 'asked');
|
|
328
365
|
X.accept({ carrier: B.c, identity: B.identity, id: r6.id }); B.e.kick();
|
|
329
|
-
|
|
330
|
-
ok(
|
|
366
|
+
const np = () => B.events.find((e) => e.what === 'failed' && e.id === r6.id && e.reason === 'no_path');
|
|
367
|
+
ok(await until(() => np() && A.events.some((e) => e.what === 'failed' && e.id === r6.id && e.reason === 'no_path')), 'direct off and no Tor: no_path on both sides');
|
|
368
|
+
ok(/No direct path to alice .* and no Tor\. Up to 8 MiB: send-file/.test(np()?.detail ?? ''), 'the refusal names send-file', np()?.detail);
|
|
369
|
+
// (0.1.19) An own contact, under 8 MiB: the sender then sends it over the relay lane by itself; the receiver's record relayed.
|
|
370
|
+
ok(await until(() => A.rec('out', r6.id)?.path_used === 'relay' && B.rec('in', r6.id)?.state === 'relayed'), 'and it goes over the relay lane: done via relay, the receiver\'s record relayed', JSON.stringify([A.rec('out', r6.id), B.rec('in', r6.id)]));
|
|
331
371
|
X.settings({ identity: B.identity, patch: { tor: true } });
|
|
332
372
|
|
|
333
373
|
// ============================================================ Tor, against a fake tor (or a real one: SIGELO_TEST_TOR)
|