@streamr/trackerless-network 0.0.1-tatum.6 → 0.0.1-tatum.7
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 +10 -8
- package/dist/src/NetworkNode.js +1 -1
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +1 -3
- package/dist/src/NetworkStack.js +18 -47
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/identifiers.js +2 -2
- package/dist/src/identifiers.js.map +1 -1
- package/dist/src/logic/{StreamNodeServer.d.ts → DeliveryRpcLocal.d.ts} +6 -5
- package/dist/src/logic/{StreamNodeServer.js → DeliveryRpcLocal.js} +5 -5
- package/dist/src/logic/{StreamNodeServer.js.map → DeliveryRpcLocal.js.map} +1 -1
- package/dist/src/logic/{RemoteRandomGraphNode.d.ts → DeliveryRpcRemote.d.ts} +2 -2
- package/dist/src/logic/{RemoteRandomGraphNode.js → DeliveryRpcRemote.js} +5 -5
- package/dist/src/logic/DeliveryRpcRemote.js.map +1 -0
- package/dist/src/logic/{StreamPartEntryPointDiscovery.d.ts → EntryPointDiscovery.d.ts} +8 -10
- package/dist/src/logic/{StreamPartEntryPointDiscovery.js → EntryPointDiscovery.js} +14 -36
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -0
- package/dist/src/logic/ILayer0.d.ts +3 -6
- package/dist/src/logic/NodeList.d.ts +10 -10
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +8 -12
- package/dist/src/logic/RandomGraphNode.js +41 -40
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +9 -12
- package/dist/src/logic/StreamrNode.js +53 -63
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +6 -1
- package/dist/src/logic/createRandomGraphNode.js +17 -23
- package/dist/src/logic/createRandomGraphNode.js.map +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.d.ts +2 -0
- package/dist/src/logic/formStreamPartDeliveryServiceId.js +8 -0
- package/dist/src/logic/formStreamPartDeliveryServiceId.js.map +1 -0
- package/dist/src/logic/inspect/Inspector.d.ts +3 -2
- package/dist/src/logic/inspect/Inspector.js +5 -5
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/{HandshakerServer.d.ts → HandshakeRpcLocal.d.ts} +10 -10
- package/dist/src/logic/neighbor-discovery/{HandshakerServer.js → HandshakeRpcLocal.js} +13 -13
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -0
- package/dist/src/logic/neighbor-discovery/{RemoteHandshaker.d.ts → HandshakeRpcRemote.d.ts} +1 -1
- package/dist/src/logic/neighbor-discovery/{RemoteHandshaker.js → HandshakeRpcRemote.js} +8 -7
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -0
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +8 -7
- package/dist/src/logic/neighbor-discovery/Handshaker.js +23 -24
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +3 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +5 -5
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.d.ts → NeighborUpdateRpcLocal.d.ts} +6 -6
- package/dist/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.js → NeighborUpdateRpcLocal.js} +9 -9
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -0
- package/dist/src/logic/neighbor-discovery/{RemoteNeighborUpdateManager.d.ts → NeighborUpdateRpcRemote.d.ts} +1 -1
- package/dist/src/logic/neighbor-discovery/{RemoteNeighborUpdateManager.js → NeighborUpdateRpcRemote.js} +5 -5
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -0
- package/dist/src/logic/propagation/Propagation.js +2 -2
- package/dist/src/logic/propagation/Propagation.js.map +1 -1
- package/dist/src/logic/proxy/{ProxyStreamConnectionClient.d.ts → ProxyClient.d.ts} +6 -9
- package/dist/src/logic/proxy/{ProxyStreamConnectionClient.js → ProxyClient.js} +23 -21
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -0
- package/dist/src/logic/proxy/{ProxyStreamConnectionServer.d.ts → ProxyConnectionRpcLocal.d.ts} +5 -5
- package/dist/src/logic/proxy/{ProxyStreamConnectionServer.js → ProxyConnectionRpcLocal.js} +6 -6
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -0
- package/dist/src/logic/proxy/{RemoteProxyServer.d.ts → ProxyConnectionRpcRemote.d.ts} +1 -1
- package/dist/src/logic/proxy/{RemoteProxyServer.js → ProxyConnectionRpcRemote.js} +4 -4
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -0
- package/dist/src/logic/temporary-connection/{TemporaryConnectionRpcServer.d.ts → TemporaryConnectionRpcLocal.d.ts} +5 -4
- package/dist/src/logic/temporary-connection/{TemporaryConnectionRpcServer.js → TemporaryConnectionRpcLocal.js} +6 -6
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -0
- package/dist/src/logic/temporary-connection/{RemoteTemporaryConnectionRpcServer.d.ts → TemporaryConnectionRpcRemote.d.ts} +1 -1
- package/dist/src/logic/temporary-connection/{RemoteTemporaryConnectionRpcServer.js → TemporaryConnectionRpcRemote.js} +4 -4
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +0 -4
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +1 -2
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +4 -4
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +7 -7
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.d.ts +10 -10
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +7 -7
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.d.ts +2 -2
- package/dist/test/benchmark/first-message.js +10 -13
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +5 -5
- package/dist/test/utils/utils.js +14 -13
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +10 -8
- package/protos/NetworkRpc.proto +5 -5
- package/src/NetworkNode.ts +1 -1
- package/src/NetworkStack.ts +20 -62
- package/src/identifiers.ts +3 -3
- package/src/logic/{StreamNodeServer.ts → DeliveryRpcLocal.ts} +8 -7
- package/src/logic/{RemoteRandomGraphNode.ts → DeliveryRpcRemote.ts} +3 -3
- package/src/logic/{StreamPartEntryPointDiscovery.ts → EntryPointDiscovery.ts} +18 -42
- package/src/logic/ILayer0.ts +3 -6
- package/src/logic/NodeList.ts +12 -12
- package/src/logic/RandomGraphNode.ts +61 -62
- package/src/logic/StreamrNode.ts +59 -73
- package/src/logic/createRandomGraphNode.ts +28 -26
- package/src/logic/formStreamPartDeliveryServiceId.ts +5 -0
- package/src/logic/inspect/Inspector.ts +8 -7
- package/src/logic/neighbor-discovery/{HandshakerServer.ts → HandshakeRpcLocal.ts} +20 -20
- package/src/logic/neighbor-discovery/{RemoteHandshaker.ts → HandshakeRpcRemote.ts} +6 -5
- package/src/logic/neighbor-discovery/Handshaker.ts +38 -38
- package/src/logic/neighbor-discovery/NeighborFinder.ts +2 -2
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +13 -10
- package/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.ts → NeighborUpdateRpcLocal.ts} +15 -15
- package/src/logic/neighbor-discovery/{RemoteNeighborUpdateManager.ts → NeighborUpdateRpcRemote.ts} +2 -2
- package/src/logic/propagation/Propagation.ts +2 -2
- package/src/logic/proxy/{ProxyStreamConnectionClient.ts → ProxyClient.ts} +27 -27
- package/src/logic/proxy/{ProxyStreamConnectionServer.ts → ProxyConnectionRpcLocal.ts} +10 -11
- package/src/logic/proxy/{RemoteProxyServer.ts → ProxyConnectionRpcRemote.ts} +1 -1
- package/src/logic/temporary-connection/{TemporaryConnectionRpcServer.ts → TemporaryConnectionRpcLocal.ts} +11 -10
- package/src/logic/temporary-connection/{RemoteTemporaryConnectionRpcServer.ts → TemporaryConnectionRpcRemote.ts} +1 -1
- package/src/proto/packages/dht/protos/DhtRpc.ts +1 -6
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +8 -8
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +2 -2
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +14 -14
- package/test/benchmark/first-message.ts +10 -13
- package/test/end-to-end/inspect.test.ts +12 -12
- package/test/end-to-end/proxy-and-full-node.test.ts +13 -14
- package/test/end-to-end/proxy-connections.test.ts +9 -11
- package/test/end-to-end/proxy-key-exchange.test.ts +12 -13
- package/test/end-to-end/random-graph-with-real-connections.test.ts +7 -7
- package/test/end-to-end/webrtc-full-node-network.test.ts +8 -8
- package/test/end-to-end/websocket-full-node-network.test.ts +8 -10
- package/test/integration/{RemoteRandomGraphNode.test.ts → DeliveryRpcRemote.test.ts} +17 -14
- package/test/integration/{RemoteHandshaker.test.ts → HandshakeRpcRemote.test.ts} +10 -9
- package/test/integration/Handshakes.test.ts +23 -20
- package/test/integration/Inspect.test.ts +3 -2
- package/test/integration/{RemoteNeighborUpdateManager.test.ts → NeighborUpdateRpcRemote.test.ts} +12 -10
- package/test/integration/NetworkNode.test.ts +9 -8
- package/test/integration/NetworkRpc.test.ts +5 -7
- package/test/integration/NetworkStack.test.ts +13 -15
- package/test/integration/Propagation.test.ts +2 -2
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +10 -8
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +17 -17
- package/test/integration/StreamrNode.test.ts +5 -3
- package/test/integration/joining-streams-on-offline-peers.test.ts +16 -18
- package/test/integration/stream-without-default-entrypoints.test.ts +11 -13
- package/test/unit/{StreamNodeServer.test.ts → DeliveryRpcLocal.test.ts} +8 -8
- package/test/unit/{StreamPartEntrypointDiscovery.test.ts → EntrypointDiscovery.test.ts} +23 -40
- package/test/unit/{HandshakerServer.test.ts → HandshakeRpcLocal.test.ts} +26 -24
- package/test/unit/Handshaker.test.ts +10 -8
- package/test/unit/Inspector.test.ts +4 -3
- package/test/unit/NeighborFinder.test.ts +5 -5
- package/test/unit/NodeList.test.ts +22 -13
- package/test/unit/{RemoteProxyServer.test.ts → ProxyConnectionRpcRemote.test.ts} +4 -4
- package/test/unit/RandomGraphNode.test.ts +6 -5
- package/test/unit/StreamMessageTranslator.test.ts +10 -9
- package/test/unit/StreamrNode.test.ts +8 -8
- package/test/utils/mock/MockLayer0.ts +7 -26
- package/test/utils/mock/MockLayer1.ts +3 -8
- package/test/utils/mock/MockNeighborFinder.ts +1 -2
- package/test/utils/mock/MockNeighborUpdateManager.ts +1 -2
- package/test/utils/mock/Transport.ts +2 -2
- package/test/utils/utils.ts +13 -12
- package/dist/src/logic/RemoteRandomGraphNode.js.map +0 -1
- package/dist/src/logic/StreamPartEntryPointDiscovery.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/HandshakerServer.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManagerServer.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/RemoteHandshaker.js.map +0 -1
- package/dist/src/logic/neighbor-discovery/RemoteNeighborUpdateManager.js.map +0 -1
- package/dist/src/logic/proxy/ProxyStreamConnectionClient.js.map +0 -1
- package/dist/src/logic/proxy/ProxyStreamConnectionServer.js.map +0 -1
- package/dist/src/logic/proxy/RemoteProxyServer.js.map +0 -1
- package/dist/src/logic/temporary-connection/RemoteTemporaryConnectionRpcServer.js.map +0 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcServer.js.map +0 -1
|
@@ -7,22 +7,29 @@ import { NodeList } from './NodeList'
|
|
|
7
7
|
import { Propagation } from './propagation/Propagation'
|
|
8
8
|
import { StreamMessage } from '../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
9
9
|
import { MarkOptional } from 'ts-essentials'
|
|
10
|
-
import {
|
|
10
|
+
import { ProxyConnectionRpcLocal } from './proxy/ProxyConnectionRpcLocal'
|
|
11
11
|
import { Inspector } from './inspect/Inspector'
|
|
12
|
-
import {
|
|
13
|
-
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
12
|
+
import { TemporaryConnectionRpcLocal } from './temporary-connection/TemporaryConnectionRpcLocal'
|
|
14
13
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../identifiers'
|
|
14
|
+
import { formStreamPartDeliveryServiceId } from './formStreamPartDeliveryServiceId'
|
|
15
15
|
|
|
16
16
|
type RandomGraphNodeConfig = MarkOptional<StrictRandomGraphNodeConfig,
|
|
17
17
|
'nearbyNodeView' | 'randomNodeView' | 'targetNeighbors' | 'propagation'
|
|
18
|
-
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | '
|
|
19
|
-
| '
|
|
20
|
-
| '
|
|
18
|
+
| 'handshaker' | 'neighborFinder' | 'neighborUpdateManager' | 'numOfTargetNeighbors'
|
|
19
|
+
| 'rpcCommunicator' | 'nodeViewSize'
|
|
20
|
+
| 'inspector' | 'temporaryConnectionRpcLocal'> & {
|
|
21
|
+
maxNumberOfContacts?: number
|
|
22
|
+
minPropagationTargets?: number
|
|
23
|
+
acceptProxyConnections?: boolean
|
|
24
|
+
neighborUpdateInterval?: number
|
|
25
|
+
}
|
|
21
26
|
|
|
22
27
|
const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGraphNodeConfig => {
|
|
23
28
|
const ownNodeId = getNodeIdFromPeerDescriptor(config.ownPeerDescriptor)
|
|
24
|
-
const rpcCommunicator = config.rpcCommunicator ?? new ListeningRpcCommunicator(
|
|
25
|
-
|
|
29
|
+
const rpcCommunicator = config.rpcCommunicator ?? new ListeningRpcCommunicator(
|
|
30
|
+
formStreamPartDeliveryServiceId(config.streamPartId),
|
|
31
|
+
config.P2PTransport
|
|
32
|
+
)
|
|
26
33
|
const numOfTargetNeighbors = config.numOfTargetNeighbors ?? 4
|
|
27
34
|
const maxNumberOfContacts = config.maxNumberOfContacts ?? 20
|
|
28
35
|
const minPropagationTargets = config.minPropagationTargets ?? 2
|
|
@@ -32,21 +39,21 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
32
39
|
const randomNodeView = config.randomNodeView ?? new NodeList(ownNodeId, maxNumberOfContacts)
|
|
33
40
|
const targetNeighbors = config.targetNeighbors ?? new NodeList(ownNodeId, maxNumberOfContacts)
|
|
34
41
|
|
|
35
|
-
const
|
|
36
|
-
|
|
42
|
+
const temporaryConnectionRpcLocal = new TemporaryConnectionRpcLocal({
|
|
43
|
+
streamPartId: config.streamPartId,
|
|
37
44
|
rpcCommunicator,
|
|
38
45
|
ownPeerDescriptor: config.ownPeerDescriptor
|
|
39
46
|
})
|
|
40
|
-
const
|
|
47
|
+
const proxyConnectionRpcLocal = acceptProxyConnections ? new ProxyConnectionRpcLocal({
|
|
41
48
|
ownPeerDescriptor: config.ownPeerDescriptor,
|
|
42
|
-
streamPartId:
|
|
49
|
+
streamPartId: config.streamPartId,
|
|
43
50
|
rpcCommunicator
|
|
44
51
|
}) : undefined
|
|
45
52
|
const propagation = config.propagation ?? new Propagation({
|
|
46
53
|
minPropagationTargets,
|
|
47
54
|
sendToNeighbor: async (neighborId: NodeID, msg: StreamMessage): Promise<void> => {
|
|
48
|
-
const remote = targetNeighbors.get(neighborId) ??
|
|
49
|
-
const proxyConnection =
|
|
55
|
+
const remote = targetNeighbors.get(neighborId) ?? temporaryConnectionRpcLocal.getNodes().get(neighborId)
|
|
56
|
+
const proxyConnection = proxyConnectionRpcLocal?.getConnection(neighborId)
|
|
50
57
|
if (remote) {
|
|
51
58
|
await remote.sendStreamMessage(msg)
|
|
52
59
|
} else if (proxyConnection) {
|
|
@@ -58,33 +65,33 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
58
65
|
})
|
|
59
66
|
const handshaker = config.handshaker ?? new Handshaker({
|
|
60
67
|
ownPeerDescriptor: config.ownPeerDescriptor,
|
|
61
|
-
|
|
68
|
+
streamPartId: config.streamPartId,
|
|
62
69
|
connectionLocker: config.connectionLocker,
|
|
63
70
|
rpcCommunicator,
|
|
64
71
|
nearbyNodeView,
|
|
65
72
|
randomNodeView,
|
|
66
73
|
targetNeighbors,
|
|
67
|
-
|
|
74
|
+
maxNeighborCount: numOfTargetNeighbors
|
|
68
75
|
})
|
|
69
76
|
const neighborFinder = config.neighborFinder ?? new NeighborFinder({
|
|
70
77
|
targetNeighbors,
|
|
71
78
|
nearbyNodeView,
|
|
72
79
|
doFindNeighbors: (excludedIds) => handshaker.attemptHandshakesOnContacts(excludedIds),
|
|
73
|
-
|
|
80
|
+
minCount: numOfTargetNeighbors
|
|
74
81
|
})
|
|
75
82
|
const neighborUpdateManager = config.neighborUpdateManager ?? new NeighborUpdateManager({
|
|
76
83
|
targetNeighbors,
|
|
77
84
|
nearbyNodeView,
|
|
78
85
|
ownPeerDescriptor: config.ownPeerDescriptor,
|
|
79
86
|
neighborFinder,
|
|
80
|
-
|
|
87
|
+
streamPartId: config.streamPartId,
|
|
81
88
|
rpcCommunicator,
|
|
82
89
|
neighborUpdateInterval
|
|
83
90
|
})
|
|
84
91
|
const inspector = config.inspector ?? new Inspector({
|
|
85
92
|
ownPeerDescriptor: config.ownPeerDescriptor,
|
|
86
93
|
rpcCommunicator,
|
|
87
|
-
|
|
94
|
+
streamPartId: config.streamPartId,
|
|
88
95
|
connectionLocker: config.connectionLocker
|
|
89
96
|
})
|
|
90
97
|
return {
|
|
@@ -98,15 +105,10 @@ const createConfigWithDefaults = (config: RandomGraphNodeConfig): StrictRandomGr
|
|
|
98
105
|
neighborUpdateManager,
|
|
99
106
|
propagation,
|
|
100
107
|
numOfTargetNeighbors,
|
|
101
|
-
minPropagationTargets,
|
|
102
|
-
maxNumberOfContacts,
|
|
103
|
-
name,
|
|
104
108
|
nodeViewSize: maxNumberOfContacts,
|
|
105
|
-
|
|
106
|
-
proxyConnectionServer,
|
|
107
|
-
neighborUpdateInterval,
|
|
109
|
+
proxyConnectionRpcLocal,
|
|
108
110
|
inspector,
|
|
109
|
-
|
|
111
|
+
temporaryConnectionRpcLocal
|
|
110
112
|
}
|
|
111
113
|
}
|
|
112
114
|
|
|
@@ -4,12 +4,13 @@ import { InspectSession, Events as InspectSessionEvents } from './InspectSession
|
|
|
4
4
|
import { TemporaryConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
6
6
|
import { Logger, waitForEvent3 } from '@streamr/utils'
|
|
7
|
-
import {
|
|
7
|
+
import { TemporaryConnectionRpcRemote } from '../temporary-connection/TemporaryConnectionRpcRemote'
|
|
8
8
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
9
|
+
import { StreamPartID } from '@streamr/protocol'
|
|
9
10
|
|
|
10
11
|
interface InspectorConfig {
|
|
11
12
|
ownPeerDescriptor: PeerDescriptor
|
|
12
|
-
|
|
13
|
+
streamPartId: StreamPartID
|
|
13
14
|
rpcCommunicator: RpcCommunicator
|
|
14
15
|
connectionLocker: ConnectionLocker
|
|
15
16
|
inspectionTimeout?: number
|
|
@@ -29,7 +30,7 @@ const DEFAULT_TIMEOUT = 60 * 1000
|
|
|
29
30
|
export class Inspector implements IInspector {
|
|
30
31
|
|
|
31
32
|
private readonly sessions: Map<NodeID, InspectSession> = new Map()
|
|
32
|
-
private readonly
|
|
33
|
+
private readonly streamPartId: StreamPartID
|
|
33
34
|
private readonly client: ProtoRpcClient<TemporaryConnectionRpcClient>
|
|
34
35
|
private readonly ownPeerDescriptor: PeerDescriptor
|
|
35
36
|
private readonly connectionLocker: ConnectionLocker
|
|
@@ -37,7 +38,7 @@ export class Inspector implements IInspector {
|
|
|
37
38
|
private readonly openInspectConnection: (peerDescriptor: PeerDescriptor, lockId: string) => Promise<void>
|
|
38
39
|
|
|
39
40
|
constructor(config: InspectorConfig) {
|
|
40
|
-
this.
|
|
41
|
+
this.streamPartId = config.streamPartId
|
|
41
42
|
this.ownPeerDescriptor = config.ownPeerDescriptor
|
|
42
43
|
this.client = toProtoRpcClient(new TemporaryConnectionRpcClient(config.rpcCommunicator.getRpcClientTransport()))
|
|
43
44
|
this.connectionLocker = config.connectionLocker
|
|
@@ -46,8 +47,8 @@ export class Inspector implements IInspector {
|
|
|
46
47
|
}
|
|
47
48
|
|
|
48
49
|
async defaultOpenInspectConnection(peerDescriptor: PeerDescriptor, lockId: string): Promise<void> {
|
|
49
|
-
const
|
|
50
|
-
await
|
|
50
|
+
const rpcRemote = new TemporaryConnectionRpcRemote(this.ownPeerDescriptor, peerDescriptor, this.streamPartId, this.client)
|
|
51
|
+
await rpcRemote.openConnection()
|
|
51
52
|
this.connectionLocker.lockConnection(peerDescriptor, lockId)
|
|
52
53
|
}
|
|
53
54
|
|
|
@@ -56,7 +57,7 @@ export class Inspector implements IInspector {
|
|
|
56
57
|
const session = new InspectSession({
|
|
57
58
|
inspectedNode: nodeId
|
|
58
59
|
})
|
|
59
|
-
const lockId = `inspector-${this.
|
|
60
|
+
const lockId = `inspector-${this.streamPartId}`
|
|
60
61
|
this.sessions.set(nodeId, session)
|
|
61
62
|
await this.openInspectConnection(peerDescriptor, lockId)
|
|
62
63
|
let success = false
|
|
@@ -4,28 +4,28 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
|
4
4
|
import { NodeList } from '../NodeList'
|
|
5
5
|
import { ConnectionLocker, DhtCallContext, PeerDescriptor } from '@streamr/dht'
|
|
6
6
|
import { IHandshakeRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
7
|
+
import { HandshakeRpcRemote } from './HandshakeRpcRemote'
|
|
8
|
+
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
9
9
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
10
10
|
import { binaryToHex } from '@streamr/utils'
|
|
11
|
+
import { StreamPartID } from '@streamr/protocol'
|
|
11
12
|
|
|
12
|
-
interface
|
|
13
|
-
|
|
14
|
-
ownPeerDescriptor: PeerDescriptor
|
|
13
|
+
interface HandshakeRpcLocalConfig {
|
|
14
|
+
streamPartId: StreamPartID
|
|
15
15
|
targetNeighbors: NodeList
|
|
16
16
|
connectionLocker: ConnectionLocker
|
|
17
17
|
ongoingHandshakes: Set<NodeID>
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
maxNeighborCount: number
|
|
19
|
+
createRpcRemote: (target: PeerDescriptor) => HandshakeRpcRemote
|
|
20
|
+
createDeliveryRpcRemote: (peerDescriptor: PeerDescriptor) => DeliveryRpcRemote
|
|
21
21
|
handshakeWithInterleaving: (target: PeerDescriptor, senderId: NodeID) => Promise<boolean>
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
export class
|
|
24
|
+
export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
25
25
|
|
|
26
|
-
private readonly config:
|
|
26
|
+
private readonly config: HandshakeRpcLocalConfig
|
|
27
27
|
|
|
28
|
-
constructor(config:
|
|
28
|
+
constructor(config: HandshakeRpcLocalConfig) {
|
|
29
29
|
this.config = config
|
|
30
30
|
}
|
|
31
31
|
|
|
@@ -40,7 +40,7 @@ export class HandshakerServer implements IHandshakeRpc {
|
|
|
40
40
|
|| this.config.ongoingHandshakes.has(getNodeIdFromPeerDescriptor(senderDescriptor))
|
|
41
41
|
) {
|
|
42
42
|
return this.acceptHandshake(request, senderDescriptor)
|
|
43
|
-
} else if (this.config.targetNeighbors.size() + this.config.ongoingHandshakes.size < this.config.
|
|
43
|
+
} else if (this.config.targetNeighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
44
44
|
return this.acceptHandshake(request, senderDescriptor)
|
|
45
45
|
} else if (this.config.targetNeighbors.size(getInterleaveSourceIds()) >= 2) {
|
|
46
46
|
return this.acceptHandshakeWithInterleaving(request, senderDescriptor)
|
|
@@ -54,8 +54,8 @@ export class HandshakerServer implements IHandshakeRpc {
|
|
|
54
54
|
requestId: request.requestId,
|
|
55
55
|
accepted: true
|
|
56
56
|
}
|
|
57
|
-
this.config.targetNeighbors.add(this.config.
|
|
58
|
-
this.config.connectionLocker.lockConnection(requester, this.config.
|
|
57
|
+
this.config.targetNeighbors.add(this.config.createDeliveryRpcRemote(requester))
|
|
58
|
+
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
59
59
|
return res
|
|
60
60
|
}
|
|
61
61
|
|
|
@@ -77,13 +77,13 @@ export class HandshakerServer implements IHandshakeRpc {
|
|
|
77
77
|
const furthest = this.config.targetNeighbors.getFurthest(exclude)
|
|
78
78
|
const furthestPeerDescriptor = furthest ? furthest.getPeerDescriptor() : undefined
|
|
79
79
|
if (furthest) {
|
|
80
|
-
const remote = this.config.
|
|
80
|
+
const remote = this.config.createRpcRemote(furthest.getPeerDescriptor())
|
|
81
81
|
remote.interleaveNotice(requester)
|
|
82
82
|
this.config.targetNeighbors.remove(furthest.getPeerDescriptor())
|
|
83
|
-
this.config.connectionLocker.unlockConnection(furthestPeerDescriptor!, this.config.
|
|
83
|
+
this.config.connectionLocker.unlockConnection(furthestPeerDescriptor!, this.config.streamPartId)
|
|
84
84
|
}
|
|
85
|
-
this.config.targetNeighbors.add(this.config.
|
|
86
|
-
this.config.connectionLocker.lockConnection(requester, this.config.
|
|
85
|
+
this.config.targetNeighbors.add(this.config.createDeliveryRpcRemote(requester))
|
|
86
|
+
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
87
87
|
return {
|
|
88
88
|
requestId: request.requestId,
|
|
89
89
|
accepted: true,
|
|
@@ -92,11 +92,11 @@ export class HandshakerServer implements IHandshakeRpc {
|
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
async interleaveNotice(message: InterleaveNotice, context: ServerCallContext): Promise<Empty> {
|
|
95
|
-
if (message.
|
|
95
|
+
if (message.streamPartId === this.config.streamPartId) {
|
|
96
96
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
97
97
|
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
98
98
|
if (this.config.targetNeighbors.hasNodeById(senderId)) {
|
|
99
|
-
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.
|
|
99
|
+
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
|
|
100
100
|
this.config.targetNeighbors.remove(senderPeerDescriptor)
|
|
101
101
|
}
|
|
102
102
|
this.config.handshakeWithInterleaving(message.interleaveTargetDescriptor!, senderId).catch((_e) => {})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { PeerDescriptor, Remote
|
|
1
|
+
import { PeerDescriptor, Remote } from '@streamr/dht'
|
|
2
2
|
import { Logger, hexToBinary } from '@streamr/utils'
|
|
3
|
+
import { v4 } from 'uuid'
|
|
3
4
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
4
5
|
import { InterleaveNotice, StreamPartHandshakeRequest } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
5
6
|
import { IHandshakeRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
@@ -11,7 +12,7 @@ interface HandshakeResponse {
|
|
|
11
12
|
interleaveTargetDescriptor?: PeerDescriptor
|
|
12
13
|
}
|
|
13
14
|
|
|
14
|
-
export class
|
|
15
|
+
export class HandshakeRpcRemote extends Remote<IHandshakeRpcClient> {
|
|
15
16
|
|
|
16
17
|
async handshake(
|
|
17
18
|
neighborIds: NodeID[],
|
|
@@ -19,8 +20,8 @@ export class RemoteHandshaker extends Remote<IHandshakeRpcClient> {
|
|
|
19
20
|
interleaveSourceId?: NodeID
|
|
20
21
|
): Promise<HandshakeResponse> {
|
|
21
22
|
const request: StreamPartHandshakeRequest = {
|
|
22
|
-
|
|
23
|
-
requestId:
|
|
23
|
+
streamPartId: this.getServiceId(),
|
|
24
|
+
requestId: v4(),
|
|
24
25
|
neighborIds: neighborIds.map((id) => hexToBinary(id)),
|
|
25
26
|
concurrentHandshakeTargetId: (concurrentHandshakeTargetId !== undefined) ? hexToBinary(concurrentHandshakeTargetId) : undefined,
|
|
26
27
|
interleaveSourceId: (interleaveSourceId !== undefined) ? hexToBinary(interleaveSourceId) : undefined
|
|
@@ -41,7 +42,7 @@ export class RemoteHandshaker extends Remote<IHandshakeRpcClient> {
|
|
|
41
42
|
|
|
42
43
|
interleaveNotice(originatorDescriptor: PeerDescriptor): void {
|
|
43
44
|
const notification: InterleaveNotice = {
|
|
44
|
-
|
|
45
|
+
streamPartId: this.getServiceId(),
|
|
45
46
|
interleaveTargetDescriptor: originatorDescriptor
|
|
46
47
|
}
|
|
47
48
|
const options = this.formDhtRpcOptions({
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { ConnectionLocker, PeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { NodeList } from '../NodeList'
|
|
3
|
-
import {
|
|
3
|
+
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
4
4
|
import { ProtoRpcClient, RpcCommunicator, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
5
5
|
import {
|
|
6
6
|
HandshakeRpcClient,
|
|
7
|
-
IHandshakeRpcClient,
|
|
7
|
+
IHandshakeRpcClient, DeliveryRpcClient
|
|
8
8
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
9
9
|
import {
|
|
10
10
|
InterleaveNotice,
|
|
@@ -13,19 +13,20 @@ import {
|
|
|
13
13
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
14
14
|
import { Logger } from '@streamr/utils'
|
|
15
15
|
import { IHandshakeRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
16
|
-
import {
|
|
17
|
-
import {
|
|
16
|
+
import { HandshakeRpcRemote } from './HandshakeRpcRemote'
|
|
17
|
+
import { HandshakeRpcLocal } from './HandshakeRpcLocal'
|
|
18
18
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
19
|
+
import { StreamPartID } from '@streamr/protocol'
|
|
19
20
|
|
|
20
21
|
interface HandshakerConfig {
|
|
21
22
|
ownPeerDescriptor: PeerDescriptor
|
|
22
|
-
|
|
23
|
+
streamPartId: StreamPartID
|
|
23
24
|
connectionLocker: ConnectionLocker
|
|
24
25
|
targetNeighbors: NodeList
|
|
25
26
|
nearbyNodeView: NodeList
|
|
26
27
|
randomNodeView: NodeList
|
|
27
28
|
rpcCommunicator: RpcCommunicator
|
|
28
|
-
|
|
29
|
+
maxNeighborCount: number
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
const logger = new Logger(module)
|
|
@@ -34,7 +35,7 @@ const PARALLEL_HANDSHAKE_COUNT = 2
|
|
|
34
35
|
|
|
35
36
|
export interface IHandshaker {
|
|
36
37
|
attemptHandshakesOnContacts(excludedIds: NodeID[]): Promise<NodeID[]>
|
|
37
|
-
getOngoingHandshakes(): Set<
|
|
38
|
+
getOngoingHandshakes(): Set<NodeID>
|
|
38
39
|
}
|
|
39
40
|
|
|
40
41
|
export class Handshaker implements IHandshaker {
|
|
@@ -42,33 +43,32 @@ export class Handshaker implements IHandshaker {
|
|
|
42
43
|
private readonly ongoingHandshakes: Set<NodeID> = new Set()
|
|
43
44
|
private config: HandshakerConfig
|
|
44
45
|
private readonly client: ProtoRpcClient<IHandshakeRpcClient>
|
|
45
|
-
private readonly
|
|
46
|
+
private readonly rpcLocal: IHandshakeRpc
|
|
46
47
|
|
|
47
48
|
constructor(config: HandshakerConfig) {
|
|
48
49
|
this.config = config
|
|
49
50
|
this.client = toProtoRpcClient(new HandshakeRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
50
|
-
this.
|
|
51
|
-
|
|
52
|
-
ownPeerDescriptor: this.config.ownPeerDescriptor,
|
|
51
|
+
this.rpcLocal = new HandshakeRpcLocal({
|
|
52
|
+
streamPartId: this.config.streamPartId,
|
|
53
53
|
targetNeighbors: this.config.targetNeighbors,
|
|
54
54
|
connectionLocker: this.config.connectionLocker,
|
|
55
55
|
ongoingHandshakes: this.ongoingHandshakes,
|
|
56
|
-
|
|
56
|
+
maxNeighborCount: this.config.maxNeighborCount,
|
|
57
57
|
handshakeWithInterleaving: (target: PeerDescriptor, senderId: NodeID) => this.handshakeWithInterleaving(target, senderId),
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
createRpcRemote: (target: PeerDescriptor) => this.createRpcRemote(target),
|
|
59
|
+
createDeliveryRpcRemote: (target: PeerDescriptor) => this.createDeliveryRpcRemote(target)
|
|
60
60
|
})
|
|
61
61
|
this.config.rpcCommunicator.registerRpcNotification(InterleaveNotice, 'interleaveNotice',
|
|
62
|
-
(req: InterleaveNotice, context) => this.
|
|
62
|
+
(req: InterleaveNotice, context) => this.rpcLocal.interleaveNotice(req, context))
|
|
63
63
|
this.config.rpcCommunicator.registerRpcMethod(StreamPartHandshakeRequest, StreamPartHandshakeResponse, 'handshake',
|
|
64
|
-
(req: StreamPartHandshakeRequest, context) => this.
|
|
64
|
+
(req: StreamPartHandshakeRequest, context) => this.rpcLocal.handshake(req, context))
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
-
|
|
68
|
-
if (this.config.targetNeighbors.size() + this.ongoingHandshakes.size < this.config.
|
|
67
|
+
async attemptHandshakesOnContacts(excludedIds: NodeID[]): Promise<NodeID[]> {
|
|
68
|
+
if (this.config.targetNeighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount - 2) {
|
|
69
69
|
logger.trace(`Attempting parallel handshakes with ${PARALLEL_HANDSHAKE_COUNT} targets`)
|
|
70
70
|
return this.selectParallelTargetsAndHandshake(excludedIds)
|
|
71
|
-
} else if (this.config.targetNeighbors.size() + this.ongoingHandshakes.size < this.config.
|
|
71
|
+
} else if (this.config.targetNeighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
72
72
|
logger.trace(`Attempting handshake with new target`)
|
|
73
73
|
return this.selectNewTargetAndHandshake(excludedIds)
|
|
74
74
|
}
|
|
@@ -82,7 +82,7 @@ export class Handshaker implements IHandshaker {
|
|
|
82
82
|
return this.doParallelHandshakes(targetNeighbors, exclude)
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
-
private selectParallelTargets(excludedIds: NodeID[]):
|
|
85
|
+
private selectParallelTargets(excludedIds: NodeID[]): HandshakeRpcRemote[] {
|
|
86
86
|
const targetNeighbors = this.config.nearbyNodeView.getClosestAndFurthest(excludedIds)
|
|
87
87
|
while (targetNeighbors.length < PARALLEL_HANDSHAKE_COUNT && this.config.randomNodeView.size(excludedIds) > 0) {
|
|
88
88
|
const random = this.config.randomNodeView.getRandom(excludedIds)
|
|
@@ -90,12 +90,12 @@ export class Handshaker implements IHandshaker {
|
|
|
90
90
|
targetNeighbors.push(random)
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
return targetNeighbors.map((neighbor) => this.
|
|
93
|
+
return targetNeighbors.map((neighbor) => this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
private async doParallelHandshakes(targets:
|
|
96
|
+
private async doParallelHandshakes(targets: HandshakeRpcRemote[], excludedIds: NodeID[]): Promise<NodeID[]> {
|
|
97
97
|
const results = await Promise.allSettled(
|
|
98
|
-
Array.from(targets.values()).map(async (target:
|
|
98
|
+
Array.from(targets.values()).map(async (target: HandshakeRpcRemote, i) => {
|
|
99
99
|
const otherNode = i === 0 ? targets[1] : targets[0]
|
|
100
100
|
const otherNodeId = otherNode ? getNodeIdFromPeerDescriptor(otherNode.getPeerDescriptor()) : undefined
|
|
101
101
|
return this.handshakeWithTarget(target, otherNodeId)
|
|
@@ -113,7 +113,7 @@ export class Handshaker implements IHandshaker {
|
|
|
113
113
|
const exclude = excludedIds.concat(this.config.targetNeighbors.getIds())
|
|
114
114
|
const targetNeighbor = this.config.nearbyNodeView.getClosest(exclude) ?? this.config.randomNodeView.getRandom(exclude)
|
|
115
115
|
if (targetNeighbor) {
|
|
116
|
-
const accepted = await this.handshakeWithTarget(this.
|
|
116
|
+
const accepted = await this.handshakeWithTarget(this.createRpcRemote(targetNeighbor.getPeerDescriptor()))
|
|
117
117
|
if (!accepted) {
|
|
118
118
|
excludedIds.push(getNodeIdFromPeerDescriptor(targetNeighbor.getPeerDescriptor()))
|
|
119
119
|
}
|
|
@@ -121,7 +121,7 @@ export class Handshaker implements IHandshaker {
|
|
|
121
121
|
return excludedIds
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
private async handshakeWithTarget(targetNeighbor:
|
|
124
|
+
private async handshakeWithTarget(targetNeighbor: HandshakeRpcRemote, concurrentNodeId?: NodeID): Promise<boolean> {
|
|
125
125
|
const targetNodeId = getNodeIdFromPeerDescriptor(targetNeighbor.getPeerDescriptor())
|
|
126
126
|
this.ongoingHandshakes.add(targetNodeId)
|
|
127
127
|
const result = await targetNeighbor.handshake(
|
|
@@ -129,8 +129,8 @@ export class Handshaker implements IHandshaker {
|
|
|
129
129
|
concurrentNodeId
|
|
130
130
|
)
|
|
131
131
|
if (result.accepted) {
|
|
132
|
-
this.config.targetNeighbors.add(this.
|
|
133
|
-
this.config.connectionLocker.lockConnection(targetNeighbor.getPeerDescriptor(), this.config.
|
|
132
|
+
this.config.targetNeighbors.add(this.createDeliveryRpcRemote(targetNeighbor.getPeerDescriptor()))
|
|
133
|
+
this.config.connectionLocker.lockConnection(targetNeighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
134
134
|
}
|
|
135
135
|
if (result.interleaveTargetDescriptor) {
|
|
136
136
|
await this.handshakeWithInterleaving(result.interleaveTargetDescriptor, targetNodeId)
|
|
@@ -140,10 +140,10 @@ export class Handshaker implements IHandshaker {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
private async handshakeWithInterleaving(target: PeerDescriptor, interleaveSourceId: NodeID): Promise<boolean> {
|
|
143
|
-
const targetNeighbor = new
|
|
143
|
+
const targetNeighbor = new HandshakeRpcRemote(
|
|
144
144
|
this.config.ownPeerDescriptor,
|
|
145
145
|
target,
|
|
146
|
-
this.config.
|
|
146
|
+
this.config.streamPartId,
|
|
147
147
|
this.client
|
|
148
148
|
)
|
|
149
149
|
const targetNodeId = getNodeIdFromPeerDescriptor(targetNeighbor.getPeerDescriptor())
|
|
@@ -154,27 +154,27 @@ export class Handshaker implements IHandshaker {
|
|
|
154
154
|
interleaveSourceId
|
|
155
155
|
)
|
|
156
156
|
if (result.accepted) {
|
|
157
|
-
this.config.targetNeighbors.add(this.
|
|
158
|
-
this.config.connectionLocker.lockConnection(targetNeighbor.getPeerDescriptor(), this.config.
|
|
157
|
+
this.config.targetNeighbors.add(this.createDeliveryRpcRemote(targetNeighbor.getPeerDescriptor()))
|
|
158
|
+
this.config.connectionLocker.lockConnection(targetNeighbor.getPeerDescriptor(), this.config.streamPartId)
|
|
159
159
|
}
|
|
160
160
|
this.ongoingHandshakes.delete(targetNodeId)
|
|
161
161
|
return result.accepted
|
|
162
162
|
}
|
|
163
163
|
|
|
164
|
-
private
|
|
165
|
-
return new
|
|
164
|
+
private createRpcRemote(targetPeerDescriptor: PeerDescriptor): HandshakeRpcRemote {
|
|
165
|
+
return new HandshakeRpcRemote(this.config.ownPeerDescriptor, targetPeerDescriptor, this.config.streamPartId, this.client)
|
|
166
166
|
}
|
|
167
167
|
|
|
168
|
-
private
|
|
169
|
-
return new
|
|
168
|
+
private createDeliveryRpcRemote(targetPeerDescriptor: PeerDescriptor): DeliveryRpcRemote {
|
|
169
|
+
return new DeliveryRpcRemote(
|
|
170
170
|
this.config.ownPeerDescriptor,
|
|
171
171
|
targetPeerDescriptor,
|
|
172
|
-
this.config.
|
|
173
|
-
toProtoRpcClient(new
|
|
172
|
+
this.config.streamPartId,
|
|
173
|
+
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
174
174
|
)
|
|
175
175
|
}
|
|
176
176
|
|
|
177
|
-
|
|
177
|
+
getOngoingHandshakes(): Set<NodeID> {
|
|
178
178
|
return this.ongoingHandshakes
|
|
179
179
|
}
|
|
180
180
|
|
|
@@ -6,7 +6,7 @@ interface FindNeighborsSessionConfig {
|
|
|
6
6
|
targetNeighbors: NodeList
|
|
7
7
|
nearbyNodeView: NodeList
|
|
8
8
|
doFindNeighbors: (excludedNodes: NodeID[]) => Promise<NodeID[]>
|
|
9
|
-
|
|
9
|
+
minCount: number
|
|
10
10
|
}
|
|
11
11
|
|
|
12
12
|
const INITIAL_WAIT = 100
|
|
@@ -33,7 +33,7 @@ export class NeighborFinder implements INeighborFinder {
|
|
|
33
33
|
return
|
|
34
34
|
}
|
|
35
35
|
const newExcludes = await this.config.doFindNeighbors(excluded)
|
|
36
|
-
if (this.config.targetNeighbors.size() < this.config.
|
|
36
|
+
if (this.config.targetNeighbors.size() < this.config.minCount && newExcludes.length < this.config.nearbyNodeView.size()) {
|
|
37
37
|
setAbortableTimeout(() => this.findNeighbors(newExcludes), INTERVAL, this.abortController.signal)
|
|
38
38
|
} else {
|
|
39
39
|
this.running = false
|
|
@@ -5,16 +5,17 @@ import { NeighborUpdateRpcClient } from '../../proto/packages/trackerless-networ
|
|
|
5
5
|
import { Logger, scheduleAtInterval } from '@streamr/utils'
|
|
6
6
|
import { INeighborFinder } from './NeighborFinder'
|
|
7
7
|
import { NodeList } from '../NodeList'
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
8
|
+
import { NeighborUpdateRpcRemote } from './NeighborUpdateRpcRemote'
|
|
9
|
+
import { NeighborUpdateRpcLocal } from './NeighborUpdateRpcLocal'
|
|
10
10
|
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
11
|
+
import { StreamPartID } from '@streamr/protocol'
|
|
11
12
|
|
|
12
13
|
interface NeighborUpdateManagerConfig {
|
|
13
14
|
ownPeerDescriptor: PeerDescriptor
|
|
14
15
|
targetNeighbors: NodeList
|
|
15
16
|
nearbyNodeView: NodeList
|
|
16
17
|
neighborFinder: INeighborFinder
|
|
17
|
-
|
|
18
|
+
streamPartId: StreamPartID
|
|
18
19
|
rpcCommunicator: ListeningRpcCommunicator
|
|
19
20
|
neighborUpdateInterval: number
|
|
20
21
|
}
|
|
@@ -27,24 +28,26 @@ export interface INeighborUpdateManager {
|
|
|
27
28
|
}
|
|
28
29
|
|
|
29
30
|
export class NeighborUpdateManager implements INeighborUpdateManager {
|
|
31
|
+
|
|
30
32
|
private readonly abortController: AbortController
|
|
31
33
|
private readonly config: NeighborUpdateManagerConfig
|
|
32
34
|
private readonly client: ProtoRpcClient<NeighborUpdateRpcClient>
|
|
33
|
-
private readonly
|
|
35
|
+
private readonly rpcLocal: NeighborUpdateRpcLocal
|
|
36
|
+
|
|
34
37
|
constructor(config: NeighborUpdateManagerConfig) {
|
|
35
38
|
this.abortController = new AbortController()
|
|
36
39
|
this.client = toProtoRpcClient(new NeighborUpdateRpcClient(config.rpcCommunicator.getRpcClientTransport()))
|
|
37
|
-
this.
|
|
40
|
+
this.rpcLocal = new NeighborUpdateRpcLocal(config)
|
|
38
41
|
this.config = config
|
|
39
42
|
this.config.rpcCommunicator.registerRpcMethod(NeighborUpdate, NeighborUpdate, 'neighborUpdate',
|
|
40
|
-
(req: NeighborUpdate, context) => this.
|
|
43
|
+
(req: NeighborUpdate, context) => this.rpcLocal.neighborUpdate(req, context))
|
|
41
44
|
}
|
|
42
45
|
|
|
43
|
-
|
|
46
|
+
async start(): Promise<void> {
|
|
44
47
|
await scheduleAtInterval(() => this.updateNeighborInfo(), this.config.neighborUpdateInterval, false, this.abortController.signal)
|
|
45
48
|
}
|
|
46
49
|
|
|
47
|
-
|
|
50
|
+
stop(): void {
|
|
48
51
|
this.abortController.abort()
|
|
49
52
|
}
|
|
50
53
|
|
|
@@ -60,7 +63,7 @@ export class NeighborUpdateManager implements INeighborUpdateManager {
|
|
|
60
63
|
}))
|
|
61
64
|
}
|
|
62
65
|
|
|
63
|
-
private createRemote(targetPeerDescriptor: PeerDescriptor):
|
|
64
|
-
return new
|
|
66
|
+
private createRemote(targetPeerDescriptor: PeerDescriptor): NeighborUpdateRpcRemote {
|
|
67
|
+
return new NeighborUpdateRpcRemote(this.config.ownPeerDescriptor, targetPeerDescriptor, this.config.streamPartId, this.client)
|
|
65
68
|
}
|
|
66
69
|
}
|