@ours.network/tg-connector 0.1.8-nightly.1 → 0.1.8-nightly.2
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/dist/connector.js
CHANGED
|
@@ -26072,6 +26072,10 @@ var TG_NET = {
|
|
|
26072
26072
|
};
|
|
26073
26073
|
var log = (...parts) => process.stderr.write(`ours-tg: ${parts.join(" ")}
|
|
26074
26074
|
`);
|
|
26075
|
+
function binHexField(av, field) {
|
|
26076
|
+
const x = av.Reduce(field);
|
|
26077
|
+
return x.IsNil() ? "" : Buffer.from(x.GetBinary()).toString("hex");
|
|
26078
|
+
}
|
|
26075
26079
|
var NAME_RE = /^[A-Za-z0-9 _.-]{1,64}$/;
|
|
26076
26080
|
function validateName(name) {
|
|
26077
26081
|
if (!NAME_RE.test(name)) return "name must be 1-64 chars of letters, digits, space, _ . or -";
|
|
@@ -26165,6 +26169,35 @@ async function contactRestoreSweep(pkt) {
|
|
|
26165
26169
|
log(`[${pkt.name}] contact-restore sweep failed:`, String(err));
|
|
26166
26170
|
}
|
|
26167
26171
|
}
|
|
26172
|
+
async function migrationSweep(pkt) {
|
|
26173
|
+
try {
|
|
26174
|
+
const { initiated, redriven, superseded, stalled } = await withScopeAsync(async (lt) => {
|
|
26175
|
+
const r = await pkt.mutatingTx("::a2a_messaging::sweep_e2e_migrations", {}, lt);
|
|
26176
|
+
return {
|
|
26177
|
+
initiated: Number(r.Reduce("initiated").Visualize()),
|
|
26178
|
+
redriven: Number(r.Reduce("redriven").Visualize()),
|
|
26179
|
+
superseded: Number(r.Reduce("superseded").Visualize()),
|
|
26180
|
+
stalled: Number(r.Reduce("stalled").Visualize())
|
|
26181
|
+
};
|
|
26182
|
+
});
|
|
26183
|
+
if (initiated + redriven + superseded + stalled > 0) {
|
|
26184
|
+
log(`[${pkt.name}] e2e migration sweep: ${initiated} offered, ${redriven} re-driven, ${superseded} superseded, ${stalled} stalled`);
|
|
26185
|
+
}
|
|
26186
|
+
} catch (err) {
|
|
26187
|
+
log(`[${pkt.name}] e2e migration sweep failed:`, String(err));
|
|
26188
|
+
}
|
|
26189
|
+
}
|
|
26190
|
+
async function readvertiseOnUpgrade(pkt) {
|
|
26191
|
+
try {
|
|
26192
|
+
const readvertised = await withScopeAsync(async (lt) => {
|
|
26193
|
+
const r = await pkt.mutatingTx("::a2a_messaging::readvertise_on_upgrade", {}, lt);
|
|
26194
|
+
return Number(r.Reduce("readvertised").Visualize());
|
|
26195
|
+
});
|
|
26196
|
+
if (readvertised > 0) log(`[${pkt.name}] re-advertised v2 AD to ${readvertised} pre-existing legacy contact(s) (migration bootstrap)`);
|
|
26197
|
+
} catch (err) {
|
|
26198
|
+
log(`[${pkt.name}] readvertise-on-upgrade sweep failed:`, String(err));
|
|
26199
|
+
}
|
|
26200
|
+
}
|
|
26168
26201
|
function botLabel(bot) {
|
|
26169
26202
|
return bot.username ? `${bot.name} (@${bot.username})` : bot.name;
|
|
26170
26203
|
}
|
|
@@ -26476,6 +26509,38 @@ function activateRoute(conn) {
|
|
|
26476
26509
|
const cid = payload.Reduce("container_id").Visualize();
|
|
26477
26510
|
log(`[${cfg.name}] contact "${name}" restored (re-keyed)`);
|
|
26478
26511
|
process.nextTick(() => void flushDeferredFor(pkt, String(cid)));
|
|
26512
|
+
} else if (event === "migration_active") {
|
|
26513
|
+
const cid = payload.Reduce("cid").Visualize();
|
|
26514
|
+
const role = payload.Reduce("role").Visualize();
|
|
26515
|
+
const epoch = binHexField(payload, "epoch");
|
|
26516
|
+
const sid = binHexField(payload, "session_id");
|
|
26517
|
+
log(`[${cfg.name}] [migration] active cid=${cid} role=${role}${epoch ? ` epoch=${epoch}` : ""}${sid ? ` session_id=${sid}` : ""}`);
|
|
26518
|
+
} else if (event === "e2e_app_send") {
|
|
26519
|
+
const cid = payload.Reduce("cid").Visualize();
|
|
26520
|
+
const sid = binHexField(payload, "session_id");
|
|
26521
|
+
const olm = payload.Reduce("olm_type").Visualize();
|
|
26522
|
+
const wireId = payload.Reduce("wire_id").Visualize();
|
|
26523
|
+
log(`[${cfg.name}] [e2e-app] send cid=${cid} session_id=${sid} olm_type=${olm} wire_id=${wireId}`);
|
|
26524
|
+
} else if (event === "e2e_app_recv") {
|
|
26525
|
+
const cid = payload.Reduce("cid").Visualize();
|
|
26526
|
+
const sid = binHexField(payload, "session_id");
|
|
26527
|
+
const ok = payload.Reduce("ok").GetBoolean();
|
|
26528
|
+
const wireId = payload.Reduce("wire_id").Visualize();
|
|
26529
|
+
log(`[${cfg.name}] [e2e-app] recv cid=${cid} session_id=${sid} ok=${ok} wire_id=${wireId}`);
|
|
26530
|
+
} else if (event === "migration_deferred_flush") {
|
|
26531
|
+
const cid = payload.Reduce("cid").Visualize();
|
|
26532
|
+
const wireId = payload.Reduce("wire_id").Visualize();
|
|
26533
|
+
log(`[${cfg.name}] [migration] flush-notify cid=${cid} wire_id=${wireId} (deferred->e2e; core delivers)`);
|
|
26534
|
+
} else if (event === "migration_stalled") {
|
|
26535
|
+
const cid = payload.Reduce("cid").Visualize();
|
|
26536
|
+
const phase = payload.Reduce("phase").Visualize();
|
|
26537
|
+
const attempts = payload.Reduce("attempts").Visualize();
|
|
26538
|
+
log(`[${cfg.name}] [migration] stalled-notify cid=${cid} phase=${phase} attempts=${attempts} (core re-drives via sweep)`);
|
|
26539
|
+
} else if (event === "downgrade_refused") {
|
|
26540
|
+
const cid = payload.Reduce("cid").Visualize();
|
|
26541
|
+
const wireAv = payload.Reduce("wire_id");
|
|
26542
|
+
const wireId = wireAv.IsNil() ? "" : String(wireAv.Visualize());
|
|
26543
|
+
log(`[${cfg.name}] [e2e-route] downgrade-dropped cid=${cid}${wireId ? ` wire_id=${wireId}` : ""} (legacy plaintext from a migrated peer \u2014 dropped by core)`);
|
|
26479
26544
|
}
|
|
26480
26545
|
}
|
|
26481
26546
|
},
|
|
@@ -26598,6 +26663,13 @@ async function restoreConnection(name) {
|
|
|
26598
26663
|
const key = isCatchAll(cfg.chatId) ? "any chat" : chatKey(cfg.chatId, cfg.threadId || void 0);
|
|
26599
26664
|
log(`[${name}] restored (bot ${botLabel(bot)}, ${key}${cfg.peerCid ? `, peer ${cfg.peerCid}` : ", awaiting proxy"})`);
|
|
26600
26665
|
await contactRestoreSweep(pkt);
|
|
26666
|
+
await readvertiseOnUpgrade(pkt);
|
|
26667
|
+
for (const ms of [1e4, 3e4, 9e4]) {
|
|
26668
|
+
setTimeout(() => {
|
|
26669
|
+
void readvertiseOnUpgrade(pkt);
|
|
26670
|
+
}, ms);
|
|
26671
|
+
}
|
|
26672
|
+
await migrationSweep(pkt);
|
|
26601
26673
|
process.nextTick(() => void processControlRequests(conn));
|
|
26602
26674
|
}
|
|
26603
26675
|
function removeConnection(name) {
|
|
@@ -26796,6 +26868,8 @@ function startRestoreSweepTimer() {
|
|
|
26796
26868
|
try {
|
|
26797
26869
|
for (const conn of connections.values()) {
|
|
26798
26870
|
await contactRestoreSweep(conn.pkt);
|
|
26871
|
+
await readvertiseOnUpgrade(conn.pkt);
|
|
26872
|
+
await migrationSweep(conn.pkt);
|
|
26799
26873
|
}
|
|
26800
26874
|
} finally {
|
|
26801
26875
|
restoreSweepRunning = false;
|
|
Binary file
|
package/dist/mufl_code/actor.mu
CHANGED
|
@@ -497,6 +497,25 @@ application actor loads libraries
|
|
|
497
497
|
$secrets -> (,)
|
|
498
498
|
).
|
|
499
499
|
}
|
|
500
|
+
// core 0.8.0/0.9.0 — end-to-end double-ratchet + its migration FSM. The
|
|
501
|
+
// connector runs the DR-routing core unconditionally, so it always speaks
|
|
502
|
+
// the e2e_signed_message envelope (core.e2e) and participates in the
|
|
503
|
+
// per-connection migration handshake (core.e2e.migrate). Advertised here so
|
|
504
|
+
// a controller's get_manifest / self_supports sees them; the peer-facing
|
|
505
|
+
// auto-migration trigger is driven by the $advertise wire piggyback below
|
|
506
|
+
// (self_advertises reads init's $advertise, not this describe() map).
|
|
507
|
+
caps a2a_capabilities::cap_e2e -> (
|
|
508
|
+
$cap -> a2a_capabilities::cap_e2e,
|
|
509
|
+
$version -> 1,
|
|
510
|
+
$params -> "",
|
|
511
|
+
$secrets -> (,)
|
|
512
|
+
).
|
|
513
|
+
caps a2a_capabilities::cap_e2e_migrate -> (
|
|
514
|
+
$cap -> a2a_capabilities::cap_e2e_migrate,
|
|
515
|
+
$version -> 1,
|
|
516
|
+
$params -> "",
|
|
517
|
+
$secrets -> (,)
|
|
518
|
+
).
|
|
500
519
|
return (
|
|
501
520
|
$version -> 1,
|
|
502
521
|
$app_id -> "network.ours.telegram-connector",
|
|
@@ -515,6 +534,14 @@ application actor loads libraries
|
|
|
515
534
|
a2a_capabilities::init (
|
|
516
535
|
$describe -> build_manifest,
|
|
517
536
|
$supported -> [],
|
|
537
|
+
// $advertise (core 0.9.0): PROTOCOL-surface capability ids carried on the
|
|
538
|
+
// wire piggyback ($caps in invite/restore/migration legs) -> self_caps, so
|
|
539
|
+
// self_advertises(cap_e2e_migrate)=TRUE (which gates mig_should_trigger) AND
|
|
540
|
+
// peers LEARN these into contact_caps. This — not the $describe manifest — is
|
|
541
|
+
// what makes an existing contact auto-migrate to the double ratchet once both
|
|
542
|
+
// sides advertise (§5.4). No handler needed (unlike $supported): these ids
|
|
543
|
+
// gate traffic shaping only and never route through dispatch.
|
|
544
|
+
$advertise -> [ a2a_capabilities::cap_e2e, a2a_capabilities::cap_e2e_migrate ],
|
|
518
545
|
$handlers -> (,),
|
|
519
546
|
$on_unknown -> fn (_: any) -> transaction::action::type[] { return []. }
|
|
520
547
|
).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ours.network/tg-connector",
|
|
3
|
-
"version": "0.1.8-nightly.
|
|
3
|
+
"version": "0.1.8-nightly.2",
|
|
4
4
|
"description": "Bridge Telegram bots to ours proxy nodes — one ADAPT wrapper hosting N messenger packets, each connecting one Telegram bot to one ours node. Run `ours-tg-connector add_new_connection`.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "FSL-1.1-Apache-2.0",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"test": "for f in tests/*.test.mjs; do echo \"# $f\"; node_modules/.bin/tsx \"$f\" || exit 1; done"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@adapt-toolkit/sdk": "0.10.
|
|
39
|
-
"@adapt-toolkit/sdk-native": "0.10.
|
|
38
|
+
"@adapt-toolkit/sdk": "0.10.8",
|
|
39
|
+
"@adapt-toolkit/sdk-native": "0.10.8",
|
|
40
40
|
"undici": "^7.28.0"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
|
-
"@adapt-toolkit/mufl": "0.10.
|
|
43
|
+
"@adapt-toolkit/mufl": "0.10.8",
|
|
44
44
|
"@types/node": "^20.14.0",
|
|
45
45
|
"esbuild": "^0.24.2",
|
|
46
46
|
"tsx": "^4.19.0",
|