@streamr/dht 100.0.0-testnet-three.1 → 100.0.0-testnet-three.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/connectivityRequestHandler.js +25 -21
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +10 -1
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +3 -2
- package/dist/src/dht/DhtNode.js +28 -11
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +2 -2
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +7 -9
- package/dist/src/dht/PeerManager.js +7 -14
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +1 -1
- package/dist/src/dht/contact/RandomContactList.js +1 -1
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.js +18 -17
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +1 -1
- package/dist/src/dht/discovery/DiscoverySession.js +5 -5
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +2 -2
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +2 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.js +2 -1
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +1 -1
- package/dist/src/dht/store/LocalDataStore.js +2 -5
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +1 -1
- package/dist/src/dht/store/StoreManager.js +10 -17
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/identifiers.d.ts +1 -0
- package/dist/src/identifiers.js +3 -3
- package/dist/src/identifiers.js.map +1 -1
- package/package.json +5 -5
- package/src/connection/connectivityRequestHandler.ts +26 -22
- package/src/connection/websocket/WebsocketConnector.ts +9 -1
- package/src/dht/DhtNode.ts +33 -16
- package/src/dht/DhtNodeRpcLocal.ts +3 -3
- package/src/dht/PeerManager.ts +12 -21
- package/src/dht/contact/ContactList.ts +1 -1
- package/src/dht/contact/RandomContactList.ts +1 -1
- package/src/dht/contact/SortedContactList.ts +26 -24
- package/src/dht/discovery/DiscoverySession.ts +5 -5
- package/src/dht/discovery/PeerDiscovery.ts +2 -2
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -1
- package/src/dht/routing/RouterRpcLocal.ts +2 -3
- package/src/dht/routing/RoutingSession.ts +2 -1
- package/src/dht/store/LocalDataStore.ts +2 -5
- package/src/dht/store/StoreManager.ts +10 -17
- package/src/identifiers.ts +1 -1
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +5 -5
- package/test/end-to-end/Layer0Webrtc.test.ts +0 -2
- package/test/unit/PeerManager.test.ts +1 -1
- package/test/unit/SortedContactList.test.ts +13 -0
- package/test/unit/StoreManager.test.ts +26 -23
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import {
|
|
2
|
+
import { createRandomDhtAddress, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
3
3
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
4
|
|
|
5
5
|
describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
@@ -26,22 +26,22 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
|
26
26
|
|
|
27
27
|
layer0EntryPoint = new DhtNode({ peerDescriptor: entrypointDescriptor, websocketServerEnableTls: false })
|
|
28
28
|
|
|
29
|
-
const layer0Node1Id =
|
|
29
|
+
const layer0Node1Id = createRandomDhtAddress()
|
|
30
30
|
layer0Node1 = new DhtNode({
|
|
31
31
|
nodeId: layer0Node1Id
|
|
32
32
|
})
|
|
33
33
|
|
|
34
|
-
const layer0Node2Id =
|
|
34
|
+
const layer0Node2Id = createRandomDhtAddress()
|
|
35
35
|
layer0Node2 = new DhtNode({
|
|
36
36
|
nodeId: layer0Node2Id
|
|
37
37
|
})
|
|
38
38
|
|
|
39
|
-
const layer0Node3Id =
|
|
39
|
+
const layer0Node3Id = createRandomDhtAddress()
|
|
40
40
|
layer0Node3 = new DhtNode({
|
|
41
41
|
nodeId: layer0Node3Id
|
|
42
42
|
})
|
|
43
43
|
|
|
44
|
-
const layer0Node4Id =
|
|
44
|
+
const layer0Node4Id = createRandomDhtAddress()
|
|
45
45
|
layer0Node4 = new DhtNode({
|
|
46
46
|
nodeId: layer0Node4Id
|
|
47
47
|
})
|
|
@@ -15,7 +15,7 @@ describe('PeerManager', () => {
|
|
|
15
15
|
return new DhtNodeRpcRemote(undefined as any, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
16
16
|
}
|
|
17
17
|
} as any)
|
|
18
|
-
manager.
|
|
18
|
+
manager.addContact(nodeIds.map((n) => ({ nodeId: getRawFromDhtAddress(n), type: NodeType.NODEJS })))
|
|
19
19
|
|
|
20
20
|
const referenceId = createRandomDhtAddress()
|
|
21
21
|
const excluded = new Set<DhtAddress>(sampleSize(nodeIds, 2)!)
|
|
@@ -118,4 +118,17 @@ describe('SortedContactList', () => {
|
|
|
118
118
|
list.setActive(item4.getNodeId())
|
|
119
119
|
expect(list.getActiveContacts()).toEqual([item2, item3, item4])
|
|
120
120
|
})
|
|
121
|
+
|
|
122
|
+
it('does not emit contactAdded if contact did not fit the structure', () => {
|
|
123
|
+
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 2, allowToContainReferenceId: false, emitEvents: true })
|
|
124
|
+
const onContactAdded = jest.fn()
|
|
125
|
+
list.on('contactAdded', onContactAdded)
|
|
126
|
+
list.addContact(item1)
|
|
127
|
+
list.addContact(item2)
|
|
128
|
+
expect(onContactAdded).toBeCalledTimes(2)
|
|
129
|
+
list.addContact(item3)
|
|
130
|
+
expect(onContactAdded).toBeCalledTimes(2)
|
|
131
|
+
expect(list.getAllContacts().length).toEqual(2)
|
|
132
|
+
})
|
|
133
|
+
|
|
121
134
|
})
|
|
@@ -27,7 +27,7 @@ describe('StoreManager', () => {
|
|
|
27
27
|
localNodeId: DhtAddress,
|
|
28
28
|
closestNeighbors: DhtAddress[],
|
|
29
29
|
replicateData: (request: ReplicateDataRequest) => unknown,
|
|
30
|
-
|
|
30
|
+
setAllEntriesAsStale: (key: DhtAddress) => unknown
|
|
31
31
|
): StoreManager => {
|
|
32
32
|
const getClosestNeighborsTo = () => {
|
|
33
33
|
return closestNeighbors.map((nodeId) => ({ nodeId: getRawFromDhtAddress(nodeId), type: NodeType.NODEJS }))
|
|
@@ -39,7 +39,11 @@ describe('StoreManager', () => {
|
|
|
39
39
|
} as any,
|
|
40
40
|
recursiveOperationManager: undefined as any,
|
|
41
41
|
localPeerDescriptor: { nodeId: getRawFromDhtAddress(localNodeId), type: NodeType.NODEJS },
|
|
42
|
-
localDataStore: {
|
|
42
|
+
localDataStore: {
|
|
43
|
+
keys: () => [getDhtAddressFromRaw(DATA_ENTRY.key)],
|
|
44
|
+
values: () => [DATA_ENTRY],
|
|
45
|
+
setAllEntriesAsStale
|
|
46
|
+
} as any,
|
|
43
47
|
serviceId: undefined as any,
|
|
44
48
|
highestTtl: undefined as any,
|
|
45
49
|
redundancyFactor: 3,
|
|
@@ -52,34 +56,34 @@ describe('StoreManager', () => {
|
|
|
52
56
|
|
|
53
57
|
it('new node is within redundancy factor', async () => {
|
|
54
58
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
55
|
-
const
|
|
59
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
56
60
|
const manager = createStoreManager(
|
|
57
61
|
NODES_CLOSEST_TO_DATA[0],
|
|
58
62
|
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[3], NODES_CLOSEST_TO_DATA[4]],
|
|
59
63
|
replicateData,
|
|
60
|
-
|
|
64
|
+
setAllEntriesAsStale
|
|
61
65
|
)
|
|
62
|
-
manager.
|
|
66
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[2]), type: NodeType.NODEJS })
|
|
63
67
|
await waitForCondition(() => replicateData.mock.calls.length === 1)
|
|
64
68
|
expect(replicateData).toHaveBeenCalledWith({
|
|
65
69
|
entry: DATA_ENTRY
|
|
66
70
|
})
|
|
67
|
-
expect(
|
|
71
|
+
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
68
72
|
})
|
|
69
73
|
|
|
70
74
|
it('new node is not within redundancy factor', async () => {
|
|
71
75
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
72
|
-
const
|
|
76
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
73
77
|
const manager = createStoreManager(
|
|
74
78
|
NODES_CLOSEST_TO_DATA[0],
|
|
75
79
|
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
76
80
|
replicateData,
|
|
77
|
-
|
|
81
|
+
setAllEntriesAsStale
|
|
78
82
|
)
|
|
79
|
-
manager.
|
|
83
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
80
84
|
await wait(50)
|
|
81
85
|
expect(replicateData).not.toHaveBeenCalled()
|
|
82
|
-
expect(
|
|
86
|
+
expect(setAllEntriesAsStale).not.toHaveBeenCalled()
|
|
83
87
|
})
|
|
84
88
|
})
|
|
85
89
|
|
|
@@ -87,48 +91,47 @@ describe('StoreManager', () => {
|
|
|
87
91
|
|
|
88
92
|
it('this node is within redundancy factor', async () => {
|
|
89
93
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
90
|
-
const
|
|
94
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
91
95
|
const manager = createStoreManager(
|
|
92
96
|
NODES_CLOSEST_TO_DATA[1],
|
|
93
97
|
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
94
98
|
replicateData,
|
|
95
|
-
|
|
99
|
+
setAllEntriesAsStale
|
|
96
100
|
)
|
|
97
|
-
manager.
|
|
101
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
98
102
|
await wait(50)
|
|
99
103
|
expect(replicateData).not.toHaveBeenCalled()
|
|
100
|
-
expect(setStale).not.toHaveBeenCalled()
|
|
101
104
|
})
|
|
102
105
|
|
|
103
106
|
it('this node is not within redundancy factor', async () => {
|
|
104
107
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
105
|
-
const
|
|
108
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
106
109
|
const manager = createStoreManager(
|
|
107
110
|
NODES_CLOSEST_TO_DATA[3],
|
|
108
111
|
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2]],
|
|
109
112
|
replicateData,
|
|
110
|
-
|
|
113
|
+
setAllEntriesAsStale
|
|
111
114
|
)
|
|
112
|
-
manager.
|
|
115
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
113
116
|
await wait(50)
|
|
114
117
|
expect(replicateData).not.toHaveBeenCalled()
|
|
115
|
-
expect(
|
|
116
|
-
expect(
|
|
118
|
+
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(1)
|
|
119
|
+
expect(setAllEntriesAsStale).toHaveBeenCalledWith(getDhtAddressFromRaw(DATA_ENTRY.key))
|
|
117
120
|
})
|
|
118
121
|
|
|
119
122
|
it('this node has less than redundancyFactor neighbors', async () => {
|
|
120
123
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
121
|
-
const
|
|
124
|
+
const setAllEntriesAsStale = jest.fn<undefined, [DhtAddress]>()
|
|
122
125
|
const manager = createStoreManager(
|
|
123
126
|
NODES_CLOSEST_TO_DATA[3],
|
|
124
127
|
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1]],
|
|
125
128
|
replicateData,
|
|
126
|
-
|
|
129
|
+
setAllEntriesAsStale
|
|
127
130
|
)
|
|
128
|
-
manager.
|
|
131
|
+
manager.onContactAdded({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
129
132
|
await wait(50)
|
|
130
133
|
expect(replicateData).not.toHaveBeenCalled()
|
|
131
|
-
expect(
|
|
134
|
+
expect(setAllEntriesAsStale).toHaveBeenCalledTimes(0)
|
|
132
135
|
})
|
|
133
136
|
})
|
|
134
137
|
})
|