@olane/o-node 0.7.54 → 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 +17 -3
- 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 +33 -11
- package/dist/src/connection/o-node-connection.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.js +113 -58
- package/dist/src/connection/o-node-connection.manager.d.ts +17 -62
- package/dist/src/connection/o-node-connection.manager.d.ts.map +1 -1
- package/dist/src/connection/o-node-connection.manager.js +65 -189
- 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 +144 -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/connection/stream-manager.events.d.ts +7 -0
- package/dist/src/connection/stream-manager.events.d.ts.map +1 -1
- package/dist/src/connection/stream-manager.events.js +1 -0
- 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 +31 -65
- package/dist/src/router/o-node.router.d.ts.map +1 -1
- package/dist/src/router/o-node.router.js +4 -2
- package/dist/src/utils/connection.utils.d.ts +3 -3
- package/dist/src/utils/connection.utils.d.ts.map +1 -1
- package/dist/src/utils/connection.utils.js +46 -19
- 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 -200
- package/dist/src/connection/o-node-stream.manager.d.ts.map +0 -1
- package/dist/src/connection/o-node-stream.manager.js +0 -633
- /package/dist/src/connection/interfaces/{stream-manager.config.js → abort-signal.config.js} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-handler.config.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-handler.config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAM,
|
|
1
|
+
{"version":3,"file":"stream-handler.config.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-handler.config.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEhD;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IAExB;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAE5B;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAC;IAErB;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;;OAGG;IACH,iBAAiB,CAAC,EAAE,MAAM,CAAC;CAC5B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,mBAAmB,CAAC;CAC7B"}
|
|
@@ -12,6 +12,7 @@ export declare enum StreamManagerEvent {
|
|
|
12
12
|
StreamReplaced = "stream-replaced",
|
|
13
13
|
StreamFailed = "stream-failed",
|
|
14
14
|
StreamIdentified = "stream-identified",
|
|
15
|
+
StreamClosed = "stream-closed",
|
|
15
16
|
InboundRequest = "inbound-request",
|
|
16
17
|
InboundResponse = "inbound-response",
|
|
17
18
|
StreamError = "stream-error"
|
|
@@ -53,6 +54,11 @@ export interface StreamIdentifiedData {
|
|
|
53
54
|
role: 'reader' | 'writer' | 'standard';
|
|
54
55
|
connectionId?: string;
|
|
55
56
|
}
|
|
57
|
+
export interface StreamClosedData {
|
|
58
|
+
streamId: string;
|
|
59
|
+
role: 'reader' | 'writer';
|
|
60
|
+
status: string;
|
|
61
|
+
}
|
|
56
62
|
export interface InboundRequestData {
|
|
57
63
|
request: any;
|
|
58
64
|
stream: any;
|
|
@@ -81,6 +87,7 @@ export type StreamManagerEventData = {
|
|
|
81
87
|
[StreamManagerEvent.StreamReplaced]: StreamReplacedData;
|
|
82
88
|
[StreamManagerEvent.StreamFailed]: StreamFailedData;
|
|
83
89
|
[StreamManagerEvent.StreamIdentified]: StreamIdentifiedData;
|
|
90
|
+
[StreamManagerEvent.StreamClosed]: StreamClosedData;
|
|
84
91
|
[StreamManagerEvent.InboundRequest]: InboundRequestData;
|
|
85
92
|
[StreamManagerEvent.InboundResponse]: InboundResponseData;
|
|
86
93
|
[StreamManagerEvent.StreamError]: StreamErrorData;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream-manager.events.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-manager.events.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,kBAAkB,wBAAwB;IAC1C,aAAa,mBAAmB;IAChC,aAAa,mBAAmB;IAChC,aAAa,mBAAmB;IAChC,YAAY,kBAAkB;IAC9B,eAAe,qBAAqB;IACpC,cAAc,oBAAoB;IAClC,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;IAC9B,gBAAgB,sBAAsB;IACtC,cAAc,oBAAoB;IAClC,eAAe,qBAAqB;IACpC,WAAW,iBAAiB;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;CAAG;AAEnC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAA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YAAY,CAAC,EAAE,gBAAgB,CAAC;IACpD,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IAC5D,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACxD,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,mBAAmB,CAAC;IAC1D,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,eAAe,CAAC;CACnD,CAAC"}
|
|
1
|
+
{"version":3,"file":"stream-manager.events.d.ts","sourceRoot":"","sources":["../../../src/connection/stream-manager.events.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,oBAAY,kBAAkB;IAC5B,kBAAkB,wBAAwB;IAC1C,aAAa,mBAAmB;IAChC,aAAa,mBAAmB;IAChC,aAAa,mBAAmB;IAChC,YAAY,kBAAkB;IAC9B,eAAe,qBAAqB;IACpC,cAAc,oBAAoB;IAClC,cAAc,oBAAoB;IAClC,YAAY,kBAAkB;IAC9B,gBAAgB,sBAAsB;IACtC,YAAY,kBAAkB;IAC9B,cAAc,oBAAoB;IAClC,eAAe,qBAAqB;IACpC,WAAW,iBAAiB;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;CAAG;AAEnC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB;IAChC,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,mBAAmB;IAClC,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,YAAY,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,kBAAkB;IACjC,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAA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AAC,EAAE,kBAAkB,CAAC;IACxD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACxD,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,gBAAgB,CAAC;IACpD,CAAC,kBAAkB,CAAC,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IAC5D,CAAC,kBAAkB,CAAC,YAAY,CAAC,EAAE,gBAAgB,CAAC;IACpD,CAAC,kBAAkB,CAAC,cAAc,CAAC,EAAE,kBAAkB,CAAC;IACxD,CAAC,kBAAkB,CAAC,eAAe,CAAC,EAAE,mBAAmB,CAAC;IAC1D,CAAC,kBAAkB,CAAC,WAAW,CAAC,EAAE,eAAe,CAAC;CACnD,CAAC"}
|
|
@@ -13,6 +13,7 @@ export var StreamManagerEvent;
|
|
|
13
13
|
StreamManagerEvent["StreamReplaced"] = "stream-replaced";
|
|
14
14
|
StreamManagerEvent["StreamFailed"] = "stream-failed";
|
|
15
15
|
StreamManagerEvent["StreamIdentified"] = "stream-identified";
|
|
16
|
+
StreamManagerEvent["StreamClosed"] = "stream-closed";
|
|
16
17
|
StreamManagerEvent["InboundRequest"] = "inbound-request";
|
|
17
18
|
StreamManagerEvent["InboundResponse"] = "inbound-response";
|
|
18
19
|
StreamManagerEvent["StreamError"] = "stream-error";
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { oNodeAddress } from '../../router/o-node.address.js';
|
|
2
|
+
import { oNodeConnectionManager } from '../../connection/o-node-connection.manager.js';
|
|
3
|
+
import { oNodeRouter } from '../../router/o-node.router.js';
|
|
4
|
+
export interface oNodeRequestManagerConfig {
|
|
5
|
+
callerAddress: oNodeAddress;
|
|
6
|
+
connectionManager: oNodeConnectionManager;
|
|
7
|
+
router: oNodeRouter;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=o-node-request-manager.config.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-node-request-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/lib/interfaces/o-node-request-manager.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AAC9D,OAAO,EAAE,sBAAsB,EAAE,MAAM,+CAA+C,CAAC;AACvF,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAE5D,MAAM,WAAW,yBAAyB;IACxC,aAAa,EAAE,YAAY,CAAC;IAC5B,iBAAiB,EAAE,sBAAsB,CAAC;IAC1C,MAAM,EAAE,WAAW,CAAC;CACrB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { oRequestManager, oResponse, UseOptions } from '@olane/o-core';
|
|
3
|
+
import { oNodeRequestManagerConfig } from './interfaces/o-node-request-manager.config.js';
|
|
4
|
+
import { oNodeConnection, oNodeConnectionConfig, oNodeConnectionManager } from '../connection/index.js';
|
|
5
|
+
import { oNodeRouter } from '../router/o-node.router.js';
|
|
6
|
+
import { oNodeAddress } from '../router/o-node.address.js';
|
|
7
|
+
import { UseDataConfig } from '@olane/o-core/dist/src/core/interfaces/use-data.config.js';
|
|
8
|
+
import { oNode } from '../o-node.js';
|
|
9
|
+
import { Connection, Stream } from '@olane/o-config';
|
|
10
|
+
import { oNodeMessageEvent, oNodeMessageEventData } from '../connection/enums/o-node-message-event.js';
|
|
11
|
+
import { oStreamRequest } from '../connection/o-stream.request.js';
|
|
12
|
+
import { EventEmitter } from 'events';
|
|
13
|
+
import { AbortSignalConfig } from '../connection/interfaces/abort-signal.config.js';
|
|
14
|
+
import { RunResult } from '@olane/o-tool';
|
|
15
|
+
export declare class oNodeRequestManager extends oRequestManager {
|
|
16
|
+
readonly config: oNodeRequestManagerConfig;
|
|
17
|
+
connectionManager: oNodeConnectionManager;
|
|
18
|
+
router: oNodeRouter;
|
|
19
|
+
protected eventEmitter: EventEmitter;
|
|
20
|
+
constructor(config: oNodeRequestManagerConfig);
|
|
21
|
+
translateAddress(address: oNodeAddress, options?: UseOptions, nodeRef?: oNode): Promise<{
|
|
22
|
+
nextHopAddress: oNodeAddress;
|
|
23
|
+
targetAddress: oNodeAddress;
|
|
24
|
+
}>;
|
|
25
|
+
connectToNode(nextHopAddress: oNodeAddress, options: Omit<oNodeConnectionConfig, 'nextHopAddress'>): Promise<oNodeConnection>;
|
|
26
|
+
send(address: oNodeAddress, data: UseDataConfig, options?: UseOptions, nodeRef?: oNode): Promise<oResponse>;
|
|
27
|
+
receiveStream({ connection, stream, }: {
|
|
28
|
+
connection: Connection;
|
|
29
|
+
stream: Stream;
|
|
30
|
+
}): Promise<void>;
|
|
31
|
+
sendResponse(request: oStreamRequest, result: RunResult): Promise<void>;
|
|
32
|
+
protected listenForMessages(connection: oNodeConnection, options: AbortSignalConfig): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Add event listener
|
|
35
|
+
*/
|
|
36
|
+
on<K extends oNodeMessageEvent>(event: K | string, listener: (data: oNodeMessageEventData[K]) => void): void;
|
|
37
|
+
/**
|
|
38
|
+
* Remove event listener
|
|
39
|
+
*/
|
|
40
|
+
off<K extends oNodeMessageEvent>(event: K | string, listener: (data: oNodeMessageEventData[K]) => void): void;
|
|
41
|
+
/**
|
|
42
|
+
* Emit event
|
|
43
|
+
*/
|
|
44
|
+
private emitAsync;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=o-node-request-manager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"o-node-request-manager.d.ts","sourceRoot":"","sources":["../../../src/lib/o-node-request-manager.ts"],"names":[],"mappings":";AAAA,OAAO,EAML,eAAe,EACf,SAAS,EAET,UAAU,EACX,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,yBAAyB,EAAE,MAAM,+CAA+C,CAAC;AAC1F,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EAEvB,MAAM,wBAAwB,CAAC;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EAClB,UAAU,EACV,MAAM,GACP,EAAE;QACD,UAAU,EAAE,UAAU,CAAC;QACvB,MAAM,EAAE,MAAM,CAAC;KAChB;IAsBK,YAAY,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,SAAS;cAsB7C,iBAAiB,CAC/B,UAAU,EAAE,eAAe,EAC3B,OAAO,EAAE,iBAAiB;IAyB5B;;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;YAQW,SAAS;CAcxB"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { CoreUtils, oError, oErrorCodes, oRequestManager, ResponseBuilder, } from '@olane/o-core';
|
|
2
|
+
import { oNodeAddress } from '../router/o-node.address.js';
|
|
3
|
+
import { oNodeMessageEvent, } from '../connection/enums/o-node-message-event.js';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
5
|
+
import { v4 } from 'uuid';
|
|
6
|
+
export class oNodeRequestManager extends oRequestManager {
|
|
7
|
+
constructor(config) {
|
|
8
|
+
super();
|
|
9
|
+
this.config = config;
|
|
10
|
+
this.eventEmitter = new EventEmitter();
|
|
11
|
+
this.router = config.router;
|
|
12
|
+
this.connectionManager = config.connectionManager;
|
|
13
|
+
}
|
|
14
|
+
async translateAddress(address, options, nodeRef) {
|
|
15
|
+
if (!nodeRef) {
|
|
16
|
+
throw new Error('Failed to translate address due to invalid node reference');
|
|
17
|
+
}
|
|
18
|
+
const { nextHopAddress, targetAddress } = options?.noRouting
|
|
19
|
+
? { nextHopAddress: address, targetAddress: address }
|
|
20
|
+
: await this.router.translate(address, nodeRef);
|
|
21
|
+
return {
|
|
22
|
+
nextHopAddress: nextHopAddress,
|
|
23
|
+
targetAddress: targetAddress,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
async connectToNode(nextHopAddress, options) {
|
|
27
|
+
if (!this.connectionManager) {
|
|
28
|
+
this.logger.error('Connection manager not initialized');
|
|
29
|
+
throw new Error('Node is not ready to connect to other nodes');
|
|
30
|
+
}
|
|
31
|
+
const connection = await this.connectionManager
|
|
32
|
+
.connect({
|
|
33
|
+
nextHopAddress: nextHopAddress,
|
|
34
|
+
...options,
|
|
35
|
+
})
|
|
36
|
+
.catch((error) => {
|
|
37
|
+
// TODO: we need to handle this better and document
|
|
38
|
+
if (error.message === 'Can not dial self') {
|
|
39
|
+
this.logger.error('Make sure you are entering the network not directly through the leader node.');
|
|
40
|
+
}
|
|
41
|
+
throw error;
|
|
42
|
+
});
|
|
43
|
+
if (!connection) {
|
|
44
|
+
throw new Error('Connection failed');
|
|
45
|
+
}
|
|
46
|
+
return connection;
|
|
47
|
+
}
|
|
48
|
+
async send(address, data, options, nodeRef) {
|
|
49
|
+
if (!address.validate()) {
|
|
50
|
+
throw new Error('Invalid address');
|
|
51
|
+
}
|
|
52
|
+
this.logger.debug('Using address: ', address.toString());
|
|
53
|
+
// check for static match
|
|
54
|
+
// TODO
|
|
55
|
+
// if (address.toStaticAddress().equals(this.config.callerAddress.toStaticAddress())) {
|
|
56
|
+
// return this.useSelf(data);
|
|
57
|
+
// }
|
|
58
|
+
// if no routing is requested, use the address as is
|
|
59
|
+
if (options?.noRouting) {
|
|
60
|
+
this.logger.debug('No routing requested, using address as is', address.toString());
|
|
61
|
+
}
|
|
62
|
+
const { nextHopAddress, targetAddress } = await this.translateAddress(address, options, nodeRef);
|
|
63
|
+
const connection = await this.connectToNode(nextHopAddress, {
|
|
64
|
+
targetAddress: targetAddress,
|
|
65
|
+
callerAddress: this.config.callerAddress,
|
|
66
|
+
readTimeoutMs: options?.readTimeoutMs,
|
|
67
|
+
drainTimeoutMs: options?.drainTimeoutMs,
|
|
68
|
+
isStream: options?.isStream,
|
|
69
|
+
abortSignal: options?.abortSignal,
|
|
70
|
+
});
|
|
71
|
+
if (options?.isStream) {
|
|
72
|
+
connection.onChunk((response) => {
|
|
73
|
+
options.onChunk?.(response);
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
// communicate the payload to the target node
|
|
77
|
+
const requestId = data?.id || v4();
|
|
78
|
+
const stream = await connection.send({
|
|
79
|
+
address: targetAddress?.toString() || '',
|
|
80
|
+
payload: data || {},
|
|
81
|
+
id: requestId,
|
|
82
|
+
}, options);
|
|
83
|
+
const response = await stream.waitForResponse(requestId);
|
|
84
|
+
stream.close();
|
|
85
|
+
// we handle streaming response differently
|
|
86
|
+
if (options?.isStream) {
|
|
87
|
+
return response;
|
|
88
|
+
}
|
|
89
|
+
// if there is an error, throw it to continue to bubble up
|
|
90
|
+
this.handleResponseError(response);
|
|
91
|
+
return response;
|
|
92
|
+
}
|
|
93
|
+
async receiveStream({ connection, stream, }) {
|
|
94
|
+
const unknown = new oNodeAddress('o://unknown', []);
|
|
95
|
+
const oConnection = await this.connectionManager.answer({
|
|
96
|
+
nextHopAddress: unknown,
|
|
97
|
+
targetAddress: unknown,
|
|
98
|
+
callerAddress: unknown,
|
|
99
|
+
p2pConnection: connection,
|
|
100
|
+
}, stream);
|
|
101
|
+
// Get the oNodeConnection for this libp2p connection
|
|
102
|
+
if (!oConnection) {
|
|
103
|
+
this.logger.error('Failed to process inbound connection');
|
|
104
|
+
throw new Error('Failed to process inbound connection');
|
|
105
|
+
}
|
|
106
|
+
// listen for requests
|
|
107
|
+
this.listenForMessages(oConnection, {});
|
|
108
|
+
}
|
|
109
|
+
async sendResponse(request, result) {
|
|
110
|
+
const responseBuilder = ResponseBuilder.create();
|
|
111
|
+
const responseStream = request.stream;
|
|
112
|
+
try {
|
|
113
|
+
// Emit InboundRequest event and wait for handler to process
|
|
114
|
+
const response = await responseBuilder.build(request, result, null);
|
|
115
|
+
await CoreUtils.sendResponse(response, request.stream);
|
|
116
|
+
this.logger.debug(`Successfully processed request: method=${request.method}, id=${request.id}`);
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
this.logger.error(`Error processing request: method=${request.method}, id=${request.id}`, error);
|
|
120
|
+
const errorResponse = await responseBuilder.buildError(request, error);
|
|
121
|
+
await CoreUtils.sendResponse(errorResponse, responseStream);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
// bubble up the messages to the request handler
|
|
125
|
+
async listenForMessages(connection, options) {
|
|
126
|
+
if (connection.eventEmitter.listenerCount(oNodeMessageEvent.request) > 0) {
|
|
127
|
+
this.logger.warn('Already listening for this event on connection id:', connection.id);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
connection.on(oNodeMessageEvent.request, async (data) => {
|
|
131
|
+
try {
|
|
132
|
+
const result = await this.emitAsync(oNodeMessageEvent.request, data);
|
|
133
|
+
this.sendResponse(data, result);
|
|
134
|
+
}
|
|
135
|
+
catch (err) {
|
|
136
|
+
this.logger.error('Error with request:', err);
|
|
137
|
+
const responseBuilder = ResponseBuilder.create();
|
|
138
|
+
const errorResponse = await responseBuilder.buildError(data, err);
|
|
139
|
+
await CoreUtils.sendResponse(errorResponse, data.stream);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Add event listener
|
|
145
|
+
*/
|
|
146
|
+
on(event, listener) {
|
|
147
|
+
this.eventEmitter.on(event, listener);
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Remove event listener
|
|
151
|
+
*/
|
|
152
|
+
off(event, listener) {
|
|
153
|
+
this.eventEmitter.off(event, listener);
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Emit event
|
|
157
|
+
*/
|
|
158
|
+
// private emit<K extends oNodeMessageEvent>(
|
|
159
|
+
// event: K,
|
|
160
|
+
// data?: oNodeMessageEventData[K],
|
|
161
|
+
// ): void {
|
|
162
|
+
// this.eventEmitter.emit(event, data);
|
|
163
|
+
// }
|
|
164
|
+
async emitAsync(event, data) {
|
|
165
|
+
const listeners = this.eventEmitter.listeners(event);
|
|
166
|
+
if (listeners.length === 0) {
|
|
167
|
+
throw new oError(oErrorCodes.INTERNAL_ERROR, `No listener registered for event: ${event}`);
|
|
168
|
+
}
|
|
169
|
+
// Call the first listener and await its response
|
|
170
|
+
const listener = listeners[0];
|
|
171
|
+
return await listener(data);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-reconnection.manager.d.ts","sourceRoot":"","sources":["../../../src/managers/o-reconnection.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EASR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAI3E,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,yBAAyB,EAAE,MAAM,CAAC;IAClC,yBAAyB,EAAE,MAAM,CAAC;CACnC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;IAI7C,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,MAAM;IAJhB,OAAO,CAAC,YAAY,CAAS;gBAGnB,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,kBAAkB;IAMpC,OAAO,CAAC,mBAAmB;IAyBrB,mBAAmB,CAAC,KAAK,EAAE,GAAG;
|
|
1
|
+
{"version":3,"file":"o-reconnection.manager.d.ts","sourceRoot":"","sources":["../../../src/managers/o-reconnection.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EASR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,kBAAkB,EAAE,MAAM,uCAAuC,CAAC;AAI3E,MAAM,WAAW,kBAAkB;IACjC,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,MAAM,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;IACnB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,yBAAyB,EAAE,MAAM,CAAC;IAClC,yBAAyB,EAAE,MAAM,CAAC;CACnC;AAED;;;;;;;;;;;GAWG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;IAI7C,OAAO,CAAC,IAAI;IACZ,OAAO,CAAC,MAAM;IAJhB,OAAO,CAAC,YAAY,CAAS;gBAGnB,IAAI,EAAE,kBAAkB,EACxB,MAAM,EAAE,kBAAkB;IAMpC,OAAO,CAAC,mBAAmB;IAyBrB,mBAAmB,CAAC,KAAK,EAAE,GAAG;YAwCtB,wBAAwB;YAaxB,wBAAwB;YAexB,wBAAwB;IAehC,mBAAmB;YAgDX,2BAA2B;YAiB3B,iBAAiB;IAkB/B;;;OAGG;YACW,yBAAyB;IAyFvC;;OAEG;IACG,yBAAyB;IAoH/B,OAAO,CAAC,yBAAyB;IAajC,OAAO,CAAC,kBAAkB;IAI1B,OAAO,CAAC,qBAAqB;IAK7B,OAAO,CAAC,KAAK;CAGd"}
|
|
@@ -33,6 +33,10 @@ export class oReconnectionManager extends oObject {
|
|
|
33
33
|
async handleNodeConnected(event) {
|
|
34
34
|
const connectedEvent = event;
|
|
35
35
|
const nodeAddress = connectedEvent.nodeAddress;
|
|
36
|
+
if (this.node.state !== NodeState.RUNNING) {
|
|
37
|
+
this.logger.warn('Ignoring node connection events during startup');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
36
40
|
// if leader is back online re-register
|
|
37
41
|
if (nodeAddress.toString() === oAddress.leader().toString()) {
|
|
38
42
|
// Check if we can register with leader (not already registering or registered)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-registration.manager.d.ts","sourceRoot":"","sources":["../../../src/managers/o-registration.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAGvE,MAAM,MAAM,iBAAiB,GACzB,gBAAgB,GAChB,aAAa,GACb,YAAY,GACZ,QAAQ,CAAC;AAEb,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;IAMnC,OAAO,CAAC,IAAI;IALxB,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,WAAW,CAAC,CAAQ;IAC5B,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAER,IAAI,EAAE,gBAAgB;IAI1C;;;OAGG;IACH,iBAAiB,IAAI,OAAO;IAM5B;;;OAGG;IACH,iBAAiB,IAAI,OAAO;IAM5B;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,iBAAiB,IAAI,OAAO;IAe5B;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;OAEG;IACH,QAAQ,IAAI,IAAI;IAKhB;;OAEG;IACH,SAAS,IAAI,kBAAkB;IAS/B;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"o-registration.manager.d.ts","sourceRoot":"","sources":["../../../src/managers/o-registration.manager.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,OAAO,EAIR,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,qCAAqC,CAAC;AAGvE,MAAM,MAAM,iBAAiB,GACzB,gBAAgB,GAChB,aAAa,GACb,YAAY,GACZ,QAAQ,CAAC;AAEb,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,iBAAiB,CAAC;IAC1B,MAAM,EAAE,iBAAiB,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;;;;;;;;;GAYG;AACH,qBAAa,oBAAqB,SAAQ,OAAO;IAMnC,OAAO,CAAC,IAAI;IALxB,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,WAAW,CAAuC;IAC1D,OAAO,CAAC,WAAW,CAAC,CAAQ;IAC5B,OAAO,CAAC,WAAW,CAAC,CAAQ;gBAER,IAAI,EAAE,gBAAgB;IAI1C;;;OAGG;IACH,iBAAiB,IAAI,OAAO;IAM5B;;;OAGG;IACH,iBAAiB,IAAI,OAAO;IAM5B;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,kBAAkB,IAAI,OAAO;IAI7B;;OAEG;IACH,iBAAiB,IAAI,OAAO;IAe5B;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;OAEG;IACH,gBAAgB,IAAI,IAAI;IAMxB;;OAEG;IACH,QAAQ,IAAI,IAAI;IAKhB;;OAEG;IACH,SAAS,IAAI,kBAAkB;IAS/B;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;IAgGrC;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,IAAI,CAAC;CAyDtC"}
|
|
@@ -141,8 +141,11 @@ export class oRegistrationManager extends oObject {
|
|
|
141
141
|
return;
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
-
//
|
|
145
|
-
|
|
144
|
+
// necessary hack to ensure that registry node and other leader->child relationships build accurately
|
|
145
|
+
const isParentLeader = this.node?.config?.parent?.value === oAddress.leader().value;
|
|
146
|
+
await this.node.use(isParentLeader
|
|
147
|
+
? this.node.config.parent
|
|
148
|
+
: new oNodeAddress(this.node.config.parent.value), {
|
|
146
149
|
method: 'child_register',
|
|
147
150
|
params: {
|
|
148
151
|
address: this.node.address.toString(),
|
|
@@ -164,7 +167,8 @@ export class oRegistrationManager extends oObject {
|
|
|
164
167
|
catch (error) {
|
|
165
168
|
// Failure - transition to failed state
|
|
166
169
|
this.parentState = 'failed';
|
|
167
|
-
this.parentError =
|
|
170
|
+
this.parentError =
|
|
171
|
+
error instanceof Error ? error : new Error(String(error));
|
|
168
172
|
this.logger.error('Failed to register with parent:', {
|
|
169
173
|
parent: this.node.parent?.toString(),
|
|
170
174
|
error: this.parentError.message,
|
|
@@ -215,7 +219,8 @@ export class oRegistrationManager extends oObject {
|
|
|
215
219
|
catch (error) {
|
|
216
220
|
// Failure - transition to failed state
|
|
217
221
|
this.leaderState = 'failed';
|
|
218
|
-
this.leaderError =
|
|
222
|
+
this.leaderError =
|
|
223
|
+
error instanceof Error ? error : new Error(String(error));
|
|
219
224
|
this.logger.error('Failed to register with leader:', {
|
|
220
225
|
leader: this.node.leader?.toString(),
|
|
221
226
|
error: this.leaderError.message,
|
package/dist/src/o-node.d.ts
CHANGED
|
@@ -1,26 +1,28 @@
|
|
|
1
1
|
import { Libp2p, Libp2pConfig } from '@olane/o-config';
|
|
2
2
|
import { PeerId } from '@olane/o-config';
|
|
3
|
+
import { oNodeRouter } from './router/o-node.router.js';
|
|
3
4
|
import { oNodeHierarchyManager } from './o-node.hierarchy-manager.js';
|
|
4
5
|
import { oNodeConfig } from './interfaces/o-node.config.js';
|
|
5
6
|
import { oNodeTransport } from './router/o-node.transport.js';
|
|
6
7
|
import { oRequest, oNotificationManager } from '@olane/o-core';
|
|
7
8
|
import { oNodeAddress } from './router/o-node.address.js';
|
|
8
|
-
import { oNodeConnection } from './connection/o-node-connection.js';
|
|
9
9
|
import { oNodeConnectionManager } from './connection/o-node-connection.manager.js';
|
|
10
10
|
import { oToolBase } from '@olane/o-tool';
|
|
11
11
|
import { oConnectionHeartbeatManager } from './managers/o-connection-heartbeat.manager.js';
|
|
12
|
-
import { oNodeConnectionConfig } from './connection/index.js';
|
|
13
12
|
import { oReconnectionManager } from './managers/o-reconnection.manager.js';
|
|
14
13
|
import { oRegistrationManager } from './managers/o-registration.manager.js';
|
|
15
14
|
import { LockManager } from './utils/lock-manager.js';
|
|
15
|
+
import { oNodeRequestManager } from './lib/o-node-request-manager.js';
|
|
16
16
|
export declare class oNode extends oToolBase {
|
|
17
17
|
peerId: PeerId;
|
|
18
18
|
p2pNode: Libp2p;
|
|
19
19
|
address: oNodeAddress;
|
|
20
20
|
config: oNodeConfig;
|
|
21
|
-
|
|
21
|
+
router: oNodeRouter;
|
|
22
22
|
hierarchyManager: oNodeHierarchyManager;
|
|
23
23
|
connectionHeartbeatManager?: oConnectionHeartbeatManager;
|
|
24
|
+
connectionManager: oNodeConnectionManager;
|
|
25
|
+
requestManager: oNodeRequestManager;
|
|
24
26
|
protected reconnectionManager?: oReconnectionManager;
|
|
25
27
|
registrationManager: oRegistrationManager;
|
|
26
28
|
protected hooksStartFinished: any[];
|
|
@@ -44,6 +46,7 @@ export declare class oNode extends oToolBase {
|
|
|
44
46
|
register(): Promise<void>;
|
|
45
47
|
extractMethod(address: oNodeAddress): string;
|
|
46
48
|
start(): Promise<void>;
|
|
49
|
+
initRequestManager(): void;
|
|
47
50
|
validateJoinRequest(request: oRequest): Promise<any>;
|
|
48
51
|
/**
|
|
49
52
|
* Configure the libp2p node
|
|
@@ -51,7 +54,6 @@ export declare class oNode extends oToolBase {
|
|
|
51
54
|
*/
|
|
52
55
|
configure(): Promise<Libp2pConfig>;
|
|
53
56
|
protected createNode(): Promise<Libp2p>;
|
|
54
|
-
connect(config: oNodeConnectionConfig): Promise<oNodeConnection>;
|
|
55
57
|
initConnectionManager(): Promise<void>;
|
|
56
58
|
protected hookInitializeFinished(): Promise<void>;
|
|
57
59
|
onInitFinished(cb: Function): void;
|
|
@@ -72,9 +74,6 @@ export declare class oNode extends oToolBase {
|
|
|
72
74
|
*/
|
|
73
75
|
protected validate(): Promise<void>;
|
|
74
76
|
initialize(): Promise<void>;
|
|
75
|
-
/**
|
|
76
|
-
* Override use() to wrap leader/registry requests with retry logic
|
|
77
|
-
*/
|
|
78
77
|
teardown(): Promise<void>;
|
|
79
78
|
/**
|
|
80
79
|
* Reset node state to allow restart after stop
|
package/dist/src/o-node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,YAAY,EAEb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"o-node.d.ts","sourceRoot":"","sources":["../../src/o-node.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,MAAM,EACN,YAAY,EAEb,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAC9D,OAAO,EAIL,QAAQ,EAER,oBAAoB,EACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAE1D,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AAEnF,OAAO,EAAmB,SAAS,EAAE,MAAM,eAAe,CAAC;AAG3D,OAAO,EAAE,2BAA2B,EAAE,MAA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AAO,CAAC,GAAG,CAAC;CAwEhE"}
|
package/dist/src/o-node.js
CHANGED
|
@@ -13,6 +13,8 @@ import { oNodeNotificationManager } from './o-node.notification-manager.js';
|
|
|
13
13
|
import { oReconnectionManager } from './managers/o-reconnection.manager.js';
|
|
14
14
|
import { oRegistrationManager } from './managers/o-registration.manager.js';
|
|
15
15
|
import { LockManager } from './utils/lock-manager.js';
|
|
16
|
+
import { oNodeRequestManager } from './lib/o-node-request-manager.js';
|
|
17
|
+
import { oNodeMessageEvent } from './connection/enums/o-node-message-event.js';
|
|
16
18
|
export class oNode extends oToolBase {
|
|
17
19
|
constructor(config) {
|
|
18
20
|
super(config);
|
|
@@ -174,6 +176,23 @@ export class oNode extends oToolBase {
|
|
|
174
176
|
await this.connectionHeartbeatManager.start();
|
|
175
177
|
}
|
|
176
178
|
}
|
|
179
|
+
initRequestManager() {
|
|
180
|
+
this.requestManager = new oNodeRequestManager({
|
|
181
|
+
callerAddress: this.address,
|
|
182
|
+
connectionManager: this.connectionManager,
|
|
183
|
+
router: this.router,
|
|
184
|
+
});
|
|
185
|
+
this.requestManager.on(oNodeMessageEvent.request, async (data) => {
|
|
186
|
+
try {
|
|
187
|
+
const result = await this.execute(data, data.stream);
|
|
188
|
+
return result;
|
|
189
|
+
}
|
|
190
|
+
catch (error) {
|
|
191
|
+
this.logger.error('Error executing tool: ', data.toString(), error, typeof error);
|
|
192
|
+
throw error; // StreamManager will handle error response building
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
177
196
|
async validateJoinRequest(request) {
|
|
178
197
|
return true;
|
|
179
198
|
}
|
|
@@ -280,32 +299,13 @@ export class oNode extends oToolBase {
|
|
|
280
299
|
this.p2pNode = await createNode(params);
|
|
281
300
|
return this.p2pNode;
|
|
282
301
|
}
|
|
283
|
-
async connect(config) {
|
|
284
|
-
if (!this.connectionManager) {
|
|
285
|
-
this.logger.error('Connection manager not initialized');
|
|
286
|
-
throw new Error('Node is not ready to connect to other nodes');
|
|
287
|
-
}
|
|
288
|
-
const connection = await this.connectionManager
|
|
289
|
-
.connect(config)
|
|
290
|
-
.catch((error) => {
|
|
291
|
-
// TODO: we need to handle this better and document
|
|
292
|
-
if (error.message === 'Can not dial self') {
|
|
293
|
-
this.logger.error('Make sure you are entering the network not directly through the leader node.');
|
|
294
|
-
}
|
|
295
|
-
throw error;
|
|
296
|
-
});
|
|
297
|
-
if (!connection) {
|
|
298
|
-
throw new Error('Connection failed');
|
|
299
|
-
}
|
|
300
|
-
return connection;
|
|
301
|
-
}
|
|
302
302
|
async initConnectionManager() {
|
|
303
303
|
this.connectionManager = new oNodeConnectionManager({
|
|
304
304
|
p2pNode: this.p2pNode,
|
|
305
305
|
defaultReadTimeoutMs: this.config.connectionTimeouts?.readTimeoutMs,
|
|
306
306
|
defaultDrainTimeoutMs: this.config.connectionTimeouts?.drainTimeoutMs,
|
|
307
307
|
runOnLimitedConnection: this.config.runOnLimitedConnection ?? false,
|
|
308
|
-
|
|
308
|
+
callerAddress: this.address?.value,
|
|
309
309
|
});
|
|
310
310
|
}
|
|
311
311
|
async hookInitializeFinished() {
|
|
@@ -429,6 +429,8 @@ export class oNode extends oToolBase {
|
|
|
429
429
|
this.peerId = this.p2pNode.peerId;
|
|
430
430
|
// initialize connection manager
|
|
431
431
|
await this.initConnectionManager();
|
|
432
|
+
// must come after connection manager
|
|
433
|
+
await this.initRequestManager();
|
|
432
434
|
// initialize address resolution
|
|
433
435
|
this.router.addResolver(new oMethodResolver(this.address));
|
|
434
436
|
this.router.addResolver(new oNodeResolver(this.address));
|
|
@@ -439,23 +441,6 @@ export class oNode extends oToolBase {
|
|
|
439
441
|
}
|
|
440
442
|
await this.hookInitializeFinished();
|
|
441
443
|
}
|
|
442
|
-
/**
|
|
443
|
-
* Override use() to wrap leader/registry requests with retry logic
|
|
444
|
-
*/
|
|
445
|
-
// async use(
|
|
446
|
-
// address: oAddress,
|
|
447
|
-
// data?: {
|
|
448
|
-
// method?: string;
|
|
449
|
-
// params?: { [key: string]: any };
|
|
450
|
-
// id?: string;
|
|
451
|
-
// },
|
|
452
|
-
// options?: UseOptions,
|
|
453
|
-
// ): Promise<any> {
|
|
454
|
-
// // Wrap leader/registry requests with retry logic
|
|
455
|
-
// return super.use(address, data, options),
|
|
456
|
-
// address,
|
|
457
|
-
// data?.method,
|
|
458
|
-
// }
|
|
459
444
|
async teardown() {
|
|
460
445
|
// Stop heartbeat before parent teardown
|
|
461
446
|
if (this.connectionHeartbeatManager) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { oAddress, oRequest } from '@olane/o-core';
|
|
2
2
|
import { oServerNode } from './nodes/server.node.js';
|
|
3
3
|
import { Connection, Stream } from '@olane/o-config';
|
|
4
|
+
import { oNodeRequestManager } from './lib/o-node-request-manager.js';
|
|
4
5
|
declare const oNodeTool_base: typeof oServerNode;
|
|
5
6
|
/**
|
|
6
7
|
* oTool is a mixin that extends the base class and implements the oTool interface
|
|
@@ -8,12 +9,11 @@ declare const oNodeTool_base: typeof oServerNode;
|
|
|
8
9
|
* @returns A new class that extends the base class and implements the oTool interface
|
|
9
10
|
*/
|
|
10
11
|
export declare class oNodeTool extends oNodeTool_base {
|
|
11
|
-
|
|
12
|
+
requestManager: oNodeRequestManager;
|
|
12
13
|
handleProtocol(address: oAddress): Promise<void>;
|
|
13
14
|
initializeProtocols(): Promise<void>;
|
|
14
15
|
initialize(): Promise<void>;
|
|
15
|
-
|
|
16
|
-
handleStream(stream: Stream, connection: Connection, reuse?: boolean): Promise<void>;
|
|
16
|
+
handleStream(stream: Stream, connection: Connection): Promise<void>;
|
|
17
17
|
_tool_identify(): Promise<any>;
|
|
18
18
|
_tool_child_register(request: oRequest): Promise<any>;
|
|
19
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;;
|
|
1
|
+
{"version":3,"file":"o-node.tool.d.ts","sourceRoot":"","sources":["../../src/o-node.tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAoB,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AACrD,OAAO,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAQrD,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;;AAEtE;;;;GAIG;AACH,qBAAa,SAAU,SAAQ,cAAkB;IACxC,cAAc,EAAG,mBAAmB,CAAC;IAyBtC,cAAc,CAAC,OAAO,EAAE,QAAQ;IAyBhC,mBAAmB;IAWnB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAK3B,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE,UAAU,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnE,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;IAQ9B,oBAAoB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,GAAG,CAAC;CAiC5D"}
|