@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,79 +0,0 @@
|
|
|
1
|
-
import { EventEmitter } from 'eventemitter3'
|
|
2
|
-
import { DhtAddress, toDhtAddress, toNodeId } from '../../src/identifiers'
|
|
3
|
-
import { Message, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { DEFAULT_SEND_OPTIONS, ITransport, SendOptions, TransportEvents } from '../../src/transport/ITransport'
|
|
5
|
-
import { ConnectionsView } from '../../src/exports'
|
|
6
|
-
|
|
7
|
-
// TODO extract ConnectionsView functionality to FakeConnectionsView
|
|
8
|
-
class FakeTransport extends EventEmitter<TransportEvents> implements ITransport, ConnectionsView {
|
|
9
|
-
|
|
10
|
-
private onSend: (msg: Message) => void
|
|
11
|
-
private readonly localPeerDescriptor: PeerDescriptor
|
|
12
|
-
// currently adds a peerDescription to the connections array when a "connect" option is seen in
|
|
13
|
-
// in send() call and never disconnects (TODO could add some disconnection logic? and maybe
|
|
14
|
-
// the connection should be seen by another FakeTransport instance, too?)
|
|
15
|
-
private connections: PeerDescriptor[] = []
|
|
16
|
-
|
|
17
|
-
constructor(peerDescriptor: PeerDescriptor, onSend: (msg: Message) => void) {
|
|
18
|
-
super()
|
|
19
|
-
this.onSend = onSend
|
|
20
|
-
this.localPeerDescriptor = peerDescriptor
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async send(msg: Message, opts?: SendOptions): Promise<void> {
|
|
24
|
-
const connect = opts?.connect ?? DEFAULT_SEND_OPTIONS.connect
|
|
25
|
-
const targetNodeId = toNodeId(msg.targetDescriptor!)
|
|
26
|
-
if (connect && !this.connections.some((c) => toNodeId(c) === targetNodeId)) {
|
|
27
|
-
this.connect(msg.targetDescriptor!)
|
|
28
|
-
}
|
|
29
|
-
msg.sourceDescriptor = this.localPeerDescriptor
|
|
30
|
-
this.onSend(msg)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
getLocalPeerDescriptor(): PeerDescriptor {
|
|
34
|
-
return this.localPeerDescriptor
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
private connect(peerDescriptor: PeerDescriptor) {
|
|
38
|
-
this.connections.push(peerDescriptor)
|
|
39
|
-
this.emit('connected', peerDescriptor)
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
getConnections(): PeerDescriptor[] {
|
|
43
|
-
return this.connections
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
getConnectionCount(): number {
|
|
47
|
-
return this.connections.length
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
hasConnection(nodeId: DhtAddress): boolean {
|
|
51
|
-
return this.connections.some((c) => toNodeId(c) === nodeId)
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
// eslint-disable-next-line class-methods-use-this
|
|
55
|
-
stop(): void | Promise<void> {
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// eslint-disable-next-line class-methods-use-this
|
|
59
|
-
getDiagnosticInfo(): Record<string, unknown> {
|
|
60
|
-
return {}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export class FakeEnvironment {
|
|
65
|
-
|
|
66
|
-
private transports: FakeTransport[] = []
|
|
67
|
-
|
|
68
|
-
createTransport(peerDescriptor: PeerDescriptor): FakeTransport {
|
|
69
|
-
const transport = new FakeTransport(peerDescriptor, (msg) => {
|
|
70
|
-
const targetNode = toDhtAddress(msg.targetDescriptor!.nodeId)
|
|
71
|
-
const targetTransport = this.transports.find((t) => toNodeId(t.getLocalPeerDescriptor()) === targetNode)
|
|
72
|
-
if (targetTransport !== undefined) {
|
|
73
|
-
targetTransport.emit('message', msg)
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
this.transports.push(transport)
|
|
77
|
-
return transport
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { areEqualBinaries } from '@streamr/utils'
|
|
2
|
-
import { printExpected, printReceived } from 'jest-matcher-utils'
|
|
3
|
-
import { isEqual } from 'lodash'
|
|
4
|
-
import { ConnectivityMethod, NodeType, PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { toDhtAddress } from '../../src/identifiers'
|
|
6
|
-
|
|
7
|
-
// we could ES2015 module syntax (https://jestjs.io/docs/expect#expectextendmatchers),
|
|
8
|
-
// but the IDE doesn't find custom matchers if we do that
|
|
9
|
-
declare global {
|
|
10
|
-
// eslint-disable-next-line @typescript-eslint/no-namespace
|
|
11
|
-
namespace jest {
|
|
12
|
-
interface Matchers<R> {
|
|
13
|
-
toEqualPeerDescriptor(expected: PeerDescriptor): R
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
const formErrorMessage = (field: keyof PeerDescriptor, expected: string | number | undefined, actual: string | number | undefined): string => {
|
|
19
|
-
return `PeerDescriptor ${field} values don't match:\nExpected: ${printExpected(expected)}\nReceived: ${printReceived(actual)}`
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
const toEqualPeerDescriptor = (
|
|
23
|
-
actual: PeerDescriptor,
|
|
24
|
-
expected: PeerDescriptor
|
|
25
|
-
): jest.CustomMatcherResult => {
|
|
26
|
-
const messages: string[] = []
|
|
27
|
-
if (!areEqualBinaries(expected.nodeId, actual.nodeId)) {
|
|
28
|
-
messages.push(formErrorMessage('nodeId', toDhtAddress(expected.nodeId), toDhtAddress(actual.nodeId)))
|
|
29
|
-
}
|
|
30
|
-
if (!isEqual(expected.type, actual.type)) {
|
|
31
|
-
const typeNames = { [NodeType.NODEJS]: 'NODEJS', [NodeType.BROWSER]: 'BROWSER' }
|
|
32
|
-
messages.push(formErrorMessage('type', typeNames[expected.type], typeNames[actual.type]))
|
|
33
|
-
}
|
|
34
|
-
expectEqualConnectivityMethod('udp', expected.udp, actual.udp, messages)
|
|
35
|
-
expectEqualConnectivityMethod('tcp', expected.tcp, actual.tcp, messages)
|
|
36
|
-
expectEqualConnectivityMethod('websocket', expected.websocket, actual.websocket, messages)
|
|
37
|
-
if (expected.region !== actual.region) {
|
|
38
|
-
messages.push(formErrorMessage('region', expected?.region, actual?.region))
|
|
39
|
-
}
|
|
40
|
-
if (messages.length > 0) {
|
|
41
|
-
return {
|
|
42
|
-
pass: false,
|
|
43
|
-
message: () => messages.join('\n\n')
|
|
44
|
-
}
|
|
45
|
-
} else {
|
|
46
|
-
return {
|
|
47
|
-
pass: true,
|
|
48
|
-
message: () => 'PeerDescriptors are equal'
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const expectEqualConnectivityMethod = (
|
|
54
|
-
field: keyof PeerDescriptor,
|
|
55
|
-
method1: ConnectivityMethod | undefined,
|
|
56
|
-
method2: ConnectivityMethod | undefined,
|
|
57
|
-
messages: string[]
|
|
58
|
-
) => {
|
|
59
|
-
const toOutput = (method?: ConnectivityMethod) => {
|
|
60
|
-
return (method !== undefined)
|
|
61
|
-
? `{port: ${method.port}, host: '${method.host}', tls: ${method.tls}}`
|
|
62
|
-
: undefined
|
|
63
|
-
}
|
|
64
|
-
if (!isEqual(method1, method2)) {
|
|
65
|
-
messages.push(formErrorMessage(field, toOutput(method1), toOutput(method2)))
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
expect.extend({
|
|
70
|
-
toEqualPeerDescriptor
|
|
71
|
-
})
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'eventemitter3'
|
|
2
|
-
import { ConnectionEvents, IConnection } from '../../../src/connection/IConnection'
|
|
3
|
-
|
|
4
|
-
export class MockConnection extends EventEmitter<ConnectionEvents> implements IConnection {
|
|
5
|
-
|
|
6
|
-
public sentData: Uint8Array[] = []
|
|
7
|
-
|
|
8
|
-
send(data: Uint8Array): Promise<void> {
|
|
9
|
-
this.sentData.push(data)
|
|
10
|
-
return Promise.resolve()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
close(graceful: boolean): Promise<void> {
|
|
14
|
-
this.emit('disconnected', graceful)
|
|
15
|
-
return Promise.resolve()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
destroy(): void {
|
|
19
|
-
this.removeAllListeners()
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
emitData(message: Uint8Array): void {
|
|
23
|
-
this.emit('data', message)
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
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,62 +0,0 @@
|
|
|
1
|
-
import { Methods } from '@streamr/test-utils'
|
|
2
|
-
import { Router } from '../../../src/dht/routing/Router'
|
|
3
|
-
import { RouteMessageAck } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
-
|
|
5
|
-
export class MockRouter implements Methods<Router> {
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line class-methods-use-this
|
|
8
|
-
addRoutingSession(): void {
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line class-methods-use-this
|
|
12
|
-
removeRoutingSession(): void {
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
// eslint-disable-next-line class-methods-use-this
|
|
16
|
-
addToDuplicateDetector(): void {
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
// eslint-disable-next-line class-methods-use-this
|
|
20
|
-
isMostLikelyDuplicate(): boolean {
|
|
21
|
-
return false
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
// eslint-disable-next-line class-methods-use-this
|
|
25
|
-
doRouteMessage(): RouteMessageAck {
|
|
26
|
-
return RouteMessageAck.create()
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// eslint-disable-next-line class-methods-use-this
|
|
30
|
-
send(): Promise<void> {
|
|
31
|
-
throw new Error('Not implemented')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// eslint-disable-next-line class-methods-use-this
|
|
35
|
-
stop(): void {
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
// eslint-disable-next-line class-methods-use-this
|
|
40
|
-
async routeMessage(): Promise<RouteMessageAck> {
|
|
41
|
-
return RouteMessageAck.create()
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
// eslint-disable-next-line class-methods-use-this
|
|
45
|
-
async forwardMessage(): Promise<RouteMessageAck> {
|
|
46
|
-
return RouteMessageAck.create()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// eslint-disable-next-line class-methods-use-this
|
|
50
|
-
onNodeConnected(): void {}
|
|
51
|
-
|
|
52
|
-
// eslint-disable-next-line class-methods-use-this
|
|
53
|
-
onNodeDisconnected(): void {}
|
|
54
|
-
|
|
55
|
-
// eslint-disable-next-line class-methods-use-this
|
|
56
|
-
resetCache(): void {}
|
|
57
|
-
|
|
58
|
-
// eslint-disable-next-line class-methods-use-this
|
|
59
|
-
getDiagnosticInfo(): Record<string, unknown> {
|
|
60
|
-
return {}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ITransport, TransportEvents } from '../../../src/transport/ITransport'
|
|
2
|
-
import { EventEmitter } from 'eventemitter3'
|
|
3
|
-
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
4
|
-
|
|
5
|
-
export class MockTransport extends EventEmitter<TransportEvents> implements ITransport {
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line class-methods-use-this
|
|
8
|
-
async send(): Promise<void> {
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// eslint-disable-next-line class-methods-use-this
|
|
13
|
-
getLocalPeerDescriptor(): PeerDescriptor {
|
|
14
|
-
return PeerDescriptor.create()
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// eslint-disable-next-line class-methods-use-this
|
|
18
|
-
stop(): void {
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
// eslint-disable-next-line class-methods-use-this
|
|
23
|
-
getDiagnosticInfo(): Record<string, unknown> {
|
|
24
|
-
return {}
|
|
25
|
-
}
|
|
26
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { MessageType as MessageType$, ScalarType } from '@protobuf-ts/runtime'
|
|
2
|
-
import { randomString } from '@streamr/utils'
|
|
3
|
-
import { Timestamp } from '../../../generated/google/protobuf/timestamp'
|
|
4
|
-
import { Any } from '../../../generated/google/protobuf/any'
|
|
5
|
-
import { DataEntry } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
6
|
-
import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../../src/identifiers'
|
|
7
|
-
import { omit } from 'lodash'
|
|
8
|
-
|
|
9
|
-
const MockData = new class extends MessageType$<{ foo: string }> {
|
|
10
|
-
constructor() {
|
|
11
|
-
super('MockData', [
|
|
12
|
-
{ no: 1, name: 'foo', kind: 'scalar', opt: false, T: ScalarType.STRING }
|
|
13
|
-
])
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export const createMockDataEntry = (
|
|
18
|
-
entry: Partial<Omit<DataEntry, 'key' | 'creator'> & { key: DhtAddress, creator: DhtAddress }> = {}
|
|
19
|
-
): DataEntry => {
|
|
20
|
-
return {
|
|
21
|
-
key: toDhtAddressRaw(entry.key ?? randomDhtAddress()),
|
|
22
|
-
data: Any.pack({ foo: randomString(5) }, MockData),
|
|
23
|
-
creator: toDhtAddressRaw(entry.creator ?? randomDhtAddress()),
|
|
24
|
-
ttl: 10000,
|
|
25
|
-
stale: false,
|
|
26
|
-
deleted: false,
|
|
27
|
-
createdAt: Timestamp.now(),
|
|
28
|
-
...omit(entry, 'key', 'creator')
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export const unpackData = (entry: DataEntry): { foo: string } => {
|
|
33
|
-
return Any.unpack(entry.data!, MockData)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export const expectEqualData = (entry1: DataEntry, entry2: DataEntry): void => {
|
|
37
|
-
expect(unpackData(entry1).foo).toBe(unpackData(entry2).foo)
|
|
38
|
-
}
|
package/test/utils/topology.ts
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { Multimap } from '@streamr/utils'
|
|
2
|
-
import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
|
|
3
|
-
import { minBy, range, without } from 'lodash'
|
|
4
|
-
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
5
|
-
import { getDistance } from '../../src/dht/PeerManager'
|
|
6
|
-
|
|
7
|
-
export const getTopologyPartitions = (topology: Multimap<DhtAddress, DhtAddress>): Set<DhtAddress>[] => {
|
|
8
|
-
let partitions: Set<DhtAddress>[] = []
|
|
9
|
-
for (const nodeId of topology.keys()) {
|
|
10
|
-
const neighbors = topology.get(nodeId)
|
|
11
|
-
const existingPartition = partitions.find((partition) => partition.has(nodeId))
|
|
12
|
-
if (existingPartition !== undefined) {
|
|
13
|
-
for (const neighbor of neighbors) {
|
|
14
|
-
if (!existingPartition.has(neighbor)) {
|
|
15
|
-
const otherPartition = partitions.find((partition) => partition.has(neighbor))
|
|
16
|
-
if (otherPartition !== undefined) {
|
|
17
|
-
for (const otherNode of otherPartition) {
|
|
18
|
-
existingPartition.add(otherNode)
|
|
19
|
-
}
|
|
20
|
-
partitions = without(partitions, otherPartition)
|
|
21
|
-
} else {
|
|
22
|
-
existingPartition.add(neighbor)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
} else {
|
|
27
|
-
const partition = new Set([nodeId, ...neighbors])
|
|
28
|
-
partitions.push(partition)
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return partitions
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
const getClosestNodes = (referenceId: DhtAddress, nodeIds: DhtAddress[], count: number, allowToContainReferenceId: boolean): DhtAddress[] => {
|
|
35
|
-
const list = new SortedContactList({
|
|
36
|
-
referenceId,
|
|
37
|
-
allowToContainReferenceId,
|
|
38
|
-
maxSize: count
|
|
39
|
-
})
|
|
40
|
-
list.addContacts(nodeIds.map((n) => ({ getNodeId: () => n })))
|
|
41
|
-
return list.getClosestContacts().map((c) => c.getNodeId())
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/*
|
|
45
|
-
* There are no network splits, and each node has only neighbors which are globally closest
|
|
46
|
-
* to the node's ID.
|
|
47
|
-
*/
|
|
48
|
-
export const createTestTopology = (nodeCount: number, minNeighorCount: number): Multimap<DhtAddress, DhtAddress> => {
|
|
49
|
-
const topology: Multimap<DhtAddress, DhtAddress> = new Multimap()
|
|
50
|
-
const nodeIds = range(nodeCount).map(() => randomDhtAddress())
|
|
51
|
-
for (const nodeId of nodeIds) {
|
|
52
|
-
const closestNodes = getClosestNodes(nodeId, nodeIds, minNeighorCount, false)
|
|
53
|
-
for (const closestNode of closestNodes) {
|
|
54
|
-
if (!topology.has(nodeId, closestNode)) {
|
|
55
|
-
topology.add(nodeId, closestNode)
|
|
56
|
-
}
|
|
57
|
-
if (!topology.has(closestNode, nodeId)) {
|
|
58
|
-
topology.add(closestNode, nodeId)
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
while (true) {
|
|
63
|
-
const partitions = getTopologyPartitions(topology)
|
|
64
|
-
if (partitions.length === 1) {
|
|
65
|
-
break
|
|
66
|
-
} else {
|
|
67
|
-
const closestPairs = nodeIds.map((nodeId: DhtAddress) => {
|
|
68
|
-
const ownPartition = partitions.find((partition) => partition.has(nodeId))!
|
|
69
|
-
const otherNodes = without(nodeIds, ...[...ownPartition])
|
|
70
|
-
const closestNodedId = getClosestNodes(nodeId, otherNodes, 1, false)[0]
|
|
71
|
-
return [nodeId, closestNodedId]
|
|
72
|
-
})
|
|
73
|
-
const mergePair = minBy(closestPairs, (pair) => getDistance(toDhtAddressRaw(pair[0]), toDhtAddressRaw(pair[1])))!
|
|
74
|
-
topology.add(mergePair[0], mergePair[1])
|
|
75
|
-
topology.add(mergePair[1], mergePair[0])
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return topology
|
|
79
|
-
}
|
package/test/utils/utils.ts
DELETED
|
@@ -1,268 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import {
|
|
3
|
-
ClosestPeersRequest,
|
|
4
|
-
ClosestPeersResponse,
|
|
5
|
-
NodeType,
|
|
6
|
-
PeerDescriptor,
|
|
7
|
-
PingRequest,
|
|
8
|
-
PingResponse,
|
|
9
|
-
RouteMessageAck,
|
|
10
|
-
RouteMessageWrapper,
|
|
11
|
-
StoreDataRequest,
|
|
12
|
-
StoreDataResponse,
|
|
13
|
-
ClosestRingPeersResponse
|
|
14
|
-
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
15
|
-
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
16
|
-
import {
|
|
17
|
-
IDhtNodeRpc,
|
|
18
|
-
IRouterRpc,
|
|
19
|
-
IStoreRpc,
|
|
20
|
-
IWebsocketClientConnectorRpc
|
|
21
|
-
} from '../../generated/packages/dht/protos/DhtRpc.server'
|
|
22
|
-
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
23
|
-
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
24
|
-
import { v4 } from 'uuid'
|
|
25
|
-
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
26
|
-
import { Empty } from '../../generated/google/protobuf/empty'
|
|
27
|
-
import { Any } from '../../generated/google/protobuf/any'
|
|
28
|
-
import { wait, until } from '@streamr/utils'
|
|
29
|
-
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
30
|
-
import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
|
|
31
|
-
|
|
32
|
-
export const createMockPeerDescriptor = (opts?: Partial<Omit<PeerDescriptor, 'nodeId'>>): PeerDescriptor => {
|
|
33
|
-
return {
|
|
34
|
-
nodeId: toDhtAddressRaw(randomDhtAddress()),
|
|
35
|
-
type: NodeType.NODEJS,
|
|
36
|
-
...opts
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const createMockRingNode = async (
|
|
41
|
-
simulator: Simulator,
|
|
42
|
-
nodeId: DhtAddress,
|
|
43
|
-
region: number
|
|
44
|
-
): Promise<DhtNode> => {
|
|
45
|
-
const maxConnections = 80
|
|
46
|
-
const dhtJoinTimeout = 45000
|
|
47
|
-
|
|
48
|
-
const peerDescriptor: PeerDescriptor = {
|
|
49
|
-
nodeId: toDhtAddressRaw(nodeId ?? randomDhtAddress()),
|
|
50
|
-
type: NodeType.NODEJS,
|
|
51
|
-
region
|
|
52
|
-
//ipAddress: ipv4ToNumber(ipAddress)
|
|
53
|
-
}
|
|
54
|
-
const mockConnectionManager = new SimulatorTransport(peerDescriptor, simulator)
|
|
55
|
-
await mockConnectionManager.start()
|
|
56
|
-
const opts = {
|
|
57
|
-
peerDescriptor: peerDescriptor,
|
|
58
|
-
transport: mockConnectionManager,
|
|
59
|
-
connectionLocker: mockConnectionManager,
|
|
60
|
-
numberOfNodesPerKBucket: 8,
|
|
61
|
-
maxConnections: maxConnections,
|
|
62
|
-
dhtJoinTimeout,
|
|
63
|
-
rpcRequestTimeout: 5000
|
|
64
|
-
}
|
|
65
|
-
const node = new class extends DhtNode {
|
|
66
|
-
async stop(): Promise<void> {
|
|
67
|
-
await super.stop()
|
|
68
|
-
await mockConnectionManager.stop()
|
|
69
|
-
}
|
|
70
|
-
}(opts)
|
|
71
|
-
await node.start()
|
|
72
|
-
return node
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export const createMockConnectionDhtNode = async (
|
|
76
|
-
simulator: Simulator,
|
|
77
|
-
nodeId?: DhtAddress,
|
|
78
|
-
numberOfNodesPerKBucket?: number,
|
|
79
|
-
maxConnections = 80,
|
|
80
|
-
dhtJoinTimeout = 45000
|
|
81
|
-
): Promise<DhtNode> => {
|
|
82
|
-
const peerDescriptor: PeerDescriptor = {
|
|
83
|
-
nodeId: toDhtAddressRaw(nodeId ?? randomDhtAddress()),
|
|
84
|
-
type: NodeType.NODEJS,
|
|
85
|
-
region: getRandomRegion()
|
|
86
|
-
}
|
|
87
|
-
const mockConnectionManager = new SimulatorTransport(peerDescriptor, simulator)
|
|
88
|
-
await mockConnectionManager.start()
|
|
89
|
-
const opts = {
|
|
90
|
-
peerDescriptor: peerDescriptor,
|
|
91
|
-
transport: mockConnectionManager,
|
|
92
|
-
connectionsView: mockConnectionManager,
|
|
93
|
-
connectionLocker: mockConnectionManager,
|
|
94
|
-
numberOfNodesPerKBucket,
|
|
95
|
-
maxConnections: maxConnections,
|
|
96
|
-
dhtJoinTimeout,
|
|
97
|
-
rpcRequestTimeout: 5000
|
|
98
|
-
}
|
|
99
|
-
const node = new class extends DhtNode {
|
|
100
|
-
async stop(): Promise<void> {
|
|
101
|
-
await super.stop()
|
|
102
|
-
await mockConnectionManager.stop()
|
|
103
|
-
}
|
|
104
|
-
}(opts)
|
|
105
|
-
await node.start()
|
|
106
|
-
return node
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const createMockConnectionLayer1Node = async (
|
|
110
|
-
layer0Node: DhtNode,
|
|
111
|
-
serviceId?: string,
|
|
112
|
-
numberOfNodesPerKBucket = 8
|
|
113
|
-
): Promise<DhtNode> => {
|
|
114
|
-
const descriptor: PeerDescriptor = {
|
|
115
|
-
nodeId: layer0Node.getLocalPeerDescriptor().nodeId,
|
|
116
|
-
type: NodeType.NODEJS,
|
|
117
|
-
}
|
|
118
|
-
const node = new DhtNode({
|
|
119
|
-
peerDescriptor: descriptor,
|
|
120
|
-
transport: layer0Node,
|
|
121
|
-
connectionsView: layer0Node.getConnectionsView(),
|
|
122
|
-
serviceId: serviceId ? serviceId : 'layer1', numberOfNodesPerKBucket,
|
|
123
|
-
rpcRequestTimeout: 10000
|
|
124
|
-
})
|
|
125
|
-
await node.start()
|
|
126
|
-
return node
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
export const createWrappedClosestPeersRequest = (
|
|
130
|
-
sourceDescriptor: PeerDescriptor
|
|
131
|
-
): RpcMessage => {
|
|
132
|
-
|
|
133
|
-
const routedMessage: ClosestPeersRequest = {
|
|
134
|
-
nodeId: sourceDescriptor.nodeId,
|
|
135
|
-
requestId: v4()
|
|
136
|
-
}
|
|
137
|
-
const rpcWrapper: RpcMessage = {
|
|
138
|
-
body: Any.pack(routedMessage, ClosestPeersRequest),
|
|
139
|
-
header: {
|
|
140
|
-
method: 'closestPeersRequest',
|
|
141
|
-
request: 'request'
|
|
142
|
-
},
|
|
143
|
-
requestId: v4()
|
|
144
|
-
}
|
|
145
|
-
return rpcWrapper
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
interface IDhtRpcWithError extends IDhtNodeRpc {
|
|
149
|
-
throwPingError: (request: PingRequest) => Promise<PingResponse>
|
|
150
|
-
respondPingWithTimeout: (request: PingRequest) => Promise<PingResponse>
|
|
151
|
-
throwGetClosestPeersError: (request: ClosestPeersRequest) => Promise<ClosestPeersResponse>
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
export const createMockDhtRpc = (neighbors: PeerDescriptor[]): IDhtRpcWithError => {
|
|
155
|
-
return {
|
|
156
|
-
async getClosestPeers(): Promise<ClosestPeersResponse> {
|
|
157
|
-
const response: ClosestPeersResponse = {
|
|
158
|
-
peers: neighbors,
|
|
159
|
-
requestId: 'why am i still here'
|
|
160
|
-
}
|
|
161
|
-
return response
|
|
162
|
-
},
|
|
163
|
-
async getClosestRingPeers(): Promise<ClosestRingPeersResponse> {
|
|
164
|
-
const response: ClosestRingPeersResponse = {
|
|
165
|
-
leftPeers: neighbors,
|
|
166
|
-
rightPeers: neighbors,
|
|
167
|
-
requestId: 'why am i still here'
|
|
168
|
-
}
|
|
169
|
-
return response
|
|
170
|
-
},
|
|
171
|
-
async ping(request: PingRequest): Promise<PingResponse> {
|
|
172
|
-
const response: PingResponse = {
|
|
173
|
-
requestId: request.requestId
|
|
174
|
-
}
|
|
175
|
-
return response
|
|
176
|
-
},
|
|
177
|
-
async leaveNotice(): Promise<Empty> {
|
|
178
|
-
return {}
|
|
179
|
-
},
|
|
180
|
-
async throwPingError(): Promise<PingResponse> {
|
|
181
|
-
throw new Error()
|
|
182
|
-
},
|
|
183
|
-
async respondPingWithTimeout(request: PingRequest): Promise<PingResponse> {
|
|
184
|
-
const response: PingResponse = {
|
|
185
|
-
requestId: request.requestId
|
|
186
|
-
}
|
|
187
|
-
await wait(2000)
|
|
188
|
-
return response
|
|
189
|
-
},
|
|
190
|
-
async throwGetClosestPeersError(): Promise<ClosestPeersResponse> {
|
|
191
|
-
throw new Error('Closest peers error')
|
|
192
|
-
}
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
interface IRouterRpcWithError extends IRouterRpc {
|
|
197
|
-
throwRouteMessageError: (request: RouteMessageWrapper) => Promise<RouteMessageAck>
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
export const mockRouterRpc: IRouterRpcWithError = {
|
|
201
|
-
async routeMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
202
|
-
const response: RouteMessageAck = {
|
|
203
|
-
requestId: routed.requestId
|
|
204
|
-
}
|
|
205
|
-
return response
|
|
206
|
-
},
|
|
207
|
-
async forwardMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
208
|
-
const response: RouteMessageAck = {
|
|
209
|
-
requestId: routed.requestId
|
|
210
|
-
}
|
|
211
|
-
return response
|
|
212
|
-
},
|
|
213
|
-
async throwRouteMessageError(): Promise<RouteMessageAck> {
|
|
214
|
-
throw new Error()
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
interface IStoreRpcWithError extends IStoreRpc {
|
|
219
|
-
throwStoreDataError: (request: StoreDataRequest) => Promise<StoreDataResponse>
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export const mockStoreRpc: IStoreRpcWithError = {
|
|
223
|
-
async storeData(): Promise<StoreDataResponse> {
|
|
224
|
-
return {}
|
|
225
|
-
},
|
|
226
|
-
async throwStoreDataError(): Promise<StoreDataResponse> {
|
|
227
|
-
throw new Error('Mock')
|
|
228
|
-
},
|
|
229
|
-
async replicateData(): Promise<Empty> {
|
|
230
|
-
return {}
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export const mockWebsocketClientConnectorRpc: IWebsocketClientConnectorRpc = {
|
|
235
|
-
async requestConnection(): Promise<Empty> {
|
|
236
|
-
return {}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
export const createMockPeers = (): PeerDescriptor[] => {
|
|
241
|
-
const n1 = createMockPeerDescriptor()
|
|
242
|
-
const n2 = createMockPeerDescriptor()
|
|
243
|
-
const n3 = createMockPeerDescriptor()
|
|
244
|
-
const n4 = createMockPeerDescriptor()
|
|
245
|
-
return [
|
|
246
|
-
n1, n2, n3, n4
|
|
247
|
-
]
|
|
248
|
-
}
|
|
249
|
-
|
|
250
|
-
/*
|
|
251
|
-
* When we start multiple nodes, most of the nodes have unlocked connections. This promise will resolve when some of those
|
|
252
|
-
* unlocked connections have been garbage collected, i.e. we typically have connections only to the nodes which
|
|
253
|
-
* are neighbors.
|
|
254
|
-
*/
|
|
255
|
-
export const waitForStableTopology = async (nodes: DhtNode[], maxConnectionCount: number = 10000, waitTime = 20000): Promise<void> => {
|
|
256
|
-
const MAX_IDLE_TIME = 100
|
|
257
|
-
const connectionManagers = nodes.map((n) => n.getTransport() as ConnectionManager)
|
|
258
|
-
await Promise.all(connectionManagers.map(async (connectionManager) => {
|
|
259
|
-
connectionManager.garbageCollectConnections(maxConnectionCount, MAX_IDLE_TIME)
|
|
260
|
-
try {
|
|
261
|
-
await until(() => connectionManager.getConnections().length <= maxConnectionCount, waitTime)
|
|
262
|
-
} catch {
|
|
263
|
-
// the topology is very likely stable, but we can't be sure (maybe the node has more than maxConnectionCount
|
|
264
|
-
// locked connections and therefore it is ok to that garbage collector was not able to remove any of those
|
|
265
|
-
// connections
|
|
266
|
-
}
|
|
267
|
-
}))
|
|
268
|
-
}
|