@streamr/trackerless-network 102.0.0-beta.0 → 102.0.0-beta.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/generated/google/protobuf/any.js.map +1 -0
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/generated/google/protobuf/timestamp.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.d.ts +9 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.js +7 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.d.ts +32 -8
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.js +23 -7
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.d.ts +5 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/generated/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -0
- package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.d.ts +3 -3
- package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.js +1 -1
- package/dist/generated/packages/trackerless-network/protos/NetworkRpc.js.map +1 -0
- package/dist/generated/packages/trackerless-network/protos/NetworkRpc.server.js.map +1 -0
- package/dist/package.json +9 -10
- package/dist/src/NetworkNode.d.ts +4 -3
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +2 -2
- package/dist/src/NetworkStack.js +4 -4
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +3 -2
- package/dist/src/exports.js +3 -2
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/ContentDeliveryLayerNode.d.ts +2 -1
- package/dist/src/logic/ContentDeliveryLayerNode.js +5 -5
- package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -1
- package/dist/src/logic/ContentDeliveryManager.d.ts +2 -1
- package/dist/src/logic/ContentDeliveryManager.js +2 -1
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
- package/dist/src/logic/ContentDeliveryRpcLocal.d.ts +3 -3
- package/dist/src/logic/ContentDeliveryRpcLocal.js +1 -1
- package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/ContentDeliveryRpcRemote.d.ts +2 -2
- package/dist/src/logic/ControlLayerNode.d.ts +1 -1
- package/dist/src/logic/DiscoveryLayerNode.d.ts +3 -3
- package/dist/src/logic/DuplicateMessageDetector.js +1 -1
- package/dist/src/logic/DuplicateMessageDetector.js.map +1 -1
- package/dist/src/logic/PeerDescriptorStoreManager.d.ts +1 -1
- package/dist/src/logic/PeerDescriptorStoreManager.js +1 -1
- package/dist/src/logic/PeerDescriptorStoreManager.js.map +1 -1
- package/dist/src/logic/inspect/InspectSession.d.ts +2 -2
- package/dist/src/logic/inspect/InspectSession.js +2 -2
- package/dist/src/logic/inspect/InspectSession.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +1 -1
- package/dist/src/logic/inspect/Inspector.js +1 -1
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/Handshaker.js +2 -2
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +2 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.d.ts +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.d.ts +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.js +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcLocal.d.ts +2 -2
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcRemote.d.ts +2 -2
- package/dist/src/logic/propagation/Propagation.d.ts +1 -1
- package/dist/src/logic/propagation/PropagationTaskStore.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +1 -2
- package/dist/src/logic/proxy/ProxyClient.js +2 -3
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +2 -2
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +4 -4
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.d.ts +2 -2
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +4 -4
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +1 -1
- package/dist/src/logic/utils.d.ts +1 -1
- package/dist/src/logic/utils.js +2 -2
- package/dist/src/logic/utils.js.map +1 -1
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/test/benchmark/first-message.js +2 -2
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +2 -2
- package/dist/test/utils/utils.js +5 -4
- package/dist/test/utils/utils.js.map +1 -1
- package/jest.config.ts +13 -0
- package/package.json +9 -10
- package/proto.sh +2 -2
- package/protos/NetworkRpc.proto +2 -3
- package/.eslintignore +0 -7
- package/.eslintrc +0 -3
- package/dist/src/proto/google/protobuf/any.js.map +0 -1
- package/dist/src/proto/google/protobuf/empty.js.map +0 -1
- package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +0 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +0 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.js.map +0 -1
- package/jest.config.js +0 -8
- package/src/NetworkNode.ts +0 -141
- package/src/NetworkStack.ts +0 -198
- package/src/exports.ts +0 -16
- package/src/logic/ContentDeliveryLayerNode.ts +0 -424
- package/src/logic/ContentDeliveryManager.ts +0 -399
- package/src/logic/ContentDeliveryRpcLocal.ts +0 -48
- package/src/logic/ContentDeliveryRpcRemote.ts +0 -44
- package/src/logic/ControlLayerNode.ts +0 -17
- package/src/logic/DiscoveryLayerNode.ts +0 -30
- package/src/logic/DuplicateMessageDetector.ts +0 -167
- package/src/logic/ExternalNetworkRpc.ts +0 -42
- package/src/logic/NodeList.ts +0 -114
- package/src/logic/PeerDescriptorStoreManager.ts +0 -96
- package/src/logic/StreamPartNetworkSplitAvoidance.ts +0 -90
- package/src/logic/StreamPartReconnect.ts +0 -38
- package/src/logic/createContentDeliveryLayerNode.ts +0 -130
- package/src/logic/formStreamPartDeliveryServiceId.ts +0 -7
- package/src/logic/inspect/InspectSession.ts +0 -54
- package/src/logic/inspect/Inspector.ts +0 -100
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +0 -138
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +0 -66
- package/src/logic/neighbor-discovery/Handshaker.ts +0 -215
- package/src/logic/neighbor-discovery/NeighborFinder.ts +0 -77
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +0 -69
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +0 -75
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +0 -35
- package/src/logic/node-info/NodeInfoClient.ts +0 -23
- package/src/logic/node-info/NodeInfoRpcLocal.ts +0 -28
- package/src/logic/node-info/NodeInfoRpcRemote.ts +0 -11
- package/src/logic/propagation/FifoMapWithTTL.ts +0 -116
- package/src/logic/propagation/Propagation.ts +0 -84
- package/src/logic/propagation/PropagationTaskStore.ts +0 -41
- package/src/logic/proxy/ProxyClient.ts +0 -287
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +0 -106
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +0 -26
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +0 -73
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +0 -29
- package/src/logic/utils.ts +0 -18
- package/src/proto/google/protobuf/any.ts +0 -326
- package/src/proto/google/protobuf/empty.ts +0 -81
- package/src/proto/google/protobuf/timestamp.ts +0 -287
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +0 -407
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +0 -160
- package/src/proto/packages/dht/protos/DhtRpc.ts +0 -1244
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +0 -218
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +0 -85
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +0 -783
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +0 -60
- package/test/benchmark/first-message.ts +0 -169
- package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +0 -160
- package/test/end-to-end/external-network-rpc.test.ts +0 -67
- package/test/end-to-end/inspect.test.ts +0 -124
- package/test/end-to-end/proxy-and-full-node.test.ts +0 -143
- package/test/end-to-end/proxy-connections.test.ts +0 -228
- package/test/end-to-end/proxy-key-exchange.test.ts +0 -126
- package/test/end-to-end/webrtc-full-node-network.test.ts +0 -85
- package/test/end-to-end/websocket-full-node-network.test.ts +0 -84
- package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +0 -139
- package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +0 -162
- package/test/integration/ContentDeliveryManager.test.ts +0 -157
- package/test/integration/ContentDeliveryRpcRemote.test.ts +0 -100
- package/test/integration/HandshakeRpcRemote.test.ts +0 -79
- package/test/integration/Handshakes.test.ts +0 -176
- package/test/integration/Inspect.test.ts +0 -89
- package/test/integration/NeighborUpdateRpcRemote.test.ts +0 -82
- package/test/integration/NetworkNode.test.ts +0 -115
- package/test/integration/NetworkRpc.test.ts +0 -52
- package/test/integration/NetworkStack.test.ts +0 -72
- package/test/integration/NodeInfoRpc.test.ts +0 -109
- package/test/integration/Propagation.test.ts +0 -76
- package/test/integration/joining-streams-on-offline-peers.test.ts +0 -82
- package/test/integration/stream-without-default-entrypoints.test.ts +0 -128
- package/test/integration/streamEntryPointReplacing.test.ts +0 -97
- package/test/types/global.d.ts +0 -2
- package/test/unit/ContentDeliveryLayerNode.test.ts +0 -112
- package/test/unit/ContentDeliveryManager.test.ts +0 -95
- package/test/unit/ContentDeliveryRpcLocal.test.ts +0 -60
- package/test/unit/DuplicateMessageDetector.test.ts +0 -192
- package/test/unit/ExternalNetworkRpc.test.ts +0 -48
- package/test/unit/FifoMapWithTtl.test.ts +0 -253
- package/test/unit/HandshakeRpcLocal.test.ts +0 -168
- package/test/unit/Handshaker.test.ts +0 -69
- package/test/unit/InspectSession.test.ts +0 -80
- package/test/unit/Inspector.test.ts +0 -51
- package/test/unit/NeighborFinder.test.ts +0 -51
- package/test/unit/NeighborUpdateRpcLocal.test.ts +0 -139
- package/test/unit/NetworkNode.test.ts +0 -42
- package/test/unit/NodeList.test.ts +0 -164
- package/test/unit/NumberPair.test.ts +0 -22
- package/test/unit/PeerDescriptorStoreManager.test.ts +0 -103
- package/test/unit/Propagation.test.ts +0 -151
- package/test/unit/ProxyConnectionRpcRemote.test.ts +0 -39
- package/test/unit/StreamPartIDDataKey.test.ts +0 -12
- package/test/unit/StreamPartNetworkSplitAvoidance.test.ts +0 -31
- package/test/unit/StreamPartReconnect.test.ts +0 -30
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +0 -38
- package/test/utils/fake/FakePeerDescriptorStoreManager.ts +0 -29
- package/test/utils/mock/MockConnectionsView.ts +0 -18
- package/test/utils/mock/MockControlLayerNode.ts +0 -78
- package/test/utils/mock/MockDiscoveryLayerNode.ts +0 -60
- package/test/utils/mock/MockHandshaker.ts +0 -17
- package/test/utils/mock/MockNeighborFinder.ts +0 -20
- package/test/utils/mock/MockNeighborUpdateManager.ts +0 -21
- package/test/utils/mock/MockTransport.ts +0 -30
- package/test/utils/utils.ts +0 -143
- package/tsconfig.browser.json +0 -12
- package/tsconfig.jest.json +0 -16
- package/tsconfig.json +0 -3
- package/tsconfig.node.json +0 -16
- /package/dist/{src/proto → generated}/google/protobuf/any.d.ts +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/any.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/empty.d.ts +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/empty.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/timestamp.d.ts +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/timestamp.js +0 -0
- /package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.js +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.js +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.client.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.client.js +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.server.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.server.js +0 -0
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
ListeningRpcCommunicator,
|
|
3
|
-
NodeType,
|
|
4
|
-
PeerDescriptor,
|
|
5
|
-
randomDhtAddress,
|
|
6
|
-
toDhtAddress,
|
|
7
|
-
toNodeId,
|
|
8
|
-
} from '@streamr/dht'
|
|
9
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
10
|
-
import { expect } from 'expect'
|
|
11
|
-
import { ContentDeliveryRpcRemote } from '../../src/logic/ContentDeliveryRpcRemote'
|
|
12
|
-
import { NodeList } from '../../src/logic/NodeList'
|
|
13
|
-
import { formStreamPartContentDeliveryServiceId } from '../../src/logic/formStreamPartDeliveryServiceId'
|
|
14
|
-
import { ContentDeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
15
|
-
import { MockTransport } from '../utils/mock/MockTransport'
|
|
16
|
-
import { createMockContentDeliveryRpcRemote, createMockPeerDescriptor } from '../utils/utils'
|
|
17
|
-
|
|
18
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
19
|
-
|
|
20
|
-
describe('NodeList', () => {
|
|
21
|
-
|
|
22
|
-
const ids = [
|
|
23
|
-
new Uint8Array([1, 1, 1]),
|
|
24
|
-
new Uint8Array([1, 1, 2]),
|
|
25
|
-
new Uint8Array([1, 1, 3]),
|
|
26
|
-
new Uint8Array([1, 1, 4]),
|
|
27
|
-
new Uint8Array([1, 1, 5])
|
|
28
|
-
]
|
|
29
|
-
const ownId = randomDhtAddress()
|
|
30
|
-
let nodeList: NodeList
|
|
31
|
-
|
|
32
|
-
const createRemoteGraphNode = (peerDescriptor: PeerDescriptor) => {
|
|
33
|
-
const mockCommunicator = new ListeningRpcCommunicator(formStreamPartContentDeliveryServiceId(streamPartId), new MockTransport())
|
|
34
|
-
return new ContentDeliveryRpcRemote(
|
|
35
|
-
createMockPeerDescriptor(),
|
|
36
|
-
peerDescriptor,
|
|
37
|
-
mockCommunicator,
|
|
38
|
-
ContentDeliveryRpcClient
|
|
39
|
-
)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
beforeEach(() => {
|
|
43
|
-
nodeList = new NodeList(ownId, 6)
|
|
44
|
-
for (const id of ids) {
|
|
45
|
-
const peerDescriptor: PeerDescriptor = {
|
|
46
|
-
nodeId: id,
|
|
47
|
-
type: NodeType.NODEJS
|
|
48
|
-
}
|
|
49
|
-
nodeList.add(createRemoteGraphNode(peerDescriptor))
|
|
50
|
-
}
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('add', () => {
|
|
54
|
-
const newDescriptor = {
|
|
55
|
-
nodeId: new Uint8Array([1, 2, 3]),
|
|
56
|
-
type: NodeType.NODEJS
|
|
57
|
-
}
|
|
58
|
-
const newNode = createRemoteGraphNode(newDescriptor)
|
|
59
|
-
nodeList.add(newNode)
|
|
60
|
-
expect(nodeList.has(toNodeId(newDescriptor))).toEqual(true)
|
|
61
|
-
|
|
62
|
-
const newDescriptor2 = {
|
|
63
|
-
nodeId: new Uint8Array([1, 2, 4]),
|
|
64
|
-
type: NodeType.NODEJS
|
|
65
|
-
}
|
|
66
|
-
const newNode2 = createRemoteGraphNode(newDescriptor2)
|
|
67
|
-
nodeList.add(newNode2)
|
|
68
|
-
expect(nodeList.has(toNodeId(newDescriptor2))).toEqual(false)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('remove', () => {
|
|
72
|
-
const toRemove = nodeList.getFirst([])
|
|
73
|
-
const nodeId = toNodeId(toRemove!.getPeerDescriptor())
|
|
74
|
-
nodeList.remove(nodeId)
|
|
75
|
-
expect(nodeList.has(nodeId)).toEqual(false)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
it('getFirst', () => {
|
|
79
|
-
const closest = nodeList.getFirst([])
|
|
80
|
-
expect(toNodeId(closest!.getPeerDescriptor()))
|
|
81
|
-
.toEqual(toDhtAddress(new Uint8Array([1, 1, 1])))
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
it('getFirst with exclude', () => {
|
|
85
|
-
const closest = nodeList.getFirst([toDhtAddress(new Uint8Array([1, 1, 1]))])
|
|
86
|
-
expect(toNodeId(closest!.getPeerDescriptor()))
|
|
87
|
-
.toEqual(toDhtAddress(new Uint8Array([1, 1, 2])))
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('getFirst wsOnly', () => {
|
|
91
|
-
nodeList.add(createMockContentDeliveryRpcRemote(createMockPeerDescriptor({ websocket: { port: 111, host: '', tls: false } })))
|
|
92
|
-
const closest = nodeList.getFirst([], true)
|
|
93
|
-
expect(closest).toBeDefined()
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('getLast', () => {
|
|
97
|
-
const closest = nodeList.getLast([])
|
|
98
|
-
expect(toNodeId(closest!.getPeerDescriptor()))
|
|
99
|
-
.toEqual(toDhtAddress(new Uint8Array([1, 1, 5])))
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('getLast with exclude', () => {
|
|
103
|
-
const closest = nodeList.getLast([toDhtAddress(new Uint8Array([1, 1, 5]))])
|
|
104
|
-
expect(toNodeId(closest!.getPeerDescriptor()))
|
|
105
|
-
.toEqual(toDhtAddress(new Uint8Array([1, 1, 4])))
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('getFirstAndLast', () => {
|
|
109
|
-
const results = nodeList.getFirstAndLast([])
|
|
110
|
-
expect(results).toEqual([nodeList.getFirst([]), nodeList.getLast([])])
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('getFirst empty', () => {
|
|
114
|
-
const emptyList = new NodeList(ownId, 2)
|
|
115
|
-
expect(emptyList.getFirst([])).toBeUndefined()
|
|
116
|
-
})
|
|
117
|
-
|
|
118
|
-
it('getLast empty', () => {
|
|
119
|
-
const emptyList = new NodeList(ownId, 2)
|
|
120
|
-
expect(emptyList.getLast([])).toBeUndefined()
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('getRandom empty', () => {
|
|
124
|
-
const emptyList = new NodeList(ownId, 2)
|
|
125
|
-
expect(emptyList.getRandom([])).toBeUndefined()
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('getFirstAndLast empty', () => {
|
|
129
|
-
const emptyList = new NodeList(ownId, 2)
|
|
130
|
-
expect(emptyList.getFirstAndLast([])).toEqual([])
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('getFirstAndLast with exclude', () => {
|
|
134
|
-
const results = nodeList.getFirstAndLast([
|
|
135
|
-
toDhtAddress(new Uint8Array([1, 1, 1])),
|
|
136
|
-
toDhtAddress(new Uint8Array([1, 1, 5]))
|
|
137
|
-
])
|
|
138
|
-
expect(results).toEqual([
|
|
139
|
-
nodeList.getFirst([toDhtAddress(new Uint8Array([1, 1, 1]))]),
|
|
140
|
-
nodeList.getLast([toDhtAddress(new Uint8Array([1, 1, 5]))])
|
|
141
|
-
])
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('items are in insertion order', () => {
|
|
145
|
-
const list = new NodeList(randomDhtAddress(), 100)
|
|
146
|
-
const item1 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
147
|
-
const item2 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
148
|
-
const item3 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
149
|
-
const item4 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
150
|
-
const item5 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
151
|
-
const item6 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
152
|
-
list.add(item2)
|
|
153
|
-
list.add(item3)
|
|
154
|
-
list.add(item1)
|
|
155
|
-
list.add(item6)
|
|
156
|
-
list.add(item4)
|
|
157
|
-
list.add(item5)
|
|
158
|
-
expect(list.getFirst([])!).toEqual(item2)
|
|
159
|
-
expect(list.getLast([])!).toEqual(item5)
|
|
160
|
-
// the order doesn't change if item re-added
|
|
161
|
-
list.add(item4)
|
|
162
|
-
expect(list.getLast([])!).toEqual(item5)
|
|
163
|
-
})
|
|
164
|
-
})
|
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { NumberPair } from '../../src/logic/DuplicateMessageDetector'
|
|
2
|
-
|
|
3
|
-
test('equalTo', () => {
|
|
4
|
-
expect(new NumberPair(5, 2).equalTo(new NumberPair(5, 3))).toEqual(false)
|
|
5
|
-
expect(new NumberPair(5, 2).equalTo(new NumberPair(5, 2))).toEqual(true)
|
|
6
|
-
})
|
|
7
|
-
|
|
8
|
-
test('greaterThan', () => {
|
|
9
|
-
expect(new NumberPair(5, 2).greaterThan(new NumberPair(6, 2))).toEqual(false)
|
|
10
|
-
expect(new NumberPair(5, 2).greaterThan(new NumberPair(5, 3))).toEqual(false)
|
|
11
|
-
expect(new NumberPair(5, 2).greaterThan(new NumberPair(5, 2))).toEqual(false)
|
|
12
|
-
expect(new NumberPair(5, 2).greaterThan(new NumberPair(5, 1))).toEqual(true)
|
|
13
|
-
expect(new NumberPair(5, 2).greaterThan(new NumberPair(3, 2))).toEqual(true)
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
test('greaterThanOrEqual', () => {
|
|
17
|
-
expect(new NumberPair(5, 2).greaterThanOrEqual(new NumberPair(6, 2))).toEqual(false)
|
|
18
|
-
expect(new NumberPair(5, 2).greaterThanOrEqual(new NumberPair(5, 3))).toEqual(false)
|
|
19
|
-
expect(new NumberPair(5, 2).greaterThanOrEqual(new NumberPair(5, 2))).toEqual(true)
|
|
20
|
-
expect(new NumberPair(5, 2).greaterThanOrEqual(new NumberPair(5, 1))).toEqual(true)
|
|
21
|
-
expect(new NumberPair(5, 2).greaterThanOrEqual(new NumberPair(3, 2))).toEqual(true)
|
|
22
|
-
})
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor, areEqualPeerDescriptors, randomDhtAddress } from '@streamr/dht'
|
|
2
|
-
import { wait } from '@streamr/utils'
|
|
3
|
-
import { PeerDescriptorStoreManager } from '../../src/logic/PeerDescriptorStoreManager'
|
|
4
|
-
import { Any } from '../../src/proto/google/protobuf/any'
|
|
5
|
-
import { DataEntry } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
-
|
|
8
|
-
const KEY = randomDhtAddress()
|
|
9
|
-
|
|
10
|
-
describe('PeerDescriptorStoreManager', () => {
|
|
11
|
-
|
|
12
|
-
let withData: PeerDescriptorStoreManager
|
|
13
|
-
let withoutData: PeerDescriptorStoreManager
|
|
14
|
-
let storeCalled: number
|
|
15
|
-
|
|
16
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
17
|
-
const deletedPeerDescriptor = createMockPeerDescriptor()
|
|
18
|
-
|
|
19
|
-
const fakeData: DataEntry = {
|
|
20
|
-
key: Uint8Array.from([1, 2, 3]),
|
|
21
|
-
data: Any.pack(peerDescriptor, PeerDescriptor),
|
|
22
|
-
creator: peerDescriptor.nodeId,
|
|
23
|
-
ttl: 1000,
|
|
24
|
-
stale: false,
|
|
25
|
-
deleted: false
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const fakeDeletedData: DataEntry = {
|
|
29
|
-
key: Uint8Array.from([1, 2, 3]),
|
|
30
|
-
data: Any.pack(deletedPeerDescriptor, PeerDescriptor),
|
|
31
|
-
creator: deletedPeerDescriptor.nodeId,
|
|
32
|
-
ttl: 1000,
|
|
33
|
-
stale: false,
|
|
34
|
-
deleted: true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const fakeFetchDataFromDht = async (): Promise<DataEntry[]> => {
|
|
38
|
-
return [fakeData, fakeDeletedData]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const fakeStoreDataToDht = async (): Promise<PeerDescriptor[]> => {
|
|
42
|
-
storeCalled++
|
|
43
|
-
return [peerDescriptor]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const fakeEmptyFetchDataFromDht = async (): Promise<DataEntry[]> => {
|
|
47
|
-
return []
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const fakeDeleteDataFromDht = async (): Promise<void> => {}
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
storeCalled = 0
|
|
54
|
-
withData = new PeerDescriptorStoreManager({
|
|
55
|
-
localPeerDescriptor: peerDescriptor,
|
|
56
|
-
key: KEY,
|
|
57
|
-
fetchDataFromDht: fakeFetchDataFromDht,
|
|
58
|
-
storeDataToDht: fakeStoreDataToDht,
|
|
59
|
-
deleteDataFromDht: fakeDeleteDataFromDht,
|
|
60
|
-
storeInterval: 2000
|
|
61
|
-
})
|
|
62
|
-
withoutData = new PeerDescriptorStoreManager({
|
|
63
|
-
localPeerDescriptor: peerDescriptor,
|
|
64
|
-
key: KEY,
|
|
65
|
-
fetchDataFromDht: fakeEmptyFetchDataFromDht,
|
|
66
|
-
storeDataToDht: fakeStoreDataToDht,
|
|
67
|
-
deleteDataFromDht: fakeDeleteDataFromDht,
|
|
68
|
-
storeInterval: 2000
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
withData.destroy()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('discoverEntryPoints filters deleted data', async () => {
|
|
77
|
-
const res = await withData.fetchNodes()
|
|
78
|
-
expect(res.length).toBe(1)
|
|
79
|
-
expect(areEqualPeerDescriptors(res[0], peerDescriptor)).toBe(true)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('discoverEntryPoints without results', async () => {
|
|
83
|
-
const res = await withoutData.fetchNodes()
|
|
84
|
-
expect(res.length).toBe(0)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('store on stream without saturated entrypoint count', async () => {
|
|
88
|
-
await withData.storeAndKeepLocalNode()
|
|
89
|
-
expect(storeCalled).toEqual(1)
|
|
90
|
-
expect(withData.isLocalNodeStored()).toEqual(true)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('will keep stored until destroyed', async () => {
|
|
94
|
-
await withData.storeAndKeepLocalNode()
|
|
95
|
-
expect(storeCalled).toEqual(1)
|
|
96
|
-
expect(withData.isLocalNodeStored()).toEqual(true)
|
|
97
|
-
await wait(4500)
|
|
98
|
-
await withData.destroy()
|
|
99
|
-
// we have configured storeInterval to 2 seconds, i.e. after 4.5 seconds it should have been called 2 more items
|
|
100
|
-
expect(storeCalled).toEqual(3)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
})
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { DhtAddress } from '@streamr/dht'
|
|
2
|
-
import { hexToBinary, wait } from '@streamr/utils'
|
|
3
|
-
import { Propagation } from '../../src/logic/propagation/Propagation'
|
|
4
|
-
import {
|
|
5
|
-
ContentType,
|
|
6
|
-
EncryptionType,
|
|
7
|
-
MessageID,
|
|
8
|
-
SignatureType,
|
|
9
|
-
StreamMessage
|
|
10
|
-
} from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
11
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
12
|
-
|
|
13
|
-
const PUBLISHER_ID = randomUserId()
|
|
14
|
-
|
|
15
|
-
function makeMsg(streamId: string, partition: number, ts: number, msgNo: number): StreamMessage {
|
|
16
|
-
const messageId: MessageID = {
|
|
17
|
-
streamId,
|
|
18
|
-
streamPartition: partition,
|
|
19
|
-
timestamp: ts,
|
|
20
|
-
sequenceNumber: msgNo,
|
|
21
|
-
messageChainId: 'msgChain',
|
|
22
|
-
publisherId: hexToBinary(PUBLISHER_ID)
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
messageId,
|
|
26
|
-
signature: hexToBinary('0x1111'),
|
|
27
|
-
signatureType: SignatureType.SECP256K1,
|
|
28
|
-
body: {
|
|
29
|
-
oneofKind: 'contentMessage',
|
|
30
|
-
contentMessage: {
|
|
31
|
-
content: new Uint8Array([1]),
|
|
32
|
-
contentType: ContentType.JSON,
|
|
33
|
-
encryptionType: EncryptionType.NONE
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const TTL = 100
|
|
40
|
-
|
|
41
|
-
const N1 = 'n1' as DhtAddress
|
|
42
|
-
const N2 = 'n2' as DhtAddress
|
|
43
|
-
const N3 = 'n3' as DhtAddress
|
|
44
|
-
const N4 = 'n4' as DhtAddress
|
|
45
|
-
const N5 = 'n5' as DhtAddress
|
|
46
|
-
|
|
47
|
-
describe(Propagation, () => {
|
|
48
|
-
let getNeighbors: jest.Mock<ReadonlyArray<DhtAddress>, [string]>
|
|
49
|
-
let sendToNeighbor: jest.Mock<Promise<void>, [DhtAddress, StreamMessage]>
|
|
50
|
-
let propagation: Propagation
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
getNeighbors = jest.fn()
|
|
54
|
-
sendToNeighbor = jest.fn()
|
|
55
|
-
propagation = new Propagation({
|
|
56
|
-
sendToNeighbor,
|
|
57
|
-
minPropagationTargets: 3,
|
|
58
|
-
ttl: TTL,
|
|
59
|
-
maxMessages: 5
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
describe('#feedUnseenMessage', () => {
|
|
64
|
-
it('message is propagated to nodes returned by getNeighbors', () => {
|
|
65
|
-
getNeighbors.mockReturnValueOnce([N1, N2, N3])
|
|
66
|
-
const msg = makeMsg('s1', 0, 1000, 1)
|
|
67
|
-
propagation.feedUnseenMessage(msg, [...getNeighbors('s1#0')], null)
|
|
68
|
-
|
|
69
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(3)
|
|
70
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N1, msg)
|
|
71
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(2, N2, msg)
|
|
72
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(3, N3, msg)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('message does not get propagated to source node (if present in getNeighbors)', () => {
|
|
76
|
-
getNeighbors.mockReturnValueOnce([N1, N2, N3])
|
|
77
|
-
const msg = makeMsg('s1', 0, 1000, 1)
|
|
78
|
-
propagation.feedUnseenMessage(msg, [...getNeighbors('s1#0')], N2)
|
|
79
|
-
|
|
80
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(2)
|
|
81
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N1, msg)
|
|
82
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(2, N3, msg)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
describe('#onNeighborJoined', () => {
|
|
87
|
-
let msg: StreamMessage
|
|
88
|
-
|
|
89
|
-
async function setUpAndFeed(neighbors: DhtAddress[]): Promise<void> {
|
|
90
|
-
getNeighbors.mockReturnValueOnce(neighbors)
|
|
91
|
-
msg = makeMsg('s1', 0, 1000, 1)
|
|
92
|
-
propagation.feedUnseenMessage(msg, [...getNeighbors('s1#0')], N2)
|
|
93
|
-
await wait(0)
|
|
94
|
-
sendToNeighbor.mockClear()
|
|
95
|
-
getNeighbors.mockClear()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
it('sends to new neighbor', async () => {
|
|
99
|
-
await setUpAndFeed([N1, N2, N3])
|
|
100
|
-
propagation.onNeighborJoined(N4)
|
|
101
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(1)
|
|
102
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N4, msg)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('sends to previously failed neighbor', async () => {
|
|
106
|
-
sendToNeighbor.mockImplementation(async (neighbor) => {
|
|
107
|
-
if (neighbor === N3) {
|
|
108
|
-
throw new Error('failed to send')
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
await setUpAndFeed([N1, N2, N3])
|
|
112
|
-
propagation.onNeighborJoined(N3)
|
|
113
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(1)
|
|
114
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N3, msg)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
it('no-op if passed source node', async () => {
|
|
118
|
-
await setUpAndFeed([N1, N2, N3])
|
|
119
|
-
propagation.onNeighborJoined(N2)
|
|
120
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('no-op if passed already handled neighbor', async () => {
|
|
124
|
-
await setUpAndFeed([N1, N2, N3])
|
|
125
|
-
propagation.onNeighborJoined(N3)
|
|
126
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('no-op if initially `minPropagationTargets` were propagated to', async () => {
|
|
130
|
-
await setUpAndFeed([N1, N2, N3, N4])
|
|
131
|
-
propagation.onNeighborJoined(N5)
|
|
132
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
it('no-op if later `minPropagationTargets` have been propagated to', async () => {
|
|
136
|
-
await setUpAndFeed([N1, N2, N3])
|
|
137
|
-
propagation.onNeighborJoined(N4)
|
|
138
|
-
await wait(0)
|
|
139
|
-
sendToNeighbor.mockClear()
|
|
140
|
-
propagation.onNeighborJoined(N5)
|
|
141
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('no-op if TTL expires', async () => {
|
|
145
|
-
await setUpAndFeed([N1, N2, N3])
|
|
146
|
-
await wait(200)
|
|
147
|
-
propagation.onNeighborJoined(N3)
|
|
148
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
3
|
-
import { hexToBinary } from '@streamr/utils'
|
|
4
|
-
import { ProxyConnectionRpcRemote } from '../../src/logic/proxy/ProxyConnectionRpcRemote'
|
|
5
|
-
import { ProxyConnectionRequest, ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
|
-
import { ProxyConnectionRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
7
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
|
-
|
|
9
|
-
describe('ProxyConnectionRpcRemote', () => {
|
|
10
|
-
|
|
11
|
-
it('happy path', async () => {
|
|
12
|
-
const onOutgoingMessage = jest.fn()
|
|
13
|
-
const rpcCommunicator = new RpcCommunicator()
|
|
14
|
-
rpcCommunicator.setOutgoingMessageListener(onOutgoingMessage)
|
|
15
|
-
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
16
|
-
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
17
|
-
const rpcRemote = new ProxyConnectionRpcRemote(
|
|
18
|
-
clientPeerDescriptor,
|
|
19
|
-
serverPeerDescriptor,
|
|
20
|
-
rpcCommunicator,
|
|
21
|
-
ProxyConnectionRpcClient
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const userId = randomUserId()
|
|
25
|
-
await rpcRemote.requestConnection(ProxyDirection.PUBLISH, userId)
|
|
26
|
-
|
|
27
|
-
const [rpcMessage, _, callContext] = onOutgoingMessage.mock.calls[0]
|
|
28
|
-
const request = ProxyConnectionRequest.fromBinary(rpcMessage.body.value)
|
|
29
|
-
expect(request).toEqual({
|
|
30
|
-
direction: ProxyDirection.PUBLISH,
|
|
31
|
-
userId: expect.toEqualBinary(hexToBinary(userId))
|
|
32
|
-
})
|
|
33
|
-
expect(callContext).toMatchObject({
|
|
34
|
-
sourceDescriptor: clientPeerDescriptor,
|
|
35
|
-
targetDescriptor: serverPeerDescriptor,
|
|
36
|
-
timeout: 5000
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
2
|
-
import { streamPartIdToDataKey } from '../../src/logic/ContentDeliveryManager'
|
|
3
|
-
|
|
4
|
-
describe('StreamPartIDtoDataKey', () => {
|
|
5
|
-
|
|
6
|
-
it('generated key length is correct (160 bits)', () => {
|
|
7
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
8
|
-
const dataKey = streamPartIdToDataKey(streamPartId)
|
|
9
|
-
expect(dataKey.length).toEqual(40)
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { MIN_NEIGHBOR_COUNT, StreamPartNetworkSplitAvoidance } from '../../src/logic/StreamPartNetworkSplitAvoidance'
|
|
2
|
-
import { MockDiscoveryLayerNode } from '../utils/mock/MockDiscoveryLayerNode'
|
|
3
|
-
|
|
4
|
-
describe('StreamPartNetworkSplitAvoidance', () => {
|
|
5
|
-
|
|
6
|
-
let avoidance: StreamPartNetworkSplitAvoidance
|
|
7
|
-
let discoveryLayerNode: MockDiscoveryLayerNode
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
discoveryLayerNode = new MockDiscoveryLayerNode()
|
|
11
|
-
avoidance = new StreamPartNetworkSplitAvoidance({
|
|
12
|
-
discoveryLayerNode,
|
|
13
|
-
discoverEntryPoints: async () => {
|
|
14
|
-
discoveryLayerNode.addNewRandomPeerToKBucket()
|
|
15
|
-
return discoveryLayerNode.getNeighbors()
|
|
16
|
-
},
|
|
17
|
-
exponentialRunOfBaseDelay: 1
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
discoveryLayerNode.stop()
|
|
23
|
-
avoidance.destroy()
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('runs avoidance until number of neighbors is above MIN_NEIGHBOR_COUNT', async () => {
|
|
27
|
-
await avoidance.avoidNetworkSplit()
|
|
28
|
-
expect(discoveryLayerNode.getNeighborCount()).toBeGreaterThan(MIN_NEIGHBOR_COUNT)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
})
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptorStoreManager } from '../../src/logic/PeerDescriptorStoreManager'
|
|
2
|
-
import { StreamPartReconnect } from '../../src/logic/StreamPartReconnect'
|
|
3
|
-
import { MockDiscoveryLayerNode } from '../utils/mock/MockDiscoveryLayerNode'
|
|
4
|
-
import { createFakePeerDescriptorStoreManager } from '../utils/fake/FakePeerDescriptorStoreManager'
|
|
5
|
-
import { waitForCondition } from '@streamr/utils'
|
|
6
|
-
|
|
7
|
-
describe('StreamPartReconnect', () => {
|
|
8
|
-
|
|
9
|
-
let peerDescriptorSoreManager: PeerDescriptorStoreManager
|
|
10
|
-
let discoveryLayerNode: MockDiscoveryLayerNode
|
|
11
|
-
let streamPartReconnect: StreamPartReconnect
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
peerDescriptorSoreManager = createFakePeerDescriptorStoreManager()
|
|
15
|
-
discoveryLayerNode = new MockDiscoveryLayerNode()
|
|
16
|
-
streamPartReconnect = new StreamPartReconnect(discoveryLayerNode, peerDescriptorSoreManager)
|
|
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
|
-
discoveryLayerNode.addNewRandomPeerToKBucket()
|
|
27
|
-
await waitForCondition(() => streamPartReconnect.isRunning() === false)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator, toDhtAddress } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
3
|
-
import { TemporaryConnectionRpcLocal } from '../../src/logic/temporary-connection/TemporaryConnectionRpcLocal'
|
|
4
|
-
import { MockTransport } from '../utils/mock/MockTransport'
|
|
5
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
6
|
-
|
|
7
|
-
describe('TemporaryConnectionRpcLocal', () => {
|
|
8
|
-
|
|
9
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
10
|
-
let rpcCommunicator: ListeningRpcCommunicator
|
|
11
|
-
let rpcLocal: TemporaryConnectionRpcLocal
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
rpcCommunicator = new ListeningRpcCommunicator('mock', new MockTransport())
|
|
15
|
-
rpcLocal = new TemporaryConnectionRpcLocal({
|
|
16
|
-
localPeerDescriptor: peerDescriptor,
|
|
17
|
-
rpcCommunicator,
|
|
18
|
-
streamPartId: StreamPartIDUtils.parse('mock#0'),
|
|
19
|
-
connectionLocker: {
|
|
20
|
-
weakLockConnection: jest.fn(),
|
|
21
|
-
weakUnlockConnection: jest.fn()
|
|
22
|
-
} as any
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
rpcCommunicator.destroy()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('Open and Close Connection', async () => {
|
|
31
|
-
const caller = createMockPeerDescriptor()
|
|
32
|
-
await rpcLocal.openConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
33
|
-
expect(rpcLocal.getNodes().get(toDhtAddress(caller.nodeId))).toBeDefined()
|
|
34
|
-
await rpcLocal.closeConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
35
|
-
expect(rpcLocal.getNodes().get(toDhtAddress(caller.nodeId))).toBeUndefined()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor } from '@streamr/dht'
|
|
2
|
-
import { PeerDescriptorStoreManager } from '../../../src/logic/PeerDescriptorStoreManager'
|
|
3
|
-
|
|
4
|
-
export const createFakePeerDescriptorStoreManager = (): PeerDescriptorStoreManager => {
|
|
5
|
-
return new FakePeerDescriptorStoreManager() as unknown as PeerDescriptorStoreManager
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class FakePeerDescriptorStoreManager {
|
|
9
|
-
|
|
10
|
-
private nodes: PeerDescriptor[] = []
|
|
11
|
-
|
|
12
|
-
setNodes(nodes: PeerDescriptor[]): void {
|
|
13
|
-
this.nodes = nodes
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async fetchNodes(): Promise<PeerDescriptor[]> {
|
|
17
|
-
return this.nodes
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line class-methods-use-this
|
|
21
|
-
async storeAndKeepLocalNode(): Promise<void> {
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line class-methods-use-this
|
|
25
|
-
isLocalNodeStored(): boolean {
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
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
|
-
}
|