@streamr/trackerless-network 102.0.0-beta.1 → 102.0.0-beta.3
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,103 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor, areEqualPeerDescriptors, randomDhtAddress } from '@streamr/dht'
|
|
2
|
-
import { wait } from '@streamr/utils'
|
|
3
|
-
import { PeerDescriptorStoreManager } from '../../src/logic/PeerDescriptorStoreManager'
|
|
4
|
-
import { Any } from '../../generated/google/protobuf/any'
|
|
5
|
-
import { DataEntry } from '../../generated/packages/dht/protos/DhtRpc'
|
|
6
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
-
|
|
8
|
-
const KEY = randomDhtAddress()
|
|
9
|
-
|
|
10
|
-
describe('PeerDescriptorStoreManager', () => {
|
|
11
|
-
|
|
12
|
-
let withData: PeerDescriptorStoreManager
|
|
13
|
-
let withoutData: PeerDescriptorStoreManager
|
|
14
|
-
let storeCalled: number
|
|
15
|
-
|
|
16
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
17
|
-
const deletedPeerDescriptor = createMockPeerDescriptor()
|
|
18
|
-
|
|
19
|
-
const fakeData: DataEntry = {
|
|
20
|
-
key: Uint8Array.from([1, 2, 3]),
|
|
21
|
-
data: Any.pack(peerDescriptor, PeerDescriptor),
|
|
22
|
-
creator: peerDescriptor.nodeId,
|
|
23
|
-
ttl: 1000,
|
|
24
|
-
stale: false,
|
|
25
|
-
deleted: false
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const fakeDeletedData: DataEntry = {
|
|
29
|
-
key: Uint8Array.from([1, 2, 3]),
|
|
30
|
-
data: Any.pack(deletedPeerDescriptor, PeerDescriptor),
|
|
31
|
-
creator: deletedPeerDescriptor.nodeId,
|
|
32
|
-
ttl: 1000,
|
|
33
|
-
stale: false,
|
|
34
|
-
deleted: true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const fakeFetchDataFromDht = async (): Promise<DataEntry[]> => {
|
|
38
|
-
return [fakeData, fakeDeletedData]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
const fakeStoreDataToDht = async (): Promise<PeerDescriptor[]> => {
|
|
42
|
-
storeCalled++
|
|
43
|
-
return [peerDescriptor]
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
const fakeEmptyFetchDataFromDht = async (): Promise<DataEntry[]> => {
|
|
47
|
-
return []
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const fakeDeleteDataFromDht = async (): Promise<void> => {}
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
storeCalled = 0
|
|
54
|
-
withData = new PeerDescriptorStoreManager({
|
|
55
|
-
localPeerDescriptor: peerDescriptor,
|
|
56
|
-
key: KEY,
|
|
57
|
-
fetchDataFromDht: fakeFetchDataFromDht,
|
|
58
|
-
storeDataToDht: fakeStoreDataToDht,
|
|
59
|
-
deleteDataFromDht: fakeDeleteDataFromDht,
|
|
60
|
-
storeInterval: 2000
|
|
61
|
-
})
|
|
62
|
-
withoutData = new PeerDescriptorStoreManager({
|
|
63
|
-
localPeerDescriptor: peerDescriptor,
|
|
64
|
-
key: KEY,
|
|
65
|
-
fetchDataFromDht: fakeEmptyFetchDataFromDht,
|
|
66
|
-
storeDataToDht: fakeStoreDataToDht,
|
|
67
|
-
deleteDataFromDht: fakeDeleteDataFromDht,
|
|
68
|
-
storeInterval: 2000
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
afterEach(() => {
|
|
73
|
-
withData.destroy()
|
|
74
|
-
})
|
|
75
|
-
|
|
76
|
-
it('discoverEntryPoints filters deleted data', async () => {
|
|
77
|
-
const res = await withData.fetchNodes()
|
|
78
|
-
expect(res.length).toBe(1)
|
|
79
|
-
expect(areEqualPeerDescriptors(res[0], peerDescriptor)).toBe(true)
|
|
80
|
-
})
|
|
81
|
-
|
|
82
|
-
it('discoverEntryPoints without results', async () => {
|
|
83
|
-
const res = await withoutData.fetchNodes()
|
|
84
|
-
expect(res.length).toBe(0)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
it('store on stream without saturated entrypoint count', async () => {
|
|
88
|
-
await withData.storeAndKeepLocalNode()
|
|
89
|
-
expect(storeCalled).toEqual(1)
|
|
90
|
-
expect(withData.isLocalNodeStored()).toEqual(true)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
it('will keep stored until destroyed', async () => {
|
|
94
|
-
await withData.storeAndKeepLocalNode()
|
|
95
|
-
expect(storeCalled).toEqual(1)
|
|
96
|
-
expect(withData.isLocalNodeStored()).toEqual(true)
|
|
97
|
-
await wait(4500)
|
|
98
|
-
await withData.destroy()
|
|
99
|
-
// we have configured storeInterval to 2 seconds, i.e. after 4.5 seconds it should have been called 2 more items
|
|
100
|
-
expect(storeCalled).toEqual(3)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
})
|
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
import { DhtAddress } from '@streamr/dht'
|
|
2
|
-
import { hexToBinary, toUserIdRaw, wait } from '@streamr/utils'
|
|
3
|
-
import { Propagation } from '../../src/logic/propagation/Propagation'
|
|
4
|
-
import {
|
|
5
|
-
ContentType,
|
|
6
|
-
EncryptionType,
|
|
7
|
-
MessageID,
|
|
8
|
-
SignatureType,
|
|
9
|
-
StreamMessage
|
|
10
|
-
} from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
11
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
12
|
-
|
|
13
|
-
const PUBLISHER_ID = randomUserId()
|
|
14
|
-
|
|
15
|
-
function makeMsg(streamId: string, partition: number, ts: number, msgNo: number): StreamMessage {
|
|
16
|
-
const messageId: MessageID = {
|
|
17
|
-
streamId,
|
|
18
|
-
streamPartition: partition,
|
|
19
|
-
timestamp: ts,
|
|
20
|
-
sequenceNumber: msgNo,
|
|
21
|
-
messageChainId: 'msgChain',
|
|
22
|
-
publisherId: toUserIdRaw(PUBLISHER_ID)
|
|
23
|
-
}
|
|
24
|
-
return {
|
|
25
|
-
messageId,
|
|
26
|
-
signature: hexToBinary('0x1111'),
|
|
27
|
-
signatureType: SignatureType.SECP256K1,
|
|
28
|
-
body: {
|
|
29
|
-
oneofKind: 'contentMessage',
|
|
30
|
-
contentMessage: {
|
|
31
|
-
content: new Uint8Array([1]),
|
|
32
|
-
contentType: ContentType.JSON,
|
|
33
|
-
encryptionType: EncryptionType.NONE
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const TTL = 100
|
|
40
|
-
|
|
41
|
-
const N1 = 'n1' as DhtAddress
|
|
42
|
-
const N2 = 'n2' as DhtAddress
|
|
43
|
-
const N3 = 'n3' as DhtAddress
|
|
44
|
-
const N4 = 'n4' as DhtAddress
|
|
45
|
-
const N5 = 'n5' as DhtAddress
|
|
46
|
-
|
|
47
|
-
describe(Propagation, () => {
|
|
48
|
-
let getNeighbors: jest.Mock<readonly DhtAddress[], [string]>
|
|
49
|
-
let sendToNeighbor: jest.Mock<Promise<void>, [DhtAddress, StreamMessage]>
|
|
50
|
-
let propagation: Propagation
|
|
51
|
-
|
|
52
|
-
beforeEach(() => {
|
|
53
|
-
getNeighbors = jest.fn()
|
|
54
|
-
sendToNeighbor = jest.fn()
|
|
55
|
-
propagation = new Propagation({
|
|
56
|
-
sendToNeighbor,
|
|
57
|
-
minPropagationTargets: 3,
|
|
58
|
-
ttl: TTL,
|
|
59
|
-
maxMessages: 5
|
|
60
|
-
})
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
describe('#feedUnseenMessage', () => {
|
|
64
|
-
it('message is propagated to nodes returned by getNeighbors', () => {
|
|
65
|
-
getNeighbors.mockReturnValueOnce([N1, N2, N3])
|
|
66
|
-
const msg = makeMsg('s1', 0, 1000, 1)
|
|
67
|
-
propagation.feedUnseenMessage(msg, [...getNeighbors('s1#0')], null)
|
|
68
|
-
|
|
69
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(3)
|
|
70
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N1, msg)
|
|
71
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(2, N2, msg)
|
|
72
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(3, N3, msg)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('message does not get propagated to source node (if present in getNeighbors)', () => {
|
|
76
|
-
getNeighbors.mockReturnValueOnce([N1, N2, N3])
|
|
77
|
-
const msg = makeMsg('s1', 0, 1000, 1)
|
|
78
|
-
propagation.feedUnseenMessage(msg, [...getNeighbors('s1#0')], N2)
|
|
79
|
-
|
|
80
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(2)
|
|
81
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N1, msg)
|
|
82
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(2, N3, msg)
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
describe('#onNeighborJoined', () => {
|
|
87
|
-
let msg: StreamMessage
|
|
88
|
-
|
|
89
|
-
async function setUpAndFeed(neighbors: DhtAddress[]): Promise<void> {
|
|
90
|
-
getNeighbors.mockReturnValueOnce(neighbors)
|
|
91
|
-
msg = makeMsg('s1', 0, 1000, 1)
|
|
92
|
-
propagation.feedUnseenMessage(msg, [...getNeighbors('s1#0')], N2)
|
|
93
|
-
await wait(0)
|
|
94
|
-
sendToNeighbor.mockClear()
|
|
95
|
-
getNeighbors.mockClear()
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
it('sends to new neighbor', async () => {
|
|
99
|
-
await setUpAndFeed([N1, N2, N3])
|
|
100
|
-
propagation.onNeighborJoined(N4)
|
|
101
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(1)
|
|
102
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N4, msg)
|
|
103
|
-
})
|
|
104
|
-
|
|
105
|
-
it('sends to previously failed neighbor', async () => {
|
|
106
|
-
sendToNeighbor.mockImplementation(async (neighbor) => {
|
|
107
|
-
if (neighbor === N3) {
|
|
108
|
-
throw new Error('failed to send')
|
|
109
|
-
}
|
|
110
|
-
})
|
|
111
|
-
await setUpAndFeed([N1, N2, N3])
|
|
112
|
-
propagation.onNeighborJoined(N3)
|
|
113
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(1)
|
|
114
|
-
expect(sendToNeighbor).toHaveBeenNthCalledWith(1, N3, msg)
|
|
115
|
-
})
|
|
116
|
-
|
|
117
|
-
it('no-op if passed source node', async () => {
|
|
118
|
-
await setUpAndFeed([N1, N2, N3])
|
|
119
|
-
propagation.onNeighborJoined(N2)
|
|
120
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
121
|
-
})
|
|
122
|
-
|
|
123
|
-
it('no-op if passed already handled neighbor', async () => {
|
|
124
|
-
await setUpAndFeed([N1, N2, N3])
|
|
125
|
-
propagation.onNeighborJoined(N3)
|
|
126
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
127
|
-
})
|
|
128
|
-
|
|
129
|
-
it('no-op if initially `minPropagationTargets` were propagated to', async () => {
|
|
130
|
-
await setUpAndFeed([N1, N2, N3, N4])
|
|
131
|
-
propagation.onNeighborJoined(N5)
|
|
132
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
it('no-op if later `minPropagationTargets` have been propagated to', async () => {
|
|
136
|
-
await setUpAndFeed([N1, N2, N3])
|
|
137
|
-
propagation.onNeighborJoined(N4)
|
|
138
|
-
await wait(0)
|
|
139
|
-
sendToNeighbor.mockClear()
|
|
140
|
-
propagation.onNeighborJoined(N5)
|
|
141
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
142
|
-
})
|
|
143
|
-
|
|
144
|
-
it('no-op if TTL expires', async () => {
|
|
145
|
-
await setUpAndFeed([N1, N2, N3])
|
|
146
|
-
await wait(200)
|
|
147
|
-
propagation.onNeighborJoined(N3)
|
|
148
|
-
expect(sendToNeighbor).toHaveBeenCalledTimes(0)
|
|
149
|
-
})
|
|
150
|
-
})
|
|
151
|
-
})
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
|
-
import { randomUserId } from '@streamr/test-utils'
|
|
3
|
-
import { hexToBinary } from '@streamr/utils'
|
|
4
|
-
import { ProxyConnectionRpcRemote } from '../../src/logic/proxy/ProxyConnectionRpcRemote'
|
|
5
|
-
import { ProxyConnectionRequest, ProxyDirection } from '../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
6
|
-
import { ProxyConnectionRpcClient } from '../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
7
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
8
|
-
|
|
9
|
-
describe('ProxyConnectionRpcRemote', () => {
|
|
10
|
-
|
|
11
|
-
it('happy path', async () => {
|
|
12
|
-
const onOutgoingMessage = jest.fn()
|
|
13
|
-
const rpcCommunicator = new RpcCommunicator()
|
|
14
|
-
rpcCommunicator.setOutgoingMessageListener(onOutgoingMessage)
|
|
15
|
-
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
16
|
-
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
17
|
-
const rpcRemote = new ProxyConnectionRpcRemote(
|
|
18
|
-
clientPeerDescriptor,
|
|
19
|
-
serverPeerDescriptor,
|
|
20
|
-
rpcCommunicator,
|
|
21
|
-
ProxyConnectionRpcClient
|
|
22
|
-
)
|
|
23
|
-
|
|
24
|
-
const userId = randomUserId()
|
|
25
|
-
await rpcRemote.requestConnection(ProxyDirection.PUBLISH, userId)
|
|
26
|
-
|
|
27
|
-
const [rpcMessage, _, callContext] = onOutgoingMessage.mock.calls[0]
|
|
28
|
-
const request = ProxyConnectionRequest.fromBinary(rpcMessage.body.value)
|
|
29
|
-
expect(request).toEqual({
|
|
30
|
-
direction: ProxyDirection.PUBLISH,
|
|
31
|
-
userId: expect.toEqualBinary(hexToBinary(userId))
|
|
32
|
-
})
|
|
33
|
-
expect(callContext).toMatchObject({
|
|
34
|
-
sourceDescriptor: clientPeerDescriptor,
|
|
35
|
-
targetDescriptor: serverPeerDescriptor,
|
|
36
|
-
timeout: 5000
|
|
37
|
-
})
|
|
38
|
-
})
|
|
39
|
-
})
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
2
|
-
import { streamPartIdToDataKey } from '../../src/logic/ContentDeliveryManager'
|
|
3
|
-
|
|
4
|
-
describe('StreamPartIDtoDataKey', () => {
|
|
5
|
-
|
|
6
|
-
it('generated key length is correct (160 bits)', () => {
|
|
7
|
-
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
8
|
-
const dataKey = streamPartIdToDataKey(streamPartId)
|
|
9
|
-
expect(dataKey.length).toEqual(40)
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
})
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { MIN_NEIGHBOR_COUNT, StreamPartNetworkSplitAvoidance } from '../../src/logic/StreamPartNetworkSplitAvoidance'
|
|
2
|
-
import { MockDiscoveryLayerNode } from '../utils/mock/MockDiscoveryLayerNode'
|
|
3
|
-
|
|
4
|
-
describe('StreamPartNetworkSplitAvoidance', () => {
|
|
5
|
-
|
|
6
|
-
let avoidance: StreamPartNetworkSplitAvoidance
|
|
7
|
-
let discoveryLayerNode: MockDiscoveryLayerNode
|
|
8
|
-
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
discoveryLayerNode = new MockDiscoveryLayerNode()
|
|
11
|
-
avoidance = new StreamPartNetworkSplitAvoidance({
|
|
12
|
-
discoveryLayerNode,
|
|
13
|
-
discoverEntryPoints: async () => {
|
|
14
|
-
discoveryLayerNode.addNewRandomPeerToKBucket()
|
|
15
|
-
return discoveryLayerNode.getNeighbors()
|
|
16
|
-
},
|
|
17
|
-
exponentialRunOfBaseDelay: 1
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
afterEach(() => {
|
|
22
|
-
discoveryLayerNode.stop()
|
|
23
|
-
avoidance.destroy()
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
it('runs avoidance until number of neighbors is above MIN_NEIGHBOR_COUNT', async () => {
|
|
27
|
-
await avoidance.avoidNetworkSplit()
|
|
28
|
-
expect(discoveryLayerNode.getNeighborCount()).toBeGreaterThan(MIN_NEIGHBOR_COUNT)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
})
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptorStoreManager } from '../../src/logic/PeerDescriptorStoreManager'
|
|
2
|
-
import { StreamPartReconnect } from '../../src/logic/StreamPartReconnect'
|
|
3
|
-
import { MockDiscoveryLayerNode } from '../utils/mock/MockDiscoveryLayerNode'
|
|
4
|
-
import { createFakePeerDescriptorStoreManager } from '../utils/fake/FakePeerDescriptorStoreManager'
|
|
5
|
-
import { until } from '@streamr/utils'
|
|
6
|
-
|
|
7
|
-
describe('StreamPartReconnect', () => {
|
|
8
|
-
|
|
9
|
-
let peerDescriptorSoreManager: PeerDescriptorStoreManager
|
|
10
|
-
let discoveryLayerNode: MockDiscoveryLayerNode
|
|
11
|
-
let streamPartReconnect: StreamPartReconnect
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
peerDescriptorSoreManager = createFakePeerDescriptorStoreManager()
|
|
15
|
-
discoveryLayerNode = new MockDiscoveryLayerNode()
|
|
16
|
-
streamPartReconnect = new StreamPartReconnect(discoveryLayerNode, peerDescriptorSoreManager)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
afterEach(() => {
|
|
20
|
-
streamPartReconnect.destroy()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('Happy path', async () => {
|
|
24
|
-
await streamPartReconnect.reconnect(1000)
|
|
25
|
-
expect(streamPartReconnect.isRunning()).toEqual(true)
|
|
26
|
-
discoveryLayerNode.addNewRandomPeerToKBucket()
|
|
27
|
-
await until(() => streamPartReconnect.isRunning() === false)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
})
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { ListeningRpcCommunicator, toDhtAddress } from '@streamr/dht'
|
|
2
|
-
import { StreamPartIDUtils } from '@streamr/utils'
|
|
3
|
-
import { TemporaryConnectionRpcLocal } from '../../src/logic/temporary-connection/TemporaryConnectionRpcLocal'
|
|
4
|
-
import { MockTransport } from '../utils/mock/MockTransport'
|
|
5
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
6
|
-
|
|
7
|
-
describe('TemporaryConnectionRpcLocal', () => {
|
|
8
|
-
|
|
9
|
-
const peerDescriptor = createMockPeerDescriptor()
|
|
10
|
-
let rpcCommunicator: ListeningRpcCommunicator
|
|
11
|
-
let rpcLocal: TemporaryConnectionRpcLocal
|
|
12
|
-
|
|
13
|
-
beforeEach(() => {
|
|
14
|
-
rpcCommunicator = new ListeningRpcCommunicator('mock', new MockTransport())
|
|
15
|
-
rpcLocal = new TemporaryConnectionRpcLocal({
|
|
16
|
-
localPeerDescriptor: peerDescriptor,
|
|
17
|
-
rpcCommunicator,
|
|
18
|
-
streamPartId: StreamPartIDUtils.parse('mock#0'),
|
|
19
|
-
connectionLocker: {
|
|
20
|
-
weakLockConnection: jest.fn(),
|
|
21
|
-
weakUnlockConnection: jest.fn()
|
|
22
|
-
} as any
|
|
23
|
-
})
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
afterEach(() => {
|
|
27
|
-
rpcCommunicator.destroy()
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('Open and Close Connection', async () => {
|
|
31
|
-
const caller = createMockPeerDescriptor()
|
|
32
|
-
await rpcLocal.openConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
33
|
-
expect(rpcLocal.getNodes().get(toDhtAddress(caller.nodeId))).toBeDefined()
|
|
34
|
-
await rpcLocal.closeConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
35
|
-
expect(rpcLocal.getNodes().get(toDhtAddress(caller.nodeId))).toBeUndefined()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
})
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor } from '@streamr/dht'
|
|
2
|
-
import { PeerDescriptorStoreManager } from '../../../src/logic/PeerDescriptorStoreManager'
|
|
3
|
-
|
|
4
|
-
export const createFakePeerDescriptorStoreManager = (): PeerDescriptorStoreManager => {
|
|
5
|
-
return new FakePeerDescriptorStoreManager() as unknown as PeerDescriptorStoreManager
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
class FakePeerDescriptorStoreManager {
|
|
9
|
-
|
|
10
|
-
private nodes: PeerDescriptor[] = []
|
|
11
|
-
|
|
12
|
-
setNodes(nodes: PeerDescriptor[]): void {
|
|
13
|
-
this.nodes = nodes
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
async fetchNodes(): Promise<PeerDescriptor[]> {
|
|
17
|
-
return this.nodes
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line class-methods-use-this
|
|
21
|
-
async storeAndKeepLocalNode(): Promise<void> {
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line class-methods-use-this
|
|
25
|
-
isLocalNodeStored(): boolean {
|
|
26
|
-
return true
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor } from '@streamr/dht'
|
|
2
|
-
|
|
3
|
-
export class MockConnectionsView {
|
|
4
|
-
// eslint-disable-next-line class-methods-use-this
|
|
5
|
-
getConnections(): PeerDescriptor[] {
|
|
6
|
-
return []
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
// eslint-disable-next-line class-methods-use-this
|
|
10
|
-
getConnectionCount(): number {
|
|
11
|
-
return 0
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
// eslint-disable-next-line class-methods-use-this
|
|
15
|
-
hasConnection(): boolean {
|
|
16
|
-
return false
|
|
17
|
-
}
|
|
18
|
-
}
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor, DataEntry, ITransport, TransportEvents, ConnectionsView } from '@streamr/dht'
|
|
2
|
-
import { ControlLayerNode } from '../../../src/logic/ControlLayerNode'
|
|
3
|
-
import { EventEmitter } from 'eventemitter3'
|
|
4
|
-
import { MockConnectionsView } from './MockConnectionsView'
|
|
5
|
-
|
|
6
|
-
export class MockControlLayerNode extends EventEmitter<TransportEvents> implements ControlLayerNode {
|
|
7
|
-
|
|
8
|
-
private readonly peerDescriptor: PeerDescriptor
|
|
9
|
-
|
|
10
|
-
constructor(peerDescriptor: PeerDescriptor) {
|
|
11
|
-
super()
|
|
12
|
-
this.peerDescriptor = peerDescriptor
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// eslint-disable-next-line class-methods-use-this
|
|
16
|
-
joinDht(): Promise<void> {
|
|
17
|
-
throw new Error('not implemented')
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line class-methods-use-this
|
|
21
|
-
hasJoined(): boolean {
|
|
22
|
-
throw new Error('not implemented')
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
getLocalPeerDescriptor(): PeerDescriptor {
|
|
26
|
-
return this.peerDescriptor
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line class-methods-use-this
|
|
30
|
-
async fetchDataFromDht(): Promise<DataEntry[]> {
|
|
31
|
-
return []
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// eslint-disable-next-line class-methods-use-this
|
|
35
|
-
async deleteDataFromDht(): Promise<void> {
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
// eslint-disable-next-line class-methods-use-this
|
|
39
|
-
async storeDataToDht(): Promise<PeerDescriptor[]> {
|
|
40
|
-
return []
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
// eslint-disable-next-line class-methods-use-this
|
|
44
|
-
async send(): Promise<void> {
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// eslint-disable-next-line class-methods-use-this
|
|
48
|
-
getConnectionsView(): ConnectionsView {
|
|
49
|
-
return new MockConnectionsView()
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// eslint-disable-next-line class-methods-use-this
|
|
53
|
-
getNeighbors(): PeerDescriptor[] {
|
|
54
|
-
return []
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
// eslint-disable-next-line class-methods-use-this
|
|
58
|
-
async waitForNetworkConnectivity(): Promise<void> {
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
// eslint-disable-next-line class-methods-use-this
|
|
62
|
-
getTransport(): ITransport {
|
|
63
|
-
throw new Error('not implemented')
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// eslint-disable-next-line class-methods-use-this
|
|
67
|
-
async start(): Promise<void> {
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// eslint-disable-next-line class-methods-use-this
|
|
71
|
-
async stop(): Promise<void> {
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// eslint-disable-next-line class-methods-use-this
|
|
75
|
-
getDiagnosticInfo(): Record<string, unknown> {
|
|
76
|
-
return {}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor, RingContacts } from '@streamr/dht'
|
|
2
|
-
import { EventEmitter } from 'eventemitter3'
|
|
3
|
-
import { DiscoveryLayerNode, DiscoveryLayerNodeEvents } from '../../../src/logic/DiscoveryLayerNode'
|
|
4
|
-
import { createMockPeerDescriptor } from '../utils'
|
|
5
|
-
|
|
6
|
-
export class MockDiscoveryLayerNode extends EventEmitter<DiscoveryLayerNodeEvents> implements DiscoveryLayerNode {
|
|
7
|
-
|
|
8
|
-
private readonly kbucketPeers: PeerDescriptor[] = []
|
|
9
|
-
private closestContacts: PeerDescriptor[] = []
|
|
10
|
-
private randomContacts: PeerDescriptor[] = []
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line class-methods-use-this
|
|
13
|
-
removeContact(): void {
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
getClosestContacts(): PeerDescriptor[] {
|
|
17
|
-
return this.closestContacts
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
setClosestContacts(contacts: PeerDescriptor[]): void {
|
|
21
|
-
this.closestContacts = contacts
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
getRandomContacts(): PeerDescriptor[] {
|
|
25
|
-
return this.randomContacts
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
setRandomContacts(contacts: PeerDescriptor[]): void {
|
|
29
|
-
this.randomContacts = contacts
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
// eslint-disable-next-line class-methods-use-this
|
|
33
|
-
getRingContacts(): RingContacts {
|
|
34
|
-
return { left: [], right: [] }
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
getNeighbors(): PeerDescriptor[] {
|
|
38
|
-
return this.kbucketPeers
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getNeighborCount(): number {
|
|
42
|
-
return this.kbucketPeers.length
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
addNewRandomPeerToKBucket(): void {
|
|
46
|
-
this.kbucketPeers.push(createMockPeerDescriptor())
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// eslint-disable-next-line class-methods-use-this
|
|
50
|
-
async joinDht(): Promise<void> {}
|
|
51
|
-
|
|
52
|
-
// eslint-disable-next-line class-methods-use-this
|
|
53
|
-
async joinRing(): Promise<void> {}
|
|
54
|
-
|
|
55
|
-
// eslint-disable-next-line class-methods-use-this
|
|
56
|
-
async start(): Promise<void> {}
|
|
57
|
-
|
|
58
|
-
// eslint-disable-next-line class-methods-use-this
|
|
59
|
-
async stop(): Promise<void> {}
|
|
60
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Methods } from '@streamr/test-utils'
|
|
2
|
-
import { Handshaker } from '../../../src/logic/neighbor-discovery/Handshaker'
|
|
3
|
-
import { DhtAddress } from '@streamr/dht'
|
|
4
|
-
|
|
5
|
-
export class MockHandshaker implements Methods<Handshaker> {
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line class-methods-use-this
|
|
8
|
-
getOngoingHandshakes(): Set<DhtAddress> {
|
|
9
|
-
return new Set()
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line class-methods-use-this
|
|
13
|
-
async attemptHandshakesOnContacts(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
14
|
-
return excludedIds
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Methods } from '@streamr/test-utils'
|
|
2
|
-
import { NeighborFinder } from '../../../src/logic/neighbor-discovery/NeighborFinder'
|
|
3
|
-
|
|
4
|
-
export class MockNeighborFinder implements Methods<NeighborFinder> {
|
|
5
|
-
|
|
6
|
-
// eslint-disable-next-line class-methods-use-this
|
|
7
|
-
start(): void {
|
|
8
|
-
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line class-methods-use-this
|
|
12
|
-
stop(): void {
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// eslint-disable-next-line class-methods-use-this
|
|
17
|
-
isRunning(): boolean {
|
|
18
|
-
return false
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { Methods } from '@streamr/test-utils'
|
|
2
|
-
import { NeighborUpdateManager } from '../../../src/logic/neighbor-discovery/NeighborUpdateManager'
|
|
3
|
-
import { NeighborUpdate } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
4
|
-
|
|
5
|
-
export class MockNeighborUpdateManager implements Methods<NeighborUpdateManager> {
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line class-methods-use-this
|
|
8
|
-
async start(): Promise<void> {
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line class-methods-use-this
|
|
13
|
-
stop(): void {
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line class-methods-use-this
|
|
18
|
-
async neighborUpdate(): Promise<NeighborUpdate> {
|
|
19
|
-
return NeighborUpdate.create()
|
|
20
|
-
}
|
|
21
|
-
}
|