@olane/o-node 0.7.51 → 0.7.52
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/index.d.ts +6 -5
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +6 -5
- package/dist/src/connection/interfaces/{o-node-connection-stream.config.d.ts → o-node-stream.config.d.ts} +2 -2
- package/dist/src/connection/interfaces/o-node-stream.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/stream-init-message.d.ts +29 -0
- package/dist/src/connection/interfaces/stream-init-message.d.ts.map +1 -0
- package/dist/src/connection/interfaces/stream-init-message.js +8 -0
- package/dist/src/connection/interfaces/stream-manager.config.d.ts +8 -0
- package/dist/src/connection/interfaces/stream-manager.config.d.ts.map +1 -0
- package/dist/src/connection/o-node-connection.d.ts +5 -7
- package/dist/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +26 -56
- package/dist/src/connection/o-node-connection.manager.d.ts +7 -0
- package/dist/src/connection/o-node-connection.manager.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.manager.js +23 -5
- package/dist/src/connection/{o-node-connection-stream.d.ts → o-node-stream.d.ts} +6 -6
- package/dist/src/connection/o-node-stream.d.ts.map +1 -0
- package/dist/src/connection/{o-node-connection-stream.js → o-node-stream.js} +2 -2
- package/dist/src/connection/o-node-stream.manager.d.ts +181 -0
- package/dist/src/connection/o-node-stream.manager.d.ts.map +1 -0
- package/dist/src/connection/o-node-stream.manager.js +526 -0
- package/dist/src/connection/stream-manager.events.d.ts +83 -0
- package/dist/src/connection/stream-manager.events.d.ts.map +1 -0
- package/dist/src/connection/stream-manager.events.js +18 -0
- package/dist/src/o-node.tool.d.ts +0 -1
- package/dist/src/o-node.tool.d.ts.map +1 -1
- package/dist/src/o-node.tool.js +30 -20
- package/dist/test/helpers/stream-pool-test-helpers.d.ts +0 -75
- package/dist/test/helpers/stream-pool-test-helpers.d.ts.map +1 -1
- package/dist/test/helpers/stream-pool-test-helpers.js +262 -229
- package/dist/test/parent-child-registration.spec.js +1 -0
- package/package.json +7 -7
- package/dist/src/connection/interfaces/o-node-connection-stream.config.d.ts.map +0 -1
- package/dist/src/connection/interfaces/stream-pool-manager.config.d.ts +0 -41
- package/dist/src/connection/interfaces/stream-pool-manager.config.d.ts.map +0 -1
- package/dist/src/connection/o-node-connection-stream.d.ts.map +0 -1
- package/dist/src/connection/stream-handler.d.ts +0 -102
- package/dist/src/connection/stream-handler.d.ts.map +0 -1
- package/dist/src/connection/stream-handler.js +0 -357
- package/dist/src/connection/stream-pool-manager.d.ts +0 -86
- package/dist/src/connection/stream-pool-manager.d.ts.map +0 -1
- package/dist/src/connection/stream-pool-manager.events.d.ts +0 -57
- package/dist/src/connection/stream-pool-manager.events.d.ts.map +0 -1
- package/dist/src/connection/stream-pool-manager.events.js +0 -14
- package/dist/src/connection/stream-pool-manager.js +0 -356
- /package/dist/src/connection/interfaces/{o-node-connection-stream.config.js → o-node-stream.config.js} +0 -0
- /package/dist/src/connection/interfaces/{stream-pool-manager.config.js → stream-manager.config.js} +0 -0
package/dist/src/o-node.tool.js
CHANGED
|
@@ -3,8 +3,8 @@ import { oTool } from '@olane/o-tool';
|
|
|
3
3
|
import { oServerNode } from './nodes/server.node.js';
|
|
4
4
|
import { oNodeTransport } from './router/o-node.transport.js';
|
|
5
5
|
import { oNodeAddress } from './router/o-node.address.js';
|
|
6
|
-
import { StreamHandler } from './connection/stream-handler.js';
|
|
7
6
|
import { ConnectionUtils } from './utils/connection.utils.js';
|
|
7
|
+
import { StreamManagerEvent } from './connection/stream-manager.events.js';
|
|
8
8
|
/**
|
|
9
9
|
* oTool is a mixin that extends the base class and implements the oTool interface
|
|
10
10
|
* @param Base - The base class to extend
|
|
@@ -60,7 +60,6 @@ export class oNodeTool extends oTool(oServerNode) {
|
|
|
60
60
|
}
|
|
61
61
|
async initialize() {
|
|
62
62
|
await super.initialize();
|
|
63
|
-
this.streamHandler = new StreamHandler(this.logger);
|
|
64
63
|
await this.initializeProtocols();
|
|
65
64
|
}
|
|
66
65
|
async handleStreamReuse(stream, connection) {
|
|
@@ -70,32 +69,43 @@ export class oNodeTool extends oTool(oServerNode) {
|
|
|
70
69
|
if (reuse) {
|
|
71
70
|
this.logger.debug('Handle stream with reuse = true');
|
|
72
71
|
// record inbound connection to manager
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
72
|
+
}
|
|
73
|
+
const remoteAddress = await ConnectionUtils.addressFromConnection({
|
|
74
|
+
currentNode: this,
|
|
75
|
+
connection: connection,
|
|
76
|
+
});
|
|
77
|
+
this.connectionManager.answer({
|
|
78
|
+
nextHopAddress: remoteAddress,
|
|
79
|
+
address: remoteAddress,
|
|
80
|
+
callerAddress: this.address,
|
|
81
|
+
p2pConnection: connection,
|
|
82
|
+
reuse,
|
|
83
|
+
});
|
|
84
|
+
// Get the oNodeConnection for this libp2p connection
|
|
85
|
+
const oConnection = this.connectionManager.getConnectionByP2pConnection(connection);
|
|
86
|
+
if (!oConnection) {
|
|
87
|
+
this.logger.error('No oNodeConnection found for incoming stream', {
|
|
88
|
+
remotePeer: connection.remotePeer.toString(),
|
|
89
|
+
connectionId: connection.id,
|
|
84
90
|
});
|
|
91
|
+
return;
|
|
85
92
|
}
|
|
86
|
-
//
|
|
87
|
-
// This follows
|
|
88
|
-
|
|
93
|
+
// Subscribe to InboundRequest events from the stream manager
|
|
94
|
+
// This follows an event-driven pattern for handling incoming requests
|
|
95
|
+
oConnection.streamManager.on(StreamManagerEvent.InboundRequest, async (data) => {
|
|
89
96
|
try {
|
|
90
|
-
const result = await this.execute(request, stream);
|
|
91
|
-
// Return the raw result -
|
|
97
|
+
const result = await this.execute(data.request, data.stream);
|
|
98
|
+
// Return the raw result - StreamManager will build and send the response
|
|
92
99
|
return result;
|
|
93
100
|
}
|
|
94
101
|
catch (error) {
|
|
95
|
-
this.logger.error('Error executing tool: ', request.toString(), error, typeof error);
|
|
96
|
-
throw error; //
|
|
102
|
+
this.logger.error('Error executing tool: ', data.request.toString(), error, typeof error);
|
|
103
|
+
throw error; // StreamManager will handle error response building
|
|
97
104
|
}
|
|
98
105
|
});
|
|
106
|
+
// Use the connection's StreamManager for consistent stream handling
|
|
107
|
+
// This follows libp2p v3 best practices for length-prefixed streaming
|
|
108
|
+
await oConnection.streamManager.handleIncomingStream(stream, connection);
|
|
99
109
|
}
|
|
100
110
|
async _tool_identify() {
|
|
101
111
|
return {
|
|
@@ -1,76 +1 @@
|
|
|
1
|
-
import { oNodeConnectionStream } from '../../src/connection/o-node-connection-stream.js';
|
|
2
|
-
import { StreamPoolManagerConfig } from '../../src/index.js';
|
|
3
|
-
/**
|
|
4
|
-
* Create a mock stream for testing
|
|
5
|
-
*/
|
|
6
|
-
export declare function createMockStream(id?: string, options?: {
|
|
7
|
-
status?: 'open' | 'closed' | 'reset';
|
|
8
|
-
writeStatus?: 'writable' | 'writing' | 'closed';
|
|
9
|
-
readStatus?: 'readable' | 'reading' | 'closed';
|
|
10
|
-
remoteReadStatus?: 'readable' | 'reading' | 'closed';
|
|
11
|
-
}): any;
|
|
12
|
-
/**
|
|
13
|
-
* Create a mock P2P connection for testing
|
|
14
|
-
*/
|
|
15
|
-
export declare function createMockP2PConnection(id?: string, status?: 'open' | 'closed'): any;
|
|
16
|
-
/**
|
|
17
|
-
* Create a mock StreamHandler for testing
|
|
18
|
-
*/
|
|
19
|
-
export declare function createMockStreamHandler(): any;
|
|
20
|
-
/**
|
|
21
|
-
* Create a mock oNodeConnectionStream
|
|
22
|
-
*/
|
|
23
|
-
export declare function createMockConnectionStream(p2pStream?: any, streamType?: 'dedicated-reader' | 'request-response' | 'general'): oNodeConnectionStream;
|
|
24
|
-
/**
|
|
25
|
-
* Factory for creating StreamPoolManager test config
|
|
26
|
-
*/
|
|
27
|
-
export declare function createStreamPoolManagerConfig(overrides?: Partial<StreamPoolManagerConfig>): StreamPoolManagerConfig;
|
|
28
|
-
/**
|
|
29
|
-
* Event capture helper for testing event emissions
|
|
30
|
-
*/
|
|
31
|
-
export declare class EventCapture {
|
|
32
|
-
private emitter;
|
|
33
|
-
private events;
|
|
34
|
-
constructor(emitter: any);
|
|
35
|
-
/**
|
|
36
|
-
* Start capturing events
|
|
37
|
-
*/
|
|
38
|
-
start(eventNames: string[]): void;
|
|
39
|
-
/**
|
|
40
|
-
* Get all captured events
|
|
41
|
-
*/
|
|
42
|
-
getEvents(): Array<{
|
|
43
|
-
type: string;
|
|
44
|
-
data: any;
|
|
45
|
-
timestamp: number;
|
|
46
|
-
}>;
|
|
47
|
-
/**
|
|
48
|
-
* Get events of specific type
|
|
49
|
-
*/
|
|
50
|
-
getEventsByType(type: string): any[];
|
|
51
|
-
/**
|
|
52
|
-
* Check if event was emitted
|
|
53
|
-
*/
|
|
54
|
-
hasEvent(type: string): boolean;
|
|
55
|
-
/**
|
|
56
|
-
* Get count of specific event type
|
|
57
|
-
*/
|
|
58
|
-
getEventCount(type: string): number;
|
|
59
|
-
/**
|
|
60
|
-
* Wait for specific event
|
|
61
|
-
*/
|
|
62
|
-
waitForEvent(type: string, timeoutMs?: number): Promise<any>;
|
|
63
|
-
/**
|
|
64
|
-
* Clear captured events
|
|
65
|
-
*/
|
|
66
|
-
clear(): void;
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* Helper to make a stream invalid
|
|
70
|
-
*/
|
|
71
|
-
export declare function makeStreamInvalid(stream: any): void;
|
|
72
|
-
/**
|
|
73
|
-
* Helper to wait for condition with timeout
|
|
74
|
-
*/
|
|
75
|
-
export declare function waitFor(condition: () => boolean, timeoutMs?: number, intervalMs?: number): Promise<void>;
|
|
76
1
|
//# sourceMappingURL=stream-pool-test-helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-pool-test-helpers.d.ts","sourceRoot":"","sources":["../../../test/helpers/stream-pool-test-helpers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"stream-pool-test-helpers.d.ts","sourceRoot":"","sources":["../../../test/helpers/stream-pool-test-helpers.ts"],"names":[],"mappings":""}
|