@streamr/dht 100.0.0-pretestnet.6 → 100.0.0-testnet-one.0
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/ConnectionLockHandler.js +2 -2
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +2 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js +2 -2
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.js +4 -1
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/ManagedConnection.js +1 -0
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/connectivityChecker.d.ts +9 -0
- package/dist/src/connection/connectivityChecker.js +121 -0
- package/dist/src/connection/connectivityChecker.js.map +1 -0
- package/dist/src/connection/connectivityRequestHandler.d.ts +2 -0
- package/dist/src/connection/connectivityRequestHandler.js +79 -0
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -0
- package/dist/src/connection/simulator/Simulator.js +3 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcRemote.js.map +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js +1 -1
- package/dist/src/connection/webrtc/iceServerAsString.js.map +1 -1
- package/dist/src/connection/websocket/ClientWebsocket.js +1 -0
- package/dist/src/connection/websocket/ClientWebsocket.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.d.ts +0 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +41 -7
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +2 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js +2 -2
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -19
- package/dist/src/dht/DhtNode.js +76 -216
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +3 -3
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +3 -3
- package/dist/src/dht/DhtNodeRpcRemote.js +4 -4
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +4 -4
- package/dist/src/dht/ExternalApiRpcLocal.js +5 -12
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcRemote.js +5 -5
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +48 -0
- package/dist/src/dht/PeerManager.js +208 -0
- package/dist/src/dht/PeerManager.js.map +1 -0
- package/dist/src/dht/contact/ContactList.d.ts +1 -1
- package/dist/src/dht/contact/ContactList.js +1 -0
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/{Remote.d.ts → RpcRemote.d.ts} +3 -3
- package/dist/src/dht/contact/{Remote.js → RpcRemote.js} +8 -8
- package/dist/src/dht/contact/RpcRemote.js.map +1 -0
- package/dist/src/dht/discovery/DiscoverySession.d.ts +2 -9
- package/dist/src/dht/discovery/DiscoverySession.js +12 -26
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -9
- package/dist/src/dht/discovery/PeerDiscovery.js +13 -15
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/FindRpcLocal.js +2 -1
- package/dist/src/dht/find/FindRpcLocal.js.map +1 -1
- package/dist/src/dht/find/FindSession.d.ts +6 -6
- package/dist/src/dht/find/FindSession.js +13 -13
- package/dist/src/dht/find/FindSession.js.map +1 -1
- package/dist/src/dht/find/FindSessionRpcLocal.d.ts +1 -1
- package/dist/src/dht/find/FindSessionRpcRemote.d.ts +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js +2 -2
- package/dist/src/dht/find/FindSessionRpcRemote.js.map +1 -1
- package/dist/src/dht/find/Finder.d.ts +4 -4
- package/dist/src/dht/find/Finder.js +50 -42
- package/dist/src/dht/find/Finder.js.map +1 -1
- package/dist/src/dht/routing/FindRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/FindRpcRemote.js +7 -5
- package/dist/src/dht/routing/FindRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -6
- package/dist/src/dht/routing/Router.js +21 -18
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcLocal.js +4 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.d.ts +2 -2
- package/dist/src/dht/routing/RouterRpcRemote.js +13 -8
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +1 -1
- package/dist/src/dht/routing/RoutingSession.js +16 -11
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/getPreviousPeer.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +3 -3
- package/dist/src/dht/store/LocalDataStore.js +18 -17
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +10 -9
- package/dist/src/dht/store/StoreRpcLocal.js +91 -99
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/dht/store/StoreRpcRemote.d.ts +4 -5
- package/dist/src/dht/store/StoreRpcRemote.js +6 -15
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -1
- package/dist/src/exports.d.ts +1 -1
- package/dist/src/exports.js +4 -4
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.js +2 -2
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/UUID.js +1 -1
- package/dist/src/helpers/UUID.js.map +1 -1
- package/dist/src/helpers/nodeId.d.ts +1 -0
- package/dist/src/helpers/{kademliaId.js → nodeId.js} +4 -4
- package/dist/src/helpers/nodeId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +5 -16
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +2 -9
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +80 -95
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +67 -66
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +3 -10
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/karma.config.js +2 -2
- package/package.json +5 -5
- package/protos/DhtRpc.proto +36 -36
- package/src/connection/ConnectionLockHandler.ts +2 -2
- package/src/connection/ConnectionLockRpcRemote.ts +2 -2
- package/src/connection/ConnectionManager.ts +4 -1
- package/src/connection/ConnectorFacade.ts +5 -4
- package/src/connection/ManagedConnection.ts +1 -0
- package/src/connection/connectivityChecker.ts +101 -0
- package/src/connection/connectivityRequestHandler.ts +79 -0
- package/src/connection/simulator/Simulator.ts +3 -2
- package/src/connection/simulator/SimulatorConnection.ts +1 -1
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +10 -10
- package/src/connection/webrtc/NodeWebrtcConnection.ts +1 -1
- package/src/connection/webrtc/WebrtcConnector.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +1 -1
- package/src/connection/webrtc/WebrtcConnectorRpcRemote.ts +2 -2
- package/src/connection/webrtc/iceServerAsString.ts +1 -1
- package/src/connection/websocket/ClientWebsocket.ts +1 -0
- package/src/connection/websocket/WebsocketConnector.ts +22 -12
- package/src/connection/websocket/WebsocketConnectorRpcRemote.ts +2 -2
- package/src/dht/DhtNode.ts +102 -269
- package/src/dht/DhtNodeRpcLocal.ts +3 -3
- package/src/dht/DhtNodeRpcRemote.ts +4 -4
- package/src/dht/ExternalApiRpcLocal.ts +8 -13
- package/src/dht/ExternalApiRpcRemote.ts +5 -5
- package/src/dht/PeerManager.ts +256 -0
- package/src/dht/contact/ContactList.ts +3 -2
- package/src/dht/contact/{Remote.ts → RpcRemote.ts} +7 -6
- package/src/dht/discovery/DiscoverySession.ts +15 -40
- package/src/dht/discovery/PeerDiscovery.ts +18 -23
- package/src/dht/find/FindRpcLocal.ts +2 -2
- package/src/dht/find/FindSession.ts +20 -20
- package/src/dht/find/FindSessionRpcLocal.ts +1 -1
- package/src/dht/find/FindSessionRpcRemote.ts +2 -2
- package/src/dht/find/Finder.ts +79 -58
- package/src/dht/routing/FindRpcRemote.ts +7 -5
- package/src/dht/routing/Router.ts +22 -21
- package/src/dht/routing/RouterRpcLocal.ts +5 -5
- package/src/dht/routing/RouterRpcRemote.ts +13 -10
- package/src/dht/routing/RoutingSession.ts +15 -10
- package/src/dht/routing/getPreviousPeer.ts +1 -1
- package/src/dht/store/LocalDataStore.ts +18 -17
- package/src/dht/store/StoreRpcLocal.ts +101 -108
- package/src/dht/store/StoreRpcRemote.ts +7 -23
- package/src/exports.ts +1 -1
- package/src/helpers/PeerID.ts +2 -2
- package/src/helpers/UUID.ts +1 -1
- package/src/helpers/{kademliaId.ts → nodeId.ts} +1 -1
- package/src/helpers/peerIdFromPeerDescriptor.ts +3 -3
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +6 -20
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -10
- package/src/proto/packages/dht/protos/DhtRpc.ts +103 -135
- package/src/transport/RoutingRpcCommunicator.ts +2 -0
- package/test/benchmark/Find.test.ts +4 -4
- package/test/benchmark/KademliaCorrectness.test.ts +2 -2
- package/test/benchmark/kademlia-simulation/Contact.ts +1 -1
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +1 -1
- package/test/end-to-end/Layer0-Layer1.test.ts +1 -1
- package/test/end-to-end/Layer0MixedConnectionTypes.test.ts +1 -1
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
- package/test/end-to-end/Layer0Webrtc.test.ts +2 -2
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +1 -1
- package/test/end-to-end/Layer1-Scale-Webrtc.test.ts +1 -1
- package/test/end-to-end/WebsocketConnectionRequest.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +8 -12
- package/test/integration/ConnectionLocking.test.ts +2 -2
- package/test/integration/ConnectionManager.test.ts +14 -14
- package/test/integration/DhtJoinPeerDiscovery.test.ts +1 -1
- package/test/integration/DhtNodeExternalAPI.test.ts +10 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +4 -4
- package/test/integration/DhtRpc.test.ts +6 -6
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +2 -2
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -1
- package/test/integration/{MigrateData.test.ts → ReplicateData.test.ts} +9 -9
- package/test/integration/RouteMessage.test.ts +2 -2
- package/test/integration/RouterRpcRemote.test.ts +2 -2
- package/test/integration/RpcErrors.test.ts +2 -2
- package/test/integration/ScaleDownDht.test.ts +4 -2
- package/test/integration/SimultaneousConnections.test.ts +8 -8
- package/test/integration/Store.test.ts +33 -13
- package/test/integration/StoreAndDelete.test.ts +19 -17
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +20 -20
- package/test/integration/StoreRpcRemote.test.ts +3 -3
- package/test/integration/WebrtcConnectionManagement.test.ts +2 -2
- package/test/integration/WebrtcConnectorRpc.test.ts +1 -1
- package/test/integration/WebsocketConnectionManagement.test.ts +2 -2
- package/test/integration/WebsocketConnectorRpc.test.ts +2 -2
- package/test/unit/ConnectivityHelpers.test.ts +4 -4
- package/test/unit/Finder.test.ts +69 -23
- package/test/unit/LocalDataStore.test.ts +60 -43
- package/test/unit/RandomContactList.test.ts +2 -2
- package/test/unit/Router.test.ts +19 -11
- package/test/unit/RoutingSession.test.ts +76 -0
- package/test/unit/SortedContactList.test.ts +2 -2
- package/test/unit/WebsocketConnector.test.ts +1 -1
- package/test/unit/connectivityRequestHandler.test.ts +71 -0
- package/test/utils/mock/Router.ts +1 -1
- package/test/utils/utils.ts +24 -22
- package/dist/src/connection/ConnectivityChecker.d.ts +0 -17
- package/dist/src/connection/ConnectivityChecker.js +0 -208
- package/dist/src/connection/ConnectivityChecker.js.map +0 -1
- package/dist/src/dht/contact/Remote.js.map +0 -1
- package/dist/src/helpers/kademliaId.d.ts +0 -1
- package/dist/src/helpers/kademliaId.js.map +0 -1
- package/src/connection/ConnectivityChecker.ts +0 -199
package/test/unit/Router.test.ts
CHANGED
|
@@ -2,7 +2,15 @@ import { v4 } from 'uuid'
|
|
|
2
2
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
3
3
|
import { Router } from '../../src/dht/routing/Router'
|
|
4
4
|
import { PeerID, PeerIDKey } from '../../src/helpers/PeerID'
|
|
5
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
Message,
|
|
7
|
+
MessageType,
|
|
8
|
+
NodeType,
|
|
9
|
+
PeerDescriptor,
|
|
10
|
+
RouteMessageAck,
|
|
11
|
+
RouteMessageError,
|
|
12
|
+
RouteMessageWrapper
|
|
13
|
+
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
6
14
|
import { createWrappedClosestPeersRequest } from '../utils/utils'
|
|
7
15
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
8
16
|
|
|
@@ -11,11 +19,11 @@ describe('Router', () => {
|
|
|
11
19
|
|
|
12
20
|
const peerId = PeerID.fromString('router')
|
|
13
21
|
const peerDescriptor1: PeerDescriptor = {
|
|
14
|
-
|
|
22
|
+
nodeId: peerId.value,
|
|
15
23
|
type: NodeType.NODEJS
|
|
16
24
|
}
|
|
17
25
|
const peerDescriptor2: PeerDescriptor = {
|
|
18
|
-
|
|
26
|
+
nodeId: PeerID.fromString('destination').value,
|
|
19
27
|
type: NodeType.NODEJS
|
|
20
28
|
}
|
|
21
29
|
const rpcWrapper = createWrappedClosestPeersRequest(peerDescriptor1)
|
|
@@ -69,7 +77,7 @@ describe('Router', () => {
|
|
|
69
77
|
reachableThrough: [],
|
|
70
78
|
routingPath: []
|
|
71
79
|
}) as RouteMessageAck
|
|
72
|
-
expect(ack.error).toEqual(
|
|
80
|
+
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
73
81
|
})
|
|
74
82
|
|
|
75
83
|
it('doRouteMessage with connections', async () => {
|
|
@@ -82,40 +90,40 @@ describe('Router', () => {
|
|
|
82
90
|
reachableThrough: [],
|
|
83
91
|
routingPath: []
|
|
84
92
|
}) as RouteMessageAck
|
|
85
|
-
expect(ack.error).
|
|
93
|
+
expect(ack.error).toBeUndefined()
|
|
86
94
|
})
|
|
87
95
|
|
|
88
96
|
it('route server is destination without connections', async () => {
|
|
89
97
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
90
|
-
expect(ack.error).
|
|
98
|
+
expect(ack.error).toBeUndefined()
|
|
91
99
|
})
|
|
92
100
|
|
|
93
101
|
it('route server with connections', async () => {
|
|
94
102
|
connections.set(PeerID.fromString('test').toKey(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
95
103
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
96
|
-
expect(ack.error).
|
|
104
|
+
expect(ack.error).toBeUndefined()
|
|
97
105
|
})
|
|
98
106
|
|
|
99
107
|
it('route server on duplicate message', async () => {
|
|
100
108
|
router.addToDuplicateDetector(routedMessage.requestId)
|
|
101
109
|
const ack = await rpcCommunicator.callRpcMethod('routeMessage', routedMessage) as RouteMessageAck
|
|
102
|
-
expect(ack.error).toEqual(
|
|
110
|
+
expect(ack.error).toEqual(RouteMessageError.DUPLICATE)
|
|
103
111
|
})
|
|
104
112
|
|
|
105
113
|
it('forward server no connections', async () => {
|
|
106
114
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
107
|
-
expect(ack.error).toEqual(
|
|
115
|
+
expect(ack.error).toEqual(RouteMessageError.NO_TARGETS)
|
|
108
116
|
})
|
|
109
117
|
|
|
110
118
|
it('forward server with connections', async () => {
|
|
111
119
|
connections.set(PeerID.fromString('test').toKey(), createMockDhtNodeRpcRemote(peerDescriptor2))
|
|
112
120
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
113
|
-
expect(ack.error).
|
|
121
|
+
expect(ack.error).toBeUndefined()
|
|
114
122
|
})
|
|
115
123
|
|
|
116
124
|
it('forward server on duplicate message', async () => {
|
|
117
125
|
router.addToDuplicateDetector(routedMessage.requestId)
|
|
118
126
|
const ack = await rpcCommunicator.callRpcMethod('forwardMessage', routedMessage) as RouteMessageAck
|
|
119
|
-
expect(ack.error).toEqual(
|
|
127
|
+
expect(ack.error).toEqual(RouteMessageError.DUPLICATE)
|
|
120
128
|
})
|
|
121
129
|
})
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { v4 } from 'uuid'
|
|
2
|
+
import { RoutingSession } from '../../src/dht/routing/RoutingSession'
|
|
3
|
+
import { Message, MessageType, NodeType, PeerDescriptor, RouteMessageWrapper } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
+
import { createWrappedClosestPeersRequest } from '../utils/utils'
|
|
5
|
+
import { hexToBinary } from '@streamr/utils'
|
|
6
|
+
import { PeerIDKey } from '../../src/helpers/PeerID'
|
|
7
|
+
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
8
|
+
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
9
|
+
import { keyFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
10
|
+
|
|
11
|
+
describe('RoutingSession', () => {
|
|
12
|
+
|
|
13
|
+
let session: RoutingSession
|
|
14
|
+
let connections: Map<PeerIDKey, DhtNodeRpcRemote>
|
|
15
|
+
let rpcCommunicator: RoutingRpcCommunicator
|
|
16
|
+
|
|
17
|
+
const mockPeerDescriptor1: PeerDescriptor = {
|
|
18
|
+
nodeId: hexToBinary('eee1'),
|
|
19
|
+
type: NodeType.NODEJS
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const mockPeerDescriptor2 = {
|
|
23
|
+
nodeId: hexToBinary('eee2'),
|
|
24
|
+
type: NodeType.NODEJS
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const rpcWrapper = createWrappedClosestPeersRequest(mockPeerDescriptor1)
|
|
28
|
+
const message: Message = {
|
|
29
|
+
serviceId: 'unknown',
|
|
30
|
+
messageId: v4(),
|
|
31
|
+
messageType: MessageType.RPC,
|
|
32
|
+
body: {
|
|
33
|
+
oneofKind: 'rpcMessage',
|
|
34
|
+
rpcMessage: rpcWrapper
|
|
35
|
+
},
|
|
36
|
+
sourceDescriptor: mockPeerDescriptor1,
|
|
37
|
+
targetDescriptor: mockPeerDescriptor2
|
|
38
|
+
}
|
|
39
|
+
const routedMessage: RouteMessageWrapper = {
|
|
40
|
+
message,
|
|
41
|
+
requestId: 'REQ',
|
|
42
|
+
routingPath: [],
|
|
43
|
+
reachableThrough: [],
|
|
44
|
+
destinationPeer: mockPeerDescriptor1,
|
|
45
|
+
sourcePeer: mockPeerDescriptor2
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
49
|
+
return new DhtNodeRpcRemote(mockPeerDescriptor1, destination, {} as any, 'router')
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
beforeEach(() => {
|
|
53
|
+
rpcCommunicator = new RoutingRpcCommunicator('mock', async () => {})
|
|
54
|
+
connections = new Map()
|
|
55
|
+
session = new RoutingSession(rpcCommunicator, mockPeerDescriptor1, routedMessage, connections, 2)
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
afterEach(() => {
|
|
59
|
+
rpcCommunicator.stop()
|
|
60
|
+
session.stop()
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('findMoreContacts', () => {
|
|
64
|
+
connections.set(keyFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
65
|
+
const contacts = session.updateAndGetRoutablePeers()
|
|
66
|
+
expect(contacts.length).toBe(1)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it('findMoreContacts peer disconnects', () => {
|
|
70
|
+
connections.set(keyFromPeerDescriptor(mockPeerDescriptor2), createMockDhtNodeRpcRemote(mockPeerDescriptor2))
|
|
71
|
+
expect(session.updateAndGetRoutablePeers().length).toBe(1)
|
|
72
|
+
connections.delete(keyFromPeerDescriptor(mockPeerDescriptor2))
|
|
73
|
+
expect(session.updateAndGetRoutablePeers().length).toBe(0)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
})
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
2
2
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
3
|
|
|
4
|
-
const createItem = (
|
|
5
|
-
return { getPeerId: () => PeerID.fromValue(
|
|
4
|
+
const createItem = (nodeId: Uint8Array): { getPeerId: () => PeerID } => {
|
|
5
|
+
return { getPeerId: () => PeerID.fromValue(nodeId) }
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
describe('SortedContactList', () => {
|
|
@@ -6,7 +6,7 @@ import { MockTransport } from '../utils/mock/Transport'
|
|
|
6
6
|
|
|
7
7
|
const createMockPeerDescriptor = (nodeType: NodeType, websocket?: ConnectivityMethod): PeerDescriptor => {
|
|
8
8
|
return {
|
|
9
|
-
|
|
9
|
+
nodeId: crypto.randomBytes(10),
|
|
10
10
|
type: nodeType,
|
|
11
11
|
websocket
|
|
12
12
|
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { waitForCondition } from '@streamr/utils'
|
|
2
|
+
import { EventEmitter } from 'eventemitter3'
|
|
3
|
+
import { once } from 'events'
|
|
4
|
+
import { Server as HttpServer, createServer as createHttpServer } from 'http'
|
|
5
|
+
import { server as WsServer } from 'websocket'
|
|
6
|
+
import { CONNECTIVITY_CHECKER_SERVICE_ID } from '../../src/connection/connectivityChecker'
|
|
7
|
+
import { attachConnectivityRequestHandler } from '../../src/connection/connectivityRequestHandler'
|
|
8
|
+
import { Message, MessageType } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
|
+
|
|
10
|
+
const HOST = '127.0.0.1'
|
|
11
|
+
const PORT = 15001
|
|
12
|
+
|
|
13
|
+
describe('connectivityRequestHandler', () => {
|
|
14
|
+
|
|
15
|
+
let httpServer: HttpServer
|
|
16
|
+
let wsServer: WsServer
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
httpServer = createHttpServer()
|
|
20
|
+
wsServer = new WsServer({
|
|
21
|
+
httpServer,
|
|
22
|
+
autoAcceptConnections: true
|
|
23
|
+
})
|
|
24
|
+
httpServer.listen(PORT)
|
|
25
|
+
await once(httpServer, 'listening')
|
|
26
|
+
})
|
|
27
|
+
|
|
28
|
+
afterAll(async () => {
|
|
29
|
+
wsServer.shutDown()
|
|
30
|
+
httpServer.close()
|
|
31
|
+
await once(httpServer, 'close')
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('happy path', async () => {
|
|
35
|
+
const connection: any = new EventEmitter()
|
|
36
|
+
connection.send = jest.fn()
|
|
37
|
+
|
|
38
|
+
attachConnectivityRequestHandler(connection as any)
|
|
39
|
+
const request: Message = {
|
|
40
|
+
serviceId: CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
41
|
+
messageType: MessageType.CONNECTIVITY_REQUEST,
|
|
42
|
+
messageId: 'mock-message-id',
|
|
43
|
+
body: {
|
|
44
|
+
oneofKind: 'connectivityRequest',
|
|
45
|
+
connectivityRequest: { port: PORT, host: HOST, tls: false, selfSigned: false }
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
connection.emit('data', Message.toBinary(request))
|
|
49
|
+
|
|
50
|
+
await waitForCondition(() => connection.send.mock.calls.length > 0)
|
|
51
|
+
|
|
52
|
+
const receivedMessage = Message.fromBinary(connection.send.mock.calls[0][0])
|
|
53
|
+
expect(receivedMessage).toEqual({
|
|
54
|
+
body: {
|
|
55
|
+
connectivityResponse: {
|
|
56
|
+
host: HOST,
|
|
57
|
+
natType: 'open_internet',
|
|
58
|
+
websocket: {
|
|
59
|
+
host: HOST,
|
|
60
|
+
port: PORT,
|
|
61
|
+
tls: false
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
oneofKind: 'connectivityResponse'
|
|
65
|
+
},
|
|
66
|
+
messageId: expect.any(String),
|
|
67
|
+
messageType: MessageType.CONNECTIVITY_RESPONSE,
|
|
68
|
+
serviceId: 'system/connectivity-checker'
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -30,7 +30,7 @@ export class MockRouter implements IRouter {
|
|
|
30
30
|
|
|
31
31
|
// eslint-disable-next-line class-methods-use-this
|
|
32
32
|
send(): Promise<void> {
|
|
33
|
-
throw Error('Not implemented')
|
|
33
|
+
throw new Error('Not implemented')
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
// eslint-disable-next-line class-methods-use-this
|
package/test/utils/utils.ts
CHANGED
|
@@ -2,7 +2,6 @@ import { DhtNode } from '../../src/dht/DhtNode'
|
|
|
2
2
|
import {
|
|
3
3
|
ClosestPeersRequest,
|
|
4
4
|
ClosestPeersResponse,
|
|
5
|
-
MigrateDataResponse,
|
|
6
5
|
NodeType,
|
|
7
6
|
PeerDescriptor,
|
|
8
7
|
PingRequest,
|
|
@@ -13,7 +12,7 @@ import {
|
|
|
13
12
|
StoreDataResponse,
|
|
14
13
|
WebsocketConnectionResponse,
|
|
15
14
|
FindRequest,
|
|
16
|
-
|
|
15
|
+
FindAction
|
|
17
16
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
18
17
|
import { RpcMessage } from '../../src/proto/packages/proto-rpc/protos/ProtoRpc'
|
|
19
18
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
@@ -31,11 +30,19 @@ import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
|
31
30
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
32
31
|
import { wait, waitForCondition } from '@streamr/utils'
|
|
33
32
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
33
|
+
import { createRandomNodeId } from '../../src/helpers/nodeId'
|
|
34
34
|
|
|
35
35
|
export const generateId = (stringId: string): Uint8Array => {
|
|
36
36
|
return PeerID.fromString(stringId).value
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
export const createMockPeerDescriptor = (): PeerDescriptor => {
|
|
40
|
+
return {
|
|
41
|
+
nodeId: createRandomNodeId(),
|
|
42
|
+
type: NodeType.NODEJS,
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
39
46
|
export const createMockConnectionDhtNode = async (
|
|
40
47
|
stringId: string,
|
|
41
48
|
simulator: Simulator,
|
|
@@ -51,7 +58,7 @@ export const createMockConnectionDhtNode = async (
|
|
|
51
58
|
id = PeerID.fromString(stringId)
|
|
52
59
|
}
|
|
53
60
|
const peerDescriptor: PeerDescriptor = {
|
|
54
|
-
|
|
61
|
+
nodeId: id.value,
|
|
55
62
|
type: NodeType.NODEJS,
|
|
56
63
|
region: getRandomRegion()
|
|
57
64
|
}
|
|
@@ -83,7 +90,7 @@ export const createMockConnectionLayer1Node = async (
|
|
|
83
90
|
): Promise<DhtNode> => {
|
|
84
91
|
const id = PeerID.fromString(stringId)
|
|
85
92
|
const descriptor: PeerDescriptor = {
|
|
86
|
-
|
|
93
|
+
nodeId: id.value,
|
|
87
94
|
type: NodeType.NODEJS,
|
|
88
95
|
}
|
|
89
96
|
const node = new DhtNode({
|
|
@@ -100,7 +107,7 @@ export const createWrappedClosestPeersRequest = (
|
|
|
100
107
|
): RpcMessage => {
|
|
101
108
|
|
|
102
109
|
const routedMessage: ClosestPeersRequest = {
|
|
103
|
-
|
|
110
|
+
nodeId: sourceDescriptor.nodeId,
|
|
104
111
|
requestId: v4()
|
|
105
112
|
}
|
|
106
113
|
const rpcWrapper: RpcMessage = {
|
|
@@ -115,10 +122,10 @@ export const createWrappedClosestPeersRequest = (
|
|
|
115
122
|
}
|
|
116
123
|
|
|
117
124
|
export const createFindRequest = (
|
|
118
|
-
|
|
125
|
+
action: FindAction
|
|
119
126
|
): FindRequest => {
|
|
120
127
|
const request: FindRequest = {
|
|
121
|
-
|
|
128
|
+
action,
|
|
122
129
|
sessionId: v4()
|
|
123
130
|
}
|
|
124
131
|
return request
|
|
@@ -170,15 +177,13 @@ interface IRouterRpcWithError extends IRouterRpc {
|
|
|
170
177
|
export const mockRouterRpc: IRouterRpcWithError = {
|
|
171
178
|
async routeMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
172
179
|
const response: RouteMessageAck = {
|
|
173
|
-
requestId: routed.requestId
|
|
174
|
-
error: ''
|
|
180
|
+
requestId: routed.requestId
|
|
175
181
|
}
|
|
176
182
|
return response
|
|
177
183
|
},
|
|
178
184
|
async forwardMessage(routed: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
179
185
|
const response: RouteMessageAck = {
|
|
180
|
-
requestId: routed.requestId
|
|
181
|
-
error: ''
|
|
186
|
+
requestId: routed.requestId
|
|
182
187
|
}
|
|
183
188
|
return response
|
|
184
189
|
},
|
|
@@ -206,11 +211,8 @@ export const mockStoreRpc: IStoreRpcWithError = {
|
|
|
206
211
|
error: 'Mock'
|
|
207
212
|
}
|
|
208
213
|
},
|
|
209
|
-
async
|
|
210
|
-
return
|
|
211
|
-
},
|
|
212
|
-
async deleteData(): Promise<DeleteDataResponse> {
|
|
213
|
-
return DeleteDataResponse.create()
|
|
214
|
+
async replicateData(): Promise<Empty> {
|
|
215
|
+
return {}
|
|
214
216
|
}
|
|
215
217
|
}
|
|
216
218
|
|
|
@@ -225,19 +227,19 @@ export const mockWebsocketConnectorRpc: IWebsocketConnectorRpc = {
|
|
|
225
227
|
|
|
226
228
|
export const getMockPeers = (): PeerDescriptor[] => {
|
|
227
229
|
const n1: PeerDescriptor = {
|
|
228
|
-
|
|
230
|
+
nodeId: generateId('Neighbor1'),
|
|
229
231
|
type: NodeType.NODEJS,
|
|
230
232
|
}
|
|
231
233
|
const n2: PeerDescriptor = {
|
|
232
|
-
|
|
234
|
+
nodeId: generateId('Neighbor2'),
|
|
233
235
|
type: NodeType.NODEJS,
|
|
234
236
|
}
|
|
235
237
|
const n3: PeerDescriptor = {
|
|
236
|
-
|
|
238
|
+
nodeId: generateId('Neighbor3'),
|
|
237
239
|
type: NodeType.NODEJS,
|
|
238
240
|
}
|
|
239
241
|
const n4: PeerDescriptor = {
|
|
240
|
-
|
|
242
|
+
nodeId: generateId('Neighbor4'),
|
|
241
243
|
type: NodeType.NODEJS,
|
|
242
244
|
}
|
|
243
245
|
return [
|
|
@@ -278,9 +280,9 @@ async function waitReadyForTesting(connectionManager: ConnectionManager, limit:
|
|
|
278
280
|
} catch (err) {
|
|
279
281
|
if (connectionManager.getNumberOfLocalLockedConnections() > 0
|
|
280
282
|
&& connectionManager.getNumberOfRemoteLockedConnections() > 0) {
|
|
281
|
-
throw Error('Connections are still locked')
|
|
283
|
+
throw new Error('Connections are still locked')
|
|
282
284
|
} else if (connectionManager.getAllConnectionPeerDescriptors().length > limit) {
|
|
283
|
-
throw Error(`ConnectionManager has more than ${limit}`)
|
|
285
|
+
throw new Error(`ConnectionManager has more than ${limit}`)
|
|
284
286
|
}
|
|
285
287
|
}
|
|
286
288
|
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { ConnectivityResponse, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
2
|
-
import { ServerWebsocket } from './websocket/ServerWebsocket';
|
|
3
|
-
export declare class ConnectivityChecker {
|
|
4
|
-
private static readonly CONNECTIVITY_CHECKER_SERVICE_ID;
|
|
5
|
-
private static readonly CONNECTIVITY_CHECKER_TIMEOUT;
|
|
6
|
-
private destroyed;
|
|
7
|
-
private readonly websocketPort;
|
|
8
|
-
private readonly tls;
|
|
9
|
-
private host?;
|
|
10
|
-
constructor(websocketPort: number, tls: boolean, host?: string);
|
|
11
|
-
sendConnectivityRequest(entryPoint: PeerDescriptor, selfSigned: boolean): Promise<ConnectivityResponse>;
|
|
12
|
-
setHost(hostName: string): void;
|
|
13
|
-
listenToIncomingConnectivityRequests(connectionToListenTo: ServerWebsocket): void;
|
|
14
|
-
private handleIncomingConnectivityRequest;
|
|
15
|
-
private connectAsync;
|
|
16
|
-
destroy(): void;
|
|
17
|
-
}
|
|
@@ -1,208 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.ConnectivityChecker = void 0;
|
|
27
|
-
const DhtRpc_1 = require("../proto/packages/dht/protos/DhtRpc");
|
|
28
|
-
const utils_1 = require("@streamr/utils");
|
|
29
|
-
const Err = __importStar(require("../helpers/errors"));
|
|
30
|
-
const ClientWebsocket_1 = require("./websocket/ClientWebsocket");
|
|
31
|
-
const uuid_1 = require("uuid");
|
|
32
|
-
const ConnectionManager_1 = require("./ConnectionManager");
|
|
33
|
-
const WebsocketConnector_1 = require("./websocket/WebsocketConnector");
|
|
34
|
-
const logger = new utils_1.Logger(module);
|
|
35
|
-
// Class for handling both client and server side of the connectivity
|
|
36
|
-
// checks. This is attached to all ServerWebsockets to listen to
|
|
37
|
-
// ConnectivityRequest messages.
|
|
38
|
-
class ConnectivityChecker {
|
|
39
|
-
constructor(websocketPort, tls, host) {
|
|
40
|
-
this.destroyed = false;
|
|
41
|
-
this.websocketPort = websocketPort;
|
|
42
|
-
this.tls = tls;
|
|
43
|
-
this.host = host;
|
|
44
|
-
}
|
|
45
|
-
async sendConnectivityRequest(entryPoint, selfSigned) {
|
|
46
|
-
if (this.destroyed) {
|
|
47
|
-
throw new Err.ConnectionFailed('ConnectivityChecker is destroyed');
|
|
48
|
-
}
|
|
49
|
-
let outgoingConnection;
|
|
50
|
-
const wsServerInfo = {
|
|
51
|
-
host: entryPoint.websocket.host,
|
|
52
|
-
port: entryPoint.websocket.port,
|
|
53
|
-
tls: entryPoint.websocket.tls,
|
|
54
|
-
};
|
|
55
|
-
const url = (0, WebsocketConnector_1.connectivityMethodToWebsocketUrl)(wsServerInfo, 'connectivityRequest');
|
|
56
|
-
try {
|
|
57
|
-
outgoingConnection = await this.connectAsync({
|
|
58
|
-
url,
|
|
59
|
-
selfSigned
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
catch (e) {
|
|
63
|
-
throw new Err.ConnectionFailed(`Failed to connect to the entrypoint ${url}`, e);
|
|
64
|
-
}
|
|
65
|
-
// send connectivity request
|
|
66
|
-
const connectivityRequestMessage = { port: this.websocketPort, host: this.host, tls: this.tls, selfSigned };
|
|
67
|
-
const msg = {
|
|
68
|
-
serviceId: ConnectivityChecker.CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
69
|
-
messageType: DhtRpc_1.MessageType.CONNECTIVITY_REQUEST, messageId: (0, uuid_1.v4)(),
|
|
70
|
-
body: {
|
|
71
|
-
oneofKind: 'connectivityRequest',
|
|
72
|
-
connectivityRequest: connectivityRequestMessage
|
|
73
|
-
}
|
|
74
|
-
};
|
|
75
|
-
const responseAwaiter = () => {
|
|
76
|
-
return new Promise((resolve, reject) => {
|
|
77
|
-
const timeoutId = setTimeout(() => {
|
|
78
|
-
outgoingConnection.close(false);
|
|
79
|
-
reject(new Err.ConnectivityResponseTimeout('timeout'));
|
|
80
|
-
}, ConnectivityChecker.CONNECTIVITY_CHECKER_TIMEOUT);
|
|
81
|
-
const listener = (bytes) => {
|
|
82
|
-
outgoingConnection.close(false);
|
|
83
|
-
try {
|
|
84
|
-
const message = DhtRpc_1.Message.fromBinary(bytes);
|
|
85
|
-
if (message.body.oneofKind === 'connectivityResponse') {
|
|
86
|
-
logger.trace('ConnectivityResponse received: ' + JSON.stringify(DhtRpc_1.Message.toJson(message)));
|
|
87
|
-
const connectivityResponseMessage = message.body.connectivityResponse;
|
|
88
|
-
outgoingConnection.off('data', listener);
|
|
89
|
-
clearTimeout(timeoutId);
|
|
90
|
-
resolve(connectivityResponseMessage);
|
|
91
|
-
}
|
|
92
|
-
else {
|
|
93
|
-
return;
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
catch (err) {
|
|
97
|
-
logger.trace(`Could not parse message: ${err}`);
|
|
98
|
-
}
|
|
99
|
-
};
|
|
100
|
-
outgoingConnection.on('data', listener);
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
try {
|
|
104
|
-
const retPromise = responseAwaiter();
|
|
105
|
-
outgoingConnection.send(DhtRpc_1.Message.toBinary(msg));
|
|
106
|
-
logger.trace('ConnectivityRequest sent: ' + JSON.stringify(DhtRpc_1.Message.toJson(msg)));
|
|
107
|
-
return await retPromise;
|
|
108
|
-
}
|
|
109
|
-
catch (e) {
|
|
110
|
-
logger.error('error getting connectivityresponse');
|
|
111
|
-
throw e;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
setHost(hostName) {
|
|
115
|
-
this.host = hostName;
|
|
116
|
-
}
|
|
117
|
-
listenToIncomingConnectivityRequests(connectionToListenTo) {
|
|
118
|
-
connectionToListenTo.on('data', (data) => {
|
|
119
|
-
logger.trace('server received data');
|
|
120
|
-
try {
|
|
121
|
-
const message = DhtRpc_1.Message.fromBinary(data);
|
|
122
|
-
if (message.body.oneofKind === 'connectivityRequest') {
|
|
123
|
-
logger.trace('ConnectivityRequest received: ' + JSON.stringify(DhtRpc_1.Message.toJson(message)));
|
|
124
|
-
this.handleIncomingConnectivityRequest(connectionToListenTo, message.body.connectivityRequest).then(() => {
|
|
125
|
-
logger.trace('handleIncomingConnectivityRequest ok');
|
|
126
|
-
return;
|
|
127
|
-
}).catch((e) => {
|
|
128
|
-
logger.error('handleIncomingConnectivityRequest' + e);
|
|
129
|
-
});
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
catch (err) {
|
|
133
|
-
logger.trace(`Could not parse message: ${err}`);
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
async handleIncomingConnectivityRequest(connection, connectivityRequest) {
|
|
138
|
-
if (this.destroyed) {
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
let outgoingConnection;
|
|
142
|
-
let connectivityResponseMessage;
|
|
143
|
-
const host = connectivityRequest.host ?? connection.getRemoteAddress();
|
|
144
|
-
try {
|
|
145
|
-
const wsServerInfo = {
|
|
146
|
-
host,
|
|
147
|
-
port: connectivityRequest.port,
|
|
148
|
-
tls: connectivityRequest.tls
|
|
149
|
-
};
|
|
150
|
-
const url = (0, WebsocketConnector_1.connectivityMethodToWebsocketUrl)(wsServerInfo, 'connectivityProbe');
|
|
151
|
-
logger.trace(`Attempting Connectivity Check to ${url}`);
|
|
152
|
-
outgoingConnection = await this.connectAsync({
|
|
153
|
-
url,
|
|
154
|
-
selfSigned: connectivityRequest.selfSigned
|
|
155
|
-
});
|
|
156
|
-
}
|
|
157
|
-
catch (err) {
|
|
158
|
-
logger.debug('error', { err });
|
|
159
|
-
connectivityResponseMessage = {
|
|
160
|
-
host,
|
|
161
|
-
natType: ConnectionManager_1.NatType.UNKNOWN
|
|
162
|
-
};
|
|
163
|
-
}
|
|
164
|
-
if (outgoingConnection) {
|
|
165
|
-
outgoingConnection.close(false);
|
|
166
|
-
logger.trace('Connectivity test produced positive result, communicating reply to the requester ' + host + ':' + connectivityRequest.port);
|
|
167
|
-
connectivityResponseMessage = {
|
|
168
|
-
host,
|
|
169
|
-
natType: ConnectionManager_1.NatType.OPEN_INTERNET,
|
|
170
|
-
websocket: { host, port: connectivityRequest.port, tls: connectivityRequest.tls }
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
const msg = {
|
|
174
|
-
serviceId: ConnectivityChecker.CONNECTIVITY_CHECKER_SERVICE_ID,
|
|
175
|
-
messageType: DhtRpc_1.MessageType.CONNECTIVITY_RESPONSE, messageId: (0, uuid_1.v4)(),
|
|
176
|
-
body: {
|
|
177
|
-
oneofKind: 'connectivityResponse',
|
|
178
|
-
connectivityResponse: connectivityResponseMessage
|
|
179
|
-
}
|
|
180
|
-
};
|
|
181
|
-
connection.send(DhtRpc_1.Message.toBinary(msg));
|
|
182
|
-
logger.trace('ConnectivityResponse sent: ' + JSON.stringify(DhtRpc_1.Message.toJson(msg)));
|
|
183
|
-
}
|
|
184
|
-
// eslint-disable-next-line class-methods-use-this
|
|
185
|
-
async connectAsync({ url, selfSigned, timeoutMs = 1000, }) {
|
|
186
|
-
const socket = new ClientWebsocket_1.ClientWebsocket();
|
|
187
|
-
let result;
|
|
188
|
-
try {
|
|
189
|
-
result = await (0, utils_1.runAndRaceEvents3)([
|
|
190
|
-
() => { socket.connect(url, selfSigned); }
|
|
191
|
-
], socket, ['connected', 'error'], timeoutMs);
|
|
192
|
-
}
|
|
193
|
-
catch (e) {
|
|
194
|
-
throw (new Err.ConnectionFailed('WebSocket connection timed out'));
|
|
195
|
-
}
|
|
196
|
-
if (result.winnerName === 'error') {
|
|
197
|
-
throw (new Err.ConnectionFailed('Could not open WebSocket connection'));
|
|
198
|
-
}
|
|
199
|
-
return socket;
|
|
200
|
-
}
|
|
201
|
-
destroy() {
|
|
202
|
-
this.destroyed = true;
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
exports.ConnectivityChecker = ConnectivityChecker;
|
|
206
|
-
ConnectivityChecker.CONNECTIVITY_CHECKER_SERVICE_ID = 'system/connectivity-checker';
|
|
207
|
-
ConnectivityChecker.CONNECTIVITY_CHECKER_TIMEOUT = 5000;
|
|
208
|
-
//# sourceMappingURL=ConnectivityChecker.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ConnectivityChecker.js","sourceRoot":"","sources":["../../../src/connection/ConnectivityChecker.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,gEAG4C;AAE5C,0CAAsF;AACtF,uDAAwC;AACxC,iEAA6D;AAC7D,+BAAyB;AACzB,2DAA6C;AAE7C,uEAAiF;AAEjF,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,qEAAqE;AACrE,gEAAgE;AAChE,iCAAiC;AAEjC,MAAa,mBAAmB;IAS5B,YAAY,aAAqB,EAAE,GAAY,EAAE,IAAa;QALtD,cAAS,GAAG,KAAK,CAAA;QAMrB,IAAI,CAAC,aAAa,GAAG,aAAa,CAAA;QAClC,IAAI,CAAC,GAAG,GAAG,GAAG,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,CAAC;IAEM,KAAK,CAAC,uBAAuB,CAAC,UAA0B,EAAE,UAAmB;QAChF,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,MAAM,IAAI,GAAG,CAAC,gBAAgB,CAAC,kCAAkC,CAAC,CAAA;SACrE;QACD,IAAI,kBAA+B,CAAA;QACnC,MAAM,YAAY,GAAG;YACjB,IAAI,EAAE,UAAU,CAAC,SAAU,CAAC,IAAI;YAChC,IAAI,EAAE,UAAU,CAAC,SAAU,CAAC,IAAI;YAChC,GAAG,EAAE,UAAU,CAAC,SAAU,CAAC,GAAG;SACjC,CAAA;QACD,MAAM,GAAG,GAAG,IAAA,qDAAgC,EAAC,YAAY,EAAE,qBAAqB,CAAC,CAAA;QACjF,IAAI;YACA,kBAAkB,G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1
|
-
export declare const createRandomKademliaId: () => Uint8Array;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kademliaId.js","sourceRoot":"","sources":["../../../src/helpers/kademliaId.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA2B;AAE3B,wDAAwD;AACxD,MAAM,2BAA2B,GAAG,EAAE,CAAA;AAE/B,MAAM,sBAAsB,GAAG,GAAe,EAAE;IACnD,OAAO,gBAAM,CAAC,WAAW,CAAC,2BAA2B,CAAC,CAAA;AAC1D,CAAC,CAAA;AAFY,QAAA,sBAAsB,0BAElC"}
|