@olane/o-node 0.7.37 → 0.7.39
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/interfaces/o-node-connection.config.d.ts +2 -0
- package/dist/src/connection/interfaces/o-node-connection.config.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.d.ts +2 -0
- package/dist/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +4 -5
- package/dist/src/connection/stream-handler.d.ts.map +1 -1
- package/dist/src/connection/stream-handler.js +13 -0
- package/package.json +7 -7
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Connection } from '@olane/o-config';
|
|
2
2
|
import { oConnectionConfig } from '@olane/o-core';
|
|
3
|
+
import type { StreamReusePolicy } from '../stream-handler.config.js';
|
|
3
4
|
export interface oNodeConnectionConfig extends oConnectionConfig {
|
|
4
5
|
p2pConnection: Connection;
|
|
5
6
|
runOnLimitedConnection?: boolean;
|
|
7
|
+
reusePolicy?: StreamReusePolicy;
|
|
6
8
|
}
|
|
7
9
|
//# sourceMappingURL=o-node-connection.config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node-connection.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"o-node-connection.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AAErE,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,aAAa,EAAE,UAAU,CAAC;IAC1B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,WAAW,CAAC,EAAE,iBAAiB,CAAC;CACjC"}
|
|
@@ -2,10 +2,12 @@ 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
|
import { StreamHandler } from './stream-handler.js';
|
|
5
|
+
import type { StreamReusePolicy } from './stream-handler.config.js';
|
|
5
6
|
export declare class oNodeConnection extends oConnection {
|
|
6
7
|
protected readonly config: oNodeConnectionConfig;
|
|
7
8
|
p2pConnection: Connection;
|
|
8
9
|
protected streamHandler: StreamHandler;
|
|
10
|
+
protected reusePolicy: StreamReusePolicy;
|
|
9
11
|
constructor(config: oNodeConnectionConfig);
|
|
10
12
|
validate(stream?: Stream): void;
|
|
11
13
|
getOrCreateStream(): Promise<Stream>;
|
|
@@ -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,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAEL,WAAW,EAGX,QAAQ,EACR,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"o-node-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAEL,WAAW,EAGX,QAAQ,EACR,SAAS,EACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AACjF,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,KAAK,EAEV,iBAAiB,EAClB,MAAM,4BAA4B,CAAC;AAEpC,qBAAa,eAAgB,SAAQ,WAAW;IAKlC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IAJrD,aAAa,EAAE,UAAU,CAAC;IACjC,SAAS,CAAC,aAAa,EAAE,aAAa,CAAC;IACvC,SAAS,CAAC,WAAW,EAAE,iBAAiB,CAAC;gBAEV,MAAM,EAAE,qBAAqB;IAO5D,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM;IAmBlB,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAkBpC,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IA2C/C,YAAY,CAAC,MAAM,EAAE,MAAM;IAQ3B,KAAK,CAAC,KAAK,EAAE,KAAK;IAMlB,KAAK;CAKZ"}
|
|
@@ -6,6 +6,7 @@ export class oNodeConnection extends oConnection {
|
|
|
6
6
|
this.config = config;
|
|
7
7
|
this.p2pConnection = config.p2pConnection;
|
|
8
8
|
this.streamHandler = new StreamHandler(this.logger);
|
|
9
|
+
this.reusePolicy = config.reusePolicy ?? 'none';
|
|
9
10
|
}
|
|
10
11
|
validate(stream) {
|
|
11
12
|
if (this.config.p2pConnection.status !== 'open') {
|
|
@@ -26,7 +27,7 @@ export class oNodeConnection extends oConnection {
|
|
|
26
27
|
? parseInt(process.env.MAX_OUTBOUND_STREAMS)
|
|
27
28
|
: 1000,
|
|
28
29
|
runOnLimitedConnection: this.config.runOnLimitedConnection ?? true,
|
|
29
|
-
reusePolicy:
|
|
30
|
+
reusePolicy: this.reusePolicy,
|
|
30
31
|
drainTimeoutMs: this.config.drainTimeoutMs,
|
|
31
32
|
};
|
|
32
33
|
return this.streamHandler.getOrCreateStream(this.p2pConnection, this.nextHopAddress.protocol, streamConfig);
|
|
@@ -41,12 +42,10 @@ export class oNodeConnection extends oConnection {
|
|
|
41
42
|
const streamConfig = {
|
|
42
43
|
signal: this.abortSignal,
|
|
43
44
|
drainTimeoutMs: this.config.drainTimeoutMs,
|
|
44
|
-
reusePolicy:
|
|
45
|
+
reusePolicy: this.reusePolicy,
|
|
45
46
|
};
|
|
46
47
|
// Send the request with backpressure handling
|
|
47
48
|
const data = new TextEncoder().encode(request.toString());
|
|
48
|
-
// Send using length-prefixed encoding
|
|
49
|
-
this.logger.info('Sending length-prefixed message...');
|
|
50
49
|
await this.streamHandler.sendLengthPrefixed(stream, data, streamConfig);
|
|
51
50
|
// Handle response using StreamHandler
|
|
52
51
|
// Pass request handler if configured to enable bidirectional stream processing
|
|
@@ -65,7 +64,7 @@ export class oNodeConnection extends oConnection {
|
|
|
65
64
|
}
|
|
66
65
|
async postTransmit(stream) {
|
|
67
66
|
const streamConfig = {
|
|
68
|
-
reusePolicy:
|
|
67
|
+
reusePolicy: this.reusePolicy,
|
|
69
68
|
};
|
|
70
69
|
await this.streamHandler.close(stream, streamConfig);
|
|
71
70
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-handler.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-handler.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACL,QAAQ,EACR,SAAS,EAIT,MAAM,EAEP,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAC;AAItE;;;;;;;GAOG;AACH,qBAAa,aAA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,MAAM,EAChB,MAAM,GAAE,mBAAwB,GAC/B,OAAO,CAAC,MAAM,CAAC;IAwDlB;;;;;;;;OAQG;IACG,kBAAkB,CACtB,MAAM,EAAE,MAAM,EACd,IAAI,EAAE,UAAU,EAChB,MAAM,GAAE,mBAAwB,GAC/B,OAAO,CAAC,IAAI,CAAC;IAKhB;;;;;OAKG;IACG,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,GAAE,mBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiB5E;;;;;;;;OAQG;IACG,oBAAoB,CACxB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,UAAU,EACtB,YAAY,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,GACtE,OAAO,CAAC,IAAI,CAAC;IA+BhB;;;;;;OAMG;YACW,oBAAoB;IA6BlC;;;;;;;;;;OAUG;IACG,oBAAoB,CACxB,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,YAAY,EACrB,MAAM,GAAE,mBAAwB,EAChC,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,SAAS,CAAC,EAC1E,SAAS,CAAC,EAAE,MAAM,GAAG,MAAM,GAC1B,OAAO,CAAC,SAAS,CAAC;IAiErB;;;;;;;OAOG;IACG,cAAc,CAClB,OAAO,EAAE,cAAc,EACvB,cAAc,EAAE,MAAM,EACtB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,OAAO,CAAC,WAAW,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC;CAyBjB"}
|
|
@@ -79,10 +79,23 @@ export class StreamHandler {
|
|
|
79
79
|
* @param config - Stream handler configuration
|
|
80
80
|
*/
|
|
81
81
|
async getOrCreateStream(connection, protocol, config = {}) {
|
|
82
|
+
this.logger.debug(`Getting or creating stream for protocol: ${protocol}, connection`, {
|
|
83
|
+
status: connection.status,
|
|
84
|
+
remoteAddr: connection.remoteAddr.toString(),
|
|
85
|
+
streamCount: connection.streams.length,
|
|
86
|
+
reusePolicy: config.reusePolicy ?? 'none',
|
|
87
|
+
});
|
|
82
88
|
if (connection.status !== 'open') {
|
|
83
89
|
throw new oError(oErrorCodes.INVALID_STATE, 'Connection not open');
|
|
84
90
|
}
|
|
85
91
|
const reusePolicy = config.reusePolicy ?? 'none';
|
|
92
|
+
this.logger.debug('Checking for existing reusable stream', connection.streams.map((s) => ({
|
|
93
|
+
status: s.status,
|
|
94
|
+
protocol: s.protocol,
|
|
95
|
+
writeStatus: s.writeStatus,
|
|
96
|
+
remoteReadStatus: s.remoteReadStatus,
|
|
97
|
+
id: s.id,
|
|
98
|
+
})));
|
|
86
99
|
// Check for existing stream if reuse is enabled
|
|
87
100
|
if (reusePolicy === 'reuse') {
|
|
88
101
|
const existingStream = connection.streams.find((stream) => stream.status === 'open' &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-node",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.39",
|
|
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.39",
|
|
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.39",
|
|
64
|
+
"@olane/o-core": "0.7.39",
|
|
65
|
+
"@olane/o-protocol": "0.7.39",
|
|
66
|
+
"@olane/o-tool": "0.7.39",
|
|
67
67
|
"debug": "^4.4.1",
|
|
68
68
|
"dotenv": "^16.5.0",
|
|
69
69
|
"json5": "^2.2.3"
|
|
70
70
|
},
|
|
71
|
-
"gitHead": "
|
|
71
|
+
"gitHead": "9c992e3bda91a7d2b587392a1db5cff47a2ca23a"
|
|
72
72
|
}
|