@streamr/dht 0.0.1-tatum.6 → 0.0.1-tatum.8
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.d.ts +1 -1
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +10 -0
- package/dist/src/connection/{RemoteConnectionLocker.js → ConnectionLockRpcRemote.js} +21 -35
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +17 -41
- package/dist/src/connection/ConnectionManager.js +148 -212
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.js +16 -13
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +49 -0
- package/dist/src/connection/ConnectorFacade.js +83 -0
- package/dist/src/connection/ConnectorFacade.js.map +1 -0
- package/dist/src/connection/Handshaker.d.ts +1 -2
- package/dist/src/connection/Handshaker.js +1 -4
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -6
- package/dist/src/connection/ManagedConnection.js +27 -36
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.js +2 -2
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -1
- package/dist/src/connection/Simulator/Simulator.d.ts +0 -2
- package/dist/src/connection/Simulator/Simulator.js +0 -5
- package/dist/src/connection/Simulator/Simulator.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnection.js +16 -13
- package/dist/src/connection/Simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +2 -3
- package/dist/src/connection/Simulator/SimulatorConnector.js +12 -14
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js +6 -1
- package/dist/src/connection/Simulator/SimulatorTransport.js.map +1 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +3 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js +12 -12
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.js.map +1 -1
- package/dist/src/connection/WebRTC/{WebRtcConnector.d.ts → WebRtcConnectorRpcLocal.d.ts} +13 -13
- package/dist/src/connection/WebRTC/{WebRtcConnector.js → WebRtcConnectorRpcLocal.js} +46 -38
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.d.ts +11 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js +55 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +1 -1
- package/dist/src/connection/WebSocket/{WebSocketConnector.d.ts → WebSocketConnectorRpcLocal.d.ts} +21 -11
- package/dist/src/connection/WebSocket/{WebSocketConnector.js → WebSocketConnectorRpcLocal.js} +80 -59
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.d.ts +8 -0
- package/dist/src/connection/WebSocket/{RemoteWebSocketConnector.js → WebSocketConnectorRpcRemote.js} +12 -16
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketServer.d.ts +11 -1
- package/dist/src/connection/WebSocket/WebSocketServer.js +15 -10
- package/dist/src/connection/WebSocket/WebSocketServer.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +18 -55
- package/dist/src/dht/DhtNode.js +122 -145
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/{RemoteExternalApi.d.ts → ExternalApiRpcRemote.d.ts} +2 -2
- package/dist/src/dht/{RemoteExternalApi.js → ExternalApiRpcRemote.js} +5 -6
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -0
- package/dist/src/dht/{DhtPeer.d.ts → RemoteDhtNode.d.ts} +2 -3
- package/dist/src/dht/{DhtPeer.js → RemoteDhtNode.js} +21 -19
- package/dist/src/dht/RemoteDhtNode.js.map +1 -0
- package/dist/src/dht/contact/ContactList.d.ts +0 -1
- package/dist/src/dht/contact/ContactList.js +0 -3
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +0 -1
- package/dist/src/dht/contact/RandomContactList.js +0 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +0 -3
- package/dist/src/dht/contact/SortedContactList.js +0 -9
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +5 -7
- package/dist/src/dht/discovery/DiscoverySession.js +9 -10
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +12 -11
- package/dist/src/dht/discovery/PeerDiscovery.js +33 -37
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/RecursiveFindSession.d.ts +9 -10
- package/dist/src/dht/find/RecursiveFindSession.js +13 -13
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -1
- package/dist/src/dht/find/RecursiveFinder.d.ts +9 -11
- package/dist/src/dht/find/RecursiveFinder.js +35 -36
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +4 -4
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.d.ts +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.js +4 -3
- package/dist/src/dht/registerExternalApiRpcMethods.js.map +1 -1
- package/dist/src/dht/routing/DuplicateDetector.d.ts +1 -2
- package/dist/src/dht/routing/DuplicateDetector.js +2 -7
- package/dist/src/dht/routing/DuplicateDetector.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +12 -15
- package/dist/src/dht/routing/Router.js +30 -33
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/{RemoteRouter.d.ts → RouterRpcRemote.d.ts} +2 -2
- package/dist/src/dht/routing/{RemoteRouter.js → RouterRpcRemote.js} +5 -5
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -4
- package/dist/src/dht/routing/RoutingSession.js +6 -5
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/{DataStore.d.ts → StoreRpcLocal.d.ts} +6 -6
- package/dist/src/dht/store/{DataStore.js → StoreRpcLocal.js} +34 -34
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -0
- package/dist/src/dht/store/{RemoteStore.d.ts → StoreRpcRemote.d.ts} +2 -2
- package/dist/src/dht/store/{RemoteStore.js → StoreRpcRemote.js} +4 -4
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -0
- package/dist/src/exports.d.ts +2 -8
- package/dist/src/exports.js +2 -14
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +0 -1
- package/dist/src/helpers/PeerID.js +0 -6
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/browser/isBrowserEnvironment.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js +6 -0
- package/dist/src/helpers/browser/isBrowserEnvironment.js.map +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.d.ts +1 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js +7 -0
- package/dist/src/helpers/browser/isBrowserEnvironment_override.js.map +1 -0
- package/dist/src/helpers/kademliaId.d.ts +1 -0
- package/dist/src/helpers/kademliaId.js +14 -0
- package/dist/src/helpers/kademliaId.js.map +1 -0
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +3 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/protoClasses.js +2 -2
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +29 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +39 -39
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +49 -162
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +47 -88
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +15 -15
- package/dist/src/transport/RoutingRpcCommunicator.js +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +10 -9
- package/protos/DhtRpc.proto +30 -60
- package/src/connection/ConnectionLockHandler.ts +1 -1
- package/src/connection/ConnectionLockRpcRemote.ts +62 -0
- package/src/connection/ConnectionManager.ts +178 -274
- package/src/connection/ConnectivityChecker.ts +15 -12
- package/src/connection/ConnectorFacade.ts +140 -0
- package/src/connection/Handshaker.ts +0 -5
- package/src/connection/ManagedConnection.ts +26 -40
- package/src/connection/ManagedWebRtcConnection.ts +0 -2
- package/src/connection/Simulator/Simulator.ts +0 -7
- package/src/connection/Simulator/SimulatorConnection.ts +16 -13
- package/src/connection/Simulator/SimulatorConnector.ts +13 -19
- package/src/connection/Simulator/SimulatorTransport.ts +6 -1
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +15 -14
- package/src/connection/WebRTC/{WebRtcConnector.ts → WebRtcConnectorRpcLocal.ts} +68 -56
- package/src/connection/WebRTC/WebRtcConnectorRpcRemote.ts +71 -0
- package/src/connection/WebRTC/iceServerAsString.ts +1 -1
- package/src/connection/WebSocket/{WebSocketConnector.ts → WebSocketConnectorRpcLocal.ts} +102 -79
- package/src/connection/WebSocket/WebSocketConnectorRpcRemote.ts +45 -0
- package/src/connection/WebSocket/WebSocketServer.ts +26 -8
- package/src/dht/DhtNode.ts +176 -203
- package/src/dht/{RemoteExternalApi.ts → ExternalApiRpcRemote.ts} +3 -4
- package/src/dht/{DhtPeer.ts → RemoteDhtNode.ts} +11 -9
- package/src/dht/contact/ContactList.ts +0 -4
- package/src/dht/contact/RandomContactList.ts +0 -4
- package/src/dht/contact/SortedContactList.ts +0 -12
- package/src/dht/discovery/DiscoverySession.ts +20 -23
- package/src/dht/discovery/PeerDiscovery.ts +47 -45
- package/src/dht/find/RecursiveFindSession.ts +21 -22
- package/src/dht/find/RecursiveFinder.ts +45 -49
- package/src/dht/find/RemoteRecursiveFindSession.ts +6 -6
- package/src/dht/registerExternalApiRpcMethods.ts +8 -5
- package/src/dht/routing/DuplicateDetector.ts +3 -10
- package/src/dht/routing/Router.ts +39 -45
- package/src/dht/routing/{RemoteRouter.ts → RouterRpcRemote.ts} +4 -4
- package/src/dht/routing/RoutingSession.ts +15 -15
- package/src/dht/store/{DataStore.ts → StoreRpcLocal.ts} +42 -42
- package/src/dht/store/{RemoteStore.ts → StoreRpcRemote.ts} +2 -2
- package/src/exports.ts +2 -8
- package/src/helpers/PeerID.ts +0 -7
- package/src/helpers/browser/isBrowserEnvironment.ts +1 -0
- package/src/helpers/browser/isBrowserEnvironment_override.ts +3 -0
- package/src/helpers/kademliaId.ts +8 -0
- package/src/helpers/peerIdFromPeerDescriptor.ts +1 -1
- package/src/helpers/protoClasses.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +54 -54
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +15 -15
- package/src/proto/packages/dht/protos/DhtRpc.ts +77 -216
- package/src/transport/RoutingRpcCommunicator.ts +1 -0
- package/test/benchmark/KademliaCorrectness.test.ts +4 -2
- package/test/benchmark/RecursiveFind.test.ts +6 -6
- package/test/end-to-end/Layer0-Layer1.test.ts +9 -9
- package/test/end-to-end/Layer0WebRTC-Layer1.test.ts +5 -5
- package/test/end-to-end/Layer0WebRTC.test.ts +5 -6
- package/test/end-to-end/Layer1-Scale-WebRTC.test.ts +13 -8
- package/test/end-to-end/Layer1-Scale-WebSocket.test.ts +15 -10
- package/test/end-to-end/WebSocketConnectionRequest.test.ts +5 -5
- package/test/integration/ConnectionLocking.test.ts +32 -26
- package/test/integration/ConnectionManager.test.ts +90 -93
- package/test/integration/DhtJoinPeerDiscovery.test.ts +53 -0
- package/test/integration/DhtRpc.test.ts +4 -6
- package/test/integration/Layer1-scale.test.ts +8 -8
- package/test/integration/MigrateData.test.ts +9 -9
- package/test/integration/Mock-Layer1-Layer0.test.ts +1 -2
- package/test/integration/RecursiveFind.test.ts +5 -5
- package/test/integration/{DhtPeer.test.ts → RemoteDhtNode.test.ts} +11 -12
- package/test/integration/RouteMessage.test.ts +7 -9
- package/test/integration/{RemoteRouter.test.ts → RouterRpcRemote.test.ts} +13 -14
- package/test/integration/RpcErrors.test.ts +25 -10
- package/test/integration/ScaleDownDht.test.ts +8 -8
- package/test/integration/SimultaneousConnections.test.ts +35 -36
- package/test/integration/Store.test.ts +8 -9
- package/test/integration/StoreAndDelete.test.ts +11 -11
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -7
- package/test/integration/{RemoteStore.test.ts → StoreRpcRemote.test.ts} +17 -18
- package/test/integration/WebRtcConnectionManagement.test.ts +26 -19
- package/test/integration/WebRtcConnectorRpc.test.ts +17 -32
- package/test/integration/WebSocket.test.ts +4 -2
- package/test/integration/WebSocketConnectionManagement.test.ts +30 -17
- package/test/integration/WebSocketConnectorRpc.test.ts +10 -15
- package/test/unit/DuplicateDetector.test.ts +3 -4
- package/test/unit/LocalDataStore.test.ts +6 -8
- package/test/unit/RandomContactList.test.ts +1 -1
- package/test/unit/RecursiveFinder.test.ts +13 -18
- package/test/unit/Router.test.ts +18 -21
- package/test/unit/WebSocketConnectorRpcLocal.test.ts +64 -0
- package/test/unit/WebSocketServer.test.ts +24 -12
- package/test/unit/{webrtcReplaceInternalIpWithExternalIp.ts → webrtcReplaceInternalIpWithExternalIp.test.ts} +1 -1
- package/test/utils/mock/RecursiveFinder.ts +2 -2
- package/test/utils/mock/Router.ts +9 -11
- package/test/utils/mock/Transport.ts +2 -2
- package/test/utils/utils.ts +55 -74
- package/dist/src/connection/RemoteConnectionLocker.d.ts +0 -13
- package/dist/src/connection/RemoteConnectionLocker.js.map +0 -1
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +0 -12
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +0 -74
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +0 -1
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +0 -9
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +0 -1
- package/dist/src/dht/DhtPeer.js.map +0 -1
- package/dist/src/dht/RemoteExternalApi.js.map +0 -1
- package/dist/src/dht/routing/RemoteRouter.js.map +0 -1
- package/dist/src/dht/store/DataStore.js.map +0 -1
- package/dist/src/dht/store/RemoteStore.js.map +0 -1
- package/dist/src/helpers/browser/isBrowser.d.ts +0 -1
- package/dist/src/helpers/browser/isBrowser.js +0 -6
- package/dist/src/helpers/browser/isBrowser.js.map +0 -1
- package/dist/src/helpers/browser/isNodeJS.d.ts +0 -1
- package/dist/src/helpers/browser/isNodeJS.js +0 -6
- package/dist/src/helpers/browser/isNodeJS.js.map +0 -1
- package/src/connection/RemoteConnectionLocker.ts +0 -84
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +0 -93
- package/src/connection/WebSocket/RemoteWebSocketConnector.ts +0 -49
- package/src/helpers/browser/isBrowser.ts +0 -1
- package/src/helpers/browser/isNodeJS.ts +0 -1
- package/test/integration/DhtWithMockConnectionLatencies.test.ts +0 -46
- package/test/integration/DhtWithMockConnections.test.ts +0 -46
- package/test/integration/DhtWithRealConnectionLatencies.test.ts +0 -47
|
@@ -1,93 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
IceCandidate,
|
|
3
|
-
PeerDescriptor,
|
|
4
|
-
RtcAnswer,
|
|
5
|
-
RtcOffer,
|
|
6
|
-
WebRtcConnectionRequest
|
|
7
|
-
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
8
|
-
import { IWebRtcConnectorServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
9
|
-
import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
|
|
10
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
11
|
-
import { Logger } from '@streamr/utils'
|
|
12
|
-
|
|
13
|
-
const logger = new Logger(module)
|
|
14
|
-
|
|
15
|
-
export class RemoteWebrtcConnector {
|
|
16
|
-
|
|
17
|
-
private peerDescriptor: PeerDescriptor
|
|
18
|
-
private client: ProtoRpcClient<IWebRtcConnectorServiceClient>
|
|
19
|
-
|
|
20
|
-
constructor(peerDescriptor: PeerDescriptor, client: ProtoRpcClient<IWebRtcConnectorServiceClient>) {
|
|
21
|
-
this.peerDescriptor = peerDescriptor
|
|
22
|
-
this.client = client
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
requestConnection(sourceDescriptor: PeerDescriptor, connectionId: string): void {
|
|
26
|
-
const request: WebRtcConnectionRequest = {
|
|
27
|
-
target: this.peerDescriptor,
|
|
28
|
-
requester: sourceDescriptor,
|
|
29
|
-
connectionId
|
|
30
|
-
}
|
|
31
|
-
const options: DhtRpcOptions = {
|
|
32
|
-
sourceDescriptor: sourceDescriptor,
|
|
33
|
-
targetDescriptor: this.peerDescriptor,
|
|
34
|
-
notification: true
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
this.client.requestConnection(request, options).catch((_e) => {
|
|
38
|
-
logger.trace('Failed to send requestConnection')
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
sendRtcOffer(sourceDescriptor: PeerDescriptor, description: string, connectionId: string): void {
|
|
43
|
-
const request: RtcOffer = {
|
|
44
|
-
target: this.peerDescriptor,
|
|
45
|
-
requester: sourceDescriptor,
|
|
46
|
-
connectionId,
|
|
47
|
-
description
|
|
48
|
-
}
|
|
49
|
-
const options: DhtRpcOptions = {
|
|
50
|
-
sourceDescriptor: sourceDescriptor,
|
|
51
|
-
targetDescriptor: this.peerDescriptor,
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.client.rtcOffer(request, options).catch((_e) => {
|
|
55
|
-
logger.trace('Failed to send rtcOffer')
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
sendRtcAnswer(sourceDescriptor: PeerDescriptor, description: string, connectionId: string): void {
|
|
60
|
-
const request: RtcAnswer = {
|
|
61
|
-
target: this.peerDescriptor,
|
|
62
|
-
requester: sourceDescriptor,
|
|
63
|
-
connectionId,
|
|
64
|
-
description
|
|
65
|
-
}
|
|
66
|
-
const options: DhtRpcOptions = {
|
|
67
|
-
sourceDescriptor: sourceDescriptor,
|
|
68
|
-
targetDescriptor: this.peerDescriptor,
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
this.client.rtcAnswer(request, options).catch((_e) => {
|
|
72
|
-
logger.trace('Failed to send rtcAnswer')
|
|
73
|
-
})
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
sendIceCandidate(sourceDescriptor: PeerDescriptor, candidate: string, mid: string, connectionId: string): void {
|
|
77
|
-
const request: IceCandidate = {
|
|
78
|
-
target: this.peerDescriptor,
|
|
79
|
-
requester: sourceDescriptor,
|
|
80
|
-
connectionId,
|
|
81
|
-
mid,
|
|
82
|
-
candidate
|
|
83
|
-
}
|
|
84
|
-
const options: DhtRpcOptions = {
|
|
85
|
-
sourceDescriptor: sourceDescriptor,
|
|
86
|
-
targetDescriptor: this.peerDescriptor,
|
|
87
|
-
}
|
|
88
|
-
this.client.iceCandidate(request, options).catch((_e) => {
|
|
89
|
-
logger.trace('Failed to send iceCandidate')
|
|
90
|
-
})
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
@@ -1,49 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
PeerDescriptor,
|
|
3
|
-
WebSocketConnectionRequest
|
|
4
|
-
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { IWebSocketConnectorServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
6
|
-
import { DhtRpcOptions } from '../../rpc-protocol/DhtRpcOptions'
|
|
7
|
-
import { Logger } from '@streamr/utils'
|
|
8
|
-
import * as Err from '../../helpers/errors'
|
|
9
|
-
import { ProtoRpcClient } from '@streamr/proto-rpc'
|
|
10
|
-
|
|
11
|
-
const logger = new Logger(module)
|
|
12
|
-
|
|
13
|
-
export class RemoteWebSocketConnector {
|
|
14
|
-
|
|
15
|
-
private peerDescriptor: PeerDescriptor
|
|
16
|
-
private client: ProtoRpcClient<IWebSocketConnectorServiceClient>
|
|
17
|
-
|
|
18
|
-
constructor(peerDescriptor: PeerDescriptor, client: ProtoRpcClient<IWebSocketConnectorServiceClient>) {
|
|
19
|
-
this.peerDescriptor = peerDescriptor
|
|
20
|
-
this.client = client
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
async requestConnection(sourceDescriptor: PeerDescriptor, ip: string, port: number): Promise<boolean> {
|
|
24
|
-
logger.trace(`Requesting WebSocket connection from ${this.peerDescriptor.kademliaId.toString()}`)
|
|
25
|
-
const request: WebSocketConnectionRequest = {
|
|
26
|
-
target: this.peerDescriptor,
|
|
27
|
-
requester: sourceDescriptor,
|
|
28
|
-
ip,
|
|
29
|
-
port
|
|
30
|
-
}
|
|
31
|
-
const options: DhtRpcOptions = {
|
|
32
|
-
sourceDescriptor: sourceDescriptor,
|
|
33
|
-
targetDescriptor: this.peerDescriptor
|
|
34
|
-
}
|
|
35
|
-
try {
|
|
36
|
-
const res = await this.client.requestConnection(request, options)
|
|
37
|
-
|
|
38
|
-
if (res.reason) {
|
|
39
|
-
logger.debug('WebSocketConnectionRequest Rejected', {
|
|
40
|
-
stack: new Err.WebSocketConnectionRequestRejected(res.reason).stack
|
|
41
|
-
})
|
|
42
|
-
}
|
|
43
|
-
return res.accepted
|
|
44
|
-
} catch (err) {
|
|
45
|
-
logger.debug(new Err.WebSocketConnectionRequestRejected('WebSocketConnectionRequest rejected', err).stack!)
|
|
46
|
-
return false
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isNodeJS = (): boolean => false
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export const isNodeJS = (): boolean => true
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
4
|
-
import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
|
|
5
|
-
|
|
6
|
-
describe('Mock connection Dht joining with latencies', () => {
|
|
7
|
-
let entryPoint: DhtNode
|
|
8
|
-
let nodes: DhtNode[]
|
|
9
|
-
let simulator: Simulator
|
|
10
|
-
let entrypointDescriptor: PeerDescriptor
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
nodes = []
|
|
14
|
-
simulator = new Simulator(LatencyType.RANDOM)
|
|
15
|
-
const entryPointId = '0'
|
|
16
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
|
|
17
|
-
entrypointDescriptor = {
|
|
18
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
19
|
-
type: NodeType.NODEJS,
|
|
20
|
-
nodeName: '0'
|
|
21
|
-
}
|
|
22
|
-
for (let i = 1; i < 100; i++) {
|
|
23
|
-
const nodeId = `${i}`
|
|
24
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
25
|
-
nodes.push(node)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
afterEach(async () => {
|
|
30
|
-
await Promise.all([
|
|
31
|
-
entryPoint.stop(),
|
|
32
|
-
...nodes.map((node) => node.stop())
|
|
33
|
-
])
|
|
34
|
-
simulator.stop()
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('Happy path', async () => {
|
|
38
|
-
await entryPoint.joinDht([entrypointDescriptor])
|
|
39
|
-
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
40
|
-
nodes.forEach((node) => {
|
|
41
|
-
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
42
|
-
expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
43
|
-
})
|
|
44
|
-
expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK() - 2)
|
|
45
|
-
}, 60 * 1000)
|
|
46
|
-
})
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { Simulator } from '../../src/connection/Simulator/Simulator'
|
|
2
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
3
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
4
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
5
|
-
|
|
6
|
-
describe('Mock IConnection DHT Joining', () => {
|
|
7
|
-
let entryPoint: DhtNode
|
|
8
|
-
let nodes: DhtNode[]
|
|
9
|
-
let entrypointDescriptor: PeerDescriptor
|
|
10
|
-
let simulator: Simulator
|
|
11
|
-
|
|
12
|
-
beforeEach(async () => {
|
|
13
|
-
nodes = []
|
|
14
|
-
simulator = new Simulator()
|
|
15
|
-
const entryPointId = '0'
|
|
16
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
|
|
17
|
-
entrypointDescriptor = {
|
|
18
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
19
|
-
type: NodeType.NODEJS,
|
|
20
|
-
nodeName: '0'
|
|
21
|
-
}
|
|
22
|
-
for (let i = 1; i < 100; i++) {
|
|
23
|
-
const nodeId = `${i}`
|
|
24
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
25
|
-
nodes.push(node)
|
|
26
|
-
}
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
afterEach(async () => {
|
|
30
|
-
await Promise.all([
|
|
31
|
-
entryPoint.stop(),
|
|
32
|
-
...nodes.map(async (node) => node.stop())
|
|
33
|
-
])
|
|
34
|
-
simulator.stop()
|
|
35
|
-
})
|
|
36
|
-
|
|
37
|
-
it('Happy path', async () => {
|
|
38
|
-
await entryPoint.joinDht([entrypointDescriptor])
|
|
39
|
-
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
40
|
-
nodes.forEach((node) => {
|
|
41
|
-
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
42
|
-
expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(node.getK() - 2)
|
|
43
|
-
})
|
|
44
|
-
expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK() - 2)
|
|
45
|
-
}, 60000)
|
|
46
|
-
})
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { DhtNode } from '../../src/dht/DhtNode'
|
|
2
|
-
import { createMockConnectionDhtNode } from '../utils/utils'
|
|
3
|
-
import { LatencyType, Simulator } from '../../src/connection/Simulator/Simulator'
|
|
4
|
-
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
-
import { getRandomRegion } from '../../src/connection/Simulator/pings'
|
|
6
|
-
|
|
7
|
-
describe('Mock connection Dht joining with real latencies', () => {
|
|
8
|
-
let entryPoint: DhtNode
|
|
9
|
-
let nodes: DhtNode[]
|
|
10
|
-
let simulator: Simulator
|
|
11
|
-
let entrypointDescriptor: PeerDescriptor
|
|
12
|
-
|
|
13
|
-
beforeEach(async () => {
|
|
14
|
-
nodes = []
|
|
15
|
-
simulator = new Simulator(LatencyType.REAL)
|
|
16
|
-
const entryPointId = '0'
|
|
17
|
-
entryPoint = await createMockConnectionDhtNode(entryPointId, simulator)
|
|
18
|
-
entrypointDescriptor = {
|
|
19
|
-
kademliaId: entryPoint.getNodeId().value,
|
|
20
|
-
type: NodeType.NODEJS,
|
|
21
|
-
region: getRandomRegion()
|
|
22
|
-
}
|
|
23
|
-
for (let i = 1; i < 100; i++) {
|
|
24
|
-
const nodeId = `${i}`
|
|
25
|
-
const node = await createMockConnectionDhtNode(nodeId, simulator)
|
|
26
|
-
nodes.push(node)
|
|
27
|
-
}
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
afterEach(async () => {
|
|
31
|
-
await Promise.all([
|
|
32
|
-
entryPoint.stop(),
|
|
33
|
-
...nodes.map((node) => node.stop())
|
|
34
|
-
])
|
|
35
|
-
simulator.stop()
|
|
36
|
-
})
|
|
37
|
-
|
|
38
|
-
it('Happy path', async () => {
|
|
39
|
-
await entryPoint.joinDht([entrypointDescriptor])
|
|
40
|
-
await Promise.all(nodes.map((node) => node.joinDht([entrypointDescriptor])))
|
|
41
|
-
nodes.forEach((node) => {
|
|
42
|
-
expect(node.getBucketSize()).toBeGreaterThanOrEqual(node.getK() - 3)
|
|
43
|
-
expect(node.getClosestContacts().length).toBeGreaterThanOrEqual(node.getK() - 3)
|
|
44
|
-
})
|
|
45
|
-
expect(entryPoint.getBucketSize()).toBeGreaterThanOrEqual(entryPoint.getK())
|
|
46
|
-
}, 60 * 1000)
|
|
47
|
-
})
|