@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,168 +0,0 @@
|
|
|
1
|
-
import { DhtAddress, NodeType, toNodeId, toDhtAddressRaw } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
3
|
-
import { NodeList } from '../../src/logic/NodeList'
|
|
4
|
-
import { HandshakeRpcLocal } from '../../src/logic/neighbor-discovery/HandshakeRpcLocal'
|
|
5
|
-
import { InterleaveRequest, StreamPartHandshakeRequest } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
|
-
import { createMockContentDeliveryRpcRemote, createMockHandshakeRpcRemote, createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
-
|
|
8
|
-
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
9
|
-
|
|
10
|
-
describe('HandshakeRpcLocal', () => {
|
|
11
|
-
|
|
12
|
-
let rpcLocal: HandshakeRpcLocal
|
|
13
|
-
|
|
14
|
-
const localPeerDescriptor = createMockPeerDescriptor()
|
|
15
|
-
|
|
16
|
-
let neighbors: NodeList
|
|
17
|
-
let ongoingHandshakes: Set<DhtAddress>
|
|
18
|
-
let ongoingInterleaves: Set<DhtAddress>
|
|
19
|
-
let handshakeWithInterleaving: jest.Mock
|
|
20
|
-
|
|
21
|
-
beforeEach(() => {
|
|
22
|
-
neighbors = new NodeList(toNodeId(localPeerDescriptor), 10)
|
|
23
|
-
ongoingHandshakes = new Set()
|
|
24
|
-
ongoingInterleaves = new Set()
|
|
25
|
-
handshakeWithInterleaving = jest.fn()
|
|
26
|
-
|
|
27
|
-
rpcLocal = new HandshakeRpcLocal({
|
|
28
|
-
streamPartId: STREAM_PART_ID,
|
|
29
|
-
ongoingHandshakes,
|
|
30
|
-
ongoingInterleaves,
|
|
31
|
-
createRpcRemote: (_p) => createMockHandshakeRpcRemote(),
|
|
32
|
-
createContentDeliveryRpcRemote: (_p) => createMockContentDeliveryRpcRemote(),
|
|
33
|
-
handshakeWithInterleaving: async (_p, _t) => {
|
|
34
|
-
handshakeWithInterleaving()
|
|
35
|
-
return true
|
|
36
|
-
},
|
|
37
|
-
neighbors,
|
|
38
|
-
maxNeighborCount: 4
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('handshake', async () => {
|
|
43
|
-
const req = StreamPartHandshakeRequest.create({
|
|
44
|
-
streamPartId: STREAM_PART_ID,
|
|
45
|
-
requestId: 'requestId'
|
|
46
|
-
})
|
|
47
|
-
const res = await rpcLocal.handshake(req, {
|
|
48
|
-
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
49
|
-
} as any)
|
|
50
|
-
expect(res.accepted).toEqual(true)
|
|
51
|
-
expect(res.interleaveTargetDescriptor).toBeUndefined()
|
|
52
|
-
expect(res.requestId).toEqual('requestId')
|
|
53
|
-
})
|
|
54
|
-
|
|
55
|
-
it('handshake interleave', async () => {
|
|
56
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
57
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
58
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
59
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
60
|
-
const req = StreamPartHandshakeRequest.create({
|
|
61
|
-
streamPartId: STREAM_PART_ID,
|
|
62
|
-
requestId: 'requestId'
|
|
63
|
-
})
|
|
64
|
-
const res = await rpcLocal.handshake(req, {
|
|
65
|
-
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
66
|
-
} as any)
|
|
67
|
-
expect(res.accepted).toEqual(true)
|
|
68
|
-
expect(res.interleaveTargetDescriptor).toBeDefined()
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('unaccepted handshake', async () => {
|
|
72
|
-
ongoingHandshakes.add('0x2222' as DhtAddress)
|
|
73
|
-
ongoingHandshakes.add('0x3333' as DhtAddress)
|
|
74
|
-
ongoingHandshakes.add('0x4444' as DhtAddress)
|
|
75
|
-
ongoingHandshakes.add('0x5555' as DhtAddress)
|
|
76
|
-
const req = StreamPartHandshakeRequest.create({
|
|
77
|
-
streamPartId: STREAM_PART_ID,
|
|
78
|
-
requestId: 'requestId'
|
|
79
|
-
})
|
|
80
|
-
const res = await rpcLocal.handshake(req, {
|
|
81
|
-
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
82
|
-
} as any)
|
|
83
|
-
expect(res.accepted).toEqual(false)
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
it('handshakeWithInterleaving success', async () => {
|
|
87
|
-
const req: InterleaveRequest = {
|
|
88
|
-
interleaveTargetDescriptor: {
|
|
89
|
-
nodeId: toDhtAddressRaw('0x2222' as DhtAddress),
|
|
90
|
-
type: NodeType.NODEJS
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
await rpcLocal.interleaveRequest(req, {
|
|
94
|
-
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
95
|
-
} as any)
|
|
96
|
-
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(1)
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('handshakeWithInterleaving success', async () => {
|
|
100
|
-
const req: InterleaveRequest = {
|
|
101
|
-
interleaveTargetDescriptor: {
|
|
102
|
-
nodeId: toDhtAddressRaw('0x2222' as DhtAddress),
|
|
103
|
-
type: NodeType.NODEJS
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
await rpcLocal.interleaveRequest(req, {
|
|
107
|
-
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
108
|
-
} as any)
|
|
109
|
-
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(1)
|
|
110
|
-
})
|
|
111
|
-
|
|
112
|
-
it('rejects handshakes if interleaving to the requestor is ongoing', async () => {
|
|
113
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
114
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
115
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
116
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
117
|
-
const requestor = createMockPeerDescriptor()
|
|
118
|
-
ongoingInterleaves.add(toNodeId(requestor))
|
|
119
|
-
const req = StreamPartHandshakeRequest.create({
|
|
120
|
-
streamPartId: STREAM_PART_ID,
|
|
121
|
-
requestId: 'requestId'
|
|
122
|
-
})
|
|
123
|
-
const res = await rpcLocal.handshake(req, {
|
|
124
|
-
incomingSourceDescriptor: requestor
|
|
125
|
-
} as any)
|
|
126
|
-
expect(res.accepted).toEqual(false)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('Rejects if interleaving is required and too many interleaving requests are ongoing', async () => {
|
|
130
|
-
const interleavingPeer1 = createMockPeerDescriptor()
|
|
131
|
-
const interleavingPeer2 = createMockPeerDescriptor()
|
|
132
|
-
const interleavingPeer3 = createMockPeerDescriptor()
|
|
133
|
-
neighbors.add(createMockContentDeliveryRpcRemote(interleavingPeer1))
|
|
134
|
-
neighbors.add(createMockContentDeliveryRpcRemote(interleavingPeer2))
|
|
135
|
-
neighbors.add(createMockContentDeliveryRpcRemote(interleavingPeer3))
|
|
136
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
137
|
-
ongoingInterleaves.add(toNodeId(interleavingPeer1))
|
|
138
|
-
ongoingInterleaves.add(toNodeId(interleavingPeer2))
|
|
139
|
-
ongoingInterleaves.add(toNodeId(interleavingPeer3))
|
|
140
|
-
const req = StreamPartHandshakeRequest.create({
|
|
141
|
-
streamPartId: STREAM_PART_ID,
|
|
142
|
-
requestId: 'requestId'
|
|
143
|
-
})
|
|
144
|
-
const res = await rpcLocal.handshake(req, {
|
|
145
|
-
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
146
|
-
} as any)
|
|
147
|
-
expect(res.accepted).toEqual(false)
|
|
148
|
-
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(0)
|
|
149
|
-
})
|
|
150
|
-
|
|
151
|
-
it('rejects handshakes if the requestor has more than maxNeighborCount neighbors', async () => {
|
|
152
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
153
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
154
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
155
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
156
|
-
neighbors.add(createMockContentDeliveryRpcRemote())
|
|
157
|
-
const req = StreamPartHandshakeRequest.create({
|
|
158
|
-
streamPartId: STREAM_PART_ID,
|
|
159
|
-
requestId: 'requestId'
|
|
160
|
-
})
|
|
161
|
-
const res = await rpcLocal.handshake(req, {
|
|
162
|
-
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
163
|
-
} as any)
|
|
164
|
-
expect(res.accepted).toEqual(false)
|
|
165
|
-
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(0)
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
})
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator, Simulator, SimulatorTransport, toNodeId } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
3
|
-
import { range } from 'lodash'
|
|
4
|
-
import { NodeList } from '../../src/logic/NodeList'
|
|
5
|
-
import { Handshaker } from '../../src/logic/neighbor-discovery/Handshaker'
|
|
6
|
-
import { createMockContentDeliveryRpcRemote, createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
-
|
|
8
|
-
describe('Handshaker', () => {
|
|
9
|
-
|
|
10
|
-
let handshaker: Handshaker
|
|
11
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
12
|
-
|
|
13
|
-
const maxNeighborCount = 4
|
|
14
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
15
|
-
|
|
16
|
-
let neighbors: NodeList
|
|
17
|
-
let leftNodeView: NodeList
|
|
18
|
-
let rightNodeView: NodeList
|
|
19
|
-
let nearbyNodeView: NodeList
|
|
20
|
-
let randomNodeView: NodeList
|
|
21
|
-
|
|
22
|
-
let simulator: Simulator
|
|
23
|
-
let simulatorTransport: SimulatorTransport
|
|
24
|
-
|
|
25
|
-
beforeEach(async () => {
|
|
26
|
-
simulator = new Simulator()
|
|
27
|
-
simulatorTransport = new SimulatorTransport(peerDescriptor, simulator)
|
|
28
|
-
await simulatorTransport.start()
|
|
29
|
-
const rpcCommunicator = new ListeningRpcCommunicator(streamPartId, simulatorTransport)
|
|
30
|
-
|
|
31
|
-
const nodeId = toNodeId(peerDescriptor)
|
|
32
|
-
neighbors = new NodeList(nodeId, 10)
|
|
33
|
-
leftNodeView = new NodeList(nodeId, 20)
|
|
34
|
-
rightNodeView = new NodeList(nodeId, 20)
|
|
35
|
-
nearbyNodeView = new NodeList(nodeId, 20)
|
|
36
|
-
randomNodeView = new NodeList(nodeId, 20)
|
|
37
|
-
|
|
38
|
-
handshaker = new Handshaker({
|
|
39
|
-
localPeerDescriptor: peerDescriptor,
|
|
40
|
-
streamPartId,
|
|
41
|
-
neighbors,
|
|
42
|
-
leftNodeView,
|
|
43
|
-
rightNodeView,
|
|
44
|
-
nearbyNodeView,
|
|
45
|
-
randomNodeView,
|
|
46
|
-
rpcCommunicator,
|
|
47
|
-
maxNeighborCount,
|
|
48
|
-
rpcRequestTimeout: 5000,
|
|
49
|
-
ongoingHandshakes: new Set()
|
|
50
|
-
})
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
afterEach(async () => {
|
|
54
|
-
await simulatorTransport.stop()
|
|
55
|
-
simulator.stop()
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
it('attemptHandshakesOnContact works with empty structures', async () => {
|
|
59
|
-
const res = await handshaker.attemptHandshakesOnContacts([])
|
|
60
|
-
expect(res.length).toEqual(0)
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
it('attemptHandshakesOnContact with known nodes that cannot be connected to', async () => {
|
|
64
|
-
range(2).forEach(() => randomNodeView.add(createMockContentDeliveryRpcRemote()))
|
|
65
|
-
const res = await handshaker.attemptHandshakesOnContacts([])
|
|
66
|
-
expect(res.length).toEqual(2)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
})
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import { InspectSession, Events } from '../../src/logic/inspect/InspectSession'
|
|
2
|
-
import { MessageID } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
|
-
import { waitForEvent3 } from '../../../utils/dist/src/waitForEvent3'
|
|
4
|
-
import { utf8ToBinary } from '@streamr/utils'
|
|
5
|
-
import { DhtAddress, randomDhtAddress } from '@streamr/dht'
|
|
6
|
-
|
|
7
|
-
describe('InspectSession', () => {
|
|
8
|
-
|
|
9
|
-
let inspectSession: InspectSession
|
|
10
|
-
let inspectedNode: DhtAddress
|
|
11
|
-
let anotherNode: DhtAddress
|
|
12
|
-
|
|
13
|
-
const publisherId = utf8ToBinary('publisherId')
|
|
14
|
-
const messageId1: MessageID = {
|
|
15
|
-
streamId: 'stream',
|
|
16
|
-
messageChainId: 'messageChain0',
|
|
17
|
-
streamPartition: 0,
|
|
18
|
-
sequenceNumber: 0,
|
|
19
|
-
timestamp: 12345,
|
|
20
|
-
publisherId
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const messageId2: MessageID = {
|
|
24
|
-
streamId: 'stream',
|
|
25
|
-
messageChainId: 'messageChain1',
|
|
26
|
-
streamPartition: 0,
|
|
27
|
-
sequenceNumber: 0,
|
|
28
|
-
timestamp: 12345,
|
|
29
|
-
publisherId
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
beforeEach(() => {
|
|
33
|
-
inspectedNode = randomDhtAddress()
|
|
34
|
-
anotherNode = randomDhtAddress()
|
|
35
|
-
inspectSession = new InspectSession({
|
|
36
|
-
inspectedNode
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
afterEach(() => {
|
|
41
|
-
inspectSession.stop()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('should mark message', () => {
|
|
45
|
-
inspectSession.markMessage(inspectedNode, messageId1)
|
|
46
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(1)
|
|
47
|
-
inspectSession.markMessage(inspectedNode, messageId2)
|
|
48
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(2)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
it('should emit done event when inspected node sends seen message', async () => {
|
|
52
|
-
inspectSession.markMessage(anotherNode, messageId1)
|
|
53
|
-
await Promise.all([
|
|
54
|
-
waitForEvent3<Events>(inspectSession, 'done', 100),
|
|
55
|
-
inspectSession.markMessage(inspectedNode, messageId1)
|
|
56
|
-
])
|
|
57
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(1)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
it('should emit done event another node sends message after inspected node', async () => {
|
|
61
|
-
inspectSession.markMessage(inspectedNode, messageId1)
|
|
62
|
-
await Promise.all([
|
|
63
|
-
waitForEvent3<Events>(inspectSession, 'done', 100),
|
|
64
|
-
inspectSession.markMessage(anotherNode, messageId1)
|
|
65
|
-
])
|
|
66
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(1)
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
it('should not emit done if messageIds do not match', async () => {
|
|
70
|
-
inspectSession.markMessage(inspectedNode, messageId1)
|
|
71
|
-
await expect(async () => {
|
|
72
|
-
await Promise.all([
|
|
73
|
-
waitForEvent3<Events>(inspectSession, 'done', 100),
|
|
74
|
-
inspectSession.markMessage(anotherNode, messageId2)
|
|
75
|
-
])
|
|
76
|
-
}).rejects.toThrow('waitForEvent3')
|
|
77
|
-
|
|
78
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(2)
|
|
79
|
-
})
|
|
80
|
-
})
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator, randomDhtAddress, toNodeId } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils, utf8ToBinary } from '@streamr/utils'
|
|
3
|
-
import { Inspector } from '../../src/logic/inspect/Inspector'
|
|
4
|
-
import { MockTransport } from '../utils/mock/MockTransport'
|
|
5
|
-
import { createMockPeerDescriptor, mockConnectionLocker } from '../utils/utils'
|
|
6
|
-
|
|
7
|
-
describe('Inspector', () => {
|
|
8
|
-
|
|
9
|
-
let inspector: Inspector
|
|
10
|
-
const inspectorDescriptor = createMockPeerDescriptor()
|
|
11
|
-
|
|
12
|
-
const inspectedDescriptor = createMockPeerDescriptor()
|
|
13
|
-
|
|
14
|
-
const nodeId = randomDhtAddress()
|
|
15
|
-
let mockConnect: jest.Mock
|
|
16
|
-
|
|
17
|
-
const messageRef = {
|
|
18
|
-
streamId: 'stream',
|
|
19
|
-
messageChainId: 'messageChain0',
|
|
20
|
-
streamPartition: 0,
|
|
21
|
-
sequenceNumber: 0,
|
|
22
|
-
timestamp: 12345,
|
|
23
|
-
publisherId: utf8ToBinary('publisher')
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
mockConnect = jest.fn(() => {})
|
|
28
|
-
inspector = new Inspector({
|
|
29
|
-
localPeerDescriptor: inspectorDescriptor,
|
|
30
|
-
streamPartId: StreamPartIDUtils.parse('stream#0'),
|
|
31
|
-
rpcCommunicator: new ListeningRpcCommunicator('inspector', new MockTransport()),
|
|
32
|
-
connectionLocker: mockConnectionLocker,
|
|
33
|
-
openInspectConnection: async () => mockConnect()
|
|
34
|
-
})
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
afterEach(() => {
|
|
38
|
-
inspector.stop()
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it('Opens inspection connection and runs successfully', async () => {
|
|
42
|
-
setTimeout(() => {
|
|
43
|
-
inspector.markMessage(toNodeId(inspectedDescriptor), messageRef)
|
|
44
|
-
inspector.markMessage(nodeId, messageRef)
|
|
45
|
-
}, 250)
|
|
46
|
-
await inspector.inspect(inspectedDescriptor)
|
|
47
|
-
expect(inspector.isInspected(toNodeId(inspectedDescriptor))).toBe(false)
|
|
48
|
-
expect(mockConnect).toBeCalledTimes(1)
|
|
49
|
-
})
|
|
50
|
-
|
|
51
|
-
})
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { NeighborFinder } from '../../src/logic/neighbor-discovery/NeighborFinder'
|
|
2
|
-
import { NodeList } from '../../src/logic/NodeList'
|
|
3
|
-
import { waitForCondition } from '@streamr/utils'
|
|
4
|
-
import { range } from 'lodash'
|
|
5
|
-
import { expect } from 'expect'
|
|
6
|
-
import { createMockContentDeliveryRpcRemote } from '../utils/utils'
|
|
7
|
-
import { DhtAddress, randomDhtAddress, toNodeId } from '@streamr/dht'
|
|
8
|
-
|
|
9
|
-
describe('NeighborFinder', () => {
|
|
10
|
-
|
|
11
|
-
const nodeId = randomDhtAddress()
|
|
12
|
-
let neighbors: NodeList
|
|
13
|
-
let nearbyNodeView: NodeList
|
|
14
|
-
let neighborFinder: NeighborFinder
|
|
15
|
-
|
|
16
|
-
const minCount = 4
|
|
17
|
-
|
|
18
|
-
beforeEach(() => {
|
|
19
|
-
neighbors = new NodeList(nodeId, 15)
|
|
20
|
-
nearbyNodeView = new NodeList(nodeId, 30)
|
|
21
|
-
range(30).forEach(() => nearbyNodeView.add(createMockContentDeliveryRpcRemote()))
|
|
22
|
-
const mockDoFindNeighbors = async (excluded: DhtAddress[]) => {
|
|
23
|
-
const target = nearbyNodeView.getRandom(excluded)
|
|
24
|
-
if (Math.random() < 0.5) {
|
|
25
|
-
neighbors.add(target!)
|
|
26
|
-
} else {
|
|
27
|
-
excluded.push(toNodeId(target!.getPeerDescriptor()))
|
|
28
|
-
}
|
|
29
|
-
return excluded
|
|
30
|
-
}
|
|
31
|
-
neighborFinder = new NeighborFinder({
|
|
32
|
-
neighbors,
|
|
33
|
-
nearbyNodeView,
|
|
34
|
-
leftNodeView: new NodeList(nodeId, 30),
|
|
35
|
-
rightNodeView: new NodeList(nodeId, 30),
|
|
36
|
-
randomNodeView: new NodeList(nodeId, 30),
|
|
37
|
-
doFindNeighbors: (excluded) => mockDoFindNeighbors(excluded),
|
|
38
|
-
minCount
|
|
39
|
-
})
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
neighborFinder.stop()
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
it('Finds target number of nodes', async () => {
|
|
47
|
-
neighborFinder.start()
|
|
48
|
-
await waitForCondition(() => neighbors.size() >= minCount, 10000)
|
|
49
|
-
expect(neighborFinder.isRunning()).toEqual(false)
|
|
50
|
-
})
|
|
51
|
-
})
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import { DhtAddress, ListeningRpcCommunicator, toNodeId } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
3
|
-
import { range } from 'lodash'
|
|
4
|
-
import { ContentDeliveryRpcRemote } from '../../src/logic/ContentDeliveryRpcRemote'
|
|
5
|
-
import { NodeList } from '../../src/logic/NodeList'
|
|
6
|
-
import { NeighborFinder } from '../../src/logic/neighbor-discovery/NeighborFinder'
|
|
7
|
-
import { NeighborUpdateRpcLocal } from '../../src/logic/neighbor-discovery/NeighborUpdateRpcLocal'
|
|
8
|
-
import { ContentDeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
9
|
-
import { MockTransport } from '../utils/mock/MockTransport'
|
|
10
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
11
|
-
|
|
12
|
-
describe('NeighborUpdateRpcLocal', () => {
|
|
13
|
-
|
|
14
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
15
|
-
const localPeerDescriptor = createMockPeerDescriptor()
|
|
16
|
-
const neighborTargetCount = 4
|
|
17
|
-
|
|
18
|
-
let rpcLocal: NeighborUpdateRpcLocal
|
|
19
|
-
let neighbors: NodeList
|
|
20
|
-
let nearbyNodeView: NodeList
|
|
21
|
-
let neighborFinder: NeighborFinder
|
|
22
|
-
let rpcCommunicator: ListeningRpcCommunicator
|
|
23
|
-
let ongoingHandshakes: Set<DhtAddress>
|
|
24
|
-
|
|
25
|
-
const addNeighbors = (count: number) => {
|
|
26
|
-
for (let i = 0; i < count; i++) {
|
|
27
|
-
neighbors.add(new ContentDeliveryRpcRemote(
|
|
28
|
-
localPeerDescriptor,
|
|
29
|
-
createMockPeerDescriptor(),
|
|
30
|
-
rpcCommunicator,
|
|
31
|
-
ContentDeliveryRpcClient
|
|
32
|
-
))
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
beforeEach(() => {
|
|
37
|
-
rpcCommunicator = new ListeningRpcCommunicator('mock', new MockTransport())
|
|
38
|
-
neighbors = new NodeList(toNodeId(localPeerDescriptor), neighborTargetCount + 1)
|
|
39
|
-
nearbyNodeView = new NodeList(toNodeId(localPeerDescriptor), neighborTargetCount)
|
|
40
|
-
neighborFinder = {
|
|
41
|
-
start: jest.fn()
|
|
42
|
-
} as any
|
|
43
|
-
ongoingHandshakes = new Set()
|
|
44
|
-
|
|
45
|
-
rpcLocal = new NeighborUpdateRpcLocal({
|
|
46
|
-
localPeerDescriptor,
|
|
47
|
-
neighbors,
|
|
48
|
-
nearbyNodeView,
|
|
49
|
-
neighborFinder,
|
|
50
|
-
streamPartId,
|
|
51
|
-
rpcCommunicator,
|
|
52
|
-
neighborTargetCount,
|
|
53
|
-
ongoingHandshakes
|
|
54
|
-
})
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
afterEach(() => {
|
|
58
|
-
rpcCommunicator.destroy()
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('response contains neighbor list of expected size', async () => {
|
|
62
|
-
addNeighbors(neighborTargetCount)
|
|
63
|
-
const res = await rpcLocal.neighborUpdate({
|
|
64
|
-
streamPartId,
|
|
65
|
-
neighborDescriptors: [localPeerDescriptor],
|
|
66
|
-
removeMe: false
|
|
67
|
-
}, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
68
|
-
expect(res.neighborDescriptors.length).toEqual(neighborTargetCount)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('updates contacts based on callers neighbors', async () => {
|
|
72
|
-
addNeighbors(neighborTargetCount)
|
|
73
|
-
expect(nearbyNodeView.size()).toEqual(0)
|
|
74
|
-
await rpcLocal.neighborUpdate({
|
|
75
|
-
streamPartId,
|
|
76
|
-
neighborDescriptors: range(neighborTargetCount).map(() => createMockPeerDescriptor()),
|
|
77
|
-
removeMe: false
|
|
78
|
-
}, { incomingSourceDescriptor: createMockPeerDescriptor() } as any)
|
|
79
|
-
expect(nearbyNodeView.size()).toEqual(4)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('does not ask to be removed if caller is a neighbor', async () => {
|
|
83
|
-
const caller = createMockPeerDescriptor()
|
|
84
|
-
const neighbor = new ContentDeliveryRpcRemote(
|
|
85
|
-
localPeerDescriptor,
|
|
86
|
-
caller,
|
|
87
|
-
rpcCommunicator,
|
|
88
|
-
ContentDeliveryRpcClient
|
|
89
|
-
)
|
|
90
|
-
neighbors.add(neighbor)
|
|
91
|
-
const res = await rpcLocal.neighborUpdate({
|
|
92
|
-
streamPartId,
|
|
93
|
-
neighborDescriptors: [localPeerDescriptor],
|
|
94
|
-
removeMe: false
|
|
95
|
-
}, { incomingSourceDescriptor: caller } as any)
|
|
96
|
-
expect(res.removeMe).toEqual(false)
|
|
97
|
-
})
|
|
98
|
-
|
|
99
|
-
it('asks to be removed if caller is not a neighbor', async () => {
|
|
100
|
-
const caller = createMockPeerDescriptor()
|
|
101
|
-
const res = await rpcLocal.neighborUpdate({
|
|
102
|
-
streamPartId,
|
|
103
|
-
neighborDescriptors: [localPeerDescriptor],
|
|
104
|
-
removeMe: false
|
|
105
|
-
}, { incomingSourceDescriptor: caller } as any)
|
|
106
|
-
expect(res.removeMe).toEqual(true)
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('asks to be removed if caller is a neighbor and both have too many neighbors', async () => {
|
|
110
|
-
const caller = createMockPeerDescriptor()
|
|
111
|
-
const neighbor = new ContentDeliveryRpcRemote(
|
|
112
|
-
localPeerDescriptor,
|
|
113
|
-
caller,
|
|
114
|
-
rpcCommunicator,
|
|
115
|
-
ContentDeliveryRpcClient
|
|
116
|
-
)
|
|
117
|
-
neighbors.add(neighbor)
|
|
118
|
-
addNeighbors(neighborTargetCount)
|
|
119
|
-
const res = await rpcLocal.neighborUpdate({
|
|
120
|
-
streamPartId,
|
|
121
|
-
neighborDescriptors: [localPeerDescriptor, ...range(neighborTargetCount).map(() => createMockPeerDescriptor())],
|
|
122
|
-
removeMe: false
|
|
123
|
-
}, { incomingSourceDescriptor: caller } as any)
|
|
124
|
-
expect(res.removeMe).toEqual(true)
|
|
125
|
-
expect(neighbors.has(toNodeId(caller))).toEqual(false)
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
it('does not ask to be removed if there is an ongoing handshake to the caller', async () => {
|
|
129
|
-
const caller = createMockPeerDescriptor()
|
|
130
|
-
ongoingHandshakes.add(toNodeId(caller))
|
|
131
|
-
const res = await rpcLocal.neighborUpdate({
|
|
132
|
-
streamPartId,
|
|
133
|
-
neighborDescriptors: [localPeerDescriptor],
|
|
134
|
-
removeMe: false
|
|
135
|
-
}, { incomingSourceDescriptor: caller } as any)
|
|
136
|
-
expect(res.removeMe).toEqual(false)
|
|
137
|
-
})
|
|
138
|
-
|
|
139
|
-
})
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
2
|
-
import { EventEmitter } from 'eventemitter3'
|
|
3
|
-
import { NetworkNode } from '../../src/NetworkNode'
|
|
4
|
-
import { NetworkStack } from '../../src/NetworkStack'
|
|
5
|
-
import { Events } from '../../src/logic/ContentDeliveryManager'
|
|
6
|
-
import { StreamMessage } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
7
|
-
import { createStreamMessage } from '../utils/utils'
|
|
8
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
9
|
-
|
|
10
|
-
const STREAM_PART = StreamPartIDUtils.parse('stream#0')
|
|
11
|
-
const PUBLISHER_ID = randomUserId()
|
|
12
|
-
|
|
13
|
-
const createMessage = (id: number): StreamMessage => {
|
|
14
|
-
return createStreamMessage(`${id}`, STREAM_PART, PUBLISHER_ID)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
describe('NetworkNode', () => {
|
|
18
|
-
|
|
19
|
-
it('message listener', async () => {
|
|
20
|
-
const contentDeliveryManager = new EventEmitter<Events>()
|
|
21
|
-
const stack: Partial<NetworkStack> = {
|
|
22
|
-
getContentDeliveryManager: () => contentDeliveryManager as any,
|
|
23
|
-
joinStreamPart: async () => {}
|
|
24
|
-
}
|
|
25
|
-
const node = new NetworkNode(stack as any)
|
|
26
|
-
await node.join(STREAM_PART)
|
|
27
|
-
const onMessage = jest.fn()
|
|
28
|
-
|
|
29
|
-
node.addMessageListener(onMessage)
|
|
30
|
-
const msg1 = createMessage(1)
|
|
31
|
-
const msg2 = createMessage(2)
|
|
32
|
-
contentDeliveryManager.emit('newMessage', msg1)
|
|
33
|
-
contentDeliveryManager.emit('newMessage', msg2)
|
|
34
|
-
expect(onMessage.mock.calls[0][0]).toEqual(msg1)
|
|
35
|
-
expect(onMessage.mock.calls[1][0]).toEqual(msg2)
|
|
36
|
-
expect(onMessage).toBeCalledTimes(2)
|
|
37
|
-
|
|
38
|
-
node.removeMessageListener(onMessage)
|
|
39
|
-
contentDeliveryManager.emit('newMessage', createMessage(3))
|
|
40
|
-
expect(onMessage).toBeCalledTimes(2)
|
|
41
|
-
})
|
|
42
|
-
})
|