@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-testnet-one.1
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/ConnectionLockHandler.js +2 -2
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +2 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js +3 -27
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +0 -1
- package/dist/src/connection/ConnectionManager.js +11 -7
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +2 -2
- package/dist/src/connection/ConnectorFacade.js +1 -2
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +1 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +122 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +2 -0
- package/dist/src/connection/connectivityRequestHandler.js +79 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.js +3 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +7 -3
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/ServerWebsocket.d.ts +4 -0
- package/dist/src/connection/websocket/ServerWebsocket.js +32 -21
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +0 -2
- package/dist/src/connection/websocket/WebsocketConnector.js +61 -16
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -11
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -4
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +5 -39
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.js +21 -4
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +13 -23
- package/dist/src/dht/DhtNode.js +97 -226
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -4
- package/dist/src/dht/DhtNodeRpcLocal.js +1 -5
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +3 -3
- package/dist/src/dht/DhtNodeRpcRemote.js +4 -4
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +4 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +5 -12
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcRemote.js +5 -5
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +52 -0
- package/dist/src/dht/PeerManager.js +273 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/ContactList.d.ts +1 -1
- package/dist/src/dht/contact/ContactList.js +1 -0
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +3 -3
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +8 -8
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +20 -6
- package/dist/src/dht/contact/SortedContactList.js +55 -24
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +4 -14
- package/dist/src/dht/discovery/DiscoverySession.js +15 -26
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -9
- package/dist/src/dht/discovery/PeerDiscovery.js +11 -19
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/FindRpcLocal.js +2 -1
- package/dist/src/dht/find/FindRpcLocal.js.map +1 -1
- package/dist/src/dht/find/FindSession.d.ts +6 -6
- package/dist/src/dht/find/FindSession.js +18 -13
- package/dist/src/dht/find/FindSession.js.map +1 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +1 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +1 -1
- package/dist/src/dht/find/Finder.d.ts +4 -4
- package/dist/src/dht/find/Finder.js +55 -42
- package/dist/src/dht/find/Finder.js.map +1 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/FindRpcRemote.js +7 -5
- package/dist/src/dht/routing/FindRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +3 -7
- package/dist/src/dht/routing/Router.js +29 -22
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcLocal.js +4 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +13 -8
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
- package/dist/src/dht/routing/RoutingSession.js +23 -11
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +3 -3
- package/dist/src/dht/store/LocalDataStore.js +18 -17
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +10 -9
- package/dist/src/dht/store/StoreRpcLocal.js +108 -102
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js +6 -15
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +1 -1
- package/dist/src/exports.js +4 -4
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +1 -0
- package/dist/src/helpers/PeerID.js +9 -4
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/UUID.js +1 -1
- package/dist/src/helpers/UUID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +1 -0
- package/dist/src/helpers/{kademliaId.js → nodeId.js} +4 -4
- package/dist/src/helpers/nodeId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +4 -4
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +5 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +2 -9
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +80 -95
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +67 -66
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +3 -10
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/karma.config.js +2 -2
- package/package.json +5 -5
- package/protos/DhtRpc.proto +36 -36
- package/src/connection/ConnectionLockHandler.ts +2 -2
- package/src/connection/ConnectionLockRpcRemote.ts +3 -4
- package/src/connection/ConnectionManager.ts +19 -17
- package/src/connection/ConnectorFacade.ts +5 -7
- package/src/connection/ManagedConnection.ts +1 -0
- package/src/connection/connectivityChecker.ts +102 -0
- package/src/connection/connectivityRequestHandler.ts +79 -0
- package/src/connection/simulator/Simulator.ts +3 -2
- package/src/connection/simulator/SimulatorConnection.ts +1 -1
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -10
- package/src/connection/webrtc/NodeWebrtcConnection.ts +1 -1
- package/src/connection/webrtc/WebrtcConnector.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +2 -2
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/ClientWebsocket.ts +6 -2
- package/src/connection/websocket/ServerWebsocket.ts +40 -25
- package/src/connection/websocket/WebsocketConnector.ts +43 -22
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +9 -11
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -16
- package/src/connection/websocket/WebsocketServer.ts +20 -5
- package/src/dht/DhtNode.ts +123 -280
- package/src/dht/DhtNodeRpcLocal.ts +2 -9
- package/src/dht/DhtNodeRpcRemote.ts +4 -4
- package/src/dht/ExternalApiRpcLocal.ts +8 -13
- package/src/dht/ExternalApiRpcRemote.ts +5 -5
- package/src/dht/PeerManager.ts +330 -0
- package/src/dht/contact/ContactList.ts +3 -2
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +7 -6
- package/src/dht/contact/SortedContactList.ts +87 -44
- package/src/dht/discovery/DiscoverySession.ts +19 -44
- package/src/dht/discovery/PeerDiscovery.ts +16 -28
- package/src/dht/find/FindRpcLocal.ts +2 -2
- package/src/dht/find/FindSession.ts +25 -20
- package/src/dht/find/FindSessionRpcLocal.ts +1 -1
- package/src/dht/find/FindSessionRpcRemote.ts +2 -2
- package/src/dht/find/Finder.ts +84 -64
- package/src/dht/routing/FindRpcRemote.ts +7 -5
- package/src/dht/routing/Router.ts +30 -25
- package/src/dht/routing/RouterRpcLocal.ts +5 -5
- package/src/dht/routing/RouterRpcRemote.ts +13 -10
- package/src/dht/routing/RoutingSession.ts +22 -17
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +18 -17
- package/src/dht/store/StoreRpcLocal.ts +118 -113
- package/src/dht/store/StoreRpcRemote.ts +7 -23
- package/src/exports.ts +1 -1
- package/src/helpers/PeerID.ts +8 -4
- package/src/helpers/UUID.ts +1 -1
- package/src/helpers/{kademliaId.ts → nodeId.ts} +1 -1
- package/src/helpers/peerIdFromPeerDescriptor.ts +6 -6
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -20
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -10
- package/src/proto/packages/dht/protos/DhtRpc.ts +103 -135
- package/src/transport/RoutingRpcCommunicator.ts +2 -0
- package/test/benchmark/Find.test.ts +5 -5
- package/test/benchmark/KademliaCorrectness.test.ts +3 -3
- package/test/benchmark/SortedContactListBenchmark.test.ts +150 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +1 -1
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +1 -1
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +6 -1
- package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
- package/test/end-to-end/Layer0.test.ts +4 -4
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +11 -11
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +6 -6
- package/test/end-to-end/Layer0Webrtc.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +3 -3
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +3 -3
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +9 -12
- package/test/integration/ConnectionLocking.test.ts +2 -2
- package/test/integration/ConnectionManager.test.ts +14 -14
- package/test/integration/DhtJoinPeerDiscovery.test.ts +3 -3
- package/test/integration/DhtNodeExternalAPI.test.ts +10 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +4 -4
- package/test/integration/DhtRpc.test.ts +6 -6
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +3 -3
- package/test/integration/Mock-Layer1-Layer0.test.ts +16 -16
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/{MigrateData.test.ts → ReplicateData.test.ts} +15 -10
- package/test/integration/RouteMessage.test.ts +2 -2
- package/test/integration/RouterRpcRemote.test.ts +2 -2
- package/test/integration/RpcErrors.test.ts +2 -2
- package/test/integration/ScaleDownDht.test.ts +4 -2
- package/test/integration/SimultaneousConnections.test.ts +89 -57
- package/test/integration/Store.test.ts +33 -13
- package/test/integration/StoreAndDelete.test.ts +19 -17
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +21 -21
- package/test/integration/StoreRpcRemote.test.ts +3 -3
- package/test/integration/WebrtcConnectionManagement.test.ts +2 -2
- package/test/integration/WebrtcConnectorRpc.test.ts +1 -1
- package/test/integration/WebsocketConnectionManagement.test.ts +41 -3
- package/test/integration/WebsocketConnectorRpc.test.ts +5 -7
- package/test/unit/ConnectivityHelpers.test.ts +4 -4
- package/test/unit/Finder.test.ts +69 -23
- package/test/unit/LocalDataStore.test.ts +60 -43
- package/test/unit/RandomContactList.test.ts +2 -2
- package/test/unit/Router.test.ts +19 -11
- package/test/unit/RoutingSession.test.ts +76 -0
- package/test/unit/SortedContactList.test.ts +17 -12
- package/test/unit/WebsocketConnector.test.ts +1 -1
- package/test/unit/connectivityRequestHandler.test.ts +71 -0
- package/test/utils/mock/Router.ts +1 -1
- package/test/utils/utils.ts +24 -22
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
|
@@ -11,15 +11,11 @@ class DhtNodeRpcLocal {
|
|
|
11
11
|
async getClosestPeers(request, context) {
|
|
12
12
|
this.config.addNewContact(context.incomingSourceDescriptor);
|
|
13
13
|
const response = {
|
|
14
|
-
peers: this.
|
|
14
|
+
peers: this.config.getClosestPeersTo(request.nodeId, this.config.peerDiscoveryQueryBatchSize),
|
|
15
15
|
requestId: request.requestId
|
|
16
16
|
};
|
|
17
17
|
return response;
|
|
18
18
|
}
|
|
19
|
-
getClosestPeerDescriptors(kademliaId, limit) {
|
|
20
|
-
const closestPeers = this.config.bucket.closest(kademliaId, limit);
|
|
21
|
-
return closestPeers.map((rpcRemote) => rpcRemote.getPeerDescriptor());
|
|
22
|
-
}
|
|
23
19
|
async ping(request, context) {
|
|
24
20
|
logger.trace('received ping request: ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(context.incomingSourceDescriptor));
|
|
25
21
|
setImmediate(() => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DhtNodeRpcLocal.js","sourceRoot":"","sources":["../../../src/dht/DhtNodeRpcLocal.ts"],"names":[],"mappings":";;;AACA,0CAAuC;
|
|
1
|
+
{"version":3,"file":"DhtNodeRpcLocal.js","sourceRoot":"","sources":["../../../src/dht/DhtNodeRpcLocal.ts"],"names":[],"mappings":";;;AACA,0CAAuC;AACvC,kFAAiF;AAqBjF,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,eAAe;IAIxB,YAAY,MAA6B;QACrC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAA4B,EAAE,OAA0B;QAC1E,IAAI,CAAC,MAAM,CAAC,aAAa,CAAE,OAA0B,CAAC,wBAAyB,CAAC,CAAA;QAChF,MAAM,QAAQ,GAAG;YACb,KAAK,EAAE,IAAI,CAAC,MAAM,CAAC,iBAAiB,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,2BAA2B,CAAC;YAC7F,SAAS,EAAE,OAAO,CAAC,SAAS;SAC/B,CAAA;QACD,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,OAAoB,EAAE,OAA0B;QACvD,MAAM,CAAC,KAAK,CAAC,yBAAyB,GAAG,IAAA,sDAA2B,EAAE,OAA0B,CAAC,wBAAyB,CAAC,CAAC,CAAA;QAC5H,YAAY,CAAC,GAAG,EAAE;YACd,IAAI,CAAC,MAAM,CAAC,aAAa,CAAE,OAA0B,CAAC,wBAAyB,CAAC,CAAA;QACpF,CAAC,CAAC,CAAA;QACF,MAAM,QAAQ,GAAiB;YAC3B,SAAS,EAAE,OAAO,CAAC,SAAS;SAC/B,CAAA;QACD,OAAO,QAAQ,CAAA;IACnB,CAAC;IAED,KAAK,CAAC,WAAW,CAAC,QAAqB,EAAE,OAA0B;QAC/D,yBAAyB;QACzB,MAAM,MAAM,GAAI,OAA0B,CAAC,wBAAyB,CAAA;QACpE,MAAM,CAAC,KAAK,CAAC,yBAAyB,GAAG,IAAA,sDAA2B,EAAC,MAAM,CAAC,CAAC,CAAA;QAC7E,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAA;QACjC,OAAO,EAAE,CAAA;IACb,CAAC;CACJ;AAnCD,0CAmCC"}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { IDhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client';
|
|
2
2
|
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
3
|
import { ProtoRpcClient } from '@streamr/proto-rpc';
|
|
4
|
-
import {
|
|
4
|
+
import { RpcRemote } from './contact/RpcRemote';
|
|
5
5
|
import { PeerID } from '../helpers/PeerID';
|
|
6
6
|
import { ServiceID } from '../types/ServiceID';
|
|
7
7
|
export interface KBucketContact {
|
|
8
8
|
id: Uint8Array;
|
|
9
9
|
vectorClock: number;
|
|
10
10
|
}
|
|
11
|
-
export declare class DhtNodeRpcRemote extends
|
|
11
|
+
export declare class DhtNodeRpcRemote extends RpcRemote<IDhtNodeRpcClient> implements KBucketContact {
|
|
12
12
|
private static counter;
|
|
13
13
|
vectorClock: number;
|
|
14
14
|
readonly id: Uint8Array;
|
|
15
15
|
constructor(localPeerDescriptor: PeerDescriptor, peerDescriptor: PeerDescriptor, client: ProtoRpcClient<IDhtNodeRpcClient>, serviceId: ServiceID, rpcRequestTimeout?: number);
|
|
16
|
-
getClosestPeers(
|
|
16
|
+
getClosestPeers(nodeId: Uint8Array): Promise<PeerDescriptor[]>;
|
|
17
17
|
ping(): Promise<boolean>;
|
|
18
18
|
leaveNotice(): void;
|
|
19
19
|
getPeerId(): PeerID;
|
|
@@ -3,19 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.DhtNodeRpcRemote = void 0;
|
|
4
4
|
const uuid_1 = require("uuid");
|
|
5
5
|
const utils_1 = require("@streamr/utils");
|
|
6
|
-
const
|
|
6
|
+
const RpcRemote_1 = require("./contact/RpcRemote");
|
|
7
7
|
const peerIdFromPeerDescriptor_1 = require("../helpers/peerIdFromPeerDescriptor");
|
|
8
8
|
const logger = new utils_1.Logger(module);
|
|
9
|
-
class DhtNodeRpcRemote extends
|
|
9
|
+
class DhtNodeRpcRemote extends RpcRemote_1.RpcRemote {
|
|
10
10
|
constructor(localPeerDescriptor, peerDescriptor, client, serviceId, rpcRequestTimeout) {
|
|
11
11
|
super(localPeerDescriptor, peerDescriptor, serviceId, client, rpcRequestTimeout);
|
|
12
12
|
this.id = this.getPeerId().value;
|
|
13
13
|
this.vectorClock = DhtNodeRpcRemote.counter++;
|
|
14
14
|
}
|
|
15
|
-
async getClosestPeers(
|
|
15
|
+
async getClosestPeers(nodeId) {
|
|
16
16
|
logger.trace(`Requesting getClosestPeers on ${this.getServiceId()} from ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.getPeerDescriptor())}`);
|
|
17
17
|
const request = {
|
|
18
|
-
|
|
18
|
+
nodeId,
|
|
19
19
|
requestId: (0, uuid_1.v4)()
|
|
20
20
|
};
|
|
21
21
|
try {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DhtNodeRpcRemote.js","sourceRoot":"","sources":["../../../src/dht/DhtNodeRpcRemote.ts"],"names":[],"mappings":";;;AAOA,+BAAyB;AACzB,0CAAuC;AAEvC,
|
|
1
|
+
{"version":3,"file":"DhtNodeRpcRemote.js","sourceRoot":"","sources":["../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AjEL,4CAkEC;AAhEkB,wBAAO,GAAG,CAAC,CAAA"}
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { IExternalApiRpc } from '../proto/packages/dht/protos/DhtRpc.server';
|
|
2
|
-
import { ExternalFindDataRequest, ExternalFindDataResponse, ExternalStoreDataRequest, ExternalStoreDataResponse, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
2
|
+
import { ExternalFindDataRequest, ExternalFindDataResponse, ExternalStoreDataRequest, ExternalStoreDataResponse, FindAction, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
3
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc';
|
|
4
4
|
import { FindResult } from './find/Finder';
|
|
5
5
|
import { Any } from '../proto/google/protobuf/any';
|
|
6
6
|
interface ExternalApiRpcLocalConfig {
|
|
7
|
-
startFind: (idToFind: Uint8Array,
|
|
8
|
-
storeDataToDht: (key: Uint8Array, data: Any) => Promise<PeerDescriptor[]>;
|
|
7
|
+
startFind: (idToFind: Uint8Array, action: FindAction, excludedPeer: PeerDescriptor) => Promise<FindResult>;
|
|
8
|
+
storeDataToDht: (key: Uint8Array, data: Any, creator: PeerDescriptor) => Promise<PeerDescriptor[]>;
|
|
9
9
|
}
|
|
10
10
|
export declare class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
11
11
|
private readonly config;
|
|
12
12
|
constructor(config: ExternalApiRpcLocalConfig);
|
|
13
13
|
externalFindData(findDataRequest: ExternalFindDataRequest, context: ServerCallContext): Promise<ExternalFindDataResponse>;
|
|
14
|
-
externalStoreData(request: ExternalStoreDataRequest): Promise<ExternalStoreDataResponse>;
|
|
14
|
+
externalStoreData(request: ExternalStoreDataRequest, context: ServerCallContext): Promise<ExternalStoreDataResponse>;
|
|
15
15
|
}
|
|
16
16
|
export {};
|
|
@@ -8,19 +8,12 @@ class ExternalApiRpcLocal {
|
|
|
8
8
|
}
|
|
9
9
|
async externalFindData(findDataRequest, context) {
|
|
10
10
|
const senderPeerDescriptor = context.incomingSourceDescriptor;
|
|
11
|
-
const result = await this.config.startFind(findDataRequest.
|
|
12
|
-
|
|
13
|
-
return DhtRpc_1.ExternalFindDataResponse.create({ dataEntries: result.dataEntries });
|
|
14
|
-
}
|
|
15
|
-
else {
|
|
16
|
-
return DhtRpc_1.ExternalFindDataResponse.create({
|
|
17
|
-
dataEntries: [],
|
|
18
|
-
error: 'Could not find data with the given key'
|
|
19
|
-
});
|
|
20
|
-
}
|
|
11
|
+
const result = await this.config.startFind(findDataRequest.key, DhtRpc_1.FindAction.FETCH_DATA, senderPeerDescriptor);
|
|
12
|
+
return DhtRpc_1.ExternalFindDataResponse.create({ entries: result.dataEntries ?? [] });
|
|
21
13
|
}
|
|
22
|
-
async externalStoreData(request) {
|
|
23
|
-
const
|
|
14
|
+
async externalStoreData(request, context) {
|
|
15
|
+
const senderPeerDescriptor = context.incomingSourceDescriptor;
|
|
16
|
+
const result = await this.config.storeDataToDht(request.key, request.data, senderPeerDescriptor);
|
|
24
17
|
return DhtRpc_1.ExternalStoreDataResponse.create({
|
|
25
18
|
storers: result
|
|
26
19
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExternalApiRpcLocal.js","sourceRoot":"","sources":["../../../src/dht/ExternalApiRpcLocal.ts"],"names":[],"mappings":";;;AACA,
|
|
1
|
+
{"version":3,"file":"ExternalApiRpcLocal.js","sourceRoot":"","sources":["../../../src/dht/ExternalApiRpcLocal.ts"],"names":[],"mappings":";;;AACA,gEAO4C;AAW5C,MAAa,mBAAmB;IAI5B,YAAY,MAAiC;QACzC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,gBAAgB,CAAC,eAAwC,EAAE,OAA0B;QACvF,MAAM,oBAAoB,GAAI,OAA0B,CAAC,wBAAyB,CAAA;QAClF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,eAAe,CAAC,GAAG,EAAE,mBAAU,CAAC,UAAU,EAAE,oBAAoB,CAAC,CAAA;QAC5G,OAAO,iCAAwB,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC,CAAA;IACjF,CAAC;IAED,KAAK,CAAC,iBAAiB,CAAC,OAAiC,EAAE,OAA0B;QACjF,MAAM,oBAAoB,GAAI,OAA0B,CAAC,wBAAyB,CAAA;QAClF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,IAAK,EAAE,oBAAoB,CAAC,CAAA;QACjG,OAAO,kCAAyB,CAAC,MAAM,CAAC;YACpC,OAAO,EAAE,MAAM;SAClB,CAAC,CAAA;IACN,CAAC;CACJ;AArBD,kDAqBC"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { Any } from '../proto/google/protobuf/any';
|
|
2
2
|
import { DataEntry, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
3
|
import { IExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client';
|
|
4
|
-
import {
|
|
5
|
-
export declare class ExternalApiRpcRemote extends
|
|
6
|
-
externalFindData(
|
|
4
|
+
import { RpcRemote } from './contact/RpcRemote';
|
|
5
|
+
export declare class ExternalApiRpcRemote extends RpcRemote<IExternalApiRpcClient> {
|
|
6
|
+
externalFindData(key: Uint8Array): Promise<DataEntry[]>;
|
|
7
7
|
storeData(key: Uint8Array, data: Any): Promise<PeerDescriptor[]>;
|
|
8
8
|
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ExternalApiRpcRemote = void 0;
|
|
4
|
-
const
|
|
5
|
-
class ExternalApiRpcRemote extends
|
|
6
|
-
async externalFindData(
|
|
4
|
+
const RpcRemote_1 = require("./contact/RpcRemote");
|
|
5
|
+
class ExternalApiRpcRemote extends RpcRemote_1.RpcRemote {
|
|
6
|
+
async externalFindData(key) {
|
|
7
7
|
const request = {
|
|
8
|
-
|
|
8
|
+
key
|
|
9
9
|
};
|
|
10
10
|
const options = this.formDhtRpcOptions({
|
|
11
11
|
timeout: 10000
|
|
12
12
|
});
|
|
13
13
|
try {
|
|
14
14
|
const data = await this.getClient().externalFindData(request, options);
|
|
15
|
-
return data.
|
|
15
|
+
return data.entries;
|
|
16
16
|
}
|
|
17
17
|
catch (err) {
|
|
18
18
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExternalApiRpcRemote.js","sourceRoot":"","sources":["../../../src/dht/ExternalApiRpcRemote.ts"],"names":[],"mappings":";;;AAGA,
|
|
1
|
+
{"version":3,"file":"ExternalApiRpcRemote.js","sourceRoot":"","sources":["../../../src/dht/ExternalApiRpcRemote.ts"],"names":[],"mappings":";;;AAGA,mDAA+C;AAE/C,MAAa,oBAAqB,SAAQ,qBAAgC;IAEtE,KAAK,CAAC,gBAAgB,CAAC,GAAe;QAClC,MAAM,OAAO,GAA4B;YACrC,GAAG;SACN,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,OAAO,EAAE,KAAK;SACjB,CAAC,CAAA;QACF,IAAI;YACA,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YACtE,OAAO,IAAI,CAAC,OAAO,CAAA;SACtB;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,EAAE,CAAA;SACZ;IACL,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,GAAe,EAAE,IAAS;QACtC,MAAM,OAAO,GAA6B;YACtC,GAAG;YACH,IAAI;SACP,CAAA;QACD,MAAM,OAAO,GAAG,IAAI,CAAC,iBAAiB,CAAC;YACnC,OAAO,EAAE,KAAK;SACjB,CAAC,CAAA;QACF,IAAI;YACA,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;YAC3E,OAAO,QAAQ,CAAC,OAAO,CAAA;SAC1B;QAAC,OAAO,GAAG,EAAE;YACV,OAAO,EAAE,CAAA;SACZ;IACL,CAAC;CACJ;AAhCD,oDAgCC"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { PeerID, PeerIDKey } from '../helpers/PeerID';
|
|
2
|
+
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
3
|
+
import { DhtNodeRpcRemote } from './DhtNodeRpcRemote';
|
|
4
|
+
import { ConnectionManager } from '../connection/ConnectionManager';
|
|
5
|
+
import EventEmitter from 'eventemitter3';
|
|
6
|
+
interface PeerManagerConfig {
|
|
7
|
+
numberOfNodesPerKBucket: number;
|
|
8
|
+
maxContactListSize: number;
|
|
9
|
+
peerDiscoveryQueryBatchSize: number;
|
|
10
|
+
ownPeerId: PeerID;
|
|
11
|
+
connectionManager: ConnectionManager;
|
|
12
|
+
isLayer0: boolean;
|
|
13
|
+
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => DhtNodeRpcRemote;
|
|
14
|
+
}
|
|
15
|
+
export interface PeerManagerEvents {
|
|
16
|
+
newContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void;
|
|
17
|
+
contactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void;
|
|
18
|
+
newRandomContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void;
|
|
19
|
+
randomContactRemoved: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void;
|
|
20
|
+
kBucketEmpty: () => void;
|
|
21
|
+
}
|
|
22
|
+
export declare const getDistance: (peerId1: Uint8Array, peerId2: Uint8Array) => number;
|
|
23
|
+
export declare class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
24
|
+
private bucket?;
|
|
25
|
+
readonly connections: Map<PeerIDKey, DhtNodeRpcRemote>;
|
|
26
|
+
private contacts?;
|
|
27
|
+
private randomPeers?;
|
|
28
|
+
private readonly config;
|
|
29
|
+
private stopped;
|
|
30
|
+
constructor(config: PeerManagerConfig);
|
|
31
|
+
private initKBuckets;
|
|
32
|
+
private onKBucketPing;
|
|
33
|
+
private onKBucketRemoved;
|
|
34
|
+
private onKBucketAdded;
|
|
35
|
+
private addClosestContactToBucket;
|
|
36
|
+
private getClosestActiveContactNotInBucket;
|
|
37
|
+
handleConnected(peerDescriptor: PeerDescriptor): void;
|
|
38
|
+
handleDisconnected(peerDescriptor: PeerDescriptor, gracefulLeave: boolean): void;
|
|
39
|
+
handlePeerLeaving(peerDescriptor: PeerDescriptor): void;
|
|
40
|
+
private removeContact;
|
|
41
|
+
stop(): void;
|
|
42
|
+
getClosestNeighborsTo(kademliaId: Uint8Array, limit?: number, excludeSet?: Set<PeerIDKey>): DhtNodeRpcRemote[];
|
|
43
|
+
getClosestContactsTo(kademliaId: Uint8Array, limit?: number, excludeSet?: Set<PeerIDKey>): DhtNodeRpcRemote[];
|
|
44
|
+
getNumberOfContacts(excludeSet?: Set<PeerIDKey>): number;
|
|
45
|
+
getNumberOfConnections(): number;
|
|
46
|
+
getNumberOfNeighbors(): number;
|
|
47
|
+
getNeighbors(): PeerDescriptor[];
|
|
48
|
+
handlePeerActive(peerId: PeerID): void;
|
|
49
|
+
handlePeerUnresponsive(peerId: PeerID): void;
|
|
50
|
+
handleNewPeers(peerDescriptors: PeerDescriptor[], setActive?: boolean): void;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,273 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PeerManager = exports.getDistance = void 0;
|
|
7
|
+
const utils_1 = require("@streamr/utils");
|
|
8
|
+
const k_bucket_1 = __importDefault(require("k-bucket"));
|
|
9
|
+
const PeerID_1 = require("../helpers/PeerID");
|
|
10
|
+
const peerIdFromPeerDescriptor_1 = require("../helpers/peerIdFromPeerDescriptor");
|
|
11
|
+
const RandomContactList_1 = require("./contact/RandomContactList");
|
|
12
|
+
const SortedContactList_1 = require("./contact/SortedContactList");
|
|
13
|
+
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
14
|
+
const logger = new utils_1.Logger(module);
|
|
15
|
+
const getDistance = (peerId1, peerId2) => {
|
|
16
|
+
return k_bucket_1.default.distance(peerId1, peerId2);
|
|
17
|
+
};
|
|
18
|
+
exports.getDistance = getDistance;
|
|
19
|
+
class PeerManager extends eventemitter3_1.default {
|
|
20
|
+
constructor(config) {
|
|
21
|
+
super();
|
|
22
|
+
// Nodes that are connected to this node on Layer0
|
|
23
|
+
this.connections = new Map();
|
|
24
|
+
this.stopped = false;
|
|
25
|
+
this.config = config;
|
|
26
|
+
this.initKBuckets();
|
|
27
|
+
}
|
|
28
|
+
initKBuckets() {
|
|
29
|
+
this.bucket = new k_bucket_1.default({
|
|
30
|
+
localNodeId: this.config.ownPeerId.value,
|
|
31
|
+
numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
|
|
32
|
+
numberOfNodesToPing: this.config.numberOfNodesPerKBucket
|
|
33
|
+
});
|
|
34
|
+
this.bucket.on('ping', (oldContacts, newContact) => this.onKBucketPing(oldContacts, newContact));
|
|
35
|
+
this.bucket.on('removed', (contact) => this.onKBucketRemoved(contact));
|
|
36
|
+
this.bucket.on('added', (contact) => this.onKBucketAdded(contact));
|
|
37
|
+
this.bucket.on('updated', () => {
|
|
38
|
+
// TODO: Update contact info to the connection manager and reconnect
|
|
39
|
+
});
|
|
40
|
+
this.contacts = new SortedContactList_1.SortedContactList({
|
|
41
|
+
referenceId: this.config.ownPeerId,
|
|
42
|
+
maxSize: this.config.maxContactListSize,
|
|
43
|
+
allowToContainReferenceId: false,
|
|
44
|
+
emitEvents: true
|
|
45
|
+
});
|
|
46
|
+
this.contacts.on('contactRemoved', (removedContact, activeContacts) => {
|
|
47
|
+
if (this.stopped) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
this.emit('contactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()));
|
|
51
|
+
this.randomPeers.addContact(this.config.createDhtNodeRpcRemote(removedContact.getPeerDescriptor()));
|
|
52
|
+
});
|
|
53
|
+
this.contacts.on('newContact', (newContact, activeContacts) => this.emit('newContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
54
|
+
this.randomPeers = new RandomContactList_1.RandomContactList(this.config.ownPeerId, this.config.maxContactListSize);
|
|
55
|
+
this.randomPeers.on('contactRemoved', (removedContact, activeContacts) => this.emit('randomContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
56
|
+
this.randomPeers.on('newContact', (newContact, activeContacts) => this.emit('newRandomContact', newContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor())));
|
|
57
|
+
}
|
|
58
|
+
onKBucketPing(oldContacts, newContact) {
|
|
59
|
+
if (this.stopped) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const sortingList = new SortedContactList_1.SortedContactList({
|
|
63
|
+
referenceId: this.config.ownPeerId,
|
|
64
|
+
maxSize: 100,
|
|
65
|
+
allowToContainReferenceId: false,
|
|
66
|
+
emitEvents: false
|
|
67
|
+
});
|
|
68
|
+
sortingList.addContacts(oldContacts);
|
|
69
|
+
const sortedContacts = sortingList.getAllContacts();
|
|
70
|
+
this.config.connectionManager?.weakUnlockConnection(sortedContacts[sortedContacts.length - 1].getPeerDescriptor());
|
|
71
|
+
this.bucket?.remove(sortedContacts[sortedContacts.length - 1].getPeerId().value);
|
|
72
|
+
this.bucket.add(newContact);
|
|
73
|
+
}
|
|
74
|
+
onKBucketRemoved(contact) {
|
|
75
|
+
if (this.stopped) {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
this.config.connectionManager?.weakUnlockConnection(contact.getPeerDescriptor());
|
|
79
|
+
logger.trace(`Removed contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())}`);
|
|
80
|
+
if (this.bucket.count() === 0) {
|
|
81
|
+
this.emit('kBucketEmpty');
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
onKBucketAdded(contact) {
|
|
85
|
+
if (this.stopped) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (!contact.getPeerId().equals(this.config.ownPeerId)) {
|
|
89
|
+
// Important to lock here, before the ping result is known
|
|
90
|
+
this.config.connectionManager?.weakLockConnection(contact.getPeerDescriptor());
|
|
91
|
+
if (this.connections.has(contact.getPeerId().toKey())) {
|
|
92
|
+
logger.trace(`Added new contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())}`);
|
|
93
|
+
}
|
|
94
|
+
else { // open connection by pinging
|
|
95
|
+
logger.trace('starting ping ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor()));
|
|
96
|
+
contact.ping().then((result) => {
|
|
97
|
+
if (result) {
|
|
98
|
+
logger.trace(`Added new contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor())}`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
logger.trace('ping failed ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor()));
|
|
102
|
+
this.config.connectionManager?.weakUnlockConnection(contact.getPeerDescriptor());
|
|
103
|
+
this.removeContact(contact.getPeerDescriptor());
|
|
104
|
+
this.addClosestContactToBucket();
|
|
105
|
+
}
|
|
106
|
+
return;
|
|
107
|
+
}).catch((_e) => {
|
|
108
|
+
this.config.connectionManager?.weakUnlockConnection(contact.getPeerDescriptor());
|
|
109
|
+
this.removeContact(contact.getPeerDescriptor());
|
|
110
|
+
this.addClosestContactToBucket();
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
addClosestContactToBucket() {
|
|
116
|
+
if (this.stopped) {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
const closest = this.getClosestActiveContactNotInBucket();
|
|
120
|
+
if (closest) {
|
|
121
|
+
this.handleNewPeers([closest.getPeerDescriptor()]);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
getClosestActiveContactNotInBucket() {
|
|
125
|
+
for (const contactId of this.contacts.getContactIds()) {
|
|
126
|
+
if (!this.bucket.get(contactId.value) && this.contacts.isActive(contactId)) {
|
|
127
|
+
return this.contacts.getContact(contactId).contact;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
return undefined;
|
|
131
|
+
}
|
|
132
|
+
handleConnected(peerDescriptor) {
|
|
133
|
+
if (PeerID_1.PeerID.fromValue(peerDescriptor.nodeId).equals(this.config.ownPeerId)) {
|
|
134
|
+
logger.error('handleConnected() to self');
|
|
135
|
+
}
|
|
136
|
+
const rpcRemote = this.config.createDhtNodeRpcRemote(peerDescriptor);
|
|
137
|
+
if (!this.connections.has(PeerID_1.PeerID.fromValue(rpcRemote.id).toKey())) {
|
|
138
|
+
this.connections.set(PeerID_1.PeerID.fromValue(rpcRemote.id).toKey(), rpcRemote);
|
|
139
|
+
logger.trace('connectionschange add ' + this.connections.size);
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
logger.trace('new connection not set to connections, there is already a connection with the peer ID');
|
|
143
|
+
}
|
|
144
|
+
logger.trace('connected: ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor) + ' ' + this.connections.size);
|
|
145
|
+
}
|
|
146
|
+
handleDisconnected(peerDescriptor, gracefulLeave) {
|
|
147
|
+
logger.trace('disconnected: ' + (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor));
|
|
148
|
+
this.connections.delete((0, peerIdFromPeerDescriptor_1.keyFromPeerDescriptor)(peerDescriptor));
|
|
149
|
+
if (this.config.isLayer0) {
|
|
150
|
+
this.bucket.remove(peerDescriptor.nodeId);
|
|
151
|
+
if (gracefulLeave === true) {
|
|
152
|
+
logger.trace((0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor) + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave);
|
|
153
|
+
this.removeContact(peerDescriptor);
|
|
154
|
+
}
|
|
155
|
+
else {
|
|
156
|
+
logger.trace((0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(peerDescriptor) + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
handlePeerLeaving(peerDescriptor) {
|
|
161
|
+
this.removeContact(peerDescriptor);
|
|
162
|
+
}
|
|
163
|
+
removeContact(contact) {
|
|
164
|
+
if (this.stopped) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
logger.trace(`Removing contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact)}`);
|
|
168
|
+
const peerId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(contact);
|
|
169
|
+
this.bucket.remove(peerId.value);
|
|
170
|
+
this.contacts.removeContact(peerId);
|
|
171
|
+
this.randomPeers.removeContact(peerId);
|
|
172
|
+
}
|
|
173
|
+
stop() {
|
|
174
|
+
this.stopped = true;
|
|
175
|
+
this.bucket.toArray().forEach((rpcRemote) => {
|
|
176
|
+
rpcRemote.leaveNotice();
|
|
177
|
+
this.bucket.remove(rpcRemote.id);
|
|
178
|
+
});
|
|
179
|
+
this.bucket.removeAllListeners();
|
|
180
|
+
this.contacts.stop();
|
|
181
|
+
this.randomPeers.stop();
|
|
182
|
+
this.connections.clear();
|
|
183
|
+
}
|
|
184
|
+
getClosestNeighborsTo(kademliaId, limit, excludeSet) {
|
|
185
|
+
const closest = new SortedContactList_1.SortedContactList({
|
|
186
|
+
referenceId: PeerID_1.PeerID.fromValue(kademliaId),
|
|
187
|
+
allowToContainReferenceId: true,
|
|
188
|
+
emitEvents: false
|
|
189
|
+
});
|
|
190
|
+
this.bucket.toArray().map((contact) => closest.addContact(contact));
|
|
191
|
+
// TODO should set the excludeSet and limit to SortedContactList constructor and remove these line
|
|
192
|
+
return closest.getClosestContacts(limit).filter((contact) => {
|
|
193
|
+
if (!excludeSet) {
|
|
194
|
+
return true;
|
|
195
|
+
}
|
|
196
|
+
else {
|
|
197
|
+
return !excludeSet.has(contact.getPeerId().toKey());
|
|
198
|
+
}
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
// TODO reduce copy-paste?
|
|
202
|
+
getClosestContactsTo(kademliaId, limit, excludeSet) {
|
|
203
|
+
const closest = new SortedContactList_1.SortedContactList({
|
|
204
|
+
referenceId: PeerID_1.PeerID.fromValue(kademliaId),
|
|
205
|
+
allowToContainReferenceId: true,
|
|
206
|
+
emitEvents: false
|
|
207
|
+
});
|
|
208
|
+
this.contacts.getAllContacts().map((contact) => closest.addContact(contact));
|
|
209
|
+
// TODO should set the excludeSet and limit to SortedContactList constructor and remove these line
|
|
210
|
+
return closest.getClosestContacts(limit).filter((contact) => {
|
|
211
|
+
if (!excludeSet) {
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
214
|
+
else {
|
|
215
|
+
return !excludeSet.has(contact.getPeerId().toKey());
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
getNumberOfContacts(excludeSet) {
|
|
220
|
+
return this.contacts.getAllContacts().filter((contact) => {
|
|
221
|
+
if (!excludeSet) {
|
|
222
|
+
return true;
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
return !excludeSet.has(contact.getPeerId().toKey());
|
|
226
|
+
}
|
|
227
|
+
}).length;
|
|
228
|
+
}
|
|
229
|
+
getNumberOfConnections() {
|
|
230
|
+
return this.connections.size;
|
|
231
|
+
}
|
|
232
|
+
getNumberOfNeighbors() {
|
|
233
|
+
return this.bucket.count();
|
|
234
|
+
}
|
|
235
|
+
getNeighbors() {
|
|
236
|
+
return this.bucket.toArray().map((rpcRemote) => rpcRemote.getPeerDescriptor());
|
|
237
|
+
}
|
|
238
|
+
handlePeerActive(peerId) {
|
|
239
|
+
this.contacts.setActive(peerId);
|
|
240
|
+
}
|
|
241
|
+
handlePeerUnresponsive(peerId) {
|
|
242
|
+
this.bucket.remove(peerId.value);
|
|
243
|
+
this.contacts.removeContact(peerId);
|
|
244
|
+
}
|
|
245
|
+
handleNewPeers(peerDescriptors, setActive) {
|
|
246
|
+
if (this.stopped) {
|
|
247
|
+
return;
|
|
248
|
+
}
|
|
249
|
+
peerDescriptors.forEach((contact) => {
|
|
250
|
+
const peerId = (0, peerIdFromPeerDescriptor_1.peerIdFromPeerDescriptor)(contact);
|
|
251
|
+
if (!peerId.equals(this.config.ownPeerId)) {
|
|
252
|
+
logger.trace(`Adding new contact ${(0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact)}`);
|
|
253
|
+
const remote = this.config.createDhtNodeRpcRemote(contact);
|
|
254
|
+
const isInBucket = (this.bucket.get(contact.nodeId) !== null);
|
|
255
|
+
const isInNeighborList = (this.contacts.getContact(peerId) !== undefined);
|
|
256
|
+
if (isInBucket || isInNeighborList) {
|
|
257
|
+
this.randomPeers.addContact(remote);
|
|
258
|
+
}
|
|
259
|
+
if (!isInBucket) {
|
|
260
|
+
this.bucket.add(remote);
|
|
261
|
+
}
|
|
262
|
+
if (!isInNeighborList) {
|
|
263
|
+
this.contacts.addContact(remote);
|
|
264
|
+
}
|
|
265
|
+
if (setActive) {
|
|
266
|
+
this.contacts.setActive(peerId);
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
exports.PeerManager = PeerManager;
|
|
273
|
+
//# sourceMappingURL=PeerManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PeerManager.js","sourceRoot":"","sources":["../../../src/dht/PeerManager.ts"],"names":[],"mappings":";;;;;;AAAA,0CAEuB;AACvB,wDAA8B;AAC9B,8CAAqD;AACrD,kFAI4C;AAK5C,mEAA+D;AAC/D,mEAA+D;AAE/D,kEAAwC;AAExC,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAoB1B,MAAM,WAAW,GAAG,CAAC,OAAmB,EAAE,OAAmB,EAAU,EAAE;IAC5E,OAAO,kBAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC,CAAA;AAC7C,CAAC,CAAA;AAFY,QAAA,WAAW,eAEvB;AAED,MAAa,WAAY,SAAQ,uBAA+B;IAkB5D,YAAY,MAAyB;QACjC,KAAK,EAAE,CAAA;QATX,kDAAkD;QAClC,gBAAW,GAAqC,IAAI,GAAG,EAAE,CAAA;QAKjE,YAAO,GAAY,KAAK,CAAA;QAI5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,YAAY,EAAE,CAAA;IACvB,CAAC;IAEO,YAAY;QAChB,IAAI,CAAC,MAAM,GAAG,IAAI,kBAAO,CAAmB;YACxC,WAAW,EAAE,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK;YACxC,uBAAuB,EAAE,IAAI,CAAC,MAAM,CAAC,uBAAuB;YAC5D,mBAAmB,EAAE,IAAI,CAAC,MAAM,CAAC,uBAAuB;SAC3D,CAAC,CAAA;QAEF,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,WAA+B,EAAE,UAA4B,EAAE,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC,W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,UAAU,CAAC,MAAM,CAAC,CAAA;iBACpC;gBACD,IAAI,SAAS,EAAE;oBACX,IAAI,CAAC,QAAS,CAAC,SAAS,CAAC,MAAM,CAAC,CAAA;iBACnC;aACJ;QACL,CAAC,CAAC,CAAA;IACN,CAAC;CACJ;AA9RD,kCA8RC"}
|
|
@@ -19,7 +19,7 @@ export declare class ContactList<C extends {
|
|
|
19
19
|
protected maxSize: number;
|
|
20
20
|
protected defaultContactQueryLimit: number;
|
|
21
21
|
constructor(ownId: PeerID, maxSize: number, defaultContactQueryLimit?: number);
|
|
22
|
-
getContact(id: PeerID): ContactState<C
|
|
22
|
+
getContact(id: PeerID): ContactState<C> | undefined;
|
|
23
23
|
getSize(): number;
|
|
24
24
|
clear(): void;
|
|
25
25
|
stop(): void;
|
|
@@ -17,6 +17,7 @@ class ContactList extends eventemitter3_1.default {
|
|
|
17
17
|
constructor(ownId, maxSize, defaultContactQueryLimit = 20) {
|
|
18
18
|
super();
|
|
19
19
|
this.contactsById = new Map();
|
|
20
|
+
// TODO move this to SortedContactList
|
|
20
21
|
this.contactIds = [];
|
|
21
22
|
this.ownId = ownId;
|
|
22
23
|
this.maxSize = maxSize;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/ContactList.ts"],"names":[],"mappings":";;;;;;AACA,kEAAwC;AAExC,MAAa,YAAY;IAKrB,YAAY,OAAU;QAJf,cAAS,GAAG,KAAK,CAAA;QACjB,WAAM,GAAG,KAAK,CAAA;QAIjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;CACJ;AARD,oCAQC;AAOD,MAAa,WAAmD,SAAQ,uBAAuB;
|
|
1
|
+
{"version":3,"file":"ContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/ContactList.ts"],"names":[],"mappings":";;;;;;AACA,kEAAwC;AAExC,MAAa,YAAY;IAKrB,YAAY,OAAU;QAJf,cAAS,GAAG,KAAK,CAAA;QACjB,WAAM,GAAG,KAAK,CAAA;QAIjB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;CACJ;AARD,oCAQC;AAOD,MAAa,WAAmD,SAAQ,uBAAuB;IAS3F,YACI,KAAa,EACb,OAAe,EACf,wBAAwB,GAAG,EAAE;QAE7B,KAAK,EAAE,CAAA;QAZD,iBAAY,GAAoC,IAAI,GAAG,EAAE,CAAA;QACnE,sCAAsC;QAC5B,eAAU,GAAa,EAAE,CAAA;QAW/B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAA;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAA;IAC5D,CAAC;IAEM,UAAU,CAAC,EAAU;QACxB,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,CAAA;IAC5C,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAA;IACjC,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;IACxB,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC;CACJ;AArCD,kCAqCC"}
|
|
@@ -3,13 +3,13 @@ import { ProtoRpcClient } from '@streamr/proto-rpc';
|
|
|
3
3
|
import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions';
|
|
4
4
|
import { ServiceID } from '../../types/ServiceID';
|
|
5
5
|
export declare const EXISTING_CONNECTION_TIMEOUT = 5000;
|
|
6
|
-
export declare abstract class
|
|
6
|
+
export declare abstract class RpcRemote<T> {
|
|
7
7
|
private readonly localPeerDescriptor;
|
|
8
8
|
private readonly remotePeerDescriptor;
|
|
9
9
|
private readonly serviceId;
|
|
10
10
|
private readonly client;
|
|
11
|
-
private readonly
|
|
12
|
-
constructor(localPeerDescriptor: PeerDescriptor, remotePeerDescriptor: PeerDescriptor, serviceId: ServiceID, client: ProtoRpcClient<T>,
|
|
11
|
+
private readonly timeout?;
|
|
12
|
+
constructor(localPeerDescriptor: PeerDescriptor, remotePeerDescriptor: PeerDescriptor, serviceId: ServiceID, client: ProtoRpcClient<T>, timeout?: number);
|
|
13
13
|
getPeerDescriptor(): PeerDescriptor;
|
|
14
14
|
getLocalPeerDescriptor(): PeerDescriptor;
|
|
15
15
|
getServiceId(): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.RpcRemote = exports.EXISTING_CONNECTION_TIMEOUT = void 0;
|
|
4
4
|
const IConnection_1 = require("../../connection/IConnection");
|
|
5
5
|
const Connectivity_1 = require("../../helpers/Connectivity");
|
|
6
6
|
// Should connect directly to the server, timeout can be low
|
|
@@ -12,7 +12,7 @@ const WEBSOCKET_SERVER_TIMEOUT = 7500;
|
|
|
12
12
|
const WEBRTC_TIMEOUT = 15000;
|
|
13
13
|
// default timeout for existing connections
|
|
14
14
|
exports.EXISTING_CONNECTION_TIMEOUT = 5000;
|
|
15
|
-
const
|
|
15
|
+
const getTimeout = (localPeerDescriptor, remotePeerDescriptor) => {
|
|
16
16
|
const connectionType = (0, Connectivity_1.expectedConnectionType)(localPeerDescriptor, remotePeerDescriptor);
|
|
17
17
|
if (connectionType === IConnection_1.ConnectionType.WEBSOCKET_CLIENT) {
|
|
18
18
|
return WEBSOCKET_CLIENT_TIMEOUT;
|
|
@@ -25,13 +25,13 @@ const getRpcTimeout = (localPeerDescriptor, remotePeerDescriptor) => {
|
|
|
25
25
|
}
|
|
26
26
|
return WEBRTC_TIMEOUT;
|
|
27
27
|
};
|
|
28
|
-
class
|
|
29
|
-
constructor(localPeerDescriptor, remotePeerDescriptor, serviceId, client,
|
|
28
|
+
class RpcRemote {
|
|
29
|
+
constructor(localPeerDescriptor, remotePeerDescriptor, serviceId, client, timeout) {
|
|
30
30
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
31
31
|
this.remotePeerDescriptor = remotePeerDescriptor;
|
|
32
32
|
this.client = client;
|
|
33
33
|
this.serviceId = serviceId;
|
|
34
|
-
this.
|
|
34
|
+
this.timeout = timeout;
|
|
35
35
|
}
|
|
36
36
|
getPeerDescriptor() {
|
|
37
37
|
return this.remotePeerDescriptor;
|
|
@@ -49,10 +49,10 @@ class Remote {
|
|
|
49
49
|
return {
|
|
50
50
|
sourceDescriptor: this.localPeerDescriptor,
|
|
51
51
|
targetDescriptor: this.remotePeerDescriptor,
|
|
52
|
-
timeout: this.
|
|
52
|
+
timeout: this.timeout ?? getTimeout(this.localPeerDescriptor, this.remotePeerDescriptor),
|
|
53
53
|
...opts
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
|
-
exports.
|
|
58
|
-
//# sourceMappingURL=
|
|
57
|
+
exports.RpcRemote = RpcRemote;
|
|
58
|
+
//# sourceMappingURL=RpcRemote.js.map
|