@streamr/dht 100.0.0-testnet-two.1 → 100.0.0-testnet-two.2
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.js +3 -3
- 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/SimulatorConnector.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 +2 -2
- 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 +21 -16
- 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 +12 -12
- 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 +16 -9
- 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 +12 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.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/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 -8
- package/dist/src/dht/store/LocalDataStore.js +18 -24
- 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 +20 -21
- 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 -1
- 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 +4 -7
- package/src/connection/ManagedConnection.ts +2 -2
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnector.ts +2 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -3
- package/src/connection/websocket/WebsocketConnector.ts +5 -6
- package/src/dht/DhtNode.ts +31 -29
- 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 +20 -20
- 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 +32 -11
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +14 -14
- 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/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +25 -33
- package/src/dht/store/StoreManager.ts +25 -29
- 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 -4
- 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 +25 -23
- 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 +37 -29
- 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
|
@@ -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
|
|
|
@@ -5,12 +5,12 @@ import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/Dh
|
|
|
5
5
|
import { createMockConnectionDhtNode, waitNodesReadyForTesting } from '../utils/utils'
|
|
6
6
|
import { execSync } from 'child_process'
|
|
7
7
|
import fs from 'fs'
|
|
8
|
-
import { Logger
|
|
8
|
+
import { Logger } from '@streamr/utils'
|
|
9
9
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
10
10
|
import { getNodeIdFromPeerDescriptor, keyFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
11
11
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
12
12
|
import { Contact } from '../../src/dht/contact/Contact'
|
|
13
|
-
import {
|
|
13
|
+
import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../src/identifiers'
|
|
14
14
|
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
15
15
|
|
|
16
16
|
const logger = new Logger(module)
|
|
@@ -27,7 +27,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
27
27
|
let nodes: DhtNode[]
|
|
28
28
|
let entrypointDescriptor: PeerDescriptor
|
|
29
29
|
const simulator = new Simulator(LatencyType.FIXED, 20)
|
|
30
|
-
const nodesById: Map<
|
|
30
|
+
const nodesById: Map<DhtAddress, DhtNode> = new Map()
|
|
31
31
|
|
|
32
32
|
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
33
33
|
console.log('ground truth data does not exist yet, generating..')
|
|
@@ -43,12 +43,12 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
43
43
|
beforeEach(async () => {
|
|
44
44
|
nodes = []
|
|
45
45
|
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
46
|
-
Uint8Array.from(dhtIds[0].data), K, MAX_CONNECTIONS)
|
|
46
|
+
getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), K, MAX_CONNECTIONS)
|
|
47
47
|
nodes.push(entryPoint)
|
|
48
48
|
nodesById.set(entryPoint.getNodeId(), entryPoint)
|
|
49
49
|
|
|
50
50
|
entrypointDescriptor = {
|
|
51
|
-
nodeId:
|
|
51
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
52
52
|
type: NodeType.NODEJS
|
|
53
53
|
}
|
|
54
54
|
|
|
@@ -56,7 +56,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
56
56
|
|
|
57
57
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
58
58
|
const node = await createMockConnectionDhtNode(simulator,
|
|
59
|
-
Uint8Array.from(dhtIds[i].data), K, MAX_CONNECTIONS)
|
|
59
|
+
getDhtAddressFromRaw(Uint8Array.from(dhtIds[i].data)), K, MAX_CONNECTIONS)
|
|
60
60
|
nodesById.set(node.getNodeId(), node)
|
|
61
61
|
nodes.push(node)
|
|
62
62
|
}
|
|
@@ -74,13 +74,13 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
74
74
|
})
|
|
75
75
|
|
|
76
76
|
it('Data replicates to the closest node no matter where it is stored', async () => {
|
|
77
|
-
const dataKey = PeerID.fromString('3232323e12r31r3')
|
|
78
|
-
const data = createMockDataEntry({ key: dataKey
|
|
77
|
+
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
78
|
+
const data = createMockDataEntry({ key: dataKey })
|
|
79
79
|
|
|
80
80
|
// calculate offline which node is closest to the data
|
|
81
81
|
|
|
82
82
|
const sortedList = new SortedContactList<Contact>({
|
|
83
|
-
referenceId: dataKey
|
|
83
|
+
referenceId: dataKey,
|
|
84
84
|
maxSize: 10000,
|
|
85
85
|
allowToContainReferenceId: true,
|
|
86
86
|
emitEvents: false
|
|
@@ -103,7 +103,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
103
103
|
await nodes[0].joinDht([entrypointDescriptor])
|
|
104
104
|
|
|
105
105
|
logger.info('storing data to node 0')
|
|
106
|
-
const successfulStorers = await nodes[0].storeDataToDht(dataKey
|
|
106
|
+
const successfulStorers = await nodes[0].storeDataToDht(dataKey, data.data!)
|
|
107
107
|
expect(successfulStorers.length).toBe(1)
|
|
108
108
|
logger.info('data successfully stored to node 0')
|
|
109
109
|
|
|
@@ -114,7 +114,8 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
114
114
|
let hasDataMarker = ''
|
|
115
115
|
|
|
116
116
|
// @ts-expect-error private field
|
|
117
|
-
|
|
117
|
+
const store = node.localDataStore
|
|
118
|
+
if (store.getEntries(dataKey)) {
|
|
118
119
|
hasDataMarker = '<-'
|
|
119
120
|
}
|
|
120
121
|
|
|
@@ -142,7 +143,8 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
142
143
|
let hasDataMarker = ''
|
|
143
144
|
|
|
144
145
|
// @ts-expect-error private field
|
|
145
|
-
|
|
146
|
+
const store = node.localDataStore
|
|
147
|
+
if (store.getEntries(dataKey)) {
|
|
146
148
|
hasDataMarker = '<-'
|
|
147
149
|
}
|
|
148
150
|
|
|
@@ -152,12 +154,13 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
152
154
|
const closestNode = nodesById.get(getNodeIdFromPeerDescriptor(closest[0].getPeerDescriptor()))!
|
|
153
155
|
|
|
154
156
|
// @ts-expect-error private field
|
|
155
|
-
|
|
157
|
+
const store = closestNode.localDataStore
|
|
158
|
+
expect(store.getEntries(dataKey).size).toBeGreaterThanOrEqual(1)
|
|
156
159
|
}, 180000)
|
|
157
160
|
|
|
158
161
|
it('Data replicates to the last remaining node if all other nodes leave gracefully', async () => {
|
|
159
|
-
const dataKey = PeerID.fromString('3232323e12r31r3')
|
|
160
|
-
const data = createMockDataEntry({ key: dataKey
|
|
162
|
+
const dataKey = getDhtAddressFromRaw(PeerID.fromString('3232323e12r31r3').value)
|
|
163
|
+
const data = createMockDataEntry({ key: dataKey })
|
|
161
164
|
|
|
162
165
|
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
163
166
|
await Promise.all(
|
|
@@ -173,7 +176,7 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
173
176
|
const randomIndex = Math.floor(Math.random() * nodes.length)
|
|
174
177
|
logger.info('storing data to a random node: ' + randomIndex)
|
|
175
178
|
|
|
176
|
-
const successfulStorers = await nodes[randomIndex].storeDataToDht(dataKey
|
|
179
|
+
const successfulStorers = await nodes[randomIndex].storeDataToDht(dataKey, data.data!)
|
|
177
180
|
|
|
178
181
|
logger.info('data successfully stored to ' + successfulStorers + ' nodes')
|
|
179
182
|
|
|
@@ -187,10 +190,10 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
187
190
|
const index = Math.floor(Math.random() * randomIndices.length)
|
|
188
191
|
const nodeIndex = randomIndices[index]
|
|
189
192
|
randomIndices.splice(index, 1)
|
|
190
|
-
|
|
193
|
+
// @ts-expect-error private field
|
|
194
|
+
const store = nodes[nodeIndex].localDataStore
|
|
191
195
|
logger.info('Stopping node ' + nodeIndex + ' ' +
|
|
192
|
-
|
|
193
|
-
(nodes[nodeIndex].localDataStore.getEntries(dataKey.value) ? ', has data' : ' does not have data'))
|
|
196
|
+
(store.getEntries(dataKey) ? ', has data' : ' does not have data'))
|
|
194
197
|
|
|
195
198
|
await nodes[nodeIndex].stop()
|
|
196
199
|
}
|
|
@@ -198,10 +201,9 @@ describe('Replicate data from node to node in DHT', () => {
|
|
|
198
201
|
logger.info('after random graceful leaving, node ' + randomIndices[0] + ' is left')
|
|
199
202
|
|
|
200
203
|
// @ts-expect-error private field
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
expect(nodes[randomIndices[0]].localDataStore.getEntries(dataKey.value).size).toBeGreaterThanOrEqual(1)
|
|
204
|
+
const firstStore = nodes[randomIndices[0]].localDataStore
|
|
205
|
+
logger.info('data of ' + randomIndices[0] + ' was ' + firstStore.getEntries(dataKey))
|
|
206
|
+
expect(firstStore.getEntries(dataKey).size).toBeGreaterThanOrEqual(1)
|
|
205
207
|
|
|
206
208
|
}, 180000)
|
|
207
209
|
})
|
|
@@ -1,21 +1,20 @@
|
|
|
1
1
|
import { DhtNode, Events as DhtNodeEvents } from '../../src/dht/DhtNode'
|
|
2
2
|
import { Message, MessageType, NodeType, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
4
|
-
import { Logger,
|
|
4
|
+
import { Logger, runAndWaitForEvents3, waitForCondition } from '@streamr/utils'
|
|
5
5
|
import { createMockConnectionDhtNode, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
6
6
|
import { PeerID, PeerIDKey } from '../../src/helpers/PeerID'
|
|
7
7
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
8
8
|
import { v4 } from 'uuid'
|
|
9
9
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
10
10
|
import { RoutingMode } from '../../src/dht/routing/RoutingSession'
|
|
11
|
-
import {
|
|
12
|
-
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
11
|
+
import { createRandomDhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../src/identifiers'
|
|
13
12
|
|
|
14
13
|
const logger = new Logger(module)
|
|
15
14
|
|
|
16
15
|
// TODO refactor the test to not to use PeerID
|
|
17
16
|
const getPeerId = (node: DhtNode) => {
|
|
18
|
-
return PeerID.fromValue(
|
|
17
|
+
return PeerID.fromValue(getRawFromDhtAddress(node.getNodeId()))
|
|
19
18
|
}
|
|
20
19
|
|
|
21
20
|
const NUM_NODES = 30
|
|
@@ -33,18 +32,18 @@ describe('Route Message With Mock Connections', () => {
|
|
|
33
32
|
beforeEach(async () => {
|
|
34
33
|
routerNodes = []
|
|
35
34
|
simulator = new Simulator()
|
|
36
|
-
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
35
|
+
entryPoint = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
37
36
|
|
|
38
37
|
entryPointDescriptor = {
|
|
39
|
-
nodeId:
|
|
38
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
40
39
|
type: NodeType.NODEJS
|
|
41
40
|
}
|
|
42
41
|
|
|
43
|
-
sourceNode = await createMockConnectionDhtNode(simulator,
|
|
44
|
-
destinationNode = await createMockConnectionDhtNode(simulator,
|
|
42
|
+
sourceNode = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
43
|
+
destinationNode = await createMockConnectionDhtNode(simulator, createRandomDhtAddress())
|
|
45
44
|
|
|
46
45
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
47
|
-
const node = await createMockConnectionDhtNode(simulator, PeerID.fromString(`${i}`).value)
|
|
46
|
+
const node = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(PeerID.fromString(`${i}`).value))
|
|
48
47
|
routerNodes.push(node)
|
|
49
48
|
}
|
|
50
49
|
|
|
@@ -157,7 +156,7 @@ describe('Route Message With Mock Connections', () => {
|
|
|
157
156
|
await Promise.all(
|
|
158
157
|
routerNodes.map(async (node) =>
|
|
159
158
|
Promise.all(routerNodes.map(async (receiver) => {
|
|
160
|
-
if (
|
|
159
|
+
if (node.getNodeId() !== receiver.getNodeId()) {
|
|
161
160
|
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
162
161
|
const message: Message = {
|
|
163
162
|
serviceId: 'nonexisting_service',
|
|
@@ -25,7 +25,7 @@ describe('RemoteRouter', () => {
|
|
|
25
25
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
26
26
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
27
27
|
})
|
|
28
|
-
remoteRouter = new RouterRpcRemote(clientPeerDescriptor, serverPeerDescriptor,
|
|
28
|
+
remoteRouter = new RouterRpcRemote(clientPeerDescriptor, serverPeerDescriptor, clientRpcCommunicator, RouterRpcClient)
|
|
29
29
|
})
|
|
30
30
|
|
|
31
31
|
it('routeMessage happy path', async () => {
|
|
@@ -3,9 +3,9 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
3
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
4
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
5
|
import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
6
|
-
import { Logger
|
|
6
|
+
import { Logger } from '@streamr/utils'
|
|
7
7
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
8
|
-
import {
|
|
8
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
9
9
|
|
|
10
10
|
const logger = new Logger(module)
|
|
11
11
|
|
|
@@ -23,11 +23,11 @@ describe('Scaling down a Dht network', () => {
|
|
|
23
23
|
beforeEach(async () => {
|
|
24
24
|
nodes = []
|
|
25
25
|
entryPoint = await createMockConnectionDhtNode(simulator,
|
|
26
|
-
|
|
26
|
+
createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
27
27
|
nodes.push(entryPoint)
|
|
28
28
|
|
|
29
29
|
entrypointDescriptor = {
|
|
30
|
-
nodeId:
|
|
30
|
+
nodeId: getRawFromDhtAddress(entryPoint.getNodeId()),
|
|
31
31
|
type: NodeType.NODEJS,
|
|
32
32
|
region: getRandomRegion()
|
|
33
33
|
}
|