@olane/o-node 0.7.1 → 0.7.3
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/connection/o-node-connection.d.ts +3 -3
- package/dist/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +19 -14
- package/dist/src/connection/o-node-connection.manager.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.manager.js +13 -13
- package/dist/src/o-node.d.ts +1 -0
- package/dist/src/o-node.d.ts.map +1 -1
- package/dist/src/o-node.js +32 -18
- package/dist/src/o-node.tool.d.ts +2 -2
- package/dist/src/o-node.tool.d.ts.map +1 -1
- package/dist/src/o-node.tool.js +33 -25
- package/dist/src/router/o-node.router.d.ts.map +1 -1
- package/dist/src/router/o-node.router.js +11 -10
- package/package.json +6 -6
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { Connection } from '@olane/o-config';
|
|
1
|
+
import { Connection, Stream } from '@olane/o-config';
|
|
2
2
|
import { oConnection, oRequest, oResponse } from '@olane/o-core';
|
|
3
3
|
import { oNodeConnectionConfig } from './interfaces/o-node-connection.config.js';
|
|
4
4
|
export declare class oNodeConnection extends oConnection {
|
|
5
5
|
protected readonly config: oNodeConnectionConfig;
|
|
6
|
-
|
|
6
|
+
p2pConnection: Connection;
|
|
7
7
|
constructor(config: oNodeConnectionConfig);
|
|
8
|
-
read(source:
|
|
8
|
+
read(source: Stream): Promise<any>;
|
|
9
9
|
validate(): void;
|
|
10
10
|
transmit(request: oRequest): Promise<oResponse>;
|
|
11
11
|
close(): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"o-node-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EAIV,MAAM,EAEP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACL,WAAW,EAGX,QAAQ,EACR,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAEjF,qBAAa,eAAgB,SAAQ,WAAW;IAGlC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IAFrD,aAAa,EAAE,UAAU,CAAC;gBAEF,MAAM,EAAE,qBAAqB;IAKtD,IAAI,CAAC,MAAM,EAAE,MAAM;IAWzB,QAAQ;IAOF,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAuC/C,KAAK;CAKZ"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Uint8ArrayList,
|
|
1
|
+
import { Uint8ArrayList, byteStream, } from '@olane/o-config';
|
|
2
2
|
import { oConnection, oError, oErrorCodes, oResponse, } from '@olane/o-core';
|
|
3
3
|
export class oNodeConnection extends oConnection {
|
|
4
4
|
constructor(config) {
|
|
@@ -7,12 +7,13 @@ export class oNodeConnection extends oConnection {
|
|
|
7
7
|
this.p2pConnection = config.p2pConnection;
|
|
8
8
|
}
|
|
9
9
|
async read(source) {
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const bytes = byteStream(source);
|
|
11
|
+
const output = await bytes.read({
|
|
12
|
+
signal: AbortSignal.timeout(5000),
|
|
13
|
+
});
|
|
14
|
+
const outputObj = output instanceof Uint8ArrayList ? output.subarray() : output;
|
|
15
|
+
const jsonStr = new TextDecoder().decode(outputObj);
|
|
16
|
+
return JSON.parse(jsonStr);
|
|
16
17
|
}
|
|
17
18
|
validate() {
|
|
18
19
|
if (this.config.p2pConnection.status !== 'open') {
|
|
@@ -22,14 +23,18 @@ export class oNodeConnection extends oConnection {
|
|
|
22
23
|
}
|
|
23
24
|
async transmit(request) {
|
|
24
25
|
try {
|
|
25
|
-
const stream = await this.p2pConnection.newStream(this.nextHopAddress.protocol
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
26
|
+
const stream = await this.p2pConnection.newStream(this.nextHopAddress.protocol, {
|
|
27
|
+
maxOutboundStreams: Infinity,
|
|
28
|
+
});
|
|
29
|
+
if (!stream || (stream.status !== 'open' && stream.status !== 'reset')) {
|
|
30
|
+
throw new oError(oErrorCodes.FAILED_TO_DIAL_TARGET, 'Failed to dial target');
|
|
31
|
+
}
|
|
32
|
+
if (stream.status === 'reset') {
|
|
33
|
+
throw new oError(oErrorCodes.CONNECTION_LIMIT_REACHED, 'Connection limit reached');
|
|
34
|
+
}
|
|
30
35
|
// Send the data
|
|
31
|
-
await stream.
|
|
32
|
-
const res = await this.read(stream
|
|
36
|
+
await stream.send(new TextEncoder().encode(request.toString()));
|
|
37
|
+
const res = await this.read(stream);
|
|
33
38
|
// process the response
|
|
34
39
|
const response = new oResponse({
|
|
35
40
|
...res.result,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node-connection.manager.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAEhG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,4BAA4B;IAKhD;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"o-node-connection.manager.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAE5C,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAEhG,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,qBAAa,sBAAuB,SAAQ,kBAAkB;IAC5D,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,4BAA4B;IAKhD;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,eAAe,CAAC;IAkDlE,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIpC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI;CAe3D"}
|
|
@@ -14,18 +14,18 @@ export class oNodeConnectionManager extends oConnectionManager {
|
|
|
14
14
|
const { address, nextHopAddress, callerAddress } = config;
|
|
15
15
|
// check if we already have a connection to this address
|
|
16
16
|
// TODO: how can we enable caching of connections & connection lifecycles
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
17
|
+
if (this.isCached(nextHopAddress)) {
|
|
18
|
+
const cachedConnection = this.getCachedConnection(nextHopAddress);
|
|
19
|
+
if (cachedConnection &&
|
|
20
|
+
cachedConnection.p2pConnection.status === 'open') {
|
|
21
|
+
this.logger.debug('Using cached connection for address: ' + address.toString());
|
|
22
|
+
return cachedConnection;
|
|
23
|
+
}
|
|
24
|
+
else {
|
|
25
|
+
// cached item is not valid, remove it
|
|
26
|
+
this.cache.delete(nextHopAddress.toString());
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
29
|
// first time setup connection
|
|
30
30
|
try {
|
|
31
31
|
const p2pConnection = await this.p2pNode.dial(nextHopAddress.libp2pTransports.map((ma) => ma.toMultiaddr()));
|
|
@@ -35,7 +35,7 @@ export class oNodeConnectionManager extends oConnectionManager {
|
|
|
35
35
|
p2pConnection: p2pConnection,
|
|
36
36
|
callerAddress: callerAddress,
|
|
37
37
|
});
|
|
38
|
-
// this.cache.set(
|
|
38
|
+
// this.cache.set(nextHopAddress.toString(), connection);
|
|
39
39
|
return connection;
|
|
40
40
|
}
|
|
41
41
|
catch (error) {
|
package/dist/src/o-node.d.ts
CHANGED
|
@@ -35,6 +35,7 @@ export declare class oNode extends oToolBase {
|
|
|
35
35
|
* @returns The libp2p config
|
|
36
36
|
*/
|
|
37
37
|
configure(): Promise<Libp2pConfig>;
|
|
38
|
+
protected createNode(): Promise<Libp2p>;
|
|
38
39
|
connect(nextHopAddress: oNodeAddress, targetAddress: oNodeAddress): Promise<oNodeConnection>;
|
|
39
40
|
initialize(): Promise<void>;
|
|
40
41
|
teardown(): Promise<void>;
|
package/dist/src/o-node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,OAAO,EAAG,MAAM,CAAC;IACjB,OAAO,EAAG,YAAY,CAAC;IACvB,MAAM,EAAE,WAAW,CAAC;IACpB,iBAAiB,EAAG,sBAAsB,CAAC;IAC3C,gBAAgB,EAAG,qBAAqB,CAAC;IAChD,SAAS,CAAC,WAAW,EAAE,OAAO,CAAS;gBAE3B,MAAM,EAAE,WAAW;IAK/B,IAAI,MAAM,IAAI,YAAY,GAAG,IAAI,CAEhC;IAED,IAAI,aAAa,IAAI,YAAY,CAKhC;IAED,IAAI,YAAY,IAAI,MAAM,GAAG,IAAI,CAOhC;IAED,mBAAmB,IAAI,GAAG,EAAE;IAItB,gBAAgB,IAAI,OAAO,CAAC,IAAI,CAAC;IASvC,IAAI,aAAa,IAAI,YAAY,CAEhC;IAED,IAAI,gBAAgB,IAAI,cAAc,EAAE,CAEvC;IAED,IAAI,UAAU,IAAI,cAAc,EAAE,CAIjC;IAEK,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAsB3B,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAuC/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;CAMhC"}
|
package/dist/src/o-node.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createNode, defaultLibp2pConfig, } from '@olane/o-config';
|
|
2
2
|
import { v4 as uuidv4 } from 'uuid';
|
|
3
3
|
import { oNodeRouter } from './router/o-node.router.js';
|
|
4
4
|
import { oNodeHierarchyManager } from './o-node.hierarchy-manager.js';
|
|
@@ -7,7 +7,6 @@ import { CoreUtils, NodeState, NodeType, oAddress, RestrictedAddresses, } from '
|
|
|
7
7
|
import { oNodeAddress } from './router/o-node.address.js';
|
|
8
8
|
import { oNodeConnectionManager } from './connection/o-node-connection.manager.js';
|
|
9
9
|
import { oNodeResolver } from './router/resolvers/o-node.resolver.js';
|
|
10
|
-
import { NetworkUtils } from './utils/network.utils.js';
|
|
11
10
|
import { oMethodResolver, oToolBase } from '@olane/o-tool';
|
|
12
11
|
import { oLeaderResolverFallback } from './router/index.js';
|
|
13
12
|
export class oNode extends oToolBase {
|
|
@@ -20,7 +19,10 @@ export class oNode extends oToolBase {
|
|
|
20
19
|
return this.isLeader ? this.address : this.config?.leader || null;
|
|
21
20
|
}
|
|
22
21
|
get networkConfig() {
|
|
23
|
-
return
|
|
22
|
+
return {
|
|
23
|
+
...defaultLibp2pConfig,
|
|
24
|
+
...(this.config.network || {}),
|
|
25
|
+
};
|
|
24
26
|
}
|
|
25
27
|
get parentPeerId() {
|
|
26
28
|
if (!this.parent || this.parent?.transports?.length === 0) {
|
|
@@ -109,7 +111,11 @@ export class oNode extends oToolBase {
|
|
|
109
111
|
}
|
|
110
112
|
async start() {
|
|
111
113
|
await super.start();
|
|
112
|
-
await NetworkUtils.advertiseToNetwork(
|
|
114
|
+
// await NetworkUtils.advertiseToNetwork(
|
|
115
|
+
// this.address,
|
|
116
|
+
// this.staticAddress,
|
|
117
|
+
// this.p2pNode,
|
|
118
|
+
// );
|
|
113
119
|
}
|
|
114
120
|
async validateJoinRequest(request) {
|
|
115
121
|
return true;
|
|
@@ -120,11 +126,9 @@ export class oNode extends oToolBase {
|
|
|
120
126
|
*/
|
|
121
127
|
async configure() {
|
|
122
128
|
const params = {
|
|
129
|
+
...defaultLibp2pConfig,
|
|
123
130
|
...this.networkConfig,
|
|
124
131
|
transports: this.configureTransports(),
|
|
125
|
-
connectionManager: {
|
|
126
|
-
...(this.networkConfig.connectionManager || {}),
|
|
127
|
-
},
|
|
128
132
|
listeners: (this.config.network?.listeners ||
|
|
129
133
|
defaultLibp2pConfig.listeners ||
|
|
130
134
|
[]).concat(`/memory/${uuidv4()}`), // ensure we allow for local in-memory communication
|
|
@@ -144,13 +148,21 @@ export class oNode extends oToolBase {
|
|
|
144
148
|
if (this.parentTransports.length > 0) {
|
|
145
149
|
// peer discovery is only allowed through the parent transports
|
|
146
150
|
const transports = this.parentTransports.map((t) => t.toMultiaddr().toString()) || [];
|
|
147
|
-
this.logger.debug('Parent transports: ', transports);
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
// this.logger.debug('Parent transports: ', transports);
|
|
152
|
+
// this.logger.debug(
|
|
153
|
+
// 'Bootstrap transports: ',
|
|
154
|
+
// transports.concat(
|
|
155
|
+
// this.leader?.libp2pTransports.map((t) => t.toString()) || [],
|
|
156
|
+
// ),
|
|
157
|
+
// );
|
|
158
|
+
// params.peerDiscovery = [
|
|
159
|
+
// bootstrap({
|
|
160
|
+
// list: transports.concat(
|
|
161
|
+
// this.leader?.libp2pTransports.map((t) => t.toString()) || [],
|
|
162
|
+
// ),
|
|
163
|
+
// }),
|
|
164
|
+
// ...(defaultLibp2pConfig.peerDiscovery || []),
|
|
165
|
+
// ];
|
|
154
166
|
// // let's make sure we only allow communication through the parent transports
|
|
155
167
|
params.connectionGater = {
|
|
156
168
|
// who can call us?
|
|
@@ -177,12 +189,15 @@ export class oNode extends oToolBase {
|
|
|
177
189
|
if (this.config.leader &&
|
|
178
190
|
!this.address.protocol.includes(this.config.leader.protocol)) {
|
|
179
191
|
const parentAddress = this.config.parent || this.config.leader;
|
|
180
|
-
this.logger.debug('Encapsulating address: ' + this.address.toString(), parentAddress.toString());
|
|
181
192
|
this.address = CoreUtils.childAddress(parentAddress, this.address);
|
|
182
|
-
this.logger.debug('Encapsulated address: ' + this.address.toString());
|
|
183
193
|
}
|
|
184
194
|
return params;
|
|
185
195
|
}
|
|
196
|
+
async createNode() {
|
|
197
|
+
const params = await this.configure();
|
|
198
|
+
this.p2pNode = await createNode(params);
|
|
199
|
+
return this.p2pNode;
|
|
200
|
+
}
|
|
186
201
|
async connect(nextHopAddress, targetAddress) {
|
|
187
202
|
if (!this.connectionManager) {
|
|
188
203
|
this.logger.error('Connection manager not initialized');
|
|
@@ -214,8 +229,7 @@ export class oNode extends oToolBase {
|
|
|
214
229
|
if (!this.address.validate()) {
|
|
215
230
|
throw new Error('Invalid address');
|
|
216
231
|
}
|
|
217
|
-
|
|
218
|
-
this.p2pNode = await createNode(params);
|
|
232
|
+
await this.createNode();
|
|
219
233
|
await this.initializeRouter();
|
|
220
234
|
this.logger.debug('Node initialized!', this.transports.map((t) => t.toString()));
|
|
221
235
|
this.address.setTransports(this.transports);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { oAddress } from '@olane/o-core';
|
|
2
|
-
import { IncomingStreamData } from '@olane/o-config';
|
|
3
2
|
import { oServerNode } from './nodes/server.node.js';
|
|
3
|
+
import { Connection, Stream } from '@olane/o-config';
|
|
4
4
|
declare const oNodeTool_base: typeof oServerNode;
|
|
5
5
|
/**
|
|
6
6
|
* oTool is a mixin that extends the base class and implements the oTool interface
|
|
@@ -10,7 +10,7 @@ declare const oNodeTool_base: typeof oServerNode;
|
|
|
10
10
|
export declare class oNodeTool extends oNodeTool_base {
|
|
11
11
|
handleProtocol(address: oAddress): Promise<void>;
|
|
12
12
|
initialize(): Promise<void>;
|
|
13
|
-
handleStream(
|
|
13
|
+
handleStream(stream: Stream, connection: Connection): Promise<void>;
|
|
14
14
|
}
|
|
15
15
|
export {};
|
|
16
16
|
//# 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;
|
|
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"}
|
package/dist/src/o-node.tool.js
CHANGED
|
@@ -9,7 +9,10 @@ import { oServerNode } from './nodes/server.node.js';
|
|
|
9
9
|
export class oNodeTool extends oTool(oServerNode) {
|
|
10
10
|
async handleProtocol(address) {
|
|
11
11
|
this.logger.debug('Handling protocol: ' + address.protocol);
|
|
12
|
-
await this.p2pNode.handle(address.protocol, this.handleStream.bind(this)
|
|
12
|
+
await this.p2pNode.handle(address.protocol, this.handleStream.bind(this), {
|
|
13
|
+
maxInboundStreams: Infinity,
|
|
14
|
+
maxOutboundStreams: Infinity,
|
|
15
|
+
});
|
|
13
16
|
}
|
|
14
17
|
async initialize() {
|
|
15
18
|
await super.initialize();
|
|
@@ -19,30 +22,35 @@ export class oNodeTool extends oTool(oServerNode) {
|
|
|
19
22
|
await this.handleProtocol(this.staticAddress);
|
|
20
23
|
}
|
|
21
24
|
}
|
|
22
|
-
async handleStream(
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
:
|
|
33
|
-
|
|
34
|
-
error
|
|
35
|
-
|
|
25
|
+
async handleStream(stream, connection) {
|
|
26
|
+
stream.addEventListener('message', async (event) => {
|
|
27
|
+
if (!event.data) {
|
|
28
|
+
this.logger.warn('Malformed event data');
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
const requestConfig = await CoreUtils.processStream(event);
|
|
32
|
+
const request = new oRequest(requestConfig);
|
|
33
|
+
let success = true;
|
|
34
|
+
const result = await this.execute(request, stream).catch((error) => {
|
|
35
|
+
this.logger.error('Error executing tool: ', request.toString(), error, typeof error);
|
|
36
|
+
success = false;
|
|
37
|
+
const responseError = error instanceof oError
|
|
38
|
+
? error
|
|
39
|
+
: new oError(oErrorCodes.UNKNOWN, error.message);
|
|
40
|
+
return {
|
|
41
|
+
error: responseError.toJSON(),
|
|
42
|
+
};
|
|
43
|
+
});
|
|
44
|
+
if (success) {
|
|
45
|
+
this.metrics.successCount++;
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
this.metrics.errorCount++;
|
|
49
|
+
}
|
|
50
|
+
// compose the response & add the expected connection + request fields
|
|
51
|
+
const response = CoreUtils.buildResponse(request, result, result?.error);
|
|
52
|
+
// add the request method to the response
|
|
53
|
+
await CoreUtils.sendResponse(response, stream);
|
|
36
54
|
});
|
|
37
|
-
if (success) {
|
|
38
|
-
this.metrics.successCount++;
|
|
39
|
-
}
|
|
40
|
-
else {
|
|
41
|
-
this.metrics.errorCount++;
|
|
42
|
-
}
|
|
43
|
-
// compose the response & add the expected connection + request fields
|
|
44
|
-
const response = CoreUtils.buildResponse(request, result, result?.error);
|
|
45
|
-
// add the request method to the response
|
|
46
|
-
return CoreUtils.sendResponse(response, stream);
|
|
47
55
|
}
|
|
48
56
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.router.d.ts","sourceRoot":"","sources":["../../../src/router/o-node.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,
|
|
1
|
+
{"version":3,"file":"o-node.router.d.ts","sourceRoot":"","sources":["../../../src/router/o-node.router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAML,cAAc,EACd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAG5C,qBAAa,WAAY,SAAQ,WAAW;;cAK1B,OAAO,CACrB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,GAAG,CAAC;IA2Ef,OAAO,CAAC,qBAAqB;IAsBvB,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC;IAqB3E,UAAU,CAAC,qBAAqB,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO;CAetE"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { oNodeAddress } from './o-node.address.js';
|
|
2
2
|
import { CoreUtils, oAddress, oError, oErrorCodes, oRequest, } from '@olane/o-core';
|
|
3
3
|
import { oToolRouter } from '@olane/o-tool';
|
|
4
|
-
import {
|
|
4
|
+
import { oNodeConnection } from '../connection/o-node-connection.js';
|
|
5
5
|
export class oNodeRouter extends oToolRouter {
|
|
6
6
|
constructor() {
|
|
7
7
|
super();
|
|
@@ -49,15 +49,15 @@ export class oNodeRouter extends oToolRouter {
|
|
|
49
49
|
}
|
|
50
50
|
// dial the target
|
|
51
51
|
try {
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
await
|
|
60
|
-
await
|
|
52
|
+
const connection = await node?.p2pNode.dial(address.libp2pTransports.map((t) => t.toMultiaddr()));
|
|
53
|
+
const nodeConnection = new oNodeConnection({
|
|
54
|
+
p2pConnection: connection,
|
|
55
|
+
nextHopAddress: address,
|
|
56
|
+
address: node.address,
|
|
57
|
+
callerAddress: node.address,
|
|
58
|
+
});
|
|
59
|
+
await nodeConnection.transmit(nextHopRequest);
|
|
60
|
+
// await stream.send(new TextEncoder().encode(response.toString()));
|
|
61
61
|
}
|
|
62
62
|
catch (error) {
|
|
63
63
|
if (error?.name === 'UnsupportedProtocolError') {
|
|
@@ -83,6 +83,7 @@ export class oNodeRouter extends oToolRouter {
|
|
|
83
83
|
async translate(address, node) {
|
|
84
84
|
const externalRoute = this.handleExternalAddress(address, node);
|
|
85
85
|
if (externalRoute) {
|
|
86
|
+
this.logger.debug('External route found', externalRoute);
|
|
86
87
|
return externalRoute;
|
|
87
88
|
}
|
|
88
89
|
const { nextHopAddress, targetAddress, requestOverride } = await this.addressResolution.resolve({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-node",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.3",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
"url": "git+https://github.com/olane-labs/olane.git"
|
|
34
34
|
},
|
|
35
35
|
"author": "oLane Inc.",
|
|
36
|
-
"license": "
|
|
36
|
+
"license": "(MIT OR Apache-2.0)",
|
|
37
37
|
"description": "oLane p2p node used to host agentic functionality",
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@eslint/eslintrc": "^3.3.1",
|
|
@@ -56,10 +56,10 @@
|
|
|
56
56
|
"typescript": "5.4.5"
|
|
57
57
|
},
|
|
58
58
|
"peerDependencies": {
|
|
59
|
-
"@olane/o-config": "^0.7.
|
|
60
|
-
"@olane/o-core": "^0.7.
|
|
61
|
-
"@olane/o-protocol": "^0.7.
|
|
62
|
-
"@olane/o-tool": "^0.7.
|
|
59
|
+
"@olane/o-config": "^0.7.2",
|
|
60
|
+
"@olane/o-core": "^0.7.2",
|
|
61
|
+
"@olane/o-protocol": "^0.7.2",
|
|
62
|
+
"@olane/o-tool": "^0.7.2"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
65
|
"debug": "^4.4.1",
|