@olane/o-node 0.7.4 → 0.7.6

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.
@@ -9,7 +9,7 @@ export class oNodeConnection extends oConnection {
9
9
  async read(source) {
10
10
  const bytes = byteStream(source);
11
11
  const output = await bytes.read({
12
- signal: AbortSignal.timeout(5000),
12
+ signal: AbortSignal.timeout(120000), // 2 min timeout
13
13
  });
14
14
  const outputObj = output instanceof Uint8ArrayList ? output.subarray() : output;
15
15
  const jsonStr = new TextDecoder().decode(outputObj);
@@ -26,6 +26,7 @@ export declare class oNode extends oToolBase {
26
26
  get parentTransports(): oNodeTransport[];
27
27
  get transports(): oNodeTransport[];
28
28
  unregister(): Promise<void>;
29
+ registerParent(): Promise<void>;
29
30
  register(): Promise<void>;
30
31
  extractMethod(address: oNodeAddress): string;
31
32
  start(): Promise<void>;
@@ -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,EAKL,QAAQ,EAET,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AACpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AAGnF,OAAO,EAAmB,SAAS,EAAE,MAAM,eAAe,CAAC;AAI3D,qBAAa,KAAM,SAAQ,SAAS;IAC3B,MAAM,EAAG,MAAM,CAAC;IAChB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/B,aAAa,CAAC,OAAO,EAAE,YAAY,GAAG,MAAM;IAItC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAStB,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAG1D;;;OAGG;IACG,SAAS,IAAI,OAAO,CAAC,YAAY,CAAC;cA0FxB,UAAU,IAAI,OAAO,CAAC,MAAM,CAAC;IAMvC,OAAO,CACX,cAAc,EAAE,YAAY,EAC5B,aAAa,EAAE,YAAY,GAC1B,OAAO,CAAC,eAAe,CAAC;IA0BrB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAoC3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;CAOhC"}
@@ -55,6 +55,7 @@ export class oNode extends oToolBase {
55
55
  .map((multiaddr) => new oNodeTransport(multiaddr.toString()));
56
56
  }
57
57
  async unregister() {
58
+ this.logger.debug('Unregistering node...');
58
59
  if (this.type === NodeType.LEADER) {
59
60
  this.logger.debug('Skipping unregistration, node is leader');
60
61
  return;
@@ -73,6 +74,28 @@ export class oNode extends oToolBase {
73
74
  };
74
75
  await this.use(address, params);
75
76
  }
77
+ async registerParent() {
78
+ if (this.type === NodeType.LEADER) {
79
+ this.logger.debug('Skipping parent registration, node is leader');
80
+ return;
81
+ }
82
+ // if no parent transports, register with the parent to get them
83
+ if (this.config.parent && this.config.parent.transports.length === 0) {
84
+ this.logger.debug('Registering node with parent...', this.config.parent);
85
+ const parentRegistration = await this.use(this.config.parent, {
86
+ method: 'child_register',
87
+ params: {
88
+ address: this.address.toString(),
89
+ transports: this.transports.map((t) => t.toString()),
90
+ peerId: this.peerId.toString(),
91
+ _token: this.config.joinToken,
92
+ },
93
+ });
94
+ const { parentTransports } = parentRegistration.result.data;
95
+ // update the parent transports
96
+ this.config.parent.setTransports(parentTransports.map((t) => new oNodeTransport(t)));
97
+ }
98
+ }
76
99
  async register() {
77
100
  if (this.type === NodeType.LEADER) {
78
101
  this.logger.debug('Skipping registration, node is leader');
@@ -92,6 +115,7 @@ export class oNode extends oToolBase {
92
115
  else {
93
116
  this.logger.debug('Registering node with leader...');
94
117
  }
118
+ await this.registerParent();
95
119
  const address = oAddress.registry();
96
120
  const params = {
97
121
  method: 'commit',
@@ -248,6 +272,7 @@ export class oNode extends oToolBase {
248
272
  }
249
273
  }
250
274
  async teardown() {
275
+ await this.unregister();
251
276
  await super.teardown();
252
277
  if (this.p2pNode) {
253
278
  await this.p2pNode.stop();
@@ -1,4 +1,4 @@
1
- import { oAddress } from '@olane/o-core';
1
+ import { oAddress, oRequest } from '@olane/o-core';
2
2
  import { oServerNode } from './nodes/server.node.js';
3
3
  import { Connection, Stream } from '@olane/o-config';
4
4
  declare const oNodeTool_base: typeof oServerNode;
@@ -11,6 +11,8 @@ export declare class oNodeTool extends oNodeTool_base {
11
11
  handleProtocol(address: oAddress): Promise<void>;
12
12
  initialize(): Promise<void>;
13
13
  handleStream(stream: Stream, connection: Connection): Promise<void>;
14
+ _tool_identify(): Promise<any>;
15
+ _tool_child_register(request: oRequest): Promise<any>;
14
16
  }
15
17
  export {};
16
18
  //# sourceMappingURL=o-node.tool.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAKT,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;;AAErD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAkB;IACzC,cAAc,CAAC,OAAO,EAAE,QAAQ;IAQhC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;CA0C1E"}
1
+ {"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,QAAQ,EAGR,QAAQ,EAET,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;;AAGrD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAkB;IACzC,cAAc,CAAC,OAAO,EAAE,QAAQ;IAQhC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IA2CnE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAa5D"}
@@ -1,6 +1,7 @@
1
- import { CoreUtils, oError, oErrorCodes, oRequest, } from '@olane/o-core';
1
+ import { CoreUtils, oAddress, oError, oErrorCodes, oRequest, } from '@olane/o-core';
2
2
  import { oTool } from '@olane/o-tool';
3
3
  import { oServerNode } from './nodes/server.node.js';
4
+ import { oNodeTransport } from './router/o-node.transport.js';
4
5
  /**
5
6
  * oTool is a mixin that extends the base class and implements the oTool interface
6
7
  * @param Base - The base class to extend
@@ -53,4 +54,21 @@ export class oNodeTool extends oTool(oServerNode) {
53
54
  await CoreUtils.sendResponse(response, stream);
54
55
  });
55
56
  }
57
+ async _tool_identify() {
58
+ return {
59
+ address: this.address.toString(),
60
+ staticAddress: this.staticAddress?.toString(),
61
+ transports: this.transports.map((t) => t.toMultiaddr().toString()),
62
+ };
63
+ }
64
+ async _tool_child_register(request) {
65
+ this.logger.debug('Child register: ', request.params);
66
+ const { address, transports } = request.params;
67
+ const childAddress = new oAddress(address, transports.map((t) => new oNodeTransport(t)));
68
+ this.hierarchyManager.addChild(childAddress);
69
+ return {
70
+ message: `Child node registered with parent! ${childAddress.toString()}`,
71
+ parentTransports: this.parentTransports.map((t) => t.toString()),
72
+ };
73
+ }
56
74
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-node",
3
- "version": "0.7.4",
3
+ "version": "0.7.6",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -56,10 +56,10 @@
56
56
  "typescript": "5.4.5"
57
57
  },
58
58
  "peerDependencies": {
59
- "@olane/o-config": "^0.7.3",
60
- "@olane/o-core": "^0.7.3",
61
- "@olane/o-protocol": "^0.7.3",
62
- "@olane/o-tool": "^0.7.3"
59
+ "@olane/o-config": "^0.7.5",
60
+ "@olane/o-core": "^0.7.5",
61
+ "@olane/o-protocol": "^0.7.5",
62
+ "@olane/o-tool": "^0.7.5"
63
63
  },
64
64
  "dependencies": {
65
65
  "debug": "^4.4.1",