@streamr/dht 100.0.0-testnet-two.4 → 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 -55
- 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 -38
- 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
|
@@ -4,6 +4,7 @@ import { Message, connection as WsConnection } from 'websocket'
|
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
5
|
import { Url } from 'url'
|
|
6
6
|
import { CUSTOM_GOING_AWAY, GOING_AWAY } from './ClientWebsocket'
|
|
7
|
+
import { createRandomConnectionId } from '../Connection'
|
|
7
8
|
|
|
8
9
|
const logger = new Logger(module)
|
|
9
10
|
|
|
@@ -34,7 +35,7 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
34
35
|
this.onError = this.onError.bind(this)
|
|
35
36
|
|
|
36
37
|
this.resourceURL = resourceURL
|
|
37
|
-
this.connectionId =
|
|
38
|
+
this.connectionId = createRandomConnectionId()
|
|
38
39
|
|
|
39
40
|
socket.on('message', this.onMessage)
|
|
40
41
|
socket.on('close', this.onClose)
|
|
@@ -82,6 +83,7 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
82
83
|
// If in an Karma / Electron test, use the NodeJS implementation
|
|
83
84
|
// of Buffer instead of the browser polyfill
|
|
84
85
|
|
|
86
|
+
// TODO: no need to check this.socket as it is always defined when stopped is false?
|
|
85
87
|
if (!this.stopped && this.socket) {
|
|
86
88
|
if (typeof NodeJsBuffer !== 'undefined') {
|
|
87
89
|
this.socket.sendBytes(NodeJsBuffer.from(data))
|
|
@@ -104,6 +106,7 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
// TODO could rename to "closeSilently?"
|
|
107
110
|
public destroy(): void {
|
|
108
111
|
if (!this.stopped) {
|
|
109
112
|
this.removeAllListeners()
|
|
@@ -119,9 +122,22 @@ export class ServerWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
119
122
|
}
|
|
120
123
|
|
|
121
124
|
public getRemoteAddress(): string {
|
|
125
|
+
// TODO: no need to check this.socket as it is always defined when stopped is false?
|
|
122
126
|
if (!this.stopped && this.socket) {
|
|
123
127
|
return this.socket.remoteAddress
|
|
124
128
|
} else {
|
|
129
|
+
// TODO throw
|
|
130
|
+
logger.error('Tried to get the remoteAddress of a stopped connection')
|
|
131
|
+
return ''
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
public getRemoteIp(): string {
|
|
136
|
+
// TODO: no need to check this.socket as it is always defined when stopped is false?
|
|
137
|
+
if (!this.stopped && this.socket) {
|
|
138
|
+
return this.socket.socket.remoteAddress!
|
|
139
|
+
} else {
|
|
140
|
+
// TODO throw
|
|
125
141
|
logger.error('Tried to get the remoteAddress of a stopped connection')
|
|
126
142
|
return ''
|
|
127
143
|
}
|
|
@@ -12,14 +12,13 @@ import {
|
|
|
12
12
|
WebsocketConnectionRequest
|
|
13
13
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
14
14
|
import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
15
|
-
import { Logger, wait } from '@streamr/utils'
|
|
15
|
+
import { ipv4ToNumber, Logger, wait } from '@streamr/utils'
|
|
16
16
|
import { ManagedConnection } from '../ManagedConnection'
|
|
17
17
|
import { WebsocketServer } from './WebsocketServer'
|
|
18
18
|
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
19
19
|
import { NatType, PortRange, TlsCertificate } from '../ConnectionManager'
|
|
20
20
|
import { ServerWebsocket } from './ServerWebsocket'
|
|
21
21
|
import { Handshaker } from '../Handshaker'
|
|
22
|
-
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
23
22
|
import { ParsedUrlQuery } from 'querystring'
|
|
24
23
|
import { range, sample } from 'lodash'
|
|
25
24
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
@@ -29,7 +28,7 @@ import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
|
29
28
|
import { attachConnectivityRequestHandler } from '../connectivityRequestHandler'
|
|
30
29
|
import * as Err from '../../helpers/errors'
|
|
31
30
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
32
|
-
import { DhtAddress } from '../../identifiers'
|
|
31
|
+
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
33
32
|
import { version } from '../../../package.json'
|
|
34
33
|
import { isCompatibleVersion } from '../../helpers/versionCompatibility'
|
|
35
34
|
|
|
@@ -46,7 +45,7 @@ const ENTRY_POINT_CONNECTION_ATTEMPTS = 5
|
|
|
46
45
|
export interface WebsocketConnectorConfig {
|
|
47
46
|
transport: ITransport
|
|
48
47
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
49
|
-
hasConnection: (
|
|
48
|
+
hasConnection: (nodeId: DhtAddress) => boolean
|
|
50
49
|
portRange?: PortRange
|
|
51
50
|
maxMessageSize?: number
|
|
52
51
|
host?: string
|
|
@@ -90,12 +89,11 @@ export class WebsocketConnector {
|
|
|
90
89
|
private registerLocalRpcMethods(config: WebsocketConnectorConfig) {
|
|
91
90
|
const rpcLocal = new WebsocketConnectorRpcLocal({
|
|
92
91
|
connect: (targetPeerDescriptor: PeerDescriptor) => this.connect(targetPeerDescriptor),
|
|
93
|
-
hasConnection: (
|
|
94
|
-
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
92
|
+
hasConnection: (nodeId: DhtAddress): boolean => {
|
|
95
93
|
if (this.connectingConnections.has(nodeId)
|
|
96
94
|
|| this.connectingConnections.has(nodeId)
|
|
97
95
|
|| this.ongoingConnectRequests.has(nodeId)
|
|
98
|
-
|| config.hasConnection(
|
|
96
|
+
|| config.hasConnection(nodeId)
|
|
99
97
|
) {
|
|
100
98
|
return true
|
|
101
99
|
} else {
|
|
@@ -167,7 +165,8 @@ export class WebsocketConnector {
|
|
|
167
165
|
// TODO: this could throw if the server is not running
|
|
168
166
|
const noServerConnectivityResponse: ConnectivityResponse = {
|
|
169
167
|
host: '127.0.0.1',
|
|
170
|
-
natType: NatType.UNKNOWN
|
|
168
|
+
natType: NatType.UNKNOWN,
|
|
169
|
+
ipAddress: ipv4ToNumber('127.0.0.1')
|
|
171
170
|
}
|
|
172
171
|
if (this.abortController.signal.aborted) {
|
|
173
172
|
return noServerConnectivityResponse
|
|
@@ -183,7 +182,9 @@ export class WebsocketConnector {
|
|
|
183
182
|
const preconfiguredConnectivityResponse: ConnectivityResponse = {
|
|
184
183
|
host: this.host!,
|
|
185
184
|
natType: NatType.OPEN_INTERNET,
|
|
186
|
-
websocket: { host: this.host!, port: this.selectedPort!, tls: this.config.tlsCertificate !== undefined }
|
|
185
|
+
websocket: { host: this.host!, port: this.selectedPort!, tls: this.config.tlsCertificate !== undefined },
|
|
186
|
+
// TODO: maybe do a DNS lookup here?
|
|
187
|
+
ipAddress: ipv4ToNumber('127.0.0.1')
|
|
187
188
|
}
|
|
188
189
|
return preconfiguredConnectivityResponse
|
|
189
190
|
} else {
|
|
@@ -7,10 +7,12 @@ import { IWebsocketConnectorRpc } from '../../proto/packages/dht/protos/DhtRpc.s
|
|
|
7
7
|
import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
|
|
8
8
|
import { ManagedConnection } from '../ManagedConnection'
|
|
9
9
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
10
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
11
|
+
import { DhtAddress } from '../../identifiers'
|
|
10
12
|
|
|
11
13
|
interface WebsocketConnectorRpcLocalConfig {
|
|
12
14
|
connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
|
|
13
|
-
hasConnection: (
|
|
15
|
+
hasConnection: (nodeId: DhtAddress) => boolean
|
|
14
16
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
15
17
|
abortSignal: AbortSignal
|
|
16
18
|
}
|
|
@@ -28,7 +30,7 @@ export class WebsocketConnectorRpcLocal implements IWebsocketConnectorRpc {
|
|
|
28
30
|
return {}
|
|
29
31
|
}
|
|
30
32
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
31
|
-
if (!this.config.hasConnection(senderPeerDescriptor)) {
|
|
33
|
+
if (!this.config.hasConnection(getNodeIdFromPeerDescriptor(senderPeerDescriptor))) {
|
|
32
34
|
const connection = this.config.connect(senderPeerDescriptor)
|
|
33
35
|
this.config.onNewConnection(connection)
|
|
34
36
|
}
|
|
@@ -2,9 +2,9 @@ import {
|
|
|
2
2
|
WebsocketConnectionRequest
|
|
3
3
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
6
5
|
import { RpcRemote } from '../../dht/contact/RpcRemote'
|
|
7
6
|
import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -10,7 +10,7 @@ import { WebsocketServerStartError } from '../../helpers/errors'
|
|
|
10
10
|
import { PortRange, TlsCertificate } from '../ConnectionManager'
|
|
11
11
|
import { range } from 'lodash'
|
|
12
12
|
import fs from 'fs'
|
|
13
|
-
import {
|
|
13
|
+
import { v4 as uuid } from 'uuid'
|
|
14
14
|
|
|
15
15
|
const logger = new Logger(module)
|
|
16
16
|
|
|
@@ -77,7 +77,7 @@ export class WebsocketServer extends EventEmitter<ConnectionSourceEvents> {
|
|
|
77
77
|
this.httpServer = createHttpServer(requestListener)
|
|
78
78
|
} else {
|
|
79
79
|
// TODO use config option or named constant?
|
|
80
|
-
const certificate = createSelfSignedCertificate('streamr-self-signed-' +
|
|
80
|
+
const certificate = createSelfSignedCertificate('streamr-self-signed-' + uuid(), 1000)
|
|
81
81
|
this.httpServer = createHttpsServer({
|
|
82
82
|
key: certificate.serverKey,
|
|
83
83
|
cert: certificate.serverCert
|
package/src/dht/DhtNode.ts
CHANGED
|
@@ -1,56 +1,51 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
+
import {
|
|
3
|
+
Logger,
|
|
4
|
+
MetricsContext,
|
|
5
|
+
merge,
|
|
6
|
+
waitForCondition
|
|
7
|
+
} from '@streamr/utils'
|
|
2
8
|
import { EventEmitter } from 'eventemitter3'
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
9
|
+
import { sample } from 'lodash'
|
|
10
|
+
import { MarkRequired } from 'ts-essentials'
|
|
11
|
+
import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
|
|
12
|
+
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../connection/ConnectorFacade'
|
|
13
|
+
import { IceServer } from '../connection/webrtc/WebrtcConnector'
|
|
14
|
+
import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
|
|
15
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
16
|
+
import { Any } from '../proto/google/protobuf/any'
|
|
5
17
|
import {
|
|
6
18
|
ClosestPeersRequest,
|
|
7
19
|
ClosestPeersResponse,
|
|
8
|
-
LeaveNotice,
|
|
9
20
|
ConnectivityResponse,
|
|
10
|
-
Message,
|
|
11
|
-
NodeType,
|
|
12
|
-
PeerDescriptor,
|
|
13
|
-
PingRequest,
|
|
14
|
-
PingResponse,
|
|
15
21
|
DataEntry,
|
|
16
22
|
ExternalFindDataRequest,
|
|
17
23
|
ExternalFindDataResponse,
|
|
18
24
|
ExternalStoreDataRequest,
|
|
19
25
|
ExternalStoreDataResponse,
|
|
20
|
-
|
|
26
|
+
LeaveNotice,
|
|
27
|
+
Message,
|
|
28
|
+
PeerDescriptor,
|
|
29
|
+
PingRequest,
|
|
30
|
+
PingResponse,
|
|
31
|
+
RecursiveOperation
|
|
21
32
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
22
|
-
import { ITransport, TransportEvents } from '../transport/ITransport'
|
|
23
|
-
import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
|
|
24
33
|
import { ExternalApiRpcClient, StoreRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
25
|
-
import {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
merge,
|
|
29
|
-
waitForCondition
|
|
30
|
-
} from '@streamr/utils'
|
|
31
|
-
import { Any } from '../proto/google/protobuf/any'
|
|
32
|
-
import {
|
|
33
|
-
getNodeIdFromPeerDescriptor
|
|
34
|
-
} from '../helpers/peerIdFromPeerDescriptor'
|
|
35
|
-
import { Router } from './routing/Router'
|
|
36
|
-
import { RecursiveOperationManager, RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
|
|
37
|
-
import { StoreManager } from './store/StoreManager'
|
|
38
|
-
import { PeerDiscovery } from './discovery/PeerDiscovery'
|
|
39
|
-
import { LocalDataStore } from './store/LocalDataStore'
|
|
40
|
-
import { IceServer } from '../connection/webrtc/WebrtcConnector'
|
|
41
|
-
import { ExternalApiRpcRemote } from './ExternalApiRpcRemote'
|
|
42
|
-
import { UUID } from '../helpers/UUID'
|
|
43
|
-
import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
|
|
44
|
-
import { sample } from 'lodash'
|
|
45
|
-
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../connection/ConnectorFacade'
|
|
46
|
-
import { MarkRequired } from 'ts-essentials'
|
|
34
|
+
import { ITransport, TransportEvents } from '../transport/ITransport'
|
|
35
|
+
import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
|
|
36
|
+
import { ServiceID } from '../types/ServiceID'
|
|
47
37
|
import { DhtNodeRpcLocal } from './DhtNodeRpcLocal'
|
|
48
|
-
import {
|
|
38
|
+
import { DhtNodeRpcRemote } from './DhtNodeRpcRemote'
|
|
49
39
|
import { ExternalApiRpcLocal } from './ExternalApiRpcLocal'
|
|
40
|
+
import { ExternalApiRpcRemote } from './ExternalApiRpcRemote'
|
|
50
41
|
import { PeerManager } from './PeerManager'
|
|
51
|
-
import {
|
|
52
|
-
import {
|
|
42
|
+
import { PeerDiscovery } from './discovery/PeerDiscovery'
|
|
43
|
+
import { RecursiveOperationManager, RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
|
|
44
|
+
import { Router } from './routing/Router'
|
|
45
|
+
import { LocalDataStore } from './store/LocalDataStore'
|
|
46
|
+
import { StoreManager } from './store/StoreManager'
|
|
53
47
|
import { StoreRpcRemote } from './store/StoreRpcRemote'
|
|
48
|
+
import { createPeerDescriptor } from '../helpers/createPeerDescriptor'
|
|
54
49
|
|
|
55
50
|
export interface DhtNodeEvents {
|
|
56
51
|
newContact: (peerDescriptor: PeerDescriptor, closestPeers: PeerDescriptor[]) => void
|
|
@@ -79,7 +74,7 @@ export interface DhtNodeOptions {
|
|
|
79
74
|
websocketHost?: string
|
|
80
75
|
websocketPortRange?: PortRange
|
|
81
76
|
websocketServerEnableTls?: boolean
|
|
82
|
-
|
|
77
|
+
nodeId?: DhtAddress
|
|
83
78
|
|
|
84
79
|
rpcRequestTimeout?: number
|
|
85
80
|
iceServers?: IceServer[]
|
|
@@ -109,28 +104,12 @@ type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
|
|
|
109
104
|
'storeMaxTtl' |
|
|
110
105
|
'networkConnectivityTimeout' |
|
|
111
106
|
'storageRedundancyFactor' |
|
|
112
|
-
'metricsContext'
|
|
113
|
-
'peerId'>
|
|
107
|
+
'metricsContext'>
|
|
114
108
|
|
|
115
109
|
const logger = new Logger(module)
|
|
116
110
|
|
|
117
111
|
export type Events = TransportEvents & DhtNodeEvents
|
|
118
112
|
|
|
119
|
-
export const createPeerDescriptor = (msg?: ConnectivityResponse, peerId?: string): PeerDescriptor => {
|
|
120
|
-
let nodeId: DhtAddressRaw
|
|
121
|
-
if (msg) {
|
|
122
|
-
nodeId = (peerId !== undefined) ? getRawFromDhtAddress(peerId as DhtAddress) : PeerID.fromIp(msg.host).value
|
|
123
|
-
} else {
|
|
124
|
-
nodeId = getRawFromDhtAddress(peerId! as DhtAddress)
|
|
125
|
-
}
|
|
126
|
-
const nodeType = isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS
|
|
127
|
-
const ret: PeerDescriptor = { nodeId, type: nodeType }
|
|
128
|
-
if (msg && msg.websocket) {
|
|
129
|
-
ret.websocket = { host: msg.websocket.host, port: msg.websocket.port, tls: msg.websocket.tls }
|
|
130
|
-
}
|
|
131
|
-
return ret
|
|
132
|
-
}
|
|
133
|
-
|
|
134
113
|
export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
135
114
|
|
|
136
115
|
private readonly config: StrictDhtNodeOptions
|
|
@@ -162,10 +141,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
162
141
|
storeMaxTtl: 60000,
|
|
163
142
|
networkConnectivityTimeout: 10000,
|
|
164
143
|
storageRedundancyFactor: 5,
|
|
165
|
-
metricsContext: new MetricsContext()
|
|
166
|
-
peerId: new UUID().toHex()
|
|
144
|
+
metricsContext: new MetricsContext()
|
|
167
145
|
}, conf)
|
|
168
|
-
this.localDataStore = new LocalDataStore(this.config.storeMaxTtl)
|
|
146
|
+
this.localDataStore = new LocalDataStore(this.config.storeMaxTtl)
|
|
169
147
|
this.send = this.send.bind(this)
|
|
170
148
|
}
|
|
171
149
|
|
|
@@ -214,7 +192,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
214
192
|
min: this.config.peerDescriptor.websocket.port,
|
|
215
193
|
max: this.config.peerDescriptor.websocket.port
|
|
216
194
|
}
|
|
217
|
-
|
|
195
|
+
// If websocketPortRange is given, create ws server using it, websocketHost can be undefined
|
|
218
196
|
} else if (this.config.websocketPortRange) {
|
|
219
197
|
connectorFacadeConfig.websocketHost = this.config.websocketHost
|
|
220
198
|
connectorFacadeConfig.websocketPortRange = this.config.websocketPortRange
|
|
@@ -334,10 +312,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
334
312
|
this.emit('connected', peerDescriptor)
|
|
335
313
|
})
|
|
336
314
|
this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
|
|
337
|
-
this.peerManager!.handleDisconnected(peerDescriptor, gracefulLeave)
|
|
315
|
+
this.peerManager!.handleDisconnected(getNodeIdFromPeerDescriptor(peerDescriptor), gracefulLeave)
|
|
338
316
|
this.emit('disconnected', peerDescriptor, gracefulLeave)
|
|
339
317
|
})
|
|
340
|
-
this.transport!.
|
|
318
|
+
this.transport!.getConnections().forEach((peer) => {
|
|
341
319
|
this.peerManager!.handleConnected(peer)
|
|
342
320
|
})
|
|
343
321
|
}
|
|
@@ -353,7 +331,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
353
331
|
.map((dhtPeer: DhtNodeRpcRemote) => dhtPeer.getPeerDescriptor())
|
|
354
332
|
},
|
|
355
333
|
addNewContact: (contact: PeerDescriptor) => this.peerManager!.handleNewPeers([contact]),
|
|
356
|
-
removeContact: (
|
|
334
|
+
removeContact: (nodeId: DhtAddress) => this.removeContact(nodeId)
|
|
357
335
|
})
|
|
358
336
|
this.rpcCommunicator!.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers',
|
|
359
337
|
(req: ClosestPeersRequest, context) => dhtNodeRpcLocal.getClosestPeers(req, context))
|
|
@@ -362,7 +340,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
362
340
|
this.rpcCommunicator!.registerRpcNotification(LeaveNotice, 'leaveNotice',
|
|
363
341
|
(_req: LeaveNotice, context) => dhtNodeRpcLocal.leaveNotice(context))
|
|
364
342
|
const externalApiRpcLocal = new ExternalApiRpcLocal({
|
|
365
|
-
executeRecursiveOperation: (key: DhtAddress, operation: RecursiveOperation, excludedPeer:
|
|
343
|
+
executeRecursiveOperation: (key: DhtAddress, operation: RecursiveOperation, excludedPeer: DhtAddress) => {
|
|
366
344
|
return this.executeRecursiveOperation(key, operation, excludedPeer)
|
|
367
345
|
},
|
|
368
346
|
storeDataToDht: (key: DhtAddress, data: Any, creator?: DhtAddress) => this.storeDataToDht(key, data, creator)
|
|
@@ -395,10 +373,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
395
373
|
}
|
|
396
374
|
|
|
397
375
|
private generatePeerDescriptorCallBack(connectivityResponse: ConnectivityResponse) {
|
|
398
|
-
if (this.config.peerDescriptor) {
|
|
376
|
+
if (this.config.peerDescriptor !== undefined) {
|
|
399
377
|
this.localPeerDescriptor = this.config.peerDescriptor
|
|
400
378
|
} else {
|
|
401
|
-
this.localPeerDescriptor = createPeerDescriptor(connectivityResponse, this.config.
|
|
379
|
+
this.localPeerDescriptor = createPeerDescriptor(connectivityResponse, this.config.nodeId)
|
|
402
380
|
}
|
|
403
381
|
return this.localPeerDescriptor
|
|
404
382
|
}
|
|
@@ -409,20 +387,20 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
409
387
|
limit).map((peer) => peer.getPeerDescriptor()
|
|
410
388
|
)
|
|
411
389
|
}
|
|
412
|
-
|
|
390
|
+
|
|
413
391
|
public getNodeId(): DhtAddress {
|
|
414
392
|
return getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
415
393
|
}
|
|
416
394
|
|
|
417
|
-
public
|
|
418
|
-
return this.peerManager!.
|
|
395
|
+
public getNeighborCount(): number {
|
|
396
|
+
return this.peerManager!.getNeighborCount()
|
|
419
397
|
}
|
|
420
398
|
|
|
421
|
-
public removeContact(
|
|
399
|
+
public removeContact(nodeId: DhtAddress): void {
|
|
422
400
|
if (!this.started) { // the stopped state is checked in PeerManager
|
|
423
401
|
return
|
|
424
402
|
}
|
|
425
|
-
this.peerManager!.handlePeerLeaving(
|
|
403
|
+
this.peerManager!.handlePeerLeaving(nodeId)
|
|
426
404
|
}
|
|
427
405
|
|
|
428
406
|
public async send(msg: Message): Promise<void> {
|
|
@@ -439,11 +417,11 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
439
417
|
) : []
|
|
440
418
|
}
|
|
441
419
|
|
|
442
|
-
public async joinDht(entryPointDescriptors: PeerDescriptor[],
|
|
420
|
+
public async joinDht(entryPointDescriptors: PeerDescriptor[], doAdditionalDistantPeerDiscovery?: boolean, retry?: boolean): Promise<void> {
|
|
443
421
|
if (!this.started) {
|
|
444
422
|
throw new Error('Cannot join DHT before calling start() on DhtNode')
|
|
445
423
|
}
|
|
446
|
-
await this.peerDiscovery!.joinDht(entryPointDescriptors,
|
|
424
|
+
await this.peerDiscovery!.joinDht(entryPointDescriptors, doAdditionalDistantPeerDiscovery, retry)
|
|
447
425
|
}
|
|
448
426
|
|
|
449
427
|
// TODO make this private and unify the public API of find/fetch/store/delete methods
|
|
@@ -451,7 +429,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
451
429
|
public async executeRecursiveOperation(
|
|
452
430
|
key: DhtAddress,
|
|
453
431
|
operation: RecursiveOperation,
|
|
454
|
-
excludedPeer?:
|
|
432
|
+
excludedPeer?: DhtAddress
|
|
455
433
|
): Promise<RecursiveOperationResult> {
|
|
456
434
|
return this.recursiveOperationManager!.execute(key, operation, excludedPeer)
|
|
457
435
|
}
|
|
@@ -507,29 +485,28 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
507
485
|
return this.localPeerDescriptor!
|
|
508
486
|
}
|
|
509
487
|
|
|
510
|
-
public
|
|
488
|
+
public getConnections(): PeerDescriptor[] {
|
|
511
489
|
return Array.from(this.peerManager!.connections.values()).map((peer) => peer.getPeerDescriptor())
|
|
512
490
|
}
|
|
513
491
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
return this.peerManager!.getNeighbors()
|
|
492
|
+
public getNeighbors(): PeerDescriptor[] {
|
|
493
|
+
return this.started ? this.peerManager!.getNeighbors() : []
|
|
517
494
|
}
|
|
518
495
|
|
|
519
|
-
public
|
|
520
|
-
return this.peerManager!.
|
|
496
|
+
public getConnectionCount(): number {
|
|
497
|
+
return this.peerManager!.getConnectionCount()
|
|
521
498
|
}
|
|
522
499
|
|
|
523
|
-
public
|
|
524
|
-
return this.connectionManager!.
|
|
500
|
+
public getLocalLockedConnectionCount(): number {
|
|
501
|
+
return this.connectionManager!.getLocalLockedConnectionCount()
|
|
525
502
|
}
|
|
526
503
|
|
|
527
|
-
public
|
|
528
|
-
return this.connectionManager!.
|
|
504
|
+
public getRemoteLockedConnectionCount(): number {
|
|
505
|
+
return this.connectionManager!.getRemoteLockedConnectionCount()
|
|
529
506
|
}
|
|
530
507
|
|
|
531
|
-
public
|
|
532
|
-
return this.connectionManager!.
|
|
508
|
+
public getWeakLockedConnectionCount(): number {
|
|
509
|
+
return this.connectionManager!.getWeakLockedConnectionCount()
|
|
533
510
|
}
|
|
534
511
|
|
|
535
512
|
public async waitForNetworkConnectivity(): Promise<void> {
|
|
@@ -537,7 +514,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
537
514
|
if (!this.peerManager) {
|
|
538
515
|
return false
|
|
539
516
|
} else {
|
|
540
|
-
return (this.peerManager.
|
|
517
|
+
return (this.peerManager.getConnectionCount() > 0)
|
|
541
518
|
}
|
|
542
519
|
}, this.config.networkConnectivityTimeout, 100, this.abortController.signal)
|
|
543
520
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
|
-
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
4
3
|
import { Empty } from '../proto/google/protobuf/empty'
|
|
5
4
|
import {
|
|
6
5
|
ClosestPeersRequest,
|
|
@@ -11,13 +10,13 @@ import {
|
|
|
11
10
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
12
11
|
import { IDhtNodeRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
13
12
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
14
|
-
import { DhtAddress, getDhtAddressFromRaw } from '../identifiers'
|
|
13
|
+
import { DhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
15
14
|
|
|
16
15
|
interface DhtNodeRpcLocalConfig {
|
|
17
16
|
peerDiscoveryQueryBatchSize: number
|
|
18
17
|
getClosestPeersTo: (nodeId: DhtAddress, limit: number) => PeerDescriptor[]
|
|
19
18
|
addNewContact: (contact: PeerDescriptor) => void
|
|
20
|
-
removeContact: (
|
|
19
|
+
removeContact: (nodeId: DhtAddress) => void
|
|
21
20
|
}
|
|
22
21
|
|
|
23
22
|
const logger = new Logger(module)
|
|
@@ -53,8 +52,9 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
53
52
|
async leaveNotice(context: ServerCallContext): Promise<Empty> {
|
|
54
53
|
// TODO check signature??
|
|
55
54
|
const sender = (context as DhtCallContext).incomingSourceDescriptor!
|
|
56
|
-
|
|
57
|
-
|
|
55
|
+
const senderNodeId = getNodeIdFromPeerDescriptor(sender)
|
|
56
|
+
logger.trace('received leave notice: ' + senderNodeId)
|
|
57
|
+
this.config.removeContact(senderNodeId)
|
|
58
58
|
return {}
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import { v4 } from 'uuid'
|
|
4
|
-
import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../identifiers'
|
|
5
|
-
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
4
|
+
import { DhtAddress, DhtAddressRaw, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../identifiers'
|
|
6
5
|
import {
|
|
7
6
|
ClosestPeersRequest,
|
|
8
7
|
PeerDescriptor,
|
|
@@ -11,6 +10,7 @@ import {
|
|
|
11
10
|
import { DhtNodeRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
12
11
|
import { ServiceID } from '../types/ServiceID'
|
|
13
12
|
import { RpcRemote } from './contact/RpcRemote'
|
|
13
|
+
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
14
14
|
|
|
15
15
|
const logger = new Logger(module)
|
|
16
16
|
|
|
@@ -31,7 +31,7 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
|
|
|
31
31
|
localPeerDescriptor: PeerDescriptor,
|
|
32
32
|
peerDescriptor: PeerDescriptor,
|
|
33
33
|
serviceId: ServiceID,
|
|
34
|
-
rpcCommunicator: RpcCommunicator
|
|
34
|
+
rpcCommunicator: RpcCommunicator<DhtCallContext>,
|
|
35
35
|
rpcRequestTimeout?: number
|
|
36
36
|
) {
|
|
37
37
|
super(localPeerDescriptor, peerDescriptor, rpcCommunicator, DhtNodeRpcClient, rpcRequestTimeout)
|
|
@@ -11,15 +11,14 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
|
11
11
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
12
12
|
import { RecursiveOperationResult } from './recursive-operation/RecursiveOperationManager'
|
|
13
13
|
import { Any } from '../proto/google/protobuf/any'
|
|
14
|
-
import { DhtAddress } from '../identifiers'
|
|
15
|
-
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
14
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
16
15
|
import { getDhtAddressFromRaw } from '../identifiers'
|
|
17
16
|
|
|
18
17
|
interface ExternalApiRpcLocalConfig {
|
|
19
18
|
executeRecursiveOperation: (
|
|
20
19
|
targetId: DhtAddress,
|
|
21
20
|
operation: RecursiveOperation,
|
|
22
|
-
excludedPeer:
|
|
21
|
+
excludedPeer: DhtAddress
|
|
23
22
|
) => Promise<RecursiveOperationResult>
|
|
24
23
|
storeDataToDht: (
|
|
25
24
|
key: DhtAddress,
|
|
@@ -41,7 +40,7 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
|
41
40
|
const result = await this.config.executeRecursiveOperation(
|
|
42
41
|
getDhtAddressFromRaw(findDataRequest.key),
|
|
43
42
|
RecursiveOperation.FETCH_DATA,
|
|
44
|
-
senderPeerDescriptor
|
|
43
|
+
getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
45
44
|
)
|
|
46
45
|
return ExternalFindDataResponse.create({ entries: result.dataEntries ?? [] })
|
|
47
46
|
}
|