@olane/o-core 0.1.0 → 0.1.2
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/core/core.node.d.ts +14 -0
- package/dist/core/core.node.d.ts.map +1 -1
- package/dist/core/core.node.js +45 -20
- package/dist/core/defaults/config.js +0 -1
- package/dist/core/defaults/index.js +0 -1
- package/dist/core/graceful-shutdown.d.ts +25 -0
- package/dist/core/graceful-shutdown.d.ts.map +1 -0
- package/dist/core/graceful-shutdown.js +84 -0
- package/dist/core/index.d.ts +1 -0
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +1 -1
- package/dist/core/interfaces/connection-manager.config.js +0 -1
- package/dist/core/interfaces/connection-send-params.interface.js +0 -1
- package/dist/core/interfaces/core-config.interface.js +0 -1
- package/dist/core/interfaces/index.js +0 -1
- package/dist/core/interfaces/node-type.enum.js +0 -1
- package/dist/core/interfaces/restricted-addresses.enum.js +0 -1
- package/dist/core/interfaces/state.enum.js +0 -1
- package/dist/core/interfaces/use-options.interface.js +0 -1
- package/dist/core/lib/index.js +0 -1
- package/dist/core/lib/o-address-resolution.js +7 -2
- package/dist/core/lib/o-address-resolver.js +2 -4
- package/dist/core/lib/o-connection-manager.d.ts +5 -0
- package/dist/core/lib/o-connection-manager.d.ts.map +1 -1
- package/dist/core/lib/o-connection-manager.js +22 -4
- package/dist/core/lib/o-connection.d.ts.map +1 -1
- package/dist/core/lib/o-connection.js +18 -8
- package/dist/core/lib/o-request.js +0 -5
- package/dist/core/lib/o-response.js +0 -4
- package/dist/core/lib/resolvers/anything.resolver.js +2 -1
- package/dist/core/lib/resolvers/index.js +0 -1
- package/dist/core/lib/resolvers/method.resolver.js +0 -1
- package/dist/core/lib/resolvers/next-hop.resolver.js +4 -1
- package/dist/core/lib/resolvers/storage.resolver.js +0 -1
- package/dist/core/o-address.d.ts +1 -1
- package/dist/core/o-address.d.ts.map +1 -1
- package/dist/core/o-address.js +0 -3
- package/dist/core/o-dependency.js +0 -3
- package/dist/core/o-parameter.d.ts +0 -1
- package/dist/core/o-parameter.d.ts.map +1 -1
- package/dist/core/o-parameter.js +0 -7
- package/dist/core/utils/core.utils.d.ts +1 -1
- package/dist/core/utils/core.utils.d.ts.map +1 -1
- package/dist/core/utils/core.utils.js +4 -2
- package/dist/core/utils/index.js +0 -1
- package/dist/core/utils/logger.js +0 -3
- package/dist/core/utils/network.utils.js +10 -2
- package/dist/error/enums/codes.error.js +0 -1
- package/dist/error/index.js +0 -1
- package/dist/error/tool.error.js +2 -4
- package/dist/index.js +0 -1
- package/dist/node/index.js +0 -1
- package/dist/node/lib/local-search.lib.js +4 -1
- package/dist/node/lib/network-activity.lib.js +0 -3
- package/dist/node/node.d.ts +9 -0
- package/dist/node/node.d.ts.map +1 -1
- package/dist/node/node.js +319 -5
- package/dist/node-host/host.node.d.ts +6 -0
- package/dist/node-host/host.node.d.ts.map +1 -1
- package/dist/node-host/host.node.js +7 -1
- package/dist/node-host/index.js +0 -1
- package/dist/node-virtual/index.js +0 -1
- package/dist/node-virtual/virtual.node.d.ts +5 -0
- package/dist/node-virtual/virtual.node.d.ts.map +1 -1
- package/dist/node-virtual/virtual.node.js +5 -1
- package/dist/plan/agent.plan.d.ts +11 -0
- package/dist/plan/agent.plan.d.ts.map +1 -1
- package/dist/plan/agent.plan.js +25 -3
- package/dist/plan/configure/configure.plan.d.ts +3 -0
- package/dist/plan/configure/configure.plan.d.ts.map +1 -1
- package/dist/plan/configure/configure.plan.js +3 -1
- package/dist/plan/error/error.plan.js +0 -2
- package/dist/plan/index.js +0 -1
- package/dist/plan/interfaces/plan-config.interface.js +0 -1
- package/dist/plan/interfaces/plan-result.interface.js +0 -1
- package/dist/plan/interfaces/plan-type.enum.js +0 -1
- package/dist/plan/interfaces/plan.result.js +0 -1
- package/dist/plan/interfaces/query.config.js +0 -1
- package/dist/plan/interfaces/task.config.js +0 -1
- package/dist/plan/o-plan.d.ts +1 -1
- package/dist/plan/o-plan.d.ts.map +1 -1
- package/dist/plan/o-plan.js +6 -7
- package/dist/plan/plan.context.js +1 -2
- package/dist/plan/prompts/agent.prompt.js +0 -1
- package/dist/plan/prompts/configure.prompt.js +0 -1
- package/dist/plan/prompts/custom.prompt.js +0 -1
- package/dist/plan/prompts/error.prompt.js +0 -1
- package/dist/plan/prompts/search.prompt.js +0 -1
- package/dist/plan/search/prompts/search-analysis.prompt.js +0 -1
- package/dist/plan/search/search.plan.d.ts +6 -0
- package/dist/plan/search/search.plan.d.ts.map +1 -1
- package/dist/plan/search/search.plan.js +13 -3
- package/dist/plan/use/index.js +0 -1
- package/dist/plan/use/use.plan.d.ts +3 -0
- package/dist/plan/use/use.plan.d.ts.map +1 -1
- package/dist/plan/use/use.plan.js +14 -1
- package/package.json +9 -14
- package/dist/core/core.node.js.map +0 -1
- package/dist/core/defaults/config.js.map +0 -1
- package/dist/core/defaults/index.js.map +0 -1
- package/dist/core/index.js.map +0 -1
- package/dist/core/interfaces/connection-manager.config.js.map +0 -1
- package/dist/core/interfaces/connection-send-params.interface.js.map +0 -1
- package/dist/core/interfaces/core-config.interface.js.map +0 -1
- package/dist/core/interfaces/index.js.map +0 -1
- package/dist/core/interfaces/node-type.enum.js.map +0 -1
- package/dist/core/interfaces/restricted-addresses.enum.js.map +0 -1
- package/dist/core/interfaces/state.enum.js.map +0 -1
- package/dist/core/interfaces/use-options.interface.js.map +0 -1
- package/dist/core/lib/index.js.map +0 -1
- package/dist/core/lib/o-address-resolution.js.map +0 -1
- package/dist/core/lib/o-address-resolver.js.map +0 -1
- package/dist/core/lib/o-connection-manager.js.map +0 -1
- package/dist/core/lib/o-connection.js.map +0 -1
- package/dist/core/lib/o-request.js.map +0 -1
- package/dist/core/lib/o-response.js.map +0 -1
- package/dist/core/lib/resolvers/anything.resolver.js.map +0 -1
- package/dist/core/lib/resolvers/index.js.map +0 -1
- package/dist/core/lib/resolvers/method.resolver.js.map +0 -1
- package/dist/core/lib/resolvers/next-hop.resolver.js.map +0 -1
- package/dist/core/lib/resolvers/storage.resolver.js.map +0 -1
- package/dist/core/o-address.js.map +0 -1
- package/dist/core/o-dependency.js.map +0 -1
- package/dist/core/o-parameter.js.map +0 -1
- package/dist/core/utils/core.utils.js.map +0 -1
- package/dist/core/utils/index.js.map +0 -1
- package/dist/core/utils/logger.js.map +0 -1
- package/dist/core/utils/network.utils.js.map +0 -1
- package/dist/error/enums/codes.error.js.map +0 -1
- package/dist/error/index.js.map +0 -1
- package/dist/error/tool.error.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/node/index.js.map +0 -1
- package/dist/node/lib/local-search.lib.js.map +0 -1
- package/dist/node/lib/network-activity.lib.js.map +0 -1
- package/dist/node/node.js.map +0 -1
- package/dist/node-host/host.node.js.map +0 -1
- package/dist/node-host/index.js.map +0 -1
- package/dist/node-virtual/index.js.map +0 -1
- package/dist/node-virtual/virtual.node.js.map +0 -1
- package/dist/plan/agent.plan.js.map +0 -1
- package/dist/plan/configure/configure.plan.js.map +0 -1
- package/dist/plan/error/error.plan.js.map +0 -1
- package/dist/plan/index.js.map +0 -1
- package/dist/plan/interfaces/plan-config.interface.js.map +0 -1
- package/dist/plan/interfaces/plan-result.interface.js.map +0 -1
- package/dist/plan/interfaces/plan-type.enum.js.map +0 -1
- package/dist/plan/interfaces/plan.result.js.map +0 -1
- package/dist/plan/interfaces/query.config.js.map +0 -1
- package/dist/plan/interfaces/task.config.js.map +0 -1
- package/dist/plan/o-plan.js.map +0 -1
- package/dist/plan/plan.context.js.map +0 -1
- package/dist/plan/prompts/agent.prompt.js.map +0 -1
- package/dist/plan/prompts/configure.prompt.js.map +0 -1
- package/dist/plan/prompts/custom.prompt.js.map +0 -1
- package/dist/plan/prompts/error.prompt.js.map +0 -1
- package/dist/plan/prompts/search.prompt.js.map +0 -1
- package/dist/plan/search/prompts/search-analysis.prompt.js.map +0 -1
- package/dist/plan/search/search.plan.js.map +0 -1
- package/dist/plan/use/index.js.map +0 -1
- package/dist/plan/use/use.plan.js.map +0 -1
- package/dist/src/core/core.node.d.ts +0 -62
- package/dist/src/core/core.node.d.ts.map +0 -1
- package/dist/src/core/core.node.js +0 -262
- package/dist/src/core/core.node.js.map +0 -1
- package/dist/src/core/index.d.ts +0 -10
- package/dist/src/core/index.d.ts.map +0 -1
- package/dist/src/core/interfaces/core-config.interface.d.ts +0 -23
- package/dist/src/core/interfaces/core-config.interface.d.ts.map +0 -1
- package/dist/src/core/interfaces/core-config.interface.js +0 -2
- package/dist/src/core/interfaces/core-config.interface.js.map +0 -1
- package/dist/src/core/interfaces/index.d.ts +0 -6
- package/dist/src/core/interfaces/index.d.ts.map +0 -1
- package/dist/src/core/lib/index.d.ts +0 -8
- package/dist/src/core/lib/index.d.ts.map +0 -1
- package/dist/src/core/lib/o-address-resolution.d.ts +0 -9
- package/dist/src/core/lib/o-address-resolution.d.ts.map +0 -1
- package/dist/src/core/lib/o-address-resolver.d.ts +0 -17
- package/dist/src/core/lib/o-address-resolver.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection-manager.d.ts +0 -17
- package/dist/src/core/lib/o-connection-manager.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection.d.ts +0 -28
- package/dist/src/core/lib/o-connection.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection.js +0 -86
- package/dist/src/core/lib/o-connection.js.map +0 -1
- package/dist/src/core/lib/o-request.d.ts +0 -17
- package/dist/src/core/lib/o-request.d.ts.map +0 -1
- package/dist/src/core/lib/o-request.js +0 -31
- package/dist/src/core/lib/o-request.js.map +0 -1
- package/dist/src/core/lib/o-response.d.ts +0 -12
- package/dist/src/core/lib/o-response.d.ts.map +0 -1
- package/dist/src/core/lib/o-response.js +0 -22
- package/dist/src/core/lib/o-response.js.map +0 -1
- package/dist/src/core/lib/resolvers/anything.resolver.d.ts +0 -8
- package/dist/src/core/lib/resolvers/anything.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/index.d.ts +0 -5
- package/dist/src/core/lib/resolvers/index.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/method.resolver.d.ts +0 -8
- package/dist/src/core/lib/resolvers/method.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts +0 -10
- package/dist/src/core/lib/resolvers/next-hop.resolver.d.ts.map +0 -1
- package/dist/src/core/lib/resolvers/storage.resolver.d.ts +0 -6
- package/dist/src/core/lib/resolvers/storage.resolver.d.ts.map +0 -1
- package/dist/src/core/o-address.d.ts +0 -20
- package/dist/src/core/o-address.d.ts.map +0 -1
- package/dist/src/core/o-dependency.d.ts +0 -9
- package/dist/src/core/o-dependency.d.ts.map +0 -1
- package/dist/src/core/o-dependency.js +0 -18
- package/dist/src/core/o-dependency.js.map +0 -1
- package/dist/src/core/o-parameter.d.ts +0 -13
- package/dist/src/core/o-parameter.d.ts.map +0 -1
- package/dist/src/core/o-parameter.js +0 -28
- package/dist/src/core/o-parameter.js.map +0 -1
- package/dist/src/core/utils/core.utils.d.ts +0 -15
- package/dist/src/core/utils/core.utils.d.ts.map +0 -1
- package/dist/src/core/utils/index.d.ts +0 -4
- package/dist/src/core/utils/index.d.ts.map +0 -1
- package/dist/src/core/utils/network.utils.d.ts +0 -10
- package/dist/src/core/utils/network.utils.d.ts.map +0 -1
- package/dist/src/index.d.ts +0 -7
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/node/index.d.ts +0 -4
- package/dist/src/node/index.d.ts.map +0 -1
- package/dist/src/node/lib/local-search.lib.d.ts +0 -6
- package/dist/src/node/lib/local-search.lib.d.ts.map +0 -1
- package/dist/src/node/lib/network-activity.lib.d.ts +0 -12
- package/dist/src/node/lib/network-activity.lib.d.ts.map +0 -1
- package/dist/src/node/node.d.ts +0 -28
- package/dist/src/node/node.d.ts.map +0 -1
- package/dist/src/node-host/host.node.d.ts +0 -6
- package/dist/src/node-host/host.node.d.ts.map +0 -1
- package/dist/src/node-host/index.d.ts +0 -2
- package/dist/src/node-host/index.d.ts.map +0 -1
- package/dist/src/node-virtual/index.d.ts +0 -2
- package/dist/src/node-virtual/index.d.ts.map +0 -1
- package/dist/src/node-virtual/virtual.node.d.ts +0 -5
- package/dist/src/node-virtual/virtual.node.d.ts.map +0 -1
- package/dist/src/plan/agent.plan.d.ts +0 -15
- package/dist/src/plan/agent.plan.d.ts.map +0 -1
- package/dist/src/plan/error/error.plan.d.ts +0 -11
- package/dist/src/plan/error/error.plan.d.ts.map +0 -1
- package/dist/src/plan/index.d.ts +0 -5
- package/dist/src/plan/index.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-config.interface.d.ts +0 -14
- package/dist/src/plan/interfaces/plan-config.interface.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-result.interface.d.ts +0 -6
- package/dist/src/plan/interfaces/plan-result.interface.d.ts.map +0 -1
- package/dist/src/plan/o-plan.d.ts +0 -33
- package/dist/src/plan/o-plan.d.ts.map +0 -1
- package/dist/src/plan/search/search.plan.d.ts +0 -11
- package/dist/src/plan/search/search.plan.d.ts.map +0 -1
- package/dist/src/plan/use/index.d.ts +0 -2
- package/dist/src/plan/use/index.d.ts.map +0 -1
- package/dist/src/plan/use/use.plan.d.ts +0 -10
- package/dist/src/plan/use/use.plan.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
package/dist/core/core.node.d.ts
CHANGED
|
@@ -44,6 +44,13 @@ export declare abstract class oCoreNode {
|
|
|
44
44
|
nextHopAddress: oAddress;
|
|
45
45
|
targetAddress: oAddress;
|
|
46
46
|
}>;
|
|
47
|
+
/**
|
|
48
|
+
* Use a tool explicitly
|
|
49
|
+
* @param addressWithLeaderTransports
|
|
50
|
+
* @param data
|
|
51
|
+
* @param config
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
47
54
|
use(addressWithLeaderTransports: oAddress, data: {
|
|
48
55
|
method?: string;
|
|
49
56
|
params?: {
|
|
@@ -55,7 +62,14 @@ export declare abstract class oCoreNode {
|
|
|
55
62
|
register(): Promise<void>;
|
|
56
63
|
connect(nextHopAddress: oAddress, targetAddress: oAddress): Promise<oConnection>;
|
|
57
64
|
teardown(): Promise<void>;
|
|
65
|
+
/**
|
|
66
|
+
* Start the node
|
|
67
|
+
* @param parent - The parent node
|
|
68
|
+
*/
|
|
58
69
|
start(): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Stop the node
|
|
72
|
+
*/
|
|
59
73
|
stop(): Promise<void>;
|
|
60
74
|
}
|
|
61
75
|
//# sourceMappingURL=core.node.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.node.d.ts","sourceRoot":"","sources":["../../src/core/core.node.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,MAAM,EACN,YAAY,EACZ,SAAS,EAET,MAAM,EACP,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,6BAA6B,CAAC;AACvD,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAC7C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,oCAAoC,CAAC;AAEhE,8BAAsB,SAAS;IAmBjB,QAAQ,CAAC,MAAM,EAAE,UAAU;IAlBhC,OAAO,
|
|
1
|
+
{"version":3,"file":"core.node.d.ts","sourceRoot":"","sources":["../../src/core/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,IAAI,OAAO,CAAC,IAAI,CAAC;CAanC"}
|
package/dist/core/core.node.js
CHANGED
|
@@ -6,25 +6,13 @@ import { NodeType } from './interfaces/node-type.enum';
|
|
|
6
6
|
import { oAddressResolution } from './lib/o-address-resolution';
|
|
7
7
|
import { oDependency } from './o-dependency';
|
|
8
8
|
export class oCoreNode {
|
|
9
|
-
config;
|
|
10
|
-
p2pNode;
|
|
11
|
-
logger;
|
|
12
|
-
networkConfig;
|
|
13
|
-
address;
|
|
14
|
-
staticAddress;
|
|
15
|
-
peerId;
|
|
16
|
-
state = NodeState.STOPPED;
|
|
17
|
-
errors = [];
|
|
18
|
-
connectionManager;
|
|
19
|
-
leaders = [];
|
|
20
|
-
addressResolution;
|
|
21
|
-
description;
|
|
22
|
-
dependencies;
|
|
23
|
-
methods;
|
|
24
|
-
successCount = 0;
|
|
25
|
-
errorCount = 0;
|
|
26
9
|
constructor(config) {
|
|
27
10
|
this.config = config;
|
|
11
|
+
this.state = NodeState.STOPPED;
|
|
12
|
+
this.errors = [];
|
|
13
|
+
this.leaders = [];
|
|
14
|
+
this.successCount = 0;
|
|
15
|
+
this.errorCount = 0;
|
|
28
16
|
this.logger = new Logger(this.constructor.name +
|
|
29
17
|
(config.name ? `:${config.name}` : '') +
|
|
30
18
|
':' +
|
|
@@ -65,12 +53,17 @@ export class oCoreNode {
|
|
|
65
53
|
}
|
|
66
54
|
getTransports(address) {
|
|
67
55
|
let leaderTransports = address.libp2pTransports;
|
|
56
|
+
// check if we already know where we want to go
|
|
68
57
|
if (leaderTransports.length > 0) {
|
|
69
58
|
return leaderTransports;
|
|
70
59
|
}
|
|
60
|
+
// if leader transports are not provided, then we need to search for them
|
|
61
|
+
// Assume we are looking for a leader within our network for now
|
|
62
|
+
// TODO: we need to add some discovery managers that every node can use to find external network resources
|
|
71
63
|
if (leaderTransports.length === 0) {
|
|
72
64
|
this.logger.debug('No leader transports provided, we are going to search within our own network');
|
|
73
65
|
if (!this.config.leader) {
|
|
66
|
+
// TODO: how do we handle when the node is the leader? // technically we are in the network
|
|
74
67
|
if (this.type === NodeType.LEADER) {
|
|
75
68
|
this.logger.debug('Node is a leader, using own transports');
|
|
76
69
|
leaderTransports = this.transports.map((t) => multiaddr(t));
|
|
@@ -90,7 +83,9 @@ export class oCoreNode {
|
|
|
90
83
|
}
|
|
91
84
|
async handleStaticAddressTranslation(addressInput) {
|
|
92
85
|
let result = addressInput;
|
|
86
|
+
// handle static address translation
|
|
93
87
|
if (result.value.indexOf('o://leader') === -1) {
|
|
88
|
+
// TODO: we need to be more dynamic around the o://leader prefix
|
|
94
89
|
const response = await this.use(new oAddress('o://leader/register', result.transports), {
|
|
95
90
|
method: 'search',
|
|
96
91
|
params: { staticAddress: result.root },
|
|
@@ -99,13 +94,15 @@ export class oCoreNode {
|
|
|
99
94
|
});
|
|
100
95
|
const searchResults = response.result.data;
|
|
101
96
|
if (searchResults.length > 0) {
|
|
97
|
+
// the root was found, let's add the rest of the path to the address
|
|
102
98
|
const remainderPaths = result.paths.split('/').slice(1);
|
|
103
|
-
|
|
104
|
-
(remainderPaths.length > 0 ? '/' + remainderPaths.join('/') : '');
|
|
99
|
+
const resolvedAddress = searchResults[0].address +
|
|
100
|
+
(remainderPaths.length > 0 ? '/' + remainderPaths.join('/') : ''); // TODO: we need to handle this better
|
|
105
101
|
result = new oAddress(resolvedAddress, result.transports);
|
|
106
102
|
}
|
|
107
103
|
else {
|
|
108
104
|
this.logger.warn('Failed to translate static address');
|
|
105
|
+
// TODO: we need to handle this better
|
|
109
106
|
}
|
|
110
107
|
}
|
|
111
108
|
return result;
|
|
@@ -113,6 +110,7 @@ export class oCoreNode {
|
|
|
113
110
|
async translateAddress(addressWithLeaderTransports) {
|
|
114
111
|
let targetAddress = addressWithLeaderTransports;
|
|
115
112
|
let nextHopAddress = addressWithLeaderTransports;
|
|
113
|
+
// handle static address translation for search based upon base functionality
|
|
116
114
|
targetAddress = await this.handleStaticAddressTranslation(targetAddress);
|
|
117
115
|
nextHopAddress = await this.addressResolution.resolve(targetAddress);
|
|
118
116
|
const leaderTransports = this.getTransports(nextHopAddress);
|
|
@@ -122,10 +120,18 @@ export class oCoreNode {
|
|
|
122
120
|
targetAddress: targetAddress,
|
|
123
121
|
};
|
|
124
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Use a tool explicitly
|
|
125
|
+
* @param addressWithLeaderTransports
|
|
126
|
+
* @param data
|
|
127
|
+
* @param config
|
|
128
|
+
* @returns
|
|
129
|
+
*/
|
|
125
130
|
async use(addressWithLeaderTransports, data, config = {}) {
|
|
126
131
|
const { nextHopAddress, targetAddress } = await this.translateAddress(addressWithLeaderTransports);
|
|
127
132
|
this.logger.debug('Using address: ', targetAddress.toString());
|
|
128
133
|
const connection = await this.connect(nextHopAddress, targetAddress);
|
|
134
|
+
// communicate the payload to the target node
|
|
129
135
|
const response = await connection.send({
|
|
130
136
|
address: targetAddress?.toString() || '',
|
|
131
137
|
payload: data,
|
|
@@ -134,9 +140,11 @@ export class oCoreNode {
|
|
|
134
140
|
}
|
|
135
141
|
async advertiseToNetwork() {
|
|
136
142
|
this.logger.debug('Advertising to network our static and absolute addresses...');
|
|
143
|
+
// advertise the absolute address to the network with timeout
|
|
137
144
|
const absoluteAddressCid = await this.address.toCID();
|
|
138
145
|
this.logger.debug('Advertising absolute address: ', absoluteAddressCid);
|
|
139
146
|
try {
|
|
147
|
+
// Add timeout to prevent hanging
|
|
140
148
|
const providePromise = this.p2pNode.services.dht.provide(absoluteAddressCid);
|
|
141
149
|
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Advertise Content routing provide timeout')), 5000));
|
|
142
150
|
await Promise.race([providePromise, timeoutPromise]);
|
|
@@ -145,9 +153,11 @@ export class oCoreNode {
|
|
|
145
153
|
catch (error) {
|
|
146
154
|
this.logger.warn('Failed to advertise absolute address (this is normal for isolated nodes):', error.message);
|
|
147
155
|
}
|
|
156
|
+
// advertise the static address to the network with timeout
|
|
148
157
|
const staticAddressCid = await this.staticAddress.toCID();
|
|
149
158
|
this.logger.debug('Advertising static address: ', staticAddressCid);
|
|
150
159
|
try {
|
|
160
|
+
// Add timeout to prevent hanging
|
|
151
161
|
const providePromise = this.p2pNode.services.dht.provide(staticAddressCid);
|
|
152
162
|
const timeoutPromise = new Promise((_, reject) => setTimeout(() => reject(new Error('Content routing provide timeout')), 5000));
|
|
153
163
|
await Promise.race([providePromise, timeoutPromise]);
|
|
@@ -158,9 +168,14 @@ export class oCoreNode {
|
|
|
158
168
|
}
|
|
159
169
|
}
|
|
160
170
|
async connectToParent() {
|
|
171
|
+
// ensure we have modified the address to be a child address if the parent address is provided
|
|
161
172
|
if (this.parent) {
|
|
162
173
|
this.logger.debug('Connecting to parent: ' + this.parent.toString());
|
|
163
174
|
await this.connect(this.parent, this.parent);
|
|
175
|
+
// this.address = CoreUtils.childAddress(this.parentAddress, this.address);
|
|
176
|
+
// await new Promise((resolve) => setTimeout(resolve, 1_000));
|
|
177
|
+
// this.logger.debug('Modified address to: ' + this.address.toString());
|
|
178
|
+
// TODO: let's ask the parent to route us to the leader
|
|
164
179
|
this.logger.debug('Successfully connected to parent');
|
|
165
180
|
}
|
|
166
181
|
else {
|
|
@@ -173,7 +188,9 @@ export class oCoreNode {
|
|
|
173
188
|
return;
|
|
174
189
|
}
|
|
175
190
|
this.logger.debug('Registering node...');
|
|
191
|
+
// connect to the parent node to establish identity
|
|
176
192
|
await this.connectToParent();
|
|
193
|
+
// register with the leader global registry
|
|
177
194
|
if (!this.config.leader) {
|
|
178
195
|
this.logger.warn('No leaders found, skipping registration');
|
|
179
196
|
return;
|
|
@@ -192,6 +209,7 @@ export class oCoreNode {
|
|
|
192
209
|
await this.use(address, params, {
|
|
193
210
|
noIndex: true,
|
|
194
211
|
});
|
|
212
|
+
// TODO: handle the response from the leader
|
|
195
213
|
}
|
|
196
214
|
async connect(nextHopAddress, targetAddress) {
|
|
197
215
|
if (!this.connectionManager) {
|
|
@@ -205,6 +223,7 @@ export class oCoreNode {
|
|
|
205
223
|
callerAddress: this.address,
|
|
206
224
|
})
|
|
207
225
|
.catch((error) => {
|
|
226
|
+
// TODO: we need to handle this better and document
|
|
208
227
|
if (error.message === 'Can not dial self') {
|
|
209
228
|
this.logger.error('Make sure you are entering the network not directly through the leader node.');
|
|
210
229
|
}
|
|
@@ -222,6 +241,10 @@ export class oCoreNode {
|
|
|
222
241
|
await this.p2pNode.stop();
|
|
223
242
|
}
|
|
224
243
|
}
|
|
244
|
+
/**
|
|
245
|
+
* Start the node
|
|
246
|
+
* @param parent - The parent node
|
|
247
|
+
*/
|
|
225
248
|
async start() {
|
|
226
249
|
if (this.state !== NodeState.STOPPED) {
|
|
227
250
|
this.logger.warn('Node is not stopped, skipping start');
|
|
@@ -244,6 +267,9 @@ export class oCoreNode {
|
|
|
244
267
|
await this.teardown();
|
|
245
268
|
}
|
|
246
269
|
}
|
|
270
|
+
/**
|
|
271
|
+
* Stop the node
|
|
272
|
+
*/
|
|
247
273
|
async stop() {
|
|
248
274
|
this.logger.debug('Stop node called...');
|
|
249
275
|
this.state = NodeState.STOPPING;
|
|
@@ -259,4 +285,3 @@ export class oCoreNode {
|
|
|
259
285
|
}
|
|
260
286
|
}
|
|
261
287
|
}
|
|
262
|
-
//# sourceMappingURL=core.node.js.map
|
|
@@ -3,4 +3,3 @@ import os from 'os';
|
|
|
3
3
|
export const DEFAULT_CONFIG_PATH = path.join(os.homedir(), '.olane');
|
|
4
4
|
export const DEFAULT_NETWORKS_PATH = path.join(DEFAULT_CONFIG_PATH, 'networks');
|
|
5
5
|
export const DEFAULT_CONFIG_FILE = path.join(DEFAULT_CONFIG_PATH, 'config.json');
|
|
6
|
-
//# sourceMappingURL=config.js.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Logger } from './utils';
|
|
2
|
+
export interface CleanupFunction {
|
|
3
|
+
(): Promise<void> | void;
|
|
4
|
+
}
|
|
5
|
+
export interface GracefulShutdownOptions {
|
|
6
|
+
timeout?: number;
|
|
7
|
+
logger?: Logger;
|
|
8
|
+
onTimeout?: () => void;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Sets up signal handlers for graceful shutdown
|
|
12
|
+
* @param cleanup Cleanup function to run on shutdown
|
|
13
|
+
* @param options Configuration options for graceful shutdown
|
|
14
|
+
*/
|
|
15
|
+
export declare function setupGracefulShutdown(cleanup: CleanupFunction, options?: GracefulShutdownOptions): void;
|
|
16
|
+
/**
|
|
17
|
+
* Creates a cleanup function that stops multiple resources
|
|
18
|
+
* @param resources Array of resources with stop methods
|
|
19
|
+
* @param logger Logger instance for logging
|
|
20
|
+
*/
|
|
21
|
+
export declare function createMultiResourceCleanup(resources: Array<{
|
|
22
|
+
stop(): Promise<void> | void;
|
|
23
|
+
address?: string;
|
|
24
|
+
}>, logger?: Logger): CleanupFunction;
|
|
25
|
+
//# sourceMappingURL=graceful-shutdown.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graceful-shutdown.d.ts","sourceRoot":"","sources":["../../src/core/graceful-shutdown.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAEjC,MAAM,WAAW,eAAe;IAC9B,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;CAC1B;AAED,MAAM,WAAW,uBAAuB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC;CACxB;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,eAAe,EACxB,OAAO,GAAE,uBAA4B,GACpC,IAAI,CAmEN;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CACxC,SAAS,EAAE,KAAK,CAAC;IAAE,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,EACpE,MAAM,GAAE,MAA2C,GAClD,eAAe,CAmBjB"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { Logger } from './utils';
|
|
2
|
+
/**
|
|
3
|
+
* Sets up signal handlers for graceful shutdown
|
|
4
|
+
* @param cleanup Cleanup function to run on shutdown
|
|
5
|
+
* @param options Configuration options for graceful shutdown
|
|
6
|
+
*/
|
|
7
|
+
export function setupGracefulShutdown(cleanup, options = {}) {
|
|
8
|
+
const { timeout = 30000, // 30 seconds default timeout
|
|
9
|
+
logger = new Logger('GracefulShutdown'), onTimeout, } = options;
|
|
10
|
+
let isShuttingDown = false;
|
|
11
|
+
const performCleanup = async (signal) => {
|
|
12
|
+
if (isShuttingDown) {
|
|
13
|
+
logger.debug('Shutdown already in progress, skipping...');
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
isShuttingDown = true;
|
|
17
|
+
logger.info(`Received ${signal}, initiating graceful shutdown...`);
|
|
18
|
+
try {
|
|
19
|
+
// Set up timeout for cleanup operations
|
|
20
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
21
|
+
setTimeout(() => {
|
|
22
|
+
reject(new Error(`Cleanup timeout after ${timeout}ms`));
|
|
23
|
+
}, timeout);
|
|
24
|
+
});
|
|
25
|
+
// Perform cleanup with timeout
|
|
26
|
+
await Promise.race([Promise.resolve(cleanup()), timeoutPromise]);
|
|
27
|
+
logger.info('Graceful shutdown completed successfully');
|
|
28
|
+
}
|
|
29
|
+
catch (error) {
|
|
30
|
+
logger.error('Error during graceful shutdown:', error);
|
|
31
|
+
if (onTimeout) {
|
|
32
|
+
onTimeout();
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
logger.info('Process exiting');
|
|
37
|
+
process.exit(0);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
// Handle SIGINT (Ctrl+C)
|
|
41
|
+
process.on('SIGINT', () => performCleanup('SIGINT'));
|
|
42
|
+
// Handle SIGTERM (termination signal)
|
|
43
|
+
process.on('SIGTERM', () => performCleanup('SIGTERM'));
|
|
44
|
+
// Handle SIGUSR2 (Node.js restart signal)
|
|
45
|
+
process.on('SIGUSR2', () => performCleanup('SIGUSR2'));
|
|
46
|
+
// Handle uncaught exceptions
|
|
47
|
+
process.on('uncaughtException', (error) => {
|
|
48
|
+
logger.error('Uncaught Exception:', error);
|
|
49
|
+
performCleanup('uncaughtException');
|
|
50
|
+
});
|
|
51
|
+
// Handle unhandled promise rejections
|
|
52
|
+
process.on('unhandledRejection', (reason, promise) => {
|
|
53
|
+
logger.error('Unhandled Rejection at:', promise, 'reason:', reason);
|
|
54
|
+
performCleanup('unhandledRejection');
|
|
55
|
+
});
|
|
56
|
+
// Handle process exit (synchronous cleanup)
|
|
57
|
+
process.on('exit', (code) => {
|
|
58
|
+
logger.info(`Process exiting with code: ${code}`);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Creates a cleanup function that stops multiple resources
|
|
63
|
+
* @param resources Array of resources with stop methods
|
|
64
|
+
* @param logger Logger instance for logging
|
|
65
|
+
*/
|
|
66
|
+
export function createMultiResourceCleanup(resources, logger = new Logger('MultiResourceCleanup')) {
|
|
67
|
+
return async () => {
|
|
68
|
+
logger.info(`Stopping ${resources.length} resources...`);
|
|
69
|
+
const stopPromises = resources.map(async (resource) => {
|
|
70
|
+
try {
|
|
71
|
+
const resourceName = resource.address || resource.constructor.name;
|
|
72
|
+
logger.debug(`Stopping resource: ${resourceName}`);
|
|
73
|
+
await Promise.resolve(resource.stop());
|
|
74
|
+
logger.debug(`Successfully stopped resource: ${resourceName}`);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
const resourceName = resource.address || resource.constructor.name;
|
|
78
|
+
logger.error(`Error stopping resource ${resourceName}:`, error);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
await Promise.allSettled(stopPromises);
|
|
82
|
+
logger.info('All resources stopped');
|
|
83
|
+
};
|
|
84
|
+
}
|
package/dist/core/index.d.ts
CHANGED
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC;AACnC,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,OAAO,CAAC;AACtB,cAAc,eAAe,CAAC;AAC9B,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC"}
|
package/dist/core/index.js
CHANGED
package/dist/core/lib/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { oAddress } from '../o-address';
|
|
2
2
|
export class oAddressResolution {
|
|
3
|
-
|
|
3
|
+
constructor() {
|
|
4
|
+
this.resolvers = [];
|
|
5
|
+
}
|
|
4
6
|
addResolver(resolver) {
|
|
5
7
|
this.resolvers.push(resolver);
|
|
6
8
|
}
|
|
@@ -14,7 +16,10 @@ export class oAddressResolution {
|
|
|
14
16
|
for (const resolver of this.resolvers) {
|
|
15
17
|
resolvedAddress = await resolver.resolve(resolvedAddress);
|
|
16
18
|
}
|
|
19
|
+
// // ensure we have the transports from the original address
|
|
20
|
+
// if (address.transports.length > 0) {
|
|
21
|
+
// resolvedAddress.setTransports(address.transports as Multiaddr[]);
|
|
22
|
+
// }
|
|
17
23
|
return resolvedAddress;
|
|
18
24
|
}
|
|
19
25
|
}
|
|
20
|
-
//# sourceMappingURL=o-address-resolution.js.map
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Logger } from '../';
|
|
2
2
|
import { oAddress } from '../o-address';
|
|
3
3
|
export class oAddressResolver {
|
|
4
|
-
address;
|
|
5
|
-
p2pNode;
|
|
6
|
-
logger;
|
|
7
4
|
constructor(address, p2pNode) {
|
|
8
5
|
this.address = address;
|
|
9
6
|
this.p2pNode = p2pNode;
|
|
@@ -22,8 +19,10 @@ export class oAddressResolver {
|
|
|
22
19
|
return targetAddress.toString()?.includes('o://leader') === false;
|
|
23
20
|
}
|
|
24
21
|
determineNextHopAddress(targetAddress) {
|
|
22
|
+
// do we have to start at the root leader or continue forward?
|
|
25
23
|
const startAtLeader = targetAddress.protocol?.includes(this.address.protocol) === false;
|
|
26
24
|
const prefix = startAtLeader ? 'o://' : this.address.value + '/';
|
|
25
|
+
// determine the next hop
|
|
27
26
|
const remainingPath = startAtLeader
|
|
28
27
|
? targetAddress.protocol
|
|
29
28
|
: targetAddress.protocol.replace(this.address.protocol + '/', '');
|
|
@@ -35,4 +34,3 @@ export class oAddressResolver {
|
|
|
35
34
|
return address;
|
|
36
35
|
}
|
|
37
36
|
}
|
|
38
|
-
//# sourceMappingURL=o-address-resolver.js.map
|
|
@@ -6,6 +6,11 @@ export declare class oConnectionManager {
|
|
|
6
6
|
private logger;
|
|
7
7
|
private p2pNode;
|
|
8
8
|
constructor(config: oConnectionManagerConfig);
|
|
9
|
+
/**
|
|
10
|
+
* Connect to a given address
|
|
11
|
+
* @param address - The address to connect to
|
|
12
|
+
* @returns The connection object
|
|
13
|
+
*/
|
|
9
14
|
connect(config: {
|
|
10
15
|
address: oAddress;
|
|
11
16
|
nextHopAddress: oAddress;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-connection-manager.d.ts","sourceRoot":"","sources":["../../../src/core/lib/o-connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAGnF,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,wBAAwB;
|
|
1
|
+
{"version":3,"file":"o-connection-manager.d.ts","sourceRoot":"","sources":["../../../src/core/lib/o-connection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AAGnF,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,OAAO,CAAS;gBAEZ,MAAM,EAAE,wBAAwB;IAK5C;;;;OAIG;IACG,OAAO,CAAC,MAAM,EAAE;QACpB,OAAO,EAAE,QAAQ,CAAC;QAClB,cAAc,EAAE,QAAQ,CAAC;QACzB,aAAa,CAAC,EAAE,QAAQ,CAAC;KAC1B,GAAG,OAAO,CAAC,WAAW,CAAC;IAqCxB,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAIpC,mBAAmB,CAAC,OAAO,EAAE,QAAQ,GAAG,WAAW,GAAG,IAAI;CAe3D"}
|
|
@@ -1,14 +1,32 @@
|
|
|
1
1
|
import { oConnection } from './o-connection';
|
|
2
2
|
export class oConnectionManager {
|
|
3
|
-
cache = new Map();
|
|
4
|
-
logger;
|
|
5
|
-
p2pNode;
|
|
6
3
|
constructor(config) {
|
|
4
|
+
this.cache = new Map();
|
|
7
5
|
this.logger = config.logger;
|
|
8
6
|
this.p2pNode = config.p2pNode;
|
|
9
7
|
}
|
|
8
|
+
/**
|
|
9
|
+
* Connect to a given address
|
|
10
|
+
* @param address - The address to connect to
|
|
11
|
+
* @returns The connection object
|
|
12
|
+
*/
|
|
10
13
|
async connect(config) {
|
|
11
14
|
const { address, nextHopAddress, callerAddress } = config;
|
|
15
|
+
// check if we already have a connection to this address
|
|
16
|
+
// TODO: how can we enable caching of connections & connection lifecycles
|
|
17
|
+
// if (this.isCached(nextHopAddress)) {
|
|
18
|
+
// const cachedConnection = this.getCachedConnection(nextHopAddress);
|
|
19
|
+
// if (cachedConnection) {
|
|
20
|
+
// this.logger.debug(
|
|
21
|
+
// 'Using cached connection for address: ' + address.toString(),
|
|
22
|
+
// );
|
|
23
|
+
// return cachedConnection;
|
|
24
|
+
// } else {
|
|
25
|
+
// // cached item is not valid, remove it
|
|
26
|
+
// this.cache.delete(nextHopAddress.toString());
|
|
27
|
+
// }
|
|
28
|
+
// }
|
|
29
|
+
// first time setup connection
|
|
12
30
|
try {
|
|
13
31
|
const p2pConnection = await this.p2pNode.dial(nextHopAddress.libp2pTransports);
|
|
14
32
|
const connection = new oConnection({
|
|
@@ -17,6 +35,7 @@ export class oConnectionManager {
|
|
|
17
35
|
p2pConnection: p2pConnection,
|
|
18
36
|
callerAddress: callerAddress,
|
|
19
37
|
});
|
|
38
|
+
// this.cache.set(address.toString(), connection);
|
|
20
39
|
return connection;
|
|
21
40
|
}
|
|
22
41
|
catch (error) {
|
|
@@ -44,4 +63,3 @@ export class oConnectionManager {
|
|
|
44
63
|
return null;
|
|
45
64
|
}
|
|
46
65
|
}
|
|
47
|
-
//# sourceMappingURL=o-connection-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-connection.d.ts","sourceRoot":"","sources":["../../../src/core/lib/o-connection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAiC,MAAM,iBAAiB,CAAC;AA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AQ,CAAC,OAAO,CAAW;IACnC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAW;IAC1C,OAAO,CAAC,cAAc,CAAa;gBAGhB,MAAM,EAAE;QACvB,cAAc,EAAE,QAAQ,CAAC;QACzB,aAAa,CAAC,EAAE,QAAQ,CAAC;QACzB,OAAO,EAAE,QAAQ,CAAC;QAClB,aAAa,EAAE,UAAU,CAAC;KAC3B;IAgBG,IAAI,CAAC,MAAM,EAAE,GAAG;IAUtB,QAAQ;IAOR,aAAa,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,oBAAoB,GAAG,QAAQ;IAyB/D,QAAQ,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,SAAS,CAAC;IAqB/C,IAAI,CAAC,IAAI,EAAE,oBAAoB,GAAG,OAAO,CAAC,SAAS,CAAC;IAMpD,KAAK;CAKZ"}
|
|
@@ -5,15 +5,9 @@ import { oRequest } from './o-request';
|
|
|
5
5
|
import { oProtocolMethods } from '@olane/o-protocol';
|
|
6
6
|
import { oResponse } from './o-response';
|
|
7
7
|
export class oConnection {
|
|
8
|
-
config;
|
|
9
|
-
id;
|
|
10
|
-
logger;
|
|
11
|
-
p2pConnection;
|
|
12
|
-
address;
|
|
13
|
-
nextHopAddress;
|
|
14
|
-
requestCounter = 0;
|
|
15
8
|
constructor(config) {
|
|
16
9
|
this.config = config;
|
|
10
|
+
this.requestCounter = 0;
|
|
17
11
|
this.id = uuidv4();
|
|
18
12
|
this.address = config.address;
|
|
19
13
|
this.nextHopAddress = config.nextHopAddress;
|
|
@@ -37,6 +31,7 @@ export class oConnection {
|
|
|
37
31
|
if (this.config.p2pConnection.status !== 'open') {
|
|
38
32
|
throw new Error('Connection is not valid');
|
|
39
33
|
}
|
|
34
|
+
// do nothing
|
|
40
35
|
}
|
|
41
36
|
createRequest(method, params) {
|
|
42
37
|
return new oRequest({
|
|
@@ -49,19 +44,35 @@ export class oConnection {
|
|
|
49
44
|
id: this.requestCounter++,
|
|
50
45
|
});
|
|
51
46
|
}
|
|
47
|
+
// async start() {
|
|
48
|
+
// this.logger.debug('Starting handshake, address: ' + this.address.value);
|
|
49
|
+
// const params = this.createRequest(oProtocolMethods.ROUTE, {
|
|
50
|
+
// address: this.address.value,
|
|
51
|
+
// payload: {
|
|
52
|
+
// method: oProtocolMethods.HANDSHAKE,
|
|
53
|
+
// params: {},
|
|
54
|
+
// },
|
|
55
|
+
// });
|
|
56
|
+
// const request = new oRequest(params);
|
|
57
|
+
// return this.transmit(request);
|
|
58
|
+
// }
|
|
52
59
|
async transmit(request) {
|
|
53
60
|
const stream = await this.p2pConnection.newStream(this.nextHopAddress.protocol);
|
|
61
|
+
// Create a pushable stream
|
|
54
62
|
const pushableStream = pushable();
|
|
55
63
|
pushableStream.push(new TextEncoder().encode(request.toString()));
|
|
56
64
|
pushableStream.end();
|
|
65
|
+
// Send the data
|
|
57
66
|
await stream.sink(pushableStream);
|
|
58
67
|
const res = await this.read(stream.source);
|
|
68
|
+
// process the response
|
|
59
69
|
const response = new oResponse({
|
|
60
70
|
...res.result,
|
|
61
71
|
});
|
|
62
72
|
return response;
|
|
63
73
|
}
|
|
64
74
|
async send(data) {
|
|
75
|
+
// proxy through the router tool
|
|
65
76
|
const request = this.createRequest(oProtocolMethods.ROUTE, data);
|
|
66
77
|
return this.transmit(request);
|
|
67
78
|
}
|
|
@@ -71,4 +82,3 @@ export class oConnection {
|
|
|
71
82
|
this.logger.debug('Connection closed');
|
|
72
83
|
}
|
|
73
84
|
}
|
|
74
|
-
//# sourceMappingURL=o-connection.js.map
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { JSONRPC_VERSION, } from '@olane/o-protocol';
|
|
2
2
|
export class oRequest {
|
|
3
|
-
jsonrpc;
|
|
4
|
-
method;
|
|
5
|
-
params;
|
|
6
|
-
id;
|
|
7
3
|
constructor(config) {
|
|
8
4
|
this.jsonrpc = JSONRPC_VERSION;
|
|
9
5
|
this.method = config.method;
|
|
@@ -28,4 +24,3 @@ export class oRequest {
|
|
|
28
24
|
return new oRequest(json);
|
|
29
25
|
}
|
|
30
26
|
}
|
|
31
|
-
//# sourceMappingURL=o-request.js.map
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import { JSONRPC_VERSION, } from '@olane/o-protocol';
|
|
2
2
|
export class oResponse {
|
|
3
|
-
jsonrpc;
|
|
4
|
-
id;
|
|
5
|
-
result;
|
|
6
3
|
constructor(config) {
|
|
7
4
|
this.jsonrpc = JSONRPC_VERSION;
|
|
8
5
|
this.id = config.id;
|
|
@@ -19,4 +16,3 @@ export class oResponse {
|
|
|
19
16
|
return JSON.stringify(this);
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
//# sourceMappingURL=o-response.js.map
|
|
@@ -6,8 +6,9 @@ export class oAnythingResolver extends oAddressResolver {
|
|
|
6
6
|
}
|
|
7
7
|
async resolve(address, node) {
|
|
8
8
|
const nextHopAddress = this.determineNextHopAddress(address);
|
|
9
|
+
// at this point, the next-hop resolver did not work so we can trust that the
|
|
10
|
+
// next hop should be contained within the current node as an abstraction
|
|
9
11
|
this.logger.debug('Resolving anything address: ', address);
|
|
10
12
|
return new oAddress(nextHopAddress.toString(), (address.transports || []).concat(this.transports));
|
|
11
13
|
}
|
|
12
14
|
}
|
|
13
|
-
//# sourceMappingURL=anything.resolver.js.map
|