@streamr/dht 100.2.5-beta.1 → 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
package/src/dht/DhtNode.ts
CHANGED
|
@@ -11,7 +11,7 @@ import { sample } from 'lodash'
|
|
|
11
11
|
import { MarkRequired } from 'ts-essentials'
|
|
12
12
|
import { ConnectionLocker, ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
|
|
13
13
|
import { ConnectionsView } from '../connection/ConnectionsView'
|
|
14
|
-
import { DefaultConnectorFacade,
|
|
14
|
+
import { DefaultConnectorFacade, DefaultConnectorFacadeOptions } from '../connection/ConnectorFacade'
|
|
15
15
|
import { IceServer } from '../connection/webrtc/WebrtcConnector'
|
|
16
16
|
import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
|
|
17
17
|
import { createPeerDescriptor } from '../helpers/createPeerDescriptor'
|
|
@@ -67,7 +67,7 @@ export interface DhtNodeEvents {
|
|
|
67
67
|
export interface DhtNodeOptions {
|
|
68
68
|
serviceId?: ServiceID
|
|
69
69
|
joinParallelism?: number
|
|
70
|
-
|
|
70
|
+
maxContactCount?: number
|
|
71
71
|
numberOfNodesPerKBucket?: number
|
|
72
72
|
joinNoProgressLimit?: number
|
|
73
73
|
peerDiscoveryQueryBatchSize?: number
|
|
@@ -96,7 +96,6 @@ export interface DhtNodeOptions {
|
|
|
96
96
|
webrtcAllowPrivateAddresses?: boolean
|
|
97
97
|
webrtcDatachannelBufferThresholdLow?: number
|
|
98
98
|
webrtcDatachannelBufferThresholdHigh?: number
|
|
99
|
-
webrtcNewConnectionTimeout?: number
|
|
100
99
|
webrtcPortRange?: PortRange
|
|
101
100
|
maxMessageSize?: number
|
|
102
101
|
maxConnections?: number
|
|
@@ -110,7 +109,7 @@ export interface DhtNodeOptions {
|
|
|
110
109
|
type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
|
|
111
110
|
'serviceId' |
|
|
112
111
|
'joinParallelism' |
|
|
113
|
-
'
|
|
112
|
+
'maxContactCount' |
|
|
114
113
|
'numberOfNodesPerKBucket' |
|
|
115
114
|
'joinNoProgressLimit' |
|
|
116
115
|
'dhtJoinTimeout' |
|
|
@@ -126,11 +125,14 @@ const logger = new Logger(module)
|
|
|
126
125
|
|
|
127
126
|
const PERIODICAL_PING_INTERVAL = 60 * 1000
|
|
128
127
|
|
|
128
|
+
// TODO move this to trackerless-network package and change serviceId to be a required paramater
|
|
129
|
+
export const CONTROL_LAYER_NODE_SERVICE_ID = 'layer0'
|
|
130
|
+
|
|
129
131
|
export type Events = TransportEvents & DhtNodeEvents
|
|
130
132
|
|
|
131
133
|
export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
132
134
|
|
|
133
|
-
private readonly
|
|
135
|
+
private readonly options: StrictDhtNodeOptions
|
|
134
136
|
private rpcCommunicator?: RoutingRpcCommunicator
|
|
135
137
|
private transport?: ITransport
|
|
136
138
|
private localPeerDescriptor?: PeerDescriptor
|
|
@@ -147,10 +149,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
147
149
|
|
|
148
150
|
constructor(conf: DhtNodeOptions) {
|
|
149
151
|
super()
|
|
150
|
-
this.
|
|
151
|
-
serviceId:
|
|
152
|
+
this.options = merge({
|
|
153
|
+
serviceId: CONTROL_LAYER_NODE_SERVICE_ID,
|
|
152
154
|
joinParallelism: 3,
|
|
153
|
-
|
|
155
|
+
maxContactCount: 200,
|
|
154
156
|
numberOfNodesPerKBucket: 8,
|
|
155
157
|
joinNoProgressLimit: 5,
|
|
156
158
|
dhtJoinTimeout: 60000,
|
|
@@ -162,26 +164,26 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
162
164
|
storageRedundancyFactor: 5, // TODO validate that this is > 1 (as each node should replicate the data to other node)
|
|
163
165
|
metricsContext: new MetricsContext()
|
|
164
166
|
}, conf)
|
|
165
|
-
this.
|
|
166
|
-
this.localDataStore = new LocalDataStore(this.
|
|
167
|
+
this.validateOptions()
|
|
168
|
+
this.localDataStore = new LocalDataStore(this.options.storeMaxTtl)
|
|
167
169
|
this.send = this.send.bind(this)
|
|
168
170
|
}
|
|
169
171
|
|
|
170
|
-
private
|
|
172
|
+
private validateOptions(): void {
|
|
171
173
|
const expectedNodeIdLength = KADEMLIA_ID_LENGTH_IN_BYTES * 2
|
|
172
|
-
if (this.
|
|
173
|
-
if (!/^[0-9a-fA-F]+$/.test(this.
|
|
174
|
+
if (this.options.nodeId !== undefined) {
|
|
175
|
+
if (!/^[0-9a-fA-F]+$/.test(this.options.nodeId)) {
|
|
174
176
|
throw new Error('Invalid nodeId, the nodeId should be a hex string')
|
|
175
|
-
} else if (this.
|
|
177
|
+
} else if (this.options.nodeId.length !== expectedNodeIdLength) {
|
|
176
178
|
throw new Error(`Invalid nodeId, the length of the nodeId should be ${expectedNodeIdLength}`)
|
|
177
179
|
}
|
|
178
180
|
}
|
|
179
|
-
if (this.
|
|
180
|
-
if (this.
|
|
181
|
+
if (this.options.peerDescriptor !== undefined) {
|
|
182
|
+
if (this.options.peerDescriptor.nodeId.length !== KADEMLIA_ID_LENGTH_IN_BYTES) {
|
|
181
183
|
throw new Error(`Invalid peerDescriptor, the length of the nodeId should be ${KADEMLIA_ID_LENGTH_IN_BYTES} bytes`)
|
|
182
184
|
}
|
|
183
185
|
}
|
|
184
|
-
if (this.
|
|
186
|
+
if (this.options.transport !== undefined && this.options.connectionsView === undefined) {
|
|
185
187
|
throw new Error('connectionsView is required when transport is given')
|
|
186
188
|
}
|
|
187
189
|
}
|
|
@@ -190,58 +192,57 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
190
192
|
if (this.started || this.abortController.signal.aborted) {
|
|
191
193
|
return
|
|
192
194
|
}
|
|
193
|
-
logger.trace(`Starting new Streamr Network DHT Node with serviceId ${this.
|
|
195
|
+
logger.trace(`Starting new Streamr Network DHT Node with serviceId ${this.options.serviceId}`)
|
|
194
196
|
this.started = true
|
|
195
197
|
|
|
196
198
|
if (isBrowserEnvironment()) {
|
|
197
|
-
this.
|
|
198
|
-
if (this.
|
|
199
|
-
this.
|
|
199
|
+
this.options.websocketPortRange = undefined
|
|
200
|
+
if (this.options.peerDescriptor) {
|
|
201
|
+
this.options.peerDescriptor.websocket = undefined
|
|
200
202
|
}
|
|
201
203
|
}
|
|
202
204
|
|
|
203
205
|
// If transport is given, do not create a ConnectionManager
|
|
204
|
-
if (this.
|
|
205
|
-
this.transport = this.
|
|
206
|
-
this.connectionsView = this.
|
|
207
|
-
this.connectionLocker = this.
|
|
206
|
+
if (this.options.transport) {
|
|
207
|
+
this.transport = this.options.transport
|
|
208
|
+
this.connectionsView = this.options.connectionsView
|
|
209
|
+
this.connectionLocker = this.options.connectionLocker
|
|
208
210
|
this.localPeerDescriptor = this.transport.getLocalPeerDescriptor()
|
|
209
211
|
} else {
|
|
210
|
-
const
|
|
212
|
+
const connectorFacadeOptions: DefaultConnectorFacadeOptions = {
|
|
211
213
|
transport: this,
|
|
212
|
-
entryPoints: this.
|
|
213
|
-
iceServers: this.
|
|
214
|
-
webrtcAllowPrivateAddresses: this.
|
|
215
|
-
webrtcDatachannelBufferThresholdLow: this.
|
|
216
|
-
webrtcDatachannelBufferThresholdHigh: this.
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
geoIpDatabaseFolder: this.config.geoIpDatabaseFolder,
|
|
214
|
+
entryPoints: this.options.entryPoints,
|
|
215
|
+
iceServers: this.options.iceServers,
|
|
216
|
+
webrtcAllowPrivateAddresses: this.options.webrtcAllowPrivateAddresses,
|
|
217
|
+
webrtcDatachannelBufferThresholdLow: this.options.webrtcDatachannelBufferThresholdLow,
|
|
218
|
+
webrtcDatachannelBufferThresholdHigh: this.options.webrtcDatachannelBufferThresholdHigh,
|
|
219
|
+
webrtcPortRange: this.options.webrtcPortRange,
|
|
220
|
+
maxMessageSize: this.options.maxMessageSize,
|
|
221
|
+
websocketServerEnableTls: this.options.websocketServerEnableTls,
|
|
222
|
+
tlsCertificate: this.options.tlsCertificate,
|
|
223
|
+
externalIp: this.options.externalIp,
|
|
224
|
+
autoCertifierUrl: this.options.autoCertifierUrl,
|
|
225
|
+
autoCertifierConfigFile: this.options.autoCertifierConfigFile,
|
|
226
|
+
geoIpDatabaseFolder: this.options.geoIpDatabaseFolder,
|
|
226
227
|
createLocalPeerDescriptor: (connectivityResponse: ConnectivityResponse) => this.generatePeerDescriptorCallBack(connectivityResponse)
|
|
227
228
|
}
|
|
228
|
-
// If own PeerDescriptor is given in
|
|
229
|
-
if (this.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
min: this.
|
|
233
|
-
max: this.
|
|
229
|
+
// If own PeerDescriptor is given in options, create a ConnectionManager with ws server
|
|
230
|
+
if (this.options.peerDescriptor?.websocket) {
|
|
231
|
+
connectorFacadeOptions.websocketHost = this.options.peerDescriptor.websocket.host
|
|
232
|
+
connectorFacadeOptions.websocketPortRange = {
|
|
233
|
+
min: this.options.peerDescriptor.websocket.port,
|
|
234
|
+
max: this.options.peerDescriptor.websocket.port
|
|
234
235
|
}
|
|
235
236
|
// If websocketPortRange is given, create ws server using it, websocketHost can be undefined
|
|
236
|
-
} else if (this.
|
|
237
|
-
|
|
238
|
-
|
|
237
|
+
} else if (this.options.websocketPortRange) {
|
|
238
|
+
connectorFacadeOptions.websocketHost = this.options.websocketHost
|
|
239
|
+
connectorFacadeOptions.websocketPortRange = this.options.websocketPortRange
|
|
239
240
|
}
|
|
240
241
|
|
|
241
242
|
const connectionManager = new ConnectionManager({
|
|
242
|
-
createConnectorFacade: () => new DefaultConnectorFacade(
|
|
243
|
-
maxConnections: this.
|
|
244
|
-
metricsContext: this.
|
|
243
|
+
createConnectorFacade: () => new DefaultConnectorFacade(connectorFacadeOptions),
|
|
244
|
+
maxConnections: this.options.maxConnections,
|
|
245
|
+
metricsContext: this.options.metricsContext
|
|
245
246
|
})
|
|
246
247
|
await connectionManager.start()
|
|
247
248
|
this.connectionsView = connectionManager
|
|
@@ -250,9 +251,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
250
251
|
}
|
|
251
252
|
|
|
252
253
|
this.rpcCommunicator = new RoutingRpcCommunicator(
|
|
253
|
-
this.
|
|
254
|
+
this.options.serviceId,
|
|
254
255
|
(msg, opts) => this.transport!.send(msg, opts),
|
|
255
|
-
{ rpcRequestTimeout: this.
|
|
256
|
+
{ rpcRequestTimeout: this.options.rpcRequestTimeout }
|
|
256
257
|
)
|
|
257
258
|
|
|
258
259
|
this.transport.on('message', (message: Message) => this.handleMessageFromTransport(message))
|
|
@@ -261,10 +262,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
261
262
|
|
|
262
263
|
this.peerDiscovery = new PeerDiscovery({
|
|
263
264
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
264
|
-
joinNoProgressLimit: this.
|
|
265
|
-
joinTimeout: this.
|
|
266
|
-
serviceId: this.
|
|
267
|
-
parallelism: this.
|
|
265
|
+
joinNoProgressLimit: this.options.joinNoProgressLimit,
|
|
266
|
+
joinTimeout: this.options.dhtJoinTimeout,
|
|
267
|
+
serviceId: this.options.serviceId,
|
|
268
|
+
parallelism: this.options.joinParallelism,
|
|
268
269
|
connectionLocker: this.connectionLocker,
|
|
269
270
|
peerManager: this.peerManager!,
|
|
270
271
|
abortSignal: this.abortController.signal,
|
|
@@ -282,7 +283,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
282
283
|
sessionTransport: this,
|
|
283
284
|
connectionsView: this.connectionsView!,
|
|
284
285
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
285
|
-
serviceId: this.
|
|
286
|
+
serviceId: this.options.serviceId,
|
|
286
287
|
localDataStore: this.localDataStore,
|
|
287
288
|
addContact: (contact: PeerDescriptor) => this.peerManager!.addContact(contact),
|
|
288
289
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => this.createDhtNodeRpcRemote(peerDescriptor),
|
|
@@ -291,9 +292,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
291
292
|
rpcCommunicator: this.rpcCommunicator,
|
|
292
293
|
recursiveOperationManager: this.recursiveOperationManager,
|
|
293
294
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
294
|
-
serviceId: this.
|
|
295
|
-
highestTtl: this.
|
|
296
|
-
redundancyFactor: this.
|
|
295
|
+
serviceId: this.options.serviceId,
|
|
296
|
+
highestTtl: this.options.storeHighestTtl,
|
|
297
|
+
redundancyFactor: this.options.storageRedundancyFactor,
|
|
297
298
|
localDataStore: this.localDataStore,
|
|
298
299
|
getNeighbors: () => this.peerManager!.getNeighbors().map((n) => n.getPeerDescriptor()),
|
|
299
300
|
createRpcRemote: (contact: PeerDescriptor) => {
|
|
@@ -302,7 +303,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
302
303
|
contact,
|
|
303
304
|
this.rpcCommunicator!,
|
|
304
305
|
StoreRpcClient,
|
|
305
|
-
this.
|
|
306
|
+
this.options.rpcRequestTimeout
|
|
306
307
|
)
|
|
307
308
|
}
|
|
308
309
|
})
|
|
@@ -312,10 +313,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
312
313
|
this.bindRpcLocalMethods()
|
|
313
314
|
|
|
314
315
|
const pruneTargets = []
|
|
315
|
-
if (this.
|
|
316
|
+
if (this.options.periodicallyPingNeighbors === true) {
|
|
316
317
|
pruneTargets.push(() => this.peerManager!.getNeighbors().map((node) => this.createDhtNodeRpcRemote(node.getPeerDescriptor())))
|
|
317
318
|
}
|
|
318
|
-
if (this.
|
|
319
|
+
if (this.options.periodicallyPingRingContacts === true) {
|
|
319
320
|
pruneTargets.push(() => this.peerManager!.getRingContacts().getAllContacts())
|
|
320
321
|
}
|
|
321
322
|
for (const pruneTarget of pruneTargets) {
|
|
@@ -330,12 +331,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
330
331
|
|
|
331
332
|
private initPeerManager() {
|
|
332
333
|
this.peerManager = new PeerManager({
|
|
333
|
-
numberOfNodesPerKBucket: this.
|
|
334
|
-
|
|
334
|
+
numberOfNodesPerKBucket: this.options.numberOfNodesPerKBucket,
|
|
335
|
+
maxContactCount: this.options.maxContactCount,
|
|
335
336
|
localNodeId: this.getNodeId(),
|
|
336
337
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
337
338
|
connectionLocker: this.connectionLocker,
|
|
338
|
-
lockId: this.
|
|
339
|
+
lockId: this.options.serviceId,
|
|
339
340
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => this.createDhtNodeRpcRemote(peerDescriptor),
|
|
340
341
|
hasConnection: (nodeId: DhtAddress) => this.connectionsView!.hasConnection(nodeId)
|
|
341
342
|
})
|
|
@@ -359,12 +360,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
359
360
|
})
|
|
360
361
|
this.peerManager.on('kBucketEmpty', () => {
|
|
361
362
|
if (!this.peerDiscovery!.isJoinOngoing()) {
|
|
362
|
-
if (this.
|
|
363
|
+
if (this.options.entryPoints && this.options.entryPoints.length > 0) {
|
|
363
364
|
setImmediate(async () => {
|
|
364
365
|
const contactedPeers = new Set<DhtAddress>()
|
|
365
366
|
const distantJoinContactPeers = new Set<DhtAddress>()
|
|
366
367
|
// TODO should we catch possible promise rejection?
|
|
367
|
-
await Promise.all(this.
|
|
368
|
+
await Promise.all(this.options.entryPoints!.map((entryPoint) =>
|
|
368
369
|
this.peerDiscovery!.rejoinDht(entryPoint, contactedPeers, distantJoinContactPeers)
|
|
369
370
|
))
|
|
370
371
|
})
|
|
@@ -378,8 +379,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
378
379
|
this.emit('connected', peerDescriptor)
|
|
379
380
|
})
|
|
380
381
|
this.transport!.on('disconnected', (peerDescriptor: PeerDescriptor, gracefulLeave: boolean) => {
|
|
381
|
-
const
|
|
382
|
-
if (
|
|
382
|
+
const isControlLayerNode = (this.connectionLocker !== undefined)
|
|
383
|
+
if (isControlLayerNode) {
|
|
383
384
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
384
385
|
if (gracefulLeave) {
|
|
385
386
|
this.peerManager!.removeContact(nodeId)
|
|
@@ -397,7 +398,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
397
398
|
return
|
|
398
399
|
}
|
|
399
400
|
const dhtNodeRpcLocal = new DhtNodeRpcLocal({
|
|
400
|
-
peerDiscoveryQueryBatchSize: this.
|
|
401
|
+
peerDiscoveryQueryBatchSize: this.options.peerDiscoveryQueryBatchSize,
|
|
401
402
|
getNeighbors: () => this.peerManager!.getNeighbors().map((n) => n.getPeerDescriptor()),
|
|
402
403
|
getClosestRingContactsTo: (ringIdRaw: RingIdRaw, limit: number) => {
|
|
403
404
|
return this.getClosestRingContactsTo(ringIdRaw, limit)
|
|
@@ -424,25 +425,25 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
424
425
|
ExternalFetchDataResponse,
|
|
425
426
|
'externalFetchData',
|
|
426
427
|
(req: ExternalFetchDataRequest, context: ServerCallContext) => externalApiRpcLocal.externalFetchData(req, context),
|
|
427
|
-
{ timeout: 10000 } // TODO use
|
|
428
|
+
{ timeout: 10000 } // TODO use options option or named constant?
|
|
428
429
|
)
|
|
429
430
|
this.rpcCommunicator!.registerRpcMethod(
|
|
430
431
|
ExternalStoreDataRequest,
|
|
431
432
|
ExternalStoreDataResponse,
|
|
432
433
|
'externalStoreData',
|
|
433
434
|
(req: ExternalStoreDataRequest, context: ServerCallContext) => externalApiRpcLocal.externalStoreData(req, context),
|
|
434
|
-
{ timeout: 10000 } // TODO use
|
|
435
|
+
{ timeout: 10000 } // TODO use options option or named constant?
|
|
435
436
|
)
|
|
436
437
|
}
|
|
437
438
|
|
|
438
439
|
private handleMessageFromTransport(message: Message): void {
|
|
439
|
-
if (message.serviceId === this.
|
|
440
|
+
if (message.serviceId === this.options.serviceId) {
|
|
440
441
|
this.rpcCommunicator?.handleMessageFromPeer(message)
|
|
441
442
|
}
|
|
442
443
|
}
|
|
443
444
|
|
|
444
445
|
private handleMessageFromRouter(message: Message): void {
|
|
445
|
-
if (message.serviceId === this.
|
|
446
|
+
if (message.serviceId === this.options.serviceId) {
|
|
446
447
|
this.rpcCommunicator?.handleMessageFromPeer(message)
|
|
447
448
|
} else {
|
|
448
449
|
this.emit('message', message)
|
|
@@ -450,13 +451,13 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
450
451
|
}
|
|
451
452
|
|
|
452
453
|
private async generatePeerDescriptorCallBack(connectivityResponse: ConnectivityResponse) {
|
|
453
|
-
if (this.
|
|
454
|
-
this.localPeerDescriptor = this.
|
|
454
|
+
if (this.options.peerDescriptor !== undefined) {
|
|
455
|
+
this.localPeerDescriptor = this.options.peerDescriptor
|
|
455
456
|
} else {
|
|
456
457
|
let region: number | undefined = undefined
|
|
457
|
-
if (this.
|
|
458
|
-
region = this.
|
|
459
|
-
logger.debug(`Using region ${region} from
|
|
458
|
+
if (this.options.region !== undefined) {
|
|
459
|
+
region = this.options.region
|
|
460
|
+
logger.debug(`Using region ${region} from options when generating local PeerDescriptor`)
|
|
460
461
|
} else if (connectivityResponse.latitude !== undefined && connectivityResponse.longitude !== undefined) {
|
|
461
462
|
region = getLocalRegionByCoordinates(connectivityResponse.latitude, connectivityResponse.longitude)
|
|
462
463
|
logger.debug(`Using region ${region} from GeoIP when generating local PeerDescriptor`)
|
|
@@ -467,7 +468,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
467
468
|
logger.debug(`Using region ${region} from CDN when generating local PeerDescriptor`)
|
|
468
469
|
}
|
|
469
470
|
|
|
470
|
-
this.localPeerDescriptor = createPeerDescriptor(connectivityResponse, region, this.
|
|
471
|
+
this.localPeerDescriptor = createPeerDescriptor(connectivityResponse, region, this.options.nodeId)
|
|
471
472
|
}
|
|
472
473
|
return this.localPeerDescriptor
|
|
473
474
|
}
|
|
@@ -522,7 +523,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
522
523
|
}
|
|
523
524
|
|
|
524
525
|
private getConnectedEntryPoints(): PeerDescriptor[] {
|
|
525
|
-
return this.
|
|
526
|
+
return this.options.entryPoints !== undefined ? this.options.entryPoints.filter((entryPoint) =>
|
|
526
527
|
this.connectionsView!.hasConnection(getNodeIdFromPeerDescriptor(entryPoint))
|
|
527
528
|
) : []
|
|
528
529
|
}
|
|
@@ -620,7 +621,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
620
621
|
public async waitForNetworkConnectivity(): Promise<void> {
|
|
621
622
|
await waitForCondition(
|
|
622
623
|
() => this.connectionsView!.getConnectionCount() > 0,
|
|
623
|
-
this.
|
|
624
|
+
this.options.networkConnectivityTimeout,
|
|
624
625
|
100,
|
|
625
626
|
this.abortController.signal
|
|
626
627
|
)
|
|
@@ -642,8 +643,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
642
643
|
this.rpcCommunicator!.stop()
|
|
643
644
|
this.router!.stop()
|
|
644
645
|
this.recursiveOperationManager!.stop()
|
|
645
|
-
if (this.
|
|
646
|
-
// if the transport was not given in
|
|
646
|
+
if (this.options.transport === undefined) {
|
|
647
|
+
// if the transport was not given in options, the instance was created in start() and
|
|
647
648
|
// this component is responsible for stopping it
|
|
648
649
|
await this.transport!.stop()
|
|
649
650
|
}
|
|
@@ -656,9 +657,9 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
656
657
|
return new DhtNodeRpcRemote(
|
|
657
658
|
this.localPeerDescriptor!,
|
|
658
659
|
peerDescriptor,
|
|
659
|
-
this.
|
|
660
|
+
this.options.serviceId,
|
|
660
661
|
this.rpcCommunicator!,
|
|
661
|
-
this.
|
|
662
|
+
this.options.rpcRequestTimeout
|
|
662
663
|
)
|
|
663
664
|
}
|
|
664
665
|
}
|
|
@@ -17,7 +17,7 @@ import { RingContacts } from './contact/RingContactList'
|
|
|
17
17
|
import { getClosestNodes } from './contact/getClosestNodes'
|
|
18
18
|
import { RingIdRaw } from './contact/ringIdentifiers'
|
|
19
19
|
|
|
20
|
-
interface
|
|
20
|
+
interface DhtNodeRpcLocalOptions {
|
|
21
21
|
peerDiscoveryQueryBatchSize: number
|
|
22
22
|
getNeighbors: () => ReadonlyArray<PeerDescriptor>
|
|
23
23
|
getClosestRingContactsTo: (id: RingIdRaw, limit: number) => RingContacts
|
|
@@ -29,19 +29,19 @@ const logger = new Logger(module)
|
|
|
29
29
|
|
|
30
30
|
export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
31
31
|
|
|
32
|
-
private readonly
|
|
32
|
+
private readonly options: DhtNodeRpcLocalOptions
|
|
33
33
|
|
|
34
|
-
constructor(
|
|
35
|
-
this.
|
|
34
|
+
constructor(options: DhtNodeRpcLocalOptions) {
|
|
35
|
+
this.options = options
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
// TODO rename to getClosestNeighbors (breaking change)
|
|
39
39
|
async getClosestPeers(request: ClosestPeersRequest, context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
40
|
-
this.
|
|
40
|
+
this.options.addContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
41
41
|
const peers = getClosestNodes(
|
|
42
42
|
getDhtAddressFromRaw(request.nodeId),
|
|
43
|
-
this.
|
|
44
|
-
{ maxCount: this.
|
|
43
|
+
this.options.getNeighbors(),
|
|
44
|
+
{ maxCount: this.options.peerDiscoveryQueryBatchSize }
|
|
45
45
|
)
|
|
46
46
|
const response = {
|
|
47
47
|
peers,
|
|
@@ -52,8 +52,8 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
52
52
|
|
|
53
53
|
// TODO rename to getClosestRingContacts (breaking change)
|
|
54
54
|
async getClosestRingPeers(request: ClosestRingPeersRequest, context: ServerCallContext): Promise<ClosestRingPeersResponse> {
|
|
55
|
-
this.
|
|
56
|
-
const closestContacts = this.
|
|
55
|
+
this.options.addContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
56
|
+
const closestContacts = this.options.getClosestRingContactsTo(request.ringId as RingIdRaw, this.options.peerDiscoveryQueryBatchSize)
|
|
57
57
|
const response = {
|
|
58
58
|
leftPeers: closestContacts.left,
|
|
59
59
|
rightPeers: closestContacts.right,
|
|
@@ -65,7 +65,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
65
65
|
async ping(request: PingRequest, context: ServerCallContext): Promise<PingResponse> {
|
|
66
66
|
logger.trace('received ping request: ' + getNodeIdFromPeerDescriptor((context as DhtCallContext).incomingSourceDescriptor!))
|
|
67
67
|
setImmediate(() => {
|
|
68
|
-
this.
|
|
68
|
+
this.options.addContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
69
69
|
})
|
|
70
70
|
const response: PingResponse = {
|
|
71
71
|
requestId: request.requestId
|
|
@@ -78,7 +78,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
78
78
|
const sender = (context as DhtCallContext).incomingSourceDescriptor!
|
|
79
79
|
const senderNodeId = getNodeIdFromPeerDescriptor(sender)
|
|
80
80
|
logger.trace('received leave notice: ' + senderNodeId)
|
|
81
|
-
this.
|
|
81
|
+
this.options.removeContact(senderNodeId)
|
|
82
82
|
return {}
|
|
83
83
|
}
|
|
84
84
|
}
|
|
@@ -14,7 +14,7 @@ import { Any } from '../proto/google/protobuf/any'
|
|
|
14
14
|
import { DhtAddress, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
15
15
|
import { getDhtAddressFromRaw } from '../identifiers'
|
|
16
16
|
|
|
17
|
-
interface
|
|
17
|
+
interface ExternalApiRpcLocalOptions {
|
|
18
18
|
executeRecursiveOperation: (
|
|
19
19
|
targetId: DhtAddress,
|
|
20
20
|
operation: RecursiveOperation,
|
|
@@ -29,15 +29,15 @@ interface ExternalApiRpcLocalConfig {
|
|
|
29
29
|
|
|
30
30
|
export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
31
31
|
|
|
32
|
-
private readonly
|
|
32
|
+
private readonly options: ExternalApiRpcLocalOptions
|
|
33
33
|
|
|
34
|
-
constructor(
|
|
35
|
-
this.
|
|
34
|
+
constructor(options: ExternalApiRpcLocalOptions) {
|
|
35
|
+
this.options = options
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
async externalFetchData(request: ExternalFetchDataRequest, context: ServerCallContext): Promise<ExternalFetchDataResponse> {
|
|
39
39
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
40
|
-
const result = await this.
|
|
40
|
+
const result = await this.options.executeRecursiveOperation(
|
|
41
41
|
getDhtAddressFromRaw(request.key),
|
|
42
42
|
RecursiveOperation.FETCH_DATA,
|
|
43
43
|
getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
@@ -47,7 +47,7 @@ export class ExternalApiRpcLocal implements IExternalApiRpc {
|
|
|
47
47
|
|
|
48
48
|
async externalStoreData(request: ExternalStoreDataRequest, context: ServerCallContext): Promise<ExternalStoreDataResponse> {
|
|
49
49
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
50
|
-
const result = await this.
|
|
50
|
+
const result = await this.options.storeDataToDht(
|
|
51
51
|
getDhtAddressFromRaw(request.key),
|
|
52
52
|
request.data!,
|
|
53
53
|
getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
@@ -11,7 +11,7 @@ export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
|
|
|
11
11
|
key: getRawFromDhtAddress(key)
|
|
12
12
|
}
|
|
13
13
|
const options = this.formDhtRpcOptions({
|
|
14
|
-
// TODO use
|
|
14
|
+
// TODO use options option or named constant?
|
|
15
15
|
timeout: 10000
|
|
16
16
|
})
|
|
17
17
|
try {
|
|
@@ -28,7 +28,7 @@ export class ExternalApiRpcRemote extends RpcRemote<ExternalApiRpcClient> {
|
|
|
28
28
|
data
|
|
29
29
|
}
|
|
30
30
|
const options = this.formDhtRpcOptions({
|
|
31
|
-
// TODO use
|
|
31
|
+
// TODO use options option or named constant?
|
|
32
32
|
timeout: 10000
|
|
33
33
|
})
|
|
34
34
|
try {
|