@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
package/protos/DhtRpc.proto
CHANGED
|
@@ -46,7 +46,7 @@ service WebrtcConnectorRpc {
|
|
|
46
46
|
service ConnectionLockRpc {
|
|
47
47
|
rpc lockRequest (LockRequest) returns (LockResponse);
|
|
48
48
|
rpc unlockRequest (UnlockRequest) returns (google.protobuf.Empty);
|
|
49
|
-
rpc gracefulDisconnect (DisconnectNotice) returns (
|
|
49
|
+
rpc gracefulDisconnect (DisconnectNotice) returns (google.protobuf.Empty);
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
service ExternalApiRpc {
|
|
@@ -137,6 +137,10 @@ message PeerDescriptor {
|
|
|
137
137
|
ConnectivityMethod tcp = 4;
|
|
138
138
|
ConnectivityMethod websocket = 5;
|
|
139
139
|
optional uint32 region = 6;
|
|
140
|
+
optional uint32 ipAddress = 7;
|
|
141
|
+
optional bytes publicKey = 8;
|
|
142
|
+
// signature of fields 2-8
|
|
143
|
+
optional bytes signature = 9;
|
|
140
144
|
}
|
|
141
145
|
|
|
142
146
|
message ConnectivityMethod {
|
|
@@ -164,6 +168,7 @@ message RouteMessageWrapper {
|
|
|
164
168
|
Message message = 4;
|
|
165
169
|
repeated PeerDescriptor reachableThrough = 5;
|
|
166
170
|
repeated PeerDescriptor routingPath = 6;
|
|
171
|
+
repeated string parallelRootNodeIds = 7;
|
|
167
172
|
}
|
|
168
173
|
|
|
169
174
|
message RouteMessageAck {
|
|
@@ -192,6 +197,7 @@ message ConnectivityResponse {
|
|
|
192
197
|
string host = 1;
|
|
193
198
|
string natType = 2;
|
|
194
199
|
ConnectivityMethod websocket = 3;
|
|
200
|
+
uint32 ipAddress = 4;
|
|
195
201
|
}
|
|
196
202
|
|
|
197
203
|
message HandshakeRequest {
|
|
@@ -286,9 +292,6 @@ message DisconnectNotice {
|
|
|
286
292
|
DisconnectMode disconnectMode = 1;
|
|
287
293
|
}
|
|
288
294
|
|
|
289
|
-
message DisconnectNoticeResponse {
|
|
290
|
-
}
|
|
291
|
-
|
|
292
295
|
message ExternalFindDataRequest {
|
|
293
296
|
bytes key = 1;
|
|
294
297
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3'
|
|
2
2
|
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { ConnectionID, ConnectionType, ConnectionEvents } from './IConnection'
|
|
4
|
+
import { v4 as uuid } from 'uuid'
|
|
4
5
|
|
|
5
6
|
export class Connection extends EventEmitter<ConnectionEvents> {
|
|
6
7
|
public connectionId: ConnectionID
|
|
@@ -9,7 +10,7 @@ export class Connection extends EventEmitter<ConnectionEvents> {
|
|
|
9
10
|
|
|
10
11
|
constructor(connectionType: ConnectionType) {
|
|
11
12
|
super()
|
|
12
|
-
this.connectionId =
|
|
13
|
+
this.connectionId = createRandomConnectionId()
|
|
13
14
|
this.connectionType = connectionType
|
|
14
15
|
}
|
|
15
16
|
|
|
@@ -21,3 +22,7 @@ export class Connection extends EventEmitter<ConnectionEvents> {
|
|
|
21
22
|
return this.peerDescriptor
|
|
22
23
|
}
|
|
23
24
|
}
|
|
25
|
+
|
|
26
|
+
export const createRandomConnectionId = (): ConnectionID => {
|
|
27
|
+
return uuid() as ConnectionID
|
|
28
|
+
}
|
|
@@ -13,15 +13,15 @@ export class ConnectionLockHandler {
|
|
|
13
13
|
// simply do not send lock requests.
|
|
14
14
|
private weakLocks: Set<DhtAddress> = new Set()
|
|
15
15
|
|
|
16
|
-
public
|
|
16
|
+
public getLocalLockedConnectionCount(): number {
|
|
17
17
|
return this.localLocks.size
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
public
|
|
20
|
+
public getRemoteLockedConnectionCount(): number {
|
|
21
21
|
return this.remoteLocks.size
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
public
|
|
24
|
+
public getWeakLockedConnectionCount(): number {
|
|
25
25
|
return this.weakLocks.size
|
|
26
26
|
}
|
|
27
27
|
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
|
-
import {
|
|
4
|
-
areEqualPeerDescriptors,
|
|
5
|
-
getNodeIdFromPeerDescriptor
|
|
6
|
-
} from '../helpers/peerIdFromPeerDescriptor'
|
|
7
3
|
import { Empty } from '../proto/google/protobuf/empty'
|
|
8
4
|
import {
|
|
9
5
|
DisconnectMode,
|
|
@@ -17,7 +13,7 @@ import { IConnectionLockRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
|
17
13
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
18
14
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
19
15
|
import { LockID } from './ConnectionLockHandler'
|
|
20
|
-
import { DhtAddress } from '../identifiers'
|
|
16
|
+
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
21
17
|
|
|
22
18
|
interface ConnectionLockRpcLocalConfig {
|
|
23
19
|
addRemoteLocked: (id: DhtAddress, lockId: LockID) => void
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
2
|
import { RpcRemote } from '../dht/contact/RpcRemote'
|
|
3
|
-
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
4
3
|
import { DisconnectMode, DisconnectNotice, LockRequest, UnlockRequest } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { ConnectionLockRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
6
5
|
import { LockID } from './ConnectionLockHandler'
|
|
6
|
+
import { getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
9
9
|
|
|
@@ -3,15 +3,9 @@ import { EventEmitter } from 'eventemitter3'
|
|
|
3
3
|
import { SortedContactList } from '../dht/contact/SortedContactList'
|
|
4
4
|
import { DuplicateDetector } from '../dht/routing/DuplicateDetector'
|
|
5
5
|
import * as Err from '../helpers/errors'
|
|
6
|
-
import {
|
|
7
|
-
areEqualPeerDescriptors,
|
|
8
|
-
getNodeIdFromPeerDescriptor,
|
|
9
|
-
peerIdFromPeerDescriptor
|
|
10
|
-
} from '../helpers/peerIdFromPeerDescriptor'
|
|
11
6
|
import {
|
|
12
7
|
DisconnectMode,
|
|
13
8
|
DisconnectNotice,
|
|
14
|
-
DisconnectNoticeResponse,
|
|
15
9
|
LockRequest,
|
|
16
10
|
LockResponse,
|
|
17
11
|
Message,
|
|
@@ -29,7 +23,8 @@ import { ConnectionLockRpcRemote } from './ConnectionLockRpcRemote'
|
|
|
29
23
|
import { WEBRTC_CLEANUP } from './webrtc/NodeWebrtcConnection'
|
|
30
24
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
31
25
|
import { ConnectionLockRpcLocal } from './ConnectionLockRpcLocal'
|
|
32
|
-
import { DhtAddress } from '../identifiers'
|
|
26
|
+
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
27
|
+
import { getOfferer } from '../helpers/offering'
|
|
33
28
|
|
|
34
29
|
export interface ConnectionManagerConfig {
|
|
35
30
|
maxConnections?: number
|
|
@@ -101,7 +96,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
101
96
|
private config: ConnectionManagerConfig
|
|
102
97
|
private readonly metricsContext: MetricsContext
|
|
103
98
|
// TODO use config option or named constant?
|
|
104
|
-
private readonly duplicateMessageDetector: DuplicateDetector = new DuplicateDetector(100000
|
|
99
|
+
private readonly duplicateMessageDetector: DuplicateDetector = new DuplicateDetector(100000)
|
|
105
100
|
private readonly metrics: ConnectionManagerMetrics
|
|
106
101
|
private locks = new ConnectionLockHandler()
|
|
107
102
|
private connections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
@@ -144,7 +139,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
144
139
|
(req: LockRequest, context: ServerCallContext) => lockRpcLocal.lockRequest(req, context))
|
|
145
140
|
this.rpcCommunicator.registerRpcNotification(UnlockRequest, 'unlockRequest',
|
|
146
141
|
(req: UnlockRequest, context: ServerCallContext) => lockRpcLocal.unlockRequest(req, context))
|
|
147
|
-
this.rpcCommunicator.
|
|
142
|
+
this.rpcCommunicator.registerRpcNotification(DisconnectNotice, 'gracefulDisconnect',
|
|
148
143
|
(req: DisconnectNotice, context: ServerCallContext) => lockRpcLocal.gracefulDisconnect(req, context))
|
|
149
144
|
}
|
|
150
145
|
|
|
@@ -181,7 +176,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
181
176
|
logger.trace(`Starting ConnectionManager...`)
|
|
182
177
|
await this.connectorFacade.start(
|
|
183
178
|
(connection: ManagedConnection) => this.onNewConnection(connection),
|
|
184
|
-
(
|
|
179
|
+
(nodeId: DhtAddress) => this.hasConnection(nodeId),
|
|
185
180
|
this
|
|
186
181
|
)
|
|
187
182
|
// Garbage collection of connections
|
|
@@ -236,20 +231,20 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
236
231
|
WEBRTC_CLEANUP.cleanUp()
|
|
237
232
|
}
|
|
238
233
|
|
|
239
|
-
public
|
|
240
|
-
return this.locks.
|
|
234
|
+
public getLocalLockedConnectionCount(): number {
|
|
235
|
+
return this.locks.getLocalLockedConnectionCount()
|
|
241
236
|
}
|
|
242
237
|
|
|
243
|
-
public
|
|
244
|
-
return this.locks.
|
|
238
|
+
public getRemoteLockedConnectionCount(): number {
|
|
239
|
+
return this.locks.getRemoteLockedConnectionCount()
|
|
245
240
|
}
|
|
246
241
|
|
|
247
|
-
public
|
|
248
|
-
return this.locks.
|
|
242
|
+
public getWeakLockedConnectionCount(): number {
|
|
243
|
+
return this.locks.getWeakLockedConnectionCount()
|
|
249
244
|
}
|
|
250
245
|
|
|
251
246
|
public async send(message: Message, opts: SendOptions = DEFAULT_SEND_OPTIONS): Promise<void> {
|
|
252
|
-
if (this.state === ConnectionManagerState.STOPPED && !opts.sendIfStopped) {
|
|
247
|
+
if ((this.state === ConnectionManagerState.STOPPED || this.state === ConnectionManagerState.STOPPING) && !opts.sendIfStopped) {
|
|
253
248
|
return
|
|
254
249
|
}
|
|
255
250
|
const peerDescriptor = message.targetDescriptor!
|
|
@@ -289,8 +284,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
289
284
|
}
|
|
290
285
|
}
|
|
291
286
|
|
|
292
|
-
public getConnection(
|
|
293
|
-
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
287
|
+
public getConnection(nodeId: DhtAddress): ManagedConnection | undefined {
|
|
294
288
|
return this.connections.get(nodeId)
|
|
295
289
|
}
|
|
296
290
|
|
|
@@ -298,18 +292,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
298
292
|
return this.connectorFacade.getLocalPeerDescriptor()!
|
|
299
293
|
}
|
|
300
294
|
|
|
301
|
-
public hasConnection(
|
|
302
|
-
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
295
|
+
public hasConnection(nodeId: DhtAddress): boolean {
|
|
303
296
|
return this.connections.has(nodeId)
|
|
304
297
|
}
|
|
305
298
|
|
|
306
|
-
public hasLocalLockedConnection(
|
|
307
|
-
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
299
|
+
public hasLocalLockedConnection(nodeId: DhtAddress): boolean {
|
|
308
300
|
return this.locks.isLocalLocked(nodeId)
|
|
309
301
|
}
|
|
310
302
|
|
|
311
|
-
public hasRemoteLockedConnection(
|
|
312
|
-
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
303
|
+
public hasRemoteLockedConnection(nodeId: DhtAddress): boolean {
|
|
313
304
|
return this.locks.isRemoteLocked(nodeId)
|
|
314
305
|
}
|
|
315
306
|
|
|
@@ -366,7 +357,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
366
357
|
const nodeId = getNodeIdFromPeerDescriptor(connection.getPeerDescriptor()!)
|
|
367
358
|
logger.trace(nodeId + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
368
359
|
const storedConnection = this.connections.get(nodeId)
|
|
369
|
-
if (storedConnection && storedConnection.connectionId
|
|
360
|
+
if (storedConnection && (storedConnection.connectionId === connection.connectionId)) {
|
|
370
361
|
this.locks.clearAllLocks(nodeId)
|
|
371
362
|
this.connections.delete(nodeId)
|
|
372
363
|
logger.trace(nodeId + ' deleted connection in onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
@@ -375,8 +366,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
375
366
|
} else {
|
|
376
367
|
logger.trace(nodeId + ' onDisconnected() did nothing, no such connection in connectionManager')
|
|
377
368
|
if (storedConnection) {
|
|
378
|
-
|
|
379
|
-
logger.trace(nodeId + ' connectionIds do not match ' + connectionId + ' ' + connection.connectionId.toString())
|
|
369
|
+
logger.trace(nodeId + ' connectionIds do not match ' + storedConnection.connectionId + ' ' + connection.connectionId.toString())
|
|
380
370
|
}
|
|
381
371
|
}
|
|
382
372
|
}
|
|
@@ -407,8 +397,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
407
397
|
const nodeId = getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
|
|
408
398
|
logger.trace(nodeId + ' acceptIncomingConnection()')
|
|
409
399
|
if (this.connections.has(nodeId)) {
|
|
410
|
-
|
|
411
|
-
if (newPeerID.hasSmallerHashThan(peerIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
|
|
400
|
+
if (getOfferer(getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()), nodeId) === 'remote') {
|
|
412
401
|
logger.trace(nodeId + ' acceptIncomingConnection() replace current connection')
|
|
413
402
|
// replace the current connection
|
|
414
403
|
const oldConnection = this.connections.get(nodeId)!
|
|
@@ -521,13 +510,10 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
521
510
|
})
|
|
522
511
|
})
|
|
523
512
|
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
.
|
|
527
|
-
|
|
528
|
-
})
|
|
529
|
-
|
|
530
|
-
await promise
|
|
513
|
+
await Promise.all([
|
|
514
|
+
promise,
|
|
515
|
+
this.doGracefullyDisconnectAsync(targetDescriptor, disconnectMode)
|
|
516
|
+
])
|
|
531
517
|
}
|
|
532
518
|
|
|
533
519
|
private async doGracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
|
|
@@ -546,7 +532,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
546
532
|
}
|
|
547
533
|
}
|
|
548
534
|
|
|
549
|
-
public
|
|
535
|
+
public getConnections(): PeerDescriptor[] {
|
|
550
536
|
return Array.from(this.connections.values())
|
|
551
537
|
.filter((managedConnection: ManagedConnection) => managedConnection.isHandshakeCompleted())
|
|
552
538
|
.map((managedConnection: ManagedConnection) => managedConnection.getPeerDescriptor()!)
|
|
@@ -10,13 +10,14 @@ import { Simulator } from './simulator/Simulator'
|
|
|
10
10
|
import { SimulatorConnector } from './simulator/SimulatorConnector'
|
|
11
11
|
import { IceServer, WebrtcConnector } from './webrtc/WebrtcConnector'
|
|
12
12
|
import { WebsocketConnector, WebsocketConnectorConfig } from './websocket/WebsocketConnector'
|
|
13
|
+
import { DhtAddress } from '../identifiers'
|
|
13
14
|
|
|
14
15
|
export interface ConnectorFacade {
|
|
15
16
|
createConnection: (peerDescriptor: PeerDescriptor) => ManagedConnection
|
|
16
17
|
getLocalPeerDescriptor: () => PeerDescriptor | undefined
|
|
17
18
|
start: (
|
|
18
19
|
onNewConnection: (connection: ManagedConnection) => boolean,
|
|
19
|
-
hasConnection: (
|
|
20
|
+
hasConnection: (nodeId: DhtAddress) => boolean,
|
|
20
21
|
autoCertifierTransport: ITransport
|
|
21
22
|
) => Promise<void>
|
|
22
23
|
stop: () => Promise<void>
|
|
@@ -59,7 +60,7 @@ export class DefaultConnectorFacade implements ConnectorFacade {
|
|
|
59
60
|
|
|
60
61
|
async start(
|
|
61
62
|
onNewConnection: (connection: ManagedConnection) => boolean,
|
|
62
|
-
hasConnection: (
|
|
63
|
+
hasConnection: (nodeId: DhtAddress) => boolean,
|
|
63
64
|
autoCertifierTransport: ITransport
|
|
64
65
|
): Promise<void> {
|
|
65
66
|
logger.trace(`Creating WebsocketConnectorRpcLocal`)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BrandedString } from '@streamr/utils'
|
|
2
2
|
|
|
3
3
|
export interface ConnectionEvents {
|
|
4
4
|
data: (bytes: Uint8Array) => void
|
|
@@ -15,13 +15,7 @@ export enum ConnectionType {
|
|
|
15
15
|
SIMULATOR_CLIENT = 'simulator-client',
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
export class ConnectionID extends UUID {
|
|
21
|
-
toMapKey(): ConnectionIDKey {
|
|
22
|
-
return this.toString() as ConnectionIDKey
|
|
23
|
-
}
|
|
24
|
-
}
|
|
18
|
+
export type ConnectionID = BrandedString<'ConnectionID'>
|
|
25
19
|
|
|
26
20
|
export interface IConnection {
|
|
27
21
|
|
|
@@ -4,9 +4,9 @@ import { Handshaker } from './Handshaker'
|
|
|
4
4
|
import { HandshakeError, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { Logger, runAndRaceEvents3, RunAndRaceEventsReturnType } from '@streamr/utils'
|
|
6
6
|
import EventEmitter from 'eventemitter3'
|
|
7
|
-
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
8
7
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
9
|
-
import { DhtAddress } from '../identifiers'
|
|
8
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
9
|
+
import { createRandomConnectionId } from './Connection'
|
|
10
10
|
|
|
11
11
|
export interface ManagedConnectionEvents {
|
|
12
12
|
managedData: (bytes: Uint8Array, remotePeerDescriptor: PeerDescriptor) => void
|
|
@@ -59,7 +59,7 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
59
59
|
this.outgoingConnection = outgoingConnection
|
|
60
60
|
this.incomingConnection = incomingConnection
|
|
61
61
|
this.connectionType = connectionType
|
|
62
|
-
this.connectionId =
|
|
62
|
+
this.connectionId = createRandomConnectionId()
|
|
63
63
|
|
|
64
64
|
this.send = this.send.bind(this)
|
|
65
65
|
this.onDisconnected = this.onDisconnected.bind(this)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger } from '@streamr/utils'
|
|
1
|
+
import { ipv4ToNumber, Logger } from '@streamr/utils'
|
|
2
2
|
import { v4 } from 'uuid'
|
|
3
3
|
import {
|
|
4
4
|
ConnectivityRequest, ConnectivityResponse,
|
|
@@ -36,6 +36,7 @@ const handleIncomingConnectivityRequest = async (connection: ServerWebsocket, co
|
|
|
36
36
|
let outgoingConnection: IConnection | undefined
|
|
37
37
|
let connectivityResponseMessage: ConnectivityResponse | undefined
|
|
38
38
|
const host = connectivityRequest.host ?? connection.getRemoteAddress()
|
|
39
|
+
const ipAddress = connection.getRemoteIp()
|
|
39
40
|
try {
|
|
40
41
|
const wsServerInfo = {
|
|
41
42
|
host,
|
|
@@ -52,17 +53,20 @@ const handleIncomingConnectivityRequest = async (connection: ServerWebsocket, co
|
|
|
52
53
|
logger.debug('error', { err })
|
|
53
54
|
connectivityResponseMessage = {
|
|
54
55
|
host,
|
|
55
|
-
natType: NatType.UNKNOWN
|
|
56
|
+
natType: NatType.UNKNOWN,
|
|
57
|
+
ipAddress: ipv4ToNumber(ipAddress)
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
if (outgoingConnection) {
|
|
59
61
|
// TODO should we have some handling for this floating promise?
|
|
60
62
|
outgoingConnection.close(false)
|
|
61
63
|
logger.trace('Connectivity test produced positive result, communicating reply to the requester ' + host + ':' + connectivityRequest.port)
|
|
64
|
+
|
|
62
65
|
connectivityResponseMessage = {
|
|
63
66
|
host,
|
|
64
67
|
natType: NatType.OPEN_INTERNET,
|
|
65
|
-
websocket: { host, port: connectivityRequest.port, tls: connectivityRequest.tls }
|
|
68
|
+
websocket: { host, port: connectivityRequest.port, tls: connectivityRequest.tls },
|
|
69
|
+
ipAddress: ipv4ToNumber(ipAddress)
|
|
66
70
|
}
|
|
67
71
|
}
|
|
68
72
|
const msg: Message = {
|
|
@@ -7,10 +7,9 @@ import { SimulatorConnection } from './SimulatorConnection'
|
|
|
7
7
|
import { ConnectionID } from '../IConnection'
|
|
8
8
|
import { Logger } from '@streamr/utils'
|
|
9
9
|
import { getRegionDelayMatrix } from './pings'
|
|
10
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
11
10
|
import Heap from 'heap'
|
|
12
11
|
import { debugVars } from '../../helpers/debugHelpers'
|
|
13
|
-
import { DhtAddress } from '../../identifiers'
|
|
12
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
14
13
|
|
|
15
14
|
const logger = new Logger(module)
|
|
16
15
|
|
|
@@ -4,7 +4,7 @@ import { Message, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
|
4
4
|
import { Connection } from '../Connection'
|
|
5
5
|
import { Logger } from '@streamr/utils'
|
|
6
6
|
import { protoToString } from '../../helpers/protoToString'
|
|
7
|
-
import { getNodeIdFromPeerDescriptor } from '../../
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
@@ -8,8 +8,7 @@ import { Logger } from '@streamr/utils'
|
|
|
8
8
|
import { ManagedConnection } from '../ManagedConnection'
|
|
9
9
|
import { Simulator } from './Simulator'
|
|
10
10
|
import { SimulatorConnection } from './SimulatorConnection'
|
|
11
|
-
import { getNodeIdFromPeerDescriptor } from '../../
|
|
12
|
-
import { DhtAddress } from '../../identifiers'
|
|
11
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
13
12
|
|
|
14
13
|
const logger = new Logger(module)
|
|
15
14
|
|
|
@@ -3,6 +3,7 @@ import { WebrtcConnectionEvents, IWebrtcConnection, RtcDescription } from './IWe
|
|
|
3
3
|
import { IConnection, ConnectionID, ConnectionEvents, ConnectionType } from '../IConnection'
|
|
4
4
|
import { Logger } from '@streamr/utils'
|
|
5
5
|
import { IceServer } from './WebrtcConnector'
|
|
6
|
+
import { createRandomConnectionId } from '../Connection'
|
|
6
7
|
|
|
7
8
|
const logger = new Logger(module)
|
|
8
9
|
|
|
@@ -34,7 +35,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
34
35
|
|
|
35
36
|
constructor(params: Params) {
|
|
36
37
|
super()
|
|
37
|
-
this.connectionId =
|
|
38
|
+
this.connectionId = createRandomConnectionId()
|
|
38
39
|
this.iceServers = params.iceServers ?? []
|
|
39
40
|
}
|
|
40
41
|
|
|
@@ -222,7 +223,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
222
223
|
this.emit('connected')
|
|
223
224
|
}
|
|
224
225
|
|
|
225
|
-
public setConnectionId(
|
|
226
|
-
this.connectionId =
|
|
226
|
+
public setConnectionId(connectionId: ConnectionID): void {
|
|
227
|
+
this.connectionId = connectionId
|
|
227
228
|
}
|
|
228
229
|
}
|
|
@@ -5,10 +5,11 @@ import EventEmitter from 'eventemitter3'
|
|
|
5
5
|
import nodeDatachannel, { DataChannel, DescriptionType, PeerConnection } from 'node-datachannel'
|
|
6
6
|
import { Logger } from '@streamr/utils'
|
|
7
7
|
import { IllegalRtcPeerConnectionState } from '../../helpers/errors'
|
|
8
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
9
8
|
import { iceServerAsString } from './iceServerAsString'
|
|
10
9
|
import { IceServer } from './WebrtcConnector'
|
|
11
10
|
import { PortRange } from '../ConnectionManager'
|
|
11
|
+
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
12
|
+
import { createRandomConnectionId } from '../Connection'
|
|
12
13
|
|
|
13
14
|
const logger = new Logger(module)
|
|
14
15
|
|
|
@@ -67,7 +68,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
67
68
|
|
|
68
69
|
constructor(params: Params) {
|
|
69
70
|
super()
|
|
70
|
-
this.connectionId =
|
|
71
|
+
this.connectionId = createRandomConnectionId()
|
|
71
72
|
this.iceServers = params.iceServers ?? []
|
|
72
73
|
// eslint-disable-next-line no-underscore-dangle
|
|
73
74
|
this._bufferThresholdHigh = params.bufferThresholdHigh ?? 2 ** 17
|
|
@@ -253,7 +254,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
253
254
|
return !this.closed && this.lastState === 'connected' && !!this.dataChannel
|
|
254
255
|
}
|
|
255
256
|
|
|
256
|
-
public setConnectionId(
|
|
257
|
-
this.connectionId =
|
|
257
|
+
public setConnectionId(connectionId: ConnectionID): void {
|
|
258
|
+
this.connectionId = connectionId
|
|
258
259
|
}
|
|
259
260
|
}
|
|
@@ -13,15 +13,11 @@ import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
|
|
|
13
13
|
import { Logger } from '@streamr/utils'
|
|
14
14
|
import * as Err from '../../helpers/errors'
|
|
15
15
|
import { ManagedConnection } from '../ManagedConnection'
|
|
16
|
-
import {
|
|
17
|
-
areEqualPeerDescriptors,
|
|
18
|
-
getNodeIdFromPeerDescriptor,
|
|
19
|
-
peerIdFromPeerDescriptor
|
|
20
|
-
} from '../../helpers/peerIdFromPeerDescriptor'
|
|
21
16
|
import { PortRange } from '../ConnectionManager'
|
|
22
17
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
23
18
|
import { WebrtcConnectorRpcLocal } from './WebrtcConnectorRpcLocal'
|
|
24
|
-
import { DhtAddress } from '../../identifiers'
|
|
19
|
+
import { DhtAddress, areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
20
|
+
import { getOfferer } from '../../helpers/offering'
|
|
25
21
|
|
|
26
22
|
const logger = new Logger(module)
|
|
27
23
|
|
|
@@ -146,7 +142,9 @@ export class WebrtcConnector {
|
|
|
146
142
|
portRange: this.config.portRange
|
|
147
143
|
})
|
|
148
144
|
|
|
149
|
-
const
|
|
145
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
146
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
147
|
+
const offering = (getOfferer(localNodeId, targetNodeId) === 'local')
|
|
150
148
|
let managedConnection: ManagedWebrtcConnection
|
|
151
149
|
|
|
152
150
|
if (offering) {
|
|
@@ -157,7 +155,7 @@ export class WebrtcConnector {
|
|
|
157
155
|
|
|
158
156
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
159
157
|
|
|
160
|
-
this.ongoingConnectAttempts.set(
|
|
158
|
+
this.ongoingConnectAttempts.set(targetNodeId, managedConnection)
|
|
161
159
|
|
|
162
160
|
const delFunc = () => {
|
|
163
161
|
this.ongoingConnectAttempts.delete(nodeId)
|
|
@@ -179,16 +177,16 @@ export class WebrtcConnector {
|
|
|
179
177
|
candidate = replaceInternalIpWithExternalIp(candidate, this.config.externalIp)
|
|
180
178
|
logger.debug(`onLocalCandidate injected external ip ${candidate} ${mid}`)
|
|
181
179
|
}
|
|
182
|
-
remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId
|
|
180
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection.connectionId)
|
|
183
181
|
})
|
|
184
182
|
|
|
185
183
|
if (offering) {
|
|
186
184
|
connection.once('localDescription', (description: string) => {
|
|
187
|
-
remoteConnector.sendRtcOffer(description, connection.connectionId
|
|
185
|
+
remoteConnector.sendRtcOffer(description, connection.connectionId)
|
|
188
186
|
})
|
|
189
187
|
} else {
|
|
190
188
|
connection.once('localDescription', (description: string) => {
|
|
191
|
-
remoteConnector.sendRtcAnswer(description, connection.connectionId
|
|
189
|
+
remoteConnector.sendRtcAnswer(description, connection.connectionId)
|
|
192
190
|
})
|
|
193
191
|
}
|
|
194
192
|
|
|
@@ -214,10 +212,4 @@ export class WebrtcConnector {
|
|
|
214
212
|
|
|
215
213
|
this.rpcCommunicator.destroy()
|
|
216
214
|
}
|
|
217
|
-
|
|
218
|
-
public isOffering(targetPeerDescriptor: PeerDescriptor): boolean {
|
|
219
|
-
const myId = peerIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
220
|
-
const theirId = peerIdFromPeerDescriptor(targetPeerDescriptor)
|
|
221
|
-
return myId.hasSmallerHashThan(theirId)
|
|
222
|
-
}
|
|
223
215
|
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import { getAddressFromIceCandidate, isPrivateIPv4 } from '../../helpers/AddressTools'
|
|
4
|
-
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
5
4
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
6
5
|
import {
|
|
7
6
|
HandshakeError,
|
|
@@ -18,9 +17,10 @@ import { ManagedConnection } from '../ManagedConnection'
|
|
|
18
17
|
import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
|
|
19
18
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
20
19
|
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
21
|
-
import { DhtAddress } from '../../identifiers'
|
|
20
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
22
21
|
import { version } from '../../../package.json'
|
|
23
22
|
import { isCompatibleVersion } from '../../helpers/versionCompatibility'
|
|
23
|
+
import { ConnectionID } from '../IConnection'
|
|
24
24
|
|
|
25
25
|
const logger = new Logger(module)
|
|
26
26
|
|
|
@@ -72,16 +72,16 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
72
72
|
WebrtcConnectorRpcClient
|
|
73
73
|
)
|
|
74
74
|
connection.on('localCandidate', (candidate: string, mid: string) => {
|
|
75
|
-
remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId
|
|
75
|
+
remoteConnector.sendIceCandidate(candidate, mid, connection!.connectionId)
|
|
76
76
|
})
|
|
77
77
|
connection.once('localDescription', (description: string) => {
|
|
78
|
-
remoteConnector.sendRtcAnswer(description, connection!.connectionId
|
|
78
|
+
remoteConnector.sendRtcAnswer(description, connection!.connectionId)
|
|
79
79
|
})
|
|
80
80
|
connection.start(false)
|
|
81
81
|
}
|
|
82
82
|
|
|
83
83
|
// Always use offerers connectionId
|
|
84
|
-
connection!.setConnectionId(request.connectionId)
|
|
84
|
+
connection!.setConnectionId(request.connectionId as ConnectionID)
|
|
85
85
|
connection!.setRemoteDescription(request.description, 'offer')
|
|
86
86
|
|
|
87
87
|
managedConnection.on('handshakeRequest', (_sourceDescriptor: PeerDescriptor, sourceVersion: string) => {
|
|
@@ -103,7 +103,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
103
103
|
const connection = this.config.ongoingConnectAttempts.get(nodeId)?.getWebrtcConnection()
|
|
104
104
|
if (!connection) {
|
|
105
105
|
return {}
|
|
106
|
-
} else if (connection.connectionId
|
|
106
|
+
} else if (connection.connectionId !== request.connectionId) {
|
|
107
107
|
logger.trace(`Ignoring RTC answer due to connectionId mismatch`)
|
|
108
108
|
return {}
|
|
109
109
|
}
|
|
@@ -117,7 +117,7 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
117
117
|
const connection = this.config.ongoingConnectAttempts.get(nodeId)?.getWebrtcConnection()
|
|
118
118
|
if (!connection) {
|
|
119
119
|
return {}
|
|
120
|
-
} else if (connection.connectionId
|
|
120
|
+
} else if (connection.connectionId !== request.connectionId) {
|
|
121
121
|
logger.trace(`Ignoring remote candidate due to connectionId mismatch`)
|
|
122
122
|
return {}
|
|
123
123
|
} else if (this.isIceCandidateAllowed(request.candidate)) {
|
|
@@ -2,6 +2,7 @@ import { Logger } from '@streamr/utils'
|
|
|
2
2
|
import EventEmitter from 'eventemitter3'
|
|
3
3
|
import { ICloseEvent, IMessageEvent, w3cwebsocket as Websocket } from 'websocket'
|
|
4
4
|
import { ConnectionEvents, ConnectionID, ConnectionType, IConnection } from '../IConnection'
|
|
5
|
+
import { createRandomConnectionId } from '../Connection'
|
|
5
6
|
|
|
6
7
|
const logger = new Logger(module)
|
|
7
8
|
|
|
@@ -24,7 +25,7 @@ export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
24
25
|
|
|
25
26
|
constructor() {
|
|
26
27
|
super()
|
|
27
|
-
this.connectionId =
|
|
28
|
+
this.connectionId = createRandomConnectionId()
|
|
28
29
|
}
|
|
29
30
|
|
|
30
31
|
// TODO explicit default value for "selfSigned" or make it required
|
|
@@ -95,7 +96,7 @@ export class ClientWebsocket extends EventEmitter<ConnectionEvents> implements I
|
|
|
95
96
|
this.emit('disconnected', gracefulLeave, undefined, 'close() called')
|
|
96
97
|
this.removeAllListeners()
|
|
97
98
|
if (!this.destroyed) {
|
|
98
|
-
logger.trace(`Closing socket for connection ${this.connectionId
|
|
99
|
+
logger.trace(`Closing socket for connection ${this.connectionId}`)
|
|
99
100
|
this.socket?.close(gracefulLeave ? CUSTOM_GOING_AWAY : undefined)
|
|
100
101
|
} else {
|
|
101
102
|
logger.debug('Tried to close() a stopped connection')
|