@streamr/dht 0.0.1-tatum.6 → 0.0.1-tatum.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/connection/ConnectionLockHandler.d.ts +1 -1
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +10 -0
- package/dist/src/connection/{RemoteConnectionLocker.js → ConnectionLockRpcRemote.js} +21 -35
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +17 -41
- package/dist/src/connection/ConnectionManager.js +148 -212
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.js +16 -13
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +49 -0
- package/dist/src/connection/ConnectorFacade.js +83 -0
- package/dist/src/connection/ConnectorFacade.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +1 -2
- package/dist/src/connection/Handshaker.js +1 -4
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -6
- package/dist/src/connection/ManagedConnection.js +27 -36
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.js +2 -2
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -1
- package/dist/src/connection/Simulator/Simulator.d.ts +0 -2
- package/dist/src/connection/Simulator/Simulator.js +0 -5
- package/dist/src/connection/Simulator/Simulator.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnection.js +16 -13
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +2 -3
- package/dist/src/connection/Simulator/SimulatorConnector.js +12 -14
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js +6 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +3 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +12 -12
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -1
- package/dist/src/connection/WebRTC/{WebRtcConnector.d.ts → WebRtcConnectorRpcLocal.d.ts} +13 -13
- package/dist/src/connection/WebRTC/{WebRtcConnector.js → WebRtcConnectorRpcLocal.js} +46 -38
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.d.ts +11 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js +55 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +1 -1
- package/dist/src/connection/WebSocket/{WebSocketConnector.d.ts → WebSocketConnectorRpcLocal.d.ts} +21 -11
- package/dist/src/connection/WebSocket/{WebSocketConnector.js → WebSocketConnectorRpcLocal.js} +80 -59
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.d.ts +8 -0
- package/dist/src/connection/WebSocket/{RemoteWebSocketConnector.js → WebSocketConnectorRpcRemote.js} +12 -16
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +11 -1
- package/dist/src/connection/WebSocket/WebSocketServer.js +15 -10
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +18 -55
- package/dist/src/dht/DhtNode.js +122 -145
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/{RemoteExternalApi.d.ts → ExternalApiRpcRemote.d.ts} +2 -2
- package/dist/src/dht/{RemoteExternalApi.js → ExternalApiRpcRemote.js} +5 -6
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -0
- package/dist/src/dht/{DhtPeer.d.ts → RemoteDhtNode.d.ts} +2 -3
- package/dist/src/dht/{DhtPeer.js → RemoteDhtNode.js} +21 -19
- package/dist/src/dht/RemoteDhtNode.js.map +1 -0
- package/dist/src/dht/contact/ContactList.d.ts +0 -1
- package/dist/src/dht/contact/ContactList.js +0 -3
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +0 -1
- package/dist/src/dht/contact/RandomContactList.js +0 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +0 -3
- package/dist/src/dht/contact/SortedContactList.js +0 -9
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +5 -7
- package/dist/src/dht/discovery/DiscoverySession.js +9 -10
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +12 -11
- package/dist/src/dht/discovery/PeerDiscovery.js +33 -37
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/RecursiveFindSession.d.ts +9 -10
- package/dist/src/dht/find/RecursiveFindSession.js +13 -13
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -1
- package/dist/src/dht/find/RecursiveFinder.d.ts +9 -11
- package/dist/src/dht/find/RecursiveFinder.js +35 -36
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +4 -4
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.d.ts +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.js +4 -3
- package/dist/src/dht/registerExternalApiRpcMethods.js.map +1 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +1 -2
- package/dist/src/dht/routing/DuplicateDetector.js +2 -7
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +12 -15
- package/dist/src/dht/routing/Router.js +30 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/{RemoteRouter.d.ts → RouterRpcRemote.d.ts} +2 -2
- package/dist/src/dht/routing/{RemoteRouter.js → RouterRpcRemote.js} +5 -5
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -4
- package/dist/src/dht/routing/RoutingSession.js +6 -5
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/{DataStore.d.ts → StoreRpcLocal.d.ts} +6 -6
- package/dist/src/dht/store/{DataStore.js → StoreRpcLocal.js} +34 -34
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -0
- package/dist/src/dht/store/{RemoteStore.d.ts → StoreRpcRemote.d.ts} +2 -2
- package/dist/src/dht/store/{RemoteStore.js → StoreRpcRemote.js} +4 -4
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -0
- package/dist/src/exports.d.ts +2 -8
- package/dist/src/exports.js +2 -14
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +0 -1
- package/dist/src/helpers/PeerID.js +0 -6
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js +6 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js.map +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js +7 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +1 -0
- package/dist/src/helpers/kademliaId.d.ts +1 -0
- package/dist/src/helpers/kademliaId.js +14 -0
- package/dist/src/helpers/kademliaId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -2
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +29 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +39 -39
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +49 -162
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +47 -88
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +15 -15
- package/dist/src/transport/RoutingRpcCommunicator.js +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +10 -9
- package/protos/DhtRpc.proto +30 -60
- package/src/connection/ConnectionLockHandler.ts +1 -1
- package/src/connection/ConnectionLockRpcRemote.ts +62 -0
- package/src/connection/ConnectionManager.ts +178 -274
- package/src/connection/ConnectivityChecker.ts +15 -12
- package/src/connection/ConnectorFacade.ts +140 -0
- package/src/connection/Handshaker.ts +0 -5
- package/src/connection/ManagedConnection.ts +26 -40
- package/src/connection/ManagedWebRtcConnection.ts +0 -2
- package/src/connection/Simulator/Simulator.ts +0 -7
- package/src/connection/Simulator/SimulatorConnection.ts +16 -13
- package/src/connection/Simulator/SimulatorConnector.ts +13 -19
- package/src/connection/Simulator/SimulatorTransport.ts +6 -1
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +15 -14
- package/src/connection/WebRTC/{WebRtcConnector.ts → WebRtcConnectorRpcLocal.ts} +68 -56
- package/src/connection/WebRTC/WebRtcConnectorRpcRemote.ts +71 -0
- package/src/connection/WebRTC/iceServerAsString.ts +1 -1
- package/src/connection/WebSocket/{WebSocketConnector.ts → WebSocketConnectorRpcLocal.ts} +102 -79
- package/src/connection/WebSocket/WebSocketConnectorRpcRemote.ts +45 -0
- package/src/connection/WebSocket/WebSocketServer.ts +26 -8
- package/src/dht/DhtNode.ts +176 -203
- package/src/dht/{RemoteExternalApi.ts → ExternalApiRpcRemote.ts} +3 -4
- package/src/dht/{DhtPeer.ts → RemoteDhtNode.ts} +11 -9
- package/src/dht/contact/ContactList.ts +0 -4
- package/src/dht/contact/RandomContactList.ts +0 -4
- package/src/dht/contact/SortedContactList.ts +0 -12
- package/src/dht/discovery/DiscoverySession.ts +20 -23
- package/src/dht/discovery/PeerDiscovery.ts +47 -45
- package/src/dht/find/RecursiveFindSession.ts +21 -22
- package/src/dht/find/RecursiveFinder.ts +45 -49
- package/src/dht/find/RemoteRecursiveFindSession.ts +6 -6
- package/src/dht/registerExternalApiRpcMethods.ts +8 -5
- package/src/dht/routing/DuplicateDetector.ts +3 -10
- package/src/dht/routing/Router.ts +39 -45
- package/src/dht/routing/{RemoteRouter.ts → RouterRpcRemote.ts} +4 -4
- package/src/dht/routing/RoutingSession.ts +15 -15
- package/src/dht/store/{DataStore.ts → StoreRpcLocal.ts} +42 -42
- package/src/dht/store/{RemoteStore.ts → StoreRpcRemote.ts} +2 -2
- package/src/exports.ts +2 -8
- package/src/helpers/PeerID.ts +0 -7
- package/src/helpers/browser/isBrowserEnvironment.ts +1 -0
- package/src/helpers/browser/isBrowserEnvironment_override.ts +3 -0
- package/src/helpers/kademliaId.ts +8 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +1 -1
- package/src/helpers/protoClasses.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +54 -54
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +15 -15
- package/src/proto/packages/dht/protos/DhtRpc.ts +77 -216
- package/src/transport/RoutingRpcCommunicator.ts +1 -0
- package/test/benchmark/KademliaCorrectness.test.ts +4 -2
- package/test/benchmark/RecursiveFind.test.ts +6 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +9 -9
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +5 -5
- package/test/end-to-end/Layer0WebRTC.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +13 -8
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +15 -10
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +5 -5
- package/test/integration/ConnectionLocking.test.ts +32 -26
- package/test/integration/ConnectionManager.test.ts +90 -93
- package/test/integration/DhtJoinPeerDiscovery.test.ts +53 -0
- package/test/integration/DhtRpc.test.ts +4 -6
- package/test/integration/Layer1-scale.test.ts +8 -8
- package/test/integration/MigrateData.test.ts +9 -9
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -2
- package/test/integration/RecursiveFind.test.ts +5 -5
- package/test/integration/{DhtPeer.test.ts → RemoteDhtNode.test.ts} +11 -12
- package/test/integration/RouteMessage.test.ts +7 -9
- package/test/integration/{RemoteRouter.test.ts → RouterRpcRemote.test.ts} +13 -14
- package/test/integration/RpcErrors.test.ts +25 -10
- package/test/integration/ScaleDownDht.test.ts +8 -8
- package/test/integration/SimultaneousConnections.test.ts +35 -36
- package/test/integration/Store.test.ts +8 -9
- package/test/integration/StoreAndDelete.test.ts +11 -11
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
- package/test/integration/{RemoteStore.test.ts → StoreRpcRemote.test.ts} +17 -18
- package/test/integration/WebRtcConnectionManagement.test.ts +26 -19
- package/test/integration/WebRtcConnectorRpc.test.ts +17 -32
- package/test/integration/WebSocket.test.ts +4 -2
- package/test/integration/WebSocketConnectionManagement.test.ts +30 -17
- package/test/integration/WebSocketConnectorRpc.test.ts +10 -15
- package/test/unit/DuplicateDetector.test.ts +3 -4
- package/test/unit/LocalDataStore.test.ts +6 -8
- package/test/unit/RandomContactList.test.ts +1 -1
- package/test/unit/RecursiveFinder.test.ts +13 -18
- package/test/unit/Router.test.ts +18 -21
- package/test/unit/WebSocketConnectorRpcLocal.test.ts +64 -0
- package/test/unit/WebSocketServer.test.ts +24 -12
- package/test/unit/{webrtcReplaceInternalIpWithExternalIp.ts → webrtcReplaceInternalIpWithExternalIp.test.ts} +1 -1
- package/test/utils/mock/RecursiveFinder.ts +2 -2
- package/test/utils/mock/Router.ts +9 -11
- package/test/utils/mock/Transport.ts +2 -2
- package/test/utils/utils.ts +55 -74
- package/dist/src/connection/RemoteConnectionLocker.d.ts +0 -13
- package/dist/src/connection/RemoteConnectionLocker.js.map +0 -1
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +0 -12
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +0 -74
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +0 -1
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +0 -9
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +0 -1
- package/dist/src/dht/DhtPeer.js.map +0 -1
- package/dist/src/dht/RemoteExternalApi.js.map +0 -1
- package/dist/src/dht/routing/RemoteRouter.js.map +0 -1
- package/dist/src/dht/store/DataStore.js.map +0 -1
- package/dist/src/dht/store/RemoteStore.js.map +0 -1
- package/dist/src/helpers/browser/isBrowser.d.ts +0 -1
- package/dist/src/helpers/browser/isBrowser.js +0 -6
- package/dist/src/helpers/browser/isBrowser.js.map +0 -1
- package/dist/src/helpers/browser/isNodeJS.d.ts +0 -1
- package/dist/src/helpers/browser/isNodeJS.js +0 -6
- package/dist/src/helpers/browser/isNodeJS.js.map +0 -1
- package/src/connection/RemoteConnectionLocker.ts +0 -84
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +0 -93
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +0 -49
- package/src/helpers/browser/isBrowser.ts +0 -1
- package/src/helpers/browser/isNodeJS.ts +0 -1
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +0 -46
- package/test/integration/DhtWithMockConnections.test.ts +0 -46
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +0 -47
|
@@ -4,7 +4,7 @@ import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
|
4
4
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
5
5
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
6
6
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
|
-
import {
|
|
7
|
+
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
8
|
import { waitForCondition } from '@streamr/utils'
|
|
9
9
|
|
|
10
10
|
describe('Storing data in DHT with two peers', () => {
|
|
@@ -48,13 +48,13 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
48
48
|
|
|
49
49
|
const successfulStorers1 = await otherNode.storeDataToDht(dataKey1.value, data1)
|
|
50
50
|
const successfulStorers2 = await entryPoint.storeDataToDht(dataKey2.value, data2)
|
|
51
|
-
expect(successfulStorers1[0].
|
|
52
|
-
expect(successfulStorers2[0].
|
|
51
|
+
expect(successfulStorers1[0].kademliaId).toStrictEqual(entryPoint.getPeerDescriptor().kademliaId)
|
|
52
|
+
expect(successfulStorers2[0].kademliaId).toStrictEqual(otherNode.getPeerDescriptor().kademliaId)
|
|
53
53
|
|
|
54
54
|
const foundData1 = await otherNode.getDataFromDht(dataKey1.value)
|
|
55
55
|
const foundData2 = await entryPoint.getDataFromDht(dataKey2.value)
|
|
56
|
-
expect(
|
|
57
|
-
expect(
|
|
56
|
+
expect(areEqualPeerDescriptors(otherNode.getPeerDescriptor(), Any.unpack(foundData1[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
57
|
+
expect(areEqualPeerDescriptors(entryPoint.getPeerDescriptor(), Any.unpack(foundData2[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
58
58
|
})
|
|
59
59
|
|
|
60
60
|
it('Can store on one peer DHT', async () => {
|
|
@@ -63,9 +63,9 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
63
63
|
const dataKey = PeerID.fromString('data-to-store')
|
|
64
64
|
const data = Any.pack(entryPoint.getPeerDescriptor(), PeerDescriptor)
|
|
65
65
|
const successfulStorers = await entryPoint.storeDataToDht(dataKey.value, data)
|
|
66
|
-
expect(successfulStorers[0].
|
|
66
|
+
expect(successfulStorers[0].kademliaId).toStrictEqual(entryPoint.getPeerDescriptor().kademliaId)
|
|
67
67
|
|
|
68
68
|
const foundData = await entryPoint.getDataFromDht(dataKey.value)
|
|
69
|
-
expect(
|
|
69
|
+
expect(areEqualPeerDescriptors(entryPoint.getPeerDescriptor(), Any.unpack(foundData[0]!.data!, PeerDescriptor))).toBeTrue()
|
|
70
70
|
}, 60000)
|
|
71
71
|
})
|
|
@@ -5,21 +5,20 @@ import {
|
|
|
5
5
|
StoreDataRequest,
|
|
6
6
|
StoreDataResponse
|
|
7
7
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
|
-
import { generateId,
|
|
8
|
+
import { generateId, mockStoreRpc } from '../utils/utils'
|
|
9
9
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import { RemoteStore } from '../../src/dht/store/RemoteStore'
|
|
10
|
+
import { StoreRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
11
|
+
import { StoreRpcRemote } from '../../src/dht/store/StoreRpcRemote'
|
|
13
12
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
14
13
|
|
|
15
|
-
describe('
|
|
14
|
+
describe('StoreRpcRemote', () => {
|
|
16
15
|
|
|
17
|
-
let
|
|
16
|
+
let rpcRemote: StoreRpcRemote
|
|
18
17
|
let clientRpcCommunicator: RpcCommunicator
|
|
19
18
|
let serverRpcCommunicator: RpcCommunicator
|
|
20
19
|
const serviceId = 'test'
|
|
21
20
|
const clientPeerDescriptor: PeerDescriptor = {
|
|
22
|
-
kademliaId: generateId('
|
|
21
|
+
kademliaId: generateId('client'),
|
|
23
22
|
type: NodeType.NODEJS
|
|
24
23
|
}
|
|
25
24
|
const serverPeerDescriptor: PeerDescriptor = {
|
|
@@ -36,31 +35,31 @@ describe('RemoteStore', () => {
|
|
|
36
35
|
beforeEach(() => {
|
|
37
36
|
clientRpcCommunicator = new RpcCommunicator()
|
|
38
37
|
serverRpcCommunicator = new RpcCommunicator()
|
|
39
|
-
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData',
|
|
40
|
-
clientRpcCommunicator.on('outgoingMessage', (message: RpcMessage
|
|
38
|
+
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.storeData)
|
|
39
|
+
clientRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
41
40
|
serverRpcCommunicator.handleIncomingMessage(message)
|
|
42
41
|
})
|
|
43
|
-
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage
|
|
42
|
+
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
44
43
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
45
44
|
})
|
|
46
|
-
const client = toProtoRpcClient(new
|
|
47
|
-
|
|
45
|
+
const client = toProtoRpcClient(new StoreRpcClient(clientRpcCommunicator.getRpcClientTransport()))
|
|
46
|
+
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor, serviceId, client)
|
|
48
47
|
})
|
|
49
48
|
|
|
50
49
|
it('storeData happy path', async () => {
|
|
51
|
-
const response = await
|
|
50
|
+
const response = await rpcRemote.storeData(request)
|
|
52
51
|
expect(response.error).toBeEmpty()
|
|
53
52
|
})
|
|
54
53
|
|
|
55
54
|
it('storeData rejects', async () => {
|
|
56
|
-
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData',
|
|
57
|
-
await expect(
|
|
58
|
-
.rejects.toThrowError('Could not store data to 736572766572 from
|
|
55
|
+
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.throwStoreDataError)
|
|
56
|
+
await expect(rpcRemote.storeData(request))
|
|
57
|
+
.rejects.toThrowError('Could not store data to 736572766572 from 636c69656e74 Error: Mock')
|
|
59
58
|
})
|
|
60
59
|
|
|
61
60
|
it('storeData response error', async () => {
|
|
62
|
-
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData',
|
|
63
|
-
const response = await
|
|
61
|
+
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.storeDataErrorString)
|
|
62
|
+
const response = await rpcRemote.storeData(request)
|
|
64
63
|
expect(response.error).toEqual('Mock')
|
|
65
64
|
})
|
|
66
65
|
|
|
@@ -6,7 +6,19 @@ import { PeerID } from '../../src/helpers/PeerID'
|
|
|
6
6
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
7
7
|
import { ITransport } from '../../src/transport/ITransport'
|
|
8
8
|
import * as Err from '../../src/helpers/errors'
|
|
9
|
-
import { SimulatorTransport } from '../../src/
|
|
9
|
+
import { SimulatorTransport } from '../../src/connection/Simulator/SimulatorTransport'
|
|
10
|
+
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
11
|
+
import { MetricsContext } from '@streamr/utils'
|
|
12
|
+
|
|
13
|
+
const createConnectionManager = (ownPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
14
|
+
return new ConnectionManager({
|
|
15
|
+
createConnectorFacade: () => new DefaultConnectorFacade({
|
|
16
|
+
transport,
|
|
17
|
+
createOwnPeerDescriptor: () => ownPeerDescriptor
|
|
18
|
+
}),
|
|
19
|
+
metricsContext: new MetricsContext()
|
|
20
|
+
})
|
|
21
|
+
}
|
|
10
22
|
|
|
11
23
|
describe('WebRTC Connection Management', () => {
|
|
12
24
|
|
|
@@ -17,32 +29,27 @@ describe('WebRTC Connection Management', () => {
|
|
|
17
29
|
|
|
18
30
|
const peerDescriptor1: PeerDescriptor = {
|
|
19
31
|
kademliaId: PeerID.fromString('peer1').value,
|
|
20
|
-
nodeName: 'peer1',
|
|
21
32
|
type: NodeType.NODEJS,
|
|
22
33
|
}
|
|
23
34
|
|
|
24
35
|
const peerDescriptor2: PeerDescriptor = {
|
|
25
36
|
kademliaId: PeerID.fromString('peer2').value,
|
|
26
|
-
nodeName: 'peer2',
|
|
27
37
|
type: NodeType.NODEJS,
|
|
28
38
|
}
|
|
29
39
|
|
|
30
|
-
let connectorTransport1:
|
|
31
|
-
let connectorTransport2:
|
|
40
|
+
let connectorTransport1: SimulatorTransport
|
|
41
|
+
let connectorTransport2: SimulatorTransport
|
|
32
42
|
|
|
33
43
|
beforeEach(async () => {
|
|
34
|
-
|
|
35
44
|
simulator = new Simulator(LatencyType.FIXED, 500)
|
|
36
|
-
|
|
37
45
|
connectorTransport1 = new SimulatorTransport(peerDescriptor1, simulator)
|
|
38
|
-
|
|
39
|
-
|
|
46
|
+
await connectorTransport1.start()
|
|
47
|
+
manager1 = createConnectionManager(peerDescriptor1, connectorTransport1)
|
|
40
48
|
connectorTransport2 = new SimulatorTransport(peerDescriptor2, simulator)
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
await manager1.start(
|
|
44
|
-
await manager2.start(
|
|
45
|
-
|
|
49
|
+
await connectorTransport2.start()
|
|
50
|
+
manager2 = createConnectionManager(peerDescriptor2, connectorTransport2)
|
|
51
|
+
await manager1.start()
|
|
52
|
+
await manager2.start()
|
|
46
53
|
})
|
|
47
54
|
|
|
48
55
|
afterEach(async () => {
|
|
@@ -138,26 +145,26 @@ describe('WebRTC Connection Management', () => {
|
|
|
138
145
|
})
|
|
139
146
|
|
|
140
147
|
const connectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
141
|
-
manager1.on('connected', (
|
|
148
|
+
manager1.on('connected', () => {
|
|
142
149
|
//expect(message.messageType).toBe(MessageType.RPC)
|
|
143
150
|
resolve()
|
|
144
151
|
})
|
|
145
152
|
})
|
|
146
153
|
|
|
147
154
|
const connectedPromise2 = new Promise<void>((resolve, _reject) => {
|
|
148
|
-
manager2.on('connected', (
|
|
155
|
+
manager2.on('connected', () => {
|
|
149
156
|
resolve()
|
|
150
157
|
})
|
|
151
158
|
})
|
|
152
159
|
|
|
153
160
|
const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
154
|
-
manager1.on('disconnected', (
|
|
161
|
+
manager1.on('disconnected', () => {
|
|
155
162
|
resolve()
|
|
156
163
|
})
|
|
157
164
|
})
|
|
158
165
|
|
|
159
166
|
const disconnectedPromise2 = new Promise<void>((resolve, _reject) => {
|
|
160
|
-
manager2.on('disconnected', (
|
|
167
|
+
manager2.on('disconnected', () => {
|
|
161
168
|
resolve()
|
|
162
169
|
})
|
|
163
170
|
})
|
|
@@ -186,7 +193,7 @@ describe('WebRTC Connection Management', () => {
|
|
|
186
193
|
}
|
|
187
194
|
|
|
188
195
|
const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
189
|
-
manager1.on('disconnected', (
|
|
196
|
+
manager1.on('disconnected', () => {
|
|
190
197
|
resolve()
|
|
191
198
|
})
|
|
192
199
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
|
-
import {
|
|
2
|
+
import { WebRtcConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
3
|
import {
|
|
4
4
|
IceCandidate,
|
|
5
5
|
NodeType,
|
|
@@ -10,29 +10,22 @@ import {
|
|
|
10
10
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
11
|
import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
12
12
|
import { generateId } from '../utils/utils'
|
|
13
|
-
import {
|
|
14
|
-
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
15
|
-
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
13
|
+
import { IWebRtcConnectorRpc } from '../../src/proto/packages/dht/protos/DhtRpc.server'
|
|
16
14
|
import { waitForCondition } from '@streamr/utils'
|
|
17
15
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
18
16
|
|
|
19
17
|
describe('WebRTC rpc messages', () => {
|
|
20
18
|
let rpcCommunicator1: RpcCommunicator
|
|
21
19
|
let rpcCommunicator2: RpcCommunicator
|
|
22
|
-
let client: ProtoRpcClient<
|
|
20
|
+
let client: ProtoRpcClient<WebRtcConnectorRpcClient>
|
|
23
21
|
|
|
24
22
|
let requestConnectionCounter: number
|
|
25
23
|
let rtcOfferCounter: number
|
|
26
24
|
let rtcAnswerCounter: number
|
|
27
25
|
let iceCandidateCounter: number
|
|
28
26
|
|
|
29
|
-
const
|
|
30
|
-
kademliaId: generateId('
|
|
31
|
-
type: NodeType.NODEJS
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const peerDescriptor2: PeerDescriptor = {
|
|
35
|
-
kademliaId: generateId('peer2'),
|
|
27
|
+
const targetDescriptor: PeerDescriptor = {
|
|
28
|
+
kademliaId: generateId('peer'),
|
|
36
29
|
type: NodeType.NODEJS
|
|
37
30
|
}
|
|
38
31
|
|
|
@@ -43,27 +36,27 @@ describe('WebRTC rpc messages', () => {
|
|
|
43
36
|
iceCandidateCounter = 0
|
|
44
37
|
|
|
45
38
|
rpcCommunicator1 = new RpcCommunicator()
|
|
46
|
-
const serverFunctions:
|
|
39
|
+
const serverFunctions: IWebRtcConnectorRpc = {
|
|
47
40
|
|
|
48
|
-
requestConnection: async (
|
|
41
|
+
requestConnection: async (): Promise<Empty> => {
|
|
49
42
|
requestConnectionCounter += 1
|
|
50
43
|
const res: Empty = {}
|
|
51
44
|
return res
|
|
52
45
|
},
|
|
53
46
|
|
|
54
|
-
rtcOffer: async (
|
|
47
|
+
rtcOffer: async (): Promise<Empty> => {
|
|
55
48
|
rtcOfferCounter += 1
|
|
56
49
|
const res: Empty = {}
|
|
57
50
|
return res
|
|
58
51
|
},
|
|
59
52
|
|
|
60
|
-
rtcAnswer: async (
|
|
53
|
+
rtcAnswer: async (): Promise<Empty> => {
|
|
61
54
|
rtcAnswerCounter += 1
|
|
62
55
|
const res: Empty = {}
|
|
63
56
|
return res
|
|
64
57
|
},
|
|
65
58
|
|
|
66
|
-
iceCandidate: async (
|
|
59
|
+
iceCandidate: async (): Promise<Empty> => {
|
|
67
60
|
iceCandidateCounter += 1
|
|
68
61
|
const res: Empty = {}
|
|
69
62
|
return res
|
|
@@ -76,15 +69,15 @@ describe('WebRTC rpc messages', () => {
|
|
|
76
69
|
rpcCommunicator2.registerRpcNotification(IceCandidate, 'iceCandidate', serverFunctions.iceCandidate)
|
|
77
70
|
rpcCommunicator2.registerRpcNotification(WebRtcConnectionRequest, 'requestConnection', serverFunctions.requestConnection)
|
|
78
71
|
|
|
79
|
-
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage
|
|
72
|
+
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
|
|
80
73
|
rpcCommunicator2.handleIncomingMessage(message)
|
|
81
74
|
})
|
|
82
75
|
|
|
83
|
-
rpcCommunicator2.on('outgoingMessage', (message: RpcMessage
|
|
76
|
+
rpcCommunicator2.on('outgoingMessage', (message: RpcMessage) => {
|
|
84
77
|
rpcCommunicator1.handleIncomingMessage(message)
|
|
85
78
|
})
|
|
86
79
|
|
|
87
|
-
client = toProtoRpcClient(new
|
|
80
|
+
client = toProtoRpcClient(new WebRtcConnectorRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
88
81
|
})
|
|
89
82
|
|
|
90
83
|
afterEach(async () => {
|
|
@@ -94,11 +87,9 @@ describe('WebRTC rpc messages', () => {
|
|
|
94
87
|
|
|
95
88
|
it('send connectionRequest', async () => {
|
|
96
89
|
client.requestConnection({
|
|
97
|
-
requester: peerDescriptor1,
|
|
98
|
-
target: peerDescriptor2,
|
|
99
90
|
connectionId: 'connectionRequest'
|
|
100
91
|
},
|
|
101
|
-
{ targetDescriptor
|
|
92
|
+
{ targetDescriptor, notification: true }
|
|
102
93
|
)
|
|
103
94
|
|
|
104
95
|
await waitForCondition(() => requestConnectionCounter === 1)
|
|
@@ -106,12 +97,10 @@ describe('WebRTC rpc messages', () => {
|
|
|
106
97
|
|
|
107
98
|
it('send rtcOffer', async () => {
|
|
108
99
|
client.rtcOffer({
|
|
109
|
-
requester: peerDescriptor1,
|
|
110
|
-
target: peerDescriptor2,
|
|
111
100
|
connectionId: 'rtcOffer',
|
|
112
101
|
description: 'aaaaaa'
|
|
113
102
|
},
|
|
114
|
-
{ targetDescriptor
|
|
103
|
+
{ targetDescriptor, notification: true }
|
|
115
104
|
)
|
|
116
105
|
|
|
117
106
|
await waitForCondition(() => rtcOfferCounter === 1)
|
|
@@ -119,12 +108,10 @@ describe('WebRTC rpc messages', () => {
|
|
|
119
108
|
|
|
120
109
|
it('send rtcAnswer', async () => {
|
|
121
110
|
client.rtcAnswer({
|
|
122
|
-
requester: peerDescriptor1,
|
|
123
|
-
target: peerDescriptor2,
|
|
124
111
|
connectionId: 'rtcOffer',
|
|
125
112
|
description: 'aaaaaa'
|
|
126
113
|
},
|
|
127
|
-
{ targetDescriptor
|
|
114
|
+
{ targetDescriptor, notification: true }
|
|
128
115
|
)
|
|
129
116
|
|
|
130
117
|
await waitForCondition(() => rtcAnswerCounter === 1)
|
|
@@ -132,13 +119,11 @@ describe('WebRTC rpc messages', () => {
|
|
|
132
119
|
|
|
133
120
|
it('send iceCandidate', async () => {
|
|
134
121
|
client.iceCandidate({
|
|
135
|
-
requester: peerDescriptor1,
|
|
136
|
-
target: peerDescriptor2,
|
|
137
122
|
connectionId: 'rtcOffer',
|
|
138
123
|
candidate: 'aaaaaa',
|
|
139
124
|
mid: 'asdasdasdasdasd'
|
|
140
125
|
},
|
|
141
|
-
{ targetDescriptor
|
|
126
|
+
{ targetDescriptor, notification: true }
|
|
142
127
|
)
|
|
143
128
|
|
|
144
129
|
await waitForCondition(() => iceCandidateCounter === 1)
|
|
@@ -9,11 +9,13 @@ const logger = new Logger(module)
|
|
|
9
9
|
|
|
10
10
|
describe('WebSocket', () => {
|
|
11
11
|
|
|
12
|
-
const webSocketServer = new WebSocketServer(
|
|
12
|
+
const webSocketServer = new WebSocketServer({
|
|
13
|
+
portRange: { min: 9999, max: 9999 }
|
|
14
|
+
})
|
|
13
15
|
const clientWebSocket = new ClientWebSocket()
|
|
14
16
|
|
|
15
17
|
beforeAll(async () => {
|
|
16
|
-
await webSocketServer.start(
|
|
18
|
+
await webSocketServer.start()
|
|
17
19
|
})
|
|
18
20
|
|
|
19
21
|
it('Happy path', (done) => {
|
|
@@ -1,15 +1,26 @@
|
|
|
1
1
|
/* eslint-disable promise/no-nesting */
|
|
2
2
|
|
|
3
|
+
import { MetricsContext, waitForCondition } from '@streamr/utils'
|
|
3
4
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
5
|
+
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
6
|
+
import { ConnectionType } from '../../src/connection/IConnection'
|
|
4
7
|
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
5
|
-
import {
|
|
8
|
+
import { SimulatorTransport } from '../../src/exports'
|
|
6
9
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
7
|
-
import { ConnectionType } from '../../src/connection/IConnection'
|
|
8
|
-
import { ITransport } from '../../src/transport/ITransport'
|
|
9
10
|
import * as Err from '../../src/helpers/errors'
|
|
10
|
-
import {
|
|
11
|
+
import { Message, MessageType, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
12
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
12
13
|
|
|
14
|
+
const createConfig = (ownPeerDescriptor: PeerDescriptor, opts: Omit<DefaultConnectorFacadeConfig, 'createOwnPeerDescriptor'>) => {
|
|
15
|
+
return {
|
|
16
|
+
createConnectorFacade: () => new DefaultConnectorFacade({
|
|
17
|
+
createOwnPeerDescriptor: () => ownPeerDescriptor,
|
|
18
|
+
...opts
|
|
19
|
+
}),
|
|
20
|
+
metricsContext: new MetricsContext()
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
13
24
|
describe('WebSocket Connection Management', () => {
|
|
14
25
|
|
|
15
26
|
const serviceId = 'test'
|
|
@@ -33,28 +44,30 @@ describe('WebSocket Connection Management', () => {
|
|
|
33
44
|
type: NodeType.NODEJS,
|
|
34
45
|
}
|
|
35
46
|
|
|
36
|
-
let connectorTransport1:
|
|
37
|
-
let connectorTransport2:
|
|
47
|
+
let connectorTransport1: SimulatorTransport
|
|
48
|
+
let connectorTransport2: SimulatorTransport
|
|
38
49
|
|
|
39
50
|
beforeEach(async () => {
|
|
40
51
|
|
|
41
|
-
connectorTransport1 = new
|
|
42
|
-
|
|
52
|
+
connectorTransport1 = new SimulatorTransport(wsServerConnectorPeerDescriptor, simulator)
|
|
53
|
+
await connectorTransport1.start()
|
|
54
|
+
connectorTransport2 = new SimulatorTransport(noWsServerConnectorPeerDescriptor, simulator)
|
|
55
|
+
await connectorTransport2.start()
|
|
43
56
|
|
|
44
|
-
const config1 = {
|
|
45
|
-
|
|
57
|
+
const config1 = createConfig(wsServerConnectorPeerDescriptor, {
|
|
58
|
+
transport: connectorTransport1,
|
|
46
59
|
websocketHost: '127.0.0.1',
|
|
47
|
-
websocketPortRange: { min: 12223, max: 12223 }
|
|
48
|
-
}
|
|
49
|
-
const config2 = {
|
|
50
|
-
|
|
51
|
-
}
|
|
60
|
+
websocketPortRange: { min: 12223, max: 12223 }
|
|
61
|
+
})
|
|
62
|
+
const config2 = createConfig(noWsServerConnectorPeerDescriptor, {
|
|
63
|
+
transport: connectorTransport2
|
|
64
|
+
})
|
|
52
65
|
|
|
53
66
|
wsServerManager = new ConnectionManager(config1)
|
|
54
67
|
noWsServerManager = new ConnectionManager(config2)
|
|
55
68
|
|
|
56
|
-
await wsServerManager.start(
|
|
57
|
-
await noWsServerManager.start(
|
|
69
|
+
await wsServerManager.start()
|
|
70
|
+
await noWsServerManager.start()
|
|
58
71
|
})
|
|
59
72
|
|
|
60
73
|
afterEach(async () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
|
-
import {
|
|
2
|
+
import { WebSocketConnectorRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
3
3
|
import { generateId } from '../utils/utils'
|
|
4
4
|
import {
|
|
5
5
|
NodeType,
|
|
@@ -7,15 +7,14 @@ import {
|
|
|
7
7
|
WebSocketConnectionRequest,
|
|
8
8
|
WebSocketConnectionResponse
|
|
9
9
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
10
|
-
import {
|
|
11
|
-
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
10
|
+
import { mockWebSocketConnectorRpc } from '../utils/utils'
|
|
12
11
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
13
12
|
|
|
14
13
|
describe('WebSocketConnectorRpc', () => {
|
|
15
14
|
let rpcCommunicator1: RpcCommunicator
|
|
16
15
|
let rpcCommunicator2: RpcCommunicator
|
|
17
|
-
let client1: ProtoRpcClient<
|
|
18
|
-
let client2: ProtoRpcClient<
|
|
16
|
+
let client1: ProtoRpcClient<WebSocketConnectorRpcClient>
|
|
17
|
+
let client2: ProtoRpcClient<WebSocketConnectorRpcClient>
|
|
19
18
|
|
|
20
19
|
const peerDescriptor1: PeerDescriptor = {
|
|
21
20
|
kademliaId: generateId('peer1'),
|
|
@@ -33,7 +32,7 @@ describe('WebSocketConnectorRpc', () => {
|
|
|
33
32
|
WebSocketConnectionRequest,
|
|
34
33
|
WebSocketConnectionResponse,
|
|
35
34
|
'requestConnection',
|
|
36
|
-
|
|
35
|
+
mockWebSocketConnectorRpc.requestConnection
|
|
37
36
|
)
|
|
38
37
|
|
|
39
38
|
rpcCommunicator2 = new RpcCommunicator()
|
|
@@ -41,19 +40,19 @@ describe('WebSocketConnectorRpc', () => {
|
|
|
41
40
|
WebSocketConnectionRequest,
|
|
42
41
|
WebSocketConnectionResponse,
|
|
43
42
|
'requestConnection',
|
|
44
|
-
|
|
43
|
+
mockWebSocketConnectorRpc.requestConnection
|
|
45
44
|
)
|
|
46
45
|
|
|
47
|
-
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage
|
|
46
|
+
rpcCommunicator1.on('outgoingMessage', (message: RpcMessage) => {
|
|
48
47
|
rpcCommunicator2.handleIncomingMessage(message)
|
|
49
48
|
})
|
|
50
49
|
|
|
51
|
-
rpcCommunicator2.on('outgoingMessage', (message: RpcMessage
|
|
50
|
+
rpcCommunicator2.on('outgoingMessage', (message: RpcMessage) => {
|
|
52
51
|
rpcCommunicator1.handleIncomingMessage(message)
|
|
53
52
|
})
|
|
54
53
|
|
|
55
|
-
client1 = toProtoRpcClient(new
|
|
56
|
-
client2 = toProtoRpcClient(new
|
|
54
|
+
client1 = toProtoRpcClient(new WebSocketConnectorRpcClient(rpcCommunicator1.getRpcClientTransport()))
|
|
55
|
+
client2 = toProtoRpcClient(new WebSocketConnectorRpcClient(rpcCommunicator2.getRpcClientTransport()))
|
|
57
56
|
})
|
|
58
57
|
|
|
59
58
|
afterEach(async () => {
|
|
@@ -63,8 +62,6 @@ describe('WebSocketConnectorRpc', () => {
|
|
|
63
62
|
|
|
64
63
|
it('Happy path', async () => {
|
|
65
64
|
const response1 = client1.requestConnection({
|
|
66
|
-
requester: peerDescriptor1,
|
|
67
|
-
target: peerDescriptor2,
|
|
68
65
|
ip: '127.0.0.1',
|
|
69
66
|
port: 9099
|
|
70
67
|
},
|
|
@@ -74,8 +71,6 @@ describe('WebSocketConnectorRpc', () => {
|
|
|
74
71
|
expect(res1.accepted).toEqual(true)
|
|
75
72
|
|
|
76
73
|
const response2 = client2.requestConnection({
|
|
77
|
-
requester: peerDescriptor2,
|
|
78
|
-
target: peerDescriptor1,
|
|
79
74
|
ip: '127.0.0.1',
|
|
80
75
|
port: 9111
|
|
81
76
|
},
|
|
@@ -3,25 +3,24 @@ import { DuplicateDetector } from '../../src/dht/routing/DuplicateDetector'
|
|
|
3
3
|
describe('Duplicate Detector', () => {
|
|
4
4
|
let detector: DuplicateDetector
|
|
5
5
|
const maxLimit = 10
|
|
6
|
-
const senderId = 'sender'
|
|
7
6
|
beforeEach(async () => {
|
|
8
7
|
detector = new DuplicateDetector(maxLimit, 100)
|
|
9
8
|
})
|
|
10
9
|
|
|
11
10
|
it('detects duplicates', async () => {
|
|
12
|
-
detector.add('test'
|
|
11
|
+
detector.add('test')
|
|
13
12
|
expect(detector.size()).toEqual(1)
|
|
14
13
|
expect(detector.isMostLikelyDuplicate('test')).toEqual(true)
|
|
15
14
|
})
|
|
16
15
|
|
|
17
16
|
it('resets on resetLimit', () => {
|
|
18
17
|
for (let i = 0; i < maxLimit; i++) {
|
|
19
|
-
detector.add(`test${i}
|
|
18
|
+
detector.add(`test${i}`)
|
|
20
19
|
}
|
|
21
20
|
for (let i = 0; i < maxLimit; i++) {
|
|
22
21
|
expect(detector.isMostLikelyDuplicate(`test${i}`)).toEqual(true)
|
|
23
22
|
}
|
|
24
|
-
detector.add('test10'
|
|
23
|
+
detector.add('test10')
|
|
25
24
|
expect(detector.size()).toEqual(10)
|
|
26
25
|
expect(detector.isMostLikelyDuplicate('test0')).toEqual(false)
|
|
27
26
|
expect(detector.isMostLikelyDuplicate('test10')).toEqual(true)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
2
2
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import {
|
|
4
|
-
|
|
4
|
+
areEqualPeerDescriptors,
|
|
5
5
|
keyFromPeerDescriptor,
|
|
6
6
|
peerIdFromPeerDescriptor
|
|
7
7
|
} from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
@@ -13,13 +13,11 @@ describe('LocalDataStore', () => {
|
|
|
13
13
|
let localDataStore: LocalDataStore
|
|
14
14
|
const storer1: PeerDescriptor = {
|
|
15
15
|
kademliaId: new Uint8Array([1, 2, 3]),
|
|
16
|
-
type: NodeType.NODEJS
|
|
17
|
-
nodeName: 'storer1'
|
|
16
|
+
type: NodeType.NODEJS
|
|
18
17
|
}
|
|
19
18
|
const storer2: PeerDescriptor = {
|
|
20
19
|
kademliaId: new Uint8Array([3, 2, 1]),
|
|
21
|
-
type: NodeType.NODEJS
|
|
22
|
-
nodeName: 'storer2'
|
|
20
|
+
type: NodeType.NODEJS
|
|
23
21
|
}
|
|
24
22
|
const data1 = Any.pack(storer1, PeerDescriptor)
|
|
25
23
|
const data2 = Any.pack(storer2, PeerDescriptor)
|
|
@@ -39,7 +37,7 @@ describe('LocalDataStore', () => {
|
|
|
39
37
|
const fetchedData = localDataStore.getEntry(dataKey)
|
|
40
38
|
fetchedData.forEach((entry) => {
|
|
41
39
|
const fetchedDescriptor = Any.unpack(entry.data!, PeerDescriptor)
|
|
42
|
-
expect(
|
|
40
|
+
expect(areEqualPeerDescriptors(fetchedDescriptor, storer1)).toBeTrue()
|
|
43
41
|
})
|
|
44
42
|
})
|
|
45
43
|
|
|
@@ -52,7 +50,7 @@ describe('LocalDataStore', () => {
|
|
|
52
50
|
const fetchedData = localDataStore.getEntry(dataKey)
|
|
53
51
|
fetchedData.forEach((entry) => {
|
|
54
52
|
const fetchedDescriptor = Any.unpack(entry.data!, PeerDescriptor)
|
|
55
|
-
expect(
|
|
53
|
+
expect(areEqualPeerDescriptors(fetchedDescriptor, storer1)).toBeTrue()
|
|
56
54
|
})
|
|
57
55
|
})
|
|
58
56
|
|
|
@@ -66,7 +64,7 @@ describe('LocalDataStore', () => {
|
|
|
66
64
|
const fetchedData = localDataStore.getEntry(dataKey)
|
|
67
65
|
fetchedData.forEach((entry) => {
|
|
68
66
|
const fetchedDescriptor = Any.unpack(entry.data!, PeerDescriptor)
|
|
69
|
-
expect(
|
|
67
|
+
expect(areEqualPeerDescriptors(fetchedDescriptor, storer2)).toBeTrue()
|
|
70
68
|
})
|
|
71
69
|
})
|
|
72
70
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RandomContactList } from '../../src/dht/contact/RandomContactList'
|
|
2
|
-
import { PeerID } from '../../src/
|
|
2
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
3
|
|
|
4
4
|
const createItem = (kademliaId: Uint8Array): { getPeerId: () => PeerID } => {
|
|
5
5
|
return { getPeerId: () => PeerID.fromValue(kademliaId) }
|