@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.
@@ -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
- protected p2pConnection: Connection;
6
+ p2pConnection: Connection;
7
7
  constructor(config: oNodeConnectionConfig);
8
- read(source: any): Promise<any>;
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,EAAE,UAAU,EAAiC,MAAM,iBAAiB,CAAC;AAC5E,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;IAF5D,SAAS,CAAC,aAAa,EAAE,UAAU,CAAC;gBAEL,MAAM,EAAE,qBAAqB;IAKtD,IAAI,CAAC,MAAM,EAAE,GAAG;IAUtB,QAAQ;IAOF,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IA4B/C,KAAK;CAKZ"}
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, pushable, all } from '@olane/o-config';
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 chunks = await all(source);
11
- const data = new Uint8ArrayList(...chunks).slice();
12
- if (!data || data.length === 0) {
13
- throw new Error('No data received');
14
- }
15
- return JSON.parse(new TextDecoder().decode(data));
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
- // Create a pushable stream
27
- const pushableStream = pushable();
28
- pushableStream.push(new TextEncoder().encode(request.toString()));
29
- pushableStream.end();
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.sink(pushableStream);
32
- const res = await this.read(stream.source);
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;IA6ClE,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIpC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI;CAe3D"}
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
- // if (this.isCached(nextHopAddress)) {
18
- // const cachedConnection = this.getCachedConnection(nextHopAddress);
19
- // if (cachedConnection) {
20
- // this.logger.debug(
21
- // 'Using cached connection for address: ' + address.toString(),
22
- // );
23
- // return cachedConnection;
24
- // } else {
25
- // // cached item is not valid, remove it
26
- // this.cache.delete(nextHopAddress.toString());
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(address.toString(), connection);
38
+ // this.cache.set(nextHopAddress.toString(), connection);
39
39
  return connection;
40
40
  }
41
41
  catch (error) {
@@ -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>;
@@ -1 +1 @@
1
- {"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,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,OA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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"}
@@ -1,4 +1,4 @@
1
- import { bootstrap, createNode, defaultLibp2pConfig, } from '@olane/o-config';
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 this.config.network || defaultLibp2pConfig;
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(this.address, this.staticAddress, this.p2pNode);
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
- params.peerDiscovery = [
149
- bootstrap({
150
- list: transports.concat(this.leader?.libp2pTransports.map((t) => t.toString()) || []),
151
- }),
152
- ...(defaultLibp2pConfig.peerDiscovery || []),
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
- const params = await this.configure();
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(streamData: IncomingStreamData): Promise<void>;
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;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAErD,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;;AAErD;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAkB;IACzC,cAAc,CAAC,OAAO,EAAE,QAAQ;IAKhC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAW3B,YAAY,CAAC,UAAU,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;CAgClE"}
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"}
@@ -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(streamData) {
23
- const { stream } = streamData;
24
- const requestConfig = await CoreUtils.processStream(stream);
25
- const request = new oRequest(requestConfig);
26
- let success = true;
27
- const result = await this.execute(request, stream).catch((error) => {
28
- this.logger.error('Error executing tool: ', error, typeof error);
29
- success = false;
30
- const responseError = error instanceof oError
31
- ? error
32
- : new oError(oErrorCodes.UNKNOWN, error.message);
33
- return {
34
- error: responseError.toJSON(),
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,EAOL,cAAc,EACd,aAAa,EACd,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,qBAAa,WAAY,SAAQ,WAAW;;cAK1B,OAAO,CACrB,OAAO,EAAE,YAAY,EACrB,OAAO,EAAE,cAAc,EACvB,IAAI,EAAE,KAAK,GACV,OAAO,CAAC,GAAG,CAAC;IAgFf,OAAO,CAAC,qBAAqB;IAsBvB,SAAS,CAAC,OAAO,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO,CAAC,aAAa,CAAC;IAoB3E,UAAU,CAAC,qBAAqB,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,GAAG,OAAO;CAetE"}
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 { pipe, pushable } from '@olane/o-config';
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 targetStream = await node?.p2pNode.dialProtocol(address.libp2pTransports.map((t) => t.toMultiaddr()), address.protocol);
53
- if (!targetStream) {
54
- throw new oError(oErrorCodes.FAILED_TO_DIAL_TARGET, 'Failed to dial target');
55
- }
56
- const pushableStream = pushable();
57
- pushableStream.push(new TextEncoder().encode(nextHopRequest.toString()));
58
- pushableStream.end();
59
- await targetStream.sink(pushableStream);
60
- await pipe(targetStream.source, stream?.sink);
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.1",
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": "ISC",
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.0",
60
- "@olane/o-core": "^0.7.0",
61
- "@olane/o-protocol": "^0.7.0",
62
- "@olane/o-tool": "^0.7.0"
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",