@streamr/dht 100.0.0-testnet-two.3 → 100.0.0-testnet-three.0
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/package.json +8 -8
- package/dist/src/connection/Connection.d.ts +1 -0
- package/dist/src/connection/Connection.js +10 -3
- package/dist/src/connection/Connection.js.map +1 -1
- package/dist/src/connection/ConnectionLockHandler.d.ts +3 -3
- package/dist/src/connection/ConnectionLockHandler.js +8 -10
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.js +5 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -4
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +8 -8
- package/dist/src/connection/ConnectionManager.js +54 -57
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +3 -2
- package/dist/src/connection/ConnectorFacade.js +7 -0
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.js +3 -1
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/IConnection.d.ts +2 -7
- package/dist/src/connection/IConnection.js +1 -8
- package/dist/src/connection/IConnection.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +23 -15
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebrtcConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +5 -2
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.js +32 -20
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +13 -10
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +9 -6
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +26 -14
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +0 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +18 -17
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +10 -9
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -0
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js +7 -4
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/ServerWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ServerWebsocket.js +22 -3
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +24 -15
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +2 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +3 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.js +6 -3
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +18 -19
- package/dist/src/dht/DhtNode.js +56 -65
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +5 -4
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +2 -1
- package/dist/src/dht/DhtNodeRpcRemote.js +5 -3
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.js +4 -3
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +5 -5
- package/dist/src/dht/PeerManager.js +31 -24
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.js +3 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.js +9 -5
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.js +1 -0
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +2 -1
- package/dist/src/dht/contact/RpcRemote.js +4 -0
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.js +3 -2
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.js +8 -8
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +8 -2
- package/dist/src/dht/discovery/PeerDiscovery.js +26 -17
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +9 -9
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +3 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +6 -5
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +26 -20
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +2 -4
- package/dist/src/dht/routing/DuplicateDetector.js +10 -15
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +1 -1
- package/dist/src/dht/routing/Router.js +20 -15
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +4 -4
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +11 -9
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +2 -0
- package/dist/src/dht/routing/RoutingSession.js +27 -9
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.js +5 -4
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.js +8 -8
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.js +1 -0
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.js +3 -3
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +1 -4
- package/dist/src/exports.js +4 -7
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/Connectivity.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.js +2 -1
- package/dist/src/helpers/MapWithTtl.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptor.d.ts +3 -0
- package/dist/src/helpers/createPeerDescriptor.js +56 -0
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.d.ts +2 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js +30 -0
- package/dist/src/helpers/createPeerDescriptorSignaturePayload.js.map +1 -0
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/errors.js +2 -0
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/offering.d.ts +4 -0
- package/dist/src/helpers/offering.js +18 -0
- package/dist/src/helpers/offering.js.map +1 -0
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/identifiers.d.ts +3 -0
- package/dist/src/identifiers.js +9 -1
- package/dist/src/identifiers.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.d.ts +8 -5
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +0 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +10 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +38 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +22 -12
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +11 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -3
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +0 -1
- package/dist/src/rpc-protocol/DhtCallContext.js +8 -0
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/transport/ITransport.d.ts +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +2 -0
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +8 -8
- package/protos/DhtRpc.proto +7 -4
- package/src/connection/Connection.ts +6 -1
- package/src/connection/ConnectionLockHandler.ts +3 -3
- package/src/connection/ConnectionLockRpcLocal.ts +1 -5
- package/src/connection/ConnectionLockRpcRemote.ts +1 -1
- package/src/connection/ConnectionManager.ts +24 -40
- package/src/connection/ConnectorFacade.ts +3 -2
- package/src/connection/IConnection.ts +2 -8
- package/src/connection/ManagedConnection.ts +3 -3
- package/src/connection/connectivityRequestHandler.ts +7 -3
- package/src/connection/simulator/Simulator.ts +1 -2
- package/src/connection/simulator/SimulatorConnection.ts +1 -1
- package/src/connection/simulator/SimulatorConnector.ts +1 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +4 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +5 -4
- package/src/connection/webrtc/WebrtcConnector.ts +9 -17
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +7 -7
- package/src/connection/websocket/ClientWebsocket.ts +3 -2
- package/src/connection/websocket/ServerWebsocket.ts +17 -1
- package/src/connection/websocket/WebsocketConnector.ts +10 -9
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +4 -2
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +1 -1
- package/src/connection/websocket/WebsocketServer.ts +2 -2
- package/src/dht/DhtNode.ts +63 -86
- package/src/dht/DhtNodeRpcLocal.ts +5 -5
- package/src/dht/DhtNodeRpcRemote.ts +3 -3
- package/src/dht/ExternalApiRpcLocal.ts +3 -4
- package/src/dht/PeerManager.ts +14 -20
- package/src/dht/contact/Contact.ts +1 -2
- package/src/dht/contact/RpcRemote.ts +2 -1
- package/src/dht/discovery/DiscoverySession.ts +2 -3
- package/src/dht/discovery/PeerDiscovery.ts +16 -9
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +12 -6
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +1 -1
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +3 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +19 -9
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +13 -3
- package/src/dht/routing/DuplicateDetector.ts +9 -21
- package/src/dht/routing/Router.ts +12 -11
- package/src/dht/routing/RouterRpcLocal.ts +1 -2
- package/src/dht/routing/RouterRpcRemote.ts +5 -5
- package/src/dht/routing/RoutingSession.ts +22 -2
- package/src/dht/store/StoreManager.ts +1 -2
- package/src/dht/store/StoreRpcRemote.ts +1 -1
- package/src/exports.ts +9 -4
- package/src/helpers/createPeerDescriptor.ts +56 -0
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +28 -0
- package/src/helpers/offering.ts +15 -0
- package/src/identifiers.ts +10 -1
- package/src/proto/google/protobuf/any.ts +12 -9
- package/src/proto/google/protobuf/empty.ts +2 -5
- package/src/proto/google/protobuf/timestamp.ts +14 -5
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -7
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +32 -20
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/rpc-protocol/DhtCallContext.ts +0 -1
- package/src/transport/ITransport.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +1 -1
- package/test/benchmark/Find.test.ts +6 -8
- package/test/benchmark/KademliaCorrectness.test.ts +2 -3
- package/test/benchmark/SortedContactListBenchmark.test.ts +16 -16
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +1 -1
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +8 -8
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +8 -8
- 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 +12 -12
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +18 -18
- package/test/end-to-end/Layer0Webrtc.test.ts +13 -10
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +3 -3
- package/test/end-to-end/memory-leak.test.ts +2 -2
- package/test/integration/ConnectionLocking.test.ts +60 -47
- package/test/integration/ConnectionManager.test.ts +8 -7
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -2
- package/test/integration/DhtNodeExternalAPI.test.ts +1 -2
- package/test/integration/DhtNodeRpcRemote.test.ts +4 -3
- package/test/integration/DhtRpc.test.ts +4 -3
- package/test/integration/Find.test.ts +4 -6
- package/test/integration/Layer1-scale.test.ts +7 -7
- package/test/integration/Mock-Layer1-Layer0.test.ts +21 -24
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +52 -161
- package/test/integration/RouteMessage.test.ts +24 -47
- package/test/integration/RouterRpcRemote.test.ts +7 -4
- package/test/integration/ScaleDownDht.test.ts +2 -3
- package/test/integration/SimultaneousConnections.test.ts +9 -8
- package/test/integration/Store.test.ts +1 -2
- package/test/integration/StoreAndDelete.test.ts +5 -0
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +59 -0
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +1 -1
- package/test/integration/StoreRpcRemote.test.ts +4 -4
- package/test/integration/WebrtcConnectionManagement.test.ts +6 -5
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -2
- package/test/integration/WebsocketConnectionManagement.test.ts +27 -15
- package/test/integration/WebsocketConnectorRpc.test.ts +3 -2
- package/test/integration/{RpcErrors.test.ts → rpc-connections-over-webrpc.test.ts} +6 -3
- package/test/unit/DuplicateDetector.test.ts +2 -2
- package/test/unit/LocalDataStore.test.ts +1 -4
- package/test/unit/RandomContactList.test.ts +2 -4
- package/test/unit/RecursiveOperationManager.test.ts +5 -6
- package/test/unit/RecursiveOperationSession.test.ts +5 -4
- package/test/unit/Router.test.ts +25 -8
- package/test/unit/RoutingSession.test.ts +3 -3
- package/test/unit/SortedContactList.test.ts +2 -4
- package/test/unit/connectivityRequestHandler.test.ts +5 -3
- package/test/unit/createPeerDescriptor.test.ts +63 -0
- package/test/utils/FakeTransport.ts +7 -4
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +6 -6
- package/dist/src/helpers/PeerID.d.ts +0 -27
- package/dist/src/helpers/PeerID.js +0 -87
- package/dist/src/helpers/PeerID.js.map +0 -1
- package/dist/src/helpers/UUID.d.ts +0 -8
- package/dist/src/helpers/UUID.js +0 -36
- package/dist/src/helpers/UUID.js.map +0 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +0 -7
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -23
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +0 -1
- package/src/helpers/PeerID.ts +0 -97
- package/src/helpers/UUID.ts +0 -35
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -20
- package/test/unit/PeerID.test.ts +0 -22
- package/test/unit/UUID.test.ts +0 -55
package/src/dht/PeerManager.ts
CHANGED
|
@@ -2,9 +2,6 @@ import {
|
|
|
2
2
|
Logger
|
|
3
3
|
} from '@streamr/utils'
|
|
4
4
|
import KBucket from 'k-bucket'
|
|
5
|
-
import {
|
|
6
|
-
getNodeIdFromPeerDescriptor
|
|
7
|
-
} from '../helpers/peerIdFromPeerDescriptor'
|
|
8
5
|
import {
|
|
9
6
|
PeerDescriptor
|
|
10
7
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
@@ -13,7 +10,7 @@ import { RandomContactList } from './contact/RandomContactList'
|
|
|
13
10
|
import { SortedContactList } from './contact/SortedContactList'
|
|
14
11
|
import { ConnectionManager } from '../connection/ConnectionManager'
|
|
15
12
|
import EventEmitter from 'eventemitter3'
|
|
16
|
-
import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../identifiers'
|
|
13
|
+
import { DhtAddress, DhtAddressRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../identifiers'
|
|
17
14
|
|
|
18
15
|
const logger = new Logger(module)
|
|
19
16
|
|
|
@@ -66,7 +63,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
66
63
|
numberOfNodesToPing: this.config.numberOfNodesPerKBucket
|
|
67
64
|
})
|
|
68
65
|
this.bucket.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
|
|
69
|
-
this.bucket.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(contact))
|
|
66
|
+
this.bucket.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
|
|
70
67
|
this.bucket.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
|
|
71
68
|
this.bucket.on('updated', () => {
|
|
72
69
|
// TODO: Update contact info to the connection manager and reconnect
|
|
@@ -114,11 +111,10 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
114
111
|
this.bucket.add(newContact)
|
|
115
112
|
}
|
|
116
113
|
|
|
117
|
-
private onKBucketRemoved(
|
|
114
|
+
private onKBucketRemoved(nodeId: DhtAddress): void {
|
|
118
115
|
if (this.stopped) {
|
|
119
116
|
return
|
|
120
117
|
}
|
|
121
|
-
const nodeId = getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())
|
|
122
118
|
this.config.connectionManager?.weakUnlockConnection(nodeId)
|
|
123
119
|
logger.trace(`Removed contact ${nodeId}`)
|
|
124
120
|
if (this.bucket.count() === 0) {
|
|
@@ -145,13 +141,13 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
145
141
|
} else {
|
|
146
142
|
logger.trace('ping failed ' + nodeId)
|
|
147
143
|
this.config.connectionManager?.weakUnlockConnection(nodeId)
|
|
148
|
-
this.removeContact(
|
|
144
|
+
this.removeContact(nodeId)
|
|
149
145
|
this.addClosestContactToBucket()
|
|
150
146
|
}
|
|
151
147
|
return
|
|
152
148
|
}).catch((_e) => {
|
|
153
149
|
this.config.connectionManager?.weakUnlockConnection(nodeId)
|
|
154
|
-
this.removeContact(
|
|
150
|
+
this.removeContact(nodeId)
|
|
155
151
|
this.addClosestContactToBucket()
|
|
156
152
|
})
|
|
157
153
|
}
|
|
@@ -192,30 +188,28 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
192
188
|
logger.trace('connected: ' + nodeId + ' ' + this.connections.size)
|
|
193
189
|
}
|
|
194
190
|
|
|
195
|
-
handleDisconnected(
|
|
196
|
-
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
191
|
+
handleDisconnected(nodeId: DhtAddress, gracefulLeave: boolean): void {
|
|
197
192
|
logger.trace('disconnected: ' + nodeId)
|
|
198
193
|
this.connections.delete(nodeId)
|
|
199
194
|
if (this.config.isLayer0) {
|
|
200
|
-
this.bucket.remove(
|
|
195
|
+
this.bucket.remove(getRawFromDhtAddress(nodeId))
|
|
201
196
|
if (gracefulLeave === true) {
|
|
202
197
|
logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
|
|
203
|
-
this.removeContact(
|
|
198
|
+
this.removeContact(nodeId)
|
|
204
199
|
} else {
|
|
205
200
|
logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
|
|
206
201
|
}
|
|
207
202
|
}
|
|
208
203
|
}
|
|
209
204
|
|
|
210
|
-
handlePeerLeaving(
|
|
211
|
-
this.removeContact(
|
|
205
|
+
handlePeerLeaving(nodeId: DhtAddress): void {
|
|
206
|
+
this.removeContact(nodeId)
|
|
212
207
|
}
|
|
213
208
|
|
|
214
|
-
private removeContact(
|
|
209
|
+
private removeContact(nodeId: DhtAddress): void {
|
|
215
210
|
if (this.stopped) {
|
|
216
211
|
return
|
|
217
212
|
}
|
|
218
|
-
const nodeId = getNodeIdFromPeerDescriptor(contact)
|
|
219
213
|
logger.trace(`Removing contact ${nodeId}`)
|
|
220
214
|
this.bucket.remove(getRawFromDhtAddress(nodeId))
|
|
221
215
|
this.contacts.removeContact(nodeId)
|
|
@@ -258,7 +252,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
258
252
|
return closest.getClosestContacts(limit)
|
|
259
253
|
}
|
|
260
254
|
|
|
261
|
-
|
|
255
|
+
getContactCount(excludedNodeIds?: Set<DhtAddress>): number {
|
|
262
256
|
return this.contacts.getAllContacts().filter((contact) => {
|
|
263
257
|
if (!excludedNodeIds) {
|
|
264
258
|
return true
|
|
@@ -268,11 +262,11 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
268
262
|
}).length
|
|
269
263
|
}
|
|
270
264
|
|
|
271
|
-
|
|
265
|
+
getConnectionCount(): number {
|
|
272
266
|
return this.connections.size
|
|
273
267
|
}
|
|
274
268
|
|
|
275
|
-
|
|
269
|
+
getNeighborCount(): number {
|
|
276
270
|
return this.bucket.count()
|
|
277
271
|
}
|
|
278
272
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
2
|
-
import { getNodeIdFromPeerDescriptor } from '../../
|
|
3
|
-
import { DhtAddress } from '../../identifiers'
|
|
2
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
4
3
|
|
|
5
4
|
export class Contact {
|
|
6
5
|
|
|
@@ -4,6 +4,7 @@ import { ConnectionType } from '../../connection/IConnection'
|
|
|
4
4
|
import { expectedConnectionType } from '../../helpers/Connectivity'
|
|
5
5
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
|
|
7
|
+
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
7
8
|
|
|
8
9
|
// Should connect directly to the server, timeout can be low
|
|
9
10
|
const WEBSOCKET_CLIENT_TIMEOUT = 5000
|
|
@@ -37,7 +38,7 @@ export abstract class RpcRemote<T extends ServiceInfo & ClassType> {
|
|
|
37
38
|
constructor(
|
|
38
39
|
localPeerDescriptor: PeerDescriptor,
|
|
39
40
|
remotePeerDescriptor: PeerDescriptor,
|
|
40
|
-
rpcCommunicator: RpcCommunicator
|
|
41
|
+
rpcCommunicator: RpcCommunicator<DhtCallContext>,
|
|
41
42
|
// eslint-disable-next-line @typescript-eslint/prefer-function-type
|
|
42
43
|
clientClass: { new (clientTransport: ClientTransport): T },
|
|
43
44
|
timeout?: number
|
|
@@ -4,8 +4,7 @@ import { v4 } from 'uuid'
|
|
|
4
4
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { PeerManager, getDistance } from '../PeerManager'
|
|
6
6
|
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
7
|
-
import { getNodeIdFromPeerDescriptor } from '../../
|
|
8
|
-
import { DhtAddress, getRawFromDhtAddress } from '../../identifiers'
|
|
7
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
|
|
9
8
|
|
|
10
9
|
const logger = new Logger(module)
|
|
11
10
|
|
|
@@ -107,7 +106,7 @@ export class DiscoverySession {
|
|
|
107
106
|
}
|
|
108
107
|
|
|
109
108
|
public async findClosestNodes(timeout: number): Promise<void> {
|
|
110
|
-
if (this.config.peerManager.
|
|
109
|
+
if (this.config.peerManager.getContactCount(this.config.contactedPeers) === 0) {
|
|
111
110
|
return
|
|
112
111
|
}
|
|
113
112
|
// TODO add abortController and signal it in stop()
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { DiscoverySession } from './DiscoverySession'
|
|
2
2
|
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
3
|
-
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
4
3
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { Logger, scheduleAtInterval, setAbortableTimeout } from '@streamr/utils'
|
|
6
5
|
import { ConnectionManager } from '../../connection/ConnectionManager'
|
|
7
6
|
import { PeerManager } from '../PeerManager'
|
|
8
|
-
import { DhtAddress,
|
|
7
|
+
import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
|
|
9
8
|
import { ServiceID } from '../../types/ServiceID'
|
|
10
9
|
|
|
11
10
|
interface PeerDiscoveryConfig {
|
|
@@ -19,6 +18,12 @@ interface PeerDiscoveryConfig {
|
|
|
19
18
|
peerManager: PeerManager
|
|
20
19
|
}
|
|
21
20
|
|
|
21
|
+
export const createDistantDhtAddress = (address: DhtAddress): DhtAddress => {
|
|
22
|
+
const raw = getRawFromDhtAddress(address)
|
|
23
|
+
const flipped = raw.map((val) => ~val)
|
|
24
|
+
return getDhtAddressFromRaw(flipped)
|
|
25
|
+
}
|
|
26
|
+
|
|
22
27
|
const logger = new Logger(module)
|
|
23
28
|
|
|
24
29
|
export class PeerDiscovery {
|
|
@@ -37,14 +42,16 @@ export class PeerDiscovery {
|
|
|
37
42
|
|
|
38
43
|
async joinDht(
|
|
39
44
|
entryPoints: PeerDescriptor[],
|
|
40
|
-
|
|
45
|
+
doAdditionalDistantPeerDiscovery = true,
|
|
41
46
|
retry = true
|
|
42
47
|
): Promise<void> {
|
|
43
48
|
const contactedPeers = new Set<DhtAddress>()
|
|
49
|
+
const distantJoinConfig = doAdditionalDistantPeerDiscovery
|
|
50
|
+
? { enabled: true, contactedPeers: new Set<DhtAddress>() } : { enabled: false } as const
|
|
44
51
|
await Promise.all(entryPoints.map((entryPoint) => this.joinThroughEntryPoint(
|
|
45
52
|
entryPoint,
|
|
46
53
|
contactedPeers,
|
|
47
|
-
|
|
54
|
+
distantJoinConfig,
|
|
48
55
|
retry
|
|
49
56
|
)))
|
|
50
57
|
}
|
|
@@ -53,7 +60,7 @@ export class PeerDiscovery {
|
|
|
53
60
|
entryPointDescriptor: PeerDescriptor,
|
|
54
61
|
// Note that this set is mutated by DiscoverySession
|
|
55
62
|
contactedPeers: Set<DhtAddress>,
|
|
56
|
-
|
|
63
|
+
additionalDistantJoin: { enabled: true, contactedPeers: Set<DhtAddress> } | { enabled: false },
|
|
57
64
|
retry = true
|
|
58
65
|
): Promise<void> {
|
|
59
66
|
if (this.isStopped()) {
|
|
@@ -71,8 +78,8 @@ export class PeerDiscovery {
|
|
|
71
78
|
this.config.peerManager.handleNewPeers([entryPointDescriptor])
|
|
72
79
|
const targetId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
|
|
73
80
|
const sessions = [this.createSession(targetId, contactedPeers)]
|
|
74
|
-
if (
|
|
75
|
-
sessions.push(this.createSession(
|
|
81
|
+
if (additionalDistantJoin.enabled) {
|
|
82
|
+
sessions.push(this.createSession(createDistantDhtAddress(targetId), additionalDistantJoin.contactedPeers))
|
|
76
83
|
}
|
|
77
84
|
await this.runSessions(sessions, entryPointDescriptor, retry)
|
|
78
85
|
this.config.connectionManager?.unlockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`)
|
|
@@ -100,7 +107,7 @@ export class PeerDiscovery {
|
|
|
100
107
|
logger.debug(`DHT join on ${this.config.serviceId} timed out`)
|
|
101
108
|
} finally {
|
|
102
109
|
if (!this.isStopped()) {
|
|
103
|
-
if (this.config.peerManager.
|
|
110
|
+
if (this.config.peerManager.getNeighborCount() === 0) {
|
|
104
111
|
if (retry) {
|
|
105
112
|
// TODO should we catch possible promise rejection?
|
|
106
113
|
// TODO use config option or named constant?
|
|
@@ -121,7 +128,7 @@ export class PeerDiscovery {
|
|
|
121
128
|
logger.debug(`Rejoining DHT ${this.config.serviceId}`)
|
|
122
129
|
this.rejoinOngoing = true
|
|
123
130
|
try {
|
|
124
|
-
await this.joinThroughEntryPoint(entryPoint, new Set())
|
|
131
|
+
await this.joinThroughEntryPoint(entryPoint, new Set(), { enabled: false })
|
|
125
132
|
logger.debug(`Rejoined DHT successfully ${this.config.serviceId}!`)
|
|
126
133
|
} catch (err) {
|
|
127
134
|
logger.warn(`Rejoining DHT ${this.config.serviceId} failed`)
|
|
@@ -9,7 +9,6 @@ import {
|
|
|
9
9
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
10
10
|
import { Router } from '../routing/Router'
|
|
11
11
|
import { RoutingMode } from '../routing/RoutingSession'
|
|
12
|
-
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
13
12
|
import { Logger, areEqualBinaries, runAndWaitForEvents3, wait } from '@streamr/utils'
|
|
14
13
|
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
15
14
|
import { RecursiveOperationSessionRpcRemote } from './RecursiveOperationSessionRpcRemote'
|
|
@@ -24,7 +23,7 @@ import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
|
24
23
|
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
25
24
|
import { ServiceID } from '../../types/ServiceID'
|
|
26
25
|
import { RecursiveOperationRpcLocal } from './RecursiveOperationRpcLocal'
|
|
27
|
-
import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
|
|
26
|
+
import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
|
|
28
27
|
import { getDistance } from '../PeerManager'
|
|
29
28
|
|
|
30
29
|
interface RecursiveOperationManagerConfig {
|
|
@@ -77,7 +76,7 @@ export class RecursiveOperationManager {
|
|
|
77
76
|
public async execute(
|
|
78
77
|
targetId: DhtAddress,
|
|
79
78
|
operation: RecursiveOperation,
|
|
80
|
-
excludedPeer?:
|
|
79
|
+
excludedPeer?: DhtAddress,
|
|
81
80
|
waitForCompletion = true
|
|
82
81
|
): Promise<RecursiveOperationResult> {
|
|
83
82
|
if (this.stopped) {
|
|
@@ -98,6 +97,7 @@ export class RecursiveOperationManager {
|
|
|
98
97
|
if (this.config.connections.size === 0) {
|
|
99
98
|
const dataEntries = Array.from(this.config.localDataStore.values(targetId))
|
|
100
99
|
session.onResponseReceived(
|
|
100
|
+
getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor),
|
|
101
101
|
[this.config.localPeerDescriptor],
|
|
102
102
|
[this.config.localPeerDescriptor],
|
|
103
103
|
dataEntries,
|
|
@@ -126,7 +126,7 @@ export class RecursiveOperationManager {
|
|
|
126
126
|
if (operation === RecursiveOperation.FETCH_DATA) {
|
|
127
127
|
const dataEntries = Array.from(this.config.localDataStore.values(targetId))
|
|
128
128
|
if (dataEntries.length > 0) {
|
|
129
|
-
this.sendResponse([], this.config.localPeerDescriptor, session.getId(), [], dataEntries, true)
|
|
129
|
+
this.sendResponse([this.config.localPeerDescriptor], this.config.localPeerDescriptor, session.getId(), [], dataEntries, true)
|
|
130
130
|
}
|
|
131
131
|
} else if (operation === RecursiveOperation.DELETE_DATA) {
|
|
132
132
|
this.config.localDataStore.markAsDeleted(targetId, getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor))
|
|
@@ -147,7 +147,13 @@ export class RecursiveOperationManager {
|
|
|
147
147
|
const isOwnNode = areEqualPeerDescriptors(this.config.localPeerDescriptor, targetPeerDescriptor)
|
|
148
148
|
if (isOwnNode && this.ongoingSessions.has(serviceId)) {
|
|
149
149
|
this.ongoingSessions.get(serviceId)!
|
|
150
|
-
.onResponseReceived(
|
|
150
|
+
.onResponseReceived(
|
|
151
|
+
getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor),
|
|
152
|
+
routingPath,
|
|
153
|
+
closestNodes,
|
|
154
|
+
dataEntries,
|
|
155
|
+
noCloserNodesFound
|
|
156
|
+
)
|
|
151
157
|
} else {
|
|
152
158
|
// TODO use config option or named constant?
|
|
153
159
|
const remoteCommunicator = new ListeningRpcCommunicator(serviceId, this.config.sessionTransport, { rpcRequestTimeout: 15000 })
|
|
@@ -164,7 +170,7 @@ export class RecursiveOperationManager {
|
|
|
164
170
|
}
|
|
165
171
|
}
|
|
166
172
|
|
|
167
|
-
private doRouteRequest(routedMessage: RouteMessageWrapper, excludedPeer?:
|
|
173
|
+
private doRouteRequest(routedMessage: RouteMessageWrapper, excludedPeer?: DhtAddress): RouteMessageAck {
|
|
168
174
|
if (this.stopped) {
|
|
169
175
|
return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
|
|
170
176
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
2
|
import { PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { IRecursiveOperationRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
4
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
5
4
|
import { createRouteMessageAck } from '../routing/RouterRpcLocal'
|
|
6
5
|
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
6
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
9
9
|
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
4
3
|
import { RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { RecursiveOperationRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
6
5
|
import { RpcRemote } from '../contact/RpcRemote'
|
|
7
6
|
import { getPreviousPeer } from '../routing/getPreviousPeer'
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -17,7 +17,8 @@ export class RecursiveOperationRpcRemote extends RpcRemote<RecursiveOperationRpc
|
|
|
17
17
|
message: params.message,
|
|
18
18
|
requestId: params.requestId ?? v4(),
|
|
19
19
|
reachableThrough: params.reachableThrough ?? [],
|
|
20
|
-
routingPath: params.routingPath
|
|
20
|
+
routingPath: params.routingPath,
|
|
21
|
+
parallelRootNodeIds: params.parallelRootNodeIds
|
|
21
22
|
}
|
|
22
23
|
const options = this.formDhtRpcOptions({
|
|
23
24
|
connect: false
|
|
@@ -16,10 +16,10 @@ import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicat
|
|
|
16
16
|
import { Contact } from '../contact/Contact'
|
|
17
17
|
import { SortedContactList } from '../contact/SortedContactList'
|
|
18
18
|
import { RecursiveOperationResult } from './RecursiveOperationManager'
|
|
19
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
20
19
|
import { ServiceID } from '../../types/ServiceID'
|
|
21
20
|
import { RecursiveOperationSessionRpcLocal } from './RecursiveOperationSessionRpcLocal'
|
|
22
|
-
import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
|
|
21
|
+
import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../identifiers'
|
|
22
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
23
23
|
|
|
24
24
|
export interface RecursiveOperationSessionEvents {
|
|
25
25
|
completed: () => void
|
|
@@ -45,6 +45,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
45
45
|
private timeoutTask?: NodeJS.Timeout
|
|
46
46
|
private completionEventEmitted = false
|
|
47
47
|
private noCloserNodesReceivedCounter = 0
|
|
48
|
+
private readonly noCloserNodesReceivedFrom: Set<DhtAddress> = new Set()
|
|
48
49
|
private readonly config: RecursiveOperationSessionConfig
|
|
49
50
|
|
|
50
51
|
constructor(config: RecursiveOperationSessionConfig) {
|
|
@@ -64,12 +65,18 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
64
65
|
|
|
65
66
|
private registerLocalRpcMethods() {
|
|
66
67
|
const rpcLocal = new RecursiveOperationSessionRpcLocal({
|
|
67
|
-
onResponseReceived: (
|
|
68
|
-
|
|
68
|
+
onResponseReceived: (
|
|
69
|
+
sourceId: DhtAddress,
|
|
70
|
+
routingPath: PeerDescriptor[],
|
|
71
|
+
nodes: PeerDescriptor[],
|
|
72
|
+
dataEntries: DataEntry[],
|
|
73
|
+
noCloserNodesFound: boolean
|
|
74
|
+
) => {
|
|
75
|
+
this.onResponseReceived(sourceId, routingPath, nodes, dataEntries, noCloserNodesFound)
|
|
69
76
|
}
|
|
70
77
|
})
|
|
71
78
|
this.rpcCommunicator.registerRpcNotification(RecursiveOperationResponse, 'sendResponse',
|
|
72
|
-
(req: RecursiveOperationResponse) => rpcLocal.sendResponse(req))
|
|
79
|
+
(req: RecursiveOperationResponse, context: ServerCallContext) => rpcLocal.sendResponse(req, context))
|
|
73
80
|
}
|
|
74
81
|
|
|
75
82
|
public start(serviceId: ServiceID): void {
|
|
@@ -97,7 +104,8 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
97
104
|
target: getRawFromDhtAddress(this.config.targetId),
|
|
98
105
|
sourcePeer: this.config.localPeerDescriptor,
|
|
99
106
|
reachableThrough: [],
|
|
100
|
-
routingPath: []
|
|
107
|
+
routingPath: [],
|
|
108
|
+
parallelRootNodeIds: []
|
|
101
109
|
}
|
|
102
110
|
return routeMessage
|
|
103
111
|
}
|
|
@@ -124,6 +132,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
124
132
|
}
|
|
125
133
|
|
|
126
134
|
public onResponseReceived(
|
|
135
|
+
sourceId: DhtAddress,
|
|
127
136
|
routingPath: PeerDescriptor[],
|
|
128
137
|
nodes: PeerDescriptor[],
|
|
129
138
|
dataEntries: DataEntry[],
|
|
@@ -137,8 +146,8 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
137
146
|
this.results.addContact(new Contact(descriptor))
|
|
138
147
|
})
|
|
139
148
|
this.processFoundData(dataEntries)
|
|
140
|
-
if (noCloserNodesFound) {
|
|
141
|
-
this.onNoCloserPeersFound()
|
|
149
|
+
if (noCloserNodesFound || this.noCloserNodesReceivedFrom.has(sourceId)) {
|
|
150
|
+
this.onNoCloserPeersFound(sourceId)
|
|
142
151
|
}
|
|
143
152
|
}
|
|
144
153
|
|
|
@@ -181,8 +190,9 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
|
|
|
181
190
|
})
|
|
182
191
|
}
|
|
183
192
|
|
|
184
|
-
private onNoCloserPeersFound(): void {
|
|
193
|
+
private onNoCloserPeersFound(sourceId: DhtAddress): void {
|
|
185
194
|
this.noCloserNodesReceivedCounter += 1
|
|
195
|
+
this.noCloserNodesReceivedFrom.add(sourceId)
|
|
186
196
|
if (this.isCompleted()) {
|
|
187
197
|
this.emit('completed')
|
|
188
198
|
this.completionEventEmitted = true
|
|
@@ -2,11 +2,20 @@ import { IRecursiveOperationSessionRpc } from '../../proto/packages/dht/protos/D
|
|
|
2
2
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
3
3
|
import { DataEntry, RecursiveOperationResponse, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
6
|
+
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
7
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
5
8
|
|
|
6
9
|
const logger = new Logger(module)
|
|
7
10
|
|
|
8
11
|
interface RecursiveOperationSessionRpcLocalConfig {
|
|
9
|
-
onResponseReceived: (
|
|
12
|
+
onResponseReceived: (
|
|
13
|
+
sourceId: DhtAddress,
|
|
14
|
+
routingPath: PeerDescriptor[],
|
|
15
|
+
nodes: PeerDescriptor[],
|
|
16
|
+
dataEntries: DataEntry[],
|
|
17
|
+
noCloserNodesFound: boolean
|
|
18
|
+
) => void
|
|
10
19
|
}
|
|
11
20
|
|
|
12
21
|
export class RecursiveOperationSessionRpcLocal implements IRecursiveOperationSessionRpc {
|
|
@@ -17,9 +26,10 @@ export class RecursiveOperationSessionRpcLocal implements IRecursiveOperationSes
|
|
|
17
26
|
this.config = config
|
|
18
27
|
}
|
|
19
28
|
|
|
20
|
-
async sendResponse(report: RecursiveOperationResponse): Promise<Empty> {
|
|
29
|
+
async sendResponse(report: RecursiveOperationResponse, context: ServerCallContext): Promise<Empty> {
|
|
30
|
+
const sourceId = getNodeIdFromPeerDescriptor((context as DhtCallContext).incomingSourceDescriptor!)
|
|
21
31
|
logger.trace('RecursiveOperationResponse arrived: ' + JSON.stringify(report))
|
|
22
|
-
this.config.onResponseReceived(report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
|
|
32
|
+
this.config.onResponseReceived(sourceId, report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
|
|
23
33
|
return {}
|
|
24
34
|
}
|
|
25
35
|
}
|
|
@@ -1,40 +1,28 @@
|
|
|
1
|
-
type QueueEntry = [timestamp: number, value: string]
|
|
2
|
-
|
|
3
1
|
export class DuplicateDetector {
|
|
4
2
|
|
|
5
3
|
private values: Set<string> = new Set()
|
|
6
|
-
private queue: Array<
|
|
7
|
-
private
|
|
8
|
-
private maxNumberOfValues: number
|
|
4
|
+
private queue: Array<string> = []
|
|
5
|
+
private maxItemCount: number
|
|
9
6
|
|
|
10
7
|
constructor(
|
|
11
|
-
|
|
12
|
-
maxAgeInSeconds: number
|
|
8
|
+
maxItemCount: number,
|
|
13
9
|
) {
|
|
14
|
-
this.
|
|
15
|
-
this.maxAge = maxAgeInSeconds * 1000
|
|
10
|
+
this.maxItemCount = maxItemCount
|
|
16
11
|
}
|
|
17
12
|
|
|
18
13
|
public add(value: string): void {
|
|
19
14
|
this.values.add(value)
|
|
20
|
-
this.queue.push(
|
|
21
|
-
this.
|
|
15
|
+
this.queue.push(value)
|
|
16
|
+
if (this.queue.length > this.maxItemCount) {
|
|
17
|
+
const removed = this.queue.shift()!
|
|
18
|
+
this.values.delete(removed)
|
|
19
|
+
}
|
|
22
20
|
}
|
|
23
21
|
|
|
24
22
|
public isMostLikelyDuplicate(value: string): boolean {
|
|
25
23
|
return this.values.has(value)
|
|
26
24
|
}
|
|
27
25
|
|
|
28
|
-
private cleanUp(): void {
|
|
29
|
-
const currentTime = Date.now()
|
|
30
|
-
|
|
31
|
-
while (this.queue.length > 0 && (this.queue.length > this.maxNumberOfValues ||
|
|
32
|
-
(currentTime - this.queue[0][0]) > this.maxAge)) {
|
|
33
|
-
const oldestEntry = this.queue.shift()
|
|
34
|
-
this.values.delete(oldestEntry![1])
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
26
|
public size(): number {
|
|
39
27
|
return this.values.size
|
|
40
28
|
}
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { Message, PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
2
|
-
import {
|
|
3
|
-
areEqualPeerDescriptors,
|
|
4
|
-
getNodeIdFromPeerDescriptor
|
|
5
|
-
} from '../../helpers/peerIdFromPeerDescriptor'
|
|
6
2
|
import { RoutingMode, RoutingSession, RoutingSessionEvents } from './RoutingSession'
|
|
7
3
|
import { Logger, executeSafePromise, raceEvents3, withTimeout } from '@streamr/utils'
|
|
8
4
|
import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
|
|
@@ -11,7 +7,7 @@ import { ConnectionManager } from '../../connection/ConnectionManager'
|
|
|
11
7
|
import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
|
|
12
8
|
import { v4 } from 'uuid'
|
|
13
9
|
import { RouterRpcLocal, createRouteMessageAck } from './RouterRpcLocal'
|
|
14
|
-
import { DhtAddress, getDhtAddressFromRaw } from '../../identifiers'
|
|
10
|
+
import { DhtAddress, areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
15
11
|
|
|
16
12
|
export interface RouterConfig {
|
|
17
13
|
rpcCommunicator: RoutingRpcCommunicator
|
|
@@ -33,7 +29,7 @@ export class Router {
|
|
|
33
29
|
private readonly forwardingTable: Map<DhtAddress, ForwardingTableEntry> = new Map()
|
|
34
30
|
private ongoingRoutingSessions: Map<string, RoutingSession> = new Map()
|
|
35
31
|
// TODO use config option or named constant?
|
|
36
|
-
private readonly duplicateRequestDetector: DuplicateDetector = new DuplicateDetector(100000
|
|
32
|
+
private readonly duplicateRequestDetector: DuplicateDetector = new DuplicateDetector(100000)
|
|
37
33
|
private stopped = false
|
|
38
34
|
private readonly config: RouterConfig
|
|
39
35
|
|
|
@@ -87,7 +83,8 @@ export class Router {
|
|
|
87
83
|
target: forwardingEntry.peerDescriptors[0].nodeId,
|
|
88
84
|
sourcePeer: this.config.localPeerDescriptor,
|
|
89
85
|
reachableThrough,
|
|
90
|
-
routingPath: []
|
|
86
|
+
routingPath: [],
|
|
87
|
+
parallelRootNodeIds: []
|
|
91
88
|
}
|
|
92
89
|
const ack = this.doRouteMessage(forwardedMessage, RoutingMode.FORWARD)
|
|
93
90
|
if (ack.error !== undefined) {
|
|
@@ -102,7 +99,8 @@ export class Router {
|
|
|
102
99
|
target: targetPeerDescriptor.nodeId,
|
|
103
100
|
sourcePeer: this.config.localPeerDescriptor,
|
|
104
101
|
reachableThrough,
|
|
105
|
-
routingPath: []
|
|
102
|
+
routingPath: [],
|
|
103
|
+
parallelRootNodeIds: []
|
|
106
104
|
}
|
|
107
105
|
const ack = this.doRouteMessage(routedMessage, RoutingMode.ROUTE)
|
|
108
106
|
if (ack.error !== undefined) {
|
|
@@ -113,7 +111,7 @@ export class Router {
|
|
|
113
111
|
}
|
|
114
112
|
}
|
|
115
113
|
|
|
116
|
-
public doRouteMessage(routedMessage: RouteMessageWrapper, mode = RoutingMode.ROUTE, excludedPeer?:
|
|
114
|
+
public doRouteMessage(routedMessage: RouteMessageWrapper, mode = RoutingMode.ROUTE, excludedPeer?: DhtAddress): RouteMessageAck {
|
|
117
115
|
if (this.stopped) {
|
|
118
116
|
return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
|
|
119
117
|
}
|
|
@@ -153,11 +151,14 @@ export class Router {
|
|
|
153
151
|
}
|
|
154
152
|
}
|
|
155
153
|
|
|
156
|
-
private createRoutingSession(routedMessage: RouteMessageWrapper, mode: RoutingMode, excludedNode?:
|
|
154
|
+
private createRoutingSession(routedMessage: RouteMessageWrapper, mode: RoutingMode, excludedNode?: DhtAddress): RoutingSession {
|
|
157
155
|
const excludedNodeIds = new Set<DhtAddress>(routedMessage.routingPath.map((descriptor) => getNodeIdFromPeerDescriptor(descriptor)))
|
|
158
156
|
if (excludedNode) {
|
|
159
|
-
excludedNodeIds.add(
|
|
157
|
+
excludedNodeIds.add(excludedNode)
|
|
160
158
|
}
|
|
159
|
+
routedMessage.parallelRootNodeIds.forEach((nodeId) => {
|
|
160
|
+
excludedNodeIds.add(nodeId as DhtAddress)
|
|
161
|
+
})
|
|
161
162
|
logger.trace('routing session created with connections: ' + this.config.connections.size)
|
|
162
163
|
return new RoutingSession({
|
|
163
164
|
rpcCommunicator: this.config.rpcCommunicator,
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { Logger, areEqualBinaries } from '@streamr/utils'
|
|
2
2
|
import { ConnectionManager } from '../../connection/ConnectionManager'
|
|
3
|
-
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
4
3
|
import { PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { IRouterRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
6
5
|
import { DuplicateDetector } from './DuplicateDetector'
|
|
7
6
|
import { RoutingMode } from './RoutingSession'
|
|
8
|
-
import { getDhtAddressFromRaw } from '../../identifiers'
|
|
7
|
+
import { areEqualPeerDescriptors, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
9
8
|
|
|
10
9
|
interface RouterRpcLocalConfig {
|
|
11
10
|
doRouteMessage: (routedMessage: RouteMessageWrapper, mode?: RoutingMode) => RouteMessageAck
|
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { Logger, areEqualBinaries } from '@streamr/utils'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
|
-
import {
|
|
4
|
-
getNodeIdFromPeerDescriptor
|
|
5
|
-
} from '../../helpers/peerIdFromPeerDescriptor'
|
|
6
3
|
import { RouteMessageError, RouteMessageWrapper } from '../../proto/packages/dht/protos/DhtRpc'
|
|
7
4
|
import { RouterRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
8
5
|
import { RpcRemote } from '../contact/RpcRemote'
|
|
9
6
|
import { getPreviousPeer } from './getPreviousPeer'
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
10
8
|
|
|
11
9
|
const logger = new Logger(module)
|
|
12
10
|
|
|
@@ -19,7 +17,8 @@ export class RouterRpcRemote extends RpcRemote<RouterRpcClient> {
|
|
|
19
17
|
message: params.message,
|
|
20
18
|
requestId: params.requestId ?? v4(),
|
|
21
19
|
reachableThrough: params.reachableThrough ?? [],
|
|
22
|
-
routingPath: params.routingPath
|
|
20
|
+
routingPath: params.routingPath,
|
|
21
|
+
parallelRootNodeIds: params.parallelRootNodeIds
|
|
23
22
|
}
|
|
24
23
|
const options = this.formDhtRpcOptions({
|
|
25
24
|
connect: false
|
|
@@ -53,7 +52,8 @@ export class RouterRpcRemote extends RpcRemote<RouterRpcClient> {
|
|
|
53
52
|
message: params.message,
|
|
54
53
|
requestId: params.requestId ?? v4(),
|
|
55
54
|
reachableThrough: params.reachableThrough ?? [],
|
|
56
|
-
routingPath: params.routingPath
|
|
55
|
+
routingPath: params.routingPath,
|
|
56
|
+
parallelRootNodeIds: params.parallelRootNodeIds
|
|
57
57
|
}
|
|
58
58
|
const options = this.formDhtRpcOptions({
|
|
59
59
|
connect: false
|