@streamr/trackerless-network 0.0.1-tatum.5 → 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/EntryPointDiscovery.d.ts +35 -0
- package/dist/src/logic/EntryPointDiscovery.js +145 -0
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -0
- package/dist/src/logic/ILayer0.d.ts +3 -6
- package/dist/src/logic/ILayer1.d.ts +2 -2
- package/dist/src/logic/NodeList.d.ts +10 -10
- package/dist/src/logic/NodeList.js +2 -2
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +8 -12
- package/dist/src/logic/RandomGraphNode.js +47 -46
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +9 -11
- package/dist/src/logic/StreamrNode.js +72 -75
- 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 +5 -5
- 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 +7 -7
- 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} +11 -11
- 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} +8 -12
- package/dist/src/logic/proxy/{ProxyStreamConnectionClient.js → ProxyClient.js} +28 -29
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -0
- package/dist/src/logic/proxy/{ProxyStreamConnectionServer.d.ts → ProxyConnectionRpcLocal.d.ts} +5 -7
- package/dist/src/logic/proxy/{ProxyStreamConnectionServer.js → ProxyConnectionRpcLocal.js} +6 -12
- 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 -14
- 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/EntryPointDiscovery.ts +181 -0
- package/src/logic/ILayer0.ts +3 -6
- package/src/logic/ILayer1.ts +2 -5
- package/src/logic/NodeList.ts +12 -12
- package/src/logic/RandomGraphNode.ts +67 -69
- package/src/logic/StreamrNode.ts +78 -90
- 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 +6 -6
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +15 -12
- package/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.ts → NeighborUpdateRpcLocal.ts} +17 -17
- 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} +33 -37
- package/src/logic/proxy/{ProxyStreamConnectionServer.ts → ProxyConnectionRpcLocal.ts} +10 -19
- 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 +10 -12
- 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/EntrypointDiscovery.test.ts +132 -0
- 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 +12 -11
- 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 +6 -13
- 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 -13
- package/dist/src/logic/RemoteRandomGraphNode.js.map +0 -1
- package/dist/src/logic/StreamPartEntryPointDiscovery.d.ts +0 -39
- package/dist/src/logic/StreamPartEntryPointDiscovery.js +0 -194
- 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
- package/src/logic/StreamPartEntryPointDiscovery.ts +0 -240
- package/test/unit/StreamPartEntrypointDiscovery.test.ts +0 -164
|
@@ -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,11 +6,11 @@ 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
|
-
const
|
|
13
|
-
const
|
|
12
|
+
const INITIAL_WAIT = 100
|
|
13
|
+
const INTERVAL = 250
|
|
14
14
|
|
|
15
15
|
export interface INeighborFinder {
|
|
16
16
|
start(excluded?: NodeID[]): void
|
|
@@ -33,8 +33,8 @@ 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.
|
|
37
|
-
setAbortableTimeout(() => this.findNeighbors(newExcludes),
|
|
36
|
+
if (this.config.targetNeighbors.size() < this.config.minCount && newExcludes.length < this.config.nearbyNodeView.size()) {
|
|
37
|
+
setAbortableTimeout(() => this.findNeighbors(newExcludes), INTERVAL, this.abortController.signal)
|
|
38
38
|
} else {
|
|
39
39
|
this.running = false
|
|
40
40
|
}
|
|
@@ -49,7 +49,7 @@ export class NeighborFinder implements INeighborFinder {
|
|
|
49
49
|
return
|
|
50
50
|
}
|
|
51
51
|
this.running = true
|
|
52
|
-
setAbortableTimeout(() => this.findNeighbors(excluded),
|
|
52
|
+
setAbortableTimeout(() => this.findNeighbors(excluded), INITIAL_WAIT, this.abortController.signal)
|
|
53
53
|
}
|
|
54
54
|
|
|
55
55
|
stop(): void {
|
|
@@ -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,31 +28,33 @@ 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
|
|
|
51
54
|
private async updateNeighborInfo(): Promise<void> {
|
|
52
55
|
logger.trace(`Updating neighbor info to nodes`)
|
|
53
|
-
const neighborDescriptors = this.config.targetNeighbors.
|
|
54
|
-
await Promise.allSettled(this.config.targetNeighbors.
|
|
56
|
+
const neighborDescriptors = this.config.targetNeighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor())
|
|
57
|
+
await Promise.allSettled(this.config.targetNeighbors.getAll().map(async (neighbor) => {
|
|
55
58
|
const res = await this.createRemote(neighbor.getPeerDescriptor()).updateNeighbors(neighborDescriptors)
|
|
56
59
|
if (res.removeMe) {
|
|
57
60
|
this.config.targetNeighbors.remove(neighbor.getPeerDescriptor())
|
|
@@ -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
|
}
|
package/src/logic/neighbor-discovery/{NeighborUpdateManagerServer.ts → NeighborUpdateRpcLocal.ts}
RENAMED
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import { DhtCallContext, ListeningRpcCommunicator } from '@streamr/dht'
|
|
3
|
-
import { PeerDescriptor } from '@streamr/dht/src/exports'
|
|
2
|
+
import { DhtCallContext, ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
4
3
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
5
4
|
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
6
5
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
7
|
-
import {
|
|
6
|
+
import { DeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
8
7
|
import { INeighborUpdateRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
9
8
|
import { NodeList } from '../NodeList'
|
|
10
|
-
import {
|
|
9
|
+
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
11
10
|
import { INeighborFinder } from './NeighborFinder'
|
|
11
|
+
import { StreamPartID } from '@streamr/protocol'
|
|
12
12
|
|
|
13
|
-
interface
|
|
13
|
+
interface NeighborUpdateRpcLocalConfig {
|
|
14
14
|
ownPeerDescriptor: PeerDescriptor
|
|
15
|
-
|
|
15
|
+
streamPartId: StreamPartID
|
|
16
16
|
targetNeighbors: NodeList
|
|
17
17
|
nearbyNodeView: NodeList
|
|
18
18
|
neighborFinder: INeighborFinder
|
|
19
19
|
rpcCommunicator: ListeningRpcCommunicator
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
export class
|
|
22
|
+
export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
23
23
|
|
|
24
|
-
private readonly config:
|
|
24
|
+
private readonly config: NeighborUpdateRpcLocalConfig
|
|
25
25
|
|
|
26
|
-
constructor(config:
|
|
26
|
+
constructor(config: NeighborUpdateRpcLocalConfig) {
|
|
27
27
|
this.config = config
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
//
|
|
30
|
+
// INeighborUpdateRpc server method
|
|
31
31
|
async neighborUpdate(message: NeighborUpdate, context: ServerCallContext): Promise<NeighborUpdate> {
|
|
32
32
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
33
33
|
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
@@ -39,24 +39,24 @@ export class NeighborUpdateManagerServer implements INeighborUpdateRpc {
|
|
|
39
39
|
return nodeId !== ownNodeId && !this.config.targetNeighbors.getIds().includes(nodeId)
|
|
40
40
|
})
|
|
41
41
|
newPeerDescriptors.forEach((peerDescriptor) => this.config.nearbyNodeView.add(
|
|
42
|
-
new
|
|
42
|
+
new DeliveryRpcRemote(
|
|
43
43
|
this.config.ownPeerDescriptor,
|
|
44
44
|
peerDescriptor,
|
|
45
|
-
this.config.
|
|
46
|
-
toProtoRpcClient(new
|
|
45
|
+
this.config.streamPartId,
|
|
46
|
+
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
47
47
|
))
|
|
48
48
|
)
|
|
49
49
|
this.config.neighborFinder.start()
|
|
50
50
|
const response: NeighborUpdate = {
|
|
51
|
-
|
|
52
|
-
neighborDescriptors: this.config.targetNeighbors.
|
|
51
|
+
streamPartId: this.config.streamPartId,
|
|
52
|
+
neighborDescriptors: this.config.targetNeighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor()),
|
|
53
53
|
removeMe: false
|
|
54
54
|
}
|
|
55
55
|
return response
|
|
56
56
|
} else {
|
|
57
57
|
const response: NeighborUpdate = {
|
|
58
|
-
|
|
59
|
-
neighborDescriptors: this.config.targetNeighbors.
|
|
58
|
+
streamPartId: this.config.streamPartId,
|
|
59
|
+
neighborDescriptors: this.config.targetNeighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor()),
|
|
60
60
|
removeMe: true
|
|
61
61
|
}
|
|
62
62
|
return response
|
package/src/logic/neighbor-discovery/{RemoteNeighborUpdateManager.ts → NeighborUpdateRpcRemote.ts}
RENAMED
|
@@ -11,11 +11,11 @@ interface UpdateNeighborsResponse {
|
|
|
11
11
|
removeMe: boolean
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export class
|
|
14
|
+
export class NeighborUpdateRpcRemote extends Remote<INeighborUpdateRpcClient> {
|
|
15
15
|
|
|
16
16
|
async updateNeighbors(neighbors: PeerDescriptor[]): Promise<UpdateNeighborsResponse> {
|
|
17
17
|
const request: NeighborUpdate = {
|
|
18
|
-
|
|
18
|
+
streamPartId: this.getServiceId(),
|
|
19
19
|
neighborDescriptors: neighbors,
|
|
20
20
|
removeMe: false
|
|
21
21
|
}
|
|
@@ -57,8 +57,8 @@ export class Propagation {
|
|
|
57
57
|
* Node should invoke this when it learns about a new node stream assignment
|
|
58
58
|
*/
|
|
59
59
|
onNeighborJoined(neighborId: NodeID): void {
|
|
60
|
-
const
|
|
61
|
-
for (const task of
|
|
60
|
+
const tasks = this.activeTaskStore.get()
|
|
61
|
+
for (const task of tasks) {
|
|
62
62
|
this.sendAndAwaitThenMark(task, neighborId)
|
|
63
63
|
}
|
|
64
64
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
|
+
ConnectionLocker,
|
|
2
3
|
ITransport,
|
|
3
4
|
ListeningRpcCommunicator,
|
|
4
5
|
PeerDescriptor
|
|
5
6
|
} from '@streamr/dht'
|
|
6
|
-
import { ConnectionLocker } from '@streamr/dht/src/exports'
|
|
7
7
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
8
8
|
import { StreamPartID } from '@streamr/protocol'
|
|
9
9
|
import { EthereumAddress, Logger, addManagedEventListener, wait } from '@streamr/utils'
|
|
@@ -17,14 +17,15 @@ import {
|
|
|
17
17
|
ProxyDirection,
|
|
18
18
|
StreamMessage
|
|
19
19
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
20
|
-
import {
|
|
20
|
+
import { DeliveryRpcClient, ProxyConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
21
21
|
import { DuplicateMessageDetector } from '../DuplicateMessageDetector'
|
|
22
22
|
import { NodeList } from '../NodeList'
|
|
23
|
-
import {
|
|
24
|
-
import {
|
|
23
|
+
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
24
|
+
import { DeliveryRpcLocal } from '../DeliveryRpcLocal'
|
|
25
25
|
import { Propagation } from '../propagation/Propagation'
|
|
26
26
|
import { markAndCheckDuplicate } from '../utils'
|
|
27
|
-
import {
|
|
27
|
+
import { ProxyConnectionRpcRemote } from './ProxyConnectionRpcRemote'
|
|
28
|
+
import { formStreamPartDeliveryServiceId } from '../formStreamPartDeliveryServiceId'
|
|
28
29
|
|
|
29
30
|
export const retry = async <T>(task: () => Promise<T>, description: string, abortSignal: AbortSignal, delay = 10000): Promise<T> => {
|
|
30
31
|
// eslint-disable-next-line no-constant-condition
|
|
@@ -41,13 +42,11 @@ export const retry = async <T>(task: () => Promise<T>, description: string, abor
|
|
|
41
42
|
}
|
|
42
43
|
}
|
|
43
44
|
|
|
44
|
-
interface
|
|
45
|
+
interface ProxyClientConfig {
|
|
45
46
|
P2PTransport: ITransport
|
|
46
47
|
ownPeerDescriptor: PeerDescriptor
|
|
47
48
|
streamPartId: StreamPartID
|
|
48
49
|
connectionLocker: ConnectionLocker
|
|
49
|
-
userId: EthereumAddress
|
|
50
|
-
nodeName?: string
|
|
51
50
|
minPropagationTargets?: number // TODO could be required option if we apply all defaults somewhere at higher level
|
|
52
51
|
}
|
|
53
52
|
|
|
@@ -60,11 +59,13 @@ interface ProxyDefinition {
|
|
|
60
59
|
|
|
61
60
|
const logger = new Logger(module)
|
|
62
61
|
|
|
63
|
-
|
|
62
|
+
const SERVICE_ID = 'system/proxy-client'
|
|
63
|
+
|
|
64
|
+
export class ProxyClient extends EventEmitter {
|
|
64
65
|
|
|
65
66
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
66
|
-
private readonly
|
|
67
|
-
private readonly config:
|
|
67
|
+
private readonly deliveryRpcLocal: DeliveryRpcLocal
|
|
68
|
+
private readonly config: ProxyClientConfig
|
|
68
69
|
private readonly duplicateDetectors: Map<string, DuplicateMessageDetector> = new Map()
|
|
69
70
|
private definition?: ProxyDefinition
|
|
70
71
|
private readonly connections: Map<NodeID, ProxyDirection> = new Map()
|
|
@@ -72,29 +73,29 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
72
73
|
private readonly targetNeighbors: NodeList
|
|
73
74
|
private readonly abortController: AbortController
|
|
74
75
|
|
|
75
|
-
constructor(config:
|
|
76
|
+
constructor(config: ProxyClientConfig) {
|
|
76
77
|
super()
|
|
77
78
|
this.config = config
|
|
78
|
-
this.rpcCommunicator = new ListeningRpcCommunicator(
|
|
79
|
+
this.rpcCommunicator = new ListeningRpcCommunicator(formStreamPartDeliveryServiceId(config.streamPartId), config.P2PTransport)
|
|
79
80
|
this.targetNeighbors = new NodeList(getNodeIdFromPeerDescriptor(this.config.ownPeerDescriptor), 1000)
|
|
80
|
-
this.
|
|
81
|
+
this.deliveryRpcLocal = new DeliveryRpcLocal({
|
|
81
82
|
ownPeerDescriptor: this.config.ownPeerDescriptor,
|
|
82
|
-
|
|
83
|
+
streamPartId: this.config.streamPartId,
|
|
83
84
|
markAndCheckDuplicate: (msg: MessageID, prev?: MessageRef) => markAndCheckDuplicate(this.duplicateDetectors, msg, prev),
|
|
84
85
|
broadcast: (message: StreamMessage, previousNode?: NodeID) => this.broadcast(message, previousNode),
|
|
85
86
|
onLeaveNotice: (senderId: NodeID) => {
|
|
86
|
-
const contact = this.targetNeighbors.
|
|
87
|
+
const contact = this.targetNeighbors.get(senderId)
|
|
87
88
|
if (contact) {
|
|
88
89
|
setImmediate(() => this.onNodeDisconnected(contact.getPeerDescriptor()))
|
|
89
90
|
}
|
|
90
91
|
},
|
|
91
92
|
rpcCommunicator: this.rpcCommunicator,
|
|
92
|
-
markForInspection: (
|
|
93
|
+
markForInspection: () => {}
|
|
93
94
|
})
|
|
94
95
|
this.propagation = new Propagation({
|
|
95
96
|
minPropagationTargets: config.minPropagationTargets ?? 2,
|
|
96
97
|
sendToNeighbor: async (neighborId: NodeID, msg: StreamMessage): Promise<void> => {
|
|
97
|
-
const remote = this.targetNeighbors.
|
|
98
|
+
const remote = this.targetNeighbors.get(neighborId)
|
|
98
99
|
if (remote) {
|
|
99
100
|
await remote.sendStreamMessage(msg)
|
|
100
101
|
} else {
|
|
@@ -107,19 +108,18 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
107
108
|
|
|
108
109
|
private registerDefaultServerMethods(): void {
|
|
109
110
|
this.rpcCommunicator.registerRpcNotification(StreamMessage, 'sendStreamMessage',
|
|
110
|
-
(msg: StreamMessage, context) => this.
|
|
111
|
+
(msg: StreamMessage, context) => this.deliveryRpcLocal.sendStreamMessage(msg, context))
|
|
111
112
|
this.rpcCommunicator.registerRpcNotification(LeaveStreamPartNotice, 'leaveStreamPartNotice',
|
|
112
|
-
(req: LeaveStreamPartNotice, context) => this.
|
|
113
|
+
(req: LeaveStreamPartNotice, context) => this.deliveryRpcLocal.leaveStreamPartNotice(req, context))
|
|
113
114
|
}
|
|
114
115
|
|
|
115
116
|
async setProxies(
|
|
116
|
-
streamPartId: StreamPartID,
|
|
117
117
|
nodes: PeerDescriptor[],
|
|
118
118
|
direction: ProxyDirection,
|
|
119
119
|
userId: EthereumAddress,
|
|
120
120
|
connectionCount?: number
|
|
121
121
|
): Promise<void> {
|
|
122
|
-
logger.trace('Setting proxies', { streamPartId, peerDescriptors: nodes, direction, userId, connectionCount })
|
|
122
|
+
logger.trace('Setting proxies', { streamPartId: this.config.streamPartId, peerDescriptors: nodes, direction, userId, connectionCount })
|
|
123
123
|
if (connectionCount !== undefined && connectionCount > nodes.length) {
|
|
124
124
|
throw Error('Cannot set connectionCount above the size of the configured array of nodes')
|
|
125
125
|
}
|
|
@@ -167,16 +167,16 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
167
167
|
private async attemptConnection(nodeId: NodeID, direction: ProxyDirection, userId: EthereumAddress): Promise<void> {
|
|
168
168
|
const peerDescriptor = this.definition!.nodes.get(nodeId)!
|
|
169
169
|
const client = toProtoRpcClient(new ProxyConnectionRpcClient(this.rpcCommunicator.getRpcClientTransport()))
|
|
170
|
-
const
|
|
171
|
-
const accepted = await
|
|
170
|
+
const rpcRemote = new ProxyConnectionRpcRemote(this.config.ownPeerDescriptor, peerDescriptor, this.config.streamPartId, client)
|
|
171
|
+
const accepted = await rpcRemote.requestConnection(direction, userId)
|
|
172
172
|
if (accepted) {
|
|
173
|
-
this.config.connectionLocker.lockConnection(peerDescriptor,
|
|
173
|
+
this.config.connectionLocker.lockConnection(peerDescriptor, SERVICE_ID)
|
|
174
174
|
this.connections.set(nodeId, direction)
|
|
175
|
-
const remote = new
|
|
175
|
+
const remote = new DeliveryRpcRemote(
|
|
176
176
|
this.config.ownPeerDescriptor,
|
|
177
177
|
peerDescriptor,
|
|
178
178
|
this.config.streamPartId,
|
|
179
|
-
toProtoRpcClient(new
|
|
179
|
+
toProtoRpcClient(new DeliveryRpcClient(this.rpcCommunicator.getRpcClientTransport()))
|
|
180
180
|
)
|
|
181
181
|
this.targetNeighbors.add(remote)
|
|
182
182
|
this.propagation.onNeighborJoined(nodeId)
|
|
@@ -202,7 +202,7 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
202
202
|
logger.info('Close proxy connection', {
|
|
203
203
|
nodeId
|
|
204
204
|
})
|
|
205
|
-
const server = this.targetNeighbors.
|
|
205
|
+
const server = this.targetNeighbors.get(nodeId)
|
|
206
206
|
server?.leaveStreamPartNotice()
|
|
207
207
|
this.removeConnection(nodeId)
|
|
208
208
|
}
|
|
@@ -221,11 +221,7 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
221
221
|
this.propagation.feedUnseenMessage(msg, this.targetNeighbors.getIds(), previousNode ?? null)
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
-
|
|
225
|
-
return this.targetNeighbors.getIds()
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
hasProxyConnection(nodeId: NodeID, direction: ProxyDirection): boolean {
|
|
224
|
+
hasConnection(nodeId: NodeID, direction: ProxyDirection): boolean {
|
|
229
225
|
return this.connections.has(nodeId) && this.connections.get(nodeId) === direction
|
|
230
226
|
}
|
|
231
227
|
|
|
@@ -233,10 +229,10 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
233
229
|
return this.definition!.direction
|
|
234
230
|
}
|
|
235
231
|
|
|
236
|
-
async onNodeDisconnected(peerDescriptor: PeerDescriptor): Promise<void> {
|
|
232
|
+
private async onNodeDisconnected(peerDescriptor: PeerDescriptor): Promise<void> {
|
|
237
233
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
238
234
|
if (this.connections.has(nodeId)) {
|
|
239
|
-
this.config.connectionLocker.unlockConnection(peerDescriptor,
|
|
235
|
+
this.config.connectionLocker.unlockConnection(peerDescriptor, SERVICE_ID)
|
|
240
236
|
this.removeConnection(nodeId)
|
|
241
237
|
await retry(() => this.updateConnections(), 'updating proxy connections', this.abortController.signal)
|
|
242
238
|
}
|
|
@@ -253,8 +249,8 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
253
249
|
}
|
|
254
250
|
|
|
255
251
|
stop(): void {
|
|
256
|
-
this.targetNeighbors.
|
|
257
|
-
this.config.connectionLocker.unlockConnection(remote.getPeerDescriptor(),
|
|
252
|
+
this.targetNeighbors.getAll().map((remote) => {
|
|
253
|
+
this.config.connectionLocker.unlockConnection(remote.getPeerDescriptor(), SERVICE_ID)
|
|
258
254
|
remote.leaveStreamPartNotice()
|
|
259
255
|
})
|
|
260
256
|
this.targetNeighbors.stop()
|