@streamr/dht 100.0.0-testnet-one.3 → 100.0.0-testnet-two.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/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +4 -4
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +3 -5
- package/dist/src/connection/ConnectionLockRpcRemote.js +4 -7
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +4 -6
- package/dist/src/connection/ConnectionManager.js +48 -46
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +2 -2
- package/dist/src/connection/ConnectorFacade.js +2 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +3 -6
- package/dist/src/connection/ManagedConnection.js +6 -10
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js +1 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +0 -3
- package/dist/src/connection/simulator/Simulator.js +3 -51
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +5 -5
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +2 -2
- 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 +7 -9
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +11 -12
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -5
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +1 -4
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +1 -2
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +3 -4
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +2 -7
- package/dist/src/connection/websocket/WebsocketConnector.js +32 -38
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +3 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -10
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +3 -6
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +0 -3
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.d.ts +1 -4
- package/dist/src/connection/websocket/WebsocketServer.js +11 -12
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +10 -13
- package/dist/src/dht/DhtNode.js +39 -52
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +0 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +7 -7
- package/dist/src/dht/DhtNodeRpcRemote.js +8 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +5 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -0
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +13 -14
- package/dist/src/dht/PeerManager.js +45 -60
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/Contact.js +2 -2
- package/dist/src/dht/contact/Contact.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js +3 -3
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +12 -11
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +7 -4
- package/dist/src/dht/contact/RpcRemote.js +5 -2
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +33 -29
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -4
- package/dist/src/dht/discovery/DiscoverySession.js +19 -20
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -5
- package/dist/src/dht/discovery/PeerDiscovery.js +12 -20
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +36 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +165 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +14 -0
- package/dist/src/dht/{find/FindRpcLocal.js → recursive-operation/RecursiveOperationRpcLocal.js} +7 -7
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.d.ts +6 -0
- package/dist/src/dht/{routing/FindRpcRemote.js → recursive-operation/RecursiveOperationRpcRemote.js} +11 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +42 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +182 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +12 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +17 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.d.ts +6 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js +21 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/Router.d.ts +4 -19
- package/dist/src/dht/routing/Router.js +41 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +6 -5
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +7 -7
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +20 -16
- package/dist/src/dht/routing/RoutingSession.js +37 -45
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +11 -13
- package/dist/src/dht/store/LocalDataStore.js +36 -56
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +33 -0
- package/dist/src/dht/store/StoreManager.js +186 -0
- package/dist/src/dht/store/StoreManager.js.map +1 -0
- package/dist/src/dht/store/StoreRpcLocal.d.ts +8 -40
- package/dist/src/dht/store/StoreRpcLocal.js +13 -229
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +5 -5
- package/dist/src/dht/store/StoreRpcRemote.js +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/MapWithTtl.d.ts +14 -0
- package/dist/src/helpers/MapWithTtl.js +59 -0
- package/dist/src/helpers/MapWithTtl.js.map +1 -0
- package/dist/src/helpers/PeerID.d.ts +2 -0
- package/dist/src/helpers/PeerID.js +4 -0
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +5 -0
- package/dist/src/helpers/nodeId.js +18 -1
- package/dist/src/helpers/nodeId.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -3
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +36 -60
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +34 -53
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
- package/dist/src/rpc-protocol/DhtCallContext.d.ts +2 -1
- package/dist/src/rpc-protocol/DhtCallContext.js.map +1 -1
- package/dist/src/rpc-protocol/DhtRpcOptions.d.ts +2 -1
- package/dist/src/transport/ITransport.d.ts +9 -1
- package/dist/src/transport/ITransport.js +5 -0
- package/dist/src/transport/ITransport.js.map +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -1
- package/dist/src/transport/RoutingRpcCommunicator.js +16 -11
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/jest.config.js +4 -1
- package/karma-setup.js +2 -0
- package/karma.config.js +11 -7
- package/package.json +6 -7
- package/protos/DhtRpc.proto +17 -23
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +8 -9
- package/src/connection/ConnectionLockRpcRemote.ts +7 -16
- package/src/connection/ConnectionManager.ts +58 -55
- package/src/connection/ConnectorFacade.ts +3 -0
- package/src/connection/ManagedConnection.ts +12 -30
- package/src/connection/connectivityChecker.ts +1 -0
- package/src/connection/simulator/Simulator.ts +5 -36
- package/src/connection/simulator/SimulatorConnector.ts +8 -8
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -4
- package/src/connection/webrtc/WebrtcConnector.ts +11 -13
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +16 -16
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +3 -13
- package/src/connection/websocket/AutoCertifierClientFacade.ts +4 -6
- package/src/connection/websocket/ClientWebsocket.ts +1 -0
- package/src/connection/websocket/WebsocketConnector.ts +43 -56
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +11 -13
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +4 -15
- package/src/connection/websocket/WebsocketServer.ts +14 -17
- package/src/dht/DhtNode.ts +67 -69
- package/src/dht/DhtNodeRpcLocal.ts +0 -1
- package/src/dht/DhtNodeRpcRemote.ts +13 -13
- package/src/dht/ExternalApiRpcLocal.ts +16 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -3
- package/src/dht/PeerManager.ts +73 -90
- package/src/dht/contact/Contact.ts +5 -4
- package/src/dht/contact/ContactList.ts +9 -9
- package/src/dht/contact/RandomContactList.ts +14 -14
- package/src/dht/contact/RpcRemote.ts +10 -7
- package/src/dht/contact/SortedContactList.ts +48 -45
- package/src/dht/discovery/DiscoverySession.ts +25 -25
- package/src/dht/discovery/PeerDiscovery.ts +16 -37
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +240 -0
- package/src/dht/{find/FindRpcLocal.ts → recursive-operation/RecursiveOperationRpcLocal.ts} +9 -9
- package/src/dht/{routing/FindRpcRemote.ts → recursive-operation/RecursiveOperationRpcRemote.ts} +10 -10
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +224 -0
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +25 -0
- package/src/dht/{find/FindSessionRpcRemote.ts → recursive-operation/RecursiveOperationSessionRpcRemote.ts} +8 -8
- package/src/dht/routing/Router.ts +45 -64
- package/src/dht/routing/RouterRpcLocal.ts +7 -6
- package/src/dht/routing/RouterRpcRemote.ts +9 -10
- package/src/dht/routing/RoutingSession.ts +59 -68
- package/src/dht/store/LocalDataStore.ts +47 -66
- package/src/dht/store/StoreManager.ts +217 -0
- package/src/dht/store/StoreRpcLocal.ts +26 -302
- package/src/dht/store/StoreRpcRemote.ts +9 -11
- package/src/exports.ts +2 -0
- package/src/helpers/MapWithTtl.ts +71 -0
- package/src/helpers/PeerID.ts +5 -0
- package/src/helpers/nodeId.ts +20 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +5 -3
- package/src/helpers/protoClasses.ts +4 -6
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
- package/src/proto/packages/dht/protos/DhtRpc.ts +49 -80
- package/src/rpc-protocol/DhtCallContext.ts +2 -1
- package/src/rpc-protocol/DhtRpcOptions.ts +2 -1
- package/src/transport/ITransport.ts +10 -1
- package/src/transport/ListeningRpcCommunicator.ts +1 -1
- package/src/transport/RoutingRpcCommunicator.ts +18 -12
- package/test/benchmark/Find.test.ts +8 -21
- package/test/benchmark/KademliaCorrectness.test.ts +11 -20
- package/test/benchmark/SortedContactListBenchmark.test.ts +9 -9
- package/test/benchmark/kademlia-simulation/Contact.ts +9 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +17 -17
- package/test/end-to-end/Layer0-Layer1.test.ts +10 -14
- package/test/end-to-end/Layer0.test.ts +15 -18
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +7 -9
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +4 -10
- package/test/end-to-end/Layer0Webrtc.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +8 -16
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +6 -13
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +5 -6
- package/test/end-to-end/memory-leak.test.ts +6 -8
- package/test/integration/ConnectionLocking.test.ts +6 -13
- package/test/integration/ConnectionManager.test.ts +26 -43
- package/test/integration/DhtJoinPeerDiscovery.test.ts +5 -10
- package/test/integration/DhtNodeExternalAPI.test.ts +16 -22
- package/test/integration/DhtNodeRpcRemote.test.ts +13 -22
- package/test/integration/DhtRpc.test.ts +13 -18
- package/test/integration/Find.test.ts +10 -10
- package/test/integration/Layer1-scale.test.ts +17 -28
- package/test/integration/Mock-Layer1-Layer0.test.ts +25 -43
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/ReplicateData.test.ts +28 -30
- package/test/integration/RouteMessage.test.ts +30 -27
- package/test/integration/RouterRpcRemote.test.ts +12 -18
- package/test/integration/RpcErrors.test.ts +8 -21
- package/test/integration/ScaleDownDht.test.ts +11 -10
- package/test/integration/SimultaneousConnections.test.ts +43 -67
- package/test/integration/Store.test.ts +23 -36
- package/test/integration/StoreAndDelete.test.ts +30 -50
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +16 -37
- package/test/integration/StoreRpcRemote.test.ts +20 -30
- package/test/integration/WebrtcConnectionManagement.test.ts +3 -13
- package/test/integration/WebrtcConnectorRpc.test.ts +3 -9
- package/test/integration/WebsocketConnectionManagement.test.ts +7 -10
- package/test/integration/WebsocketConnectorRpc.test.ts +8 -17
- package/test/unit/ConnectivityHelpers.test.ts +9 -17
- package/test/unit/DuplicateDetector.test.ts +7 -4
- package/test/unit/LocalDataStore.test.ts +66 -77
- package/test/unit/PeerManager.test.ts +31 -0
- package/test/unit/RandomContactList.test.ts +13 -8
- package/test/unit/{Finder.test.ts → RecursiveOperationManager.test.ts} +38 -43
- package/test/unit/RecursiveOperationSession.test.ts +68 -0
- package/test/unit/Router.test.ts +15 -22
- package/test/unit/RoutingSession.test.ts +23 -25
- package/test/unit/SortedContactList.test.ts +41 -26
- package/test/unit/StoreManager.test.ts +132 -0
- package/test/unit/WebsocketConnector.test.ts +27 -35
- package/test/unit/customMatchers.test.ts +16 -0
- package/test/utils/FakeTransport.ts +44 -0
- package/test/utils/customMatchers.ts +70 -0
- package/test/utils/mock/MockRpcCommunicator.ts +7 -0
- package/test/utils/mock/Router.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +36 -0
- package/test/utils/utils.ts +49 -87
- package/dist/src/dht/find/FindRpcLocal.d.ts +0 -14
- package/dist/src/dht/find/FindRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSession.d.ts +0 -44
- package/dist/src/dht/find/FindSession.js +0 -150
- package/dist/src/dht/find/FindSession.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +0 -12
- package/dist/src/dht/find/FindSessionRpcLocal.js +0 -17
- package/dist/src/dht/find/FindSessionRpcLocal.js.map +0 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +0 -6
- package/dist/src/dht/find/FindSessionRpcRemote.js +0 -21
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +0 -1
- package/dist/src/dht/find/Finder.d.ts +0 -49
- package/dist/src/dht/find/Finder.js +0 -197
- package/dist/src/dht/find/Finder.js.map +0 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +0 -6
- package/dist/src/dht/routing/FindRpcRemote.js.map +0 -1
- package/src/dht/find/FindSession.ts +0 -183
- package/src/dht/find/FindSessionRpcLocal.ts +0 -25
- package/src/dht/find/Finder.ts +0 -295
package/protos/DhtRpc.proto
CHANGED
|
@@ -19,8 +19,8 @@ service RouterRpc {
|
|
|
19
19
|
rpc forwardMessage (RouteMessageWrapper) returns (RouteMessageAck);
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
service
|
|
23
|
-
rpc
|
|
22
|
+
service RecursiveOperationRpc {
|
|
23
|
+
rpc routeRequest (RouteMessageWrapper) returns (RouteMessageAck);
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
service StoreRpc {
|
|
@@ -28,12 +28,12 @@ service StoreRpc {
|
|
|
28
28
|
rpc replicateData (ReplicateDataRequest) returns (google.protobuf.Empty);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
service
|
|
32
|
-
rpc
|
|
31
|
+
service RecursiveOperationSessionRpc {
|
|
32
|
+
rpc sendResponse(RecursiveOperationResponse) returns (google.protobuf.Empty);
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
service WebsocketConnectorRpc {
|
|
36
|
-
rpc requestConnection (WebsocketConnectionRequest) returns (
|
|
36
|
+
rpc requestConnection (WebsocketConnectionRequest) returns (google.protobuf.Empty);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
service WebrtcConnectorRpc {
|
|
@@ -59,13 +59,12 @@ service ExternalApiRpc {
|
|
|
59
59
|
message StoreDataRequest {
|
|
60
60
|
bytes key = 1;
|
|
61
61
|
google.protobuf.Any data = 2;
|
|
62
|
-
|
|
62
|
+
bytes creator = 3;
|
|
63
63
|
google.protobuf.Timestamp createdAt = 4;
|
|
64
64
|
uint32 ttl = 5;
|
|
65
65
|
}
|
|
66
66
|
|
|
67
67
|
message StoreDataResponse {
|
|
68
|
-
string error = 1;
|
|
69
68
|
}
|
|
70
69
|
|
|
71
70
|
message ExternalStoreDataRequest {
|
|
@@ -84,7 +83,7 @@ message ReplicateDataRequest {
|
|
|
84
83
|
message DataEntry {
|
|
85
84
|
bytes key = 1;
|
|
86
85
|
google.protobuf.Any data = 2;
|
|
87
|
-
|
|
86
|
+
bytes creator = 3;
|
|
88
87
|
google.protobuf.Timestamp createdAt = 4;
|
|
89
88
|
google.protobuf.Timestamp storedAt = 5;
|
|
90
89
|
uint32 ttl = 6; // milliseconds
|
|
@@ -102,18 +101,18 @@ message ClosestPeersResponse {
|
|
|
102
101
|
string requestId = 2;
|
|
103
102
|
}
|
|
104
103
|
|
|
105
|
-
message
|
|
104
|
+
message RecursiveOperationRequest {
|
|
106
105
|
string sessionId = 1;
|
|
107
|
-
|
|
106
|
+
RecursiveOperation operation = 2;
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
enum
|
|
111
|
-
|
|
109
|
+
enum RecursiveOperation {
|
|
110
|
+
FIND_NODE = 0;
|
|
112
111
|
FETCH_DATA = 1;
|
|
113
112
|
DELETE_DATA = 2;
|
|
114
113
|
}
|
|
115
114
|
|
|
116
|
-
message
|
|
115
|
+
message RecursiveOperationResponse {
|
|
117
116
|
repeated PeerDescriptor closestConnectedPeers = 1;
|
|
118
117
|
repeated DataEntry dataEntries = 2;
|
|
119
118
|
bool noCloserNodesFound = 3;
|
|
@@ -150,7 +149,6 @@ message ConnectivityMethod {
|
|
|
150
149
|
enum NodeType {
|
|
151
150
|
NODEJS = 0;
|
|
152
151
|
BROWSER = 1;
|
|
153
|
-
VIRTUAL = 3;
|
|
154
152
|
}
|
|
155
153
|
|
|
156
154
|
enum RpcResponseError {
|
|
@@ -161,9 +159,9 @@ enum RpcResponseError {
|
|
|
161
159
|
}
|
|
162
160
|
|
|
163
161
|
message RouteMessageWrapper {
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
162
|
+
string requestId = 1;
|
|
163
|
+
PeerDescriptor sourcePeer = 2;
|
|
164
|
+
bytes target = 3;
|
|
167
165
|
Message message = 4;
|
|
168
166
|
repeated PeerDescriptor reachableThrough = 5;
|
|
169
167
|
repeated PeerDescriptor routingPath = 6;
|
|
@@ -220,7 +218,7 @@ enum MessageType {
|
|
|
220
218
|
CONNECTIVITY_RESPONSE = 2;
|
|
221
219
|
HANDSHAKE_REQUEST = 3;
|
|
222
220
|
HANDSHAKE_RESPONSE = 4;
|
|
223
|
-
|
|
221
|
+
RECURSIVE_OPERATION_REQUEST = 5;
|
|
224
222
|
}
|
|
225
223
|
|
|
226
224
|
message Message {
|
|
@@ -235,7 +233,7 @@ message Message {
|
|
|
235
233
|
HandshakeRequest handshakeRequest = 8;
|
|
236
234
|
HandshakeResponse handshakeResponse = 9;
|
|
237
235
|
protorpc.RpcMessage rpcMessage = 10;
|
|
238
|
-
|
|
236
|
+
RecursiveOperationRequest recursiveOperationRequest = 11;
|
|
239
237
|
};
|
|
240
238
|
}
|
|
241
239
|
|
|
@@ -245,10 +243,6 @@ message Message {
|
|
|
245
243
|
message WebsocketConnectionRequest {
|
|
246
244
|
}
|
|
247
245
|
|
|
248
|
-
message WebsocketConnectionResponse {
|
|
249
|
-
bool accepted = 1;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
246
|
// WebRTC
|
|
253
247
|
message WebrtcConnectionRequest {
|
|
254
248
|
}
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
// Connection locks are independent of the existence of connections
|
|
2
2
|
// that is why this class is needed
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { NodeID } from '../helpers/nodeId'
|
|
5
5
|
|
|
6
6
|
export type LockID = string
|
|
7
7
|
|
|
8
8
|
export class ConnectionLockHandler {
|
|
9
9
|
|
|
10
|
-
private localLocks: Map<
|
|
11
|
-
private remoteLocks: Map<
|
|
10
|
+
private localLocks: Map<NodeID, Set<LockID>> = new Map()
|
|
11
|
+
private remoteLocks: Map<NodeID, Set<LockID>> = new Map()
|
|
12
12
|
// TODO: remove weakLocks use localLocks instead. When opening weakLocks from the ConnectioManager,
|
|
13
13
|
// simply do not send lock requests.
|
|
14
|
-
private weakLocks: Set<
|
|
14
|
+
private weakLocks: Set<NodeID> = new Set()
|
|
15
15
|
|
|
16
16
|
public getNumberOfLocalLockedConnections(): number {
|
|
17
17
|
return this.localLocks.size
|
|
@@ -25,7 +25,7 @@ export class ConnectionLockHandler {
|
|
|
25
25
|
return this.weakLocks.size
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
public isLocalLocked(id:
|
|
28
|
+
public isLocalLocked(id: NodeID, lockId?: LockID): boolean {
|
|
29
29
|
if (lockId === undefined) {
|
|
30
30
|
return this.localLocks.has(id)
|
|
31
31
|
} else {
|
|
@@ -33,7 +33,7 @@ export class ConnectionLockHandler {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
public isRemoteLocked(id:
|
|
36
|
+
public isRemoteLocked(id: NodeID, lockId?: LockID): boolean {
|
|
37
37
|
if (lockId === undefined) {
|
|
38
38
|
return this.remoteLocks.has(id)
|
|
39
39
|
} else {
|
|
@@ -45,33 +45,33 @@ export class ConnectionLockHandler {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
private isWeakLocked(id:
|
|
48
|
+
private isWeakLocked(id: NodeID): boolean {
|
|
49
49
|
return this.weakLocks.has(id)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
public isLocked(id:
|
|
52
|
+
public isLocked(id: NodeID): boolean {
|
|
53
53
|
return (this.isLocalLocked(id) || this.isRemoteLocked(id) || this.isWeakLocked(id))
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
public addLocalLocked(id:
|
|
56
|
+
public addLocalLocked(id: NodeID, lockId: LockID): void {
|
|
57
57
|
if (!this.localLocks.has(id)) {
|
|
58
58
|
this.localLocks.set(id, new Set())
|
|
59
59
|
}
|
|
60
60
|
this.localLocks.get(id)!.add(lockId)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
public addRemoteLocked(id:
|
|
63
|
+
public addRemoteLocked(id: NodeID, lockId: LockID): void {
|
|
64
64
|
if (!this.remoteLocks.has(id)) {
|
|
65
65
|
this.remoteLocks.set(id, new Set())
|
|
66
66
|
}
|
|
67
67
|
this.remoteLocks.get(id)!.add(lockId)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
public addWeakLocked(id:
|
|
70
|
+
public addWeakLocked(id: NodeID): void {
|
|
71
71
|
this.weakLocks.add(id)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
public removeLocalLocked(id:
|
|
74
|
+
public removeLocalLocked(id: NodeID, lockId: LockID): void {
|
|
75
75
|
if (this.localLocks.has(id)) {
|
|
76
76
|
this.localLocks.get(id)?.delete(lockId)
|
|
77
77
|
if (this.localLocks.get(id)?.size === 0) {
|
|
@@ -80,7 +80,7 @@ export class ConnectionLockHandler {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
public removeRemoteLocked(id:
|
|
83
|
+
public removeRemoteLocked(id: NodeID, lockId: LockID): void {
|
|
84
84
|
if (this.remoteLocks.has(id)) {
|
|
85
85
|
this.remoteLocks.get(id)?.delete(lockId)
|
|
86
86
|
if (this.remoteLocks.get(id)?.size === 0) {
|
|
@@ -89,11 +89,11 @@ export class ConnectionLockHandler {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
public removeWeakLocked(id:
|
|
92
|
+
public removeWeakLocked(id: NodeID): void {
|
|
93
93
|
this.weakLocks.delete(id)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
public clearAllLocks(id:
|
|
96
|
+
public clearAllLocks(id: NodeID): void {
|
|
97
97
|
this.localLocks.delete(id)
|
|
98
98
|
this.remoteLocks.delete(id)
|
|
99
99
|
this.weakLocks.delete(id)
|
|
@@ -2,8 +2,7 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import {
|
|
4
4
|
areEqualPeerDescriptors,
|
|
5
|
-
|
|
6
|
-
peerIdFromPeerDescriptor
|
|
5
|
+
getNodeIdFromPeerDescriptor
|
|
7
6
|
} from '../helpers/peerIdFromPeerDescriptor'
|
|
8
7
|
import { Empty } from '../proto/google/protobuf/empty'
|
|
9
8
|
import {
|
|
@@ -16,13 +15,13 @@ import {
|
|
|
16
15
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
17
16
|
import { IConnectionLockRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
18
17
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
19
|
-
import { PeerIDKey } from '../helpers/PeerID'
|
|
20
18
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
21
19
|
import { LockID } from './ConnectionLockHandler'
|
|
20
|
+
import { NodeID } from '../helpers/nodeId'
|
|
22
21
|
|
|
23
22
|
interface ConnectionLockRpcLocalConfig {
|
|
24
|
-
addRemoteLocked: (id:
|
|
25
|
-
removeRemoteLocked: (id:
|
|
23
|
+
addRemoteLocked: (id: NodeID, lockId: LockID) => void
|
|
24
|
+
removeRemoteLocked: (id: NodeID, lockId: LockID) => void
|
|
26
25
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => void
|
|
27
26
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
28
27
|
}
|
|
@@ -39,14 +38,14 @@ export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
|
39
38
|
|
|
40
39
|
async lockRequest(lockRequest: LockRequest, context: ServerCallContext): Promise<LockResponse> {
|
|
41
40
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
42
|
-
const remotePeerId = peerIdFromPeerDescriptor(senderPeerDescriptor)
|
|
43
41
|
if (areEqualPeerDescriptors(senderPeerDescriptor, this.config.getLocalPeerDescriptor())) {
|
|
44
42
|
const response: LockResponse = {
|
|
45
43
|
accepted: false
|
|
46
44
|
}
|
|
47
45
|
return response
|
|
48
46
|
}
|
|
49
|
-
|
|
47
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
48
|
+
this.config.addRemoteLocked(remoteNodeId, lockRequest.lockId)
|
|
50
49
|
const response: LockResponse = {
|
|
51
50
|
accepted: true
|
|
52
51
|
}
|
|
@@ -55,8 +54,8 @@ export class ConnectionLockRpcLocal implements IConnectionLockRpc {
|
|
|
55
54
|
|
|
56
55
|
async unlockRequest(unlockRequest: UnlockRequest, context: ServerCallContext): Promise<Empty> {
|
|
57
56
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
58
|
-
const
|
|
59
|
-
this.config.removeRemoteLocked(
|
|
57
|
+
const nodeId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
58
|
+
this.config.removeRemoteLocked(nodeId, unlockRequest.lockId)
|
|
60
59
|
return {}
|
|
61
60
|
}
|
|
62
61
|
|
|
@@ -1,22 +1,13 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
3
|
-
import { IConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
4
|
-
import { LockRequest, UnlockRequest, PeerDescriptor, DisconnectNotice, DisconnectMode } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
6
2
|
import { RpcRemote } from '../dht/contact/RpcRemote'
|
|
3
|
+
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
4
|
+
import { DisconnectMode, DisconnectNotice, LockRequest, UnlockRequest } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { ConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
7
6
|
import { LockID } from './ConnectionLockHandler'
|
|
8
7
|
|
|
9
8
|
const logger = new Logger(module)
|
|
10
9
|
|
|
11
|
-
export class ConnectionLockRpcRemote extends RpcRemote<
|
|
12
|
-
|
|
13
|
-
constructor(
|
|
14
|
-
localPeerDescriptor: PeerDescriptor,
|
|
15
|
-
targetPeerDescriptor: PeerDescriptor,
|
|
16
|
-
client: ProtoRpcClient<IConnectionLockRpcClient>
|
|
17
|
-
) {
|
|
18
|
-
super(localPeerDescriptor, targetPeerDescriptor, 'DUMMY', client)
|
|
19
|
-
}
|
|
10
|
+
export class ConnectionLockRpcRemote extends RpcRemote<ConnectionLockRpcClient> {
|
|
20
11
|
|
|
21
12
|
public async lockRequest(lockId: LockID): Promise<boolean> {
|
|
22
13
|
logger.trace(`Requesting locked connection to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())}`)
|
|
@@ -52,9 +43,9 @@ export class ConnectionLockRpcRemote extends RpcRemote<IConnectionLockRpcClient>
|
|
|
52
43
|
disconnectMode
|
|
53
44
|
}
|
|
54
45
|
const options = this.formDhtRpcOptions({
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
timeout: 2000
|
|
46
|
+
connect: false,
|
|
47
|
+
sendIfStopped: true,
|
|
48
|
+
timeout: 2000 // TODO use config option or named constant?
|
|
58
49
|
})
|
|
59
50
|
await this.getClient().gracefulDisconnect(request, options)
|
|
60
51
|
}
|
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
1
|
import { CountMetric, LevelMetric, Logger, Metric, MetricsContext, MetricsDefinition, RateMetric, waitForEvent3 } from '@streamr/utils'
|
|
3
2
|
import { EventEmitter } from 'eventemitter3'
|
|
4
3
|
import { Contact } from '../dht/contact/Contact'
|
|
5
4
|
import { SortedContactList } from '../dht/contact/SortedContactList'
|
|
6
5
|
import { DuplicateDetector } from '../dht/routing/DuplicateDetector'
|
|
7
|
-
import { PeerIDKey } from '../helpers/PeerID'
|
|
8
6
|
import * as Err from '../helpers/errors'
|
|
9
7
|
import {
|
|
10
8
|
areEqualPeerDescriptors,
|
|
11
9
|
getNodeIdFromPeerDescriptor,
|
|
12
|
-
keyFromPeerDescriptor,
|
|
13
10
|
peerIdFromPeerDescriptor
|
|
14
11
|
} from '../helpers/peerIdFromPeerDescriptor'
|
|
15
12
|
import { protoToString } from '../helpers/protoToString'
|
|
@@ -25,7 +22,7 @@ import {
|
|
|
25
22
|
UnlockRequest
|
|
26
23
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
27
24
|
import { ConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
28
|
-
import { ITransport, TransportEvents } from '../transport/ITransport'
|
|
25
|
+
import { DEFAULT_SEND_OPTIONS, ITransport, SendOptions, TransportEvents } from '../transport/ITransport'
|
|
29
26
|
import { RoutingRpcCommunicator } from '../transport/RoutingRpcCommunicator'
|
|
30
27
|
import { ConnectionLockHandler, LockID } from './ConnectionLockHandler'
|
|
31
28
|
import { ConnectorFacade } from './ConnectorFacade'
|
|
@@ -34,6 +31,7 @@ import { ConnectionLockRpcRemote } from './ConnectionLockRpcRemote'
|
|
|
34
31
|
import { WEBRTC_CLEANUP } from './webrtc/NodeWebrtcConnection'
|
|
35
32
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
36
33
|
import { ConnectionLockRpcLocal } from './ConnectionLockRpcLocal'
|
|
34
|
+
import { NodeID } from '../helpers/nodeId'
|
|
37
35
|
|
|
38
36
|
export interface ConnectionManagerConfig {
|
|
39
37
|
maxConnections?: number
|
|
@@ -55,9 +53,6 @@ interface ConnectionManagerMetrics extends MetricsDefinition {
|
|
|
55
53
|
connectionTotalFailureCount: Metric
|
|
56
54
|
}
|
|
57
55
|
|
|
58
|
-
// TODO move this type identifiers.ts and use also in other classes (and rename to ServiceID)
|
|
59
|
-
type ServiceId = string
|
|
60
|
-
|
|
61
56
|
const logger = new Logger(module)
|
|
62
57
|
|
|
63
58
|
enum ConnectionManagerState {
|
|
@@ -68,8 +63,8 @@ enum ConnectionManagerState {
|
|
|
68
63
|
}
|
|
69
64
|
|
|
70
65
|
export interface ConnectionLocker {
|
|
71
|
-
lockConnection(targetDescriptor: PeerDescriptor,
|
|
72
|
-
unlockConnection(targetDescriptor: PeerDescriptor,
|
|
66
|
+
lockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void
|
|
67
|
+
unlockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void
|
|
73
68
|
weakLockConnection(targetDescriptor: PeerDescriptor): void
|
|
74
69
|
weakUnlockConnection(targetDescriptor: PeerDescriptor): void
|
|
75
70
|
}
|
|
@@ -107,10 +102,11 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
107
102
|
|
|
108
103
|
private config: ConnectionManagerConfig
|
|
109
104
|
private readonly metricsContext: MetricsContext
|
|
105
|
+
// TODO use config option or named constant?
|
|
110
106
|
private readonly duplicateMessageDetector: DuplicateDetector = new DuplicateDetector(100000, 100)
|
|
111
107
|
private readonly metrics: ConnectionManagerMetrics
|
|
112
108
|
private locks = new ConnectionLockHandler()
|
|
113
|
-
private connections: Map<
|
|
109
|
+
private connections: Map<NodeID, ManagedConnection> = new Map()
|
|
114
110
|
private readonly connectorFacade: ConnectorFacade
|
|
115
111
|
private rpcCommunicator?: RoutingRpcCommunicator
|
|
116
112
|
private disconnectorIntervalRef?: NodeJS.Timeout
|
|
@@ -135,11 +131,11 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
135
131
|
this.connectorFacade = this.config.createConnectorFacade()
|
|
136
132
|
this.send = this.send.bind(this)
|
|
137
133
|
this.rpcCommunicator = new RoutingRpcCommunicator(INTERNAL_SERVICE_ID, this.send, {
|
|
138
|
-
rpcRequestTimeout: 10000
|
|
134
|
+
rpcRequestTimeout: 10000 // TODO use config option or named constant?
|
|
139
135
|
})
|
|
140
136
|
const lockRpcLocal = new ConnectionLockRpcLocal({
|
|
141
|
-
addRemoteLocked: (id:
|
|
142
|
-
removeRemoteLocked: (id:
|
|
137
|
+
addRemoteLocked: (id: NodeID, lockId: LockID) => this.locks.addRemoteLocked(id, lockId),
|
|
138
|
+
removeRemoteLocked: (id: NodeID, lockId: LockID) => this.locks.removeRemoteLocked(id, lockId),
|
|
143
139
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => {
|
|
144
140
|
// TODO should we have some handling for this floating promise?
|
|
145
141
|
this.closeConnection(peerDescriptor, gracefulLeave, reason)
|
|
@@ -159,13 +155,13 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
159
155
|
return
|
|
160
156
|
}
|
|
161
157
|
const disconnectionCandidates = new SortedContactList<Contact>({
|
|
162
|
-
referenceId:
|
|
158
|
+
referenceId: getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()),
|
|
163
159
|
maxSize: 100000, // TODO use config option or named constant?
|
|
164
160
|
allowToContainReferenceId: false,
|
|
165
161
|
emitEvents: false
|
|
166
162
|
})
|
|
167
163
|
this.connections.forEach((connection) => {
|
|
168
|
-
if (!this.locks.isLocked(connection.
|
|
164
|
+
if (!this.locks.isLocked(connection.getNodeId()) && Date.now() - connection.getLastUsed() > lastUsedLimit) {
|
|
169
165
|
logger.trace('disconnecting in timeout interval: ' + getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()))
|
|
170
166
|
disconnectionCandidates.addContact(new Contact(connection.getPeerDescriptor()!))
|
|
171
167
|
}
|
|
@@ -187,6 +183,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
187
183
|
logger.trace(`Starting ConnectionManager...`)
|
|
188
184
|
await this.connectorFacade.start(
|
|
189
185
|
(connection: ManagedConnection) => this.onNewConnection(connection),
|
|
186
|
+
(peerDescriptor: PeerDescriptor) => this.hasConnection(peerDescriptor),
|
|
190
187
|
this
|
|
191
188
|
)
|
|
192
189
|
// Garbage collection of connections
|
|
@@ -194,7 +191,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
194
191
|
logger.trace('disconnectorInterval')
|
|
195
192
|
const LAST_USED_LIMIT = 20000
|
|
196
193
|
this.garbageCollectConnections(this.config.maxConnections ?? 80, LAST_USED_LIMIT)
|
|
197
|
-
}, 5000)
|
|
194
|
+
}, 5000) // TODO use config option or named constant?
|
|
198
195
|
}
|
|
199
196
|
|
|
200
197
|
public async stop(): Promise<void> {
|
|
@@ -217,6 +214,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
217
214
|
}
|
|
218
215
|
} else {
|
|
219
216
|
logger.trace('handshake of connection not completed, force-closing')
|
|
217
|
+
// TODO use config option or named constant?
|
|
220
218
|
const eventReceived = waitForEvent3<ManagedConnectionEvents>(peer, 'disconnected', 2000)
|
|
221
219
|
// TODO should we have some handling for this floating promise?
|
|
222
220
|
peer.close(true)
|
|
@@ -252,8 +250,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
252
250
|
return this.locks.getNumberOfWeakLockedConnections()
|
|
253
251
|
}
|
|
254
252
|
|
|
255
|
-
public async send(message: Message,
|
|
256
|
-
if (this.state === ConnectionManagerState.STOPPED && !
|
|
253
|
+
public async send(message: Message, opts: SendOptions = DEFAULT_SEND_OPTIONS): Promise<void> {
|
|
254
|
+
if (this.state === ConnectionManagerState.STOPPED && !opts.sendIfStopped) {
|
|
257
255
|
return
|
|
258
256
|
}
|
|
259
257
|
const peerDescriptor = message.targetDescriptor!
|
|
@@ -265,18 +263,18 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
265
263
|
...message,
|
|
266
264
|
sourceDescriptor: this.getLocalPeerDescriptor()
|
|
267
265
|
}
|
|
268
|
-
const
|
|
269
|
-
let connection = this.connections.get(
|
|
270
|
-
if (!connection &&
|
|
266
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
267
|
+
let connection = this.connections.get(nodeId)
|
|
268
|
+
if (!connection && opts.connect) {
|
|
271
269
|
connection = this.connectorFacade.createConnection(peerDescriptor)
|
|
272
270
|
this.onNewConnection(connection)
|
|
273
271
|
} else if (!connection) {
|
|
274
|
-
throw new Err.SendFailed('No connection to target,
|
|
272
|
+
throw new Err.SendFailed('No connection to target, connect flag is false')
|
|
275
273
|
}
|
|
276
274
|
const binary = Message.toBinary(message)
|
|
277
275
|
this.metrics.sendBytesPerSecond.record(binary.byteLength)
|
|
278
276
|
this.metrics.sendMessagesPerSecond.record(1)
|
|
279
|
-
return connection.send(binary,
|
|
277
|
+
return connection.send(binary, opts.connect)
|
|
280
278
|
}
|
|
281
279
|
|
|
282
280
|
private isConnectionToSelf(peerDescriptor: PeerDescriptor): boolean {
|
|
@@ -294,8 +292,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
294
292
|
}
|
|
295
293
|
|
|
296
294
|
public getConnection(peerDescriptor: PeerDescriptor): ManagedConnection | undefined {
|
|
297
|
-
const
|
|
298
|
-
return this.connections.get(
|
|
295
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
296
|
+
return this.connections.get(nodeId)
|
|
299
297
|
}
|
|
300
298
|
|
|
301
299
|
public getLocalPeerDescriptor(): PeerDescriptor {
|
|
@@ -303,18 +301,18 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
303
301
|
}
|
|
304
302
|
|
|
305
303
|
public hasConnection(peerDescriptor: PeerDescriptor): boolean {
|
|
306
|
-
const
|
|
307
|
-
return this.connections.has(
|
|
304
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
305
|
+
return this.connections.has(nodeId)
|
|
308
306
|
}
|
|
309
307
|
|
|
310
308
|
public hasLocalLockedConnection(peerDescriptor: PeerDescriptor): boolean {
|
|
311
|
-
const
|
|
312
|
-
return this.locks.isLocalLocked(
|
|
309
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
310
|
+
return this.locks.isLocalLocked(nodeId)
|
|
313
311
|
}
|
|
314
312
|
|
|
315
313
|
public hasRemoteLockedConnection(peerDescriptor: PeerDescriptor): boolean {
|
|
316
|
-
const
|
|
317
|
-
return this.locks.isRemoteLocked(
|
|
314
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
315
|
+
return this.locks.isRemoteLocked(nodeId)
|
|
318
316
|
}
|
|
319
317
|
|
|
320
318
|
public handleMessage(message: Message): void {
|
|
@@ -370,11 +368,11 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
370
368
|
private onDisconnected(connection: ManagedConnection, gracefulLeave: boolean) {
|
|
371
369
|
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()) + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
372
370
|
|
|
373
|
-
const
|
|
374
|
-
const storedConnection = this.connections.get(
|
|
371
|
+
const nodeId = getNodeIdFromPeerDescriptor(connection.getPeerDescriptor()!)
|
|
372
|
+
const storedConnection = this.connections.get(nodeId)
|
|
375
373
|
if (storedConnection && storedConnection.connectionId.equals(connection.connectionId)) {
|
|
376
|
-
this.locks.clearAllLocks(
|
|
377
|
-
this.connections.delete(
|
|
374
|
+
this.locks.clearAllLocks(nodeId)
|
|
375
|
+
this.connections.delete(nodeId)
|
|
378
376
|
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor())
|
|
379
377
|
+ ' deleted connection in onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
380
378
|
this.emit('disconnected', connection.getPeerDescriptor()!, gracefulLeave)
|
|
@@ -395,7 +393,6 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
395
393
|
return false
|
|
396
394
|
}
|
|
397
395
|
logger.trace('onNewConnection()')
|
|
398
|
-
connection.offeredAsIncoming = true
|
|
399
396
|
if (!this.acceptNewConnection(connection)) {
|
|
400
397
|
return false
|
|
401
398
|
}
|
|
@@ -416,13 +413,13 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
416
413
|
private acceptNewConnection(newConnection: ManagedConnection): boolean {
|
|
417
414
|
logger.trace(getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!) + ' acceptIncomingConnection()')
|
|
418
415
|
const newPeerID = peerIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
|
|
419
|
-
const
|
|
420
|
-
if (this.connections.has(
|
|
416
|
+
const nodeId = getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
|
|
417
|
+
if (this.connections.has(nodeId)) {
|
|
421
418
|
if (newPeerID.hasSmallerHashThan(peerIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
|
|
422
419
|
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(newConnection.getPeerDescriptor())
|
|
423
420
|
+ ' acceptIncomingConnection() replace current connection')
|
|
424
421
|
// replace the current connection
|
|
425
|
-
const oldConnection = this.connections.get(
|
|
422
|
+
const oldConnection = this.connections.get(nodeId)!
|
|
426
423
|
logger.trace('replaced: ' + getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!))
|
|
427
424
|
const buffer = oldConnection.stealOutputBuffer()
|
|
428
425
|
|
|
@@ -438,14 +435,14 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
438
435
|
}
|
|
439
436
|
|
|
440
437
|
logger.trace(getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!) + ' added to connections at acceptIncomingConnection')
|
|
441
|
-
this.connections.set(
|
|
438
|
+
this.connections.set(nodeId, newConnection)
|
|
442
439
|
|
|
443
440
|
return true
|
|
444
441
|
}
|
|
445
442
|
|
|
446
443
|
private async closeConnection(peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string): Promise<void> {
|
|
447
444
|
logger.trace(getNodeIdFromPeerDescriptor(peerDescriptor) + ' ' + 'closeConnection() ' + reason)
|
|
448
|
-
const id =
|
|
445
|
+
const id = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
449
446
|
this.locks.clearAllLocks(id)
|
|
450
447
|
if (this.connections.has(id)) {
|
|
451
448
|
const connectionToClose = this.connections.get(id)!
|
|
@@ -461,13 +458,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
461
458
|
if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
|
|
462
459
|
return
|
|
463
460
|
}
|
|
464
|
-
const
|
|
461
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
465
462
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
466
463
|
this.getLocalPeerDescriptor(),
|
|
467
464
|
targetDescriptor,
|
|
468
|
-
|
|
465
|
+
'DUMMY',
|
|
466
|
+
this.rpcCommunicator!,
|
|
467
|
+
ConnectionLockRpcClient
|
|
469
468
|
)
|
|
470
|
-
this.locks.addLocalLocked(
|
|
469
|
+
this.locks.addLocalLocked(nodeId, lockId)
|
|
471
470
|
rpcRemote.lockRequest(lockId)
|
|
472
471
|
.then((_accepted) => logger.trace('LockRequest successful'))
|
|
473
472
|
.catch((err) => { logger.debug(err) })
|
|
@@ -477,14 +476,16 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
477
476
|
if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
|
|
478
477
|
return
|
|
479
478
|
}
|
|
480
|
-
const
|
|
481
|
-
this.locks.removeLocalLocked(
|
|
479
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
480
|
+
this.locks.removeLocalLocked(nodeId, lockId)
|
|
482
481
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
483
482
|
this.getLocalPeerDescriptor(),
|
|
484
483
|
targetDescriptor,
|
|
485
|
-
|
|
484
|
+
'DUMMY',
|
|
485
|
+
this.rpcCommunicator!,
|
|
486
|
+
ConnectionLockRpcClient
|
|
486
487
|
)
|
|
487
|
-
if (this.connections.has(
|
|
488
|
+
if (this.connections.has(nodeId)) {
|
|
488
489
|
rpcRemote.unlockRequest(lockId)
|
|
489
490
|
}
|
|
490
491
|
}
|
|
@@ -493,22 +494,21 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
493
494
|
if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
|
|
494
495
|
return
|
|
495
496
|
}
|
|
496
|
-
const
|
|
497
|
-
this.locks.addWeakLocked(
|
|
497
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
498
|
+
this.locks.addWeakLocked(nodeId)
|
|
498
499
|
}
|
|
499
500
|
|
|
500
501
|
public weakUnlockConnection(targetDescriptor: PeerDescriptor): void {
|
|
501
502
|
if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
|
|
502
503
|
return
|
|
503
504
|
}
|
|
504
|
-
const
|
|
505
|
-
this.locks.removeWeakLocked(
|
|
506
|
-
|
|
505
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
506
|
+
this.locks.removeWeakLocked(nodeId)
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
private async gracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
|
|
510
510
|
|
|
511
|
-
const connection = this.connections.get(
|
|
511
|
+
const connection = this.connections.get(getNodeIdFromPeerDescriptor(targetDescriptor))
|
|
512
512
|
|
|
513
513
|
if (!connection) {
|
|
514
514
|
logger.debug('gracefullyDisconnectedAsync() tried on a non-existing connection')
|
|
@@ -516,6 +516,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
const promise = new Promise<void>((resolve, _reject) => {
|
|
519
|
+
// TODO use config option or named constant?
|
|
519
520
|
// eslint-disable-next-line promise/catch-or-return
|
|
520
521
|
waitForEvent3<ManagedConnectionEvents>(connection, 'disconnected', 2000).then(() => {
|
|
521
522
|
logger.trace('disconnected event received in gracefullyDisconnectAsync()')
|
|
@@ -546,7 +547,9 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
546
547
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
547
548
|
this.getLocalPeerDescriptor(),
|
|
548
549
|
targetDescriptor,
|
|
549
|
-
|
|
550
|
+
'DUMMY',
|
|
551
|
+
this.rpcCommunicator!,
|
|
552
|
+
ConnectionLockRpcClient
|
|
550
553
|
)
|
|
551
554
|
try {
|
|
552
555
|
await rpcRemote.gracefulDisconnect(disconnectMode)
|