@streamr/dht 100.2.5-beta.1 → 101.0.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +8 -8
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionLockRpcLocal.js +8 -8
- package/dist/src/connection/ConnectionLockRpcLocal.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js +1 -1
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -1
- package/dist/src/connection/ConnectionManager.d.ts +4 -6
- package/dist/src/connection/ConnectionManager.js +128 -103
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +15 -14
- package/dist/src/connection/ConnectorFacade.js +70 -52
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +9 -2
- package/dist/src/connection/Handshaker.js +117 -27
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +13 -38
- package/dist/src/connection/ManagedConnection.js +31 -252
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/OutputBuffer.d.ts +9 -0
- package/dist/src/connection/OutputBuffer.js +26 -0
- package/dist/src/connection/OutputBuffer.js.map +1 -0
- package/dist/src/connection/PendingConnection.d.ts +19 -0
- package/dist/src/connection/PendingConnection.js +59 -0
- package/dist/src/connection/PendingConnection.js.map +1 -0
- package/dist/src/connection/connectivityChecker.js +3 -3
- package/dist/src/connection/connectivityChecker.js.map +1 -1
- package/dist/src/connection/connectivityRequestHandler.js +2 -2
- package/dist/src/connection/connectivityRequestHandler.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.d.ts +1 -3
- package/dist/src/connection/simulator/Simulator.js +1 -4
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +1 -2
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.d.ts +3 -3
- package/dist/src/connection/simulator/SimulatorConnector.js +28 -21
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.d.ts +1 -6
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +3 -20
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.d.ts +11 -6
- package/dist/src/connection/webrtc/WebrtcConnector.js +57 -42
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +8 -10
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +21 -44
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js +8 -2
- package/dist/src/connection/websocket/AbstractWebsocketClientConnection.js.map +1 -1
- package/dist/src/connection/websocket/AutoCertifierClientFacade.d.ts +3 -3
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js +8 -8
- package/dist/src/connection/websocket/AutoCertifierClientFacade.js.map +1 -1
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js +1 -1
- package/dist/src/connection/websocket/NodeWebsocketClientConnection.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketClientConnector.d.ts +26 -0
- package/dist/src/connection/websocket/WebsocketClientConnector.js +86 -0
- package/dist/src/connection/websocket/WebsocketClientConnector.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.d.ts +19 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js +23 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.d.ts +5 -0
- package/dist/src/connection/websocket/{WebsocketConnectorRpcRemote.js → WebsocketClientConnectorRpcRemote.js} +4 -4
- package/dist/src/connection/websocket/WebsocketClientConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/websocket/WebsocketServer.d.ts +8 -5
- package/dist/src/connection/websocket/WebsocketServer.js +11 -11
- package/dist/src/connection/websocket/WebsocketServer.js.map +1 -1
- package/dist/src/connection/websocket/{WebsocketConnector.d.ts → WebsocketServerConnector.d.ts} +16 -21
- package/dist/src/connection/websocket/{WebsocketConnector.js → WebsocketServerConnector.js} +112 -160
- package/dist/src/connection/websocket/WebsocketServerConnector.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +4 -4
- package/dist/src/dht/DhtNode.js +85 -84
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +3 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +9 -9
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +5 -5
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.js +2 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +4 -4
- package/dist/src/dht/PeerManager.js +22 -22
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +3 -3
- package/dist/src/dht/contact/SortedContactList.js +9 -9
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -3
- package/dist/src/dht/discovery/DiscoverySession.js +21 -21
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -3
- package/dist/src/dht/discovery/PeerDiscovery.js +46 -44
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/discovery/RingDiscoverySession.d.ts +3 -3
- package/dist/src/dht/discovery/RingDiscoverySession.js +19 -19
- package/dist/src/dht/discovery/RingDiscoverySession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +33 -33
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js +8 -8
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcLocal.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +4 -4
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +24 -24
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.d.ts +4 -4
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js +5 -5
- package/dist/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +3 -3
- package/dist/src/dht/routing/Router.js +20 -20
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.d.ts +3 -3
- package/dist/src/dht/routing/RouterRpcLocal.js +16 -16
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
- package/dist/src/dht/routing/RoutingSession.js +24 -24
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +25 -25
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +3 -3
- package/dist/src/dht/store/StoreRpcLocal.js +12 -12
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/exports.d.ts +3 -0
- package/dist/src/exports.js +5 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.d.ts +5 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.d.ts +1 -0
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.d.ts +1 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +4 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +8 -8
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +3 -3
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +4 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +2 -2
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/transport/ListeningRpcCommunicator.d.ts +2 -2
- package/dist/src/transport/ListeningRpcCommunicator.js +2 -2
- package/dist/src/transport/ListeningRpcCommunicator.js.map +1 -1
- package/dist/src/transport/RoutingRpcCommunicator.d.ts +2 -2
- package/dist/src/transport/RoutingRpcCommunicator.js +2 -2
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +8 -8
- package/protos/DhtRpc.proto +1 -1
- package/src/connection/ConnectionLockRpcLocal.ts +9 -9
- package/src/connection/ConnectionLockRpcRemote.ts +1 -1
- package/src/connection/ConnectionManager.ts +153 -111
- package/src/connection/ConnectorFacade.ts +84 -61
- package/src/connection/Handshaker.ts +131 -27
- package/src/connection/ManagedConnection.ts +41 -304
- package/src/connection/OutputBuffer.ts +28 -0
- package/src/connection/PendingConnection.ts +68 -0
- package/src/connection/connectivityChecker.ts +2 -2
- package/src/connection/connectivityRequestHandler.ts +1 -1
- package/src/connection/simulator/Simulator.ts +1 -5
- package/src/connection/simulator/SimulatorConnection.ts +1 -2
- package/src/connection/simulator/SimulatorConnector.ts +34 -33
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -6
- package/src/connection/webrtc/NodeWebrtcConnection.ts +3 -24
- package/src/connection/webrtc/WebrtcConnector.ts +73 -62
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +26 -56
- package/src/connection/websocket/AbstractWebsocketClientConnection.ts +8 -2
- package/src/connection/websocket/AutoCertifierClientFacade.ts +11 -11
- package/src/connection/websocket/NodeWebsocketClientConnection.ts +1 -1
- package/src/connection/websocket/WebsocketClientConnector.ts +119 -0
- package/src/connection/websocket/WebsocketClientConnectorRpcLocal.ts +39 -0
- package/src/connection/websocket/{WebsocketConnectorRpcRemote.ts → WebsocketClientConnectorRpcRemote.ts} +2 -2
- package/src/connection/websocket/WebsocketServer.ts +18 -14
- package/src/connection/websocket/{WebsocketConnector.ts → WebsocketServerConnector.ts} +128 -205
- package/src/dht/DhtNode.ts +90 -89
- package/src/dht/DhtNodeRpcLocal.ts +11 -11
- package/src/dht/ExternalApiRpcLocal.ts +6 -6
- package/src/dht/ExternalApiRpcRemote.ts +2 -2
- package/src/dht/PeerManager.ts +24 -24
- package/src/dht/contact/SortedContactList.ts +10 -10
- package/src/dht/discovery/DiscoverySession.ts +24 -24
- package/src/dht/discovery/PeerDiscovery.ts +47 -45
- package/src/dht/discovery/RingDiscoverySession.ts +23 -23
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +36 -36
- package/src/dht/recursive-operation/RecursiveOperationRpcLocal.ts +9 -9
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +25 -25
- package/src/dht/recursive-operation/RecursiveOperationSessionRpcLocal.ts +7 -7
- package/src/dht/routing/Router.ts +21 -21
- package/src/dht/routing/RouterRpcLocal.ts +17 -17
- package/src/dht/routing/RoutingSession.ts +26 -26
- package/src/dht/store/StoreManager.ts +27 -27
- package/src/dht/store/StoreRpcLocal.ts +13 -13
- package/src/exports.ts +3 -0
- package/src/proto/google/protobuf/any.ts +6 -9
- package/src/proto/google/protobuf/empty.ts +2 -1
- package/src/proto/google/protobuf/timestamp.ts +2 -11
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +9 -9
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +3 -3
- package/src/proto/packages/dht/protos/DhtRpc.ts +4 -4
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/transport/ListeningRpcCommunicator.ts +3 -3
- package/src/transport/RoutingRpcCommunicator.ts +3 -3
- package/test/end-to-end/Layer0Webrtc.test.ts +0 -10
- package/test/integration/ConnectionManager.test.ts +3 -2
- package/test/integration/GeoIpConnectivityChecking.test.ts +1 -1
- package/test/integration/SimultaneousConnections.test.ts +2 -2
- package/test/integration/WebrtcConnectionManagement.test.ts +2 -10
- package/test/integration/{WebsocketConnectorRpc.test.ts → WebsocketClientConnectorRpc.test.ts} +9 -9
- package/test/integration/WebsocketConnectionManagement.test.ts +11 -29
- package/test/unit/ConnectionManager.test.ts +64 -0
- package/test/unit/DiscoverySession.test.ts +1 -1
- package/test/unit/Handshaker.test.ts +169 -0
- package/test/unit/ManagedConnection.test.ts +58 -0
- package/test/unit/PendingConnection.test.ts +57 -0
- package/test/unit/WebrtcConnector.test.ts +56 -0
- package/test/unit/{WebsocketConnector.test.ts → WebsocketClientConnector.test.ts} +56 -11
- package/test/unit/WebsocketServerConnector.test.ts +102 -0
- package/test/utils/FakeConnectorFacade.ts +41 -0
- package/test/utils/mock/MockConnection.ts +26 -0
- package/test/utils/utils.ts +2 -2
- package/dist/src/connection/IConnectionSource.d.ts +0 -4
- package/dist/src/connection/IConnectionSource.js +0 -3
- package/dist/src/connection/IConnectionSource.js.map +0 -1
- package/dist/src/connection/webrtc/ManagedWebrtcConnection.d.ts +0 -7
- package/dist/src/connection/webrtc/ManagedWebrtcConnection.js +0 -20
- package/dist/src/connection/webrtc/ManagedWebrtcConnection.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketConnector.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.d.ts +0 -19
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js +0 -23
- package/dist/src/connection/websocket/WebsocketConnectorRpcLocal.js.map +0 -1
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.d.ts +0 -5
- package/dist/src/connection/websocket/WebsocketConnectorRpcRemote.js.map +0 -1
- package/src/connection/IConnectionSource.ts +0 -6
- package/src/connection/webrtc/ManagedWebrtcConnection.ts +0 -27
- package/src/connection/websocket/WebsocketConnectorRpcLocal.ts +0 -39
|
@@ -5,18 +5,20 @@ import {
|
|
|
5
5
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { ITransport } from '../transport/ITransport'
|
|
7
7
|
import { PortRange, TlsCertificate } from './ConnectionManager'
|
|
8
|
-
import { ManagedConnection } from './ManagedConnection'
|
|
9
8
|
import { Simulator } from './simulator/Simulator'
|
|
10
9
|
import { SimulatorConnector } from './simulator/SimulatorConnector'
|
|
11
10
|
import { IceServer, WebrtcConnector } from './webrtc/WebrtcConnector'
|
|
12
|
-
import {
|
|
11
|
+
import { WebsocketClientConnector } from './websocket/WebsocketClientConnector'
|
|
13
12
|
import { DhtAddress } from '../identifiers'
|
|
13
|
+
import { WebsocketServerConnector, WebsocketServerConnectorOptions } from './websocket/WebsocketServerConnector'
|
|
14
|
+
import { PendingConnection } from './PendingConnection'
|
|
15
|
+
import { ListeningRpcCommunicator } from '../transport/ListeningRpcCommunicator'
|
|
14
16
|
|
|
15
17
|
export interface ConnectorFacade {
|
|
16
|
-
createConnection: (peerDescriptor: PeerDescriptor) =>
|
|
18
|
+
createConnection: (peerDescriptor: PeerDescriptor) => PendingConnection
|
|
17
19
|
getLocalPeerDescriptor: () => PeerDescriptor | undefined
|
|
18
20
|
start: (
|
|
19
|
-
onNewConnection: (connection:
|
|
21
|
+
onNewConnection: (connection: PendingConnection) => boolean,
|
|
20
22
|
hasConnection: (nodeId: DhtAddress) => boolean,
|
|
21
23
|
autoCertifierTransport: ITransport
|
|
22
24
|
) => Promise<void>
|
|
@@ -26,7 +28,7 @@ export interface ConnectorFacade {
|
|
|
26
28
|
const logger = new Logger(module)
|
|
27
29
|
|
|
28
30
|
// TODO: Wrap component specific configs to their own objects.
|
|
29
|
-
export interface
|
|
31
|
+
export interface DefaultConnectorFacadeOptions {
|
|
30
32
|
transport: ITransport
|
|
31
33
|
websocketHost?: string
|
|
32
34
|
websocketPortRange?: PortRange
|
|
@@ -35,7 +37,6 @@ export interface DefaultConnectorFacadeConfig {
|
|
|
35
37
|
webrtcAllowPrivateAddresses?: boolean
|
|
36
38
|
webrtcDatachannelBufferThresholdLow?: number
|
|
37
39
|
webrtcDatachannelBufferThresholdHigh?: number
|
|
38
|
-
webrtcNewConnectionTimeout?: number
|
|
39
40
|
externalIp?: string
|
|
40
41
|
webrtcPortRange?: PortRange
|
|
41
42
|
maxMessageSize?: number
|
|
@@ -50,76 +51,91 @@ export interface DefaultConnectorFacadeConfig {
|
|
|
50
51
|
|
|
51
52
|
export class DefaultConnectorFacade implements ConnectorFacade {
|
|
52
53
|
|
|
53
|
-
private readonly
|
|
54
|
+
private readonly options: DefaultConnectorFacadeOptions
|
|
54
55
|
private localPeerDescriptor?: PeerDescriptor
|
|
55
|
-
private
|
|
56
|
+
private websocketConnectorRpcCommunicator?: ListeningRpcCommunicator
|
|
57
|
+
private websocketClientConnector?: WebsocketClientConnector
|
|
58
|
+
private websocketServerConnector?: WebsocketServerConnector
|
|
56
59
|
private webrtcConnector?: WebrtcConnector
|
|
57
|
-
constructor(
|
|
58
|
-
this.
|
|
60
|
+
constructor(options: DefaultConnectorFacadeOptions) {
|
|
61
|
+
this.options = options
|
|
59
62
|
}
|
|
60
63
|
|
|
61
64
|
async start(
|
|
62
|
-
onNewConnection: (connection:
|
|
65
|
+
onNewConnection: (connection: PendingConnection) => boolean,
|
|
63
66
|
hasConnection: (nodeId: DhtAddress) => boolean,
|
|
64
67
|
autoCertifierTransport: ITransport
|
|
65
68
|
): Promise<void> {
|
|
66
69
|
logger.trace(`Creating WebsocketConnectorRpcLocal`)
|
|
67
|
-
|
|
68
|
-
|
|
70
|
+
this.websocketConnectorRpcCommunicator = new ListeningRpcCommunicator(
|
|
71
|
+
WebsocketClientConnector.WEBSOCKET_CONNECTOR_SERVICE_ID,
|
|
72
|
+
this.options.transport,
|
|
73
|
+
{ rpcRequestTimeout: 15000 } // TODO use options option or named constant?
|
|
74
|
+
|
|
75
|
+
)
|
|
76
|
+
const webSocketClientConnectorOptions = {
|
|
69
77
|
// TODO should we use canConnect also for WebrtcConnector? (NET-1142)
|
|
70
78
|
onNewConnection,
|
|
71
79
|
hasConnection,
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
rpcCommunicator: this.websocketConnectorRpcCommunicator
|
|
81
|
+
}
|
|
82
|
+
this.websocketClientConnector = new WebsocketClientConnector(webSocketClientConnectorOptions)
|
|
83
|
+
|
|
84
|
+
const webSocketServerConnectorOptions = {
|
|
85
|
+
rpcCommunicator: this.websocketConnectorRpcCommunicator,
|
|
86
|
+
// TODO should we use canConnect also for WebrtcConnector? (NET-1142)
|
|
87
|
+
onNewConnection,
|
|
88
|
+
hasConnection,
|
|
89
|
+
portRange: this.options.websocketPortRange,
|
|
90
|
+
host: this.options.websocketHost,
|
|
91
|
+
entrypoints: this.options.entryPoints,
|
|
92
|
+
tlsCertificate: this.options.tlsCertificate,
|
|
93
|
+
serverEnableTls: this.options.websocketServerEnableTls!,
|
|
94
|
+
autoCertifierUrl: this.options.autoCertifierUrl!,
|
|
95
|
+
autoCertifierConfigFile: this.options.autoCertifierConfigFile!,
|
|
79
96
|
autoCertifierTransport,
|
|
80
|
-
maxMessageSize: this.
|
|
81
|
-
geoIpDatabaseFolder: this.
|
|
97
|
+
maxMessageSize: this.options.maxMessageSize,
|
|
98
|
+
geoIpDatabaseFolder: this.options.geoIpDatabaseFolder
|
|
82
99
|
}
|
|
83
|
-
this.
|
|
84
|
-
logger.trace(`Creating WebRtcConnectorRpcLocal`)
|
|
100
|
+
this.websocketServerConnector = new WebsocketServerConnector(webSocketServerConnectorOptions)
|
|
85
101
|
this.webrtcConnector = new WebrtcConnector({
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
externalIp: this.
|
|
93
|
-
portRange: this.
|
|
94
|
-
maxMessageSize: this.
|
|
95
|
-
}
|
|
96
|
-
await this.
|
|
102
|
+
onNewConnection,
|
|
103
|
+
transport: this.options.transport,
|
|
104
|
+
iceServers: this.options.iceServers,
|
|
105
|
+
allowPrivateAddresses: this.options.webrtcAllowPrivateAddresses,
|
|
106
|
+
bufferThresholdLow: this.options.webrtcDatachannelBufferThresholdLow,
|
|
107
|
+
bufferThresholdHigh: this.options.webrtcDatachannelBufferThresholdHigh,
|
|
108
|
+
externalIp: this.options.externalIp,
|
|
109
|
+
portRange: this.options.webrtcPortRange,
|
|
110
|
+
maxMessageSize: this.options.maxMessageSize
|
|
111
|
+
})
|
|
112
|
+
await this.websocketServerConnector.start()
|
|
97
113
|
// TODO: generate a PeerDescriptor in a single function. Requires changes to the createOwnPeerDescriptor
|
|
98
|
-
// function in the
|
|
114
|
+
// function in the options. Currently it's given by the DhtNode and it sets the PeerDescriptor for the
|
|
99
115
|
// DhtNode in each call.
|
|
100
116
|
// LocalPeerDescriptor could be stored in one place and passed from there to the connectors
|
|
101
|
-
const temporarilySelfSigned = (!this.
|
|
102
|
-
const connectivityResponse = await this.
|
|
103
|
-
const localPeerDescriptor = await this.
|
|
117
|
+
const temporarilySelfSigned = (!this.options.tlsCertificate && this.options.websocketServerEnableTls === true)
|
|
118
|
+
const connectivityResponse = await this.websocketServerConnector.checkConnectivity(temporarilySelfSigned)
|
|
119
|
+
const localPeerDescriptor = await this.options.createLocalPeerDescriptor(connectivityResponse)
|
|
104
120
|
this.setLocalPeerDescriptor(localPeerDescriptor)
|
|
105
|
-
if (localPeerDescriptor.websocket && !this.
|
|
121
|
+
if (localPeerDescriptor.websocket && !this.options.tlsCertificate && this.options.websocketServerEnableTls) {
|
|
106
122
|
try {
|
|
107
|
-
await this.
|
|
108
|
-
const connectivityResponse = await this.
|
|
109
|
-
const autocertifiedLocalPeerDescriptor = await this.
|
|
123
|
+
await this.websocketServerConnector.autoCertify()
|
|
124
|
+
const connectivityResponse = await this.websocketServerConnector.checkConnectivity(false)
|
|
125
|
+
const autocertifiedLocalPeerDescriptor = await this.options.createLocalPeerDescriptor(connectivityResponse)
|
|
110
126
|
if (autocertifiedLocalPeerDescriptor.websocket !== undefined) {
|
|
111
127
|
this.setLocalPeerDescriptor(autocertifiedLocalPeerDescriptor)
|
|
112
128
|
} else {
|
|
113
129
|
logger.warn('Connectivity check failed after auto-certification, disabling WebSocket server TLS')
|
|
114
|
-
await this.
|
|
115
|
-
...
|
|
130
|
+
await this.restartWebsocketServerConnector({
|
|
131
|
+
...webSocketServerConnectorOptions,
|
|
116
132
|
serverEnableTls: false
|
|
117
133
|
})
|
|
118
134
|
}
|
|
119
135
|
} catch (err) {
|
|
120
136
|
logger.warn('Failed to auto-certify, disabling WebSocket server TLS', { err })
|
|
121
|
-
await this.
|
|
122
|
-
...
|
|
137
|
+
await this.restartWebsocketServerConnector({
|
|
138
|
+
...webSocketServerConnectorOptions,
|
|
123
139
|
serverEnableTls: false
|
|
124
140
|
})
|
|
125
141
|
}
|
|
@@ -128,24 +144,27 @@ export class DefaultConnectorFacade implements ConnectorFacade {
|
|
|
128
144
|
|
|
129
145
|
private setLocalPeerDescriptor(peerDescriptor: PeerDescriptor) {
|
|
130
146
|
this.localPeerDescriptor = peerDescriptor
|
|
131
|
-
this.
|
|
147
|
+
this.websocketServerConnector!.setLocalPeerDescriptor(peerDescriptor)
|
|
148
|
+
this.websocketClientConnector!.setLocalPeerDescriptor(peerDescriptor)
|
|
132
149
|
this.webrtcConnector!.setLocalPeerDescriptor(peerDescriptor)
|
|
133
150
|
}
|
|
134
151
|
|
|
135
|
-
async
|
|
136
|
-
await this.
|
|
137
|
-
this.
|
|
138
|
-
await this.
|
|
139
|
-
const connectivityResponse = await this.
|
|
140
|
-
const localPeerDescriptor = await this.
|
|
152
|
+
async restartWebsocketServerConnector(options: WebsocketServerConnectorOptions): Promise<void> {
|
|
153
|
+
await this.websocketServerConnector!.destroy()
|
|
154
|
+
this.websocketServerConnector = new WebsocketServerConnector(options)
|
|
155
|
+
await this.websocketServerConnector.start()
|
|
156
|
+
const connectivityResponse = await this.websocketServerConnector.checkConnectivity(false)
|
|
157
|
+
const localPeerDescriptor = await this.options.createLocalPeerDescriptor(connectivityResponse)
|
|
141
158
|
this.setLocalPeerDescriptor(localPeerDescriptor)
|
|
142
159
|
}
|
|
143
160
|
|
|
144
|
-
createConnection(peerDescriptor: PeerDescriptor):
|
|
145
|
-
if (this.
|
|
146
|
-
return this.
|
|
161
|
+
createConnection(peerDescriptor: PeerDescriptor): PendingConnection {
|
|
162
|
+
if (this.websocketClientConnector!.isPossibleToFormConnection(peerDescriptor)) {
|
|
163
|
+
return this.websocketClientConnector!.connect(peerDescriptor)
|
|
164
|
+
} else if (this.websocketServerConnector!.isPossibleToFormConnection(peerDescriptor)) {
|
|
165
|
+
return this.websocketServerConnector!.connect(peerDescriptor)
|
|
147
166
|
} else {
|
|
148
|
-
return this.webrtcConnector!.connect(peerDescriptor)
|
|
167
|
+
return this.webrtcConnector!.connect(peerDescriptor, false)
|
|
149
168
|
}
|
|
150
169
|
}
|
|
151
170
|
|
|
@@ -154,7 +173,9 @@ export class DefaultConnectorFacade implements ConnectorFacade {
|
|
|
154
173
|
}
|
|
155
174
|
|
|
156
175
|
async stop(): Promise<void> {
|
|
157
|
-
|
|
176
|
+
this.websocketConnectorRpcCommunicator!.destroy()
|
|
177
|
+
await this.websocketServerConnector!.destroy()
|
|
178
|
+
await this.websocketClientConnector!.destroy()
|
|
158
179
|
await this.webrtcConnector!.stop()
|
|
159
180
|
}
|
|
160
181
|
}
|
|
@@ -170,7 +191,9 @@ export class SimulatorConnectorFacade implements ConnectorFacade {
|
|
|
170
191
|
this.simulator = simulator
|
|
171
192
|
}
|
|
172
193
|
|
|
173
|
-
async start(
|
|
194
|
+
async start(
|
|
195
|
+
onNewConnection: (connection: PendingConnection) => boolean,
|
|
196
|
+
): Promise<void> {
|
|
174
197
|
logger.trace(`Creating SimulatorConnector`)
|
|
175
198
|
this.simulatorConnector = new SimulatorConnector(
|
|
176
199
|
this.localPeerDescriptor,
|
|
@@ -180,7 +203,7 @@ export class SimulatorConnectorFacade implements ConnectorFacade {
|
|
|
180
203
|
this.simulator.addConnector(this.simulatorConnector)
|
|
181
204
|
}
|
|
182
205
|
|
|
183
|
-
createConnection(peerDescriptor: PeerDescriptor):
|
|
206
|
+
createConnection(peerDescriptor: PeerDescriptor): PendingConnection {
|
|
184
207
|
return this.simulatorConnector!.connect(peerDescriptor)
|
|
185
208
|
}
|
|
186
209
|
|
|
@@ -4,6 +4,8 @@ import { v4 } from 'uuid'
|
|
|
4
4
|
import { Message, HandshakeRequest, HandshakeResponse, PeerDescriptor, HandshakeError } from '../proto/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { IConnection } from './IConnection'
|
|
6
6
|
import { LOCAL_PROTOCOL_VERSION, isMaybeSupportedVersion } from '../helpers/version'
|
|
7
|
+
import { getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
8
|
+
import { PendingConnection } from './PendingConnection'
|
|
7
9
|
|
|
8
10
|
const logger = new Logger(module)
|
|
9
11
|
|
|
@@ -13,9 +15,134 @@ interface HandshakerEvents {
|
|
|
13
15
|
handshakeFailed: (error?: HandshakeError) => void
|
|
14
16
|
}
|
|
15
17
|
|
|
18
|
+
// Optimally the Outgoing and Incoming Handshakers could be their own separate classes
|
|
19
|
+
// However, in cases where the PeerDescriptor of the other end of the connection can be known
|
|
20
|
+
// only after a HandshakeRequest a base Handshaker class is needed as the IncomingHandshaker currently
|
|
21
|
+
// requires knowledge of the other ends PeerDescriptor. (Note PendingConnection requires the remote PeerDescriptor)
|
|
22
|
+
export const createOutgoingHandshaker = (
|
|
23
|
+
localPeerDescriptor: PeerDescriptor,
|
|
24
|
+
pendingConnection: PendingConnection,
|
|
25
|
+
connection: IConnection,
|
|
26
|
+
targetPeerDescriptor?: PeerDescriptor
|
|
27
|
+
): Handshaker => {
|
|
28
|
+
const handshaker = new Handshaker(localPeerDescriptor, connection)
|
|
29
|
+
const stopHandshaker = () => {
|
|
30
|
+
handshaker.stop()
|
|
31
|
+
connection.off('disconnected', disconnectedListener)
|
|
32
|
+
connection.off('connected', connectedListener)
|
|
33
|
+
handshaker.off('handshakeCompleted', handshakeCompletedListener)
|
|
34
|
+
handshaker.off('handshakeFailed', handshakeFailedListener)
|
|
35
|
+
pendingConnection.off('disconnected', managedConnectionDisconnectedListener)
|
|
36
|
+
}
|
|
37
|
+
const handshakeFailedListener = (error?: HandshakeError) => {
|
|
38
|
+
if (error === HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR || error === HandshakeError.UNSUPPORTED_VERSION) {
|
|
39
|
+
pendingConnection.close(false)
|
|
40
|
+
stopHandshaker()
|
|
41
|
+
} else {
|
|
42
|
+
// Wait for the other end to close the connection
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const handshakeCompletedListener = (peerDescriptor: PeerDescriptor) => {
|
|
46
|
+
logger.trace('handshake completed for outgoing connection, ' + getNodeIdFromPeerDescriptor(peerDescriptor))
|
|
47
|
+
pendingConnection.onHandshakeCompleted(connection)
|
|
48
|
+
stopHandshaker()
|
|
49
|
+
}
|
|
50
|
+
const connectedListener = () => handshaker.sendHandshakeRequest(targetPeerDescriptor)
|
|
51
|
+
const disconnectedListener = (graceful: boolean) => {
|
|
52
|
+
pendingConnection.close(graceful)
|
|
53
|
+
stopHandshaker()
|
|
54
|
+
}
|
|
55
|
+
const managedConnectionDisconnectedListener = () => {
|
|
56
|
+
connection.close(false)
|
|
57
|
+
stopHandshaker()
|
|
58
|
+
}
|
|
59
|
+
handshaker.once('handshakeFailed', handshakeFailedListener)
|
|
60
|
+
handshaker.once('handshakeCompleted', handshakeCompletedListener)
|
|
61
|
+
connection.once('connected', connectedListener)
|
|
62
|
+
connection.once('disconnected', disconnectedListener)
|
|
63
|
+
pendingConnection.once('disconnected', managedConnectionDisconnectedListener)
|
|
64
|
+
return handshaker
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
export const createIncomingHandshaker = (
|
|
68
|
+
localPeerDescriptor: PeerDescriptor,
|
|
69
|
+
pendingConnection: PendingConnection,
|
|
70
|
+
connection: IConnection
|
|
71
|
+
): Handshaker => {
|
|
72
|
+
const handshaker = new Handshaker(localPeerDescriptor, connection)
|
|
73
|
+
const stopHandshaker = () => {
|
|
74
|
+
handshaker.stop()
|
|
75
|
+
pendingConnection.off('disconnected', connectionDisconnected)
|
|
76
|
+
connection.off('disconnected', connectionDisconnected)
|
|
77
|
+
}
|
|
78
|
+
const onHandshakeRequest = (): void => {
|
|
79
|
+
stopHandshaker()
|
|
80
|
+
}
|
|
81
|
+
const connectionDisconnected = (graceful: boolean) => {
|
|
82
|
+
pendingConnection.close(graceful)
|
|
83
|
+
stopHandshaker()
|
|
84
|
+
}
|
|
85
|
+
const managedConnectionDisconnected = () => {
|
|
86
|
+
connection.close(false)
|
|
87
|
+
stopHandshaker()
|
|
88
|
+
}
|
|
89
|
+
handshaker.on('handshakeRequest', onHandshakeRequest)
|
|
90
|
+
connection.once('disconnected', connectionDisconnected)
|
|
91
|
+
pendingConnection.once('disconnected', managedConnectionDisconnected)
|
|
92
|
+
return handshaker
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export const rejectHandshake = (
|
|
96
|
+
pendingConnection: PendingConnection,
|
|
97
|
+
connection: IConnection,
|
|
98
|
+
handshaker: Handshaker,
|
|
99
|
+
error: HandshakeError
|
|
100
|
+
): void => {
|
|
101
|
+
handshaker.sendHandshakeResponse(error)
|
|
102
|
+
connection.destroy()
|
|
103
|
+
pendingConnection.destroy()
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export const acceptHandshake = (handshaker: Handshaker, pendingConnection: PendingConnection, connection: IConnection): void => {
|
|
107
|
+
handshaker.sendHandshakeResponse()
|
|
108
|
+
pendingConnection.onHandshakeCompleted(connection)
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
export const createHandshakeRequest = (localPeerDescriptor: PeerDescriptor, remotePeerDescriptor: PeerDescriptor): Message => {
|
|
112
|
+
const outgoingHandshake: HandshakeRequest = {
|
|
113
|
+
sourcePeerDescriptor: localPeerDescriptor,
|
|
114
|
+
targetPeerDescriptor: remotePeerDescriptor,
|
|
115
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
116
|
+
}
|
|
117
|
+
return {
|
|
118
|
+
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
119
|
+
messageId: v4(),
|
|
120
|
+
body: {
|
|
121
|
+
oneofKind: 'handshakeRequest',
|
|
122
|
+
handshakeRequest: outgoingHandshake
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
export const createHandshakeResponse = (localPeerDescriptor: PeerDescriptor, error?: HandshakeError): Message => {
|
|
128
|
+
const outgoingHandshakeResponse: HandshakeResponse = {
|
|
129
|
+
sourcePeerDescriptor: localPeerDescriptor,
|
|
130
|
+
error,
|
|
131
|
+
version: LOCAL_PROTOCOL_VERSION
|
|
132
|
+
}
|
|
133
|
+
return {
|
|
134
|
+
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
135
|
+
messageId: v4(),
|
|
136
|
+
body: {
|
|
137
|
+
oneofKind: 'handshakeResponse',
|
|
138
|
+
handshakeResponse: outgoingHandshakeResponse
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
16
143
|
export class Handshaker extends EventEmitter<HandshakerEvents> {
|
|
17
144
|
|
|
18
|
-
|
|
145
|
+
public static readonly HANDSHAKER_SERVICE_ID = 'system/handshaker'
|
|
19
146
|
private localPeerDescriptor: PeerDescriptor
|
|
20
147
|
private connection: IConnection
|
|
21
148
|
private readonly onDataListener: (data: Uint8Array) => void
|
|
@@ -60,42 +187,19 @@ export class Handshaker extends EventEmitter<HandshakerEvents> {
|
|
|
60
187
|
}
|
|
61
188
|
|
|
62
189
|
public sendHandshakeRequest(remotePeerDescriptor?: PeerDescriptor): void {
|
|
63
|
-
const
|
|
64
|
-
sourcePeerDescriptor: this.localPeerDescriptor,
|
|
65
|
-
targetPeerDescriptor: remotePeerDescriptor,
|
|
66
|
-
version: LOCAL_PROTOCOL_VERSION
|
|
67
|
-
}
|
|
68
|
-
const msg: Message = {
|
|
69
|
-
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
70
|
-
messageId: v4(),
|
|
71
|
-
body: {
|
|
72
|
-
oneofKind: 'handshakeRequest',
|
|
73
|
-
handshakeRequest: outgoingHandshake
|
|
74
|
-
}
|
|
75
|
-
}
|
|
190
|
+
const msg = createHandshakeRequest(this.localPeerDescriptor, remotePeerDescriptor!)
|
|
76
191
|
this.connection.send(Message.toBinary(msg))
|
|
77
192
|
logger.trace('handshake request sent')
|
|
78
193
|
}
|
|
79
194
|
|
|
80
195
|
public sendHandshakeResponse(error?: HandshakeError): void {
|
|
81
|
-
const
|
|
82
|
-
sourcePeerDescriptor: this.localPeerDescriptor,
|
|
83
|
-
error,
|
|
84
|
-
version: LOCAL_PROTOCOL_VERSION
|
|
85
|
-
}
|
|
86
|
-
const msg: Message = {
|
|
87
|
-
serviceId: Handshaker.HANDSHAKER_SERVICE_ID,
|
|
88
|
-
messageId: v4(),
|
|
89
|
-
body: {
|
|
90
|
-
oneofKind: 'handshakeResponse',
|
|
91
|
-
handshakeResponse: outgoingHandshakeResponse
|
|
92
|
-
}
|
|
93
|
-
}
|
|
196
|
+
const msg = createHandshakeResponse(this.localPeerDescriptor, error)
|
|
94
197
|
this.connection.send(Message.toBinary(msg))
|
|
95
198
|
logger.trace('handshake response sent')
|
|
96
199
|
}
|
|
97
200
|
|
|
98
201
|
public stop(): void {
|
|
99
202
|
this.connection.off('data', this.onDataListener)
|
|
203
|
+
this.removeAllListeners()
|
|
100
204
|
}
|
|
101
205
|
}
|