@streamr/trackerless-network 0.0.1-tatum.6 → 0.0.1-tatum.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +10 -8
- package/dist/src/NetworkNode.js +2 -2
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +5 -6
- package/dist/src/NetworkStack.js +27 -56
- 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} +10 -12
- package/dist/src/logic/{StreamPartEntryPointDiscovery.js → EntryPointDiscovery.js} +18 -40
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -0
- package/dist/src/logic/Layer0Node.d.ts +14 -0
- package/dist/src/logic/{ILayer1.js → Layer0Node.js} +1 -1
- package/dist/src/logic/Layer0Node.js.map +1 -0
- package/dist/src/logic/{ILayer1.d.ts → Layer1Node.d.ts} +5 -5
- package/dist/src/logic/{ILayer0.js → Layer1Node.js} +1 -1
- package/dist/src/logic/Layer1Node.js.map +1 -0
- 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 +11 -15
- package/dist/src/logic/RandomGraphNode.js +46 -45
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +15 -18
- package/dist/src/logic/StreamrNode.js +78 -87
- 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} +7 -10
- package/dist/src/logic/proxy/{ProxyStreamConnectionClient.js → ProxyClient.js} +24 -22
- 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.client.d.ts +10 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +7 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +54 -118
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +50 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +6 -0
- 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 +16 -17
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +7 -6
- package/dist/test/utils/utils.js +18 -17
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +10 -8
- package/protos/NetworkRpc.proto +5 -5
- package/src/NetworkNode.ts +2 -2
- package/src/NetworkStack.ts +31 -72
- 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} +24 -48
- package/src/logic/Layer0Node.ts +15 -0
- package/src/logic/{ILayer1.ts → Layer1Node.ts} +5 -5
- package/src/logic/NodeList.ts +12 -12
- package/src/logic/RandomGraphNode.ts +73 -74
- package/src/logic/StreamrNode.ts +90 -103
- 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} +29 -29
- 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.client.ts +13 -0
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +6 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +88 -166
- 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 +19 -20
- package/test/end-to-end/inspect.test.ts +12 -12
- package/test/end-to-end/proxy-and-full-node.test.ts +17 -18
- 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 +27 -22
- 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 +4 -3
- 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 +14 -13
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +23 -20
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +30 -29
- package/test/integration/StreamrNode.test.ts +16 -13
- package/test/integration/joining-streams-on-offline-peers.test.ts +16 -18
- package/test/integration/stream-without-default-entrypoints.test.ts +12 -14
- package/test/unit/{StreamNodeServer.test.ts → DeliveryRpcLocal.test.ts} +8 -8
- package/test/unit/{StreamPartEntrypointDiscovery.test.ts → EntrypointDiscovery.test.ts} +27 -44
- 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 +15 -13
- package/test/unit/StreamMessageTranslator.test.ts +10 -9
- package/test/unit/StreamrNode.test.ts +10 -10
- package/test/utils/mock/{MockLayer0.ts → MockLayer0Node.ts} +23 -26
- package/test/utils/mock/{MockLayer1.ts → MockLayer1Node.ts} +5 -10
- 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 +18 -16
- package/dist/src/logic/ILayer0.d.ts +0 -13
- package/dist/src/logic/ILayer0.js.map +0 -1
- package/dist/src/logic/ILayer1.js.map +0 -1
- 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
- package/src/logic/ILayer0.ts +0 -14
|
@@ -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
|
}
|
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,23 +39,23 @@ 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
|
-
|
|
51
|
+
streamPartId: this.config.streamPartId,
|
|
52
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
|
-
|
|
58
|
+
streamPartId: this.config.streamPartId,
|
|
59
59
|
neighborDescriptors: this.config.targetNeighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor()),
|
|
60
60
|
removeMe: true
|
|
61
61
|
}
|
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
|
-
|
|
45
|
+
interface ProxyClientConfig {
|
|
46
|
+
transport: 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,14 +73,14 @@ 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.transport)
|
|
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) => {
|
|
@@ -89,7 +90,7 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
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,
|
|
@@ -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)
|
|
@@ -232,7 +232,7 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
232
232
|
private async onNodeDisconnected(peerDescriptor: PeerDescriptor): Promise<void> {
|
|
233
233
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
234
234
|
if (this.connections.has(nodeId)) {
|
|
235
|
-
this.config.connectionLocker.unlockConnection(peerDescriptor,
|
|
235
|
+
this.config.connectionLocker.unlockConnection(peerDescriptor, SERVICE_ID)
|
|
236
236
|
this.removeConnection(nodeId)
|
|
237
237
|
await retry(() => this.updateConnections(), 'updating proxy connections', this.abortController.signal)
|
|
238
238
|
}
|
|
@@ -241,7 +241,7 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
241
241
|
async start(): Promise<void> {
|
|
242
242
|
this.registerDefaultServerMethods()
|
|
243
243
|
addManagedEventListener<any, any>(
|
|
244
|
-
this.config.
|
|
244
|
+
this.config.transport as any,
|
|
245
245
|
'disconnected',
|
|
246
246
|
(peerDescriptor: PeerDescriptor) => this.onNodeDisconnected(peerDescriptor),
|
|
247
247
|
this.abortController.signal
|
|
@@ -250,7 +250,7 @@ export class ProxyStreamConnectionClient extends EventEmitter {
|
|
|
250
250
|
|
|
251
251
|
stop(): void {
|
|
252
252
|
this.targetNeighbors.getAll().map((remote) => {
|
|
253
|
-
this.config.connectionLocker.unlockConnection(remote.getPeerDescriptor(),
|
|
253
|
+
this.config.connectionLocker.unlockConnection(remote.getPeerDescriptor(), SERVICE_ID)
|
|
254
254
|
remote.leaveStreamPartNotice()
|
|
255
255
|
})
|
|
256
256
|
this.targetNeighbors.stop()
|
|
@@ -8,25 +8,24 @@ import {
|
|
|
8
8
|
StreamMessageType
|
|
9
9
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
10
10
|
import { IProxyConnectionRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
11
|
-
import {
|
|
12
|
-
import { ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
11
|
+
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
12
|
+
import { DhtCallContext, ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
13
13
|
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
14
|
-
import {
|
|
14
|
+
import { DeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
15
15
|
import { EventEmitter } from 'eventemitter3'
|
|
16
16
|
import { EthereumAddress, Logger, binaryToHex, toEthereumAddress } from '@streamr/utils'
|
|
17
17
|
import { StreamPartID } from '@streamr/protocol'
|
|
18
18
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
19
|
-
import { DhtCallContext } from '@streamr/dht/src/exports'
|
|
20
19
|
|
|
21
20
|
const logger = new Logger(module)
|
|
22
21
|
|
|
23
22
|
interface ProxyConnection {
|
|
24
23
|
direction: ProxyDirection // Direction is from the client's point of view
|
|
25
24
|
userId: EthereumAddress
|
|
26
|
-
remote:
|
|
25
|
+
remote: DeliveryRpcRemote
|
|
27
26
|
}
|
|
28
27
|
|
|
29
|
-
interface
|
|
28
|
+
interface ProxyConnectionRpcLocalConfig {
|
|
30
29
|
ownPeerDescriptor: PeerDescriptor
|
|
31
30
|
streamPartId: StreamPartID
|
|
32
31
|
rpcCommunicator: ListeningRpcCommunicator
|
|
@@ -36,12 +35,12 @@ export interface Events {
|
|
|
36
35
|
newConnection: (nodeId: NodeID) => void
|
|
37
36
|
}
|
|
38
37
|
|
|
39
|
-
export class
|
|
38
|
+
export class ProxyConnectionRpcLocal extends EventEmitter<Events> implements IProxyConnectionRpc {
|
|
40
39
|
|
|
41
|
-
private readonly config:
|
|
40
|
+
private readonly config: ProxyConnectionRpcLocalConfig
|
|
42
41
|
private readonly connections: Map<NodeID, ProxyConnection> = new Map()
|
|
43
42
|
|
|
44
|
-
constructor(config:
|
|
43
|
+
constructor(config: ProxyConnectionRpcLocalConfig) {
|
|
45
44
|
super()
|
|
46
45
|
this.config = config
|
|
47
46
|
this.config.rpcCommunicator.registerRpcMethod(ProxyConnectionRequest, ProxyConnectionResponse, 'requestConnection',
|
|
@@ -95,11 +94,11 @@ export class ProxyStreamConnectionServer extends EventEmitter<Events> implements
|
|
|
95
94
|
this.connections.set(senderId, {
|
|
96
95
|
direction: request.direction,
|
|
97
96
|
userId: toEthereumAddress(binaryToHex(request.userId, true)),
|
|
98
|
-
remote: new
|
|
97
|
+
remote: new DeliveryRpcRemote(
|
|
99
98
|
this.config.ownPeerDescriptor,
|
|
100
99
|
senderPeerDescriptor,
|
|
101
100
|
this.config.streamPartId,
|
|
102
|
-
toProtoRpcClient(new
|
|
101
|
+
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
103
102
|
)
|
|
104
103
|
})
|
|
105
104
|
const response: ProxyConnectionResponse = {
|
|
@@ -5,7 +5,7 @@ import { IProxyConnectionRpcClient } from '../../proto/packages/trackerless-netw
|
|
|
5
5
|
|
|
6
6
|
const logger = new Logger(module)
|
|
7
7
|
|
|
8
|
-
export class
|
|
8
|
+
export class ProxyConnectionRpcRemote extends Remote<IProxyConnectionRpcClient> {
|
|
9
9
|
|
|
10
10
|
async requestConnection(direction: ProxyDirection, userId: EthereumAddress): Promise<boolean> {
|
|
11
11
|
const request: ProxyConnectionRequest = {
|