@streamr/trackerless-network 100.0.0-testnet-one.4 → 100.0.0-testnet-two.0
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 +7 -7
- package/dist/src/NetworkStack.d.ts +1 -5
- package/dist/src/NetworkStack.js +1 -3
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/logic/DeliveryRpcLocal.d.ts +1 -1
- package/dist/src/logic/DeliveryRpcLocal.js +3 -3
- package/dist/src/logic/DeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/DeliveryRpcRemote.d.ts +3 -3
- package/dist/src/logic/DeliveryRpcRemote.js +3 -2
- package/dist/src/logic/DeliveryRpcRemote.js.map +1 -1
- package/dist/src/logic/EntryPointDiscovery.d.ts +3 -0
- package/dist/src/logic/EntryPointDiscovery.js +11 -5
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +10 -8
- package/dist/src/logic/RandomGraphNode.js +23 -17
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.js +13 -4
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.d.ts +2 -1
- package/dist/src/logic/formStreamPartDeliveryServiceId.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +5 -11
- package/dist/src/logic/inspect/Inspector.js +2 -3
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +3 -3
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +39 -13
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +5 -3
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +18 -8
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +1 -6
- package/dist/src/logic/neighbor-discovery/Handshaker.js +6 -6
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +1 -6
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +3 -8
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +1 -3
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +1 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +4 -1
- package/dist/src/logic/proxy/ProxyClient.js +7 -6
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +2 -3
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.d.ts +2 -2
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +2 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +2 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +21 -22
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +18 -18
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +36 -60
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +34 -53
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +11 -12
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +6 -5
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +2 -2
- 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 +26 -10
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +21 -9
- 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 +4 -3
- package/dist/test/benchmark/first-message.js +4 -6
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +1 -1
- package/dist/test/utils/utils.js +8 -7
- package/dist/test/utils/utils.js.map +1 -1
- package/package.json +7 -7
- package/protos/NetworkRpc.proto +8 -4
- package/src/NetworkStack.ts +1 -7
- package/src/logic/DeliveryRpcLocal.ts +4 -4
- package/src/logic/DeliveryRpcRemote.ts +5 -4
- package/src/logic/EntryPointDiscovery.ts +10 -6
- package/src/logic/RandomGraphNode.ts +38 -25
- package/src/logic/StreamrNode.ts +22 -5
- package/src/logic/formStreamPartDeliveryServiceId.ts +2 -1
- package/src/logic/inspect/Inspector.ts +15 -16
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +46 -15
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +21 -10
- package/src/logic/neighbor-discovery/Handshaker.ts +15 -24
- package/src/logic/neighbor-discovery/NeighborFinder.ts +1 -7
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +10 -12
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +4 -4
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +2 -2
- package/src/logic/proxy/ProxyClient.ts +19 -7
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +3 -3
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +3 -3
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +3 -2
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +2 -2
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +31 -32
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +11 -12
- package/src/proto/packages/dht/protos/DhtRpc.ts +49 -80
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +7 -6
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +4 -3
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +36 -15
- package/test/benchmark/first-message.ts +8 -6
- package/test/end-to-end/random-graph-with-real-connections.test.ts +10 -5
- package/test/end-to-end/webrtc-full-node-network.test.ts +1 -1
- package/test/end-to-end/websocket-full-node-network.test.ts +2 -2
- package/test/integration/DeliveryRpcRemote.test.ts +3 -3
- package/test/integration/HandshakeRpcRemote.test.ts +2 -4
- package/test/integration/Handshakes.test.ts +8 -7
- package/test/integration/Inspect.test.ts +0 -2
- package/test/integration/NeighborUpdateRpcRemote.test.ts +2 -2
- package/test/integration/NetworkNode.test.ts +0 -2
- package/test/integration/NetworkRpc.test.ts +0 -3
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +4 -4
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +4 -5
- package/test/integration/stream-without-default-entrypoints.test.ts +4 -7
- package/test/integration/streamEntryPointReplacing.test.ts +94 -0
- package/test/unit/DeliveryRpcLocal.test.ts +2 -1
- package/test/unit/EntrypointDiscovery.test.ts +5 -2
- package/test/unit/HandshakeRpcLocal.test.ts +47 -9
- package/test/unit/NodeList.test.ts +10 -12
- package/test/unit/ProxyConnectionRpcRemote.test.ts +18 -10
- package/test/unit/RandomGraphNode.test.ts +6 -4
- package/test/utils/mock/MockHandshaker.ts +3 -2
- package/test/utils/mock/MockNeighborFinder.ts +3 -2
- package/test/utils/mock/MockNeighborUpdateManager.ts +3 -2
- package/test/utils/utils.ts +16 -8
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PeerDescriptor, ConnectionLocker } from '@streamr/dht'
|
|
1
|
+
import { PeerDescriptor, ConnectionLocker, LockID } from '@streamr/dht'
|
|
2
2
|
import { MessageID } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { InspectSession, Events as InspectSessionEvents } from './InspectSession'
|
|
4
4
|
import { TemporaryConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
|
-
import {
|
|
5
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
6
6
|
import { Logger, waitForEvent3 } from '@streamr/utils'
|
|
7
7
|
import { TemporaryConnectionRpcRemote } from '../temporary-connection/TemporaryConnectionRpcRemote'
|
|
8
8
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
@@ -14,40 +14,39 @@ interface InspectorConfig {
|
|
|
14
14
|
rpcCommunicator: RpcCommunicator
|
|
15
15
|
connectionLocker: ConnectionLocker
|
|
16
16
|
inspectionTimeout?: number
|
|
17
|
-
openInspectConnection?: (peerDescriptor: PeerDescriptor, lockId:
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
export interface IInspector {
|
|
21
|
-
inspect(peerDescriptor: PeerDescriptor): Promise<boolean>
|
|
22
|
-
markMessage(sender: NodeID, messageId: MessageID): void
|
|
23
|
-
isInspected(nodeId: NodeID): boolean
|
|
24
|
-
stop(): void
|
|
17
|
+
openInspectConnection?: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
25
18
|
}
|
|
26
19
|
|
|
27
20
|
const logger = new Logger(module)
|
|
28
21
|
const DEFAULT_TIMEOUT = 60 * 1000
|
|
29
22
|
|
|
30
|
-
export class Inspector
|
|
23
|
+
export class Inspector {
|
|
31
24
|
|
|
32
25
|
private readonly sessions: Map<NodeID, InspectSession> = new Map()
|
|
33
26
|
private readonly streamPartId: StreamPartID
|
|
34
|
-
private readonly client: ProtoRpcClient<TemporaryConnectionRpcClient>
|
|
35
27
|
private readonly localPeerDescriptor: PeerDescriptor
|
|
28
|
+
private readonly rpcCommunicator: RpcCommunicator
|
|
36
29
|
private readonly connectionLocker: ConnectionLocker
|
|
37
30
|
private readonly inspectionTimeout: number
|
|
38
|
-
private readonly openInspectConnection: (peerDescriptor: PeerDescriptor, lockId:
|
|
31
|
+
private readonly openInspectConnection: (peerDescriptor: PeerDescriptor, lockId: LockID) => Promise<void>
|
|
39
32
|
|
|
40
33
|
constructor(config: InspectorConfig) {
|
|
41
34
|
this.streamPartId = config.streamPartId
|
|
42
35
|
this.localPeerDescriptor = config.localPeerDescriptor
|
|
43
|
-
this.
|
|
36
|
+
this.rpcCommunicator = config.rpcCommunicator
|
|
44
37
|
this.connectionLocker = config.connectionLocker
|
|
45
38
|
this.inspectionTimeout = config.inspectionTimeout ?? DEFAULT_TIMEOUT
|
|
46
39
|
this.openInspectConnection = config.openInspectConnection ?? this.defaultOpenInspectConnection
|
|
47
40
|
}
|
|
48
41
|
|
|
49
|
-
async defaultOpenInspectConnection(peerDescriptor: PeerDescriptor, lockId:
|
|
50
|
-
const rpcRemote = new TemporaryConnectionRpcRemote(
|
|
42
|
+
async defaultOpenInspectConnection(peerDescriptor: PeerDescriptor, lockId: LockID): Promise<void> {
|
|
43
|
+
const rpcRemote = new TemporaryConnectionRpcRemote(
|
|
44
|
+
this.localPeerDescriptor,
|
|
45
|
+
peerDescriptor,
|
|
46
|
+
this.streamPartId,
|
|
47
|
+
this.rpcCommunicator,
|
|
48
|
+
TemporaryConnectionRpcClient
|
|
49
|
+
)
|
|
51
50
|
await rpcRemote.openConnection()
|
|
52
51
|
this.connectionLocker.lockConnection(peerDescriptor, lockId)
|
|
53
52
|
}
|
|
@@ -1,5 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
1
|
+
import {
|
|
2
|
+
InterleaveRequest,
|
|
3
|
+
InterleaveResponse,
|
|
4
|
+
StreamPartHandshakeRequest,
|
|
5
|
+
StreamPartHandshakeResponse
|
|
6
|
+
} from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
7
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
4
8
|
import { NodeList } from '../NodeList'
|
|
5
9
|
import { ConnectionLocker, DhtCallContext, PeerDescriptor } from '@streamr/dht'
|
|
@@ -7,7 +11,7 @@ import { IHandshakeRpc } from '../../proto/packages/trackerless-network/protos/N
|
|
|
7
11
|
import { HandshakeRpcRemote } from './HandshakeRpcRemote'
|
|
8
12
|
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
9
13
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
10
|
-
import { binaryToHex } from '@streamr/utils'
|
|
14
|
+
import { Logger, binaryToHex } from '@streamr/utils'
|
|
11
15
|
import { StreamPartID } from '@streamr/protocol'
|
|
12
16
|
|
|
13
17
|
interface HandshakeRpcLocalConfig {
|
|
@@ -15,12 +19,15 @@ interface HandshakeRpcLocalConfig {
|
|
|
15
19
|
targetNeighbors: NodeList
|
|
16
20
|
connectionLocker: ConnectionLocker
|
|
17
21
|
ongoingHandshakes: Set<NodeID>
|
|
22
|
+
ongoingInterleaves: Set<NodeID>
|
|
18
23
|
maxNeighborCount: number
|
|
19
24
|
createRpcRemote: (target: PeerDescriptor) => HandshakeRpcRemote
|
|
20
25
|
createDeliveryRpcRemote: (peerDescriptor: PeerDescriptor) => DeliveryRpcRemote
|
|
21
26
|
handshakeWithInterleaving: (target: PeerDescriptor, senderId: NodeID) => Promise<boolean>
|
|
22
27
|
}
|
|
23
28
|
|
|
29
|
+
const logger = new Logger(module)
|
|
30
|
+
|
|
24
31
|
export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
25
32
|
|
|
26
33
|
private readonly config: HandshakeRpcLocalConfig
|
|
@@ -36,13 +43,17 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
36
43
|
private handleRequest(request: StreamPartHandshakeRequest, context: ServerCallContext): StreamPartHandshakeResponse {
|
|
37
44
|
const senderDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
38
45
|
const getInterleaveSourceIds = () => (request.interleaveSourceId !== undefined) ? [binaryToHex(request.interleaveSourceId) as NodeID] : []
|
|
39
|
-
if (this.config.
|
|
46
|
+
if (this.config.ongoingInterleaves.has(getNodeIdFromPeerDescriptor(senderDescriptor))) {
|
|
47
|
+
return this.rejectHandshake(request)
|
|
48
|
+
} else if (this.config.targetNeighbors.hasNode(senderDescriptor)
|
|
40
49
|
|| this.config.ongoingHandshakes.has(getNodeIdFromPeerDescriptor(senderDescriptor))
|
|
41
50
|
) {
|
|
42
51
|
return this.acceptHandshake(request, senderDescriptor)
|
|
43
52
|
} else if (this.config.targetNeighbors.size() + this.config.ongoingHandshakes.size < this.config.maxNeighborCount) {
|
|
44
53
|
return this.acceptHandshake(request, senderDescriptor)
|
|
45
|
-
} else if (this.config.targetNeighbors.size(getInterleaveSourceIds()) >= 2) {
|
|
54
|
+
} else if (this.config.targetNeighbors.size(getInterleaveSourceIds()) - this.config.ongoingInterleaves.size >= 2) {
|
|
55
|
+
// Do not accept the handshakes requests if the target neighbor count can potentially drop below 2
|
|
56
|
+
// due to interleaving. This ensures that a stable number of connections is kept during high churn.
|
|
46
57
|
return this.acceptHandshakeWithInterleaving(request, senderDescriptor)
|
|
47
58
|
} else {
|
|
48
59
|
return this.rejectHandshake(request)
|
|
@@ -69,7 +80,9 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
69
80
|
}
|
|
70
81
|
|
|
71
82
|
private acceptHandshakeWithInterleaving(request: StreamPartHandshakeRequest, requester: PeerDescriptor): StreamPartHandshakeResponse {
|
|
72
|
-
const exclude
|
|
83
|
+
const exclude: NodeID[] = []
|
|
84
|
+
request.neighborIds.forEach((id: Uint8Array) => exclude.push(binaryToHex(id) as NodeID))
|
|
85
|
+
this.config.ongoingInterleaves.forEach((id) => exclude.push(id))
|
|
73
86
|
exclude.push(getNodeIdFromPeerDescriptor(requester))
|
|
74
87
|
if (request.interleaveSourceId !== undefined) {
|
|
75
88
|
exclude.push(binaryToHex(request.interleaveSourceId) as NodeID)
|
|
@@ -77,10 +90,25 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
77
90
|
const furthest = this.config.targetNeighbors.getFurthest(exclude)
|
|
78
91
|
const furthestPeerDescriptor = furthest ? furthest.getPeerDescriptor() : undefined
|
|
79
92
|
if (furthest) {
|
|
93
|
+
const nodeId = getNodeIdFromPeerDescriptor(furthest.getPeerDescriptor())
|
|
80
94
|
const remote = this.config.createRpcRemote(furthest.getPeerDescriptor())
|
|
81
|
-
|
|
82
|
-
this
|
|
83
|
-
|
|
95
|
+
this.config.ongoingInterleaves.add(nodeId)
|
|
96
|
+
// Run this with then catch instead of setImmediate to avoid changes in state
|
|
97
|
+
// eslint-disable-next-line promise/catch-or-return
|
|
98
|
+
remote.interleaveRequest(requester).then((response) => {
|
|
99
|
+
// If response is accepted, remove the furthest node from the target neighbors
|
|
100
|
+
// and unlock the connection
|
|
101
|
+
// If response is not accepted, keep the furthest node as a neighbor
|
|
102
|
+
if (response.accepted) {
|
|
103
|
+
this.config.targetNeighbors.remove(furthest.getPeerDescriptor())
|
|
104
|
+
this.config.connectionLocker.unlockConnection(furthestPeerDescriptor!, this.config.streamPartId)
|
|
105
|
+
}
|
|
106
|
+
return
|
|
107
|
+
}).catch(() => {
|
|
108
|
+
// no-op: InterleaveRequest cannot reject
|
|
109
|
+
}).finally(() => {
|
|
110
|
+
this.config.ongoingInterleaves.delete(nodeId)
|
|
111
|
+
})
|
|
84
112
|
}
|
|
85
113
|
this.config.targetNeighbors.add(this.config.createDeliveryRpcRemote(requester))
|
|
86
114
|
this.config.connectionLocker.lockConnection(requester, this.config.streamPartId)
|
|
@@ -91,16 +119,19 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
91
119
|
}
|
|
92
120
|
}
|
|
93
121
|
|
|
94
|
-
async
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
122
|
+
async interleaveRequest(message: InterleaveRequest, context: ServerCallContext): Promise<InterleaveResponse> {
|
|
123
|
+
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
124
|
+
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
125
|
+
try {
|
|
126
|
+
await this.config.handshakeWithInterleaving(message.interleaveTargetDescriptor!, senderId)
|
|
98
127
|
if (this.config.targetNeighbors.hasNodeById(senderId)) {
|
|
99
128
|
this.config.connectionLocker.unlockConnection(senderPeerDescriptor, this.config.streamPartId)
|
|
100
129
|
this.config.targetNeighbors.remove(senderPeerDescriptor)
|
|
101
130
|
}
|
|
102
|
-
|
|
131
|
+
return { accepted: true }
|
|
132
|
+
} catch (err) {
|
|
133
|
+
logger.debug(`interleaveRequest to ${getNodeIdFromPeerDescriptor(message.interleaveTargetDescriptor!)} failed: ${err}`)
|
|
134
|
+
return { accepted: false }
|
|
103
135
|
}
|
|
104
|
-
return Empty
|
|
105
136
|
}
|
|
106
137
|
}
|
|
@@ -2,8 +2,8 @@ import { PeerDescriptor, RpcRemote } from '@streamr/dht'
|
|
|
2
2
|
import { Logger, hexToBinary } from '@streamr/utils'
|
|
3
3
|
import { v4 } from 'uuid'
|
|
4
4
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
5
|
+
import { InterleaveRequest, InterleaveResponse, StreamPartHandshakeRequest } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
|
+
import { HandshakeRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
7
7
|
|
|
8
8
|
const logger = new Logger(module)
|
|
9
9
|
|
|
@@ -12,7 +12,9 @@ interface HandshakeResponse {
|
|
|
12
12
|
interleaveTargetDescriptor?: PeerDescriptor
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export
|
|
15
|
+
export const INTERLEAVE_REQUEST_TIMEOUT = 15000
|
|
16
|
+
|
|
17
|
+
export class HandshakeRpcRemote extends RpcRemote<HandshakeRpcClient> {
|
|
16
18
|
|
|
17
19
|
async handshake(
|
|
18
20
|
neighborIds: NodeID[],
|
|
@@ -40,16 +42,25 @@ export class HandshakeRpcRemote extends RpcRemote<IHandshakeRpcClient> {
|
|
|
40
42
|
}
|
|
41
43
|
}
|
|
42
44
|
|
|
43
|
-
|
|
44
|
-
const
|
|
45
|
-
streamPartId: this.getServiceId(),
|
|
45
|
+
async interleaveRequest(originatorDescriptor: PeerDescriptor): Promise<InterleaveResponse> {
|
|
46
|
+
const request: InterleaveRequest = {
|
|
46
47
|
interleaveTargetDescriptor: originatorDescriptor
|
|
47
48
|
}
|
|
48
49
|
const options = this.formDhtRpcOptions({
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
this.getClient().interleaveNotice(notification, options).catch(() => {
|
|
52
|
-
logger.debug('Failed to send interleaveNotice')
|
|
50
|
+
connect: false,
|
|
51
|
+
timeout: INTERLEAVE_REQUEST_TIMEOUT
|
|
53
52
|
})
|
|
53
|
+
try {
|
|
54
|
+
const res = await this.getClient().interleaveRequest(request, options)
|
|
55
|
+
return {
|
|
56
|
+
accepted: res.accepted
|
|
57
|
+
}
|
|
58
|
+
} catch (err) {
|
|
59
|
+
logger.debug(`interleaveRequest to ${getNodeIdFromPeerDescriptor(this.getPeerDescriptor())} failed: ${err}`)
|
|
60
|
+
return {
|
|
61
|
+
accepted: false
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
54
65
|
}
|
|
55
66
|
}
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { ConnectionLocker, PeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { NodeList } from '../NodeList'
|
|
3
3
|
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
4
|
-
import {
|
|
4
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
5
5
|
import {
|
|
6
|
-
HandshakeRpcClient
|
|
7
|
-
IHandshakeRpcClient, DeliveryRpcClient
|
|
6
|
+
DeliveryRpcClient, HandshakeRpcClient
|
|
8
7
|
} from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
9
8
|
import {
|
|
10
|
-
|
|
9
|
+
InterleaveRequest,
|
|
10
|
+
InterleaveResponse,
|
|
11
11
|
StreamPartHandshakeRequest,
|
|
12
12
|
StreamPartHandshakeResponse
|
|
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 { HandshakeRpcRemote } from './HandshakeRpcRemote'
|
|
16
|
+
import { HandshakeRpcRemote, INTERLEAVE_REQUEST_TIMEOUT } from './HandshakeRpcRemote'
|
|
17
17
|
import { HandshakeRpcLocal } from './HandshakeRpcLocal'
|
|
18
18
|
import { NodeID, getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
19
19
|
import { StreamPartID } from '@streamr/protocol'
|
|
@@ -34,38 +34,33 @@ const logger = new Logger(module)
|
|
|
34
34
|
|
|
35
35
|
const PARALLEL_HANDSHAKE_COUNT = 2
|
|
36
36
|
|
|
37
|
-
export
|
|
38
|
-
attemptHandshakesOnContacts(excludedIds: NodeID[]): Promise<NodeID[]>
|
|
39
|
-
getOngoingHandshakes(): Set<NodeID>
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export class Handshaker implements IHandshaker {
|
|
37
|
+
export class Handshaker {
|
|
43
38
|
|
|
44
39
|
private readonly ongoingHandshakes: Set<NodeID> = new Set()
|
|
45
40
|
private config: HandshakerConfig
|
|
46
|
-
private readonly client: ProtoRpcClient<IHandshakeRpcClient>
|
|
47
41
|
private readonly rpcLocal: IHandshakeRpc
|
|
48
42
|
|
|
49
43
|
constructor(config: HandshakerConfig) {
|
|
50
44
|
this.config = config
|
|
51
|
-
this.client = toProtoRpcClient(new HandshakeRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
52
45
|
this.rpcLocal = new HandshakeRpcLocal({
|
|
53
46
|
streamPartId: this.config.streamPartId,
|
|
54
47
|
targetNeighbors: this.config.targetNeighbors,
|
|
55
48
|
connectionLocker: this.config.connectionLocker,
|
|
56
49
|
ongoingHandshakes: this.ongoingHandshakes,
|
|
50
|
+
ongoingInterleaves: new Set(),
|
|
57
51
|
maxNeighborCount: this.config.maxNeighborCount,
|
|
58
52
|
handshakeWithInterleaving: (target: PeerDescriptor, senderId: NodeID) => this.handshakeWithInterleaving(target, senderId),
|
|
59
53
|
createRpcRemote: (target: PeerDescriptor) => this.createRpcRemote(target),
|
|
60
54
|
createDeliveryRpcRemote: (target: PeerDescriptor) => this.createDeliveryRpcRemote(target)
|
|
61
55
|
})
|
|
62
|
-
this.config.rpcCommunicator.
|
|
63
|
-
(req:
|
|
56
|
+
this.config.rpcCommunicator.registerRpcMethod(InterleaveRequest, InterleaveResponse, 'interleaveRequest',
|
|
57
|
+
(req: InterleaveRequest, context) => this.rpcLocal.interleaveRequest(req, context), { timeout: INTERLEAVE_REQUEST_TIMEOUT })
|
|
64
58
|
this.config.rpcCommunicator.registerRpcMethod(StreamPartHandshakeRequest, StreamPartHandshakeResponse, 'handshake',
|
|
65
59
|
(req: StreamPartHandshakeRequest, context) => this.rpcLocal.handshake(req, context))
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
async attemptHandshakesOnContacts(excludedIds: NodeID[]): Promise<NodeID[]> {
|
|
63
|
+
// TODO use config option or named constant? or why the value 2?
|
|
69
64
|
if (this.config.targetNeighbors.size() + this.ongoingHandshakes.size < this.config.maxNeighborCount - 2) {
|
|
70
65
|
logger.trace(`Attempting parallel handshakes with ${PARALLEL_HANDSHAKE_COUNT} targets`)
|
|
71
66
|
return this.selectParallelTargetsAndHandshake(excludedIds)
|
|
@@ -142,13 +137,7 @@ export class Handshaker implements IHandshaker {
|
|
|
142
137
|
}
|
|
143
138
|
|
|
144
139
|
private async handshakeWithInterleaving(target: PeerDescriptor, interleaveSourceId: NodeID): Promise<boolean> {
|
|
145
|
-
const targetNeighbor =
|
|
146
|
-
this.config.localPeerDescriptor,
|
|
147
|
-
target,
|
|
148
|
-
this.config.streamPartId,
|
|
149
|
-
this.client,
|
|
150
|
-
this.config.rpcRequestTimeout
|
|
151
|
-
)
|
|
140
|
+
const targetNeighbor = this.createRpcRemote(target)
|
|
152
141
|
const targetNodeId = getNodeIdFromPeerDescriptor(targetNeighbor.getPeerDescriptor())
|
|
153
142
|
this.ongoingHandshakes.add(targetNodeId)
|
|
154
143
|
const result = await targetNeighbor.handshake(
|
|
@@ -169,7 +158,8 @@ export class Handshaker implements IHandshaker {
|
|
|
169
158
|
this.config.localPeerDescriptor,
|
|
170
159
|
targetPeerDescriptor,
|
|
171
160
|
this.config.streamPartId,
|
|
172
|
-
this.
|
|
161
|
+
this.config.rpcCommunicator,
|
|
162
|
+
HandshakeRpcClient,
|
|
173
163
|
this.config.rpcRequestTimeout
|
|
174
164
|
)
|
|
175
165
|
}
|
|
@@ -179,7 +169,8 @@ export class Handshaker implements IHandshaker {
|
|
|
179
169
|
this.config.localPeerDescriptor,
|
|
180
170
|
targetPeerDescriptor,
|
|
181
171
|
this.config.streamPartId,
|
|
182
|
-
|
|
172
|
+
this.config.rpcCommunicator,
|
|
173
|
+
DeliveryRpcClient,
|
|
183
174
|
this.config.rpcRequestTimeout
|
|
184
175
|
)
|
|
185
176
|
}
|
|
@@ -12,13 +12,7 @@ interface FindNeighborsSessionConfig {
|
|
|
12
12
|
const INITIAL_WAIT = 100
|
|
13
13
|
const INTERVAL = 250
|
|
14
14
|
|
|
15
|
-
export
|
|
16
|
-
start(excluded?: NodeID[]): void
|
|
17
|
-
stop(): void
|
|
18
|
-
isRunning(): boolean
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export class NeighborFinder implements INeighborFinder {
|
|
15
|
+
export class NeighborFinder {
|
|
22
16
|
private readonly abortController: AbortController
|
|
23
17
|
private readonly config: FindNeighborsSessionConfig
|
|
24
18
|
private running = false
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
2
2
|
import { ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
3
|
-
import { ProtoRpcClient, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
4
3
|
import { NeighborUpdateRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
4
|
import { Logger, scheduleAtInterval } from '@streamr/utils'
|
|
6
|
-
import {
|
|
5
|
+
import { NeighborFinder } from './NeighborFinder'
|
|
7
6
|
import { NodeList } from '../NodeList'
|
|
8
7
|
import { NeighborUpdateRpcRemote } from './NeighborUpdateRpcRemote'
|
|
9
8
|
import { NeighborUpdateRpcLocal } from './NeighborUpdateRpcLocal'
|
|
@@ -14,7 +13,7 @@ interface NeighborUpdateManagerConfig {
|
|
|
14
13
|
localPeerDescriptor: PeerDescriptor
|
|
15
14
|
targetNeighbors: NodeList
|
|
16
15
|
nearbyNodeView: NodeList
|
|
17
|
-
neighborFinder:
|
|
16
|
+
neighborFinder: NeighborFinder
|
|
18
17
|
streamPartId: StreamPartID
|
|
19
18
|
rpcCommunicator: ListeningRpcCommunicator
|
|
20
19
|
neighborUpdateInterval: number
|
|
@@ -22,21 +21,14 @@ interface NeighborUpdateManagerConfig {
|
|
|
22
21
|
|
|
23
22
|
const logger = new Logger(module)
|
|
24
23
|
|
|
25
|
-
export
|
|
26
|
-
start(): Promise<void>
|
|
27
|
-
stop(): void
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class NeighborUpdateManager implements INeighborUpdateManager {
|
|
24
|
+
export class NeighborUpdateManager {
|
|
31
25
|
|
|
32
26
|
private readonly abortController: AbortController
|
|
33
27
|
private readonly config: NeighborUpdateManagerConfig
|
|
34
|
-
private readonly client: ProtoRpcClient<NeighborUpdateRpcClient>
|
|
35
28
|
private readonly rpcLocal: NeighborUpdateRpcLocal
|
|
36
29
|
|
|
37
30
|
constructor(config: NeighborUpdateManagerConfig) {
|
|
38
31
|
this.abortController = new AbortController()
|
|
39
|
-
this.client = toProtoRpcClient(new NeighborUpdateRpcClient(config.rpcCommunicator.getRpcClientTransport()))
|
|
40
32
|
this.rpcLocal = new NeighborUpdateRpcLocal(config)
|
|
41
33
|
this.config = config
|
|
42
34
|
this.config.rpcCommunicator.registerRpcMethod(NeighborUpdate, NeighborUpdate, 'neighborUpdate',
|
|
@@ -64,6 +56,12 @@ export class NeighborUpdateManager implements INeighborUpdateManager {
|
|
|
64
56
|
}
|
|
65
57
|
|
|
66
58
|
private createRemote(targetPeerDescriptor: PeerDescriptor): NeighborUpdateRpcRemote {
|
|
67
|
-
return new NeighborUpdateRpcRemote(
|
|
59
|
+
return new NeighborUpdateRpcRemote(
|
|
60
|
+
this.config.localPeerDescriptor,
|
|
61
|
+
targetPeerDescriptor,
|
|
62
|
+
this.config.streamPartId,
|
|
63
|
+
this.config.rpcCommunicator,
|
|
64
|
+
NeighborUpdateRpcClient
|
|
65
|
+
)
|
|
68
66
|
}
|
|
69
67
|
}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
2
|
import { DhtCallContext, ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
3
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
4
3
|
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
5
4
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
5
|
import { DeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
7
6
|
import { INeighborUpdateRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
8
7
|
import { NodeList } from '../NodeList'
|
|
9
8
|
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
10
|
-
import {
|
|
9
|
+
import { NeighborFinder } from './NeighborFinder'
|
|
11
10
|
import { StreamPartID } from '@streamr/protocol'
|
|
12
11
|
|
|
13
12
|
interface NeighborUpdateRpcLocalConfig {
|
|
@@ -15,7 +14,7 @@ interface NeighborUpdateRpcLocalConfig {
|
|
|
15
14
|
streamPartId: StreamPartID
|
|
16
15
|
targetNeighbors: NodeList
|
|
17
16
|
nearbyNodeView: NodeList
|
|
18
|
-
neighborFinder:
|
|
17
|
+
neighborFinder: NeighborFinder
|
|
19
18
|
rpcCommunicator: ListeningRpcCommunicator
|
|
20
19
|
}
|
|
21
20
|
|
|
@@ -43,7 +42,8 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
43
42
|
this.config.localPeerDescriptor,
|
|
44
43
|
peerDescriptor,
|
|
45
44
|
this.config.streamPartId,
|
|
46
|
-
|
|
45
|
+
this.config.rpcCommunicator,
|
|
46
|
+
DeliveryRpcClient
|
|
47
47
|
))
|
|
48
48
|
)
|
|
49
49
|
this.config.neighborFinder.start()
|
|
@@ -2,7 +2,7 @@ import { PeerDescriptor, RpcRemote } from '@streamr/dht'
|
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
4
4
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
-
import {
|
|
5
|
+
import { NeighborUpdateRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
6
6
|
|
|
7
7
|
const logger = new Logger(module)
|
|
8
8
|
|
|
@@ -11,7 +11,7 @@ interface UpdateNeighborsResponse {
|
|
|
11
11
|
removeMe: boolean
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export class NeighborUpdateRpcRemote extends RpcRemote<
|
|
14
|
+
export class NeighborUpdateRpcRemote extends RpcRemote<NeighborUpdateRpcClient> {
|
|
15
15
|
|
|
16
16
|
async updateNeighbors(neighbors: PeerDescriptor[]): Promise<UpdateNeighborsResponse> {
|
|
17
17
|
const request: NeighborUpdate = {
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
ListeningRpcCommunicator,
|
|
5
5
|
PeerDescriptor
|
|
6
6
|
} from '@streamr/dht'
|
|
7
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
8
7
|
import { StreamPartID } from '@streamr/protocol'
|
|
9
8
|
import { EthereumAddress, Logger, addManagedEventListener, wait } from '@streamr/utils'
|
|
10
9
|
import { EventEmitter } from 'eventemitter3'
|
|
@@ -27,6 +26,7 @@ import { markAndCheckDuplicate } from '../utils'
|
|
|
27
26
|
import { ProxyConnectionRpcRemote } from './ProxyConnectionRpcRemote'
|
|
28
27
|
import { formStreamPartDeliveryServiceId } from '../formStreamPartDeliveryServiceId'
|
|
29
28
|
|
|
29
|
+
// TODO use config option or named constant?
|
|
30
30
|
export const retry = async <T>(task: () => Promise<T>, description: string, abortSignal: AbortSignal, delay = 10000): Promise<T> => {
|
|
31
31
|
// eslint-disable-next-line no-constant-condition
|
|
32
32
|
while (true) {
|
|
@@ -57,11 +57,15 @@ interface ProxyDefinition {
|
|
|
57
57
|
userId: EthereumAddress
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
interface Events {
|
|
61
|
+
message: (message: StreamMessage) => void
|
|
62
|
+
}
|
|
63
|
+
|
|
60
64
|
const logger = new Logger(module)
|
|
61
65
|
|
|
62
66
|
const SERVICE_ID = 'system/proxy-client'
|
|
63
67
|
|
|
64
|
-
export class ProxyClient extends EventEmitter {
|
|
68
|
+
export class ProxyClient extends EventEmitter<Events> {
|
|
65
69
|
|
|
66
70
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
67
71
|
private readonly deliveryRpcLocal: DeliveryRpcLocal
|
|
@@ -77,6 +81,7 @@ export class ProxyClient extends EventEmitter {
|
|
|
77
81
|
super()
|
|
78
82
|
this.config = config
|
|
79
83
|
this.rpcCommunicator = new ListeningRpcCommunicator(formStreamPartDeliveryServiceId(config.streamPartId), config.transport)
|
|
84
|
+
// TODO use config option or named constant?
|
|
80
85
|
this.targetNeighbors = new NodeList(getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor), 1000)
|
|
81
86
|
this.deliveryRpcLocal = new DeliveryRpcLocal({
|
|
82
87
|
localPeerDescriptor: this.config.localPeerDescriptor,
|
|
@@ -94,6 +99,7 @@ export class ProxyClient extends EventEmitter {
|
|
|
94
99
|
markForInspection: () => {}
|
|
95
100
|
})
|
|
96
101
|
this.propagation = new Propagation({
|
|
102
|
+
// TODO use config option or named constant?
|
|
97
103
|
minPropagationTargets: config.minPropagationTargets ?? 2,
|
|
98
104
|
sendToNeighbor: async (neighborId: NodeID, msg: StreamMessage): Promise<void> => {
|
|
99
105
|
const remote = this.targetNeighbors.get(neighborId)
|
|
@@ -167,8 +173,13 @@ export class ProxyClient extends EventEmitter {
|
|
|
167
173
|
|
|
168
174
|
private async attemptConnection(nodeId: NodeID, direction: ProxyDirection, userId: EthereumAddress): Promise<void> {
|
|
169
175
|
const peerDescriptor = this.definition!.nodes.get(nodeId)!
|
|
170
|
-
const
|
|
171
|
-
|
|
176
|
+
const rpcRemote = new ProxyConnectionRpcRemote(
|
|
177
|
+
this.config.localPeerDescriptor,
|
|
178
|
+
peerDescriptor,
|
|
179
|
+
this.config.streamPartId,
|
|
180
|
+
this.rpcCommunicator,
|
|
181
|
+
ProxyConnectionRpcClient
|
|
182
|
+
)
|
|
172
183
|
const accepted = await rpcRemote.requestConnection(direction, userId)
|
|
173
184
|
if (accepted) {
|
|
174
185
|
this.config.connectionLocker.lockConnection(peerDescriptor, SERVICE_ID)
|
|
@@ -177,7 +188,8 @@ export class ProxyClient extends EventEmitter {
|
|
|
177
188
|
this.config.localPeerDescriptor,
|
|
178
189
|
peerDescriptor,
|
|
179
190
|
this.config.streamPartId,
|
|
180
|
-
|
|
191
|
+
this.rpcCommunicator,
|
|
192
|
+
DeliveryRpcClient
|
|
181
193
|
)
|
|
182
194
|
this.targetNeighbors.add(remote)
|
|
183
195
|
this.propagation.onNeighborJoined(nodeId)
|
|
@@ -204,7 +216,7 @@ export class ProxyClient extends EventEmitter {
|
|
|
204
216
|
nodeId
|
|
205
217
|
})
|
|
206
218
|
const server = this.targetNeighbors.get(nodeId)
|
|
207
|
-
server?.leaveStreamPartNotice()
|
|
219
|
+
server?.leaveStreamPartNotice(false)
|
|
208
220
|
this.removeConnection(nodeId)
|
|
209
221
|
}
|
|
210
222
|
}
|
|
@@ -253,7 +265,7 @@ export class ProxyClient extends EventEmitter {
|
|
|
253
265
|
stop(): void {
|
|
254
266
|
this.targetNeighbors.getAll().map((remote) => {
|
|
255
267
|
this.config.connectionLocker.unlockConnection(remote.getPeerDescriptor(), SERVICE_ID)
|
|
256
|
-
remote.leaveStreamPartNotice()
|
|
268
|
+
remote.leaveStreamPartNotice(false)
|
|
257
269
|
})
|
|
258
270
|
this.targetNeighbors.stop()
|
|
259
271
|
this.rpcCommunicator.destroy()
|
|
@@ -10,7 +10,6 @@ import {
|
|
|
10
10
|
import { IProxyConnectionRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
11
11
|
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
12
12
|
import { DhtCallContext, ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
13
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
14
13
|
import { DeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
15
14
|
import { EventEmitter } from 'eventemitter3'
|
|
16
15
|
import { EthereumAddress, Logger, binaryToHex, toEthereumAddress } from '@streamr/utils'
|
|
@@ -60,7 +59,7 @@ export class ProxyConnectionRpcLocal extends EventEmitter<Events> implements IPr
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
stop(): void {
|
|
63
|
-
this.connections.forEach((connection) => connection.remote.leaveStreamPartNotice())
|
|
62
|
+
this.connections.forEach((connection) => connection.remote.leaveStreamPartNotice(false))
|
|
64
63
|
this.connections.clear()
|
|
65
64
|
this.removeAllListeners()
|
|
66
65
|
}
|
|
@@ -98,7 +97,8 @@ export class ProxyConnectionRpcLocal extends EventEmitter<Events> implements IPr
|
|
|
98
97
|
this.config.localPeerDescriptor,
|
|
99
98
|
senderPeerDescriptor,
|
|
100
99
|
this.config.streamPartId,
|
|
101
|
-
|
|
100
|
+
this.config.rpcCommunicator,
|
|
101
|
+
DeliveryRpcClient
|
|
102
102
|
)
|
|
103
103
|
})
|
|
104
104
|
const response: ProxyConnectionResponse = {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { EXISTING_CONNECTION_TIMEOUT, RpcRemote } from '@streamr/dht'
|
|
2
2
|
import { EthereumAddress, Logger, hexToBinary } from '@streamr/utils'
|
|
3
3
|
import { ProxyConnectionRequest, ProxyDirection } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
4
|
-
import {
|
|
4
|
+
import { ProxyConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
|
|
6
6
|
const logger = new Logger(module)
|
|
7
7
|
|
|
8
|
-
export class ProxyConnectionRpcRemote extends RpcRemote<
|
|
8
|
+
export class ProxyConnectionRpcRemote extends RpcRemote<ProxyConnectionRpcClient> {
|
|
9
9
|
|
|
10
10
|
async requestConnection(direction: ProxyDirection, userId: EthereumAddress): Promise<boolean> {
|
|
11
11
|
const request: ProxyConnectionRequest = {
|
|
@@ -4,7 +4,6 @@ import { ITemporaryConnectionRpc } from '../../proto/packages/trackerless-networ
|
|
|
4
4
|
import { DhtCallContext, ListeningRpcCommunicator } from '@streamr/dht'
|
|
5
5
|
import { DeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
6
6
|
import { NodeList } from '../NodeList'
|
|
7
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
8
7
|
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
9
8
|
import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
|
|
10
9
|
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
@@ -23,6 +22,7 @@ export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
|
23
22
|
|
|
24
23
|
constructor(config: TemporaryConnectionRpcLocalConfig) {
|
|
25
24
|
this.config = config
|
|
25
|
+
// TODO use config option or named constant?
|
|
26
26
|
this.temporaryNodes = new NodeList(getNodeIdFromPeerDescriptor(config.localPeerDescriptor), 10)
|
|
27
27
|
}
|
|
28
28
|
|
|
@@ -43,7 +43,8 @@ export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
|
43
43
|
this.config.localPeerDescriptor,
|
|
44
44
|
sender,
|
|
45
45
|
this.config.streamPartId,
|
|
46
|
-
|
|
46
|
+
this.config.rpcCommunicator,
|
|
47
|
+
DeliveryRpcClient
|
|
47
48
|
)
|
|
48
49
|
this.temporaryNodes.add(remote)
|
|
49
50
|
return {
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { RpcRemote } from '@streamr/dht'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
3
|
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
4
|
-
import {
|
|
4
|
+
import { TemporaryConnectionRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
|
|
6
6
|
const logger = new Logger(module)
|
|
7
7
|
|
|
8
|
-
export class TemporaryConnectionRpcRemote extends RpcRemote<
|
|
8
|
+
export class TemporaryConnectionRpcRemote extends RpcRemote<TemporaryConnectionRpcClient> {
|
|
9
9
|
|
|
10
10
|
async openConnection(): Promise<boolean> {
|
|
11
11
|
try {
|