@streamr/trackerless-network 100.2.4-beta.0 → 100.2.5-beta.0
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 +6 -7
- package/dist/src/NetworkStack.js +1 -1
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/logic/ContentDeliveryLayerNode.js +9 -8
- package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -1
- package/dist/src/logic/ContentDeliveryManager.d.ts +2 -0
- package/dist/src/logic/ContentDeliveryManager.js +43 -13
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
- package/dist/src/logic/EntryPointDiscovery.d.ts +3 -14
- package/dist/src/logic/EntryPointDiscovery.js +9 -83
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
- package/dist/src/logic/Layer0Node.d.ts +2 -2
- package/dist/src/logic/Layer1Node.d.ts +7 -3
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.d.ts +18 -0
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.js +73 -0
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.js.map +1 -0
- package/dist/src/logic/StreamPartReconnect.d.ts +11 -0
- package/dist/src/logic/StreamPartReconnect.js +35 -0
- package/dist/src/logic/StreamPartReconnect.js.map +1 -0
- package/dist/src/proto/google/protobuf/any.d.ts +4 -11
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +1 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +3 -9
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +2 -2
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/test/benchmark/first-message.js +1 -1
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.js +2 -0
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +6 -7
- package/src/NetworkStack.ts +1 -1
- package/src/logic/ContentDeliveryLayerNode.ts +11 -9
- package/src/logic/ContentDeliveryManager.ts +44 -16
- package/src/logic/EntryPointDiscovery.ts +14 -102
- package/src/logic/Layer0Node.ts +2 -2
- package/src/logic/Layer1Node.ts +7 -3
- package/src/logic/StreamPartNetworkSplitAvoidance.ts +89 -0
- package/src/logic/StreamPartReconnect.ts +37 -0
- package/src/proto/google/protobuf/any.ts +4 -11
- package/src/proto/google/protobuf/empty.ts +1 -0
- package/src/proto/google/protobuf/timestamp.ts +3 -9
- package/src/proto/packages/dht/protos/DhtRpc.ts +3 -3
- package/test/benchmark/first-message.ts +1 -1
- package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +2 -0
- package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +2 -0
- package/test/integration/ContentDeliveryManager.test.ts +2 -0
- package/test/integration/Inspect.test.ts +2 -1
- package/test/integration/NetworkNode.test.ts +4 -2
- package/test/integration/NodeInfoRpc.test.ts +2 -0
- package/test/integration/joining-streams-on-offline-peers.test.ts +3 -0
- package/test/integration/stream-without-default-entrypoints.test.ts +2 -0
- package/test/integration/streamEntryPointReplacing.test.ts +2 -0
- package/test/unit/ContentDeliveryLayerNode.test.ts +5 -5
- package/test/unit/ContentDeliveryManager.test.ts +1 -1
- package/test/unit/ContentDeliveryRpcLocal.test.ts +1 -1
- package/test/unit/EntrypointDiscovery.test.ts +9 -40
- package/test/unit/Inspector.test.ts +1 -1
- package/test/unit/NeighborUpdateRpcLocal.test.ts +1 -1
- package/test/unit/NodeList.test.ts +1 -1
- package/test/unit/StreamPartNetworkSplitAvoidance.test.ts +32 -0
- package/test/unit/StreamPartReconnect.test.ts +30 -0
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +1 -1
- package/test/utils/fake/FakeEntryPointDiscovery.ts +29 -0
- package/test/utils/mock/MockConnectionsView.ts +18 -0
- package/test/utils/mock/MockLayer0Node.ts +5 -14
- package/test/utils/mock/MockLayer1Node.ts +2 -2
- package/test/utils/mock/{Transport.ts → MockTransport.ts} +2 -16
- package/test/utils/utils.ts +2 -0
|
@@ -37,14 +37,16 @@ describe('NetworkNode', () => {
|
|
|
37
37
|
layer0: {
|
|
38
38
|
entryPoints: [pd1],
|
|
39
39
|
peerDescriptor: pd1,
|
|
40
|
-
transport: transport1
|
|
40
|
+
transport: transport1,
|
|
41
|
+
connectionsView: transport1
|
|
41
42
|
}
|
|
42
43
|
})
|
|
43
44
|
node2 = createNetworkNode({
|
|
44
45
|
layer0: {
|
|
45
46
|
entryPoints: [pd1],
|
|
46
47
|
peerDescriptor: pd2,
|
|
47
|
-
transport: transport2
|
|
48
|
+
transport: transport2,
|
|
49
|
+
connectionsView: transport2
|
|
48
50
|
}
|
|
49
51
|
})
|
|
50
52
|
|
|
@@ -40,6 +40,7 @@ describe('NetworkStack NodeInfoRpc', () => {
|
|
|
40
40
|
requesteStack = new NetworkStack({
|
|
41
41
|
layer0: {
|
|
42
42
|
transport: requesteeTransport1,
|
|
43
|
+
connectionsView: requesteeTransport1,
|
|
43
44
|
peerDescriptor: requesteePeerDescriptor,
|
|
44
45
|
entryPoints: [requesteePeerDescriptor]
|
|
45
46
|
}
|
|
@@ -47,6 +48,7 @@ describe('NetworkStack NodeInfoRpc', () => {
|
|
|
47
48
|
otherStack = new NetworkStack({
|
|
48
49
|
layer0: {
|
|
49
50
|
transport: otherTransport,
|
|
51
|
+
connectionsView: otherTransport,
|
|
50
52
|
peerDescriptor: otherPeerDescriptor,
|
|
51
53
|
entryPoints: [requesteePeerDescriptor]
|
|
52
54
|
}
|
|
@@ -28,6 +28,7 @@ describe('Joining stream parts on offline nodes', () => {
|
|
|
28
28
|
entryPoint = new NetworkStack({
|
|
29
29
|
layer0: {
|
|
30
30
|
transport: entryPointTransport,
|
|
31
|
+
connectionsView: entryPointTransport,
|
|
31
32
|
peerDescriptor: entryPointPeerDescriptor,
|
|
32
33
|
entryPoints: [entryPointPeerDescriptor]
|
|
33
34
|
}
|
|
@@ -36,6 +37,7 @@ describe('Joining stream parts on offline nodes', () => {
|
|
|
36
37
|
node1 = new NetworkStack({
|
|
37
38
|
layer0: {
|
|
38
39
|
transport: node1Transport,
|
|
40
|
+
connectionsView: node1Transport,
|
|
39
41
|
peerDescriptor: node1PeerDescriptor,
|
|
40
42
|
entryPoints: [entryPointPeerDescriptor]
|
|
41
43
|
}
|
|
@@ -44,6 +46,7 @@ describe('Joining stream parts on offline nodes', () => {
|
|
|
44
46
|
node2 = new NetworkStack({
|
|
45
47
|
layer0: {
|
|
46
48
|
transport: node2Transport,
|
|
49
|
+
connectionsView: node2Transport,
|
|
47
50
|
peerDescriptor: node2PeerDescriptor,
|
|
48
51
|
entryPoints: [entryPointPeerDescriptor]
|
|
49
52
|
}
|
|
@@ -53,6 +53,7 @@ describe('stream without default entrypoints', () => {
|
|
|
53
53
|
entrypoint = createNetworkNode({
|
|
54
54
|
layer0: {
|
|
55
55
|
transport: entryPointTransport,
|
|
56
|
+
connectionsView: entryPointTransport,
|
|
56
57
|
peerDescriptor: entryPointPeerDescriptor,
|
|
57
58
|
entryPoints: [entryPointPeerDescriptor]
|
|
58
59
|
}
|
|
@@ -66,6 +67,7 @@ describe('stream without default entrypoints', () => {
|
|
|
66
67
|
layer0: {
|
|
67
68
|
peerDescriptor,
|
|
68
69
|
transport,
|
|
70
|
+
connectionsView: transport,
|
|
69
71
|
entryPoints: [entryPointPeerDescriptor]
|
|
70
72
|
}
|
|
71
73
|
})
|
|
@@ -27,6 +27,7 @@ describe('Stream Entry Points are replaced when known entry points leave streams
|
|
|
27
27
|
const node = new NetworkStack({
|
|
28
28
|
layer0: {
|
|
29
29
|
transport,
|
|
30
|
+
connectionsView: transport,
|
|
30
31
|
peerDescriptor,
|
|
31
32
|
entryPoints: [entryPointPeerDescriptor]
|
|
32
33
|
}
|
|
@@ -41,6 +42,7 @@ describe('Stream Entry Points are replaced when known entry points leave streams
|
|
|
41
42
|
layer0EntryPoint = new NetworkStack({
|
|
42
43
|
layer0: {
|
|
43
44
|
transport: entryPointTransport,
|
|
45
|
+
connectionsView: entryPointTransport,
|
|
44
46
|
peerDescriptor: entryPointPeerDescriptor,
|
|
45
47
|
entryPoints: [entryPointPeerDescriptor]
|
|
46
48
|
}
|
|
@@ -6,7 +6,7 @@ import { MockHandshaker } from '../utils/mock/MockHandshaker'
|
|
|
6
6
|
import { MockLayer1Node } from '../utils/mock/MockLayer1Node'
|
|
7
7
|
import { MockNeighborFinder } from '../utils/mock/MockNeighborFinder'
|
|
8
8
|
import { MockNeighborUpdateManager } from '../utils/mock/MockNeighborUpdateManager'
|
|
9
|
-
import { MockTransport } from '../utils/mock/
|
|
9
|
+
import { MockTransport } from '../utils/mock/MockTransport'
|
|
10
10
|
import { createMockPeerDescriptor, createMockContentDeliveryRpcRemote, mockConnectionLocker } from '../utils/utils'
|
|
11
11
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
12
12
|
import { getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
@@ -65,11 +65,11 @@ describe('ContentDeliveryLayerNode', () => {
|
|
|
65
65
|
expect(ids[0]).toEqual(getNodeIdFromPeerDescriptor(mockRemote.getPeerDescriptor()))
|
|
66
66
|
})
|
|
67
67
|
|
|
68
|
-
it('Adds Closest Nodes from layer1
|
|
68
|
+
it('Adds Closest Nodes from layer1 nearbyContactAdded event to nearbyNodeView', async () => {
|
|
69
69
|
const peerDescriptor1 = createMockPeerDescriptor()
|
|
70
70
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
71
71
|
layer1Node.setClosestContacts([peerDescriptor1, peerDescriptor2])
|
|
72
|
-
layer1Node.emit('
|
|
72
|
+
layer1Node.emit('nearbyContactAdded', peerDescriptor1)
|
|
73
73
|
await waitForCondition(() => nearbyNodeView.size() === 2)
|
|
74
74
|
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor1))).toBeTruthy()
|
|
75
75
|
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
@@ -85,12 +85,12 @@ describe('ContentDeliveryLayerNode', () => {
|
|
|
85
85
|
expect(randomNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
86
86
|
})
|
|
87
87
|
|
|
88
|
-
it('Adds Nodes from layer1
|
|
88
|
+
it('Adds Nodes from layer1 neighbors to nearbyNodeView if its size is below nodeViewSize', async () => {
|
|
89
89
|
const peerDescriptor1 = createMockPeerDescriptor()
|
|
90
90
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
91
91
|
layer1Node.addNewRandomPeerToKBucket()
|
|
92
92
|
layer1Node.setClosestContacts([peerDescriptor1, peerDescriptor2])
|
|
93
|
-
layer1Node.emit('
|
|
93
|
+
layer1Node.emit('nearbyContactAdded', peerDescriptor1)
|
|
94
94
|
await waitForCondition(() => {
|
|
95
95
|
return nearbyNodeView.size() === 3
|
|
96
96
|
}, 20000)
|
|
@@ -4,7 +4,7 @@ import { randomEthereumAddress } from '@streamr/test-utils'
|
|
|
4
4
|
import { waitForCondition } from '@streamr/utils'
|
|
5
5
|
import { ContentDeliveryManager } from '../../src/logic/ContentDeliveryManager'
|
|
6
6
|
import { MockLayer0Node } from '../utils/mock/MockLayer0Node'
|
|
7
|
-
import { MockTransport } from '../utils/mock/
|
|
7
|
+
import { MockTransport } from '../utils/mock/MockTransport'
|
|
8
8
|
import { createMockPeerDescriptor, createStreamMessage, mockConnectionLocker } from '../utils/utils'
|
|
9
9
|
import { ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
10
10
|
|
|
@@ -3,7 +3,7 @@ import { StreamPartIDUtils } from '@streamr/protocol'
|
|
|
3
3
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
4
4
|
import { ContentDeliveryRpcLocal } from '../../src/logic/ContentDeliveryRpcLocal'
|
|
5
5
|
import { LeaveStreamPartNotice } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
|
-
import { MockTransport } from '../utils/mock/
|
|
6
|
+
import { MockTransport } from '../utils/mock/MockTransport'
|
|
7
7
|
import { createMockPeerDescriptor, createStreamMessage } from '../utils/utils'
|
|
8
8
|
|
|
9
9
|
describe('ContentDeliveryRpcLocal', () => {
|
|
@@ -1,11 +1,9 @@
|
|
|
1
1
|
import { PeerDescriptor, areEqualPeerDescriptors } from '@streamr/dht'
|
|
2
2
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
3
3
|
import { wait } from '@streamr/utils'
|
|
4
|
-
import { range } from 'lodash'
|
|
5
4
|
import { EntryPointDiscovery } from '../../src/logic/EntryPointDiscovery'
|
|
6
5
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
7
6
|
import { DataEntry } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
|
-
import { MockLayer1Node } from '../utils/mock/MockLayer1Node'
|
|
9
7
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
10
8
|
|
|
11
9
|
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
@@ -52,24 +50,11 @@ describe('EntryPointDiscovery', () => {
|
|
|
52
50
|
|
|
53
51
|
const fakeDeleteEntryPointData = async (): Promise<void> => {}
|
|
54
52
|
|
|
55
|
-
const addNodesToStreamPart = (layer1: MockLayer1Node, count: number) => {
|
|
56
|
-
range(count).forEach(() => {
|
|
57
|
-
layer1.addNewRandomPeerToKBucket()
|
|
58
|
-
layer1.addNewRandomPeerToKBucket()
|
|
59
|
-
layer1.addNewRandomPeerToKBucket()
|
|
60
|
-
layer1.addNewRandomPeerToKBucket()
|
|
61
|
-
})
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
let layer1Node: MockLayer1Node
|
|
65
|
-
|
|
66
53
|
beforeEach(() => {
|
|
67
54
|
storeCalled = 0
|
|
68
|
-
layer1Node = new MockLayer1Node()
|
|
69
55
|
entryPointDiscoveryWithData = new EntryPointDiscovery({
|
|
70
56
|
localPeerDescriptor: peerDescriptor,
|
|
71
57
|
streamPartId: STREAM_PART_ID,
|
|
72
|
-
layer1Node,
|
|
73
58
|
fetchEntryPointData: fakeFetchEntryPointData,
|
|
74
59
|
storeEntryPointData: fakeStoreEntryPointData,
|
|
75
60
|
deleteEntryPointData: fakeDeleteEntryPointData,
|
|
@@ -78,7 +63,6 @@ describe('EntryPointDiscovery', () => {
|
|
|
78
63
|
entryPointDiscoveryWithoutData = new EntryPointDiscovery({
|
|
79
64
|
localPeerDescriptor: peerDescriptor,
|
|
80
65
|
streamPartId: STREAM_PART_ID,
|
|
81
|
-
layer1Node,
|
|
82
66
|
fetchEntryPointData: fakeEmptyFetchEntryPointData,
|
|
83
67
|
storeEntryPointData: fakeStoreEntryPointData,
|
|
84
68
|
deleteEntryPointData: fakeDeleteEntryPointData,
|
|
@@ -90,40 +74,25 @@ describe('EntryPointDiscovery', () => {
|
|
|
90
74
|
entryPointDiscoveryWithData.destroy()
|
|
91
75
|
})
|
|
92
76
|
|
|
93
|
-
it('
|
|
94
|
-
const res = await entryPointDiscoveryWithData.
|
|
95
|
-
expect(res.
|
|
96
|
-
expect(res
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('discoverEntryPointsFromDht does not have known entrypoints', async () => {
|
|
100
|
-
const res = await entryPointDiscoveryWithData.discoverEntryPointsFromDht(0)
|
|
101
|
-
expect(res.discoveredEntryPoints.length).toBe(1)
|
|
102
|
-
expect(areEqualPeerDescriptors(res.discoveredEntryPoints[0], peerDescriptor)).toBe(true)
|
|
77
|
+
it('discoverEntryPoints filters deleted data', async () => {
|
|
78
|
+
const res = await entryPointDiscoveryWithData.discoverEntryPoints()
|
|
79
|
+
expect(res.length).toBe(1)
|
|
80
|
+
expect(areEqualPeerDescriptors(res[0], peerDescriptor)).toBe(true)
|
|
103
81
|
})
|
|
104
82
|
|
|
105
|
-
it('
|
|
106
|
-
const res = await entryPointDiscoveryWithoutData.
|
|
107
|
-
expect(res.
|
|
108
|
-
expect(res.discoveredEntryPoints.length).toBe(1)
|
|
109
|
-
expect(areEqualPeerDescriptors(res.discoveredEntryPoints[0], peerDescriptor)).toBe(true) // localPeerDescriptor
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('store on empty stream', async () => {
|
|
113
|
-
await entryPointDiscoveryWithData.storeSelfAsEntryPointIfNecessary(0)
|
|
114
|
-
expect(storeCalled).toEqual(1)
|
|
115
|
-
expect(entryPointDiscoveryWithData.isLocalNodeEntryPoint()).toEqual(true)
|
|
83
|
+
it('discoverEntryPoints without results', async () => {
|
|
84
|
+
const res = await entryPointDiscoveryWithoutData.discoverEntryPoints()
|
|
85
|
+
expect(res.length).toBe(0)
|
|
116
86
|
})
|
|
117
87
|
|
|
118
88
|
it('store on stream without saturated entrypoint count', async () => {
|
|
119
|
-
|
|
120
|
-
await entryPointDiscoveryWithData.storeSelfAsEntryPointIfNecessary(0)
|
|
89
|
+
await entryPointDiscoveryWithData.storeAndKeepLocalNodeAsEntryPoint()
|
|
121
90
|
expect(storeCalled).toEqual(1)
|
|
122
91
|
expect(entryPointDiscoveryWithData.isLocalNodeEntryPoint()).toEqual(true)
|
|
123
92
|
})
|
|
124
93
|
|
|
125
94
|
it('will keep stored until destroyed', async () => {
|
|
126
|
-
await entryPointDiscoveryWithData.
|
|
95
|
+
await entryPointDiscoveryWithData.storeAndKeepLocalNodeAsEntryPoint()
|
|
127
96
|
expect(storeCalled).toEqual(1)
|
|
128
97
|
expect(entryPointDiscoveryWithData.isLocalNodeEntryPoint()).toEqual(true)
|
|
129
98
|
await wait(4500)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ListeningRpcCommunicator, createRandomDhtAddress, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { utf8ToBinary } from '@streamr/utils'
|
|
3
3
|
import { Inspector } from '../../src/logic/inspect/Inspector'
|
|
4
|
-
import { MockTransport } from '../utils/mock/
|
|
4
|
+
import { MockTransport } from '../utils/mock/MockTransport'
|
|
5
5
|
import { createMockPeerDescriptor, mockConnectionLocker } from '../utils/utils'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
7
|
|
|
@@ -4,7 +4,7 @@ import { NeighborUpdateRpcLocal } from '../../src/logic/neighbor-discovery/Neigh
|
|
|
4
4
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
5
5
|
import { NodeList } from '../../src/logic/NodeList'
|
|
6
6
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
|
-
import { MockTransport } from '../utils/mock/
|
|
7
|
+
import { MockTransport } from '../utils/mock/MockTransport'
|
|
8
8
|
import { ContentDeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
9
9
|
import { ContentDeliveryRpcRemote } from '../../src/logic/ContentDeliveryRpcRemote'
|
|
10
10
|
import { range } from 'lodash'
|
|
@@ -13,7 +13,7 @@ import { NodeList } from '../../src/logic/NodeList'
|
|
|
13
13
|
import { formStreamPartContentDeliveryServiceId } from '../../src/logic/formStreamPartDeliveryServiceId'
|
|
14
14
|
import { ContentDeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
15
15
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
16
|
-
import { MockTransport } from '../utils/mock/
|
|
16
|
+
import { MockTransport } from '../utils/mock/MockTransport'
|
|
17
17
|
|
|
18
18
|
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
19
19
|
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { MIN_NEIGHBOR_COUNT } from '../../src/logic/StreamPartNetworkSplitAvoidance'
|
|
2
|
+
import { StreamPartNetworkSplitAvoidance } from '../../src/logic/StreamPartNetworkSplitAvoidance'
|
|
3
|
+
import { MockLayer1Node } from '../utils/mock/MockLayer1Node'
|
|
4
|
+
|
|
5
|
+
describe('StreamPartNetworkSplitAvoidance', () => {
|
|
6
|
+
|
|
7
|
+
let avoidance: StreamPartNetworkSplitAvoidance
|
|
8
|
+
let layer1Node: MockLayer1Node
|
|
9
|
+
|
|
10
|
+
beforeEach(() => {
|
|
11
|
+
layer1Node = new MockLayer1Node()
|
|
12
|
+
avoidance = new StreamPartNetworkSplitAvoidance({
|
|
13
|
+
layer1Node,
|
|
14
|
+
discoverEntryPoints: async () => {
|
|
15
|
+
layer1Node.addNewRandomPeerToKBucket()
|
|
16
|
+
return layer1Node.getNeighbors()
|
|
17
|
+
},
|
|
18
|
+
exponentialRunOfBaseDelay: 1
|
|
19
|
+
})
|
|
20
|
+
})
|
|
21
|
+
|
|
22
|
+
afterEach(() => {
|
|
23
|
+
layer1Node.stop()
|
|
24
|
+
avoidance.destroy()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('runs avoidance until number of neighbors is above MIN_NEIGHBOR_COUNT', async () => {
|
|
28
|
+
await avoidance.avoidNetworkSplit()
|
|
29
|
+
expect(layer1Node.getNeighborCount()).toBeGreaterThan(MIN_NEIGHBOR_COUNT)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
})
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { EntryPointDiscovery } from '../../src/logic/EntryPointDiscovery'
|
|
2
|
+
import { StreamPartReconnect } from '../../src/logic/StreamPartReconnect'
|
|
3
|
+
import { MockLayer1Node } from '../utils/mock/MockLayer1Node'
|
|
4
|
+
import { createFakeEntryPointDiscovery } from '../utils/fake/FakeEntryPointDiscovery'
|
|
5
|
+
import { waitForCondition } from '@streamr/utils'
|
|
6
|
+
|
|
7
|
+
describe('StreamPartReconnect', () => {
|
|
8
|
+
|
|
9
|
+
let entryPointDiscovery: EntryPointDiscovery
|
|
10
|
+
let layer1Node: MockLayer1Node
|
|
11
|
+
let streamPartReconnect: StreamPartReconnect
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
entryPointDiscovery = createFakeEntryPointDiscovery()
|
|
15
|
+
layer1Node = new MockLayer1Node()
|
|
16
|
+
streamPartReconnect = new StreamPartReconnect(layer1Node, entryPointDiscovery)
|
|
17
|
+
})
|
|
18
|
+
|
|
19
|
+
afterEach(() => {
|
|
20
|
+
streamPartReconnect.destroy()
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
it('Happy path', async () => {
|
|
24
|
+
await streamPartReconnect.reconnect(1000)
|
|
25
|
+
expect(streamPartReconnect.isRunning()).toEqual(true)
|
|
26
|
+
layer1Node.addNewRandomPeerToKBucket()
|
|
27
|
+
await waitForCondition(() => streamPartReconnect.isRunning() === false)
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
})
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
2
2
|
import { TemporaryConnectionRpcLocal } from '../../src/logic/temporary-connection/TemporaryConnectionRpcLocal'
|
|
3
|
-
import { MockTransport } from '../utils/mock/
|
|
3
|
+
import { MockTransport } from '../utils/mock/MockTransport'
|
|
4
4
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
5
5
|
import { ListeningRpcCommunicator, getDhtAddressFromRaw } from '@streamr/dht'
|
|
6
6
|
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { PeerDescriptor } from '@streamr/dht'
|
|
2
|
+
import { EntryPointDiscovery } from '../../../src/logic/EntryPointDiscovery'
|
|
3
|
+
|
|
4
|
+
export const createFakeEntryPointDiscovery = (): EntryPointDiscovery => {
|
|
5
|
+
return new FakeEntryPointDiscovery() as unknown as EntryPointDiscovery
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
class FakeEntryPointDiscovery {
|
|
9
|
+
|
|
10
|
+
private entryPoints: PeerDescriptor[] = []
|
|
11
|
+
|
|
12
|
+
setEntryPoints(nodes: PeerDescriptor[]): void {
|
|
13
|
+
this.entryPoints = nodes
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async discoverEntryPoints(): Promise<PeerDescriptor[]> {
|
|
17
|
+
return this.entryPoints
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line class-methods-use-this
|
|
21
|
+
async storeAndKeepLocalNodeAsEntryPoint(): Promise<void> {
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// eslint-disable-next-line class-methods-use-this
|
|
25
|
+
isLocalNodeEntryPoint(): boolean {
|
|
26
|
+
return true
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { PeerDescriptor } from '@streamr/dht'
|
|
2
|
+
|
|
3
|
+
export class MockConnectionsView {
|
|
4
|
+
// eslint-disable-next-line class-methods-use-this
|
|
5
|
+
getConnections(): PeerDescriptor[] {
|
|
6
|
+
return []
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line class-methods-use-this
|
|
10
|
+
getConnectionCount(): number {
|
|
11
|
+
return 0
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line class-methods-use-this
|
|
15
|
+
hasConnection(): boolean {
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { PeerDescriptor, DataEntry, ITransport } from '@streamr/dht'
|
|
1
|
+
import { PeerDescriptor, DataEntry, ITransport, TransportEvents, ConnectionsView } from '@streamr/dht'
|
|
2
2
|
import { Layer0Node } from '../../../src/logic/Layer0Node'
|
|
3
3
|
import { EventEmitter } from 'eventemitter3'
|
|
4
|
+
import { MockConnectionsView } from './MockConnectionsView'
|
|
4
5
|
|
|
5
|
-
export class MockLayer0Node extends EventEmitter implements Layer0Node {
|
|
6
|
+
export class MockLayer0Node extends EventEmitter<TransportEvents> implements Layer0Node {
|
|
6
7
|
|
|
7
8
|
private readonly peerDescriptor: PeerDescriptor
|
|
8
9
|
|
|
@@ -44,18 +45,8 @@ export class MockLayer0Node extends EventEmitter implements Layer0Node {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
// eslint-disable-next-line class-methods-use-this
|
|
47
|
-
|
|
48
|
-
return
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
// eslint-disable-next-line class-methods-use-this
|
|
52
|
-
getConnectionCount(): number {
|
|
53
|
-
return 0
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
// eslint-disable-next-line class-methods-use-this
|
|
57
|
-
hasConnection(): boolean {
|
|
58
|
-
return false
|
|
48
|
+
getConnectionsView(): ConnectionsView {
|
|
49
|
+
return new MockConnectionsView()
|
|
59
50
|
}
|
|
60
51
|
|
|
61
52
|
// eslint-disable-next-line class-methods-use-this
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { PeerDescriptor, RingContacts } from '@streamr/dht'
|
|
2
2
|
import { EventEmitter } from 'eventemitter3'
|
|
3
|
-
import { Layer1Node } from '../../../src/logic/Layer1Node'
|
|
3
|
+
import { Layer1Node, Layer1NodeEvents } from '../../../src/logic/Layer1Node'
|
|
4
4
|
import { createMockPeerDescriptor } from '../utils'
|
|
5
5
|
|
|
6
|
-
export class MockLayer1Node extends EventEmitter implements Layer1Node {
|
|
6
|
+
export class MockLayer1Node extends EventEmitter<Layer1NodeEvents> implements Layer1Node {
|
|
7
7
|
|
|
8
8
|
private readonly kbucketPeers: PeerDescriptor[] = []
|
|
9
9
|
private closestContacts: PeerDescriptor[] = []
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { ITransport, PeerDescriptor } from '@streamr/dht'
|
|
2
|
+
import { TransportEvents } from '@streamr/dht'
|
|
2
3
|
import { EventEmitter } from 'eventemitter3'
|
|
3
4
|
|
|
4
|
-
export class MockTransport extends EventEmitter implements ITransport {
|
|
5
|
+
export class MockTransport extends EventEmitter<TransportEvents> implements ITransport {
|
|
5
6
|
|
|
6
7
|
// eslint-disable-next-line class-methods-use-this
|
|
7
8
|
async send(): Promise<void> {
|
|
@@ -13,21 +14,6 @@ export class MockTransport extends EventEmitter implements ITransport {
|
|
|
13
14
|
return PeerDescriptor.create()
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
// eslint-disable-next-line class-methods-use-this
|
|
17
|
-
getConnections(): PeerDescriptor[] {
|
|
18
|
-
return []
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line class-methods-use-this
|
|
22
|
-
getConnectionCount(): number {
|
|
23
|
-
return 0
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// eslint-disable-next-line class-methods-use-this
|
|
27
|
-
hasConnection(): boolean {
|
|
28
|
-
return false
|
|
29
|
-
}
|
|
30
|
-
|
|
31
17
|
// eslint-disable-next-line class-methods-use-this
|
|
32
18
|
stop(): void {
|
|
33
19
|
}
|
package/test/utils/utils.ts
CHANGED
|
@@ -47,6 +47,7 @@ export const createMockContentDeliveryLayerNodeAndDhtNode = async (
|
|
|
47
47
|
await mockCm.start()
|
|
48
48
|
const layer1Node = new DhtNode({
|
|
49
49
|
transport: mockCm,
|
|
50
|
+
connectionsView: mockCm,
|
|
50
51
|
peerDescriptor: localPeerDescriptor,
|
|
51
52
|
numberOfNodesPerKBucket: 4,
|
|
52
53
|
entryPoints: [entryPointDescriptor],
|
|
@@ -134,6 +135,7 @@ export const createNetworkNodeWithSimulator = async (
|
|
|
134
135
|
peerDescriptor,
|
|
135
136
|
entryPoints,
|
|
136
137
|
transport,
|
|
138
|
+
connectionsView: transport,
|
|
137
139
|
maxConnections: 25,
|
|
138
140
|
storeHighestTtl: 120000,
|
|
139
141
|
storeMaxTtl: 120000
|