@streamr/dht 102.0.0-beta.0 → 102.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +15 -16
- package/dist/src/connection/ConnectionManager.js +18 -8
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +9 -5
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +17 -7
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.js +20 -10
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +3 -3
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.js +3 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/pings.d.ts +1 -1
- package/dist/src/connection/simulator/pings.js +3 -3
- package/dist/src/connection/simulator/pings.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +0 -2
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +19 -9
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -2
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.d.ts +0 -2
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnection.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketServerConnector.js +28 -18
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +1 -0
- package/dist/src/dht/DhtNode.js +3 -2
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +1 -1
- package/dist/src/dht/PeerManager.d.ts +2 -1
- package/dist/src/dht/PeerManager.js +2 -1
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.js +1 -1
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +0 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +0 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +0 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +2 -2
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.js +2 -2
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
- package/dist/src/dht/store/LocalDataStore.js +1 -1
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +1 -1
- package/dist/src/helpers/AddressTools.js +2 -3
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/debugHelpers.js +2 -2
- package/dist/src/helpers/debugHelpers.js.map +1 -1
- package/dist/src/helpers/protoClasses.d.ts +1 -1
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/helpers/protoToString.js +1 -2
- package/dist/src/helpers/protoToString.js.map +1 -1
- package/dist/src/helpers/version.d.ts +1 -1
- package/dist/src/helpers/version.js +4 -4
- package/dist/src/helpers/version.js.map +1 -1
- package/eslint.config.mjs +12 -0
- package/jest.config.ts +12 -0
- package/package.json +15 -16
- package/protos/DhtRpc.proto +6 -4
- package/src/connection/ConnectionManager.ts +2 -2
- package/src/connection/Handshaker.ts +15 -11
- package/src/connection/connectivityChecker.ts +4 -4
- package/src/connection/connectivityRequestHandler.ts +3 -3
- package/src/connection/simulator/Simulator.ts +4 -3
- package/src/connection/simulator/pings.ts +1 -1
- package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -2
- package/src/connection/webrtc/WebrtcConnector.ts +3 -3
- package/src/connection/websocket/WebsocketServerConnector.ts +17 -13
- package/src/dht/DhtNode.ts +8 -3
- package/src/dht/DhtNodeRpcLocal.ts +1 -1
- package/src/dht/PeerManager.ts +4 -2
- package/src/dht/contact/SortedContactList.ts +1 -1
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +1 -1
- package/src/dht/routing/DuplicateDetector.ts +1 -1
- package/src/dht/routing/RoutingSession.ts +2 -2
- package/src/dht/routing/RoutingTablesCache.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +1 -1
- package/src/dht/store/StoreManager.ts +1 -1
- package/src/dht/store/StoreRpcLocal.ts +1 -1
- package/src/helpers/protoClasses.ts +1 -1
- package/src/helpers/version.ts +2 -2
- package/test/benchmark/Find.test.ts +3 -3
- package/test/benchmark/KademliaCorrectness.test.ts +2 -2
- package/test/benchmark/RingCorrectness.test.ts +3 -3
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +2 -2
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +2 -2
- package/test/end-to-end/memory-leak.test.ts +2 -2
- package/test/integration/ConnectionLocking.test.ts +32 -22
- package/test/integration/ConnectionManager.test.ts +3 -3
- package/test/integration/ConnectivityChecking.test.ts +1 -1
- package/test/integration/DhtNode.test.ts +2 -2
- package/test/integration/GeoIpConnectivityChecking.test.ts +6 -6
- package/test/integration/Layer1-scale.test.ts +1 -1
- package/test/integration/RouteMessage.test.ts +4 -4
- package/test/integration/SimultaneousConnections.test.ts +9 -9
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +1 -1
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +3 -3
- package/test/integration/StoreRpcRemote.test.ts +1 -1
- package/test/integration/WebrtcConnectionManagement.test.ts +0 -28
- package/test/integration/WebrtcConnectorRpc.test.ts +5 -5
- package/test/integration/WebsocketConnectionManagement.test.ts +3 -3
- package/test/integration/rpc-connections-over-webrtc.test.ts +8 -43
- package/test/unit/AutoCertifierClientFacade.test.ts +6 -6
- package/test/unit/Handshaker.test.ts +1 -1
- package/test/unit/ListeningRpcCommunicator.test.ts +3 -3
- package/test/unit/PeerManager.test.ts +2 -2
- package/test/unit/RecursiveOperationSession.test.ts +2 -2
- package/test/unit/RoutingSession.test.ts +7 -0
- package/test/unit/SortedContactList.test.ts +3 -3
- package/test/unit/StoreManager.test.ts +2 -2
- package/test/unit/connectivityRequestHandler.test.ts +5 -5
- package/test/unit/customMatchers.test.ts +18 -0
- package/test/unit/getClosestNodes.test.ts +1 -1
- package/test/unit/version.test.ts +9 -9
- package/test/utils/customMatchers.ts +6 -6
- package/test/utils/topology.ts +0 -1
- package/test/utils/utils.ts +2 -2
- package/.eslintignore +0 -5
- package/.eslintrc +0 -3
- package/dist/generated/google/protobuf/any.d.ts +0 -180
- package/dist/generated/google/protobuf/any.js +0 -155
- package/dist/generated/google/protobuf/any.js.map +0 -1
- package/dist/generated/google/protobuf/empty.d.ts +0 -31
- package/dist/generated/google/protobuf/empty.js +0 -32
- package/dist/generated/google/protobuf/empty.js.map +0 -1
- package/dist/generated/google/protobuf/timestamp.d.ts +0 -155
- package/dist/generated/google/protobuf/timestamp.js +0 -136
- package/dist/generated/google/protobuf/timestamp.js.map +0 -1
- package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +0 -361
- package/dist/generated/packages/dht/protos/DhtRpc.client.js +0 -285
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/generated/packages/dht/protos/DhtRpc.d.ts +0 -991
- package/dist/generated/packages/dht/protos/DhtRpc.js +0 -675
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +0 -162
- package/dist/generated/packages/dht/protos/DhtRpc.server.js +0 -3
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +0 -1
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -87
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +0 -66
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
- package/generated/google/protobuf/any.ts +0 -326
- package/generated/google/protobuf/empty.ts +0 -81
- package/generated/google/protobuf/timestamp.ts +0 -287
- package/generated/packages/dht/protos/DhtRpc.client.ts +0 -419
- package/generated/packages/dht/protos/DhtRpc.server.ts +0 -165
- package/generated/packages/dht/protos/DhtRpc.ts +0 -1266
- package/generated/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
- package/jest.config.js +0 -5
|
@@ -12,7 +12,7 @@ import { attachConnectivityRequestHandler, DISABLE_CONNECTIVITY_PROBE } from '..
|
|
|
12
12
|
import { WebsocketServerConnection } from './WebsocketServerConnection'
|
|
13
13
|
import { ConnectionType, IConnection } from '../IConnection'
|
|
14
14
|
import queryString from 'querystring'
|
|
15
|
-
import {
|
|
15
|
+
import { isMaybeSupportedProtocolVersion, LOCAL_PROTOCOL_VERSION } from '../../helpers/version'
|
|
16
16
|
import { shuffle } from 'lodash'
|
|
17
17
|
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
18
18
|
import { acceptHandshake, Handshaker, rejectHandshake } from '../Handshaker'
|
|
@@ -114,23 +114,27 @@ export class WebsocketServerConnector {
|
|
|
114
114
|
private attachHandshaker(connection: IConnection) {
|
|
115
115
|
// TODO: use createIncomingHandshaker here?
|
|
116
116
|
const handshaker = new Handshaker(this.localPeerDescriptor!, connection)
|
|
117
|
-
handshaker.once('handshakeRequest', (
|
|
118
|
-
|
|
117
|
+
handshaker.once('handshakeRequest', (
|
|
118
|
+
localPeerDescriptor: PeerDescriptor,
|
|
119
|
+
remoteProtocolVersion: string,
|
|
120
|
+
remotePeerDescriptor?: PeerDescriptor
|
|
121
|
+
) => {
|
|
122
|
+
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, handshaker, remoteProtocolVersion, remotePeerDescriptor)
|
|
119
123
|
})
|
|
120
124
|
}
|
|
121
125
|
|
|
122
126
|
private onServerSocketHandshakeRequest(
|
|
123
|
-
|
|
127
|
+
remotePeerDescriptor: PeerDescriptor,
|
|
124
128
|
websocketServerConnection: IConnection,
|
|
125
129
|
handshaker: Handshaker,
|
|
126
|
-
|
|
130
|
+
remoteProtocolVersion: string,
|
|
127
131
|
targetPeerDescriptor?: PeerDescriptor
|
|
128
132
|
) {
|
|
129
|
-
const nodeId = toNodeId(
|
|
133
|
+
const nodeId = toNodeId(remotePeerDescriptor)
|
|
130
134
|
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
131
135
|
const { pendingConnection, delFunc } = this.ongoingConnectRequests.get(nodeId)!
|
|
132
|
-
if (!
|
|
133
|
-
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.
|
|
136
|
+
if (!isMaybeSupportedProtocolVersion(remoteProtocolVersion)) {
|
|
137
|
+
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
|
|
134
138
|
delFunc()
|
|
135
139
|
} else if (targetPeerDescriptor && !areEqualPeerDescriptors(this.localPeerDescriptor!, targetPeerDescriptor)) {
|
|
136
140
|
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR)
|
|
@@ -139,10 +143,10 @@ export class WebsocketServerConnector {
|
|
|
139
143
|
acceptHandshake(handshaker, pendingConnection, websocketServerConnection)
|
|
140
144
|
}
|
|
141
145
|
} else {
|
|
142
|
-
const pendingConnection = new PendingConnection(
|
|
146
|
+
const pendingConnection = new PendingConnection(remotePeerDescriptor)
|
|
143
147
|
|
|
144
|
-
if (!
|
|
145
|
-
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.
|
|
148
|
+
if (!isMaybeSupportedProtocolVersion(remoteProtocolVersion)) {
|
|
149
|
+
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
|
|
146
150
|
} else if (targetPeerDescriptor && !areEqualPeerDescriptors(this.localPeerDescriptor!, targetPeerDescriptor)) {
|
|
147
151
|
rejectHandshake(pendingConnection, websocketServerConnection, handshaker, HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR)
|
|
148
152
|
} else if (this.options.onNewConnection(pendingConnection)) {
|
|
@@ -160,7 +164,7 @@ export class WebsocketServerConnector {
|
|
|
160
164
|
host: '127.0.0.1',
|
|
161
165
|
natType: NatType.UNKNOWN,
|
|
162
166
|
ipAddress: ipv4ToNumber('127.0.0.1'),
|
|
163
|
-
|
|
167
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
164
168
|
}
|
|
165
169
|
}
|
|
166
170
|
if (!this.options.entrypoints || this.options.entrypoints.length === 0) {
|
|
@@ -175,7 +179,7 @@ export class WebsocketServerConnector {
|
|
|
175
179
|
},
|
|
176
180
|
// TODO: Resolve the given host name or or use as is if IP was given.
|
|
177
181
|
ipAddress: ipv4ToNumber('127.0.0.1'),
|
|
178
|
-
|
|
182
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
179
183
|
}
|
|
180
184
|
}
|
|
181
185
|
const shuffledEntrypoints = shuffle(this.options.entrypoints)
|
package/src/dht/DhtNode.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
MetricsContext,
|
|
5
5
|
merge,
|
|
6
6
|
scheduleAtInterval,
|
|
7
|
-
|
|
7
|
+
until
|
|
8
8
|
} from '@streamr/utils'
|
|
9
9
|
import { EventEmitter } from 'eventemitter3'
|
|
10
10
|
import { sample } from 'lodash'
|
|
@@ -79,6 +79,10 @@ export interface DhtNodeOptions {
|
|
|
79
79
|
storageRedundancyFactor?: number
|
|
80
80
|
periodicallyPingNeighbors?: boolean
|
|
81
81
|
periodicallyPingRingContacts?: boolean
|
|
82
|
+
// Limit for how many new neighbors to ping. If number of neighbors is higher than the limit new neighbors
|
|
83
|
+
// are not pinged when they are added. This is to prevent flooding the network with pings when joining.
|
|
84
|
+
// Enable periodicallyPingNeighbors to eventually ping all neighbors.
|
|
85
|
+
neighborPingLimit?: number
|
|
82
86
|
|
|
83
87
|
transport?: ITransport
|
|
84
88
|
connectionsView?: ConnectionsView
|
|
@@ -340,7 +344,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
340
344
|
connectionLocker: this.connectionLocker,
|
|
341
345
|
lockId: this.options.serviceId,
|
|
342
346
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => this.createDhtNodeRpcRemote(peerDescriptor),
|
|
343
|
-
hasConnection: (nodeId: DhtAddress) => this.connectionsView!.hasConnection(nodeId)
|
|
347
|
+
hasConnection: (nodeId: DhtAddress) => this.connectionsView!.hasConnection(nodeId),
|
|
348
|
+
neighborPingLimit: this.options.neighborPingLimit
|
|
344
349
|
})
|
|
345
350
|
this.peerManager.on('nearbyContactRemoved', (peerDescriptor: PeerDescriptor) => {
|
|
346
351
|
this.emit('nearbyContactRemoved', peerDescriptor)
|
|
@@ -621,7 +626,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
621
626
|
}
|
|
622
627
|
|
|
623
628
|
public async waitForNetworkConnectivity(): Promise<void> {
|
|
624
|
-
await
|
|
629
|
+
await until(
|
|
625
630
|
() => this.connectionsView!.getConnectionCount() > 0,
|
|
626
631
|
this.options.networkConnectivityTimeout,
|
|
627
632
|
100,
|
|
@@ -19,7 +19,7 @@ import { RingIdRaw } from './contact/ringIdentifiers'
|
|
|
19
19
|
|
|
20
20
|
interface DhtNodeRpcLocalOptions {
|
|
21
21
|
peerDiscoveryQueryBatchSize: number
|
|
22
|
-
getNeighbors: () =>
|
|
22
|
+
getNeighbors: () => readonly PeerDescriptor[]
|
|
23
23
|
getClosestRingContactsTo: (id: RingIdRaw, limit: number) => RingContacts
|
|
24
24
|
addContact: (contact: PeerDescriptor) => void
|
|
25
25
|
removeContact: (nodeId: DhtAddress) => void
|
package/src/dht/PeerManager.ts
CHANGED
|
@@ -23,6 +23,7 @@ interface PeerManagerOptions {
|
|
|
23
23
|
localNodeId: DhtAddress
|
|
24
24
|
localPeerDescriptor: PeerDescriptor
|
|
25
25
|
connectionLocker?: ConnectionLocker
|
|
26
|
+
neighborPingLimit?: number
|
|
26
27
|
lockId: LockID
|
|
27
28
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => DhtNodeRpcRemote
|
|
28
29
|
hasConnection: (nodeId: DhtAddress) => boolean
|
|
@@ -154,7 +155,8 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
154
155
|
const nodeId = toNodeId(peerDescriptor)
|
|
155
156
|
// Important to lock here, before the ping result is known
|
|
156
157
|
this.options.connectionLocker?.weakLockConnection(nodeId, this.options.lockId)
|
|
157
|
-
if (this.options.hasConnection(contact.getNodeId())
|
|
158
|
+
if (this.options.hasConnection(contact.getNodeId())
|
|
159
|
+
|| (this.options.neighborPingLimit !== undefined && this.neighbors.count() > this.options.neighborPingLimit)) {
|
|
158
160
|
logger.trace(`Added new contact ${nodeId}`)
|
|
159
161
|
} else { // open connection by pinging
|
|
160
162
|
logger.trace('starting ping ' + nodeId)
|
|
@@ -266,7 +268,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
266
268
|
return this.neighbors.count()
|
|
267
269
|
}
|
|
268
270
|
|
|
269
|
-
getNeighbors():
|
|
271
|
+
getNeighbors(): readonly DhtNodeRpcRemote[] {
|
|
270
272
|
return this.neighbors.toArray()
|
|
271
273
|
}
|
|
272
274
|
|
|
@@ -42,7 +42,7 @@ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
42
42
|
|
|
43
43
|
public addContact(contact: C): void {
|
|
44
44
|
const contactId = contact.getNodeId()
|
|
45
|
-
if (this.options.excludedNodeIds
|
|
45
|
+
if (this.options.excludedNodeIds?.has(contactId)) {
|
|
46
46
|
return
|
|
47
47
|
}
|
|
48
48
|
if ((!this.options.allowToContainReferenceId && (this.options.referenceId === contactId)) ||
|
|
@@ -39,7 +39,7 @@ interface RecursiveOperationManagerOptions {
|
|
|
39
39
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => DhtNodeRpcRemote
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
-
export interface RecursiveOperationResult { closestNodes:
|
|
42
|
+
export interface RecursiveOperationResult { closestNodes: PeerDescriptor[], dataEntries?: DataEntry[] }
|
|
43
43
|
|
|
44
44
|
const logger = new Logger(module)
|
|
45
45
|
|
|
@@ -16,7 +16,7 @@ import { RoutingTable, RoutingTablesCache } from './RoutingTablesCache'
|
|
|
16
16
|
const logger = new Logger(module)
|
|
17
17
|
|
|
18
18
|
const MAX_FAILED_HOPS = 2
|
|
19
|
-
const ROUTING_TABLE_MAX_SIZE =
|
|
19
|
+
const ROUTING_TABLE_MAX_SIZE = 5
|
|
20
20
|
|
|
21
21
|
export class RoutingRemoteContact extends Contact {
|
|
22
22
|
|
|
@@ -163,7 +163,7 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
|
|
|
163
163
|
const previousId = previousPeer ? toNodeId(previousPeer) : undefined
|
|
164
164
|
const targetId = toDhtAddress(this.options.routedMessage.target)
|
|
165
165
|
let routingTable: RoutingTable
|
|
166
|
-
if (this.options.routingTablesCache.has(targetId, previousId)) {
|
|
166
|
+
if (this.options.routingTablesCache.has(targetId, previousId) && this.options.routingTablesCache.get(targetId, previousId)!.getSize() > 0) {
|
|
167
167
|
routingTable = this.options.routingTablesCache.get(targetId, previousId)!
|
|
168
168
|
} else {
|
|
169
169
|
routingTable = new SortedContactList<RoutingRemoteContact>({
|
|
@@ -6,7 +6,7 @@ import { LRUCache } from 'lru-cache'
|
|
|
6
6
|
type RoutingTableID = string
|
|
7
7
|
export type RoutingTable = Pick<
|
|
8
8
|
SortedContactList<RoutingRemoteContact>,
|
|
9
|
-
'getClosestContacts' | 'addContacts' | 'addContact' | 'removeContact' | 'stop'>
|
|
9
|
+
'getClosestContacts' | 'addContacts' | 'addContact' | 'removeContact' | 'stop' | 'getSize'>
|
|
10
10
|
|
|
11
11
|
const createRoutingTableId = (targetId: DhtAddress, previousId?: DhtAddress): RoutingTableID => {
|
|
12
12
|
return targetId + (previousId ? previousId : '')
|
|
@@ -36,7 +36,7 @@ export class LocalDataStore {
|
|
|
36
36
|
|
|
37
37
|
public markAsDeleted(key: DhtAddress, creator: DhtAddress): boolean {
|
|
38
38
|
const item = this.store.get(key)
|
|
39
|
-
if (
|
|
39
|
+
if (!item?.has(creator)) {
|
|
40
40
|
return false
|
|
41
41
|
}
|
|
42
42
|
const storedEntry = item.get(creator)
|
|
@@ -32,7 +32,7 @@ interface StoreManagerOptions {
|
|
|
32
32
|
serviceId: ServiceID
|
|
33
33
|
highestTtl: number
|
|
34
34
|
redundancyFactor: number
|
|
35
|
-
getNeighbors: () =>
|
|
35
|
+
getNeighbors: () => readonly PeerDescriptor[]
|
|
36
36
|
createRpcRemote: (contact: PeerDescriptor) => StoreRpcRemote
|
|
37
37
|
}
|
|
38
38
|
|
|
@@ -17,7 +17,7 @@ interface StoreRpcLocalOptions {
|
|
|
17
17
|
localDataStore: LocalDataStore
|
|
18
18
|
localPeerDescriptor: PeerDescriptor
|
|
19
19
|
replicateDataToContact: (dataEntry: DataEntry, contact: PeerDescriptor) => Promise<void>
|
|
20
|
-
getStorers: (key: DhtAddress) =>
|
|
20
|
+
getStorers: (key: DhtAddress) => readonly PeerDescriptor[]
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const logger = new Logger(module)
|
|
@@ -28,7 +28,7 @@ import {
|
|
|
28
28
|
|
|
29
29
|
} from '../../generated/packages/dht/protos/DhtRpc'
|
|
30
30
|
|
|
31
|
-
export const protoClasses:
|
|
31
|
+
export const protoClasses: IMessageType<any>[] = [
|
|
32
32
|
ClosestPeersRequest,
|
|
33
33
|
ClosestPeersResponse,
|
|
34
34
|
RecursiveOperationRequest,
|
package/src/helpers/version.ts
CHANGED
|
@@ -6,9 +6,9 @@ export const LOCAL_PROTOCOL_VERSION = '1.1'
|
|
|
6
6
|
*
|
|
7
7
|
* The older version assumes optimistically that it may be supported by the newer
|
|
8
8
|
* version. It can't know for sure, but the other node will tell if it is not
|
|
9
|
-
* supported (e.g. rejecting the handshake with
|
|
9
|
+
* supported (e.g. rejecting the handshake with UNSUPPORTED_PROTOCOL_VERSION error).
|
|
10
10
|
*/
|
|
11
|
-
export const
|
|
11
|
+
export const isMaybeSupportedProtocolVersion = (remoteVersion: string): boolean => {
|
|
12
12
|
const localMajor = parseVersion(LOCAL_PROTOCOL_VERSION)!.major
|
|
13
13
|
const remoteMajor = parseVersion(remoteVersion)?.major
|
|
14
14
|
if ((remoteMajor === undefined) || (remoteMajor < localMajor)) {
|
|
@@ -21,7 +21,7 @@ describe('Find correctness', () => {
|
|
|
21
21
|
execSync('npm run prepare-kademlia-simulation')
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
const dhtIds:
|
|
24
|
+
const dhtIds: { type: string, data: number[] }[] = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
25
25
|
|
|
26
26
|
beforeEach(async () => {
|
|
27
27
|
|
|
@@ -49,10 +49,10 @@ describe('Find correctness', () => {
|
|
|
49
49
|
)
|
|
50
50
|
|
|
51
51
|
logger.info('waiting 120s')
|
|
52
|
-
debugVars
|
|
52
|
+
debugVars.waiting = true
|
|
53
53
|
|
|
54
54
|
await wait(120000)
|
|
55
|
-
debugVars
|
|
55
|
+
debugVars.waiting = false
|
|
56
56
|
logger.info('waiting over')
|
|
57
57
|
|
|
58
58
|
nodes.forEach((node) => logger.info(toNodeId(node.getLocalPeerDescriptor()) + ': connections:' +
|
|
@@ -22,8 +22,8 @@ describe('Kademlia correctness', () => {
|
|
|
22
22
|
execSync('npm run prepare-kademlia-simulation')
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
const dhtIds:
|
|
26
|
-
const groundTruth: Record<string,
|
|
25
|
+
const dhtIds: { type: string, data: number[] }[] = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
26
|
+
const groundTruth: Record<string, { name: string, distance: number, id: { type: string, data: number[] } }[]>
|
|
27
27
|
= JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
28
28
|
|
|
29
29
|
beforeEach(async () => {
|
|
@@ -18,7 +18,7 @@ describe('Ring correctness', () => {
|
|
|
18
18
|
const NUM_NODES = 900
|
|
19
19
|
const nodeIndicesById: Record<DhtAddress, number> = {}
|
|
20
20
|
|
|
21
|
-
const regions:
|
|
21
|
+
const regions: number[] = []
|
|
22
22
|
for (let i = 0; i < (NUM_NODES + 1); i++) {
|
|
23
23
|
regions.push(i)
|
|
24
24
|
}
|
|
@@ -36,8 +36,8 @@ describe('Ring correctness', () => {
|
|
|
36
36
|
execSync('npm run prepare-kademlia-simulation')
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
const dhtIds:
|
|
40
|
-
const groundTruth: Record<string,
|
|
39
|
+
const dhtIds: { type: string, data: number[] }[] = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
40
|
+
const groundTruth: Record<string, { name: string, distance: number, id: { type: string, data: number[] } }[]>
|
|
41
41
|
= JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
42
42
|
|
|
43
43
|
beforeEach(async () => {
|
|
@@ -26,7 +26,7 @@ class MockNode {
|
|
|
26
26
|
host: 'localhost',
|
|
27
27
|
natType: NatType.UNKNOWN,
|
|
28
28
|
ipAddress: ipv4ToNumber(ipAddress),
|
|
29
|
-
|
|
29
|
+
protocolVersion: '0.0.0'
|
|
30
30
|
|
|
31
31
|
}
|
|
32
32
|
this.peerDescriptor = createPeerDescriptor(connectivityResponse, getRandomRegion())
|
|
@@ -39,7 +39,7 @@ class MockNode {
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
// populate with mock ip addresses
|
|
42
|
-
const mockData:
|
|
42
|
+
const mockData: [number, string][] = [
|
|
43
43
|
[0, '5.2.4.2'],
|
|
44
44
|
[0, '6.23.2.4'],
|
|
45
45
|
[0, '7.2.4.2'],
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
4
|
-
import {
|
|
4
|
+
import { until } from '@streamr/utils'
|
|
5
5
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
6
6
|
import { areEqualPeerDescriptors } from '../../src/identifiers'
|
|
7
7
|
|
|
@@ -60,7 +60,7 @@ describe('Websocket IConnection Requests', () => {
|
|
|
60
60
|
await node2.joinDht([epPeerDescriptor])
|
|
61
61
|
await node1.joinDht([epPeerDescriptor])
|
|
62
62
|
|
|
63
|
-
await
|
|
63
|
+
await until(() => { return (connected1 && connected2) })
|
|
64
64
|
|
|
65
65
|
expect((node1.getTransport() as ConnectionManager).hasConnection(node2.getNodeId())).toEqual(true)
|
|
66
66
|
expect((node2.getTransport() as ConnectionManager).hasConnection(node1.getNodeId())).toEqual(true)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import LeakDetector from 'jest-leak-detector'
|
|
2
|
-
import {
|
|
2
|
+
import { until } from '@streamr/utils'
|
|
3
3
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
4
|
import { Message } from '../../generated/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
@@ -55,7 +55,7 @@ describe('memory leak', () => {
|
|
|
55
55
|
}
|
|
56
56
|
}
|
|
57
57
|
await sender.send(msg)
|
|
58
|
-
await
|
|
58
|
+
await until(() => receivedMessage !== undefined)
|
|
59
59
|
expect(receivedMessage!.messageId).toEqual(MESSAGE_ID)
|
|
60
60
|
|
|
61
61
|
await Promise.all([
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MetricsContext,
|
|
1
|
+
import { MetricsContext, until } from '@streamr/utils'
|
|
2
2
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
3
|
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
4
4
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
@@ -60,7 +60,8 @@ describe('Connection Locking', () => {
|
|
|
60
60
|
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
61
61
|
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
62
62
|
await Promise.all([
|
|
63
|
-
|
|
63
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
64
65
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
65
66
|
])
|
|
66
67
|
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
@@ -72,11 +73,13 @@ describe('Connection Locking', () => {
|
|
|
72
73
|
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
73
74
|
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
74
75
|
await Promise.all([
|
|
75
|
-
|
|
76
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
77
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
76
78
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
77
79
|
])
|
|
78
80
|
await Promise.all([
|
|
79
|
-
|
|
81
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
82
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
80
83
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
81
84
|
])
|
|
82
85
|
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
@@ -88,16 +91,17 @@ describe('Connection Locking', () => {
|
|
|
88
91
|
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
89
92
|
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
90
93
|
await Promise.all([
|
|
91
|
-
|
|
94
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
95
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
92
96
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
93
97
|
])
|
|
94
|
-
expect(connectionManager1.hasConnection(nodeId2))
|
|
98
|
+
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
95
99
|
expect(connectionManager2.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
96
100
|
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
97
101
|
|
|
98
102
|
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock')
|
|
99
103
|
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
100
|
-
await
|
|
104
|
+
await until(() => connectionManager2.hasRemoteLockedConnection(nodeId1) === false)
|
|
101
105
|
expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
|
|
102
106
|
})
|
|
103
107
|
|
|
@@ -105,15 +109,17 @@ describe('Connection Locking', () => {
|
|
|
105
109
|
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
106
110
|
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
107
111
|
await Promise.all([
|
|
108
|
-
|
|
112
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
113
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
109
114
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
110
115
|
])
|
|
111
116
|
await Promise.all([
|
|
112
|
-
|
|
117
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
118
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
113
119
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
114
120
|
])
|
|
115
121
|
|
|
116
|
-
expect(connectionManager1.hasConnection(nodeId2))
|
|
122
|
+
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
117
123
|
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(false)
|
|
118
124
|
|
|
119
125
|
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
@@ -128,17 +134,19 @@ describe('Connection Locking', () => {
|
|
|
128
134
|
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
129
135
|
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
130
136
|
await Promise.all([
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
138
|
+
until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
|
|
139
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
133
140
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
141
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
134
142
|
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
135
143
|
])
|
|
136
144
|
|
|
137
|
-
expect(connectionManager1.hasLocalLockedConnection(nodeId2))
|
|
138
|
-
expect(connectionManager2.hasLocalLockedConnection(nodeId1))
|
|
145
|
+
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
146
|
+
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
|
|
139
147
|
|
|
140
148
|
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
141
|
-
await
|
|
149
|
+
await until(() =>
|
|
142
150
|
connectionManager1.hasRemoteLockedConnection(nodeId2)
|
|
143
151
|
&& !connectionManager1.hasLocalLockedConnection(nodeId2)
|
|
144
152
|
&& !connectionManager2.hasRemoteLockedConnection(nodeId1)
|
|
@@ -153,28 +161,30 @@ describe('Connection Locking', () => {
|
|
|
153
161
|
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
154
162
|
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
155
163
|
await Promise.all([
|
|
156
|
-
|
|
157
|
-
|
|
164
|
+
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
165
|
+
until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
|
|
166
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
158
167
|
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
168
|
+
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
159
169
|
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
160
170
|
])
|
|
161
|
-
expect(connectionManager1.hasConnection(nodeId2))
|
|
171
|
+
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
162
172
|
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
|
|
163
173
|
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
164
174
|
|
|
165
175
|
//@ts-expect-error private field
|
|
166
176
|
await connectionManager1.gracefullyDisconnectAsync(mockPeerDescriptor2)
|
|
167
177
|
|
|
168
|
-
await
|
|
178
|
+
await until(() =>
|
|
169
179
|
!connectionManager1.hasRemoteLockedConnection(nodeId2)
|
|
170
180
|
&& !connectionManager1.hasLocalLockedConnection(nodeId2)
|
|
171
181
|
)
|
|
172
|
-
await
|
|
182
|
+
await until(() =>
|
|
173
183
|
!connectionManager2.hasRemoteLockedConnection(nodeId1)
|
|
174
184
|
&& !connectionManager2.hasLocalLockedConnection(nodeId1)
|
|
175
185
|
)
|
|
176
|
-
await
|
|
177
|
-
await
|
|
186
|
+
await until(() => !connectionManager2.hasConnection(nodeId1))
|
|
187
|
+
await until(() => !connectionManager1.hasConnection(nodeId2))
|
|
178
188
|
|
|
179
189
|
expect(connectionManager1.hasConnection(nodeId2)).toEqual(false)
|
|
180
190
|
expect(connectionManager2.hasConnection(nodeId1)).toEqual(false)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Logger, MetricsContext,
|
|
1
|
+
import { Logger, MetricsContext, until, waitForEvent3 } from '@streamr/utils'
|
|
2
2
|
import { MarkOptional } from 'ts-essentials'
|
|
3
3
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
4
4
|
import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../../src/connection/ConnectorFacade'
|
|
@@ -513,11 +513,11 @@ describe('ConnectionManager', () => {
|
|
|
513
513
|
await Promise.all([connectedPromise1, connectedPromise2, connectionManager2.send(msg)])
|
|
514
514
|
|
|
515
515
|
await connectionManager1.enablePrivateClientMode()
|
|
516
|
-
await
|
|
516
|
+
await until(() => connectionManager2.getConnections().length === 0)
|
|
517
517
|
expect(connectionManager1.getConnections().length).toEqual(1)
|
|
518
518
|
|
|
519
519
|
await connectionManager1.disablePrivateClientMode()
|
|
520
|
-
await
|
|
520
|
+
await until(() => connectionManager2.getConnections().length === 1)
|
|
521
521
|
expect(connectionManager1.getConnections().length).toEqual(1)
|
|
522
522
|
|
|
523
523
|
await connectionManager1.stop()
|
|
@@ -48,6 +48,6 @@ describe('ConnectivityChecking', () => {
|
|
|
48
48
|
allowSelfSignedCertificate: false
|
|
49
49
|
}
|
|
50
50
|
const response = await sendConnectivityRequest(request, server.getLocalPeerDescriptor())
|
|
51
|
-
expect(response.
|
|
51
|
+
expect(response.protocolVersion).toEqual(LOCAL_PROTOCOL_VERSION)
|
|
52
52
|
})
|
|
53
53
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { until } from '@streamr/utils'
|
|
2
2
|
import { range, without } from 'lodash'
|
|
3
3
|
import { DhtNodeRpcLocal } from '../../src/dht/DhtNodeRpcLocal'
|
|
4
4
|
import { DhtNode, ListeningRpcCommunicator, toNodeId } from '../../src/exports'
|
|
@@ -58,7 +58,7 @@ describe('DhtNode', () => {
|
|
|
58
58
|
await localNode.joinDht([entryPointPeerDescriptor])
|
|
59
59
|
await localNode.waitForNetworkConnectivity()
|
|
60
60
|
|
|
61
|
-
await
|
|
61
|
+
await until(() => localNode.getNeighborCount() === otherPeerDescriptors.length + 1)
|
|
62
62
|
const expectedNodeIds = without(getAllPeerDescriptors(), localPeerDescriptor).map((n) => toNodeId(n))
|
|
63
63
|
const actualNodeIds = localNode.getClosestContacts().map((n) => toNodeId(n))
|
|
64
64
|
expect(actualNodeIds).toIncludeSameMembers(expectedNodeIds)
|
|
@@ -8,12 +8,12 @@ import { LOCAL_PROTOCOL_VERSION } from '../../src/helpers/version'
|
|
|
8
8
|
import { WebsocketServerConnection } from '../../src/connection/websocket/WebsocketServerConnection'
|
|
9
9
|
import fs from 'fs'
|
|
10
10
|
|
|
11
|
-
//
|
|
12
|
-
const testIp = '
|
|
11
|
+
// helsinki.fi
|
|
12
|
+
const testIp = '128.214.222.50'
|
|
13
13
|
|
|
14
|
-
//
|
|
15
|
-
const testLatitude =
|
|
16
|
-
const testLongitude =
|
|
14
|
+
// Helsinki, Finland
|
|
15
|
+
const testLatitude = 60.1719
|
|
16
|
+
const testLongitude = 24.9347
|
|
17
17
|
|
|
18
18
|
const dbPath = '/tmp/geoipdatabasesintegration'
|
|
19
19
|
|
|
@@ -65,7 +65,7 @@ describe('ConnectivityChecking', () => {
|
|
|
65
65
|
allowSelfSignedCertificate: false
|
|
66
66
|
}
|
|
67
67
|
const response = await sendConnectivityRequest(request, server.getLocalPeerDescriptor())
|
|
68
|
-
expect(response.
|
|
68
|
+
expect(response.protocolVersion).toEqual(LOCAL_PROTOCOL_VERSION)
|
|
69
69
|
expect(response.latitude).toEqual(testLatitude)
|
|
70
70
|
expect(response.longitude).toEqual(testLongitude)
|
|
71
71
|
})
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DhtNode, Events as DhtNodeEvents } from '../../src/dht/DhtNode'
|
|
2
2
|
import { Message, NodeType, PeerDescriptor, RouteMessageWrapper } from '../../generated/packages/dht/protos/DhtRpc'
|
|
3
3
|
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
4
|
-
import { Logger, runAndWaitForEvents3,
|
|
4
|
+
import { Logger, runAndWaitForEvents3, until } from '@streamr/utils'
|
|
5
5
|
import { createMockConnectionDhtNode, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
6
6
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
7
7
|
import { v4 } from 'uuid'
|
|
@@ -116,7 +116,7 @@ describe('Route Message With Mock Connections', () => {
|
|
|
116
116
|
parallelRootNodeIds: []
|
|
117
117
|
})
|
|
118
118
|
}
|
|
119
|
-
await
|
|
119
|
+
await until(() => receivedMessages === messageCount)
|
|
120
120
|
})
|
|
121
121
|
|
|
122
122
|
it('From all to all', async () => {
|
|
@@ -157,10 +157,10 @@ describe('Route Message With Mock Connections', () => {
|
|
|
157
157
|
}))
|
|
158
158
|
)
|
|
159
159
|
)
|
|
160
|
-
await
|
|
160
|
+
await until(() => receivedMessageCounts[routerNodes[0].getNodeId()] >= routerNodes.length - 1, 30000)
|
|
161
161
|
await Promise.all(
|
|
162
162
|
Object.keys(receivedMessageCounts).map(async (key) =>
|
|
163
|
-
|
|
163
|
+
until(() => receivedMessageCounts[key as DhtAddress] >= routerNodes.length - 1, 30000)
|
|
164
164
|
)
|
|
165
165
|
)
|
|
166
166
|
|