@streamr/dht 102.0.0-beta.1 → 102.0.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/generated/google/protobuf/any.d.ts +180 -0
- package/dist/generated/google/protobuf/any.js +155 -0
- package/dist/generated/google/protobuf/any.js.map +1 -0
- package/dist/generated/google/protobuf/empty.d.ts +31 -0
- package/dist/generated/google/protobuf/empty.js +32 -0
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/generated/google/protobuf/timestamp.d.ts +155 -0
- package/dist/generated/google/protobuf/timestamp.js +136 -0
- package/dist/generated/google/protobuf/timestamp.js.map +1 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.d.ts +361 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js +285 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/generated/packages/dht/protos/DhtRpc.d.ts +999 -0
- package/dist/generated/packages/dht/protos/DhtRpc.js +677 -0
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.d.ts +162 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js +3 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.d.ts +87 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js +66 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/package.json +7 -7
- package/package.json +7 -7
- package/src/connection/Connection.ts +0 -28
- package/src/connection/ConnectionLockRpcLocal.ts +0 -78
- package/src/connection/ConnectionLockRpcRemote.ts +0 -64
- package/src/connection/ConnectionLockStates.ts +0 -131
- package/src/connection/ConnectionManager.ts +0 -661
- package/src/connection/ConnectionsView.ts +0 -8
- package/src/connection/ConnectorFacade.ts +0 -217
- package/src/connection/Handshaker.ts +0 -209
- package/src/connection/IConnection.ts +0 -40
- package/src/connection/ManagedConnection.ts +0 -113
- package/src/connection/OutputBuffer.ts +0 -28
- package/src/connection/PendingConnection.ts +0 -68
- package/src/connection/connectivityChecker.ts +0 -108
- package/src/connection/connectivityRequestHandler.ts +0 -116
- package/src/connection/simulator/Simulator.ts +0 -369
- package/src/connection/simulator/SimulatorConnection.ts +0 -137
- package/src/connection/simulator/SimulatorConnector.ts +0 -98
- package/src/connection/simulator/SimulatorTransport.ts +0 -15
- package/src/connection/simulator/pings.ts +0 -42
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -242
- package/src/connection/webrtc/IWebrtcConnection.ts +0 -24
- package/src/connection/webrtc/NodeWebrtcConnection.ts +0 -245
- package/src/connection/webrtc/WebrtcConnector.ts +0 -234
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +0 -108
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +0 -60
- package/src/connection/webrtc/iceServerAsString.ts +0 -15
- package/src/connection/websocket/AbstractWebsocketClientConnection.ts +0 -122
- package/src/connection/websocket/AutoCertifierClientFacade.ts +0 -89
- package/src/connection/websocket/BrowserWebsocketClientConnection.ts +0 -44
- package/src/connection/websocket/NodeWebsocketClientConnection.ts +0 -39
- package/src/connection/websocket/WebsocketClientConnector.ts +0 -119
- package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +0 -38
- package/src/connection/websocket/WebsocketClientConnectorRpcRemote.ts +0 -19
- package/src/connection/websocket/WebsocketServer.ts +0 -164
- package/src/connection/websocket/WebsocketServerConnection.ts +0 -109
- package/src/connection/websocket/WebsocketServerConnector.ts +0 -290
- package/src/dht/DhtNode.ts +0 -683
- package/src/dht/DhtNodeRpcLocal.ts +0 -84
- package/src/dht/DhtNodeRpcRemote.ts +0 -107
- package/src/dht/ExternalApiRpcLocal.ts +0 -58
- package/src/dht/ExternalApiRpcRemote.ts +0 -41
- package/src/dht/PeerManager.ts +0 -305
- package/src/dht/contact/Contact.ts +0 -19
- package/src/dht/contact/ContactList.ts +0 -43
- package/src/dht/contact/RandomContactList.ts +0 -56
- package/src/dht/contact/RingContactList.ts +0 -143
- package/src/dht/contact/RpcRemote.ts +0 -72
- package/src/dht/contact/SortedContactList.ts +0 -173
- package/src/dht/contact/getClosestNodes.ts +0 -24
- package/src/dht/contact/ringIdentifiers.ts +0 -62
- package/src/dht/discovery/DiscoverySession.ts +0 -129
- package/src/dht/discovery/PeerDiscovery.ts +0 -244
- package/src/dht/discovery/RingDiscoverySession.ts +0 -148
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +0 -251
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +0 -34
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +0 -43
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +0 -231
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +0 -35
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcRemote.ts +0 -30
- package/src/dht/routing/DuplicateDetector.ts +0 -34
- package/src/dht/routing/Router.ts +0 -246
- package/src/dht/routing/RouterRpcLocal.ts +0 -78
- package/src/dht/routing/RouterRpcRemote.ts +0 -80
- package/src/dht/routing/RoutingSession.ts +0 -243
- package/src/dht/routing/RoutingTablesCache.ts +0 -60
- package/src/dht/routing/getPreviousPeer.ts +0 -6
- package/src/dht/store/LocalDataStore.ts +0 -84
- package/src/dht/store/StoreManager.ts +0 -170
- package/src/dht/store/StoreRpcLocal.ts +0 -89
- package/src/dht/store/StoreRpcRemote.ts +0 -32
- package/src/exports.ts +0 -33
- package/src/helpers/AddressTools.ts +0 -28
- package/src/helpers/Connectivity.ts +0 -19
- package/src/helpers/browser/isBrowserEnvironment.ts +0 -1
- package/src/helpers/browser/isBrowserEnvironment_override.ts +0 -3
- package/src/helpers/createPeerDescriptor.ts +0 -57
- package/src/helpers/createPeerDescriptorSignaturePayload.ts +0 -28
- package/src/helpers/debugHelpers.ts +0 -9
- package/src/helpers/errors.ts +0 -49
- package/src/helpers/offering.ts +0 -15
- package/src/helpers/protoClasses.ts +0 -57
- package/src/helpers/protoToString.ts +0 -21
- package/src/helpers/version.ts +0 -32
- package/src/identifiers.ts +0 -29
- package/src/rpc-protocol/DhtCallContext.ts +0 -14
- package/src/rpc-protocol/DhtRpcOptions.ts +0 -10
- package/src/transport/ITransport.ts +0 -37
- package/src/transport/ListeningRpcCommunicator.ts +0 -32
- package/src/transport/RoutingRpcCommunicator.ts +0 -66
- package/src/types/ServiceID.ts +0 -1
- package/src/types/textencoding.d.ts +0 -6
- package/test/benchmark/Find.test.ts +0 -72
- package/test/benchmark/KademliaCorrectness.test.ts +0 -114
- package/test/benchmark/RingCorrectness.test.ts +0 -157
- package/test/benchmark/SortedContactListBenchmark.test.ts +0 -108
- package/test/benchmark/WebsocketServerMemoryLeak.test.ts +0 -41
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +0 -71
- package/test/end-to-end/GeoIpLayer0.test.ts +0 -55
- package/test/end-to-end/Layer0-Layer1.test.ts +0 -93
- package/test/end-to-end/Layer0.test.ts +0 -76
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +0 -110
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +0 -137
- package/test/end-to-end/Layer0Webrtc.test.ts +0 -85
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +0 -82
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +0 -76
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +0 -52
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +0 -69
- package/test/end-to-end/memory-leak.test.ts +0 -80
- package/test/integration/ConnectionLocking.test.ts +0 -192
- package/test/integration/ConnectionManager.test.ts +0 -528
- package/test/integration/ConnectivityChecking.test.ts +0 -53
- package/test/integration/DhtJoinPeerDiscovery.test.ts +0 -49
- package/test/integration/DhtNode.test.ts +0 -66
- package/test/integration/DhtNodeExternalAPI.test.ts +0 -48
- package/test/integration/DhtNodeRpcRemote.test.ts +0 -66
- package/test/integration/DhtRpc.test.ts +0 -121
- package/test/integration/Find.test.ts +0 -45
- package/test/integration/GeoIpConnectivityChecking.test.ts +0 -72
- package/test/integration/Layer1-scale.test.ts +0 -189
- package/test/integration/Mock-Layer1-Layer0.test.ts +0 -85
- package/test/integration/MultipleEntryPointJoining.test.ts +0 -105
- package/test/integration/ReplicateData.test.ts +0 -104
- package/test/integration/RouteMessage.test.ts +0 -230
- package/test/integration/RouterRpcRemote.test.ts +0 -77
- package/test/integration/SimultaneousConnections.test.ts +0 -316
- package/test/integration/Store.test.ts +0 -85
- package/test/integration/StoreAndDelete.test.ts +0 -77
- package/test/integration/StoreOnDhtWithThreeNodes.test.ts +0 -59
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +0 -51
- package/test/integration/StoreRpcRemote.test.ts +0 -54
- package/test/integration/WebrtcConnectionManagement.test.ts +0 -191
- package/test/integration/WebrtcConnectorRpc.test.ts +0 -125
- package/test/integration/Websocket.test.ts +0 -65
- package/test/integration/WebsocketClientConnectorRpc.test.ts +0 -69
- package/test/integration/WebsocketConnectionManagement.test.ts +0 -191
- package/test/integration/rpc-connections-over-webrtc.test.ts +0 -123
- package/test/kademlia-simulation/data/nodeids.json +0 -13002
- package/test/kademlia-simulation/data/orderedneighbors.json +0 -1001
- package/test/types/global.d.ts +0 -1
- package/test/unit/AddressTools.test.ts +0 -44
- package/test/unit/AutoCertifierClientFacade.test.ts +0 -58
- package/test/unit/ConnectionManager.test.ts +0 -65
- package/test/unit/ConnectivityHelpers.test.ts +0 -61
- package/test/unit/DiscoverySession.test.ts +0 -87
- package/test/unit/DuplicateDetector.test.ts +0 -31
- package/test/unit/Handshaker.test.ts +0 -169
- package/test/unit/ListeningRpcCommunicator.test.ts +0 -52
- package/test/unit/LocalDataStore.test.ts +0 -108
- package/test/unit/ManagedConnection.test.ts +0 -58
- package/test/unit/PeerManager.test.ts +0 -93
- package/test/unit/PendingConnection.test.ts +0 -57
- package/test/unit/ProtobufMessage.test.ts +0 -21
- package/test/unit/RandomContactList.test.ts +0 -58
- package/test/unit/RecursiveOperationManager.test.ts +0 -161
- package/test/unit/RecursiveOperationSession.test.ts +0 -68
- package/test/unit/Router.test.ts +0 -137
- package/test/unit/RoutingSession.test.ts +0 -86
- package/test/unit/SortedContactList.test.ts +0 -115
- package/test/unit/StoreManager.test.ts +0 -146
- package/test/unit/StoreRpcLocal.test.ts +0 -167
- package/test/unit/WebrtcConnection.test.ts +0 -29
- package/test/unit/WebrtcConnector.test.ts +0 -56
- package/test/unit/WebsocketClientConnector.test.ts +0 -101
- package/test/unit/WebsocketServer.test.ts +0 -66
- package/test/unit/WebsocketServerConnector.test.ts +0 -102
- package/test/unit/connectivityRequestHandler.test.ts +0 -104
- package/test/unit/createPeerDescriptor.test.ts +0 -69
- package/test/unit/customMatchers.test.ts +0 -34
- package/test/unit/getClosestNodes.test.ts +0 -30
- package/test/unit/version.test.ts +0 -18
- package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +0 -18
- package/test/utils/FakeConnectorFacade.ts +0 -41
- package/test/utils/FakeRpcCommunicator.ts +0 -23
- package/test/utils/FakeTransport.ts +0 -79
- package/test/utils/customMatchers.ts +0 -71
- package/test/utils/mock/MockConnection.ts +0 -26
- package/test/utils/mock/MockConnectionsView.ts +0 -18
- package/test/utils/mock/MockRouter.ts +0 -62
- package/test/utils/mock/MockRpcCommunicator.ts +0 -7
- package/test/utils/mock/MockTransport.ts +0 -26
- package/test/utils/mock/mockDataEntry.ts +0 -38
- package/test/utils/topology.ts +0 -79
- package/test/utils/utils.ts +0 -268
- package/tsconfig.browser.json +0 -17
- package/tsconfig.jest.json +0 -25
- package/tsconfig.json +0 -3
- package/tsconfig.node.json +0 -24
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
3
|
-
|
|
4
|
-
const STREAM_ID = 'stream'
|
|
5
|
-
const NUM_OF_NODES = 16
|
|
6
|
-
const NUM_OF_NODES_PER_KBUCKET = 8
|
|
7
|
-
const WEBSOCKET_PORT_RANGE = { min: 62200, max: 62200 + NUM_OF_NODES }
|
|
8
|
-
|
|
9
|
-
describe('Layer1 Scale', () => {
|
|
10
|
-
|
|
11
|
-
const epPeerDescriptor = createMockPeerDescriptor({
|
|
12
|
-
websocket: { host: '127.0.0.1', port: 43225, tls: false }
|
|
13
|
-
})
|
|
14
|
-
let layer0Nodes: DhtNode[]
|
|
15
|
-
let layer1Nodes: DhtNode[]
|
|
16
|
-
let epLayer0Node: DhtNode
|
|
17
|
-
let epLayer1Node: DhtNode
|
|
18
|
-
|
|
19
|
-
beforeEach(async () => {
|
|
20
|
-
epLayer0Node = new DhtNode({
|
|
21
|
-
peerDescriptor: epPeerDescriptor,
|
|
22
|
-
websocketServerEnableTls: false
|
|
23
|
-
})
|
|
24
|
-
await epLayer0Node.start()
|
|
25
|
-
await epLayer0Node.joinDht([epPeerDescriptor])
|
|
26
|
-
|
|
27
|
-
epLayer1Node = new DhtNode({
|
|
28
|
-
transport: epLayer0Node,
|
|
29
|
-
connectionsView: epLayer0Node.getConnectionsView(),
|
|
30
|
-
peerDescriptor: epPeerDescriptor,
|
|
31
|
-
serviceId: STREAM_ID
|
|
32
|
-
})
|
|
33
|
-
await epLayer1Node.start()
|
|
34
|
-
await epLayer1Node.joinDht([epPeerDescriptor])
|
|
35
|
-
|
|
36
|
-
layer0Nodes = []
|
|
37
|
-
layer1Nodes = []
|
|
38
|
-
|
|
39
|
-
for (let i = 0; i < NUM_OF_NODES; i++) {
|
|
40
|
-
const node = new DhtNode({
|
|
41
|
-
websocketPortRange: WEBSOCKET_PORT_RANGE,
|
|
42
|
-
entryPoints: [epPeerDescriptor],
|
|
43
|
-
websocketServerEnableTls: false,
|
|
44
|
-
numberOfNodesPerKBucket: NUM_OF_NODES_PER_KBUCKET
|
|
45
|
-
})
|
|
46
|
-
await node.start()
|
|
47
|
-
layer0Nodes.push(node)
|
|
48
|
-
const layer1 = new DhtNode({
|
|
49
|
-
transport: node,
|
|
50
|
-
connectionsView: node.getConnectionsView(),
|
|
51
|
-
entryPoints: [epPeerDescriptor],
|
|
52
|
-
peerDescriptor: node.getLocalPeerDescriptor(),
|
|
53
|
-
serviceId: STREAM_ID,
|
|
54
|
-
numberOfNodesPerKBucket: NUM_OF_NODES_PER_KBUCKET
|
|
55
|
-
})
|
|
56
|
-
await layer1.start()
|
|
57
|
-
layer1Nodes.push(layer1)
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
await Promise.all(layer0Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
61
|
-
|
|
62
|
-
await Promise.all(layer1Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
63
|
-
|
|
64
|
-
}, 120000)
|
|
65
|
-
|
|
66
|
-
afterEach(async () => {
|
|
67
|
-
await Promise.all(layer1Nodes.map((node) => node.stop()))
|
|
68
|
-
await Promise.all(layer0Nodes.map((node) => node.stop()))
|
|
69
|
-
await epLayer0Node.stop()
|
|
70
|
-
await epLayer1Node.stop()
|
|
71
|
-
}, 15000)
|
|
72
|
-
|
|
73
|
-
// TODO: fix flaky test in NET-1021
|
|
74
|
-
it('bucket sizes', async () => {
|
|
75
|
-
layer0Nodes.forEach((node) => {
|
|
76
|
-
expect(node.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET - 1)
|
|
77
|
-
})
|
|
78
|
-
layer1Nodes.forEach((node ) => {
|
|
79
|
-
expect(node.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
80
|
-
})
|
|
81
|
-
})
|
|
82
|
-
})
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
3
|
-
|
|
4
|
-
const STREAM_ID = 'stream'
|
|
5
|
-
const NUM_OF_NODES = 16
|
|
6
|
-
const NUM_OF_NODES_PER_KBUCKET = 8
|
|
7
|
-
|
|
8
|
-
describe('Layer1 Scale', () => {
|
|
9
|
-
|
|
10
|
-
const epPeerDescriptor = createMockPeerDescriptor({
|
|
11
|
-
websocket: { host: '127.0.0.1', port: 43228, tls: false }
|
|
12
|
-
})
|
|
13
|
-
let layer0Nodes: DhtNode[]
|
|
14
|
-
let layer1Nodes: DhtNode[]
|
|
15
|
-
let epLayer0Node: DhtNode
|
|
16
|
-
let epLayer1Node: DhtNode
|
|
17
|
-
|
|
18
|
-
beforeEach(async () => {
|
|
19
|
-
epLayer0Node = new DhtNode({
|
|
20
|
-
peerDescriptor: epPeerDescriptor,
|
|
21
|
-
websocketServerEnableTls: false
|
|
22
|
-
})
|
|
23
|
-
await epLayer0Node.start()
|
|
24
|
-
await epLayer0Node.joinDht([epPeerDescriptor])
|
|
25
|
-
|
|
26
|
-
epLayer1Node = new DhtNode({
|
|
27
|
-
transport: epLayer0Node,
|
|
28
|
-
connectionsView: epLayer0Node.getConnectionsView(),
|
|
29
|
-
peerDescriptor: epPeerDescriptor,
|
|
30
|
-
serviceId: STREAM_ID
|
|
31
|
-
})
|
|
32
|
-
await epLayer1Node.start()
|
|
33
|
-
await epLayer1Node.joinDht([epPeerDescriptor])
|
|
34
|
-
|
|
35
|
-
layer0Nodes = []
|
|
36
|
-
layer1Nodes = []
|
|
37
|
-
|
|
38
|
-
for (let i = 1; i < NUM_OF_NODES; i++) {
|
|
39
|
-
const node = new DhtNode({
|
|
40
|
-
entryPoints: [epPeerDescriptor],
|
|
41
|
-
numberOfNodesPerKBucket: NUM_OF_NODES_PER_KBUCKET
|
|
42
|
-
})
|
|
43
|
-
await node.start()
|
|
44
|
-
layer0Nodes.push(node)
|
|
45
|
-
const layer1 = new DhtNode({
|
|
46
|
-
transport: node,
|
|
47
|
-
connectionsView: node.getConnectionsView(),
|
|
48
|
-
entryPoints: [epPeerDescriptor],
|
|
49
|
-
peerDescriptor: node.getLocalPeerDescriptor(),
|
|
50
|
-
serviceId: STREAM_ID,
|
|
51
|
-
rpcRequestTimeout: 5000,
|
|
52
|
-
numberOfNodesPerKBucket: NUM_OF_NODES_PER_KBUCKET
|
|
53
|
-
})
|
|
54
|
-
await layer1.start()
|
|
55
|
-
layer1Nodes.push(layer1)
|
|
56
|
-
}
|
|
57
|
-
await Promise.all(layer0Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
58
|
-
await Promise.all(layer1Nodes.map((node) => node.joinDht([epPeerDescriptor])))
|
|
59
|
-
}, 120000)
|
|
60
|
-
|
|
61
|
-
afterEach(async () => {
|
|
62
|
-
await Promise.all(layer1Nodes.map((node) => node.stop()))
|
|
63
|
-
await Promise.all(layer0Nodes.map((node) => node.stop()))
|
|
64
|
-
await epLayer0Node.stop()
|
|
65
|
-
await epLayer1Node.stop()
|
|
66
|
-
}, 15000)
|
|
67
|
-
|
|
68
|
-
it('bucket sizes', async () => {
|
|
69
|
-
layer0Nodes.forEach((node) => {
|
|
70
|
-
expect(node.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET - 1)
|
|
71
|
-
})
|
|
72
|
-
layer1Nodes.forEach((node) => {
|
|
73
|
-
expect(node.getNeighborCount()).toBeGreaterThanOrEqual(NUM_OF_NODES_PER_KBUCKET / 2)
|
|
74
|
-
})
|
|
75
|
-
})
|
|
76
|
-
})
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
3
|
-
import os from 'os'
|
|
4
|
-
|
|
5
|
-
describe('Failed autocertification', () => {
|
|
6
|
-
|
|
7
|
-
let entryPoint: DhtNode
|
|
8
|
-
let failedAutocertificationNode: DhtNode
|
|
9
|
-
let node: DhtNode
|
|
10
|
-
let entryPointPeerDescriptor: PeerDescriptor
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
entryPoint = new DhtNode({ websocketHost: '127.0.0.1', websocketPortRange: { min: 11112, max: 11112 }, websocketServerEnableTls: false })
|
|
14
|
-
await entryPoint.start()
|
|
15
|
-
entryPointPeerDescriptor = entryPoint.getLocalPeerDescriptor()
|
|
16
|
-
await entryPoint.joinDht([entryPointPeerDescriptor])
|
|
17
|
-
|
|
18
|
-
failedAutocertificationNode = new DhtNode({
|
|
19
|
-
websocketPortRange: { min: 11113, max: 11113 },
|
|
20
|
-
websocketHost: '127.0.0.1',
|
|
21
|
-
entryPoints: [entryPointPeerDescriptor],
|
|
22
|
-
websocketServerEnableTls: true,
|
|
23
|
-
autoCertifierConfigFile: os.tmpdir() + '/failedAutoCertificationConfigFile.json',
|
|
24
|
-
autoCertifierUrl: 'http://127.0.0.1:44444'
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
node = new DhtNode({
|
|
28
|
-
websocketPortRange: { min: 11114, max: 11114 },
|
|
29
|
-
websocketHost: '127.0.0.1',
|
|
30
|
-
entryPoints: [entryPointPeerDescriptor],
|
|
31
|
-
websocketServerEnableTls: false
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
await node.start()
|
|
35
|
-
await node.joinDht([entryPointPeerDescriptor])
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
afterEach(async () => {
|
|
39
|
-
await failedAutocertificationNode.stop()
|
|
40
|
-
await entryPoint.stop()
|
|
41
|
-
await node.stop()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('failed auto certification should default to no tls', async () => {
|
|
45
|
-
await failedAutocertificationNode.start()
|
|
46
|
-
const failedAutocertificationPeerDescriptor = failedAutocertificationNode.getLocalPeerDescriptor()
|
|
47
|
-
expect(failedAutocertificationPeerDescriptor.websocket!.tls).toBe(false)
|
|
48
|
-
await failedAutocertificationNode.joinDht([entryPointPeerDescriptor])
|
|
49
|
-
expect(failedAutocertificationNode.getNeighborCount()).toEqual(2)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
})
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
2
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
4
|
-
import { until } from '@streamr/utils'
|
|
5
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
6
|
-
import { areEqualPeerDescriptors } from '../../src/identifiers'
|
|
7
|
-
|
|
8
|
-
describe('Websocket IConnection Requests', () => {
|
|
9
|
-
|
|
10
|
-
const epPeerDescriptor = createMockPeerDescriptor({
|
|
11
|
-
websocket: { host: '127.0.0.1', port: 10021, tls: false }
|
|
12
|
-
})
|
|
13
|
-
let epDhtNode: DhtNode
|
|
14
|
-
let node1: DhtNode
|
|
15
|
-
let node2: DhtNode
|
|
16
|
-
|
|
17
|
-
beforeEach(async () => {
|
|
18
|
-
|
|
19
|
-
epDhtNode = new DhtNode({ peerDescriptor: epPeerDescriptor, websocketServerEnableTls: false })
|
|
20
|
-
await epDhtNode.start()
|
|
21
|
-
|
|
22
|
-
await epDhtNode.joinDht([epPeerDescriptor])
|
|
23
|
-
|
|
24
|
-
node1 = new DhtNode({
|
|
25
|
-
websocketPortRange: { min: 10022, max: 10022 },
|
|
26
|
-
entryPoints: [epPeerDescriptor],
|
|
27
|
-
websocketServerEnableTls: false
|
|
28
|
-
})
|
|
29
|
-
node2 = new DhtNode({
|
|
30
|
-
entryPoints: [epPeerDescriptor],
|
|
31
|
-
websocketServerEnableTls: false
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
await node1.start()
|
|
35
|
-
await node2.start()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
afterEach(async () => {
|
|
39
|
-
await epDhtNode.stop()
|
|
40
|
-
await node1.stop()
|
|
41
|
-
await node2.stop()
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('Happy Path', async () => {
|
|
45
|
-
|
|
46
|
-
let connected1 = false
|
|
47
|
-
let connected2 = false
|
|
48
|
-
|
|
49
|
-
node1.on('connected', (peerDescriptor: PeerDescriptor) => {
|
|
50
|
-
if (areEqualPeerDescriptors(peerDescriptor, node2.getLocalPeerDescriptor())) {
|
|
51
|
-
connected1 = true
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
node2.on('connected', (peerDescriptor: PeerDescriptor) => {
|
|
55
|
-
if (areEqualPeerDescriptors(peerDescriptor, node1.getLocalPeerDescriptor())) {
|
|
56
|
-
connected2 = true
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
await node2.joinDht([epPeerDescriptor])
|
|
61
|
-
await node1.joinDht([epPeerDescriptor])
|
|
62
|
-
|
|
63
|
-
await until(() => { return (connected1 && connected2) })
|
|
64
|
-
|
|
65
|
-
expect((node1.getTransport() as ConnectionManager).hasConnection(node2.getNodeId())).toEqual(true)
|
|
66
|
-
expect((node2.getTransport() as ConnectionManager).hasConnection(node1.getNodeId())).toEqual(true)
|
|
67
|
-
|
|
68
|
-
}, 10000)
|
|
69
|
-
})
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
import LeakDetector from 'jest-leak-detector'
|
|
2
|
-
import { until } from '@streamr/utils'
|
|
3
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
4
|
-
import { Message } from '../../generated/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { RpcMessage } from '../../generated/packages/proto-rpc/protos/ProtoRpc'
|
|
6
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
|
-
import { toNodeId } from '../../src/identifiers'
|
|
8
|
-
|
|
9
|
-
const MESSAGE_ID = 'mock-message-id'
|
|
10
|
-
|
|
11
|
-
describe('memory leak', () => {
|
|
12
|
-
|
|
13
|
-
it('send message', async () => {
|
|
14
|
-
const entryPointDescriptor = createMockPeerDescriptor({
|
|
15
|
-
websocket: {
|
|
16
|
-
host: '127.0.0.1',
|
|
17
|
-
port: 11224,
|
|
18
|
-
tls: false
|
|
19
|
-
}
|
|
20
|
-
})
|
|
21
|
-
let entryPoint: DhtNode | undefined = new DhtNode({
|
|
22
|
-
nodeId: toNodeId(entryPointDescriptor),
|
|
23
|
-
websocketHost: entryPointDescriptor.websocket!.host,
|
|
24
|
-
websocketPortRange: {
|
|
25
|
-
min: entryPointDescriptor.websocket!.port,
|
|
26
|
-
max: entryPointDescriptor.websocket!.port
|
|
27
|
-
},
|
|
28
|
-
entryPoints: [entryPointDescriptor],
|
|
29
|
-
websocketServerEnableTls: false
|
|
30
|
-
})
|
|
31
|
-
await entryPoint.start()
|
|
32
|
-
await entryPoint.joinDht([entryPointDescriptor])
|
|
33
|
-
let sender: DhtNode | undefined = new DhtNode({ entryPoints: [entryPointDescriptor] })
|
|
34
|
-
let receiver: DhtNode | undefined = new DhtNode({ entryPoints: [entryPointDescriptor] })
|
|
35
|
-
await Promise.all([
|
|
36
|
-
(async () => {
|
|
37
|
-
await sender.start()
|
|
38
|
-
await sender.joinDht([entryPointDescriptor])
|
|
39
|
-
})(),
|
|
40
|
-
(async () => {
|
|
41
|
-
await receiver.start()
|
|
42
|
-
await receiver.joinDht([entryPointDescriptor])
|
|
43
|
-
})()
|
|
44
|
-
])
|
|
45
|
-
|
|
46
|
-
let receivedMessage: Message | undefined = undefined
|
|
47
|
-
receiver.on('message', (msg: Message) => receivedMessage = msg)
|
|
48
|
-
const msg: Message = {
|
|
49
|
-
serviceId: 'mock-service-id',
|
|
50
|
-
targetDescriptor: receiver.getLocalPeerDescriptor(),
|
|
51
|
-
messageId: 'mock-message-id',
|
|
52
|
-
body: {
|
|
53
|
-
oneofKind: 'rpcMessage',
|
|
54
|
-
rpcMessage: RpcMessage.create()
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
await sender.send(msg)
|
|
58
|
-
await until(() => receivedMessage !== undefined)
|
|
59
|
-
expect(receivedMessage!.messageId).toEqual(MESSAGE_ID)
|
|
60
|
-
|
|
61
|
-
await Promise.all([
|
|
62
|
-
entryPoint.stop(),
|
|
63
|
-
sender.stop(),
|
|
64
|
-
receiver.stop()
|
|
65
|
-
])
|
|
66
|
-
|
|
67
|
-
const detector1 = new LeakDetector(entryPoint)
|
|
68
|
-
entryPoint = undefined
|
|
69
|
-
await detector1.isLeaking()
|
|
70
|
-
expect(await detector1.isLeaking()).toBe(false)
|
|
71
|
-
|
|
72
|
-
const detector2 = new LeakDetector(sender)
|
|
73
|
-
sender = undefined
|
|
74
|
-
expect(await detector2.isLeaking()).toBe(false)
|
|
75
|
-
|
|
76
|
-
const detector3 = new LeakDetector(receiver)
|
|
77
|
-
receiver = undefined
|
|
78
|
-
expect(await detector3.isLeaking()).toBe(false)
|
|
79
|
-
}, 10000)
|
|
80
|
-
})
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { MetricsContext, until } from '@streamr/utils'
|
|
2
|
-
import { ConnectionManager } from '../../src/connection/ConnectionManager'
|
|
3
|
-
import { DefaultConnectorFacade } from '../../src/connection/ConnectorFacade'
|
|
4
|
-
import { LatencyType, Simulator } from '../../src/connection/simulator/Simulator'
|
|
5
|
-
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
6
|
-
import { ITransport } from '../../src/transport/ITransport'
|
|
7
|
-
import { PeerDescriptor } from '../../generated/packages/dht/protos/DhtRpc'
|
|
8
|
-
import { getRandomRegion } from '../../dist/src/connection/simulator/pings'
|
|
9
|
-
import { createMockPeerDescriptor } from '../utils/utils'
|
|
10
|
-
import { toNodeId } from '../../src/identifiers'
|
|
11
|
-
|
|
12
|
-
const createConnectionManager = (localPeerDescriptor: PeerDescriptor, transport: ITransport) => {
|
|
13
|
-
return new ConnectionManager({
|
|
14
|
-
createConnectorFacade: () => new DefaultConnectorFacade({
|
|
15
|
-
transport,
|
|
16
|
-
createLocalPeerDescriptor: async () => localPeerDescriptor
|
|
17
|
-
}),
|
|
18
|
-
metricsContext: new MetricsContext(),
|
|
19
|
-
allowIncomingPrivateConnections: true
|
|
20
|
-
})
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
describe('Connection Locking', () => {
|
|
24
|
-
|
|
25
|
-
const mockPeerDescriptor1 = createMockPeerDescriptor({
|
|
26
|
-
region: getRandomRegion()
|
|
27
|
-
})
|
|
28
|
-
const mockPeerDescriptor2 = createMockPeerDescriptor({
|
|
29
|
-
region: getRandomRegion()
|
|
30
|
-
})
|
|
31
|
-
let mockConnectorTransport1: ConnectionManager
|
|
32
|
-
let mockConnectorTransport2: ConnectionManager
|
|
33
|
-
let connectionManager1: ConnectionManager
|
|
34
|
-
let connectionManager2: ConnectionManager
|
|
35
|
-
let simulator: Simulator
|
|
36
|
-
|
|
37
|
-
beforeEach(async () => {
|
|
38
|
-
simulator = new Simulator(LatencyType.REAL)
|
|
39
|
-
mockConnectorTransport1 = new SimulatorTransport(mockPeerDescriptor1, simulator)
|
|
40
|
-
await mockConnectorTransport1.start()
|
|
41
|
-
mockConnectorTransport2 = new SimulatorTransport(mockPeerDescriptor2, simulator)
|
|
42
|
-
await mockConnectorTransport2.start()
|
|
43
|
-
connectionManager1 = createConnectionManager(mockPeerDescriptor1, mockConnectorTransport1)
|
|
44
|
-
connectionManager2 = createConnectionManager(mockPeerDescriptor2, mockConnectorTransport2)
|
|
45
|
-
await connectionManager1.start()
|
|
46
|
-
await connectionManager2.start()
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
afterEach(async () => {
|
|
50
|
-
await Promise.all([
|
|
51
|
-
mockConnectorTransport1.stop(),
|
|
52
|
-
mockConnectorTransport2.stop(),
|
|
53
|
-
connectionManager1.stop(),
|
|
54
|
-
connectionManager2.stop()
|
|
55
|
-
])
|
|
56
|
-
simulator.stop()
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('can lock connections', async () => {
|
|
60
|
-
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
61
|
-
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
62
|
-
await Promise.all([
|
|
63
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
65
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
66
|
-
])
|
|
67
|
-
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
68
|
-
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
69
|
-
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
70
|
-
})
|
|
71
|
-
|
|
72
|
-
it('Multiple services on the same peer', async () => {
|
|
73
|
-
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
74
|
-
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
75
|
-
await Promise.all([
|
|
76
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
77
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
78
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
79
|
-
])
|
|
80
|
-
await Promise.all([
|
|
81
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
82
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
83
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
84
|
-
])
|
|
85
|
-
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
86
|
-
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
87
|
-
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
88
|
-
})
|
|
89
|
-
|
|
90
|
-
it('can unlock connections', async () => {
|
|
91
|
-
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
92
|
-
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
93
|
-
await Promise.all([
|
|
94
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
95
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
96
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock')
|
|
97
|
-
])
|
|
98
|
-
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
99
|
-
expect(connectionManager2.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
100
|
-
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
101
|
-
|
|
102
|
-
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock')
|
|
103
|
-
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
104
|
-
await until(() => connectionManager2.hasRemoteLockedConnection(nodeId1) === false)
|
|
105
|
-
expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
|
|
106
|
-
})
|
|
107
|
-
|
|
108
|
-
it('unlocking multiple services', async () => {
|
|
109
|
-
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
110
|
-
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
111
|
-
await Promise.all([
|
|
112
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
113
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
114
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1')
|
|
115
|
-
])
|
|
116
|
-
await Promise.all([
|
|
117
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
118
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
119
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock2')
|
|
120
|
-
])
|
|
121
|
-
|
|
122
|
-
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
123
|
-
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(false)
|
|
124
|
-
|
|
125
|
-
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
126
|
-
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
127
|
-
|
|
128
|
-
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock2')
|
|
129
|
-
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(false)
|
|
130
|
-
expect(connectionManager1.hasConnection(nodeId1)).toEqual(false)
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('maintains connection if both sides initially lock and then one end unlocks', async () => {
|
|
134
|
-
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
135
|
-
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
136
|
-
await Promise.all([
|
|
137
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
138
|
-
until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
|
|
139
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
140
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
141
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
142
|
-
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
143
|
-
])
|
|
144
|
-
|
|
145
|
-
expect(connectionManager1.hasLocalLockedConnection(nodeId2)).toEqual(true)
|
|
146
|
-
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
|
|
147
|
-
|
|
148
|
-
connectionManager1.unlockConnection(mockPeerDescriptor2, 'testLock1')
|
|
149
|
-
await until(() =>
|
|
150
|
-
connectionManager1.hasRemoteLockedConnection(nodeId2)
|
|
151
|
-
&& !connectionManager1.hasLocalLockedConnection(nodeId2)
|
|
152
|
-
&& !connectionManager2.hasRemoteLockedConnection(nodeId1)
|
|
153
|
-
&& connectionManager2.hasLocalLockedConnection(nodeId1)
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
expect(connectionManager2.hasConnection(nodeId1)).toEqual(true)
|
|
157
|
-
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
158
|
-
})
|
|
159
|
-
|
|
160
|
-
it('unlocks after graceful disconnect', async () => {
|
|
161
|
-
const nodeId1 = toNodeId(mockPeerDescriptor1)
|
|
162
|
-
const nodeId2 = toNodeId(mockPeerDescriptor2)
|
|
163
|
-
await Promise.all([
|
|
164
|
-
until(() => connectionManager2.hasRemoteLockedConnection(nodeId1)),
|
|
165
|
-
until(() => connectionManager1.hasRemoteLockedConnection(nodeId2)),
|
|
166
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
167
|
-
connectionManager1.lockConnection(mockPeerDescriptor2, 'testLock1'),
|
|
168
|
-
// eslint-disable-next-line @typescript-eslint/no-confusing-void-expression
|
|
169
|
-
connectionManager2.lockConnection(mockPeerDescriptor1, 'testLock1')
|
|
170
|
-
])
|
|
171
|
-
expect(connectionManager1.hasConnection(nodeId2)).toEqual(true)
|
|
172
|
-
expect(connectionManager2.hasLocalLockedConnection(nodeId1)).toEqual(true)
|
|
173
|
-
expect(connectionManager2.hasRemoteLockedConnection(nodeId1)).toEqual(true)
|
|
174
|
-
|
|
175
|
-
//@ts-expect-error private field
|
|
176
|
-
await connectionManager1.gracefullyDisconnectAsync(mockPeerDescriptor2)
|
|
177
|
-
|
|
178
|
-
await until(() =>
|
|
179
|
-
!connectionManager1.hasRemoteLockedConnection(nodeId2)
|
|
180
|
-
&& !connectionManager1.hasLocalLockedConnection(nodeId2)
|
|
181
|
-
)
|
|
182
|
-
await until(() =>
|
|
183
|
-
!connectionManager2.hasRemoteLockedConnection(nodeId1)
|
|
184
|
-
&& !connectionManager2.hasLocalLockedConnection(nodeId1)
|
|
185
|
-
)
|
|
186
|
-
await until(() => !connectionManager2.hasConnection(nodeId1))
|
|
187
|
-
await until(() => !connectionManager1.hasConnection(nodeId2))
|
|
188
|
-
|
|
189
|
-
expect(connectionManager1.hasConnection(nodeId2)).toEqual(false)
|
|
190
|
-
expect(connectionManager2.hasConnection(nodeId1)).toEqual(false)
|
|
191
|
-
}, 10000)
|
|
192
|
-
})
|