@olane/o-client-limited 0.7.45 → 0.7.46
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,8 +1,15 @@
|
|
|
1
1
|
import { oNodeConnection, oNodeConnectionConfig, oNodeTool } from '@olane/o-node';
|
|
2
2
|
import { oNodeConfig } from '@olane/o-node';
|
|
3
3
|
export declare class oLimitedTool extends oNodeTool {
|
|
4
|
+
protected backgroundReaders: Map<string, boolean>;
|
|
4
5
|
constructor(config: oNodeConfig);
|
|
5
6
|
connect(config: oNodeConnectionConfig): Promise<oNodeConnection>;
|
|
7
|
+
/**
|
|
8
|
+
* Start a background reader on the stream to handle incoming requests.
|
|
9
|
+
* Uses handleIncomingStream which runs a persistent while loop,
|
|
10
|
+
* allowing the stream to receive multiple messages over its lifetime.
|
|
11
|
+
*/
|
|
12
|
+
private startBackgroundReader;
|
|
6
13
|
initConnectionManager(): Promise<void>;
|
|
7
14
|
}
|
|
8
15
|
//# sourceMappingURL=o-limited.tool.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-limited.tool.d.ts","sourceRoot":"","sources":["../../src/o-limited.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,SAAS,EACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"o-limited.tool.d.ts","sourceRoot":"","sources":["../../src/o-limited.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,SAAS,EACV,MAAM,eAAe,CAAC;AAEvB,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAI5C,qBAAa,YAAa,SAAQ,SAAS;IACzC,SAAS,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,CAAa;gBAElD,MAAM,EAAE,WAAW;IAUzB,OAAO,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IA2BtE;;;;OAIG;IACH,OAAO,CAAC,qBAAqB;IA8CvB,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC;CAQ7C"}
|
|
@@ -9,6 +9,7 @@ export class oLimitedTool extends oNodeTool {
|
|
|
9
9
|
listeners: config.network?.listeners || [], // default to no listeners
|
|
10
10
|
},
|
|
11
11
|
});
|
|
12
|
+
this.backgroundReaders = new Map();
|
|
12
13
|
}
|
|
13
14
|
async connect(config) {
|
|
14
15
|
this.handleProtocol(config.nextHopAddress).catch((error) => {
|
|
@@ -20,7 +21,46 @@ export class oLimitedTool extends oNodeTool {
|
|
|
20
21
|
...config,
|
|
21
22
|
requestHandler: this.execute.bind(this),
|
|
22
23
|
};
|
|
23
|
-
|
|
24
|
+
const connection = await super.connect(configWithHandler);
|
|
25
|
+
// Hook postTransmit to start background reader for reuse streams
|
|
26
|
+
const originalPostTransmit = connection.postTransmit.bind(connection);
|
|
27
|
+
connection.postTransmit = async (stream) => {
|
|
28
|
+
// Start background reader for bidirectional communication on reuse streams
|
|
29
|
+
if (connection.reusePolicy === 'reuse') {
|
|
30
|
+
this.startBackgroundReader(stream, connection);
|
|
31
|
+
}
|
|
32
|
+
await originalPostTransmit(stream);
|
|
33
|
+
};
|
|
34
|
+
return connection;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Start a background reader on the stream to handle incoming requests.
|
|
38
|
+
* Uses handleIncomingStream which runs a persistent while loop,
|
|
39
|
+
* allowing the stream to receive multiple messages over its lifetime.
|
|
40
|
+
*/
|
|
41
|
+
startBackgroundReader(stream, connection) {
|
|
42
|
+
const streamId = stream.p2pStream?.id || stream.id;
|
|
43
|
+
// Don't start duplicate readers for the same stream
|
|
44
|
+
if (this.backgroundReaders.get(streamId)) {
|
|
45
|
+
this.logger.debug('Background reader already running for stream:', streamId);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
this.backgroundReaders.set(streamId, true);
|
|
49
|
+
this.logger.debug('Starting background reader for stream:', streamId);
|
|
50
|
+
// Get the raw p2p stream
|
|
51
|
+
const p2pStream = stream.p2pStream || stream;
|
|
52
|
+
// Use the connection's streamHandler to handle incoming requests
|
|
53
|
+
const streamHandler = connection.streamHandler;
|
|
54
|
+
// Start the persistent read loop in the background
|
|
55
|
+
streamHandler
|
|
56
|
+
.handleIncomingStream(p2pStream, connection.p2pConnection, async (request, s) => {
|
|
57
|
+
this.logger.debug('Background reader received request:', request.method);
|
|
58
|
+
return this.execute(request, s);
|
|
59
|
+
})
|
|
60
|
+
.catch((error) => {
|
|
61
|
+
this.logger.debug('Background reader exited:', error?.message || 'stream closed');
|
|
62
|
+
this.backgroundReaders.delete(streamId);
|
|
63
|
+
});
|
|
24
64
|
}
|
|
25
65
|
async initConnectionManager() {
|
|
26
66
|
this.connectionManager = new oLimitedConnectionManager({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-client-limited",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.46",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -53,13 +53,13 @@
|
|
|
53
53
|
"typescript": "5.4.5"
|
|
54
54
|
},
|
|
55
55
|
"dependencies": {
|
|
56
|
-
"@olane/o-config": "0.7.
|
|
57
|
-
"@olane/o-core": "0.7.
|
|
58
|
-
"@olane/o-node": "0.7.
|
|
59
|
-
"@olane/o-protocol": "0.7.
|
|
60
|
-
"@olane/o-tool": "0.7.
|
|
56
|
+
"@olane/o-config": "0.7.46",
|
|
57
|
+
"@olane/o-core": "0.7.46",
|
|
58
|
+
"@olane/o-node": "0.7.46",
|
|
59
|
+
"@olane/o-protocol": "0.7.46",
|
|
60
|
+
"@olane/o-tool": "0.7.46",
|
|
61
61
|
"debug": "^4.4.1",
|
|
62
62
|
"dotenv": "^16.5.0"
|
|
63
63
|
},
|
|
64
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "48c45f37c6e2e1ee626ce1fb0f0de175ca2db3b6"
|
|
65
65
|
}
|