@streamr/trackerless-network 100.0.0-pretestnet.6 → 100.0.0-rc.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/README.md +57 -0
- package/dist/package.json +12 -12
- 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 +19 -16
- package/dist/src/logic/NodeList.js.map +1 -1
- package/dist/src/logic/RandomGraphNode.d.ts +26 -22
- package/dist/src/logic/RandomGraphNode.js +85 -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 +12 -12
- 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 +26 -27
- package/src/logic/RandomGraphNode.ts +158 -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,20 +1,19 @@
|
|
|
1
|
-
import { NodeList } from '../../src/logic/NodeList'
|
|
2
|
-
import { DeliveryRpcRemote } from '../../src/logic/DeliveryRpcRemote'
|
|
3
1
|
import {
|
|
4
|
-
PeerDescriptor,
|
|
5
2
|
ListeningRpcCommunicator,
|
|
6
|
-
Simulator,
|
|
7
|
-
SimulatorTransport,
|
|
8
3
|
NodeType,
|
|
4
|
+
PeerDescriptor,
|
|
5
|
+
createRandomDhtAddress,
|
|
6
|
+
getDhtAddressFromRaw,
|
|
7
|
+
getNodeIdFromPeerDescriptor,
|
|
9
8
|
} from '@streamr/dht'
|
|
10
|
-
import { DeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
11
|
-
import { toProtoRpcClient } from '@streamr/proto-rpc'
|
|
12
|
-
import { expect } from 'expect'
|
|
13
|
-
import { NodeID, getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
14
|
-
import { createMockPeerDescriptor, createRandomNodeId } from '../utils/utils'
|
|
15
|
-
import { binaryToHex } from '@streamr/utils'
|
|
16
9
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
10
|
+
import { expect } from 'expect'
|
|
11
|
+
import { DeliveryRpcRemote } from '../../src/logic/DeliveryRpcRemote'
|
|
12
|
+
import { NodeList } from '../../src/logic/NodeList'
|
|
17
13
|
import { formStreamPartDeliveryServiceId } from '../../src/logic/formStreamPartDeliveryServiceId'
|
|
14
|
+
import { DeliveryRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
15
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
16
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
18
17
|
|
|
19
18
|
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
20
19
|
|
|
@@ -27,115 +26,92 @@ describe('NodeList', () => {
|
|
|
27
26
|
new Uint8Array([1, 1, 4]),
|
|
28
27
|
new Uint8Array([1, 1, 5])
|
|
29
28
|
]
|
|
30
|
-
const ownId =
|
|
29
|
+
const ownId = createRandomDhtAddress()
|
|
31
30
|
let nodeList: NodeList
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const createRemoteGraphNode = async (peerDescriptor: PeerDescriptor) => {
|
|
36
|
-
const mockTransport = new SimulatorTransport(peerDescriptor, simulator)
|
|
37
|
-
await mockTransport.start()
|
|
38
|
-
const mockCommunicator = new ListeningRpcCommunicator(formStreamPartDeliveryServiceId(streamPartId), mockTransport)
|
|
39
|
-
const mockClient = mockCommunicator.getRpcClientTransport()
|
|
40
|
-
|
|
41
|
-
mockTransports.push(mockTransport)
|
|
31
|
+
|
|
32
|
+
const createRemoteGraphNode = (peerDescriptor: PeerDescriptor) => {
|
|
33
|
+
const mockCommunicator = new ListeningRpcCommunicator(formStreamPartDeliveryServiceId(streamPartId), new MockTransport())
|
|
42
34
|
return new DeliveryRpcRemote(
|
|
43
35
|
createMockPeerDescriptor(),
|
|
44
36
|
peerDescriptor,
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
mockCommunicator,
|
|
38
|
+
DeliveryRpcClient
|
|
47
39
|
)
|
|
48
40
|
}
|
|
49
41
|
|
|
50
|
-
beforeEach(
|
|
51
|
-
simulator = new Simulator()
|
|
52
|
-
mockTransports = []
|
|
42
|
+
beforeEach(() => {
|
|
53
43
|
nodeList = new NodeList(ownId, 6)
|
|
54
44
|
for (const id of ids) {
|
|
55
45
|
const peerDescriptor: PeerDescriptor = {
|
|
56
|
-
|
|
46
|
+
nodeId: id,
|
|
57
47
|
type: NodeType.NODEJS
|
|
58
48
|
}
|
|
59
|
-
nodeList.add(
|
|
60
|
-
}
|
|
61
|
-
})
|
|
62
|
-
|
|
63
|
-
afterEach(async () => {
|
|
64
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
65
|
-
for (let i = 0; i < mockTransports.length; i++) {
|
|
66
|
-
await mockTransports[i].stop()
|
|
49
|
+
nodeList.add(createRemoteGraphNode(peerDescriptor))
|
|
67
50
|
}
|
|
68
|
-
simulator.stop()
|
|
69
51
|
})
|
|
70
52
|
|
|
71
|
-
it('add',
|
|
53
|
+
it('add', () => {
|
|
72
54
|
const newDescriptor = {
|
|
73
|
-
|
|
55
|
+
nodeId: new Uint8Array([1, 2, 3]),
|
|
74
56
|
type: NodeType.NODEJS
|
|
75
57
|
}
|
|
76
|
-
const newNode =
|
|
58
|
+
const newNode = createRemoteGraphNode(newDescriptor)
|
|
77
59
|
nodeList.add(newNode)
|
|
78
|
-
expect(nodeList.
|
|
60
|
+
expect(nodeList.has(getNodeIdFromPeerDescriptor(newDescriptor))).toEqual(true)
|
|
79
61
|
|
|
80
62
|
const newDescriptor2 = {
|
|
81
|
-
|
|
63
|
+
nodeId: new Uint8Array([1, 2, 4]),
|
|
82
64
|
type: NodeType.NODEJS
|
|
83
65
|
}
|
|
84
|
-
const newNode2 =
|
|
66
|
+
const newNode2 = createRemoteGraphNode(newDescriptor2)
|
|
85
67
|
nodeList.add(newNode2)
|
|
86
|
-
expect(nodeList.
|
|
68
|
+
expect(nodeList.has(getNodeIdFromPeerDescriptor(newDescriptor2))).toEqual(false)
|
|
87
69
|
})
|
|
88
70
|
|
|
89
71
|
it('remove', () => {
|
|
90
|
-
const toRemove = nodeList.
|
|
91
|
-
nodeList.remove(toRemove!.getPeerDescriptor())
|
|
92
|
-
expect(nodeList.hasNode(toRemove!.getPeerDescriptor())).toEqual(false)
|
|
93
|
-
})
|
|
94
|
-
|
|
95
|
-
it('removeById', () => {
|
|
96
|
-
const toRemove = nodeList.getClosest([])
|
|
72
|
+
const toRemove = nodeList.getFirst([])
|
|
97
73
|
const nodeId = getNodeIdFromPeerDescriptor(toRemove!.getPeerDescriptor())
|
|
98
|
-
nodeList.
|
|
99
|
-
expect(nodeList.
|
|
74
|
+
nodeList.remove(nodeId)
|
|
75
|
+
expect(nodeList.has(nodeId)).toEqual(false)
|
|
100
76
|
})
|
|
101
77
|
|
|
102
|
-
it('
|
|
103
|
-
const closest = nodeList.
|
|
78
|
+
it('getFirst', () => {
|
|
79
|
+
const closest = nodeList.getFirst([])
|
|
104
80
|
expect(getNodeIdFromPeerDescriptor(closest!.getPeerDescriptor()))
|
|
105
|
-
.toEqual(
|
|
81
|
+
.toEqual(getDhtAddressFromRaw(new Uint8Array([1, 1, 1])))
|
|
106
82
|
})
|
|
107
83
|
|
|
108
|
-
it('
|
|
109
|
-
const closest = nodeList.
|
|
84
|
+
it('getFirst with exclude', () => {
|
|
85
|
+
const closest = nodeList.getFirst([getDhtAddressFromRaw(new Uint8Array([1, 1, 1]))])
|
|
110
86
|
expect(getNodeIdFromPeerDescriptor(closest!.getPeerDescriptor()))
|
|
111
|
-
.toEqual(
|
|
87
|
+
.toEqual(getDhtAddressFromRaw(new Uint8Array([1, 1, 2])))
|
|
112
88
|
})
|
|
113
89
|
|
|
114
|
-
it('
|
|
115
|
-
const closest = nodeList.
|
|
90
|
+
it('getLast', () => {
|
|
91
|
+
const closest = nodeList.getLast([])
|
|
116
92
|
expect(getNodeIdFromPeerDescriptor(closest!.getPeerDescriptor()))
|
|
117
|
-
.toEqual(
|
|
93
|
+
.toEqual(getDhtAddressFromRaw(new Uint8Array([1, 1, 5])))
|
|
118
94
|
})
|
|
119
95
|
|
|
120
|
-
it('
|
|
121
|
-
const closest = nodeList.
|
|
96
|
+
it('getLast with exclude', () => {
|
|
97
|
+
const closest = nodeList.getLast([getDhtAddressFromRaw(new Uint8Array([1, 1, 5]))])
|
|
122
98
|
expect(getNodeIdFromPeerDescriptor(closest!.getPeerDescriptor()))
|
|
123
|
-
.toEqual(
|
|
99
|
+
.toEqual(getDhtAddressFromRaw(new Uint8Array([1, 1, 4])))
|
|
124
100
|
})
|
|
125
101
|
|
|
126
|
-
it('
|
|
127
|
-
const results = nodeList.
|
|
128
|
-
expect(results).toEqual([nodeList.
|
|
102
|
+
it('getFirstAndLast', () => {
|
|
103
|
+
const results = nodeList.getFirstAndLast([])
|
|
104
|
+
expect(results).toEqual([nodeList.getFirst([]), nodeList.getLast([])])
|
|
129
105
|
})
|
|
130
106
|
|
|
131
|
-
it('
|
|
107
|
+
it('getFirst empty', () => {
|
|
132
108
|
const emptyList = new NodeList(ownId, 2)
|
|
133
|
-
expect(emptyList.
|
|
109
|
+
expect(emptyList.getFirst([])).toBeUndefined()
|
|
134
110
|
})
|
|
135
111
|
|
|
136
|
-
it('
|
|
112
|
+
it('getLast empty', () => {
|
|
137
113
|
const emptyList = new NodeList(ownId, 2)
|
|
138
|
-
expect(emptyList.
|
|
114
|
+
expect(emptyList.getLast([])).toBeUndefined()
|
|
139
115
|
})
|
|
140
116
|
|
|
141
117
|
it('getRandom empty', () => {
|
|
@@ -143,19 +119,40 @@ describe('NodeList', () => {
|
|
|
143
119
|
expect(emptyList.getRandom([])).toBeUndefined()
|
|
144
120
|
})
|
|
145
121
|
|
|
146
|
-
it('
|
|
122
|
+
it('getFirstAndLast empty', () => {
|
|
147
123
|
const emptyList = new NodeList(ownId, 2)
|
|
148
|
-
expect(emptyList.
|
|
124
|
+
expect(emptyList.getFirstAndLast([])).toEqual([])
|
|
149
125
|
})
|
|
150
126
|
|
|
151
|
-
it('
|
|
152
|
-
const results = nodeList.
|
|
153
|
-
|
|
154
|
-
|
|
127
|
+
it('getFirstAndLast with exclude', () => {
|
|
128
|
+
const results = nodeList.getFirstAndLast([
|
|
129
|
+
getDhtAddressFromRaw(new Uint8Array([1, 1, 1])),
|
|
130
|
+
getDhtAddressFromRaw(new Uint8Array([1, 1, 5]))
|
|
155
131
|
])
|
|
156
132
|
expect(results).toEqual([
|
|
157
|
-
nodeList.
|
|
158
|
-
nodeList.
|
|
133
|
+
nodeList.getFirst([getDhtAddressFromRaw(new Uint8Array([1, 1, 1]))]),
|
|
134
|
+
nodeList.getLast([getDhtAddressFromRaw(new Uint8Array([1, 1, 5]))])
|
|
159
135
|
])
|
|
160
136
|
})
|
|
137
|
+
|
|
138
|
+
it('items are in insertion order', () => {
|
|
139
|
+
const list = new NodeList(createRandomDhtAddress(), 100)
|
|
140
|
+
const item1 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
141
|
+
const item2 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
142
|
+
const item3 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
143
|
+
const item4 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
144
|
+
const item5 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
145
|
+
const item6 = createRemoteGraphNode(createMockPeerDescriptor())
|
|
146
|
+
list.add(item2)
|
|
147
|
+
list.add(item3)
|
|
148
|
+
list.add(item1)
|
|
149
|
+
list.add(item6)
|
|
150
|
+
list.add(item4)
|
|
151
|
+
list.add(item5)
|
|
152
|
+
expect(list.getFirst([])!).toEqual(item2)
|
|
153
|
+
expect(list.getLast([])!).toEqual(item5)
|
|
154
|
+
// the order doesn't change if item re-added
|
|
155
|
+
list.add(item4)
|
|
156
|
+
expect(list.getLast([])!).toEqual(item5)
|
|
157
|
+
})
|
|
161
158
|
})
|
|
@@ -2,12 +2,12 @@ import {
|
|
|
2
2
|
ContentType,
|
|
3
3
|
EncryptionType,
|
|
4
4
|
MessageID,
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
SignatureType,
|
|
6
|
+
StreamMessage
|
|
7
7
|
} from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
8
8
|
import { Propagation } from '../../src/logic/propagation/Propagation'
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { hexToBinary, toEthereumAddress, utf8ToBinary, wait } from '@streamr/utils'
|
|
10
|
+
import { DhtAddress } from '@streamr/dht'
|
|
11
11
|
|
|
12
12
|
const PUBLISHER_ID = toEthereumAddress('0x1111111111111111111111111111111111111111')
|
|
13
13
|
|
|
@@ -22,25 +22,30 @@ function makeMsg(streamId: string, partition: number, ts: number, msgNo: number)
|
|
|
22
22
|
}
|
|
23
23
|
return {
|
|
24
24
|
messageId,
|
|
25
|
-
content: new Uint8Array([1]),
|
|
26
|
-
contentType: ContentType.JSON,
|
|
27
|
-
encryptionType: EncryptionType.NONE,
|
|
28
25
|
signature: hexToBinary('0x1111'),
|
|
29
|
-
|
|
26
|
+
signatureType: SignatureType.SECP256K1,
|
|
27
|
+
body: {
|
|
28
|
+
oneofKind: 'contentMessage',
|
|
29
|
+
contentMessage: {
|
|
30
|
+
content: new Uint8Array([1]),
|
|
31
|
+
contentType: ContentType.JSON,
|
|
32
|
+
encryptionType: EncryptionType.NONE
|
|
33
|
+
}
|
|
34
|
+
}
|
|
30
35
|
}
|
|
31
36
|
}
|
|
32
37
|
|
|
33
38
|
const TTL = 100
|
|
34
39
|
|
|
35
|
-
const N1 = 'n1' as
|
|
36
|
-
const N2 = 'n2' as
|
|
37
|
-
const N3 = 'n3' as
|
|
38
|
-
const N4 = 'n4' as
|
|
39
|
-
const N5 = 'n5' as
|
|
40
|
+
const N1 = 'n1' as DhtAddress
|
|
41
|
+
const N2 = 'n2' as DhtAddress
|
|
42
|
+
const N3 = 'n3' as DhtAddress
|
|
43
|
+
const N4 = 'n4' as DhtAddress
|
|
44
|
+
const N5 = 'n5' as DhtAddress
|
|
40
45
|
|
|
41
46
|
describe(Propagation, () => {
|
|
42
|
-
let getNeighbors: jest.Mock<ReadonlyArray<
|
|
43
|
-
let sendToNeighbor: jest.Mock<Promise<void>, [
|
|
47
|
+
let getNeighbors: jest.Mock<ReadonlyArray<DhtAddress>, [string]>
|
|
48
|
+
let sendToNeighbor: jest.Mock<Promise<void>, [DhtAddress, StreamMessage]>
|
|
44
49
|
let propagation: Propagation
|
|
45
50
|
|
|
46
51
|
beforeEach(() => {
|
|
@@ -80,7 +85,7 @@ describe(Propagation, () => {
|
|
|
80
85
|
describe('#onNeighborJoined', () => {
|
|
81
86
|
let msg: StreamMessage
|
|
82
87
|
|
|
83
|
-
async function setUpAndFeed(neighbors:
|
|
88
|
+
async function setUpAndFeed(neighbors: DhtAddress[]): Promise<void> {
|
|
84
89
|
getNeighbors.mockReturnValueOnce(neighbors)
|
|
85
90
|
msg = makeMsg('s1', 0, 1000, 1)
|
|
86
91
|
propagation.feedUnseenMessage(msg, [...getNeighbors('s1#0')], N2)
|
|
@@ -1,30 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { RpcCommunicator } from '@streamr/proto-rpc'
|
|
2
2
|
import { randomEthereumAddress } from '@streamr/test-utils'
|
|
3
3
|
import { hexToBinary } from '@streamr/utils'
|
|
4
4
|
import { ProxyConnectionRpcRemote } from '../../src/logic/proxy/ProxyConnectionRpcRemote'
|
|
5
|
-
import { ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
5
|
+
import { ProxyConnectionRequest, ProxyDirection } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
6
|
+
import { ProxyConnectionRpcClient } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc.client'
|
|
6
7
|
import { createMockPeerDescriptor } from '../utils/utils'
|
|
7
8
|
|
|
8
9
|
describe('ProxyConnectionRpcRemote', () => {
|
|
9
10
|
|
|
10
|
-
it('happy path', () => {
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
it('happy path', async () => {
|
|
12
|
+
const onOutgoingMessage = jest.fn()
|
|
13
|
+
const rpcCommunicator = new RpcCommunicator()
|
|
14
|
+
rpcCommunicator.setOutgoingMessageListener(onOutgoingMessage)
|
|
14
15
|
const clientPeerDescriptor = createMockPeerDescriptor()
|
|
15
16
|
const serverPeerDescriptor = createMockPeerDescriptor()
|
|
16
17
|
const rpcRemote = new ProxyConnectionRpcRemote(
|
|
17
18
|
clientPeerDescriptor,
|
|
18
19
|
serverPeerDescriptor,
|
|
19
|
-
|
|
20
|
-
|
|
20
|
+
rpcCommunicator,
|
|
21
|
+
ProxyConnectionRpcClient
|
|
21
22
|
)
|
|
23
|
+
|
|
22
24
|
const userId = randomEthereumAddress()
|
|
23
|
-
rpcRemote.requestConnection(ProxyDirection.PUBLISH, userId)
|
|
24
|
-
|
|
25
|
+
await rpcRemote.requestConnection(ProxyDirection.PUBLISH, userId)
|
|
26
|
+
|
|
27
|
+
const [rpcMessage, _, callContext] = onOutgoingMessage.mock.calls[0]
|
|
28
|
+
const request = ProxyConnectionRequest.fromBinary(rpcMessage.body.value)
|
|
29
|
+
expect(request).toEqual({
|
|
25
30
|
direction: ProxyDirection.PUBLISH,
|
|
26
|
-
userId: hexToBinary(userId)
|
|
27
|
-
}
|
|
31
|
+
userId: Uint8Array.from(hexToBinary(userId))
|
|
32
|
+
})
|
|
33
|
+
expect(callContext).toMatchObject({
|
|
28
34
|
sourceDescriptor: clientPeerDescriptor,
|
|
29
35
|
targetDescriptor: serverPeerDescriptor,
|
|
30
36
|
timeout: 5000
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { waitForCondition } from '@streamr/utils'
|
|
2
|
-
import { getNodeIdFromPeerDescriptor } from '../../src/identifiers'
|
|
3
2
|
import { NodeList } from '../../src/logic/NodeList'
|
|
4
3
|
import { RandomGraphNode } from '../../src/logic/RandomGraphNode'
|
|
5
4
|
import { createRandomGraphNode } from '../../src/logic/createRandomGraphNode'
|
|
@@ -10,13 +9,14 @@ import { MockNeighborUpdateManager } from '../utils/mock/MockNeighborUpdateManag
|
|
|
10
9
|
import { MockTransport } from '../utils/mock/Transport'
|
|
11
10
|
import { createMockPeerDescriptor, createMockDeliveryRpcRemote, mockConnectionLocker } from '../utils/utils'
|
|
12
11
|
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
12
|
+
import { getNodeIdFromPeerDescriptor } from '@streamr/dht'
|
|
13
13
|
|
|
14
14
|
describe('RandomGraphNode', () => {
|
|
15
15
|
|
|
16
16
|
let randomGraphNode: RandomGraphNode
|
|
17
17
|
const peerDescriptor = createMockPeerDescriptor()
|
|
18
18
|
|
|
19
|
-
let
|
|
19
|
+
let neighbors: NodeList
|
|
20
20
|
let nearbyNodeView: NodeList
|
|
21
21
|
let randomNodeView: NodeList
|
|
22
22
|
|
|
@@ -25,23 +25,25 @@ describe('RandomGraphNode', () => {
|
|
|
25
25
|
beforeEach(async () => {
|
|
26
26
|
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
neighbors = new NodeList(nodeId, 10)
|
|
29
29
|
randomNodeView = new NodeList(nodeId, 10)
|
|
30
30
|
nearbyNodeView = new NodeList(nodeId, 10)
|
|
31
31
|
layer1Node = new MockLayer1Node()
|
|
32
32
|
|
|
33
33
|
randomGraphNode = createRandomGraphNode({
|
|
34
|
-
|
|
34
|
+
neighbors,
|
|
35
35
|
randomNodeView,
|
|
36
36
|
nearbyNodeView,
|
|
37
37
|
transport: new MockTransport(),
|
|
38
38
|
localPeerDescriptor: peerDescriptor,
|
|
39
39
|
layer1Node,
|
|
40
40
|
connectionLocker: mockConnectionLocker,
|
|
41
|
-
handshaker: new MockHandshaker(),
|
|
42
|
-
neighborUpdateManager: new MockNeighborUpdateManager(),
|
|
43
|
-
neighborFinder: new MockNeighborFinder(),
|
|
44
|
-
streamPartId: StreamPartIDUtils.parse('stream#0')
|
|
41
|
+
handshaker: new MockHandshaker() as any,
|
|
42
|
+
neighborUpdateManager: new MockNeighborUpdateManager() as any,
|
|
43
|
+
neighborFinder: new MockNeighborFinder() as any,
|
|
44
|
+
streamPartId: StreamPartIDUtils.parse('stream#0'),
|
|
45
|
+
isLocalNodeEntryPoint: () => false
|
|
46
|
+
|
|
45
47
|
})
|
|
46
48
|
await randomGraphNode.start()
|
|
47
49
|
})
|
|
@@ -50,12 +52,11 @@ describe('RandomGraphNode', () => {
|
|
|
50
52
|
randomGraphNode.stop()
|
|
51
53
|
})
|
|
52
54
|
|
|
53
|
-
it('
|
|
55
|
+
it('getNeighbors', () => {
|
|
54
56
|
const mockRemote = createMockDeliveryRpcRemote()
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
expect(
|
|
58
|
-
targetNeighbors.remove(mockRemote.getPeerDescriptor())
|
|
57
|
+
neighbors.add(mockRemote)
|
|
58
|
+
const result = randomGraphNode.getNeighbors()
|
|
59
|
+
expect(getNodeIdFromPeerDescriptor(result[0])).toEqual(getNodeIdFromPeerDescriptor(mockRemote.getPeerDescriptor()))
|
|
59
60
|
})
|
|
60
61
|
|
|
61
62
|
it('getNearbyNodeView', () => {
|
|
@@ -65,19 +66,19 @@ describe('RandomGraphNode', () => {
|
|
|
65
66
|
expect(ids[0]).toEqual(getNodeIdFromPeerDescriptor(mockRemote.getPeerDescriptor()))
|
|
66
67
|
})
|
|
67
68
|
|
|
68
|
-
it('Adds Closest Nodes from layer1
|
|
69
|
+
it('Adds Closest Nodes from layer1 contactAdded event to nearbyNodeView', async () => {
|
|
69
70
|
const peerDescriptor1 = createMockPeerDescriptor()
|
|
70
71
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
71
|
-
layer1Node.emit('
|
|
72
|
+
layer1Node.emit('contactAdded', peerDescriptor1, [peerDescriptor1, peerDescriptor2])
|
|
72
73
|
await waitForCondition(() => nearbyNodeView.size() === 2)
|
|
73
74
|
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor1))).toBeTruthy()
|
|
74
75
|
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
75
76
|
})
|
|
76
77
|
|
|
77
|
-
it('Adds Random Nodes from layer1
|
|
78
|
+
it('Adds Random Nodes from layer1 randomContactAdded event to randomNodeView', async () => {
|
|
78
79
|
const peerDescriptor1 = createMockPeerDescriptor()
|
|
79
80
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
80
|
-
layer1Node.emit('
|
|
81
|
+
layer1Node.emit('randomContactAdded', peerDescriptor1, [peerDescriptor1, peerDescriptor2])
|
|
81
82
|
await waitForCondition(() => randomNodeView.size() === 2)
|
|
82
83
|
expect(randomNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor1))).toBeTruthy()
|
|
83
84
|
expect(randomNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
@@ -87,10 +88,12 @@ describe('RandomGraphNode', () => {
|
|
|
87
88
|
const peerDescriptor1 = createMockPeerDescriptor()
|
|
88
89
|
const peerDescriptor2 = createMockPeerDescriptor()
|
|
89
90
|
layer1Node.addNewRandomPeerToKBucket()
|
|
90
|
-
layer1Node.emit('
|
|
91
|
-
await waitForCondition(() =>
|
|
91
|
+
layer1Node.emit('contactAdded', peerDescriptor1, [peerDescriptor1, peerDescriptor2])
|
|
92
|
+
await waitForCondition(() => {
|
|
93
|
+
return nearbyNodeView.size() === 3
|
|
94
|
+
}, 20000)
|
|
92
95
|
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor1))).toBeTruthy()
|
|
93
96
|
expect(nearbyNodeView.get(getNodeIdFromPeerDescriptor(peerDescriptor2))).toBeTruthy()
|
|
94
|
-
})
|
|
97
|
+
}, 25000)
|
|
95
98
|
|
|
96
99
|
})
|
|
@@ -3,11 +3,12 @@ import {
|
|
|
3
3
|
MessageID,
|
|
4
4
|
StreamMessage as OldStreamMessage,
|
|
5
5
|
StreamMessageType as OldStreamMessageType,
|
|
6
|
-
StreamPartIDUtils
|
|
6
|
+
StreamPartIDUtils,
|
|
7
|
+
ContentType,
|
|
8
|
+
SignatureType
|
|
7
9
|
} from '@streamr/protocol'
|
|
8
10
|
import { binaryToHex, binaryToUtf8, hexToBinary, toEthereumAddress, utf8ToBinary } from '@streamr/utils'
|
|
9
11
|
import { StreamMessageTranslator } from '../../src/logic/protocol-integration/stream-message/StreamMessageTranslator'
|
|
10
|
-
import { StreamMessageType } from '../../src/proto/packages/trackerless-network/protos/NetworkRpc'
|
|
11
12
|
import { createStreamMessage } from '../utils/utils'
|
|
12
13
|
|
|
13
14
|
const STREAM_PART_ID = StreamPartIDUtils.parse('TEST#0')
|
|
@@ -31,10 +32,11 @@ describe('StreamMessageTranslator', () => {
|
|
|
31
32
|
)
|
|
32
33
|
const oldProtocolMsg = new OldStreamMessage({
|
|
33
34
|
messageId,
|
|
34
|
-
prevMsgRef: null,
|
|
35
35
|
content: utf8ToBinary(JSON.stringify({ hello: 'WORLD' })),
|
|
36
|
+
contentType: ContentType.JSON,
|
|
36
37
|
messageType: OldStreamMessageType.MESSAGE,
|
|
37
38
|
encryptionType: EncryptionType.NONE,
|
|
39
|
+
signatureType: SignatureType.SECP256K1,
|
|
38
40
|
signature,
|
|
39
41
|
})
|
|
40
42
|
|
|
@@ -46,10 +48,10 @@ describe('StreamMessageTranslator', () => {
|
|
|
46
48
|
expect(translated.messageId!.sequenceNumber).toEqual(0)
|
|
47
49
|
expect(binaryToHex(translated.messageId!.publisherId, true)).toEqual('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
48
50
|
expect(translated.previousMessageRef).toEqual(undefined)
|
|
49
|
-
expect(translated.
|
|
50
|
-
expect(translated.groupKeyId).toEqual(undefined)
|
|
51
|
+
expect(translated.body.oneofKind).toEqual('contentMessage')
|
|
52
|
+
expect((translated.body as any).contentMessage.groupKeyId).toEqual(undefined)
|
|
51
53
|
expect(translated.signature).toStrictEqual(signature)
|
|
52
|
-
expect(JSON.parse(binaryToUtf8(translated.content))).toEqual({ hello: 'WORLD' })
|
|
54
|
+
expect(JSON.parse(binaryToUtf8((translated.body as any).contentMessage.content))).toEqual({ hello: 'WORLD' })
|
|
53
55
|
})
|
|
54
56
|
|
|
55
57
|
it('translates protobuf to old protocol', () => {
|
|
@@ -59,10 +61,10 @@ describe('StreamMessageTranslator', () => {
|
|
|
59
61
|
expect(translated.messageId.timestamp).toBeGreaterThanOrEqual(0)
|
|
60
62
|
expect(translated.messageId.sequenceNumber).toEqual(0)
|
|
61
63
|
expect(translated.getPublisherId()).toEqual('0xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa')
|
|
62
|
-
expect(translated.prevMsgRef).toEqual(
|
|
64
|
+
expect(translated.prevMsgRef).toEqual(undefined)
|
|
63
65
|
expect(translated.messageType).toEqual(OldStreamMessageType.MESSAGE)
|
|
64
66
|
expect(translated.contentType).toEqual(0)
|
|
65
|
-
expect(translated.groupKeyId).toEqual(
|
|
67
|
+
expect(translated.groupKeyId).toEqual(undefined)
|
|
66
68
|
expect(translated.signature).toStrictEqual(signature)
|
|
67
69
|
expect(translated.getParsedContent()).toEqual({ hello: 'WORLD' })
|
|
68
70
|
})
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
2
|
+
import { streamPartIdToDataKey } from '../../src/logic/EntryPointDiscovery'
|
|
3
|
+
|
|
4
|
+
describe('StreamPartIDtoDataKey', () => {
|
|
5
|
+
|
|
6
|
+
it('generated key length is correct (160 bits)', () => {
|
|
7
|
+
const streamPartId = StreamPartIDUtils.parse('stream#0')
|
|
8
|
+
const dataKey = streamPartIdToDataKey(streamPartId)
|
|
9
|
+
expect(dataKey.length).toEqual(40)
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
})
|
|
@@ -56,6 +56,7 @@ describe('StreamrNode', () => {
|
|
|
56
56
|
node.broadcast(message)
|
|
57
57
|
await waitForCondition(() => node.hasStreamPart(streamPartId))
|
|
58
58
|
})
|
|
59
|
+
|
|
59
60
|
})
|
|
60
61
|
|
|
61
62
|
describe('proxied stream', () => {
|
|
@@ -93,4 +94,5 @@ describe('StreamrNode', () => {
|
|
|
93
94
|
expect(node.isProxiedStreamPart(streamPartId)).toBe(false)
|
|
94
95
|
})
|
|
95
96
|
})
|
|
97
|
+
|
|
96
98
|
})
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { StreamPartIDUtils } from '@streamr/protocol'
|
|
2
|
+
import { TemporaryConnectionRpcLocal } from '../../src/logic/temporary-connection/TemporaryConnectionRpcLocal'
|
|
3
|
+
import { MockTransport } from '../utils/mock/Transport'
|
|
4
|
+
import { createMockPeerDescriptor } from '../utils/utils'
|
|
5
|
+
import { ListeningRpcCommunicator, getDhtAddressFromRaw } from '@streamr/dht'
|
|
6
|
+
|
|
7
|
+
describe('TemporaryConnectionRpcLocal', () => {
|
|
8
|
+
|
|
9
|
+
const peerDescriptor = createMockPeerDescriptor()
|
|
10
|
+
let rpcCommunicator: ListeningRpcCommunicator
|
|
11
|
+
let rpcLocal: TemporaryConnectionRpcLocal
|
|
12
|
+
|
|
13
|
+
beforeEach(() => {
|
|
14
|
+
rpcCommunicator = new ListeningRpcCommunicator('mock', new MockTransport())
|
|
15
|
+
rpcLocal = new TemporaryConnectionRpcLocal({
|
|
16
|
+
localPeerDescriptor: peerDescriptor,
|
|
17
|
+
rpcCommunicator,
|
|
18
|
+
streamPartId: StreamPartIDUtils.parse('mock#0'),
|
|
19
|
+
connectionLocker: {
|
|
20
|
+
weakLockConnection: jest.fn(),
|
|
21
|
+
weakUnlockConnection: jest.fn()
|
|
22
|
+
} as any
|
|
23
|
+
})
|
|
24
|
+
})
|
|
25
|
+
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
rpcCommunicator.destroy()
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
it('Open and Close Connection', async () => {
|
|
31
|
+
const caller = createMockPeerDescriptor()
|
|
32
|
+
await rpcLocal.openConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
33
|
+
expect(rpcLocal.getNodes().get(getDhtAddressFromRaw(caller.nodeId))).toBeDefined()
|
|
34
|
+
await rpcLocal.closeConnection({}, { incomingSourceDescriptor: caller } as any)
|
|
35
|
+
expect(rpcLocal.getNodes().get(getDhtAddressFromRaw(caller.nodeId))).toBeUndefined()
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
})
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ContentType,
|
|
3
|
+
EncryptionType,
|
|
4
|
+
MessageID,
|
|
5
|
+
MessageRef,
|
|
6
|
+
SignatureType,
|
|
7
|
+
StreamMessage,
|
|
8
|
+
toStreamID
|
|
9
|
+
} from '@streamr/protocol'
|
|
10
|
+
import { toEthereumAddress } from '@streamr/utils'
|
|
11
|
+
import { convertBytesToStreamMessage, convertStreamMessageToBytes } from '../../src/exports'
|
|
12
|
+
|
|
13
|
+
describe('oldStreamMessageBinaryUtils', () => {
|
|
14
|
+
it('convertStreamMessageToBytes and convertBytesToStreamMessage', () => {
|
|
15
|
+
const streamMessage = new StreamMessage({
|
|
16
|
+
messageId: new MessageID(
|
|
17
|
+
toStreamID('test.ens/foobar'),
|
|
18
|
+
0,
|
|
19
|
+
10001,
|
|
20
|
+
0,
|
|
21
|
+
toEthereumAddress('0x1234567890123456789012345678901234567890'),
|
|
22
|
+
'msgChainId'
|
|
23
|
+
),
|
|
24
|
+
prevMsgRef: new MessageRef(10000, 1),
|
|
25
|
+
content: new Uint8Array([1, 2, 3]),
|
|
26
|
+
contentType: ContentType.BINARY,
|
|
27
|
+
encryptionType: EncryptionType.NONE,
|
|
28
|
+
groupKeyId: '0x1234567890123456789012345678901234567890',
|
|
29
|
+
signatureType: SignatureType.SECP256K1,
|
|
30
|
+
signature: new Uint8Array([7, 8, 9])
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
const bytes = convertStreamMessageToBytes(streamMessage)
|
|
34
|
+
expect(bytes).toBeInstanceOf(Uint8Array)
|
|
35
|
+
expect(bytes.length).toBeGreaterThan(100)
|
|
36
|
+
const convertedStreamMessage = convertBytesToStreamMessage(bytes)
|
|
37
|
+
expect(convertedStreamMessage).toEqual(streamMessage)
|
|
38
|
+
})
|
|
39
|
+
})
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Methods } from '@streamr/test-utils'
|
|
2
|
+
import { Handshaker } from '../../../src/logic/neighbor-discovery/Handshaker'
|
|
3
|
+
import { DhtAddress } from '@streamr/dht'
|
|
3
4
|
|
|
4
|
-
export class MockHandshaker implements
|
|
5
|
+
export class MockHandshaker implements Methods<Handshaker> {
|
|
5
6
|
|
|
6
7
|
// eslint-disable-next-line class-methods-use-this
|
|
7
|
-
getOngoingHandshakes(): Set<
|
|
8
|
+
getOngoingHandshakes(): Set<DhtAddress> {
|
|
8
9
|
return new Set()
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
// eslint-disable-next-line class-methods-use-this
|
|
12
|
-
async attemptHandshakesOnContacts(excludedIds:
|
|
13
|
+
async attemptHandshakesOnContacts(excludedIds: DhtAddress[]): Promise<DhtAddress[]> {
|
|
13
14
|
return excludedIds
|
|
14
15
|
}
|
|
15
16
|
|