@olane/o-client-limited 0.7.51 → 0.7.53
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/o-limited-connection.d.ts +12 -21
- package/dist/src/connection/o-limited-connection.d.ts.map +1 -1
- package/dist/src/connection/o-limited-connection.js +31 -65
- package/dist/src/connection/o-limited.stream-manager.d.ts +79 -0
- package/dist/src/connection/o-limited.stream-manager.d.ts.map +1 -0
- package/dist/src/connection/o-limited.stream-manager.js +234 -0
- package/dist/test/bidirectional-communication.spec.d.ts +2 -0
- package/dist/test/bidirectional-communication.spec.d.ts.map +1 -0
- package/dist/test/bidirectional-communication.spec.js +265 -0
- package/dist/test/helpers/index.d.ts +2 -3
- package/dist/test/helpers/index.d.ts.map +1 -1
- package/dist/test/helpers/index.js +2 -3
- package/dist/test/helpers/limited-test-tool.d.ts +41 -0
- package/dist/test/helpers/limited-test-tool.d.ts.map +1 -0
- package/dist/test/helpers/limited-test-tool.js +98 -0
- package/dist/test/helpers/receiver-test-tool.d.ts +34 -0
- package/dist/test/helpers/receiver-test-tool.d.ts.map +1 -0
- package/dist/test/helpers/receiver-test-tool.js +67 -0
- package/dist/test/limited-connection-lifecycle.spec.d.ts +2 -0
- package/dist/test/limited-connection-lifecycle.spec.d.ts.map +1 -0
- package/dist/test/limited-connection-lifecycle.spec.js +209 -0
- package/dist/test/limited-stream-manager.spec.d.ts +2 -0
- package/dist/test/limited-stream-manager.spec.d.ts.map +1 -0
- package/dist/test/limited-stream-manager.spec.js +222 -0
- package/dist/test/reader-stream-recovery.spec.d.ts +2 -0
- package/dist/test/reader-stream-recovery.spec.d.ts.map +1 -0
- package/dist/test/reader-stream-recovery.spec.js +188 -0
- package/package.json +8 -8
- package/dist/test/configuration.spec.d.ts +0 -1
- package/dist/test/configuration.spec.d.ts.map +0 -1
- package/dist/test/configuration.spec.js +0 -335
- package/dist/test/error-handling.spec.d.ts +0 -2
- package/dist/test/error-handling.spec.d.ts.map +0 -1
- package/dist/test/error-handling.spec.js +0 -378
- package/dist/test/helpers/mock-p2p-connection.d.ts +0 -38
- package/dist/test/helpers/mock-p2p-connection.d.ts.map +0 -1
- package/dist/test/helpers/mock-p2p-connection.js +0 -66
- package/dist/test/helpers/mock-stream-handler.d.ts +0 -43
- package/dist/test/helpers/mock-stream-handler.d.ts.map +0 -1
- package/dist/test/helpers/mock-stream-handler.js +0 -71
- package/dist/test/helpers/mock-stream.d.ts +0 -46
- package/dist/test/helpers/mock-stream.d.ts.map +0 -1
- package/dist/test/helpers/mock-stream.js +0 -59
- package/dist/test/method.spec.d.ts +0 -1
- package/dist/test/method.spec.d.ts.map +0 -1
- package/dist/test/method.spec.js +0 -29
- package/dist/test/stream-reuse.spec.d.ts +0 -1
- package/dist/test/stream-reuse.spec.d.ts.map +0 -1
- package/dist/test/stream-reuse.spec.js +0 -267
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { TestEnvironment, createConnectionSpy, } from '@olane/o-node/test/helpers';
|
|
3
|
+
import { oNodeAddress } from '@olane/o-node';
|
|
4
|
+
import { LimitedTestTool, ReceiverTestTool } from './helpers/index.js';
|
|
5
|
+
describe('Bidirectional Communication', () => {
|
|
6
|
+
const env = new TestEnvironment();
|
|
7
|
+
let caller;
|
|
8
|
+
let receiver;
|
|
9
|
+
afterEach(async () => {
|
|
10
|
+
await env.cleanup();
|
|
11
|
+
});
|
|
12
|
+
describe('Caller → Receiver', () => {
|
|
13
|
+
it('should send request and receive response', async () => {
|
|
14
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
15
|
+
address: new oNodeAddress('o://caller'),
|
|
16
|
+
});
|
|
17
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
18
|
+
address: new oNodeAddress('o://receiver'),
|
|
19
|
+
});
|
|
20
|
+
const response = await caller.use(new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports), {
|
|
21
|
+
method: 'echo',
|
|
22
|
+
params: { message: 'hello-receiver' },
|
|
23
|
+
});
|
|
24
|
+
expect(response.result.success).to.be.true;
|
|
25
|
+
expect(response.result.data.message).to.equal('hello-receiver');
|
|
26
|
+
expect(receiver.receivedRequests).to.have.lengthOf(1);
|
|
27
|
+
});
|
|
28
|
+
it('should handle multiple sequential requests', async () => {
|
|
29
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
30
|
+
address: new oNodeAddress('o://caller'),
|
|
31
|
+
});
|
|
32
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
33
|
+
address: new oNodeAddress('o://receiver'),
|
|
34
|
+
});
|
|
35
|
+
const receiverAddr = new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports);
|
|
36
|
+
for (let i = 0; i < 5; i++) {
|
|
37
|
+
const response = await caller.use(receiverAddr, {
|
|
38
|
+
method: 'echo',
|
|
39
|
+
params: { message: `request-${i}` },
|
|
40
|
+
});
|
|
41
|
+
expect(response.result.success).to.be.true;
|
|
42
|
+
expect(response.result.data.message).to.equal(`request-${i}`);
|
|
43
|
+
}
|
|
44
|
+
expect(receiver.receivedRequests).to.have.lengthOf(5);
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
describe('Receiver → Caller', () => {
|
|
48
|
+
it('should send request via reader stream and receive response', async () => {
|
|
49
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
50
|
+
address: new oNodeAddress('o://caller'),
|
|
51
|
+
});
|
|
52
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
53
|
+
address: new oNodeAddress('o://receiver'),
|
|
54
|
+
});
|
|
55
|
+
const receiverAddr = new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports);
|
|
56
|
+
// First: Caller establishes connection (creates reader stream)
|
|
57
|
+
const initialResponse = await caller.use(receiverAddr, {
|
|
58
|
+
method: 'echo',
|
|
59
|
+
params: { message: 'initial' },
|
|
60
|
+
});
|
|
61
|
+
expect(initialResponse.result.success).to.be.true;
|
|
62
|
+
// Set up event listeners on both sides
|
|
63
|
+
const callerConn = caller.getFirstConnection();
|
|
64
|
+
const receiverConn = receiver.getFirstConnection();
|
|
65
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
66
|
+
// if (callerConn) {
|
|
67
|
+
// caller.setupEventListeners(callerConn);
|
|
68
|
+
// }
|
|
69
|
+
// if (receiverConn) {
|
|
70
|
+
// receiver.setupStreamListeners(receiverConn);
|
|
71
|
+
// }
|
|
72
|
+
// // Wait for receiver to identify reader stream
|
|
73
|
+
// await env.waitFor(() => receiver.identifiedStreams.length > 0, 5000, 100);
|
|
74
|
+
// expect(receiver.identifiedStreams).to.have.lengthOf(1);
|
|
75
|
+
// expect(receiver.identifiedStreams[0].role).to.equal('reader');
|
|
76
|
+
// Now: Receiver calls back to caller
|
|
77
|
+
const callerAddr = new oNodeAddress(caller.address.toString(), caller.address.libp2pTransports);
|
|
78
|
+
const response = await receiver.use(callerAddr, {
|
|
79
|
+
method: 'echo',
|
|
80
|
+
params: { message: 'hello-caller' },
|
|
81
|
+
});
|
|
82
|
+
console.log('Response from caller:', response);
|
|
83
|
+
expect(response.result.success).to.be.true;
|
|
84
|
+
expect(response.result.data.message).to.equal('hello-caller');
|
|
85
|
+
expect(caller.callCount).to.equal(1); // Only the reverse call
|
|
86
|
+
});
|
|
87
|
+
it('should handle request via tool method that calls caller', async () => {
|
|
88
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
89
|
+
address: new oNodeAddress('o://caller'),
|
|
90
|
+
});
|
|
91
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
92
|
+
address: new oNodeAddress('o://receiver'),
|
|
93
|
+
});
|
|
94
|
+
const receiverAddr = new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports);
|
|
95
|
+
// Establish connection
|
|
96
|
+
await caller.use(receiverAddr, {
|
|
97
|
+
method: 'echo',
|
|
98
|
+
params: { message: 'initial' },
|
|
99
|
+
});
|
|
100
|
+
// Set up event listeners
|
|
101
|
+
// const callerConn = caller.getFirstConnection();
|
|
102
|
+
// const receiverConn = receiver.getFirstConnection();
|
|
103
|
+
// if (callerConn) {
|
|
104
|
+
// caller.setupEventListeners(callerConn);
|
|
105
|
+
// }
|
|
106
|
+
// if (receiverConn) {
|
|
107
|
+
// receiver.setupStreamListeners(receiverConn);
|
|
108
|
+
// }
|
|
109
|
+
// // Wait for reader stream identification
|
|
110
|
+
// await env.waitFor(() => receiver.identifiedStreams.length > 0, 5000, 100);
|
|
111
|
+
// Caller calls receiver method that will call back to caller
|
|
112
|
+
const callerAddr = new oNodeAddress(caller.address.toString(), caller.address.libp2pTransports);
|
|
113
|
+
const response = await receiver.use(receiverAddr, {
|
|
114
|
+
method: 'call_caller',
|
|
115
|
+
params: { callerAddress: callerAddr },
|
|
116
|
+
});
|
|
117
|
+
expect(response.result.success).to.be.true;
|
|
118
|
+
expect(response.result.data.callerResponse.data.message).to.equal('from-receiver');
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
describe('Concurrent Bidirectional', () => {
|
|
122
|
+
it('should handle multiple concurrent bidirectional requests', async () => {
|
|
123
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
124
|
+
address: new oNodeAddress('o://caller'),
|
|
125
|
+
});
|
|
126
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
127
|
+
address: new oNodeAddress('o://receiver'),
|
|
128
|
+
});
|
|
129
|
+
const receiverAddr = new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports);
|
|
130
|
+
const callerAddr = new oNodeAddress(caller.address.toString(), caller.address.libp2pTransports);
|
|
131
|
+
// Establish connection
|
|
132
|
+
await caller.use(receiverAddr, {
|
|
133
|
+
method: 'echo',
|
|
134
|
+
params: { message: 'initial' },
|
|
135
|
+
});
|
|
136
|
+
// Set up event listeners
|
|
137
|
+
// const callerConn = caller.getFirstConnection();
|
|
138
|
+
// const receiverConn = receiver.getFirstConnection();
|
|
139
|
+
// if (callerConn) {
|
|
140
|
+
// caller.setupEventListeners(callerConn);
|
|
141
|
+
// }
|
|
142
|
+
// if (receiverConn) {
|
|
143
|
+
// receiver.setupStreamListeners(receiverConn);
|
|
144
|
+
// }
|
|
145
|
+
// // Wait for reader stream identification
|
|
146
|
+
// await env.waitFor(() => receiver.identifiedStreams.length > 0, 5000, 100);
|
|
147
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
148
|
+
console.log('Starting concurrent bidirectional requests');
|
|
149
|
+
// Concurrent bidirectional requests
|
|
150
|
+
const promises = [];
|
|
151
|
+
// Caller → Receiver
|
|
152
|
+
// for (let i = 0; i < 5; i++) {
|
|
153
|
+
// promises.push(
|
|
154
|
+
// caller.use(receiverAddr, {
|
|
155
|
+
// method: 'echo',
|
|
156
|
+
// params: { message: `c2r-${i}` },
|
|
157
|
+
// }),
|
|
158
|
+
// );
|
|
159
|
+
// }
|
|
160
|
+
// Receiver → Caller
|
|
161
|
+
for (let i = 0; i < 5; i++) {
|
|
162
|
+
promises.push(receiver.use(callerAddr, {
|
|
163
|
+
method: 'echo',
|
|
164
|
+
params: { message: `r2c-${i}` },
|
|
165
|
+
}));
|
|
166
|
+
}
|
|
167
|
+
const responses = await Promise.all(promises);
|
|
168
|
+
responses.forEach((response) => {
|
|
169
|
+
expect(response.result.success).to.be.true;
|
|
170
|
+
});
|
|
171
|
+
// Verify request counts
|
|
172
|
+
expect(caller.callCount).to.equal(5); // 5 from receiver
|
|
173
|
+
expect(receiver.receivedRequests).to.have.lengthOf(6); // 5 from caller + 1 initial
|
|
174
|
+
});
|
|
175
|
+
});
|
|
176
|
+
describe('Stream Reuse Verification', () => {
|
|
177
|
+
it('should reuse outbound streams for multiple requests', async () => {
|
|
178
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
179
|
+
address: new oNodeAddress('o://caller'),
|
|
180
|
+
});
|
|
181
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
182
|
+
address: new oNodeAddress('o://receiver'),
|
|
183
|
+
});
|
|
184
|
+
const receiverAddr = new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports);
|
|
185
|
+
const spy = createConnectionSpy(caller);
|
|
186
|
+
spy.start();
|
|
187
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
188
|
+
// Multiple requests should use same stream
|
|
189
|
+
for (let i = 0; i < 10; i++) {
|
|
190
|
+
await caller.use(receiverAddr, {
|
|
191
|
+
method: 'echo',
|
|
192
|
+
params: { message: `test-${i}` },
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
const stats = spy.getConnectionStats();
|
|
196
|
+
// Should have created connection
|
|
197
|
+
expect(stats.length).to.be.greaterThan(0);
|
|
198
|
+
// Should have limited number of streams (reader + outbound, reused)
|
|
199
|
+
const streamCount = stats.reduce((sum, conn) => sum + (conn.streams?.length || 0), 0);
|
|
200
|
+
// With reuse, stream count should be much less than request count
|
|
201
|
+
expect(streamCount).to.be.lessThan(10);
|
|
202
|
+
expect(receiver.receivedRequests).to.have.lengthOf(10);
|
|
203
|
+
spy.stop();
|
|
204
|
+
});
|
|
205
|
+
it('should maintain single connection across many requests', async () => {
|
|
206
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
207
|
+
address: new oNodeAddress('o://caller'),
|
|
208
|
+
});
|
|
209
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
210
|
+
address: new oNodeAddress('o://receiver'),
|
|
211
|
+
});
|
|
212
|
+
const receiverAddr = new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports);
|
|
213
|
+
const spy = createConnectionSpy(caller);
|
|
214
|
+
spy.start();
|
|
215
|
+
await new Promise((resolve) => setTimeout(resolve, 1000));
|
|
216
|
+
// Make multiple requests
|
|
217
|
+
for (let i = 0; i < 20; i++) {
|
|
218
|
+
await caller.use(receiverAddr, {
|
|
219
|
+
method: 'echo',
|
|
220
|
+
params: { message: `request-${i}` },
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
// Should only have 1 connection
|
|
224
|
+
const summary = spy.getSummary();
|
|
225
|
+
expect(summary.currentConnections).to.equal(1);
|
|
226
|
+
expect(receiver.receivedRequests).to.have.lengthOf(20);
|
|
227
|
+
spy.stop();
|
|
228
|
+
});
|
|
229
|
+
});
|
|
230
|
+
describe('Reader Stream Identification', () => {
|
|
231
|
+
it('should create and identify reader stream', async () => {
|
|
232
|
+
caller = await env.createNode(LimitedTestTool, {
|
|
233
|
+
address: new oNodeAddress('o://caller'),
|
|
234
|
+
});
|
|
235
|
+
receiver = await env.createNode(ReceiverTestTool, {
|
|
236
|
+
address: new oNodeAddress('o://receiver'),
|
|
237
|
+
});
|
|
238
|
+
const receiverAddr = new oNodeAddress(receiver.address.toString(), receiver.address.libp2pTransports);
|
|
239
|
+
// Make initial connection
|
|
240
|
+
await caller.use(receiverAddr, {
|
|
241
|
+
method: 'echo',
|
|
242
|
+
params: { message: 'test' },
|
|
243
|
+
});
|
|
244
|
+
// Set up event listeners
|
|
245
|
+
const callerConn = caller.getFirstConnection();
|
|
246
|
+
const receiverConn = receiver.getFirstConnection();
|
|
247
|
+
if (callerConn) {
|
|
248
|
+
caller.setupEventListeners(callerConn);
|
|
249
|
+
}
|
|
250
|
+
if (receiverConn) {
|
|
251
|
+
receiver.setupStreamListeners(receiverConn);
|
|
252
|
+
}
|
|
253
|
+
// Wait a bit for events to propagate
|
|
254
|
+
await new Promise((resolve) => setTimeout(resolve, 200));
|
|
255
|
+
// Verify reader stream was created on caller side
|
|
256
|
+
const readerEvents = caller.getReaderEvents();
|
|
257
|
+
expect(readerEvents.length).to.be.greaterThan(0);
|
|
258
|
+
const readerStarted = readerEvents.find((e) => e.type === 'reader-started');
|
|
259
|
+
expect(readerStarted).to.exist;
|
|
260
|
+
// Verify receiver identified the reader stream
|
|
261
|
+
expect(receiver.identifiedStreams.length).to.be.greaterThan(0);
|
|
262
|
+
expect(receiver.identifiedStreams[0].role).to.equal('reader');
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
});
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { MockStreamHandler, createMockStreamHandler, } from './mock-stream-handler.js';
|
|
1
|
+
export { LimitedTestTool } from './limited-test-tool.js';
|
|
2
|
+
export { ReceiverTestTool } from './receiver-test-tool.js';
|
|
4
3
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../test/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../test/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC"}
|
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export {
|
|
3
|
-
export { MockStreamHandler, createMockStreamHandler, } from './mock-stream-handler.js';
|
|
1
|
+
export { LimitedTestTool } from './limited-test-tool.js';
|
|
2
|
+
export { ReceiverTestTool } from './receiver-test-tool.js';
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import type { oRequest } from '@olane/o-core';
|
|
2
|
+
import { oLimitedTool } from '../../src/o-limited.tool.js';
|
|
3
|
+
/**
|
|
4
|
+
* Test tool that uses limited connections
|
|
5
|
+
* Tracks events and call counts for verification
|
|
6
|
+
*/
|
|
7
|
+
export declare class LimitedTestTool extends oLimitedTool {
|
|
8
|
+
callCount: number;
|
|
9
|
+
streamManagerEvents: Array<{
|
|
10
|
+
type: string;
|
|
11
|
+
data: any;
|
|
12
|
+
}>;
|
|
13
|
+
private eventListenersSetup;
|
|
14
|
+
initialize(): Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Set up event listeners for stream manager events
|
|
17
|
+
* Call this after first connection is established
|
|
18
|
+
*/
|
|
19
|
+
setupEventListeners(connection: any): void;
|
|
20
|
+
/**
|
|
21
|
+
* Simple echo method
|
|
22
|
+
*/
|
|
23
|
+
_tool_echo(request: oRequest): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Method that calls back to the requester
|
|
26
|
+
* Used to test bidirectional communication
|
|
27
|
+
*/
|
|
28
|
+
_tool_reverse_echo(request: oRequest): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Get all reader-related events
|
|
31
|
+
*/
|
|
32
|
+
getReaderEvents(): Array<{
|
|
33
|
+
type: string;
|
|
34
|
+
data: any;
|
|
35
|
+
}>;
|
|
36
|
+
/**
|
|
37
|
+
* Get the first connection (for accessing stream manager)
|
|
38
|
+
*/
|
|
39
|
+
getFirstConnection(): any;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=limited-test-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limited-test-tool.d.ts","sourceRoot":"","sources":["../../../test/helpers/limited-test-tool.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAI9C,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAE3D;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,YAAY;IACxC,SAAS,SAAK;IACd,mBAAmB,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC,CAAM;IACpE,OAAO,CAAC,mBAAmB,CAAS;IAE9B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IASjC;;;OAGG;IACH,mBAAmB,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI;IAiD1C;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAUjD;;;OAGG;IACG,kBAAkB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAczD;;OAEG;IACH,eAAe,IAAI,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,GAAG,CAAA;KAAE,CAAC;IAIrD;;OAEG;IACH,kBAAkB,IAAI,GAAG;CAO1B"}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { oLimitedConnectionManager } from '../../src/connection/o-limited-connection-manager.js';
|
|
2
|
+
import { StreamManagerEvent } from '@olane/o-node';
|
|
3
|
+
import { oLimitedTool } from '../../src/o-limited.tool.js';
|
|
4
|
+
/**
|
|
5
|
+
* Test tool that uses limited connections
|
|
6
|
+
* Tracks events and call counts for verification
|
|
7
|
+
*/
|
|
8
|
+
export class LimitedTestTool extends oLimitedTool {
|
|
9
|
+
constructor() {
|
|
10
|
+
super(...arguments);
|
|
11
|
+
this.callCount = 0;
|
|
12
|
+
this.streamManagerEvents = [];
|
|
13
|
+
this.eventListenersSetup = false;
|
|
14
|
+
}
|
|
15
|
+
async initialize() {
|
|
16
|
+
await super.initialize();
|
|
17
|
+
// Use limited connection manager
|
|
18
|
+
this.connectionManager = new oLimitedConnectionManager({
|
|
19
|
+
p2pNode: this.p2pNode,
|
|
20
|
+
runOnLimitedConnection: true,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Set up event listeners for stream manager events
|
|
25
|
+
* Call this after first connection is established
|
|
26
|
+
*/
|
|
27
|
+
setupEventListeners(connection) {
|
|
28
|
+
if (this.eventListenersSetup || !connection?.streamManager) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
this.eventListenersSetup = true;
|
|
32
|
+
// Listen to all stream manager events
|
|
33
|
+
connection.streamManager.on(StreamManagerEvent.ReaderStarted, (data) => {
|
|
34
|
+
this.streamManagerEvents.push({
|
|
35
|
+
type: 'reader-started',
|
|
36
|
+
data,
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
connection.streamManager.on(StreamManagerEvent.ReaderFailed, (data) => {
|
|
40
|
+
this.streamManagerEvents.push({
|
|
41
|
+
type: 'reader-failed',
|
|
42
|
+
data,
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
connection.streamManager.on(StreamManagerEvent.ReaderRecovered, (data) => {
|
|
46
|
+
this.streamManagerEvents.push({
|
|
47
|
+
type: 'reader-recovered',
|
|
48
|
+
data,
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
connection.streamManager.on(StreamManagerEvent.StreamIdentified, (data) => {
|
|
52
|
+
this.streamManagerEvents.push({
|
|
53
|
+
type: 'stream-identified',
|
|
54
|
+
data,
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Simple echo method
|
|
60
|
+
*/
|
|
61
|
+
async _tool_echo(request) {
|
|
62
|
+
this.callCount++;
|
|
63
|
+
return {
|
|
64
|
+
message: request.params.message,
|
|
65
|
+
nodeAddress: this.address.toString(),
|
|
66
|
+
callCount: this.callCount,
|
|
67
|
+
timestamp: Date.now(),
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Method that calls back to the requester
|
|
72
|
+
* Used to test bidirectional communication
|
|
73
|
+
*/
|
|
74
|
+
async _tool_reverse_echo(request) {
|
|
75
|
+
const callerAddress = request.params.callerAddress;
|
|
76
|
+
const response = await this.use(callerAddress, {
|
|
77
|
+
method: 'echo',
|
|
78
|
+
params: { message: 'reverse-response' },
|
|
79
|
+
});
|
|
80
|
+
return {
|
|
81
|
+
original: request.params.message,
|
|
82
|
+
reversed: response.result,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Get all reader-related events
|
|
87
|
+
*/
|
|
88
|
+
getReaderEvents() {
|
|
89
|
+
return this.streamManagerEvents.filter((e) => e.type.includes('reader'));
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get the first connection (for accessing stream manager)
|
|
93
|
+
*/
|
|
94
|
+
getFirstConnection() {
|
|
95
|
+
const firstEntry = Array.from(this.connectionManager?.cachedConnections?.values() || []);
|
|
96
|
+
return firstEntry?.[0];
|
|
97
|
+
}
|
|
98
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { oNodeTool } from '@olane/o-node';
|
|
2
|
+
import type { oRequest } from '@olane/o-core';
|
|
3
|
+
/**
|
|
4
|
+
* Standard receiver tool (uses base connection manager)
|
|
5
|
+
* Tracks received requests and identified streams
|
|
6
|
+
*/
|
|
7
|
+
export declare class ReceiverTestTool extends oNodeTool {
|
|
8
|
+
receivedRequests: oRequest[];
|
|
9
|
+
identifiedStreams: Array<{
|
|
10
|
+
streamId: string;
|
|
11
|
+
role: string;
|
|
12
|
+
}>;
|
|
13
|
+
private eventListenersSetup;
|
|
14
|
+
constructor(config: any);
|
|
15
|
+
/**
|
|
16
|
+
* Set up event listeners for stream identification
|
|
17
|
+
* Call this after tool is started
|
|
18
|
+
*/
|
|
19
|
+
setupStreamListeners(connection: any): void;
|
|
20
|
+
/**
|
|
21
|
+
* Simple echo method
|
|
22
|
+
*/
|
|
23
|
+
_tool_echo(request: oRequest): Promise<any>;
|
|
24
|
+
/**
|
|
25
|
+
* Method that calls back to the caller
|
|
26
|
+
* Tests receiver → caller communication
|
|
27
|
+
*/
|
|
28
|
+
_tool_call_caller(request: oRequest): Promise<any>;
|
|
29
|
+
/**
|
|
30
|
+
* Get the first connection (for accessing stream manager)
|
|
31
|
+
*/
|
|
32
|
+
getFirstConnection(): any;
|
|
33
|
+
}
|
|
34
|
+
//# sourceMappingURL=receiver-test-tool.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receiver-test-tool.d.ts","sourceRoot":"","sources":["../../../test/helpers/receiver-test-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC1C,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAI9C;;;GAGG;AACH,qBAAa,gBAAiB,SAAQ,SAAS;IACtC,gBAAgB,EAAE,QAAQ,EAAE,CAAM;IAClC,iBAAiB,EAAE,KAAK,CAAC;QAAE,QAAQ,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAM;IACzE,OAAO,CAAC,mBAAmB,CAAS;gBAExB,MAAM,EAAE,GAAG;IAIvB;;;OAGG;IACH,oBAAoB,CAAC,UAAU,EAAE,GAAG,GAAG,IAAI;IAmB3C;;OAEG;IACG,UAAU,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAUjD;;;OAGG;IACG,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;IAiBxD;;OAEG;IACH,kBAAkB,IAAI,GAAG;CAM1B"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { oNodeTool } from '@olane/o-node';
|
|
2
|
+
import { StreamManagerEvent } from '@olane/o-node';
|
|
3
|
+
/**
|
|
4
|
+
* Standard receiver tool (uses base connection manager)
|
|
5
|
+
* Tracks received requests and identified streams
|
|
6
|
+
*/
|
|
7
|
+
export class ReceiverTestTool extends oNodeTool {
|
|
8
|
+
constructor(config) {
|
|
9
|
+
super(config);
|
|
10
|
+
this.receivedRequests = [];
|
|
11
|
+
this.identifiedStreams = [];
|
|
12
|
+
this.eventListenersSetup = false;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Set up event listeners for stream identification
|
|
16
|
+
* Call this after tool is started
|
|
17
|
+
*/
|
|
18
|
+
setupStreamListeners(connection) {
|
|
19
|
+
if (this.eventListenersSetup || !connection?.streamManager) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
this.eventListenersSetup = true;
|
|
23
|
+
// Listen for stream identification events
|
|
24
|
+
connection.streamManager.on(StreamManagerEvent.StreamIdentified, (data) => {
|
|
25
|
+
this.identifiedStreams.push({
|
|
26
|
+
streamId: data.streamId,
|
|
27
|
+
role: data.role,
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Simple echo method
|
|
33
|
+
*/
|
|
34
|
+
async _tool_echo(request) {
|
|
35
|
+
this.receivedRequests.push(request);
|
|
36
|
+
return {
|
|
37
|
+
message: request.params.message,
|
|
38
|
+
nodeAddress: this.address.toString(),
|
|
39
|
+
requestCount: this.receivedRequests.length,
|
|
40
|
+
timestamp: Date.now(),
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Method that calls back to the caller
|
|
45
|
+
* Tests receiver → caller communication
|
|
46
|
+
*/
|
|
47
|
+
async _tool_call_caller(request) {
|
|
48
|
+
this.receivedRequests.push(request);
|
|
49
|
+
const callerAddress = request.params.callerAddress;
|
|
50
|
+
// Call back to the caller
|
|
51
|
+
const response = await this.use(callerAddress, {
|
|
52
|
+
method: 'echo',
|
|
53
|
+
params: { message: 'from-receiver' },
|
|
54
|
+
});
|
|
55
|
+
return {
|
|
56
|
+
callerResponse: response.result,
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the first connection (for accessing stream manager)
|
|
62
|
+
*/
|
|
63
|
+
getFirstConnection() {
|
|
64
|
+
const firstEntry = Array.from(this.connectionManager?.cachedConnections?.values() || []);
|
|
65
|
+
return firstEntry?.[0];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"limited-connection-lifecycle.spec.d.ts","sourceRoot":"","sources":["../../test/limited-connection-lifecycle.spec.ts"],"names":[],"mappings":""}
|