@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
|
@@ -3,11 +3,10 @@ import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
|
3
3
|
import { DefaultConnectorFacade, DefaultConnectorFacadeConfig } from '../../src/connection/ConnectorFacade'
|
|
4
4
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
5
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
|
-
import { Message, MessageType,
|
|
6
|
+
import { Message, MessageType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
7
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
8
8
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
9
9
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
10
|
-
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
11
10
|
import { MockTransport } from '../utils/mock/Transport'
|
|
12
11
|
|
|
13
12
|
const BASE_MESSAGE: Message = {
|
|
@@ -88,27 +87,23 @@ describe('SimultaneousConnections', () => {
|
|
|
88
87
|
let connectionManager1: ConnectionManager
|
|
89
88
|
let connectionManager2: ConnectionManager
|
|
90
89
|
|
|
91
|
-
const wsPeerDescriptor1
|
|
92
|
-
nodeId: createRandomNodeId(),
|
|
93
|
-
type: NodeType.NODEJS,
|
|
90
|
+
const wsPeerDescriptor1 = createMockPeerDescriptor({
|
|
94
91
|
websocket: {
|
|
95
92
|
host: '127.0.0.1',
|
|
96
93
|
port: 43432,
|
|
97
94
|
tls: false
|
|
98
95
|
},
|
|
99
96
|
region: getRandomRegion()
|
|
100
|
-
}
|
|
97
|
+
})
|
|
101
98
|
|
|
102
|
-
const wsPeerDescriptor2
|
|
103
|
-
nodeId: createRandomNodeId(),
|
|
104
|
-
type: NodeType.NODEJS,
|
|
99
|
+
const wsPeerDescriptor2 = createMockPeerDescriptor({
|
|
105
100
|
websocket: {
|
|
106
101
|
host: '127.0.0.1',
|
|
107
102
|
port: 43433,
|
|
108
103
|
tls: false
|
|
109
104
|
},
|
|
110
105
|
region: getRandomRegion()
|
|
111
|
-
}
|
|
106
|
+
})
|
|
112
107
|
|
|
113
108
|
beforeEach(async () => {
|
|
114
109
|
|
|
@@ -176,16 +171,14 @@ describe('SimultaneousConnections', () => {
|
|
|
176
171
|
let connectionManager1: ConnectionManager
|
|
177
172
|
let connectionManager2: ConnectionManager
|
|
178
173
|
|
|
179
|
-
const wsPeerDescriptor1
|
|
180
|
-
nodeId: createRandomNodeId(),
|
|
181
|
-
type: NodeType.NODEJS,
|
|
174
|
+
const wsPeerDescriptor1 = createMockPeerDescriptor({
|
|
182
175
|
websocket: {
|
|
183
176
|
host: '127.0.0.1',
|
|
184
177
|
port: 43432,
|
|
185
178
|
tls: false
|
|
186
179
|
},
|
|
187
180
|
region: getRandomRegion()
|
|
188
|
-
}
|
|
181
|
+
})
|
|
189
182
|
|
|
190
183
|
const wsPeerDescriptor2 = createMockPeerDescriptor({ region: getRandomRegion() })
|
|
191
184
|
|
|
@@ -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 { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
4
|
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
5
5
|
import { PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
@@ -44,17 +44,23 @@ describe('Storing data in DHT', () => {
|
|
|
44
44
|
it('Storing data works', async () => {
|
|
45
45
|
const storingNodeIndex = 34
|
|
46
46
|
const entry = createMockDataEntry()
|
|
47
|
-
const successfulStorers = await nodes[storingNodeIndex].storeDataToDht(
|
|
47
|
+
const successfulStorers = await nodes[storingNodeIndex].storeDataToDht(
|
|
48
|
+
getDhtAddressFromRaw(entry.key),
|
|
49
|
+
entry.data!
|
|
50
|
+
)
|
|
48
51
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
49
52
|
}, 30000)
|
|
50
53
|
|
|
51
54
|
it('Storing and getting data works', async () => {
|
|
52
55
|
const storingNode = getRandomNode()
|
|
53
56
|
const entry = createMockDataEntry()
|
|
54
|
-
const successfulStorers = await storingNode.storeDataToDht(
|
|
57
|
+
const successfulStorers = await storingNode.storeDataToDht(
|
|
58
|
+
getDhtAddressFromRaw(entry.key),
|
|
59
|
+
entry.data!
|
|
60
|
+
)
|
|
55
61
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
56
62
|
const fetchingNode = getRandomNode()
|
|
57
|
-
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
63
|
+
const results = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
58
64
|
results.forEach((result) => {
|
|
59
65
|
expectEqualData(result, entry)
|
|
60
66
|
})
|
|
@@ -64,13 +70,17 @@ describe('Storing data in DHT', () => {
|
|
|
64
70
|
const storingNode = getRandomNode()
|
|
65
71
|
const entry = createMockDataEntry()
|
|
66
72
|
const requestor = createMockPeerDescriptor()
|
|
67
|
-
const successfulStorers = await storingNode.storeDataToDht(
|
|
73
|
+
const successfulStorers = await storingNode.storeDataToDht(
|
|
74
|
+
getDhtAddressFromRaw(entry.key),
|
|
75
|
+
entry.data!,
|
|
76
|
+
getDhtAddressFromRaw(requestor.nodeId)
|
|
77
|
+
)
|
|
68
78
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
69
79
|
const fetchingNode = getRandomNode()
|
|
70
|
-
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
80
|
+
const results = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
71
81
|
results.forEach((result) => {
|
|
72
82
|
expectEqualData(result, entry)
|
|
73
|
-
expect(
|
|
83
|
+
expect(getDhtAddressFromRaw(result.creator)).toEqual(getNodeIdFromPeerDescriptor(requestor))
|
|
74
84
|
})
|
|
75
85
|
}, 30000)
|
|
76
86
|
})
|
|
@@ -2,7 +2,8 @@ import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator
|
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { createMockConnectionDhtNode, waitConnectionManagersReadyForTesting } from '../utils/utils'
|
|
4
4
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
5
|
-
import {
|
|
5
|
+
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
6
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
7
|
|
|
7
8
|
const NUM_NODES = 5
|
|
8
9
|
const MAX_CONNECTIONS = 5
|
|
@@ -20,7 +21,7 @@ describe('Storing data in DHT', () => {
|
|
|
20
21
|
beforeEach(async () => {
|
|
21
22
|
nodes = []
|
|
22
23
|
const entryPoint = await createMockConnectionDhtNode(simulator,
|
|
23
|
-
|
|
24
|
+
createRandomDhtAddress(), K, MAX_CONNECTIONS)
|
|
24
25
|
nodes.push(entryPoint)
|
|
25
26
|
for (let i = 1; i < NUM_NODES; i++) {
|
|
26
27
|
const node = await createMockConnectionDhtNode(simulator,
|
|
@@ -38,11 +39,11 @@ describe('Storing data in DHT', () => {
|
|
|
38
39
|
it('Data can be deleted', async () => {
|
|
39
40
|
const storingNode = getRandomNode()
|
|
40
41
|
const entry = createMockDataEntry()
|
|
41
|
-
const successfulStorers = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
42
|
+
const successfulStorers = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
42
43
|
expect(successfulStorers.length).toBeGreaterThan(4)
|
|
43
|
-
await storingNode.deleteDataFromDht(entry.key, true)
|
|
44
|
+
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
44
45
|
const fetchingNode = getRandomNode()
|
|
45
|
-
const results = await fetchingNode.getDataFromDht(entry.key)
|
|
46
|
+
const results = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
46
47
|
results.forEach((result) => {
|
|
47
48
|
expect(result.deleted).toBeTrue()
|
|
48
49
|
expectEqualData(result, entry)
|
|
@@ -52,18 +53,18 @@ describe('Storing data in DHT', () => {
|
|
|
52
53
|
it('Data can be deleted and re-stored', async () => {
|
|
53
54
|
const storingNode = getRandomNode()
|
|
54
55
|
const entry = createMockDataEntry()
|
|
55
|
-
const successfulStorers1 = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
56
|
+
const successfulStorers1 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
56
57
|
expect(successfulStorers1.length).toBeGreaterThan(4)
|
|
57
|
-
await storingNode.deleteDataFromDht(entry.key, true)
|
|
58
|
+
await storingNode.deleteDataFromDht(getDhtAddressFromRaw(entry.key), true)
|
|
58
59
|
const fetchingNode = getRandomNode()
|
|
59
|
-
const results1 = await fetchingNode.getDataFromDht(entry.key)
|
|
60
|
+
const results1 = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
60
61
|
results1.forEach((result) => {
|
|
61
62
|
expect(result.deleted).toBeTrue()
|
|
62
63
|
expectEqualData(result, entry)
|
|
63
64
|
})
|
|
64
|
-
const successfulStorers2 = await storingNode.storeDataToDht(entry.key, entry.data!)
|
|
65
|
+
const successfulStorers2 = await storingNode.storeDataToDht(getDhtAddressFromRaw(entry.key), entry.data!)
|
|
65
66
|
expect(successfulStorers2.length).toBeGreaterThan(4)
|
|
66
|
-
const results2 = await fetchingNode.getDataFromDht(entry.key)
|
|
67
|
+
const results2 = await fetchingNode.getDataFromDht(getDhtAddressFromRaw(entry.key))
|
|
67
68
|
results2.forEach((result) => {
|
|
68
69
|
expect(result.deleted).toBeFalse()
|
|
69
70
|
expectEqualData(result, entry)
|
|
@@ -3,6 +3,7 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
3
3
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
4
|
import { waitForCondition } from '@streamr/utils'
|
|
5
5
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
6
7
|
|
|
7
8
|
describe('Storing data in DHT with two peers', () => {
|
|
8
9
|
|
|
@@ -31,10 +32,10 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
31
32
|
it('Node can store on two peer DHT', async () => {
|
|
32
33
|
const storedData1 = createMockDataEntry()
|
|
33
34
|
const storedData2 = createMockDataEntry()
|
|
34
|
-
await otherNode.storeDataToDht(storedData1.key, storedData1.data!)
|
|
35
|
-
await entryPoint.storeDataToDht(storedData2.key, storedData2.data!)
|
|
36
|
-
const foundData1 = await otherNode.getDataFromDht(storedData1.key)
|
|
37
|
-
const foundData2 = await entryPoint.getDataFromDht(storedData2.key)
|
|
35
|
+
await otherNode.storeDataToDht(getDhtAddressFromRaw(storedData1.key), storedData1.data!)
|
|
36
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData2.key), storedData2.data!)
|
|
37
|
+
const foundData1 = await otherNode.getDataFromDht(getDhtAddressFromRaw(storedData1.key))
|
|
38
|
+
const foundData2 = await entryPoint.getDataFromDht(getDhtAddressFromRaw(storedData2.key))
|
|
38
39
|
expectEqualData(foundData1[0], storedData1)
|
|
39
40
|
expectEqualData(foundData2[0], storedData2)
|
|
40
41
|
})
|
|
@@ -43,8 +44,8 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
43
44
|
await otherNode.stop()
|
|
44
45
|
await waitForCondition(() => entryPoint.getNumberOfNeighbors() === 0)
|
|
45
46
|
const storedData = createMockDataEntry()
|
|
46
|
-
await entryPoint.storeDataToDht(storedData.key, storedData.data!)
|
|
47
|
-
const foundData = await entryPoint.getDataFromDht(storedData.key)
|
|
47
|
+
await entryPoint.storeDataToDht(getDhtAddressFromRaw(storedData.key), storedData.data!)
|
|
48
|
+
const foundData = await entryPoint.getDataFromDht(getDhtAddressFromRaw(storedData.key))
|
|
48
49
|
expectEqualData(foundData[0], storedData)
|
|
49
50
|
}, 60000)
|
|
50
51
|
})
|
|
@@ -9,9 +9,7 @@ import { StoreRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.clien
|
|
|
9
9
|
import { StoreRpcRemote } from '../../src/dht/store/StoreRpcRemote'
|
|
10
10
|
import { createMockDataEntry } from '../utils/mock/mockDataEntry'
|
|
11
11
|
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
12
|
-
import {
|
|
13
|
-
|
|
14
|
-
const SERVICE_ID = 'test'
|
|
12
|
+
import { createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
15
13
|
|
|
16
14
|
describe('StoreRpcRemote', () => {
|
|
17
15
|
|
|
@@ -24,7 +22,7 @@ describe('StoreRpcRemote', () => {
|
|
|
24
22
|
const request: StoreDataRequest = {
|
|
25
23
|
key: data.key,
|
|
26
24
|
data: data.data,
|
|
27
|
-
creator:
|
|
25
|
+
creator: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
28
26
|
ttl: 10
|
|
29
27
|
}
|
|
30
28
|
|
|
@@ -38,7 +36,7 @@ describe('StoreRpcRemote', () => {
|
|
|
38
36
|
serverRpcCommunicator.on('outgoingMessage', (message: RpcMessage) => {
|
|
39
37
|
clientRpcCommunicator.handleIncomingMessage(message)
|
|
40
38
|
})
|
|
41
|
-
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor,
|
|
39
|
+
rpcRemote = new StoreRpcRemote(clientPeerDescriptor, serverPeerDescriptor, clientRpcCommunicator, StoreRpcClient)
|
|
42
40
|
})
|
|
43
41
|
|
|
44
42
|
it('storeData happy path', async () => {
|
|
@@ -37,4 +37,8 @@ describe('isPrivateIPv4', () => {
|
|
|
37
37
|
it('return false for a public address', () => {
|
|
38
38
|
expect(isPrivateIPv4('203.0.113.181')).toBe(false)
|
|
39
39
|
})
|
|
40
|
+
|
|
41
|
+
it('return true for localhost IP address', () => {
|
|
42
|
+
expect(isPrivateIPv4('127.0.0.1')).toBe(true)
|
|
43
|
+
})
|
|
40
44
|
})
|
|
@@ -2,17 +2,16 @@ import { wait } from '@streamr/utils'
|
|
|
2
2
|
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
3
3
|
import {
|
|
4
4
|
getNodeIdFromPeerDescriptor,
|
|
5
|
-
peerIdFromPeerDescriptor
|
|
6
5
|
} from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
7
6
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
7
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
9
|
-
import {
|
|
8
|
+
import { DhtAddress, createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
10
9
|
|
|
11
10
|
describe('LocalDataStore', () => {
|
|
12
11
|
|
|
13
12
|
let localDataStore: LocalDataStore
|
|
14
13
|
|
|
15
|
-
const getEntryArray = (key:
|
|
14
|
+
const getEntryArray = (key: DhtAddress) => {
|
|
16
15
|
return Array.from(localDataStore.getEntries(key).values())
|
|
17
16
|
}
|
|
18
17
|
|
|
@@ -27,84 +26,93 @@ describe('LocalDataStore', () => {
|
|
|
27
26
|
it('can store', () => {
|
|
28
27
|
const storedEntry = createMockDataEntry()
|
|
29
28
|
localDataStore.storeEntry(storedEntry)
|
|
30
|
-
const fetchedEntries = getEntryArray(storedEntry.key)
|
|
29
|
+
const fetchedEntries = getEntryArray(getDhtAddressFromRaw(storedEntry.key))
|
|
31
30
|
expect(fetchedEntries).toHaveLength(1)
|
|
32
31
|
expectEqualData(fetchedEntries[0], storedEntry)
|
|
33
32
|
})
|
|
34
33
|
|
|
35
34
|
it('multiple storers behind one key', () => {
|
|
36
|
-
const creator1 =
|
|
37
|
-
const creator2 =
|
|
38
|
-
const key =
|
|
35
|
+
const creator1 = createRandomDhtAddress()
|
|
36
|
+
const creator2 = createRandomDhtAddress()
|
|
37
|
+
const key = createRandomDhtAddress()
|
|
39
38
|
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
40
39
|
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
41
40
|
localDataStore.storeEntry(storedEntry1)
|
|
42
41
|
localDataStore.storeEntry(storedEntry2)
|
|
43
42
|
const fetchedEntries = localDataStore.getEntries(key)
|
|
44
43
|
expect(fetchedEntries.size).toBe(2)
|
|
45
|
-
expectEqualData(fetchedEntries.get(
|
|
46
|
-
expectEqualData(fetchedEntries.get(
|
|
44
|
+
expectEqualData(fetchedEntries.get(creator1)!, storedEntry1)
|
|
45
|
+
expectEqualData(fetchedEntries.get(creator2)!, storedEntry2)
|
|
47
46
|
})
|
|
48
47
|
|
|
49
48
|
it('can remove data entries', () => {
|
|
50
|
-
const creator1 =
|
|
51
|
-
const creator2 =
|
|
52
|
-
const key =
|
|
49
|
+
const creator1 = createRandomDhtAddress()
|
|
50
|
+
const creator2 = createRandomDhtAddress()
|
|
51
|
+
const key = createRandomDhtAddress()
|
|
53
52
|
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
54
53
|
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
55
54
|
localDataStore.storeEntry(storedEntry1)
|
|
56
55
|
localDataStore.storeEntry(storedEntry2)
|
|
57
|
-
localDataStore.deleteEntry(key,
|
|
56
|
+
localDataStore.deleteEntry(key, creator1)
|
|
58
57
|
const fetchedEntries = getEntryArray(key)
|
|
59
58
|
expect(fetchedEntries).toHaveLength(1)
|
|
60
59
|
expectEqualData(fetchedEntries[0], storedEntry2)
|
|
61
60
|
})
|
|
62
61
|
|
|
63
62
|
it('can remove all data entries', () => {
|
|
64
|
-
const creator1 =
|
|
65
|
-
const creator2 =
|
|
66
|
-
const key =
|
|
63
|
+
const creator1 = createRandomDhtAddress()
|
|
64
|
+
const creator2 = createRandomDhtAddress()
|
|
65
|
+
const key = createRandomDhtAddress()
|
|
67
66
|
const storedEntry1 = createMockDataEntry({ key, creator: creator1 })
|
|
68
67
|
const storedEntry2 = createMockDataEntry({ key, creator: creator2 })
|
|
69
68
|
localDataStore.storeEntry(storedEntry1)
|
|
70
69
|
localDataStore.storeEntry(storedEntry2)
|
|
71
|
-
localDataStore.deleteEntry(key,
|
|
72
|
-
localDataStore.deleteEntry(key,
|
|
70
|
+
localDataStore.deleteEntry(key, creator1)
|
|
71
|
+
localDataStore.deleteEntry(key, creator2)
|
|
73
72
|
expect(getEntryArray(key)).toHaveLength(0)
|
|
74
73
|
})
|
|
75
74
|
|
|
76
75
|
it('data is deleted after TTL', async () => {
|
|
77
76
|
const storedEntry = createMockDataEntry({ ttl: 1000 })
|
|
78
77
|
localDataStore.storeEntry(storedEntry)
|
|
79
|
-
expect(getEntryArray(storedEntry.key)).toHaveLength(1)
|
|
78
|
+
expect(getEntryArray(getDhtAddressFromRaw(storedEntry.key))).toHaveLength(1)
|
|
80
79
|
await wait(1100)
|
|
81
|
-
expect(getEntryArray(storedEntry.key)).toHaveLength(0)
|
|
80
|
+
expect(getEntryArray(getDhtAddressFromRaw(storedEntry.key))).toHaveLength(0)
|
|
82
81
|
})
|
|
83
82
|
|
|
84
83
|
describe('mark data as deleted', () => {
|
|
85
84
|
|
|
86
85
|
it('happy path', () => {
|
|
87
|
-
const creator1 =
|
|
86
|
+
const creator1 = createRandomDhtAddress()
|
|
88
87
|
const storedEntry = createMockDataEntry({ creator: creator1 })
|
|
89
88
|
localDataStore.storeEntry(storedEntry)
|
|
90
|
-
const notDeletedData = localDataStore.getEntries(storedEntry.key)
|
|
91
|
-
expect(notDeletedData.get(
|
|
92
|
-
const returnValue = localDataStore.markAsDeleted(
|
|
89
|
+
const notDeletedData = localDataStore.getEntries(getDhtAddressFromRaw(storedEntry.key))
|
|
90
|
+
expect(notDeletedData.get(creator1)!.deleted).toBeFalse()
|
|
91
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
92
|
+
getDhtAddressFromRaw(storedEntry.key),
|
|
93
|
+
creator1
|
|
94
|
+
)
|
|
93
95
|
expect(returnValue).toBe(true)
|
|
94
|
-
const deletedData = localDataStore.getEntries(storedEntry.key)
|
|
95
|
-
expect(deletedData.get(
|
|
96
|
+
const deletedData = localDataStore.getEntries(getDhtAddressFromRaw(storedEntry.key))
|
|
97
|
+
expect(deletedData.get(creator1)!.deleted).toBeTrue()
|
|
96
98
|
})
|
|
97
99
|
|
|
98
100
|
it('data not stored', () => {
|
|
99
|
-
const
|
|
100
|
-
const returnValue = localDataStore.markAsDeleted(
|
|
101
|
+
const key = createRandomDhtAddress()
|
|
102
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
103
|
+
key,
|
|
104
|
+
getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
|
|
105
|
+
)
|
|
101
106
|
expect(returnValue).toBe(false)
|
|
102
107
|
})
|
|
103
108
|
|
|
104
109
|
it('data not stored by the given creator', () => {
|
|
105
110
|
const storedEntry = createMockDataEntry()
|
|
106
111
|
localDataStore.storeEntry(storedEntry)
|
|
107
|
-
const returnValue = localDataStore.markAsDeleted(
|
|
112
|
+
const returnValue = localDataStore.markAsDeleted(
|
|
113
|
+
getDhtAddressFromRaw(storedEntry.key),
|
|
114
|
+
getNodeIdFromPeerDescriptor(createMockPeerDescriptor())
|
|
115
|
+
)
|
|
108
116
|
expect(returnValue).toBe(false)
|
|
109
117
|
})
|
|
110
118
|
})
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { hexToBinary } from '@streamr/utils'
|
|
2
1
|
import { PeerManager, getDistance } from '../../src/dht/PeerManager'
|
|
3
|
-
import {
|
|
2
|
+
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
4
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { range, sampleSize, sortBy, without } from 'lodash'
|
|
6
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
@@ -9,22 +8,22 @@ import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
|
9
8
|
describe('PeerManager', () => {
|
|
10
9
|
|
|
11
10
|
it('getClosestContactsTo', () => {
|
|
12
|
-
const nodeIds = range(10).map(() =>
|
|
11
|
+
const nodeIds = range(10).map(() => createRandomDhtAddress())
|
|
13
12
|
const manager = new PeerManager({
|
|
14
|
-
localNodeId:
|
|
13
|
+
localNodeId: createRandomDhtAddress(),
|
|
15
14
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => {
|
|
16
15
|
return new DhtNodeRpcRemote(undefined as any, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
17
16
|
}
|
|
18
17
|
} as any)
|
|
19
|
-
manager.handleNewPeers(nodeIds.map((n) => ({ nodeId:
|
|
18
|
+
manager.handleNewPeers(nodeIds.map((n) => ({ nodeId: getRawFromDhtAddress(n), type: NodeType.NODEJS })))
|
|
20
19
|
|
|
21
|
-
const referenceId =
|
|
22
|
-
const excluded = new Set<
|
|
20
|
+
const referenceId = createRandomDhtAddress()
|
|
21
|
+
const excluded = new Set<DhtAddress>(sampleSize(nodeIds, 2)!)
|
|
23
22
|
const actual = manager.getClosestContactsTo(referenceId, 5, excluded)
|
|
24
23
|
|
|
25
24
|
const expected = sortBy(
|
|
26
25
|
without(nodeIds, ...Array.from(excluded.values())),
|
|
27
|
-
(n:
|
|
26
|
+
(n: DhtAddress) => getDistance(getRawFromDhtAddress(n), getRawFromDhtAddress(referenceId))
|
|
28
27
|
).slice(0, 5)
|
|
29
28
|
expect(actual.map((n) => n.getNodeId())).toEqual(expected)
|
|
30
29
|
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RandomContactList } from '../../src/dht/contact/RandomContactList'
|
|
2
2
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
|
-
import {
|
|
3
|
+
import { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
4
|
|
|
5
|
-
const createItem = (nodeId:
|
|
5
|
+
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress, getPeerId: () => PeerID } => {
|
|
6
6
|
return {
|
|
7
|
-
getNodeId: () =>
|
|
7
|
+
getNodeId: () => getDhtAddressFromRaw(nodeId),
|
|
8
8
|
getPeerId: () => PeerID.fromValue(nodeId)
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -21,6 +21,7 @@ import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescrip
|
|
|
21
21
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
22
22
|
import { Router } from '../../src/dht/routing/Router'
|
|
23
23
|
import { ITransport } from '../../src/exports'
|
|
24
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
24
25
|
|
|
25
26
|
const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
|
|
26
27
|
return {
|
|
@@ -85,7 +86,7 @@ describe('RecursiveOperationManager', () => {
|
|
|
85
86
|
|
|
86
87
|
it('startFind with mode Node returns self if no peers', async () => {
|
|
87
88
|
const recursiveOperationManager = createRecursiveOperationManager()
|
|
88
|
-
const res = await recursiveOperationManager.execute(PeerID.fromString('find').value, RecursiveOperation.FIND_NODE)
|
|
89
|
+
const res = await recursiveOperationManager.execute(getDhtAddressFromRaw(PeerID.fromString('find').value), RecursiveOperation.FIND_NODE)
|
|
89
90
|
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
90
91
|
recursiveOperationManager.stop()
|
|
91
92
|
})
|
|
@@ -3,7 +3,7 @@ import { range } from 'lodash'
|
|
|
3
3
|
import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
|
|
4
4
|
import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
|
|
5
5
|
import { ServiceID } from '../../src/exports'
|
|
6
|
-
import {
|
|
6
|
+
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
7
7
|
import { Message, PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { RecursiveOperationSessionRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
9
9
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
@@ -21,7 +21,6 @@ describe('RecursiveOperationSession', () => {
|
|
|
21
21
|
return new RecursiveOperationSessionRpcRemote(
|
|
22
22
|
createMockPeerDescriptor(),
|
|
23
23
|
localPeerDescriptor,
|
|
24
|
-
serviceId,
|
|
25
24
|
new RoutingRpcCommunicator(serviceId, send),
|
|
26
25
|
RecursiveOperationSessionRpcClient
|
|
27
26
|
)
|
|
@@ -36,7 +35,7 @@ describe('RecursiveOperationSession', () => {
|
|
|
36
35
|
const doRouteRequest = jest.fn()
|
|
37
36
|
const session = new RecursiveOperationSession({
|
|
38
37
|
transport: environment.createTransport(),
|
|
39
|
-
targetId:
|
|
38
|
+
targetId: createRandomDhtAddress(),
|
|
40
39
|
localPeerDescriptor,
|
|
41
40
|
waitedRoutingPathCompletions: 3,
|
|
42
41
|
operation: RecursiveOperation.FIND_NODE,
|
package/test/unit/Router.test.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
13
13
|
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
14
14
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
15
|
-
import {
|
|
15
|
+
import { DhtAddress } from '../../src/identifiers'
|
|
16
16
|
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
17
17
|
|
|
18
18
|
describe('Router', () => {
|
|
@@ -40,7 +40,7 @@ describe('Router', () => {
|
|
|
40
40
|
target: peerDescriptor1.nodeId,
|
|
41
41
|
sourcePeer: peerDescriptor2
|
|
42
42
|
}
|
|
43
|
-
let connections: Map<
|
|
43
|
+
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
44
44
|
const rpcCommunicator = new FakeRpcCommunicator()
|
|
45
45
|
|
|
46
46
|
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
@@ -5,13 +5,13 @@ import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../u
|
|
|
5
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
6
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
7
7
|
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
|
-
import {
|
|
8
|
+
import { DhtAddress } from '../../src/identifiers'
|
|
9
9
|
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
10
10
|
|
|
11
11
|
describe('RoutingSession', () => {
|
|
12
12
|
|
|
13
13
|
let session: RoutingSession
|
|
14
|
-
let connections: Map<
|
|
14
|
+
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
15
15
|
let rpcCommunicator: RoutingRpcCommunicator
|
|
16
16
|
const mockPeerDescriptor1 = createMockPeerDescriptor()
|
|
17
17
|
const mockPeerDescriptor2 = createMockPeerDescriptor()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
2
2
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
|
-
import {
|
|
3
|
+
import { DhtAddress, DhtAddressRaw, createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
4
|
|
|
5
|
-
const createItem = (nodeId:
|
|
5
|
+
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress, getPeerId: () => PeerID } => {
|
|
6
6
|
return {
|
|
7
|
-
getNodeId: () =>
|
|
7
|
+
getNodeId: () => getDhtAddressFromRaw(nodeId),
|
|
8
8
|
getPeerId: () => PeerID.fromValue(nodeId)
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -72,7 +72,7 @@ describe('SortedContactList', () => {
|
|
|
72
72
|
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false, emitEvents: true })
|
|
73
73
|
const onContactRemoved = jest.fn()
|
|
74
74
|
list.on('contactRemoved', onContactRemoved)
|
|
75
|
-
list.removeContact(
|
|
75
|
+
list.removeContact(createRandomDhtAddress())
|
|
76
76
|
list.addContact(item3)
|
|
77
77
|
list.removeContact(item3.getNodeId())
|
|
78
78
|
list.addContact(item4)
|
|
@@ -84,10 +84,10 @@ describe('SortedContactList', () => {
|
|
|
84
84
|
expect(list.getContact(item2.getNodeId())).toBeFalsy()
|
|
85
85
|
expect(list.getContactIds()).toEqual(list.getContactIds().sort(list.compareIds))
|
|
86
86
|
expect(list.getAllContacts()).toEqual([item1, item3, item4])
|
|
87
|
-
const ret = list.removeContact(
|
|
87
|
+
const ret = list.removeContact(getDhtAddressFromRaw(Buffer.from([0, 0, 0, 6])))
|
|
88
88
|
expect(ret).toEqual(false)
|
|
89
89
|
list.removeContact(item3.getNodeId())
|
|
90
|
-
list.removeContact(
|
|
90
|
+
list.removeContact(createRandomDhtAddress())
|
|
91
91
|
expect(list.getAllContacts()).toEqual([item1, item4])
|
|
92
92
|
expect(onContactRemoved).toHaveBeenNthCalledWith(1, item3, [])
|
|
93
93
|
expect(onContactRemoved).toHaveBeenNthCalledWith(2, item2, [item1, item3, item4])
|