@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
|
@@ -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, DefaultConnectorFacadeOptions } from '../../src/connection/ConnectorFacade'
|
|
4
4
|
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
@@ -79,8 +79,8 @@ describe('SimultaneousConnections', () => {
|
|
|
79
79
|
simTransport1.send(msg1),
|
|
80
80
|
simTransport2.send(msg2)
|
|
81
81
|
])
|
|
82
|
-
await
|
|
83
|
-
await
|
|
82
|
+
await until(() => simTransport2.hasConnection(toNodeId(peerDescriptor1)))
|
|
83
|
+
await until(() => simTransport1.hasConnection(toNodeId(peerDescriptor2)))
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
describe('Websocket 2 servers', () => {
|
|
@@ -160,8 +160,8 @@ describe('SimultaneousConnections', () => {
|
|
|
160
160
|
connectionManager2.send(msg2)
|
|
161
161
|
])
|
|
162
162
|
|
|
163
|
-
await
|
|
164
|
-
await
|
|
163
|
+
await until(() => connectionManager1.hasConnection(toNodeId(wsPeerDescriptor2)))
|
|
164
|
+
await until(() => connectionManager2.hasConnection(toNodeId(wsPeerDescriptor1)))
|
|
165
165
|
})
|
|
166
166
|
})
|
|
167
167
|
|
|
@@ -240,8 +240,8 @@ describe('SimultaneousConnections', () => {
|
|
|
240
240
|
connectionManager2.send(msg2)
|
|
241
241
|
])
|
|
242
242
|
|
|
243
|
-
await
|
|
244
|
-
await
|
|
243
|
+
await until(() => connectionManager1.hasConnection(toNodeId(wsPeerDescriptor2)))
|
|
244
|
+
await until(() => connectionManager2.hasConnection(toNodeId(wsPeerDescriptor1)))
|
|
245
245
|
})
|
|
246
246
|
})
|
|
247
247
|
|
|
@@ -308,8 +308,8 @@ describe('SimultaneousConnections', () => {
|
|
|
308
308
|
connectionManager2.send(msg2)
|
|
309
309
|
])
|
|
310
310
|
|
|
311
|
-
await
|
|
312
|
-
await
|
|
311
|
+
await until(() => connectionManager1.hasConnection(toNodeId(wrtcPeerDescriptor2)))
|
|
312
|
+
await until(() => connectionManager2.hasConnection(toNodeId(wrtcPeerDescriptor1)))
|
|
313
313
|
})
|
|
314
314
|
})
|
|
315
315
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
2
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
3
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
4
|
-
import {
|
|
4
|
+
import { until } from '@streamr/utils'
|
|
5
5
|
import { createMockDataEntry, expectEqualData } from '../utils/mock/mockDataEntry'
|
|
6
6
|
import { toDhtAddress } from '../../src/identifiers'
|
|
7
7
|
|
|
@@ -26,7 +26,7 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
26
26
|
afterEach(async () => {
|
|
27
27
|
await entryPoint.stop()
|
|
28
28
|
await otherNode.stop()
|
|
29
|
-
simulator
|
|
29
|
+
simulator!.stop()
|
|
30
30
|
})
|
|
31
31
|
|
|
32
32
|
it('Node can store on two peer DHT', async () => {
|
|
@@ -42,7 +42,7 @@ describe('Storing data in DHT with two peers', () => {
|
|
|
42
42
|
|
|
43
43
|
it('Can store on one peer DHT', async () => {
|
|
44
44
|
await otherNode.stop()
|
|
45
|
-
await
|
|
45
|
+
await until(() => entryPoint.getNeighborCount() === 0)
|
|
46
46
|
const storedData = createMockDataEntry()
|
|
47
47
|
await entryPoint.storeDataToDht(toDhtAddress(storedData.key), storedData.data!)
|
|
48
48
|
const foundData = await entryPoint.fetchDataFromDht(toDhtAddress(storedData.key))
|
|
@@ -45,7 +45,7 @@ describe('StoreRpcRemote', () => {
|
|
|
45
45
|
|
|
46
46
|
it('storeData rejects', async () => {
|
|
47
47
|
serverRpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData', mockStoreRpc.throwStoreDataError)
|
|
48
|
-
await expect(rpcRemote.storeData(request)).rejects.
|
|
48
|
+
await expect(rpcRemote.storeData(request)).rejects.toThrow(
|
|
49
49
|
'Could not store data to'
|
|
50
50
|
+ ` ${toNodeId(serverPeerDescriptor)} from ${toNodeId(clientPeerDescriptor)}`
|
|
51
51
|
+ ' Error: Mock'
|
|
@@ -162,34 +162,6 @@ describe('WebRTC Connection Management', () => {
|
|
|
162
162
|
|
|
163
163
|
}, 20000)
|
|
164
164
|
|
|
165
|
-
it('Disconnects webrtcconnection while being connected', async () => {
|
|
166
|
-
const msg: Message = {
|
|
167
|
-
serviceId,
|
|
168
|
-
messageId: '1',
|
|
169
|
-
body: {
|
|
170
|
-
oneofKind: 'rpcMessage',
|
|
171
|
-
rpcMessage: RpcMessage.create()
|
|
172
|
-
},
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
const disconnectedPromise1 = new Promise<void>((resolve, _reject) => {
|
|
176
|
-
manager1.on('disconnected', () => {
|
|
177
|
-
resolve()
|
|
178
|
-
})
|
|
179
|
-
})
|
|
180
|
-
|
|
181
|
-
msg.targetDescriptor = peerDescriptor2
|
|
182
|
-
manager1.send(msg).catch((e) => {
|
|
183
|
-
expect(e.code).toEqual('SEND_FAILED')
|
|
184
|
-
})
|
|
185
|
-
|
|
186
|
-
// @ts-expect-error private field
|
|
187
|
-
manager1.closeConnection(peerDescriptor2)
|
|
188
|
-
|
|
189
|
-
await disconnectedPromise1
|
|
190
|
-
|
|
191
|
-
}, 20000)
|
|
192
|
-
|
|
193
165
|
it('failed connections are cleaned up', async () => {
|
|
194
166
|
const msg: Message = {
|
|
195
167
|
serviceId,
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { Empty } from '../../generated/google/protobuf/empty'
|
|
10
10
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
11
11
|
import { IWebrtcConnectorRpc } from '../../generated/packages/dht/protos/DhtRpc.server'
|
|
12
|
-
import {
|
|
12
|
+
import { until } from '@streamr/utils'
|
|
13
13
|
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
14
14
|
import { DhtCallContext } from '../../src/rpc-protocol/DhtCallContext'
|
|
15
15
|
|
|
@@ -86,7 +86,7 @@ describe('WebRTC rpc messages', () => {
|
|
|
86
86
|
{ targetDescriptor, notification: true }
|
|
87
87
|
)
|
|
88
88
|
|
|
89
|
-
await
|
|
89
|
+
await until(() => requestConnectionCounter === 1)
|
|
90
90
|
})
|
|
91
91
|
|
|
92
92
|
it('send rtcOffer', async () => {
|
|
@@ -97,7 +97,7 @@ describe('WebRTC rpc messages', () => {
|
|
|
97
97
|
{ targetDescriptor, notification: true }
|
|
98
98
|
)
|
|
99
99
|
|
|
100
|
-
await
|
|
100
|
+
await until(() => rtcOfferCounter === 1)
|
|
101
101
|
})
|
|
102
102
|
|
|
103
103
|
it('send rtcAnswer', async () => {
|
|
@@ -108,7 +108,7 @@ describe('WebRTC rpc messages', () => {
|
|
|
108
108
|
{ targetDescriptor, notification: true }
|
|
109
109
|
)
|
|
110
110
|
|
|
111
|
-
await
|
|
111
|
+
await until(() => rtcAnswerCounter === 1)
|
|
112
112
|
})
|
|
113
113
|
|
|
114
114
|
it('send iceCandidate', async () => {
|
|
@@ -120,6 +120,6 @@ describe('WebRTC rpc messages', () => {
|
|
|
120
120
|
{ targetDescriptor, notification: true }
|
|
121
121
|
)
|
|
122
122
|
|
|
123
|
-
await
|
|
123
|
+
await until(() => iceCandidateCounter === 1)
|
|
124
124
|
})
|
|
125
125
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { MetricsContext,
|
|
1
|
+
import { MetricsContext, until, waitForEvent3 } from '@streamr/utils'
|
|
2
2
|
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
3
|
import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../../src/connection/ConnectorFacade'
|
|
4
4
|
import { Simulator } from '../../src/connection/simulator/Simulator'
|
|
@@ -158,13 +158,13 @@ describe('Websocket Connection Management', () => {
|
|
|
158
158
|
targetDescriptor: wsServerConnectorPeerDescriptor
|
|
159
159
|
}
|
|
160
160
|
await noWsServerManager.send(dummyMessage)
|
|
161
|
-
await
|
|
161
|
+
await until(
|
|
162
162
|
() => {
|
|
163
163
|
const nodeId = toNodeId(noWsServerConnectorPeerDescriptor)
|
|
164
164
|
return wsServerManager.hasConnection(nodeId)
|
|
165
165
|
}
|
|
166
166
|
)
|
|
167
|
-
await
|
|
167
|
+
await until(
|
|
168
168
|
() => noWsServerManager.hasConnection(toNodeId(wsServerConnectorPeerDescriptor))
|
|
169
169
|
)
|
|
170
170
|
})
|
|
@@ -51,7 +51,6 @@ describe('RPC connections over WebRTC', () => {
|
|
|
51
51
|
await connectorTransport2.start()
|
|
52
52
|
manager2 = createConnectionManager(peerDescriptor2, connectorTransport2)
|
|
53
53
|
rpcCommunicator2 = new ListeningRpcCommunicator(SERVICE_ID, manager2)
|
|
54
|
-
//client2 = toProtoRpcClient(new DhtNodeRpcClient(rpcCommunicator2.getRpcClientTransport()))
|
|
55
54
|
|
|
56
55
|
await manager1.start()
|
|
57
56
|
await manager2.start()
|
|
@@ -88,7 +87,7 @@ describe('RPC connections over WebRTC', () => {
|
|
|
88
87
|
const response = await client1.ping(request, options)
|
|
89
88
|
|
|
90
89
|
expect(response.requestId).toEqual(request.requestId)
|
|
91
|
-
}
|
|
90
|
+
})
|
|
92
91
|
|
|
93
92
|
it('Throws an exception if RPC method is not defined', async () => {
|
|
94
93
|
|
|
@@ -102,57 +101,23 @@ describe('RPC connections over WebRTC', () => {
|
|
|
102
101
|
|
|
103
102
|
await expect(client1.ping(request, options))
|
|
104
103
|
.rejects.toThrow('Server does not implement method ping')
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
/*
|
|
108
|
-
|
|
109
|
-
TODO enable these tests (NET-1177)
|
|
104
|
+
})
|
|
110
105
|
|
|
111
|
-
it
|
|
106
|
+
it('Throws a client-side exception if WebRTC connection fails', async () => {
|
|
112
107
|
|
|
113
108
|
const request: PingRequest = {
|
|
114
109
|
requestId: v4()
|
|
115
110
|
}
|
|
116
111
|
const options: DhtRpcOptions = {
|
|
117
112
|
sourceDescriptor: peerDescriptor1,
|
|
118
|
-
targetDescriptor: peerDescriptor2
|
|
113
|
+
targetDescriptor: peerDescriptor2,
|
|
114
|
+
timeout: 10000
|
|
119
115
|
}
|
|
120
|
-
await connectorTransport1.stop()
|
|
121
116
|
await manager2.stop()
|
|
122
117
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}, 60000)
|
|
126
|
-
|
|
127
|
-
it('Disconnects WebrtcConnection while being connected', async () => {
|
|
128
|
-
|
|
129
|
-
const rpcMessage: RpcMessage = {
|
|
130
|
-
header: {},
|
|
131
|
-
body: new Uint8Array(10),
|
|
132
|
-
requestId: v4()
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
const msg: Message = {
|
|
136
|
-
serviceId,
|
|
137
|
-
messageId: '1',
|
|
138
|
-
body: RpcMessage.toBinary(rpcMessage)
|
|
139
|
-
}
|
|
118
|
+
await expect(client1.ping(request, options))
|
|
119
|
+
.rejects.toThrow('Peer disconnected')
|
|
140
120
|
|
|
141
|
-
|
|
142
|
-
manager1.on('disconnected', () => {
|
|
143
|
-
//expect(message.body.oneofKind).toBe('rpcMessage')
|
|
144
|
-
resolve()
|
|
145
|
-
})
|
|
146
|
-
})
|
|
147
|
-
|
|
148
|
-
msg.targetDescriptor = peerDescriptor2
|
|
149
|
-
manager1.send(msg).catch((e) => {
|
|
150
|
-
expect(e.code).toEqual('CONNECTION_FAILED')
|
|
151
|
-
})
|
|
152
|
-
|
|
153
|
-
manager1.disconnect(peerDescriptor2!, undefined, 100)
|
|
154
|
-
await disconnectedPromise1
|
|
121
|
+
}, 10000)
|
|
155
122
|
|
|
156
|
-
}, 20000)
|
|
157
|
-
*/
|
|
158
123
|
})
|
|
@@ -42,17 +42,17 @@ describe('AutoCertifierClientFacade', () => {
|
|
|
42
42
|
|
|
43
43
|
it('start', async () => {
|
|
44
44
|
await client.start()
|
|
45
|
-
expect(setHost).
|
|
46
|
-
expect(updateCertificate).
|
|
45
|
+
expect(setHost).toHaveBeenCalled()
|
|
46
|
+
expect(updateCertificate).toHaveBeenCalled()
|
|
47
47
|
})
|
|
48
48
|
|
|
49
49
|
it('updated events are processed', async () => {
|
|
50
50
|
await client.start()
|
|
51
|
-
expect(setHost).
|
|
52
|
-
expect(updateCertificate).
|
|
51
|
+
expect(setHost).toHaveBeenCalledTimes(1)
|
|
52
|
+
expect(updateCertificate).toHaveBeenCalledTimes(1);
|
|
53
53
|
(mockClient as MockAutoCertifierClient).emitUpdateSubdomain()
|
|
54
|
-
expect(setHost).
|
|
55
|
-
expect(updateCertificate).
|
|
54
|
+
expect(setHost).toHaveBeenCalledTimes(2)
|
|
55
|
+
expect(updateCertificate).toHaveBeenCalledTimes(2)
|
|
56
56
|
})
|
|
57
57
|
|
|
58
58
|
})
|
|
@@ -104,7 +104,7 @@ describe('Handshaker', () => {
|
|
|
104
104
|
})
|
|
105
105
|
|
|
106
106
|
it('onHandshakeFailed unsupported version', () => {
|
|
107
|
-
handshaker.emit('handshakeFailed', HandshakeError.
|
|
107
|
+
handshaker.emit('handshakeFailed', HandshakeError.UNSUPPORTED_PROTOCOL_VERSION)
|
|
108
108
|
expect(mockOnHandshakeCompleted).not.toHaveBeenCalled()
|
|
109
109
|
expect(mockPendingConnectionClose).toHaveBeenCalledTimes(1)
|
|
110
110
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { until } from '@streamr/utils'
|
|
2
2
|
import { ListeningRpcCommunicator } from '../../src/transport/ListeningRpcCommunicator'
|
|
3
3
|
import { MockTransport } from '../utils/mock/MockTransport'
|
|
4
4
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
@@ -44,9 +44,9 @@ describe('ListeningRpcCommunicator', () => {
|
|
|
44
44
|
RpcMessage.create(),
|
|
45
45
|
{ targetDescriptor: peerDescriptor }, createDeferredPromises()
|
|
46
46
|
)
|
|
47
|
-
await
|
|
47
|
+
await until(() => rpcCommunicator.getRequestIds(() => true).length > 0)
|
|
48
48
|
transport.emit('disconnected', peerDescriptor, false)
|
|
49
|
-
await
|
|
49
|
+
await until(() => rpcCommunicator.getRequestIds(() => true).length === 0)
|
|
50
50
|
}, 10000)
|
|
51
51
|
|
|
52
52
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { until } from '@streamr/utils'
|
|
2
2
|
import { range, sample, sampleSize } from 'lodash'
|
|
3
3
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
4
4
|
import { PeerManager } from '../../src/dht/PeerManager'
|
|
@@ -64,7 +64,7 @@ describe('PeerManager', () => {
|
|
|
64
64
|
expect(manager.getNeighborCount()).toBe(0)
|
|
65
65
|
manager.addContact(failureContact)
|
|
66
66
|
const closesSuccessContact = getClosestNodes(toNodeId(localPeerDescriptor), successContacts)[0]
|
|
67
|
-
await
|
|
67
|
+
await until(() => {
|
|
68
68
|
const neighborNodeIds = manager.getNeighbors().map((n) => n.getNodeId())
|
|
69
69
|
return neighborNodeIds.includes(toNodeId(closesSuccessContact))
|
|
70
70
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { until } from '@streamr/utils'
|
|
2
2
|
import { range } from 'lodash'
|
|
3
3
|
import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
|
|
4
4
|
import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
|
|
@@ -59,7 +59,7 @@ describe('RecursiveOperationSession', () => {
|
|
|
59
59
|
|
|
60
60
|
// TODO now waits for the 4s timeout, could setup test so that it completes by receiving
|
|
61
61
|
// all data it wants
|
|
62
|
-
await
|
|
62
|
+
await until(() => onCompleted.mock.calls.length > 0)
|
|
63
63
|
const result = session.getResults()
|
|
64
64
|
// TODO assert peer descriptors
|
|
65
65
|
expect(result.closestNodes).toHaveLength(6)
|
|
@@ -76,4 +76,11 @@ describe('RoutingSession', () => {
|
|
|
76
76
|
expect(session.updateAndGetRoutablePeers().length).toBe(0)
|
|
77
77
|
})
|
|
78
78
|
|
|
79
|
+
it('recalculates Routing Table if it is empty', () => {
|
|
80
|
+
connections.set(toNodeId(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
81
|
+
expect(session.updateAndGetRoutablePeers().length).toBe(1)
|
|
82
|
+
routingTablesCache.onNodeDisconnected(toNodeId(mockPeerDescriptor2))
|
|
83
|
+
expect(session.updateAndGetRoutablePeers().length).toBe(1)
|
|
84
|
+
})
|
|
85
|
+
|
|
79
86
|
})
|
|
@@ -38,7 +38,7 @@ describe('SortedContactList', () => {
|
|
|
38
38
|
expect(list.getSize()).toEqual(3)
|
|
39
39
|
expect(list.getClosestContacts()).toEqual([item1, item2, item3])
|
|
40
40
|
expect(list.getContactIds()).toEqual([item1.getNodeId(), item2.getNodeId(), item3.getNodeId()])
|
|
41
|
-
expect(onContactRemoved).
|
|
41
|
+
expect(onContactRemoved).toHaveBeenCalledWith(item4)
|
|
42
42
|
expect(list.getContact(item4.getNodeId())).toBeFalsy()
|
|
43
43
|
})
|
|
44
44
|
|
|
@@ -106,9 +106,9 @@ describe('SortedContactList', () => {
|
|
|
106
106
|
list.on('contactAdded', onContactAdded)
|
|
107
107
|
list.addContact(item1)
|
|
108
108
|
list.addContact(item2)
|
|
109
|
-
expect(onContactAdded).
|
|
109
|
+
expect(onContactAdded).toHaveBeenCalledTimes(2)
|
|
110
110
|
list.addContact(item3)
|
|
111
|
-
expect(onContactAdded).
|
|
111
|
+
expect(onContactAdded).toHaveBeenCalledTimes(2)
|
|
112
112
|
expect(list.getClosestContacts().length).toEqual(2)
|
|
113
113
|
})
|
|
114
114
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { wait,
|
|
1
|
+
import { wait, until } from '@streamr/utils'
|
|
2
2
|
import { range, without } from 'lodash'
|
|
3
3
|
import { getClosestNodes } from '../../src/dht/contact/getClosestNodes'
|
|
4
4
|
import { StoreManager } from '../../src/dht/store/StoreManager'
|
|
@@ -67,7 +67,7 @@ describe('StoreManager', () => {
|
|
|
67
67
|
setAllEntriesAsStale
|
|
68
68
|
)
|
|
69
69
|
manager.onContactAdded(getNodeCloseToData(2))
|
|
70
|
-
await
|
|
70
|
+
await until(() => replicateData.mock.calls.length === 1)
|
|
71
71
|
expect(replicateData).toHaveBeenCalledWith({
|
|
72
72
|
entry: DATA_ENTRY
|
|
73
73
|
}, true)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ipv4ToNumber,
|
|
1
|
+
import { ipv4ToNumber, until } from '@streamr/utils'
|
|
2
2
|
import { EventEmitter } from 'eventemitter3'
|
|
3
3
|
import { once } from 'events'
|
|
4
4
|
import { Server as HttpServer, createServer as createHttpServer } from 'http'
|
|
@@ -48,7 +48,7 @@ describe('connectivityRequestHandler', () => {
|
|
|
48
48
|
}
|
|
49
49
|
connection.emit('data', Message.toBinary(request))
|
|
50
50
|
|
|
51
|
-
await
|
|
51
|
+
await until(() => connection.send.mock.calls.length > 0)
|
|
52
52
|
|
|
53
53
|
const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
|
|
54
54
|
expect(receivedMessage).toEqual({
|
|
@@ -62,7 +62,7 @@ describe('connectivityRequestHandler', () => {
|
|
|
62
62
|
tls: false
|
|
63
63
|
},
|
|
64
64
|
ipAddress: ipv4ToNumber(HOST),
|
|
65
|
-
|
|
65
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
66
66
|
},
|
|
67
67
|
oneofKind: 'connectivityResponse'
|
|
68
68
|
},
|
|
@@ -83,7 +83,7 @@ describe('connectivityRequestHandler', () => {
|
|
|
83
83
|
}
|
|
84
84
|
connection.emit('data', Message.toBinary(request))
|
|
85
85
|
|
|
86
|
-
await
|
|
86
|
+
await until(() => connection.send.mock.calls.length > 0)
|
|
87
87
|
|
|
88
88
|
const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
|
|
89
89
|
expect(receivedMessage).toEqual({
|
|
@@ -92,7 +92,7 @@ describe('connectivityRequestHandler', () => {
|
|
|
92
92
|
host: HOST,
|
|
93
93
|
natType: 'unknown',
|
|
94
94
|
ipAddress: ipv4ToNumber(HOST),
|
|
95
|
-
|
|
95
|
+
protocolVersion: LOCAL_PROTOCOL_VERSION
|
|
96
96
|
},
|
|
97
97
|
oneofKind: 'connectivityResponse'
|
|
98
98
|
},
|
|
@@ -13,4 +13,22 @@ describe('custom matchers', () => {
|
|
|
13
13
|
it('no match', () => {
|
|
14
14
|
expect(createMockPeerDescriptor()).not.toEqualPeerDescriptor(createMockPeerDescriptor())
|
|
15
15
|
})
|
|
16
|
+
|
|
17
|
+
describe('error message', () => {
|
|
18
|
+
|
|
19
|
+
it('normal', () => {
|
|
20
|
+
const actual = createMockPeerDescriptor()
|
|
21
|
+
const expected = createMockPeerDescriptor()
|
|
22
|
+
expect(() => {
|
|
23
|
+
expect(actual).toEqualPeerDescriptor(expected)
|
|
24
|
+
}).toThrow('PeerDescriptor nodeId values don\'t match')
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
it('inverse', () => {
|
|
28
|
+
const peerDescriptor = createMockPeerDescriptor()
|
|
29
|
+
expect(() => {
|
|
30
|
+
expect(peerDescriptor).not.toEqualPeerDescriptor(peerDescriptor)
|
|
31
|
+
}).toThrow('PeerDescriptors are equal')
|
|
32
|
+
})
|
|
33
|
+
})
|
|
16
34
|
})
|
|
@@ -10,7 +10,7 @@ describe('getClosestNodes', () => {
|
|
|
10
10
|
it('happy path', () => {
|
|
11
11
|
const peerDescriptors = range(10).map(() => createMockPeerDescriptor())
|
|
12
12
|
const referenceId = randomDhtAddress()
|
|
13
|
-
const excluded = new Set<DhtAddress>(sampleSize(peerDescriptors.map((n) => toNodeId(n), 2))
|
|
13
|
+
const excluded = new Set<DhtAddress>(sampleSize(peerDescriptors.map((n) => toNodeId(n)), 2))
|
|
14
14
|
|
|
15
15
|
const actual = getClosestNodes(
|
|
16
16
|
referenceId,
|
|
@@ -1,18 +1,18 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { isMaybeSupportedProtocolVersion } from '../../src/helpers/version'
|
|
2
2
|
|
|
3
3
|
describe('version', () => {
|
|
4
4
|
|
|
5
5
|
it('supported', () => {
|
|
6
|
-
expect(
|
|
7
|
-
expect(
|
|
8
|
-
expect(
|
|
9
|
-
expect(
|
|
6
|
+
expect(isMaybeSupportedProtocolVersion('1.0')).toBe(true)
|
|
7
|
+
expect(isMaybeSupportedProtocolVersion('1.1')).toBe(true)
|
|
8
|
+
expect(isMaybeSupportedProtocolVersion('2.0')).toBe(true)
|
|
9
|
+
expect(isMaybeSupportedProtocolVersion('3.5')).toBe(true)
|
|
10
10
|
})
|
|
11
11
|
|
|
12
12
|
it('not supported', () => {
|
|
13
|
-
expect(
|
|
14
|
-
expect(
|
|
15
|
-
expect(
|
|
16
|
-
expect(
|
|
13
|
+
expect(isMaybeSupportedProtocolVersion('')).toBe(false)
|
|
14
|
+
expect(isMaybeSupportedProtocolVersion('100.0.0-testnet-three.3')).toBe(false)
|
|
15
|
+
expect(isMaybeSupportedProtocolVersion('0.0')).toBe(false)
|
|
16
|
+
expect(isMaybeSupportedProtocolVersion('0.1')).toBe(false)
|
|
17
17
|
})
|
|
18
18
|
})
|
|
@@ -15,8 +15,8 @@ declare global {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
|
|
18
|
-
const formErrorMessage = (
|
|
19
|
-
return
|
|
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
20
|
}
|
|
21
21
|
|
|
22
22
|
const toEqualPeerDescriptor = (
|
|
@@ -32,7 +32,7 @@ const toEqualPeerDescriptor = (
|
|
|
32
32
|
messages.push(formErrorMessage('type', typeNames[expected.type], typeNames[actual.type]))
|
|
33
33
|
}
|
|
34
34
|
expectEqualConnectivityMethod('udp', expected.udp, actual.udp, messages)
|
|
35
|
-
expectEqualConnectivityMethod('
|
|
35
|
+
expectEqualConnectivityMethod('tcp', expected.tcp, actual.tcp, messages)
|
|
36
36
|
expectEqualConnectivityMethod('websocket', expected.websocket, actual.websocket, messages)
|
|
37
37
|
if (expected.region !== actual.region) {
|
|
38
38
|
messages.push(formErrorMessage('region', expected?.region, actual?.region))
|
|
@@ -45,13 +45,13 @@ const toEqualPeerDescriptor = (
|
|
|
45
45
|
} else {
|
|
46
46
|
return {
|
|
47
47
|
pass: true,
|
|
48
|
-
message: () =>
|
|
48
|
+
message: () => 'PeerDescriptors are equal'
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
const expectEqualConnectivityMethod = (
|
|
54
|
-
|
|
54
|
+
field: keyof PeerDescriptor,
|
|
55
55
|
method1: ConnectivityMethod | undefined,
|
|
56
56
|
method2: ConnectivityMethod | undefined,
|
|
57
57
|
messages: string[]
|
|
@@ -62,7 +62,7 @@ const expectEqualConnectivityMethod = (
|
|
|
62
62
|
: undefined
|
|
63
63
|
}
|
|
64
64
|
if (!isEqual(method1, method2)) {
|
|
65
|
-
messages.push(formErrorMessage(
|
|
65
|
+
messages.push(formErrorMessage(field, toOutput(method1), toOutput(method2)))
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
|
package/test/utils/topology.ts
CHANGED
package/test/utils/utils.ts
CHANGED
|
@@ -25,7 +25,7 @@ import { v4 } from 'uuid'
|
|
|
25
25
|
import { getRandomRegion } from '../../src/connection/simulator/pings'
|
|
26
26
|
import { Empty } from '../../generated/google/protobuf/empty'
|
|
27
27
|
import { Any } from '../../generated/google/protobuf/any'
|
|
28
|
-
import { wait,
|
|
28
|
+
import { wait, until } from '@streamr/utils'
|
|
29
29
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
30
30
|
import { DhtAddress, randomDhtAddress, toDhtAddressRaw } from '../../src/identifiers'
|
|
31
31
|
|
|
@@ -258,7 +258,7 @@ export const waitForStableTopology = async (nodes: DhtNode[], maxConnectionCount
|
|
|
258
258
|
await Promise.all(connectionManagers.map(async (connectionManager) => {
|
|
259
259
|
connectionManager.garbageCollectConnections(maxConnectionCount, MAX_IDLE_TIME)
|
|
260
260
|
try {
|
|
261
|
-
await
|
|
261
|
+
await until(() => connectionManager.getConnections().length <= maxConnectionCount, waitTime)
|
|
262
262
|
} catch {
|
|
263
263
|
// the topology is very likely stable, but we can't be sure (maybe the node has more than maxConnectionCount
|
|
264
264
|
// locked connections and therefore it is ok to that garbage collector was not able to remove any of those
|
package/.eslintignore
DELETED
package/.eslintrc
DELETED