@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-testnet-one.1
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.js +2 -2
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +2 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js +3 -27
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +0 -1
- package/dist/src/connection/ConnectionManager.js +11 -7
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +2 -2
- package/dist/src/connection/ConnectorFacade.js +1 -2
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +1 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +122 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +2 -0
- package/dist/src/connection/connectivityRequestHandler.js +79 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.js +3 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.d.ts +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js +7 -3
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/ServerWebsocket.d.ts +4 -0
- package/dist/src/connection/websocket/ServerWebsocket.js +32 -21
- package/dist/src/connection/websocket/ServerWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +0 -2
- package/dist/src/connection/websocket/WebsocketConnector.js +61 -16
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +8 -11
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +4 -4
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +5 -39
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketServer.js +21 -4
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +13 -23
- package/dist/src/dht/DhtNode.js +97 -226
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -4
- package/dist/src/dht/DhtNodeRpcLocal.js +1 -5
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +3 -3
- package/dist/src/dht/DhtNodeRpcRemote.js +4 -4
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +4 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +5 -12
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcRemote.js +5 -5
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +52 -0
- package/dist/src/dht/PeerManager.js +273 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/ContactList.d.ts +1 -1
- package/dist/src/dht/contact/ContactList.js +1 -0
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +3 -3
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +8 -8
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/contact/SortedContactList.d.ts +20 -6
- package/dist/src/dht/contact/SortedContactList.js +55 -24
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +4 -14
- package/dist/src/dht/discovery/DiscoverySession.js +15 -26
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -9
- package/dist/src/dht/discovery/PeerDiscovery.js +11 -19
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/FindRpcLocal.js +2 -1
- package/dist/src/dht/find/FindRpcLocal.js.map +1 -1
- package/dist/src/dht/find/FindSession.d.ts +6 -6
- package/dist/src/dht/find/FindSession.js +18 -13
- package/dist/src/dht/find/FindSession.js.map +1 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +1 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +1 -1
- package/dist/src/dht/find/Finder.d.ts +4 -4
- package/dist/src/dht/find/Finder.js +55 -42
- package/dist/src/dht/find/Finder.js.map +1 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/FindRpcRemote.js +7 -5
- package/dist/src/dht/routing/FindRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +3 -7
- package/dist/src/dht/routing/Router.js +29 -22
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcLocal.js +4 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +13 -8
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
- package/dist/src/dht/routing/RoutingSession.js +23 -11
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +3 -3
- package/dist/src/dht/store/LocalDataStore.js +18 -17
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +10 -9
- package/dist/src/dht/store/StoreRpcLocal.js +108 -102
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js +6 -15
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +1 -1
- package/dist/src/exports.js +4 -4
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +1 -0
- package/dist/src/helpers/PeerID.js +9 -4
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/UUID.js +1 -1
- package/dist/src/helpers/UUID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +1 -0
- package/dist/src/helpers/{kademliaId.js → nodeId.js} +4 -4
- package/dist/src/helpers/nodeId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +4 -4
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +5 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +2 -9
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +80 -95
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +67 -66
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +3 -10
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/karma.config.js +2 -2
- package/package.json +5 -5
- package/protos/DhtRpc.proto +36 -36
- package/src/connection/ConnectionLockHandler.ts +2 -2
- package/src/connection/ConnectionLockRpcRemote.ts +3 -4
- package/src/connection/ConnectionManager.ts +19 -17
- package/src/connection/ConnectorFacade.ts +5 -7
- package/src/connection/ManagedConnection.ts +1 -0
- package/src/connection/connectivityChecker.ts +102 -0
- package/src/connection/connectivityRequestHandler.ts +79 -0
- package/src/connection/simulator/Simulator.ts +3 -2
- package/src/connection/simulator/SimulatorConnection.ts +1 -1
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -10
- package/src/connection/webrtc/NodeWebrtcConnection.ts +1 -1
- package/src/connection/webrtc/WebrtcConnector.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +2 -2
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/ClientWebsocket.ts +6 -2
- package/src/connection/websocket/ServerWebsocket.ts +40 -25
- package/src/connection/websocket/WebsocketConnector.ts +43 -22
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +9 -11
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +7 -16
- package/src/connection/websocket/WebsocketServer.ts +20 -5
- package/src/dht/DhtNode.ts +123 -280
- package/src/dht/DhtNodeRpcLocal.ts +2 -9
- package/src/dht/DhtNodeRpcRemote.ts +4 -4
- package/src/dht/ExternalApiRpcLocal.ts +8 -13
- package/src/dht/ExternalApiRpcRemote.ts +5 -5
- package/src/dht/PeerManager.ts +330 -0
- package/src/dht/contact/ContactList.ts +3 -2
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +7 -6
- package/src/dht/contact/SortedContactList.ts +87 -44
- package/src/dht/discovery/DiscoverySession.ts +19 -44
- package/src/dht/discovery/PeerDiscovery.ts +16 -28
- package/src/dht/find/FindRpcLocal.ts +2 -2
- package/src/dht/find/FindSession.ts +25 -20
- package/src/dht/find/FindSessionRpcLocal.ts +1 -1
- package/src/dht/find/FindSessionRpcRemote.ts +2 -2
- package/src/dht/find/Finder.ts +84 -64
- package/src/dht/routing/FindRpcRemote.ts +7 -5
- package/src/dht/routing/Router.ts +30 -25
- package/src/dht/routing/RouterRpcLocal.ts +5 -5
- package/src/dht/routing/RouterRpcRemote.ts +13 -10
- package/src/dht/routing/RoutingSession.ts +22 -17
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +18 -17
- package/src/dht/store/StoreRpcLocal.ts +118 -113
- package/src/dht/store/StoreRpcRemote.ts +7 -23
- package/src/exports.ts +1 -1
- package/src/helpers/PeerID.ts +8 -4
- package/src/helpers/UUID.ts +1 -1
- package/src/helpers/{kademliaId.ts → nodeId.ts} +1 -1
- package/src/helpers/peerIdFromPeerDescriptor.ts +6 -6
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -20
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -10
- package/src/proto/packages/dht/protos/DhtRpc.ts +103 -135
- package/src/transport/RoutingRpcCommunicator.ts +2 -0
- package/test/benchmark/Find.test.ts +5 -5
- package/test/benchmark/KademliaCorrectness.test.ts +3 -3
- package/test/benchmark/SortedContactListBenchmark.test.ts +150 -0
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +41 -0
- package/test/benchmark/kademlia-simulation/Contact.ts +1 -1
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +1 -1
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +6 -1
- 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 +11 -11
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +6 -6
- package/test/end-to-end/Layer0Webrtc.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +3 -3
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +3 -3
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +9 -12
- package/test/integration/ConnectionLocking.test.ts +2 -2
- package/test/integration/ConnectionManager.test.ts +14 -14
- package/test/integration/DhtJoinPeerDiscovery.test.ts +3 -3
- package/test/integration/DhtNodeExternalAPI.test.ts +10 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +4 -4
- package/test/integration/DhtRpc.test.ts +6 -6
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +3 -3
- package/test/integration/Mock-Layer1-Layer0.test.ts +16 -16
- package/test/integration/MultipleEntryPointJoining.test.ts +7 -7
- package/test/integration/{MigrateData.test.ts → ReplicateData.test.ts} +15 -10
- package/test/integration/RouteMessage.test.ts +2 -2
- package/test/integration/RouterRpcRemote.test.ts +2 -2
- package/test/integration/RpcErrors.test.ts +2 -2
- package/test/integration/ScaleDownDht.test.ts +4 -2
- package/test/integration/SimultaneousConnections.test.ts +89 -57
- package/test/integration/Store.test.ts +33 -13
- package/test/integration/StoreAndDelete.test.ts +19 -17
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +21 -21
- package/test/integration/StoreRpcRemote.test.ts +3 -3
- package/test/integration/WebrtcConnectionManagement.test.ts +2 -2
- package/test/integration/WebrtcConnectorRpc.test.ts +1 -1
- package/test/integration/WebsocketConnectionManagement.test.ts +41 -3
- package/test/integration/WebsocketConnectorRpc.test.ts +5 -7
- package/test/unit/ConnectivityHelpers.test.ts +4 -4
- package/test/unit/Finder.test.ts +69 -23
- package/test/unit/LocalDataStore.test.ts +60 -43
- package/test/unit/RandomContactList.test.ts +2 -2
- package/test/unit/Router.test.ts +19 -11
- package/test/unit/RoutingSession.test.ts +76 -0
- package/test/unit/SortedContactList.test.ts +17 -12
- package/test/unit/WebsocketConnector.test.ts +1 -1
- package/test/unit/connectivityRequestHandler.test.ts +71 -0
- package/test/utils/mock/Router.ts +1 -1
- package/test/utils/utils.ts +24 -22
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import KBucket from 'k-bucket'
|
|
4
|
+
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
5
|
+
import { PeerID } from '../../src/helpers/PeerID'
|
|
6
|
+
import crypto from 'crypto'
|
|
7
|
+
|
|
8
|
+
const NUM_ADDS = 1000
|
|
9
|
+
interface Item {
|
|
10
|
+
id: Uint8Array
|
|
11
|
+
vectorClock: number
|
|
12
|
+
getPeerId: () => PeerID
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const createRandomItem = (index: number): Item => {
|
|
16
|
+
const rand = new Uint8Array(crypto.randomBytes(20))
|
|
17
|
+
return {
|
|
18
|
+
getPeerId: () => PeerID.fromValue(rand),
|
|
19
|
+
id: rand,
|
|
20
|
+
vectorClock: index
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function shuffleArray<T>(array: T[]): T[] {
|
|
25
|
+
for (let i = array.length - 1; i > 0; i--) {
|
|
26
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
27
|
+
[array[i], array[j]] = [array[j], array[i]]
|
|
28
|
+
}
|
|
29
|
+
return array
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
describe('SortedContactListBenchmark', () => {
|
|
33
|
+
|
|
34
|
+
it('adds ' + NUM_ADDS + ' random peerIDs', async () => {
|
|
35
|
+
const randomIds = []
|
|
36
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
37
|
+
randomIds.push(createRandomItem(i))
|
|
38
|
+
}
|
|
39
|
+
const list = new SortedContactList({
|
|
40
|
+
referenceId: PeerID.fromValue(crypto.randomBytes(20)),
|
|
41
|
+
allowToContainReferenceId: true,
|
|
42
|
+
emitEvents: true
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
console.time('SortedContactList.addContact() with emitEvents=true')
|
|
46
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
47
|
+
list.addContact(randomIds[i])
|
|
48
|
+
}
|
|
49
|
+
console.timeEnd('SortedContactList.addContact() with emitEvents=true')
|
|
50
|
+
|
|
51
|
+
const list2 = new SortedContactList({
|
|
52
|
+
referenceId: PeerID.fromValue(crypto.randomBytes(20)),
|
|
53
|
+
allowToContainReferenceId: true,
|
|
54
|
+
emitEvents: false
|
|
55
|
+
})
|
|
56
|
+
|
|
57
|
+
console.time('SortedContactList.addContact() with emitEvents=false')
|
|
58
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
59
|
+
list2.addContact(randomIds[i])
|
|
60
|
+
}
|
|
61
|
+
console.timeEnd('SortedContactList.addContact() with emitEvents=false')
|
|
62
|
+
|
|
63
|
+
const kBucket = new KBucket<Item>({ localNodeId: crypto.randomBytes(20) })
|
|
64
|
+
console.time('KBucket.add()')
|
|
65
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
66
|
+
kBucket.add(randomIds[i])
|
|
67
|
+
}
|
|
68
|
+
console.timeEnd('KBucket.add()')
|
|
69
|
+
|
|
70
|
+
console.time('kBucket toArray()')
|
|
71
|
+
|
|
72
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
73
|
+
kBucket.toArray()
|
|
74
|
+
}
|
|
75
|
+
console.timeEnd('kBucket toArray()')
|
|
76
|
+
|
|
77
|
+
console.time('kBucket closest()')
|
|
78
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
79
|
+
kBucket.closest(crypto.randomBytes(20), 20)
|
|
80
|
+
}
|
|
81
|
+
console.timeEnd('kBucket closest()')
|
|
82
|
+
|
|
83
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=true')
|
|
84
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
85
|
+
const closest = new SortedContactList<Item>({
|
|
86
|
+
referenceId: PeerID.fromValue(crypto.randomBytes(20)),
|
|
87
|
+
allowToContainReferenceId: true,
|
|
88
|
+
emitEvents: true
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
const arrayFromBucket = kBucket.toArray()
|
|
92
|
+
arrayFromBucket.map((contact) => closest.addContact(contact))
|
|
93
|
+
closest.getClosestContacts(20)
|
|
94
|
+
}
|
|
95
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=true')
|
|
96
|
+
|
|
97
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=false')
|
|
98
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
99
|
+
const closest = new SortedContactList<Item>({
|
|
100
|
+
referenceId: PeerID.fromValue(crypto.randomBytes(20)),
|
|
101
|
+
allowToContainReferenceId: true,
|
|
102
|
+
emitEvents: false
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
const arrayFromBucket = kBucket.toArray()
|
|
106
|
+
arrayFromBucket.map((contact) => closest.addContact(contact))
|
|
107
|
+
closest.getClosestContacts(20)
|
|
108
|
+
}
|
|
109
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false')
|
|
110
|
+
|
|
111
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=false and lodash')
|
|
112
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
113
|
+
const closest = new SortedContactList<Item>({
|
|
114
|
+
referenceId: PeerID.fromValue(crypto.randomBytes(20)),
|
|
115
|
+
allowToContainReferenceId: true,
|
|
116
|
+
emitEvents: false
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
const arrayFromBucket = kBucket.toArray()
|
|
120
|
+
arrayFromBucket.map((contact) => closest.addContact(contact))
|
|
121
|
+
closest.getClosestContacts(20)
|
|
122
|
+
}
|
|
123
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false and lodash')
|
|
124
|
+
|
|
125
|
+
console.time('SortedContactList.getClosestContacts() with emitEvents=false and addContacts()')
|
|
126
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
127
|
+
const closest = new SortedContactList<Item>({
|
|
128
|
+
referenceId: PeerID.fromValue(crypto.randomBytes(20)),
|
|
129
|
+
allowToContainReferenceId: true,
|
|
130
|
+
emitEvents: false
|
|
131
|
+
})
|
|
132
|
+
|
|
133
|
+
const arrayFromBucket = kBucket.toArray()
|
|
134
|
+
closest.addContacts(arrayFromBucket)
|
|
135
|
+
closest.getClosestContacts(20)
|
|
136
|
+
}
|
|
137
|
+
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false and addContacts()')
|
|
138
|
+
|
|
139
|
+
const shuffled = shuffleArray(kBucket.toArray())
|
|
140
|
+
console.time('kbucket add and closest')
|
|
141
|
+
for (let i = 0; i < NUM_ADDS; i++) {
|
|
142
|
+
const bucket2 = new KBucket<Item>({ localNodeId: crypto.randomBytes(20) })
|
|
143
|
+
|
|
144
|
+
shuffled.map((contact) => bucket2.add(contact))
|
|
145
|
+
bucket2.closest(crypto.randomBytes(20), 20)
|
|
146
|
+
}
|
|
147
|
+
console.timeEnd('kbucket add and closest')
|
|
148
|
+
|
|
149
|
+
})
|
|
150
|
+
})
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
import { wait } from '@streamr/utils'
|
|
4
|
+
import { WebsocketServer } from '../../src/connection/websocket/WebsocketServer'
|
|
5
|
+
import { ClientWebsocket } from '../../src/exports'
|
|
6
|
+
|
|
7
|
+
// This 'test' is meant to be run manually using the following command:
|
|
8
|
+
// node --inspect ../../../../node_modules/.bin/jest WebsocketServerMemoryLeak.test.ts
|
|
9
|
+
// while wathing for memory leaks in Chrome DevTools
|
|
10
|
+
|
|
11
|
+
describe('WebsocketServermemoryLeak', () => {
|
|
12
|
+
|
|
13
|
+
it('Accepts and detroys connections', async () => {
|
|
14
|
+
const server = new WebsocketServer({
|
|
15
|
+
portRange: { min: 19792, max: 19792 },
|
|
16
|
+
enableTls: false
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
server.on('connected', (connection) => {
|
|
20
|
+
console.log('ServerWebsocket connected')
|
|
21
|
+
connection.destroy()
|
|
22
|
+
console.log('ServerWebsocket destroyed')
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
const port = await server.start()
|
|
26
|
+
expect(port).toEqual(19792)
|
|
27
|
+
|
|
28
|
+
for (let i = 0; i < 10000; i++) {
|
|
29
|
+
const clientWebsocket: ClientWebsocket = new ClientWebsocket()
|
|
30
|
+
clientWebsocket.on('connected', () => {
|
|
31
|
+
console.log('clientWebsocket connected ' + i)
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
clientWebsocket.connect(`ws://127.0.0.1:${port}`)
|
|
35
|
+
i++
|
|
36
|
+
await wait(3000)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
await server.stop()
|
|
40
|
+
}, 120000000)
|
|
41
|
+
})
|
|
@@ -17,7 +17,7 @@ export class KademliaSimulation {
|
|
|
17
17
|
|
|
18
18
|
constructor() {
|
|
19
19
|
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
20
|
-
throw ('Cannot find test/data/nodeids.json, please run "npm run prepare-kademlia-simulation first"')
|
|
20
|
+
throw new Error('Cannot find test/data/nodeids.json, please run "npm run prepare-kademlia-simulation first"')
|
|
21
21
|
}
|
|
22
22
|
this.dhtIds = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
23
23
|
this.groundTruth = JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
@@ -26,7 +26,12 @@ export class SimulationNode {
|
|
|
26
26
|
numberOfNodesPerKBucket: this.numberOfNodesPerKBucket
|
|
27
27
|
})
|
|
28
28
|
|
|
29
|
-
this.neighborList = new SortedContactList(
|
|
29
|
+
this.neighborList = new SortedContactList({
|
|
30
|
+
referenceId: this.ownId,
|
|
31
|
+
maxSize: 1000,
|
|
32
|
+
allowToContainReferenceId: false,
|
|
33
|
+
emitEvents: false
|
|
34
|
+
})
|
|
30
35
|
}
|
|
31
36
|
|
|
32
37
|
// For simulation use
|
|
@@ -4,7 +4,7 @@ import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescrip
|
|
|
4
4
|
|
|
5
5
|
describe('Layer0-Layer1', () => {
|
|
6
6
|
const epPeerDescriptor: PeerDescriptor = {
|
|
7
|
-
|
|
7
|
+
nodeId: Uint8Array.from([1, 2, 3]),
|
|
8
8
|
type: NodeType.NODEJS,
|
|
9
9
|
websocket: { host: '127.0.0.1', port: 10016, tls: false }
|
|
10
10
|
}
|
|
@@ -71,9 +71,9 @@ describe('Layer0', () => {
|
|
|
71
71
|
node4.joinDht([epPeerDescriptor])
|
|
72
72
|
])
|
|
73
73
|
|
|
74
|
-
expect(node1.
|
|
75
|
-
expect(node2.
|
|
76
|
-
expect(node3.
|
|
77
|
-
expect(node4.
|
|
74
|
+
expect(node1.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
75
|
+
expect(node2.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
76
|
+
expect(node3.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
77
|
+
expect(node4.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
78
78
|
}, 10000)
|
|
79
79
|
})
|
|
@@ -7,7 +7,7 @@ import { TransportEvents } from '../../src/transport/ITransport'
|
|
|
7
7
|
describe('Layer0MixedConnectionTypes', () => {
|
|
8
8
|
|
|
9
9
|
const epPeerDescriptor: PeerDescriptor = {
|
|
10
|
-
|
|
10
|
+
nodeId: Uint8Array.from([1, 2, 3]),
|
|
11
11
|
type: NodeType.NODEJS,
|
|
12
12
|
websocket: { host: '127.0.0.1', port: 11221, tls: false }
|
|
13
13
|
}
|
|
@@ -89,11 +89,11 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
89
89
|
node5.joinDht([epPeerDescriptor])
|
|
90
90
|
])
|
|
91
91
|
|
|
92
|
-
expect(node1.
|
|
93
|
-
expect(node2.
|
|
94
|
-
expect(node3.
|
|
95
|
-
expect(node4.
|
|
96
|
-
expect(node5.
|
|
92
|
+
expect(node1.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
93
|
+
expect(node2.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
94
|
+
expect(node3.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
95
|
+
expect(node4.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
96
|
+
expect(node5.getNumberOfNeighbors()).toBeGreaterThanOrEqual(1)
|
|
97
97
|
|
|
98
98
|
}, 15000)
|
|
99
99
|
|
|
@@ -105,10 +105,10 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
105
105
|
node4.joinDht([epPeerDescriptor]),
|
|
106
106
|
node5.joinDht([epPeerDescriptor])
|
|
107
107
|
])
|
|
108
|
-
expect(node1.
|
|
109
|
-
expect(node2.
|
|
110
|
-
expect(node3.
|
|
111
|
-
expect(node4.
|
|
112
|
-
expect(node5.
|
|
108
|
+
expect(node1.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
109
|
+
expect(node2.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
110
|
+
expect(node3.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
111
|
+
expect(node4.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
112
|
+
expect(node5.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
113
113
|
}, 30000)
|
|
114
114
|
})
|
|
@@ -4,7 +4,7 @@ import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/Dh
|
|
|
4
4
|
|
|
5
5
|
describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
6
6
|
const entrypointDescriptor: PeerDescriptor = {
|
|
7
|
-
|
|
7
|
+
nodeId: new Uint8Array([0]),
|
|
8
8
|
type: NodeType.NODEJS,
|
|
9
9
|
websocket: {
|
|
10
10
|
host: '127.0.0.1',
|
|
@@ -53,7 +53,7 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
|
53
53
|
})
|
|
54
54
|
|
|
55
55
|
layer1EntryPoint = new DhtNode({
|
|
56
|
-
peerId: binaryToHex(entrypointDescriptor.
|
|
56
|
+
peerId: binaryToHex(entrypointDescriptor.nodeId),
|
|
57
57
|
transport: layer0EntryPoint,
|
|
58
58
|
serviceId: 'layer1'
|
|
59
59
|
})
|
|
@@ -125,9 +125,9 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
|
125
125
|
await layer1Node3.joinDht([entrypointDescriptor])
|
|
126
126
|
await layer1Node4.joinDht([entrypointDescriptor])
|
|
127
127
|
|
|
128
|
-
expect(layer1Node1.
|
|
129
|
-
expect(layer1Node2.
|
|
130
|
-
expect(layer1Node3.
|
|
131
|
-
expect(layer1Node4.
|
|
128
|
+
expect(layer1Node1.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
129
|
+
expect(layer1Node2.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
130
|
+
expect(layer1Node3.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
131
|
+
expect(layer1Node4.getNumberOfNeighbors()).toBeGreaterThanOrEqual(2)
|
|
132
132
|
}, 60000)
|
|
133
133
|
})
|
|
@@ -7,7 +7,7 @@ import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/Dh
|
|
|
7
7
|
|
|
8
8
|
describe('Layer0 with WebRTC connections', () => {
|
|
9
9
|
const epPeerDescriptor: PeerDescriptor = {
|
|
10
|
-
|
|
10
|
+
nodeId: PeerID.fromString('entrypoint').value,
|
|
11
11
|
type: NodeType.NODEJS,
|
|
12
12
|
websocket: { host: '127.0.0.1', port: 10029, tls: false }
|
|
13
13
|
}
|
|
@@ -61,7 +61,7 @@ describe('Layer0 with WebRTC connections', () => {
|
|
|
61
61
|
'connected',
|
|
62
62
|
20000,
|
|
63
63
|
(peerDescriptor: PeerDescriptor) => {
|
|
64
|
-
return areEqualBinaries(peerDescriptor.
|
|
64
|
+
return areEqualBinaries(peerDescriptor.nodeId, node1.getLocalPeerDescriptor().nodeId)
|
|
65
65
|
}
|
|
66
66
|
),
|
|
67
67
|
node2.joinDht([epPeerDescriptor]),
|
|
@@ -6,7 +6,7 @@ const NUM_OF_NODES_PER_KBUCKET = 8
|
|
|
6
6
|
|
|
7
7
|
describe('Layer1 Scale', () => {
|
|
8
8
|
const epPeerDescriptor: PeerDescriptor = {
|
|
9
|
-
|
|
9
|
+
nodeId: PeerID.fromString('entrypoint').value,
|
|
10
10
|
type: NodeType.NODEJS,
|
|
11
11
|
websocket: { host: '127.0.0.1', port: 43225, tls: false }
|
|
12
12
|
}
|
|
@@ -75,10 +75,10 @@ describe('Layer1 Scale', () => {
|
|
|
75
75
|
// TODO: fix flaky test in NET-1021
|
|
76
76
|
it('bucket sizes', async () => {
|
|
77
77
|
layer0Nodes.forEach((node) => {
|
|
78
|
-
expect(node.
|
|
78
|
+
expect(node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET - 1)
|
|
79
79
|
})
|
|
80
80
|
layer1Nodes.forEach((node ) => {
|
|
81
|
-
expect(node.
|
|
81
|
+
expect(node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
82
82
|
})
|
|
83
83
|
})
|
|
84
84
|
})
|
|
@@ -6,7 +6,7 @@ const NUM_OF_NODES_PER_KBUCKET = 8
|
|
|
6
6
|
|
|
7
7
|
describe('Layer1 Scale', () => {
|
|
8
8
|
const epPeerDescriptor: PeerDescriptor = {
|
|
9
|
-
|
|
9
|
+
nodeId: PeerID.fromString('0').value,
|
|
10
10
|
type: NodeType.NODEJS,
|
|
11
11
|
websocket: { host: '127.0.0.1', port: 43228, tls: false }
|
|
12
12
|
}
|
|
@@ -65,10 +65,10 @@ describe('Layer1 Scale', () => {
|
|
|
65
65
|
|
|
66
66
|
it('bucket sizes', async () => {
|
|
67
67
|
layer0Nodes.forEach((node) => {
|
|
68
|
-
expect(node.
|
|
68
|
+
expect(node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET - 1)
|
|
69
69
|
})
|
|
70
70
|
layer1Nodes.forEach((node) => {
|
|
71
|
-
expect(node.
|
|
71
|
+
expect(node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
72
72
|
})
|
|
73
73
|
})
|
|
74
74
|
})
|
|
@@ -46,7 +46,7 @@ describe('Failed autocertification', () => {
|
|
|
46
46
|
const failedAutocertificationPeerDescriptor = failedAutocertificationNode.getLocalPeerDescriptor()
|
|
47
47
|
expect(failedAutocertificationPeerDescriptor.websocket!.tls).toBe(false)
|
|
48
48
|
await failedAutocertificationNode.joinDht([entryPointPeerDescriptor])
|
|
49
|
-
expect(failedAutocertificationNode.
|
|
49
|
+
expect(failedAutocertificationNode.getNumberOfNeighbors()).toEqual(2)
|
|
50
50
|
})
|
|
51
51
|
|
|
52
52
|
})
|
|
@@ -7,7 +7,7 @@ import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescrip
|
|
|
7
7
|
|
|
8
8
|
describe('Websocket IConnection Requests', () => {
|
|
9
9
|
const epPeerDescriptor: PeerDescriptor = {
|
|
10
|
-
|
|
10
|
+
nodeId: PeerID.fromString('3').value,
|
|
11
11
|
type: NodeType.NODEJS,
|
|
12
12
|
websocket: { host: '127.0.0.1', port: 10021, tls: false }
|
|
13
13
|
}
|
|
@@ -11,7 +11,7 @@ describe('memory leak', () => {
|
|
|
11
11
|
|
|
12
12
|
it('send message', async () => {
|
|
13
13
|
const entryPointDescriptor = {
|
|
14
|
-
|
|
14
|
+
nodeId: randomBytes(10),
|
|
15
15
|
type: NodeType.NODEJS,
|
|
16
16
|
websocket: {
|
|
17
17
|
host: '127.0.0.1',
|
|
@@ -20,7 +20,7 @@ describe('memory leak', () => {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
let entryPoint: DhtNode | undefined = new DhtNode({
|
|
23
|
-
peerId: binaryToHex(entryPointDescriptor.
|
|
23
|
+
peerId: binaryToHex(entryPointDescriptor.nodeId),
|
|
24
24
|
websocketHost: entryPointDescriptor.websocket!.host,
|
|
25
25
|
websocketPortRange: {
|
|
26
26
|
min: entryPointDescriptor.websocket.port,
|
|
@@ -33,20 +33,16 @@ describe('memory leak', () => {
|
|
|
33
33
|
await entryPoint.joinDht([entryPointDescriptor])
|
|
34
34
|
let sender: DhtNode | undefined = new DhtNode({})
|
|
35
35
|
let receiver: DhtNode | undefined = new DhtNode({})
|
|
36
|
-
|
|
37
|
-
async () => {
|
|
36
|
+
await Promise.all([
|
|
37
|
+
(async () => {
|
|
38
38
|
await sender.start()
|
|
39
39
|
await sender.joinDht([entryPointDescriptor])
|
|
40
|
-
},
|
|
41
|
-
async () => {
|
|
40
|
+
})(),
|
|
41
|
+
(async () => {
|
|
42
42
|
await receiver.start()
|
|
43
43
|
await receiver.joinDht([entryPointDescriptor])
|
|
44
|
-
}
|
|
45
|
-
])
|
|
46
|
-
await sender.start()
|
|
47
|
-
await sender.joinDht([entryPointDescriptor])
|
|
48
|
-
await receiver.start()
|
|
49
|
-
await receiver.joinDht([entryPointDescriptor])
|
|
44
|
+
})()
|
|
45
|
+
])
|
|
50
46
|
|
|
51
47
|
let receivedMessage: Message | undefined = undefined
|
|
52
48
|
receiver.on('message', (msg: Message) => receivedMessage = msg)
|
|
@@ -72,6 +68,7 @@ describe('memory leak', () => {
|
|
|
72
68
|
|
|
73
69
|
const detector1 = new LeakDetector(entryPoint)
|
|
74
70
|
entryPoint = undefined
|
|
71
|
+
await detector1.isLeaking()
|
|
75
72
|
expect(await detector1.isLeaking()).toBe(false)
|
|
76
73
|
|
|
77
74
|
const detector2 = new LeakDetector(sender)
|
|
@@ -21,12 +21,12 @@ const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport:
|
|
|
21
21
|
describe('Connection Locking', () => {
|
|
22
22
|
|
|
23
23
|
const mockPeerDescriptor1: PeerDescriptor = {
|
|
24
|
-
|
|
24
|
+
nodeId: PeerID.fromString('mock1').value,
|
|
25
25
|
type: NodeType.NODEJS,
|
|
26
26
|
region: getRandomRegion()
|
|
27
27
|
}
|
|
28
28
|
const mockPeerDescriptor2: PeerDescriptor = {
|
|
29
|
-
|
|
29
|
+
nodeId: PeerID.fromString('mock2').value,
|
|
30
30
|
type: NodeType.NODEJS,
|
|
31
31
|
region: getRandomRegion()
|
|
32
32
|
}
|
|
@@ -8,7 +8,7 @@ import { Logger, MetricsContext, waitForEvent3 } from '@streamr/utils'
|
|
|
8
8
|
import { SimulatorTransport } from '../../src/exports'
|
|
9
9
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
10
10
|
import { MarkOptional } from 'ts-essentials'
|
|
11
|
-
import {
|
|
11
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
12
12
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
13
13
|
|
|
14
14
|
const logger = new Logger(module)
|
|
@@ -18,20 +18,20 @@ describe('ConnectionManager', () => {
|
|
|
18
18
|
const serviceId = 'demo'
|
|
19
19
|
|
|
20
20
|
const mockPeerDescriptor1: PeerDescriptor = {
|
|
21
|
-
|
|
21
|
+
nodeId: PeerID.fromString('tester1').value,
|
|
22
22
|
type: NodeType.NODEJS
|
|
23
23
|
}
|
|
24
24
|
const mockPeerDescriptor2: PeerDescriptor = {
|
|
25
|
-
|
|
25
|
+
nodeId: PeerID.fromString('tester2').value,
|
|
26
26
|
type: NodeType.NODEJS
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
const mockPeerDescriptor3: PeerDescriptor = {
|
|
30
|
-
|
|
30
|
+
nodeId: PeerID.fromString('tester3').value,
|
|
31
31
|
type: NodeType.NODEJS
|
|
32
32
|
}
|
|
33
33
|
const mockPeerDescriptor4: PeerDescriptor = {
|
|
34
|
-
|
|
34
|
+
nodeId: PeerID.fromString('tester4').value,
|
|
35
35
|
type: NodeType.NODEJS
|
|
36
36
|
}
|
|
37
37
|
const simulator = new Simulator()
|
|
@@ -89,7 +89,7 @@ describe('ConnectionManager', () => {
|
|
|
89
89
|
transport: mockTransport,
|
|
90
90
|
websocketPortRange: { min: 9992, max: 9992 },
|
|
91
91
|
entryPoints: [
|
|
92
|
-
{
|
|
92
|
+
{ nodeId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 12345, tls: false } }
|
|
93
93
|
]
|
|
94
94
|
})
|
|
95
95
|
|
|
@@ -112,7 +112,7 @@ describe('ConnectionManager', () => {
|
|
|
112
112
|
transport: mockConnectorTransport2,
|
|
113
113
|
websocketPortRange: { min: 9994, max: 9994 },
|
|
114
114
|
entryPoints: [
|
|
115
|
-
{
|
|
115
|
+
{ nodeId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 9993, tls: false } }
|
|
116
116
|
]
|
|
117
117
|
})
|
|
118
118
|
|
|
@@ -306,7 +306,7 @@ describe('ConnectionManager', () => {
|
|
|
306
306
|
await connectionManager4.stop()
|
|
307
307
|
})
|
|
308
308
|
|
|
309
|
-
it('Cannot send to own WebsocketServer if
|
|
309
|
+
it('Cannot send to own WebsocketServer if nodeIds do not match', async () => {
|
|
310
310
|
const connectionManager1 = createConnectionManager({
|
|
311
311
|
transport: mockTransport,
|
|
312
312
|
websocketHost: '127.0.0.1',
|
|
@@ -317,7 +317,7 @@ describe('ConnectionManager', () => {
|
|
|
317
317
|
expect(createLocalPeerDescriptor.mock.calls[0][0].host).toEqual('127.0.0.1')
|
|
318
318
|
|
|
319
319
|
const peerDescriptor = connectionManager1.getLocalPeerDescriptor()
|
|
320
|
-
peerDescriptor.
|
|
320
|
+
peerDescriptor.nodeId = new Uint8Array([12, 12, 12, 12])
|
|
321
321
|
const msg: Message = {
|
|
322
322
|
serviceId,
|
|
323
323
|
messageType: MessageType.RPC,
|
|
@@ -335,10 +335,10 @@ describe('ConnectionManager', () => {
|
|
|
335
335
|
await connectionManager1.stop()
|
|
336
336
|
})
|
|
337
337
|
|
|
338
|
-
it('Cannot send to a WebSocketServer if
|
|
338
|
+
it('Cannot send to a WebSocketServer if nodeIds do not match', async () => {
|
|
339
339
|
|
|
340
340
|
const peerDescriptor1 = {
|
|
341
|
-
|
|
341
|
+
nodeId: createRandomNodeId(),
|
|
342
342
|
type: NodeType.NODEJS,
|
|
343
343
|
websocket: {
|
|
344
344
|
host: '127.0.0.1',
|
|
@@ -348,7 +348,7 @@ describe('ConnectionManager', () => {
|
|
|
348
348
|
}
|
|
349
349
|
|
|
350
350
|
const peerDescriptor2 = {
|
|
351
|
-
|
|
351
|
+
nodeId: createRandomNodeId(),
|
|
352
352
|
type: NodeType.NODEJS,
|
|
353
353
|
websocket: {
|
|
354
354
|
host: '127.0.0.1',
|
|
@@ -379,8 +379,8 @@ describe('ConnectionManager', () => {
|
|
|
379
379
|
messageType: MessageType.RPC,
|
|
380
380
|
messageId: '1',
|
|
381
381
|
targetDescriptor: {
|
|
382
|
-
// This is not the correct
|
|
383
|
-
|
|
382
|
+
// This is not the correct nodeId of peerDescriptor2
|
|
383
|
+
nodeId: new Uint8Array([1, 2, 3, 4]),
|
|
384
384
|
type: NodeType.NODEJS,
|
|
385
385
|
websocket: peerDescriptor2.websocket
|
|
386
386
|
},
|
|
@@ -11,7 +11,7 @@ const runTest = async (latencyType: LatencyType) => {
|
|
|
11
11
|
const entryPointId = '0'
|
|
12
12
|
const entryPoint = await createMockConnectionDhtNode(entryPointId, simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
13
13
|
const entrypointDescriptor = {
|
|
14
|
-
|
|
14
|
+
nodeId: entryPoint.getNodeId().value,
|
|
15
15
|
type: NodeType.NODEJS,
|
|
16
16
|
region: getRandomRegion()
|
|
17
17
|
}
|
|
@@ -25,10 +25,10 @@ const runTest = async (latencyType: LatencyType) => {
|
|
|
25
25
|
await entryPoint.joinDht([entrypointDescriptor])
|
|
26
26
|
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
27
27
|
nodes.forEach((node) => {
|
|
28
|
-
expect(node.
|
|
28
|
+
expect(node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
29
29
|
expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
30
30
|
})
|
|
31
|
-
expect(entryPoint.
|
|
31
|
+
expect(entryPoint.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
32
32
|
|
|
33
33
|
await Promise.all([
|
|
34
34
|
entryPoint.stop(),
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
2
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
3
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
3
|
+
import { createMockConnectionDhtNode, createMockPeerDescriptor } from '../utils/utils'
|
|
4
4
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
5
5
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
-
import {
|
|
6
|
+
import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
7
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
7
8
|
|
|
8
9
|
describe('DhtNodeExternalApi', () => {
|
|
9
10
|
|
|
@@ -28,7 +29,7 @@ describe('DhtNodeExternalApi', () => {
|
|
|
28
29
|
|
|
29
30
|
it('findData happy path', async () => {
|
|
30
31
|
const data = Any.pack(dhtNode1.getLocalPeerDescriptor(), PeerDescriptor)
|
|
31
|
-
const key =
|
|
32
|
+
const key = createRandomNodeId()
|
|
32
33
|
await dhtNode1.storeDataToDht(key, data)
|
|
33
34
|
|
|
34
35
|
const foundData = await remote.findDataViaPeer(key, dhtNode1.getLocalPeerDescriptor())
|
|
@@ -36,17 +37,19 @@ describe('DhtNodeExternalApi', () => {
|
|
|
36
37
|
})
|
|
37
38
|
|
|
38
39
|
it('findData returns empty array if no data found', async () => {
|
|
39
|
-
const foundData = await remote.findDataViaPeer(
|
|
40
|
+
const foundData = await remote.findDataViaPeer(createRandomNodeId(), dhtNode1.getLocalPeerDescriptor())
|
|
40
41
|
expect(foundData).toEqual([])
|
|
41
42
|
})
|
|
42
43
|
|
|
43
44
|
it('external store data happy path', async () => {
|
|
44
|
-
const
|
|
45
|
-
const
|
|
45
|
+
const storedPeerDescriptor = createMockPeerDescriptor()
|
|
46
|
+
const data = Any.pack(storedPeerDescriptor, PeerDescriptor)
|
|
47
|
+
const key = createRandomNodeId()
|
|
46
48
|
|
|
47
49
|
await remote.storeDataViaPeer(key, data, dhtNode1.getLocalPeerDescriptor())
|
|
48
50
|
const foundData = await remote.findDataViaPeer(key, dhtNode1.getLocalPeerDescriptor())
|
|
49
|
-
expect(Any.unpack(foundData[0].data!, PeerDescriptor)).toEqual(
|
|
51
|
+
expect(areEqualPeerDescriptors(Any.unpack(foundData[0].data!, PeerDescriptor), storedPeerDescriptor)).toEqual(true)
|
|
52
|
+
expect(areEqualPeerDescriptors(foundData[0].creator!, remote.getLocalPeerDescriptor())).toEqual(true)
|
|
50
53
|
})
|
|
51
54
|
|
|
52
55
|
})
|