@streamr/dht 100.0.0-testnet-three.6 → 100.1.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/README.md +1 -1
- package/dist/package.json +12 -8
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/{ConnectionLockHandler.d.ts → ConnectionLockStates.d.ts} +3 -3
- package/dist/src/connection/{ConnectionLockHandler.js → ConnectionLockStates.js} +17 -9
- package/dist/src/connection/ConnectionLockStates.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +9 -7
- package/dist/src/connection/ConnectionManager.js +16 -18
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.js +1 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.js +6 -13
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -2
- package/dist/src/connection/ManagedConnection.js +8 -8
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +1 -1
- package/dist/src/connection/connectivityChecker.js +8 -8
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.d.ts +2 -2
- package/dist/src/connection/connectivityRequestHandler.js +10 -11
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +1 -0
- package/dist/src/connection/webrtc/WebrtcConnector.js +13 -8
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -0
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +4 -6
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +28 -0
- package/dist/src/connection/websocket/{ClientWebsocket.js → AbstractWebsocketClientConnection.js} +42 -68
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js.map +1 -0
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.d.ts +7 -0
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js +39 -0
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketConnector.js +26 -23
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.js +25 -35
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{ServerWebsocket.d.ts → WebsocketServerConnection.d.ts} +4 -5
- package/dist/src/connection/websocket/{ServerWebsocket.js → WebsocketServerConnection.js} +18 -51
- package/dist/src/connection/websocket/WebsocketServerConnection.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +15 -8
- package/dist/src/dht/DhtNode.js +62 -31
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +5 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +10 -0
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +3 -0
- package/dist/src/dht/DhtNodeRpcRemote.js +16 -1
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +2 -2
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +15 -3
- package/dist/src/dht/PeerManager.js +54 -40
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +31 -0
- package/dist/src/dht/contact/RingContactList.js +133 -0
- package/dist/src/dht/contact/RingContactList.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +2 -1
- package/dist/src/dht/contact/SortedContactList.js +19 -17
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/contact/ringIdentifiers.d.ts +16 -0
- package/dist/src/dht/contact/ringIdentifiers.js +54 -0
- package/dist/src/dht/contact/ringIdentifiers.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.js +3 -1
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +6 -2
- package/dist/src/dht/discovery/PeerDiscovery.js +41 -4
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +29 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js +125 -0
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -0
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +0 -1
- package/dist/src/dht/routing/Router.js +0 -1
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +0 -1
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.js +2 -2
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.js +2 -2
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.js +2 -2
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/exports.d.ts +3 -2
- package/dist/src/exports.js +3 -3
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/createPeerDescriptor.d.ts +1 -1
- package/dist/src/helpers/createPeerDescriptor.js +2 -1
- package/dist/src/helpers/createPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/version.d.ts +6 -0
- package/dist/src/helpers/version.js +38 -0
- package/dist/src/helpers/version.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +16 -6
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +11 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +98 -87
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +45 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +10 -4
- package/dist/src/transport/RoutingRpcCommunicator.js +0 -2
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/karma.config.js +4 -1
- package/package.json +12 -8
- package/protos/DhtRpc.proto +21 -21
- package/src/connection/ConnectionLockRpcLocal.ts +1 -1
- package/src/connection/ConnectionLockRpcRemote.ts +2 -2
- package/src/connection/{ConnectionLockHandler.ts → ConnectionLockStates.ts} +14 -6
- package/src/connection/ConnectionManager.ts +21 -22
- package/src/connection/ConnectorFacade.ts +1 -2
- package/src/connection/Handshaker.ts +7 -15
- package/src/connection/ManagedConnection.ts +8 -8
- package/src/connection/connectivityChecker.ts +9 -10
- package/src/connection/connectivityRequestHandler.ts +16 -16
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +18 -0
- package/src/connection/webrtc/NodeWebrtcConnection.ts +1 -1
- package/src/connection/webrtc/WebrtcConnector.ts +14 -8
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +5 -5
- package/src/connection/websocket/{ClientWebsocket.ts → AbstractWebsocketClientConnection.ts} +57 -70
- package/src/connection/websocket/BrowserWebsocketClientConnection.ts +44 -0
- package/src/connection/websocket/NodeWebsocketClientConnection.ts +39 -0
- package/src/connection/websocket/WebsocketConnector.ts +27 -28
- package/src/connection/websocket/WebsocketServer.ts +27 -42
- package/src/connection/websocket/{ServerWebsocket.ts → WebsocketServerConnection.ts} +15 -56
- package/src/dht/DhtNode.ts +85 -50
- package/src/dht/DhtNodeRpcLocal.ts +16 -0
- package/src/dht/DhtNodeRpcRemote.ts +19 -1
- package/src/dht/ExternalApiRpcLocal.ts +5 -5
- package/src/dht/ExternalApiRpcRemote.ts +4 -4
- package/src/dht/PeerManager.ts +70 -44
- package/src/dht/contact/RingContactList.ts +151 -0
- package/src/dht/contact/SortedContactList.ts +22 -18
- package/src/dht/contact/ringIdentifiers.ts +62 -0
- package/src/dht/discovery/DiscoverySession.ts +3 -1
- package/src/dht/discovery/PeerDiscovery.ts +45 -6
- package/src/dht/discovery/RingDiscoverySession.ts +162 -0
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +1 -1
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +1 -1
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +1 -3
- package/src/dht/routing/Router.ts +0 -2
- package/src/dht/routing/RouterRpcLocal.ts +0 -1
- package/src/dht/routing/RouterRpcRemote.ts +2 -2
- package/src/dht/routing/RoutingSession.ts +2 -2
- package/src/dht/store/LocalDataStore.ts +1 -1
- package/src/dht/store/StoreManager.ts +2 -2
- package/src/exports.ts +3 -2
- package/src/helpers/createPeerDescriptor.ts +2 -1
- package/src/helpers/version.ts +32 -0
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +22 -9
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +10 -4
- package/src/proto/packages/dht/protos/DhtRpc.ts +122 -100
- package/src/transport/RoutingRpcCommunicator.ts +1 -2
- package/test/benchmark/Find.test.ts +3 -4
- package/test/benchmark/KademliaCorrectness.test.ts +14 -8
- package/test/benchmark/RingCorrectness.test.ts +157 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +2 -2
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +72 -0
- package/test/data/generateGroundTruthData.ts +2 -2
- package/test/end-to-end/memory-leak.test.ts +1 -2
- package/test/integration/ConnectionManager.test.ts +28 -10
- package/test/integration/ConnectivityChecking.test.ts +3 -15
- package/test/integration/DhtNodeExternalAPI.test.ts +6 -6
- package/test/integration/Find.test.ts +6 -6
- package/test/integration/Layer1-scale.test.ts +0 -1
- package/test/integration/ReplicateData.test.ts +4 -4
- package/test/integration/RouteMessage.test.ts +1 -6
- package/test/integration/RouterRpcRemote.test.ts +1 -3
- package/test/integration/SimultaneousConnections.test.ts +9 -10
- package/test/integration/Store.test.ts +4 -4
- package/test/integration/StoreAndDelete.test.ts +5 -5
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +5 -5
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +3 -3
- package/test/integration/WebrtcConnectionManagement.test.ts +3 -9
- package/test/integration/Websocket.test.ts +2 -2
- package/test/integration/WebsocketConnectionManagement.test.ts +1 -6
- package/test/integration/rpc-connections-over-webrpc.test.ts +1 -2
- package/test/unit/PeerManager.test.ts +44 -10
- package/test/unit/RecursiveOperationManager.test.ts +14 -8
- package/test/unit/RecursiveOperationSession.test.ts +1 -1
- package/test/unit/Router.test.ts +0 -3
- package/test/unit/RoutingSession.test.ts +1 -2
- package/test/unit/connectivityRequestHandler.test.ts +5 -9
- package/test/unit/createPeerDescriptor.test.ts +12 -6
- package/test/unit/version.test.ts +18 -0
- package/test/utils/utils.ts +60 -47
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +4 -2
- package/tsconfig.node.json +4 -2
- package/dist/src/connection/ConnectionLockHandler.js.map +0 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +0 -17
- package/dist/src/connection/websocket/ClientWebsocket.js.map +0 -1
- package/dist/src/connection/websocket/ServerWebsocket.js.map +0 -1
- package/dist/src/helpers/MapWithTtl.d.ts +0 -14
- package/dist/src/helpers/MapWithTtl.js +0 -60
- package/dist/src/helpers/MapWithTtl.js.map +0 -1
- package/dist/src/helpers/versionCompatibility.d.ts +0 -2
- package/dist/src/helpers/versionCompatibility.js +0 -18
- package/dist/src/helpers/versionCompatibility.js.map +0 -1
- package/src/helpers/MapWithTtl.ts +0 -71
- package/src/helpers/versionCompatibility.ts +0 -13
- package/test/unit/versionCompatibility.test.ts +0 -16
|
@@ -3,7 +3,7 @@ import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
|
3
3
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
4
4
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
|
-
import { Message,
|
|
6
|
+
import { Message, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
7
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
8
8
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
9
9
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
@@ -12,7 +12,6 @@ import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
|
12
12
|
|
|
13
13
|
const BASE_MESSAGE: Message = {
|
|
14
14
|
serviceId: 'serviceId',
|
|
15
|
-
messageType: MessageType.RPC,
|
|
16
15
|
messageId: '1',
|
|
17
16
|
body: {
|
|
18
17
|
oneofKind: 'rpcMessage',
|
|
@@ -63,13 +62,13 @@ describe('SimultaneousConnections', () => {
|
|
|
63
62
|
|
|
64
63
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
65
64
|
simTransport1.on('message', async (message: Message) => {
|
|
66
|
-
expect(message.
|
|
65
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
67
66
|
resolve()
|
|
68
67
|
})
|
|
69
68
|
})
|
|
70
69
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
71
70
|
simTransport2.on('message', async (message: Message) => {
|
|
72
|
-
expect(message.
|
|
71
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
73
72
|
resolve()
|
|
74
73
|
})
|
|
75
74
|
})
|
|
@@ -142,13 +141,13 @@ describe('SimultaneousConnections', () => {
|
|
|
142
141
|
|
|
143
142
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
144
143
|
connectionManager1.on('message', async (message: Message) => {
|
|
145
|
-
expect(message.
|
|
144
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
146
145
|
resolve()
|
|
147
146
|
})
|
|
148
147
|
})
|
|
149
148
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
150
149
|
connectionManager2.on('message', async (message: Message) => {
|
|
151
|
-
expect(message.
|
|
150
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
152
151
|
resolve()
|
|
153
152
|
})
|
|
154
153
|
})
|
|
@@ -222,13 +221,13 @@ describe('SimultaneousConnections', () => {
|
|
|
222
221
|
|
|
223
222
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
224
223
|
connectionManager1.on('message', async (message: Message) => {
|
|
225
|
-
expect(message.
|
|
224
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
226
225
|
resolve()
|
|
227
226
|
})
|
|
228
227
|
})
|
|
229
228
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
230
229
|
connectionManager2.on('message', async (message: Message) => {
|
|
231
|
-
expect(message.
|
|
230
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
232
231
|
resolve()
|
|
233
232
|
})
|
|
234
233
|
})
|
|
@@ -290,13 +289,13 @@ describe('SimultaneousConnections', () => {
|
|
|
290
289
|
|
|
291
290
|
const promise1 = new Promise<void>((resolve, _reject) => {
|
|
292
291
|
connectionManager1.on('message', async (message: Message) => {
|
|
293
|
-
expect(message.
|
|
292
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
294
293
|
resolve()
|
|
295
294
|
})
|
|
296
295
|
})
|
|
297
296
|
const promise2 = new Promise<void>((resolve, _reject) => {
|
|
298
297
|
connectionManager2.on('message', async (message: Message) => {
|
|
299
|
-
expect(message.
|
|
298
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
300
299
|
resolve()
|
|
301
300
|
})
|
|
302
301
|
})
|
|
@@ -3,7 +3,7 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
3
3
|
import { getDhtAddressFromRaw, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
4
4
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
|
-
import { createMockConnectionDhtNode, createMockPeerDescriptor,
|
|
6
|
+
import { createMockConnectionDhtNode, createMockPeerDescriptor, waitForStableTopology } from '../utils/utils'
|
|
7
7
|
|
|
8
8
|
const NUM_NODES = 100
|
|
9
9
|
const MAX_CONNECTIONS = 20
|
|
@@ -33,7 +33,7 @@ describe('Storing data in DHT', () => {
|
|
|
33
33
|
nodes.push(node)
|
|
34
34
|
}
|
|
35
35
|
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
36
|
-
await
|
|
36
|
+
await waitForStableTopology(nodes, MAX_CONNECTIONS)
|
|
37
37
|
}, 90000)
|
|
38
38
|
|
|
39
39
|
afterEach(async () => {
|
|
@@ -59,7 +59,7 @@ describe('Storing data in DHT', () => {
|
|
|
59
59
|
)
|
|
60
60
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
61
61
|
const fetchingNode = getRandomNode()
|
|
62
|
-
const results = await fetchingNode.
|
|
62
|
+
const results = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
63
63
|
results.forEach((result) => {
|
|
64
64
|
expectEqualData(result, entry)
|
|
65
65
|
})
|
|
@@ -76,7 +76,7 @@ describe('Storing data in DHT', () => {
|
|
|
76
76
|
)
|
|
77
77
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
78
78
|
const fetchingNode = getRandomNode()
|
|
79
|
-
const results = await fetchingNode.
|
|
79
|
+
const results = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
80
80
|
results.forEach((result) => {
|
|
81
81
|
expectEqualData(result, entry)
|
|
82
82
|
expect(getDhtAddressFromRaw(result.creator)).toEqual(getNodeIdFromPeerDescriptor(requestor))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { createMockConnectionDhtNode,
|
|
3
|
+
import { createMockConnectionDhtNode, waitForStableTopology } from '../utils/utils'
|
|
4
4
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
5
5
|
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
6
6
|
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
@@ -30,7 +30,7 @@ describe('Storing data in DHT', () => {
|
|
|
30
30
|
nodes.push(node)
|
|
31
31
|
}
|
|
32
32
|
await Promise.all(nodes.map((node) => node.joinDht([entryPoint.getLocalPeerDescriptor()])))
|
|
33
|
-
await
|
|
33
|
+
await waitForStableTopology(nodes, MAX_CONNECTIONS)
|
|
34
34
|
}, 90000)
|
|
35
35
|
|
|
36
36
|
afterEach(async () => {
|
|
@@ -46,7 +46,7 @@ describe('Storing data in DHT', () => {
|
|
|
46
46
|
// Wait for the delete operation to propagate
|
|
47
47
|
await wait(500)
|
|
48
48
|
const fetchingNode = getRandomNode()
|
|
49
|
-
const results = await fetchingNode.
|
|
49
|
+
const results = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
50
50
|
results.forEach((result) => {
|
|
51
51
|
expect(result.deleted).toBeTrue()
|
|
52
52
|
expectEqualData(result, entry)
|
|
@@ -62,14 +62,14 @@ describe('Storing data in DHT', () => {
|
|
|
62
62
|
// Wait for the delete operation to propagate
|
|
63
63
|
await wait(500)
|
|
64
64
|
const fetchingNode = getRandomNode()
|
|
65
|
-
const results1 = await fetchingNode.
|
|
65
|
+
const results1 = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
66
66
|
results1.forEach((result) => {
|
|
67
67
|
expect(result.deleted).toBeTrue()
|
|
68
68
|
expectEqualData(result, entry)
|
|
69
69
|
})
|
|
70
70
|
const successfulStorers2 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
71
71
|
expect(successfulStorers2.length).toBeGreaterThan(4)
|
|
72
|
-
const results2 = await fetchingNode.
|
|
72
|
+
const results2 = await fetchingNode.fetchDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
73
73
|
results2.forEach((result) => {
|
|
74
74
|
expect(result.deleted).toBeFalse()
|
|
75
75
|
expectEqualData(result, entry)
|
|
@@ -41,15 +41,15 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
41
41
|
const storedData1 = createMockDataEntry()
|
|
42
42
|
const storedData2 = createMockDataEntry()
|
|
43
43
|
// Here we effectively test that fetching "null" data doesn't take too long. A test timeout here indicates an issue.
|
|
44
|
-
await node1.
|
|
45
|
-
await node2.
|
|
44
|
+
await node1.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
45
|
+
await node2.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
46
46
|
|
|
47
47
|
await node1.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
48
48
|
await node2.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
49
49
|
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData2.key), storedData2.data!)
|
|
50
|
-
const foundData1 = await node1.
|
|
51
|
-
const foundData2 = await node2.
|
|
52
|
-
const foundData3 = await entryPoint.
|
|
50
|
+
const foundData1 = await node1.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
51
|
+
const foundData2 = await node2.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
52
|
+
const foundData3 = await entryPoint.fetchDataFromDht(getDhtAddressFromRaw(storedData2.key))
|
|
53
53
|
expectEqualData(foundData1[0], storedData1)
|
|
54
54
|
expectEqualData(foundData1[1], storedData1)
|
|
55
55
|
expectEqualData(foundData2[0], storedData1)
|
|
@@ -34,8 +34,8 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
34
34
|
const storedData2 = createMockDataEntry()
|
|
35
35
|
await otherNode.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
36
36
|
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData2.key), storedData2.data!)
|
|
37
|
-
const foundData1 = await otherNode.
|
|
38
|
-
const foundData2 = await entryPoint.
|
|
37
|
+
const foundData1 = await otherNode.fetchDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
38
|
+
const foundData2 = await entryPoint.fetchDataFromDht(getDhtAddressFromRaw(storedData2.key))
|
|
39
39
|
expectEqualData(foundData1[0], storedData1)
|
|
40
40
|
expectEqualData(foundData2[0], storedData2)
|
|
41
41
|
})
|
|
@@ -45,7 +45,7 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
45
45
|
await waitForCondition(() => entryPoint.getNeighborCount() === 0)
|
|
46
46
|
const storedData = createMockDataEntry()
|
|
47
47
|
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData.key), storedData.data!)
|
|
48
|
-
const foundData = await entryPoint.
|
|
48
|
+
const foundData = await entryPoint.fetchDataFromDht(getDhtAddressFromRaw(storedData.key))
|
|
49
49
|
expectEqualData(foundData[0], storedData)
|
|
50
50
|
}, 60000)
|
|
51
51
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
-
import { Message,
|
|
3
|
+
import { Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
5
5
|
import { ConnectionType } from '../../src/connection/IConnection'
|
|
6
6
|
import { ITransport } from '../../src/transport/ITransport'
|
|
@@ -63,7 +63,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
63
63
|
oneofKind: 'rpcMessage',
|
|
64
64
|
rpcMessage: RpcMessage.create()
|
|
65
65
|
},
|
|
66
|
-
messageType: MessageType.RPC,
|
|
67
66
|
messageId: 'mockerer'
|
|
68
67
|
}
|
|
69
68
|
|
|
@@ -87,7 +86,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
87
86
|
oneofKind: 'rpcMessage',
|
|
88
87
|
rpcMessage: RpcMessage.create()
|
|
89
88
|
},
|
|
90
|
-
messageType: MessageType.RPC,
|
|
91
89
|
messageId: 'mockerer'
|
|
92
90
|
}
|
|
93
91
|
manager1.on('message', (message: Message) => {
|
|
@@ -108,7 +106,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
108
106
|
oneofKind: 'rpcMessage',
|
|
109
107
|
rpcMessage: RpcMessage.create()
|
|
110
108
|
},
|
|
111
|
-
messageType: MessageType.RPC,
|
|
112
109
|
messageId: 'mockerer'
|
|
113
110
|
}
|
|
114
111
|
dummyMessage.targetDescriptor = peerDescriptor1
|
|
@@ -120,7 +117,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
120
117
|
it('Connects and disconnects webrtc connections', async () => {
|
|
121
118
|
const msg: Message = {
|
|
122
119
|
serviceId,
|
|
123
|
-
messageType: MessageType.RPC,
|
|
124
120
|
messageId: '1',
|
|
125
121
|
body: {
|
|
126
122
|
oneofKind: 'rpcMessage',
|
|
@@ -130,14 +126,14 @@ describe('WebRTC Connection Management', () => {
|
|
|
130
126
|
|
|
131
127
|
const dataPromise = new Promise<void>((resolve, _reject) => {
|
|
132
128
|
manager2.on('message', async (message: Message) => {
|
|
133
|
-
expect(message.
|
|
129
|
+
expect(message.body.oneofKind).toBe('rpcMessage')
|
|
134
130
|
resolve()
|
|
135
131
|
})
|
|
136
132
|
})
|
|
137
133
|
|
|
138
134
|
const connectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
139
135
|
manager1.on('connected', () => {
|
|
140
|
-
//expect(message.
|
|
136
|
+
//expect(message.body.oneofKind).toBe('rpcMessage')
|
|
141
137
|
resolve()
|
|
142
138
|
})
|
|
143
139
|
})
|
|
@@ -175,7 +171,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
175
171
|
it('Disconnects webrtcconnection while being connected', async () => {
|
|
176
172
|
const msg: Message = {
|
|
177
173
|
serviceId,
|
|
178
|
-
messageType: MessageType.RPC,
|
|
179
174
|
messageId: '1',
|
|
180
175
|
body: {
|
|
181
176
|
oneofKind: 'rpcMessage',
|
|
@@ -204,7 +199,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
204
199
|
it('failed connections are cleaned up', async () => {
|
|
205
200
|
const msg: Message = {
|
|
206
201
|
serviceId,
|
|
207
|
-
messageType: MessageType.RPC,
|
|
208
202
|
messageId: '1',
|
|
209
203
|
body: {
|
|
210
204
|
oneofKind: 'rpcMessage',
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { WebsocketServer } from '../../src/connection/websocket/WebsocketServer'
|
|
4
4
|
import { IConnection } from '../../src/connection/IConnection'
|
|
5
|
-
import {
|
|
5
|
+
import { WebsocketClientConnection } from '../../src/connection/websocket/NodeWebsocketClientConnection'
|
|
6
6
|
import { Logger } from '@streamr/utils'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
@@ -13,7 +13,7 @@ describe('Websocket', () => {
|
|
|
13
13
|
portRange: { min: 9977, max: 9977 },
|
|
14
14
|
enableTls: false
|
|
15
15
|
})
|
|
16
|
-
const clientWebsocket = new
|
|
16
|
+
const clientWebsocket = new WebsocketClientConnection()
|
|
17
17
|
|
|
18
18
|
beforeAll(async () => {
|
|
19
19
|
await websocketServer.start()
|
|
@@ -7,7 +7,7 @@ import { ConnectionType } from '../../src/connection/IConnection'
|
|
|
7
7
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
8
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
9
9
|
import * as Err from '../../src/helpers/errors'
|
|
10
|
-
import { Message,
|
|
10
|
+
import { Message, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
11
11
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
12
12
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
13
13
|
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
@@ -98,7 +98,6 @@ describe('Websocket Connection Management', () => {
|
|
|
98
98
|
oneofKind: 'rpcMessage',
|
|
99
99
|
rpcMessage: RpcMessage.create()
|
|
100
100
|
},
|
|
101
|
-
messageType: MessageType.RPC,
|
|
102
101
|
messageId: 'mockerer',
|
|
103
102
|
targetDescriptor: noWsServerConnectorPeerDescriptor
|
|
104
103
|
}
|
|
@@ -124,7 +123,6 @@ describe('Websocket Connection Management', () => {
|
|
|
124
123
|
oneofKind: 'rpcMessage',
|
|
125
124
|
rpcMessage: RpcMessage.create()
|
|
126
125
|
},
|
|
127
|
-
messageType: MessageType.RPC,
|
|
128
126
|
messageId: 'mockerer',
|
|
129
127
|
targetDescriptor: biggerNoWsServerConnectorPeerDescriptor
|
|
130
128
|
}
|
|
@@ -150,7 +148,6 @@ describe('Websocket Connection Management', () => {
|
|
|
150
148
|
oneofKind: 'rpcMessage',
|
|
151
149
|
rpcMessage: RpcMessage.create()
|
|
152
150
|
},
|
|
153
|
-
messageType: MessageType.RPC,
|
|
154
151
|
messageId: 'mockerer',
|
|
155
152
|
targetDescriptor: {
|
|
156
153
|
nodeId: new Uint8Array([1, 2, 4]),
|
|
@@ -172,7 +169,6 @@ describe('Websocket Connection Management', () => {
|
|
|
172
169
|
oneofKind: 'rpcMessage',
|
|
173
170
|
rpcMessage: RpcMessage.create()
|
|
174
171
|
},
|
|
175
|
-
messageType: MessageType.RPC,
|
|
176
172
|
messageId: 'mockerer',
|
|
177
173
|
targetDescriptor: wsServerConnectorPeerDescriptor
|
|
178
174
|
}
|
|
@@ -199,7 +195,6 @@ describe('Websocket Connection Management', () => {
|
|
|
199
195
|
oneofKind: 'rpcMessage',
|
|
200
196
|
rpcMessage: RpcMessage.create()
|
|
201
197
|
},
|
|
202
|
-
messageType: MessageType.RPC,
|
|
203
198
|
messageId: 'mockerer',
|
|
204
199
|
targetDescriptor: noWsServerConnectorPeerDescriptor
|
|
205
200
|
}
|
|
@@ -133,14 +133,13 @@ describe('RPC connections over WebRTC', () => {
|
|
|
133
133
|
|
|
134
134
|
const msg: Message = {
|
|
135
135
|
serviceId,
|
|
136
|
-
messageType: MessageType.RPC,
|
|
137
136
|
messageId: '1',
|
|
138
137
|
body: RpcMessage.toBinary(rpcMessage)
|
|
139
138
|
}
|
|
140
139
|
|
|
141
140
|
const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
142
141
|
manager1.on('disconnected', () => {
|
|
143
|
-
//expect(message.
|
|
142
|
+
//expect(message.body.oneofKind).toBe('rpcMessage')
|
|
144
143
|
resolve()
|
|
145
144
|
})
|
|
146
145
|
})
|
|
@@ -1,24 +1,35 @@
|
|
|
1
1
|
import { PeerManager, getDistance } from '../../src/dht/PeerManager'
|
|
2
|
-
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
2
|
+
import { DhtAddress, createRandomDhtAddress, getNodeIdFromPeerDescriptor, getRawFromDhtAddress } from '../../src/identifiers'
|
|
3
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { range, sampleSize, sortBy, without } from 'lodash'
|
|
4
|
+
import { range, sample, sampleSize, sortBy, without } from 'lodash'
|
|
5
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
6
|
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
7
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
|
+
|
|
9
|
+
const createPeerManager = (nodeIds: DhtAddress[]) => {
|
|
10
|
+
const peerDescriptor = createMockPeerDescriptor()
|
|
11
|
+
const manager = new PeerManager({
|
|
12
|
+
localNodeId: getNodeIdFromPeerDescriptor(peerDescriptor),
|
|
13
|
+
localPeerDescriptor: peerDescriptor,
|
|
14
|
+
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => {
|
|
15
|
+
return new DhtNodeRpcRemote(undefined as any, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
16
|
+
}
|
|
17
|
+
} as any)
|
|
18
|
+
const contacts = nodeIds.map((n) => ({ nodeId: getRawFromDhtAddress(n), type: NodeType.NODEJS }))
|
|
19
|
+
for (const contact of contacts) {
|
|
20
|
+
manager.addContact(contact)
|
|
21
|
+
}
|
|
22
|
+
return manager
|
|
23
|
+
}
|
|
7
24
|
|
|
8
25
|
describe('PeerManager', () => {
|
|
9
26
|
|
|
10
27
|
it('getClosestContactsTo', () => {
|
|
11
28
|
const nodeIds = range(10).map(() => createRandomDhtAddress())
|
|
12
|
-
const manager =
|
|
13
|
-
localNodeId: createRandomDhtAddress(),
|
|
14
|
-
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => {
|
|
15
|
-
return new DhtNodeRpcRemote(undefined as any, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
16
|
-
}
|
|
17
|
-
} as any)
|
|
18
|
-
manager.addContact(nodeIds.map((n) => ({ nodeId: getRawFromDhtAddress(n), type: NodeType.NODEJS })))
|
|
19
|
-
|
|
29
|
+
const manager = createPeerManager(nodeIds)
|
|
20
30
|
const referenceId = createRandomDhtAddress()
|
|
21
31
|
const excluded = new Set<DhtAddress>(sampleSize(nodeIds, 2))
|
|
32
|
+
|
|
22
33
|
const actual = manager.getClosestContactsTo(referenceId, 5, excluded)
|
|
23
34
|
|
|
24
35
|
const expected = sortBy(
|
|
@@ -27,4 +38,27 @@ describe('PeerManager', () => {
|
|
|
27
38
|
).slice(0, 5)
|
|
28
39
|
expect(actual.map((n) => n.getNodeId())).toEqual(expected)
|
|
29
40
|
})
|
|
41
|
+
|
|
42
|
+
it('getClosestNeighborsTo', () => {
|
|
43
|
+
const nodeIds = range(10).map(() => createRandomDhtAddress())
|
|
44
|
+
const manager = createPeerManager(nodeIds)
|
|
45
|
+
const referenceId = createRandomDhtAddress()
|
|
46
|
+
const excluded = new Set<DhtAddress>(sampleSize(nodeIds, 2))
|
|
47
|
+
|
|
48
|
+
const actual = manager.getClosestNeighborsTo(referenceId, 5, excluded)
|
|
49
|
+
|
|
50
|
+
const expected = sortBy(
|
|
51
|
+
without(manager.getNeighbors().map((n) => getNodeIdFromPeerDescriptor(n)), ...Array.from(excluded.values())),
|
|
52
|
+
(n: DhtAddress) => getDistance(getRawFromDhtAddress(n), getRawFromDhtAddress(referenceId))
|
|
53
|
+
).slice(0, 5)
|
|
54
|
+
expect(actual.map((n) => n.getNodeId())).toEqual(expected)
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
it('getContactCount', () => {
|
|
58
|
+
const nodeIds = range(10).map(() => createRandomDhtAddress())
|
|
59
|
+
const manager = createPeerManager(nodeIds)
|
|
60
|
+
expect(manager.getContactCount()).toBe(10)
|
|
61
|
+
expect(manager.getContactCount(new Set(sampleSize(nodeIds, 2)))).toBe(8)
|
|
62
|
+
expect(manager.getContactCount(new Set([sample(nodeIds)!, createRandomDhtAddress()]))).toBe(9)
|
|
63
|
+
})
|
|
30
64
|
})
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
RecursiveOperation,
|
|
3
3
|
Message,
|
|
4
|
-
MessageType,
|
|
5
4
|
RouteMessageAck,
|
|
6
5
|
RouteMessageError,
|
|
7
|
-
RouteMessageWrapper
|
|
6
|
+
RouteMessageWrapper,
|
|
7
|
+
RecursiveOperationRequest
|
|
8
8
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
9
|
import {
|
|
10
10
|
createWrappedClosestPeersRequest,
|
|
11
|
-
createFindRequest,
|
|
12
11
|
createMockPeerDescriptor
|
|
13
12
|
} from '../utils/utils'
|
|
14
13
|
import { RecursiveOperationManager } from '../../src/dht/recursive-operation/RecursiveOperationManager'
|
|
@@ -33,15 +32,23 @@ const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
|
|
|
33
32
|
addToDuplicateDetector: () => {}
|
|
34
33
|
}
|
|
35
34
|
}
|
|
35
|
+
|
|
36
|
+
const createRequest = (): RecursiveOperationRequest => {
|
|
37
|
+
const request: RecursiveOperationRequest = {
|
|
38
|
+
operation: RecursiveOperation.FIND_CLOSEST_NODES,
|
|
39
|
+
sessionId: v4()
|
|
40
|
+
}
|
|
41
|
+
return request
|
|
42
|
+
}
|
|
43
|
+
|
|
36
44
|
describe('RecursiveOperationManager', () => {
|
|
37
45
|
|
|
38
46
|
const peerDescriptor1 = createMockPeerDescriptor()
|
|
39
47
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
40
|
-
const recursiveOperationRequest =
|
|
48
|
+
const recursiveOperationRequest = createRequest()
|
|
41
49
|
const message: Message = {
|
|
42
50
|
serviceId: 'unknown',
|
|
43
51
|
messageId: v4(),
|
|
44
|
-
messageType: MessageType.RPC,
|
|
45
52
|
body: {
|
|
46
53
|
oneofKind: 'recursiveOperationRequest',
|
|
47
54
|
recursiveOperationRequest
|
|
@@ -83,9 +90,9 @@ describe('RecursiveOperationManager', () => {
|
|
|
83
90
|
recursiveOperationManager.stop()
|
|
84
91
|
})
|
|
85
92
|
|
|
86
|
-
it('
|
|
93
|
+
it('find closest nodes returns self if no peers', async () => {
|
|
87
94
|
const recursiveOperationManager = createRecursiveOperationManager()
|
|
88
|
-
const res = await recursiveOperationManager.execute(createRandomDhtAddress(), RecursiveOperation.
|
|
95
|
+
const res = await recursiveOperationManager.execute(createRandomDhtAddress(), RecursiveOperation.FIND_CLOSEST_NODES)
|
|
89
96
|
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
90
97
|
recursiveOperationManager.stop()
|
|
91
98
|
})
|
|
@@ -96,7 +103,6 @@ describe('RecursiveOperationManager', () => {
|
|
|
96
103
|
const badMessage: Message = {
|
|
97
104
|
serviceId: 'unknown',
|
|
98
105
|
messageId: v4(),
|
|
99
|
-
messageType: MessageType.RPC,
|
|
100
106
|
body: {
|
|
101
107
|
oneofKind: 'rpcMessage',
|
|
102
108
|
rpcMessage: rpcWrapper
|
|
@@ -39,7 +39,7 @@ describe('RecursiveOperationSession', () => {
|
|
|
39
39
|
targetId: createRandomDhtAddress(),
|
|
40
40
|
localPeerDescriptor,
|
|
41
41
|
waitedRoutingPathCompletions: 3,
|
|
42
|
-
operation: RecursiveOperation.
|
|
42
|
+
operation: RecursiveOperation.FIND_CLOSEST_NODES,
|
|
43
43
|
doRouteRequest
|
|
44
44
|
})
|
|
45
45
|
const onCompleted = jest.fn()
|
package/test/unit/Router.test.ts
CHANGED
|
@@ -3,7 +3,6 @@ import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
|
3
3
|
import { Router } from '../../src/dht/routing/Router'
|
|
4
4
|
import {
|
|
5
5
|
Message,
|
|
6
|
-
MessageType,
|
|
7
6
|
PeerDescriptor,
|
|
8
7
|
RouteMessageAck,
|
|
9
8
|
RouteMessageError,
|
|
@@ -23,7 +22,6 @@ describe('Router', () => {
|
|
|
23
22
|
const message: Message = {
|
|
24
23
|
serviceId: 'unknown',
|
|
25
24
|
messageId: v4(),
|
|
26
|
-
messageType: MessageType.RPC,
|
|
27
25
|
body: {
|
|
28
26
|
oneofKind: 'rpcMessage',
|
|
29
27
|
rpcMessage: rpcWrapper
|
|
@@ -52,7 +50,6 @@ describe('Router', () => {
|
|
|
52
50
|
router = new Router({
|
|
53
51
|
localPeerDescriptor: peerDescriptor1,
|
|
54
52
|
rpcCommunicator: rpcCommunicator as any,
|
|
55
|
-
addContact: (_contact) => {},
|
|
56
53
|
connections,
|
|
57
54
|
handleMessage: () => {}
|
|
58
55
|
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { v4 } from 'uuid'
|
|
2
2
|
import { RoutingMode, RoutingSession } from '../../src/dht/routing/RoutingSession'
|
|
3
|
-
import { Message,
|
|
3
|
+
import { Message, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
5
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
6
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
@@ -20,7 +20,6 @@ describe('RoutingSession', () => {
|
|
|
20
20
|
const message: Message = {
|
|
21
21
|
serviceId: 'unknown',
|
|
22
22
|
messageId: v4(),
|
|
23
|
-
messageType: MessageType.RPC,
|
|
24
23
|
body: {
|
|
25
24
|
oneofKind: 'rpcMessage',
|
|
26
25
|
rpcMessage: rpcWrapper
|
|
@@ -5,8 +5,8 @@ import { Server as HttpServer, createServer as createHttpServer } from 'http'
|
|
|
5
5
|
import { server as WsServer } from 'websocket'
|
|
6
6
|
import { CONNECTIVITY_CHECKER_SERVICE_ID } from '../../src/connection/connectivityChecker'
|
|
7
7
|
import { attachConnectivityRequestHandler } from '../../src/connection/connectivityRequestHandler'
|
|
8
|
-
import { Message
|
|
9
|
-
import {
|
|
8
|
+
import { Message } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
|
+
import { LOCAL_PROTOCOL_VERSION } from '../../src/helpers/version'
|
|
10
10
|
|
|
11
11
|
const HOST = '127.0.0.1'
|
|
12
12
|
const PORT = 15001
|
|
@@ -27,7 +27,7 @@ describe('connectivityRequestHandler', () => {
|
|
|
27
27
|
await once(httpServer, 'listening')
|
|
28
28
|
connection = new EventEmitter()
|
|
29
29
|
connection.send = jest.fn()
|
|
30
|
-
connection.
|
|
30
|
+
connection.remoteIpAddress = HOST
|
|
31
31
|
})
|
|
32
32
|
|
|
33
33
|
afterEach(async () => {
|
|
@@ -40,7 +40,6 @@ describe('connectivityRequestHandler', () => {
|
|
|
40
40
|
attachConnectivityRequestHandler(connection)
|
|
41
41
|
const request: Message = {
|
|
42
42
|
serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
43
|
-
messageType: MessageType.CONNECTIVITY_REQUEST,
|
|
44
43
|
messageId: 'mock-message-id',
|
|
45
44
|
body: {
|
|
46
45
|
oneofKind: 'connectivityRequest',
|
|
@@ -63,12 +62,11 @@ describe('connectivityRequestHandler', () => {
|
|
|
63
62
|
tls: false
|
|
64
63
|
},
|
|
65
64
|
ipAddress: ipv4ToNumber(HOST),
|
|
66
|
-
version
|
|
65
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
67
66
|
},
|
|
68
67
|
oneofKind: 'connectivityResponse'
|
|
69
68
|
},
|
|
70
69
|
messageId: expect.any(String),
|
|
71
|
-
messageType: MessageType.CONNECTIVITY_RESPONSE,
|
|
72
70
|
serviceId: 'system/connectivity-checker'
|
|
73
71
|
})
|
|
74
72
|
})
|
|
@@ -77,7 +75,6 @@ describe('connectivityRequestHandler', () => {
|
|
|
77
75
|
attachConnectivityRequestHandler(connection)
|
|
78
76
|
const request: Message = {
|
|
79
77
|
serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
80
|
-
messageType: MessageType.CONNECTIVITY_REQUEST,
|
|
81
78
|
messageId: 'mock-message-id',
|
|
82
79
|
body: {
|
|
83
80
|
oneofKind: 'connectivityRequest',
|
|
@@ -95,12 +92,11 @@ describe('connectivityRequestHandler', () => {
|
|
|
95
92
|
host: HOST,
|
|
96
93
|
natType: 'unknown',
|
|
97
94
|
ipAddress: ipv4ToNumber(HOST),
|
|
98
|
-
version
|
|
95
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
99
96
|
},
|
|
100
97
|
oneofKind: 'connectivityResponse'
|
|
101
98
|
},
|
|
102
99
|
messageId: expect.any(String),
|
|
103
|
-
messageType: MessageType.CONNECTIVITY_RESPONSE,
|
|
104
100
|
serviceId: 'system/connectivity-checker'
|
|
105
101
|
})
|
|
106
102
|
})
|