@olane/o-core 0.6.13 → 0.7.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/README.md +490 -140
- package/dist/src/connection/index.d.ts +8 -0
- package/dist/src/connection/index.d.ts.map +1 -0
- package/dist/src/connection/index.js +7 -0
- package/dist/src/connection/interfaces/connection-manager.config.d.ts +3 -0
- package/dist/src/connection/interfaces/connection-manager.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/connection-send-params.interface.d.ts.map +1 -0
- package/dist/src/connection/interfaces/connection.config.d.ts +7 -0
- package/dist/src/connection/interfaces/connection.config.d.ts.map +1 -0
- package/dist/src/connection/interfaces/index.d.ts +5 -0
- package/dist/src/connection/interfaces/index.d.ts.map +1 -0
- package/dist/src/connection/interfaces/index.js +4 -0
- package/dist/src/connection/interfaces/request-state.enum.d.ts +7 -0
- package/dist/src/connection/interfaces/request-state.enum.d.ts.map +1 -0
- package/dist/src/connection/interfaces/request-state.enum.js +7 -0
- package/dist/src/connection/o-connection-manager.d.ts +19 -0
- package/dist/src/connection/o-connection-manager.d.ts.map +1 -0
- package/dist/src/connection/o-connection-manager.js +27 -0
- package/dist/src/connection/o-connection.d.ts +20 -0
- package/dist/src/connection/o-connection.d.ts.map +1 -0
- package/dist/src/connection/o-connection.js +45 -0
- package/dist/src/{core/lib → connection}/o-request.d.ts +5 -1
- package/dist/src/connection/o-request.d.ts.map +1 -0
- package/dist/src/{core/lib → connection}/o-request.js +8 -1
- package/dist/src/connection/o-response.d.ts.map +1 -0
- package/dist/src/core/defaults/config.d.ts +1 -1
- package/dist/src/core/defaults/config.d.ts.map +1 -1
- package/dist/src/core/defaults/config.js +1 -1
- package/dist/src/core/graceful-shutdown.d.ts +1 -1
- package/dist/src/core/graceful-shutdown.d.ts.map +1 -1
- package/dist/src/core/graceful-shutdown.js +1 -1
- package/dist/src/core/index.d.ts +3 -5
- package/dist/src/core/index.d.ts.map +1 -1
- package/dist/src/core/index.js +3 -5
- package/dist/src/core/interfaces/index.d.ts +1 -2
- package/dist/src/core/interfaces/index.d.ts.map +1 -1
- package/dist/src/core/interfaces/index.js +1 -2
- package/dist/src/core/interfaces/{core-config.interface.d.ts → o-core.config.d.ts} +4 -5
- package/dist/src/core/interfaces/o-core.config.d.ts.map +1 -0
- package/dist/src/core/interfaces/o-core.interface.d.ts +18 -0
- package/dist/src/core/interfaces/o-core.interface.d.ts.map +1 -0
- package/dist/src/core/lib/index.d.ts +3 -7
- package/dist/src/core/lib/index.d.ts.map +1 -1
- package/dist/src/core/lib/index.js +3 -7
- package/dist/src/core/lib/o-hierarchy.manager.d.ts +24 -0
- package/dist/src/core/lib/o-hierarchy.manager.d.ts.map +1 -0
- package/dist/src/core/lib/o-hierarchy.manager.js +57 -0
- package/dist/src/core/lib/o-metrics.d.ts +5 -0
- package/dist/src/core/lib/o-metrics.d.ts.map +1 -0
- package/dist/src/core/lib/o-metrics.js +6 -0
- package/dist/src/core/lib/o-request.manager.d.ts +10 -0
- package/dist/src/core/lib/o-request.manager.d.ts.map +1 -0
- package/dist/src/core/lib/o-request.manager.js +18 -0
- package/dist/src/core/o-core.d.ts +190 -0
- package/dist/src/core/o-core.d.ts.map +1 -0
- package/dist/src/core/o-core.js +334 -0
- package/dist/src/core/o-object.d.ts +7 -0
- package/dist/src/core/o-object.d.ts.map +1 -0
- package/dist/src/core/o-object.js +10 -0
- package/dist/src/error/enums/codes.error.d.ts +16 -14
- package/dist/src/error/enums/codes.error.d.ts.map +1 -1
- package/dist/src/error/enums/codes.error.js +18 -16
- package/dist/src/error/index.d.ts +1 -1
- package/dist/src/error/index.d.ts.map +1 -1
- package/dist/src/error/index.js +1 -1
- package/dist/src/error/interfaces/o-error.interface.d.ts +6 -0
- package/dist/src/error/interfaces/o-error.interface.d.ts.map +1 -0
- package/dist/src/error/o-error.d.ts +15 -0
- package/dist/src/error/o-error.d.ts.map +1 -0
- package/dist/src/error/{tool.error.js → o-error.js} +4 -4
- package/dist/src/index.d.ts +3 -3
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +3 -3
- package/dist/src/router/enums/restricted-addresses.enum.d.ts +8 -0
- package/dist/src/router/enums/restricted-addresses.enum.d.ts.map +1 -0
- package/dist/src/router/enums/restricted-addresses.enum.js +13 -0
- package/dist/src/router/index.d.ts +9 -0
- package/dist/src/router/index.d.ts.map +1 -0
- package/dist/src/router/index.js +8 -0
- package/dist/src/router/interfaces/resolve.request.d.ts +10 -0
- package/dist/src/router/interfaces/resolve.request.d.ts.map +1 -0
- package/dist/src/router/interfaces/route.response.d.ts +8 -0
- package/dist/src/router/interfaces/route.response.d.ts.map +1 -0
- package/dist/src/router/o-address-resolution.d.ts +12 -0
- package/dist/src/router/o-address-resolution.d.ts.map +1 -0
- package/dist/src/router/o-address-resolution.js +42 -0
- package/dist/src/router/o-address-resolver.d.ts +14 -0
- package/dist/src/router/o-address-resolver.d.ts.map +1 -0
- package/dist/src/router/o-address-resolver.js +19 -0
- package/dist/src/router/o-address.d.ts +33 -0
- package/dist/src/router/o-address.d.ts.map +1 -0
- package/dist/src/router/o-address.js +101 -0
- package/dist/src/router/o-request.router.d.ts +18 -0
- package/dist/src/router/o-request.router.d.ts.map +1 -0
- package/dist/src/router/o-request.router.js +12 -0
- package/dist/src/router/o-router.d.ts +19 -0
- package/dist/src/router/o-router.d.ts.map +1 -0
- package/dist/src/router/o-router.js +14 -0
- package/dist/src/transports/custom.transport.d.ts +6 -0
- package/dist/src/transports/custom.transport.d.ts.map +1 -0
- package/dist/src/transports/custom.transport.js +10 -0
- package/dist/src/transports/index.d.ts +4 -0
- package/dist/src/transports/index.d.ts.map +1 -0
- package/dist/src/transports/index.js +3 -0
- package/dist/src/transports/interfaces/transport-type.enum.d.ts +5 -0
- package/dist/src/transports/interfaces/transport-type.enum.d.ts.map +1 -0
- package/dist/src/transports/interfaces/transport-type.enum.js +5 -0
- package/dist/src/transports/o-transport.d.ts +10 -0
- package/dist/src/transports/o-transport.d.ts.map +1 -0
- package/dist/src/transports/o-transport.js +16 -0
- package/dist/src/{core/utils → utils}/core.utils.d.ts +4 -3
- package/dist/src/utils/core.utils.d.ts.map +1 -0
- package/dist/src/{core/utils → utils}/core.utils.js +17 -2
- package/dist/src/utils/index.d.ts +2 -0
- package/dist/src/utils/index.d.ts.map +1 -1
- package/dist/src/utils/index.js +2 -0
- package/dist/src/{core/utils → utils}/logger.d.ts +1 -0
- package/dist/src/utils/logger.d.ts.map +1 -0
- package/dist/src/{core/utils → utils}/logger.js +4 -1
- package/dist/test/server/in-process.spec.js +2 -14
- package/package.json +3 -3
- package/dist/src/core/core.node.d.ts +0 -79
- package/dist/src/core/core.node.d.ts.map +0 -1
- package/dist/src/core/core.node.js +0 -304
- package/dist/src/core/interfaces/connection-manager.config.d.ts +0 -7
- package/dist/src/core/interfaces/connection-manager.config.d.ts.map +0 -1
- package/dist/src/core/interfaces/connection-send-params.interface.d.ts.map +0 -1
- package/dist/src/core/interfaces/core-config.interface.d.ts.map +0 -1
- package/dist/src/core/interfaces/restricted-addresses.enum.d.ts +0 -13
- package/dist/src/core/interfaces/restricted-addresses.enum.d.ts.map +0 -1
- package/dist/src/core/interfaces/restricted-addresses.enum.js +0 -18
- 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-resolution.js +0 -24
- 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-address-resolver.js +0 -36
- package/dist/src/core/lib/o-connection-manager.d.ts +0 -22
- package/dist/src/core/lib/o-connection-manager.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection-manager.js +0 -65
- package/dist/src/core/lib/o-connection.d.ts +0 -27
- package/dist/src/core/lib/o-connection.d.ts.map +0 -1
- package/dist/src/core/lib/o-connection.js +0 -84
- package/dist/src/core/lib/o-request.d.ts.map +0 -1
- package/dist/src/core/lib/o-response.d.ts.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/anything.resolver.js +0 -15
- 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/index.js +0 -4
- 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/method.resolver.js +0 -18
- 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/next-hop.resolver.js +0 -59
- 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/lib/resolvers/storage.resolver.js +0 -10
- 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-address.js +0 -47
- 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/index.js +0 -3
- package/dist/src/core/utils/logger.d.ts.map +0 -1
- package/dist/src/core/utils/network.utils.d.ts +0 -16
- package/dist/src/core/utils/network.utils.d.ts.map +0 -1
- package/dist/src/core/utils/network.utils.js +0 -35
- package/dist/src/error/tool.error.d.ts +0 -19
- package/dist/src/error/tool.error.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/index.js +0 -3
- package/dist/src/node/interfaces/route.request.d.ts +0 -14
- package/dist/src/node/interfaces/route.request.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/local-search.lib.js +0 -10
- 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/lib/network-activity.lib.js +0 -29
- package/dist/src/node/node.d.ts +0 -45
- package/dist/src/node/node.d.ts.map +0 -1
- package/dist/src/node/node.js +0 -359
- 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/index.js +0 -1
- package/dist/src/node-virtual/virtual.node.d.ts +0 -10
- package/dist/src/node-virtual/virtual.node.d.ts.map +0 -1
- package/dist/src/node-virtual/virtual.node.js +0 -12
- package/dist/src/plan/agent.plan.d.ts +0 -28
- package/dist/src/plan/agent.plan.d.ts.map +0 -1
- package/dist/src/plan/agent.plan.js +0 -187
- package/dist/src/plan/index.d.ts +0 -5
- package/dist/src/plan/index.d.ts.map +0 -1
- package/dist/src/plan/index.js +0 -4
- package/dist/src/plan/interfaces/configure.result.d.ts +0 -6
- package/dist/src/plan/interfaces/configure.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/handshake.result.d.ts +0 -14
- package/dist/src/plan/interfaces/handshake.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-config.interface.d.ts +0 -16
- 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/interfaces/plan-type.enum.d.ts +0 -8
- package/dist/src/plan/interfaces/plan-type.enum.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan-type.enum.js +0 -8
- package/dist/src/plan/interfaces/plan.result.d.ts +0 -15
- package/dist/src/plan/interfaces/plan.result.d.ts.map +0 -1
- package/dist/src/plan/interfaces/plan.result.js +0 -1
- package/dist/src/plan/interfaces/query.config.d.ts +0 -6
- package/dist/src/plan/interfaces/query.config.d.ts.map +0 -1
- package/dist/src/plan/interfaces/query.config.js +0 -1
- package/dist/src/plan/interfaces/task.config.d.ts +0 -10
- package/dist/src/plan/interfaces/task.config.d.ts.map +0 -1
- package/dist/src/plan/interfaces/task.config.js +0 -1
- package/dist/src/plan/o-plan.d.ts +0 -36
- package/dist/src/plan/o-plan.d.ts.map +0 -1
- package/dist/src/plan/o-plan.js +0 -202
- package/dist/src/plan/plan.context.d.ts +0 -10
- package/dist/src/plan/plan.context.d.ts.map +0 -1
- package/dist/src/plan/plan.context.js +0 -28
- package/dist/src/plan/prompts/agent.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/agent.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/agent.prompt.js +0 -112
- package/dist/src/plan/prompts/configure.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/configure.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/configure.prompt.js +0 -40
- package/dist/src/plan/prompts/custom.prompt.d.ts +0 -2
- package/dist/src/plan/prompts/custom.prompt.d.ts.map +0 -1
- package/dist/src/plan/prompts/custom.prompt.js +0 -80
- package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts +0 -2
- package/dist/src/plan/search/prompts/search-analysis.prompt.d.ts.map +0 -1
- package/dist/src/plan/search/prompts/search-analysis.prompt.js +0 -14
- package/dist/src/plan/search/search.plan.d.ts +0 -21
- package/dist/src/plan/search/search.plan.d.ts.map +0 -1
- package/dist/src/plan/search/search.plan.js +0 -53
- 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/index.js +0 -1
- package/dist/src/plan/use/use.plan.d.ts +0 -16
- package/dist/src/plan/use/use.plan.d.ts.map +0 -1
- package/dist/src/plan/use/use.plan.js +0 -149
- /package/dist/src/{core → connection}/interfaces/connection-manager.config.js +0 -0
- /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.d.ts +0 -0
- /package/dist/src/{core → connection}/interfaces/connection-send-params.interface.js +0 -0
- /package/dist/src/{core/interfaces/core-config.interface.js → connection/interfaces/connection.config.js} +0 -0
- /package/dist/src/{core/lib → connection}/o-response.d.ts +0 -0
- /package/dist/src/{core/lib → connection}/o-response.js +0 -0
- /package/dist/src/{node/interfaces/route.request.js → core/interfaces/o-core.config.js} +0 -0
- /package/dist/src/{plan/interfaces/configure.result.js → core/interfaces/o-core.interface.js} +0 -0
- /package/dist/src/{plan/interfaces/handshake.result.js → error/interfaces/o-error.interface.js} +0 -0
- /package/dist/src/{plan/interfaces/plan-config.interface.js → router/interfaces/resolve.request.js} +0 -0
- /package/dist/src/{plan/interfaces/plan-result.interface.js → router/interfaces/route.response.js} +0 -0
package/dist/src/utils/index.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../src/utils/logger.ts"],"names":[],"mappings":"AAGA,qBAAa,MAAM;IAGL,OAAO,CAAC,QAAQ,CAAC,IAAI;IAFjC,OAAO,CAAC,GAAG,CAAW;gBAEO,IAAI,EAAE,MAAM;IAIzC,YAAY,CAAC,IAAI,EAAE,MAAM;IAIzB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAIpB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAInB,IAAI,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAInB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;IAIpB,KAAK,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE;CAGrB"}
|
|
@@ -3,7 +3,10 @@ import chalk from 'chalk';
|
|
|
3
3
|
export class Logger {
|
|
4
4
|
constructor(name) {
|
|
5
5
|
this.name = name;
|
|
6
|
-
this.log = debug('
|
|
6
|
+
this.log = debug('olane-os:' + name);
|
|
7
|
+
}
|
|
8
|
+
setNamespace(name) {
|
|
9
|
+
this.log = debug('olane-os:' + name);
|
|
7
10
|
}
|
|
8
11
|
debug(...args) {
|
|
9
12
|
this.log(chalk.blue('[DEBUG]'), ...args);
|
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
import { NodeState, oAddress, oVirtualNode } from '../../src/index.js';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
1
|
describe('in-process @memory', () => {
|
|
4
2
|
it('should be able to start a single node with no leader', async () => {
|
|
5
|
-
|
|
6
|
-
address: new oAddress('o://test'),
|
|
7
|
-
leader: null,
|
|
8
|
-
parent: null,
|
|
9
|
-
});
|
|
10
|
-
await node.start();
|
|
11
|
-
expect(node.state).to.equal(NodeState.RUNNING);
|
|
12
|
-
const transports = node.transports;
|
|
13
|
-
// expect(transports.length).to.equal(1);
|
|
14
|
-
// expect(transports[0].toString()).to.contain('/memory');
|
|
15
|
-
await node.stop();
|
|
16
|
-
expect(node.state).to.equal(NodeState.STOPPED);
|
|
3
|
+
// do nothing
|
|
17
4
|
});
|
|
18
5
|
});
|
|
6
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@olane/o-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/src/index.js",
|
|
6
6
|
"types": "dist/src/index.d.ts",
|
|
@@ -61,8 +61,8 @@
|
|
|
61
61
|
"typescript": "^5.8.3"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@olane/o-config": "^0.
|
|
65
|
-
"@olane/o-protocol": "^0.
|
|
64
|
+
"@olane/o-config": "^0.7.1",
|
|
65
|
+
"@olane/o-protocol": "^0.7.1"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"chalk": "^5.4.1",
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Libp2p, Libp2pConfig, Multiaddr, PeerId } from '@olane/o-config';
|
|
2
|
-
import { CoreConfig } from './interfaces/core-config.interface.js';
|
|
3
|
-
import { NodeState } from './interfaces/state.enum.js';
|
|
4
|
-
import { oAddress } from './o-address.js';
|
|
5
|
-
import { Logger } from './utils/logger.js';
|
|
6
|
-
import { NodeType } from './interfaces/node-type.enum.js';
|
|
7
|
-
import { oConnectionManager } from './lib/o-connection-manager.js';
|
|
8
|
-
import { oResponse } from './lib/o-response.js';
|
|
9
|
-
import { oConnection } from './lib/o-connection.js';
|
|
10
|
-
import { oMethod, oRequest } from '@olane/o-protocol';
|
|
11
|
-
import { oAddressResolution } from './lib/o-address-resolution.js';
|
|
12
|
-
import { oDependency } from './o-dependency.js';
|
|
13
|
-
export declare abstract class oCoreNode {
|
|
14
|
-
readonly config: CoreConfig;
|
|
15
|
-
p2pNode: Libp2p;
|
|
16
|
-
logger: Logger;
|
|
17
|
-
networkConfig: Libp2pConfig;
|
|
18
|
-
address: oAddress;
|
|
19
|
-
readonly staticAddress: oAddress;
|
|
20
|
-
peerId: PeerId;
|
|
21
|
-
state: NodeState;
|
|
22
|
-
errors: Error[];
|
|
23
|
-
connectionManager: oConnectionManager;
|
|
24
|
-
leaders: Multiaddr[];
|
|
25
|
-
addressResolution: oAddressResolution;
|
|
26
|
-
readonly description: string;
|
|
27
|
-
dependencies: oDependency[];
|
|
28
|
-
methods: {
|
|
29
|
-
[key: string]: oMethod;
|
|
30
|
-
};
|
|
31
|
-
requests: {
|
|
32
|
-
[key: string]: oRequest;
|
|
33
|
-
};
|
|
34
|
-
successCount: number;
|
|
35
|
-
errorCount: number;
|
|
36
|
-
constructor(config: CoreConfig);
|
|
37
|
-
get type(): NodeType;
|
|
38
|
-
get transports(): string[];
|
|
39
|
-
initialize(): Promise<void>;
|
|
40
|
-
whoami(): Promise<any>;
|
|
41
|
-
get parent(): oAddress | null;
|
|
42
|
-
get parentPeerId(): string | null;
|
|
43
|
-
get parentTransports(): Multiaddr[];
|
|
44
|
-
getTransports(address: oAddress): Multiaddr[];
|
|
45
|
-
handleStaticAddressTranslation(addressInput: oAddress): Promise<oAddress>;
|
|
46
|
-
translateAddress(addressWithLeaderTransports: oAddress): Promise<{
|
|
47
|
-
nextHopAddress: oAddress;
|
|
48
|
-
targetAddress: oAddress;
|
|
49
|
-
}>;
|
|
50
|
-
isInternalAddress(addressWithLeaderTransports: oAddress): boolean;
|
|
51
|
-
/**
|
|
52
|
-
* Use a tool explicitly
|
|
53
|
-
* @param addressWithLeaderTransports
|
|
54
|
-
* @param data
|
|
55
|
-
* @param config
|
|
56
|
-
* @returns
|
|
57
|
-
*/
|
|
58
|
-
use(addressWithLeaderTransports: oAddress, data?: {
|
|
59
|
-
method?: string;
|
|
60
|
-
params?: {
|
|
61
|
-
[key: string]: any;
|
|
62
|
-
};
|
|
63
|
-
id?: string;
|
|
64
|
-
}): Promise<oResponse>;
|
|
65
|
-
unregister(): Promise<void>;
|
|
66
|
-
register(): Promise<void>;
|
|
67
|
-
connect(nextHopAddress: oAddress, targetAddress: oAddress): Promise<oConnection>;
|
|
68
|
-
teardown(): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Start the node
|
|
71
|
-
* @param parent - The parent node
|
|
72
|
-
*/
|
|
73
|
-
start(): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Stop the node
|
|
76
|
-
*/
|
|
77
|
-
stop(): Promise<void>;
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=core.node.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core.node.d.ts","sourceRoot":"","sources":["../../../src/core/core.node.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,304 +0,0 @@
|
|
|
1
|
-
import { defaultLibp2pConfig, multiaddr, } from '@olane/o-config';
|
|
2
|
-
import { NodeState } from './interfaces/state.enum.js';
|
|
3
|
-
import { oAddress } from './o-address.js';
|
|
4
|
-
import { Logger } from './utils/logger.js';
|
|
5
|
-
import { NodeType } from './interfaces/node-type.enum.js';
|
|
6
|
-
import { oAddressResolution } from './lib/o-address-resolution.js';
|
|
7
|
-
import { oDependency } from './o-dependency.js';
|
|
8
|
-
import { oToolError } from '../error/tool.error.js';
|
|
9
|
-
export class oCoreNode {
|
|
10
|
-
constructor(config) {
|
|
11
|
-
this.config = config;
|
|
12
|
-
this.state = NodeState.STOPPED;
|
|
13
|
-
this.errors = [];
|
|
14
|
-
this.leaders = [];
|
|
15
|
-
this.requests = {};
|
|
16
|
-
this.successCount = 0;
|
|
17
|
-
this.errorCount = 0;
|
|
18
|
-
this.logger = new Logger(this.constructor.name +
|
|
19
|
-
(config.name ? `:${config.name}` : '') +
|
|
20
|
-
':' +
|
|
21
|
-
config.address.toString());
|
|
22
|
-
this.address = config.address || new oAddress('o://node');
|
|
23
|
-
this.networkConfig = config.network || defaultLibp2pConfig;
|
|
24
|
-
this.addressResolution = new oAddressResolution();
|
|
25
|
-
this.staticAddress = config.address;
|
|
26
|
-
this.description = config.description || '';
|
|
27
|
-
this.dependencies =
|
|
28
|
-
config.dependencies?.map((d) => new oDependency(d)) || [];
|
|
29
|
-
this.methods = config.methods || {};
|
|
30
|
-
}
|
|
31
|
-
get type() {
|
|
32
|
-
return this.config.type || NodeType.UNKNOWN;
|
|
33
|
-
}
|
|
34
|
-
get transports() {
|
|
35
|
-
return this.p2pNode
|
|
36
|
-
.getMultiaddrs()
|
|
37
|
-
.map((multiaddr) => multiaddr.toString());
|
|
38
|
-
}
|
|
39
|
-
async initialize() { }
|
|
40
|
-
async whoami() {
|
|
41
|
-
return {
|
|
42
|
-
address: this.address.toString(),
|
|
43
|
-
type: this.type,
|
|
44
|
-
description: this.description,
|
|
45
|
-
methods: this.methods,
|
|
46
|
-
successCount: this.successCount,
|
|
47
|
-
errorCount: this.errorCount,
|
|
48
|
-
};
|
|
49
|
-
}
|
|
50
|
-
get parent() {
|
|
51
|
-
return this.config.parent || null;
|
|
52
|
-
}
|
|
53
|
-
get parentPeerId() {
|
|
54
|
-
if (!this.parent || this.parent?.transports?.length === 0) {
|
|
55
|
-
return null;
|
|
56
|
-
}
|
|
57
|
-
const transport = this.parent?.transports[0];
|
|
58
|
-
const peerId = transport.toString().split('/p2p/')[1];
|
|
59
|
-
return peerId;
|
|
60
|
-
}
|
|
61
|
-
get parentTransports() {
|
|
62
|
-
return this.parent?.transports.map((t) => multiaddr(t)) || [];
|
|
63
|
-
}
|
|
64
|
-
getTransports(address) {
|
|
65
|
-
let leaderTransports = address.libp2pTransports;
|
|
66
|
-
// check if we already know where we want to go
|
|
67
|
-
if (leaderTransports.length > 0) {
|
|
68
|
-
return leaderTransports;
|
|
69
|
-
}
|
|
70
|
-
// if leader transports are not provided, then we need to search for them
|
|
71
|
-
// Assume we are looking for a leader within our network for now
|
|
72
|
-
// TODO: we need to add some discovery managers that every node can use to find external network resources
|
|
73
|
-
if (leaderTransports.length === 0) {
|
|
74
|
-
this.logger.debug('No leader transports provided, we are going to search within our own network');
|
|
75
|
-
if (!this.config.leader) {
|
|
76
|
-
// TODO: how do we handle when the node is the leader? // technically we are in the network
|
|
77
|
-
if (this.type === NodeType.LEADER) {
|
|
78
|
-
this.logger.debug('Node is a leader, using own transports');
|
|
79
|
-
leaderTransports = this.transports.map((t) => multiaddr(t));
|
|
80
|
-
}
|
|
81
|
-
else {
|
|
82
|
-
this.logger.warn('We are not within a network, cannot search for addressed node without leader.');
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
else {
|
|
86
|
-
leaderTransports = this.config.leader.libp2pTransports;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
if (leaderTransports.length === 0) {
|
|
90
|
-
throw new Error('No leader transports provided, cannot search for leaders');
|
|
91
|
-
}
|
|
92
|
-
return leaderTransports;
|
|
93
|
-
}
|
|
94
|
-
async handleStaticAddressTranslation(addressInput) {
|
|
95
|
-
let result = addressInput;
|
|
96
|
-
this.logger.debug('Handling static address translation...', result.toString());
|
|
97
|
-
// handle static address translation
|
|
98
|
-
if (result.value.indexOf('o://leader') === -1) {
|
|
99
|
-
// TODO: we need to be more dynamic around the o://leader prefix
|
|
100
|
-
const response = await this.use(new oAddress('o://leader/register', result.transports), {
|
|
101
|
-
method: 'search',
|
|
102
|
-
params: { staticAddress: result.root },
|
|
103
|
-
});
|
|
104
|
-
const searchResults = response.result.data;
|
|
105
|
-
if (searchResults.length > 0) {
|
|
106
|
-
// the root was found, let's add the rest of the path to the address
|
|
107
|
-
const remainderPaths = result.paths.split('/').slice(1);
|
|
108
|
-
const resolvedAddress = searchResults[0].address +
|
|
109
|
-
(remainderPaths.length > 0 ? '/' + remainderPaths.join('/') : ''); // TODO: we need to handle this better
|
|
110
|
-
result = new oAddress(resolvedAddress, result.transports);
|
|
111
|
-
}
|
|
112
|
-
else {
|
|
113
|
-
this.logger.warn('Failed to translate static address');
|
|
114
|
-
// TODO: we need to handle this better
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return result;
|
|
118
|
-
}
|
|
119
|
-
async translateAddress(addressWithLeaderTransports) {
|
|
120
|
-
// determine if this is external
|
|
121
|
-
const isInternal = this.isInternalAddress(addressWithLeaderTransports);
|
|
122
|
-
if (!isInternal) {
|
|
123
|
-
// external address, so we need to route
|
|
124
|
-
this.logger.debug('Address is external, routing...', addressWithLeaderTransports);
|
|
125
|
-
return {
|
|
126
|
-
nextHopAddress: new oAddress('o://leader', addressWithLeaderTransports.libp2pTransports),
|
|
127
|
-
targetAddress: addressWithLeaderTransports,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
let targetAddress = addressWithLeaderTransports;
|
|
131
|
-
let nextHopAddress = addressWithLeaderTransports;
|
|
132
|
-
// handle static address translation for search based upon base functionality
|
|
133
|
-
targetAddress = await this.handleStaticAddressTranslation(targetAddress);
|
|
134
|
-
nextHopAddress = await this.addressResolution.resolve(targetAddress);
|
|
135
|
-
const leaderTransports = this.getTransports(nextHopAddress);
|
|
136
|
-
nextHopAddress.setTransports(leaderTransports);
|
|
137
|
-
return {
|
|
138
|
-
nextHopAddress,
|
|
139
|
-
targetAddress: targetAddress,
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
isInternalAddress(addressWithLeaderTransports) {
|
|
143
|
-
if (addressWithLeaderTransports.libp2pTransports?.length > 0) {
|
|
144
|
-
// transports are provided, let's see if they match our known leaders
|
|
145
|
-
const leaderTransports = this.type === NodeType.LEADER
|
|
146
|
-
? this.address.libp2pTransports
|
|
147
|
-
: this.config.leader?.libp2pTransports;
|
|
148
|
-
this.logger.debug('Leader transports: ', leaderTransports);
|
|
149
|
-
if (leaderTransports && leaderTransports.length > 0) {
|
|
150
|
-
this.logger.debug('Address transports: ', addressWithLeaderTransports.libp2pTransports);
|
|
151
|
-
// compare against our known leaders
|
|
152
|
-
const isInternal = leaderTransports.some((t) => addressWithLeaderTransports.libp2pTransports.includes(t));
|
|
153
|
-
return isInternal;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
/**
|
|
159
|
-
* Use a tool explicitly
|
|
160
|
-
* @param addressWithLeaderTransports
|
|
161
|
-
* @param data
|
|
162
|
-
* @param config
|
|
163
|
-
* @returns
|
|
164
|
-
*/
|
|
165
|
-
async use(addressWithLeaderTransports, data) {
|
|
166
|
-
if (!addressWithLeaderTransports.validate()) {
|
|
167
|
-
throw new Error('Invalid address');
|
|
168
|
-
}
|
|
169
|
-
const { nextHopAddress, targetAddress } = await this.translateAddress(addressWithLeaderTransports);
|
|
170
|
-
const connection = await this.connect(nextHopAddress, targetAddress);
|
|
171
|
-
// communicate the payload to the target node
|
|
172
|
-
const response = await connection.send({
|
|
173
|
-
address: targetAddress?.toString() || '',
|
|
174
|
-
payload: data || {},
|
|
175
|
-
id: data?.id,
|
|
176
|
-
});
|
|
177
|
-
// if there is an error, throw it to continue to bubble up
|
|
178
|
-
if (response.result.error) {
|
|
179
|
-
this.logger.error('response.result.error', JSON.stringify(response.result.error, null, 2));
|
|
180
|
-
throw oToolError.fromJSON(response.result.error);
|
|
181
|
-
}
|
|
182
|
-
return response;
|
|
183
|
-
}
|
|
184
|
-
async unregister() {
|
|
185
|
-
if (this.type === NodeType.LEADER) {
|
|
186
|
-
this.logger.debug('Skipping unregistration, node is leader');
|
|
187
|
-
return;
|
|
188
|
-
}
|
|
189
|
-
if (!this.config.leader) {
|
|
190
|
-
this.logger.debug('No leader found, skipping unregistration');
|
|
191
|
-
return;
|
|
192
|
-
}
|
|
193
|
-
const address = new oAddress('o://leader/register');
|
|
194
|
-
// attempt to unregister from the network
|
|
195
|
-
const params = {
|
|
196
|
-
method: 'remove',
|
|
197
|
-
params: {
|
|
198
|
-
peerId: this.peerId.toString(),
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
await this.use(address, params);
|
|
202
|
-
}
|
|
203
|
-
async register() {
|
|
204
|
-
if (this.type === NodeType.LEADER) {
|
|
205
|
-
this.logger.debug('Skipping registration, node is leader');
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
this.logger.debug('Registering node...');
|
|
209
|
-
// register with the leader global registry
|
|
210
|
-
if (!this.config.leader) {
|
|
211
|
-
this.logger.warn('No leaders found, skipping registration');
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
else {
|
|
215
|
-
this.logger.debug('Registering node with leader...', this.config.leader);
|
|
216
|
-
}
|
|
217
|
-
const address = new oAddress('o://register');
|
|
218
|
-
const params = {
|
|
219
|
-
method: 'commit',
|
|
220
|
-
params: {
|
|
221
|
-
peerId: this.peerId.toString(),
|
|
222
|
-
address: this.address.toString(),
|
|
223
|
-
protocols: this.p2pNode.getProtocols(),
|
|
224
|
-
transports: this.transports,
|
|
225
|
-
staticAddress: this.staticAddress.toString(),
|
|
226
|
-
},
|
|
227
|
-
};
|
|
228
|
-
await this.use(address, params);
|
|
229
|
-
this.logger.debug('Registration successful');
|
|
230
|
-
}
|
|
231
|
-
async connect(nextHopAddress, targetAddress) {
|
|
232
|
-
if (!this.connectionManager) {
|
|
233
|
-
this.logger.error('Connection manager not initialized');
|
|
234
|
-
throw new Error('Node is not ready to connect to other nodes');
|
|
235
|
-
}
|
|
236
|
-
const connection = await this.connectionManager
|
|
237
|
-
.connect({
|
|
238
|
-
address: targetAddress,
|
|
239
|
-
nextHopAddress,
|
|
240
|
-
callerAddress: this.address,
|
|
241
|
-
})
|
|
242
|
-
.catch((error) => {
|
|
243
|
-
// TODO: we need to handle this better and document
|
|
244
|
-
if (error.message === 'Can not dial self') {
|
|
245
|
-
this.logger.error('Make sure you are entering the network not directly through the leader node.');
|
|
246
|
-
}
|
|
247
|
-
throw error;
|
|
248
|
-
});
|
|
249
|
-
this.logger.debug('Successfully connected to: ', nextHopAddress.toString());
|
|
250
|
-
if (!connection) {
|
|
251
|
-
throw new Error('Connection failed');
|
|
252
|
-
}
|
|
253
|
-
return connection;
|
|
254
|
-
}
|
|
255
|
-
async teardown() {
|
|
256
|
-
this.logger.debug('Tearing down node...');
|
|
257
|
-
if (this.p2pNode) {
|
|
258
|
-
await this.p2pNode.stop();
|
|
259
|
-
}
|
|
260
|
-
}
|
|
261
|
-
/**
|
|
262
|
-
* Start the node
|
|
263
|
-
* @param parent - The parent node
|
|
264
|
-
*/
|
|
265
|
-
async start() {
|
|
266
|
-
if (this.state !== NodeState.STOPPED) {
|
|
267
|
-
this.logger.warn('Node is not stopped, skipping start');
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
this.state = NodeState.STARTING;
|
|
271
|
-
this.p2pNode = this.p2pNode;
|
|
272
|
-
try {
|
|
273
|
-
await this.initialize();
|
|
274
|
-
this.logger.debug('Initializing connection manager...');
|
|
275
|
-
await this.register().catch((error) => {
|
|
276
|
-
this.logger.error('Failed to register node', error);
|
|
277
|
-
});
|
|
278
|
-
this.state = NodeState.RUNNING;
|
|
279
|
-
}
|
|
280
|
-
catch (error) {
|
|
281
|
-
this.logger.error('Failed to start node', error);
|
|
282
|
-
this.errors.push(error);
|
|
283
|
-
this.state = NodeState.ERROR;
|
|
284
|
-
await this.teardown();
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* Stop the node
|
|
289
|
-
*/
|
|
290
|
-
async stop() {
|
|
291
|
-
this.logger.debug('Stop node called...');
|
|
292
|
-
this.state = NodeState.STOPPING;
|
|
293
|
-
try {
|
|
294
|
-
await this.teardown();
|
|
295
|
-
this.state = NodeState.STOPPED;
|
|
296
|
-
this.logger.debug('Node stopped!');
|
|
297
|
-
}
|
|
298
|
-
catch (error) {
|
|
299
|
-
this.errors.push(error);
|
|
300
|
-
this.state = NodeState.ERROR;
|
|
301
|
-
this.logger.error('Node failed to stop', error);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-manager.config.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/connection-manager.config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,MAAM,WAAW,wBAAwB;IACvC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC;CACjB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"connection-send-params.interface.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/connection-send-params.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,oBAAoB;IACnC,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE;QACP,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;KACxB,CAAC;IACF,EAAE,CAAC,EAAE,MAAM,CAAC;CACb"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"core-config.interface.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/core-config.interface.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAEzD,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,QAAQ,CAAC;IAClB,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IACxB,MAAM,EAAE,QAAQ,GAAG,IAAI,CAAC;IACxB,IAAI,CAAC,EAAE,QAAQ,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,WAAW,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;KAAE,CAAC;IACrC,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,aAAa,CAAC,EAAE,QAAQ,CAAC;CAC1B"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
export declare enum RestrictedAddresses {
|
|
2
|
-
GLOBAL_PREFIX = "o://",
|
|
3
|
-
REGISTRATION = "register",
|
|
4
|
-
LEADER = "leader",
|
|
5
|
-
TOOL = "tool",
|
|
6
|
-
AGENT = "agent"
|
|
7
|
-
}
|
|
8
|
-
export declare const REGISTRATION_ADRESS: string;
|
|
9
|
-
export declare const LEADER_ADRESS: string;
|
|
10
|
-
export declare const TOOL_ADRESS: string;
|
|
11
|
-
export declare const AGENT_ADRESS: string;
|
|
12
|
-
export declare const RestrictedAddressesList: string[];
|
|
13
|
-
//# sourceMappingURL=restricted-addresses.enum.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"restricted-addresses.enum.d.ts","sourceRoot":"","sources":["../../../../src/core/interfaces/restricted-addresses.enum.ts"],"names":[],"mappings":"AAAA,oBAAY,mBAAmB;IAC7B,aAAa,SAAS;IACtB,YAAY,aAAa;IACzB,MAAM,WAAW;IACjB,IAAI,SAAS;IACb,KAAK,UAAU;CAChB;AAED,eAAO,MAAM,mBAAmB,QACsC,CAAC;AAEvE,eAAO,MAAM,aAAa,QACsC,CAAC;AAEjE,eAAO,MAAM,WAAW,QACsC,CAAC;AAE/D,eAAO,MAAM,YAAY,QACsC,CAAC;AAEhE,eAAO,MAAM,uBAAuB,UAKnC,CAAC"}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export var RestrictedAddresses;
|
|
2
|
-
(function (RestrictedAddresses) {
|
|
3
|
-
RestrictedAddresses["GLOBAL_PREFIX"] = "o://";
|
|
4
|
-
RestrictedAddresses["REGISTRATION"] = "register";
|
|
5
|
-
RestrictedAddresses["LEADER"] = "leader";
|
|
6
|
-
RestrictedAddresses["TOOL"] = "tool";
|
|
7
|
-
RestrictedAddresses["AGENT"] = "agent";
|
|
8
|
-
})(RestrictedAddresses || (RestrictedAddresses = {}));
|
|
9
|
-
export const REGISTRATION_ADRESS = RestrictedAddresses.GLOBAL_PREFIX + RestrictedAddresses.REGISTRATION;
|
|
10
|
-
export const LEADER_ADRESS = RestrictedAddresses.GLOBAL_PREFIX + RestrictedAddresses.LEADER;
|
|
11
|
-
export const TOOL_ADRESS = RestrictedAddresses.GLOBAL_PREFIX + RestrictedAddresses.TOOL;
|
|
12
|
-
export const AGENT_ADRESS = RestrictedAddresses.GLOBAL_PREFIX + RestrictedAddresses.AGENT;
|
|
13
|
-
export const RestrictedAddressesList = [
|
|
14
|
-
REGISTRATION_ADRESS,
|
|
15
|
-
LEADER_ADRESS,
|
|
16
|
-
TOOL_ADRESS,
|
|
17
|
-
AGENT_ADRESS,
|
|
18
|
-
];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { oAddress } from '../o-address.js';
|
|
2
|
-
import { oAddressResolver } from './o-address-resolver.js';
|
|
3
|
-
export declare class oAddressResolution {
|
|
4
|
-
private readonly resolvers;
|
|
5
|
-
addResolver(resolver: oAddressResolver): void;
|
|
6
|
-
supportsTransport(address: oAddress): boolean;
|
|
7
|
-
resolve(address: oAddress): Promise<oAddress>;
|
|
8
|
-
}
|
|
9
|
-
//# sourceMappingURL=o-address-resolution.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"o-address-resolution.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/o-address-resolution.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,QAAQ,CAAC,SAAS,CAA0B;IAEpD,WAAW,CAAC,QAAQ,EAAE,gBAAgB;IAItC,iBAAiB,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO;IAWvC,OAAO,CAAC,OAAO,EAAE,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;CAOpD"}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { oAddress } from '../o-address.js';
|
|
2
|
-
export class oAddressResolution {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.resolvers = [];
|
|
5
|
-
}
|
|
6
|
-
addResolver(resolver) {
|
|
7
|
-
this.resolvers.push(resolver);
|
|
8
|
-
}
|
|
9
|
-
supportsTransport(address) {
|
|
10
|
-
if (address.libp2pTransports.length > 0) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return this.resolvers.some((r) => address.customTransports.some((t) => {
|
|
14
|
-
return r.transports.includes(t);
|
|
15
|
-
}));
|
|
16
|
-
}
|
|
17
|
-
async resolve(address) {
|
|
18
|
-
let resolvedAddress = new oAddress(address.toString(), address.transports);
|
|
19
|
-
for (const resolver of this.resolvers) {
|
|
20
|
-
resolvedAddress = await resolver.resolve(resolvedAddress);
|
|
21
|
-
}
|
|
22
|
-
return resolvedAddress;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Libp2p } from '@olane/o-config';
|
|
2
|
-
import { Logger } from '../utils/logger.js';
|
|
3
|
-
import { oAddress } from '../o-address.js';
|
|
4
|
-
import { oNode } from '../../node/index.js';
|
|
5
|
-
export declare class oAddressResolver {
|
|
6
|
-
protected readonly address: oAddress;
|
|
7
|
-
protected readonly p2pNode: Libp2p;
|
|
8
|
-
logger: Logger;
|
|
9
|
-
constructor(address: oAddress, p2pNode: Libp2p);
|
|
10
|
-
get transports(): string[];
|
|
11
|
-
isHoppingDown(targetAddress: oAddress): boolean;
|
|
12
|
-
isLeaderNextHop(targetAddress: oAddress): boolean;
|
|
13
|
-
isStaticAddress(targetAddress: oAddress): boolean;
|
|
14
|
-
determineNextHopAddress(targetAddress: oAddress): oAddress;
|
|
15
|
-
resolve(address: oAddress, node?: oNode): Promise<oAddress>;
|
|
16
|
-
}
|
|
17
|
-
//# sourceMappingURL=o-address-resolver.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"o-address-resolver.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/o-address-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAa,MAAM,iBAAiB,CAAC;AACpD,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAE5C,qBAAa,gBAAgB;IAGzB,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,QAAQ;IACpC,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,MAAM;IAH7B,MAAM,EAAE,MAAM,CAAC;gBAED,OAAO,EAAE,QAAQ,EACjB,OAAO,EAAE,MAAM;IAKpC,IAAI,UAAU,IAAI,MAAM,EAAE,CAEzB;IAED,aAAa,CAAC,aAAa,EAAE,QAAQ,GAAG,OAAO;IAI/C,eAAe,CAAC,aAAa,EAAE,QAAQ,GAAG,OAAO;IAIjD,eAAe,CAAC,aAAa,EAAE,QAAQ,GAAG,OAAO;IAIjD,uBAAuB,CAAC,aAAa,EAAE,QAAQ;IAezC,OAAO,CAAC,OAAO,EAAE,QAAQ,EAAE,IAAI,CAAC,EAAE,KAAK,GAAG,OAAO,CAAC,QAAQ,CAAC;CAGlE"}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Logger } from '../utils/logger.js';
|
|
2
|
-
import { oAddress } from '../o-address.js';
|
|
3
|
-
export class oAddressResolver {
|
|
4
|
-
constructor(address, p2pNode) {
|
|
5
|
-
this.address = address;
|
|
6
|
-
this.p2pNode = p2pNode;
|
|
7
|
-
this.logger = new Logger(this.constructor.name);
|
|
8
|
-
}
|
|
9
|
-
get transports() {
|
|
10
|
-
return [];
|
|
11
|
-
}
|
|
12
|
-
isHoppingDown(targetAddress) {
|
|
13
|
-
return targetAddress.protocol?.includes(this.address.protocol) === false;
|
|
14
|
-
}
|
|
15
|
-
isLeaderNextHop(targetAddress) {
|
|
16
|
-
return targetAddress.protocol?.includes(this.address.protocol) === false;
|
|
17
|
-
}
|
|
18
|
-
isStaticAddress(targetAddress) {
|
|
19
|
-
return targetAddress.toString()?.includes('o://leader') === false;
|
|
20
|
-
}
|
|
21
|
-
determineNextHopAddress(targetAddress) {
|
|
22
|
-
// do we have to start at the root leader or continue forward?
|
|
23
|
-
const startAtLeader = targetAddress.protocol?.includes(this.address.protocol) === false;
|
|
24
|
-
const prefix = startAtLeader ? 'o://' : this.address.value + '/';
|
|
25
|
-
// determine the next hop
|
|
26
|
-
const remainingPath = startAtLeader
|
|
27
|
-
? targetAddress.protocol
|
|
28
|
-
: targetAddress.protocol.replace(this.address.protocol + '/', '');
|
|
29
|
-
const nextHop = remainingPath.replace('/o/', '').split('/').reverse().pop();
|
|
30
|
-
const nextHopAddress = new oAddress(prefix + nextHop);
|
|
31
|
-
return nextHopAddress;
|
|
32
|
-
}
|
|
33
|
-
async resolve(address, node) {
|
|
34
|
-
return address;
|
|
35
|
-
}
|
|
36
|
-
}
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { oAddress } from '../o-address.js';
|
|
2
|
-
import { oConnection } from './o-connection.js';
|
|
3
|
-
import { oConnectionManagerConfig } from '../interfaces/connection-manager.config.js';
|
|
4
|
-
export declare class oConnectionManager {
|
|
5
|
-
private cache;
|
|
6
|
-
private logger;
|
|
7
|
-
private p2pNode;
|
|
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
|
-
*/
|
|
14
|
-
connect(config: {
|
|
15
|
-
address: oAddress;
|
|
16
|
-
nextHopAddress: oAddress;
|
|
17
|
-
callerAddress?: oAddress;
|
|
18
|
-
}): Promise<oConnection>;
|
|
19
|
-
isCached(address: oAddress): boolean;
|
|
20
|
-
getCachedConnection(address: oAddress): oConnection | null;
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=o-connection-manager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
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,iBAAiB,CAAC;AAE3C,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4CAA4C,CAAC;AAGtF,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"}
|