@streamr/dht 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/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/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,58 +0,0 @@
|
|
|
1
|
-
import { wait } from '@streamr/utils'
|
|
2
|
-
import { ManagedConnection } from '../../src/exports'
|
|
3
|
-
import { MockConnection } from '../utils/mock/MockConnection'
|
|
4
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
5
|
-
|
|
6
|
-
describe('ManagedConnection', () => {
|
|
7
|
-
|
|
8
|
-
let managedConnection: ManagedConnection
|
|
9
|
-
let connection: MockConnection
|
|
10
|
-
beforeEach(() => {
|
|
11
|
-
connection = new MockConnection()
|
|
12
|
-
managedConnection = new ManagedConnection(createMockPeerDescriptor(), connection)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
managedConnection.close(false)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('emits disconnected after close', (done) => {
|
|
20
|
-
managedConnection.once('disconnected', (graceful) => {
|
|
21
|
-
expect(graceful).toBe(true)
|
|
22
|
-
done()
|
|
23
|
-
})
|
|
24
|
-
managedConnection.close(true)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('sends data', () => {
|
|
28
|
-
const data = new Uint8Array([1, 2, 3])
|
|
29
|
-
managedConnection.send(data)
|
|
30
|
-
expect(connection.sentData[0]).toEqual(data)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('emits data', (done) => {
|
|
34
|
-
const data = new Uint8Array([1, 2, 3])
|
|
35
|
-
managedConnection.on('managedData', (data) => {
|
|
36
|
-
expect(data).toEqual(data)
|
|
37
|
-
done()
|
|
38
|
-
})
|
|
39
|
-
connection.emitData(data)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('sets lastUsedTimestamp on send', async () => {
|
|
43
|
-
const createdTimestamp = managedConnection.getLastUsedTimestamp()
|
|
44
|
-
await wait(5)
|
|
45
|
-
managedConnection.send(new Uint8Array([1, 2, 3]))
|
|
46
|
-
expect(managedConnection.getLastUsedTimestamp()).toBeGreaterThan(createdTimestamp)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('replace as duplicate', async () => {
|
|
50
|
-
managedConnection.once('disconnected', () => {
|
|
51
|
-
throw new Error('disconnected')
|
|
52
|
-
})
|
|
53
|
-
managedConnection.replaceAsDuplicate()
|
|
54
|
-
managedConnection.close(true)
|
|
55
|
-
await wait(50)
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
})
|
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import { until } from '@streamr/utils'
|
|
2
|
-
import { range, sample, sampleSize } from 'lodash'
|
|
3
|
-
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
4
|
-
import { PeerManager } from '../../src/dht/PeerManager'
|
|
5
|
-
import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
|
|
6
|
-
import { DhtAddress, randomDhtAddress, toNodeId, toDhtAddressRaw } from '../../src/identifiers'
|
|
7
|
-
import { NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
8
|
-
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
9
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
10
|
-
|
|
11
|
-
const createDhtNodeRpcRemote = (
|
|
12
|
-
peerDescriptor: PeerDescriptor,
|
|
13
|
-
localPeerDescriptor: PeerDescriptor,
|
|
14
|
-
pingFailures: Set<DhtAddress>
|
|
15
|
-
) => {
|
|
16
|
-
const remote = new class extends DhtNodeRpcRemote {
|
|
17
|
-
// eslint-disable-next-line class-methods-use-this
|
|
18
|
-
async ping(): Promise<boolean> {
|
|
19
|
-
return !pingFailures.has(toNodeId(peerDescriptor))
|
|
20
|
-
}
|
|
21
|
-
}(localPeerDescriptor, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
22
|
-
return remote
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
const createPeerManager = (
|
|
26
|
-
nodeIds: DhtAddress[],
|
|
27
|
-
localPeerDescriptor = createMockPeerDescriptor(),
|
|
28
|
-
pingFailures: Set<DhtAddress> = new Set()
|
|
29
|
-
) => {
|
|
30
|
-
const manager = new PeerManager({
|
|
31
|
-
localNodeId: toNodeId(localPeerDescriptor),
|
|
32
|
-
localPeerDescriptor: localPeerDescriptor,
|
|
33
|
-
isLayer0: true,
|
|
34
|
-
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => createDhtNodeRpcRemote(peerDescriptor, localPeerDescriptor, pingFailures),
|
|
35
|
-
hasConnection: () => false
|
|
36
|
-
} as any)
|
|
37
|
-
const contacts = nodeIds.map((n) => ({ nodeId: toDhtAddressRaw(n), type: NodeType.NODEJS }))
|
|
38
|
-
for (const contact of contacts) {
|
|
39
|
-
manager.addContact(contact)
|
|
40
|
-
}
|
|
41
|
-
return manager
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
describe('PeerManager', () => {
|
|
45
|
-
|
|
46
|
-
it('getNearbyContactCount', () => {
|
|
47
|
-
const nodeIds = range(10).map(() => randomDhtAddress())
|
|
48
|
-
const manager = createPeerManager(nodeIds)
|
|
49
|
-
expect(manager.getNearbyContactCount()).toBe(10)
|
|
50
|
-
expect(manager.getNearbyContactCount(new Set(sampleSize(nodeIds, 2)))).toBe(8)
|
|
51
|
-
expect(manager.getNearbyContactCount(new Set([sample(nodeIds)!, randomDhtAddress()]))).toBe(9)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
|
-
it('addContact: ping fails', async () => {
|
|
55
|
-
const localPeerDescriptor = createMockPeerDescriptor()
|
|
56
|
-
const successContacts = range(5).map(() => createMockPeerDescriptor())
|
|
57
|
-
const failureContact = createMockPeerDescriptor()
|
|
58
|
-
const manager = createPeerManager([], localPeerDescriptor, new Set([toNodeId(failureContact)]))
|
|
59
|
-
for (const successContact of successContacts) {
|
|
60
|
-
manager.addContact(successContact)
|
|
61
|
-
manager.setContactActive(toNodeId(successContact))
|
|
62
|
-
manager.removeNeighbor(toNodeId(successContact))
|
|
63
|
-
}
|
|
64
|
-
expect(manager.getNeighborCount()).toBe(0)
|
|
65
|
-
manager.addContact(failureContact)
|
|
66
|
-
const closesSuccessContact = getClosestNodes(toNodeId(localPeerDescriptor), successContacts)[0]
|
|
67
|
-
await until(() => {
|
|
68
|
-
const neighborNodeIds = manager.getNeighbors().map((n) => n.getNodeId())
|
|
69
|
-
return neighborNodeIds.includes(toNodeId(closesSuccessContact))
|
|
70
|
-
})
|
|
71
|
-
expect(manager.getNeighborCount()).toBe(1)
|
|
72
|
-
expect(manager.getNeighbors()[0].getPeerDescriptor()).toEqualPeerDescriptor(closesSuccessContact)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('pruneOfflineNodes removes offline nodes', async () => {
|
|
76
|
-
const localPeerDescriptor = createMockPeerDescriptor()
|
|
77
|
-
const successContacts = range(5).map(() => createMockPeerDescriptor())
|
|
78
|
-
const failureContact = createMockPeerDescriptor()
|
|
79
|
-
const failureSet: Set<DhtAddress> = new Set()
|
|
80
|
-
const manager = createPeerManager([], localPeerDescriptor, failureSet)
|
|
81
|
-
for (const successContact of successContacts) {
|
|
82
|
-
manager.addContact(successContact)
|
|
83
|
-
}
|
|
84
|
-
manager.addContact(failureContact)
|
|
85
|
-
expect(manager.getNeighborCount()).toBe(6)
|
|
86
|
-
failureSet.add(toNodeId(failureContact))
|
|
87
|
-
await manager.pruneOfflineNodes(
|
|
88
|
-
manager.getNeighbors().map((node) => createDhtNodeRpcRemote(node.getPeerDescriptor(), localPeerDescriptor, failureSet))
|
|
89
|
-
)
|
|
90
|
-
expect(manager.getNeighborCount()).toBe(5)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
})
|
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
import { wait, waitForEvent3 } from '@streamr/utils'
|
|
2
|
-
import { PendingConnection } from '../../src/exports'
|
|
3
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
4
|
-
import { PendingConnectionEvents } from '../../src/connection/PendingConnection'
|
|
5
|
-
import { MockConnection } from '../utils/mock/MockConnection'
|
|
6
|
-
|
|
7
|
-
describe('PendingConnection', () => {
|
|
8
|
-
|
|
9
|
-
let pendingConnection: PendingConnection
|
|
10
|
-
|
|
11
|
-
beforeEach(() => {
|
|
12
|
-
pendingConnection = new PendingConnection(createMockPeerDescriptor(), 500)
|
|
13
|
-
})
|
|
14
|
-
|
|
15
|
-
afterEach(() => {
|
|
16
|
-
pendingConnection.close(false)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
it('does not emit disconnected after replacedAsDuplicate', async () => {
|
|
20
|
-
pendingConnection.once('disconnected', () => {
|
|
21
|
-
throw new Error('disconnected')
|
|
22
|
-
})
|
|
23
|
-
pendingConnection.replaceAsDuplicate()
|
|
24
|
-
pendingConnection.close(false)
|
|
25
|
-
await wait(50)
|
|
26
|
-
})
|
|
27
|
-
|
|
28
|
-
it('emits disconnected after timed out', async () => {
|
|
29
|
-
await waitForEvent3<PendingConnectionEvents>(pendingConnection, 'disconnected')
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('does not emit disconnected if destroyed', async () => {
|
|
33
|
-
pendingConnection.once('disconnected', () => {
|
|
34
|
-
throw new Error('disconnected')
|
|
35
|
-
})
|
|
36
|
-
pendingConnection.destroy()
|
|
37
|
-
await wait(50)
|
|
38
|
-
})
|
|
39
|
-
|
|
40
|
-
it('emites connected', (done) => {
|
|
41
|
-
const mockConnection = new MockConnection()
|
|
42
|
-
pendingConnection.once('connected', (_peerDescriptor, connection) => {
|
|
43
|
-
expect(mockConnection).toEqual(connection)
|
|
44
|
-
done()
|
|
45
|
-
})
|
|
46
|
-
pendingConnection.onHandshakeCompleted(mockConnection)
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
it('does not emit connected if replaced', async () => {
|
|
50
|
-
pendingConnection.once('connected', () => {
|
|
51
|
-
throw new Error('connected')
|
|
52
|
-
})
|
|
53
|
-
pendingConnection.replaceAsDuplicate()
|
|
54
|
-
await wait(50)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
})
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
import { ProtobufMessage } from '../../src/protobufclasses/ProtobufMessage'
|
|
3
|
-
import { Message, RpcMessage } from '../../generated/DhtRpc'
|
|
4
|
-
import { v4 } from 'uuid'
|
|
5
|
-
import { MessageType } from '@protobuf-ts/runtime'
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
describe('ProtobufMessage', () => {
|
|
9
|
-
|
|
10
|
-
it('can parse and print a Message', async () => {
|
|
11
|
-
|
|
12
|
-
/*
|
|
13
|
-
const message: Message = {
|
|
14
|
-
messageId: v4(),
|
|
15
|
-
messageType:
|
|
16
|
-
}
|
|
17
|
-
const data = Message.toBinary(message)
|
|
18
|
-
ProtobufMessage.fromBinary(data)
|
|
19
|
-
*/
|
|
20
|
-
})
|
|
21
|
-
})
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import { RandomContactList } from '../../src/dht/contact/RandomContactList'
|
|
2
|
-
import { DhtAddress, DhtAddressRaw, toDhtAddress } from '../../src/identifiers'
|
|
3
|
-
|
|
4
|
-
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress } => {
|
|
5
|
-
return {
|
|
6
|
-
getNodeId: () => toDhtAddress(nodeId)
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
describe('RandomContactList', () => {
|
|
11
|
-
|
|
12
|
-
const item0 = createItem(new Uint8Array([0, 0, 0, 0]))
|
|
13
|
-
const item1 = createItem(new Uint8Array([0, 0, 0, 1]))
|
|
14
|
-
const item2 = createItem(new Uint8Array([0, 0, 0, 2]))
|
|
15
|
-
const item3 = createItem(new Uint8Array([0, 0, 0, 3]))
|
|
16
|
-
const item4 = createItem(new Uint8Array([0, 0, 0, 4]))
|
|
17
|
-
|
|
18
|
-
it('adds contacts correctly', () => {
|
|
19
|
-
const list = new RandomContactList(item0.getNodeId(), 5, 1)
|
|
20
|
-
list.addContact(item1)
|
|
21
|
-
list.addContact(item2)
|
|
22
|
-
list.addContact(item3)
|
|
23
|
-
list.addContact(item3)
|
|
24
|
-
list.addContact(item4)
|
|
25
|
-
list.addContact(item4)
|
|
26
|
-
expect(list.getSize()).toEqual(4)
|
|
27
|
-
expect(list.getContacts()).toEqual(
|
|
28
|
-
[item1, item2, item3, item4]
|
|
29
|
-
)
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
it('removes contacts correctly', () => {
|
|
33
|
-
const list = new RandomContactList(item0.getNodeId(), 5, 1)
|
|
34
|
-
list.addContact(item1)
|
|
35
|
-
list.addContact(item2)
|
|
36
|
-
list.addContact(item3)
|
|
37
|
-
list.addContact(item4)
|
|
38
|
-
list.removeContact(item2.getNodeId())
|
|
39
|
-
expect(list.getContact(item1.getNodeId())).toBeTruthy()
|
|
40
|
-
expect(list.getContact(item3.getNodeId())).toBeTruthy()
|
|
41
|
-
expect(list.getContact(item4.getNodeId())).toBeTruthy()
|
|
42
|
-
expect(list.getContacts()).toEqual(
|
|
43
|
-
[item1, item3, item4]
|
|
44
|
-
)
|
|
45
|
-
expect(list.getSize()).toEqual(3)
|
|
46
|
-
})
|
|
47
|
-
|
|
48
|
-
it('get contacts', () => {
|
|
49
|
-
const list = new RandomContactList(item0.getNodeId(), 5, 1)
|
|
50
|
-
list.addContact(item1)
|
|
51
|
-
list.addContact(item2)
|
|
52
|
-
list.addContact(item3)
|
|
53
|
-
list.addContact(item4)
|
|
54
|
-
expect(list.getContacts()).toHaveLength(4)
|
|
55
|
-
expect(list.getContacts(3)).toHaveLength(3)
|
|
56
|
-
expect(list.getContacts(-2)).toHaveLength(0)
|
|
57
|
-
})
|
|
58
|
-
})
|
|
@@ -1,161 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
RecursiveOperation,
|
|
3
|
-
Message,
|
|
4
|
-
RouteMessageAck,
|
|
5
|
-
RouteMessageError,
|
|
6
|
-
RouteMessageWrapper,
|
|
7
|
-
RecursiveOperationRequest
|
|
8
|
-
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
9
|
-
import {
|
|
10
|
-
createWrappedClosestPeersRequest,
|
|
11
|
-
createMockPeerDescriptor
|
|
12
|
-
} from '../utils/utils'
|
|
13
|
-
import { RecursiveOperationManager } from '../../src/dht/recursive-operation/RecursiveOperationManager'
|
|
14
|
-
import { LocalDataStore } from '../../src/dht/store/LocalDataStore'
|
|
15
|
-
import { v4 } from 'uuid'
|
|
16
|
-
import { MockRouter } from '../utils/mock/MockRouter'
|
|
17
|
-
import { MockTransport } from '../utils/mock/MockTransport'
|
|
18
|
-
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
19
|
-
import { Router } from '../../src/dht/routing/Router'
|
|
20
|
-
import { ITransport } from '../../src/transport/ITransport'
|
|
21
|
-
import { areEqualPeerDescriptors, randomDhtAddress } from '../../src/identifiers'
|
|
22
|
-
import { MockConnectionsView } from '../utils/mock/MockConnectionsView'
|
|
23
|
-
|
|
24
|
-
const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
|
|
25
|
-
return {
|
|
26
|
-
doRouteMessage: (routedMessage: RouteMessageWrapper) => {
|
|
27
|
-
return {
|
|
28
|
-
requestId: routedMessage.requestId,
|
|
29
|
-
error
|
|
30
|
-
}
|
|
31
|
-
},
|
|
32
|
-
isMostLikelyDuplicate: () => false,
|
|
33
|
-
addToDuplicateDetector: () => {}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const createRequest = (): RecursiveOperationRequest => {
|
|
38
|
-
const request: RecursiveOperationRequest = {
|
|
39
|
-
operation: RecursiveOperation.FIND_CLOSEST_NODES,
|
|
40
|
-
sessionId: v4()
|
|
41
|
-
}
|
|
42
|
-
return request
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
describe('RecursiveOperationManager', () => {
|
|
46
|
-
|
|
47
|
-
const peerDescriptor1 = createMockPeerDescriptor()
|
|
48
|
-
const peerDescriptor2 = createMockPeerDescriptor()
|
|
49
|
-
const recursiveOperationRequest = createRequest()
|
|
50
|
-
const message: Message = {
|
|
51
|
-
serviceId: 'unknown',
|
|
52
|
-
messageId: v4(),
|
|
53
|
-
body: {
|
|
54
|
-
oneofKind: 'recursiveOperationRequest',
|
|
55
|
-
recursiveOperationRequest
|
|
56
|
-
},
|
|
57
|
-
sourceDescriptor: peerDescriptor1,
|
|
58
|
-
targetDescriptor: peerDescriptor2
|
|
59
|
-
}
|
|
60
|
-
const routedMessage: RouteMessageWrapper = {
|
|
61
|
-
message,
|
|
62
|
-
requestId: 'REQ',
|
|
63
|
-
routingPath: [],
|
|
64
|
-
reachableThrough: [],
|
|
65
|
-
sourcePeer: peerDescriptor1,
|
|
66
|
-
target: peerDescriptor2.nodeId,
|
|
67
|
-
parallelRootNodeIds: []
|
|
68
|
-
}
|
|
69
|
-
const rpcCommunicator = new FakeRpcCommunicator()
|
|
70
|
-
|
|
71
|
-
const createRecursiveOperationManager = (
|
|
72
|
-
router: Router = new MockRouter() as any,
|
|
73
|
-
transport: ITransport = new MockTransport()
|
|
74
|
-
): RecursiveOperationManager => {
|
|
75
|
-
return new RecursiveOperationManager({
|
|
76
|
-
localPeerDescriptor: peerDescriptor1,
|
|
77
|
-
router,
|
|
78
|
-
serviceId: 'RecursiveOperationManager',
|
|
79
|
-
localDataStore: new LocalDataStore(30 * 100),
|
|
80
|
-
sessionTransport: transport,
|
|
81
|
-
connectionsView: new MockConnectionsView(),
|
|
82
|
-
addContact: () => {},
|
|
83
|
-
rpcCommunicator: rpcCommunicator as any,
|
|
84
|
-
createDhtNodeRpcRemote: () => undefined as any
|
|
85
|
-
})
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
it('RecursiveOperationManager server', async () => {
|
|
89
|
-
const recursiveOperationManager = createRecursiveOperationManager()
|
|
90
|
-
const res = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage) as RouteMessageAck
|
|
91
|
-
expect(res.error).toBeUndefined()
|
|
92
|
-
recursiveOperationManager.stop()
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('find closest nodes returns self if no peers', async () => {
|
|
96
|
-
const recursiveOperationManager = createRecursiveOperationManager()
|
|
97
|
-
const res = await recursiveOperationManager.execute(randomDhtAddress(), RecursiveOperation.FIND_CLOSEST_NODES)
|
|
98
|
-
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
99
|
-
recursiveOperationManager.stop()
|
|
100
|
-
})
|
|
101
|
-
|
|
102
|
-
it('RecursiveOperationManager server throws if payload is not RecursiveOperationRequest', async () => {
|
|
103
|
-
const manager = createRecursiveOperationManager(new MockRouter() as any)
|
|
104
|
-
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
105
|
-
const badMessage: Message = {
|
|
106
|
-
serviceId: 'unknown',
|
|
107
|
-
messageId: v4(),
|
|
108
|
-
body: {
|
|
109
|
-
oneofKind: 'rpcMessage',
|
|
110
|
-
rpcMessage: rpcWrapper
|
|
111
|
-
},
|
|
112
|
-
sourceDescriptor: peerDescriptor1,
|
|
113
|
-
targetDescriptor: peerDescriptor2
|
|
114
|
-
}
|
|
115
|
-
await expect(() => rpcCommunicator.callRpcMethod('routeRequest', {
|
|
116
|
-
message: badMessage,
|
|
117
|
-
requestId: 'REQ',
|
|
118
|
-
routingPath: [],
|
|
119
|
-
reachableThrough: [],
|
|
120
|
-
target: peerDescriptor1.nodeId,
|
|
121
|
-
sourcePeer: peerDescriptor2
|
|
122
|
-
})).rejects.toThrow()
|
|
123
|
-
manager.stop()
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('no targets', async () => {
|
|
127
|
-
const router = createMockRouter(RouteMessageError.NO_TARGETS)
|
|
128
|
-
const send = jest.fn()
|
|
129
|
-
const transport = {
|
|
130
|
-
send,
|
|
131
|
-
getConnections: () => [],
|
|
132
|
-
on: () => {},
|
|
133
|
-
off: () => {}
|
|
134
|
-
}
|
|
135
|
-
const recursiveOperationManager = createRecursiveOperationManager(router as any, transport as any)
|
|
136
|
-
const ack = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage)
|
|
137
|
-
expect(ack).toEqual({
|
|
138
|
-
requestId: routedMessage.requestId,
|
|
139
|
-
error: RouteMessageError.NO_TARGETS
|
|
140
|
-
})
|
|
141
|
-
expect(send).toHaveBeenCalledTimes(1)
|
|
142
|
-
recursiveOperationManager.stop()
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('error', async () => {
|
|
146
|
-
const router = createMockRouter(RouteMessageError.DUPLICATE)
|
|
147
|
-
const send = jest.fn()
|
|
148
|
-
const transport = {
|
|
149
|
-
send,
|
|
150
|
-
getConnections: () => []
|
|
151
|
-
}
|
|
152
|
-
const recursiveOperationManager = createRecursiveOperationManager(router as any, transport as any)
|
|
153
|
-
const ack = await rpcCommunicator.callRpcMethod('routeRequest', routedMessage)
|
|
154
|
-
expect(ack).toEqual({
|
|
155
|
-
requestId: routedMessage.requestId,
|
|
156
|
-
error: RouteMessageError.DUPLICATE
|
|
157
|
-
})
|
|
158
|
-
expect(send).not.toHaveBeenCalled()
|
|
159
|
-
recursiveOperationManager.stop()
|
|
160
|
-
})
|
|
161
|
-
})
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { until } from '@streamr/utils'
|
|
2
|
-
import { range } from 'lodash'
|
|
3
|
-
import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
|
|
4
|
-
import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
|
|
5
|
-
import { ServiceID } from '../../src/types/ServiceID'
|
|
6
|
-
import { randomDhtAddress } from '../../src/identifiers'
|
|
7
|
-
import { Message, PeerDescriptor, RecursiveOperation } from '../../generated/packages/dht/protos/DhtRpc'
|
|
8
|
-
import { RecursiveOperationSessionRpcClient } from '../../generated/packages/dht/protos/DhtRpc.client'
|
|
9
|
-
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
10
|
-
import { FakeEnvironment } from '../utils/FakeTransport'
|
|
11
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
12
|
-
|
|
13
|
-
describe('RecursiveOperationSession', () => {
|
|
14
|
-
|
|
15
|
-
let environment: FakeEnvironment
|
|
16
|
-
let localPeerDescriptor: PeerDescriptor
|
|
17
|
-
|
|
18
|
-
const createRpcRemote = (serviceId: ServiceID) => {
|
|
19
|
-
const mockPeerDescriptor = createMockPeerDescriptor()
|
|
20
|
-
const transport = environment.createTransport(mockPeerDescriptor)
|
|
21
|
-
const send = (msg: Message) => transport.send(msg)
|
|
22
|
-
return new RecursiveOperationSessionRpcRemote(
|
|
23
|
-
mockPeerDescriptor,
|
|
24
|
-
localPeerDescriptor,
|
|
25
|
-
new RoutingRpcCommunicator(serviceId, send),
|
|
26
|
-
RecursiveOperationSessionRpcClient
|
|
27
|
-
)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
beforeEach(() => {
|
|
31
|
-
environment = new FakeEnvironment()
|
|
32
|
-
localPeerDescriptor = createMockPeerDescriptor()
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
it('happy path', async () => {
|
|
36
|
-
const doRouteRequest = jest.fn()
|
|
37
|
-
const session = new RecursiveOperationSession({
|
|
38
|
-
transport: environment.createTransport(localPeerDescriptor),
|
|
39
|
-
targetId: randomDhtAddress(),
|
|
40
|
-
localPeerDescriptor,
|
|
41
|
-
waitedRoutingPathCompletions: 3,
|
|
42
|
-
operation: RecursiveOperation.FIND_CLOSEST_NODES,
|
|
43
|
-
doRouteRequest
|
|
44
|
-
})
|
|
45
|
-
const onCompleted = jest.fn()
|
|
46
|
-
session.on('completed', onCompleted)
|
|
47
|
-
|
|
48
|
-
session.start('')
|
|
49
|
-
expect(doRouteRequest).toHaveBeenCalled()
|
|
50
|
-
range(3).forEach(() => {
|
|
51
|
-
const remote = createRpcRemote(session.getId())
|
|
52
|
-
remote.sendResponse(
|
|
53
|
-
[createMockPeerDescriptor(), createMockPeerDescriptor()],
|
|
54
|
-
[createMockPeerDescriptor(), createMockPeerDescriptor()],
|
|
55
|
-
[],
|
|
56
|
-
true
|
|
57
|
-
)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
// TODO now waits for the 4s timeout, could setup test so that it completes by receiving
|
|
61
|
-
// all data it wants
|
|
62
|
-
await until(() => onCompleted.mock.calls.length > 0)
|
|
63
|
-
const result = session.getResults()
|
|
64
|
-
// TODO assert peer descriptors
|
|
65
|
-
expect(result.closestNodes).toHaveLength(6)
|
|
66
|
-
expect(result.dataEntries).toEqual([])
|
|
67
|
-
})
|
|
68
|
-
})
|
package/test/unit/Router.test.ts
DELETED
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { v4 } from 'uuid'
|
|
2
|
-
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
3
|
-
import { Router } from '../../src/dht/routing/Router'
|
|
4
|
-
import {
|
|
5
|
-
Message,
|
|
6
|
-
PeerDescriptor,
|
|
7
|
-
RouteMessageAck,
|
|
8
|
-
RouteMessageError,
|
|
9
|
-
RouteMessageWrapper
|
|
10
|
-
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
11
|
-
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
12
|
-
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
13
|
-
import { DhtAddress, toNodeId, randomDhtAddress } from '../../src/identifiers'
|
|
14
|
-
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
15
|
-
|
|
16
|
-
describe('Router', () => {
|
|
17
|
-
|
|
18
|
-
let router: Router
|
|
19
|
-
const peerDescriptor1 = createMockPeerDescriptor()
|
|
20
|
-
const peerDescriptor2 = createMockPeerDescriptor()
|
|
21
|
-
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
22
|
-
const message: Message = {
|
|
23
|
-
serviceId: 'unknown',
|
|
24
|
-
messageId: v4(),
|
|
25
|
-
body: {
|
|
26
|
-
oneofKind: 'rpcMessage',
|
|
27
|
-
rpcMessage: rpcWrapper
|
|
28
|
-
},
|
|
29
|
-
sourceDescriptor: peerDescriptor1,
|
|
30
|
-
targetDescriptor: peerDescriptor2
|
|
31
|
-
}
|
|
32
|
-
const routedMessage: RouteMessageWrapper = {
|
|
33
|
-
message,
|
|
34
|
-
requestId: 'REQ',
|
|
35
|
-
routingPath: [],
|
|
36
|
-
reachableThrough: [],
|
|
37
|
-
target: peerDescriptor1.nodeId,
|
|
38
|
-
sourcePeer: peerDescriptor2,
|
|
39
|
-
parallelRootNodeIds: []
|
|
40
|
-
}
|
|
41
|
-
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
42
|
-
const rpcCommunicator = new FakeRpcCommunicator()
|
|
43
|
-
|
|
44
|
-
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
45
|
-
return new DhtNodeRpcRemote(peerDescriptor1, destination, undefined as any, new MockRpcCommunicator())
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
beforeEach(() => {
|
|
49
|
-
connections = new Map()
|
|
50
|
-
router = new Router({
|
|
51
|
-
localPeerDescriptor: peerDescriptor1,
|
|
52
|
-
rpcCommunicator: rpcCommunicator as any,
|
|
53
|
-
handleMessage: () => {},
|
|
54
|
-
getConnections: () => [...connections.values()].map((c) => c.getPeerDescriptor())
|
|
55
|
-
})
|
|
56
|
-
})
|
|
57
|
-
|
|
58
|
-
afterEach(() => {
|
|
59
|
-
router.stop()
|
|
60
|
-
})
|
|
61
|
-
|
|
62
|
-
it('doRouteMessage without connections', async () => {
|
|
63
|
-
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
64
|
-
message,
|
|
65
|
-
target: peerDescriptor2.nodeId,
|
|
66
|
-
requestId: v4(),
|
|
67
|
-
sourcePeer: peerDescriptor1,
|
|
68
|
-
reachableThrough: [],
|
|
69
|
-
routingPath: [],
|
|
70
|
-
parallelRootNodeIds: []
|
|
71
|
-
}) as RouteMessageAck
|
|
72
|
-
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
73
|
-
})
|
|
74
|
-
|
|
75
|
-
it('doRouteMessage with connections', async () => {
|
|
76
|
-
connections.set(randomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
77
|
-
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
78
|
-
message,
|
|
79
|
-
target: peerDescriptor2.nodeId,
|
|
80
|
-
requestId: v4(),
|
|
81
|
-
sourcePeer: peerDescriptor1,
|
|
82
|
-
reachableThrough: [],
|
|
83
|
-
routingPath: [],
|
|
84
|
-
parallelRootNodeIds: []
|
|
85
|
-
}) as RouteMessageAck
|
|
86
|
-
expect(ack.error).toBeUndefined()
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
it('doRouteMessage with parallelRootNodeIds', async () => {
|
|
90
|
-
const nodeId = toNodeId(peerDescriptor2)
|
|
91
|
-
connections.set(nodeId, createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
92
|
-
const ack = await rpcCommunicator.callRpcMethod('routeMessage', {
|
|
93
|
-
message,
|
|
94
|
-
target: peerDescriptor2.nodeId,
|
|
95
|
-
requestId: v4(),
|
|
96
|
-
sourcePeer: peerDescriptor1,
|
|
97
|
-
reachableThrough: [],
|
|
98
|
-
routingPath: [],
|
|
99
|
-
parallelRootNodeIds: [nodeId]
|
|
100
|
-
}) as RouteMessageAck
|
|
101
|
-
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
102
|
-
})
|
|
103
|
-
|
|
104
|
-
it('route server is destination without connections', async () => {
|
|
105
|
-
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
106
|
-
expect(ack.error).toBeUndefined()
|
|
107
|
-
})
|
|
108
|
-
|
|
109
|
-
it('route server with connections', async () => {
|
|
110
|
-
connections.set(randomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
111
|
-
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
112
|
-
expect(ack.error).toBeUndefined()
|
|
113
|
-
})
|
|
114
|
-
|
|
115
|
-
it('route server on duplicate message', async () => {
|
|
116
|
-
router.addToDuplicateDetector(routedMessage.requestId)
|
|
117
|
-
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
118
|
-
expect(ack.error).toEqual(RouteMessageError.DUPLICATE)
|
|
119
|
-
})
|
|
120
|
-
|
|
121
|
-
it('forward server no connections', async () => {
|
|
122
|
-
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
123
|
-
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
124
|
-
})
|
|
125
|
-
|
|
126
|
-
it('forward server with connections', async () => {
|
|
127
|
-
connections.set(randomDhtAddress(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
128
|
-
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
129
|
-
expect(ack.error).toBeUndefined()
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
it('forward server on duplicate message', async () => {
|
|
133
|
-
router.addToDuplicateDetector(routedMessage.requestId)
|
|
134
|
-
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
135
|
-
expect(ack.error).toEqual(RouteMessageError.DUPLICATE)
|
|
136
|
-
})
|
|
137
|
-
})
|