@streamr/dht 100.2.5-beta.0 → 101.0.0-beta.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/package.json +7 -7
- 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 +7 -7
- 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
|
@@ -21,16 +21,16 @@ class WebsocketServer extends eventemitter3_1.default {
|
|
|
21
21
|
httpServer;
|
|
22
22
|
wsServer;
|
|
23
23
|
abortController = new AbortController();
|
|
24
|
-
|
|
25
|
-
constructor(
|
|
24
|
+
options;
|
|
25
|
+
constructor(options) {
|
|
26
26
|
super();
|
|
27
|
-
this.
|
|
27
|
+
this.options = options;
|
|
28
28
|
}
|
|
29
29
|
async start() {
|
|
30
|
-
const ports = (0, lodash_1.range)(this.
|
|
30
|
+
const ports = (0, lodash_1.range)(this.options.portRange.min, this.options.portRange.max + 1);
|
|
31
31
|
for (const port of ports) {
|
|
32
32
|
try {
|
|
33
|
-
await (0, utils_1.asAbortable)(this.startServer(port, this.
|
|
33
|
+
await (0, utils_1.asAbortable)(this.startServer(port, this.options.enableTls), this.abortController.signal);
|
|
34
34
|
return port;
|
|
35
35
|
}
|
|
36
36
|
catch (err) {
|
|
@@ -42,7 +42,7 @@ class WebsocketServer extends eventemitter3_1.default {
|
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
44
|
}
|
|
45
|
-
throw new errors_1.WebsocketServerStartError(`Failed to start WebSocket server on any port in range: ${this.
|
|
45
|
+
throw new errors_1.WebsocketServerStartError(`Failed to start WebSocket server on any port in range: ${this.options.portRange.min}-${this.options.portRange.min}`);
|
|
46
46
|
}
|
|
47
47
|
// If tlsCertificate has been given the tls boolean is ignored
|
|
48
48
|
// TODO: could be simplified?
|
|
@@ -53,17 +53,17 @@ class WebsocketServer extends eventemitter3_1.default {
|
|
|
53
53
|
response.end();
|
|
54
54
|
};
|
|
55
55
|
return new Promise((resolve, reject) => {
|
|
56
|
-
if (this.
|
|
56
|
+
if (this.options.tlsCertificate) {
|
|
57
57
|
this.httpServer = (0, https_1.createServer)({
|
|
58
|
-
key: fs_1.default.readFileSync(this.
|
|
59
|
-
cert: fs_1.default.readFileSync(this.
|
|
58
|
+
key: fs_1.default.readFileSync(this.options.tlsCertificate.privateKeyFileName),
|
|
59
|
+
cert: fs_1.default.readFileSync(this.options.tlsCertificate.certFileName)
|
|
60
60
|
}, requestListener);
|
|
61
61
|
}
|
|
62
62
|
else if (!tls) {
|
|
63
63
|
this.httpServer = (0, http_1.createServer)(requestListener);
|
|
64
64
|
}
|
|
65
65
|
else {
|
|
66
|
-
// TODO use
|
|
66
|
+
// TODO use options option or named constant?
|
|
67
67
|
const certificate = (0, autocertifier_client_1.createSelfSignedCertificate)('streamr-self-signed-' + (0, uuid_1.v4)(), 1000);
|
|
68
68
|
this.httpServer = (0, https_1.createServer)({
|
|
69
69
|
key: certificate.serverKey,
|
|
@@ -135,7 +135,7 @@ class WebsocketServer extends eventemitter3_1.default {
|
|
|
135
135
|
});
|
|
136
136
|
}
|
|
137
137
|
createWsServer() {
|
|
138
|
-
const maxPayload = this.
|
|
138
|
+
const maxPayload = this.options.maxMessageSize ?? 1048576;
|
|
139
139
|
return this.wsServer = new ws_1.default.Server({
|
|
140
140
|
noServer: true,
|
|
141
141
|
maxPayload
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketServer.js","sourceRoot":"","sources":["../../../../src/connection/websocket/WebsocketServer.ts"],"names":[],"mappings":";;;;;;AAAA,+BAA8G;AAC9G,iCAAgF;AAChF,kEAAwC;AACxC,4CAA0B;AAC1B,2EAAuE;
|
|
1
|
+
{"version":3,"file":"WebsocketServer.js","sourceRoot":"","sources":["../../../../src/connection/websocket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A;YACF,IAAI,CAAC,UAAU,EAAE,KAAK,EAAE,CAAA;YACxB,oFAAoF;YACpF,yFAAyF;YACzF,oEAAoE;YACpE,kFAAkF;YAClF,6DAA6D;YAC7D,IAAI,CAAC,UAAU,EAAE,mBAAmB,EAAE,CAAA;QAC1C,CAAC,CAAC,CAAA;IACN,CAAC;IAEO,cAAc;QAClB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,cAAc,IAAI,OAAO,CAAA;QACzD,OAAO,IAAI,CAAC,QAAQ,GAAG,IAAI,YAAS,CAAC,MAAM,CAAC;YACxC,QAAQ,EAAE,IAAI;YACd,UAAU;SACb,CAAC,CAAA;IACN,CAAC;CACJ;AAvID,0CAuIC"}
|
package/dist/src/connection/websocket/{WebsocketConnector.d.ts → WebsocketServerConnector.d.ts}
RENAMED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { ConnectivityMethod, ConnectivityResponse, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
3
|
-
import { ManagedConnection } from '../ManagedConnection';
|
|
4
|
-
import { PortRange, TlsCertificate } from '../ConnectionManager';
|
|
1
|
+
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator';
|
|
5
2
|
import { DhtAddress } from '../../identifiers';
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
3
|
+
import { ConnectivityResponse, PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc';
|
|
4
|
+
import { PortRange, TlsCertificate } from '../ConnectionManager';
|
|
5
|
+
import { ITransport } from '../../transport/ITransport';
|
|
6
|
+
import { PendingConnection } from '../PendingConnection';
|
|
7
|
+
export interface WebsocketServerConnectorOptions {
|
|
8
|
+
onNewConnection: (connection: PendingConnection) => boolean;
|
|
9
|
+
rpcCommunicator: ListeningRpcCommunicator;
|
|
11
10
|
hasConnection: (nodeId: DhtAddress) => boolean;
|
|
12
11
|
portRange?: PortRange;
|
|
13
12
|
maxMessageSize?: number;
|
|
@@ -20,9 +19,7 @@ export interface WebsocketConnectorConfig {
|
|
|
20
19
|
serverEnableTls: boolean;
|
|
21
20
|
geoIpDatabaseFolder?: string;
|
|
22
21
|
}
|
|
23
|
-
export declare class
|
|
24
|
-
private static readonly WEBSOCKET_CONNECTOR_SERVICE_ID;
|
|
25
|
-
private readonly rpcCommunicator;
|
|
22
|
+
export declare class WebsocketServerConnector {
|
|
26
23
|
private readonly websocketServer?;
|
|
27
24
|
private geoIpLocator?;
|
|
28
25
|
private readonly ongoingConnectRequests;
|
|
@@ -30,20 +27,18 @@ export declare class WebsocketConnector {
|
|
|
30
27
|
private autoCertifierClient?;
|
|
31
28
|
private selectedPort?;
|
|
32
29
|
private localPeerDescriptor?;
|
|
33
|
-
private connectingConnections;
|
|
34
30
|
private abortController;
|
|
35
|
-
private readonly
|
|
36
|
-
constructor(
|
|
37
|
-
|
|
31
|
+
private readonly options;
|
|
32
|
+
constructor(options: WebsocketServerConnectorOptions);
|
|
33
|
+
start(): Promise<void>;
|
|
38
34
|
private attachHandshaker;
|
|
35
|
+
private onServerSocketHandshakeRequest;
|
|
36
|
+
checkConnectivity(allowSelfSignedCertificate: boolean): Promise<ConnectivityResponse>;
|
|
39
37
|
autoCertify(): Promise<void>;
|
|
40
38
|
private setHost;
|
|
41
|
-
|
|
42
|
-
checkConnectivity(allowSelfSignedCertificate: boolean): Promise<ConnectivityResponse>;
|
|
43
|
-
isPossibleToFormConnection(targetPeerDescriptor: PeerDescriptor): boolean;
|
|
44
|
-
connect(targetPeerDescriptor: PeerDescriptor): ManagedConnection;
|
|
39
|
+
connect(targetPeerDescriptor: PeerDescriptor): PendingConnection;
|
|
45
40
|
private requestConnectionFromPeer;
|
|
46
|
-
|
|
41
|
+
isPossibleToFormConnection(targetPeerDescriptor: PeerDescriptor): boolean;
|
|
47
42
|
setLocalPeerDescriptor(localPeerDescriptor: PeerDescriptor): void;
|
|
48
43
|
destroy(): Promise<void>;
|
|
49
44
|
}
|
|
@@ -26,38 +26,31 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const ListeningRpcCommunicator_1 = require("../../transport/ListeningRpcCommunicator");
|
|
33
|
-
const WebsocketConnectorRpcLocal_1 = require("./WebsocketConnectorRpcLocal");
|
|
34
|
-
const WebsocketConnectorRpcRemote_1 = require("./WebsocketConnectorRpcRemote");
|
|
35
|
-
const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
36
|
-
const DhtRpc_client_1 = require("../../proto/packages/dht/protos/DhtRpc.client");
|
|
37
|
-
const utils_1 = require("@streamr/utils");
|
|
38
|
-
const ManagedConnection_1 = require("../ManagedConnection");
|
|
29
|
+
exports.WebsocketServerConnector = void 0;
|
|
30
|
+
const geoip_location_1 = require("@streamr/geoip-location");
|
|
31
|
+
const WebsocketClientConnector_1 = require("./WebsocketClientConnector");
|
|
39
32
|
const WebsocketServer_1 = require("./WebsocketServer");
|
|
40
|
-
const
|
|
33
|
+
const identifiers_1 = require("../../identifiers");
|
|
34
|
+
const AutoCertifierClientFacade_1 = require("./AutoCertifierClientFacade");
|
|
35
|
+
const DhtRpc_1 = require("../../proto/packages/dht/protos/DhtRpc");
|
|
41
36
|
const ConnectionManager_1 = require("../ConnectionManager");
|
|
42
|
-
const
|
|
37
|
+
const utils_1 = require("@streamr/utils");
|
|
38
|
+
const connectivityRequestHandler_1 = require("../connectivityRequestHandler");
|
|
39
|
+
const IConnection_1 = require("../IConnection");
|
|
43
40
|
const querystring_1 = __importDefault(require("querystring"));
|
|
41
|
+
const version_1 = require("../../helpers/version");
|
|
44
42
|
const lodash_1 = require("lodash");
|
|
45
|
-
const
|
|
43
|
+
const connectivityChecker_1 = require("../connectivityChecker");
|
|
44
|
+
const Handshaker_1 = require("../Handshaker");
|
|
45
|
+
const WebsocketClientConnectorRpcRemote_1 = require("./WebsocketClientConnectorRpcRemote");
|
|
46
|
+
const DhtRpc_client_1 = require("../../proto/packages/dht/protos/DhtRpc.client");
|
|
46
47
|
const errors_1 = require("../../helpers/errors");
|
|
47
|
-
const AutoCertifierClientFacade_1 = require("./AutoCertifierClientFacade");
|
|
48
|
-
const connectivityRequestHandler_1 = require("../connectivityRequestHandler");
|
|
49
48
|
const Err = __importStar(require("../../helpers/errors"));
|
|
50
|
-
const
|
|
51
|
-
const
|
|
52
|
-
const geoip_location_1 = require("@streamr/geoip-location");
|
|
49
|
+
const Connectivity_1 = require("../../helpers/Connectivity");
|
|
50
|
+
const PendingConnection_1 = require("../PendingConnection");
|
|
53
51
|
const logger = new utils_1.Logger(module);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
};
|
|
57
|
-
exports.connectivityMethodToWebsocketUrl = connectivityMethodToWebsocketUrl;
|
|
58
|
-
class WebsocketConnector {
|
|
59
|
-
static WEBSOCKET_CONNECTOR_SERVICE_ID = 'system/websocket-connector';
|
|
60
|
-
rpcCommunicator;
|
|
52
|
+
// TODO: Move server starting logic including autocertification and connectivity checking to WebsocketServer.ts?
|
|
53
|
+
class WebsocketServerConnector {
|
|
61
54
|
websocketServer;
|
|
62
55
|
geoIpLocator;
|
|
63
56
|
ongoingConnectRequests = new Map();
|
|
@@ -65,62 +58,17 @@ class WebsocketConnector {
|
|
|
65
58
|
autoCertifierClient;
|
|
66
59
|
selectedPort;
|
|
67
60
|
localPeerDescriptor;
|
|
68
|
-
connectingConnections = new Map();
|
|
69
61
|
abortController = new AbortController();
|
|
70
|
-
|
|
71
|
-
constructor(
|
|
72
|
-
this.
|
|
73
|
-
this.websocketServer =
|
|
74
|
-
portRange:
|
|
75
|
-
tlsCertificate:
|
|
76
|
-
maxMessageSize:
|
|
77
|
-
enableTls:
|
|
62
|
+
options;
|
|
63
|
+
constructor(options) {
|
|
64
|
+
this.options = options;
|
|
65
|
+
this.websocketServer = options.portRange ? new WebsocketServer_1.WebsocketServer({
|
|
66
|
+
portRange: options.portRange,
|
|
67
|
+
tlsCertificate: options.tlsCertificate,
|
|
68
|
+
maxMessageSize: options.maxMessageSize,
|
|
69
|
+
enableTls: options.serverEnableTls
|
|
78
70
|
}) : undefined;
|
|
79
|
-
this.host =
|
|
80
|
-
this.rpcCommunicator = new ListeningRpcCommunicator_1.ListeningRpcCommunicator(WebsocketConnector.WEBSOCKET_CONNECTOR_SERVICE_ID, config.transport, {
|
|
81
|
-
rpcRequestTimeout: 15000 // TODO use config option or named constant?
|
|
82
|
-
});
|
|
83
|
-
this.registerLocalRpcMethods(config);
|
|
84
|
-
}
|
|
85
|
-
registerLocalRpcMethods(config) {
|
|
86
|
-
const rpcLocal = new WebsocketConnectorRpcLocal_1.WebsocketConnectorRpcLocal({
|
|
87
|
-
connect: (targetPeerDescriptor) => this.connect(targetPeerDescriptor),
|
|
88
|
-
hasConnection: (nodeId) => (this.connectingConnections.has(nodeId)
|
|
89
|
-
|| this.ongoingConnectRequests.has(nodeId)
|
|
90
|
-
|| config.hasConnection(nodeId)),
|
|
91
|
-
onNewConnection: (connection) => config.onNewConnection(connection),
|
|
92
|
-
abortSignal: this.abortController.signal
|
|
93
|
-
});
|
|
94
|
-
this.rpcCommunicator.registerRpcNotification(DhtRpc_1.WebsocketConnectionRequest, 'requestConnection', async (req, context) => {
|
|
95
|
-
if (!this.abortController.signal.aborted) {
|
|
96
|
-
return rpcLocal.requestConnection(req, context);
|
|
97
|
-
}
|
|
98
|
-
else {
|
|
99
|
-
return {};
|
|
100
|
-
}
|
|
101
|
-
});
|
|
102
|
-
}
|
|
103
|
-
attachHandshaker(connection) {
|
|
104
|
-
const handshaker = new Handshaker_1.Handshaker(this.localPeerDescriptor, connection);
|
|
105
|
-
handshaker.once('handshakeRequest', (localPeerDescriptor, sourceVersion, remotePeerDescriptor) => {
|
|
106
|
-
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, sourceVersion, remotePeerDescriptor);
|
|
107
|
-
});
|
|
108
|
-
}
|
|
109
|
-
async autoCertify() {
|
|
110
|
-
this.autoCertifierClient = new AutoCertifierClientFacade_1.AutoCertifierClientFacade({
|
|
111
|
-
configFile: this.config.autoCertifierConfigFile,
|
|
112
|
-
transport: this.config.autoCertifierTransport,
|
|
113
|
-
url: this.config.autoCertifierUrl,
|
|
114
|
-
wsServerPort: this.selectedPort,
|
|
115
|
-
setHost: (hostName) => this.setHost(hostName),
|
|
116
|
-
updateCertificate: (certificate, privateKey) => this.websocketServer.updateCertificate(certificate, privateKey)
|
|
117
|
-
});
|
|
118
|
-
logger.trace(`AutoCertifying subdomain...`);
|
|
119
|
-
await this.autoCertifierClient.start();
|
|
120
|
-
}
|
|
121
|
-
setHost(hostName) {
|
|
122
|
-
logger.trace(`Setting host name to ${hostName}`);
|
|
123
|
-
this.host = hostName;
|
|
71
|
+
this.host = options.host;
|
|
124
72
|
}
|
|
125
73
|
async start() {
|
|
126
74
|
if (!this.abortController.signal.aborted && this.websocketServer) {
|
|
@@ -149,8 +97,8 @@ class WebsocketConnector {
|
|
|
149
97
|
}
|
|
150
98
|
}
|
|
151
99
|
});
|
|
152
|
-
if (this.
|
|
153
|
-
const geoIpLocator = new geoip_location_1.GeoIpLocator(this.
|
|
100
|
+
if (this.options.geoIpDatabaseFolder) {
|
|
101
|
+
const geoIpLocator = new geoip_location_1.GeoIpLocator(this.options.geoIpDatabaseFolder);
|
|
154
102
|
try {
|
|
155
103
|
await geoIpLocator.start();
|
|
156
104
|
this.geoIpLocator = geoIpLocator;
|
|
@@ -163,6 +111,45 @@ class WebsocketConnector {
|
|
|
163
111
|
this.selectedPort = port;
|
|
164
112
|
}
|
|
165
113
|
}
|
|
114
|
+
attachHandshaker(connection) {
|
|
115
|
+
// TODO: use createIncomingHandshaker here?
|
|
116
|
+
const handshaker = new Handshaker_1.Handshaker(this.localPeerDescriptor, connection);
|
|
117
|
+
handshaker.once('handshakeRequest', (localPeerDescriptor, sourceVersion, remotePeerDescriptor) => {
|
|
118
|
+
this.onServerSocketHandshakeRequest(localPeerDescriptor, connection, handshaker, sourceVersion, remotePeerDescriptor);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
onServerSocketHandshakeRequest(sourcePeerDescriptor, websocketServerConnection, handshaker, remoteVersion, targetPeerDescriptor) {
|
|
122
|
+
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(sourcePeerDescriptor);
|
|
123
|
+
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
124
|
+
const { pendingConnection, delFunc } = this.ongoingConnectRequests.get(nodeId);
|
|
125
|
+
if (!(0, version_1.isMaybeSupportedVersion)(remoteVersion)) {
|
|
126
|
+
(0, Handshaker_1.rejectHandshake)(pendingConnection, websocketServerConnection, handshaker, DhtRpc_1.HandshakeError.UNSUPPORTED_VERSION);
|
|
127
|
+
delFunc();
|
|
128
|
+
}
|
|
129
|
+
else if (targetPeerDescriptor && !(0, identifiers_1.areEqualPeerDescriptors)(this.localPeerDescriptor, targetPeerDescriptor)) {
|
|
130
|
+
(0, Handshaker_1.rejectHandshake)(pendingConnection, websocketServerConnection, handshaker, DhtRpc_1.HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR);
|
|
131
|
+
delFunc();
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
(0, Handshaker_1.acceptHandshake)(handshaker, pendingConnection, websocketServerConnection);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
const pendingConnection = new PendingConnection_1.PendingConnection(sourcePeerDescriptor);
|
|
139
|
+
if (!(0, version_1.isMaybeSupportedVersion)(remoteVersion)) {
|
|
140
|
+
(0, Handshaker_1.rejectHandshake)(pendingConnection, websocketServerConnection, handshaker, DhtRpc_1.HandshakeError.UNSUPPORTED_VERSION);
|
|
141
|
+
}
|
|
142
|
+
else if (targetPeerDescriptor && !(0, identifiers_1.areEqualPeerDescriptors)(this.localPeerDescriptor, targetPeerDescriptor)) {
|
|
143
|
+
(0, Handshaker_1.rejectHandshake)(pendingConnection, websocketServerConnection, handshaker, DhtRpc_1.HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR);
|
|
144
|
+
}
|
|
145
|
+
else if (this.options.onNewConnection(pendingConnection)) {
|
|
146
|
+
(0, Handshaker_1.acceptHandshake)(handshaker, pendingConnection, websocketServerConnection);
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
(0, Handshaker_1.rejectHandshake)(pendingConnection, websocketServerConnection, handshaker, DhtRpc_1.HandshakeError.DUPLICATE_CONNECTION);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
166
153
|
async checkConnectivity(allowSelfSignedCertificate) {
|
|
167
154
|
// TODO: this could throw?
|
|
168
155
|
if (this.abortController.signal.aborted) {
|
|
@@ -173,22 +160,22 @@ class WebsocketConnector {
|
|
|
173
160
|
version: version_1.LOCAL_PROTOCOL_VERSION
|
|
174
161
|
};
|
|
175
162
|
}
|
|
176
|
-
if (!this.
|
|
177
|
-
// return connectivity info given in
|
|
163
|
+
if (!this.options.entrypoints || this.options.entrypoints.length === 0) {
|
|
164
|
+
// return connectivity info given in options
|
|
178
165
|
return {
|
|
179
166
|
host: this.host,
|
|
180
167
|
natType: ConnectionManager_1.NatType.OPEN_INTERNET,
|
|
181
168
|
websocket: {
|
|
182
169
|
host: this.host,
|
|
183
170
|
port: this.selectedPort,
|
|
184
|
-
tls: this.
|
|
171
|
+
tls: this.options.tlsCertificate !== undefined
|
|
185
172
|
},
|
|
186
173
|
// TODO: Resolve the given host name or or use as is if IP was given.
|
|
187
174
|
ipAddress: (0, utils_1.ipv4ToNumber)('127.0.0.1'),
|
|
188
175
|
version: version_1.LOCAL_PROTOCOL_VERSION
|
|
189
176
|
};
|
|
190
177
|
}
|
|
191
|
-
const shuffledEntrypoints = (0, lodash_1.shuffle)(this.
|
|
178
|
+
const shuffledEntrypoints = (0, lodash_1.shuffle)(this.options.entrypoints);
|
|
192
179
|
while (shuffledEntrypoints.length > 0 && !this.abortController.signal.aborted) {
|
|
193
180
|
const entryPoint = shuffledEntrypoints[0];
|
|
194
181
|
try {
|
|
@@ -196,7 +183,7 @@ class WebsocketConnector {
|
|
|
196
183
|
const connectivityRequest = {
|
|
197
184
|
port: this.selectedPort ?? connectivityRequestHandler_1.DISABLE_CONNECTIVITY_PROBE,
|
|
198
185
|
host: this.host,
|
|
199
|
-
tls: this.websocketServer ? this.
|
|
186
|
+
tls: this.websocketServer ? this.options.serverEnableTls : false,
|
|
200
187
|
allowSelfSignedCertificate
|
|
201
188
|
};
|
|
202
189
|
if (!this.abortController.signal.aborted) {
|
|
@@ -208,50 +195,41 @@ class WebsocketConnector {
|
|
|
208
195
|
}
|
|
209
196
|
catch (err) {
|
|
210
197
|
const error = `Failed to connect to entrypoint with id ${(0, identifiers_1.getNodeIdFromPeerDescriptor)(entryPoint)} `
|
|
211
|
-
+ `and URL ${(0,
|
|
198
|
+
+ `and URL ${(0, WebsocketClientConnector_1.connectivityMethodToWebsocketUrl)(entryPoint.websocket)}`;
|
|
212
199
|
logger.error(error, { err });
|
|
213
200
|
shuffledEntrypoints.shift();
|
|
214
201
|
await (0, utils_1.wait)(2000, this.abortController.signal);
|
|
215
202
|
}
|
|
216
203
|
}
|
|
217
|
-
throw new errors_1.WebsocketServerStartError(`Failed to connect to the entrypoints after ${this.
|
|
218
|
-
+ `Attempted hosts: ${this.
|
|
204
|
+
throw new errors_1.WebsocketServerStartError(`Failed to connect to the entrypoints after ${this.options.entrypoints.length} attempts\n`
|
|
205
|
+
+ `Attempted hosts: ${this.options.entrypoints.map((entry) => `${entry.websocket.host}:${entry.websocket.port}`).join(', ')}`);
|
|
219
206
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
207
|
+
async autoCertify() {
|
|
208
|
+
this.autoCertifierClient = new AutoCertifierClientFacade_1.AutoCertifierClientFacade({
|
|
209
|
+
configFile: this.options.autoCertifierConfigFile,
|
|
210
|
+
transport: this.options.autoCertifierTransport,
|
|
211
|
+
url: this.options.autoCertifierUrl,
|
|
212
|
+
wsServerPort: this.selectedPort,
|
|
213
|
+
setHost: (hostName) => this.setHost(hostName),
|
|
214
|
+
updateCertificate: (certificate, privateKey) => this.websocketServer.updateCertificate(certificate, privateKey)
|
|
215
|
+
});
|
|
216
|
+
logger.trace(`AutoCertifying subdomain...`);
|
|
217
|
+
await this.autoCertifierClient.start();
|
|
218
|
+
}
|
|
219
|
+
setHost(hostName) {
|
|
220
|
+
logger.trace(`Setting host name to ${hostName}`);
|
|
221
|
+
this.host = hostName;
|
|
223
222
|
}
|
|
224
223
|
connect(targetPeerDescriptor) {
|
|
225
224
|
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(targetPeerDescriptor);
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return existingConnection;
|
|
229
|
-
}
|
|
230
|
-
if (this.localPeerDescriptor.websocket && !targetPeerDescriptor.websocket) {
|
|
231
|
-
return this.requestConnectionFromPeer(this.localPeerDescriptor, targetPeerDescriptor);
|
|
232
|
-
}
|
|
233
|
-
else {
|
|
234
|
-
const socket = new NodeWebsocketClientConnection_1.WebsocketClientConnection();
|
|
235
|
-
const url = (0, exports.connectivityMethodToWebsocketUrl)(targetPeerDescriptor.websocket);
|
|
236
|
-
const managedConnection = new ManagedConnection_1.ManagedConnection(this.localPeerDescriptor, IConnection_1.ConnectionType.WEBSOCKET_CLIENT, socket, undefined, targetPeerDescriptor);
|
|
237
|
-
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor);
|
|
238
|
-
this.connectingConnections.set(nodeId, managedConnection);
|
|
239
|
-
const delFunc = () => {
|
|
240
|
-
if (this.connectingConnections.has(nodeId)) {
|
|
241
|
-
this.connectingConnections.delete(nodeId);
|
|
242
|
-
}
|
|
243
|
-
socket.off('disconnected', delFunc);
|
|
244
|
-
managedConnection.off('handshakeCompleted', delFunc);
|
|
245
|
-
};
|
|
246
|
-
socket.on('disconnected', delFunc);
|
|
247
|
-
managedConnection.on('handshakeCompleted', delFunc);
|
|
248
|
-
socket.connect(url, false);
|
|
249
|
-
return managedConnection;
|
|
225
|
+
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
226
|
+
return this.ongoingConnectRequests.get(nodeId).pendingConnection;
|
|
250
227
|
}
|
|
228
|
+
return this.requestConnectionFromPeer(this.localPeerDescriptor, targetPeerDescriptor);
|
|
251
229
|
}
|
|
252
230
|
requestConnectionFromPeer(localPeerDescriptor, targetPeerDescriptor) {
|
|
253
231
|
setImmediate(() => {
|
|
254
|
-
const remoteConnector = new
|
|
232
|
+
const remoteConnector = new WebsocketClientConnectorRpcRemote_1.WebsocketClientConnectorRpcRemote(localPeerDescriptor, targetPeerDescriptor, this.options.rpcCommunicator, DhtRpc_client_1.WebsocketClientConnectorRpcClient);
|
|
255
233
|
remoteConnector.requestConnection().then(() => {
|
|
256
234
|
logger.trace('Sent WebsocketConnectionRequest notification to peer', { targetPeerDescriptor });
|
|
257
235
|
}, (err) => {
|
|
@@ -260,59 +238,33 @@ class WebsocketConnector {
|
|
|
260
238
|
});
|
|
261
239
|
});
|
|
262
240
|
});
|
|
263
|
-
const
|
|
241
|
+
const pendingConnection = new PendingConnection_1.PendingConnection(targetPeerDescriptor);
|
|
264
242
|
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(targetPeerDescriptor);
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
onServerSocketHandshakeRequest(sourcePeerDescriptor, websocketServerConnection, remoteVersion, targetPeerDescriptor) {
|
|
271
|
-
const nodeId = (0, identifiers_1.getNodeIdFromPeerDescriptor)(sourcePeerDescriptor);
|
|
272
|
-
if (this.ongoingConnectRequests.has(nodeId)) {
|
|
273
|
-
const ongoingConnectRequest = this.ongoingConnectRequests.get(nodeId);
|
|
274
|
-
if (!(0, version_1.isMaybeSupportedVersion)(remoteVersion)) {
|
|
275
|
-
ongoingConnectRequest.rejectHandshake(DhtRpc_1.HandshakeError.UNSUPPORTED_VERSION);
|
|
276
|
-
}
|
|
277
|
-
else if (targetPeerDescriptor && !(0, identifiers_1.areEqualPeerDescriptors)(this.localPeerDescriptor, targetPeerDescriptor)) {
|
|
278
|
-
ongoingConnectRequest.rejectHandshake(DhtRpc_1.HandshakeError.INVALID_TARGET_PEER_DESCRIPTOR);
|
|
279
|
-
}
|
|
280
|
-
else {
|
|
281
|
-
ongoingConnectRequest.attachImplementation(websocketServerConnection);
|
|
282
|
-
ongoingConnectRequest.acceptHandshake();
|
|
283
|
-
}
|
|
243
|
+
// TODO: can this leak?
|
|
244
|
+
const delFunc = () => {
|
|
245
|
+
pendingConnection.off('connected', delFunc);
|
|
246
|
+
pendingConnection.off('disconnected', delFunc);
|
|
284
247
|
this.ongoingConnectRequests.delete(nodeId);
|
|
285
|
-
}
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
}
|
|
295
|
-
else if (this.config.onNewConnection(managedConnection)) {
|
|
296
|
-
managedConnection.acceptHandshake();
|
|
297
|
-
}
|
|
298
|
-
else {
|
|
299
|
-
managedConnection.rejectHandshake(DhtRpc_1.HandshakeError.DUPLICATE_CONNECTION);
|
|
300
|
-
}
|
|
301
|
-
}
|
|
248
|
+
};
|
|
249
|
+
pendingConnection.on('connected', delFunc);
|
|
250
|
+
pendingConnection.on('disconnected', delFunc);
|
|
251
|
+
this.ongoingConnectRequests.set(nodeId, { pendingConnection, delFunc });
|
|
252
|
+
return pendingConnection;
|
|
253
|
+
}
|
|
254
|
+
isPossibleToFormConnection(targetPeerDescriptor) {
|
|
255
|
+
const connectionType = (0, Connectivity_1.expectedConnectionType)(this.localPeerDescriptor, targetPeerDescriptor);
|
|
256
|
+
return (connectionType === IConnection_1.ConnectionType.WEBSOCKET_SERVER);
|
|
302
257
|
}
|
|
303
258
|
setLocalPeerDescriptor(localPeerDescriptor) {
|
|
304
259
|
this.localPeerDescriptor = localPeerDescriptor;
|
|
305
260
|
}
|
|
306
261
|
async destroy() {
|
|
307
262
|
this.abortController.abort();
|
|
308
|
-
this.rpcCommunicator.destroy();
|
|
309
263
|
const requests = Array.from(this.ongoingConnectRequests.values());
|
|
310
|
-
await Promise.allSettled(requests.map((
|
|
311
|
-
const attempts = Array.from(this.connectingConnections.values());
|
|
312
|
-
await Promise.allSettled(attempts.map((conn) => conn.close(false)));
|
|
264
|
+
await Promise.allSettled(requests.map((ongoingConnectRequest) => ongoingConnectRequest.pendingConnection.close(true)));
|
|
313
265
|
await this.websocketServer?.stop();
|
|
314
266
|
await this.geoIpLocator?.stop();
|
|
315
267
|
}
|
|
316
268
|
}
|
|
317
|
-
exports.
|
|
318
|
-
//# sourceMappingURL=
|
|
269
|
+
exports.WebsocketServerConnector = WebsocketServerConnector;
|
|
270
|
+
//# sourceMappingURL=WebsocketServerConnector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"WebsocketServerConnector.js","sourceRoot":"","sources":["../../../../src/connection/websocket/WebsocketServerConnector.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4DAAsD;AAEtD,yEAAqF;AACrF,uDAAmD;AACnD,mDAAoG;AACpG,2EAAuE;AACvE,mEAA6G;AAC7G,4DAAyE;AAEzE,0CAA2D;AAC3D,8EAA4G;AAE5G,gDAA4D;AAC5D,8DAAqC;AACrC,mDAAuF;AACvF,mCAAgC;AAChC,gEAAgE;AAChE,8CAA4E;AAC5E,2FAAuF;AACvF,iFAAiG;AACjG,iDAAgE;AAChE,0DAA2C;AAC3C,6DAAmE;AACnE,4DAAwD;AAExD,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAwBjC,gHAAgH;AAChH,MAAa,wBAAwB;IAEhB,eAAe,CAAkB;IAC1C,YAAY,CAAe;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-
|
|
25
|
+
maxContactCount?: number;
|
|
26
26
|
numberOfNodesPerKBucket?: number;
|
|
27
27
|
joinNoProgressLimit?: number;
|
|
28
28
|
peerDiscoveryQueryBatchSize?: number;
|
|
@@ -49,7 +49,6 @@ export interface DhtNodeOptions {
|
|
|
49
49
|
webrtcAllowPrivateAddresses?: boolean;
|
|
50
50
|
webrtcDatachannelBufferThresholdLow?: number;
|
|
51
51
|
webrtcDatachannelBufferThresholdHigh?: number;
|
|
52
|
-
webrtcNewConnectionTimeout?: number;
|
|
53
52
|
webrtcPortRange?: PortRange;
|
|
54
53
|
maxMessageSize?: number;
|
|
55
54
|
maxConnections?: number;
|
|
@@ -59,9 +58,10 @@ export interface DhtNodeOptions {
|
|
|
59
58
|
autoCertifierConfigFile?: string;
|
|
60
59
|
geoIpDatabaseFolder?: string;
|
|
61
60
|
}
|
|
61
|
+
export declare const CONTROL_LAYER_NODE_SERVICE_ID = "layer0";
|
|
62
62
|
export type Events = TransportEvents & DhtNodeEvents;
|
|
63
63
|
export declare class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
64
|
-
private readonly
|
|
64
|
+
private readonly options;
|
|
65
65
|
private rpcCommunicator?;
|
|
66
66
|
private transport?;
|
|
67
67
|
private localPeerDescriptor?;
|
|
@@ -76,7 +76,7 @@ export declare class DhtNode extends EventEmitter<Events> implements ITransport
|
|
|
76
76
|
private started;
|
|
77
77
|
private abortController;
|
|
78
78
|
constructor(conf: DhtNodeOptions);
|
|
79
|
-
private
|
|
79
|
+
private validateOptions;
|
|
80
80
|
start(): Promise<void>;
|
|
81
81
|
private initPeerManager;
|
|
82
82
|
private bindRpcLocalMethods;
|