@streamr/trackerless-network 101.1.2 → 102.0.0-beta.1
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/{src/proto → generated}/google/protobuf/any.d.ts +11 -4
- package/dist/generated/google/protobuf/any.js.map +1 -0
- package/dist/{src/proto → generated}/google/protobuf/empty.d.ts +0 -1
- package/dist/generated/google/protobuf/empty.js.map +1 -0
- package/dist/{src/proto → generated}/google/protobuf/timestamp.d.ts +9 -3
- package/dist/generated/google/protobuf/timestamp.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.d.ts +9 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.client.js +7 -0
- package/dist/generated/packages/dht/protos/DhtRpc.client.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.d.ts +32 -8
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.js +23 -7
- package/dist/generated/packages/dht/protos/DhtRpc.js.map +1 -0
- package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.d.ts +5 -0
- package/dist/generated/packages/dht/protos/DhtRpc.server.js.map +1 -0
- package/dist/generated/packages/proto-rpc/protos/ProtoRpc.js.map +1 -0
- package/dist/generated/packages/trackerless-network/protos/NetworkRpc.client.js.map +1 -0
- package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.d.ts +29 -5
- package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.js +17 -3
- package/dist/generated/packages/trackerless-network/protos/NetworkRpc.js.map +1 -0
- package/dist/generated/packages/trackerless-network/protos/NetworkRpc.server.js.map +1 -0
- package/dist/package.json +10 -11
- package/dist/src/NetworkNode.d.ts +8 -7
- package/dist/src/NetworkNode.js +5 -3
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +2 -2
- package/dist/src/NetworkStack.js +7 -6
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +3 -2
- package/dist/src/exports.js +3 -2
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/ContentDeliveryLayerNode.d.ts +5 -1
- package/dist/src/logic/ContentDeliveryLayerNode.js +30 -10
- package/dist/src/logic/ContentDeliveryLayerNode.js.map +1 -1
- package/dist/src/logic/ContentDeliveryManager.d.ts +8 -3
- package/dist/src/logic/ContentDeliveryManager.js +28 -7
- package/dist/src/logic/ContentDeliveryManager.js.map +1 -1
- package/dist/src/logic/ContentDeliveryRpcLocal.d.ts +3 -3
- package/dist/src/logic/ContentDeliveryRpcLocal.js +3 -3
- package/dist/src/logic/ContentDeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/ContentDeliveryRpcRemote.d.ts +5 -2
- package/dist/src/logic/ContentDeliveryRpcRemote.js +7 -0
- package/dist/src/logic/ContentDeliveryRpcRemote.js.map +1 -1
- package/dist/src/logic/ControlLayerNode.d.ts +1 -1
- package/dist/src/logic/DiscoveryLayerNode.d.ts +3 -3
- package/dist/src/logic/DuplicateMessageDetector.js +3 -3
- package/dist/src/logic/DuplicateMessageDetector.js.map +1 -1
- package/dist/src/logic/ExternalNetworkRpc.js.map +1 -1
- package/dist/src/logic/NodeList.js +2 -2
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/PeerDescriptorStoreManager.d.ts +1 -1
- package/dist/src/logic/PeerDescriptorStoreManager.js +1 -2
- package/dist/src/logic/PeerDescriptorStoreManager.js.map +1 -1
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.js +4 -3
- package/dist/src/logic/StreamPartNetworkSplitAvoidance.js.map +1 -1
- package/dist/src/logic/createContentDeliveryLayerNode.js +1 -1
- package/dist/src/logic/createContentDeliveryLayerNode.js.map +1 -1
- package/dist/src/logic/inspect/InspectSession.d.ts +2 -2
- package/dist/src/logic/inspect/InspectSession.js +2 -2
- package/dist/src/logic/inspect/InspectSession.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +1 -1
- package/dist/src/logic/inspect/Inspector.js +4 -4
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +9 -9
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +2 -2
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +5 -5
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.js +14 -14
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +5 -0
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +5 -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 +4 -4
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.d.ts +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.d.ts +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.js +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcLocal.d.ts +2 -2
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoRpcRemote.d.ts +2 -2
- package/dist/src/logic/propagation/Propagation.d.ts +1 -1
- package/dist/src/logic/propagation/Propagation.js +0 -1
- package/dist/src/logic/propagation/Propagation.js.map +1 -1
- package/dist/src/logic/propagation/PropagationTaskStore.d.ts +1 -1
- package/dist/src/logic/proxy/ProxyClient.d.ts +4 -4
- package/dist/src/logic/proxy/ProxyClient.js +11 -7
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +4 -4
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +5 -5
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.d.ts +4 -4
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.d.ts +4 -4
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +4 -4
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +2 -2
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/utils.d.ts +1 -1
- package/dist/src/logic/utils.js +2 -2
- package/dist/src/logic/utils.js.map +1 -1
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.js +3 -0
- package/dist/src/types.js.map +1 -0
- package/dist/test/benchmark/first-message.js +3 -4
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +4 -4
- package/dist/test/utils/utils.js +6 -5
- package/dist/test/utils/utils.js.map +1 -1
- package/jest.config.ts +13 -0
- package/karma-setup.js +7 -0
- package/karma.config.js +1 -1
- package/package.json +10 -11
- package/proto.sh +2 -2
- package/protos/NetworkRpc.proto +9 -4
- package/src/NetworkNode.ts +12 -9
- package/src/NetworkStack.ts +10 -10
- package/src/exports.ts +5 -3
- package/src/logic/ContentDeliveryLayerNode.ts +35 -11
- package/src/logic/ContentDeliveryManager.ts +41 -13
- package/src/logic/ContentDeliveryRpcLocal.ts +6 -6
- package/src/logic/ContentDeliveryRpcRemote.ts +12 -2
- package/src/logic/ControlLayerNode.ts +1 -1
- package/src/logic/DiscoveryLayerNode.ts +3 -3
- package/src/logic/DuplicateMessageDetector.ts +4 -4
- package/src/logic/ExternalNetworkRpc.ts +0 -1
- package/src/logic/NodeList.ts +4 -3
- package/src/logic/PeerDescriptorStoreManager.ts +1 -2
- package/src/logic/StreamPartNetworkSplitAvoidance.ts +5 -4
- package/src/logic/createContentDeliveryLayerNode.ts +3 -3
- package/src/logic/inspect/InspectSession.ts +5 -4
- package/src/logic/inspect/Inspector.ts +6 -6
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +13 -13
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +8 -8
- package/src/logic/neighbor-discovery/Handshaker.ts +15 -15
- package/src/logic/neighbor-discovery/NeighborFinder.ts +6 -1
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +6 -4
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +7 -7
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +4 -4
- package/src/logic/node-info/NodeInfoClient.ts +2 -2
- package/src/logic/node-info/NodeInfoRpcLocal.ts +2 -2
- package/src/logic/node-info/NodeInfoRpcRemote.ts +2 -2
- package/src/logic/propagation/Propagation.ts +1 -2
- package/src/logic/propagation/PropagationTaskStore.ts +1 -1
- package/src/logic/proxy/ProxyClient.ts +17 -12
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +10 -10
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +5 -5
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +9 -9
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +4 -4
- package/src/logic/utils.ts +4 -4
- package/src/types.ts +13 -0
- package/test/benchmark/first-message.ts +6 -5
- package/test/end-to-end/content-delivery-layer-node-with-real-connections.test.ts +11 -6
- package/test/end-to-end/external-network-rpc.test.ts +2 -2
- package/test/end-to-end/inspect.test.ts +5 -5
- package/test/end-to-end/proxy-and-full-node.test.ts +6 -6
- package/test/end-to-end/proxy-connections.test.ts +12 -14
- package/test/end-to-end/proxy-key-exchange.test.ts +11 -9
- package/test/end-to-end/webrtc-full-node-network.test.ts +7 -9
- package/test/end-to-end/websocket-full-node-network.test.ts +8 -10
- package/test/integration/ContentDeliveryLayerNode-Layer1Node-Latencies.test.ts +11 -11
- package/test/integration/ContentDeliveryLayerNode-Layer1Node.test.ts +10 -10
- package/test/integration/ContentDeliveryManager.test.ts +49 -25
- package/test/integration/ContentDeliveryRpcRemote.test.ts +8 -8
- package/test/integration/HandshakeRpcRemote.test.ts +2 -2
- package/test/integration/Handshakes.test.ts +21 -56
- package/test/integration/Inspect.test.ts +2 -2
- package/test/integration/NeighborUpdateRpcRemote.test.ts +2 -2
- package/test/integration/NetworkNode.test.ts +5 -4
- package/test/integration/NetworkRpc.test.ts +10 -10
- package/test/integration/NetworkStack.test.ts +4 -4
- package/test/integration/NodeInfoRpc.test.ts +9 -5
- package/test/integration/Propagation.test.ts +6 -6
- package/test/integration/joining-streams-on-offline-peers.test.ts +5 -5
- package/test/integration/stream-without-default-entrypoints.test.ts +8 -7
- package/test/integration/streamEntryPointReplacing.test.ts +5 -5
- package/test/types/global.d.ts +1 -0
- package/test/unit/ContentDeliveryLayerNode.test.ts +26 -14
- package/test/unit/ContentDeliveryManager.test.ts +10 -9
- package/test/unit/ContentDeliveryRpcLocal.test.ts +3 -3
- package/test/unit/DuplicateMessageDetector.test.ts +10 -10
- package/test/unit/ExternalNetworkRpc.test.ts +3 -3
- package/test/unit/HandshakeRpcLocal.test.ts +8 -21
- package/test/unit/Handshaker.test.ts +2 -2
- package/test/unit/InspectSession.test.ts +7 -4
- package/test/unit/Inspector.test.ts +5 -5
- package/test/unit/NeighborFinder.test.ts +5 -5
- package/test/unit/NeighborUpdateRpcLocal.test.ts +6 -6
- package/test/unit/NetworkNode.test.ts +5 -5
- package/test/unit/NodeList.test.ts +23 -23
- package/test/unit/PeerDescriptorStoreManager.test.ts +4 -4
- package/test/unit/Propagation.test.ts +8 -7
- package/test/unit/ProxyConnectionRpcRemote.test.ts +5 -5
- package/test/unit/StreamPartReconnect.test.ts +2 -2
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +3 -3
- package/test/utils/mock/MockControlLayerNode.ts +5 -0
- package/test/utils/mock/MockNeighborUpdateManager.ts +1 -1
- package/test/utils/mock/MockTransport.ts +11 -0
- package/test/utils/utils.ts +10 -9
- package/tsconfig.browser.json +1 -0
- package/tsconfig.jest.json +2 -1
- package/tsconfig.json +3 -0
- package/tsconfig.node.json +1 -0
- package/.eslintignore +0 -7
- package/.eslintrc +0 -3
- package/dist/src/proto/google/protobuf/any.js.map +0 -1
- package/dist/src/proto/google/protobuf/empty.js.map +0 -1
- package/dist/src/proto/google/protobuf/timestamp.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +0 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.js.map +0 -1
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js.map +0 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js.map +0 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js.map +0 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.server.js.map +0 -1
- package/jest.config.js +0 -5
- package/src/proto/google/protobuf/any.ts +0 -319
- package/src/proto/google/protobuf/empty.ts +0 -82
- package/src/proto/google/protobuf/timestamp.ts +0 -281
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +0 -407
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +0 -160
- package/src/proto/packages/dht/protos/DhtRpc.ts +0 -1244
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +0 -108
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +0 -218
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +0 -85
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +0 -752
- /package/dist/{src/proto → generated}/google/protobuf/any.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/empty.js +0 -0
- /package/dist/{src/proto → generated}/google/protobuf/timestamp.js +0 -0
- /package/dist/{src/proto → generated}/packages/dht/protos/DhtRpc.server.js +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/proto-rpc/protos/ProtoRpc.js +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.client.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.client.js +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.server.d.ts +0 -0
- /package/dist/{src/proto → generated}/packages/trackerless-network/protos/NetworkRpc.server.js +0 -0
|
@@ -4,8 +4,8 @@ import {
|
|
|
4
4
|
DhtAddressRaw,
|
|
5
5
|
DhtCallContext,
|
|
6
6
|
PeerDescriptor,
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
toDhtAddress,
|
|
8
|
+
toNodeId
|
|
9
9
|
} from '@streamr/dht'
|
|
10
10
|
import { Logger, StreamPartID } from '@streamr/utils'
|
|
11
11
|
import {
|
|
@@ -13,8 +13,8 @@ import {
|
|
|
13
13
|
InterleaveResponse,
|
|
14
14
|
StreamPartHandshakeRequest,
|
|
15
15
|
StreamPartHandshakeResponse
|
|
16
|
-
} from '
|
|
17
|
-
import { IHandshakeRpc } from '
|
|
16
|
+
} from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
17
|
+
import { IHandshakeRpc } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.server'
|
|
18
18
|
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
19
19
|
import { NodeList } from '../NodeList'
|
|
20
20
|
import { HandshakeRpcRemote } from './HandshakeRpcRemote'
|
|
@@ -46,8 +46,8 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
46
46
|
|
|
47
47
|
private handleRequest(request: StreamPartHandshakeRequest, context: ServerCallContext): StreamPartHandshakeResponse {
|
|
48
48
|
const senderDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
49
|
-
const getInterleaveNodeIds = () => (request.interleaveNodeId !== undefined) ? [
|
|
50
|
-
const senderNodeId =
|
|
49
|
+
const getInterleaveNodeIds = () => (request.interleaveNodeId !== undefined) ? [toDhtAddress(request.interleaveNodeId)] : []
|
|
50
|
+
const senderNodeId = toNodeId(senderDescriptor)
|
|
51
51
|
if (this.options.ongoingInterleaves.has(senderNodeId)) {
|
|
52
52
|
return this.rejectHandshake(request)
|
|
53
53
|
} else if (this.options.neighbors.has(senderNodeId)
|
|
@@ -88,16 +88,16 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
88
88
|
|
|
89
89
|
private acceptHandshakeWithInterleaving(request: StreamPartHandshakeRequest, requester: PeerDescriptor): StreamPartHandshakeResponse {
|
|
90
90
|
const exclude: DhtAddress[] = []
|
|
91
|
-
request.neighborNodeIds.forEach((id: DhtAddressRaw) => exclude.push(
|
|
91
|
+
request.neighborNodeIds.forEach((id: DhtAddressRaw) => exclude.push(toDhtAddress(id)))
|
|
92
92
|
this.options.ongoingInterleaves.forEach((id) => exclude.push(id))
|
|
93
|
-
exclude.push(
|
|
93
|
+
exclude.push(toNodeId(requester))
|
|
94
94
|
if (request.interleaveNodeId !== undefined) {
|
|
95
|
-
exclude.push(
|
|
95
|
+
exclude.push(toDhtAddress(request.interleaveNodeId))
|
|
96
96
|
}
|
|
97
97
|
const last = this.options.neighbors.getLast(exclude)
|
|
98
98
|
const lastPeerDescriptor = last ? last.getPeerDescriptor() : undefined
|
|
99
99
|
if (last) {
|
|
100
|
-
const nodeId =
|
|
100
|
+
const nodeId = toNodeId(last.getPeerDescriptor())
|
|
101
101
|
const remote = this.options.createRpcRemote(last.getPeerDescriptor())
|
|
102
102
|
this.options.ongoingInterleaves.add(nodeId)
|
|
103
103
|
// Run this with then catch instead of setImmediate to avoid changes in state
|
|
@@ -107,7 +107,7 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
107
107
|
// and unlock the connection
|
|
108
108
|
// If response is not accepted, keep the last node as a neighbor
|
|
109
109
|
if (response.accepted) {
|
|
110
|
-
this.options.neighbors.remove(
|
|
110
|
+
this.options.neighbors.remove(toNodeId(lastPeerDescriptor!))
|
|
111
111
|
}
|
|
112
112
|
}).catch(() => {
|
|
113
113
|
// no-op: InterleaveRequest cannot reject
|
|
@@ -125,13 +125,13 @@ export class HandshakeRpcLocal implements IHandshakeRpc {
|
|
|
125
125
|
|
|
126
126
|
async interleaveRequest(message: InterleaveRequest, context: ServerCallContext): Promise<InterleaveResponse> {
|
|
127
127
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
128
|
-
const remoteNodeId =
|
|
128
|
+
const remoteNodeId = toNodeId(senderPeerDescriptor)
|
|
129
129
|
try {
|
|
130
130
|
await this.options.handshakeWithInterleaving(message.interleaveTargetDescriptor!, remoteNodeId)
|
|
131
131
|
this.options.neighbors.remove(remoteNodeId)
|
|
132
132
|
return { accepted: true }
|
|
133
133
|
} catch (err) {
|
|
134
|
-
logger.debug(`interleaveRequest to ${
|
|
134
|
+
logger.debug(`interleaveRequest to ${toNodeId(message.interleaveTargetDescriptor!)} failed`, { err })
|
|
135
135
|
return { accepted: false }
|
|
136
136
|
}
|
|
137
137
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { DhtAddress, PeerDescriptor, RpcRemote,
|
|
1
|
+
import { DhtAddress, PeerDescriptor, RpcRemote, toNodeId, toDhtAddressRaw } from '@streamr/dht'
|
|
2
2
|
import { Logger, StreamPartID } from '@streamr/utils'
|
|
3
3
|
import { v4 } from 'uuid'
|
|
4
|
-
import { InterleaveRequest, InterleaveResponse, StreamPartHandshakeRequest } from '
|
|
5
|
-
import { HandshakeRpcClient } from '
|
|
4
|
+
import { InterleaveRequest, InterleaveResponse, StreamPartHandshakeRequest } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
+
import { HandshakeRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
6
6
|
|
|
7
7
|
const logger = new Logger(module)
|
|
8
8
|
|
|
@@ -24,9 +24,9 @@ export class HandshakeRpcRemote extends RpcRemote<HandshakeRpcClient> {
|
|
|
24
24
|
const request: StreamPartHandshakeRequest = {
|
|
25
25
|
streamPartId,
|
|
26
26
|
requestId: v4(),
|
|
27
|
-
neighborNodeIds: neighborNodeIds.map((id) =>
|
|
28
|
-
concurrentHandshakeNodeId: (concurrentHandshakeNodeId !== undefined) ?
|
|
29
|
-
interleaveNodeId: (interleaveNodeId !== undefined) ?
|
|
27
|
+
neighborNodeIds: neighborNodeIds.map((id) => toDhtAddressRaw(id)),
|
|
28
|
+
concurrentHandshakeNodeId: (concurrentHandshakeNodeId !== undefined) ? toDhtAddressRaw(concurrentHandshakeNodeId) : undefined,
|
|
29
|
+
interleaveNodeId: (interleaveNodeId !== undefined) ? toDhtAddressRaw(interleaveNodeId) : undefined
|
|
30
30
|
}
|
|
31
31
|
try {
|
|
32
32
|
const response = await this.getClient().handshake(request, this.formDhtRpcOptions())
|
|
@@ -35,7 +35,7 @@ export class HandshakeRpcRemote extends RpcRemote<HandshakeRpcClient> {
|
|
|
35
35
|
interleaveTargetDescriptor: response.interleaveTargetDescriptor
|
|
36
36
|
}
|
|
37
37
|
} catch (err: any) {
|
|
38
|
-
logger.debug(`handshake to ${
|
|
38
|
+
logger.debug(`handshake to ${toNodeId(this.getPeerDescriptor())} failed`, { err })
|
|
39
39
|
return {
|
|
40
40
|
accepted: false
|
|
41
41
|
}
|
|
@@ -56,7 +56,7 @@ export class HandshakeRpcRemote extends RpcRemote<HandshakeRpcClient> {
|
|
|
56
56
|
accepted: res.accepted
|
|
57
57
|
}
|
|
58
58
|
} catch (err) {
|
|
59
|
-
logger.debug(`interleaveRequest to ${
|
|
59
|
+
logger.debug(`interleaveRequest to ${toNodeId(this.getPeerDescriptor())} failed`, { err })
|
|
60
60
|
return {
|
|
61
61
|
accepted: false
|
|
62
62
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import { DhtAddress, ListeningRpcCommunicator, PeerDescriptor,
|
|
1
|
+
import { DhtAddress, ListeningRpcCommunicator, PeerDescriptor, toNodeId } from '@streamr/dht'
|
|
2
2
|
import { Logger, StreamPartID } from '@streamr/utils'
|
|
3
3
|
import {
|
|
4
4
|
InterleaveRequest,
|
|
5
5
|
InterleaveResponse,
|
|
6
6
|
StreamPartHandshakeRequest,
|
|
7
7
|
StreamPartHandshakeResponse
|
|
8
|
-
} from '
|
|
8
|
+
} from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
9
9
|
import {
|
|
10
10
|
ContentDeliveryRpcClient, HandshakeRpcClient
|
|
11
|
-
} from '
|
|
11
|
+
} from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
12
12
|
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
13
13
|
import { NodeList } from '../NodeList'
|
|
14
14
|
import { HandshakeRpcLocal } from './HandshakeRpcLocal'
|
|
@@ -70,7 +70,7 @@ export class Handshaker {
|
|
|
70
70
|
private async selectParallelTargetsAndHandshake(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
71
71
|
const exclude = excludedIds.concat(this.options.neighbors.getIds())
|
|
72
72
|
const neighbors = this.selectParallelTargets(exclude)
|
|
73
|
-
neighbors.forEach((contact) => this.options.ongoingHandshakes.add(
|
|
73
|
+
neighbors.forEach((contact) => this.options.ongoingHandshakes.add(toNodeId(contact.getPeerDescriptor())))
|
|
74
74
|
return this.doParallelHandshakes(neighbors, exclude)
|
|
75
75
|
}
|
|
76
76
|
|
|
@@ -83,7 +83,7 @@ export class Handshaker {
|
|
|
83
83
|
true
|
|
84
84
|
)
|
|
85
85
|
if (wsNode) {
|
|
86
|
-
const wsNodeId =
|
|
86
|
+
const wsNodeId = toNodeId(wsNode.getPeerDescriptor())
|
|
87
87
|
excludedIds.push(wsNodeId)
|
|
88
88
|
neighbors.set(wsNodeId, wsNode)
|
|
89
89
|
}
|
|
@@ -92,21 +92,21 @@ export class Handshaker {
|
|
|
92
92
|
const left = this.options.leftNodeView.getFirst([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
93
93
|
const right = this.options.rightNodeView.getFirst([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
94
94
|
if (left) {
|
|
95
|
-
neighbors.set(
|
|
95
|
+
neighbors.set(toNodeId(left.getPeerDescriptor()), left)
|
|
96
96
|
}
|
|
97
97
|
if (right) {
|
|
98
|
-
neighbors.set(
|
|
98
|
+
neighbors.set(toNodeId(right.getPeerDescriptor()), right)
|
|
99
99
|
}
|
|
100
100
|
// If there is still room add the closest contact based on the kademlia metric
|
|
101
101
|
if (neighbors.size < PARALLEL_HANDSHAKE_COUNT) {
|
|
102
102
|
const first = this.options.nearbyNodeView.getFirst([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
103
103
|
if (first) {
|
|
104
|
-
neighbors.set(
|
|
104
|
+
neighbors.set(toNodeId(first.getPeerDescriptor()), first)
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
const getExcludedFromRandomView = () => [
|
|
108
108
|
...excludedIds,
|
|
109
|
-
...Array.from(neighbors.values()).map((neighbor) =>
|
|
109
|
+
...Array.from(neighbors.values()).map((neighbor) => toNodeId(neighbor.getPeerDescriptor()))
|
|
110
110
|
]
|
|
111
111
|
// If there is still room add a random contact until PARALLEL_HANDSHAKE_COUNT is reached
|
|
112
112
|
while (
|
|
@@ -115,7 +115,7 @@ export class Handshaker {
|
|
|
115
115
|
) {
|
|
116
116
|
const random = this.options.randomNodeView.getRandom([...excludedIds, ...Array.from(neighbors.keys())] as DhtAddress[])
|
|
117
117
|
if (random) {
|
|
118
|
-
neighbors.set(
|
|
118
|
+
neighbors.set(toNodeId(random.getPeerDescriptor()), random)
|
|
119
119
|
}
|
|
120
120
|
}
|
|
121
121
|
return Array.from(neighbors.values()).map((neighbor) => this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
@@ -126,13 +126,13 @@ export class Handshaker {
|
|
|
126
126
|
Array.from(targets.values()).map(async (target: HandshakeRpcRemote, i) => {
|
|
127
127
|
const otherNode = i === 0 ? targets[1] : targets[0]
|
|
128
128
|
// TODO better check (currently this condition is always true)
|
|
129
|
-
const otherNodeId = otherNode ?
|
|
129
|
+
const otherNodeId = otherNode ? toNodeId(otherNode.getPeerDescriptor()) : undefined
|
|
130
130
|
return this.handshakeWithTarget(target, otherNodeId)
|
|
131
131
|
})
|
|
132
132
|
)
|
|
133
133
|
results.forEach((res, i) => {
|
|
134
134
|
if (res.status !== 'fulfilled' || !res.value) {
|
|
135
|
-
excludedIds.push(
|
|
135
|
+
excludedIds.push(toNodeId(targets[i].getPeerDescriptor()))
|
|
136
136
|
}
|
|
137
137
|
})
|
|
138
138
|
return excludedIds
|
|
@@ -147,14 +147,14 @@ export class Handshaker {
|
|
|
147
147
|
if (neighbor) {
|
|
148
148
|
const accepted = await this.handshakeWithTarget(this.createRpcRemote(neighbor.getPeerDescriptor()))
|
|
149
149
|
if (!accepted) {
|
|
150
|
-
excludedIds.push(
|
|
150
|
+
excludedIds.push(toNodeId(neighbor.getPeerDescriptor()))
|
|
151
151
|
}
|
|
152
152
|
}
|
|
153
153
|
return excludedIds
|
|
154
154
|
}
|
|
155
155
|
|
|
156
156
|
private async handshakeWithTarget(neighbor: HandshakeRpcRemote, concurrentNodeId?: DhtAddress): Promise<boolean> {
|
|
157
|
-
const targetNodeId =
|
|
157
|
+
const targetNodeId = toNodeId(neighbor.getPeerDescriptor())
|
|
158
158
|
this.options.ongoingHandshakes.add(targetNodeId)
|
|
159
159
|
const result = await neighbor.handshake(
|
|
160
160
|
this.options.streamPartId,
|
|
@@ -173,7 +173,7 @@ export class Handshaker {
|
|
|
173
173
|
|
|
174
174
|
private async handshakeWithInterleaving(target: PeerDescriptor, remoteNodeId: DhtAddress): Promise<boolean> {
|
|
175
175
|
const neighbor = this.createRpcRemote(target)
|
|
176
|
-
const targetNodeId =
|
|
176
|
+
const targetNodeId = toNodeId(neighbor.getPeerDescriptor())
|
|
177
177
|
this.options.ongoingHandshakes.add(targetNodeId)
|
|
178
178
|
const result = await neighbor.handshake(
|
|
179
179
|
this.options.streamPartId,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { setAbortableTimeout } from '@streamr/utils'
|
|
1
|
+
import { Logger, setAbortableTimeout } from '@streamr/utils'
|
|
2
2
|
import { NodeList } from '../NodeList'
|
|
3
3
|
import { DhtAddress } from '@streamr/dht'
|
|
4
4
|
|
|
@@ -15,6 +15,8 @@ interface FindNeighborsSessionOptions {
|
|
|
15
15
|
const INITIAL_WAIT = 100
|
|
16
16
|
const INTERVAL = 250
|
|
17
17
|
|
|
18
|
+
const logger = new Logger(module)
|
|
19
|
+
|
|
18
20
|
export class NeighborFinder {
|
|
19
21
|
private readonly abortController: AbortController
|
|
20
22
|
private readonly options: FindNeighborsSessionOptions
|
|
@@ -39,6 +41,9 @@ export class NeighborFinder {
|
|
|
39
41
|
if (this.options.neighbors.size() < this.options.minCount && newExcludes.length < uniqueContactCount) {
|
|
40
42
|
// TODO should we catch possible promise rejection?
|
|
41
43
|
setAbortableTimeout(() => this.findNeighbors(newExcludes), INTERVAL, this.abortController.signal)
|
|
44
|
+
} else if (this.options.neighbors.size() === 0 && uniqueContactCount > 0) {
|
|
45
|
+
logger.debug('No neighbors found yet contacts are available, restarting handshaking process')
|
|
46
|
+
setAbortableTimeout(() => this.findNeighbors([]), INTERVAL, this.abortController.signal)
|
|
42
47
|
} else {
|
|
43
48
|
this.running = false
|
|
44
49
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { DhtAddress, ListeningRpcCommunicator, PeerDescriptor,
|
|
1
|
+
import { DhtAddress, ListeningRpcCommunicator, PeerDescriptor, toNodeId } from '@streamr/dht'
|
|
2
2
|
import { Logger, StreamPartID, scheduleAtInterval } from '@streamr/utils'
|
|
3
|
-
import { NeighborUpdate } from '
|
|
4
|
-
import { NeighborUpdateRpcClient } from '
|
|
3
|
+
import { NeighborUpdate } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
4
|
+
import { NeighborUpdateRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
import { NodeList } from '../NodeList'
|
|
6
6
|
import { NeighborFinder } from './NeighborFinder'
|
|
7
7
|
import { NeighborUpdateRpcLocal } from './NeighborUpdateRpcLocal'
|
|
@@ -46,10 +46,12 @@ export class NeighborUpdateManager {
|
|
|
46
46
|
private async updateNeighborInfo(): Promise<void> {
|
|
47
47
|
logger.trace(`Updating neighbor info to nodes`)
|
|
48
48
|
const neighborDescriptors = this.options.neighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor())
|
|
49
|
+
const startTime = Date.now()
|
|
49
50
|
await Promise.allSettled(this.options.neighbors.getAll().map(async (neighbor) => {
|
|
50
51
|
const res = await this.createRemote(neighbor.getPeerDescriptor()).updateNeighbors(this.options.streamPartId, neighborDescriptors)
|
|
52
|
+
const nodeId = toNodeId(neighbor.getPeerDescriptor())
|
|
53
|
+
this.options.neighbors.get(nodeId)!.setRtt(Date.now() - startTime)
|
|
51
54
|
if (res.removeMe) {
|
|
52
|
-
const nodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
53
55
|
this.options.neighbors.remove(nodeId)
|
|
54
56
|
this.options.neighborFinder.start([nodeId])
|
|
55
57
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import { DhtAddress, DhtCallContext, ListeningRpcCommunicator, PeerDescriptor,
|
|
2
|
+
import { DhtAddress, DhtCallContext, ListeningRpcCommunicator, PeerDescriptor, toNodeId } from '@streamr/dht'
|
|
3
3
|
import { StreamPartID } from '@streamr/utils'
|
|
4
|
-
import { NeighborUpdate } from '
|
|
5
|
-
import { ContentDeliveryRpcClient } from '
|
|
6
|
-
import { INeighborUpdateRpc } from '
|
|
4
|
+
import { NeighborUpdate } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
+
import { ContentDeliveryRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
6
|
+
import { INeighborUpdateRpc } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.server'
|
|
7
7
|
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
8
8
|
import { NodeList } from '../NodeList'
|
|
9
9
|
import { NeighborFinder } from './NeighborFinder'
|
|
@@ -28,9 +28,9 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
private updateContacts(neighborDescriptors: PeerDescriptor[]): void {
|
|
31
|
-
const ownNodeId =
|
|
31
|
+
const ownNodeId = toNodeId(this.options.localPeerDescriptor)
|
|
32
32
|
const newPeerDescriptors = neighborDescriptors.filter((peerDescriptor) => {
|
|
33
|
-
const nodeId =
|
|
33
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
34
34
|
return nodeId !== ownNodeId && !this.options.neighbors.getIds().includes(nodeId)
|
|
35
35
|
})
|
|
36
36
|
newPeerDescriptors.forEach((peerDescriptor) => this.options.nearbyNodeView.add(
|
|
@@ -54,7 +54,7 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
54
54
|
// INeighborUpdateRpc server method
|
|
55
55
|
async neighborUpdate(message: NeighborUpdate, context: ServerCallContext): Promise<NeighborUpdate> {
|
|
56
56
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
57
|
-
const remoteNodeId =
|
|
57
|
+
const remoteNodeId = toNodeId(senderPeerDescriptor)
|
|
58
58
|
this.updateContacts(message.neighborDescriptors)
|
|
59
59
|
if (!this.options.neighbors.has(remoteNodeId) && !this.options.ongoingHandshakes.has(remoteNodeId)) {
|
|
60
60
|
return this.createResponse(true)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { PeerDescriptor, RpcRemote,
|
|
1
|
+
import { PeerDescriptor, RpcRemote, toNodeId } from '@streamr/dht'
|
|
2
2
|
import { Logger, StreamPartID } from '@streamr/utils'
|
|
3
|
-
import { NeighborUpdate } from '
|
|
4
|
-
import { NeighborUpdateRpcClient } from '
|
|
3
|
+
import { NeighborUpdate } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
4
|
+
import { NeighborUpdateRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
|
|
6
6
|
const logger = new Logger(module)
|
|
7
7
|
|
|
@@ -25,7 +25,7 @@ export class NeighborUpdateRpcRemote extends RpcRemote<NeighborUpdateRpcClient>
|
|
|
25
25
|
removeMe: response.removeMe
|
|
26
26
|
}
|
|
27
27
|
} catch (err: any) {
|
|
28
|
-
logger.debug(`updateNeighbors to ${
|
|
28
|
+
logger.debug(`updateNeighbors to ${toNodeId(this.getPeerDescriptor())} failed`, { err })
|
|
29
29
|
return {
|
|
30
30
|
peerDescriptors: [],
|
|
31
31
|
removeMe: true
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DhtCallContext, PeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
3
|
-
import { NodeInfo } from '../../
|
|
4
|
-
import { NodeInfoRpcClient } from '
|
|
3
|
+
import { NodeInfo } from '../../types'
|
|
4
|
+
import { NodeInfoRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
import { NodeInfoRpcRemote } from './NodeInfoRpcRemote'
|
|
6
6
|
|
|
7
7
|
export class NodeInfoClient {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NodeInfoRequest, NodeInfoResponse } from '
|
|
2
|
-
import { INodeInfoRpc } from '
|
|
1
|
+
import { NodeInfoRequest, NodeInfoResponse } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
2
|
+
import { INodeInfoRpc } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.server'
|
|
3
3
|
import { NetworkStack } from '../../NetworkStack'
|
|
4
4
|
import { ListeningRpcCommunicator } from '@streamr/dht'
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { NodeInfoResponse } from '
|
|
2
|
-
import { NodeInfoRpcClient } from '
|
|
1
|
+
import { NodeInfoResponse } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
2
|
+
import { NodeInfoRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
3
3
|
import { RpcRemote } from '@streamr/dht'
|
|
4
4
|
|
|
5
5
|
export class NodeInfoRpcRemote extends RpcRemote<NodeInfoRpcClient> {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DhtAddress } from '@streamr/dht'
|
|
2
|
-
import { StreamMessage } from '
|
|
2
|
+
import { StreamMessage } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { PropagationTask, PropagationTaskStore } from './PropagationTaskStore'
|
|
4
4
|
|
|
5
5
|
type SendToNeighborFn = (neighborId: DhtAddress, msg: StreamMessage) => Promise<void>
|
|
@@ -65,7 +65,6 @@ export class Propagation {
|
|
|
65
65
|
|
|
66
66
|
private sendAndAwaitThenMark({ message, source, handledNeighbors }: PropagationTask, neighborId: DhtAddress): void {
|
|
67
67
|
if (!handledNeighbors.has(neighborId) && neighborId !== source) {
|
|
68
|
-
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
69
68
|
(async () => {
|
|
70
69
|
try {
|
|
71
70
|
await this.sendToNeighbor(neighborId, message)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DhtAddress } from '@streamr/dht'
|
|
2
|
-
import { MessageRef, StreamMessage } from '
|
|
2
|
+
import { MessageRef, StreamMessage } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { FifoMapWithTTL } from './FifoMapWithTTL'
|
|
4
4
|
|
|
5
5
|
export interface PropagationTask {
|
|
@@ -4,9 +4,9 @@ import {
|
|
|
4
4
|
ITransport,
|
|
5
5
|
ListeningRpcCommunicator,
|
|
6
6
|
PeerDescriptor,
|
|
7
|
-
|
|
7
|
+
toNodeId
|
|
8
8
|
} from '@streamr/dht'
|
|
9
|
-
import {
|
|
9
|
+
import { Logger, StreamPartID, UserID, addManagedEventListener, wait } from '@streamr/utils'
|
|
10
10
|
import { EventEmitter } from 'eventemitter3'
|
|
11
11
|
import { sampleSize } from 'lodash'
|
|
12
12
|
import {
|
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
MessageRef,
|
|
16
16
|
ProxyDirection,
|
|
17
17
|
StreamMessage
|
|
18
|
-
} from '
|
|
19
|
-
import { ContentDeliveryRpcClient, ProxyConnectionRpcClient } from '
|
|
18
|
+
} from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
19
|
+
import { ContentDeliveryRpcClient, ProxyConnectionRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
20
20
|
import { ContentDeliveryRpcLocal } from '../ContentDeliveryRpcLocal'
|
|
21
21
|
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
22
22
|
import { DuplicateMessageDetector } from '../DuplicateMessageDetector'
|
|
@@ -28,7 +28,6 @@ import { ProxyConnectionRpcRemote } from './ProxyConnectionRpcRemote'
|
|
|
28
28
|
|
|
29
29
|
// TODO use options option or named constant?
|
|
30
30
|
export const retry = async <T>(task: () => Promise<T>, description: string, abortSignal: AbortSignal, delay = 10000): Promise<T> => {
|
|
31
|
-
// eslint-disable-next-line no-constant-condition
|
|
32
31
|
while (true) {
|
|
33
32
|
try {
|
|
34
33
|
const result = await task()
|
|
@@ -54,7 +53,7 @@ interface ProxyDefinition {
|
|
|
54
53
|
nodes: Map<DhtAddress, PeerDescriptor>
|
|
55
54
|
connectionCount: number
|
|
56
55
|
direction: ProxyDirection
|
|
57
|
-
userId:
|
|
56
|
+
userId: UserID
|
|
58
57
|
}
|
|
59
58
|
|
|
60
59
|
interface ProxyConnection {
|
|
@@ -87,7 +86,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
87
86
|
this.options = options
|
|
88
87
|
this.rpcCommunicator = new ListeningRpcCommunicator(formStreamPartContentDeliveryServiceId(options.streamPartId), options.transport)
|
|
89
88
|
// TODO use options option or named constant?
|
|
90
|
-
this.neighbors = new NodeList(
|
|
89
|
+
this.neighbors = new NodeList(toNodeId(this.options.localPeerDescriptor), 1000)
|
|
91
90
|
this.contentDeliveryRpcLocal = new ContentDeliveryRpcLocal({
|
|
92
91
|
localPeerDescriptor: this.options.localPeerDescriptor,
|
|
93
92
|
streamPartId: this.options.streamPartId,
|
|
@@ -128,7 +127,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
128
127
|
async setProxies(
|
|
129
128
|
nodes: PeerDescriptor[],
|
|
130
129
|
direction: ProxyDirection,
|
|
131
|
-
userId:
|
|
130
|
+
userId: UserID,
|
|
132
131
|
connectionCount?: number
|
|
133
132
|
): Promise<void> {
|
|
134
133
|
logger.trace('Setting proxies', { streamPartId: this.options.streamPartId, peerDescriptors: nodes, direction, userId, connectionCount })
|
|
@@ -137,7 +136,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
137
136
|
}
|
|
138
137
|
const nodesIds = new Map<DhtAddress, PeerDescriptor>()
|
|
139
138
|
nodes.forEach((peerDescriptor) => {
|
|
140
|
-
nodesIds.set(
|
|
139
|
+
nodesIds.set(toNodeId(peerDescriptor), peerDescriptor)
|
|
141
140
|
})
|
|
142
141
|
this.definition = {
|
|
143
142
|
nodes: nodesIds,
|
|
@@ -176,7 +175,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
176
175
|
))
|
|
177
176
|
}
|
|
178
177
|
|
|
179
|
-
private async attemptConnection(nodeId: DhtAddress, direction: ProxyDirection, userId:
|
|
178
|
+
private async attemptConnection(nodeId: DhtAddress, direction: ProxyDirection, userId: UserID): Promise<void> {
|
|
180
179
|
const peerDescriptor = this.definition!.nodes.get(nodeId)!
|
|
181
180
|
const rpcRemote = new ProxyConnectionRpcRemote(
|
|
182
181
|
this.options.localPeerDescriptor,
|
|
@@ -225,7 +224,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
225
224
|
}
|
|
226
225
|
|
|
227
226
|
private removeConnection(peerDescriptor: PeerDescriptor): void {
|
|
228
|
-
const nodeId =
|
|
227
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
229
228
|
this.connections.delete(nodeId)
|
|
230
229
|
this.neighbors.remove(nodeId)
|
|
231
230
|
this.options.connectionLocker.unlockConnection(peerDescriptor, SERVICE_ID)
|
|
@@ -248,7 +247,7 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
248
247
|
}
|
|
249
248
|
|
|
250
249
|
private async onNodeDisconnected(peerDescriptor: PeerDescriptor): Promise<void> {
|
|
251
|
-
const nodeId =
|
|
250
|
+
const nodeId = toNodeId(peerDescriptor)
|
|
252
251
|
if (this.connections.has(nodeId)) {
|
|
253
252
|
this.options.connectionLocker.unlockConnection(peerDescriptor, SERVICE_ID)
|
|
254
253
|
this.removeConnection(peerDescriptor)
|
|
@@ -267,6 +266,12 @@ export class ProxyClient extends EventEmitter<Events> {
|
|
|
267
266
|
)
|
|
268
267
|
}
|
|
269
268
|
|
|
269
|
+
public getDiagnosticInfo(): Record<string, unknown> {
|
|
270
|
+
return {
|
|
271
|
+
neighbors: this.neighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor()),
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
270
275
|
stop(): void {
|
|
271
276
|
this.neighbors.getAll().forEach((remote) => {
|
|
272
277
|
this.options.connectionLocker.unlockConnection(remote.getPeerDescriptor(), SERVICE_ID)
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import { DhtAddress, DhtCallContext, ListeningRpcCommunicator, PeerDescriptor,
|
|
3
|
-
import {
|
|
2
|
+
import { DhtAddress, DhtCallContext, ListeningRpcCommunicator, PeerDescriptor, toNodeId } from '@streamr/dht'
|
|
3
|
+
import { Logger, StreamPartID, toUserId, UserID } from '@streamr/utils'
|
|
4
4
|
import { EventEmitter } from 'eventemitter3'
|
|
5
5
|
import {
|
|
6
6
|
ProxyConnectionRequest,
|
|
7
7
|
ProxyConnectionResponse,
|
|
8
8
|
ProxyDirection,
|
|
9
9
|
StreamMessage
|
|
10
|
-
} from '
|
|
11
|
-
import { ContentDeliveryRpcClient } from '
|
|
12
|
-
import { IProxyConnectionRpc } from '
|
|
10
|
+
} from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
11
|
+
import { ContentDeliveryRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
12
|
+
import { IProxyConnectionRpc } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.server'
|
|
13
13
|
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
14
14
|
|
|
15
15
|
const logger = new Logger(module)
|
|
16
16
|
|
|
17
17
|
interface ProxyConnection {
|
|
18
18
|
direction: ProxyDirection // Direction is from the client's point of view
|
|
19
|
-
userId:
|
|
19
|
+
userId: UserID
|
|
20
20
|
remote: ContentDeliveryRpcRemote
|
|
21
21
|
}
|
|
22
22
|
|
|
@@ -64,7 +64,7 @@ export class ProxyConnectionRpcLocal extends EventEmitter<Events> implements IPr
|
|
|
64
64
|
if (msg.body.oneofKind === 'groupKeyRequest') {
|
|
65
65
|
try {
|
|
66
66
|
const recipientId = msg.body.groupKeyRequest.recipientId
|
|
67
|
-
return this.getNodeIdsForUserId(
|
|
67
|
+
return this.getNodeIdsForUserId(toUserId(recipientId))
|
|
68
68
|
} catch (err) {
|
|
69
69
|
logger.trace(`Could not parse GroupKeyRequest`, { err })
|
|
70
70
|
return []
|
|
@@ -74,7 +74,7 @@ export class ProxyConnectionRpcLocal extends EventEmitter<Events> implements IPr
|
|
|
74
74
|
}
|
|
75
75
|
}
|
|
76
76
|
|
|
77
|
-
private getNodeIdsForUserId(userId:
|
|
77
|
+
private getNodeIdsForUserId(userId: UserID): DhtAddress[] {
|
|
78
78
|
return Array.from(this.connections.keys()).filter((nodeId) => this.connections.get(nodeId)!.userId === userId)
|
|
79
79
|
}
|
|
80
80
|
|
|
@@ -85,10 +85,10 @@ export class ProxyConnectionRpcLocal extends EventEmitter<Events> implements IPr
|
|
|
85
85
|
// IProxyConnectionRpc server method
|
|
86
86
|
async requestConnection(request: ProxyConnectionRequest, context: ServerCallContext): Promise<ProxyConnectionResponse> {
|
|
87
87
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
88
|
-
const remoteNodeId =
|
|
88
|
+
const remoteNodeId = toNodeId(senderPeerDescriptor)
|
|
89
89
|
this.connections.set(remoteNodeId, {
|
|
90
90
|
direction: request.direction,
|
|
91
|
-
userId:
|
|
91
|
+
userId: toUserId(request.userId),
|
|
92
92
|
remote: new ContentDeliveryRpcRemote(
|
|
93
93
|
this.options.localPeerDescriptor,
|
|
94
94
|
senderPeerDescriptor,
|
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
import { EXISTING_CONNECTION_TIMEOUT, RpcRemote } from '@streamr/dht'
|
|
2
|
-
import {
|
|
3
|
-
import { ProxyConnectionRequest, ProxyDirection } from '
|
|
4
|
-
import { ProxyConnectionRpcClient } from '
|
|
2
|
+
import { Logger, UserID, toUserIdRaw } from '@streamr/utils'
|
|
3
|
+
import { ProxyConnectionRequest, ProxyDirection } from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
4
|
+
import { ProxyConnectionRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
5
|
|
|
6
6
|
const logger = new Logger(module)
|
|
7
7
|
|
|
8
8
|
export class ProxyConnectionRpcRemote extends RpcRemote<ProxyConnectionRpcClient> {
|
|
9
9
|
|
|
10
|
-
async requestConnection(direction: ProxyDirection, userId:
|
|
10
|
+
async requestConnection(direction: ProxyDirection, userId: UserID): Promise<boolean> {
|
|
11
11
|
const request: ProxyConnectionRequest = {
|
|
12
12
|
direction,
|
|
13
|
-
userId:
|
|
13
|
+
userId: toUserIdRaw(userId)
|
|
14
14
|
}
|
|
15
15
|
const options = this.formDhtRpcOptions({
|
|
16
16
|
timeout: EXISTING_CONNECTION_TIMEOUT
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import { ConnectionLocker, DhtAddress, DhtCallContext, ListeningRpcCommunicator,
|
|
2
|
+
import { ConnectionLocker, DhtAddress, DhtCallContext, ListeningRpcCommunicator, toNodeId } from '@streamr/dht'
|
|
3
3
|
import { StreamPartID } from '@streamr/utils'
|
|
4
|
-
import { Empty } from '
|
|
5
|
-
import { PeerDescriptor } from '
|
|
4
|
+
import { Empty } from '../../../generated/google/protobuf/empty'
|
|
5
|
+
import { PeerDescriptor } from '../../../generated/packages/dht/protos/DhtRpc'
|
|
6
6
|
import {
|
|
7
7
|
CloseTemporaryConnection,
|
|
8
8
|
TemporaryConnectionRequest,
|
|
9
9
|
TemporaryConnectionResponse
|
|
10
|
-
} from '
|
|
11
|
-
import { ContentDeliveryRpcClient } from '
|
|
12
|
-
import { ITemporaryConnectionRpc } from '
|
|
10
|
+
} from '../../../generated/packages/trackerless-network/protos/NetworkRpc'
|
|
11
|
+
import { ContentDeliveryRpcClient } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.client'
|
|
12
|
+
import { ITemporaryConnectionRpc } from '../../../generated/packages/trackerless-network/protos/NetworkRpc.server'
|
|
13
13
|
import { ContentDeliveryRpcRemote } from '../ContentDeliveryRpcRemote'
|
|
14
14
|
import { NodeList } from '../NodeList'
|
|
15
15
|
|
|
@@ -30,7 +30,7 @@ export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
|
30
30
|
constructor(options: TemporaryConnectionRpcLocalOptions) {
|
|
31
31
|
this.options = options
|
|
32
32
|
// TODO use options option or named constant?
|
|
33
|
-
this.temporaryNodes = new NodeList(
|
|
33
|
+
this.temporaryNodes = new NodeList(toNodeId(options.localPeerDescriptor), 10)
|
|
34
34
|
this.lockId = LOCK_ID_BASE + options.streamPartId
|
|
35
35
|
}
|
|
36
36
|
|
|
@@ -59,14 +59,14 @@ export class TemporaryConnectionRpcLocal implements ITemporaryConnectionRpc {
|
|
|
59
59
|
ContentDeliveryRpcClient
|
|
60
60
|
)
|
|
61
61
|
this.temporaryNodes.add(remote)
|
|
62
|
-
this.options.connectionLocker.weakLockConnection(
|
|
62
|
+
this.options.connectionLocker.weakLockConnection(toNodeId(sender), this.lockId)
|
|
63
63
|
return {
|
|
64
64
|
accepted: true
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
|
|
68
68
|
async closeConnection(_request: CloseTemporaryConnection, context: ServerCallContext): Promise<Empty> {
|
|
69
|
-
const remoteNodeId =
|
|
69
|
+
const remoteNodeId = toNodeId((context as DhtCallContext).incomingSourceDescriptor!)
|
|
70
70
|
this.removeNode(remoteNodeId)
|
|
71
71
|
return {}
|
|
72
72
|
}
|