@olane/o-node 0.7.12-alpha.4 → 0.7.12-alpha.5

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 +1 @@
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;IAyC/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;IAiD/C,KAAK;CAKZ"}
@@ -33,8 +33,14 @@ export class oNodeConnection extends oConnection {
33
33
  if (stream.status === 'reset') {
34
34
  throw new oError(oErrorCodes.CONNECTION_LIMIT_REACHED, 'Connection limit reached');
35
35
  }
36
- // Send the data
37
- await stream.send(new TextEncoder().encode(request.toString()));
36
+ // Send the data with backpressure handling (libp2p v3 best practice)
37
+ const data = new TextEncoder().encode(request.toString());
38
+ const sent = stream.send(data);
39
+ // If send() returns false, wait for the stream to drain before continuing
40
+ if (!sent) {
41
+ this.logger.debug('Stream buffer full, waiting for drain...');
42
+ await stream.onDrain({ signal: AbortSignal.timeout(30000) }); // 30 second timeout
43
+ }
38
44
  const res = await this.read(stream);
39
45
  await stream.close();
40
46
  // process the response
@@ -6,7 +6,7 @@ export declare class oNodeConnectionManager extends oConnectionManager {
6
6
  private p2pNode;
7
7
  constructor(config: oNodeConnectionManagerConfig);
8
8
  /**
9
- * Connect to a given address
9
+ * Connect to a given address with exponential backoff retry
10
10
  * @param address - The address to connect to
11
11
  * @returns The connection object
12
12
  */
@@ -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;IAkDlE,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;IAqFlE,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIpC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI;CAe3D"}
@@ -6,7 +6,7 @@ export class oNodeConnectionManager extends oConnectionManager {
6
6
  this.p2pNode = config.p2pNode;
7
7
  }
8
8
  /**
9
- * Connect to a given address
9
+ * Connect to a given address with exponential backoff retry
10
10
  * @param address - The address to connect to
11
11
  * @returns The connection object
12
12
  */
@@ -26,25 +26,45 @@ export class oNodeConnectionManager extends oConnectionManager {
26
26
  this.cache.delete(nextHopAddress.toString());
27
27
  }
28
28
  }
29
- // first time setup connection
30
- try {
31
- const p2pConnection = await this.p2pNode.dial(nextHopAddress.libp2pTransports.map((ma) => ma.toMultiaddr()));
32
- const connection = new oNodeConnection({
33
- nextHopAddress: nextHopAddress,
34
- address: address,
35
- p2pConnection: p2pConnection,
36
- callerAddress: callerAddress,
37
- });
38
- // this.cache.set(nextHopAddress.toString(), connection);
39
- return connection;
40
- }
41
- catch (error) {
42
- this.logger.error(`[${callerAddress?.toString() || 'unknown'}] Error connecting to address! Next hop:` +
43
- nextHopAddress +
44
- ' With Address:' +
45
- address.toString(), error);
46
- throw error;
29
+ // Retry configuration for handling transient connection failures
30
+ const MAX_RETRIES = 3;
31
+ const BASE_DELAY_MS = 1000; // Start with 1 second
32
+ const MAX_DELAY_MS = 10000; // Cap at 10 seconds
33
+ // first time setup connection with retry logic
34
+ let lastError;
35
+ for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
36
+ try {
37
+ if (attempt > 0) {
38
+ // Calculate exponential backoff delay: 1s, 2s, 4s, 8s (capped at MAX_DELAY_MS)
39
+ const delay = Math.min(BASE_DELAY_MS * Math.pow(2, attempt - 1), MAX_DELAY_MS);
40
+ this.logger.debug(`Retry attempt ${attempt}/${MAX_RETRIES} for ${nextHopAddress.toString()} after ${delay}ms delay`);
41
+ await new Promise((resolve) => setTimeout(resolve, delay));
42
+ }
43
+ const p2pConnection = await this.p2pNode.dial(nextHopAddress.libp2pTransports.map((ma) => ma.toMultiaddr()));
44
+ const connection = new oNodeConnection({
45
+ nextHopAddress: nextHopAddress,
46
+ address: address,
47
+ p2pConnection: p2pConnection,
48
+ callerAddress: callerAddress,
49
+ });
50
+ if (attempt > 0) {
51
+ this.logger.info(`Successfully connected to ${nextHopAddress.toString()} on retry attempt ${attempt}`);
52
+ }
53
+ // this.cache.set(nextHopAddress.toString(), connection);
54
+ return connection;
55
+ }
56
+ catch (error) {
57
+ lastError = error;
58
+ this.logger.warn(`[${callerAddress?.toString() || 'unknown'}] Connection attempt ${attempt + 1}/${MAX_RETRIES + 1} failed for ${nextHopAddress.toString()}: ${error instanceof Error ? error.message : String(error)}`);
59
+ // Don't retry on the last attempt
60
+ if (attempt === MAX_RETRIES) {
61
+ break;
62
+ }
63
+ }
47
64
  }
65
+ // All retries exhausted
66
+ this.logger.error(`[${callerAddress?.toString() || 'unknown'}] Failed to connect after ${MAX_RETRIES + 1} attempts to address! Next hop: ${nextHopAddress} With Address: ${address.toString()}`, lastError);
67
+ throw lastError;
48
68
  }
49
69
  isCached(address) {
50
70
  return this.cache.has(address.toString());
@@ -1 +1 @@
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
+ {"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;IAiDnE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAa5D"}
@@ -24,7 +24,10 @@ export class oNodeTool extends oTool(oServerNode) {
24
24
  }
25
25
  }
26
26
  async handleStream(stream, connection) {
27
- stream.addEventListener('message', async (event) => {
27
+ // CRITICAL: Attach message listener immediately to prevent buffer overflow (libp2p v3)
28
+ // Per libp2p migration guide: "If no message event handler is added, streams will
29
+ // buffer incoming data until a pre-configured limit is reached, after which the stream will be reset."
30
+ const messageHandler = async (event) => {
28
31
  if (!event.data) {
29
32
  this.logger.warn('Malformed event data');
30
33
  return;
@@ -52,7 +55,9 @@ export class oNodeTool extends oTool(oServerNode) {
52
55
  const response = CoreUtils.buildResponse(request, result, result?.error);
53
56
  // add the request method to the response
54
57
  await CoreUtils.sendResponse(response, stream);
55
- });
58
+ };
59
+ // Attach listener synchronously before any async operations
60
+ stream.addEventListener('message', messageHandler);
56
61
  }
57
62
  async _tool_identify() {
58
63
  return {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@olane/o-node",
3
- "version": "0.7.12-alpha.4",
3
+ "version": "0.7.12-alpha.5",
4
4
  "type": "module",
5
5
  "main": "dist/src/index.js",
6
6
  "types": "dist/src/index.d.ts",
@@ -54,12 +54,12 @@
54
54
  "typescript": "5.4.5"
55
55
  },
56
56
  "dependencies": {
57
- "@olane/o-config": "0.7.12-alpha.4",
57
+ "@olane/o-config": "0.7.12-alpha.5",
58
58
  "@olane/o-core": "0.7.12-alpha.4",
59
59
  "@olane/o-protocol": "0.7.12-alpha.4",
60
- "@olane/o-tool": "0.7.12-alpha.4",
60
+ "@olane/o-tool": "0.7.12-alpha.5",
61
61
  "debug": "^4.4.1",
62
62
  "dotenv": "^16.5.0"
63
63
  },
64
- "gitHead": "13c575d61a455fce146303f4060c6628851a7223"
64
+ "gitHead": "f0b799131f025624da04374b76e9aa373402f787"
65
65
  }