@olane/o-node 0.7.41 → 0.7.43
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/src/router/o-node.address.d.ts +1 -1
- package/dist/src/router/o-node.address.d.ts.map +1 -1
- package/dist/src/router/o-node.address.js +1 -1
- package/dist/src/utils/connection.utils.d.ts +1 -1
- package/dist/src/utils/connection.utils.d.ts.map +1 -1
- package/dist/src/utils/connection.utils.js +41 -19
- package/package.json +7 -7
|
@@ -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):
|
|
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,
|
|
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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.utils.d.ts","sourceRoot":"","sources":["../../../src/utils/connection.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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.
|
|
3
|
+
"version": "0.7.43",
|
|
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.
|
|
43
|
+
"@olane/o-test": "0.7.43",
|
|
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.
|
|
64
|
-
"@olane/o-core": "0.7.
|
|
65
|
-
"@olane/o-protocol": "0.7.
|
|
66
|
-
"@olane/o-tool": "0.7.
|
|
63
|
+
"@olane/o-config": "0.7.43",
|
|
64
|
+
"@olane/o-core": "0.7.43",
|
|
65
|
+
"@olane/o-protocol": "0.7.43",
|
|
66
|
+
"@olane/o-tool": "0.7.43",
|
|
67
67
|
"debug": "^4.4.1",
|
|
68
68
|
"dotenv": "^16.5.0",
|
|
69
69
|
"json5": "^2.2.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "12e63fad2b09173fbcf455d881276b7ca7b3344d"
|
|
72
72
|
}
|