sigelo-contact 0.1.22 → 0.1.23
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/package.json +1 -1
- package/page.mjs +35 -6
- package/test-transfer-web.mjs +8 -0
- package/test-transfer.mjs +18 -0
- package/transfer-engine.mjs +40 -10
- package/transfer-node.mjs +4 -2
- package/transfer-web.mjs +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sigelo-contact",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.23",
|
|
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-apps (AGPL-3.0).",
|
|
6
6
|
"keywords": [
|
package/page.mjs
CHANGED
|
@@ -125,14 +125,17 @@
|
|
|
125
125
|
// host_peer); checked (capsOf: keys model, effort, permissionMode; others dropped; commands [{name, args?, help}], the chat
|
|
126
126
|
// commands it takes, a malformed row dropped), kept as data.host[did], never in the
|
|
127
127
|
// history; the contact's `host`. POST /api/host/set sends HOST_SET_LABEL {key, value} (a choice it offered) and marks it
|
|
128
|
-
// next until the agent says again.
|
|
128
|
+
// next until the agent says again. POST /api/host/ask sends HOST_SET_LABEL {ask: "caps"}: the host sends its caps again (the
|
|
129
|
+
// agent page's Ask again). A rename of an own agent that sent its caps (POST /api/rename, /api/agents/rename) also sends
|
|
130
|
+
// HOST_SET_LABEL {name}: the host says that name in its own lines and keeps it (hostName). A HOST_SET_LABEL that reaches a
|
|
131
|
+
// page: dropped (a page hosts nothing).
|
|
129
132
|
// The Session card (2026-11-28): the caps' `session` {folder, home, root, started, resumed, login: {state, account?, here},
|
|
130
133
|
// waits?} (sessionOf; malformed: dropped, the fields kept). POST /api/host/dirs, /api/host/session, /api/host/login send
|
|
131
134
|
// HOST_DIRS_LABEL {path, into?, id}, HOST_SESSION_LABEL {do, path?}, HOST_LOGIN_LABEL {do, code?}; the agent's answers on the
|
|
132
135
|
// same labels are kept beside its caps (host.dirs, host.session_ev, host.login_ev; checked by dirsOf, sessionEvOf,
|
|
133
136
|
// loginEvOf), never in the history; the code a person pastes is sent, never kept.
|
|
134
137
|
//
|
|
135
|
-
// The public invite (UI-API.md "Public
|
|
138
|
+
// The public invite (UI-API.md "Public code"): a public code (sigelo-public/0, carrier.mjs invitePublic), PUB-…
|
|
136
139
|
// with the four words and a link, for 1, 6 or 12 months, Pro only, kept in the contact store; each use a request to
|
|
137
140
|
// approve (/api/public/approve, /refuse) unless open; Pause and the cap: /api/public/set; Stop for good (Revoke for
|
|
138
141
|
// all): /api/invite/cancel {id}. An earlier version's 7-day long code (data.public) runs out as an ordinary invite.
|
|
@@ -883,6 +886,14 @@ export function makePage({ makeCarrier, link: L, linksFile, groups: G = null, gr
|
|
|
883
886
|
};
|
|
884
887
|
// The contact holding a worker's original DID, live, or null.
|
|
885
888
|
const contactOfWorker = (w) => carrier.contacts().contacts.find((x) => !x.revoked && x.chain.includes(w.original)) ?? null;
|
|
889
|
+
// A rename told to the agent's host (UX review A): an own agent that sent its caps (a host) gets HOST_SET_LABEL {name}; it
|
|
890
|
+
// says that name in its own lines and keeps it. Not sent (offline, refused): the rename stands here, the host keeps its own.
|
|
891
|
+
const hostName = async (c, name) => {
|
|
892
|
+
if (!c || !data.host?.[c.did] || typeof name !== 'string' || !(c.ours === true || c.tier === 'own' || c.chain?.some((d) => workerDids.has(d)))) return;
|
|
893
|
+
// Kept before anything else goes or is acknowledged (the flush rule), as every route that sends does.
|
|
894
|
+
try { await carrier.send(c.did, { name }, { label: HOST_SET_LABEL }); } catch {}
|
|
895
|
+
saveData();
|
|
896
|
+
};
|
|
886
897
|
// A contact's kind (UI-API.md "Kinds"): person, agent or desk (a support desk). The human's choice (POST /api/kind,
|
|
887
898
|
// data.kind) wins; else what the contact said of itself once paired (carrier.mjs "Kinds": kind_peer agent or desk);
|
|
888
899
|
// else an agent when the page knows it is one (my agent: ours by its operator attestation, on this machine, or a
|
|
@@ -1527,7 +1538,7 @@ export function makePage({ makeCarrier, link: L, linksFile, groups: G = null, gr
|
|
|
1527
1538
|
if (typeof b['statement'] !== 'string' || b['statement'].length > 4 * TEXT_MAX) refuse(400, 'body', 'statement: the signed text, as it was shared');
|
|
1528
1539
|
return checked(checkStatement(b['statement'], nowS()));
|
|
1529
1540
|
},
|
|
1530
|
-
//
|
|
1541
|
+
// How old this identity is (Me → How old this identity is): what this identity's own bundle shows of its age, checked (SPEC §9): the day its
|
|
1531
1542
|
// genesis names (its own word) and each attestation a world signed, with when.
|
|
1532
1543
|
'GET /api/attestations': () => {
|
|
1533
1544
|
const bundle = carrier.identity().bundle, r = verify(bundle, nowS());
|
|
@@ -1589,7 +1600,7 @@ export function makePage({ makeCarrier, link: L, linksFile, groups: G = null, gr
|
|
|
1589
1600
|
changed();
|
|
1590
1601
|
return { cancelled: true, ...(r.unparked !== undefined && { unparked: r.unparked }), ...(r.detail && { detail: r.detail }) };
|
|
1591
1602
|
}),
|
|
1592
|
-
// A public code's requests and settings (UI-API.md "Public
|
|
1603
|
+
// A public code's requests and settings (UI-API.md "Public code").
|
|
1593
1604
|
'POST /api/public/approve': (b) => serial(async () => {
|
|
1594
1605
|
if (typeof b['id'] !== 'string') refuse(400, 'body', 'id: a request\'s id (pending.public.requests[].id)');
|
|
1595
1606
|
const r = await carrier.approvePublic(b['id'], { started: startedBy(b) }).catch((e) => (e.check === 'challenge_unknown' ? refuse(404, 'request', e.message) : Promise.reject(e)));
|
|
@@ -1634,7 +1645,9 @@ export function makePage({ makeCarrier, link: L, linksFile, groups: G = null, gr
|
|
|
1634
1645
|
}),
|
|
1635
1646
|
'POST /api/rename': (b) => serial(async () => {
|
|
1636
1647
|
// A name another live contact holds is refused (409 name_taken): `send <name>` would refuse both.
|
|
1637
|
-
|
|
1648
|
+
const c = contactOf(b['contact']), r = await carrier.rename(c.did, cleanName(b['name'], 'name'));
|
|
1649
|
+
await hostName(c, r?.name ?? b['name']);
|
|
1650
|
+
return r;
|
|
1638
1651
|
}),
|
|
1639
1652
|
'POST /api/tier': (b) => serial(async () => {
|
|
1640
1653
|
const c = contactOf(b['contact']), tier = b['tier'];
|
|
@@ -1660,6 +1673,15 @@ export function makePage({ makeCarrier, link: L, linksFile, groups: G = null, gr
|
|
|
1660
1673
|
saveData(); changed();
|
|
1661
1674
|
return { did: c.did, host: h, status: r.status };
|
|
1662
1675
|
}),
|
|
1676
|
+
// Ask again (the agent page waiting for its settings): HOST_SET_LABEL {ask: "caps"}, which a host answers with its caps
|
|
1677
|
+
// (sigelo-agent-host.ts; an older host notes "Not a setting" and sends them too). My own agents only; nothing kept.
|
|
1678
|
+
'POST /api/host/ask': (b) => serial(async () => {
|
|
1679
|
+
const c = contactOf(b['contact']);
|
|
1680
|
+
if (!(c.ours === true || c.tier === 'own' || c.chain?.some((d) => workerDids.has(d)))) refuse(409, 'host_not_own', 'only your own agent is asked for its settings');
|
|
1681
|
+
const r = await carrier.send(c.did, { ask: 'caps' }, { label: HOST_SET_LABEL });
|
|
1682
|
+
saveData(); changed();
|
|
1683
|
+
return { did: c.did, status: r.status };
|
|
1684
|
+
}),
|
|
1663
1685
|
// The Session card (the header's): a folder listing, a new session (or in another folder), the login; the agent answers on the
|
|
1664
1686
|
// same label. Only to an agent whose caps carry the session.
|
|
1665
1687
|
'POST /api/host/dirs': (b) => serial(async () => {
|
|
@@ -1963,6 +1985,7 @@ export function makePage({ makeCarrier, link: L, linksFile, groups: G = null, gr
|
|
|
1963
1985
|
if (same) refuse(409, 'name_taken', `${name} is worker ${same[0]} already: another name`);
|
|
1964
1986
|
const c = contactOfWorker(w);
|
|
1965
1987
|
if (c && c.name !== name) carrier.rename(c.did, name);
|
|
1988
|
+
if (c) await hostName(c, name);
|
|
1966
1989
|
await K.update((x) => { if (x.workers[i]) x.workers[i].name = name; });
|
|
1967
1990
|
changed();
|
|
1968
1991
|
return { worker: i, name };
|
|
@@ -2238,7 +2261,12 @@ function transferRoutes({ X, engine, host, carrier, identity, serial, contactOf,
|
|
|
2238
2261
|
'POST /api/transfers/cancel': (b) => serial(() => call(async () => strip(await X.cancel({ carrier, identity, id: idOf(b), engine })))),
|
|
2239
2262
|
'POST /api/transfers/forget': (b) => serial(() => call(async () => strip(X.forget({ carrier, identity, id: idOf(b), engine })))),
|
|
2240
2263
|
'POST /api/transfers/direct': (b) => serial(() => call(async () => {
|
|
2241
|
-
|
|
2264
|
+
// A contact's route (Settings → Privacy's choice, per contact): direct, relay, tor, or null (the default again).
|
|
2265
|
+
if (b['route'] !== undefined) {
|
|
2266
|
+
if (b['route'] !== null && !['direct', 'relay', 'tor'].includes(b['route'])) refuse(400, 'body', 'route: direct, relay, tor or null (the default)');
|
|
2267
|
+
return X.setRoute({ carrier, identity, contact: contactOf(b['contact']).did, route: b['route'] });
|
|
2268
|
+
}
|
|
2269
|
+
if (typeof b['on'] !== 'boolean') refuse(400, 'body', 'on: true or false (or route)');
|
|
2242
2270
|
return X.setDirect({ carrier, identity, contact: contactOf(b['contact']).did, on: b['on'] });
|
|
2243
2271
|
})),
|
|
2244
2272
|
'GET /api/transfers/settings': () => settings(),
|
|
@@ -2248,6 +2276,7 @@ function transferRoutes({ X, engine, host, carrier, identity, serial, contactOf,
|
|
|
2248
2276
|
if (b['prefer'] !== undefined) { if (b['prefer'] !== 'fast' && b['prefer'] !== 'private') refuse(400, 'body', 'prefer: fast or private'); patch.prefer = b['prefer']; }
|
|
2249
2277
|
if (b['auto_mb'] !== undefined) { if (typeof b['auto_mb'] !== 'number' || !Number.isFinite(b['auto_mb']) || b['auto_mb'] < 0) refuse(400, 'body', 'auto_mb: a size in MB, 0: always ask'); patch.auto_mb = b['auto_mb']; }
|
|
2250
2278
|
if (b['keep_location'] !== undefined) { if (typeof b['keep_location'] !== 'boolean') refuse(400, 'body', 'keep_location: true or false'); patch.keep_location = b['keep_location']; }
|
|
2279
|
+
if (b['route'] !== undefined) { if (b['route'] !== null && !['direct', 'relay', 'tor'].includes(b['route'])) refuse(400, 'body', 'route: direct, relay, tor or null'); patch.route = b['route']; }
|
|
2251
2280
|
X.settings({ identity, patch });
|
|
2252
2281
|
return settings();
|
|
2253
2282
|
})),
|
package/test-transfer-web.mjs
CHANGED
|
@@ -168,6 +168,14 @@ const TURN = { urls: ['turn:relay.test:3478?transport=udp', 'turn:relay.test:347
|
|
|
168
168
|
// "Always relay my media" (UI-API.md "Settings"): the policy, the page's peer under it, the engine's.
|
|
169
169
|
ok(eng({}, {}).policyNow() === 'all' && eng({ policy: () => 'relay' }, {}).policyNow() === 'relay' && eng({ env: { SIGELO_ICE_POLICY: 'relay' } }, {}).policyNow() === 'relay'
|
|
170
170
|
&& eng({ policy: () => { throw new Error('x'); } }, {}).policyNow() === 'all', 'the engine\'s policy: the setting (policy()) or SIGELO_ICE_POLICY=relay; else all');
|
|
171
|
+
{
|
|
172
|
+
// A contact's route "relay" (the app's How files go): the direct lane only through TURN for that contact alone.
|
|
173
|
+
let rec = JSON.stringify({ v: E.FILE_V, out: {}, in: {}, direct: { 'did:x:r': 'relay', 'did:x:d': true }, auto: {}, settings: {} });
|
|
174
|
+
const io = { lock: (f) => f(), read: () => rec, write: (t) => { rec = t; } };
|
|
175
|
+
const e = eng({ io }, {});
|
|
176
|
+
ok(e.policyNow({ did: 'did:x:r', tier: 'friend' }) === 'relay' && e.policyNow({ did: 'did:x:d', tier: 'friend' }) === 'all' && e.policyNow() === 'all',
|
|
177
|
+
'the engine\'s policy per contact: route relay → relay for that one; direct → all');
|
|
178
|
+
}
|
|
171
179
|
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
180
|
cfg = null;
|
|
173
181
|
class RS { constructor(c) { cfg = c; this.iceGatheringState = 'complete'; this.localDescription = null; } addEventListener() {} createDataChannel() { return { readyState: 'connecting', addEventListener() {} }; }
|
package/test-transfer.mjs
CHANGED
|
@@ -269,6 +269,24 @@ try {
|
|
|
269
269
|
// The direct switch: friend contacts are asked once; own ones are on.
|
|
270
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');
|
|
271
271
|
ok(X.list({ carrier: A.c, identity: A.identity }).out.length === 0, 'and nothing was sent');
|
|
272
|
+
// The route (the app's Settings → Privacy): a default for everyone answers instead of the question; per contact over it.
|
|
273
|
+
const R = (direct, settings = {}) => ({ direct, settings });
|
|
274
|
+
ok(X.routeFor(R({}, { route: 'relay' }), { did: 'd', tier: 'friend' }) === 'relay' && X.directFor(R({}, { route: 'relay' }), { did: 'd', tier: 'friend' }) === true
|
|
275
|
+
&& X.directFor(R({}, { route: 'tor' }), { did: 'd', tier: 'friend' }) === false && X.routeFor(R({}, { route: 'tor' }), { did: 'd', tier: 'own' }) === 'direct'
|
|
276
|
+
&& X.routeFor(R({ d: 'relay' }, { route: 'tor' }), { did: 'd', tier: 'friend' }) === 'relay' && X.routeFor(R({ d: false }), { did: 'd', tier: 'own' }) === 'tor',
|
|
277
|
+
'routeFor: per contact first ("relay" kept), own direct, then the default; directFor reads relay as direct, tor as off');
|
|
278
|
+
const dset = X.settings({ identity: A.identity, patch: { route: 'relay' } });
|
|
279
|
+
const noFile = await failure(() => send(join(dir, 'not-there.bin')));
|
|
280
|
+
ok(dset.route === 'relay' && noFile !== 'direct_ask' && noFile !== 'accepted' && !(Object.keys(X.list({ carrier: A.c, identity: A.identity }).route).length), `a default route set: the send is not asked (it got to the file: ${noFile}), nothing kept per contact`);
|
|
281
|
+
const sr = X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: 'tor' }), L1 = X.list({ carrier: A.c, identity: A.identity });
|
|
282
|
+
ok(sr.route === 'tor' && sr.uses === 'tor' && L1.route[sr.did] === 'tor' && L1.direct[sr.did] === false, 'setRoute: bob tor, listed (route tor, direct false)');
|
|
283
|
+
X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: 'relay' });
|
|
284
|
+
const L2 = X.list({ carrier: A.c, identity: A.identity });
|
|
285
|
+
ok(L2.route[sr.did] === 'relay' && L2.direct[sr.did] === true, 'setRoute relay: listed relay, direct true for older pages');
|
|
286
|
+
const back = X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: null });
|
|
287
|
+
ok(back.route === null && back.uses === 'relay' && !(sr.did in X.list({ carrier: A.c, identity: A.identity }).route) && await failure(() => X.setRoute({ carrier: A.c, identity: A.identity, contact: 'bob', route: 'fast' })) === 'usage',
|
|
288
|
+
'setRoute null: the default again (relay); a route not one of three: usage');
|
|
289
|
+
ok(X.settings({ identity: A.identity, patch: { route: null } }).route === null && await failure(() => X.settings({ identity: A.identity, patch: { route: 'x' } })) === 'usage', 'settings route null: none again; a bad one: usage');
|
|
272
290
|
A.c.setTier('bob', 'own'); B.c.setTier('alice', 'own');
|
|
273
291
|
// The accept rule would land small files from an own contact unasked: asked here until its own part below.
|
|
274
292
|
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');
|
package/transfer-engine.mjs
CHANGED
|
@@ -13,8 +13,14 @@
|
|
|
13
13
|
// tor: null | { caps(), serve(engine, side, r, a), connect(engine, side, r, x, a), close(a) },
|
|
14
14
|
// flushEach: chunks between flushes (Node 8; the phone 1: the bitmap saved after every chunk) }
|
|
15
15
|
//
|
|
16
|
-
// The records file: { v, out: { id: sender's record }, in: { id: receiver's record }, direct: { DID: true|false },
|
|
17
|
-
// auto: { DID: MB (0: always ask) }, settings: { tor, prefer, auto_mb, keep_location } }.
|
|
16
|
+
// The records file: { v, out: { id: sender's record }, in: { id: receiver's record }, direct: { DID: true|false|"relay" },
|
|
17
|
+
// auto: { DID: MB (0: always ask) }, settings: { tor, prefer, auto_mb, keep_location, route } }.
|
|
18
|
+
//
|
|
19
|
+
// The route (how a contact's files go, the app's Settings → Privacy): "direct" (the direct lane, the contact sees this
|
|
20
|
+
// device's addresses), "relay" (the direct lane only through the relay's TURN, as "Always relay my media" for that
|
|
21
|
+
// contact alone: the contact sees the relay's address) or "tor" (no direct lane: Tor, else the relay lane up to 8 MiB).
|
|
22
|
+
// Per contact: direct[DID] (true: direct, "relay", false: tor); else own agents and contacts direct; else settings.route,
|
|
23
|
+
// the default for everyone; none set (the CLI's start): asked (direct_ask), as before.
|
|
18
24
|
//
|
|
19
25
|
// The accept rule: a file lands without a question up to the size set
|
|
20
26
|
// (settings.auto_mb, default 25 MB; per contact auto[DID]) from own agents and own contacts (tier own,
|
|
@@ -86,8 +92,14 @@ export function contactOf(carrier, who) {
|
|
|
86
92
|
return hit[0];
|
|
87
93
|
}
|
|
88
94
|
const own = (c) => c.tier === 'own' || c.ours === true;
|
|
89
|
-
|
|
90
|
-
|
|
95
|
+
export const ROUTES = ['direct', 'relay', 'tor'];
|
|
96
|
+
const routeOfDirect = (v) => (v === true ? 'direct' : v === 'relay' ? 'relay' : v === false ? 'tor' : null);
|
|
97
|
+
const directOfRoute = (r) => (r === 'direct' ? true : r === 'relay' ? 'relay' : r === 'tor' ? false : undefined);
|
|
98
|
+
const routeDefault = (s) => (ROUTES.includes(s.settings?.route) ? s.settings.route : null);
|
|
99
|
+
/** How this contact's files go: "direct", "relay" or "tor"; null: not asked yet (no choice for them, no default). */
|
|
100
|
+
export const routeFor = (s, c) => (Object.hasOwn(s.direct, c.did) ? routeOfDirect(s.direct[c.did]) : own(c) ? 'direct' : routeDefault(s));
|
|
101
|
+
/** May this contact learn this agent's addresses (direct)? true (direct, or through the relay's TURN), false, or null: not asked yet (never for own). */
|
|
102
|
+
export const directFor = (s, c) => { const r = routeFor(s, c); return r === null ? null : r !== 'tor'; };
|
|
91
103
|
const decideDirect = (s, c, direct) => {
|
|
92
104
|
if (direct === true || direct === false) { s.direct[c.did] = direct; return direct; }
|
|
93
105
|
const d = directFor(s, c);
|
|
@@ -101,7 +113,7 @@ export function trustOf(c, compared = () => false) {
|
|
|
101
113
|
return compared(c.did) ? 'compared' : 'other';
|
|
102
114
|
}
|
|
103
115
|
export const autoDefault = (s) => (Number.isFinite(s.settings.auto_mb) && s.settings.auto_mb >= 0 ? s.settings.auto_mb : AUTO_MB);
|
|
104
|
-
const settingsOf = (s) => ({ tor: s.settings.tor !== false, prefer: s.settings.prefer === 'private' ? 'private' : 'fast', auto_mb: autoDefault(s), keep_location: s.settings.keep_location === true });
|
|
116
|
+
const settingsOf = (s) => ({ tor: s.settings.tor !== false, prefer: s.settings.prefer === 'private' ? 'private' : 'fast', auto_mb: autoDefault(s), keep_location: s.settings.keep_location === true, route: routeDefault(s) });
|
|
105
117
|
const sendMsg = (carrier, to, content, local) => carrier.send(to, content, { label: TRANSFER_LABEL, internal: TRANSFER_SEND, local });
|
|
106
118
|
|
|
107
119
|
// ---------------------------------------------------------------- the verbs
|
|
@@ -276,7 +288,9 @@ export function list({ carrier, io, engine = null }) {
|
|
|
276
288
|
return {
|
|
277
289
|
out: Object.values(s.out).map((r) => { const { file: _f, ...x } = live(r); return x; }).sort(sort),
|
|
278
290
|
in: Object.values(s.in).map((r) => (stale(r, now) && !engine?.attempts.get(r.id)?.channel ? { ...live(r), state: 'interrupted', reason: 'stalled', detail: staleDetail(r) } : live(r))).sort(sort),
|
|
279
|
-
direct:
|
|
291
|
+
// direct: true|false for older pages ("relay" reads true: the direct lane, through TURN); route: each one's route.
|
|
292
|
+
direct: Object.fromEntries(Object.entries(s.direct).map(([k, v]) => [k, v !== false])),
|
|
293
|
+
route: Object.fromEntries(Object.entries(s.direct).map(([k, v]) => [k, routeOfDirect(v)])),
|
|
280
294
|
auto: { ...s.auto },
|
|
281
295
|
settings: settingsOf(s),
|
|
282
296
|
};
|
|
@@ -287,6 +301,15 @@ export function setDirect({ carrier, io, contact, on }) {
|
|
|
287
301
|
const c = contactOf(carrier, contact);
|
|
288
302
|
return state(io, nowS(carrier), (s) => { s.direct[c.did] = on; return { did: c.did, name: c.name, direct: on }; });
|
|
289
303
|
}
|
|
304
|
+
/** A contact's route ("direct", "relay", "tor"), or null: back to the default (own: direct; else settings.route). */
|
|
305
|
+
export function setRoute({ carrier, io, contact, route }) {
|
|
306
|
+
if (route !== null && !ROUTES.includes(route)) fail('usage', 'route: direct, relay, tor or null (the default)');
|
|
307
|
+
const c = contactOf(carrier, contact);
|
|
308
|
+
return state(io, nowS(carrier), (s) => {
|
|
309
|
+
if (route === null) delete s.direct[c.did]; else s.direct[c.did] = directOfRoute(route);
|
|
310
|
+
return { did: c.did, name: c.name, route, uses: routeFor(s, c) };
|
|
311
|
+
});
|
|
312
|
+
}
|
|
290
313
|
const mbOk = (x) => Number.isFinite(x) && x >= 0 && x <= MAX_SIZE / 1e6;
|
|
291
314
|
/** A contact's own size for the accept rule: MB (0: always ask), or null: the default. */
|
|
292
315
|
export function setAuto({ carrier, io, contact, mb }) {
|
|
@@ -297,14 +320,17 @@ export function setAuto({ carrier, io, contact, mb }) {
|
|
|
297
320
|
return { did: c.did, name: c.name, auto_mb: mb };
|
|
298
321
|
});
|
|
299
322
|
}
|
|
300
|
-
/** The settings, patched: { tor: true|false, prefer: 'fast'|'private', auto_mb: MB (0: always ask), keep_location: camera photos keep their location tags (default false: removed)
|
|
323
|
+
/** The settings, patched: { tor: true|false, prefer: 'fast'|'private', auto_mb: MB (0: always ask), keep_location: camera photos keep their location tags (default false: removed),
|
|
324
|
+
* route: 'direct'|'relay'|'tor' (how files go for everyone without a choice of their own), null: none (asked) }. */
|
|
301
325
|
export function settings({ io, patch = {}, now = Math.floor(Date.now() / 1000) }) {
|
|
302
326
|
if (patch.tor !== undefined && typeof patch.tor !== 'boolean') fail('usage', 'tor: on or off');
|
|
303
327
|
if (patch.prefer !== undefined && patch.prefer !== 'fast' && patch.prefer !== 'private') fail('usage', 'prefer: fast or private');
|
|
304
328
|
if (patch.auto_mb !== undefined && !mbOk(patch.auto_mb)) fail('usage', 'auto_mb: 0 (always ask) to 17179');
|
|
305
329
|
if (patch.keep_location !== undefined && typeof patch.keep_location !== 'boolean') fail('usage', 'keep_location: true or false');
|
|
330
|
+
if (patch.route !== undefined && patch.route !== null && !ROUTES.includes(patch.route)) fail('usage', 'route: direct, relay, tor or null');
|
|
306
331
|
return state(io, now, (s) => {
|
|
307
332
|
for (const k of ['tor', 'prefer', 'auto_mb', 'keep_location']) if (patch[k] !== undefined) s.settings[k] = patch[k];
|
|
333
|
+
if (patch.route === null) delete s.settings.route; else if (patch.route !== undefined) s.settings.route = patch.route;
|
|
308
334
|
return settingsOf(s);
|
|
309
335
|
});
|
|
310
336
|
}
|
|
@@ -351,11 +377,15 @@ export class Engine {
|
|
|
351
377
|
stunOf(c) { return this.stun ?? stunFor(this.carrier, c, this.env); }
|
|
352
378
|
/** The TURN server for an attempt starting now (relay/turn.mjs, fresh credentials), or null: STUN alone, as before.
|
|
353
379
|
* rtc: the direct path's module; only one with TURN_OK true gets one (werift: apps/transfer/rtc.mjs, with its DTLS checks). */
|
|
354
|
-
/** The ICE policy of an attempt starting now: "relay" when the setting or
|
|
355
|
-
policyNow(
|
|
380
|
+
/** The ICE policy of an attempt starting now: "relay" when the setting, SIGELO_ICE_POLICY or contact c's route says so, else "all". */
|
|
381
|
+
policyNow(c = null) {
|
|
382
|
+
let p = null; try { p = typeof this.policy === 'function' ? this.policy() : this.policy; } catch {}
|
|
383
|
+
if (p === 'relay' || this.env.SIGELO_ICE_POLICY === 'relay') return 'relay';
|
|
384
|
+
return c && this.st((s) => routeFor(s, c)) === 'relay' ? 'relay' : 'all';
|
|
385
|
+
}
|
|
356
386
|
/** The direct lane's peer for an attempt, under the policy: { peer, turn } or { peer: null } (relay only, no TURN). */
|
|
357
387
|
async #peerFor(rtc, c) {
|
|
358
|
-
const policy = this.policyNow(), turn = await this.turnOf(rtc);
|
|
388
|
+
const policy = this.policyNow(c), turn = await this.turnOf(rtc);
|
|
359
389
|
if (policy === 'relay' && turn === null) return { peer: null, turn: null };
|
|
360
390
|
return { peer: await rtc.peer({ stun: this.stunOf(c), turn, gatherMs: GATHER_MS, ...(policy === 'relay' && { policy }) }), turn };
|
|
361
391
|
}
|
package/transfer-node.mjs
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
// accept({ carrier, identity, id, direct, via, local }) the receiver's yes (free disk checked); the engine offers
|
|
14
14
|
// decline / cancel / resume / forget({ carrier, identity, id, local })
|
|
15
15
|
// intake({ carrier, identity, compared }) → the files asked: manifests and ends filed by a process with no engine (inbox)
|
|
16
|
-
// list({ carrier, identity }) → { out, in, direct, auto, settings }; setDirect({ carrier, identity, contact, on });
|
|
16
|
+
// list({ carrier, identity }) → { out, in, direct, route, auto, settings }; setDirect({ carrier, identity, contact, on });
|
|
17
|
+
// setRoute({ carrier, identity, contact, route }) (direct, relay, tor; null: the default)
|
|
17
18
|
// setAuto({ carrier, identity, contact, mb }); settings({ identity, patch })
|
|
18
19
|
// const e = new Engine({ carrier, identity, rtc, tor, stun, pro, compared, onEvent }); e.kick(); await e.idle(); e.live(); await e.close()
|
|
19
20
|
//
|
|
@@ -43,7 +44,7 @@ import { sendable, transact } from './platform-node.mjs';
|
|
|
43
44
|
import * as E from './transfer-engine.mjs';
|
|
44
45
|
import { CHUNK, MAX_SIZE, T, TRANSFER_LABEL, chunkLength, chunksOf, deframer, enframe, frames, readFrame } from './transfer.mjs';
|
|
45
46
|
|
|
46
|
-
export const { FILE_V, contactOf, directFor, trustOf } = E;
|
|
47
|
+
export const { FILE_V, contactOf, directFor, routeFor, trustOf } = E;
|
|
47
48
|
export { TRANSFER_LABEL };
|
|
48
49
|
const TOR_CONNECT_MS = 120_000, TOR_PROBE_MS = 1500;
|
|
49
50
|
|
|
@@ -169,6 +170,7 @@ export const cancel = (o) => E.cancel({ ...o, io: ioOf(o) });
|
|
|
169
170
|
export const forget = (o) => E.forget({ ...o, io: ioOf(o) });
|
|
170
171
|
export const list = (o) => E.list({ ...o, io: ioOf(o) });
|
|
171
172
|
export const setDirect = (o) => E.setDirect({ ...o, io: ioOf(o) });
|
|
173
|
+
export const setRoute = (o) => E.setRoute({ ...o, io: ioOf(o) });
|
|
172
174
|
export const setAuto = (o) => E.setAuto({ ...o, io: ioOf(o) });
|
|
173
175
|
export const settings = ({ identity, patch, now }) => E.settings({ io: nodeIo(identity), patch, ...(now !== undefined && { now }) });
|
|
174
176
|
/** The STUN servers for a transfer with contact c: SIGELO_STUN, else this agent's relay host and the contact's, port 3478. */
|
package/transfer-web.mjs
CHANGED
|
@@ -70,7 +70,7 @@ export function webTransfers(io, { compared = () => false, rtc = null } = {}) {
|
|
|
70
70
|
return {
|
|
71
71
|
io,
|
|
72
72
|
send: w(E.send), accept: w(E.accept), resume: w(E.resume), retry: w(E.retry), decline: w(E.decline), cancel: w(E.cancel), forget: w(E.forget),
|
|
73
|
-
list: w(E.list), setDirect: w(E.setDirect), setAuto: w(E.setAuto), settings: ({ patch, now } = {}) => E.settings({ io, patch, ...(now !== undefined && { now }) }),
|
|
73
|
+
list: w(E.list), setDirect: w(E.setDirect), setRoute: w(E.setRoute), setAuto: w(E.setAuto), settings: ({ patch, now } = {}) => E.settings({ io, patch, ...(now !== undefined && { now }) }),
|
|
74
74
|
prepare: w(E.prepare), sendTo: w(E.sendTo), fanOut: w(E.fanOut), contactOf: E.contactOf, trustOf: E.trustOf,
|
|
75
75
|
intake: ({ carrier }) => E.intake({ carrier, io, compared }),
|
|
76
76
|
torCaps: async () => ({ serve: false, connect: false }), torConfig: () => null,
|