@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
|
@@ -8,14 +8,14 @@ import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
|
8
8
|
import { StoreRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
9
9
|
import { StoreRpcRemote } from '../../src/dht/store/StoreRpcRemote'
|
|
10
10
|
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
11
|
-
import {
|
|
12
|
-
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
11
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
12
|
+
import { createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
|
|
13
13
|
|
|
14
14
|
describe('StoreRpcRemote', () => {
|
|
15
15
|
|
|
16
16
|
let rpcRemote: StoreRpcRemote
|
|
17
|
-
let clientRpcCommunicator: RpcCommunicator
|
|
18
|
-
let serverRpcCommunicator: RpcCommunicator
|
|
17
|
+
let clientRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
18
|
+
let serverRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
19
19
|
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
20
20
|
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
21
21
|
const data = createMockDataEntry()
|
|
@@ -9,6 +9,7 @@ import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTran
|
|
|
9
9
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
10
10
|
import { MetricsContext } from '@streamr/utils'
|
|
11
11
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
12
13
|
|
|
13
14
|
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
14
15
|
return new ConnectionManager({
|
|
@@ -68,8 +69,8 @@ describe('WebRTC Connection Management', () => {
|
|
|
68
69
|
|
|
69
70
|
manager2.on('message', (message: Message) => {
|
|
70
71
|
expect(message.messageId).toEqual('mockerer')
|
|
71
|
-
expect(manager1.getConnection(peerDescriptor2)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
72
|
-
expect(manager2.getConnection(peerDescriptor1)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
72
|
+
expect(manager1.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor2))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
73
|
+
expect(manager2.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor1))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
73
74
|
|
|
74
75
|
done()
|
|
75
76
|
})
|
|
@@ -91,8 +92,8 @@ describe('WebRTC Connection Management', () => {
|
|
|
91
92
|
}
|
|
92
93
|
manager1.on('message', (message: Message) => {
|
|
93
94
|
expect(message.messageId).toEqual('mockerer')
|
|
94
|
-
expect(manager1.getConnection(peerDescriptor2)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
95
|
-
expect(manager2.getConnection(peerDescriptor1)!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
95
|
+
expect(manager1.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor2))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
96
|
+
expect(manager2.getConnection(getNodeIdFromPeerDescriptor(peerDescriptor1))!.connectionType).toEqual(ConnectionType.WEBRTC)
|
|
96
97
|
|
|
97
98
|
done()
|
|
98
99
|
})
|
|
@@ -226,6 +227,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
226
227
|
manager1.send(msg),
|
|
227
228
|
disconnectedPromise1
|
|
228
229
|
])
|
|
229
|
-
expect(manager1.getConnection(msg.targetDescriptor
|
|
230
|
+
expect(manager1.getConnection(getNodeIdFromPeerDescriptor(msg.targetDescriptor))).toBeUndefined()
|
|
230
231
|
}, 20000)
|
|
231
232
|
})
|
|
@@ -11,11 +11,12 @@ import { createMockPeerDescriptor } from '../utils/utils'
|
|
|
11
11
|
import { IWebrtcConnectorRpc } from '../../src/proto/packages/dht/protos/DhtRpc.server'
|
|
12
12
|
import { waitForCondition } from '@streamr/utils'
|
|
13
13
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
14
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
14
15
|
|
|
15
16
|
describe('WebRTC rpc messages', () => {
|
|
16
17
|
|
|
17
|
-
let rpcCommunicator1: RpcCommunicator
|
|
18
|
-
let rpcCommunicator2: RpcCommunicator
|
|
18
|
+
let rpcCommunicator1: RpcCommunicator<DhtCallContext>
|
|
19
|
+
let rpcCommunicator2: RpcCommunicator<DhtCallContext>
|
|
19
20
|
let client: ProtoRpcClient<WebrtcConnectorRpcClient>
|
|
20
21
|
let requestConnectionCounter: number
|
|
21
22
|
let rtcOfferCounter: number
|
|
@@ -5,12 +5,12 @@ import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
|
5
5
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
6
6
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
7
7
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
|
-
import { SimulatorTransport } from '../../src/
|
|
9
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
8
|
+
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
10
9
|
import * as Err from '../../src/helpers/errors'
|
|
11
10
|
import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
12
11
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
13
12
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
13
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
14
14
|
|
|
15
15
|
const SERVICE_ID = 'test'
|
|
16
16
|
|
|
@@ -31,7 +31,7 @@ describe('Websocket Connection Management', () => {
|
|
|
31
31
|
let biggerNoWsServerManager: ConnectionManager
|
|
32
32
|
const simulator = new Simulator()
|
|
33
33
|
const wsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
34
|
-
nodeId:
|
|
34
|
+
nodeId: new Uint8Array([2]),
|
|
35
35
|
type: NodeType.NODEJS,
|
|
36
36
|
websocket: {
|
|
37
37
|
host: '127.0.0.1',
|
|
@@ -40,11 +40,11 @@ describe('Websocket Connection Management', () => {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
const noWsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
43
|
-
nodeId:
|
|
43
|
+
nodeId: new Uint8Array([1]),
|
|
44
44
|
type: NodeType.NODEJS,
|
|
45
45
|
}
|
|
46
46
|
const biggerNoWsServerConnectorPeerDescriptor: PeerDescriptor = {
|
|
47
|
-
nodeId:
|
|
47
|
+
nodeId: new Uint8Array([3]),
|
|
48
48
|
type: NodeType.NODEJS,
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -91,7 +91,7 @@ describe('Websocket Connection Management', () => {
|
|
|
91
91
|
await connectorTransport3.stop()
|
|
92
92
|
})
|
|
93
93
|
|
|
94
|
-
it('Can open connections to serverless peer with smaller
|
|
94
|
+
it('Can open connections to serverless peer with smaller nodeId', (done) => {
|
|
95
95
|
const dummyMessage: Message = {
|
|
96
96
|
serviceId: SERVICE_ID,
|
|
97
97
|
body: {
|
|
@@ -104,8 +104,12 @@ describe('Websocket Connection Management', () => {
|
|
|
104
104
|
}
|
|
105
105
|
noWsServerManager.on('message', (message: Message) => {
|
|
106
106
|
expect(message.messageId).toEqual('mockerer')
|
|
107
|
-
expect(wsServerManager.getConnection(noWsServerConnectorPeerDescriptor)!.connectionType).toEqual(
|
|
108
|
-
|
|
107
|
+
expect(wsServerManager.getConnection(getNodeIdFromPeerDescriptor(noWsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
108
|
+
ConnectionType.WEBSOCKET_SERVER
|
|
109
|
+
)
|
|
110
|
+
expect(noWsServerManager.getConnection(getNodeIdFromPeerDescriptor(wsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
111
|
+
ConnectionType.WEBSOCKET_CLIENT
|
|
112
|
+
)
|
|
109
113
|
|
|
110
114
|
done()
|
|
111
115
|
})
|
|
@@ -113,7 +117,7 @@ describe('Websocket Connection Management', () => {
|
|
|
113
117
|
wsServerManager.send(dummyMessage)
|
|
114
118
|
})
|
|
115
119
|
|
|
116
|
-
it('Can open connections to serverless peer with bigger
|
|
120
|
+
it('Can open connections to serverless peer with bigger nodeId', (done) => {
|
|
117
121
|
const dummyMessage: Message = {
|
|
118
122
|
serviceId: SERVICE_ID,
|
|
119
123
|
body: {
|
|
@@ -126,8 +130,12 @@ describe('Websocket Connection Management', () => {
|
|
|
126
130
|
}
|
|
127
131
|
biggerNoWsServerManager.on('message', (message: Message) => {
|
|
128
132
|
expect(message.messageId).toEqual('mockerer')
|
|
129
|
-
expect(wsServerManager.getConnection(biggerNoWsServerConnectorPeerDescriptor)!.connectionType).toEqual(
|
|
130
|
-
|
|
133
|
+
expect(wsServerManager.getConnection(getNodeIdFromPeerDescriptor(biggerNoWsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
134
|
+
ConnectionType.WEBSOCKET_SERVER
|
|
135
|
+
)
|
|
136
|
+
expect(biggerNoWsServerManager.getConnection(getNodeIdFromPeerDescriptor(wsServerConnectorPeerDescriptor))!.connectionType).toEqual(
|
|
137
|
+
ConnectionType.WEBSOCKET_CLIENT
|
|
138
|
+
)
|
|
131
139
|
|
|
132
140
|
done()
|
|
133
141
|
})
|
|
@@ -154,7 +162,7 @@ describe('Websocket Connection Management', () => {
|
|
|
154
162
|
waitForEvent3<TransportEvents>(wsServerManager, 'disconnected', 15000),
|
|
155
163
|
wsServerManager.send(dummyMessage)
|
|
156
164
|
])
|
|
157
|
-
expect(wsServerManager.getConnection(dummyMessage.targetDescriptor!)).toBeUndefined()
|
|
165
|
+
expect(wsServerManager.getConnection(getNodeIdFromPeerDescriptor(dummyMessage.targetDescriptor!))).toBeUndefined()
|
|
158
166
|
}, 20000)
|
|
159
167
|
|
|
160
168
|
it('Can open connections to peer with server', async () => {
|
|
@@ -171,12 +179,16 @@ describe('Websocket Connection Management', () => {
|
|
|
171
179
|
await noWsServerManager.send(dummyMessage)
|
|
172
180
|
await waitForCondition(
|
|
173
181
|
() => {
|
|
174
|
-
|
|
175
|
-
|
|
182
|
+
const nodeId = getNodeIdFromPeerDescriptor(noWsServerConnectorPeerDescriptor)
|
|
183
|
+
return (!!wsServerManager.getConnection(nodeId)
|
|
184
|
+
&& wsServerManager.getConnection(nodeId)!.connectionType === ConnectionType.WEBSOCKET_SERVER)
|
|
176
185
|
}
|
|
177
186
|
)
|
|
178
187
|
await waitForCondition(
|
|
179
|
-
() =>
|
|
188
|
+
() => {
|
|
189
|
+
const connection = noWsServerManager.getConnection(getNodeIdFromPeerDescriptor(wsServerConnectorPeerDescriptor))!
|
|
190
|
+
return connection.connectionType === ConnectionType.WEBSOCKET_CLIENT
|
|
191
|
+
}
|
|
180
192
|
)
|
|
181
193
|
})
|
|
182
194
|
|
|
@@ -7,11 +7,12 @@ import {
|
|
|
7
7
|
import { mockWebsocketConnectorRpc } from '../utils/utils'
|
|
8
8
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
9
9
|
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
10
|
+
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
10
11
|
|
|
11
12
|
describe('WebsocketConnectorRpc', () => {
|
|
12
13
|
|
|
13
|
-
let rpcCommunicator1: RpcCommunicator
|
|
14
|
-
let rpcCommunicator2: RpcCommunicator
|
|
14
|
+
let rpcCommunicator1: RpcCommunicator<DhtCallContext>
|
|
15
|
+
let rpcCommunicator2: RpcCommunicator<DhtCallContext>
|
|
15
16
|
let client1: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
16
17
|
let client2: ProtoRpcClient<WebsocketConnectorRpcClient>
|
|
17
18
|
const peerDescriptor1 = createMockPeerDescriptor()
|
|
@@ -24,7 +24,7 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport:
|
|
|
24
24
|
})
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
describe('RPC
|
|
27
|
+
describe('RPC connections over WebRTC', () => {
|
|
28
28
|
|
|
29
29
|
let manager1: ConnectionManager
|
|
30
30
|
let manager2: ConnectionManager
|
|
@@ -58,10 +58,10 @@ describe('RPC errors', () => {
|
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
afterEach(async () => {
|
|
61
|
-
await connectorTransport1.stop()
|
|
62
|
-
await connectorTransport2.stop()
|
|
63
61
|
await manager1.stop()
|
|
64
62
|
await manager2.stop()
|
|
63
|
+
await connectorTransport1.stop()
|
|
64
|
+
await connectorTransport2.stop()
|
|
65
65
|
simulator.stop()
|
|
66
66
|
})
|
|
67
67
|
|
|
@@ -104,6 +104,9 @@ describe('RPC errors', () => {
|
|
|
104
104
|
}, 60000)
|
|
105
105
|
|
|
106
106
|
/*
|
|
107
|
+
|
|
108
|
+
TODO enable these tests (NET-1177)
|
|
109
|
+
|
|
107
110
|
it.only('Throws a client-side exception if WebRTC connection fails', async () => {
|
|
108
111
|
|
|
109
112
|
const request: PingRequest = {
|
|
@@ -7,7 +7,7 @@ describe('Duplicate Detector', () => {
|
|
|
7
7
|
let detector: DuplicateDetector
|
|
8
8
|
|
|
9
9
|
beforeEach(async () => {
|
|
10
|
-
detector = new DuplicateDetector(MAX_VALUE_COUNT
|
|
10
|
+
detector = new DuplicateDetector(MAX_VALUE_COUNT)
|
|
11
11
|
})
|
|
12
12
|
|
|
13
13
|
it('detects duplicates', async () => {
|
|
@@ -16,7 +16,7 @@ describe('Duplicate Detector', () => {
|
|
|
16
16
|
expect(detector.isMostLikelyDuplicate('test')).toEqual(true)
|
|
17
17
|
})
|
|
18
18
|
|
|
19
|
-
it('
|
|
19
|
+
it('removes from tail when full', () => {
|
|
20
20
|
for (let i = 0; i < MAX_VALUE_COUNT; i++) {
|
|
21
21
|
detector.add(`test${i}`)
|
|
22
22
|
}
|
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { wait } from '@streamr/utils'
|
|
2
2
|
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
3
|
-
import {
|
|
4
|
-
getNodeIdFromPeerDescriptor,
|
|
5
|
-
} from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
3
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
4
|
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
8
|
-
import { createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
5
|
+
import { createRandomDhtAddress, getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
9
6
|
|
|
10
7
|
describe('LocalDataStore', () => {
|
|
11
8
|
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { RandomContactList } from '../../src/dht/contact/RandomContactList'
|
|
2
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
2
|
import { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
3
|
|
|
5
|
-
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress
|
|
4
|
+
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress } => {
|
|
6
5
|
return {
|
|
7
|
-
getNodeId: () => getDhtAddressFromRaw(nodeId)
|
|
8
|
-
getPeerId: () => PeerID.fromValue(nodeId)
|
|
6
|
+
getNodeId: () => getDhtAddressFromRaw(nodeId)
|
|
9
7
|
}
|
|
10
8
|
}
|
|
11
9
|
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
RouteMessageError,
|
|
7
7
|
RouteMessageWrapper
|
|
8
8
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
10
9
|
import {
|
|
11
10
|
createWrappedClosestPeersRequest,
|
|
12
11
|
createFindRequest,
|
|
@@ -17,11 +16,10 @@ import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
|
17
16
|
import { v4 } from 'uuid'
|
|
18
17
|
import { MockRouter } from '../utils/mock/Router'
|
|
19
18
|
import { MockTransport } from '../utils/mock/Transport'
|
|
20
|
-
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
21
19
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
22
20
|
import { Router } from '../../src/dht/routing/Router'
|
|
23
|
-
import { ITransport } from '../../src/
|
|
24
|
-
import {
|
|
21
|
+
import { ITransport } from '../../src/transport/ITransport'
|
|
22
|
+
import { areEqualPeerDescriptors, createRandomDhtAddress } from '../../src/identifiers'
|
|
25
23
|
|
|
26
24
|
const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
|
|
27
25
|
return {
|
|
@@ -57,7 +55,8 @@ describe('RecursiveOperationManager', () => {
|
|
|
57
55
|
routingPath: [],
|
|
58
56
|
reachableThrough: [],
|
|
59
57
|
sourcePeer: peerDescriptor1,
|
|
60
|
-
target: peerDescriptor2.nodeId
|
|
58
|
+
target: peerDescriptor2.nodeId,
|
|
59
|
+
parallelRootNodeIds: []
|
|
61
60
|
}
|
|
62
61
|
const rpcCommunicator = new FakeRpcCommunicator()
|
|
63
62
|
|
|
@@ -86,7 +85,7 @@ describe('RecursiveOperationManager', () => {
|
|
|
86
85
|
|
|
87
86
|
it('startFind with mode Node returns self if no peers', async () => {
|
|
88
87
|
const recursiveOperationManager = createRecursiveOperationManager()
|
|
89
|
-
const res = await recursiveOperationManager.execute(
|
|
88
|
+
const res = await recursiveOperationManager.execute(createRandomDhtAddress(), RecursiveOperation.FIND_NODE)
|
|
90
89
|
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
91
90
|
recursiveOperationManager.stop()
|
|
92
91
|
})
|
|
@@ -2,7 +2,7 @@ import { waitForCondition } from '@streamr/utils'
|
|
|
2
2
|
import { range } from 'lodash'
|
|
3
3
|
import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
|
|
4
4
|
import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
|
|
5
|
-
import { ServiceID } from '../../src/
|
|
5
|
+
import { ServiceID } from '../../src/types/ServiceID'
|
|
6
6
|
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
7
7
|
import { Message, PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { RecursiveOperationSessionRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
@@ -16,10 +16,11 @@ describe('RecursiveOperationSession', () => {
|
|
|
16
16
|
let localPeerDescriptor: PeerDescriptor
|
|
17
17
|
|
|
18
18
|
const createRpcRemote = (serviceId: ServiceID) => {
|
|
19
|
-
const
|
|
19
|
+
const mockPeerDescriptor = createMockPeerDescriptor()
|
|
20
|
+
const transport = environment.createTransport(mockPeerDescriptor)
|
|
20
21
|
const send = (msg: Message) => transport.send(msg)
|
|
21
22
|
return new RecursiveOperationSessionRpcRemote(
|
|
22
|
-
|
|
23
|
+
mockPeerDescriptor,
|
|
23
24
|
localPeerDescriptor,
|
|
24
25
|
new RoutingRpcCommunicator(serviceId, send),
|
|
25
26
|
RecursiveOperationSessionRpcClient
|
|
@@ -34,7 +35,7 @@ describe('RecursiveOperationSession', () => {
|
|
|
34
35
|
it('happy path', async () => {
|
|
35
36
|
const doRouteRequest = jest.fn()
|
|
36
37
|
const session = new RecursiveOperationSession({
|
|
37
|
-
transport: environment.createTransport(),
|
|
38
|
+
transport: environment.createTransport(localPeerDescriptor),
|
|
38
39
|
targetId: createRandomDhtAddress(),
|
|
39
40
|
localPeerDescriptor,
|
|
40
41
|
waitedRoutingPathCompletions: 3,
|
package/test/unit/Router.test.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { v4 } from 'uuid'
|
|
2
2
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
3
3
|
import { Router } from '../../src/dht/routing/Router'
|
|
4
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
5
4
|
import {
|
|
6
5
|
Message,
|
|
7
6
|
MessageType,
|
|
@@ -12,7 +11,7 @@ import {
|
|
|
12
11
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
13
12
|
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
14
13
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
15
|
-
import { DhtAddress } from '../../src/identifiers'
|
|
14
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor, createRandomDhtAddress } from '../../src/identifiers'
|
|
16
15
|
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
17
16
|
|
|
18
17
|
describe('Router', () => {
|
|
@@ -38,7 +37,8 @@ describe('Router', () => {
|
|
|
38
37
|
routingPath: [],
|
|
39
38
|
reachableThrough: [],
|
|
40
39
|
target: peerDescriptor1.nodeId,
|
|
41
|
-
sourcePeer: peerDescriptor2
|
|
40
|
+
sourcePeer: peerDescriptor2,
|
|
41
|
+
parallelRootNodeIds: []
|
|
42
42
|
}
|
|
43
43
|
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
44
44
|
const rpcCommunicator = new FakeRpcCommunicator()
|
|
@@ -68,31 +68,48 @@ describe('Router', () => {
|
|
|
68
68
|
requestId: v4(),
|
|
69
69
|
sourcePeer: peerDescriptor1,
|
|
70
70
|
reachableThrough: [],
|
|
71
|
-
routingPath: []
|
|
71
|
+
routingPath: [],
|
|
72
|
+
parallelRootNodeIds: []
|
|
72
73
|
}) as RouteMessageAck
|
|
73
74
|
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
74
75
|
})
|
|
75
76
|
|
|
76
77
|
it('doRouteMessage with connections', async () => {
|
|
77
|
-
connections.set(
|
|
78
|
+
connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
78
79
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
79
80
|
message,
|
|
80
81
|
target: peerDescriptor2.nodeId,
|
|
81
82
|
requestId: v4(),
|
|
82
83
|
sourcePeer: peerDescriptor1,
|
|
83
84
|
reachableThrough: [],
|
|
84
|
-
routingPath: []
|
|
85
|
+
routingPath: [],
|
|
86
|
+
parallelRootNodeIds: []
|
|
85
87
|
}) as RouteMessageAck
|
|
86
88
|
expect(ack.error).toBeUndefined()
|
|
87
89
|
})
|
|
88
90
|
|
|
91
|
+
it('doRouteMessage with parallelRootNodeIds', async () => {
|
|
92
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor2)
|
|
93
|
+
connections.set(nodeId, createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
94
|
+
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
95
|
+
message,
|
|
96
|
+
target: peerDescriptor2.nodeId,
|
|
97
|
+
requestId: v4(),
|
|
98
|
+
sourcePeer: peerDescriptor1,
|
|
99
|
+
reachableThrough: [],
|
|
100
|
+
routingPath: [],
|
|
101
|
+
parallelRootNodeIds: [nodeId]
|
|
102
|
+
}) as RouteMessageAck
|
|
103
|
+
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
104
|
+
})
|
|
105
|
+
|
|
89
106
|
it('route server is destination without connections', async () => {
|
|
90
107
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
91
108
|
expect(ack.error).toBeUndefined()
|
|
92
109
|
})
|
|
93
110
|
|
|
94
111
|
it('route server with connections', async () => {
|
|
95
|
-
connections.set(
|
|
112
|
+
connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
96
113
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
97
114
|
expect(ack.error).toBeUndefined()
|
|
98
115
|
})
|
|
@@ -109,7 +126,7 @@ describe('Router', () => {
|
|
|
109
126
|
})
|
|
110
127
|
|
|
111
128
|
it('forward server with connections', async () => {
|
|
112
|
-
connections.set(
|
|
129
|
+
connections.set(createRandomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
113
130
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
114
131
|
expect(ack.error).toBeUndefined()
|
|
115
132
|
})
|
|
@@ -4,8 +4,7 @@ import { Message, MessageType, PeerDescriptor, RouteMessageWrapper } from '../..
|
|
|
4
4
|
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
5
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
6
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
7
|
-
import { getNodeIdFromPeerDescriptor } from '../../src/
|
|
8
|
-
import { DhtAddress } from '../../src/identifiers'
|
|
7
|
+
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
9
8
|
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
10
9
|
|
|
11
10
|
describe('RoutingSession', () => {
|
|
@@ -33,7 +32,8 @@ describe('RoutingSession', () => {
|
|
|
33
32
|
routingPath: [],
|
|
34
33
|
reachableThrough: [],
|
|
35
34
|
target: mockPeerDescriptor1.nodeId,
|
|
36
|
-
sourcePeer: mockPeerDescriptor2
|
|
35
|
+
sourcePeer: mockPeerDescriptor2,
|
|
36
|
+
parallelRootNodeIds: []
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
2
|
-
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
2
|
import { DhtAddress, DhtAddressRaw, createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
3
|
|
|
5
|
-
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress
|
|
4
|
+
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress } => {
|
|
6
5
|
return {
|
|
7
|
-
getNodeId: () => getDhtAddressFromRaw(nodeId)
|
|
8
|
-
getPeerId: () => PeerID.fromValue(nodeId)
|
|
6
|
+
getNodeId: () => getDhtAddressFromRaw(nodeId)
|
|
9
7
|
}
|
|
10
8
|
}
|
|
11
9
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { waitForCondition } from '@streamr/utils'
|
|
1
|
+
import { ipv4ToNumber, waitForCondition } from '@streamr/utils'
|
|
2
2
|
import { EventEmitter } from 'eventemitter3'
|
|
3
3
|
import { once } from 'events'
|
|
4
4
|
import { Server as HttpServer, createServer as createHttpServer } from 'http'
|
|
@@ -34,8 +34,9 @@ describe('connectivityRequestHandler', () => {
|
|
|
34
34
|
it('happy path', async () => {
|
|
35
35
|
const connection: any = new EventEmitter()
|
|
36
36
|
connection.send = jest.fn()
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
connection.getRemoteIp = () => HOST
|
|
38
|
+
|
|
39
|
+
attachConnectivityRequestHandler(connection)
|
|
39
40
|
const request: Message = {
|
|
40
41
|
serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
41
42
|
messageType: MessageType.CONNECTIVITY_REQUEST,
|
|
@@ -60,6 +61,7 @@ describe('connectivityRequestHandler', () => {
|
|
|
60
61
|
port: PORT,
|
|
61
62
|
tls: false
|
|
62
63
|
},
|
|
64
|
+
ipAddress: ipv4ToNumber(HOST)
|
|
63
65
|
},
|
|
64
66
|
oneofKind: 'connectivityResponse'
|
|
65
67
|
},
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { ipv4ToNumber } from '@streamr/utils'
|
|
2
|
+
import { createPeerDescriptor } from '../../src/helpers/createPeerDescriptor'
|
|
3
|
+
import { isBrowserEnvironment } from '../../src/helpers/browser/isBrowserEnvironment'
|
|
4
|
+
import { NodeType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
6
|
+
|
|
7
|
+
const IP_ADDRESS = '1.2.3.4'
|
|
8
|
+
|
|
9
|
+
describe('createPeerDescriptor', () => {
|
|
10
|
+
|
|
11
|
+
it('without websocket', () => {
|
|
12
|
+
const connectivityResponse = {
|
|
13
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS)
|
|
14
|
+
} as any
|
|
15
|
+
const peerDescriptor = createPeerDescriptor(connectivityResponse)
|
|
16
|
+
expect(peerDescriptor).toEqual({
|
|
17
|
+
nodeId: expect.any(Uint8Array),
|
|
18
|
+
type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
|
|
19
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
20
|
+
publicKey: expect.any(Uint8Array),
|
|
21
|
+
signature: expect.any(Uint8Array)
|
|
22
|
+
})
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
it('with websocket', () => {
|
|
26
|
+
const connectivityResponse = {
|
|
27
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
28
|
+
websocket: {
|
|
29
|
+
host: 'bar.com',
|
|
30
|
+
port: 123,
|
|
31
|
+
tls: true
|
|
32
|
+
}
|
|
33
|
+
} as any
|
|
34
|
+
const peerDescriptor = createPeerDescriptor(connectivityResponse)
|
|
35
|
+
expect(peerDescriptor).toEqual({
|
|
36
|
+
nodeId: expect.any(Uint8Array),
|
|
37
|
+
type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
|
|
38
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
39
|
+
publicKey: expect.any(Uint8Array),
|
|
40
|
+
signature: expect.any(Uint8Array),
|
|
41
|
+
websocket: {
|
|
42
|
+
host: 'bar.com',
|
|
43
|
+
port: 123,
|
|
44
|
+
tls: true
|
|
45
|
+
}
|
|
46
|
+
})
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('explicit nodeId', () => {
|
|
50
|
+
const nodeId = createRandomDhtAddress()
|
|
51
|
+
const connectivityResponse = {
|
|
52
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS)
|
|
53
|
+
} as any
|
|
54
|
+
const peerDescriptor = createPeerDescriptor(connectivityResponse, nodeId)
|
|
55
|
+
expect(peerDescriptor).toEqual({
|
|
56
|
+
nodeId: getRawFromDhtAddress(nodeId),
|
|
57
|
+
type: isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS,
|
|
58
|
+
ipAddress: ipv4ToNumber(IP_ADDRESS),
|
|
59
|
+
publicKey: expect.any(Uint8Array),
|
|
60
|
+
signature: expect.any(Uint8Array)
|
|
61
|
+
})
|
|
62
|
+
})
|
|
63
|
+
})
|
|
@@ -5,13 +5,16 @@ import { Message, PeerDescriptor } from '../../src/proto/packages/dht/protos/Dht
|
|
|
5
5
|
class FakeTransport extends EventEmitter<TransportEvents> implements ITransport {
|
|
6
6
|
|
|
7
7
|
private onSend: (msg: Message) => void
|
|
8
|
+
private readonly localPeerDescriptor: PeerDescriptor
|
|
8
9
|
|
|
9
|
-
constructor(onSend: (msg: Message) => void) {
|
|
10
|
+
constructor(peerDescriptor: PeerDescriptor, onSend: (msg: Message) => void) {
|
|
10
11
|
super()
|
|
11
12
|
this.onSend = onSend
|
|
13
|
+
this.localPeerDescriptor = peerDescriptor
|
|
12
14
|
}
|
|
13
15
|
|
|
14
16
|
async send(msg: Message): Promise<void> {
|
|
17
|
+
msg.sourceDescriptor = this.localPeerDescriptor
|
|
15
18
|
this.onSend(msg)
|
|
16
19
|
}
|
|
17
20
|
|
|
@@ -21,7 +24,7 @@ class FakeTransport extends EventEmitter<TransportEvents> implements ITransport
|
|
|
21
24
|
}
|
|
22
25
|
|
|
23
26
|
// eslint-disable-next-line class-methods-use-this
|
|
24
|
-
|
|
27
|
+
getConnections(): PeerDescriptor[] {
|
|
25
28
|
throw new Error('not implemented')
|
|
26
29
|
}
|
|
27
30
|
|
|
@@ -34,8 +37,8 @@ export class FakeEnvironment {
|
|
|
34
37
|
|
|
35
38
|
private transports: FakeTransport[] = []
|
|
36
39
|
|
|
37
|
-
createTransport(): ITransport {
|
|
38
|
-
const transport = new FakeTransport((msg) => {
|
|
40
|
+
createTransport(peerDescriptor: PeerDescriptor): ITransport {
|
|
41
|
+
const transport = new FakeTransport(peerDescriptor, (msg) => {
|
|
39
42
|
this.transports.forEach((t) => t.emit('message', msg))
|
|
40
43
|
})
|
|
41
44
|
this.transports.push(transport)
|
|
@@ -15,7 +15,7 @@ export class MockTransport extends EventEmitter<TransportEvents> implements ITra
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
// eslint-disable-next-line class-methods-use-this
|
|
18
|
-
|
|
18
|
+
getConnections(): PeerDescriptor[] {
|
|
19
19
|
return []
|
|
20
20
|
}
|
|
21
21
|
|
package/test/utils/utils.ts
CHANGED
|
@@ -235,15 +235,15 @@ async function waitReadyForTesting(connectionManager: ConnectionManager, limit:
|
|
|
235
235
|
connectionManager.garbageCollectConnections(limit, LAST_USED_LIMIT)
|
|
236
236
|
try {
|
|
237
237
|
await waitForCondition(() => {
|
|
238
|
-
return (connectionManager.
|
|
239
|
-
connectionManager.
|
|
240
|
-
connectionManager.
|
|
238
|
+
return (connectionManager.getLocalLockedConnectionCount() === 0 &&
|
|
239
|
+
connectionManager.getRemoteLockedConnectionCount() === 0 &&
|
|
240
|
+
connectionManager.getConnections().length <= limit)
|
|
241
241
|
}, 20000)
|
|
242
242
|
} catch (err) {
|
|
243
|
-
if (connectionManager.
|
|
244
|
-
&& connectionManager.
|
|
243
|
+
if (connectionManager.getLocalLockedConnectionCount() > 0
|
|
244
|
+
&& connectionManager.getRemoteLockedConnectionCount() > 0) {
|
|
245
245
|
throw new Error('Connections are still locked')
|
|
246
|
-
} else if (connectionManager.
|
|
246
|
+
} else if (connectionManager.getConnections().length > limit) {
|
|
247
247
|
throw new Error(`ConnectionManager has more than ${limit}`)
|
|
248
248
|
}
|
|
249
249
|
}
|