@olane/o-node 0.7.41 → 0.7.42

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.
@@ -14,6 +14,6 @@ export declare class oNodeAddress extends oAddress {
14
14
  toString(): string;
15
15
  toMultiaddr(): Multiaddr;
16
16
  static fromMultiaddr(ma: Multiaddr): oAddress;
17
- static fromProtocol(protocol: string): oAddress;
17
+ static fromProtocol(protocol: string): oNodeAddress;
18
18
  }
19
19
  //# sourceMappingURL=o-node.address.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.address.d.ts","sourceRoot":"","sources":["../../../src/router/o-node.address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAExD,qBAAa,YAAa,SAAQ,QAAQ;aAItB,KAAK,EAAE,MAAM;IAHxB,UAAU,EAAE,cAAc,EAAE,CAAM;gBAGvB,KAAK,EAAE,MAAM,EAC7B,UAAU,GAAE,cAAc,EAAO;IAMnC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;KACpC,GAAG,YAAY;IAShB,IAAI,gBAAgB,IAAI,cAAc,EAAE,CAEvC;IAED,IAAI,gBAAgB,IAAI,cAAc,EAAE,CAEvC;IAED,QAAQ,IAAI,MAAM;IAIlB,WAAW,IAAI,SAAS;IAIxB,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,QAAQ;IAI7C,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,QAAQ;CAIhD"}
1
+ {"version":3,"file":"o-node.address.d.ts","sourceRoot":"","sources":["../../../src/router/o-node.address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAiB,MAAM,eAAe,CAAC;AAExD,qBAAa,YAAa,SAAQ,QAAQ;aAItB,KAAK,EAAE,MAAM;IAHxB,UAAU,EAAE,cAAc,EAAE,CAAM;gBAGvB,KAAK,EAAE,MAAM,EAC7B,UAAU,GAAE,cAAc,EAAO;IAMnC,MAAM,CAAC,QAAQ,CAAC,IAAI,EAAE;QACpB,KAAK,EAAE,MAAM,CAAC;QACd,UAAU,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;KACpC,GAAG,YAAY;IAShB,IAAI,gBAAgB,IAAI,cAAc,EAAE,CAEvC;IAED,IAAI,gBAAgB,IAAI,cAAc,EAAE,CAEvC;IAED,QAAQ,IAAI,MAAM;IAIlB,WAAW,IAAI,SAAS;IAIxB,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,QAAQ;IAI7C,MAAM,CAAC,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,YAAY;CAIpD"}
@@ -28,6 +28,6 @@ export class oNodeAddress extends oAddress {
28
28
  }
29
29
  static fromProtocol(protocol) {
30
30
  const addressInput = protocol.replace('/o/', 'o://');
31
- return new oAddress(addressInput);
31
+ return new oNodeAddress(addressInput);
32
32
  }
33
33
  }
@@ -4,6 +4,6 @@ export declare class ConnectionUtils extends oObject {
4
4
  static addressFromConnection(options: {
5
5
  currentNode: any;
6
6
  connection: Connection;
7
- }): Promise<import("@olane/o-core").oAddress>;
7
+ }): Promise<any>;
8
8
  }
9
9
  //# sourceMappingURL=connection.utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"connection.utils.d.ts","sourceRoot":"","sources":["../../../src/utils/connection.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAGxC,qBAAa,eAAgB,SAAQ,OAAO;WACtB,qBAAqB,CAAC,OAAO,EAAE;QACjD,WAAW,EAAE,GAAG,CAAC;QACjB,UAAU,EAAE,UAAU,CAAC;KACxB;CAsCF"}
1
+ {"version":3,"file":"connection.utils.d.ts","sourceRoot":"","sources":["../../../src/utils/connection.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAA2B,MAAM,iBAAiB,CAAC;AACtE,OAAO,EAAuB,OAAO,EAAE,MAAM,eAAe,CAAC;AAI7D,qBAAa,eAAgB,SAAQ,OAAO;WACtB,qBAAqB,CAAC,OAAO,EAAE;QACjD,WAAW,EAAE,GAAG,CAAC;QACjB,UAAU,EAAE,UAAU,CAAC;KACxB;CAmEF"}
@@ -1,26 +1,48 @@
1
- import { oObject } from '@olane/o-core';
1
+ import { oError, oErrorCodes, oObject } from '@olane/o-core';
2
2
  import { oNodeAddress } from '../router/o-node.address.js';
3
+ import { oNodeTransport } from '../router/o-node.transport.js';
3
4
  export class ConnectionUtils extends oObject {
4
5
  static async addressFromConnection(options) {
5
- const { currentNode, connection } = options;
6
- const p2pNode = currentNode.p2pNode;
7
- // Extract the actual olane address from the peer store
8
- const peers = await p2pNode.peerStore.all();
9
- const remotePeer = peers.find((peer) => peer.id.toString() === connection.remotePeer.toString());
10
- if (!remotePeer) {
11
- console.log('Failed to find peer:', remotePeer);
12
- throw new Error(`Failed to extract remote address, peer ${connection.remotePeer.toString()} not found in peer store.`);
6
+ try {
7
+ console.log('[ConnectionUtils] addressFromConnection');
8
+ const { currentNode, connection } = options;
9
+ const p2pNode = currentNode.p2pNode;
10
+ // Extract the actual olane address from the peer store
11
+ const peers = await p2pNode.peerStore.all();
12
+ const remotePeer = peers.find((peer) => peer.id.toString() === connection.remotePeer.toString());
13
+ if (!remotePeer) {
14
+ console.log('Failed to find peer:', remotePeer);
15
+ throw new Error(`Failed to extract remote address, peer ${connection.remotePeer.toString()} not found in peer store.`);
16
+ }
17
+ // Get origin address for comparison
18
+ const originAddress = currentNode.address?.value;
19
+ if (!originAddress) {
20
+ throw new Error('Origin address is not configured');
21
+ }
22
+ const originProtocol = originAddress.toString();
23
+ const oProtocol = remotePeer.protocols.find((p) => p.startsWith('/o/') && p.startsWith(originProtocol) === false);
24
+ if (!oProtocol) {
25
+ throw new Error('Failed to extract remote address, could not find o-protocol in peer protocols.');
26
+ }
27
+ const address = oNodeAddress.fromProtocol(oProtocol);
28
+ if (remotePeer.addresses.length === 0 &&
29
+ address.value === currentNode.leader.value) {
30
+ // leader - use known address
31
+ return currentNode.leader;
32
+ }
33
+ if (remotePeer.addresses.length === 0 &&
34
+ address.value === currentNode.parent.value) {
35
+ // leader - use known address
36
+ return currentNode.parent;
37
+ }
38
+ address.setTransports(remotePeer.addresses.map(({ multiaddr }) => {
39
+ return new oNodeTransport(multiaddr);
40
+ }));
41
+ return address;
13
42
  }
14
- // Get origin address for comparison
15
- const originAddress = currentNode.address?.value;
16
- if (!originAddress) {
17
- throw new Error('Origin address is not configured');
43
+ catch (e) {
44
+ console.error('Failed to get address from connection:', e);
45
+ throw new oError(oErrorCodes.UNKNOWN, 'Failed to get address from connection');
18
46
  }
19
- const originProtocol = originAddress.toString();
20
- const oProtocol = remotePeer.protocols.find((p) => p.startsWith('/o/') && p.startsWith(originProtocol) === false);
21
- if (!oProtocol) {
22
- throw new Error('Failed to extract remote address, could not find o-protocol in peer protocols.');
23
- }
24
- return oNodeAddress.fromProtocol(oProtocol);
25
47
  }
26
48
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-node",
3
- "version": "0.7.41",
3
+ "version": "0.7.42",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -40,7 +40,7 @@
40
40
  "devDependencies": {
41
41
  "@eslint/eslintrc": "^3.3.1",
42
42
  "@eslint/js": "^9.29.0",
43
- "@olane/o-test": "0.7.41",
43
+ "@olane/o-test": "0.7.42",
44
44
  "@tsconfig/node20": "^20.1.6",
45
45
  "@types/jest": "^30.0.0",
46
46
  "@types/json5": "^2.2.0",
@@ -60,13 +60,13 @@
60
60
  "typescript": "5.4.5"
61
61
  },
62
62
  "dependencies": {
63
- "@olane/o-config": "0.7.41",
64
- "@olane/o-core": "0.7.41",
65
- "@olane/o-protocol": "0.7.41",
66
- "@olane/o-tool": "0.7.41",
63
+ "@olane/o-config": "0.7.42",
64
+ "@olane/o-core": "0.7.42",
65
+ "@olane/o-protocol": "0.7.42",
66
+ "@olane/o-tool": "0.7.42",
67
67
  "debug": "^4.4.1",
68
68
  "dotenv": "^16.5.0",
69
69
  "json5": "^2.2.3"
70
70
  },
71
- "gitHead": "f705ab1099e0df6220c8f1d9a44e5b6cd09eb224"
71
+ "gitHead": "689465b34c2aefe28b6c87e3822d69651f2a49b7"
72
72
  }