@toon-protocol/connector 3.15.5 → 3.17.0
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/client/connector-admin-client.d.ts +61 -0
- package/dist/client/connector-admin-client.d.ts.map +1 -0
- package/dist/client/connector-admin-client.js +87 -0
- package/dist/client/connector-admin-client.js.map +1 -0
- package/dist/core/connector-node.d.ts +3 -0
- package/dist/core/connector-node.d.ts.map +1 -1
- package/dist/core/connector-node.js +138 -3
- package/dist/core/connector-node.js.map +1 -1
- package/dist/core/registry-db-schema.d.ts +5 -0
- package/dist/core/registry-db-schema.d.ts.map +1 -0
- package/dist/core/registry-db-schema.js +35 -0
- package/dist/core/registry-db-schema.js.map +1 -0
- package/dist/core/registry-store.d.ts +33 -0
- package/dist/core/registry-store.d.ts.map +1 -0
- package/dist/core/registry-store.js +103 -0
- package/dist/core/registry-store.js.map +1 -0
- package/dist/http/admin-api-inventory.d.ts.map +1 -1
- package/dist/http/admin-api-inventory.js +21 -0
- package/dist/http/admin-api-inventory.js.map +1 -1
- package/dist/http/admin-api.d.ts +14 -0
- package/dist/http/admin-api.d.ts.map +1 -1
- package/dist/http/admin-api.js +207 -4
- package/dist/http/admin-api.js.map +1 -1
- package/dist/http/admin-server.d.ts +2 -0
- package/dist/http/admin-server.d.ts.map +1 -1
- package/dist/http/admin-server.js +3 -1
- package/dist/http/admin-server.js.map +1 -1
- package/dist/lib.d.ts +2 -0
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +4 -1
- package/dist/lib.js.map +1 -1
- package/dist/routing/relation-route-validator.d.ts +15 -0
- package/dist/routing/relation-route-validator.d.ts.map +1 -0
- package/dist/routing/relation-route-validator.js +47 -0
- package/dist/routing/relation-route-validator.js.map +1 -0
- package/dist/routing/routing-table.d.ts +11 -0
- package/dist/routing/routing-table.d.ts.map +1 -1
- package/dist/routing/routing-table.js +6 -0
- package/dist/routing/routing-table.js.map +1 -1
- package/dist/settlement/mina-payment-channel-sdk.d.ts +18 -3
- package/dist/settlement/mina-payment-channel-sdk.d.ts.map +1 -1
- package/dist/settlement/mina-payment-channel-sdk.js +155 -10
- package/dist/settlement/mina-payment-channel-sdk.js.map +1 -1
- package/dist/settlement/provider/mina-payment-channel-provider.d.ts +3 -0
- package/dist/settlement/provider/mina-payment-channel-provider.d.ts.map +1 -1
- package/dist/settlement/provider/mina-payment-channel-provider.js +8 -1
- package/dist/settlement/provider/mina-payment-channel-provider.js.map +1 -1
- package/dist/settlement/provider/payment-channel-provider.d.ts +2 -0
- package/dist/settlement/provider/payment-channel-provider.d.ts.map +1 -1
- package/package.json +5 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { PeerRelation } from '../config/types';
|
|
2
|
+
export type FetchLike = (input: string, init?: {
|
|
3
|
+
method?: string;
|
|
4
|
+
headers?: Record<string, string>;
|
|
5
|
+
body?: string;
|
|
6
|
+
}) => Promise<{
|
|
7
|
+
status: number;
|
|
8
|
+
ok: boolean;
|
|
9
|
+
json: () => Promise<unknown>;
|
|
10
|
+
text: () => Promise<string>;
|
|
11
|
+
}>;
|
|
12
|
+
export interface ConnectorAdminClientOptions {
|
|
13
|
+
baseUrl: string;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
fetch?: FetchLike;
|
|
16
|
+
}
|
|
17
|
+
export interface AdminRouteInput {
|
|
18
|
+
prefix: string;
|
|
19
|
+
priority?: number;
|
|
20
|
+
}
|
|
21
|
+
export interface RegisterPeerInput {
|
|
22
|
+
id: string;
|
|
23
|
+
url: string;
|
|
24
|
+
authToken: string;
|
|
25
|
+
relation?: PeerRelation;
|
|
26
|
+
transport?: 'direct' | 'socks5';
|
|
27
|
+
routes?: AdminRouteInput[];
|
|
28
|
+
settlement?: Record<string, unknown>;
|
|
29
|
+
}
|
|
30
|
+
export declare class ConnectorAdminError extends Error {
|
|
31
|
+
readonly status: number;
|
|
32
|
+
readonly body: unknown;
|
|
33
|
+
constructor(message: string, status: number, body: unknown);
|
|
34
|
+
}
|
|
35
|
+
export declare class ConnectorAdminClient {
|
|
36
|
+
private readonly baseUrl;
|
|
37
|
+
private readonly apiKey?;
|
|
38
|
+
private readonly fetchImpl;
|
|
39
|
+
constructor(options: ConnectorAdminClientOptions);
|
|
40
|
+
registerPeer(input: RegisterPeerInput): Promise<unknown>;
|
|
41
|
+
removePeer(peerId: string, removeRoutes?: boolean): Promise<unknown>;
|
|
42
|
+
listPeers(): Promise<unknown>;
|
|
43
|
+
addRoute(route: {
|
|
44
|
+
prefix: string;
|
|
45
|
+
nextHop: string;
|
|
46
|
+
priority?: number;
|
|
47
|
+
}): Promise<unknown>;
|
|
48
|
+
removeRoute(prefix: string): Promise<unknown>;
|
|
49
|
+
listRoutes(): Promise<unknown>;
|
|
50
|
+
setDesiredState(state: {
|
|
51
|
+
peers?: RegisterPeerInput[];
|
|
52
|
+
routes?: Array<{
|
|
53
|
+
prefix: string;
|
|
54
|
+
nextHop: string;
|
|
55
|
+
priority?: number;
|
|
56
|
+
}>;
|
|
57
|
+
}): Promise<unknown>;
|
|
58
|
+
private send;
|
|
59
|
+
private parseBody;
|
|
60
|
+
}
|
|
61
|
+
//# sourceMappingURL=connector-admin-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-admin-client.d.ts","sourceRoot":"","sources":["../../src/client/connector-admin-client.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAGpD,MAAM,MAAM,SAAS,GAAG,CACtB,KAAK,EAAE,MAAM,EACb,IAAI,CAAC,EAAE;IACL,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,MAAM,CAAC;CACf,KACE,OAAO,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,EAAE,EAAE,OAAO,CAAC;IACZ,IAAI,EA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OAAO,CAAC;IAK7B,QAAQ,CAAC,KAAK,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAKzF,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAK7C,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAS9B,eAAe,CAAC,KAAK,EAAE;QACrB,KAAK,CAAC,EAAE,iBAAiB,EAAE,CAAC;QAC5B,MAAM,CAAC,EAAE,KAAK,CAAC;YAAE,MAAM,EAAE,MAAM,CAAC;YAAC,OAAO,EAAE,MAAM,CAAC;YAAC,QAAQ,CAAC,EAAE,MAAM,CAAA;SAAE,CAAC,CAAC;KACxE,GAAG,OAAO,CAAC,OAAO,CAAC;YAIN,IAAI;YA0BJ,SAAS;CAcxB"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ConnectorAdminClient = exports.ConnectorAdminError = void 0;
|
|
4
|
+
class ConnectorAdminError extends Error {
|
|
5
|
+
status;
|
|
6
|
+
body;
|
|
7
|
+
constructor(message, status, body) {
|
|
8
|
+
super(message);
|
|
9
|
+
this.status = status;
|
|
10
|
+
this.body = body;
|
|
11
|
+
this.name = 'ConnectorAdminError';
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ConnectorAdminError = ConnectorAdminError;
|
|
15
|
+
class ConnectorAdminClient {
|
|
16
|
+
baseUrl;
|
|
17
|
+
apiKey;
|
|
18
|
+
fetchImpl;
|
|
19
|
+
constructor(options) {
|
|
20
|
+
this.baseUrl = options.baseUrl.replace(/\/+$/, '');
|
|
21
|
+
this.apiKey = options.apiKey;
|
|
22
|
+
const resolved = options.fetch ?? globalThis.fetch;
|
|
23
|
+
if (!resolved) {
|
|
24
|
+
throw new Error('No fetch implementation available; pass one via options.fetch');
|
|
25
|
+
}
|
|
26
|
+
this.fetchImpl = resolved;
|
|
27
|
+
}
|
|
28
|
+
registerPeer(input) {
|
|
29
|
+
return this.send('POST', '/admin/peers', input);
|
|
30
|
+
}
|
|
31
|
+
removePeer(peerId, removeRoutes = true) {
|
|
32
|
+
const query = removeRoutes ? '' : '?removeRoutes=false';
|
|
33
|
+
return this.send('DELETE', `/admin/peers/${encodeURIComponent(peerId)}${query}`);
|
|
34
|
+
}
|
|
35
|
+
listPeers() {
|
|
36
|
+
return this.send('GET', '/admin/peers');
|
|
37
|
+
}
|
|
38
|
+
addRoute(route) {
|
|
39
|
+
return this.send('POST', '/admin/routes', route);
|
|
40
|
+
}
|
|
41
|
+
removeRoute(prefix) {
|
|
42
|
+
return this.send('DELETE', `/admin/routes/${encodeURIComponent(prefix)}`);
|
|
43
|
+
}
|
|
44
|
+
listRoutes() {
|
|
45
|
+
return this.send('GET', '/admin/routes');
|
|
46
|
+
}
|
|
47
|
+
setDesiredState(state) {
|
|
48
|
+
return this.send('PUT', '/admin/desired-state', state);
|
|
49
|
+
}
|
|
50
|
+
async send(method, path, body) {
|
|
51
|
+
const headers = {};
|
|
52
|
+
if (body !== undefined) {
|
|
53
|
+
headers['content-type'] = 'application/json';
|
|
54
|
+
}
|
|
55
|
+
if (this.apiKey) {
|
|
56
|
+
headers['X-Api-Key'] = this.apiKey;
|
|
57
|
+
}
|
|
58
|
+
const res = await this.fetchImpl(`${this.baseUrl}${path}`, {
|
|
59
|
+
method,
|
|
60
|
+
headers,
|
|
61
|
+
body: body !== undefined ? JSON.stringify(body) : undefined,
|
|
62
|
+
});
|
|
63
|
+
const parsed = await this.parseBody(res);
|
|
64
|
+
if (!res.ok) {
|
|
65
|
+
const message = (parsed && typeof parsed === 'object' && 'message' in parsed
|
|
66
|
+
? String(parsed.message)
|
|
67
|
+
: undefined) ?? `Admin request failed: ${method} ${path} → ${res.status}`;
|
|
68
|
+
throw new ConnectorAdminError(message, res.status, parsed);
|
|
69
|
+
}
|
|
70
|
+
return parsed;
|
|
71
|
+
}
|
|
72
|
+
async parseBody(res) {
|
|
73
|
+
try {
|
|
74
|
+
return await res.json();
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
try {
|
|
78
|
+
return await res.text();
|
|
79
|
+
}
|
|
80
|
+
catch {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.ConnectorAdminClient = ConnectorAdminClient;
|
|
87
|
+
//# sourceMappingURL=connector-admin-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connector-admin-client.js","sourceRoot":"","sources":["../../src/client/connector-admin-client.ts"],"names":[],"mappings":";;;AA2DA,MAAa,mBAAoB,SAAQ,KAAK;IAGjC;IACA;IAHX,YACE,OAAe,EACN,MAAc,EACd,IAAa;QAEtB,KAAK,CAAC,OAAO,CAAC,CAAC;QAHN,WAAM,GAAN,MAAM,CAAQ;QACd,SAAI,GAAJ,IAAI,CAAS;QAGtB,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAC;IACpC,CAAC;CACF;AATD,kDASC;AAED,MAAa,oBAAoB;IACd,OAAO,CAAS;IAChB,MAAM,CAAU;IAChB,SAAS,CAAY;IAEtC,YAAY,OAAoC;QAC9C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;QACnD,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;QAC7B,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,IAAK,UAAU,CAAC,KAA+B,CAAC;QAC9E,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,MAAM,IAAI,KAAK,CAAC,+DAA+D,CAAC,CAAC;QACnF,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC;IAC5B,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AAM,CAAC;QACrC,CAAC;QAED,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,OAAO,GAAG,IAAI,EAAE,EAAE;YACzD,MAAM;YACN,OAAO;YACP,IAAI,EAAE,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;SAC5D,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC;QACzC,IAAI,CAAC,GAAG,CAAC,EAAE,EAAE,CAAC;YACZ,MAAM,OAAO,GACX,CAAC,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,SAAS,IAAI,MAAM;gBAC1D,CAAC,CAAC,MAAM,CAAE,MAA+B,CAAC,OAAO,CAAC;gBAClD,CAAC,CAAC,SAAS,CAAC,IAAI,yBAAyB,MAAM,IAAI,IAAI,MAAM,GAAG,CAAC,MAAM,EAAE,CAAC;YAC9E,MAAM,IAAI,mBAAmB,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7D,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;IAEO,KAAK,CAAC,SAAS,CAAC,GAGvB;QACC,IAAI,CAAC;YACH,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,IAAI,CAAC;gBACH,OAAO,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;YAC1B,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,SAAS,CAAC;YACnB,CAAC;QACH,CAAC;IACH,CAAC;CACF;AAlGD,oDAkGC"}
|
|
@@ -31,6 +31,7 @@ export declare class ConnectorNode implements HealthStatusProvider {
|
|
|
31
31
|
private _tigerBeetleClient;
|
|
32
32
|
private _inMemoryLedgerClient;
|
|
33
33
|
private readonly _settlementPeers;
|
|
34
|
+
private _registryStore;
|
|
34
35
|
private _healthStatus;
|
|
35
36
|
private readonly _ilpMetrics;
|
|
36
37
|
private readonly _startTime;
|
|
@@ -74,6 +75,8 @@ export declare class ConnectorNode implements HealthStatusProvider {
|
|
|
74
75
|
listRoutes(): RouteInfo[];
|
|
75
76
|
addRoute(route: RouteInfo): void;
|
|
76
77
|
removeRoute(prefix: string): void;
|
|
78
|
+
private _openRegistryStore;
|
|
79
|
+
private _reconcileRegistry;
|
|
77
80
|
openChannel(params: {
|
|
78
81
|
peerId: string;
|
|
79
82
|
chain: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connector-node.d.ts","sourceRoot":"","sources":["../../src/core/connector-node.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;
|
|
1
|
+
{"version":3,"file":"connector-node.d.ts","sourceRoot":"","sources":["../../src/core/connector-node.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAMxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAI7D,OAAO,EACL,iBAAiB,EAIjB,gBAAgB,EAChB,eAAe,EAGhB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,eAAe,EAEf,oBAAoB,EACpB,gBAAgB,EAChB,uBAAuB,EACvB,QAAQ,EACR,kBAAkB,EAClB,SAAS,EACT,gBAAgB,EAChB,cAAc,EAGf,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,iBAAiB,EAOlB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,cAAc,EAA+B,MAAM,mBAAmB,CAAC;AAgBhF,OAAO,EAAE,YAAY,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACnE,OAAO,EAAE,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
const nodePath = tslib_1.__importStar(require("path"));
|
|
7
7
|
const routing_table_1 = require("../routing/routing-table");
|
|
8
|
+
const relation_route_validator_1 = require("../routing/relation-route-validator");
|
|
8
9
|
const btp_client_manager_1 = require("../btp/btp-client-manager");
|
|
9
10
|
const btp_server_1 = require("../btp/btp-server");
|
|
10
11
|
const packet_handler_1 = require("./packet-handler");
|
|
@@ -26,6 +27,8 @@ const account_manager_1 = require("../settlement/account-manager");
|
|
|
26
27
|
const settlement_monitor_1 = require("../settlement/settlement-monitor");
|
|
27
28
|
const claim_receiver_1 = require("../settlement/claim-receiver");
|
|
28
29
|
const claim_receiver_db_schema_1 = require("../settlement/claim-receiver-db-schema");
|
|
30
|
+
const registry_db_schema_1 = require("./registry-db-schema");
|
|
31
|
+
const registry_store_1 = require("./registry-store");
|
|
29
32
|
const key_manager_1 = require("../security/key-manager");
|
|
30
33
|
const optional_require_1 = require("../utils/optional-require");
|
|
31
34
|
const tigerbeetle_client_1 = require("../settlement/tigerbeetle-client");
|
|
@@ -63,6 +66,7 @@ class ConnectorNode {
|
|
|
63
66
|
_tigerBeetleClient = null;
|
|
64
67
|
_inMemoryLedgerClient = null;
|
|
65
68
|
_settlementPeers = new Map();
|
|
69
|
+
_registryStore = null;
|
|
66
70
|
_healthStatus = 'starting';
|
|
67
71
|
_ilpMetrics;
|
|
68
72
|
_startTime = new Date();
|
|
@@ -734,6 +738,7 @@ class ConnectorNode {
|
|
|
734
738
|
event: 'health_server_started',
|
|
735
739
|
port: healthCheckPort,
|
|
736
740
|
}, 'Health server started');
|
|
741
|
+
await this._openRegistryStore();
|
|
737
742
|
const adminApiEnabled = this._config.adminApi?.enabled || process.env.ADMIN_API_ENABLED === 'true';
|
|
738
743
|
if (adminApiEnabled) {
|
|
739
744
|
const adminConfig = {
|
|
@@ -761,6 +766,8 @@ class ConnectorNode {
|
|
|
761
766
|
managedAnonClient: this._managedAnonClient ?? undefined,
|
|
762
767
|
transportType: this._transportType ?? 'direct',
|
|
763
768
|
setPeerRelation: (peerId, relation) => this._packetHandler.setPeerRelation(peerId, relation),
|
|
769
|
+
getPeerRelation: (peerId) => this._packetHandler.getPeerRelation(peerId),
|
|
770
|
+
registryStore: this._registryStore ?? undefined,
|
|
764
771
|
});
|
|
765
772
|
await this._adminServer.start();
|
|
766
773
|
this._logger.info({
|
|
@@ -794,6 +801,7 @@ class ConnectorNode {
|
|
|
794
801
|
totalPeers: this._config.peers.length,
|
|
795
802
|
}, 'Some peer connections failed during startup (will retry in background)');
|
|
796
803
|
}
|
|
804
|
+
await this._reconcileRegistry();
|
|
797
805
|
const connectedPeers = this._btpClientManager.getPeerStatus();
|
|
798
806
|
const connectedCount = Array.from(connectedPeers.values()).filter(Boolean).length;
|
|
799
807
|
if (this._channelManager && this._paymentChannelSDK) {
|
|
@@ -1264,6 +1272,20 @@ class ConnectorNode {
|
|
|
1264
1272
|
throw new Error(settlementError);
|
|
1265
1273
|
}
|
|
1266
1274
|
}
|
|
1275
|
+
const localPrefixes = (0, relation_route_validator_1.deriveLocalPrefixes)(this._routingTable.getAllRoutes(), this._config.nodeId);
|
|
1276
|
+
let effectiveRoutes = config.routes;
|
|
1277
|
+
if (!effectiveRoutes || effectiveRoutes.length === 0) {
|
|
1278
|
+
const autoRoute = (0, relation_route_validator_1.deriveDefaultChildRoute)(config.relation, localPrefixes, config.id);
|
|
1279
|
+
if (autoRoute) {
|
|
1280
|
+
effectiveRoutes = [autoRoute];
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
if (effectiveRoutes && effectiveRoutes.length > 0) {
|
|
1284
|
+
const relationValidation = (0, relation_route_validator_1.validateRelationRoute)(config.relation, localPrefixes, effectiveRoutes.map((r) => r.prefix));
|
|
1285
|
+
if (!relationValidation.ok) {
|
|
1286
|
+
throw new Error(relationValidation.error);
|
|
1287
|
+
}
|
|
1288
|
+
}
|
|
1267
1289
|
const existingPeers = this._btpClientManager.getPeerIds();
|
|
1268
1290
|
const isUpdate = existingPeers.includes(config.id);
|
|
1269
1291
|
if (!isUpdate) {
|
|
@@ -1291,16 +1313,25 @@ class ConnectorNode {
|
|
|
1291
1313
|
transport: this._btpClientManager.getPeerTransport(config.id) ?? null,
|
|
1292
1314
|
}, `Re-registering peer: ${config.id}`);
|
|
1293
1315
|
}
|
|
1294
|
-
if (
|
|
1295
|
-
for (const route of
|
|
1316
|
+
if (effectiveRoutes) {
|
|
1317
|
+
for (const route of effectiveRoutes) {
|
|
1296
1318
|
this._routingTable.addRoute(route.prefix, config.id, route.priority ?? 0);
|
|
1297
1319
|
this._logger.info({ event: 'route_added', prefix: route.prefix, nextHop: config.id }, `Added route: ${route.prefix} -> ${config.id}`);
|
|
1298
1320
|
}
|
|
1299
1321
|
}
|
|
1300
1322
|
this._packetHandler.setPeerRelation(config.id, config.relation ?? 'peer');
|
|
1301
1323
|
if (config.settlement) {
|
|
1302
|
-
this._applySettlementConfig(config.id, config.settlement,
|
|
1324
|
+
this._applySettlementConfig(config.id, config.settlement, effectiveRoutes, isUpdate);
|
|
1303
1325
|
}
|
|
1326
|
+
this._registryStore?.savePeer({
|
|
1327
|
+
id: config.id,
|
|
1328
|
+
url: config.url,
|
|
1329
|
+
authToken: config.authToken,
|
|
1330
|
+
relation: config.relation,
|
|
1331
|
+
transport: config.transport,
|
|
1332
|
+
settlementJson: config.settlement ? JSON.stringify(config.settlement) : undefined,
|
|
1333
|
+
source: 'runtime',
|
|
1334
|
+
});
|
|
1304
1335
|
const routes = this._routingTable.getAllRoutes();
|
|
1305
1336
|
const peerRoutes = routes.filter((r) => r.nextHop === config.id);
|
|
1306
1337
|
const connected = this._btpClientManager.isConnected(config.id);
|
|
@@ -1348,6 +1379,7 @@ class ConnectorNode {
|
|
|
1348
1379
|
}
|
|
1349
1380
|
}
|
|
1350
1381
|
}
|
|
1382
|
+
this._registryStore?.deletePeer(peerId);
|
|
1351
1383
|
return { peerId, removedRoutes };
|
|
1352
1384
|
}
|
|
1353
1385
|
listPeers() {
|
|
@@ -1411,6 +1443,14 @@ class ConnectorNode {
|
|
|
1411
1443
|
if (!existingPeers.includes(route.nextHop)) {
|
|
1412
1444
|
this._logger.warn({ event: 'route_nextHop_unknown', prefix: route.prefix, nextHop: route.nextHop }, `Adding route with unknown nextHop peer: ${route.nextHop}`);
|
|
1413
1445
|
}
|
|
1446
|
+
const nextHopRelation = this._packetHandler.getPeerRelation(route.nextHop);
|
|
1447
|
+
const localPrefixes = (0, relation_route_validator_1.deriveLocalPrefixes)(this._routingTable.getAllRoutes(), this._config.nodeId);
|
|
1448
|
+
const relationValidation = (0, relation_route_validator_1.validateRelationRoute)(nextHopRelation, localPrefixes, [
|
|
1449
|
+
route.prefix,
|
|
1450
|
+
]);
|
|
1451
|
+
if (!relationValidation.ok) {
|
|
1452
|
+
throw new Error(relationValidation.error);
|
|
1453
|
+
}
|
|
1414
1454
|
this._routingTable.addRoute(route.prefix, route.nextHop, route.priority ?? 0);
|
|
1415
1455
|
this._logger.info({ event: 'route_added', prefix: route.prefix, nextHop: route.nextHop }, `Added route: ${route.prefix} -> ${route.nextHop}`);
|
|
1416
1456
|
}
|
|
@@ -1423,6 +1463,101 @@ class ConnectorNode {
|
|
|
1423
1463
|
this._routingTable.removeRoute(prefix);
|
|
1424
1464
|
this._logger.info({ event: 'route_removed', prefix }, `Removed route: ${prefix}`);
|
|
1425
1465
|
}
|
|
1466
|
+
async _openRegistryStore() {
|
|
1467
|
+
try {
|
|
1468
|
+
const LibsqlModule = await (0, optional_require_1.requireOptional)('libsql', 'peer/route registry persistence');
|
|
1469
|
+
const LibsqlDatabase = LibsqlModule.default;
|
|
1470
|
+
await fs_1.promises.mkdir('./data', { recursive: true });
|
|
1471
|
+
const registryDbPath = `./data/registry-${this._config.nodeId}.db`;
|
|
1472
|
+
const registryDb = new LibsqlDatabase(registryDbPath);
|
|
1473
|
+
(0, registry_db_schema_1.initializeRegistrySchema)(registryDb);
|
|
1474
|
+
this._registryStore = new registry_store_1.RegistryStore(registryDb, this._logger);
|
|
1475
|
+
this._routingTable.setPersistence(this._registryStore);
|
|
1476
|
+
}
|
|
1477
|
+
catch (error) {
|
|
1478
|
+
this._logger.warn({
|
|
1479
|
+
event: 'registry_persistence_disabled',
|
|
1480
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1481
|
+
}, 'Peer/route registry persistence unavailable; runtime peers/routes will not survive restart');
|
|
1482
|
+
this._registryStore = null;
|
|
1483
|
+
}
|
|
1484
|
+
}
|
|
1485
|
+
async _reconcileRegistry() {
|
|
1486
|
+
if (!this._registryStore) {
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
const { peers, routes } = this._registryStore.loadAll();
|
|
1490
|
+
for (const peer of this._config.peers) {
|
|
1491
|
+
this._registryStore.savePeer({
|
|
1492
|
+
id: peer.id,
|
|
1493
|
+
url: peer.url,
|
|
1494
|
+
authToken: peer.authToken,
|
|
1495
|
+
relation: peer.relation,
|
|
1496
|
+
transport: peer.transport,
|
|
1497
|
+
source: 'config',
|
|
1498
|
+
});
|
|
1499
|
+
}
|
|
1500
|
+
for (const route of this._config.routes) {
|
|
1501
|
+
this._registryStore.saveRoute({
|
|
1502
|
+
prefix: route.prefix,
|
|
1503
|
+
nextHop: route.nextHop,
|
|
1504
|
+
priority: route.priority ?? 0,
|
|
1505
|
+
source: 'config',
|
|
1506
|
+
});
|
|
1507
|
+
}
|
|
1508
|
+
const existingPeerIds = new Set(this._btpClientManager.getPeerIds());
|
|
1509
|
+
let replayedPeers = 0;
|
|
1510
|
+
for (const peer of peers) {
|
|
1511
|
+
if (peer.source !== 'runtime' || existingPeerIds.has(peer.id)) {
|
|
1512
|
+
continue;
|
|
1513
|
+
}
|
|
1514
|
+
try {
|
|
1515
|
+
await this.registerPeer({
|
|
1516
|
+
id: peer.id,
|
|
1517
|
+
url: peer.url,
|
|
1518
|
+
authToken: peer.authToken,
|
|
1519
|
+
relation: peer.relation,
|
|
1520
|
+
transport: peer.transport,
|
|
1521
|
+
settlement: peer.settlementJson
|
|
1522
|
+
? JSON.parse(peer.settlementJson)
|
|
1523
|
+
: undefined,
|
|
1524
|
+
});
|
|
1525
|
+
replayedPeers++;
|
|
1526
|
+
}
|
|
1527
|
+
catch (error) {
|
|
1528
|
+
this._logger.warn({
|
|
1529
|
+
event: 'registry_peer_replay_failed',
|
|
1530
|
+
peerId: peer.id,
|
|
1531
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1532
|
+
}, `Failed to replay persisted peer: ${peer.id}`);
|
|
1533
|
+
}
|
|
1534
|
+
}
|
|
1535
|
+
const existingPrefixes = new Set(this._routingTable.getAllRoutes().map((r) => r.prefix));
|
|
1536
|
+
let replayedRoutes = 0;
|
|
1537
|
+
for (const route of routes) {
|
|
1538
|
+
if (route.source !== 'runtime' || existingPrefixes.has(route.prefix)) {
|
|
1539
|
+
continue;
|
|
1540
|
+
}
|
|
1541
|
+
try {
|
|
1542
|
+
this.addRoute({
|
|
1543
|
+
prefix: route.prefix,
|
|
1544
|
+
nextHop: route.nextHop,
|
|
1545
|
+
priority: route.priority,
|
|
1546
|
+
});
|
|
1547
|
+
replayedRoutes++;
|
|
1548
|
+
}
|
|
1549
|
+
catch (error) {
|
|
1550
|
+
this._logger.warn({
|
|
1551
|
+
event: 'registry_route_replay_failed',
|
|
1552
|
+
prefix: route.prefix,
|
|
1553
|
+
error: error instanceof Error ? error.message : String(error),
|
|
1554
|
+
}, `Failed to replay persisted route: ${route.prefix}`);
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
if (replayedPeers > 0 || replayedRoutes > 0) {
|
|
1558
|
+
this._logger.info({ event: 'registry_reconciled', replayedPeers, replayedRoutes }, `Replayed ${replayedPeers} peer(s) and ${replayedRoutes} route(s) from the persistent registry`);
|
|
1559
|
+
}
|
|
1560
|
+
}
|
|
1426
1561
|
async openChannel(params) {
|
|
1427
1562
|
if (!this._btpServerStarted) {
|
|
1428
1563
|
throw new config_loader_1.ConnectorNotStartedError('Connector is not started. Call start() before openChannel().');
|