@streamr/trackerless-network 0.0.1-tatum.5 → 0.0.1-tatum.7
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 +10 -8
- package/dist/src/NetworkNode.js +1 -1
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +1 -3
- package/dist/src/NetworkStack.js +18 -47
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/identifiers.js +2 -2
- package/dist/src/identifiers.js.map +1 -1
- package/dist/src/logic/{StreamNodeServer.d.ts → DeliveryRpcLocal.d.ts} +6 -5
- package/dist/src/logic/{StreamNodeServer.js → DeliveryRpcLocal.js} +5 -5
- package/dist/src/logic/{StreamNodeServer.js.map → DeliveryRpcLocal.js.map} +1 -1
- package/dist/src/logic/{RemoteRandomGraphNode.d.ts → DeliveryRpcRemote.d.ts} +2 -2
- package/dist/src/logic/{RemoteRandomGraphNode.js → DeliveryRpcRemote.js} +5 -5
- package/dist/src/logic/DeliveryRpcRemote.js.map +1 -0
- package/dist/src/logic/EntryPointDiscovery.d.ts +35 -0
- package/dist/src/logic/EntryPointDiscovery.js +145 -0
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -0
- package/dist/src/logic/ILayer0.d.ts +3 -6
- package/dist/src/logic/ILayer1.d.ts +2 -2
- package/dist/src/logic/NodeList.d.ts +10 -10
- package/dist/src/logic/NodeList.js +2 -2
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +8 -12
- package/dist/src/logic/RandomGraphNode.js +47 -46
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +9 -11
- package/dist/src/logic/StreamrNode.js +72 -75
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +6 -1
- package/dist/src/logic/createRandomGraphNode.js +17 -23
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.d.ts +2 -0
- package/dist/src/logic/formStreamPartDeliveryServiceId.js +8 -0
- package/dist/src/logic/formStreamPartDeliveryServiceId.js.map +1 -0
- package/dist/src/logic/inspect/Inspector.d.ts +3 -2
- package/dist/src/logic/inspect/Inspector.js +5 -5
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/{HandshakerServer.d.ts → HandshakeRpcLocal.d.ts} +10 -10
- package/dist/src/logic/neighbor-discovery/{HandshakerServer.js → HandshakeRpcLocal.js} +13 -13
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -0
- package/dist/src/logic/neighbor-discovery/{RemoteHandshaker.d.ts → HandshakeRpcRemote.d.ts} +1 -1
- package/dist/src/logic/neighbor-discovery/{RemoteHandshaker.js → HandshakeRpcRemote.js} +8 -7
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -0
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +8 -7
- package/dist/src/logic/neighbor-discovery/Handshaker.js +23 -24
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +5 -5
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +3 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +7 -7
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.d.ts → NeighborUpdateRpcLocal.d.ts} +6 -6
- package/dist/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.js → NeighborUpdateRpcLocal.js} +11 -11
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -0
- package/dist/src/logic/neighbor-discovery/{RemoteNeighborUpdateManager.d.ts → NeighborUpdateRpcRemote.d.ts} +1 -1
- package/dist/src/logic/neighbor-discovery/{RemoteNeighborUpdateManager.js → NeighborUpdateRpcRemote.js} +5 -5
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -0
- package/dist/src/logic/propagation/Propagation.js +2 -2
- package/dist/src/logic/propagation/Propagation.js.map +1 -1
- package/dist/src/logic/proxy/{ProxyStreamConnectionClient.d.ts → ProxyClient.d.ts} +8 -12
- package/dist/src/logic/proxy/{ProxyStreamConnectionClient.js → ProxyClient.js} +28 -29
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -0
- package/dist/src/logic/proxy/{ProxyStreamConnectionServer.d.ts → ProxyConnectionRpcLocal.d.ts} +5 -7
- package/dist/src/logic/proxy/{ProxyStreamConnectionServer.js → ProxyConnectionRpcLocal.js} +6 -12
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -0
- package/dist/src/logic/proxy/{RemoteProxyServer.d.ts → ProxyConnectionRpcRemote.d.ts} +1 -1
- package/dist/src/logic/proxy/{RemoteProxyServer.js → ProxyConnectionRpcRemote.js} +4 -4
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -0
- package/dist/src/logic/temporary-connection/{TemporaryConnectionRpcServer.d.ts → TemporaryConnectionRpcLocal.d.ts} +5 -4
- package/dist/src/logic/temporary-connection/{TemporaryConnectionRpcServer.js → TemporaryConnectionRpcLocal.js} +6 -6
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -0
- package/dist/src/logic/temporary-connection/{RemoteTemporaryConnectionRpcServer.d.ts → TemporaryConnectionRpcRemote.d.ts} +1 -1
- package/dist/src/logic/temporary-connection/{RemoteTemporaryConnectionRpcServer.js → TemporaryConnectionRpcRemote.js} +4 -4
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +0 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +1 -2
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +4 -4
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +7 -7
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +10 -10
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +7 -7
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.d.ts +2 -2
- package/dist/test/benchmark/first-message.js +10 -13
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +5 -5
- package/dist/test/utils/utils.js +14 -14
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +10 -8
- package/protos/NetworkRpc.proto +5 -5
- package/src/NetworkNode.ts +1 -1
- package/src/NetworkStack.ts +20 -62
- package/src/identifiers.ts +3 -3
- package/src/logic/{StreamNodeServer.ts → DeliveryRpcLocal.ts} +8 -7
- package/src/logic/{RemoteRandomGraphNode.ts → DeliveryRpcRemote.ts} +3 -3
- package/src/logic/EntryPointDiscovery.ts +181 -0
- package/src/logic/ILayer0.ts +3 -6
- package/src/logic/ILayer1.ts +2 -5
- package/src/logic/NodeList.ts +12 -12
- package/src/logic/RandomGraphNode.ts +67 -69
- package/src/logic/StreamrNode.ts +78 -90
- package/src/logic/createRandomGraphNode.ts +28 -26
- package/src/logic/formStreamPartDeliveryServiceId.ts +5 -0
- package/src/logic/inspect/Inspector.ts +8 -7
- package/src/logic/neighbor-discovery/{HandshakerServer.ts → HandshakeRpcLocal.ts} +20 -20
- package/src/logic/neighbor-discovery/{RemoteHandshaker.ts → HandshakeRpcRemote.ts} +6 -5
- package/src/logic/neighbor-discovery/Handshaker.ts +38 -38
- package/src/logic/neighbor-discovery/NeighborFinder.ts +6 -6
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +15 -12
- package/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.ts → NeighborUpdateRpcLocal.ts} +17 -17
- package/src/logic/neighbor-discovery/{RemoteNeighborUpdateManager.ts → NeighborUpdateRpcRemote.ts} +2 -2
- package/src/logic/propagation/Propagation.ts +2 -2
- package/src/logic/proxy/{ProxyStreamConnectionClient.ts → ProxyClient.ts} +33 -37
- package/src/logic/proxy/{ProxyStreamConnectionServer.ts → ProxyConnectionRpcLocal.ts} +10 -19
- package/src/logic/proxy/{RemoteProxyServer.ts → ProxyConnectionRpcRemote.ts} +1 -1
- package/src/logic/temporary-connection/{TemporaryConnectionRpcServer.ts → TemporaryConnectionRpcLocal.ts} +11 -10
- package/src/logic/temporary-connection/{RemoteTemporaryConnectionRpcServer.ts → TemporaryConnectionRpcRemote.ts} +1 -1
- package/src/proto/packages/dht/protos/DhtRpc.ts +1 -6
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +8 -8
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +2 -2
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +14 -14
- package/test/benchmark/first-message.ts +10 -13
- package/test/end-to-end/inspect.test.ts +12 -12
- package/test/end-to-end/proxy-and-full-node.test.ts +13 -14
- package/test/end-to-end/proxy-connections.test.ts +10 -12
- package/test/end-to-end/proxy-key-exchange.test.ts +12 -13
- package/test/end-to-end/random-graph-with-real-connections.test.ts +7 -7
- package/test/end-to-end/webrtc-full-node-network.test.ts +8 -8
- package/test/end-to-end/websocket-full-node-network.test.ts +8 -10
- package/test/integration/{RemoteRandomGraphNode.test.ts → DeliveryRpcRemote.test.ts} +17 -14
- package/test/integration/{RemoteHandshaker.test.ts → HandshakeRpcRemote.test.ts} +10 -9
- package/test/integration/Handshakes.test.ts +23 -20
- package/test/integration/Inspect.test.ts +3 -2
- package/test/integration/{RemoteNeighborUpdateManager.test.ts → NeighborUpdateRpcRemote.test.ts} +12 -10
- package/test/integration/NetworkNode.test.ts +9 -8
- package/test/integration/NetworkRpc.test.ts +5 -7
- package/test/integration/NetworkStack.test.ts +13 -15
- package/test/integration/Propagation.test.ts +2 -2
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +10 -8
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +17 -17
- package/test/integration/StreamrNode.test.ts +5 -3
- package/test/integration/joining-streams-on-offline-peers.test.ts +16 -18
- package/test/integration/stream-without-default-entrypoints.test.ts +11 -13
- package/test/unit/{StreamNodeServer.test.ts → DeliveryRpcLocal.test.ts} +8 -8
- package/test/unit/EntrypointDiscovery.test.ts +132 -0
- package/test/unit/{HandshakerServer.test.ts → HandshakeRpcLocal.test.ts} +26 -24
- package/test/unit/Handshaker.test.ts +10 -8
- package/test/unit/Inspector.test.ts +4 -3
- package/test/unit/NeighborFinder.test.ts +5 -5
- package/test/unit/NodeList.test.ts +22 -13
- package/test/unit/{RemoteProxyServer.test.ts → ProxyConnectionRpcRemote.test.ts} +4 -4
- package/test/unit/RandomGraphNode.test.ts +12 -11
- package/test/unit/StreamMessageTranslator.test.ts +10 -9
- package/test/unit/StreamrNode.test.ts +8 -8
- package/test/utils/mock/MockLayer0.ts +7 -26
- package/test/utils/mock/MockLayer1.ts +6 -13
- package/test/utils/mock/MockNeighborFinder.ts +1 -2
- package/test/utils/mock/MockNeighborUpdateManager.ts +1 -2
- package/test/utils/mock/Transport.ts +2 -2
- package/test/utils/utils.ts +13 -13
- package/dist/src/logic/RemoteRandomGraphNode.js.map +0 -1
- package/dist/src/logic/StreamPartEntryPointDiscovery.d.ts +0 -39
- package/dist/src/logic/StreamPartEntryPointDiscovery.js +0 -194
- package/dist/src/logic/StreamPartEntryPointDiscovery.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/HandshakerServer.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManagerServer.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/RemoteHandshaker.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/RemoteNeighborUpdateManager.js.map +0 -1
- package/dist/src/logic/proxy/ProxyStreamConnectionClient.js.map +0 -1
- package/dist/src/logic/proxy/ProxyStreamConnectionServer.js.map +0 -1
- package/dist/src/logic/proxy/RemoteProxyServer.js.map +0 -1
- package/dist/src/logic/temporary-connection/RemoteTemporaryConnectionRpcServer.js.map +0 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcServer.js.map +0 -1
- package/src/logic/StreamPartEntryPointDiscovery.ts +0 -240
- package/test/unit/StreamPartEntrypointDiscovery.test.ts +0 -164
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { PeerDescriptor, areEqualPeerDescriptors } from '@streamr/dht'
|
|
2
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
3
|
+
import { wait } from '@streamr/utils'
|
|
4
|
+
import { range } from 'lodash'
|
|
5
|
+
import { EntryPointDiscovery } from '../../src/logic/EntryPointDiscovery'
|
|
6
|
+
import { Any } from '../../src/proto/google/protobuf/any'
|
|
7
|
+
import { DataEntry } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
|
+
import { MockLayer1 } from '../utils/mock/MockLayer1'
|
|
9
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
10
|
+
|
|
11
|
+
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
12
|
+
|
|
13
|
+
describe('EntryPointDiscovery', () => {
|
|
14
|
+
|
|
15
|
+
let entryPointDiscoveryWithData: EntryPointDiscovery
|
|
16
|
+
let entryPointDiscoveryWithoutData: EntryPointDiscovery
|
|
17
|
+
let storeCalled: number
|
|
18
|
+
|
|
19
|
+
const peerDescriptor = createMockPeerDescriptor()
|
|
20
|
+
const deletedPeerDescriptor = createMockPeerDescriptor()
|
|
21
|
+
|
|
22
|
+
const fakeData: DataEntry = {
|
|
23
|
+
data: Any.pack(peerDescriptor, PeerDescriptor),
|
|
24
|
+
ttl: 1000,
|
|
25
|
+
storer: peerDescriptor,
|
|
26
|
+
kademliaId: Uint8Array.from([1, 2, 3]),
|
|
27
|
+
stale: false,
|
|
28
|
+
deleted: false
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const fakeDeletedData: DataEntry = {
|
|
32
|
+
data: Any.pack(deletedPeerDescriptor, PeerDescriptor),
|
|
33
|
+
ttl: 1000,
|
|
34
|
+
storer: deletedPeerDescriptor,
|
|
35
|
+
kademliaId: Uint8Array.from([1, 2, 3]),
|
|
36
|
+
stale: false,
|
|
37
|
+
deleted: true
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const fakeGetEntryPointData = async (): Promise<DataEntry[]> => {
|
|
41
|
+
return [fakeData, fakeDeletedData]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const fakeStoreEntryPointData = async (): Promise<PeerDescriptor[]> => {
|
|
45
|
+
storeCalled++
|
|
46
|
+
return [peerDescriptor]
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const fakeEmptyGetEntryPointData = async (): Promise<DataEntry[]> => {
|
|
50
|
+
return []
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const fakeDeleteEntryPointData = async (): Promise<void> => {}
|
|
54
|
+
|
|
55
|
+
const addNodesToStreamPart = (layer1: MockLayer1, count: number) => {
|
|
56
|
+
range(count).forEach(() => {
|
|
57
|
+
layer1.addNewRandomPeerToKBucket()
|
|
58
|
+
layer1.addNewRandomPeerToKBucket()
|
|
59
|
+
layer1.addNewRandomPeerToKBucket()
|
|
60
|
+
layer1.addNewRandomPeerToKBucket()
|
|
61
|
+
})
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let layer1: MockLayer1
|
|
65
|
+
|
|
66
|
+
beforeEach(() => {
|
|
67
|
+
storeCalled = 0
|
|
68
|
+
layer1 = new MockLayer1()
|
|
69
|
+
entryPointDiscoveryWithData = new EntryPointDiscovery({
|
|
70
|
+
ownPeerDescriptor: peerDescriptor,
|
|
71
|
+
streamPartId: STREAM_PART_ID,
|
|
72
|
+
layer1,
|
|
73
|
+
getEntryPointData: fakeGetEntryPointData,
|
|
74
|
+
storeEntryPointData: fakeStoreEntryPointData,
|
|
75
|
+
deleteEntryPointData: fakeDeleteEntryPointData,
|
|
76
|
+
storeInterval: 2000
|
|
77
|
+
})
|
|
78
|
+
entryPointDiscoveryWithoutData = new EntryPointDiscovery({
|
|
79
|
+
ownPeerDescriptor: peerDescriptor,
|
|
80
|
+
streamPartId: STREAM_PART_ID,
|
|
81
|
+
layer1,
|
|
82
|
+
getEntryPointData: fakeEmptyGetEntryPointData,
|
|
83
|
+
storeEntryPointData: fakeStoreEntryPointData,
|
|
84
|
+
deleteEntryPointData: fakeDeleteEntryPointData,
|
|
85
|
+
storeInterval: 2000
|
|
86
|
+
})
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
afterEach(() => {
|
|
90
|
+
entryPointDiscoveryWithData.destroy()
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
it('discoverEntryPointsFromDht has known entrypoints', async () => {
|
|
94
|
+
const res = await entryPointDiscoveryWithData.discoverEntryPointsFromDht(1)
|
|
95
|
+
expect(res.entryPointsFromDht).toEqual(false)
|
|
96
|
+
expect(res.discoveredEntryPoints).toEqual([])
|
|
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)
|
|
103
|
+
})
|
|
104
|
+
|
|
105
|
+
it('discoverEntryPointsfromDht on an empty stream', async () => {
|
|
106
|
+
const res = await entryPointDiscoveryWithoutData.discoverEntryPointsFromDht(0)
|
|
107
|
+
expect(res.entryPointsFromDht).toEqual(true)
|
|
108
|
+
expect(res.discoveredEntryPoints.length).toBe(1)
|
|
109
|
+
expect(areEqualPeerDescriptors(res.discoveredEntryPoints[0], peerDescriptor)).toBe(true) // ownPeerDescriptor
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('store on empty stream', async () => {
|
|
113
|
+
await entryPointDiscoveryWithData.storeSelfAsEntryPointIfNecessary(0)
|
|
114
|
+
expect(storeCalled).toEqual(1)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('store on stream without saturated entrypoint count', async () => {
|
|
118
|
+
addNodesToStreamPart(layer1, 4)
|
|
119
|
+
await entryPointDiscoveryWithData.storeSelfAsEntryPointIfNecessary(0)
|
|
120
|
+
expect(storeCalled).toEqual(1)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('will keep stored until destroyed', async () => {
|
|
124
|
+
await entryPointDiscoveryWithData.storeSelfAsEntryPointIfNecessary(0)
|
|
125
|
+
expect(storeCalled).toEqual(1)
|
|
126
|
+
await wait(4500)
|
|
127
|
+
await entryPointDiscoveryWithData.destroy()
|
|
128
|
+
// we have configured storeInterval to 2 seconds, i.e. after 4.5 seconds it should have been called 2 more items
|
|
129
|
+
expect(storeCalled).toEqual(3)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
})
|
|
@@ -2,13 +2,16 @@ import { NodeType } from '@streamr/dht'
|
|
|
2
2
|
import { hexToBinary } from '@streamr/utils'
|
|
3
3
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
4
4
|
import { NodeList } from '../../src/logic/NodeList'
|
|
5
|
-
import {
|
|
5
|
+
import { HandshakeRpcLocal } from '../../src/logic/neighbor-discovery/HandshakeRpcLocal'
|
|
6
6
|
import { InterleaveNotice, StreamPartHandshakeRequest } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
7
|
-
import { createMockPeerDescriptor,
|
|
7
|
+
import { createMockPeerDescriptor, createMockHandshakeRpcRemote, createMockDeliveryRpcRemote, mockConnectionLocker } from '../utils/utils'
|
|
8
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
8
9
|
|
|
9
|
-
|
|
10
|
+
const STREAM_PART_ID = StreamPartIDUtils.parse('stream#0')
|
|
10
11
|
|
|
11
|
-
|
|
12
|
+
describe('HandshakeRpcLocal', () => {
|
|
13
|
+
|
|
14
|
+
let rpcLocal: HandshakeRpcLocal
|
|
12
15
|
|
|
13
16
|
const ownPeerDescriptor = createMockPeerDescriptor()
|
|
14
17
|
|
|
@@ -22,28 +25,27 @@ describe('HandshakerServer', () => {
|
|
|
22
25
|
|
|
23
26
|
handshakeWithInterleaving = jest.fn()
|
|
24
27
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
ownPeerDescriptor,
|
|
28
|
+
rpcLocal = new HandshakeRpcLocal({
|
|
29
|
+
streamPartId: STREAM_PART_ID,
|
|
28
30
|
connectionLocker: mockConnectionLocker,
|
|
29
31
|
ongoingHandshakes,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
+
createRpcRemote: (_p) => createMockHandshakeRpcRemote(),
|
|
33
|
+
createDeliveryRpcRemote: (_p) => createMockDeliveryRpcRemote(),
|
|
32
34
|
handshakeWithInterleaving: async (_p, _t) => {
|
|
33
35
|
handshakeWithInterleaving()
|
|
34
36
|
return true
|
|
35
37
|
},
|
|
36
38
|
targetNeighbors,
|
|
37
|
-
|
|
39
|
+
maxNeighborCount: 4
|
|
38
40
|
})
|
|
39
41
|
})
|
|
40
42
|
|
|
41
43
|
it('handshake', async () => {
|
|
42
44
|
const req = StreamPartHandshakeRequest.create({
|
|
43
|
-
|
|
45
|
+
streamPartId: STREAM_PART_ID,
|
|
44
46
|
requestId: 'requestId'
|
|
45
47
|
})
|
|
46
|
-
const res = await
|
|
48
|
+
const res = await rpcLocal.handshake(req, {
|
|
47
49
|
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
48
50
|
} as any)
|
|
49
51
|
expect(res.accepted).toEqual(true)
|
|
@@ -52,15 +54,15 @@ describe('HandshakerServer', () => {
|
|
|
52
54
|
})
|
|
53
55
|
|
|
54
56
|
it('handshake interleave', async () => {
|
|
55
|
-
targetNeighbors.add(
|
|
56
|
-
targetNeighbors.add(
|
|
57
|
-
targetNeighbors.add(
|
|
58
|
-
targetNeighbors.add(
|
|
57
|
+
targetNeighbors.add(createMockDeliveryRpcRemote())
|
|
58
|
+
targetNeighbors.add(createMockDeliveryRpcRemote())
|
|
59
|
+
targetNeighbors.add(createMockDeliveryRpcRemote())
|
|
60
|
+
targetNeighbors.add(createMockDeliveryRpcRemote())
|
|
59
61
|
const req = StreamPartHandshakeRequest.create({
|
|
60
|
-
|
|
62
|
+
streamPartId: STREAM_PART_ID,
|
|
61
63
|
requestId: 'requestId'
|
|
62
64
|
})
|
|
63
|
-
const res = await
|
|
65
|
+
const res = await rpcLocal.handshake(req, {
|
|
64
66
|
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
65
67
|
} as any)
|
|
66
68
|
expect(res.accepted).toEqual(true)
|
|
@@ -73,10 +75,10 @@ describe('HandshakerServer', () => {
|
|
|
73
75
|
ongoingHandshakes.add('0x4444' as NodeID)
|
|
74
76
|
ongoingHandshakes.add('0x5555' as NodeID)
|
|
75
77
|
const req = StreamPartHandshakeRequest.create({
|
|
76
|
-
|
|
78
|
+
streamPartId: STREAM_PART_ID,
|
|
77
79
|
requestId: 'requestId'
|
|
78
80
|
})
|
|
79
|
-
const res = await
|
|
81
|
+
const res = await rpcLocal.handshake(req, {
|
|
80
82
|
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
81
83
|
} as any)
|
|
82
84
|
expect(res.accepted).toEqual(false)
|
|
@@ -84,14 +86,14 @@ describe('HandshakerServer', () => {
|
|
|
84
86
|
|
|
85
87
|
it('handshakeWithInterleaving success', async () => {
|
|
86
88
|
const req: InterleaveNotice = {
|
|
87
|
-
|
|
89
|
+
streamPartId: STREAM_PART_ID,
|
|
88
90
|
interleaveTargetDescriptor: {
|
|
89
91
|
kademliaId: hexToBinary('0x2222'),
|
|
90
92
|
type: NodeType.NODEJS
|
|
91
93
|
}
|
|
92
94
|
|
|
93
95
|
}
|
|
94
|
-
await
|
|
96
|
+
await rpcLocal.interleaveNotice(req, {
|
|
95
97
|
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
96
98
|
} as any)
|
|
97
99
|
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(1)
|
|
@@ -99,13 +101,13 @@ describe('HandshakerServer', () => {
|
|
|
99
101
|
|
|
100
102
|
it('handshakeWithInterleaving success', async () => {
|
|
101
103
|
const req: InterleaveNotice = {
|
|
102
|
-
|
|
104
|
+
streamPartId: StreamPartIDUtils.parse('other-stream#0'),
|
|
103
105
|
interleaveTargetDescriptor: {
|
|
104
106
|
kademliaId: hexToBinary('0x2222'),
|
|
105
107
|
type: NodeType.NODEJS
|
|
106
108
|
}
|
|
107
109
|
}
|
|
108
|
-
await
|
|
110
|
+
await rpcLocal.interleaveNotice(req, {
|
|
109
111
|
incomingSourceDescriptor: createMockPeerDescriptor()
|
|
110
112
|
} as any)
|
|
111
113
|
expect(handshakeWithInterleaving).toHaveBeenCalledTimes(0)
|
|
@@ -3,15 +3,16 @@ import { range } from 'lodash'
|
|
|
3
3
|
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
4
4
|
import { NodeList } from '../../src/logic/NodeList'
|
|
5
5
|
import { Handshaker } from '../../src/logic/neighbor-discovery/Handshaker'
|
|
6
|
-
import { createMockPeerDescriptor,
|
|
6
|
+
import { createMockPeerDescriptor, createMockDeliveryRpcRemote, mockConnectionLocker } from '../utils/utils'
|
|
7
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
8
|
|
|
8
9
|
describe('Handshaker', () => {
|
|
9
10
|
|
|
10
11
|
let handshaker: Handshaker
|
|
11
12
|
const peerDescriptor = createMockPeerDescriptor()
|
|
12
13
|
|
|
13
|
-
const
|
|
14
|
-
const
|
|
14
|
+
const maxNeighborCount = 4
|
|
15
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
15
16
|
|
|
16
17
|
let targetNeighbors: NodeList
|
|
17
18
|
let nearbyNodeView: NodeList
|
|
@@ -20,10 +21,11 @@ describe('Handshaker', () => {
|
|
|
20
21
|
let simulator: Simulator
|
|
21
22
|
let simulatorTransport: SimulatorTransport
|
|
22
23
|
|
|
23
|
-
beforeEach(() => {
|
|
24
|
+
beforeEach(async () => {
|
|
24
25
|
simulator = new Simulator()
|
|
25
26
|
simulatorTransport = new SimulatorTransport(peerDescriptor, simulator)
|
|
26
|
-
|
|
27
|
+
await simulatorTransport.start()
|
|
28
|
+
const rpcCommunicator = new ListeningRpcCommunicator(streamPartId, simulatorTransport)
|
|
27
29
|
|
|
28
30
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
29
31
|
targetNeighbors = new NodeList(nodeId, 10)
|
|
@@ -32,13 +34,13 @@ describe('Handshaker', () => {
|
|
|
32
34
|
|
|
33
35
|
handshaker = new Handshaker({
|
|
34
36
|
ownPeerDescriptor: peerDescriptor,
|
|
35
|
-
|
|
37
|
+
streamPartId,
|
|
36
38
|
connectionLocker: mockConnectionLocker,
|
|
37
39
|
targetNeighbors,
|
|
38
40
|
nearbyNodeView,
|
|
39
41
|
randomNodeView,
|
|
40
42
|
rpcCommunicator,
|
|
41
|
-
|
|
43
|
+
maxNeighborCount
|
|
42
44
|
})
|
|
43
45
|
})
|
|
44
46
|
|
|
@@ -53,7 +55,7 @@ describe('Handshaker', () => {
|
|
|
53
55
|
})
|
|
54
56
|
|
|
55
57
|
it('attemptHandshakesOnContact with known nodes that cannot be connected to', async () => {
|
|
56
|
-
range(2).forEach(() => nearbyNodeView.add(
|
|
58
|
+
range(2).forEach(() => nearbyNodeView.add(createMockDeliveryRpcRemote()))
|
|
57
59
|
const res = await handshaker.attemptHandshakesOnContacts([])
|
|
58
60
|
expect(res.length).toEqual(2)
|
|
59
61
|
})
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator
|
|
1
|
+
import { ListeningRpcCommunicator } from '@streamr/dht'
|
|
2
2
|
import { utf8ToBinary } from '@streamr/utils'
|
|
3
3
|
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
4
4
|
import { Inspector } from '../../src/logic/inspect/Inspector'
|
|
5
5
|
import { MockTransport } from '../utils/mock/Transport'
|
|
6
6
|
import { createMockPeerDescriptor, createRandomNodeId, mockConnectionLocker } from '../utils/utils'
|
|
7
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
7
8
|
|
|
8
9
|
describe('Inspector', () => {
|
|
9
10
|
|
|
@@ -28,10 +29,10 @@ describe('Inspector', () => {
|
|
|
28
29
|
mockConnect = jest.fn(() => {})
|
|
29
30
|
inspector = new Inspector({
|
|
30
31
|
ownPeerDescriptor: inspectorDescriptor,
|
|
31
|
-
|
|
32
|
+
streamPartId: StreamPartIDUtils.parse('stream#0'),
|
|
32
33
|
rpcCommunicator: new ListeningRpcCommunicator('inspector', new MockTransport()),
|
|
33
34
|
connectionLocker: mockConnectionLocker,
|
|
34
|
-
openInspectConnection: async (
|
|
35
|
+
openInspectConnection: async () => mockConnect()
|
|
35
36
|
})
|
|
36
37
|
})
|
|
37
38
|
|
|
@@ -3,7 +3,7 @@ import { NodeList } from '../../src/logic/NodeList'
|
|
|
3
3
|
import { waitForCondition } from '@streamr/utils'
|
|
4
4
|
import { range } from 'lodash'
|
|
5
5
|
import { expect } from 'expect'
|
|
6
|
-
import {
|
|
6
|
+
import { createMockDeliveryRpcRemote, createRandomNodeId } from '../utils/utils'
|
|
7
7
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
8
8
|
|
|
9
9
|
describe('NeighborFinder', () => {
|
|
@@ -13,12 +13,12 @@ describe('NeighborFinder', () => {
|
|
|
13
13
|
let nearbyNodeView: NodeList
|
|
14
14
|
let neighborFinder: NeighborFinder
|
|
15
15
|
|
|
16
|
-
const
|
|
16
|
+
const minCount = 4
|
|
17
17
|
|
|
18
18
|
beforeEach(() => {
|
|
19
19
|
targetNeighbors = new NodeList(nodeId, 15)
|
|
20
20
|
nearbyNodeView = new NodeList(nodeId, 30)
|
|
21
|
-
range(30).forEach(() => nearbyNodeView.add(
|
|
21
|
+
range(30).forEach(() => nearbyNodeView.add(createMockDeliveryRpcRemote()))
|
|
22
22
|
const mockDoFindNeighbors = async (excluded: NodeID[]) => {
|
|
23
23
|
const target = nearbyNodeView.getRandom(excluded)
|
|
24
24
|
if (Math.random() < 0.5) {
|
|
@@ -32,7 +32,7 @@ describe('NeighborFinder', () => {
|
|
|
32
32
|
targetNeighbors,
|
|
33
33
|
nearbyNodeView,
|
|
34
34
|
doFindNeighbors: (excluded) => mockDoFindNeighbors(excluded),
|
|
35
|
-
|
|
35
|
+
minCount
|
|
36
36
|
})
|
|
37
37
|
})
|
|
38
38
|
|
|
@@ -42,7 +42,7 @@ describe('NeighborFinder', () => {
|
|
|
42
42
|
|
|
43
43
|
it('Finds target number of nodes', async () => {
|
|
44
44
|
neighborFinder.start()
|
|
45
|
-
await waitForCondition(() => targetNeighbors.size() >=
|
|
45
|
+
await waitForCondition(() => targetNeighbors.size() >= minCount, 10000)
|
|
46
46
|
expect(neighborFinder.isRunning()).toEqual(false)
|
|
47
47
|
})
|
|
48
48
|
})
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NodeList } from '../../src/logic/NodeList'
|
|
2
|
-
import {
|
|
2
|
+
import { DeliveryRpcRemote } from '../../src/logic/DeliveryRpcRemote'
|
|
3
3
|
import {
|
|
4
4
|
PeerDescriptor,
|
|
5
5
|
ListeningRpcCommunicator,
|
|
@@ -7,12 +7,16 @@ import {
|
|
|
7
7
|
SimulatorTransport,
|
|
8
8
|
NodeType,
|
|
9
9
|
} from '@streamr/dht'
|
|
10
|
-
import {
|
|
10
|
+
import { DeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
11
11
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
12
12
|
import { expect } from 'expect'
|
|
13
13
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
14
14
|
import { createMockPeerDescriptor, createRandomNodeId } from '../utils/utils'
|
|
15
15
|
import { binaryToHex } from '@streamr/utils'
|
|
16
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
17
|
+
import { formStreamPartDeliveryServiceId } from '../../src/logic/formStreamPartDeliveryServiceId'
|
|
18
|
+
|
|
19
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
16
20
|
|
|
17
21
|
describe('NodeList', () => {
|
|
18
22
|
|
|
@@ -24,31 +28,36 @@ describe('NodeList', () => {
|
|
|
24
28
|
new Uint8Array([1, 1, 5])
|
|
25
29
|
]
|
|
26
30
|
const ownId = createRandomNodeId()
|
|
27
|
-
const graphId = 'test'
|
|
28
31
|
let nodeList: NodeList
|
|
29
32
|
let simulator: Simulator
|
|
30
33
|
let mockTransports: SimulatorTransport[]
|
|
31
34
|
|
|
32
|
-
const createRemoteGraphNode = (peerDescriptor: PeerDescriptor) => {
|
|
35
|
+
const createRemoteGraphNode = async (peerDescriptor: PeerDescriptor) => {
|
|
33
36
|
const mockTransport = new SimulatorTransport(peerDescriptor, simulator)
|
|
34
|
-
|
|
37
|
+
await mockTransport.start()
|
|
38
|
+
const mockCommunicator = new ListeningRpcCommunicator(formStreamPartDeliveryServiceId(streamPartId), mockTransport)
|
|
35
39
|
const mockClient = mockCommunicator.getRpcClientTransport()
|
|
36
40
|
|
|
37
41
|
mockTransports.push(mockTransport)
|
|
38
|
-
return new
|
|
42
|
+
return new DeliveryRpcRemote(
|
|
43
|
+
createMockPeerDescriptor(),
|
|
44
|
+
peerDescriptor,
|
|
45
|
+
streamPartId,
|
|
46
|
+
toProtoRpcClient(new DeliveryRpcClient(mockClient))
|
|
47
|
+
)
|
|
39
48
|
}
|
|
40
49
|
|
|
41
|
-
beforeEach(() => {
|
|
50
|
+
beforeEach(async () => {
|
|
42
51
|
simulator = new Simulator()
|
|
43
52
|
mockTransports = []
|
|
44
53
|
nodeList = new NodeList(ownId, 6)
|
|
45
|
-
|
|
54
|
+
for (const id of ids) {
|
|
46
55
|
const peerDescriptor: PeerDescriptor = {
|
|
47
56
|
kademliaId: id,
|
|
48
57
|
type: NodeType.NODEJS
|
|
49
58
|
}
|
|
50
|
-
nodeList.add(createRemoteGraphNode(peerDescriptor))
|
|
51
|
-
}
|
|
59
|
+
nodeList.add(await createRemoteGraphNode(peerDescriptor))
|
|
60
|
+
}
|
|
52
61
|
})
|
|
53
62
|
|
|
54
63
|
afterEach(async ()=> {
|
|
@@ -59,12 +68,12 @@ describe('NodeList', () => {
|
|
|
59
68
|
simulator.stop()
|
|
60
69
|
})
|
|
61
70
|
|
|
62
|
-
it('add', () => {
|
|
71
|
+
it('add', async () => {
|
|
63
72
|
const newDescriptor = {
|
|
64
73
|
kademliaId: new Uint8Array([1, 2, 3]),
|
|
65
74
|
type: NodeType.NODEJS
|
|
66
75
|
}
|
|
67
|
-
const newNode = createRemoteGraphNode(newDescriptor)
|
|
76
|
+
const newNode = await createRemoteGraphNode(newDescriptor)
|
|
68
77
|
nodeList.add(newNode)
|
|
69
78
|
expect(nodeList.hasNode(newDescriptor)).toEqual(true)
|
|
70
79
|
|
|
@@ -72,7 +81,7 @@ describe('NodeList', () => {
|
|
|
72
81
|
kademliaId: new Uint8Array([1, 2, 4]),
|
|
73
82
|
type: NodeType.NODEJS
|
|
74
83
|
}
|
|
75
|
-
const newNode2 = createRemoteGraphNode(newDescriptor2)
|
|
84
|
+
const newNode2 = await createRemoteGraphNode(newDescriptor2)
|
|
76
85
|
nodeList.add(newNode2)
|
|
77
86
|
expect(nodeList.hasNode(newDescriptor2)).toEqual(false)
|
|
78
87
|
})
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
2
2
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
3
3
|
import { hexToBinary } from '@streamr/utils'
|
|
4
|
-
import {
|
|
4
|
+
import { ProxyConnectionRpcRemote } from '../../src/logic/proxy/ProxyConnectionRpcRemote'
|
|
5
5
|
import { ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
6
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
7
|
|
|
8
|
-
describe('
|
|
8
|
+
describe('ProxyConnectionRpcRemote', () => {
|
|
9
9
|
|
|
10
10
|
it('happy path', () => {
|
|
11
11
|
const client = {
|
|
@@ -13,14 +13,14 @@ describe('RemoteProxyServer', () => {
|
|
|
13
13
|
}
|
|
14
14
|
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
15
15
|
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
16
|
-
const
|
|
16
|
+
const rpcRemote = new ProxyConnectionRpcRemote(
|
|
17
17
|
clientPeerDescriptor,
|
|
18
18
|
serverPeerDescriptor,
|
|
19
19
|
StreamPartIDUtils.parse('stream#0'),
|
|
20
20
|
client
|
|
21
21
|
)
|
|
22
22
|
const userId = randomEthereumAddress()
|
|
23
|
-
|
|
23
|
+
rpcRemote.requestConnection(ProxyDirection.PUBLISH, userId)
|
|
24
24
|
expect(client.requestConnection).toBeCalledWith({
|
|
25
25
|
direction: ProxyDirection.PUBLISH,
|
|
26
26
|
userId: hexToBinary(userId)
|
|
@@ -8,7 +8,8 @@ import { MockLayer1 } from '../utils/mock/MockLayer1'
|
|
|
8
8
|
import { MockNeighborFinder } from '../utils/mock/MockNeighborFinder'
|
|
9
9
|
import { MockNeighborUpdateManager } from '../utils/mock/MockNeighborUpdateManager'
|
|
10
10
|
import { MockTransport } from '../utils/mock/Transport'
|
|
11
|
-
import { createMockPeerDescriptor,
|
|
11
|
+
import { createMockPeerDescriptor, createMockDeliveryRpcRemote, mockConnectionLocker } from '../utils/utils'
|
|
12
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
12
13
|
|
|
13
14
|
describe('RandomGraphNode', () => {
|
|
14
15
|
|
|
@@ -26,7 +27,7 @@ describe('RandomGraphNode', () => {
|
|
|
26
27
|
targetNeighbors = new NodeList(nodeId, 10)
|
|
27
28
|
randomNodeView = new NodeList(nodeId, 10)
|
|
28
29
|
nearbyNodeView = new NodeList(nodeId, 10)
|
|
29
|
-
layer1 = new MockLayer1(
|
|
30
|
+
layer1 = new MockLayer1()
|
|
30
31
|
|
|
31
32
|
randomGraphNode = createRandomGraphNode({
|
|
32
33
|
targetNeighbors,
|
|
@@ -39,7 +40,7 @@ describe('RandomGraphNode', () => {
|
|
|
39
40
|
handshaker: new MockHandshaker(),
|
|
40
41
|
neighborUpdateManager: new MockNeighborUpdateManager(),
|
|
41
42
|
neighborFinder: new MockNeighborFinder(),
|
|
42
|
-
|
|
43
|
+
streamPartId: StreamPartIDUtils.parse('stream#0')
|
|
43
44
|
})
|
|
44
45
|
await randomGraphNode.start()
|
|
45
46
|
})
|
|
@@ -49,7 +50,7 @@ describe('RandomGraphNode', () => {
|
|
|
49
50
|
})
|
|
50
51
|
|
|
51
52
|
it('getTargetNeighborIds', () => {
|
|
52
|
-
const mockRemote =
|
|
53
|
+
const mockRemote = createMockDeliveryRpcRemote()
|
|
53
54
|
targetNeighbors.add(mockRemote)
|
|
54
55
|
const ids = randomGraphNode.getTargetNeighborIds()
|
|
55
56
|
expect(ids[0]).toEqual(getNodeIdFromPeerDescriptor(mockRemote.getPeerDescriptor()))
|
|
@@ -57,7 +58,7 @@ describe('RandomGraphNode', () => {
|
|
|
57
58
|
})
|
|
58
59
|
|
|
59
60
|
it('getNearbyNodeView', () => {
|
|
60
|
-
const mockRemote =
|
|
61
|
+
const mockRemote = createMockDeliveryRpcRemote()
|
|
61
62
|
nearbyNodeView.add(mockRemote)
|
|
62
63
|
const ids = randomGraphNode.getNearbyNodeView().getIds()
|
|
63
64
|
expect(ids[0]).toEqual(getNodeIdFromPeerDescriptor(mockRemote.getPeerDescriptor()))
|
|
@@ -68,8 +69,8 @@ describe('RandomGraphNode', () => {
|
|
|
68
69
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
69
70
|
layer1.emit('newContact', peerDescriptor1, [peerDescriptor1, peerDescriptor2])
|
|
70
71
|
await waitForCondition(() => nearbyNodeView.size() === 2)
|
|
71
|
-
expect(nearbyNodeView.
|
|
72
|
-
expect(nearbyNodeView.
|
|
72
|
+
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor1))).toBeTruthy()
|
|
73
|
+
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
73
74
|
})
|
|
74
75
|
|
|
75
76
|
it('Adds Random Nodes from layer1 newRandomContact event to randomNodeView', async () => {
|
|
@@ -77,8 +78,8 @@ describe('RandomGraphNode', () => {
|
|
|
77
78
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
78
79
|
layer1.emit('newRandomContact', peerDescriptor1, [peerDescriptor1, peerDescriptor2])
|
|
79
80
|
await waitForCondition(() => randomNodeView.size() === 2)
|
|
80
|
-
expect(randomNodeView.
|
|
81
|
-
expect(randomNodeView.
|
|
81
|
+
expect(randomNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor1))).toBeTruthy()
|
|
82
|
+
expect(randomNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
82
83
|
})
|
|
83
84
|
|
|
84
85
|
it('Adds Nodes from layer1 KBucket to nearbyNodeView if its size is below nodeViewSize', async () => {
|
|
@@ -87,8 +88,8 @@ describe('RandomGraphNode', () => {
|
|
|
87
88
|
layer1.addNewRandomPeerToKBucket()
|
|
88
89
|
layer1.emit('newContact', peerDescriptor1, [peerDescriptor1, peerDescriptor2])
|
|
89
90
|
await waitForCondition(() => nearbyNodeView.size() === 3)
|
|
90
|
-
expect(nearbyNodeView.
|
|
91
|
-
expect(nearbyNodeView.
|
|
91
|
+
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor1))).toBeTruthy()
|
|
92
|
+
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
92
93
|
})
|
|
93
94
|
|
|
94
95
|
})
|
|
@@ -3,26 +3,27 @@ import {
|
|
|
3
3
|
MessageID,
|
|
4
4
|
StreamMessage as OldStreamMessage,
|
|
5
5
|
StreamMessageType as OldStreamMessageType,
|
|
6
|
-
StreamPartIDUtils
|
|
7
|
-
toStreamID
|
|
6
|
+
StreamPartIDUtils
|
|
8
7
|
} from '@streamr/protocol'
|
|
9
8
|
import { binaryToHex, binaryToUtf8, hexToBinary, toEthereumAddress, utf8ToBinary } from '@streamr/utils'
|
|
10
9
|
import { StreamMessageTranslator } from '../../src/logic/protocol-integration/stream-message/StreamMessageTranslator'
|
|
11
10
|
import { StreamMessageType } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
12
11
|
import { createStreamMessage } from '../utils/utils'
|
|
13
12
|
|
|
13
|
+
const STREAM_PART_ID = StreamPartIDUtils.parse('TEST#0')
|
|
14
|
+
|
|
14
15
|
describe('StreamMessageTranslator', () => {
|
|
15
16
|
|
|
16
17
|
const publisherId = toEthereumAddress('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
17
18
|
const signature = hexToBinary('0x1234')
|
|
18
19
|
const protobufMsg = createStreamMessage(
|
|
19
20
|
JSON.stringify({ hello: 'WORLD' }),
|
|
20
|
-
|
|
21
|
+
STREAM_PART_ID,
|
|
21
22
|
publisherId
|
|
22
23
|
)
|
|
23
24
|
const messageId = new MessageID(
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
StreamPartIDUtils.getStreamID(STREAM_PART_ID),
|
|
26
|
+
StreamPartIDUtils.getStreamPartition(STREAM_PART_ID),
|
|
26
27
|
Date.now(),
|
|
27
28
|
0,
|
|
28
29
|
publisherId,
|
|
@@ -39,10 +40,10 @@ describe('StreamMessageTranslator', () => {
|
|
|
39
40
|
|
|
40
41
|
it('translates old protocol to protobuf', () => {
|
|
41
42
|
const translated = StreamMessageTranslator.toProtobuf(oldProtocolMsg)
|
|
43
|
+
expect(translated.messageId!.streamId).toEqual(StreamPartIDUtils.getStreamID(STREAM_PART_ID))
|
|
44
|
+
expect(translated.messageId!.streamPartition).toEqual(StreamPartIDUtils.getStreamPartition(STREAM_PART_ID))
|
|
42
45
|
expect(translated.messageId!.timestamp).toBeGreaterThanOrEqual(0)
|
|
43
46
|
expect(translated.messageId!.sequenceNumber).toEqual(0)
|
|
44
|
-
expect(translated.messageId!.streamId).toEqual('TEST')
|
|
45
|
-
expect(translated.messageId!.streamPartition).toEqual(0)
|
|
46
47
|
expect(binaryToHex(translated.messageId!.publisherId, true)).toEqual('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
47
48
|
expect(translated.previousMessageRef).toEqual(undefined)
|
|
48
49
|
expect(translated.messageType).toEqual(StreamMessageType.MESSAGE)
|
|
@@ -53,10 +54,10 @@ describe('StreamMessageTranslator', () => {
|
|
|
53
54
|
|
|
54
55
|
it('translates protobuf to old protocol', () => {
|
|
55
56
|
const translated = StreamMessageTranslator.toClientProtocol(protobufMsg)
|
|
57
|
+
expect(translated.messageId.streamId).toEqual(StreamPartIDUtils.getStreamID(STREAM_PART_ID))
|
|
58
|
+
expect(translated.messageId.streamPartition).toEqual(StreamPartIDUtils.getStreamPartition(STREAM_PART_ID))
|
|
56
59
|
expect(translated.messageId.timestamp).toBeGreaterThanOrEqual(0)
|
|
57
60
|
expect(translated.messageId.sequenceNumber).toEqual(0)
|
|
58
|
-
expect(translated.messageId.streamId).toEqual('TEST')
|
|
59
|
-
expect(translated.messageId.streamPartition).toEqual(0)
|
|
60
61
|
expect(translated.getPublisherId()).toEqual('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
61
62
|
expect(translated.prevMsgRef).toEqual(null)
|
|
62
63
|
expect(translated.messageType).toEqual(OldStreamMessageType.MESSAGE)
|