@streamr/dht 0.0.1-tatum.1 → 0.0.1-tatum.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/src/connection/ConnectionManager.d.ts +6 -1
- package/dist/src/connection/ConnectionManager.js +21 -26
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.d.ts +4 -2
- package/dist/src/connection/ConnectivityChecker.js +23 -19
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +2 -6
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js +1 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -1
- package/dist/src/connection/WebRTC/WebRtcConnector.d.ts +2 -0
- package/dist/src/connection/WebRTC/WebRtcConnector.js +14 -1
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +1 -1
- package/dist/src/connection/WebSocket/WebSocketConnector.d.ts +5 -3
- package/dist/src/connection/WebSocket/WebSocketConnector.js +19 -12
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +1 -1
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +2 -2
- package/dist/src/connection/WebSocket/WebSocketServer.js +29 -37
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -6
- package/dist/src/dht/DhtNode.js +14 -21
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtPeer.js +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +4 -2
- package/dist/src/dht/discovery/PeerDiscovery.js +18 -33
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/routing/RemoteRouter.js +2 -4
- package/dist/src/dht/routing/RemoteRouter.js.map +1 -1
- package/dist/src/dht/store/DataStore.js +6 -6
- package/dist/src/exports.d.ts +1 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/errors.d.ts +1 -1
- package/dist/src/helpers/errors.js +3 -3
- package/dist/src/helpers/errors.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +0 -2
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +14 -50
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +9 -35
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/package.json +9 -9
- package/protos/DhtRpc.proto +7 -16
- package/src/connection/ConnectionManager.ts +31 -28
- package/src/connection/ConnectivityChecker.ts +28 -23
- package/src/connection/ManagedConnection.ts +2 -6
- package/src/connection/Simulator/SimulatorTransport.ts +1 -1
- package/src/connection/WebRTC/BrowserWebRtcConnection.ts +13 -2
- package/src/connection/WebRTC/WebRtcConnector.ts +14 -0
- package/src/connection/WebSocket/WebSocketConnector.ts +23 -12
- package/src/connection/WebSocket/WebSocketServer.ts +33 -20
- package/src/dht/DhtNode.ts +23 -24
- package/src/dht/DhtPeer.ts +1 -1
- package/src/dht/discovery/PeerDiscovery.ts +17 -8
- package/src/dht/routing/RemoteRouter.ts +2 -4
- package/src/dht/store/DataStore.ts +6 -6
- package/src/exports.ts +1 -1
- package/src/helpers/errors.ts +1 -1
- package/src/helpers/protoClasses.ts +1 -5
- package/src/proto/google/protobuf/any.ts +1 -1
- package/src/proto/google/protobuf/empty.ts +1 -1
- package/src/proto/google/protobuf/timestamp.ts +1 -1
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +1 -1
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +1 -1
- package/src/proto/packages/dht/protos/DhtRpc.ts +22 -69
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/test/benchmark/KademliaCorrectness.test.ts +1 -1
- package/test/benchmark/RecursiveFind.test.ts +1 -1
- package/test/end-to-end/Layer0-Layer1.test.ts +3 -3
- package/test/end-to-end/Layer0.test.ts +5 -5
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +6 -6
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +18 -19
- package/test/end-to-end/Layer0WebRTC.test.ts +18 -24
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +2 -2
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +3 -3
- package/test/integration/ConnectionManager.test.ts +10 -9
- package/test/integration/DhtRpc.test.ts +2 -2
- package/test/integration/MigrateData.test.ts +3 -3
- package/test/integration/RouteMessage.test.ts +2 -2
- package/test/integration/ScaleDownDht.test.ts +1 -1
- package/test/integration/SimultaneousConnections.test.ts +9 -6
- package/test/integration/WebRtcConnectionManagement.test.ts +2 -2
- package/test/integration/WebRtcConnectorRpc.test.ts +2 -2
- package/test/integration/WebSocketConnectionManagement.test.ts +3 -2
- package/test/integration/WebSocketConnectorRpc.test.ts +4 -4
- package/test/unit/WebSocketServer.test.ts +1 -8
- package/test/unit/webrtcReplaceInternalIpWithExternalIp.ts +18 -0
- package/test/utils/utils.ts +1 -2
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protobuf-ts 2.
|
|
1
|
+
// @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
|
|
2
2
|
// @generated from protobuf file "packages/dht/protos/DhtRpc.proto" (package "dht", syntax proto3)
|
|
3
3
|
// tslint:disable
|
|
4
4
|
import { Empty } from "../../../google/protobuf/empty";
|
|
@@ -240,48 +240,18 @@ export interface PeerDescriptor {
|
|
|
240
240
|
* @generated from protobuf message dht.ConnectivityMethod
|
|
241
241
|
*/
|
|
242
242
|
export interface ConnectivityMethod {
|
|
243
|
-
/**
|
|
244
|
-
* @generated from protobuf field: uint32 port = 2;
|
|
245
|
-
*/
|
|
246
|
-
port: number;
|
|
247
|
-
/**
|
|
248
|
-
* @generated from protobuf field: string ip = 3;
|
|
249
|
-
*/
|
|
250
|
-
ip: string;
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* @generated from protobuf message dht.ConnectivityReportRequest
|
|
254
|
-
*/
|
|
255
|
-
export interface ConnectivityReportRequest {
|
|
256
243
|
/**
|
|
257
244
|
* @generated from protobuf field: uint32 port = 1;
|
|
258
245
|
*/
|
|
259
246
|
port: number;
|
|
260
247
|
/**
|
|
261
|
-
* @generated from protobuf field: string
|
|
248
|
+
* @generated from protobuf field: string host = 2;
|
|
262
249
|
*/
|
|
263
|
-
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* @generated from protobuf message dht.ConnectivityReportResponse
|
|
267
|
-
*/
|
|
268
|
-
export interface ConnectivityReportResponse {
|
|
269
|
-
/**
|
|
270
|
-
* @generated from protobuf field: string open_internet = 1;
|
|
271
|
-
*/
|
|
272
|
-
openInternet: string;
|
|
273
|
-
/**
|
|
274
|
-
* @generated from protobuf field: string ip = 2;
|
|
275
|
-
*/
|
|
276
|
-
ip: string;
|
|
277
|
-
/**
|
|
278
|
-
* @generated from protobuf field: string natType = 3;
|
|
279
|
-
*/
|
|
280
|
-
natType: string;
|
|
250
|
+
host: string;
|
|
281
251
|
/**
|
|
282
|
-
* @generated from protobuf field:
|
|
252
|
+
* @generated from protobuf field: bool tls = 3;
|
|
283
253
|
*/
|
|
284
|
-
|
|
254
|
+
tls: boolean;
|
|
285
255
|
}
|
|
286
256
|
/**
|
|
287
257
|
* @generated from protobuf message dht.RouteMessageWrapper
|
|
@@ -347,6 +317,14 @@ export interface ConnectivityRequest {
|
|
|
347
317
|
* @generated from protobuf field: uint32 port = 1;
|
|
348
318
|
*/
|
|
349
319
|
port: number;
|
|
320
|
+
/**
|
|
321
|
+
* @generated from protobuf field: bool tls = 2;
|
|
322
|
+
*/
|
|
323
|
+
tls: boolean;
|
|
324
|
+
/**
|
|
325
|
+
* @generated from protobuf field: optional string host = 3;
|
|
326
|
+
*/
|
|
327
|
+
host?: string;
|
|
350
328
|
}
|
|
351
329
|
/**
|
|
352
330
|
* @generated from protobuf message dht.ConnectivityResponse
|
|
@@ -357,9 +335,9 @@ export interface ConnectivityResponse {
|
|
|
357
335
|
*/
|
|
358
336
|
openInternet: boolean;
|
|
359
337
|
/**
|
|
360
|
-
* @generated from protobuf field: string
|
|
338
|
+
* @generated from protobuf field: string host = 2;
|
|
361
339
|
*/
|
|
362
|
-
|
|
340
|
+
host: string;
|
|
363
341
|
/**
|
|
364
342
|
* @generated from protobuf field: string natType = 3;
|
|
365
343
|
*/
|
|
@@ -1007,8 +985,9 @@ export const PeerDescriptor = new PeerDescriptor$Type();
|
|
|
1007
985
|
class ConnectivityMethod$Type extends MessageType$<ConnectivityMethod> {
|
|
1008
986
|
constructor() {
|
|
1009
987
|
super("dht.ConnectivityMethod", [
|
|
1010
|
-
{ no:
|
|
1011
|
-
{ no:
|
|
988
|
+
{ no: 1, name: "port", kind: "scalar", T: 13 /*ScalarType.UINT32*/ },
|
|
989
|
+
{ no: 2, name: "host", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
990
|
+
{ no: 3, name: "tls", kind: "scalar", T: 8 /*ScalarType.BOOL*/ }
|
|
1012
991
|
]);
|
|
1013
992
|
}
|
|
1014
993
|
}
|
|
@@ -1017,34 +996,6 @@ class ConnectivityMethod$Type extends MessageType$<ConnectivityMethod> {
|
|
|
1017
996
|
*/
|
|
1018
997
|
export const ConnectivityMethod = new ConnectivityMethod$Type();
|
|
1019
998
|
// @generated message type with reflection information, may provide speed optimized methods
|
|
1020
|
-
class ConnectivityReportRequest$Type extends MessageType$<ConnectivityReportRequest> {
|
|
1021
|
-
constructor() {
|
|
1022
|
-
super("dht.ConnectivityReportRequest", [
|
|
1023
|
-
{ no: 1, name: "port", kind: "scalar", T: 13 /*ScalarType.UINT32*/ },
|
|
1024
|
-
{ no: 2, name: "requestId", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
|
|
1025
|
-
]);
|
|
1026
|
-
}
|
|
1027
|
-
}
|
|
1028
|
-
/**
|
|
1029
|
-
* @generated MessageType for protobuf message dht.ConnectivityReportRequest
|
|
1030
|
-
*/
|
|
1031
|
-
export const ConnectivityReportRequest = new ConnectivityReportRequest$Type();
|
|
1032
|
-
// @generated message type with reflection information, may provide speed optimized methods
|
|
1033
|
-
class ConnectivityReportResponse$Type extends MessageType$<ConnectivityReportResponse> {
|
|
1034
|
-
constructor() {
|
|
1035
|
-
super("dht.ConnectivityReportResponse", [
|
|
1036
|
-
{ no: 1, name: "open_internet", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
1037
|
-
{ no: 2, name: "ip", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
1038
|
-
{ no: 3, name: "natType", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
1039
|
-
{ no: 4, name: "requestId", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
|
|
1040
|
-
]);
|
|
1041
|
-
}
|
|
1042
|
-
}
|
|
1043
|
-
/**
|
|
1044
|
-
* @generated MessageType for protobuf message dht.ConnectivityReportResponse
|
|
1045
|
-
*/
|
|
1046
|
-
export const ConnectivityReportResponse = new ConnectivityReportResponse$Type();
|
|
1047
|
-
// @generated message type with reflection information, may provide speed optimized methods
|
|
1048
999
|
class RouteMessageWrapper$Type extends MessageType$<RouteMessageWrapper> {
|
|
1049
1000
|
constructor() {
|
|
1050
1001
|
super("dht.RouteMessageWrapper", [
|
|
@@ -1081,7 +1032,9 @@ export const RouteMessageAck = new RouteMessageAck$Type();
|
|
|
1081
1032
|
class ConnectivityRequest$Type extends MessageType$<ConnectivityRequest> {
|
|
1082
1033
|
constructor() {
|
|
1083
1034
|
super("dht.ConnectivityRequest", [
|
|
1084
|
-
{ no: 1, name: "port", kind: "scalar", T: 13 /*ScalarType.UINT32*/ }
|
|
1035
|
+
{ no: 1, name: "port", kind: "scalar", T: 13 /*ScalarType.UINT32*/ },
|
|
1036
|
+
{ no: 2, name: "tls", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
|
|
1037
|
+
{ no: 3, name: "host", kind: "scalar", opt: true, T: 9 /*ScalarType.STRING*/ }
|
|
1085
1038
|
]);
|
|
1086
1039
|
}
|
|
1087
1040
|
}
|
|
@@ -1094,7 +1047,7 @@ class ConnectivityResponse$Type extends MessageType$<ConnectivityResponse> {
|
|
|
1094
1047
|
constructor() {
|
|
1095
1048
|
super("dht.ConnectivityResponse", [
|
|
1096
1049
|
{ no: 1, name: "open_internet", kind: "scalar", T: 8 /*ScalarType.BOOL*/ },
|
|
1097
|
-
{ no: 2, name: "
|
|
1050
|
+
{ no: 2, name: "host", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
1098
1051
|
{ no: 3, name: "natType", kind: "scalar", T: 9 /*ScalarType.STRING*/ },
|
|
1099
1052
|
{ no: 4, name: "websocket", kind: "message", T: () => ConnectivityMethod }
|
|
1100
1053
|
]);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// @generated by protobuf-ts 2.
|
|
1
|
+
// @generated by protobuf-ts 2.9.1 with parameter server_generic,generate_dependencies,long_type_number
|
|
2
2
|
// @generated from protobuf file "packages/proto-rpc/protos/ProtoRpc.proto" (package "protorpc", syntax proto3)
|
|
3
3
|
// tslint:disable
|
|
4
4
|
import { MessageType } from "@protobuf-ts/runtime";
|
|
@@ -86,7 +86,7 @@ describe('Kademlia correctness', () => {
|
|
|
86
86
|
correctNeighbors++
|
|
87
87
|
}
|
|
88
88
|
} catch (e) {
|
|
89
|
-
console.error('Node ' + nodes[i].
|
|
89
|
+
console.error('Node ' + nodes[i].getPeerDescriptor().nodeName + ' had only ' + kademliaNeighbors.length + ' kademlia neighbors')
|
|
90
90
|
}
|
|
91
91
|
if (correctNeighbors === 0) {
|
|
92
92
|
console.log('No correct neighbors found for node ' + i)
|
|
@@ -70,7 +70,7 @@ describe('Recursive find correctness', () => {
|
|
|
70
70
|
debugVars['waiting'] = false
|
|
71
71
|
logger.info('waiting over')
|
|
72
72
|
|
|
73
|
-
nodes.forEach((node) => logger.info(node.
|
|
73
|
+
nodes.forEach((node) => logger.info(node.getPeerDescriptor().nodeName + ': connections:' +
|
|
74
74
|
node.getNumberOfConnections() + ', kbucket: ' + node.getBucketSize()
|
|
75
75
|
+ ', localLocked: ' + node.getNumberOfLocalLockedConnections()
|
|
76
76
|
+ ', remoteLocked: ' + node.getNumberOfRemoteLockedConnections()
|
|
@@ -6,7 +6,7 @@ describe('Layer0-Layer1', () => {
|
|
|
6
6
|
const epPeerDescriptor: PeerDescriptor = {
|
|
7
7
|
kademliaId: Uint8Array.from([1, 2, 3]),
|
|
8
8
|
type: NodeType.NODEJS,
|
|
9
|
-
websocket: {
|
|
9
|
+
websocket: { host: '127.0.0.1', port: 10016, tls: false }
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const STREAM_ID1 = 'stream1'
|
|
@@ -29,8 +29,8 @@ describe('Layer0-Layer1', () => {
|
|
|
29
29
|
await epDhtNode.start()
|
|
30
30
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
31
31
|
|
|
32
|
-
node1 = new DhtNode({
|
|
33
|
-
node2 = new DhtNode({
|
|
32
|
+
node1 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
33
|
+
node2 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
34
34
|
|
|
35
35
|
await node1.start()
|
|
36
36
|
await node2.start()
|
|
@@ -6,7 +6,7 @@ describe('Layer0', () => {
|
|
|
6
6
|
const epPeerDescriptor: PeerDescriptor = {
|
|
7
7
|
kademliaId: Uint8Array.from([1, 2, 3]),
|
|
8
8
|
type: NodeType.NODEJS,
|
|
9
|
-
websocket: {
|
|
9
|
+
websocket: { host: '127.0.0.1', port: 10011, tls: false }
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
let epDhtNode: DhtNode
|
|
@@ -23,10 +23,10 @@ describe('Layer0', () => {
|
|
|
23
23
|
|
|
24
24
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
25
25
|
|
|
26
|
-
node1 = new DhtNode({
|
|
27
|
-
node2 = new DhtNode({
|
|
28
|
-
node3 = new DhtNode({
|
|
29
|
-
node4 = new DhtNode({
|
|
26
|
+
node1 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
27
|
+
node2 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
28
|
+
node3 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
29
|
+
node4 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
30
30
|
|
|
31
31
|
await node1.start()
|
|
32
32
|
await node2.start()
|
|
@@ -8,7 +8,7 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
8
8
|
const epPeerDescriptor: PeerDescriptor = {
|
|
9
9
|
kademliaId: Uint8Array.from([1, 2, 3]),
|
|
10
10
|
type: NodeType.NODEJS,
|
|
11
|
-
websocket: {
|
|
11
|
+
websocket: { host: '127.0.0.1', port: 11221, tls: false }
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
let epDhtNode: DhtNode
|
|
@@ -25,11 +25,11 @@ describe('Layer0MixedConnectionTypes', () => {
|
|
|
25
25
|
await epDhtNode.start()
|
|
26
26
|
|
|
27
27
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
28
|
-
node1 = new DhtNode({
|
|
29
|
-
node2 = new DhtNode({
|
|
30
|
-
node3 = new DhtNode({
|
|
31
|
-
node4 = new DhtNode({
|
|
32
|
-
node5 = new DhtNode({
|
|
28
|
+
node1 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
29
|
+
node2 = new DhtNode({ websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
30
|
+
node3 = new DhtNode({ entryPoints: [epPeerDescriptor] })
|
|
31
|
+
node4 = new DhtNode({ entryPoints: [epPeerDescriptor] })
|
|
32
|
+
node5 = new DhtNode({ entryPoints: [epPeerDescriptor] })
|
|
33
33
|
|
|
34
34
|
await Promise.all([
|
|
35
35
|
node1.start(),
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
+
import { binaryToHex } from '@streamr/utils'
|
|
1
2
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { PeerID } from '../../src/exports'
|
|
4
4
|
|
|
5
5
|
describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
6
|
-
const entryPointId = '00000'
|
|
7
|
-
|
|
8
6
|
const entrypointDescriptor: PeerDescriptor = {
|
|
9
|
-
kademliaId:
|
|
7
|
+
kademliaId: new Uint8Array([0]),
|
|
10
8
|
type: NodeType.NODEJS,
|
|
11
9
|
websocket: {
|
|
12
|
-
|
|
13
|
-
port: 23232
|
|
10
|
+
host: '127.0.0.1',
|
|
11
|
+
port: 23232,
|
|
12
|
+
tls: false
|
|
14
13
|
}
|
|
15
14
|
}
|
|
16
15
|
|
|
@@ -33,52 +32,52 @@ describe('Layer 1 on Layer 0 with mocked connections', () => {
|
|
|
33
32
|
|
|
34
33
|
layer0EntryPoint = new DhtNode({ peerDescriptor: entrypointDescriptor })
|
|
35
34
|
|
|
36
|
-
const layer0Node1Id = '
|
|
35
|
+
const layer0Node1Id = '11'
|
|
37
36
|
layer0Node1 = new DhtNode({
|
|
38
|
-
|
|
37
|
+
peerId: layer0Node1Id
|
|
39
38
|
})
|
|
40
39
|
|
|
41
|
-
const layer0Node2Id = '
|
|
40
|
+
const layer0Node2Id = '22'
|
|
42
41
|
layer0Node2 = new DhtNode({
|
|
43
|
-
|
|
42
|
+
peerId: layer0Node2Id
|
|
44
43
|
})
|
|
45
44
|
|
|
46
|
-
const layer0Node3Id = '
|
|
45
|
+
const layer0Node3Id = '33'
|
|
47
46
|
layer0Node3 = new DhtNode({
|
|
48
|
-
|
|
47
|
+
peerId: layer0Node3Id
|
|
49
48
|
})
|
|
50
49
|
|
|
51
|
-
const layer0Node4Id = '
|
|
50
|
+
const layer0Node4Id = '44'
|
|
52
51
|
layer0Node4 = new DhtNode({
|
|
53
|
-
|
|
52
|
+
peerId: layer0Node4Id
|
|
54
53
|
})
|
|
55
54
|
|
|
56
55
|
layer1EntryPoint = new DhtNode({
|
|
57
|
-
|
|
56
|
+
peerId: binaryToHex(entrypointDescriptor.kademliaId),
|
|
58
57
|
transportLayer: layer0EntryPoint,
|
|
59
58
|
serviceId: 'layer1'
|
|
60
59
|
})
|
|
61
60
|
|
|
62
61
|
layer1Node1 = new DhtNode({
|
|
63
|
-
|
|
62
|
+
peerId: layer0Node1Id,
|
|
64
63
|
transportLayer: layer0Node1,
|
|
65
64
|
serviceId: 'layer1'
|
|
66
65
|
})
|
|
67
66
|
|
|
68
67
|
layer1Node2 = new DhtNode({
|
|
69
|
-
|
|
68
|
+
peerId: layer0Node2Id,
|
|
70
69
|
transportLayer: layer0Node2,
|
|
71
70
|
serviceId: 'layer1'
|
|
72
71
|
})
|
|
73
72
|
|
|
74
73
|
layer1Node3 = new DhtNode({
|
|
75
|
-
|
|
74
|
+
peerId: layer0Node3Id,
|
|
76
75
|
transportLayer: layer0Node3,
|
|
77
76
|
serviceId: 'layer1'
|
|
78
77
|
})
|
|
79
78
|
|
|
80
79
|
layer1Node4 = new DhtNode({
|
|
81
|
-
|
|
80
|
+
peerId: layer0Node4Id,
|
|
82
81
|
transportLayer: layer0Node4,
|
|
83
82
|
serviceId: 'layer1'
|
|
84
83
|
})
|
|
@@ -1,17 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { areEqualBinaries, waitForEvent3 } from '@streamr/utils'
|
|
2
|
+
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
|
+
import { ConnectionType } from '../../src/connection/IConnection'
|
|
2
4
|
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
5
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
4
|
-
import {
|
|
5
|
-
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
6
|
-
import EventEmitter from 'events'
|
|
7
|
-
import { waitForEvent } from '@streamr/utils'
|
|
6
|
+
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
7
|
|
|
9
8
|
describe('Layer0 with WebRTC connections', () => {
|
|
10
9
|
const epPeerDescriptor: PeerDescriptor = {
|
|
11
10
|
kademliaId: PeerID.fromString('entrypoint').value,
|
|
12
11
|
nodeName: 'entrypoint',
|
|
13
12
|
type: NodeType.NODEJS,
|
|
14
|
-
websocket: {
|
|
13
|
+
websocket: { host: '127.0.0.1', port: 10029, tls: false }
|
|
15
14
|
}
|
|
16
15
|
let epDhtNode: DhtNode
|
|
17
16
|
let node1: DhtNode
|
|
@@ -26,10 +25,10 @@ describe('Layer0 with WebRTC connections', () => {
|
|
|
26
25
|
|
|
27
26
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
28
27
|
|
|
29
|
-
node1 = new DhtNode({
|
|
30
|
-
node2 = new DhtNode({
|
|
31
|
-
node3 = new DhtNode({
|
|
32
|
-
node4 = new DhtNode({
|
|
28
|
+
node1 = new DhtNode({ nodeName: 'Peer0', entryPoints: [epPeerDescriptor] })
|
|
29
|
+
node2 = new DhtNode({ nodeName: 'Peer1', entryPoints: [epPeerDescriptor] })
|
|
30
|
+
node3 = new DhtNode({ nodeName: 'Peer2', entryPoints: [epPeerDescriptor] })
|
|
31
|
+
node4 = new DhtNode({ nodeName: 'Peer3', entryPoints: [epPeerDescriptor] })
|
|
33
32
|
|
|
34
33
|
await Promise.all([
|
|
35
34
|
node1.start(),
|
|
@@ -51,22 +50,17 @@ describe('Layer0 with WebRTC connections', () => {
|
|
|
51
50
|
await epDhtNode.stop()
|
|
52
51
|
})
|
|
53
52
|
|
|
54
|
-
class Peer0Listener extends EventEmitter {
|
|
55
|
-
private nodeToListen: DhtNode
|
|
56
|
-
constructor(nodeToListen: DhtNode) {
|
|
57
|
-
super()
|
|
58
|
-
this.nodeToListen = nodeToListen
|
|
59
|
-
this.nodeToListen.on('connected', (peer: PeerDescriptor) => {
|
|
60
|
-
if (PeerID.fromValue(peer.kademliaId).equals(PeerID.fromString('Peer0'))) {
|
|
61
|
-
this.emit('peer0connected')
|
|
62
|
-
}
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
53
|
it('Happy path two peers', async () => {
|
|
68
54
|
|
|
69
|
-
await Promise.all([
|
|
55
|
+
await Promise.all([
|
|
56
|
+
waitForEvent3<any>(
|
|
57
|
+
node2 as any,
|
|
58
|
+
'connected',
|
|
59
|
+
20000,
|
|
60
|
+
(peerDescriptor: PeerDescriptor) => {
|
|
61
|
+
return areEqualBinaries(peerDescriptor.kademliaId, node1.getPeerDescriptor().kademliaId)
|
|
62
|
+
}
|
|
63
|
+
),
|
|
70
64
|
node2.joinDht([epPeerDescriptor]),
|
|
71
65
|
node1.joinDht([epPeerDescriptor])
|
|
72
66
|
])
|
|
@@ -6,7 +6,7 @@ describe('Layer1 Scale', () => {
|
|
|
6
6
|
const epPeerDescriptor: PeerDescriptor = {
|
|
7
7
|
kademliaId: PeerID.fromString('0').value,
|
|
8
8
|
type: NodeType.NODEJS,
|
|
9
|
-
websocket: {
|
|
9
|
+
websocket: { host: '127.0.0.1', port: 43228, tls: false },
|
|
10
10
|
nodeName: 'entrypoint'
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -34,7 +34,7 @@ describe('Layer1 Scale', () => {
|
|
|
34
34
|
layer1Nodes = []
|
|
35
35
|
|
|
36
36
|
for (let i = 1; i < NUM_OF_NODES; i++) {
|
|
37
|
-
const node = new DhtNode({
|
|
37
|
+
const node = new DhtNode({ nodeName: `${i}`, entryPoints: [epPeerDescriptor] })
|
|
38
38
|
await node.start()
|
|
39
39
|
layer0Nodes.push(node)
|
|
40
40
|
const layer1 = new DhtNode({
|
|
@@ -6,7 +6,7 @@ describe('Layer1 Scale', () => {
|
|
|
6
6
|
const epPeerDescriptor: PeerDescriptor = {
|
|
7
7
|
kademliaId: PeerID.fromString('entrypoint').value,
|
|
8
8
|
type: NodeType.NODEJS,
|
|
9
|
-
websocket: {
|
|
9
|
+
websocket: { host: '127.0.0.1', port: 43225, tls: false },
|
|
10
10
|
nodeName: 'entrypoint'
|
|
11
11
|
}
|
|
12
12
|
|
|
@@ -36,7 +36,7 @@ describe('Layer1 Scale', () => {
|
|
|
36
36
|
layer1Nodes = []
|
|
37
37
|
|
|
38
38
|
for (let i = 0; i < NUM_OF_NODES; i++) {
|
|
39
|
-
const node = new DhtNode({
|
|
39
|
+
const node = new DhtNode({ nodeName: `${i}`, websocketPortRange, entryPoints: [epPeerDescriptor] })
|
|
40
40
|
await node.start()
|
|
41
41
|
layer0Nodes.push(node)
|
|
42
42
|
const layer1 = new DhtNode({
|
|
@@ -9,7 +9,7 @@ describe('WebSocket IConnection Requests', () => {
|
|
|
9
9
|
const epPeerDescriptor: PeerDescriptor = {
|
|
10
10
|
kademliaId: PeerID.fromString('3').value,
|
|
11
11
|
type: NodeType.NODEJS,
|
|
12
|
-
websocket: {
|
|
12
|
+
websocket: { host: '127.0.0.1', port: 10021, tls: false }
|
|
13
13
|
}
|
|
14
14
|
let epDhtNode: DhtNode
|
|
15
15
|
let node1: DhtNode
|
|
@@ -22,8 +22,8 @@ describe('WebSocket IConnection Requests', () => {
|
|
|
22
22
|
|
|
23
23
|
await epDhtNode.joinDht([epPeerDescriptor])
|
|
24
24
|
|
|
25
|
-
node1 = new DhtNode({
|
|
26
|
-
node2 = new DhtNode({
|
|
25
|
+
node1 = new DhtNode({ nodeName: 'node1', websocketPortRange: { min: 10022, max: 10022 }, entryPoints: [epPeerDescriptor] })
|
|
26
|
+
node2 = new DhtNode({ nodeName: 'node2', entryPoints: [epPeerDescriptor] })
|
|
27
27
|
await node1.start()
|
|
28
28
|
await node2.start()
|
|
29
29
|
})
|
|
@@ -8,6 +8,7 @@ import { Logger } from '@streamr/utils'
|
|
|
8
8
|
|
|
9
9
|
const logger = new Logger(module)
|
|
10
10
|
|
|
11
|
+
// TODO: refactor this test file to use beforeEach and AfterEach for proper teardown
|
|
11
12
|
describe('ConnectionManager', () => {
|
|
12
13
|
const serviceId = 'demo'
|
|
13
14
|
|
|
@@ -52,7 +53,7 @@ describe('ConnectionManager', () => {
|
|
|
52
53
|
})
|
|
53
54
|
|
|
54
55
|
await connectionManager.start((report) => {
|
|
55
|
-
expect(report.
|
|
56
|
+
expect(report.host).toEqual('127.0.0.1')
|
|
56
57
|
expect(report.openInternet).toEqual(true)
|
|
57
58
|
return createPeerDescriptor(report)
|
|
58
59
|
})
|
|
@@ -66,7 +67,7 @@ describe('ConnectionManager', () => {
|
|
|
66
67
|
transportLayer: mockTransport,
|
|
67
68
|
websocketPortRange: { min: 9992, max: 9992 },
|
|
68
69
|
entryPoints: [
|
|
69
|
-
{ kademliaId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: {
|
|
70
|
+
{ kademliaId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 12345, tls: false } }
|
|
70
71
|
]
|
|
71
72
|
})
|
|
72
73
|
|
|
@@ -85,7 +86,7 @@ describe('ConnectionManager', () => {
|
|
|
85
86
|
})
|
|
86
87
|
|
|
87
88
|
await connectionManager1.start((report) => {
|
|
88
|
-
expect(report.
|
|
89
|
+
expect(report.host).toEqual('127.0.0.1')
|
|
89
90
|
expect(report.openInternet).toEqual(true)
|
|
90
91
|
return createPeerDescriptor(report)
|
|
91
92
|
})
|
|
@@ -94,12 +95,12 @@ describe('ConnectionManager', () => {
|
|
|
94
95
|
transportLayer: mockConnectorTransport2,
|
|
95
96
|
websocketPortRange: { min: 9994, max: 9994 },
|
|
96
97
|
entryPoints: [
|
|
97
|
-
{ kademliaId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: {
|
|
98
|
+
{ kademliaId: Uint8Array.from([1, 2, 3]), type: NodeType.NODEJS, websocket: { host: '127.0.0.1', port: 9993, tls: false } }
|
|
98
99
|
]
|
|
99
100
|
})
|
|
100
101
|
|
|
101
102
|
await connectionManager2.start((report) => {
|
|
102
|
-
expect(report.
|
|
103
|
+
expect(report.host).toEqual('127.0.0.1')
|
|
103
104
|
expect(report.openInternet).toEqual(true)
|
|
104
105
|
return createPeerDescriptor(report)
|
|
105
106
|
})
|
|
@@ -118,7 +119,7 @@ describe('ConnectionManager', () => {
|
|
|
118
119
|
let peerDescriptor: PeerDescriptor | undefined
|
|
119
120
|
|
|
120
121
|
await connectionManager1.start((report) => {
|
|
121
|
-
expect(report.
|
|
122
|
+
expect(report.host).toEqual('127.0.0.1')
|
|
122
123
|
expect(report.openInternet).toEqual(true)
|
|
123
124
|
peerDescriptor = createPeerDescriptor(report)
|
|
124
125
|
return peerDescriptor
|
|
@@ -134,7 +135,7 @@ describe('ConnectionManager', () => {
|
|
|
134
135
|
|
|
135
136
|
let peerDescriptor2: PeerDescriptor | undefined
|
|
136
137
|
await connectionManager2.start((report2) => {
|
|
137
|
-
expect(report2.
|
|
138
|
+
expect(report2.host).toEqual('127.0.0.1')
|
|
138
139
|
expect(report2.openInternet).toEqual(true)
|
|
139
140
|
peerDescriptor2 = createPeerDescriptor(report2)
|
|
140
141
|
return peerDescriptor2
|
|
@@ -187,7 +188,7 @@ describe('ConnectionManager', () => {
|
|
|
187
188
|
|
|
188
189
|
let peerDescriptor: PeerDescriptor | undefined
|
|
189
190
|
await connectionManager1.start((report) => {
|
|
190
|
-
expect(report.
|
|
191
|
+
expect(report.host).toEqual('127.0.0.1')
|
|
191
192
|
expect(report.openInternet).toEqual(true)
|
|
192
193
|
peerDescriptor = createPeerDescriptor(report)
|
|
193
194
|
return peerDescriptor
|
|
@@ -316,7 +317,7 @@ describe('ConnectionManager', () => {
|
|
|
316
317
|
})
|
|
317
318
|
|
|
318
319
|
await connectionManager1.start((report) => {
|
|
319
|
-
expect(report.
|
|
320
|
+
expect(report.host).toEqual('127.0.0.1')
|
|
320
321
|
expect(report.openInternet).toEqual(true)
|
|
321
322
|
return createPeerDescriptor(report)
|
|
322
323
|
})
|
|
@@ -114,13 +114,13 @@ describe('Migrating data from node to node in DHT', () => {
|
|
|
114
114
|
hasDataMarker = '<-'
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
-
logger.info(contact.getPeerDescriptor().nodeName + ' ' + node.
|
|
117
|
+
logger.info(contact.getPeerDescriptor().nodeName + ' ' + node.getPeerDescriptor().nodeName + hasDataMarker)
|
|
118
118
|
})
|
|
119
119
|
|
|
120
120
|
logger.info(NUM_NODES + ' nodes joining layer0 DHT')
|
|
121
121
|
await Promise.all(
|
|
122
122
|
nodes.map((node) => {
|
|
123
|
-
if (node.
|
|
123
|
+
if (node.getPeerDescriptor().nodeName != '0') {
|
|
124
124
|
node.joinDht([entrypointDescriptor])
|
|
125
125
|
}
|
|
126
126
|
})
|
|
@@ -142,7 +142,7 @@ describe('Migrating data from node to node in DHT', () => {
|
|
|
142
142
|
hasDataMarker = '<-'
|
|
143
143
|
}
|
|
144
144
|
|
|
145
|
-
logger.info('' + node.
|
|
145
|
+
logger.info('' + node.getPeerDescriptor().nodeName + hasDataMarker)
|
|
146
146
|
})
|
|
147
147
|
|
|
148
148
|
const closestNode = nodesById.get(PeerID.fromValue(closest[0].getPeerDescriptor().kademliaId).toKey())!
|
|
@@ -113,7 +113,7 @@ describe('Route Message With Mock Connections', () => {
|
|
|
113
113
|
sourceDescriptor: sourceNode.getPeerDescriptor(),
|
|
114
114
|
targetDescriptor: destinationNode.getPeerDescriptor()
|
|
115
115
|
}
|
|
116
|
-
|
|
116
|
+
sourceNode.router!.doRouteMessage({
|
|
117
117
|
message,
|
|
118
118
|
destinationPeer: destinationNode.getPeerDescriptor(),
|
|
119
119
|
requestId: v4(),
|
|
@@ -169,7 +169,7 @@ describe('Route Message With Mock Connections', () => {
|
|
|
169
169
|
sourceDescriptor: node.getPeerDescriptor(),
|
|
170
170
|
targetDescriptor: destinationNode.getPeerDescriptor()
|
|
171
171
|
}
|
|
172
|
-
|
|
172
|
+
node.router!.doRouteMessage({
|
|
173
173
|
message,
|
|
174
174
|
destinationPeer: receiver.getPeerDescriptor(),
|
|
175
175
|
sourcePeer: node.getPeerDescriptor(),
|
|
@@ -55,7 +55,7 @@ describe('Scaling down a Dht network', () => {
|
|
|
55
55
|
const nodeIsCleaned = nodes.every((node) =>
|
|
56
56
|
node.getAllConnectionPeerDescriptors().every((peer) => {
|
|
57
57
|
if (isSamePeerDescriptor(peer, stoppingPeerDescriptor)) {
|
|
58
|
-
logger.error(' ' + node.
|
|
58
|
+
logger.error(' ' + node.getPeerDescriptor().nodeName + ', ' + stoppingPeerDescriptor.nodeName + ' cleaning up failed')
|
|
59
59
|
}
|
|
60
60
|
return !isSamePeerDescriptor(peer, stoppingPeerDescriptor)
|
|
61
61
|
})
|
|
@@ -87,8 +87,9 @@ describe('SimultaneousConnections', () => {
|
|
|
87
87
|
nodeName: 'mock1WebSocket',
|
|
88
88
|
type: NodeType.NODEJS,
|
|
89
89
|
websocket: {
|
|
90
|
-
|
|
91
|
-
port: 43432
|
|
90
|
+
host: '127.0.0.1',
|
|
91
|
+
port: 43432,
|
|
92
|
+
tls: false
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
95
|
|
|
@@ -97,8 +98,9 @@ describe('SimultaneousConnections', () => {
|
|
|
97
98
|
nodeName: 'mock2WebSocket',
|
|
98
99
|
type: NodeType.NODEJS,
|
|
99
100
|
websocket: {
|
|
100
|
-
|
|
101
|
-
port: 43433
|
|
101
|
+
host: '127.0.0.1',
|
|
102
|
+
port: 43433,
|
|
103
|
+
tls: false
|
|
102
104
|
}
|
|
103
105
|
}
|
|
104
106
|
|
|
@@ -170,8 +172,9 @@ describe('SimultaneousConnections', () => {
|
|
|
170
172
|
nodeName: 'mock1WebSocketServer',
|
|
171
173
|
type: NodeType.NODEJS,
|
|
172
174
|
websocket: {
|
|
173
|
-
|
|
174
|
-
port: 43432
|
|
175
|
+
host: '127.0.0.1',
|
|
176
|
+
port: 43432,
|
|
177
|
+
tls: false
|
|
175
178
|
}
|
|
176
179
|
}
|
|
177
180
|
|