@streamr/dht 100.0.0-testnet-two.0 → 100.0.0-testnet-two.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +66 -0
- package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionManager.js +3 -3
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +14 -5
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +3 -3
- package/dist/src/connection/ManagedConnection.js +3 -3
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- package/dist/src/connection/simulator/Simulator.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +11 -3
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +18 -8
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -8
- package/dist/src/dht/DhtNode.js +23 -18
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +4 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +3 -2
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
- package/dist/src/dht/DhtNodeRpcRemote.js +10 -11
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +9 -9
- package/dist/src/dht/PeerManager.js +12 -12
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +2 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +1 -4
- package/dist/src/dht/contact/RpcRemote.js +1 -5
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +5 -5
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -2
- package/dist/src/dht/discovery/DiscoverySession.js +9 -12
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +16 -9
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +12 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +6 -6
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -2
- package/dist/src/dht/routing/Router.js +2 -2
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +3 -3
- package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
- package/dist/src/dht/routing/RoutingSession.js +4 -4
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +6 -8
- package/dist/src/dht/store/LocalDataStore.js +18 -24
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +20 -21
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +2 -1
- package/dist/src/dht/store/StoreRpcLocal.js +10 -8
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js +6 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +2 -2
- package/dist/src/helpers/PeerID.js +3 -3
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -2
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/helpers/versionCompatibility.d.ts +2 -0
- package/dist/src/helpers/versionCompatibility.js +18 -0
- package/dist/src/helpers/versionCompatibility.js.map +1 -0
- package/dist/src/identifiers.d.ts +6 -0
- package/dist/src/identifiers.js +23 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +13 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +9 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/package.json +5 -5
- package/protos/DhtRpc.proto +3 -1
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +3 -3
- package/src/connection/ConnectionManager.ts +4 -7
- package/src/connection/Handshaker.ts +21 -6
- package/src/connection/ManagedConnection.ts +10 -6
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnector.ts +2 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +11 -5
- package/src/connection/websocket/WebsocketConnector.ts +19 -11
- package/src/dht/DhtNode.ts +33 -31
- package/src/dht/DhtNodeRpcLocal.ts +4 -4
- package/src/dht/DhtNodeRpcRemote.ts +15 -17
- package/src/dht/ExternalApiRpcLocal.ts +15 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -4
- package/src/dht/PeerManager.ts +20 -20
- package/src/dht/contact/Contact.ts +2 -2
- package/src/dht/contact/ContactList.ts +7 -7
- package/src/dht/contact/RandomContactList.ts +6 -6
- package/src/dht/contact/RpcRemote.ts +0 -8
- package/src/dht/contact/SortedContactList.ts +22 -22
- package/src/dht/discovery/DiscoverySession.ts +16 -16
- package/src/dht/discovery/PeerDiscovery.ts +32 -11
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +14 -14
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +11 -11
- package/src/dht/routing/Router.ts +5 -5
- package/src/dht/routing/RouterRpcLocal.ts +3 -3
- package/src/dht/routing/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +25 -33
- package/src/dht/store/StoreManager.ts +25 -29
- package/src/dht/store/StoreRpcLocal.ts +11 -9
- package/src/exports.ts +2 -0
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/PeerID.ts +4 -4
- package/src/helpers/peerIdFromPeerDescriptor.ts +4 -4
- package/src/helpers/versionCompatibility.ts +13 -0
- package/src/identifiers.ts +20 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +18 -10
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +4 -3
- package/test/benchmark/KademliaCorrectness.test.ts +4 -4
- package/test/benchmark/SortedContactListBenchmark.test.ts +15 -14
- package/test/benchmark/kademlia-simulation/Contact.ts +7 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +10 -11
- package/test/data/generateGroundTruthData.ts +5 -4
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +3 -2
- package/test/integration/ConnectionManager.test.ts +3 -3
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -1
- package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +3 -2
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +3 -3
- package/test/integration/Mock-Layer1-Layer0.test.ts +6 -5
- package/test/integration/ReplicateData.test.ts +25 -23
- package/test/integration/RouteMessage.test.ts +9 -10
- package/test/integration/RouterRpcRemote.test.ts +1 -1
- package/test/integration/ScaleDownDht.test.ts +4 -4
- package/test/integration/SimultaneousConnections.test.ts +7 -14
- package/test/integration/Store.test.ts +17 -7
- package/test/integration/StoreAndDelete.test.ts +11 -10
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -6
- package/test/integration/StoreRpcRemote.test.ts +3 -5
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/LocalDataStore.test.ts +37 -29
- package/test/unit/PeerManager.test.ts +7 -8
- package/test/unit/RandomContactList.test.ts +3 -3
- package/test/unit/RecursiveOperationManager.test.ts +2 -1
- package/test/unit/RecursiveOperationSession.test.ts +2 -3
- package/test/unit/Router.test.ts +2 -2
- package/test/unit/RoutingSession.test.ts +2 -2
- package/test/unit/SortedContactList.test.ts +6 -6
- package/test/unit/StoreManager.test.ts +26 -23
- package/test/unit/versionCompatibility.test.ts +16 -0
- package/test/utils/customMatchers.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +8 -6
- package/test/utils/utils.ts +4 -4
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +2 -1
- package/dist/src/helpers/nodeId.d.ts +0 -6
- package/dist/src/helpers/nodeId.js +0 -31
- package/dist/src/helpers/nodeId.js.map +0 -1
- package/src/helpers/nodeId.ts +0 -28
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { hexToBinary } from '@streamr/utils'
|
|
2
1
|
import { PeerManager, getDistance } from '../../src/dht/PeerManager'
|
|
3
|
-
import {
|
|
2
|
+
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
4
3
|
import { NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
4
|
import { range, sampleSize, sortBy, without } from 'lodash'
|
|
6
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
@@ -9,22 +8,22 @@ import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
|
9
8
|
describe('PeerManager', () => {
|
|
10
9
|
|
|
11
10
|
it('getClosestContactsTo', () => {
|
|
12
|
-
const nodeIds = range(10).map(() =>
|
|
11
|
+
const nodeIds = range(10).map(() => createRandomDhtAddress())
|
|
13
12
|
const manager = new PeerManager({
|
|
14
|
-
localNodeId:
|
|
13
|
+
localNodeId: createRandomDhtAddress(),
|
|
15
14
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => {
|
|
16
15
|
return new DhtNodeRpcRemote(undefined as any, peerDescriptor, undefined as any, new MockRpcCommunicator())
|
|
17
16
|
}
|
|
18
17
|
} as any)
|
|
19
|
-
manager.handleNewPeers(nodeIds.map((n) => ({ nodeId:
|
|
18
|
+
manager.handleNewPeers(nodeIds.map((n) => ({ nodeId: getRawFromDhtAddress(n), type: NodeType.NODEJS })))
|
|
20
19
|
|
|
21
|
-
const referenceId =
|
|
22
|
-
const excluded = new Set<
|
|
20
|
+
const referenceId = createRandomDhtAddress()
|
|
21
|
+
const excluded = new Set<DhtAddress>(sampleSize(nodeIds, 2)!)
|
|
23
22
|
const actual = manager.getClosestContactsTo(referenceId, 5, excluded)
|
|
24
23
|
|
|
25
24
|
const expected = sortBy(
|
|
26
25
|
without(nodeIds, ...Array.from(excluded.values())),
|
|
27
|
-
(n:
|
|
26
|
+
(n: DhtAddress) => getDistance(getRawFromDhtAddress(n), getRawFromDhtAddress(referenceId))
|
|
28
27
|
).slice(0, 5)
|
|
29
28
|
expect(actual.map((n) => n.getNodeId())).toEqual(expected)
|
|
30
29
|
})
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { RandomContactList } from '../../src/dht/contact/RandomContactList'
|
|
2
2
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
|
-
import {
|
|
3
|
+
import { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
4
|
|
|
5
|
-
const createItem = (nodeId:
|
|
5
|
+
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress, getPeerId: () => PeerID } => {
|
|
6
6
|
return {
|
|
7
|
-
getNodeId: () =>
|
|
7
|
+
getNodeId: () => getDhtAddressFromRaw(nodeId),
|
|
8
8
|
getPeerId: () => PeerID.fromValue(nodeId)
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -21,6 +21,7 @@ import { areEqualPeerDescriptors } from '../../src/helpers/peerIdFromPeerDescrip
|
|
|
21
21
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
22
22
|
import { Router } from '../../src/dht/routing/Router'
|
|
23
23
|
import { ITransport } from '../../src/exports'
|
|
24
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
24
25
|
|
|
25
26
|
const createMockRouter = (error?: RouteMessageError): Partial<Router> => {
|
|
26
27
|
return {
|
|
@@ -85,7 +86,7 @@ describe('RecursiveOperationManager', () => {
|
|
|
85
86
|
|
|
86
87
|
it('startFind with mode Node returns self if no peers', async () => {
|
|
87
88
|
const recursiveOperationManager = createRecursiveOperationManager()
|
|
88
|
-
const res = await recursiveOperationManager.execute(PeerID.fromString('find').value, RecursiveOperation.FIND_NODE)
|
|
89
|
+
const res = await recursiveOperationManager.execute(getDhtAddressFromRaw(PeerID.fromString('find').value), RecursiveOperation.FIND_NODE)
|
|
89
90
|
expect(areEqualPeerDescriptors(res.closestNodes[0], peerDescriptor1)).toEqual(true)
|
|
90
91
|
recursiveOperationManager.stop()
|
|
91
92
|
})
|
|
@@ -3,7 +3,7 @@ import { range } from 'lodash'
|
|
|
3
3
|
import { RecursiveOperationSession } from '../../src/dht/recursive-operation/RecursiveOperationSession'
|
|
4
4
|
import { RecursiveOperationSessionRpcRemote } from '../../src/dht/recursive-operation/RecursiveOperationSessionRpcRemote'
|
|
5
5
|
import { ServiceID } from '../../src/exports'
|
|
6
|
-
import {
|
|
6
|
+
import { createRandomDhtAddress } from '../../src/identifiers'
|
|
7
7
|
import { Message, PeerDescriptor, RecursiveOperation } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
8
8
|
import { RecursiveOperationSessionRpcClient } from '../../src/proto/packages/dht/protos/DhtRpc.client'
|
|
9
9
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
@@ -21,7 +21,6 @@ describe('RecursiveOperationSession', () => {
|
|
|
21
21
|
return new RecursiveOperationSessionRpcRemote(
|
|
22
22
|
createMockPeerDescriptor(),
|
|
23
23
|
localPeerDescriptor,
|
|
24
|
-
serviceId,
|
|
25
24
|
new RoutingRpcCommunicator(serviceId, send),
|
|
26
25
|
RecursiveOperationSessionRpcClient
|
|
27
26
|
)
|
|
@@ -36,7 +35,7 @@ describe('RecursiveOperationSession', () => {
|
|
|
36
35
|
const doRouteRequest = jest.fn()
|
|
37
36
|
const session = new RecursiveOperationSession({
|
|
38
37
|
transport: environment.createTransport(),
|
|
39
|
-
targetId:
|
|
38
|
+
targetId: createRandomDhtAddress(),
|
|
40
39
|
localPeerDescriptor,
|
|
41
40
|
waitedRoutingPathCompletions: 3,
|
|
42
41
|
operation: RecursiveOperation.FIND_NODE,
|
package/test/unit/Router.test.ts
CHANGED
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
13
13
|
import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../utils/utils'
|
|
14
14
|
import { FakeRpcCommunicator } from '../utils/FakeRpcCommunicator'
|
|
15
|
-
import {
|
|
15
|
+
import { DhtAddress } from '../../src/identifiers'
|
|
16
16
|
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
17
17
|
|
|
18
18
|
describe('Router', () => {
|
|
@@ -40,7 +40,7 @@ describe('Router', () => {
|
|
|
40
40
|
target: peerDescriptor1.nodeId,
|
|
41
41
|
sourcePeer: peerDescriptor2
|
|
42
42
|
}
|
|
43
|
-
let connections: Map<
|
|
43
|
+
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
44
44
|
const rpcCommunicator = new FakeRpcCommunicator()
|
|
45
45
|
|
|
46
46
|
const createMockDhtNodeRpcRemote = (destination: PeerDescriptor): DhtNodeRpcRemote => {
|
|
@@ -5,13 +5,13 @@ import { createMockPeerDescriptor, createWrappedClosestPeersRequest } from '../u
|
|
|
5
5
|
import { DhtNodeRpcRemote } from '../../src/dht/DhtNodeRpcRemote'
|
|
6
6
|
import { RoutingRpcCommunicator } from '../../src/transport/RoutingRpcCommunicator'
|
|
7
7
|
import { getNodeIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
|
|
8
|
-
import {
|
|
8
|
+
import { DhtAddress } from '../../src/identifiers'
|
|
9
9
|
import { MockRpcCommunicator } from '../utils/mock/MockRpcCommunicator'
|
|
10
10
|
|
|
11
11
|
describe('RoutingSession', () => {
|
|
12
12
|
|
|
13
13
|
let session: RoutingSession
|
|
14
|
-
let connections: Map<
|
|
14
|
+
let connections: Map<DhtAddress, DhtNodeRpcRemote>
|
|
15
15
|
let rpcCommunicator: RoutingRpcCommunicator
|
|
16
16
|
const mockPeerDescriptor1 = createMockPeerDescriptor()
|
|
17
17
|
const mockPeerDescriptor2 = createMockPeerDescriptor()
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SortedContactList } from '../../src/dht/contact/SortedContactList'
|
|
2
2
|
import { PeerID } from '../../src/helpers/PeerID'
|
|
3
|
-
import {
|
|
3
|
+
import { DhtAddress, DhtAddressRaw, createRandomDhtAddress, getDhtAddressFromRaw } from '../../src/identifiers'
|
|
4
4
|
|
|
5
|
-
const createItem = (nodeId:
|
|
5
|
+
const createItem = (nodeId: DhtAddressRaw): { getNodeId: () => DhtAddress, getPeerId: () => PeerID } => {
|
|
6
6
|
return {
|
|
7
|
-
getNodeId: () =>
|
|
7
|
+
getNodeId: () => getDhtAddressFromRaw(nodeId),
|
|
8
8
|
getPeerId: () => PeerID.fromValue(nodeId)
|
|
9
9
|
}
|
|
10
10
|
}
|
|
@@ -72,7 +72,7 @@ describe('SortedContactList', () => {
|
|
|
72
72
|
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 8, allowToContainReferenceId: false, emitEvents: true })
|
|
73
73
|
const onContactRemoved = jest.fn()
|
|
74
74
|
list.on('contactRemoved', onContactRemoved)
|
|
75
|
-
list.removeContact(
|
|
75
|
+
list.removeContact(createRandomDhtAddress())
|
|
76
76
|
list.addContact(item3)
|
|
77
77
|
list.removeContact(item3.getNodeId())
|
|
78
78
|
list.addContact(item4)
|
|
@@ -84,10 +84,10 @@ describe('SortedContactList', () => {
|
|
|
84
84
|
expect(list.getContact(item2.getNodeId())).toBeFalsy()
|
|
85
85
|
expect(list.getContactIds()).toEqual(list.getContactIds().sort(list.compareIds))
|
|
86
86
|
expect(list.getAllContacts()).toEqual([item1, item3, item4])
|
|
87
|
-
const ret = list.removeContact(
|
|
87
|
+
const ret = list.removeContact(getDhtAddressFromRaw(Buffer.from([0, 0, 0, 6])))
|
|
88
88
|
expect(ret).toEqual(false)
|
|
89
89
|
list.removeContact(item3.getNodeId())
|
|
90
|
-
list.removeContact(
|
|
90
|
+
list.removeContact(createRandomDhtAddress())
|
|
91
91
|
expect(list.getAllContacts()).toEqual([item1, item4])
|
|
92
92
|
expect(onContactRemoved).toHaveBeenNthCalledWith(1, item3, [])
|
|
93
93
|
expect(onContactRemoved).toHaveBeenNthCalledWith(2, item2, [item1, item3, item4])
|
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
import { wait, waitForCondition } from '@streamr/utils'
|
|
2
|
-
import crypto from 'crypto'
|
|
3
2
|
import { range, sortBy } from 'lodash'
|
|
4
|
-
import { Key } from 'readline'
|
|
5
3
|
import { getDistance } from '../../src/dht/PeerManager'
|
|
6
4
|
import { StoreManager } from '../../src/dht/store/StoreManager'
|
|
7
|
-
import {
|
|
5
|
+
import {
|
|
6
|
+
DhtAddress,
|
|
7
|
+
createRandomDhtAddress,
|
|
8
|
+
getDhtAddressFromRaw,
|
|
9
|
+
getRawFromDhtAddress,
|
|
10
|
+
} from '../../src/identifiers'
|
|
8
11
|
import { NodeType, ReplicateDataRequest } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
9
12
|
|
|
10
13
|
const DATA_ENTRY = {
|
|
11
|
-
key:
|
|
12
|
-
creator:
|
|
14
|
+
key: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
15
|
+
creator: getRawFromDhtAddress(createRandomDhtAddress())
|
|
13
16
|
}
|
|
14
17
|
const NODES_CLOSEST_TO_DATA = sortBy(
|
|
15
|
-
range(5).map(() =>
|
|
16
|
-
(id:
|
|
18
|
+
range(5).map(() => createRandomDhtAddress()),
|
|
19
|
+
(id: DhtAddress) => getDistance(getRawFromDhtAddress(id), DATA_ENTRY.key)
|
|
17
20
|
)
|
|
18
21
|
|
|
19
22
|
describe('StoreManager', () => {
|
|
@@ -21,13 +24,13 @@ describe('StoreManager', () => {
|
|
|
21
24
|
describe('new contact', () => {
|
|
22
25
|
|
|
23
26
|
const createStoreManager = (
|
|
24
|
-
localNodeId:
|
|
25
|
-
closestNeighbors:
|
|
27
|
+
localNodeId: DhtAddress,
|
|
28
|
+
closestNeighbors: DhtAddress[],
|
|
26
29
|
replicateData: (request: ReplicateDataRequest) => unknown,
|
|
27
|
-
setStale: (key:
|
|
30
|
+
setStale: (key: DhtAddress, creator: DhtAddress, stale: boolean) => unknown
|
|
28
31
|
): StoreManager => {
|
|
29
32
|
const getClosestNeighborsTo = () => {
|
|
30
|
-
return closestNeighbors.map((nodeId) => ({ nodeId, type: NodeType.NODEJS }))
|
|
33
|
+
return closestNeighbors.map((nodeId) => ({ nodeId: getRawFromDhtAddress(nodeId), type: NodeType.NODEJS }))
|
|
31
34
|
}
|
|
32
35
|
return new StoreManager({
|
|
33
36
|
rpcCommunicator: {
|
|
@@ -35,7 +38,7 @@ describe('StoreManager', () => {
|
|
|
35
38
|
registerRpcNotification: () => {}
|
|
36
39
|
} as any,
|
|
37
40
|
recursiveOperationManager: undefined as any,
|
|
38
|
-
localPeerDescriptor: { nodeId: localNodeId, type: NodeType.NODEJS },
|
|
41
|
+
localPeerDescriptor: { nodeId: getRawFromDhtAddress(localNodeId), type: NodeType.NODEJS },
|
|
39
42
|
localDataStore: { values: () => [DATA_ENTRY], setStale } as any,
|
|
40
43
|
serviceId: undefined as any,
|
|
41
44
|
highestTtl: undefined as any,
|
|
@@ -49,14 +52,14 @@ describe('StoreManager', () => {
|
|
|
49
52
|
|
|
50
53
|
it('new node is within redundancy factor', async () => {
|
|
51
54
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
52
|
-
const setStale = jest.fn<undefined, [
|
|
55
|
+
const setStale = jest.fn<undefined, [DhtAddress, DhtAddress]>()
|
|
53
56
|
const manager = createStoreManager(
|
|
54
57
|
NODES_CLOSEST_TO_DATA[0],
|
|
55
58
|
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[3], NODES_CLOSEST_TO_DATA[4]],
|
|
56
59
|
replicateData,
|
|
57
60
|
setStale
|
|
58
61
|
)
|
|
59
|
-
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[2], type: NodeType.NODEJS })
|
|
62
|
+
manager.onNewContact({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[2]), type: NodeType.NODEJS })
|
|
60
63
|
await waitForCondition(() => replicateData.mock.calls.length === 1)
|
|
61
64
|
expect(replicateData).toHaveBeenCalledWith({
|
|
62
65
|
entry: DATA_ENTRY
|
|
@@ -66,14 +69,14 @@ describe('StoreManager', () => {
|
|
|
66
69
|
|
|
67
70
|
it('new node is not within redundancy factor', async () => {
|
|
68
71
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
69
|
-
const setStale = jest.fn<undefined, [
|
|
72
|
+
const setStale = jest.fn<undefined, [DhtAddress, DhtAddress]>()
|
|
70
73
|
const manager = createStoreManager(
|
|
71
74
|
NODES_CLOSEST_TO_DATA[0],
|
|
72
75
|
[NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
73
76
|
replicateData,
|
|
74
77
|
setStale
|
|
75
78
|
)
|
|
76
|
-
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
79
|
+
manager.onNewContact({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
77
80
|
await wait(50)
|
|
78
81
|
expect(replicateData).not.toHaveBeenCalled()
|
|
79
82
|
expect(setStale).not.toHaveBeenCalled()
|
|
@@ -84,14 +87,14 @@ describe('StoreManager', () => {
|
|
|
84
87
|
|
|
85
88
|
it('this node is within redundancy factor', async () => {
|
|
86
89
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
87
|
-
const setStale = jest.fn<undefined, [
|
|
90
|
+
const setStale = jest.fn<undefined, [DhtAddress, DhtAddress]>()
|
|
88
91
|
const manager = createStoreManager(
|
|
89
92
|
NODES_CLOSEST_TO_DATA[1],
|
|
90
93
|
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[2], NODES_CLOSEST_TO_DATA[3]],
|
|
91
94
|
replicateData,
|
|
92
95
|
setStale
|
|
93
96
|
)
|
|
94
|
-
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
97
|
+
manager.onNewContact({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
95
98
|
await wait(50)
|
|
96
99
|
expect(replicateData).not.toHaveBeenCalled()
|
|
97
100
|
expect(setStale).not.toHaveBeenCalled()
|
|
@@ -99,30 +102,30 @@ describe('StoreManager', () => {
|
|
|
99
102
|
|
|
100
103
|
it('this node is not within redundancy factor', async () => {
|
|
101
104
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
102
|
-
const setStale = jest.fn<undefined, [
|
|
105
|
+
const setStale = jest.fn<undefined, [DhtAddress, DhtAddress]>()
|
|
103
106
|
const manager = createStoreManager(
|
|
104
107
|
NODES_CLOSEST_TO_DATA[3],
|
|
105
108
|
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1], NODES_CLOSEST_TO_DATA[2]],
|
|
106
109
|
replicateData,
|
|
107
110
|
setStale
|
|
108
111
|
)
|
|
109
|
-
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
112
|
+
manager.onNewContact({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
110
113
|
await wait(50)
|
|
111
114
|
expect(replicateData).not.toHaveBeenCalled()
|
|
112
115
|
expect(setStale).toHaveBeenCalledTimes(1)
|
|
113
|
-
expect(setStale).toHaveBeenCalledWith(DATA_ENTRY.key,
|
|
116
|
+
expect(setStale).toHaveBeenCalledWith(getDhtAddressFromRaw(DATA_ENTRY.key), getDhtAddressFromRaw(DATA_ENTRY.creator), true)
|
|
114
117
|
})
|
|
115
118
|
|
|
116
119
|
it('this node has less than redundancyFactor neighbors', async () => {
|
|
117
120
|
const replicateData = jest.fn<undefined, [ReplicateDataRequest]>()
|
|
118
|
-
const setStale = jest.fn<undefined, [
|
|
121
|
+
const setStale = jest.fn<undefined, [DhtAddress, DhtAddress]>()
|
|
119
122
|
const manager = createStoreManager(
|
|
120
123
|
NODES_CLOSEST_TO_DATA[3],
|
|
121
124
|
[NODES_CLOSEST_TO_DATA[0], NODES_CLOSEST_TO_DATA[1]],
|
|
122
125
|
replicateData,
|
|
123
126
|
setStale
|
|
124
127
|
)
|
|
125
|
-
manager.onNewContact({ nodeId: NODES_CLOSEST_TO_DATA[4], type: NodeType.NODEJS })
|
|
128
|
+
manager.onNewContact({ nodeId: getRawFromDhtAddress(NODES_CLOSEST_TO_DATA[4]), type: NodeType.NODEJS })
|
|
126
129
|
await wait(50)
|
|
127
130
|
expect(replicateData).not.toHaveBeenCalled()
|
|
128
131
|
expect(setStale).toHaveBeenCalledTimes(0)
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { isCompatibleVersion } from '../../src/helpers/versionCompatibility'
|
|
2
|
+
|
|
3
|
+
describe('version compatibility', () => {
|
|
4
|
+
|
|
5
|
+
it('same minor versions should be compatible', () => {
|
|
6
|
+
expect(isCompatibleVersion('1.2.3', '1.2.4')).toBe(true)
|
|
7
|
+
expect(isCompatibleVersion('100.0.0-pretestnet.0', '100.0.0-pretestnet.40')).toBe(true)
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
it('different minor versions should not be compatible', () => {
|
|
11
|
+
expect(isCompatibleVersion('1.2.3', '2.2.4')).toBe(false)
|
|
12
|
+
expect(isCompatibleVersion('1.2.3', '1.3.4')).toBe(false)
|
|
13
|
+
expect(isCompatibleVersion('100.0.0-testnet.0', '101.0.0-pretestnet.40')).toBe(false)
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
})
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { areEqualBinaries
|
|
1
|
+
import { areEqualBinaries } from '@streamr/utils'
|
|
2
2
|
import { printExpected, printReceived } from 'jest-matcher-utils'
|
|
3
3
|
import { isEqual } from 'lodash'
|
|
4
4
|
import { ConnectivityMethod, NodeType, PeerDescriptor } from '../../src/proto/packages/dht/protos/DhtRpc'
|
|
5
|
+
import { getDhtAddressFromRaw } from '../../src/identifiers'
|
|
5
6
|
|
|
6
7
|
// we could ES2015 module syntax (https://jestjs.io/docs/expect#expectextendmatchers),
|
|
7
8
|
// but the IDE doesn't find custom matchers if we do that
|
|
@@ -24,7 +25,7 @@ const toEqualPeerDescriptor = (
|
|
|
24
25
|
): jest.CustomMatcherResult => {
|
|
25
26
|
const messages: string[] = []
|
|
26
27
|
if (!areEqualBinaries(expected.nodeId, actual.nodeId)) {
|
|
27
|
-
messages.push(formErrorMessage('nodeId',
|
|
28
|
+
messages.push(formErrorMessage('nodeId', getDhtAddressFromRaw(expected.nodeId), getDhtAddressFromRaw(actual.nodeId)))
|
|
28
29
|
}
|
|
29
30
|
if (!isEqual(expected.type, actual.type)) {
|
|
30
31
|
const typeNames = { [NodeType.NODEJS]: 'NODEJS', [NodeType.BROWSER]: 'BROWSER' }
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { MessageType as MessageType$, ScalarType } from '@protobuf-ts/runtime'
|
|
2
2
|
import { randomString } from '@streamr/utils'
|
|
3
|
-
import crypto from 'crypto'
|
|
4
3
|
import { Timestamp } from '../../../src/proto/google/protobuf/timestamp'
|
|
5
4
|
import { Any } from '../../../src/proto/google/protobuf/any'
|
|
6
5
|
import { DataEntry } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
7
|
-
import {
|
|
6
|
+
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
7
|
+
import { omit } from 'lodash'
|
|
8
8
|
|
|
9
9
|
const MockData = new class extends MessageType$<{ foo: string }> {
|
|
10
10
|
constructor() {
|
|
@@ -14,16 +14,18 @@ const MockData = new class extends MessageType$<{ foo: string }> {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
export const createMockDataEntry = (
|
|
17
|
+
export const createMockDataEntry = (
|
|
18
|
+
entry: Partial<Omit<DataEntry, 'key' | 'creator'> & { key: DhtAddress, creator: DhtAddress }> = {}
|
|
19
|
+
): DataEntry => {
|
|
18
20
|
return {
|
|
19
|
-
key:
|
|
21
|
+
key: getRawFromDhtAddress(entry.key ?? createRandomDhtAddress()),
|
|
20
22
|
data: Any.pack({ foo: randomString(5) }, MockData),
|
|
21
|
-
creator: entry.creator ??
|
|
23
|
+
creator: getRawFromDhtAddress(entry.creator ?? createRandomDhtAddress()),
|
|
22
24
|
ttl: 10000,
|
|
23
25
|
stale: false,
|
|
24
26
|
deleted: false,
|
|
25
27
|
createdAt: Timestamp.now(),
|
|
26
|
-
...entry
|
|
28
|
+
...omit(entry, 'key', 'creator')
|
|
27
29
|
}
|
|
28
30
|
}
|
|
29
31
|
|
package/test/utils/utils.ts
CHANGED
|
@@ -28,11 +28,11 @@ import { Empty } from '../../src/proto/google/protobuf/empty'
|
|
|
28
28
|
import { Any } from '../../src/proto/google/protobuf/any'
|
|
29
29
|
import { wait, waitForCondition } from '@streamr/utils'
|
|
30
30
|
import { SimulatorTransport } from '../../src/connection/simulator/SimulatorTransport'
|
|
31
|
-
import {
|
|
31
|
+
import { DhtAddress, createRandomDhtAddress, getRawFromDhtAddress } from '../../src/identifiers'
|
|
32
32
|
|
|
33
33
|
export const createMockPeerDescriptor = (opts?: Partial<Omit<PeerDescriptor, 'nodeId'>>): PeerDescriptor => {
|
|
34
34
|
return {
|
|
35
|
-
nodeId:
|
|
35
|
+
nodeId: getRawFromDhtAddress(createRandomDhtAddress()),
|
|
36
36
|
type: NodeType.NODEJS,
|
|
37
37
|
...opts
|
|
38
38
|
}
|
|
@@ -40,13 +40,13 @@ export const createMockPeerDescriptor = (opts?: Partial<Omit<PeerDescriptor, 'no
|
|
|
40
40
|
|
|
41
41
|
export const createMockConnectionDhtNode = async (
|
|
42
42
|
simulator: Simulator,
|
|
43
|
-
nodeId?:
|
|
43
|
+
nodeId?: DhtAddress,
|
|
44
44
|
numberOfNodesPerKBucket?: number,
|
|
45
45
|
maxConnections = 80,
|
|
46
46
|
dhtJoinTimeout = 45000
|
|
47
47
|
): Promise<DhtNode> => {
|
|
48
48
|
const peerDescriptor: PeerDescriptor = {
|
|
49
|
-
nodeId: nodeId ??
|
|
49
|
+
nodeId: getRawFromDhtAddress(nodeId ?? createRandomDhtAddress()),
|
|
50
50
|
type: NodeType.NODEJS,
|
|
51
51
|
region: getRandomRegion()
|
|
52
52
|
}
|
package/tsconfig.browser.json
CHANGED
package/tsconfig.jest.json
CHANGED
package/tsconfig.node.json
CHANGED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { BrandedString } from '@streamr/utils';
|
|
2
|
-
export declare const createRandomNodeId: () => Uint8Array;
|
|
3
|
-
export type NodeID = BrandedString<'NodeID'>;
|
|
4
|
-
export declare const areEqualNodeIds: (nodeId1: NodeID, nodeId2: NodeID) => boolean;
|
|
5
|
-
export declare const getNodeIdFromDataKey: (key: Uint8Array) => NodeID;
|
|
6
|
-
export declare const getNodeIdFromBinary: (id: Uint8Array) => NodeID;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.getNodeIdFromBinary = exports.getNodeIdFromDataKey = exports.areEqualNodeIds = exports.createRandomNodeId = void 0;
|
|
7
|
-
const utils_1 = require("@streamr/utils");
|
|
8
|
-
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
-
// https://www.scs.stanford.edu/~dm/home/papers/kpos.pdf
|
|
10
|
-
const KADEMLIA_ID_LENGTH_IN_BYTES = 20;
|
|
11
|
-
// TODO this should return NodeID
|
|
12
|
-
const createRandomNodeId = () => {
|
|
13
|
-
return crypto_1.default.randomBytes(KADEMLIA_ID_LENGTH_IN_BYTES);
|
|
14
|
-
};
|
|
15
|
-
exports.createRandomNodeId = createRandomNodeId;
|
|
16
|
-
// TODO remove this or add support for UInt8Array parameters
|
|
17
|
-
const areEqualNodeIds = (nodeId1, nodeId2) => {
|
|
18
|
-
return nodeId1 === nodeId2;
|
|
19
|
-
};
|
|
20
|
-
exports.areEqualNodeIds = areEqualNodeIds;
|
|
21
|
-
// TODO maybe this is not needed and we can use just getNodeIdFromBinary?
|
|
22
|
-
const getNodeIdFromDataKey = (key) => {
|
|
23
|
-
return (0, exports.getNodeIdFromBinary)(key);
|
|
24
|
-
};
|
|
25
|
-
exports.getNodeIdFromDataKey = getNodeIdFromDataKey;
|
|
26
|
-
// TODO should we have similar method to convert nodeId to bucketId (which is just hexToBinary)
|
|
27
|
-
const getNodeIdFromBinary = (id) => {
|
|
28
|
-
return (0, utils_1.binaryToHex)(id);
|
|
29
|
-
};
|
|
30
|
-
exports.getNodeIdFromBinary = getNodeIdFromBinary;
|
|
31
|
-
//# sourceMappingURL=nodeId.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"nodeId.js","sourceRoot":"","sources":["../../../src/helpers/nodeId.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA2D;AAC3D,oDAA2B;AAE3B,wDAAwD;AACxD,MAAM,2BAA2B,GAAG,EAAE,CAAA;AAEtC,iCAAiC;AAC1B,MAAM,kBAAkB,GAAG,GAAe,EAAE;IAC/C,OAAO,gBAAM,CAAC,WAAW,CAAC,2BAA2B,CAAC,CAAA;AAC1D,CAAC,CAAA;AAFY,QAAA,kBAAkB,sBAE9B;AAKD,4DAA4D;AACrD,MAAM,eAAe,GAAG,CAAC,OAAe,EAAE,OAAe,EAAW,EAAE;IACzE,OAAO,OAAO,KAAK,OAAO,CAAA;AAC9B,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B;AAED,yEAAyE;AAClE,MAAM,oBAAoB,GAAG,CAAC,GAAe,EAAU,EAAE;IAC5D,OAAO,IAAA,2BAAmB,EAAC,GAAG,CAAC,CAAA;AACnC,CAAC,CAAA;AAFY,QAAA,oBAAoB,wBAEhC;AAED,+FAA+F;AACxF,MAAM,mBAAmB,GAAG,CAAC,EAAc,EAAU,EAAE;IAC1D,OAAO,IAAA,mBAAW,EAAC,EAAE,CAAsB,CAAA;AAC/C,CAAC,CAAA;AAFY,QAAA,mBAAmB,uBAE/B"}
|
package/src/helpers/nodeId.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { BrandedString, binaryToHex } from '@streamr/utils'
|
|
2
|
-
import crypto from 'crypto'
|
|
3
|
-
|
|
4
|
-
// https://www.scs.stanford.edu/~dm/home/papers/kpos.pdf
|
|
5
|
-
const KADEMLIA_ID_LENGTH_IN_BYTES = 20
|
|
6
|
-
|
|
7
|
-
// TODO this should return NodeID
|
|
8
|
-
export const createRandomNodeId = (): Uint8Array => {
|
|
9
|
-
return crypto.randomBytes(KADEMLIA_ID_LENGTH_IN_BYTES)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
// TODO rename the file to be "NodeID.ts" instead of "nodeId.ts"
|
|
13
|
-
export type NodeID = BrandedString<'NodeID'>
|
|
14
|
-
|
|
15
|
-
// TODO remove this or add support for UInt8Array parameters
|
|
16
|
-
export const areEqualNodeIds = (nodeId1: NodeID, nodeId2: NodeID): boolean => {
|
|
17
|
-
return nodeId1 === nodeId2
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
// TODO maybe this is not needed and we can use just getNodeIdFromBinary?
|
|
21
|
-
export const getNodeIdFromDataKey = (key: Uint8Array): NodeID => {
|
|
22
|
-
return getNodeIdFromBinary(key)
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
// TODO should we have similar method to convert nodeId to bucketId (which is just hexToBinary)
|
|
26
|
-
export const getNodeIdFromBinary = (id: Uint8Array): NodeID => {
|
|
27
|
-
return binaryToHex(id) as unknown as NodeID
|
|
28
|
-
}
|