@olane/o-node 0.7.55 → 0.7.56
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/enums/o-node-message-event.d.ts +14 -0
- package/dist/src/connection/enums/o-node-message-event.d.ts.map +1 -0
- package/dist/src/connection/enums/o-node-message-event.js +5 -0
- package/dist/src/connection/index.d.ts +0 -3
- package/dist/src/connection/index.d.ts.map +1 -1
- package/dist/src/connection/index.js +0 -3
- package/dist/src/connection/interfaces/abort-signal.config.d.ts +5 -0
- package/dist/src/connection/interfaces/abort-signal.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/o-node-connection-manager.config.d.ts +13 -1
- package/dist/src/connection/interfaces/o-node-connection-manager.config.d.ts.map +1 -1
- package/dist/src/connection/interfaces/o-node-connection.config.d.ts +18 -5
- package/dist/src/connection/interfaces/o-node-connection.config.d.ts.map +1 -1
- package/dist/src/connection/interfaces/o-node-stream.config.d.ts +3 -11
- package/dist/src/connection/interfaces/o-node-stream.config.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.d.ts +29 -53
- package/dist/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +102 -146
- package/dist/src/connection/o-node-connection.manager.d.ts +12 -8
- package/dist/src/connection/o-node-connection.manager.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.manager.js +46 -34
- package/dist/src/connection/o-node-stream.d.ts +48 -15
- package/dist/src/connection/o-node-stream.d.ts.map +1 -1
- package/dist/src/connection/o-node-stream.js +143 -31
- package/dist/src/connection/stream-handler.config.d.ts +0 -11
- package/dist/src/connection/stream-handler.config.d.ts.map +1 -1
- package/dist/src/lib/interfaces/o-node-request-manager.config.d.ts +9 -0
- package/dist/src/lib/interfaces/o-node-request-manager.config.d.ts.map +1 -0
- package/dist/src/lib/interfaces/o-node-request-manager.config.js +1 -0
- package/dist/src/lib/o-node-request-manager.d.ts +46 -0
- package/dist/src/lib/o-node-request-manager.d.ts.map +1 -0
- package/dist/src/lib/o-node-request-manager.js +173 -0
- package/dist/src/managers/o-reconnection.manager.d.ts.map +1 -1
- package/dist/src/managers/o-reconnection.manager.js +4 -0
- package/dist/src/managers/o-registration.manager.d.ts.map +1 -1
- package/dist/src/managers/o-registration.manager.js +9 -4
- package/dist/src/o-node.d.ts +6 -7
- package/dist/src/o-node.d.ts.map +1 -1
- package/dist/src/o-node.js +22 -37
- package/dist/src/o-node.tool.d.ts +3 -3
- package/dist/src/o-node.tool.d.ts.map +1 -1
- package/dist/src/o-node.tool.js +27 -56
- package/dist/src/router/o-node.router.d.ts.map +1 -1
- package/dist/src/router/o-node.router.js +4 -2
- package/dist/test/connection-management.spec.js +3 -0
- package/package.json +7 -7
- package/dist/src/connection/interfaces/stream-init-message.d.ts +0 -64
- package/dist/src/connection/interfaces/stream-init-message.d.ts.map +0 -1
- package/dist/src/connection/interfaces/stream-init-message.js +0 -18
- package/dist/src/connection/interfaces/stream-manager.config.d.ts +0 -8
- package/dist/src/connection/interfaces/stream-manager.config.d.ts.map +0 -1
- package/dist/src/connection/o-node-stream.manager.d.ts +0 -210
- package/dist/src/connection/o-node-stream.manager.d.ts.map +0 -1
- package/dist/src/connection/o-node-stream.manager.js +0 -696
- /package/dist/src/connection/interfaces/{stream-manager.config.js → abort-signal.config.js} +0 -0
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { oResponse } from '@olane/o-core';
|
|
2
|
+
import { oStreamRequest } from '../o-stream.request.js';
|
|
3
|
+
export declare enum oNodeMessageEvent {
|
|
4
|
+
request = "request",
|
|
5
|
+
response = "response"
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Mapped type for type-safe event listeners
|
|
9
|
+
*/
|
|
10
|
+
export type oNodeMessageEventData = {
|
|
11
|
+
[oNodeMessageEvent.request]: oStreamRequest;
|
|
12
|
+
[oNodeMessageEvent.response]: oResponse;
|
|
13
|
+
};
|
|
14
|
+
//# sourceMappingURL=o-node-message-event.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-node-message-event.d.ts","sourceRoot":"","sources":["../../../../src/connection/enums/o-node-message-event.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,SAAS,EAAE,MAAM,eAAe,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExD,oBAAY,iBAAiB;IAC3B,OAAO,YAAY;IACnB,QAAQ,aAAa;CACtB;AAED;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,cAAc,CAAC;IAC5C,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;CACzC,CAAC"}
|
|
@@ -3,10 +3,7 @@ export * from './o-node-connection.manager.js';
|
|
|
3
3
|
export * from './interfaces/o-node-connection.config.js';
|
|
4
4
|
export * from './interfaces/o-node-connection-manager.config.js';
|
|
5
5
|
export * from './interfaces/o-node-stream.config.js';
|
|
6
|
-
export * from './interfaces/stream-manager.config.js';
|
|
7
|
-
export * from './interfaces/stream-init-message.js';
|
|
8
6
|
export * from './o-node-stream.js';
|
|
9
7
|
export * from './stream-handler.config.js';
|
|
10
|
-
export * from './o-node-stream.manager.js';
|
|
11
8
|
export * from './stream-manager.events.js';
|
|
12
9
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,kDAAkD,CAAC;AACjE,cAAc,sCAAsC,CAAC;AACrD,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/connection/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0CAA0C,CAAC;AACzD,cAAc,kDAAkD,CAAC;AACjE,cAAc,sCAAsC,CAAC;AACrD,cAAc,oBAAoB,CAAC;AACnC,cAAc,4BAA4B,CAAC;AAC3C,cAAc,4BAA4B,CAAC"}
|
|
@@ -3,9 +3,6 @@ export * from './o-node-connection.manager.js';
|
|
|
3
3
|
export * from './interfaces/o-node-connection.config.js';
|
|
4
4
|
export * from './interfaces/o-node-connection-manager.config.js';
|
|
5
5
|
export * from './interfaces/o-node-stream.config.js';
|
|
6
|
-
export * from './interfaces/stream-manager.config.js';
|
|
7
|
-
export * from './interfaces/stream-init-message.js';
|
|
8
6
|
export * from './o-node-stream.js';
|
|
9
7
|
export * from './stream-handler.config.js';
|
|
10
|
-
export * from './o-node-stream.manager.js';
|
|
11
8
|
export * from './stream-manager.events.js';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"abort-signal.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/abort-signal.config.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,iBAAiB;IAChC,WAAW,CAAC,EAAE,WAAW,CAAC;CAC3B"}
|
|
@@ -3,6 +3,18 @@ import { Libp2p } from '@olane/o-config';
|
|
|
3
3
|
export interface oNodeConnectionManagerConfig extends oConnectionManagerConfig {
|
|
4
4
|
p2pNode: Libp2p;
|
|
5
5
|
runOnLimitedConnection?: boolean;
|
|
6
|
-
|
|
6
|
+
callerAddress?: string;
|
|
7
|
+
/**
|
|
8
|
+
* Default timeout in milliseconds for reading response data from a stream.
|
|
9
|
+
* Can be overridden per connection.
|
|
10
|
+
* Default: 120000 (2 minutes)
|
|
11
|
+
*/
|
|
12
|
+
defaultReadTimeoutMs?: number;
|
|
13
|
+
/**
|
|
14
|
+
* Default timeout in milliseconds for waiting for stream buffer to drain when backpressure occurs.
|
|
15
|
+
* Can be overridden per connection.
|
|
16
|
+
* Default: 30000 (30 seconds)
|
|
17
|
+
*/
|
|
18
|
+
defaultDrainTimeoutMs?: number;
|
|
7
19
|
}
|
|
8
20
|
//# sourceMappingURL=o-node-connection-manager.config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node-connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection-manager.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"o-node-connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-connection-manager.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,MAAM,WAAW,4BAA6B,SAAQ,wBAAwB;IAC5E,OAAO,EAAE,MAAM,CAAC;IAChB,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B;;;;OAIG;IACH,qBAAqB,CAAC,EAAE,MAAM,CAAC;CAChC"}
|
|
@@ -1,10 +1,23 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Connection } from '@olane/o-config';
|
|
2
3
|
import { oConnectionConfig } from '@olane/o-core';
|
|
3
|
-
import
|
|
4
|
+
import { oNodeAddress } from '../../router';
|
|
4
5
|
export interface oNodeConnectionConfig extends oConnectionConfig {
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
nextHopAddress: oNodeAddress;
|
|
7
|
+
callerAddress?: oNodeAddress;
|
|
8
|
+
targetAddress: oNodeAddress;
|
|
9
|
+
p2pConnection?: Connection;
|
|
7
10
|
runOnLimitedConnection?: boolean;
|
|
8
|
-
|
|
11
|
+
/**
|
|
12
|
+
* Timeout in milliseconds for waiting for stream buffer to drain when backpressure occurs.
|
|
13
|
+
* Default: 30000 (30 seconds)
|
|
14
|
+
*/
|
|
15
|
+
drainTimeoutMs?: number;
|
|
16
|
+
abortSignal?: AbortSignal;
|
|
17
|
+
/**
|
|
18
|
+
* Timeout in milliseconds for reading response data from a stream.
|
|
19
|
+
* Default: 120000 (2 minutes)
|
|
20
|
+
*/
|
|
21
|
+
readTimeoutMs?: number;
|
|
9
22
|
}
|
|
10
23
|
//# 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,
|
|
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,EAAU,MAAM,iBAAiB,CAAC;AACrD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAE5C,MAAM,WAAW,qBAAsB,SAAQ,iBAAiB;IAC9D,cAAc,EAAE,YAAY,CAAC;IAC7B,aAAa,CAAC,EAAE,YAAY,CAAC;IAC7B,aAAa,EAAE,YAAY,CAAC;IAC5B,aAAa,CAAC,EAAE,UAAU,CAAC;IAC3B,sBAAsB,CAAC,EAAE,OAAO,CAAC;IACjC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B;;;OAGG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB"}
|
|
@@ -1,16 +1,8 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { oAddress } from '@olane/o-core';
|
|
2
|
-
import { StreamReusePolicy } from '../stream-handler.config';
|
|
3
|
-
/**
|
|
4
|
-
* Stream type defines the role and usage pattern of a stream:
|
|
5
|
-
* - 'dedicated-reader': Stream exclusively used for reading incoming requests (background reader)
|
|
6
|
-
* - 'request-response': Stream used for outgoing request-response cycles
|
|
7
|
-
* - 'general': Stream with no specific role (default, backward compatible)
|
|
8
|
-
*/
|
|
9
|
-
export type StreamType = 'dedicated-reader' | 'request-response' | 'general';
|
|
10
3
|
export interface oNodeStreamConfig {
|
|
11
|
-
direction: 'inbound' | 'outbound';
|
|
12
|
-
reusePolicy: StreamReusePolicy;
|
|
13
4
|
remoteAddress: oAddress;
|
|
14
|
-
|
|
5
|
+
abortSignal?: AbortSignal;
|
|
6
|
+
limited?: boolean;
|
|
15
7
|
}
|
|
16
8
|
//# sourceMappingURL=o-node-stream.config.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node-stream.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-stream.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,
|
|
1
|
+
{"version":3,"file":"o-node-stream.config.d.ts","sourceRoot":"","sources":["../../../../src/connection/interfaces/o-node-stream.config.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,MAAM,WAAW,iBAAiB;IAChC,aAAa,EAAE,QAAQ,CAAC;IACxB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB"}
|
|
@@ -1,73 +1,49 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Connection, Multiaddr } from '@olane/o-config';
|
|
3
|
+
import { oAddress, oConnection, oRequest } from '@olane/o-core';
|
|
3
4
|
import { oNodeConnectionConfig } from './interfaces/o-node-connection.config.js';
|
|
4
|
-
import type { StreamReusePolicy } from './stream-handler.config.js';
|
|
5
|
-
import { oNodeAddress } from '../router/o-node.address.js';
|
|
6
5
|
import { oNodeStream } from './o-node-stream.js';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
protocolVersion?: string;
|
|
12
|
-
listenAddrs: Multiaddr[];
|
|
13
|
-
observedAddr?: Multiaddr;
|
|
14
|
-
timestamp: number;
|
|
15
|
-
}
|
|
6
|
+
import { oNodeStreamConfig } from './interfaces/o-node-stream.config.js';
|
|
7
|
+
import { AbortSignalConfig } from './interfaces/abort-signal.config.js';
|
|
8
|
+
import { EventEmitter } from 'events';
|
|
9
|
+
import { oNodeMessageEvent, oNodeMessageEventData } from './enums/o-node-message-event.js';
|
|
16
10
|
export declare class oNodeConnection extends oConnection {
|
|
17
11
|
protected readonly config: oNodeConnectionConfig;
|
|
18
12
|
p2pConnection: Connection;
|
|
19
|
-
protected
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
protected identifyData?: CachedIdentifyData;
|
|
23
|
-
protected identifyListener?: (evt: any) => void;
|
|
13
|
+
protected streams: Map<string, oNodeStream>;
|
|
14
|
+
protected runOnLimitedConnection: boolean;
|
|
15
|
+
eventEmitter: EventEmitter;
|
|
24
16
|
constructor(config: oNodeConnectionConfig);
|
|
17
|
+
listenForClose(): void;
|
|
18
|
+
get isOpen(): boolean;
|
|
25
19
|
get remotePeerId(): import("@olane/o-config").PeerId;
|
|
26
20
|
get remoteAddr(): Multiaddr;
|
|
27
21
|
/**
|
|
28
22
|
* Get the connection configuration for compatibility checking.
|
|
29
23
|
*/
|
|
30
24
|
get connectionConfig(): oNodeConnectionConfig;
|
|
31
|
-
supportsAddress(address: oNodeAddress): boolean;
|
|
32
|
-
get streams(): oNodeStream[];
|
|
33
|
-
/**
|
|
34
|
-
* Get cached identify data for the remote peer.
|
|
35
|
-
* Returns undefined if identify event hasn't been received yet.
|
|
36
|
-
*/
|
|
37
|
-
get cachedIdentifyData(): CachedIdentifyData | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Get protocols supported by the remote peer from cached identify data.
|
|
40
|
-
* Returns empty array if identify data not available yet.
|
|
41
|
-
*/
|
|
42
|
-
get remoteProtocols(): string[];
|
|
43
|
-
/**
|
|
44
|
-
* Get agent version of the remote peer from cached identify data.
|
|
45
|
-
*/
|
|
46
|
-
get remoteAgentVersion(): string | undefined;
|
|
47
|
-
/**
|
|
48
|
-
* Get protocol version of the remote peer from cached identify data.
|
|
49
|
-
*/
|
|
50
|
-
get remoteProtocolVersion(): string | undefined;
|
|
51
|
-
/**
|
|
52
|
-
* Get listen addresses advertised by the remote peer.
|
|
53
|
-
* Returns empty array if identify data not available yet.
|
|
54
|
-
*/
|
|
55
|
-
get remoteListenAddrs(): Multiaddr[];
|
|
56
|
-
/**
|
|
57
|
-
* Get our observed address as seen by the remote peer.
|
|
58
|
-
*/
|
|
59
|
-
get observedAddress(): Multiaddr | undefined;
|
|
60
25
|
get address(): oAddress;
|
|
61
26
|
get nextHopAddress(): oAddress;
|
|
62
27
|
get callerAddress(): oAddress | undefined;
|
|
63
|
-
|
|
28
|
+
newStream(config: oNodeStreamConfig): Promise<oNodeStream>;
|
|
29
|
+
listenForMessages(stream: oNodeStream, options: AbortSignalConfig): Promise<void>;
|
|
30
|
+
trackStream(stream: oNodeStream, options: AbortSignalConfig): void;
|
|
31
|
+
protected doSend(request: oRequest, options: AbortSignalConfig): Promise<oNodeStream>;
|
|
32
|
+
transmit(request: oRequest, options: AbortSignalConfig): Promise<oNodeStream>;
|
|
64
33
|
postTransmit(stream: oNodeStream): Promise<void>;
|
|
65
|
-
/**
|
|
66
|
-
* Set up persistent listener for identify events from the remote peer
|
|
67
|
-
*/
|
|
68
|
-
protected setupIdentifyListener(): void;
|
|
69
34
|
abort(error: Error): Promise<void>;
|
|
70
35
|
close(): Promise<void>;
|
|
36
|
+
/**
|
|
37
|
+
* Add event listener
|
|
38
|
+
*/
|
|
39
|
+
on<K extends oNodeMessageEvent>(event: K | string, listener: (data: oNodeMessageEventData[K]) => void): void;
|
|
40
|
+
/**
|
|
41
|
+
* Remove event listener
|
|
42
|
+
*/
|
|
43
|
+
off<K extends oNodeMessageEvent>(event: K | string, listener: (data: oNodeMessageEventData[K]) => void): void;
|
|
44
|
+
/**
|
|
45
|
+
* Emit event
|
|
46
|
+
*/
|
|
47
|
+
private emit;
|
|
71
48
|
}
|
|
72
|
-
export {};
|
|
73
49
|
//# sourceMappingURL=o-node-connection.d.ts.map
|
|
@@ -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,
|
|
1
|
+
{"version":3,"file":"o-node-connection.d.ts","sourceRoot":"","sources":["../../../src/connection/o-node-connection.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAU,SAAS,EAAU,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAEL,QAAQ,EACR,WAAW,EAGX,QAAQ,EAET,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAGjF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,MAAM,sCAAsC,CAAC;AACzE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qCAAqC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EACL,iBAAiB,EACjB,qBAAqB,EACtB,MAAM,iCAAiC,CAAC;AAYzC,qBAAa,eAAgB,SAAQ,WAAW;IAMlC,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,qBAAqB;IALrD,aAAa,EAAE,UAAU,CAAC;IACjC,SAAS,CAAC,OAAO,EAAE,GAAG,CAAC,MAAM,EAAE,WAAW,CAAC,CAAkC;IAC7E,SAAS,CAAC,sBAAsB,EAAE,OAAO,CAAC;IAC1C,YAAY,EAAE,YAAY,CAAsB;gBAEjB,MAAM,EAAE,qBAAqB;IAQ5D,cAAc;IAMd,IAAI,MAAM,YAET;IAED,IAAI,YAAY,qCAEf;IAED,IAAI,UAAU,cAEb;IAED;;OAEG;IACH,IAAI,gBAAgB,IAAI,qBAAqB,CAE5C;IAED,IAAI,OAAO,IAAI,QAAQ,CAEtB;IAED,IAAI,cAAc,IAAI,QAAQ,CAK7B;IAED,IAAI,aAAa,IAAI,QAAQ,GAAG,SAAS,CAMxC;IAEK,SAAS,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC,WAAW,CAAC;IA2B1D,iBAAiB,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,iBAAiB;IAyBvE,WAAW,CAAC,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,iBAAiB;cAO3C,MAAM,CACpB,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,WAAW,CAAC;IAsBjB,QAAQ,CACZ,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,iBAAiB,GACzB,OAAO,CAAC,WAAW,CAAC;IAoBjB,YAAY,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAIhD,KAAK,CAAC,KAAK,EAAE,KAAK;IAMlB,KAAK;IAOX;;OAEG;IACH,EAAE,CAAC,CAAC,SAAS,iBAAiB,EAC5B,KAAK,EAAE,CAAC,GAAG,MAAM,EACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,IAAI,GACjD,IAAI;IAIP;;OAEG;IACH,GAAG,CAAC,CAAC,SAAS,iBAAiB,EAC7B,KAAK,EAAE,CAAC,GAAG,MAAM,EACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,qBAAqB,CAAC,CAAC,CAAC,KAAK,IAAI,GACjD,IAAI;IAIP;;OAEG;IACH,OAAO,CAAC,IAAI;CAMb"}
|
|
@@ -1,19 +1,24 @@
|
|
|
1
1
|
import { oConnection, oError, oErrorCodes, } from '@olane/o-core';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { oNodeStream } from './o-node-stream.js';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import { oNodeMessageEvent, } from './enums/o-node-message-event.js';
|
|
4
5
|
export class oNodeConnection extends oConnection {
|
|
5
6
|
constructor(config) {
|
|
6
7
|
super(config);
|
|
7
8
|
this.config = config;
|
|
9
|
+
this.streams = new Map();
|
|
10
|
+
this.eventEmitter = new EventEmitter();
|
|
8
11
|
this.p2pConnection = config.p2pConnection;
|
|
9
|
-
this.
|
|
10
|
-
this.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
this.runOnLimitedConnection = config.runOnLimitedConnection ?? false;
|
|
13
|
+
this.listenForClose();
|
|
14
|
+
}
|
|
15
|
+
listenForClose() {
|
|
16
|
+
this.p2pConnection.addEventListener('close', () => {
|
|
17
|
+
this.close();
|
|
14
18
|
});
|
|
15
|
-
|
|
16
|
-
|
|
19
|
+
}
|
|
20
|
+
get isOpen() {
|
|
21
|
+
return this.p2pConnection.status === 'open';
|
|
17
22
|
}
|
|
18
23
|
get remotePeerId() {
|
|
19
24
|
return this.p2pConnection.remotePeer;
|
|
@@ -27,63 +32,8 @@ export class oNodeConnection extends oConnection {
|
|
|
27
32
|
get connectionConfig() {
|
|
28
33
|
return this.config;
|
|
29
34
|
}
|
|
30
|
-
supportsAddress(address) {
|
|
31
|
-
return address.libp2pTransports.some((transport) => {
|
|
32
|
-
return transport.toString() === this.remoteAddr.toString();
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
get streams() {
|
|
36
|
-
return this.streamManager.getAllStreams();
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Get cached identify data for the remote peer.
|
|
40
|
-
* Returns undefined if identify event hasn't been received yet.
|
|
41
|
-
*/
|
|
42
|
-
get cachedIdentifyData() {
|
|
43
|
-
return this.identifyData;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* Get protocols supported by the remote peer from cached identify data.
|
|
47
|
-
* Returns empty array if identify data not available yet.
|
|
48
|
-
*/
|
|
49
|
-
get remoteProtocols() {
|
|
50
|
-
return this.identifyData?.protocols || [];
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Get agent version of the remote peer from cached identify data.
|
|
54
|
-
*/
|
|
55
|
-
get remoteAgentVersion() {
|
|
56
|
-
return this.identifyData?.agentVersion;
|
|
57
|
-
}
|
|
58
|
-
/**
|
|
59
|
-
* Get protocol version of the remote peer from cached identify data.
|
|
60
|
-
*/
|
|
61
|
-
get remoteProtocolVersion() {
|
|
62
|
-
return this.identifyData?.protocolVersion;
|
|
63
|
-
}
|
|
64
|
-
/**
|
|
65
|
-
* Get listen addresses advertised by the remote peer.
|
|
66
|
-
* Returns empty array if identify data not available yet.
|
|
67
|
-
*/
|
|
68
|
-
get remoteListenAddrs() {
|
|
69
|
-
return this.identifyData?.listenAddrs || [];
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Get our observed address as seen by the remote peer.
|
|
73
|
-
*/
|
|
74
|
-
get observedAddress() {
|
|
75
|
-
return this.identifyData?.observedAddr;
|
|
76
|
-
}
|
|
77
35
|
get address() {
|
|
78
|
-
|
|
79
|
-
this.identifyData.protocols.length > 0) {
|
|
80
|
-
const filtered = this.identifyData.protocols.filter((p) => p.startsWith('/o/'));
|
|
81
|
-
if (filtered.length > 0) {
|
|
82
|
-
const remoteAddress = oNodeAddress.fromProtocol(filtered[0]);
|
|
83
|
-
return remoteAddress;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
return this.config.address;
|
|
36
|
+
return this.config.targetAddress;
|
|
87
37
|
}
|
|
88
38
|
get nextHopAddress() {
|
|
89
39
|
if (this.config.nextHopAddress.value === 'o://unknown') {
|
|
@@ -97,53 +47,77 @@ export class oNodeConnection extends oConnection {
|
|
|
97
47
|
}
|
|
98
48
|
return this.config.callerAddress;
|
|
99
49
|
}
|
|
100
|
-
async
|
|
50
|
+
async newStream(config) {
|
|
51
|
+
const protocol = config.remoteAddress.protocol;
|
|
52
|
+
this.logger.debug('Creating new stream', {
|
|
53
|
+
protocol,
|
|
54
|
+
currentStreamCount: this.streams.size,
|
|
55
|
+
});
|
|
56
|
+
// Create stream from libp2p connection
|
|
57
|
+
const stream = await this.p2pConnection.newStream(protocol, {
|
|
58
|
+
signal: config.abortSignal,
|
|
59
|
+
maxOutboundStreams: 1000,
|
|
60
|
+
runOnLimitedConnection: this.runOnLimitedConnection,
|
|
61
|
+
});
|
|
62
|
+
// Wrap in oNodeStream with metadata
|
|
63
|
+
const wrappedStream = new oNodeStream(stream, config);
|
|
64
|
+
this.logger.debug('Stream created', {
|
|
65
|
+
streamId: stream.id,
|
|
66
|
+
protocol,
|
|
67
|
+
totalStreams: this.streams.size,
|
|
68
|
+
});
|
|
69
|
+
return wrappedStream;
|
|
70
|
+
}
|
|
71
|
+
// bubble up the messages to the request handler
|
|
72
|
+
async listenForMessages(stream, options) {
|
|
101
73
|
try {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
? parseInt(process.env.MAX_OUTBOUND_STREAMS)
|
|
112
|
-
: 1000,
|
|
113
|
-
runOnLimitedConnection: this.config.runOnLimitedConnection ?? false,
|
|
114
|
-
};
|
|
115
|
-
// Get stream from StreamManager
|
|
116
|
-
const wrappedStream = await this.streamManager.getOrCreateStream(protocol, this.nextHopAddress, streamConfig);
|
|
117
|
-
// Ensure stream is valid
|
|
118
|
-
wrappedStream.validate();
|
|
119
|
-
const stream = wrappedStream.p2pStream;
|
|
120
|
-
// Send the request with backpressure handling
|
|
121
|
-
const data = new TextEncoder().encode(request.toString());
|
|
122
|
-
await this.streamManager.sendLengthPrefixed(stream, data, streamConfig);
|
|
123
|
-
// Determine which stream to wait for response on
|
|
124
|
-
// If _streamId is specified, use that stream (for limited connections with persistent writer stream)
|
|
125
|
-
let responseStream = stream;
|
|
126
|
-
if (request.params._streamId) {
|
|
127
|
-
const specifiedStream = this.streamManager.getStreamById(request.params._streamId);
|
|
128
|
-
if (specifiedStream) {
|
|
129
|
-
responseStream = specifiedStream;
|
|
130
|
-
this.logger.debug('Using specified stream for response', {
|
|
131
|
-
requestStreamId: stream.id,
|
|
132
|
-
responseStreamId: specifiedStream.id,
|
|
133
|
-
});
|
|
134
|
-
}
|
|
135
|
-
else {
|
|
136
|
-
this.logger.warn('Specified response stream not found, using request stream', {
|
|
137
|
-
streamId: request.params._streamId,
|
|
138
|
-
});
|
|
74
|
+
stream.on(oNodeMessageEvent.request, (data) => {
|
|
75
|
+
this.emit(oNodeMessageEvent.request, data);
|
|
76
|
+
});
|
|
77
|
+
stream.on(oNodeMessageEvent.response, (data) => {
|
|
78
|
+
this.emit(oNodeMessageEvent.response, data);
|
|
79
|
+
});
|
|
80
|
+
stream.p2pStream.addEventListener('close', () => {
|
|
81
|
+
if (this.streams.has(stream.id)) {
|
|
82
|
+
this.streams.delete(stream.id);
|
|
139
83
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
84
|
+
});
|
|
85
|
+
await stream.listen(options);
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
this.logger.warn('Stream errored out when listening for key messages:', err?.message);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
trackStream(stream, options) {
|
|
92
|
+
this.streams.set(stream.id, stream);
|
|
93
|
+
this.logger.debug('Stream count: ' + this.streams.size);
|
|
94
|
+
// persistent listener
|
|
95
|
+
this.listenForMessages(stream, options);
|
|
96
|
+
}
|
|
97
|
+
async doSend(request, options) {
|
|
98
|
+
try {
|
|
99
|
+
// create a new stream and send the payload
|
|
100
|
+
const wrappedStream = await this.newStream({
|
|
101
|
+
remoteAddress: this.nextHopAddress,
|
|
102
|
+
limited: this.runOnLimitedConnection,
|
|
103
|
+
...options,
|
|
104
|
+
});
|
|
105
|
+
this.trackStream(wrappedStream, options);
|
|
106
|
+
await wrappedStream.send(request, options);
|
|
107
|
+
return wrappedStream;
|
|
108
|
+
}
|
|
109
|
+
catch (err) {
|
|
110
|
+
this.logger.error('Failed to send request over stream.', err);
|
|
111
|
+
throw new oError(oErrorCodes.SEND_FAILED, 'Failed to send request over stream.', { request: request.toJSON() });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
async transmit(request, options) {
|
|
115
|
+
try {
|
|
116
|
+
this.logger.debug('Transmitting request on limited connection?', this.config.runOnLimitedConnection);
|
|
117
|
+
const stream = await this.doSend(request, options);
|
|
144
118
|
// Handle cleanup of the stream
|
|
145
|
-
await this.postTransmit(
|
|
146
|
-
return
|
|
119
|
+
await this.postTransmit(stream);
|
|
120
|
+
return stream;
|
|
147
121
|
}
|
|
148
122
|
catch (error) {
|
|
149
123
|
if (error?.name === 'UnsupportedProtocolError') {
|
|
@@ -153,37 +127,7 @@ export class oNodeConnection extends oConnection {
|
|
|
153
127
|
}
|
|
154
128
|
}
|
|
155
129
|
async postTransmit(stream) {
|
|
156
|
-
//
|
|
157
|
-
await this.streamManager.releaseStream(stream.p2pStream.id);
|
|
158
|
-
}
|
|
159
|
-
/**
|
|
160
|
-
* Set up persistent listener for identify events from the remote peer
|
|
161
|
-
*/
|
|
162
|
-
setupIdentifyListener() {
|
|
163
|
-
if (!this.p2pNode) {
|
|
164
|
-
return;
|
|
165
|
-
}
|
|
166
|
-
this.identifyListener = (evt) => {
|
|
167
|
-
const { peerId, protocols, agentVersion, protocolVersion, listenAddrs, observedAddr, } = evt.detail;
|
|
168
|
-
// Only cache if this event is for our remote peer
|
|
169
|
-
if (peerId?.toString() === this.remotePeerId.toString()) {
|
|
170
|
-
this.identifyData = {
|
|
171
|
-
protocols: protocols || [],
|
|
172
|
-
agentVersion,
|
|
173
|
-
protocolVersion,
|
|
174
|
-
listenAddrs: listenAddrs || [],
|
|
175
|
-
observedAddr,
|
|
176
|
-
timestamp: Date.now(),
|
|
177
|
-
};
|
|
178
|
-
this.logger.debug('Cached identify data for peer', {
|
|
179
|
-
peerId: peerId.toString(),
|
|
180
|
-
protocols: this.identifyData.protocols,
|
|
181
|
-
agentVersion: this.identifyData.agentVersion,
|
|
182
|
-
});
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
this.p2pNode.addEventListener('peer:identify', this.identifyListener);
|
|
186
|
-
this.logger.debug('Identify listener set up for connection');
|
|
130
|
+
// after transmit, let's just leave this connection open for now
|
|
187
131
|
}
|
|
188
132
|
async abort(error) {
|
|
189
133
|
this.logger.debug('Aborting connection');
|
|
@@ -192,13 +136,25 @@ export class oNodeConnection extends oConnection {
|
|
|
192
136
|
}
|
|
193
137
|
async close() {
|
|
194
138
|
this.logger.debug('Closing connection');
|
|
195
|
-
// Remove identify listener
|
|
196
|
-
if (this.p2pNode && this.identifyListener) {
|
|
197
|
-
this.p2pNode.removeEventListener('peer:identify', this.identifyListener);
|
|
198
|
-
}
|
|
199
|
-
// Close stream manager (handles all stream cleanup)
|
|
200
|
-
await this.streamManager.close();
|
|
201
139
|
await this.p2pConnection.close();
|
|
202
140
|
this.logger.debug('Connection closed');
|
|
203
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Add event listener
|
|
144
|
+
*/
|
|
145
|
+
on(event, listener) {
|
|
146
|
+
this.eventEmitter.on(event, listener);
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Remove event listener
|
|
150
|
+
*/
|
|
151
|
+
off(event, listener) {
|
|
152
|
+
this.eventEmitter.off(event, listener);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Emit event
|
|
156
|
+
*/
|
|
157
|
+
emit(event, data) {
|
|
158
|
+
this.eventEmitter.emit(event, data);
|
|
159
|
+
}
|
|
204
160
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { oAddress, oConnectionManager } from '@olane/o-core';
|
|
3
|
+
import { Libp2p, Connection, Stream } from '@olane/o-config';
|
|
3
4
|
import { oNodeConnectionManagerConfig } from './interfaces/o-node-connection-manager.config.js';
|
|
5
|
+
import { oNodeAddress } from '../router/o-node.address.js';
|
|
4
6
|
import { oNodeConnection } from './o-node-connection.js';
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
import { oNodeConnectionConfig } from './interfaces/o-node-connection.config.js';
|
|
5
9
|
/**
|
|
6
10
|
* Manages oNodeConnection instances, reusing connections when possible.
|
|
7
11
|
*/
|
|
@@ -13,6 +17,7 @@ export declare class oNodeConnectionManager extends oConnectionManager {
|
|
|
13
17
|
/** Single cache of oNodeConnection instances keyed by address */
|
|
14
18
|
protected cachedConnections: Map<string, oNodeConnection>;
|
|
15
19
|
protected pendingDialsByAddress: Map<string, Promise<Connection>>;
|
|
20
|
+
protected eventEmitter: EventEmitter;
|
|
16
21
|
constructor(config: oNodeConnectionManagerConfig);
|
|
17
22
|
/**
|
|
18
23
|
* Set up listeners to maintain connection cache state
|
|
@@ -36,16 +41,15 @@ export declare class oNodeConnectionManager extends oConnectionManager {
|
|
|
36
41
|
*/
|
|
37
42
|
protected getOrCreateP2pConnection(nextHopAddress: oAddress, addressKey: string): Promise<Connection>;
|
|
38
43
|
protected performDial(nextHopAddress: oAddress, addressKey: string): Promise<Connection>;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
reuse?: boolean;
|
|
42
|
-
}): Promise<oNodeConnection>;
|
|
43
|
-
getConnectionFromAddress(address: oAddress): oNodeConnection | null;
|
|
44
|
+
createConnection(config: oNodeConnectionConfig): Promise<oNodeConnection>;
|
|
45
|
+
answer(config: oNodeConnectionConfig, stream: Stream): Promise<oNodeConnection>;
|
|
44
46
|
/**
|
|
45
47
|
* Connect to a given address, reusing oNodeConnection when possible
|
|
46
48
|
* @param config - Connection configuration
|
|
47
49
|
* @returns The connection object
|
|
48
50
|
*/
|
|
49
|
-
connect(config:
|
|
51
|
+
connect(config: oNodeConnectionConfig): Promise<oNodeConnection>;
|
|
52
|
+
getCachedConnectionFromAddress(address: oNodeAddress): oNodeConnection | null;
|
|
53
|
+
get connectionCount(): number;
|
|
50
54
|
}
|
|
51
55
|
//# sourceMappingURL=o-node-connection.manager.d.ts.map
|
|
@@ -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,
|
|
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,EAAqB,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAChF,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,4BAA4B,EAAE,MAAM,kDAAkD,CAAC;AAChG,OAAO,EAAE,YAAY,EAAE,MAAM,6BAA6B,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,EAAE,qBAAqB,EAAE,MAAM,0CAA0C,CAAC;AAGjF;;GAEG;AACH,qBAAa,sBAAuB,SAAQ,kBAAkB;IAShD,QAAQ,CAAC,MAAM,EAAE,4BAA4B;IARzD,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC;IAC1B,SAAS,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC;IACxC,SAAS,CAAC,qBAAqB,CAAC,EAAE,MAAM,CAAC;IACzC,iEAAiE;IACjE,SAAS,CAAC,iBAAiB,EAAE,GAAG,CAAC,MAAM,EAAE,eAAe,CAAC,CAAa;IACtE,SAAS,CAAC,qBAAqB,EAAE,GAAG,CAAC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC,CAAa;IAC9E,SAAS,CAAC,YAAY,EAAE,YAAY,CAAsB;gBAErC,MAAM,EAAE,4BAA4B;IAWzD;;OAEG;IACH,SAAS,CAAC,wBAAwB,IAAI,IAAI;IAY1C;;;;OAIG;IACH,SAAS,CAAC,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,MAAM,GAAG,IAAI;IAahE;;;;OAIG;IACH,SAAS,CAAC,eAAe,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI;IAWtD;;;OAGG;cACa,wBAAwB,CACtC,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC;cAoBN,WAAW,CACzB,cAAc,EAAE,QAAQ,EACxB,UAAU,EAAE,MAAM,GACjB,OAAO,CAAC,UAAU,CAAC;IAqBhB,gBAAgB,CACpB,MAAM,EAAE,qBAAqB,GAC5B,OAAO,CAAC,eAAe,CAAC;IAIrB,MAAM,CACV,MAAM,EAAE,qBAAqB,EAC7B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,eAAe,CAAC;IAgE3B;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,eAAe,CAAC;IAyDtE,8BAA8B,CAC5B,OAAO,EAAE,YAAY,GACpB,eAAe,GAAG,IAAI;IAezB,IAAI,eAAe,WAElB;CACF"}
|