@streamr/dht 100.0.0-testnet-two.1 → 100.0.0-testnet-two.3
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 +5 -5
- package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionManager.d.ts +5 -4
- package/dist/src/connection/ConnectionManager.js +32 -36
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -2
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +21 -22
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +4 -3
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +11 -8
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +6 -5
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -8
- package/dist/src/dht/DhtNode.js +26 -22
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
- package/dist/src/dht/DhtNodeRpcRemote.js +9 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +9 -9
- package/dist/src/dht/PeerManager.js +35 -30
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +2 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +1 -4
- package/dist/src/dht/contact/RpcRemote.js +1 -5
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +5 -5
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -2
- package/dist/src/dht/discovery/DiscoverySession.js +9 -9
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +18 -10
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +15 -14
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +6 -6
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -2
- package/dist/src/dht/routing/Router.js +2 -2
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +3 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +4 -2
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
- package/dist/src/dht/routing/RoutingSession.js +4 -4
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +6 -9
- package/dist/src/dht/store/LocalDataStore.js +27 -32
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +26 -23
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +2 -1
- package/dist/src/dht/store/StoreRpcLocal.js +10 -8
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js +6 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +2 -2
- package/dist/src/helpers/PeerID.js +3 -3
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -2
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/identifiers.d.ts +6 -0
- package/dist/src/identifiers.js +23 -0
- package/dist/src/identifiers.js.map +1 -0
- package/package.json +5 -5
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +3 -3
- package/src/connection/ConnectionManager.ts +36 -46
- package/src/connection/ManagedConnection.ts +2 -2
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnection.ts +21 -23
- package/src/connection/simulator/SimulatorConnector.ts +6 -5
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/NodeWebrtcConnection.ts +11 -10
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -3
- package/src/connection/websocket/WebsocketConnector.ts +9 -9
- package/src/dht/DhtNode.ts +36 -35
- package/src/dht/DhtNodeRpcLocal.ts +3 -2
- package/src/dht/DhtNodeRpcRemote.ts +14 -12
- package/src/dht/ExternalApiRpcLocal.ts +15 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -4
- package/src/dht/PeerManager.ts +43 -38
- package/src/dht/contact/Contact.ts +2 -2
- package/src/dht/contact/ContactList.ts +7 -7
- package/src/dht/contact/RandomContactList.ts +6 -6
- package/src/dht/contact/RpcRemote.ts +0 -8
- package/src/dht/contact/SortedContactList.ts +22 -22
- package/src/dht/discovery/DiscoverySession.ts +16 -14
- package/src/dht/discovery/PeerDiscovery.ts +34 -12
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +17 -17
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +2 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +11 -11
- package/src/dht/routing/Router.ts +5 -5
- package/src/dht/routing/RouterRpcLocal.ts +3 -3
- package/src/dht/routing/RouterRpcRemote.ts +4 -4
- package/src/dht/routing/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +31 -40
- package/src/dht/store/StoreManager.ts +31 -31
- package/src/dht/store/StoreRpcLocal.ts +11 -9
- package/src/exports.ts +2 -0
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/PeerID.ts +4 -4
- package/src/helpers/peerIdFromPeerDescriptor.ts +4 -6
- package/src/identifiers.ts +20 -0
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +4 -3
- package/test/benchmark/KademliaCorrectness.test.ts +4 -4
- package/test/benchmark/SortedContactListBenchmark.test.ts +15 -14
- package/test/benchmark/kademlia-simulation/Contact.ts +7 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +10 -11
- package/test/data/generateGroundTruthData.ts +5 -4
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +3 -2
- package/test/integration/ConnectionManager.test.ts +3 -3
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -1
- package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +3 -2
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +3 -3
- package/test/integration/Mock-Layer1-Layer0.test.ts +6 -5
- package/test/integration/ReplicateData.test.ts +38 -30
- package/test/integration/RouteMessage.test.ts +9 -10
- package/test/integration/RouterRpcRemote.test.ts +1 -1
- package/test/integration/ScaleDownDht.test.ts +4 -4
- package/test/integration/SimultaneousConnections.test.ts +7 -14
- package/test/integration/Store.test.ts +17 -7
- package/test/integration/StoreAndDelete.test.ts +11 -10
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -6
- package/test/integration/StoreRpcRemote.test.ts +3 -5
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/LocalDataStore.test.ts +41 -41
- package/test/unit/PeerManager.test.ts +7 -8
- package/test/unit/RandomContactList.test.ts +3 -3
- package/test/unit/RecursiveOperationManager.test.ts +2 -1
- package/test/unit/RecursiveOperationSession.test.ts +2 -3
- package/test/unit/Router.test.ts +2 -2
- package/test/unit/RoutingSession.test.ts +2 -2
- package/test/unit/SortedContactList.test.ts +6 -6
- package/test/unit/StoreManager.test.ts +26 -23
- package/test/utils/customMatchers.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +8 -6
- package/test/utils/utils.ts +4 -4
- package/dist/src/helpers/nodeId.d.ts +0 -6
- package/dist/src/helpers/nodeId.js +0 -31
- package/dist/src/helpers/nodeId.js.map +0 -1
- package/src/helpers/nodeId.ts +0 -28
|
@@ -6,7 +6,7 @@ import { Logger, runAndRaceEvents3, RunAndRaceEventsReturnType } from '@streamr/
|
|
|
6
6
|
import EventEmitter from 'eventemitter3'
|
|
7
7
|
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
8
8
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
9
|
-
import {
|
|
9
|
+
import { DhtAddress } from '../identifiers'
|
|
10
10
|
|
|
11
11
|
export interface ManagedConnectionEvents {
|
|
12
12
|
managedData: (bytes: Uint8Array, remotePeerDescriptor: PeerDescriptor) => void
|
|
@@ -156,7 +156,7 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
156
156
|
return this
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
public getNodeId():
|
|
159
|
+
public getNodeId(): DhtAddress {
|
|
160
160
|
return getNodeIdFromPeerDescriptor(this.remotePeerDescriptor!)
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -10,7 +10,7 @@ import { getRegionDelayMatrix } from './pings'
|
|
|
10
10
|
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
11
11
|
import Heap from 'heap'
|
|
12
12
|
import { debugVars } from '../../helpers/debugHelpers'
|
|
13
|
-
import {
|
|
13
|
+
import { DhtAddress } from '../../identifiers'
|
|
14
14
|
|
|
15
15
|
const logger = new Logger(module)
|
|
16
16
|
|
|
@@ -92,7 +92,7 @@ class CloseOperation extends SimulatorOperation {
|
|
|
92
92
|
|
|
93
93
|
export class Simulator extends EventEmitter<ConnectionSourceEvents> {
|
|
94
94
|
private stopped = false
|
|
95
|
-
private connectors: Map<
|
|
95
|
+
private connectors: Map<DhtAddress, SimulatorConnector> = new Map()
|
|
96
96
|
private latencyTable?: Array<Array<number>>
|
|
97
97
|
private associations: Map<ConnectionID, Association> = new Map()
|
|
98
98
|
|
|
@@ -45,38 +45,34 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
45
45
|
this.simulator.send(this, data)
|
|
46
46
|
|
|
47
47
|
} else {
|
|
48
|
-
|
|
49
|
-
|
|
48
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
49
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
|
|
50
|
+
logger.error(localNodeId + ', ' + targetNodeId + 'tried to send() on a stopped connection')
|
|
50
51
|
}
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
public async close(gracefulLeave: boolean): Promise<void> {
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
56
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
|
|
56
57
|
|
|
58
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close()')
|
|
57
59
|
if (!this.stopped) {
|
|
58
|
-
logger.trace(
|
|
59
|
-
+ getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' close() not stopped')
|
|
60
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() not stopped')
|
|
60
61
|
this.stopped = true
|
|
61
62
|
|
|
62
63
|
try {
|
|
63
|
-
logger.trace(
|
|
64
|
-
' close() calling simulator.disconnect()')
|
|
64
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() calling simulator.disconnect()')
|
|
65
65
|
this.simulator.close(this)
|
|
66
|
-
logger.trace(
|
|
67
|
-
' close() simulator.disconnect returned')
|
|
66
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() simulator.disconnect returned')
|
|
68
67
|
} catch (e) {
|
|
69
|
-
logger.trace(
|
|
70
|
-
'close aborted' + e)
|
|
68
|
+
logger.trace(localNodeId + ', ' + targetNodeId + 'close aborted' + e)
|
|
71
69
|
} finally {
|
|
72
|
-
logger.trace(
|
|
73
|
-
' calling this.doDisconnect')
|
|
70
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' calling this.doDisconnect')
|
|
74
71
|
this.doDisconnect(gracefulLeave)
|
|
75
72
|
}
|
|
76
73
|
|
|
77
74
|
} else {
|
|
78
|
-
logger.trace(
|
|
79
|
-
' close() tried to close a stopped connection')
|
|
75
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() tried to close a stopped connection')
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
78
|
|
|
@@ -109,7 +105,8 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
109
105
|
|
|
110
106
|
public handleIncomingDisconnection(): void {
|
|
111
107
|
if (!this.stopped) {
|
|
112
|
-
|
|
108
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
109
|
+
logger.trace(localNodeId + ' handleIncomingDisconnection()')
|
|
113
110
|
this.stopped = true
|
|
114
111
|
this.doDisconnect(false)
|
|
115
112
|
} else {
|
|
@@ -118,23 +115,24 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
118
115
|
}
|
|
119
116
|
|
|
120
117
|
public destroy(): void {
|
|
118
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
121
119
|
if (!this.stopped) {
|
|
122
|
-
logger.trace(
|
|
120
|
+
logger.trace(localNodeId + ' destroy()')
|
|
123
121
|
this.removeAllListeners()
|
|
124
122
|
this.close(false).catch((_e) => { })
|
|
125
123
|
} else {
|
|
126
|
-
logger.trace(
|
|
124
|
+
logger.trace(localNodeId + ' tried to call destroy() a stopped connection')
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
private doDisconnect(gracefulLeave: boolean) {
|
|
131
|
-
|
|
129
|
+
const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
|
|
130
|
+
const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
|
|
131
|
+
logger.trace(localNodeId + ' doDisconnect()')
|
|
132
132
|
this.stopped = true
|
|
133
133
|
|
|
134
|
-
logger.trace(
|
|
135
|
-
+ getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' doDisconnect emitting')
|
|
134
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' doDisconnect emitting')
|
|
136
135
|
|
|
137
136
|
this.emit('disconnected', gracefulLeave)
|
|
138
|
-
|
|
139
137
|
}
|
|
140
138
|
}
|
|
@@ -9,13 +9,13 @@ import { ManagedConnection } from '../ManagedConnection'
|
|
|
9
9
|
import { Simulator } from './Simulator'
|
|
10
10
|
import { SimulatorConnection } from './SimulatorConnection'
|
|
11
11
|
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
12
|
-
import {
|
|
12
|
+
import { DhtAddress } from '../../identifiers'
|
|
13
13
|
|
|
14
14
|
const logger = new Logger(module)
|
|
15
15
|
|
|
16
16
|
export class SimulatorConnector {
|
|
17
17
|
|
|
18
|
-
private connectingConnections: Map<
|
|
18
|
+
private connectingConnections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
19
19
|
private stopped = false
|
|
20
20
|
private localPeerDescriptor: PeerDescriptor
|
|
21
21
|
private simulator: Simulator
|
|
@@ -62,7 +62,8 @@ export class SimulatorConnector {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
public handleIncomingConnection(sourceConnection: SimulatorConnection): void {
|
|
65
|
-
|
|
65
|
+
const localNodeId = getNodeIdFromPeerDescriptor(sourceConnection.localPeerDescriptor)
|
|
66
|
+
logger.trace(localNodeId + ' incoming connection, stopped: ' + this.stopped)
|
|
66
67
|
if (this.stopped) {
|
|
67
68
|
return
|
|
68
69
|
}
|
|
@@ -74,10 +75,10 @@ export class SimulatorConnector {
|
|
|
74
75
|
logger.trace('connected')
|
|
75
76
|
|
|
76
77
|
managedConnection.once('handshakeRequest', () => {
|
|
77
|
-
logger.trace(
|
|
78
|
+
logger.trace(localNodeId + ' incoming handshake request')
|
|
78
79
|
|
|
79
80
|
if (this.onNewConnection(managedConnection)) {
|
|
80
|
-
logger.trace(
|
|
81
|
+
logger.trace(localNodeId + ' calling acceptHandshake')
|
|
81
82
|
managedConnection.acceptHandshake()
|
|
82
83
|
} else {
|
|
83
84
|
managedConnection.rejectHandshake(HandshakeError.DUPLICATE_CONNECTION)
|
|
@@ -194,10 +194,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
194
194
|
logger.warn(`dc.onError: ${err}`)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
dataChannel.onbufferedamountlow = () => {
|
|
198
|
-
//this.emitLowBackpressure()
|
|
199
|
-
}
|
|
200
|
-
|
|
201
197
|
dataChannel.onmessage = (msg) => {
|
|
202
198
|
logger.trace('dc.onmessage')
|
|
203
199
|
this.emit('data', new Uint8Array(msg.data))
|
|
@@ -80,7 +80,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
80
80
|
|
|
81
81
|
public start(isOffering: boolean): void {
|
|
82
82
|
const nodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
83
|
-
logger.trace(`Starting new connection for peer ${
|
|
83
|
+
logger.trace(`Starting new connection for peer ${nodeId}`, { isOffering })
|
|
84
84
|
this.connection = new PeerConnection(nodeId, {
|
|
85
85
|
iceServers: this.iceServers.map(iceServerAsString),
|
|
86
86
|
maxMessageSize: this.maxMessageSize,
|
|
@@ -112,12 +112,13 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
112
112
|
|
|
113
113
|
public async setRemoteDescription(description: string, type: string): Promise<void> {
|
|
114
114
|
if (this.connection) {
|
|
115
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
115
116
|
try {
|
|
116
|
-
logger.trace(`Setting remote descriptor for peer: ${
|
|
117
|
+
logger.trace(`Setting remote descriptor for peer: ${remoteNodeId}`)
|
|
117
118
|
this.connection.setRemoteDescription(description, type as DescriptionType)
|
|
118
119
|
this.remoteDescriptionSet = true
|
|
119
120
|
} catch (err) {
|
|
120
|
-
logger.debug(`Failed to set remote descriptor for peer ${
|
|
121
|
+
logger.debug(`Failed to set remote descriptor for peer ${remoteNodeId}`)
|
|
121
122
|
}
|
|
122
123
|
} else {
|
|
123
124
|
this.doClose(false, `Tried to set description for non-existent connection`)
|
|
@@ -127,11 +128,12 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
127
128
|
public addRemoteCandidate(candidate: string, mid: string): void {
|
|
128
129
|
if (this.connection) {
|
|
129
130
|
if (this.remoteDescriptionSet) {
|
|
131
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
130
132
|
try {
|
|
131
|
-
logger.trace(`Setting remote candidate for peer: ${
|
|
133
|
+
logger.trace(`Setting remote candidate for peer: ${remoteNodeId}`)
|
|
132
134
|
this.connection.addRemoteCandidate(candidate, mid)
|
|
133
135
|
} catch (err) {
|
|
134
|
-
logger.debug(`Failed to set remote candidate for peer ${
|
|
136
|
+
logger.debug(`Failed to set remote candidate for peer ${remoteNodeId}`)
|
|
135
137
|
}
|
|
136
138
|
} else {
|
|
137
139
|
// TODO: should queue candidates until remote description is set?
|
|
@@ -147,7 +149,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
147
149
|
try {
|
|
148
150
|
this.dataChannel!.sendMessageBinary(data as Buffer)
|
|
149
151
|
} catch (err) {
|
|
150
|
-
|
|
152
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
153
|
+
logger.debug('Failed to send binary message to ' + remoteNodeId + err)
|
|
151
154
|
}
|
|
152
155
|
}
|
|
153
156
|
}
|
|
@@ -158,10 +161,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
|
|
|
158
161
|
|
|
159
162
|
private doClose(gracefulLeave: boolean, reason?: string): void {
|
|
160
163
|
if (!this.closed) {
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
+ `${(reason !== undefined) ? `, reason: ${reason}` : ''}`
|
|
164
|
-
)
|
|
164
|
+
const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
|
|
165
|
+
logger.trace(`Closing Node WebRTC Connection to ${remoteNodeId}` + `${(reason !== undefined) ? `, reason: ${reason}` : ''}`)
|
|
165
166
|
|
|
166
167
|
this.closed = true
|
|
167
168
|
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { PortRange } from '../ConnectionManager'
|
|
22
22
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
23
23
|
import { WebrtcConnectorRpcLocal } from './WebrtcConnectorRpcLocal'
|
|
24
|
-
import {
|
|
24
|
+
import { DhtAddress } from '../../identifiers'
|
|
25
25
|
|
|
26
26
|
const logger = new Logger(module)
|
|
27
27
|
|
|
@@ -58,7 +58,7 @@ export class WebrtcConnector {
|
|
|
58
58
|
|
|
59
59
|
private static readonly WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc-connector'
|
|
60
60
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
61
|
-
private readonly ongoingConnectAttempts: Map<
|
|
61
|
+
private readonly ongoingConnectAttempts: Map<DhtAddress, ManagedWebrtcConnection> = new Map()
|
|
62
62
|
private localPeerDescriptor?: PeerDescriptor
|
|
63
63
|
private stopped = false
|
|
64
64
|
private config: WebrtcConnectorConfig
|
|
@@ -170,7 +170,6 @@ export class WebrtcConnector {
|
|
|
170
170
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
171
171
|
this.localPeerDescriptor!,
|
|
172
172
|
targetPeerDescriptor,
|
|
173
|
-
'DUMMY',
|
|
174
173
|
this.rpcCommunicator,
|
|
175
174
|
WebrtcConnectorRpcClient
|
|
176
175
|
)
|
|
@@ -18,7 +18,7 @@ import { ManagedConnection } from '../ManagedConnection'
|
|
|
18
18
|
import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
|
|
19
19
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
20
20
|
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
21
|
-
import {
|
|
21
|
+
import { DhtAddress } from '../../identifiers'
|
|
22
22
|
import { version } from '../../../package.json'
|
|
23
23
|
import { isCompatibleVersion } from '../../helpers/versionCompatibility'
|
|
24
24
|
|
|
@@ -28,7 +28,7 @@ interface WebrtcConnectorRpcLocalConfig {
|
|
|
28
28
|
connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
|
|
29
29
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
30
30
|
// TODO pass accessor methods instead of passing a mutable entity
|
|
31
|
-
ongoingConnectAttempts: Map<
|
|
31
|
+
ongoingConnectAttempts: Map<DhtAddress, ManagedWebrtcConnection>
|
|
32
32
|
rpcCommunicator: ListeningRpcCommunicator
|
|
33
33
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
34
34
|
allowPrivateAddresses: boolean
|
|
@@ -68,7 +68,6 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
68
68
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
69
69
|
this.config.getLocalPeerDescriptor(),
|
|
70
70
|
remotePeer,
|
|
71
|
-
'DUMMY',
|
|
72
71
|
this.config.rpcCommunicator,
|
|
73
72
|
WebrtcConnectorRpcClient
|
|
74
73
|
)
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
WebsocketConnectionRequest
|
|
13
13
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
14
14
|
import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
15
|
-
import { Logger,
|
|
15
|
+
import { Logger, wait } from '@streamr/utils'
|
|
16
16
|
import { ManagedConnection } from '../ManagedConnection'
|
|
17
17
|
import { WebsocketServer } from './WebsocketServer'
|
|
18
18
|
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
@@ -29,7 +29,7 @@ import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
|
29
29
|
import { attachConnectivityRequestHandler } from '../connectivityRequestHandler'
|
|
30
30
|
import * as Err from '../../helpers/errors'
|
|
31
31
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
32
|
-
import {
|
|
32
|
+
import { DhtAddress } from '../../identifiers'
|
|
33
33
|
import { version } from '../../../package.json'
|
|
34
34
|
import { isCompatibleVersion } from '../../helpers/versionCompatibility'
|
|
35
35
|
|
|
@@ -63,12 +63,12 @@ export class WebsocketConnector {
|
|
|
63
63
|
private static readonly WEBSOCKET_CONNECTOR_SERVICE_ID = 'system/websocket-connector'
|
|
64
64
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
65
65
|
private readonly websocketServer?: WebsocketServer
|
|
66
|
-
private readonly ongoingConnectRequests: Map<
|
|
66
|
+
private readonly ongoingConnectRequests: Map<DhtAddress, ManagedConnection> = new Map()
|
|
67
67
|
private host?: string
|
|
68
68
|
private autoCertifierClient?: AutoCertifierClientFacade
|
|
69
69
|
private selectedPort?: number
|
|
70
70
|
private localPeerDescriptor?: PeerDescriptor
|
|
71
|
-
private connectingConnections: Map<
|
|
71
|
+
private connectingConnections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
72
72
|
private abortController = new AbortController()
|
|
73
73
|
private readonly config: WebsocketConnectorConfig
|
|
74
74
|
|
|
@@ -203,7 +203,7 @@ export class WebsocketConnector {
|
|
|
203
203
|
}
|
|
204
204
|
} catch (err) {
|
|
205
205
|
if (reattempt < ENTRY_POINT_CONNECTION_ATTEMPTS) {
|
|
206
|
-
const error = `Failed to connect to entrypoint with id ${
|
|
206
|
+
const error = `Failed to connect to entrypoint with id ${getNodeIdFromPeerDescriptor(entryPoint)} `
|
|
207
207
|
+ `and URL ${connectivityMethodToWebsocketUrl(entryPoint.websocket!)}`
|
|
208
208
|
logger.error(error, { error: err })
|
|
209
209
|
await wait(2000)
|
|
@@ -241,7 +241,7 @@ export class WebsocketConnector {
|
|
|
241
241
|
)
|
|
242
242
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
243
243
|
|
|
244
|
-
this.connectingConnections.set(
|
|
244
|
+
this.connectingConnections.set(nodeId, managedConnection)
|
|
245
245
|
|
|
246
246
|
const delFunc = () => {
|
|
247
247
|
if (this.connectingConnections.has(nodeId)) {
|
|
@@ -264,7 +264,6 @@ export class WebsocketConnector {
|
|
|
264
264
|
const remoteConnector = new WebsocketConnectorRpcRemote(
|
|
265
265
|
localPeerDescriptor,
|
|
266
266
|
targetPeerDescriptor,
|
|
267
|
-
'DUMMY',
|
|
268
267
|
this.rpcCommunicator,
|
|
269
268
|
WebsocketConnectorRpcClient
|
|
270
269
|
)
|
|
@@ -284,9 +283,10 @@ export class WebsocketConnector {
|
|
|
284
283
|
undefined,
|
|
285
284
|
targetPeerDescriptor
|
|
286
285
|
)
|
|
287
|
-
|
|
286
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
287
|
+
managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(nodeId))
|
|
288
288
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
289
|
-
this.ongoingConnectRequests.set(
|
|
289
|
+
this.ongoingConnectRequests.set(nodeId, managedConnection)
|
|
290
290
|
return managedConnection
|
|
291
291
|
}
|
|
292
292
|
|
package/src/dht/DhtNode.ts
CHANGED
|
@@ -25,7 +25,6 @@ import { ExternalApiRpcClient, StoreRpcClient } from '../proto/packages/dht/prot
|
|
|
25
25
|
import {
|
|
26
26
|
Logger,
|
|
27
27
|
MetricsContext,
|
|
28
|
-
hexToBinary,
|
|
29
28
|
merge,
|
|
30
29
|
waitForCondition
|
|
31
30
|
} from '@streamr/utils'
|
|
@@ -50,7 +49,7 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
|
50
49
|
import { ExternalApiRpcLocal } from './ExternalApiRpcLocal'
|
|
51
50
|
import { PeerManager } from './PeerManager'
|
|
52
51
|
import { ServiceID } from '../types/ServiceID'
|
|
53
|
-
import {
|
|
52
|
+
import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../identifiers'
|
|
54
53
|
import { StoreRpcRemote } from './store/StoreRpcRemote'
|
|
55
54
|
|
|
56
55
|
export interface DhtNodeEvents {
|
|
@@ -118,11 +117,11 @@ const logger = new Logger(module)
|
|
|
118
117
|
export type Events = TransportEvents & DhtNodeEvents
|
|
119
118
|
|
|
120
119
|
export const createPeerDescriptor = (msg?: ConnectivityResponse, peerId?: string): PeerDescriptor => {
|
|
121
|
-
let nodeId:
|
|
120
|
+
let nodeId: DhtAddressRaw
|
|
122
121
|
if (msg) {
|
|
123
|
-
nodeId = (peerId !== undefined) ?
|
|
122
|
+
nodeId = (peerId !== undefined) ? getRawFromDhtAddress(peerId as DhtAddress) : PeerID.fromIp(msg.host).value
|
|
124
123
|
} else {
|
|
125
|
-
nodeId =
|
|
124
|
+
nodeId = getRawFromDhtAddress(peerId! as DhtAddress)
|
|
126
125
|
}
|
|
127
126
|
const nodeType = isBrowserEnvironment() ? NodeType.BROWSER : NodeType.NODEJS
|
|
128
127
|
const ret: PeerDescriptor = { nodeId, type: nodeType }
|
|
@@ -276,14 +275,13 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
276
275
|
highestTtl: this.config.storeHighestTtl,
|
|
277
276
|
redundancyFactor: this.config.storageRedundancyFactor,
|
|
278
277
|
localDataStore: this.localDataStore,
|
|
279
|
-
getClosestNeighborsTo: (
|
|
280
|
-
return this.peerManager!.getClosestNeighborsTo(
|
|
278
|
+
getClosestNeighborsTo: (key: DhtAddress, n?: number) => {
|
|
279
|
+
return this.peerManager!.getClosestNeighborsTo(key, n).map((n) => n.getPeerDescriptor())
|
|
281
280
|
},
|
|
282
281
|
createRpcRemote: (contact: PeerDescriptor) => {
|
|
283
282
|
return new StoreRpcRemote(
|
|
284
283
|
this.localPeerDescriptor!,
|
|
285
284
|
contact,
|
|
286
|
-
this.config.serviceId,
|
|
287
285
|
this.rpcCommunicator!,
|
|
288
286
|
StoreRpcClient,
|
|
289
287
|
this.config.rpcRequestTimeout
|
|
@@ -350,8 +348,8 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
350
348
|
}
|
|
351
349
|
const dhtNodeRpcLocal = new DhtNodeRpcLocal({
|
|
352
350
|
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
353
|
-
getClosestPeersTo: (
|
|
354
|
-
return this.peerManager!.getClosestNeighborsTo(
|
|
351
|
+
getClosestPeersTo: (nodeId: DhtAddress, limit: number) => {
|
|
352
|
+
return this.peerManager!.getClosestNeighborsTo(nodeId, limit)
|
|
355
353
|
.map((dhtPeer: DhtNodeRpcRemote) => dhtPeer.getPeerDescriptor())
|
|
356
354
|
},
|
|
357
355
|
addNewContact: (contact: PeerDescriptor) => this.peerManager!.handleNewPeers([contact]),
|
|
@@ -364,10 +362,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
364
362
|
this.rpcCommunicator!.registerRpcNotification(LeaveNotice, 'leaveNotice',
|
|
365
363
|
(_req: LeaveNotice, context) => dhtNodeRpcLocal.leaveNotice(context))
|
|
366
364
|
const externalApiRpcLocal = new ExternalApiRpcLocal({
|
|
367
|
-
executeRecursiveOperation: (key:
|
|
365
|
+
executeRecursiveOperation: (key: DhtAddress, operation: RecursiveOperation, excludedPeer: PeerDescriptor) => {
|
|
368
366
|
return this.executeRecursiveOperation(key, operation, excludedPeer)
|
|
369
367
|
},
|
|
370
|
-
storeDataToDht: (key:
|
|
368
|
+
storeDataToDht: (key: DhtAddress, data: Any, creator?: DhtAddress) => this.storeDataToDht(key, data, creator)
|
|
371
369
|
})
|
|
372
370
|
this.rpcCommunicator!.registerRpcMethod(
|
|
373
371
|
ExternalFindDataRequest,
|
|
@@ -386,13 +384,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
386
384
|
}
|
|
387
385
|
|
|
388
386
|
private handleMessage(message: Message): void {
|
|
387
|
+
const nodeId = getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
|
|
389
388
|
if (message.serviceId === this.config.serviceId) {
|
|
390
|
-
logger.trace('
|
|
391
|
-
+ ' ' + message.serviceId + ' ' + message.messageId)
|
|
389
|
+
logger.trace('calling this.handleMessageFromPeer ' + nodeId + ' ' + message.serviceId + ' ' + message.messageId)
|
|
392
390
|
this.rpcCommunicator?.handleMessageFromPeer(message)
|
|
393
391
|
} else {
|
|
394
|
-
logger.trace('emit "message" ' +
|
|
395
|
-
+ ' ' + message.serviceId + ' ' + message.messageId)
|
|
392
|
+
logger.trace('emit "message" ' + nodeId + ' ' + message.serviceId + ' ' + message.messageId)
|
|
396
393
|
this.emit('message', message)
|
|
397
394
|
}
|
|
398
395
|
}
|
|
@@ -408,12 +405,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
408
405
|
|
|
409
406
|
public getClosestContacts(limit?: number): PeerDescriptor[] {
|
|
410
407
|
return this.peerManager!.getClosestContactsTo(
|
|
411
|
-
|
|
408
|
+
this.getNodeId(),
|
|
412
409
|
limit).map((peer) => peer.getPeerDescriptor()
|
|
413
410
|
)
|
|
414
411
|
}
|
|
415
412
|
|
|
416
|
-
public getNodeId():
|
|
413
|
+
public getNodeId(): DhtAddress {
|
|
417
414
|
return getNodeIdFromPeerDescriptor(this.localPeerDescriptor!)
|
|
418
415
|
}
|
|
419
416
|
|
|
@@ -432,66 +429,70 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
432
429
|
if (!this.started || this.abortController.signal.aborted) {
|
|
433
430
|
return
|
|
434
431
|
}
|
|
435
|
-
const reachableThrough = this.peerDiscovery!.isJoinOngoing() ? this.
|
|
432
|
+
const reachableThrough = this.peerDiscovery!.isJoinOngoing() ? this.getConnectedEntryPoints() : []
|
|
436
433
|
this.router!.send(msg, reachableThrough)
|
|
437
434
|
}
|
|
438
435
|
|
|
436
|
+
private getConnectedEntryPoints(): PeerDescriptor[] {
|
|
437
|
+
return this.config.entryPoints !== undefined ? this.config.entryPoints.filter((entryPoint) =>
|
|
438
|
+
this.peerManager!.connections.has(getNodeIdFromPeerDescriptor(entryPoint))
|
|
439
|
+
) : []
|
|
440
|
+
}
|
|
441
|
+
|
|
439
442
|
public async joinDht(entryPointDescriptors: PeerDescriptor[], doAdditionalRandomPeerDiscovery?: boolean, retry?: boolean): Promise<void> {
|
|
440
443
|
if (!this.started) {
|
|
441
444
|
throw new Error('Cannot join DHT before calling start() on DhtNode')
|
|
442
445
|
}
|
|
443
|
-
await
|
|
444
|
-
this.peerDiscovery!.joinDht(entryPoint, doAdditionalRandomPeerDiscovery, retry)
|
|
445
|
-
))
|
|
446
|
+
await this.peerDiscovery!.joinDht(entryPointDescriptors, doAdditionalRandomPeerDiscovery, retry)
|
|
446
447
|
}
|
|
447
448
|
|
|
448
449
|
// TODO make this private and unify the public API of find/fetch/store/delete methods
|
|
449
450
|
// (we already have storeDataToDht etc. here)
|
|
450
451
|
public async executeRecursiveOperation(
|
|
451
|
-
key:
|
|
452
|
+
key: DhtAddress,
|
|
452
453
|
operation: RecursiveOperation,
|
|
453
454
|
excludedPeer?: PeerDescriptor
|
|
454
455
|
): Promise<RecursiveOperationResult> {
|
|
455
456
|
return this.recursiveOperationManager!.execute(key, operation, excludedPeer)
|
|
456
457
|
}
|
|
457
458
|
|
|
458
|
-
public async storeDataToDht(key:
|
|
459
|
-
|
|
460
|
-
|
|
459
|
+
public async storeDataToDht(key: DhtAddress, data: Any, creator?: DhtAddress): Promise<PeerDescriptor[]> {
|
|
460
|
+
const connectedEntryPoints = this.getConnectedEntryPoints()
|
|
461
|
+
if (this.peerDiscovery!.isJoinOngoing() && connectedEntryPoints.length > 0) {
|
|
462
|
+
return this.storeDataViaPeer(key, data, sample(connectedEntryPoints)!)
|
|
461
463
|
}
|
|
462
|
-
return this.storeManager!.storeDataToDht(key, data, creator ??
|
|
464
|
+
return this.storeManager!.storeDataToDht(key, data, creator ?? this.getNodeId())
|
|
463
465
|
}
|
|
464
466
|
|
|
465
|
-
public async storeDataViaPeer(key:
|
|
467
|
+
public async storeDataViaPeer(key: DhtAddress, data: Any, peer: PeerDescriptor): Promise<PeerDescriptor[]> {
|
|
466
468
|
const rpcRemote = new ExternalApiRpcRemote(
|
|
467
469
|
this.localPeerDescriptor!,
|
|
468
470
|
peer,
|
|
469
|
-
this.config.serviceId,
|
|
470
471
|
this.rpcCommunicator!,
|
|
471
472
|
ExternalApiRpcClient
|
|
472
473
|
)
|
|
473
474
|
return await rpcRemote.storeData(key, data)
|
|
474
475
|
}
|
|
475
476
|
|
|
476
|
-
public async getDataFromDht(key:
|
|
477
|
-
|
|
478
|
-
|
|
477
|
+
public async getDataFromDht(key: DhtAddress): Promise<DataEntry[]> {
|
|
478
|
+
const connectedEntryPoints = this.getConnectedEntryPoints()
|
|
479
|
+
if (this.peerDiscovery!.isJoinOngoing() && connectedEntryPoints.length > 0) {
|
|
480
|
+
return this.findDataViaPeer(key, sample(connectedEntryPoints)!)
|
|
479
481
|
}
|
|
480
482
|
const result = await this.recursiveOperationManager!.execute(key, RecursiveOperation.FETCH_DATA)
|
|
481
483
|
return result.dataEntries ?? [] // TODO is this fallback needed?
|
|
482
484
|
}
|
|
483
485
|
|
|
484
|
-
public async deleteDataFromDht(key:
|
|
486
|
+
public async deleteDataFromDht(key: DhtAddress, waitForCompletion: boolean): Promise<void> {
|
|
485
487
|
if (!this.abortController.signal.aborted) {
|
|
486
488
|
await this.recursiveOperationManager!.execute(key, RecursiveOperation.DELETE_DATA, undefined, waitForCompletion)
|
|
487
489
|
}
|
|
488
490
|
}
|
|
489
491
|
|
|
490
|
-
public async findDataViaPeer(key:
|
|
492
|
+
public async findDataViaPeer(key: DhtAddress, peer: PeerDescriptor): Promise<DataEntry[]> {
|
|
491
493
|
const rpcRemote = new ExternalApiRpcRemote(
|
|
492
494
|
this.localPeerDescriptor!,
|
|
493
495
|
peer,
|
|
494
|
-
this.config.serviceId,
|
|
495
496
|
this.rpcCommunicator!,
|
|
496
497
|
ExternalApiRpcClient
|
|
497
498
|
)
|
|
@@ -11,10 +11,11 @@ import {
|
|
|
11
11
|
} from '../proto/packages/dht/protos/DhtRpc'
|
|
12
12
|
import { IDhtNodeRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
13
13
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
14
|
+
import { DhtAddress, getDhtAddressFromRaw } from '../identifiers'
|
|
14
15
|
|
|
15
16
|
interface DhtNodeRpcLocalConfig {
|
|
16
17
|
peerDiscoveryQueryBatchSize: number
|
|
17
|
-
getClosestPeersTo: (nodeId:
|
|
18
|
+
getClosestPeersTo: (nodeId: DhtAddress, limit: number) => PeerDescriptor[]
|
|
18
19
|
addNewContact: (contact: PeerDescriptor) => void
|
|
19
20
|
removeContact: (contact: PeerDescriptor) => void
|
|
20
21
|
}
|
|
@@ -32,7 +33,7 @@ export class DhtNodeRpcLocal implements IDhtNodeRpc {
|
|
|
32
33
|
async getClosestPeers(request: ClosestPeersRequest, context: ServerCallContext): Promise<ClosestPeersResponse> {
|
|
33
34
|
this.config.addNewContact((context as DhtCallContext).incomingSourceDescriptor!)
|
|
34
35
|
const response = {
|
|
35
|
-
peers: this.config.getClosestPeersTo(request.nodeId, this.config.peerDiscoveryQueryBatchSize),
|
|
36
|
+
peers: this.config.getClosestPeersTo(getDhtAddressFromRaw(request.nodeId), this.config.peerDiscoveryQueryBatchSize),
|
|
36
37
|
requestId: request.requestId
|
|
37
38
|
}
|
|
38
39
|
return response
|