@streamr/dht 0.0.1-tatum.7 → 0.0.1-tatum.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/src/connection/ConnectionLockRpcRemote.d.ts +10 -0
- package/dist/src/connection/{RemoteConnectionLocker.js → ConnectionLockRpcRemote.js} +20 -35
- package/dist/src/connection/ConnectionLockRpcRemote.js.map +1 -0
- package/dist/src/connection/ConnectionManager.d.ts +0 -1
- package/dist/src/connection/ConnectionManager.js +27 -25
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ConnectivityChecker.js +4 -4
- package/dist/src/connection/ConnectivityChecker.js.map +1 -1
- package/dist/src/connection/ConnectorFacade.d.ts +1 -1
- package/dist/src/connection/ConnectorFacade.js +5 -8
- package/dist/src/connection/ConnectorFacade.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +1 -2
- package/dist/src/connection/Handshaker.js +1 -4
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +1 -2
- package/dist/src/connection/ManagedConnection.js +4 -5
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.d.ts +1 -1
- package/dist/src/connection/ManagedWebRtcConnection.js +2 -2
- package/dist/src/connection/ManagedWebRtcConnection.js.map +1 -1
- package/dist/src/connection/Simulator/SimulatorConnector.d.ts +1 -2
- package/dist/src/connection/Simulator/SimulatorConnector.js +3 -4
- package/dist/src/connection/Simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/WebRTC/NodeWebRtcConnection.d.ts +1 -1
- package/dist/src/connection/WebRTC/{WebRtcConnector.d.ts → WebRtcConnectorRpcLocal.d.ts} +9 -9
- package/dist/src/connection/WebRTC/{WebRtcConnector.js → WebRtcConnectorRpcLocal.js} +38 -30
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.d.ts +11 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js +55 -0
- package/dist/src/connection/WebRTC/WebRtcConnectorRpcRemote.js.map +1 -0
- package/dist/src/connection/WebRTC/iceServerAsString.d.ts +1 -1
- package/dist/src/connection/WebSocket/{WebSocketConnector.d.ts → WebSocketConnectorRpcLocal.d.ts} +6 -7
- package/dist/src/connection/WebSocket/{WebSocketConnector.js → WebSocketConnectorRpcLocal.js} +20 -20
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcLocal.js.map +1 -0
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.d.ts +8 -0
- package/dist/src/connection/WebSocket/{RemoteWebSocketConnector.js → WebSocketConnectorRpcRemote.js} +11 -16
- package/dist/src/connection/WebSocket/WebSocketConnectorRpcRemote.js.map +1 -0
- package/dist/src/dht/DhtNode.d.ts +6 -7
- package/dist/src/dht/DhtNode.js +22 -23
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/{RemoteExternalApi.d.ts → ExternalApiRpcRemote.d.ts} +2 -2
- package/dist/src/dht/{RemoteExternalApi.js → ExternalApiRpcRemote.js} +5 -6
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -0
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +3 -2
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/find/RecursiveFindSession.d.ts +5 -5
- package/dist/src/dht/find/RecursiveFindSession.js +7 -7
- package/dist/src/dht/find/RecursiveFindSession.js.map +1 -1
- package/dist/src/dht/find/RecursiveFinder.d.ts +7 -7
- package/dist/src/dht/find/RecursiveFinder.js +24 -24
- package/dist/src/dht/find/RecursiveFinder.js.map +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.d.ts +1 -1
- package/dist/src/dht/find/RemoteRecursiveFindSession.js +4 -4
- package/dist/src/dht/find/RemoteRecursiveFindSession.js.map +1 -1
- package/dist/src/dht/registerExternalApiRpcMethods.js +4 -3
- package/dist/src/dht/registerExternalApiRpcMethods.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -2
- package/dist/src/dht/routing/Router.js +2 -4
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/{RemoteRouter.d.ts → RouterRpcRemote.d.ts} +2 -2
- package/dist/src/dht/routing/{RemoteRouter.js → RouterRpcRemote.js} +4 -4
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -0
- package/dist/src/dht/routing/RoutingSession.js +2 -2
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/{DataStore.d.ts → StoreRpcLocal.d.ts} +4 -4
- package/dist/src/dht/store/{DataStore.js → StoreRpcLocal.js} +27 -27
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -0
- package/dist/src/dht/store/{RemoteStore.d.ts → StoreRpcRemote.d.ts} +2 -2
- package/dist/src/dht/store/{RemoteStore.js → StoreRpcRemote.js} +4 -4
- package/dist/src/dht/store/StoreRpcRemote.js.map +1 -0
- package/dist/src/exports.d.ts +1 -1
- package/dist/src/helpers/protoClasses.js +2 -2
- package/dist/src/helpers/protoClasses.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +29 -29
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +39 -39
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +49 -158
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +46 -86
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +15 -15
- package/dist/src/transport/RoutingRpcCommunicator.js +1 -0
- package/dist/src/transport/RoutingRpcCommunicator.js.map +1 -1
- package/package.json +4 -4
- package/protos/DhtRpc.proto +30 -59
- package/src/connection/ConnectionLockRpcRemote.ts +62 -0
- package/src/connection/ConnectionManager.ts +33 -32
- package/src/connection/ConnectivityChecker.ts +1 -1
- package/src/connection/ConnectorFacade.ts +7 -10
- package/src/connection/Handshaker.ts +0 -5
- package/src/connection/ManagedConnection.ts +3 -6
- package/src/connection/ManagedWebRtcConnection.ts +0 -2
- package/src/connection/Simulator/SimulatorConnector.ts +2 -7
- package/src/connection/WebRTC/NodeWebRtcConnection.ts +1 -1
- package/src/connection/WebRTC/{WebRtcConnector.ts → WebRtcConnectorRpcLocal.ts} +46 -34
- package/src/connection/WebRTC/WebRtcConnectorRpcRemote.ts +71 -0
- package/src/connection/WebRTC/iceServerAsString.ts +1 -1
- package/src/connection/WebSocket/{WebSocketConnector.ts → WebSocketConnectorRpcLocal.ts} +26 -26
- package/src/connection/WebSocket/{RemoteWebSocketConnector.ts → WebSocketConnectorRpcRemote.ts} +13 -18
- package/src/dht/DhtNode.ts +32 -33
- package/src/dht/{RemoteExternalApi.ts → ExternalApiRpcRemote.ts} +3 -4
- package/src/dht/discovery/PeerDiscovery.ts +4 -3
- package/src/dht/find/RecursiveFindSession.ts +11 -11
- package/src/dht/find/RecursiveFinder.ts +29 -30
- package/src/dht/find/RemoteRecursiveFindSession.ts +6 -6
- package/src/dht/registerExternalApiRpcMethods.ts +7 -4
- package/src/dht/routing/Router.ts +4 -6
- package/src/dht/routing/{RemoteRouter.ts → RouterRpcRemote.ts} +2 -2
- package/src/dht/routing/RoutingSession.ts +6 -6
- package/src/dht/store/{DataStore.ts → StoreRpcLocal.ts} +31 -31
- package/src/dht/store/{RemoteStore.ts → StoreRpcRemote.ts} +2 -2
- package/src/exports.ts +1 -1
- package/src/helpers/protoClasses.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +54 -54
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +15 -15
- package/src/proto/packages/dht/protos/DhtRpc.ts +76 -210
- package/src/transport/RoutingRpcCommunicator.ts +1 -0
- package/test/integration/{RemoteRouter.test.ts → RouterRpcRemote.test.ts} +8 -8
- package/test/integration/{RemoteStore.test.ts → StoreRpcRemote.test.ts} +13 -13
- package/test/integration/WebRtcConnectorRpc.test.ts +11 -24
- package/test/integration/WebSocketConnectorRpc.test.ts +8 -12
- package/test/unit/RecursiveFinder.test.ts +5 -6
- package/test/unit/{WebSocketConnector.test.ts → WebSocketConnectorRpcLocal.test.ts} +3 -3
- package/test/unit/webrtcReplaceInternalIpWithExternalIp.test.ts +1 -1
- package/test/utils/utils.ts +16 -26
- package/dist/src/connection/RemoteConnectionLocker.d.ts +0 -13
- package/dist/src/connection/RemoteConnectionLocker.js.map +0 -1
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.d.ts +0 -12
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js +0 -74
- package/dist/src/connection/WebRTC/RemoteWebrtcConnector.js.map +0 -1
- package/dist/src/connection/WebRTC/WebRtcConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.d.ts +0 -9
- package/dist/src/connection/WebSocket/RemoteWebSocketConnector.js.map +0 -1
- package/dist/src/connection/WebSocket/WebSocketConnector.js.map +0 -1
- package/dist/src/dht/RemoteExternalApi.js.map +0 -1
- package/dist/src/dht/routing/RemoteRouter.js.map +0 -1
- package/dist/src/dht/store/DataStore.js.map +0 -1
- package/dist/src/dht/store/RemoteStore.js.map +0 -1
- package/src/connection/RemoteConnectionLocker.ts +0 -85
- package/src/connection/WebRTC/RemoteWebrtcConnector.ts +0 -93
package/src/dht/DhtNode.ts
CHANGED
|
@@ -15,16 +15,16 @@ import {
|
|
|
15
15
|
PeerDescriptor,
|
|
16
16
|
PingRequest,
|
|
17
17
|
PingResponse,
|
|
18
|
-
FindMode,
|
|
19
18
|
DataEntry,
|
|
20
19
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
21
20
|
import { DisconnectionType, ITransport, TransportEvents } from '../transport/ITransport'
|
|
22
21
|
import { ConnectionManager, PortRange, TlsCertificate } from '../connection/ConnectionManager'
|
|
23
|
-
import { DhtRpcServiceClient,
|
|
22
|
+
import { DhtRpcServiceClient, ExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
24
23
|
import {
|
|
25
24
|
Logger,
|
|
26
25
|
MetricsContext,
|
|
27
26
|
hexToBinary,
|
|
27
|
+
merge,
|
|
28
28
|
waitForCondition
|
|
29
29
|
} from '@streamr/utils'
|
|
30
30
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
@@ -35,12 +35,12 @@ import { Any } from '../proto/google/protobuf/any'
|
|
|
35
35
|
import { areEqualPeerDescriptors, keyFromPeerDescriptor, peerIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
36
36
|
import { Router } from './routing/Router'
|
|
37
37
|
import { RecursiveFinder, RecursiveFindResult } from './find/RecursiveFinder'
|
|
38
|
-
import {
|
|
38
|
+
import { StoreRpcLocal } from './store/StoreRpcLocal'
|
|
39
39
|
import { PeerDiscovery } from './discovery/PeerDiscovery'
|
|
40
40
|
import { LocalDataStore } from './store/LocalDataStore'
|
|
41
|
-
import { IceServer } from '../connection/WebRTC/
|
|
41
|
+
import { IceServer } from '../connection/WebRTC/WebRtcConnectorRpcLocal'
|
|
42
42
|
import { registerExternalApiRpcMethods } from './registerExternalApiRpcMethods'
|
|
43
|
-
import {
|
|
43
|
+
import { ExternalApiRpcRemote } from './ExternalApiRpcRemote'
|
|
44
44
|
import { UUID } from '../helpers/UUID'
|
|
45
45
|
import { isBrowserEnvironment } from '../helpers/browser/isBrowserEnvironment'
|
|
46
46
|
import { sample } from 'lodash'
|
|
@@ -65,13 +65,13 @@ export interface DhtNodeOptions {
|
|
|
65
65
|
maxNeighborListSize?: number
|
|
66
66
|
numberOfNodesPerKBucket?: number
|
|
67
67
|
joinNoProgressLimit?: number
|
|
68
|
-
|
|
68
|
+
peerDiscoveryQueryBatchSize?: number
|
|
69
69
|
dhtJoinTimeout?: number
|
|
70
70
|
metricsContext?: MetricsContext
|
|
71
71
|
storeHighestTtl?: number
|
|
72
72
|
storeMaxTtl?: number
|
|
73
73
|
networkConnectivityTimeout?: number
|
|
74
|
-
|
|
74
|
+
storageRedundancyFactor?: number
|
|
75
75
|
|
|
76
76
|
transport?: ITransport
|
|
77
77
|
peerDescriptor?: PeerDescriptor
|
|
@@ -100,12 +100,12 @@ type StrictDhtNodeOptions = MarkRequired<DhtNodeOptions,
|
|
|
100
100
|
'numberOfNodesPerKBucket' |
|
|
101
101
|
'joinNoProgressLimit' |
|
|
102
102
|
'dhtJoinTimeout' |
|
|
103
|
-
'
|
|
103
|
+
'peerDiscoveryQueryBatchSize' |
|
|
104
104
|
'maxConnections' |
|
|
105
105
|
'storeHighestTtl' |
|
|
106
106
|
'storeMaxTtl' |
|
|
107
107
|
'networkConnectivityTimeout' |
|
|
108
|
-
'
|
|
108
|
+
'storageRedundancyFactor' |
|
|
109
109
|
'metricsContext' |
|
|
110
110
|
'peerId'>
|
|
111
111
|
|
|
@@ -141,7 +141,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
141
141
|
private transport?: ITransport
|
|
142
142
|
private ownPeerDescriptor?: PeerDescriptor
|
|
143
143
|
public router?: Router
|
|
144
|
-
|
|
144
|
+
private storeRpcLocal?: StoreRpcLocal
|
|
145
145
|
private localDataStore = new LocalDataStore()
|
|
146
146
|
private recursiveFinder?: RecursiveFinder
|
|
147
147
|
private peerDiscovery?: PeerDiscovery
|
|
@@ -153,23 +153,22 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
153
153
|
|
|
154
154
|
constructor(conf: DhtNodeOptions) {
|
|
155
155
|
super()
|
|
156
|
-
this.config = {
|
|
156
|
+
this.config = merge({
|
|
157
157
|
serviceId: 'layer0',
|
|
158
158
|
joinParallelism: 3,
|
|
159
159
|
maxNeighborListSize: 200,
|
|
160
160
|
numberOfNodesPerKBucket: 8,
|
|
161
161
|
joinNoProgressLimit: 4,
|
|
162
162
|
dhtJoinTimeout: 60000,
|
|
163
|
-
|
|
163
|
+
peerDiscoveryQueryBatchSize: 5,
|
|
164
164
|
maxConnections: 80,
|
|
165
165
|
storeHighestTtl: 60000,
|
|
166
166
|
storeMaxTtl: 60000,
|
|
167
167
|
networkConnectivityTimeout: 10000,
|
|
168
|
-
|
|
168
|
+
storageRedundancyFactor: 5,
|
|
169
169
|
metricsContext: new MetricsContext(),
|
|
170
|
-
peerId: new UUID().toHex()
|
|
171
|
-
|
|
172
|
-
}
|
|
170
|
+
peerId: new UUID().toHex()
|
|
171
|
+
}, conf)
|
|
173
172
|
this.send = this.send.bind(this)
|
|
174
173
|
}
|
|
175
174
|
|
|
@@ -250,7 +249,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
250
249
|
randomPeers: this.randomPeers!,
|
|
251
250
|
openInternetPeers: this.openInternetPeers!,
|
|
252
251
|
joinNoProgressLimit: this.config.joinNoProgressLimit,
|
|
253
|
-
|
|
252
|
+
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
254
253
|
joinTimeout: this.config.dhtJoinTimeout,
|
|
255
254
|
serviceId: this.config.serviceId,
|
|
256
255
|
parallelism: this.config.joinParallelism,
|
|
@@ -276,14 +275,14 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
276
275
|
isPeerCloserToIdThanSelf: this.isPeerCloserToIdThanSelf.bind(this),
|
|
277
276
|
localDataStore: this.localDataStore
|
|
278
277
|
})
|
|
279
|
-
this.
|
|
278
|
+
this.storeRpcLocal = new StoreRpcLocal({
|
|
280
279
|
rpcCommunicator: this.rpcCommunicator,
|
|
281
280
|
recursiveFinder: this.recursiveFinder,
|
|
282
281
|
ownPeerDescriptor: this.ownPeerDescriptor!,
|
|
283
282
|
serviceId: this.config.serviceId,
|
|
284
283
|
highestTtl: this.config.storeHighestTtl,
|
|
285
284
|
maxTtl: this.config.storeMaxTtl,
|
|
286
|
-
|
|
285
|
+
redundancyFactor: this.config.storageRedundancyFactor,
|
|
287
286
|
localDataStore: this.localDataStore,
|
|
288
287
|
dhtNodeEmitter: this,
|
|
289
288
|
getNodesClosestToIdFromBucket: (id: Uint8Array, n?: number) => {
|
|
@@ -492,7 +491,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
492
491
|
this.emit(
|
|
493
492
|
'newKbucketContact',
|
|
494
493
|
contact.getPeerDescriptor(),
|
|
495
|
-
this.neighborList!.getClosestContacts(this.config.
|
|
494
|
+
this.neighborList!.getClosestContacts(this.config.peerDiscoveryQueryBatchSize).map((peer) => peer.getPeerDescriptor())
|
|
496
495
|
)
|
|
497
496
|
} else { // open connection by pinging
|
|
498
497
|
logger.trace('starting ping ' + keyFromPeerDescriptor(contact.getPeerDescriptor()))
|
|
@@ -502,7 +501,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
502
501
|
this.emit(
|
|
503
502
|
'newKbucketContact',
|
|
504
503
|
contact.getPeerDescriptor(),
|
|
505
|
-
this.neighborList!.getClosestContacts(this.config.
|
|
504
|
+
this.neighborList!.getClosestContacts(this.config.peerDiscoveryQueryBatchSize).map((peer) => peer.getPeerDescriptor())
|
|
506
505
|
)
|
|
507
506
|
} else {
|
|
508
507
|
logger.trace('ping failed ' + keyFromPeerDescriptor(contact.getPeerDescriptor()))
|
|
@@ -618,49 +617,49 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
618
617
|
))
|
|
619
618
|
}
|
|
620
619
|
|
|
621
|
-
public async startRecursiveFind(idToFind: Uint8Array,
|
|
622
|
-
return this.recursiveFinder!.startRecursiveFind(idToFind,
|
|
620
|
+
public async startRecursiveFind(idToFind: Uint8Array, fetchData?: boolean, excludedPeer?: PeerDescriptor): Promise<RecursiveFindResult> {
|
|
621
|
+
return this.recursiveFinder!.startRecursiveFind(idToFind, fetchData, excludedPeer)
|
|
623
622
|
}
|
|
624
623
|
|
|
625
624
|
public async storeDataToDht(key: Uint8Array, data: Any): Promise<PeerDescriptor[]> {
|
|
626
625
|
if (this.peerDiscovery!.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
|
|
627
626
|
return this.storeDataViaPeer(key, data, sample(this.config.entryPoints)!)
|
|
628
627
|
}
|
|
629
|
-
return this.
|
|
628
|
+
return this.storeRpcLocal!.storeDataToDht(key, data)
|
|
630
629
|
}
|
|
631
630
|
|
|
632
631
|
public async storeDataViaPeer(key: Uint8Array, data: Any, peer: PeerDescriptor): Promise<PeerDescriptor[]> {
|
|
633
|
-
const
|
|
632
|
+
const rpcRemote = new ExternalApiRpcRemote(
|
|
634
633
|
this.ownPeerDescriptor!,
|
|
635
634
|
peer,
|
|
636
635
|
this.config.serviceId,
|
|
637
|
-
toProtoRpcClient(new
|
|
636
|
+
toProtoRpcClient(new ExternalApiRpcClient(this.rpcCommunicator!.getRpcClientTransport()))
|
|
638
637
|
)
|
|
639
|
-
return await
|
|
638
|
+
return await rpcRemote.storeData(key, data)
|
|
640
639
|
}
|
|
641
640
|
|
|
642
641
|
public async getDataFromDht(idToFind: Uint8Array): Promise<DataEntry[]> {
|
|
643
642
|
if (this.peerDiscovery!.isJoinOngoing() && this.config.entryPoints && this.config.entryPoints.length > 0) {
|
|
644
643
|
return this.findDataViaPeer(idToFind, sample(this.config.entryPoints)!)
|
|
645
644
|
}
|
|
646
|
-
const result = await this.recursiveFinder!.startRecursiveFind(idToFind,
|
|
645
|
+
const result = await this.recursiveFinder!.startRecursiveFind(idToFind, true)
|
|
647
646
|
return result.dataEntries ?? []
|
|
648
647
|
}
|
|
649
648
|
|
|
650
649
|
public async deleteDataFromDht(idToDelete: Uint8Array): Promise<void> {
|
|
651
650
|
if (!this.stopped) {
|
|
652
|
-
return this.
|
|
651
|
+
return this.storeRpcLocal!.deleteDataFromDht(idToDelete)
|
|
653
652
|
}
|
|
654
653
|
}
|
|
655
654
|
|
|
656
655
|
public async findDataViaPeer(idToFind: Uint8Array, peer: PeerDescriptor): Promise<DataEntry[]> {
|
|
657
|
-
const
|
|
656
|
+
const rpcRemote = new ExternalApiRpcRemote(
|
|
658
657
|
this.ownPeerDescriptor!,
|
|
659
658
|
peer,
|
|
660
659
|
this.config.serviceId,
|
|
661
|
-
toProtoRpcClient(new
|
|
660
|
+
toProtoRpcClient(new ExternalApiRpcClient(this.rpcCommunicator!.getRpcClientTransport()))
|
|
662
661
|
)
|
|
663
|
-
return await
|
|
662
|
+
return await rpcRemote.findData(idToFind)
|
|
664
663
|
}
|
|
665
664
|
|
|
666
665
|
public getRpcCommunicator(): RoutingRpcCommunicator {
|
|
@@ -740,7 +739,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
740
739
|
private async getClosestPeers(request: ClosestPeersRequest, context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
741
740
|
this.addNewContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
742
741
|
const response = {
|
|
743
|
-
peers: this.getClosestPeerDescriptors(request.kademliaId, this.config.
|
|
742
|
+
peers: this.getClosestPeerDescriptors(request.kademliaId, this.config.peerDiscoveryQueryBatchSize),
|
|
744
743
|
requestId: request.requestId
|
|
745
744
|
}
|
|
746
745
|
return response
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { Any } from '../proto/google/protobuf/any'
|
|
2
2
|
import { DataEntry, ExternalStoreDataRequest, FindDataRequest, PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import {
|
|
3
|
+
import { IExternalApiRpcClient } from '../proto/packages/dht/protos/DhtRpc.client'
|
|
4
4
|
import { Remote } from './contact/Remote'
|
|
5
5
|
|
|
6
|
-
export class
|
|
6
|
+
export class ExternalApiRpcRemote extends Remote<IExternalApiRpcClient> {
|
|
7
7
|
|
|
8
8
|
async findData(idToFind: Uint8Array): Promise<DataEntry[]> {
|
|
9
9
|
const request: FindDataRequest = {
|
|
10
|
-
kademliaId: idToFind
|
|
11
|
-
requestor: this.getLocalPeerDescriptor(),
|
|
10
|
+
kademliaId: idToFind
|
|
12
11
|
}
|
|
13
12
|
const options = this.formDhtRpcOptions({
|
|
14
13
|
timeout: 10000
|
|
@@ -20,7 +20,7 @@ interface PeerDiscoveryConfig {
|
|
|
20
20
|
randomPeers: RandomContactList<RemoteDhtNode>
|
|
21
21
|
openInternetPeers: SortedContactList<RemoteDhtNode>
|
|
22
22
|
joinNoProgressLimit: number
|
|
23
|
-
|
|
23
|
+
peerDiscoveryQueryBatchSize: number
|
|
24
24
|
serviceId: string
|
|
25
25
|
parallelism: number
|
|
26
26
|
joinTimeout: number
|
|
@@ -59,9 +59,10 @@ export class PeerDiscovery {
|
|
|
59
59
|
}
|
|
60
60
|
this.config.connectionManager?.lockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`)
|
|
61
61
|
this.config.addContact(entryPointDescriptor)
|
|
62
|
-
const
|
|
62
|
+
const targetId = peerIdFromPeerDescriptor(this.config.ownPeerDescriptor).value
|
|
63
|
+
const closest = this.config.bucket.closest(targetId, this.config.peerDiscoveryQueryBatchSize)
|
|
63
64
|
this.config.neighborList.addContacts(closest)
|
|
64
|
-
const sessions = [this.createSession(
|
|
65
|
+
const sessions = [this.createSession(targetId)]
|
|
65
66
|
if (doAdditionalRandomPeerDiscovery) {
|
|
66
67
|
sessions.push(this.createSession(createRandomKademliaId()))
|
|
67
68
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Logger } from '@streamr/utils'
|
|
2
2
|
import EventEmitter from 'eventemitter3'
|
|
3
3
|
import { PeerID, PeerIDKey } from '../../helpers/PeerID'
|
|
4
|
-
import { DataEntry,
|
|
4
|
+
import { DataEntry, PeerDescriptor, FindResponse } from '../../proto/packages/dht/protos/DhtRpc'
|
|
5
5
|
import { IRecursiveFindSessionService } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
6
6
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
7
7
|
import { ITransport } from '../../transport/ITransport'
|
|
@@ -23,7 +23,7 @@ export interface RecursiveFindSessionConfig {
|
|
|
23
23
|
kademliaIdToFind: Uint8Array
|
|
24
24
|
ownPeerId: PeerID
|
|
25
25
|
waitedRoutingPathCompletions: number
|
|
26
|
-
|
|
26
|
+
fetchData: boolean
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvents> implements IRecursiveFindSessionService {
|
|
@@ -33,7 +33,7 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
33
33
|
private readonly ownPeerId: PeerID
|
|
34
34
|
private readonly waitedRoutingPathCompletions: number
|
|
35
35
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
36
|
-
private readonly
|
|
36
|
+
private readonly fetchData: boolean
|
|
37
37
|
private results: SortedContactList<Contact>
|
|
38
38
|
private foundData: Map<string, DataEntry> = new Map()
|
|
39
39
|
private allKnownHops: Set<PeerIDKey> = new Set()
|
|
@@ -50,12 +50,12 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
50
50
|
this.ownPeerId = config.ownPeerId
|
|
51
51
|
this.waitedRoutingPathCompletions = config.waitedRoutingPathCompletions
|
|
52
52
|
this.results = new SortedContactList(PeerID.fromValue(this.kademliaIdToFind), 10, undefined, true)
|
|
53
|
-
this.
|
|
53
|
+
this.fetchData = config.fetchData
|
|
54
54
|
this.rpcCommunicator = new ListeningRpcCommunicator(this.serviceId, this.transport, {
|
|
55
55
|
rpcRequestTimeout: 15000
|
|
56
56
|
})
|
|
57
|
-
this.rpcCommunicator.registerRpcNotification(
|
|
58
|
-
(req:
|
|
57
|
+
this.rpcCommunicator.registerRpcNotification(FindResponse, 'sendFindResponse',
|
|
58
|
+
(req: FindResponse) => this.sendFindResponse(req))
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
private isFindCompleted(): boolean {
|
|
@@ -64,10 +64,10 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
64
64
|
unreportedHops.delete(id)
|
|
65
65
|
})
|
|
66
66
|
if (this.noCloserNodesReceivedCounter >= 1 && unreportedHops.size === 0) {
|
|
67
|
-
if (this.
|
|
67
|
+
if (this.fetchData
|
|
68
68
|
&& (this.hasNonStaleData() || this.noCloserNodesReceivedCounter >= this.waitedRoutingPathCompletions)) {
|
|
69
69
|
return true
|
|
70
|
-
} else if (this.
|
|
70
|
+
} else if (this.fetchData) {
|
|
71
71
|
return false
|
|
72
72
|
}
|
|
73
73
|
return true
|
|
@@ -79,7 +79,7 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
79
79
|
return Array.from(this.foundData.values()).some((entry) => entry.stale === false)
|
|
80
80
|
}
|
|
81
81
|
|
|
82
|
-
public
|
|
82
|
+
public doSendFindResponse(
|
|
83
83
|
routingPath: PeerDescriptor[],
|
|
84
84
|
nodes: PeerDescriptor[],
|
|
85
85
|
dataEntries: DataEntry[],
|
|
@@ -156,9 +156,9 @@ export class RecursiveFindSession extends EventEmitter<RecursiveFindSessionEvent
|
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
public async
|
|
159
|
+
public async sendFindResponse(report: FindResponse): Promise<Empty> {
|
|
160
160
|
logger.trace('recursiveFindReport arrived: ' + JSON.stringify(report))
|
|
161
|
-
this.
|
|
161
|
+
this.doSendFindResponse(report.routingPath, report.closestConnectedPeers, report.dataEntries, report.noCloserNodesFound)
|
|
162
162
|
return {}
|
|
163
163
|
}
|
|
164
164
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DataEntry,
|
|
3
|
-
FindMode,
|
|
4
3
|
Message,
|
|
5
4
|
MessageType,
|
|
6
5
|
NodeType,
|
|
7
6
|
PeerDescriptor,
|
|
8
|
-
|
|
7
|
+
FindRequest,
|
|
9
8
|
RouteMessageAck,
|
|
10
9
|
RouteMessageWrapper
|
|
11
10
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
@@ -21,7 +20,7 @@ import { RecursiveFindSession, RecursiveFindSessionEvents } from './RecursiveFin
|
|
|
21
20
|
import { RemoteDhtNode } from '../RemoteDhtNode'
|
|
22
21
|
import { ITransport } from '../../transport/ITransport'
|
|
23
22
|
import { LocalDataStore } from '../store/LocalDataStore'
|
|
24
|
-
import {
|
|
23
|
+
import { IRouterRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
25
24
|
import { ListeningRpcCommunicator } from '../../transport/ListeningRpcCommunicator'
|
|
26
25
|
import { RecursiveFindSessionServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
27
26
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
@@ -40,10 +39,10 @@ interface RecursiveFinderConfig {
|
|
|
40
39
|
}
|
|
41
40
|
|
|
42
41
|
interface RecursiveFinderFunc {
|
|
43
|
-
startRecursiveFind(idToFind: Uint8Array,
|
|
42
|
+
startRecursiveFind(idToFind: Uint8Array, fetchData?: boolean): Promise<RecursiveFindResult>
|
|
44
43
|
}
|
|
45
44
|
|
|
46
|
-
export interface IRecursiveFinder extends Pick<
|
|
45
|
+
export interface IRecursiveFinder extends Pick<IRouterRpc, 'findRecursively'>, RecursiveFinderFunc {}
|
|
47
46
|
|
|
48
47
|
export interface RecursiveFindResult { closestNodes: Array<PeerDescriptor>, dataEntries?: Array<DataEntry> }
|
|
49
48
|
|
|
@@ -79,7 +78,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
79
78
|
|
|
80
79
|
public async startRecursiveFind(
|
|
81
80
|
idToFind: Uint8Array,
|
|
82
|
-
|
|
81
|
+
fetchData: boolean = false,
|
|
83
82
|
excludedPeer?: PeerDescriptor
|
|
84
83
|
): Promise<RecursiveFindResult> {
|
|
85
84
|
if (this.stopped) {
|
|
@@ -92,11 +91,11 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
92
91
|
kademliaIdToFind: idToFind,
|
|
93
92
|
ownPeerId: peerIdFromPeerDescriptor(this.ownPeerDescriptor),
|
|
94
93
|
waitedRoutingPathCompletions: this.connections.size > 1 ? 2 : 1,
|
|
95
|
-
|
|
94
|
+
fetchData
|
|
96
95
|
})
|
|
97
96
|
if (this.connections.size === 0) {
|
|
98
97
|
const data = this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
99
|
-
recursiveFindSession.
|
|
98
|
+
recursiveFindSession.doSendFindResponse(
|
|
100
99
|
[this.ownPeerDescriptor],
|
|
101
100
|
[this.ownPeerDescriptor],
|
|
102
101
|
data ? Array.from(data.values()) : [],
|
|
@@ -104,7 +103,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
104
103
|
)
|
|
105
104
|
return recursiveFindSession.getResults()
|
|
106
105
|
}
|
|
107
|
-
const routeMessage = this.
|
|
106
|
+
const routeMessage = this.wrapFindRequest(idToFind, sessionId, fetchData)
|
|
108
107
|
this.ongoingSessions.set(sessionId, recursiveFindSession)
|
|
109
108
|
try {
|
|
110
109
|
await runAndWaitForEvents3<RecursiveFindSessionEvents>(
|
|
@@ -115,28 +114,28 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
115
114
|
} catch (err) {
|
|
116
115
|
logger.debug(`doFindRecursively failed with error ${err}`)
|
|
117
116
|
}
|
|
118
|
-
this.findAndReportLocalData(idToFind,
|
|
117
|
+
this.findAndReportLocalData(idToFind, fetchData, [], this.ownPeerDescriptor, sessionId)
|
|
119
118
|
this.ongoingSessions.delete(sessionId)
|
|
120
119
|
recursiveFindSession.stop()
|
|
121
120
|
return recursiveFindSession.getResults()
|
|
122
121
|
}
|
|
123
122
|
|
|
124
|
-
private
|
|
123
|
+
private wrapFindRequest(idToFind: Uint8Array, sessionId: string, fetchData: boolean): RouteMessageWrapper {
|
|
125
124
|
const targetDescriptor: PeerDescriptor = {
|
|
126
125
|
kademliaId: idToFind,
|
|
127
126
|
type: NodeType.VIRTUAL
|
|
128
127
|
}
|
|
129
|
-
const request:
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
const request: FindRequest = {
|
|
129
|
+
sessionId,
|
|
130
|
+
fetchData
|
|
132
131
|
}
|
|
133
132
|
const msg: Message = {
|
|
134
133
|
messageType: MessageType.RECURSIVE_FIND_REQUEST,
|
|
135
134
|
messageId: v4(),
|
|
136
135
|
serviceId: this.serviceId,
|
|
137
136
|
body: {
|
|
138
|
-
oneofKind: '
|
|
139
|
-
|
|
137
|
+
oneofKind: 'findRequest',
|
|
138
|
+
findRequest: request
|
|
140
139
|
}
|
|
141
140
|
}
|
|
142
141
|
const routeMessage: RouteMessageWrapper = {
|
|
@@ -152,29 +151,29 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
152
151
|
|
|
153
152
|
private findAndReportLocalData(
|
|
154
153
|
idToFind: Uint8Array,
|
|
155
|
-
|
|
154
|
+
fetchData: boolean,
|
|
156
155
|
routingPath: PeerDescriptor[],
|
|
157
156
|
sourcePeer: PeerDescriptor,
|
|
158
157
|
sessionId: string
|
|
159
158
|
): boolean {
|
|
160
|
-
if (
|
|
159
|
+
if (fetchData) {
|
|
161
160
|
const data = this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
162
161
|
if (data.size > 0) {
|
|
163
|
-
this.
|
|
162
|
+
this.sendFindResponse(routingPath, sourcePeer, sessionId, [], data, true)
|
|
164
163
|
return true
|
|
165
164
|
}
|
|
166
165
|
}
|
|
167
166
|
return false
|
|
168
167
|
}
|
|
169
168
|
|
|
170
|
-
private findLocalData(idToFind: Uint8Array,
|
|
171
|
-
if (
|
|
169
|
+
private findLocalData(idToFind: Uint8Array, fetchData: boolean): Map<PeerIDKey, DataEntry> | undefined {
|
|
170
|
+
if (fetchData) {
|
|
172
171
|
return this.localDataStore.getEntry(PeerID.fromValue(idToFind))
|
|
173
172
|
}
|
|
174
173
|
return undefined
|
|
175
174
|
}
|
|
176
175
|
|
|
177
|
-
private
|
|
176
|
+
private sendFindResponse(
|
|
178
177
|
routingPath: PeerDescriptor[],
|
|
179
178
|
targetPeerDescriptor: PeerDescriptor,
|
|
180
179
|
serviceId: string,
|
|
@@ -186,7 +185,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
186
185
|
const isOwnNode = areEqualPeerDescriptors(this.ownPeerDescriptor, targetPeerDescriptor)
|
|
187
186
|
if (isOwnNode && this.ongoingSessions.has(serviceId)) {
|
|
188
187
|
this.ongoingSessions.get(serviceId)!
|
|
189
|
-
.
|
|
188
|
+
.doSendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
190
189
|
} else {
|
|
191
190
|
const remoteCommunicator = new ListeningRpcCommunicator(serviceId, this.sessionTransport, { rpcRequestTimeout: 15000 })
|
|
192
191
|
const remoteSession = new RemoteRecursiveFindSession(
|
|
@@ -195,7 +194,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
195
194
|
serviceId,
|
|
196
195
|
toProtoRpcClient(new RecursiveFindSessionServiceClient(remoteCommunicator.getRpcClientTransport()))
|
|
197
196
|
)
|
|
198
|
-
remoteSession.
|
|
197
|
+
remoteSession.sendFindResponse(routingPath, closestNodes, dataEntries, noCloserNodesFound)
|
|
199
198
|
}
|
|
200
199
|
}
|
|
201
200
|
|
|
@@ -205,18 +204,18 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
205
204
|
}
|
|
206
205
|
const idToFind = peerIdFromPeerDescriptor(routedMessage.destinationPeer!)
|
|
207
206
|
const msg = routedMessage.message
|
|
208
|
-
const
|
|
207
|
+
const findRequest = msg?.body.oneofKind === 'findRequest' ? msg.body.findRequest : undefined
|
|
209
208
|
const closestPeersToDestination = this.getClosestConnections(routedMessage.destinationPeer!.kademliaId, 5)
|
|
210
|
-
const data = this.findLocalData(idToFind.value,
|
|
209
|
+
const data = this.findLocalData(idToFind.value, findRequest!.fetchData)
|
|
211
210
|
if (areEqualPeerDescriptors(this.ownPeerDescriptor, routedMessage.destinationPeer!)) {
|
|
212
|
-
this.
|
|
211
|
+
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
213
212
|
closestPeersToDestination, data, true)
|
|
214
213
|
return createRouteMessageAck(routedMessage)
|
|
215
214
|
}
|
|
216
215
|
const ack = this.router.doRouteMessage(routedMessage, RoutingMode.RECURSIVE_FIND, excludedPeer)
|
|
217
216
|
if (ack.error === RoutingErrors.NO_CANDIDATES_FOUND) {
|
|
218
217
|
logger.trace(`findRecursively Node found no candidates`)
|
|
219
|
-
this.
|
|
218
|
+
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
220
219
|
closestPeersToDestination, data, true)
|
|
221
220
|
} else if (ack.error) {
|
|
222
221
|
return ack
|
|
@@ -226,7 +225,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
226
225
|
&& routedMessage.previousPeer
|
|
227
226
|
&& !this.isPeerCloserToIdThanSelf(closestPeersToDestination[0], idToFind)
|
|
228
227
|
)
|
|
229
|
-
this.
|
|
228
|
+
this.sendFindResponse(routedMessage.routingPath, routedMessage.sourcePeer!, findRequest!.sessionId,
|
|
230
229
|
closestPeersToDestination, data, noCloserContactsFound)
|
|
231
230
|
}
|
|
232
231
|
return ack
|
|
@@ -245,7 +244,7 @@ export class RecursiveFinder implements IRecursiveFinder {
|
|
|
245
244
|
return closestPeers.getClosestContacts(limit).map((peer) => peer.getPeerDescriptor())
|
|
246
245
|
}
|
|
247
246
|
|
|
248
|
-
//
|
|
247
|
+
// IRouterRpc method
|
|
249
248
|
async findRecursively(routedMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
250
249
|
if (this.stopped) {
|
|
251
250
|
return createRouteMessageAck(routedMessage, 'findRecursively() service is not running')
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DataEntry,
|
|
3
3
|
PeerDescriptor,
|
|
4
|
-
|
|
4
|
+
FindResponse
|
|
5
5
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
6
6
|
import { IRecursiveFindSessionServiceClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
7
7
|
import { Logger } from '@streamr/utils'
|
|
@@ -11,16 +11,16 @@ const logger = new Logger(module)
|
|
|
11
11
|
|
|
12
12
|
export class RemoteRecursiveFindSession extends Remote<IRecursiveFindSessionServiceClient> {
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
sendFindResponse(routingPath: PeerDescriptor[], closestNodes: PeerDescriptor[],
|
|
15
15
|
dataEntries: DataEntry[], noCloserNodesFound: boolean): void {
|
|
16
|
-
const report:
|
|
16
|
+
const report: FindResponse = {
|
|
17
17
|
routingPath,
|
|
18
|
-
|
|
18
|
+
closestConnectedPeers: closestNodes,
|
|
19
19
|
dataEntries,
|
|
20
20
|
noCloserNodesFound
|
|
21
21
|
}
|
|
22
|
-
this.getClient().
|
|
23
|
-
logger.trace('Failed to send
|
|
22
|
+
this.getClient().sendFindResponse(report, this.formDhtRpcOptions()).catch((_e) => {
|
|
23
|
+
logger.trace('Failed to send FindResult')
|
|
24
24
|
})
|
|
25
25
|
}
|
|
26
26
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { DhtNode } from '../dht/DhtNode'
|
|
2
|
-
import { ExternalStoreDataRequest, ExternalStoreDataResponse, FindDataRequest, FindDataResponse
|
|
2
|
+
import { ExternalStoreDataRequest, ExternalStoreDataResponse, FindDataRequest, FindDataResponse } from '../proto/packages/dht/protos/DhtRpc'
|
|
3
|
+
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
4
|
+
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
3
5
|
|
|
4
6
|
export const registerExternalApiRpcMethods = (thisNode: DhtNode): void => {
|
|
5
7
|
const rpcCommunicator = thisNode.getRpcCommunicator()
|
|
@@ -7,7 +9,7 @@ export const registerExternalApiRpcMethods = (thisNode: DhtNode): void => {
|
|
|
7
9
|
FindDataRequest,
|
|
8
10
|
FindDataResponse,
|
|
9
11
|
'findData',
|
|
10
|
-
(req: FindDataRequest) => findData(thisNode, req),
|
|
12
|
+
(req: FindDataRequest, context: ServerCallContext) => findData(thisNode, req, context),
|
|
11
13
|
{ timeout: 10000 }
|
|
12
14
|
)
|
|
13
15
|
rpcCommunicator.registerRpcMethod(
|
|
@@ -20,8 +22,9 @@ export const registerExternalApiRpcMethods = (thisNode: DhtNode): void => {
|
|
|
20
22
|
}
|
|
21
23
|
|
|
22
24
|
// IDHTRpcService method for external findRecursive calls
|
|
23
|
-
const findData = async (thisNode: DhtNode, findDataRequest: FindDataRequest): Promise<FindDataResponse> => {
|
|
24
|
-
const
|
|
25
|
+
const findData = async (thisNode: DhtNode, findDataRequest: FindDataRequest, context: ServerCallContext): Promise<FindDataResponse> => {
|
|
26
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
27
|
+
const result = await thisNode.startRecursiveFind(findDataRequest.kademliaId, true, senderPeerDescriptor)
|
|
25
28
|
if (result.dataEntries) {
|
|
26
29
|
return FindDataResponse.create({ dataEntries: result.dataEntries })
|
|
27
30
|
} else {
|
|
@@ -8,13 +8,11 @@ import { DuplicateDetector } from './DuplicateDetector'
|
|
|
8
8
|
import { ConnectionManager } from '../../connection/ConnectionManager'
|
|
9
9
|
import { RemoteDhtNode } from '../RemoteDhtNode'
|
|
10
10
|
import { v4 } from 'uuid'
|
|
11
|
-
import {
|
|
11
|
+
import { IRouterRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
|
|
12
12
|
|
|
13
13
|
export const createRouteMessageAck = (routedMessage: RouteMessageWrapper, error?: string): RouteMessageAck => {
|
|
14
14
|
const ack: RouteMessageAck = {
|
|
15
15
|
requestId: routedMessage.requestId,
|
|
16
|
-
destinationPeer: routedMessage.sourcePeer,
|
|
17
|
-
sourcePeer: routedMessage.destinationPeer,
|
|
18
16
|
error: error ? error : ''
|
|
19
17
|
}
|
|
20
18
|
return ack
|
|
@@ -49,7 +47,7 @@ interface IRouterFunc {
|
|
|
49
47
|
stop(): void
|
|
50
48
|
}
|
|
51
49
|
|
|
52
|
-
export interface IRouter extends Omit<
|
|
50
|
+
export interface IRouter extends Omit<IRouterRpc, 'findRecursively'>, IRouterFunc {}
|
|
53
51
|
|
|
54
52
|
const logger = new Logger(module)
|
|
55
53
|
|
|
@@ -194,7 +192,7 @@ export class Router implements IRouter {
|
|
|
194
192
|
this.duplicateRequestDetector.clear()
|
|
195
193
|
}
|
|
196
194
|
|
|
197
|
-
//
|
|
195
|
+
// IRouterRpc method
|
|
198
196
|
async routeMessage(routedMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
199
197
|
if (this.stopped) {
|
|
200
198
|
return createRouteMessageAck(routedMessage, 'routeMessage() service is not running')
|
|
@@ -238,7 +236,7 @@ export class Router implements IRouter {
|
|
|
238
236
|
}
|
|
239
237
|
}
|
|
240
238
|
|
|
241
|
-
//
|
|
239
|
+
// IRouterRpc method
|
|
242
240
|
async forwardMessage(forwardMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
|
|
243
241
|
if (this.stopped) {
|
|
244
242
|
return createRouteMessageAck(forwardMessage, 'forwardMessage() service is not running')
|
|
@@ -5,13 +5,13 @@ import {
|
|
|
5
5
|
keyFromPeerDescriptor,
|
|
6
6
|
peerIdFromPeerDescriptor
|
|
7
7
|
} from '../../helpers/peerIdFromPeerDescriptor'
|
|
8
|
-
import {
|
|
8
|
+
import { IRouterRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
9
9
|
import { Remote } from '../contact/Remote'
|
|
10
10
|
import { Logger } from '@streamr/utils'
|
|
11
11
|
|
|
12
12
|
const logger = new Logger(module)
|
|
13
13
|
|
|
14
|
-
export class
|
|
14
|
+
export class RouterRpcRemote extends Remote<IRouterRpcClient> {
|
|
15
15
|
|
|
16
16
|
async routeMessage(params: RouteMessageWrapper): Promise<boolean> {
|
|
17
17
|
const message: RouteMessageWrapper = {
|