@streamr/trackerless-network 100.0.0-pretestnet.4 → 100.0.0-rc.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/README.md +57 -0
- package/dist/package.json +11 -11
- package/dist/src/NetworkNode.d.ts +6 -5
- package/dist/src/NetworkNode.js +9 -2
- package/dist/src/NetworkNode.js.map +1 -1
- package/dist/src/NetworkStack.d.ts +13 -9
- package/dist/src/NetworkStack.js +80 -12
- package/dist/src/NetworkStack.js.map +1 -1
- package/dist/src/exports.d.ts +4 -3
- package/dist/src/exports.js +12 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/logic/DeliveryRpcLocal.d.ts +4 -5
- package/dist/src/logic/DeliveryRpcLocal.js +6 -5
- package/dist/src/logic/DeliveryRpcLocal.js.map +1 -1
- package/dist/src/logic/DeliveryRpcRemote.d.ts +5 -4
- package/dist/src/logic/DeliveryRpcRemote.js +4 -3
- package/dist/src/logic/DeliveryRpcRemote.js.map +1 -1
- package/dist/src/logic/DuplicateMessageDetector.d.ts +3 -3
- package/dist/src/logic/DuplicateMessageDetector.js +10 -6
- package/dist/src/logic/DuplicateMessageDetector.js.map +1 -1
- package/dist/src/logic/EntryPointDiscovery.d.ts +8 -5
- package/dist/src/logic/EntryPointDiscovery.js +24 -15
- package/dist/src/logic/EntryPointDiscovery.js.map +1 -1
- package/dist/src/logic/Layer0Node.d.ts +6 -4
- package/dist/src/logic/Layer1Node.d.ts +12 -6
- package/dist/src/logic/NodeList.d.ts +13 -15
- package/dist/src/logic/NodeList.js +18 -15
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +26 -22
- package/dist/src/logic/RandomGraphNode.js +82 -52
- package/dist/src/logic/RandomGraphNode.js.map +1 -1
- package/dist/src/logic/StreamrNode.d.ts +6 -6
- package/dist/src/logic/StreamrNode.js +53 -37
- package/dist/src/logic/StreamrNode.js.map +1 -1
- package/dist/src/logic/createRandomGraphNode.d.ts +2 -2
- package/dist/src/logic/createRandomGraphNode.js +33 -21
- package/dist/src/logic/createRandomGraphNode.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/InspectSession.d.ts +4 -3
- package/dist/src/logic/inspect/InspectSession.js +6 -2
- package/dist/src/logic/inspect/InspectSession.js.map +1 -1
- package/dist/src/logic/inspect/Inspector.d.ts +11 -16
- package/dist/src/logic/inspect/Inspector.js +21 -9
- package/dist/src/logic/inspect/Inspector.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.d.ts +7 -9
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js +55 -32
- package/dist/src/logic/neighbor-discovery/HandshakeRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.d.ts +8 -6
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js +25 -16
- package/dist/src/logic/neighbor-discovery/HandshakeRpcRemote.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/Handshaker.d.ts +9 -15
- package/dist/src/logic/neighbor-discovery/Handshaker.js +68 -44
- package/dist/src/logic/neighbor-discovery/Handshaker.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborFinder.d.ts +8 -10
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js +12 -2
- package/dist/src/logic/neighbor-discovery/NeighborFinder.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.d.ts +7 -10
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js +11 -9
- package/dist/src/logic/neighbor-discovery/NeighborUpdateManager.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.d.ts +8 -4
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js +33 -24
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.js.map +1 -1
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.d.ts +5 -4
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js +4 -5
- package/dist/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.js.map +1 -1
- package/dist/src/logic/node-info/NodeInfoClient.d.ts +9 -0
- package/dist/src/logic/node-info/NodeInfoClient.js +21 -0
- package/dist/src/logic/node-info/NodeInfoClient.js.map +1 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.d.ts +12 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js +22 -0
- package/dist/src/logic/node-info/NodeInfoRpcLocal.js.map +1 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.d.ts +6 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.js +11 -0
- package/dist/src/logic/node-info/NodeInfoRpcRemote.js.map +1 -0
- package/dist/src/logic/propagation/FifoMapWithTTL.js +7 -3
- package/dist/src/logic/propagation/FifoMapWithTTL.js.map +1 -1
- package/dist/src/logic/propagation/Propagation.d.ts +4 -4
- package/dist/src/logic/propagation/Propagation.js +4 -0
- package/dist/src/logic/propagation/Propagation.js.map +1 -1
- package/dist/src/logic/propagation/PropagationTaskStore.d.ts +2 -2
- package/dist/src/logic/propagation/PropagationTaskStore.js +1 -0
- package/dist/src/logic/propagation/PropagationTaskStore.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js +1 -1
- package/dist/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js +87 -53
- package/dist/src/logic/protocol-integration/stream-message/StreamMessageTranslator.js.map +1 -1
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.d.ts +7 -0
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js +32 -0
- package/dist/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.js.map +1 -0
- package/dist/src/logic/proxy/ProxyClient.d.ts +8 -6
- package/dist/src/logic/proxy/ProxyClient.js +40 -28
- package/dist/src/logic/proxy/ProxyClient.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.d.ts +6 -7
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js +8 -8
- package/dist/src/logic/proxy/ProxyConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/proxy/ProxyConnectionRpcRemote.d.ts +3 -3
- 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 +9 -4
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js +21 -6
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcLocal.js.map +1 -1
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.d.ts +4 -3
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js +13 -3
- package/dist/src/logic/temporary-connection/TemporaryConnectionRpcRemote.js.map +1 -1
- package/dist/src/logic/utils.js.map +1 -1
- package/dist/src/proto/google/protobuf/any.js +8 -8
- package/dist/src/proto/google/protobuf/any.js.map +1 -1
- package/dist/src/proto/google/protobuf/empty.js +2 -4
- package/dist/src/proto/google/protobuf/empty.js.map +1 -1
- package/dist/src/proto/google/protobuf/timestamp.js +10 -10
- package/dist/src/proto/google/protobuf/timestamp.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.d.ts +36 -49
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js +54 -52
- package/dist/src/proto/packages/dht/protos/DhtRpc.client.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +184 -234
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +118 -168
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/dist/src/proto/packages/dht/protos/DhtRpc.server.d.ts +20 -29
- package/dist/src/proto/packages/proto-rpc/protos/ProtoRpc.js +1 -1
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.d.ts +42 -5
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.client.js +52 -19
- 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 +193 -28
- package/dist/src/proto/packages/trackerless-network/protos/NetworkRpc.js +129 -20
- 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 +20 -3
- package/dist/test/benchmark/first-message.js +14 -15
- package/dist/test/benchmark/first-message.js.map +1 -1
- package/dist/test/utils/utils.d.ts +2 -4
- package/dist/test/utils/utils.js +20 -19
- package/dist/test/utils/utils.js.map +1 -1
- package/jest.config.js +3 -38
- package/package.json +11 -11
- package/protos/NetworkRpc.proto +57 -12
- package/src/NetworkNode.ts +13 -6
- package/src/NetworkStack.ts +94 -16
- package/src/exports.ts +11 -3
- package/src/logic/DeliveryRpcLocal.ts +7 -8
- package/src/logic/DeliveryRpcRemote.ts +7 -5
- package/src/logic/DuplicateMessageDetector.ts +7 -7
- package/src/logic/EntryPointDiscovery.ts +26 -19
- package/src/logic/Layer0Node.ts +6 -4
- package/src/logic/Layer1Node.ts +21 -6
- package/src/logic/NodeList.ts +25 -26
- package/src/logic/RandomGraphNode.ts +148 -78
- package/src/logic/StreamrNode.ts +58 -41
- package/src/logic/createRandomGraphNode.ts +37 -25
- package/src/logic/formStreamPartDeliveryServiceId.ts +2 -1
- package/src/logic/inspect/InspectSession.ts +8 -4
- package/src/logic/inspect/Inspector.ts +34 -24
- package/src/logic/neighbor-discovery/HandshakeRpcLocal.ts +72 -38
- package/src/logic/neighbor-discovery/HandshakeRpcRemote.ts +32 -20
- package/src/logic/neighbor-discovery/Handshaker.ts +90 -75
- package/src/logic/neighbor-discovery/NeighborFinder.ts +18 -13
- package/src/logic/neighbor-discovery/NeighborUpdateManager.ts +19 -20
- package/src/logic/neighbor-discovery/NeighborUpdateRpcLocal.ts +43 -33
- package/src/logic/neighbor-discovery/NeighborUpdateRpcRemote.ts +6 -6
- package/src/logic/node-info/NodeInfoClient.ts +23 -0
- package/src/logic/node-info/NodeInfoRpcLocal.ts +28 -0
- package/src/logic/node-info/NodeInfoRpcRemote.ts +11 -0
- package/src/logic/propagation/Propagation.ts +7 -6
- package/src/logic/propagation/PropagationTaskStore.ts +2 -2
- package/src/logic/protocol-integration/stream-message/GroupKeyRequestTranslator.ts +1 -1
- package/src/logic/protocol-integration/stream-message/GroupKeyResponseTranslator.ts +1 -2
- package/src/logic/protocol-integration/stream-message/StreamMessageTranslator.ts +95 -69
- package/src/logic/protocol-integration/stream-message/oldStreamMessageBinaryUtils.ts +37 -0
- package/src/logic/proxy/ProxyClient.ts +60 -40
- package/src/logic/proxy/ProxyConnectionRpcLocal.ts +15 -19
- package/src/logic/proxy/ProxyConnectionRpcRemote.ts +3 -3
- package/src/logic/temporary-connection/TemporaryConnectionRpcLocal.ts +30 -10
- package/src/logic/temporary-connection/TemporaryConnectionRpcRemote.ts +14 -4
- package/src/proto/google/protobuf/any.ts +4 -4
- package/src/proto/google/protobuf/empty.ts +2 -4
- package/src/proto/google/protobuf/timestamp.ts +4 -4
- package/src/proto/packages/dht/protos/DhtRpc.client.ts +50 -66
- package/src/proto/packages/dht/protos/DhtRpc.server.ts +21 -30
- package/src/proto/packages/dht/protos/DhtRpc.ts +242 -316
- package/src/proto/packages/proto-rpc/protos/ProtoRpc.ts +1 -1
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.client.ts +49 -7
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.server.ts +21 -4
- package/src/proto/packages/trackerless-network/protos/NetworkRpc.ts +251 -44
- package/test/benchmark/StreamPartIdDataKeyDistribution.test.ts +60 -0
- package/test/benchmark/first-message.ts +38 -17
- package/test/end-to-end/inspect.test.ts +16 -4
- package/test/end-to-end/proxy-and-full-node.test.ts +26 -13
- package/test/end-to-end/proxy-connections.test.ts +23 -11
- package/test/end-to-end/proxy-key-exchange.test.ts +25 -15
- package/test/end-to-end/random-graph-with-real-connections.test.ts +35 -32
- package/test/end-to-end/webrtc-full-node-network.test.ts +11 -12
- package/test/end-to-end/websocket-full-node-network.test.ts +12 -12
- package/test/integration/DeliveryRpcRemote.test.ts +6 -9
- package/test/integration/HandshakeRpcRemote.test.ts +6 -8
- package/test/integration/Handshakes.test.ts +29 -27
- package/test/integration/Inspect.test.ts +0 -2
- package/test/integration/NeighborUpdateRpcRemote.test.ts +6 -7
- package/test/integration/NetworkNode.test.ts +27 -12
- package/test/integration/NetworkRpc.test.ts +3 -5
- package/test/integration/NetworkStack.test.ts +2 -2
- package/test/integration/NodeInfoRpc.test.ts +104 -0
- package/test/integration/Propagation.test.ts +3 -3
- package/test/integration/RandomGraphNode-Layer1Node-Latencies.test.ts +24 -25
- package/test/integration/RandomGraphNode-Layer1Node.test.ts +26 -24
- package/test/integration/StreamrNode.test.ts +4 -16
- package/test/integration/joining-streams-on-offline-peers.test.ts +7 -31
- package/test/integration/stream-without-default-entrypoints.test.ts +22 -23
- package/test/integration/streamEntryPointReplacing.test.ts +94 -0
- package/test/unit/DeliveryRpcLocal.test.ts +2 -1
- package/test/unit/EntrypointDiscovery.test.ts +11 -8
- package/test/unit/GroupKeyResponseTranslator.test.ts +1 -1
- package/test/unit/HandshakeRpcLocal.test.ts +80 -28
- package/test/unit/Handshaker.test.ts +14 -9
- package/test/unit/InspectSession.test.ts +5 -6
- package/test/unit/Inspector.test.ts +3 -4
- package/test/unit/NeighborFinder.test.ts +12 -9
- package/test/unit/NeighborUpdateRpcLocal.test.ts +139 -0
- package/test/unit/NodeList.test.ts +77 -80
- package/test/unit/Propagation.test.ts +21 -16
- package/test/unit/ProxyConnectionRpcRemote.test.ts +18 -12
- package/test/unit/RandomGraphNode.test.ts +23 -20
- package/test/unit/StreamMessageTranslator.test.ts +10 -8
- package/test/unit/StreamPartIDDataKey.test.ts +12 -0
- package/test/unit/StreamrNode.test.ts +2 -0
- package/test/unit/TemporaryConnectionRpcLocal.test.ts +38 -0
- package/test/unit/oldStreamMessageBinaryUtils.test.ts +39 -0
- package/test/utils/mock/MockHandshaker.ts +6 -5
- package/test/utils/mock/MockLayer0Node.ts +7 -2
- package/test/utils/mock/MockLayer1Node.ts +5 -2
- package/test/utils/mock/MockNeighborFinder.ts +3 -2
- package/test/utils/mock/MockNeighborUpdateManager.ts +3 -2
- package/test/utils/mock/Transport.ts +1 -1
- package/test/utils/utils.ts +40 -25
- package/tsconfig.jest.json +5 -4
- package/tsconfig.node.json +2 -2
- package/dist/src/identifiers.d.ts +0 -4
- package/dist/src/identifiers.js +0 -9
- package/dist/src/identifiers.js.map +0 -1
- package/src/identifiers.ts +0 -8
- package/test/unit/GroupKeyRequestTranslator.test.ts +0 -36
|
@@ -1,42 +1,35 @@
|
|
|
1
1
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
2
|
-
import { ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
3
|
-
import { ProtoRpcClient, toProtoRpcClient } from '@streamr/proto-rpc'
|
|
2
|
+
import { DhtAddress, ListeningRpcCommunicator, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
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'
|
|
10
|
-
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
11
9
|
import { StreamPartID } from '@streamr/protocol'
|
|
12
10
|
|
|
13
11
|
interface NeighborUpdateManagerConfig {
|
|
14
12
|
localPeerDescriptor: PeerDescriptor
|
|
15
|
-
|
|
13
|
+
neighbors: NodeList
|
|
16
14
|
nearbyNodeView: NodeList
|
|
17
|
-
neighborFinder:
|
|
15
|
+
neighborFinder: NeighborFinder
|
|
18
16
|
streamPartId: StreamPartID
|
|
19
17
|
rpcCommunicator: ListeningRpcCommunicator
|
|
20
18
|
neighborUpdateInterval: number
|
|
19
|
+
neighborTargetCount: number
|
|
20
|
+
ongoingHandshakes: Set<DhtAddress>
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
const logger = new Logger(module)
|
|
24
24
|
|
|
25
|
-
export
|
|
26
|
-
start(): Promise<void>
|
|
27
|
-
stop(): void
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export class NeighborUpdateManager implements INeighborUpdateManager {
|
|
25
|
+
export class NeighborUpdateManager {
|
|
31
26
|
|
|
32
27
|
private readonly abortController: AbortController
|
|
33
28
|
private readonly config: NeighborUpdateManagerConfig
|
|
34
|
-
private readonly client: ProtoRpcClient<NeighborUpdateRpcClient>
|
|
35
29
|
private readonly rpcLocal: NeighborUpdateRpcLocal
|
|
36
30
|
|
|
37
31
|
constructor(config: NeighborUpdateManagerConfig) {
|
|
38
32
|
this.abortController = new AbortController()
|
|
39
|
-
this.client = toProtoRpcClient(new NeighborUpdateRpcClient(config.rpcCommunicator.getRpcClientTransport()))
|
|
40
33
|
this.rpcLocal = new NeighborUpdateRpcLocal(config)
|
|
41
34
|
this.config = config
|
|
42
35
|
this.config.rpcCommunicator.registerRpcMethod(NeighborUpdate, NeighborUpdate, 'neighborUpdate',
|
|
@@ -53,17 +46,23 @@ export class NeighborUpdateManager implements INeighborUpdateManager {
|
|
|
53
46
|
|
|
54
47
|
private async updateNeighborInfo(): Promise<void> {
|
|
55
48
|
logger.trace(`Updating neighbor info to nodes`)
|
|
56
|
-
const neighborDescriptors = this.config.
|
|
57
|
-
await Promise.allSettled(this.config.
|
|
58
|
-
const res = await this.createRemote(neighbor.getPeerDescriptor()).updateNeighbors(neighborDescriptors)
|
|
49
|
+
const neighborDescriptors = this.config.neighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor())
|
|
50
|
+
await Promise.allSettled(this.config.neighbors.getAll().map(async (neighbor) => {
|
|
51
|
+
const res = await this.createRemote(neighbor.getPeerDescriptor()).updateNeighbors(this.config.streamPartId, neighborDescriptors)
|
|
59
52
|
if (res.removeMe) {
|
|
60
|
-
|
|
61
|
-
this.config.
|
|
53
|
+
const nodeId = getNodeIdFromPeerDescriptor(neighbor.getPeerDescriptor())
|
|
54
|
+
this.config.neighbors.remove(nodeId)
|
|
55
|
+
this.config.neighborFinder.start([nodeId])
|
|
62
56
|
}
|
|
63
57
|
}))
|
|
64
58
|
}
|
|
65
59
|
|
|
66
60
|
private createRemote(targetPeerDescriptor: PeerDescriptor): NeighborUpdateRpcRemote {
|
|
67
|
-
return new NeighborUpdateRpcRemote(
|
|
61
|
+
return new NeighborUpdateRpcRemote(
|
|
62
|
+
this.config.localPeerDescriptor,
|
|
63
|
+
targetPeerDescriptor,
|
|
64
|
+
this.config.rpcCommunicator,
|
|
65
|
+
NeighborUpdateRpcClient
|
|
66
|
+
)
|
|
68
67
|
}
|
|
69
68
|
}
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
2
|
-
import { DhtCallContext, ListeningRpcCommunicator, PeerDescriptor } from '@streamr/dht'
|
|
3
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
4
|
-
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
2
|
+
import { DhtAddress, DhtCallContext, ListeningRpcCommunicator, PeerDescriptor, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
5
3
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
4
|
import { DeliveryRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
7
5
|
import { INeighborUpdateRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
8
6
|
import { NodeList } from '../NodeList'
|
|
9
7
|
import { DeliveryRpcRemote } from '../DeliveryRpcRemote'
|
|
10
|
-
import {
|
|
8
|
+
import { NeighborFinder } from './NeighborFinder'
|
|
11
9
|
import { StreamPartID } from '@streamr/protocol'
|
|
12
10
|
|
|
13
11
|
interface NeighborUpdateRpcLocalConfig {
|
|
14
12
|
localPeerDescriptor: PeerDescriptor
|
|
15
13
|
streamPartId: StreamPartID
|
|
16
|
-
|
|
14
|
+
neighbors: NodeList
|
|
17
15
|
nearbyNodeView: NodeList
|
|
18
|
-
neighborFinder:
|
|
16
|
+
neighborFinder: NeighborFinder
|
|
19
17
|
rpcCommunicator: ListeningRpcCommunicator
|
|
18
|
+
neighborTargetCount: number
|
|
19
|
+
ongoingHandshakes: Set<DhtAddress>
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
@@ -27,39 +27,49 @@ export class NeighborUpdateRpcLocal implements INeighborUpdateRpc {
|
|
|
27
27
|
this.config = config
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
+
private updateContacts(neighborDescriptors: PeerDescriptor[]): void {
|
|
31
|
+
const ownNodeId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
|
|
32
|
+
const newPeerDescriptors = neighborDescriptors.filter((peerDescriptor) => {
|
|
33
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
34
|
+
return nodeId !== ownNodeId && !this.config.neighbors.getIds().includes(nodeId)
|
|
35
|
+
})
|
|
36
|
+
newPeerDescriptors.forEach((peerDescriptor) => this.config.nearbyNodeView.add(
|
|
37
|
+
new DeliveryRpcRemote(
|
|
38
|
+
this.config.localPeerDescriptor,
|
|
39
|
+
peerDescriptor,
|
|
40
|
+
this.config.rpcCommunicator,
|
|
41
|
+
DeliveryRpcClient
|
|
42
|
+
))
|
|
43
|
+
)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
private createResponse(removeMe: boolean): NeighborUpdate {
|
|
47
|
+
return {
|
|
48
|
+
streamPartId: this.config.streamPartId,
|
|
49
|
+
neighborDescriptors: this.config.neighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor()),
|
|
50
|
+
removeMe
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
30
54
|
// INeighborUpdateRpc server method
|
|
31
55
|
async neighborUpdate(message: NeighborUpdate, context: ServerCallContext): Promise<NeighborUpdate> {
|
|
32
56
|
const senderPeerDescriptor = (context as DhtCallContext).incomingSourceDescriptor!
|
|
33
57
|
const senderId = getNodeIdFromPeerDescriptor(senderPeerDescriptor)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
38
|
-
const ownNodeId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
|
|
39
|
-
return nodeId !== ownNodeId && !this.config.targetNeighbors.getIds().includes(nodeId)
|
|
40
|
-
})
|
|
41
|
-
newPeerDescriptors.forEach((peerDescriptor) => this.config.nearbyNodeView.add(
|
|
42
|
-
new DeliveryRpcRemote(
|
|
43
|
-
this.config.localPeerDescriptor,
|
|
44
|
-
peerDescriptor,
|
|
45
|
-
this.config.streamPartId,
|
|
46
|
-
toProtoRpcClient(new DeliveryRpcClient(this.config.rpcCommunicator.getRpcClientTransport()))
|
|
47
|
-
))
|
|
48
|
-
)
|
|
49
|
-
this.config.neighborFinder.start()
|
|
50
|
-
const response: NeighborUpdate = {
|
|
51
|
-
streamPartId: this.config.streamPartId,
|
|
52
|
-
neighborDescriptors: this.config.targetNeighbors.getAll().map((neighbor) => neighbor.getPeerDescriptor()),
|
|
53
|
-
removeMe: false
|
|
54
|
-
}
|
|
55
|
-
return response
|
|
58
|
+
this.updateContacts(message.neighborDescriptors)
|
|
59
|
+
if (!this.config.neighbors.has(senderId) && !this.config.ongoingHandshakes.has(senderId)) {
|
|
60
|
+
return this.createResponse(true)
|
|
56
61
|
} else {
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
62
|
+
const isOverNeighborCount = this.config.neighbors.size() > this.config.neighborTargetCount
|
|
63
|
+
// Motivation: We don't know the remote's neighborTargetCount setting here. We only ask to cut connections
|
|
64
|
+
// if the remote has a "sufficient" number of neighbors, where "sufficient" means our neighborTargetCount
|
|
65
|
+
// setting.
|
|
66
|
+
&& message.neighborDescriptors.length > this.config.neighborTargetCount
|
|
67
|
+
if (!isOverNeighborCount) {
|
|
68
|
+
this.config.neighborFinder.start()
|
|
69
|
+
} else {
|
|
70
|
+
this.config.neighbors.remove(senderId)
|
|
61
71
|
}
|
|
62
|
-
return
|
|
72
|
+
return this.createResponse(isOverNeighborCount)
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
75
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { PeerDescriptor,
|
|
1
|
+
import { PeerDescriptor, RpcRemote, getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
2
2
|
import { Logger } from '@streamr/utils'
|
|
3
|
-
import { getNodeIdFromPeerDescriptor } from '../../identifiers'
|
|
4
3
|
import { NeighborUpdate } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
-
import {
|
|
4
|
+
import { NeighborUpdateRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
|
+
import { StreamPartID } from '@streamr/protocol'
|
|
6
6
|
|
|
7
7
|
const logger = new Logger(module)
|
|
8
8
|
|
|
@@ -11,11 +11,11 @@ interface UpdateNeighborsResponse {
|
|
|
11
11
|
removeMe: boolean
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
export class NeighborUpdateRpcRemote extends
|
|
14
|
+
export class NeighborUpdateRpcRemote extends RpcRemote<NeighborUpdateRpcClient> {
|
|
15
15
|
|
|
16
|
-
async updateNeighbors(neighbors: PeerDescriptor[]): Promise<UpdateNeighborsResponse> {
|
|
16
|
+
async updateNeighbors(streamPartId: StreamPartID, neighbors: PeerDescriptor[]): Promise<UpdateNeighborsResponse> {
|
|
17
17
|
const request: NeighborUpdate = {
|
|
18
|
-
streamPartId
|
|
18
|
+
streamPartId,
|
|
19
19
|
neighborDescriptors: neighbors,
|
|
20
20
|
removeMe: false
|
|
21
21
|
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { DhtCallContext, PeerDescriptor } from '@streamr/dht'
|
|
2
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
3
|
+
import { NodeInfo } from '../../NetworkStack'
|
|
4
|
+
import { NodeInfoRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
5
|
+
import { NodeInfoRpcRemote } from './NodeInfoRpcRemote'
|
|
6
|
+
|
|
7
|
+
export class NodeInfoClient {
|
|
8
|
+
private readonly ownPeerDescriptor: PeerDescriptor
|
|
9
|
+
private readonly rpcCommunicator: RpcCommunicator<DhtCallContext>
|
|
10
|
+
|
|
11
|
+
constructor(ownPeerDescriptor: PeerDescriptor, rpcCommunicator: RpcCommunicator<DhtCallContext>) {
|
|
12
|
+
this.ownPeerDescriptor = ownPeerDescriptor
|
|
13
|
+
this.rpcCommunicator = rpcCommunicator
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async getInfo(node: PeerDescriptor): Promise<NodeInfo> {
|
|
17
|
+
const remote = new NodeInfoRpcRemote(this.ownPeerDescriptor, node, this.rpcCommunicator, NodeInfoRpcClient)
|
|
18
|
+
// TODO remove casting when we validate NodeInfoResponse messages and therefore can annotate
|
|
19
|
+
// each of the field as required in the decorated type
|
|
20
|
+
return remote.getInfo() as unknown as NodeInfo
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NodeInfoRequest, NodeInfoResponse } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
2
|
+
import { INodeInfoRpc } from '../../proto/packages/trackerless-network/protos/NetworkRpc.server'
|
|
3
|
+
import { NetworkStack } from '../../NetworkStack'
|
|
4
|
+
import { ListeningRpcCommunicator } from '@streamr/dht'
|
|
5
|
+
|
|
6
|
+
export const NODE_INFO_RPC_SERVICE_ID = 'system/node-info-rpc'
|
|
7
|
+
|
|
8
|
+
export class NodeInfoRpcLocal implements INodeInfoRpc {
|
|
9
|
+
|
|
10
|
+
private readonly stack: NetworkStack
|
|
11
|
+
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
12
|
+
|
|
13
|
+
constructor(stack: NetworkStack, rpcCommunicator: ListeningRpcCommunicator) {
|
|
14
|
+
this.stack = stack
|
|
15
|
+
this.rpcCommunicator = rpcCommunicator
|
|
16
|
+
this.registerDefaultServerMethods()
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
private registerDefaultServerMethods(): void {
|
|
20
|
+
this.rpcCommunicator.registerRpcMethod(NodeInfoRequest, NodeInfoResponse, 'getInfo',
|
|
21
|
+
() => this.getInfo())
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
async getInfo(): Promise<NodeInfoResponse> {
|
|
25
|
+
return this.stack.createNodeInfo()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { NodeInfoResponse } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
2
|
+
import { NodeInfoRpcClient } from '../../proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
3
|
+
import { RpcRemote } from '@streamr/dht'
|
|
4
|
+
|
|
5
|
+
export class NodeInfoRpcRemote extends RpcRemote<NodeInfoRpcClient> {
|
|
6
|
+
|
|
7
|
+
async getInfo(): Promise<NodeInfoResponse> {
|
|
8
|
+
return this.getClient().getInfo({}, this.formDhtRpcOptions())
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DhtAddress } from '@streamr/dht'
|
|
2
2
|
import { StreamMessage } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { PropagationTask, PropagationTaskStore } from './PropagationTaskStore'
|
|
4
4
|
|
|
5
|
-
type SendToNeighborFn = (neighborId:
|
|
5
|
+
type SendToNeighborFn = (neighborId: DhtAddress, msg: StreamMessage) => Promise<void>
|
|
6
6
|
|
|
7
7
|
interface ConstructorOptions {
|
|
8
8
|
sendToNeighbor: SendToNeighborFn
|
|
@@ -41,11 +41,11 @@ export class Propagation {
|
|
|
41
41
|
/**
|
|
42
42
|
* Node should invoke this when it learns about a new message
|
|
43
43
|
*/
|
|
44
|
-
feedUnseenMessage(message: StreamMessage, targets:
|
|
44
|
+
feedUnseenMessage(message: StreamMessage, targets: DhtAddress[], source: DhtAddress | null): void {
|
|
45
45
|
const task = {
|
|
46
46
|
message,
|
|
47
47
|
source,
|
|
48
|
-
handledNeighbors: new Set<
|
|
48
|
+
handledNeighbors: new Set<DhtAddress>()
|
|
49
49
|
}
|
|
50
50
|
this.activeTaskStore.add(task)
|
|
51
51
|
for (const target of targets) {
|
|
@@ -56,15 +56,16 @@ export class Propagation {
|
|
|
56
56
|
/**
|
|
57
57
|
* Node should invoke this when it learns about a new node stream assignment
|
|
58
58
|
*/
|
|
59
|
-
onNeighborJoined(neighborId:
|
|
59
|
+
onNeighborJoined(neighborId: DhtAddress): void {
|
|
60
60
|
const tasks = this.activeTaskStore.get()
|
|
61
61
|
for (const task of tasks) {
|
|
62
62
|
this.sendAndAwaitThenMark(task, neighborId)
|
|
63
63
|
}
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
private sendAndAwaitThenMark({ message, source, handledNeighbors }: PropagationTask, neighborId:
|
|
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
|
|
68
69
|
(async () => {
|
|
69
70
|
try {
|
|
70
71
|
await this.sendToNeighbor(neighborId, message)
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { DhtAddress } from '@streamr/dht'
|
|
2
2
|
import { MessageRef, StreamMessage } from '../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
3
3
|
import { FifoMapWithTTL } from './FifoMapWithTTL'
|
|
4
4
|
|
|
5
5
|
export interface PropagationTask {
|
|
6
6
|
message: StreamMessage
|
|
7
7
|
source: string | null
|
|
8
|
-
handledNeighbors: Set<
|
|
8
|
+
handledNeighbors: Set<DhtAddress>
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
/**
|
|
@@ -10,7 +10,7 @@ export class GroupKeyRequestTranslator {
|
|
|
10
10
|
recipientId: hexToBinary(msg.recipient),
|
|
11
11
|
requestId: msg.requestId,
|
|
12
12
|
rsaPublicKey: utf8ToBinary(msg.rsaPublicKey),
|
|
13
|
-
groupKeyIds: msg.groupKeyIds
|
|
13
|
+
groupKeyIds: [...msg.groupKeyIds]
|
|
14
14
|
}
|
|
15
15
|
return translated
|
|
16
16
|
}
|
|
@@ -6,11 +6,10 @@ import { toEthereumAddress, binaryToHex, hexToBinary } from '@streamr/utils'
|
|
|
6
6
|
export class GroupKeyResponseTranslator {
|
|
7
7
|
|
|
8
8
|
static toProtobuf(msg: OldGroupKeyResponse): GroupKeyResponse {
|
|
9
|
-
|
|
10
9
|
const groupKeys = msg.encryptedGroupKeys.map((groupKey) => {
|
|
11
10
|
return {
|
|
12
11
|
data: groupKey.data,
|
|
13
|
-
id: groupKey.
|
|
12
|
+
id: groupKey.id
|
|
14
13
|
}
|
|
15
14
|
})
|
|
16
15
|
const translated: GroupKeyResponse = {
|
|
@@ -4,10 +4,9 @@ import {
|
|
|
4
4
|
StreamMessageType as OldStreamMessageType,
|
|
5
5
|
MessageRef as OldMessageRef,
|
|
6
6
|
EncryptedGroupKey as OldEncryptedGroupKey,
|
|
7
|
-
GroupKeyRequest as OldGroupKeyRequest,
|
|
8
|
-
GroupKeyResponse as OldGroupKeyResponse,
|
|
9
7
|
StreamID,
|
|
10
8
|
EncryptionType as OldEncryptionType,
|
|
9
|
+
SignatureType as OldSignatureType,
|
|
11
10
|
ContentType as OldContentType
|
|
12
11
|
} from '@streamr/protocol'
|
|
13
12
|
import {
|
|
@@ -17,13 +16,11 @@ import {
|
|
|
17
16
|
GroupKeyRequest,
|
|
18
17
|
GroupKeyResponse,
|
|
19
18
|
MessageRef,
|
|
19
|
+
SignatureType,
|
|
20
20
|
StreamMessage,
|
|
21
|
-
StreamMessageType,
|
|
22
21
|
MessageID
|
|
23
22
|
} from '../../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
24
|
-
import { toEthereumAddress, binaryToHex,
|
|
25
|
-
import { GroupKeyRequestTranslator } from './GroupKeyRequestTranslator'
|
|
26
|
-
import { GroupKeyResponseTranslator } from './GroupKeyResponseTranslator'
|
|
23
|
+
import { toEthereumAddress, binaryToHex, hexToBinary } from '@streamr/utils'
|
|
27
24
|
|
|
28
25
|
const oldToNewEncryptionType = (type: OldEncryptionType): EncryptionType => {
|
|
29
26
|
if (type === OldEncryptionType.AES) {
|
|
@@ -39,36 +36,39 @@ const newToOldEncryptionType = (type: EncryptionType): OldEncryptionType => {
|
|
|
39
36
|
return OldEncryptionType.NONE
|
|
40
37
|
}
|
|
41
38
|
|
|
39
|
+
const oldToNewContentType = (type: OldContentType): ContentType => {
|
|
40
|
+
if (type === OldContentType.JSON) {
|
|
41
|
+
return ContentType.JSON
|
|
42
|
+
}
|
|
43
|
+
return ContentType.BINARY
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const newToOldContentType = (type: ContentType): OldContentType => {
|
|
47
|
+
if (type === ContentType.JSON) {
|
|
48
|
+
return OldContentType.JSON
|
|
49
|
+
}
|
|
50
|
+
return OldContentType.BINARY
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const oldToNewSignatureType = (type: OldSignatureType): SignatureType => {
|
|
54
|
+
if (type === OldSignatureType.LEGACY_SECP256K1) {
|
|
55
|
+
return SignatureType.LEGACY_SECP256K1
|
|
56
|
+
}
|
|
57
|
+
return SignatureType.SECP256K1
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
const newToOldSignatureType = (type: SignatureType): OldSignatureType => {
|
|
61
|
+
if (type === SignatureType.LEGACY_SECP256K1) {
|
|
62
|
+
return OldSignatureType.LEGACY_SECP256K1
|
|
63
|
+
}
|
|
64
|
+
return OldSignatureType.SECP256K1
|
|
65
|
+
|
|
66
|
+
}
|
|
67
|
+
|
|
42
68
|
// eslint-disable-next-line @typescript-eslint/no-extraneous-class
|
|
43
69
|
export class StreamMessageTranslator {
|
|
44
70
|
|
|
45
71
|
static toProtobuf(msg: OldStreamMessage): StreamMessage {
|
|
46
|
-
let content: Uint8Array
|
|
47
|
-
let messageType: StreamMessageType
|
|
48
|
-
if (msg.messageType === OldStreamMessageType.MESSAGE) {
|
|
49
|
-
content = msg.serializedContent
|
|
50
|
-
messageType = StreamMessageType.MESSAGE
|
|
51
|
-
} else if (msg.messageType === OldStreamMessageType.GROUP_KEY_REQUEST) {
|
|
52
|
-
content = GroupKeyRequest.toBinary(
|
|
53
|
-
GroupKeyRequestTranslator.toProtobuf(
|
|
54
|
-
OldGroupKeyRequest.deserialize(
|
|
55
|
-
binaryToUtf8(msg.serializedContent),
|
|
56
|
-
OldStreamMessageType.GROUP_KEY_REQUEST) as OldGroupKeyRequest
|
|
57
|
-
)
|
|
58
|
-
)
|
|
59
|
-
messageType = StreamMessageType.GROUP_KEY_REQUEST
|
|
60
|
-
} else if (msg.messageType === OldStreamMessageType.GROUP_KEY_RESPONSE) {
|
|
61
|
-
content = GroupKeyResponse.toBinary(
|
|
62
|
-
GroupKeyResponseTranslator.toProtobuf(
|
|
63
|
-
OldGroupKeyResponse.deserialize(
|
|
64
|
-
binaryToUtf8(msg.serializedContent),
|
|
65
|
-
OldStreamMessageType.GROUP_KEY_RESPONSE) as OldGroupKeyResponse
|
|
66
|
-
)
|
|
67
|
-
)
|
|
68
|
-
messageType = StreamMessageType.GROUP_KEY_RESPONSE
|
|
69
|
-
} else {
|
|
70
|
-
throw new Error('invalid message type')
|
|
71
|
-
}
|
|
72
72
|
const messageId: MessageID = {
|
|
73
73
|
timestamp: msg.getTimestamp(),
|
|
74
74
|
sequenceNumber: msg.getSequenceNumber(),
|
|
@@ -78,52 +78,84 @@ export class StreamMessageTranslator {
|
|
|
78
78
|
messageChainId: msg.getMsgChainId()
|
|
79
79
|
}
|
|
80
80
|
let previousMessageRef: MessageRef | undefined = undefined
|
|
81
|
-
if (msg.
|
|
81
|
+
if (msg.prevMsgRef) {
|
|
82
82
|
previousMessageRef = {
|
|
83
|
-
timestamp: msg.
|
|
84
|
-
sequenceNumber: msg.
|
|
83
|
+
timestamp: msg.prevMsgRef.timestamp,
|
|
84
|
+
sequenceNumber: msg.prevMsgRef.sequenceNumber
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
|
-
let
|
|
88
|
-
if (msg.
|
|
89
|
-
newGroupKey =
|
|
90
|
-
|
|
91
|
-
|
|
87
|
+
let body: StreamMessage['body']
|
|
88
|
+
if (msg.messageType === OldStreamMessageType.MESSAGE) {
|
|
89
|
+
let newGroupKey: GroupKey | undefined = undefined
|
|
90
|
+
if (msg.newGroupKey) {
|
|
91
|
+
newGroupKey = {
|
|
92
|
+
id: msg.newGroupKey.id,
|
|
93
|
+
data: msg.newGroupKey.data
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
body = {
|
|
97
|
+
oneofKind: 'contentMessage',
|
|
98
|
+
contentMessage: {
|
|
99
|
+
content: msg.content,
|
|
100
|
+
contentType: oldToNewContentType(msg.contentType),
|
|
101
|
+
encryptionType: oldToNewEncryptionType(msg.encryptionType),
|
|
102
|
+
groupKeyId: msg.groupKeyId ?? undefined,
|
|
103
|
+
newGroupKey
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
} else if (msg.messageType === OldStreamMessageType.GROUP_KEY_REQUEST) {
|
|
107
|
+
body = {
|
|
108
|
+
oneofKind: 'groupKeyRequest',
|
|
109
|
+
groupKeyRequest: GroupKeyRequest.fromBinary(msg.content)
|
|
92
110
|
}
|
|
111
|
+
} else if (msg.messageType === OldStreamMessageType.GROUP_KEY_RESPONSE) {
|
|
112
|
+
body = {
|
|
113
|
+
oneofKind: 'groupKeyResponse',
|
|
114
|
+
groupKeyResponse: GroupKeyResponse.fromBinary(msg.content)
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
throw new Error('invalid message type')
|
|
93
118
|
}
|
|
94
119
|
const translated: StreamMessage = {
|
|
95
120
|
messageId,
|
|
96
121
|
previousMessageRef,
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
encryptionType: oldToNewEncryptionType(msg.encryptionType),
|
|
101
|
-
groupKeyId: msg.groupKeyId ?? undefined,
|
|
102
|
-
newGroupKey,
|
|
103
|
-
signature: msg.signature
|
|
122
|
+
signature: msg.signature,
|
|
123
|
+
signatureType: oldToNewSignatureType(msg.signatureType),
|
|
124
|
+
body
|
|
104
125
|
}
|
|
105
126
|
return translated
|
|
106
127
|
}
|
|
107
128
|
|
|
108
129
|
static toClientProtocol(msg: StreamMessage): OldStreamMessage {
|
|
109
|
-
let content: Uint8Array
|
|
110
130
|
let messageType: OldStreamMessageType
|
|
111
|
-
|
|
131
|
+
let content: Uint8Array
|
|
132
|
+
let contentType: OldContentType = OldContentType.BINARY
|
|
133
|
+
let encryptionType: OldEncryptionType = OldEncryptionType.NONE
|
|
134
|
+
let newGroupKey: OldEncryptedGroupKey | undefined = undefined
|
|
135
|
+
let groupKeyId: string | undefined = undefined
|
|
136
|
+
if (msg.body.oneofKind === 'contentMessage') {
|
|
112
137
|
messageType = OldStreamMessageType.MESSAGE
|
|
113
|
-
content = msg.content
|
|
114
|
-
|
|
138
|
+
content = msg.body.contentMessage.content
|
|
139
|
+
contentType = newToOldContentType(msg.body.contentMessage.contentType)
|
|
140
|
+
encryptionType = newToOldEncryptionType(msg.body.contentMessage.encryptionType)
|
|
141
|
+
if (msg.body.contentMessage.newGroupKey) {
|
|
142
|
+
newGroupKey = new OldEncryptedGroupKey(
|
|
143
|
+
msg.body.contentMessage.newGroupKey.id,
|
|
144
|
+
msg.body.contentMessage.newGroupKey.data
|
|
145
|
+
)
|
|
146
|
+
}
|
|
147
|
+
groupKeyId = msg.body.contentMessage.groupKeyId
|
|
148
|
+
} else if (msg.body.oneofKind === 'groupKeyRequest') {
|
|
115
149
|
messageType = OldStreamMessageType.GROUP_KEY_REQUEST
|
|
116
150
|
try {
|
|
117
|
-
|
|
118
|
-
content = utf8ToBinary(GroupKeyRequestTranslator.toClientProtocol(parsedRequest).serialize())
|
|
151
|
+
content = GroupKeyRequest.toBinary(msg.body.groupKeyRequest)
|
|
119
152
|
} catch (err) {
|
|
120
153
|
throw new Error(`invalid group key request: ${err}`)
|
|
121
154
|
}
|
|
122
|
-
} else if (msg.
|
|
155
|
+
} else if (msg.body.oneofKind === 'groupKeyResponse') {
|
|
123
156
|
messageType = OldStreamMessageType.GROUP_KEY_RESPONSE
|
|
124
157
|
try {
|
|
125
|
-
|
|
126
|
-
content = utf8ToBinary(GroupKeyResponseTranslator.toClientProtocol(parsedResponse).serialize())
|
|
158
|
+
content = GroupKeyResponse.toBinary(msg.body.groupKeyResponse)
|
|
127
159
|
} catch (err) {
|
|
128
160
|
throw new Error(`invalid group key response: ${err}`)
|
|
129
161
|
}
|
|
@@ -142,23 +174,17 @@ export class StreamMessageTranslator {
|
|
|
142
174
|
if (msg.previousMessageRef) {
|
|
143
175
|
prevMsgRef = new OldMessageRef(Number(msg.previousMessageRef.timestamp), msg.previousMessageRef.sequenceNumber)
|
|
144
176
|
}
|
|
145
|
-
let newGroupKey: OldEncryptedGroupKey | undefined = undefined
|
|
146
|
-
if (msg.newGroupKey) {
|
|
147
|
-
newGroupKey = new OldEncryptedGroupKey(
|
|
148
|
-
msg.newGroupKey.id,
|
|
149
|
-
msg.newGroupKey.data,
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
177
|
const translated = new OldStreamMessage({
|
|
153
178
|
messageId,
|
|
154
179
|
prevMsgRef,
|
|
155
|
-
content,
|
|
156
180
|
messageType,
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
181
|
+
content,
|
|
182
|
+
contentType,
|
|
183
|
+
signature: msg.signature,
|
|
184
|
+
signatureType: newToOldSignatureType(msg.signatureType),
|
|
185
|
+
encryptionType,
|
|
186
|
+
groupKeyId,
|
|
187
|
+
newGroupKey
|
|
162
188
|
})
|
|
163
189
|
return translated
|
|
164
190
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import {
|
|
2
|
+
StreamMessage as OldStreamMessage,
|
|
3
|
+
GroupKeyRequest as OldGroupKeyRequest,
|
|
4
|
+
GroupKeyResponse as OldGroupKeyResponse
|
|
5
|
+
} from '@streamr/protocol'
|
|
6
|
+
import { StreamMessageTranslator } from './StreamMessageTranslator'
|
|
7
|
+
import {
|
|
8
|
+
StreamMessage,
|
|
9
|
+
GroupKeyRequest,
|
|
10
|
+
GroupKeyResponse
|
|
11
|
+
} from '../../../proto/packages/trackerless-network/protos/NetworkRpc'
|
|
12
|
+
import { GroupKeyResponseTranslator } from './GroupKeyResponseTranslator'
|
|
13
|
+
import { GroupKeyRequestTranslator } from './GroupKeyRequestTranslator'
|
|
14
|
+
|
|
15
|
+
export function convertStreamMessageToBytes(oldStreamMessage: OldStreamMessage): Uint8Array {
|
|
16
|
+
return StreamMessage.toBinary(StreamMessageTranslator.toProtobuf(oldStreamMessage))
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function convertBytesToStreamMessage(bytes: Uint8Array): OldStreamMessage {
|
|
20
|
+
return StreamMessageTranslator.toClientProtocol(StreamMessage.fromBinary(bytes))
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export const convertGroupKeyRequestToBytes = (oldGroupKeyRequest: OldGroupKeyRequest): Uint8Array => {
|
|
24
|
+
return GroupKeyRequest.toBinary(GroupKeyRequestTranslator.toProtobuf(oldGroupKeyRequest))
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export const convertBytesToGroupKeyRequest = (bytes: Uint8Array): OldGroupKeyRequest => {
|
|
28
|
+
return GroupKeyRequestTranslator.toClientProtocol(GroupKeyRequest.fromBinary(bytes))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export const convertGroupKeyResponseToBytes = (oldGroupKeyResponse: OldGroupKeyResponse): Uint8Array => {
|
|
32
|
+
return GroupKeyResponse.toBinary(GroupKeyResponseTranslator.toProtobuf(oldGroupKeyResponse))
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export const convertBytesToGroupKeyResponse = (bytes: Uint8Array): OldGroupKeyResponse => {
|
|
36
|
+
return GroupKeyResponseTranslator.toClientProtocol(GroupKeyResponse.fromBinary(bytes))
|
|
37
|
+
}
|