@streamr/dht 100.0.0-testnet-two.1 → 100.0.0-testnet-two.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +5 -5
- package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionManager.d.ts +5 -4
- package/dist/src/connection/ConnectionManager.js +32 -36
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +21 -22
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +4 -3
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +11 -8
- 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.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +6 -5
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -8
- package/dist/src/dht/DhtNode.js +26 -22
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
- package/dist/src/dht/DhtNodeRpcRemote.js +9 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +9 -9
- package/dist/src/dht/PeerManager.js +35 -30
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +2 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +1 -4
- package/dist/src/dht/contact/RpcRemote.js +1 -5
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +5 -5
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -2
- package/dist/src/dht/discovery/DiscoverySession.js +9 -9
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +18 -10
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +15 -14
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +6 -6
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -2
- package/dist/src/dht/routing/Router.js +2 -2
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +3 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +4 -2
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
- package/dist/src/dht/routing/RoutingSession.js +4 -4
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +6 -9
- package/dist/src/dht/store/LocalDataStore.js +27 -32
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +26 -23
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +2 -1
- package/dist/src/dht/store/StoreRpcLocal.js +10 -8
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js +6 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +2 -2
- package/dist/src/helpers/PeerID.js +3 -3
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -2
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/identifiers.d.ts +6 -0
- package/dist/src/identifiers.js +23 -0
- package/dist/src/identifiers.js.map +1 -0
- package/package.json +5 -5
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +3 -3
- package/src/connection/ConnectionManager.ts +36 -46
- package/src/connection/ManagedConnection.ts +2 -2
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnection.ts +21 -23
- package/src/connection/simulator/SimulatorConnector.ts +6 -5
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/NodeWebrtcConnection.ts +11 -10
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -3
- package/src/connection/websocket/WebsocketConnector.ts +9 -9
- package/src/dht/DhtNode.ts +36 -35
- package/src/dht/DhtNodeRpcLocal.ts +3 -2
- package/src/dht/DhtNodeRpcRemote.ts +14 -12
- package/src/dht/ExternalApiRpcLocal.ts +15 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -4
- package/src/dht/PeerManager.ts +43 -38
- package/src/dht/contact/Contact.ts +2 -2
- package/src/dht/contact/ContactList.ts +7 -7
- package/src/dht/contact/RandomContactList.ts +6 -6
- package/src/dht/contact/RpcRemote.ts +0 -8
- package/src/dht/contact/SortedContactList.ts +22 -22
- package/src/dht/discovery/DiscoverySession.ts +16 -14
- package/src/dht/discovery/PeerDiscovery.ts +34 -12
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +17 -17
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +2 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +11 -11
- package/src/dht/routing/Router.ts +5 -5
- package/src/dht/routing/RouterRpcLocal.ts +3 -3
- package/src/dht/routing/RouterRpcRemote.ts +4 -4
- package/src/dht/routing/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +31 -40
- package/src/dht/store/StoreManager.ts +31 -31
- package/src/dht/store/StoreRpcLocal.ts +11 -9
- package/src/exports.ts +2 -0
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/PeerID.ts +4 -4
- package/src/helpers/peerIdFromPeerDescriptor.ts +4 -6
- package/src/identifiers.ts +20 -0
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +4 -3
- package/test/benchmark/KademliaCorrectness.test.ts +4 -4
- package/test/benchmark/SortedContactListBenchmark.test.ts +15 -14
- package/test/benchmark/kademlia-simulation/Contact.ts +7 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +10 -11
- package/test/data/generateGroundTruthData.ts +5 -4
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +3 -2
- package/test/integration/ConnectionManager.test.ts +3 -3
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -1
- package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +3 -2
- 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 +6 -5
- package/test/integration/ReplicateData.test.ts +38 -30
- package/test/integration/RouteMessage.test.ts +9 -10
- package/test/integration/RouterRpcRemote.test.ts +1 -1
- package/test/integration/ScaleDownDht.test.ts +4 -4
- package/test/integration/SimultaneousConnections.test.ts +7 -14
- package/test/integration/Store.test.ts +17 -7
- package/test/integration/StoreAndDelete.test.ts +11 -10
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -6
- package/test/integration/StoreRpcRemote.test.ts +3 -5
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/LocalDataStore.test.ts +41 -41
- package/test/unit/PeerManager.test.ts +7 -8
- package/test/unit/RandomContactList.test.ts +3 -3
- package/test/unit/RecursiveOperationManager.test.ts +2 -1
- package/test/unit/RecursiveOperationSession.test.ts +2 -3
- package/test/unit/Router.test.ts +2 -2
- package/test/unit/RoutingSession.test.ts +2 -2
- package/test/unit/SortedContactList.test.ts +6 -6
- package/test/unit/StoreManager.test.ts +26 -23
- package/test/utils/customMatchers.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +8 -6
- package/test/utils/utils.ts +4 -4
- package/dist/src/helpers/nodeId.d.ts +0 -6
- package/dist/src/helpers/nodeId.js +0 -31
- package/dist/src/helpers/nodeId.js.map +0 -1
- package/src/helpers/nodeId.ts +0 -28
|
@@ -3,19 +3,20 @@
|
|
|
3
3
|
import KBucket from 'k-bucket'
|
|
4
4
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
5
5
|
import crypto from 'crypto'
|
|
6
|
-
import {
|
|
6
|
+
import { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
7
7
|
|
|
8
8
|
const NUM_ADDS = 1000
|
|
9
|
+
|
|
9
10
|
interface Item {
|
|
10
|
-
id:
|
|
11
|
+
id: DhtAddressRaw
|
|
11
12
|
vectorClock: number
|
|
12
|
-
getNodeId: () =>
|
|
13
|
+
getNodeId: () => DhtAddress
|
|
13
14
|
}
|
|
14
15
|
|
|
15
16
|
const createRandomItem = (index: number): Item => {
|
|
16
17
|
const rand = new Uint8Array(crypto.randomBytes(20))
|
|
17
18
|
return {
|
|
18
|
-
getNodeId: () =>
|
|
19
|
+
getNodeId: () => getDhtAddressFromRaw(rand),
|
|
19
20
|
id: rand,
|
|
20
21
|
vectorClock: index
|
|
21
22
|
}
|
|
@@ -37,7 +38,7 @@ describe('SortedContactListBenchmark', () => {
|
|
|
37
38
|
randomIds.push(createRandomItem(i))
|
|
38
39
|
}
|
|
39
40
|
const list = new SortedContactList({
|
|
40
|
-
referenceId:
|
|
41
|
+
referenceId: getDhtAddressFromRaw(crypto.randomBytes(20)),
|
|
41
42
|
allowToContainReferenceId: true,
|
|
42
43
|
emitEvents: true
|
|
43
44
|
})
|
|
@@ -49,7 +50,7 @@ describe('SortedContactListBenchmark', () => {
|
|
|
49
50
|
console.timeEnd('SortedContactList.addContact() with emitEvents=true')
|
|
50
51
|
|
|
51
52
|
const list2 = new SortedContactList({
|
|
52
|
-
referenceId:
|
|
53
|
+
referenceId: getDhtAddressFromRaw(crypto.randomBytes(20)),
|
|
53
54
|
allowToContainReferenceId: true,
|
|
54
55
|
emitEvents: false
|
|
55
56
|
})
|
|
@@ -83,13 +84,13 @@ describe('SortedContactListBenchmark', () => {
|
|
|
83
84
|
console.time('SortedContactList.getClosestContacts() with emitEvents=true')
|
|
84
85
|
for (let i = 0; i < NUM_ADDS; i++) {
|
|
85
86
|
const closest = new SortedContactList<Item>({
|
|
86
|
-
referenceId:
|
|
87
|
+
referenceId: getDhtAddressFromRaw(crypto.randomBytes(20)),
|
|
87
88
|
allowToContainReferenceId: true,
|
|
88
89
|
emitEvents: true
|
|
89
90
|
})
|
|
90
91
|
|
|
91
92
|
const arrayFromBucket = kBucket.toArray()
|
|
92
|
-
arrayFromBucket.
|
|
93
|
+
arrayFromBucket.forEach((contact) => closest.addContact(contact))
|
|
93
94
|
closest.getClosestContacts(20)
|
|
94
95
|
}
|
|
95
96
|
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=true')
|
|
@@ -97,13 +98,13 @@ describe('SortedContactListBenchmark', () => {
|
|
|
97
98
|
console.time('SortedContactList.getClosestContacts() with emitEvents=false')
|
|
98
99
|
for (let i = 0; i < NUM_ADDS; i++) {
|
|
99
100
|
const closest = new SortedContactList<Item>({
|
|
100
|
-
referenceId:
|
|
101
|
+
referenceId: getDhtAddressFromRaw(crypto.randomBytes(20)),
|
|
101
102
|
allowToContainReferenceId: true,
|
|
102
103
|
emitEvents: false
|
|
103
104
|
})
|
|
104
105
|
|
|
105
106
|
const arrayFromBucket = kBucket.toArray()
|
|
106
|
-
arrayFromBucket.
|
|
107
|
+
arrayFromBucket.forEach((contact) => closest.addContact(contact))
|
|
107
108
|
closest.getClosestContacts(20)
|
|
108
109
|
}
|
|
109
110
|
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false')
|
|
@@ -111,13 +112,13 @@ describe('SortedContactListBenchmark', () => {
|
|
|
111
112
|
console.time('SortedContactList.getClosestContacts() with emitEvents=false and lodash')
|
|
112
113
|
for (let i = 0; i < NUM_ADDS; i++) {
|
|
113
114
|
const closest = new SortedContactList<Item>({
|
|
114
|
-
referenceId:
|
|
115
|
+
referenceId: getDhtAddressFromRaw(crypto.randomBytes(20)),
|
|
115
116
|
allowToContainReferenceId: true,
|
|
116
117
|
emitEvents: false
|
|
117
118
|
})
|
|
118
119
|
|
|
119
120
|
const arrayFromBucket = kBucket.toArray()
|
|
120
|
-
arrayFromBucket.
|
|
121
|
+
arrayFromBucket.forEach((contact) => closest.addContact(contact))
|
|
121
122
|
closest.getClosestContacts(20)
|
|
122
123
|
}
|
|
123
124
|
console.timeEnd('SortedContactList.getClosestContacts() with emitEvents=false and lodash')
|
|
@@ -125,7 +126,7 @@ describe('SortedContactListBenchmark', () => {
|
|
|
125
126
|
console.time('SortedContactList.getClosestContacts() with emitEvents=false and addContacts()')
|
|
126
127
|
for (let i = 0; i < NUM_ADDS; i++) {
|
|
127
128
|
const closest = new SortedContactList<Item>({
|
|
128
|
-
referenceId:
|
|
129
|
+
referenceId: getDhtAddressFromRaw(crypto.randomBytes(20)),
|
|
129
130
|
allowToContainReferenceId: true,
|
|
130
131
|
emitEvents: false
|
|
131
132
|
})
|
|
@@ -141,7 +142,7 @@ describe('SortedContactListBenchmark', () => {
|
|
|
141
142
|
for (let i = 0; i < NUM_ADDS; i++) {
|
|
142
143
|
const bucket2 = new KBucket<Item>({ localNodeId: crypto.randomBytes(20) })
|
|
143
144
|
|
|
144
|
-
shuffled.
|
|
145
|
+
shuffled.forEach((contact) => bucket2.add(contact))
|
|
145
146
|
bucket2.closest(crypto.randomBytes(20), 20)
|
|
146
147
|
}
|
|
147
148
|
console.timeEnd('kbucket add and closest')
|
|
@@ -1,32 +1,31 @@
|
|
|
1
1
|
import type { SimulationNode } from './SimulationNode'
|
|
2
2
|
import { NodeType, PeerDescriptor } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import {
|
|
4
|
-
import { hexToBinary } from '@streamr/utils'
|
|
3
|
+
import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
5
4
|
|
|
6
5
|
export class Contact {
|
|
7
6
|
private static counter = 0
|
|
8
7
|
|
|
9
|
-
public ownId:
|
|
10
|
-
public id:
|
|
8
|
+
public ownId: DhtAddress
|
|
9
|
+
public id: DhtAddressRaw
|
|
11
10
|
public vectorClock = 0
|
|
12
11
|
public dhtNode: SimulationNode | undefined
|
|
13
12
|
|
|
14
|
-
constructor(ownId:
|
|
13
|
+
constructor(ownId: DhtAddress, dhtNode?: SimulationNode) {
|
|
15
14
|
this.ownId = ownId
|
|
16
15
|
this.vectorClock = Contact.counter++
|
|
17
16
|
this.dhtNode = dhtNode
|
|
18
|
-
this.id =
|
|
17
|
+
this.id = getRawFromDhtAddress(ownId)
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
getPeerDescriptor(): PeerDescriptor {
|
|
22
21
|
const peerDescriptor: PeerDescriptor = {
|
|
23
|
-
nodeId:
|
|
22
|
+
nodeId: getRawFromDhtAddress(this.ownId),
|
|
24
23
|
type: NodeType.NODEJS
|
|
25
24
|
}
|
|
26
25
|
return peerDescriptor
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
getNodeId():
|
|
28
|
+
getNodeId(): DhtAddress {
|
|
30
29
|
return this.ownId
|
|
31
30
|
}
|
|
32
31
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import { SimulationNode } from './SimulationNode'
|
|
4
4
|
import fs from 'fs'
|
|
5
|
-
import {
|
|
5
|
+
import { getDhtAddressFromRaw } from '../../../src/identifiers'
|
|
6
6
|
|
|
7
7
|
export class KademliaSimulation {
|
|
8
8
|
|
|
@@ -25,7 +25,7 @@ export class KademliaSimulation {
|
|
|
25
25
|
|
|
26
26
|
public run(): void {
|
|
27
27
|
for (let i = 0; i < KademliaSimulation.NUM_NODES; i++) {
|
|
28
|
-
const node = new SimulationNode(
|
|
28
|
+
const node = new SimulationNode(getDhtAddressFromRaw(Buffer.from(this.dhtIds[i].data.slice(0, KademliaSimulation.ID_LENGTH))))
|
|
29
29
|
this.nodeNamesById[JSON.stringify(node.getContact().id)] = i
|
|
30
30
|
this.nodes.push(node)
|
|
31
31
|
node.joinDht(this.nodes[0])
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import KBucket from 'k-bucket'
|
|
2
2
|
import { Contact } from './Contact'
|
|
3
3
|
import { SortedContactList } from '../../../src/dht/contact/SortedContactList'
|
|
4
|
-
import {
|
|
5
|
-
import { hexToBinary } from '@streamr/utils'
|
|
4
|
+
import { DhtAddress, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
6
5
|
|
|
7
6
|
export class SimulationNode {
|
|
8
7
|
|
|
@@ -17,13 +16,13 @@ export class SimulationNode {
|
|
|
17
16
|
private numberOfOutgoingRpcCalls = 0
|
|
18
17
|
|
|
19
18
|
private neighborList: SortedContactList<Contact>
|
|
20
|
-
private ownId:
|
|
19
|
+
private ownId: DhtAddress
|
|
21
20
|
|
|
22
|
-
constructor(ownId:
|
|
21
|
+
constructor(ownId: DhtAddress) {
|
|
23
22
|
this.ownId = ownId
|
|
24
23
|
this.ownContact = new Contact(this.ownId, this)
|
|
25
24
|
this.bucket = new KBucket({
|
|
26
|
-
localNodeId:
|
|
25
|
+
localNodeId: getRawFromDhtAddress(this.ownId),
|
|
27
26
|
numberOfNodesPerKBucket: this.numberOfNodesPerKBucket
|
|
28
27
|
})
|
|
29
28
|
|
|
@@ -58,9 +57,9 @@ export class SimulationNode {
|
|
|
58
57
|
|
|
59
58
|
// RPC call
|
|
60
59
|
|
|
61
|
-
public getClosestNodesTo(id:
|
|
60
|
+
public getClosestNodesTo(id: DhtAddress, caller: SimulationNode): Contact[] {
|
|
62
61
|
this.numberOfIncomingRpcCalls++
|
|
63
|
-
const idValue =
|
|
62
|
+
const idValue = getRawFromDhtAddress(id)
|
|
64
63
|
const ret = this.bucket.closest(idValue)
|
|
65
64
|
if (!this.bucket.get(idValue)) {
|
|
66
65
|
const contact = new Contact(id, caller)
|
|
@@ -86,12 +85,12 @@ export class SimulationNode {
|
|
|
86
85
|
}
|
|
87
86
|
|
|
88
87
|
public joinDht(entryPoint: SimulationNode): void {
|
|
89
|
-
if (
|
|
88
|
+
if (entryPoint.getContact().getNodeId() === this.ownId) {
|
|
90
89
|
return
|
|
91
90
|
}
|
|
92
91
|
|
|
93
92
|
this.bucket.add(entryPoint.getContact())
|
|
94
|
-
const closest = this.bucket.closest(
|
|
93
|
+
const closest = this.bucket.closest(getRawFromDhtAddress(this.ownId), this.ALPHA)
|
|
95
94
|
|
|
96
95
|
this.neighborList.addContacts(closest)
|
|
97
96
|
|
|
@@ -105,7 +104,7 @@ export class SimulationNode {
|
|
|
105
104
|
|
|
106
105
|
this.findMoreContacts(uncontacted, this.neighborList)
|
|
107
106
|
|
|
108
|
-
if (
|
|
107
|
+
if (oldClosestContactId === this.neighborList.getClosestContactId()) {
|
|
109
108
|
uncontacted = this.neighborList.getUncontactedContacts(this.K)
|
|
110
109
|
if (uncontacted.length === 0) {
|
|
111
110
|
return
|
|
@@ -116,7 +115,7 @@ export class SimulationNode {
|
|
|
116
115
|
this.findMoreContacts(uncontacted, this.neighborList)
|
|
117
116
|
|
|
118
117
|
if (this.neighborList.getActiveContacts().length >= this.K ||
|
|
119
|
-
|
|
118
|
+
(oldClosestContactId === this.neighborList.getClosestContactId())) {
|
|
120
119
|
return
|
|
121
120
|
}
|
|
122
121
|
uncontacted = this.neighborList.getUncontactedContacts(this.ALPHA)
|
|
@@ -1,16 +1,17 @@
|
|
|
1
1
|
import fs from 'fs'
|
|
2
2
|
import crypto from 'crypto'
|
|
3
3
|
import KBucket from 'k-bucket'
|
|
4
|
+
import { DhtAddressRaw } from '../../src/identifiers'
|
|
4
5
|
|
|
5
6
|
const ID_LENGTH = 8
|
|
6
7
|
const NUM_NODES = 2000
|
|
7
8
|
const NUM_NEAREST = 10
|
|
8
9
|
|
|
9
|
-
const generateId = function():
|
|
10
|
+
const generateId = function(): DhtAddressRaw {
|
|
10
11
|
return crypto.randomBytes(ID_LENGTH)
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
const findNNearestNeighbors = function(ownIndex: number, ownId:
|
|
14
|
+
const findNNearestNeighbors = function(ownIndex: number, ownId: DhtAddressRaw, nodes: Array<DhtAddressRaw>, n: number): Array<number> {
|
|
14
15
|
const retIndex: Array<number> = []
|
|
15
16
|
|
|
16
17
|
for (let i = 0; i < n; i++) {
|
|
@@ -37,7 +38,7 @@ const neighborWriter = fs.createWriteStream('orderedneighbors.json', {})
|
|
|
37
38
|
|
|
38
39
|
neighborWriter.write('{\n')
|
|
39
40
|
|
|
40
|
-
const nodes: Array<
|
|
41
|
+
const nodes: Array<DhtAddressRaw> = []
|
|
41
42
|
|
|
42
43
|
// generate nodeIds
|
|
43
44
|
|
|
@@ -53,7 +54,7 @@ for (let i = 0; i < NUM_NODES; i++) {
|
|
|
53
54
|
|
|
54
55
|
const neighborIds = findNNearestNeighbors(i, nodes[i], nodes, NUM_NEAREST)
|
|
55
56
|
|
|
56
|
-
const neighborNames: Array<{ name: number, distance: number, id:
|
|
57
|
+
const neighborNames: Array<{ name: number, distance: number, id: DhtAddressRaw }> = []
|
|
57
58
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
58
59
|
for (let j = 0; j < neighborIds.length; j++) {
|
|
59
60
|
neighborNames.push({ name: neighborIds[j], distance: KBucket.distance(nodes[i], nodes[neighborIds[j]]), id: nodes[neighborIds[j]] })
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { binaryToHex } from '@streamr/utils'
|
|
2
1
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
2
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
3
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/exports'
|
|
4
4
|
|
|
5
5
|
describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
6
6
|
|
|
@@ -47,7 +47,7 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
layer1EntryPoint = new DhtNode({
|
|
50
|
-
peerId:
|
|
50
|
+
peerId: getNodeIdFromPeerDescriptor(entrypointDescriptor),
|
|
51
51
|
transport: layer0EntryPoint,
|
|
52
52
|
serviceId: 'layer1'
|
|
53
53
|
})
|
|
@@ -21,7 +21,7 @@ describe('Failed autocertification', () => {
|
|
|
21
21
|
entryPoints: [entryPointPeerDescriptor],
|
|
22
22
|
websocketServerEnableTls: true,
|
|
23
23
|
autoCertifierConfigFile: os.tmpdir() + '/failedAutoCertificationConfigFile.json',
|
|
24
|
-
autoCertifierUrl: 'http://
|
|
24
|
+
autoCertifierUrl: 'http://127.0.0.1:44444'
|
|
25
25
|
})
|
|
26
26
|
|
|
27
27
|
node = new DhtNode({
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import LeakDetector from 'jest-leak-detector'
|
|
2
|
-
import {
|
|
2
|
+
import { waitForCondition } from '@streamr/utils'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
4
|
import { Message, MessageType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
6
6
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/exports'
|
|
7
8
|
|
|
8
9
|
const MESSAGE_ID = 'mock-message-id'
|
|
9
10
|
|
|
@@ -18,7 +19,7 @@ describe('memory leak', () => {
|
|
|
18
19
|
}
|
|
19
20
|
})
|
|
20
21
|
let entryPoint: DhtNode | undefined = new DhtNode({
|
|
21
|
-
peerId:
|
|
22
|
+
peerId: getNodeIdFromPeerDescriptor(entryPointDescriptor),
|
|
22
23
|
websocketHost: entryPointDescriptor.websocket!.host,
|
|
23
24
|
websocketPortRange: {
|
|
24
25
|
min: entryPointDescriptor.websocket!.port,
|
|
@@ -9,7 +9,7 @@ import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/
|
|
|
9
9
|
import { MarkOptional } from 'ts-essentials'
|
|
10
10
|
import { TransportEvents } from '../../src/transport/ITransport'
|
|
11
11
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
|
-
import {
|
|
12
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
13
13
|
|
|
14
14
|
const SERVICE_ID = 'demo'
|
|
15
15
|
|
|
@@ -363,7 +363,7 @@ describe('ConnectionManager', () => {
|
|
|
363
363
|
messageId: '1',
|
|
364
364
|
targetDescriptor: {
|
|
365
365
|
// This is not the correct nodeId of peerDescriptor2
|
|
366
|
-
nodeId:
|
|
366
|
+
nodeId: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
367
367
|
type: NodeType.NODEJS,
|
|
368
368
|
websocket: peerDescriptor2.websocket
|
|
369
369
|
},
|
|
@@ -387,7 +387,7 @@ describe('ConnectionManager', () => {
|
|
|
387
387
|
const connectionManager1 = createConnectionManager({
|
|
388
388
|
transport: mockTransport,
|
|
389
389
|
websocketHost: '127.0.0.1',
|
|
390
|
-
autoCertifierUrl: 'https://
|
|
390
|
+
autoCertifierUrl: 'https://127.0.0.1:12333',
|
|
391
391
|
websocketServerEnableTls: true,
|
|
392
392
|
websocketPortRange: { min: 10004, max: 10004 }
|
|
393
393
|
})
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
5
|
import { createMockConnectionDhtNode, createMockPeerDescriptor } from '../utils/utils'
|
|
5
6
|
|
|
6
7
|
const NUM_OF_NODES_PER_KBUCKET = 8
|
|
@@ -10,7 +11,7 @@ const runTest = async (latencyType: LatencyType) => {
|
|
|
10
11
|
const entrypointDescriptor = createMockPeerDescriptor({
|
|
11
12
|
region: getRandomRegion()
|
|
12
13
|
})
|
|
13
|
-
const entryPoint = await createMockConnectionDhtNode(simulator, entrypointDescriptor.nodeId, NUM_OF_NODES_PER_KBUCKET)
|
|
14
|
+
const entryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(entrypointDescriptor.nodeId), NUM_OF_NODES_PER_KBUCKET)
|
|
14
15
|
const nodes: DhtNode[] = []
|
|
15
16
|
for (let i = 1; i < 100; i++) {
|
|
16
17
|
const node = await createMockConnectionDhtNode(simulator, undefined, NUM_OF_NODES_PER_KBUCKET)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import {
|
|
3
|
+
import { createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
4
|
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
5
5
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
6
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
@@ -28,22 +28,22 @@ describe('DhtNodeExternalApi', () => {
|
|
|
28
28
|
|
|
29
29
|
it('findData happy path', async () => {
|
|
30
30
|
const entry = createMockDataEntry()
|
|
31
|
-
await dhtNode1.storeDataToDht(entry.key, entry.data!)
|
|
32
|
-
const foundData = await remote.findDataViaPeer(entry.key, dhtNode1.getLocalPeerDescriptor())
|
|
31
|
+
await dhtNode1.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
32
|
+
const foundData = await remote.findDataViaPeer(getDhtAddressFromRaw(entry.key), dhtNode1.getLocalPeerDescriptor())
|
|
33
33
|
expectEqualData(foundData[0], entry)
|
|
34
34
|
})
|
|
35
35
|
|
|
36
36
|
it('findData returns empty array if no data found', async () => {
|
|
37
|
-
const foundData = await remote.findDataViaPeer(
|
|
37
|
+
const foundData = await remote.findDataViaPeer(createRandomDhtAddress(), dhtNode1.getLocalPeerDescriptor())
|
|
38
38
|
expect(foundData).toEqual([])
|
|
39
39
|
})
|
|
40
40
|
|
|
41
41
|
it('external store data happy path', async () => {
|
|
42
42
|
const entry = createMockDataEntry()
|
|
43
|
-
await remote.storeDataViaPeer(entry.key, entry.data!, dhtNode1.getLocalPeerDescriptor())
|
|
44
|
-
const foundData = await remote.findDataViaPeer(entry.key, dhtNode1.getLocalPeerDescriptor())
|
|
43
|
+
await remote.storeDataViaPeer(getDhtAddressFromRaw(entry.key), entry.data!, dhtNode1.getLocalPeerDescriptor())
|
|
44
|
+
const foundData = await remote.findDataViaPeer(getDhtAddressFromRaw(entry.key), dhtNode1.getLocalPeerDescriptor())
|
|
45
45
|
expectEqualData(foundData[0], entry)
|
|
46
|
-
expect(
|
|
46
|
+
expect(getDhtAddressFromRaw(foundData[0].creator)).toEqual(getNodeIdFromPeerDescriptor(remote.getLocalPeerDescriptor()))
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
})
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
PingResponse
|
|
9
9
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
10
10
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
11
|
+
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
11
12
|
|
|
12
13
|
const SERVICE_ID = 'test'
|
|
13
14
|
|
|
@@ -45,7 +46,7 @@ describe('DhtNodeRpcRemote', () => {
|
|
|
45
46
|
})
|
|
46
47
|
|
|
47
48
|
it('getClosestPeers happy path', async () => {
|
|
48
|
-
const neighbors = await rpcRemote.getClosestPeers(clientPeerDescriptor
|
|
49
|
+
const neighbors = await rpcRemote.getClosestPeers(getNodeIdFromPeerDescriptor(clientPeerDescriptor))
|
|
49
50
|
expect(neighbors.length).toEqual(createMockPeers().length)
|
|
50
51
|
})
|
|
51
52
|
|
|
@@ -57,7 +58,7 @@ describe('DhtNodeRpcRemote', () => {
|
|
|
57
58
|
|
|
58
59
|
it('getClosestPeers error path', async () => {
|
|
59
60
|
serverRpcCommunicator.registerRpcMethod(ClosestPeersRequest, ClosestPeersResponse, 'getClosestPeers', mockDhtRpc.throwGetClosestPeersError)
|
|
60
|
-
await expect(rpcRemote.getClosestPeers(clientPeerDescriptor
|
|
61
|
+
await expect(rpcRemote.getClosestPeers(getNodeIdFromPeerDescriptor(clientPeerDescriptor)))
|
|
61
62
|
.rejects.toThrow('Closest peers error')
|
|
62
63
|
})
|
|
63
64
|
|
|
@@ -4,7 +4,7 @@ import { PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht
|
|
|
4
4
|
import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
5
5
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
6
6
|
import { peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
7
|
-
import {
|
|
7
|
+
import { getDhtAddressFromRaw, getRawFromDhtAddress } from '../../src/identifiers'
|
|
8
8
|
|
|
9
9
|
const NUM_NODES = 100
|
|
10
10
|
const K = 2
|
|
@@ -38,8 +38,8 @@ describe('Find correctness', () => {
|
|
|
38
38
|
})
|
|
39
39
|
|
|
40
40
|
it('Entrypoint can find a node from the network (exact match)', async () => {
|
|
41
|
-
const targetId =
|
|
42
|
-
const results = await entryPoint.executeRecursiveOperation(targetId, RecursiveOperation.FIND_NODE)
|
|
41
|
+
const targetId = getRawFromDhtAddress(nodes[45].getNodeId())
|
|
42
|
+
const results = await entryPoint.executeRecursiveOperation(getDhtAddressFromRaw(targetId), RecursiveOperation.FIND_NODE)
|
|
43
43
|
expect(results.closestNodes.length).toBeGreaterThanOrEqual(5)
|
|
44
44
|
expect(PeerID.fromValue(targetId).equals(peerIdFromPeerDescriptor(results.closestNodes[0])))
|
|
45
45
|
}, 30000)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
3
4
|
import { createMockConnectionDhtNode, createMockConnectionLayer1Node, createMockPeerDescriptor } from '../utils/utils'
|
|
4
|
-
import { areEqualNodeIds } from '../../src/helpers/nodeId'
|
|
5
5
|
|
|
6
6
|
const NODE_COUNT = 48
|
|
7
7
|
const NUM_OF_NODES_PER_KBUCKET = 8
|
|
@@ -16,7 +16,7 @@ describe('Layer1', () => {
|
|
|
16
16
|
|
|
17
17
|
beforeEach(async () => {
|
|
18
18
|
simulator = new Simulator()
|
|
19
|
-
layer0EntryPoint = await createMockConnectionDhtNode(simulator, entryPoint0Descriptor.nodeId)
|
|
19
|
+
layer0EntryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(entryPoint0Descriptor.nodeId))
|
|
20
20
|
await layer0EntryPoint.joinDht([entryPoint0Descriptor])
|
|
21
21
|
|
|
22
22
|
nodes = []
|
|
@@ -62,7 +62,7 @@ describe('Layer1', () => {
|
|
|
62
62
|
for (let i = 0; i < NODE_COUNT; i++) {
|
|
63
63
|
const layer0Node = nodes[i]
|
|
64
64
|
const layer1Node = layer1Nodes[i]
|
|
65
|
-
expect(
|
|
65
|
+
expect(layer1Node.getNodeId()).toEqual(layer0Node.getNodeId())
|
|
66
66
|
expect(layer1Node.getNumberOfConnections()).toEqual(layer0Node.getNumberOfConnections())
|
|
67
67
|
expect(layer1Node.getNumberOfNeighbors()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
68
68
|
expect(layer1Node.getAllConnectionPeerDescriptors()).toEqual(layer0Node.getAllConnectionPeerDescriptors())
|
|
@@ -3,6 +3,7 @@ import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
4
|
import { createMockConnectionDhtNode, createMockConnectionLayer1Node } from '../utils/utils'
|
|
5
5
|
import { PeerID } from '../../src/exports'
|
|
6
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
7
|
|
|
7
8
|
const logger = new Logger(module)
|
|
8
9
|
|
|
@@ -24,11 +25,11 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
|
24
25
|
|
|
25
26
|
beforeEach(async () => {
|
|
26
27
|
|
|
27
|
-
layer0EntryPoint = await createMockConnectionDhtNode(simulator, PeerID.fromString('layer0entrypoint').value)
|
|
28
|
-
layer0Node1 = await createMockConnectionDhtNode(simulator, PeerID.fromString('node1').value)
|
|
29
|
-
layer0Node2 = await createMockConnectionDhtNode(simulator, PeerID.fromString('node2').value)
|
|
30
|
-
layer0Node3 = await createMockConnectionDhtNode(simulator, PeerID.fromString('node3').value)
|
|
31
|
-
layer0Node4 = await createMockConnectionDhtNode(simulator, PeerID.fromString('node4').value)
|
|
28
|
+
layer0EntryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('layer0entrypoint').value))
|
|
29
|
+
layer0Node1 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node1').value))
|
|
30
|
+
layer0Node2 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node2').value))
|
|
31
|
+
layer0Node3 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node3').value))
|
|
32
|
+
layer0Node4 = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString('node4').value))
|
|
32
33
|
|
|
33
34
|
layer1EntryPoint = await createMockConnectionLayer1Node(layer0EntryPoint)
|
|
34
35
|
|