@olane/o-node 0.7.12-alpha.16 → 0.7.12-alpha.18

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.
@@ -185,7 +185,7 @@ export class oReconnectionManager extends oObject {
185
185
  this.logger.info(`Parent discovery attempt ${attempt} (elapsed: ${elapsedMinutes}m)`);
186
186
  try {
187
187
  // Query registry for parent by its known address
188
- const response = await this.node.use(new oAddress('o://registry'), {
188
+ const response = await this.node.use(oAddress.registry(), {
189
189
  method: 'find_available_parent',
190
190
  params: {
191
191
  parentAddress: this.node.config.parent?.toString(),
@@ -45,7 +45,10 @@ export declare class oNode extends oToolBase {
45
45
  configure(): Promise<Libp2pConfig>;
46
46
  protected createNode(): Promise<Libp2p>;
47
47
  connect(nextHopAddress: oNodeAddress, targetAddress: oNodeAddress): Promise<oNodeConnection>;
48
- postInitialize(): Promise<void>;
48
+ initConnectionManager(): Promise<void>;
49
+ initReconnectionManager(): Promise<void>;
50
+ hookInitializeFinished(): Promise<void>;
51
+ hookStartFinished(): Promise<void>;
49
52
  initialize(): Promise<void>;
50
53
  /**
51
54
  * Override use() to wrap leader/registry requests with retry logic
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EACN,YAAY,EACb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAIL,QAAQ,EACR,QAAQ,EAER,oBAAoB,EACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe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ader?.libp2pTransports || []);
117
117
  }
118
118
  else {
119
+ this.logger.debug('Waiting for parent and reconnecting...');
119
120
  await this.reconnectionManager?.waitForParentAndReconnect();
120
121
  }
121
122
  }
@@ -226,12 +227,28 @@ export class oNode extends oToolBase {
226
227
  // ];
227
228
  // // let's make sure we only allow communication through the parent transports
228
229
  params.connectionGater = {
230
+ denyDialPeer: (peerId) => {
231
+ // we can call the leader
232
+ if (this.config.leader?.libp2pTransports.some((t) => t.toPeerId() === peerId.toString())) {
233
+ return false;
234
+ }
235
+ // we can call our parent
236
+ if (this.parentPeerId === peerId.toString()) {
237
+ return false;
238
+ }
239
+ // we can call our children
240
+ if (this.hierarchyManager.children.some((c) => c.libp2pTransports.some((t) => t.toPeerId() === peerId.toString()))) {
241
+ return false;
242
+ }
243
+ return true;
244
+ },
229
245
  // who can call us?
230
246
  denyInboundEncryptedConnection: (peerId, maConn) => {
231
247
  // deny all inbound connections unless they are from a parent transport
232
248
  if (this.parentPeerId === peerId.toString()) {
233
249
  return false;
234
250
  }
251
+ // allow connections from children (for ping)
235
252
  if (this.hierarchyManager.children.some((c) => c.libp2pTransports.some((t) => t.toPeerId() === peerId.toString()))) {
236
253
  return false;
237
254
  }
@@ -282,7 +299,27 @@ export class oNode extends oToolBase {
282
299
  }
283
300
  return connection;
284
301
  }
285
- async postInitialize() {
302
+ async initConnectionManager() {
303
+ this.connectionManager = new oNodeConnectionManager({
304
+ p2pNode: this.p2pNode,
305
+ });
306
+ }
307
+ async initReconnectionManager() {
308
+ // Initialize reconnection manager
309
+ if (this.config.reconnection?.enabled !== false) {
310
+ this.reconnectionManager = new oReconnectionManager(this, {
311
+ enabled: true,
312
+ maxAttempts: this.config.reconnection?.maxAttempts ?? 10,
313
+ baseDelayMs: this.config.reconnection?.baseDelayMs ?? 5000,
314
+ maxDelayMs: this.config.reconnection?.maxDelayMs ?? 60000,
315
+ useLeaderFallback: this.config.reconnection?.useLeaderFallback ?? true,
316
+ parentDiscoveryIntervalMs: this.config.reconnection?.parentDiscoveryIntervalMs ?? 10000,
317
+ parentDiscoveryMaxDelayMs: this.config.reconnection?.parentDiscoveryMaxDelayMs ?? 60000,
318
+ });
319
+ }
320
+ }
321
+ async hookInitializeFinished() { }
322
+ async hookStartFinished() {
286
323
  // Initialize connection heartbeat manager
287
324
  this.connectionHeartbeatManager = new oConnectionHeartbeatManager(this, {
288
325
  enabled: this.config.connectionHeartbeat?.enabled ?? true,
@@ -308,13 +345,11 @@ export class oNode extends oToolBase {
308
345
  await this.initializeRouter();
309
346
  // need to wait until our libpp2 node is initialized before calling super.initialize
310
347
  await super.initialize();
311
- this.logger.debug('Node initialized!', this.transports.map((t) => t.toString()));
348
+ this.logger.debug('Node initializedddd!', this.transports.map((t) => t.toString()));
312
349
  this.address.setTransports(this.transports);
313
350
  this.peerId = this.p2pNode.peerId;
314
351
  // initialize connection manager
315
- this.connectionManager = new oNodeConnectionManager({
316
- p2pNode: this.p2pNode,
317
- });
352
+ await this.initConnectionManager();
318
353
  // Initialize leader request wrapper with circuit breaker
319
354
  this.leaderRequestWrapper = new LeaderRequestWrapper({
320
355
  enabled: this.config.leaderRetry?.enabled ?? true,
@@ -340,21 +375,9 @@ export class oNode extends oToolBase {
340
375
  this.logger.debug('Adding leader resolver fallback...');
341
376
  this.router.addResolver(new oLeaderResolverFallback(this.address));
342
377
  }
343
- // Read ENABLE_LEADER_HEARTBEAT environment variable
344
- const enableLeaderHeartbeat = this.parent?.toString() === oAddress.leader().toString();
345
- this.logger.debug(`Enable leader heartbeat: ${enableLeaderHeartbeat}`);
346
- // Initialize reconnection manager
347
- if (this.config.reconnection?.enabled !== false) {
348
- this.reconnectionManager = new oReconnectionManager(this, {
349
- enabled: true,
350
- maxAttempts: this.config.reconnection?.maxAttempts ?? 10,
351
- baseDelayMs: this.config.reconnection?.baseDelayMs ?? 5000,
352
- maxDelayMs: this.config.reconnection?.maxDelayMs ?? 60000,
353
- useLeaderFallback: this.config.reconnection?.useLeaderFallback ?? true,
354
- parentDiscoveryIntervalMs: this.config.reconnection?.parentDiscoveryIntervalMs ?? 10000,
355
- parentDiscoveryMaxDelayMs: this.config.reconnection?.parentDiscoveryMaxDelayMs ?? 60000,
356
- });
357
- }
378
+ // initialize reconnection manager
379
+ await this.initReconnectionManager();
380
+ await this.hookInitializeFinished();
358
381
  }
359
382
  /**
360
383
  * Override use() to wrap leader/registry requests with retry logic
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-node",
3
- "version": "0.7.12-alpha.16",
3
+ "version": "0.7.12-alpha.18",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -54,12 +54,12 @@
54
54
  "typescript": "5.4.5"
55
55
  },
56
56
  "dependencies": {
57
- "@olane/o-config": "0.7.12-alpha.16",
58
- "@olane/o-core": "0.7.12-alpha.16",
59
- "@olane/o-protocol": "0.7.12-alpha.16",
60
- "@olane/o-tool": "0.7.12-alpha.16",
57
+ "@olane/o-config": "0.7.12-alpha.18",
58
+ "@olane/o-core": "0.7.12-alpha.18",
59
+ "@olane/o-protocol": "0.7.12-alpha.18",
60
+ "@olane/o-tool": "0.7.12-alpha.18",
61
61
  "debug": "^4.4.1",
62
62
  "dotenv": "^16.5.0"
63
63
  },
64
- "gitHead": "b4a4aa915d38e29962e2ee8f71838864de185af1"
64
+ "gitHead": "800caa15822914672538c443efc9e741fe3ee1f3"
65
65
  }