@streamr/dht 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/generated/google/protobuf/any.d.ts +180 -0
- package/dist/generated/google/protobuf/any.js +155 -0
- package/dist/generated/google/protobuf/any.js.map +1 -0
- package/dist/generated/google/protobuf/empty.d.ts +31 -0
- package/dist/generated/google/protobuf/empty.js +32 -0
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/generated/google/protobuf/timestamp.d.ts +155 -0
- package/dist/generated/google/protobuf/timestamp.js +136 -0
- package/dist/generated/google/protobuf/timestamp.js.map +1 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +361 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js +285 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/generated/packages/dht/protos/DhtRpc.d.ts +999 -0
- package/dist/generated/packages/dht/protos/DhtRpc.js +677 -0
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +162 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js +3 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +66 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/package.json +7 -7
- package/package.json +7 -7
- package/eslint.config.mjs +0 -12
- package/src/connection/Connection.ts +0 -28
- package/src/connection/ConnectionLockRpcLocal.ts +0 -78
- package/src/connection/ConnectionLockRpcRemote.ts +0 -64
- package/src/connection/ConnectionLockStates.ts +0 -131
- package/src/connection/ConnectionManager.ts +0 -661
- package/src/connection/ConnectionsView.ts +0 -8
- package/src/connection/ConnectorFacade.ts +0 -217
- package/src/connection/Handshaker.ts +0 -209
- package/src/connection/IConnection.ts +0 -40
- package/src/connection/ManagedConnection.ts +0 -113
- package/src/connection/OutputBuffer.ts +0 -28
- package/src/connection/PendingConnection.ts +0 -68
- package/src/connection/connectivityChecker.ts +0 -108
- package/src/connection/connectivityRequestHandler.ts +0 -116
- package/src/connection/simulator/Simulator.ts +0 -369
- package/src/connection/simulator/SimulatorConnection.ts +0 -137
- package/src/connection/simulator/SimulatorConnector.ts +0 -98
- package/src/connection/simulator/SimulatorTransport.ts +0 -15
- package/src/connection/simulator/pings.ts +0 -42
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -242
- package/src/connection/webrtc/IWebrtcConnection.ts +0 -24
- package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -245
- package/src/connection/webrtc/WebrtcConnector.ts +0 -234
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +0 -108
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +0 -60
- package/src/connection/webrtc/iceServerAsString.ts +0 -15
- package/src/connection/websocket/AbstractWebsocketClientConnection.ts +0 -122
- package/src/connection/websocket/AutoCertifierClientFacade.ts +0 -89
- package/src/connection/websocket/BrowserWebsocketClientConnection.ts +0 -44
- package/src/connection/websocket/NodeWebsocketClientConnection.ts +0 -39
- package/src/connection/websocket/WebsocketClientConnector.ts +0 -119
- package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +0 -38
- package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +0 -19
- package/src/connection/websocket/WebsocketServer.ts +0 -164
- package/src/connection/websocket/WebsocketServerConnection.ts +0 -109
- package/src/connection/websocket/WebsocketServerConnector.ts +0 -290
- package/src/dht/DhtNode.ts +0 -683
- package/src/dht/DhtNodeRpcLocal.ts +0 -84
- package/src/dht/DhtNodeRpcRemote.ts +0 -107
- package/src/dht/ExternalApiRpcLocal.ts +0 -58
- package/src/dht/ExternalApiRpcRemote.ts +0 -41
- package/src/dht/PeerManager.ts +0 -305
- package/src/dht/contact/Contact.ts +0 -19
- package/src/dht/contact/ContactList.ts +0 -43
- package/src/dht/contact/RandomContactList.ts +0 -56
- package/src/dht/contact/RingContactList.ts +0 -143
- package/src/dht/contact/RpcRemote.ts +0 -72
- package/src/dht/contact/SortedContactList.ts +0 -173
- package/src/dht/contact/getClosestNodes.ts +0 -24
- package/src/dht/contact/ringIdentifiers.ts +0 -62
- package/src/dht/discovery/DiscoverySession.ts +0 -129
- package/src/dht/discovery/PeerDiscovery.ts +0 -244
- package/src/dht/discovery/RingDiscoverySession.ts +0 -148
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +0 -251
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -34
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +0 -43
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +0 -231
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +0 -35
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +0 -30
- package/src/dht/routing/DuplicateDetector.ts +0 -34
- package/src/dht/routing/Router.ts +0 -246
- package/src/dht/routing/RouterRpcLocal.ts +0 -78
- package/src/dht/routing/RouterRpcRemote.ts +0 -80
- package/src/dht/routing/RoutingSession.ts +0 -243
- package/src/dht/routing/RoutingTablesCache.ts +0 -60
- package/src/dht/routing/getPreviousPeer.ts +0 -6
- package/src/dht/store/LocalDataStore.ts +0 -84
- package/src/dht/store/StoreManager.ts +0 -170
- package/src/dht/store/StoreRpcLocal.ts +0 -89
- package/src/dht/store/StoreRpcRemote.ts +0 -32
- package/src/exports.ts +0 -33
- package/src/helpers/AddressTools.ts +0 -28
- package/src/helpers/Connectivity.ts +0 -19
- package/src/helpers/browser/isBrowserEnvironment.ts +0 -1
- package/src/helpers/browser/isBrowserEnvironment_override.ts +0 -3
- package/src/helpers/createPeerDescriptor.ts +0 -57
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +0 -28
- package/src/helpers/debugHelpers.ts +0 -9
- package/src/helpers/errors.ts +0 -49
- package/src/helpers/offering.ts +0 -15
- package/src/helpers/protoClasses.ts +0 -57
- package/src/helpers/protoToString.ts +0 -21
- package/src/helpers/version.ts +0 -32
- package/src/identifiers.ts +0 -29
- package/src/rpc-protocol/DhtCallContext.ts +0 -14
- package/src/rpc-protocol/DhtRpcOptions.ts +0 -10
- package/src/transport/ITransport.ts +0 -37
- package/src/transport/ListeningRpcCommunicator.ts +0 -32
- package/src/transport/RoutingRpcCommunicator.ts +0 -66
- package/src/types/ServiceID.ts +0 -1
- package/src/types/textencoding.d.ts +0 -6
- package/test/benchmark/Find.test.ts +0 -72
- package/test/benchmark/KademliaCorrectness.test.ts +0 -114
- package/test/benchmark/RingCorrectness.test.ts +0 -157
- package/test/benchmark/SortedContactListBenchmark.test.ts +0 -108
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +0 -41
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +0 -71
- package/test/end-to-end/GeoIpLayer0.test.ts +0 -55
- package/test/end-to-end/Layer0-Layer1.test.ts +0 -93
- package/test/end-to-end/Layer0.test.ts +0 -76
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +0 -110
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +0 -137
- package/test/end-to-end/Layer0Webrtc.test.ts +0 -85
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +0 -82
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +0 -76
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +0 -52
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +0 -69
- package/test/end-to-end/memory-leak.test.ts +0 -80
- package/test/integration/ConnectionLocking.test.ts +0 -192
- package/test/integration/ConnectionManager.test.ts +0 -528
- package/test/integration/ConnectivityChecking.test.ts +0 -53
- package/test/integration/DhtJoinPeerDiscovery.test.ts +0 -49
- package/test/integration/DhtNode.test.ts +0 -66
- package/test/integration/DhtNodeExternalAPI.test.ts +0 -48
- package/test/integration/DhtNodeRpcRemote.test.ts +0 -66
- package/test/integration/DhtRpc.test.ts +0 -121
- package/test/integration/Find.test.ts +0 -45
- package/test/integration/GeoIpConnectivityChecking.test.ts +0 -72
- package/test/integration/Layer1-scale.test.ts +0 -189
- package/test/integration/Mock-Layer1-Layer0.test.ts +0 -85
- package/test/integration/MultipleEntryPointJoining.test.ts +0 -105
- package/test/integration/ReplicateData.test.ts +0 -104
- package/test/integration/RouteMessage.test.ts +0 -230
- package/test/integration/RouterRpcRemote.test.ts +0 -77
- package/test/integration/SimultaneousConnections.test.ts +0 -316
- package/test/integration/Store.test.ts +0 -85
- package/test/integration/StoreAndDelete.test.ts +0 -77
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +0 -59
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +0 -51
- package/test/integration/StoreRpcRemote.test.ts +0 -54
- package/test/integration/WebrtcConnectionManagement.test.ts +0 -191
- package/test/integration/WebrtcConnectorRpc.test.ts +0 -125
- package/test/integration/Websocket.test.ts +0 -65
- package/test/integration/WebsocketClientConnectorRpc.test.ts +0 -69
- package/test/integration/WebsocketConnectionManagement.test.ts +0 -191
- package/test/integration/rpc-connections-over-webrtc.test.ts +0 -123
- package/test/kademlia-simulation/data/nodeids.json +0 -13002
- package/test/kademlia-simulation/data/orderedneighbors.json +0 -1001
- package/test/types/global.d.ts +0 -1
- package/test/unit/AddressTools.test.ts +0 -44
- package/test/unit/AutoCertifierClientFacade.test.ts +0 -58
- package/test/unit/ConnectionManager.test.ts +0 -65
- package/test/unit/ConnectivityHelpers.test.ts +0 -61
- package/test/unit/DiscoverySession.test.ts +0 -87
- package/test/unit/DuplicateDetector.test.ts +0 -31
- package/test/unit/Handshaker.test.ts +0 -169
- package/test/unit/ListeningRpcCommunicator.test.ts +0 -52
- package/test/unit/LocalDataStore.test.ts +0 -108
- package/test/unit/ManagedConnection.test.ts +0 -58
- package/test/unit/PeerManager.test.ts +0 -93
- package/test/unit/PendingConnection.test.ts +0 -57
- package/test/unit/ProtobufMessage.test.ts +0 -21
- package/test/unit/RandomContactList.test.ts +0 -58
- package/test/unit/RecursiveOperationManager.test.ts +0 -161
- package/test/unit/RecursiveOperationSession.test.ts +0 -68
- package/test/unit/Router.test.ts +0 -137
- package/test/unit/RoutingSession.test.ts +0 -86
- package/test/unit/SortedContactList.test.ts +0 -115
- package/test/unit/StoreManager.test.ts +0 -146
- package/test/unit/StoreRpcLocal.test.ts +0 -167
- package/test/unit/WebrtcConnection.test.ts +0 -29
- package/test/unit/WebrtcConnector.test.ts +0 -56
- package/test/unit/WebsocketClientConnector.test.ts +0 -101
- package/test/unit/WebsocketServer.test.ts +0 -66
- package/test/unit/WebsocketServerConnector.test.ts +0 -102
- package/test/unit/connectivityRequestHandler.test.ts +0 -104
- package/test/unit/createPeerDescriptor.test.ts +0 -69
- package/test/unit/customMatchers.test.ts +0 -34
- package/test/unit/getClosestNodes.test.ts +0 -30
- package/test/unit/version.test.ts +0 -18
- package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +0 -18
- package/test/utils/FakeConnectorFacade.ts +0 -41
- package/test/utils/FakeRpcCommunicator.ts +0 -23
- package/test/utils/FakeTransport.ts +0 -79
- package/test/utils/customMatchers.ts +0 -71
- package/test/utils/mock/MockConnection.ts +0 -26
- package/test/utils/mock/MockConnectionsView.ts +0 -18
- package/test/utils/mock/MockRouter.ts +0 -62
- package/test/utils/mock/MockRpcCommunicator.ts +0 -7
- package/test/utils/mock/MockTransport.ts +0 -26
- package/test/utils/mock/mockDataEntry.ts +0 -38
- package/test/utils/topology.ts +0 -79
- package/test/utils/utils.ts +0 -268
- package/tsconfig.browser.json +0 -17
- package/tsconfig.jest.json +0 -25
- package/tsconfig.json +0 -3
- package/tsconfig.node.json +0 -24
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
|
-
|
|
6
|
-
describe('multiple entry point joining', () => {
|
|
7
|
-
|
|
8
|
-
describe('all nodes are entry points', () => {
|
|
9
|
-
|
|
10
|
-
let simulator: Simulator
|
|
11
|
-
let node1: DhtNode
|
|
12
|
-
let node2: DhtNode
|
|
13
|
-
let node3: DhtNode
|
|
14
|
-
let entryPoints: PeerDescriptor[]
|
|
15
|
-
|
|
16
|
-
beforeEach(async () => {
|
|
17
|
-
simulator = new Simulator(LatencyType.REAL)
|
|
18
|
-
|
|
19
|
-
node1 = await createMockConnectionDhtNode(simulator)
|
|
20
|
-
node2 = await createMockConnectionDhtNode(simulator)
|
|
21
|
-
node3 = await createMockConnectionDhtNode(simulator)
|
|
22
|
-
|
|
23
|
-
entryPoints = [
|
|
24
|
-
node1.getLocalPeerDescriptor(),
|
|
25
|
-
node2.getLocalPeerDescriptor(),
|
|
26
|
-
node3.getLocalPeerDescriptor()
|
|
27
|
-
]
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
afterEach(async () => {
|
|
31
|
-
await Promise.all([
|
|
32
|
-
node1.stop(),
|
|
33
|
-
node2.stop(),
|
|
34
|
-
node3.stop()
|
|
35
|
-
])
|
|
36
|
-
simulator.stop()
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('can join simultaneously', async () => {
|
|
40
|
-
await Promise.all([
|
|
41
|
-
node1.joinDht(entryPoints),
|
|
42
|
-
node2.joinDht(entryPoints),
|
|
43
|
-
node3.joinDht(entryPoints)
|
|
44
|
-
])
|
|
45
|
-
expect(node1.getNeighborCount()).toEqual(2)
|
|
46
|
-
expect(node2.getNeighborCount()).toEqual(2)
|
|
47
|
-
expect(node3.getNeighborCount()).toEqual(2)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('can join even if a node is offline', async () => {
|
|
51
|
-
await node3.stop()
|
|
52
|
-
await Promise.all([
|
|
53
|
-
node1.joinDht(entryPoints),
|
|
54
|
-
node2.joinDht(entryPoints)
|
|
55
|
-
])
|
|
56
|
-
expect(node1.getNeighborCount()).toEqual(1)
|
|
57
|
-
expect(node2.getNeighborCount()).toEqual(1)
|
|
58
|
-
}, 10000)
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
describe('non entry point nodes can join via multiple entry points', () => {
|
|
62
|
-
let simulator: Simulator
|
|
63
|
-
let entryPoint1: DhtNode
|
|
64
|
-
let entryPoint2: DhtNode
|
|
65
|
-
let node1: DhtNode
|
|
66
|
-
let node2: DhtNode
|
|
67
|
-
let entryPoints: PeerDescriptor[]
|
|
68
|
-
|
|
69
|
-
beforeEach(async () => {
|
|
70
|
-
simulator = new Simulator(LatencyType.REAL)
|
|
71
|
-
|
|
72
|
-
entryPoint1 = await createMockConnectionDhtNode(simulator)
|
|
73
|
-
entryPoint2 = await createMockConnectionDhtNode(simulator)
|
|
74
|
-
|
|
75
|
-
node1 = await createMockConnectionDhtNode(simulator)
|
|
76
|
-
node2 = await createMockConnectionDhtNode(simulator)
|
|
77
|
-
|
|
78
|
-
entryPoints = [
|
|
79
|
-
entryPoint1.getLocalPeerDescriptor(),
|
|
80
|
-
entryPoint2.getLocalPeerDescriptor(),
|
|
81
|
-
]
|
|
82
|
-
|
|
83
|
-
await entryPoint1.joinDht(entryPoints)
|
|
84
|
-
await entryPoint2.joinDht(entryPoints)
|
|
85
|
-
})
|
|
86
|
-
|
|
87
|
-
afterEach(async () => {
|
|
88
|
-
await Promise.all([
|
|
89
|
-
entryPoint1.stop(),
|
|
90
|
-
entryPoint2.stop(),
|
|
91
|
-
node1.stop(),
|
|
92
|
-
node2.stop()
|
|
93
|
-
])
|
|
94
|
-
simulator.stop()
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
it('non-entry point nodes can join', async () => {
|
|
98
|
-
await node1.joinDht(entryPoints)
|
|
99
|
-
expect(node1.getNeighborCount()).toEqual(2)
|
|
100
|
-
await node2.joinDht(entryPoints)
|
|
101
|
-
expect(node2.getNeighborCount()).toEqual(3)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
})
|
|
105
|
-
})
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
2
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { createMockConnectionDhtNode, waitForStableTopology } from '../utils/utils'
|
|
4
|
-
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
5
|
-
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
|
-
import { DhtAddress, randomDhtAddress, toDhtAddress, toNodeId } from '../../src/identifiers'
|
|
7
|
-
import { sample } from 'lodash'
|
|
8
|
-
import { DataEntry, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
9
|
-
|
|
10
|
-
const DATA = createMockDataEntry()
|
|
11
|
-
const NUM_NODES = 100
|
|
12
|
-
const MAX_CONNECTIONS = 80
|
|
13
|
-
const K = 8
|
|
14
|
-
const ENTRY_POINT_INDEX = 0
|
|
15
|
-
|
|
16
|
-
const getDataEntries = (node: DhtNode): DataEntry[] => {
|
|
17
|
-
// @ts-expect-error private field
|
|
18
|
-
const store = node.localDataStore
|
|
19
|
-
return Array.from(store.values(toDhtAddress(DATA.key)))
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
describe('Replicate data from node to node in DHT', () => {
|
|
23
|
-
|
|
24
|
-
let nodes: DhtNode[]
|
|
25
|
-
let entryPointDescriptor: PeerDescriptor
|
|
26
|
-
const simulator = new Simulator(LatencyType.FIXED, 20)
|
|
27
|
-
|
|
28
|
-
beforeEach(async () => {
|
|
29
|
-
const entryPoint = await createMockConnectionDhtNode(simulator, randomDhtAddress(), K, MAX_CONNECTIONS)
|
|
30
|
-
entryPointDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
31
|
-
await entryPoint.joinDht([entryPointDescriptor])
|
|
32
|
-
nodes = []
|
|
33
|
-
nodes.push(entryPoint)
|
|
34
|
-
for (let i = 1; i < NUM_NODES; i++) {
|
|
35
|
-
const node = await createMockConnectionDhtNode(
|
|
36
|
-
simulator,
|
|
37
|
-
randomDhtAddress(),
|
|
38
|
-
K,
|
|
39
|
-
MAX_CONNECTIONS
|
|
40
|
-
)
|
|
41
|
-
nodes.push(node)
|
|
42
|
-
}
|
|
43
|
-
}, 60000)
|
|
44
|
-
|
|
45
|
-
afterEach(async () => {
|
|
46
|
-
await Promise.all(nodes.map(async (node) => await node.stop()))
|
|
47
|
-
}, 60000)
|
|
48
|
-
|
|
49
|
-
afterAll(async () => {
|
|
50
|
-
simulator.stop()
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
it('Data replicates to the closest node no matter where it is stored', async () => {
|
|
54
|
-
// calculate offline which node is closest to the data
|
|
55
|
-
const sortedList = new SortedContactList<DhtNode>({
|
|
56
|
-
referenceId: toDhtAddress(DATA.key),
|
|
57
|
-
maxSize: 10000,
|
|
58
|
-
allowToContainReferenceId: true
|
|
59
|
-
})
|
|
60
|
-
nodes.forEach((node) => sortedList.addContact(node))
|
|
61
|
-
|
|
62
|
-
const closest = sortedList.getClosestContacts()
|
|
63
|
-
const successfulStorers = await nodes[0].storeDataToDht(toDhtAddress(DATA.key), DATA.data!)
|
|
64
|
-
expect(successfulStorers.length).toBe(1)
|
|
65
|
-
|
|
66
|
-
await Promise.all(
|
|
67
|
-
nodes.map(async (node, i) => {
|
|
68
|
-
if (i !== ENTRY_POINT_INDEX) {
|
|
69
|
-
await node.joinDht([entryPointDescriptor])
|
|
70
|
-
}
|
|
71
|
-
})
|
|
72
|
-
)
|
|
73
|
-
await waitForStableTopology(nodes)
|
|
74
|
-
|
|
75
|
-
const data = getDataEntries(closest[0])
|
|
76
|
-
expect(data).toHaveLength(1)
|
|
77
|
-
expectEqualData(data[0], DATA)
|
|
78
|
-
}, 180000)
|
|
79
|
-
|
|
80
|
-
it('Data replicates to the other nodes when storers are stopped', async () => {
|
|
81
|
-
await Promise.all(
|
|
82
|
-
nodes.map(async (node, i) => {
|
|
83
|
-
if (i !== ENTRY_POINT_INDEX) {
|
|
84
|
-
await node.joinDht([entryPointDescriptor])
|
|
85
|
-
}
|
|
86
|
-
})
|
|
87
|
-
)
|
|
88
|
-
await waitForStableTopology(nodes)
|
|
89
|
-
|
|
90
|
-
const randomIndex = Math.floor(Math.random() * nodes.length)
|
|
91
|
-
const storerDescriptors = await nodes[randomIndex].storeDataToDht(toDhtAddress(DATA.key), DATA.data!)
|
|
92
|
-
const stoppedNodeIds: DhtAddress[] = []
|
|
93
|
-
await Promise.all(storerDescriptors.map(async (storerDescriptor) => {
|
|
94
|
-
const storer = nodes.find((n) => n.getNodeId() === toNodeId(storerDescriptor))!
|
|
95
|
-
await storer.stop()
|
|
96
|
-
stoppedNodeIds.push(storer.getNodeId())
|
|
97
|
-
}))
|
|
98
|
-
|
|
99
|
-
const randomNonStoppedNode = sample(nodes.filter((n) => !stoppedNodeIds.includes(n.getNodeId())))!
|
|
100
|
-
const data = await randomNonStoppedNode.fetchDataFromDht(toDhtAddress(DATA.key))
|
|
101
|
-
expect(data).toHaveLength(1)
|
|
102
|
-
expectEqualData(data[0], DATA)
|
|
103
|
-
}, 180000)
|
|
104
|
-
})
|
|
@@ -1,230 +0,0 @@
|
|
|
1
|
-
import { DhtNode, Events as DhtNodeEvents } from '../../src/dht/DhtNode'
|
|
2
|
-
import { Message, NodeType, PeerDescriptor, RouteMessageWrapper } from '../../generated/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
4
|
-
import { Logger, runAndWaitForEvents3, until } from '@streamr/utils'
|
|
5
|
-
import { createMockConnectionDhtNode, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
6
|
-
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
7
|
-
import { v4 } from 'uuid'
|
|
8
|
-
import { Any } from '../../generated/google/protobuf/any'
|
|
9
|
-
import { RoutingMode } from '../../src/dht/routing/RoutingSession'
|
|
10
|
-
import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
|
|
11
|
-
|
|
12
|
-
const logger = new Logger(module)
|
|
13
|
-
|
|
14
|
-
const NUM_NODES = 30
|
|
15
|
-
|
|
16
|
-
describe('Route Message With Mock Connections', () => {
|
|
17
|
-
|
|
18
|
-
let entryPoint: DhtNode
|
|
19
|
-
let sourceNode: DhtNode
|
|
20
|
-
let destinationNode: DhtNode
|
|
21
|
-
let routerNodes: DhtNode[]
|
|
22
|
-
let simulator: Simulator
|
|
23
|
-
let entryPointDescriptor: PeerDescriptor
|
|
24
|
-
|
|
25
|
-
beforeEach(async () => {
|
|
26
|
-
routerNodes = []
|
|
27
|
-
simulator = new Simulator()
|
|
28
|
-
entryPoint = await createMockConnectionDhtNode(simulator, randomDhtAddress())
|
|
29
|
-
|
|
30
|
-
entryPointDescriptor = {
|
|
31
|
-
nodeId: toDhtAddressRaw(entryPoint.getNodeId()),
|
|
32
|
-
type: NodeType.NODEJS
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
sourceNode = await createMockConnectionDhtNode(simulator, randomDhtAddress())
|
|
36
|
-
destinationNode = await createMockConnectionDhtNode(simulator, randomDhtAddress())
|
|
37
|
-
|
|
38
|
-
for (let i = 1; i < NUM_NODES; i++) {
|
|
39
|
-
const node = await createMockConnectionDhtNode(simulator, randomDhtAddress())
|
|
40
|
-
routerNodes.push(node)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
await destinationNode.joinDht([entryPointDescriptor])
|
|
44
|
-
await sourceNode.joinDht([entryPointDescriptor])
|
|
45
|
-
await Promise.all(routerNodes.map((node) => node.joinDht([entryPointDescriptor])))
|
|
46
|
-
await entryPoint.joinDht([entryPointDescriptor])
|
|
47
|
-
}, 15000)
|
|
48
|
-
|
|
49
|
-
afterEach(async () => {
|
|
50
|
-
await Promise.allSettled(routerNodes.map((node) => node.stop()))
|
|
51
|
-
await Promise.allSettled([
|
|
52
|
-
entryPoint.stop(),
|
|
53
|
-
destinationNode.stop(),
|
|
54
|
-
sourceNode.stop()
|
|
55
|
-
])
|
|
56
|
-
|
|
57
|
-
logger.info('calling simulator stop')
|
|
58
|
-
simulator.stop()
|
|
59
|
-
logger.info('simulator stop called')
|
|
60
|
-
}, 10000)
|
|
61
|
-
|
|
62
|
-
it('Happy path', async () => {
|
|
63
|
-
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
64
|
-
const message: Message = {
|
|
65
|
-
serviceId: 'unknown',
|
|
66
|
-
messageId: v4(),
|
|
67
|
-
body: {
|
|
68
|
-
oneofKind: 'rpcMessage',
|
|
69
|
-
rpcMessage: rpcWrapper
|
|
70
|
-
},
|
|
71
|
-
sourceDescriptor: sourceNode.getLocalPeerDescriptor(),
|
|
72
|
-
targetDescriptor: destinationNode.getLocalPeerDescriptor()
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
await runAndWaitForEvents3<DhtNodeEvents>([() => {
|
|
76
|
-
// @ts-expect-error private
|
|
77
|
-
sourceNode.router!.doRouteMessage({
|
|
78
|
-
message,
|
|
79
|
-
target: destinationNode.getLocalPeerDescriptor().nodeId,
|
|
80
|
-
requestId: v4(),
|
|
81
|
-
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
82
|
-
reachableThrough: [],
|
|
83
|
-
routingPath: [],
|
|
84
|
-
parallelRootNodeIds: []
|
|
85
|
-
})
|
|
86
|
-
}], [[destinationNode, 'message']], 20000)
|
|
87
|
-
}, 30000)
|
|
88
|
-
|
|
89
|
-
it('Receives multiple messages', async () => {
|
|
90
|
-
const messageCount = 20
|
|
91
|
-
let receivedMessages = 0
|
|
92
|
-
destinationNode.on('message', () => {
|
|
93
|
-
receivedMessages += 1
|
|
94
|
-
})
|
|
95
|
-
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
96
|
-
|
|
97
|
-
for (let i = 0; i < messageCount; i++) {
|
|
98
|
-
const message: Message = {
|
|
99
|
-
serviceId: 'unknown',
|
|
100
|
-
messageId: v4(),
|
|
101
|
-
body: {
|
|
102
|
-
oneofKind: 'rpcMessage',
|
|
103
|
-
rpcMessage: rpcWrapper
|
|
104
|
-
},
|
|
105
|
-
sourceDescriptor: sourceNode.getLocalPeerDescriptor(),
|
|
106
|
-
targetDescriptor: destinationNode.getLocalPeerDescriptor()
|
|
107
|
-
}
|
|
108
|
-
// @ts-expect-error private
|
|
109
|
-
sourceNode.router!.doRouteMessage({
|
|
110
|
-
message,
|
|
111
|
-
target: destinationNode.getLocalPeerDescriptor().nodeId,
|
|
112
|
-
requestId: v4(),
|
|
113
|
-
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
114
|
-
reachableThrough: [],
|
|
115
|
-
routingPath: [],
|
|
116
|
-
parallelRootNodeIds: []
|
|
117
|
-
})
|
|
118
|
-
}
|
|
119
|
-
await until(() => receivedMessages === messageCount)
|
|
120
|
-
})
|
|
121
|
-
|
|
122
|
-
it('From all to all', async () => {
|
|
123
|
-
const receivedMessageCounts: Record<DhtAddress, number> = {}
|
|
124
|
-
routerNodes.forEach((node) => {
|
|
125
|
-
const key = node.getNodeId()
|
|
126
|
-
receivedMessageCounts[key] = 0
|
|
127
|
-
node.on('message', () => {
|
|
128
|
-
receivedMessageCounts[key] = receivedMessageCounts[key] + 1
|
|
129
|
-
})
|
|
130
|
-
})
|
|
131
|
-
await Promise.all(
|
|
132
|
-
routerNodes.map(async (node) =>
|
|
133
|
-
Promise.all(routerNodes.map(async (receiver) => {
|
|
134
|
-
if (node.getNodeId() !== receiver.getNodeId()) {
|
|
135
|
-
const rpcWrapper = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
136
|
-
const message: Message = {
|
|
137
|
-
serviceId: 'nonexisting_service',
|
|
138
|
-
messageId: v4(),
|
|
139
|
-
body: {
|
|
140
|
-
oneofKind: 'rpcMessage',
|
|
141
|
-
rpcMessage: rpcWrapper
|
|
142
|
-
},
|
|
143
|
-
sourceDescriptor: node.getLocalPeerDescriptor(),
|
|
144
|
-
targetDescriptor: destinationNode.getLocalPeerDescriptor()
|
|
145
|
-
}
|
|
146
|
-
// @ts-expect-error private
|
|
147
|
-
node.router!.doRouteMessage({
|
|
148
|
-
message,
|
|
149
|
-
target: receiver.getLocalPeerDescriptor().nodeId,
|
|
150
|
-
sourcePeer: node.getLocalPeerDescriptor(),
|
|
151
|
-
requestId: v4(),
|
|
152
|
-
reachableThrough: [],
|
|
153
|
-
routingPath: [],
|
|
154
|
-
parallelRootNodeIds: []
|
|
155
|
-
})
|
|
156
|
-
}
|
|
157
|
-
}))
|
|
158
|
-
)
|
|
159
|
-
)
|
|
160
|
-
await until(() => receivedMessageCounts[routerNodes[0].getNodeId()] >= routerNodes.length - 1, 30000)
|
|
161
|
-
await Promise.all(
|
|
162
|
-
Object.keys(receivedMessageCounts).map(async (key) =>
|
|
163
|
-
until(() => receivedMessageCounts[key as DhtAddress] >= routerNodes.length - 1, 30000)
|
|
164
|
-
)
|
|
165
|
-
)
|
|
166
|
-
|
|
167
|
-
}, 90000)
|
|
168
|
-
|
|
169
|
-
it('Destination receives forwarded message', async () => {
|
|
170
|
-
const closestPeersRequest = createWrappedClosestPeersRequest(sourceNode.getLocalPeerDescriptor())
|
|
171
|
-
const closestPeersRequestMessage: Message = {
|
|
172
|
-
serviceId: 'unknown',
|
|
173
|
-
messageId: v4(),
|
|
174
|
-
body: {
|
|
175
|
-
oneofKind: 'rpcMessage',
|
|
176
|
-
rpcMessage: closestPeersRequest
|
|
177
|
-
},
|
|
178
|
-
sourceDescriptor: sourceNode.getLocalPeerDescriptor(),
|
|
179
|
-
targetDescriptor: destinationNode.getLocalPeerDescriptor()
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const routeMessageWrapper: RouteMessageWrapper = {
|
|
183
|
-
message: closestPeersRequestMessage,
|
|
184
|
-
target: destinationNode.getLocalPeerDescriptor().nodeId,
|
|
185
|
-
requestId: v4(),
|
|
186
|
-
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
187
|
-
reachableThrough: [entryPointDescriptor],
|
|
188
|
-
routingPath: [],
|
|
189
|
-
parallelRootNodeIds: []
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const rpcMessage: RpcMessage = {
|
|
193
|
-
body: Any.pack(routeMessageWrapper, RouteMessageWrapper),
|
|
194
|
-
header: {
|
|
195
|
-
method: 'routeMessage',
|
|
196
|
-
request: 'request'
|
|
197
|
-
},
|
|
198
|
-
requestId: v4()
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
const requestMessage: Message = {
|
|
202
|
-
serviceId: 'layer0',
|
|
203
|
-
messageId: v4(),
|
|
204
|
-
body: {
|
|
205
|
-
oneofKind: 'rpcMessage',
|
|
206
|
-
rpcMessage
|
|
207
|
-
},
|
|
208
|
-
sourceDescriptor: sourceNode.getLocalPeerDescriptor(),
|
|
209
|
-
targetDescriptor: entryPoint.getLocalPeerDescriptor()
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
const forwardedMessage: RouteMessageWrapper = {
|
|
213
|
-
message: requestMessage,
|
|
214
|
-
requestId: v4(),
|
|
215
|
-
sourcePeer: sourceNode.getLocalPeerDescriptor(),
|
|
216
|
-
target: entryPoint.getLocalPeerDescriptor().nodeId,
|
|
217
|
-
reachableThrough: [],
|
|
218
|
-
routingPath: [],
|
|
219
|
-
parallelRootNodeIds: []
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
await runAndWaitForEvents3<DhtNodeEvents>([() => {
|
|
223
|
-
// @ts-expect-error private
|
|
224
|
-
sourceNode.router!.doRouteMessage(forwardedMessage, RoutingMode.FORWARD)
|
|
225
|
-
}], [[destinationNode, 'message']])
|
|
226
|
-
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
})
|
|
230
|
-
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
|
-
import { RouterRpcRemote } from '../../src/dht/routing/RouterRpcRemote'
|
|
3
|
-
import { Message, RouteMessageAck, RouteMessageWrapper } from '../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { RouterRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
|
|
5
|
-
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
6
|
-
import { createMockPeerDescriptor, createWrappedClosestPeersRequest, mockRouterRpc } from '../utils/utils'
|
|
7
|
-
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
8
|
-
|
|
9
|
-
const SERVICE_ID = 'test'
|
|
10
|
-
|
|
11
|
-
describe('RemoteRouter', () => {
|
|
12
|
-
|
|
13
|
-
let remoteRouter: RouterRpcRemote
|
|
14
|
-
let clientRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
15
|
-
let serverRpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
16
|
-
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
17
|
-
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
18
|
-
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
clientRpcCommunicator = new RpcCommunicator()
|
|
21
|
-
serverRpcCommunicator = new RpcCommunicator()
|
|
22
|
-
serverRpcCommunicator.registerRpcMethod(RouteMessageWrapper, RouteMessageAck, 'routeMessage', mockRouterRpc.routeMessage)
|
|
23
|
-
clientRpcCommunicator.setOutgoingMessageListener(async (message: RpcMessage) => {
|
|
24
|
-
serverRpcCommunicator.handleIncomingMessage(message, new DhtCallContext())
|
|
25
|
-
})
|
|
26
|
-
serverRpcCommunicator.setOutgoingMessageListener(async (message: RpcMessage) => {
|
|
27
|
-
clientRpcCommunicator.handleIncomingMessage(message, new DhtCallContext())
|
|
28
|
-
})
|
|
29
|
-
remoteRouter = new RouterRpcRemote(clientPeerDescriptor, serverPeerDescriptor, clientRpcCommunicator, RouterRpcClient)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('routeMessage happy path', async () => {
|
|
33
|
-
const rpcWrapper = createWrappedClosestPeersRequest(clientPeerDescriptor)
|
|
34
|
-
const routed: Message = {
|
|
35
|
-
serviceId: SERVICE_ID,
|
|
36
|
-
messageId: 'routed',
|
|
37
|
-
body: {
|
|
38
|
-
oneofKind: 'rpcMessage',
|
|
39
|
-
rpcMessage: rpcWrapper
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
const routable = await remoteRouter.routeMessage({
|
|
43
|
-
requestId: 'routed',
|
|
44
|
-
message: routed,
|
|
45
|
-
sourcePeer: clientPeerDescriptor,
|
|
46
|
-
target: serverPeerDescriptor.nodeId,
|
|
47
|
-
reachableThrough: [],
|
|
48
|
-
routingPath: [],
|
|
49
|
-
parallelRootNodeIds: []
|
|
50
|
-
})
|
|
51
|
-
expect(routable).toEqual(true)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('routeMessage error path', async () => {
|
|
55
|
-
serverRpcCommunicator.registerRpcMethod(RouteMessageWrapper, RouteMessageAck, 'routeMessage', mockRouterRpc.throwRouteMessageError)
|
|
56
|
-
const rpcWrapper = createWrappedClosestPeersRequest(clientPeerDescriptor)
|
|
57
|
-
const routed: Message = {
|
|
58
|
-
serviceId: SERVICE_ID,
|
|
59
|
-
messageId: 'routed',
|
|
60
|
-
body: {
|
|
61
|
-
oneofKind: 'rpcMessage',
|
|
62
|
-
rpcMessage: rpcWrapper
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
const routable = await remoteRouter.routeMessage({
|
|
66
|
-
requestId: 'routed',
|
|
67
|
-
message: routed,
|
|
68
|
-
sourcePeer: clientPeerDescriptor,
|
|
69
|
-
target: serverPeerDescriptor.nodeId,
|
|
70
|
-
reachableThrough: [],
|
|
71
|
-
routingPath: [],
|
|
72
|
-
parallelRootNodeIds: []
|
|
73
|
-
})
|
|
74
|
-
expect(routable).toEqual(false)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
})
|