@streamr/trackerless-network 102.0.0-beta.1 → 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/package.json +5 -5
- package/package.json +5 -5
- package/src/NetworkNode.ts +0 -142
- package/src/NetworkStack.ts +0 -197
- package/src/exports.ts +0 -18
- package/src/logic/ContentDeliveryLayerNode.ts +0 -424
- package/src/logic/ContentDeliveryManager.ts +0 -401
- 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 -55
- 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 -286
- 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/types.ts +0 -13
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +0 -60
- package/test/benchmark/first-message.ts +0 -171
- package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +0 -165
- 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 -226
- package/test/end-to-end/proxy-key-exchange.test.ts +0 -126
- package/test/end-to-end/webrtc-full-node-network.test.ts +0 -83
- package/test/end-to-end/websocket-full-node-network.test.ts +0 -82
- 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 -160
- package/test/integration/ContentDeliveryRpcRemote.test.ts +0 -100
- package/test/integration/HandshakeRpcRemote.test.ts +0 -79
- package/test/integration/Handshakes.test.ts +0 -141
- 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 -1
- package/test/unit/ContentDeliveryLayerNode.test.ts +0 -112
- package/test/unit/ContentDeliveryManager.test.ts +0 -96
- 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 -155
- package/test/unit/Handshaker.test.ts +0 -69
- package/test/unit/InspectSession.test.ts +0 -83
- 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 -144
- package/tsconfig.browser.json +0 -13
- package/tsconfig.jest.json +0 -17
- package/tsconfig.json +0 -3
- package/tsconfig.node.json +0 -17
|
@@ -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,83 +0,0 @@
|
|
|
1
|
-
import { InspectSession, Events } from '../../src/logic/inspect/InspectSession'
|
|
2
|
-
import { MessageID } from '../../generated/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
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
56
|
-
inspectSession.markMessage(inspectedNode, messageId1)
|
|
57
|
-
])
|
|
58
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(1)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
it('should emit done event another node sends message after inspected node', async () => {
|
|
62
|
-
inspectSession.markMessage(inspectedNode, messageId1)
|
|
63
|
-
await Promise.all([
|
|
64
|
-
waitForEvent3<Events>(inspectSession, 'done', 100),
|
|
65
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
66
|
-
inspectSession.markMessage(anotherNode, messageId1)
|
|
67
|
-
])
|
|
68
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(1)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
it('should not emit done if messageIds do not match', async () => {
|
|
72
|
-
inspectSession.markMessage(inspectedNode, messageId1)
|
|
73
|
-
await expect(async () => {
|
|
74
|
-
await Promise.all([
|
|
75
|
-
waitForEvent3<Events>(inspectSession, 'done', 100),
|
|
76
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
77
|
-
inspectSession.markMessage(anotherNode, messageId2)
|
|
78
|
-
])
|
|
79
|
-
}).rejects.toThrow('waitForEvent3')
|
|
80
|
-
|
|
81
|
-
expect(inspectSession.getInspectedMessageCount()).toBe(2)
|
|
82
|
-
})
|
|
83
|
-
})
|
|
@@ -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).toHaveBeenCalledTimes(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 { until } 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 until(() => 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 '../../generated/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 '../../generated/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).toHaveBeenCalledTimes(2)
|
|
37
|
-
|
|
38
|
-
node.removeMessageListener(onMessage)
|
|
39
|
-
contentDeliveryManager.emit('newMessage', createMessage(3))
|
|
40
|
-
expect(onMessage).toHaveBeenCalledTimes(2)
|
|
41
|
-
})
|
|
42
|
-
})
|
|
@@ -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 '../../generated/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
|
-
})
|