@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.
Files changed (189) hide show
  1. package/dist/package.json +66 -0
  2. package/dist/src/connection/ConnectionLockHandler.d.ts +11 -11
  3. package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
  4. package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
  5. package/dist/src/connection/ConnectionManager.js +3 -3
  6. package/dist/src/connection/ConnectionManager.js.map +1 -1
  7. package/dist/src/connection/Handshaker.d.ts +1 -1
  8. package/dist/src/connection/Handshaker.js +14 -5
  9. package/dist/src/connection/Handshaker.js.map +1 -1
  10. package/dist/src/connection/ManagedConnection.d.ts +3 -3
  11. package/dist/src/connection/ManagedConnection.js +3 -3
  12. package/dist/src/connection/ManagedConnection.js.map +1 -1
  13. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  14. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  15. package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
  16. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  17. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
  18. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +11 -3
  19. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  20. package/dist/src/connection/websocket/WebsocketConnector.js +18 -8
  21. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  22. package/dist/src/dht/DhtNode.d.ts +9 -8
  23. package/dist/src/dht/DhtNode.js +23 -18
  24. package/dist/src/dht/DhtNode.js.map +1 -1
  25. package/dist/src/dht/DhtNodeRpcLocal.d.ts +4 -3
  26. package/dist/src/dht/DhtNodeRpcLocal.js +3 -2
  27. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  28. package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
  29. package/dist/src/dht/DhtNodeRpcRemote.js +10 -11
  30. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  31. package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
  32. package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
  33. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  34. package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -2
  35. package/dist/src/dht/ExternalApiRpcRemote.js +3 -2
  36. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  37. package/dist/src/dht/PeerManager.d.ts +9 -9
  38. package/dist/src/dht/PeerManager.js +12 -12
  39. package/dist/src/dht/PeerManager.js.map +1 -1
  40. package/dist/src/dht/contact/Contact.d.ts +2 -2
  41. package/dist/src/dht/contact/ContactList.d.ts +7 -7
  42. package/dist/src/dht/contact/ContactList.js.map +1 -1
  43. package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
  44. package/dist/src/dht/contact/RandomContactList.js +2 -3
  45. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  46. package/dist/src/dht/contact/RpcRemote.d.ts +1 -4
  47. package/dist/src/dht/contact/RpcRemote.js +1 -5
  48. package/dist/src/dht/contact/RpcRemote.js.map +1 -1
  49. package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
  50. package/dist/src/dht/contact/SortedContactList.js +5 -5
  51. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  52. package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -2
  53. package/dist/src/dht/discovery/DiscoverySession.js +9 -12
  54. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  55. package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -1
  56. package/dist/src/dht/discovery/PeerDiscovery.js +16 -9
  57. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  58. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
  59. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +12 -11
  60. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  61. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
  62. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +6 -6
  63. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  64. package/dist/src/dht/routing/Router.d.ts +2 -2
  65. package/dist/src/dht/routing/Router.js +2 -2
  66. package/dist/src/dht/routing/Router.js.map +1 -1
  67. package/dist/src/dht/routing/RouterRpcLocal.js +3 -3
  68. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  69. package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
  70. package/dist/src/dht/routing/RoutingSession.js +4 -4
  71. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  72. package/dist/src/dht/store/LocalDataStore.d.ts +6 -8
  73. package/dist/src/dht/store/LocalDataStore.js +18 -24
  74. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  75. package/dist/src/dht/store/StoreManager.d.ts +3 -3
  76. package/dist/src/dht/store/StoreManager.js +20 -21
  77. package/dist/src/dht/store/StoreManager.js.map +1 -1
  78. package/dist/src/dht/store/StoreRpcLocal.d.ts +2 -1
  79. package/dist/src/dht/store/StoreRpcLocal.js +10 -8
  80. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  81. package/dist/src/exports.d.ts +2 -0
  82. package/dist/src/exports.js +6 -1
  83. package/dist/src/exports.js.map +1 -1
  84. package/dist/src/helpers/AddressTools.js +2 -0
  85. package/dist/src/helpers/AddressTools.js.map +1 -1
  86. package/dist/src/helpers/PeerID.d.ts +2 -2
  87. package/dist/src/helpers/PeerID.js +3 -3
  88. package/dist/src/helpers/PeerID.js.map +1 -1
  89. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -2
  90. package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
  91. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
  92. package/dist/src/helpers/versionCompatibility.d.ts +2 -0
  93. package/dist/src/helpers/versionCompatibility.js +18 -0
  94. package/dist/src/helpers/versionCompatibility.js.map +1 -0
  95. package/dist/src/identifiers.d.ts +6 -0
  96. package/dist/src/identifiers.js +23 -0
  97. package/dist/src/identifiers.js.map +1 -0
  98. package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +13 -5
  99. package/dist/src/proto/packages/dht/protos/DhtRpc.js +9 -5
  100. package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
  101. package/package.json +5 -5
  102. package/protos/DhtRpc.proto +3 -1
  103. package/src/connection/ConnectionLockHandler.ts +15 -15
  104. package/src/connection/ConnectionLockRpcLocal.ts +3 -3
  105. package/src/connection/ConnectionManager.ts +4 -7
  106. package/src/connection/Handshaker.ts +21 -6
  107. package/src/connection/ManagedConnection.ts +10 -6
  108. package/src/connection/simulator/Simulator.ts +2 -2
  109. package/src/connection/simulator/SimulatorConnector.ts +2 -2
  110. package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
  111. package/src/connection/webrtc/WebrtcConnector.ts +2 -3
  112. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +11 -5
  113. package/src/connection/websocket/WebsocketConnector.ts +19 -11
  114. package/src/dht/DhtNode.ts +33 -31
  115. package/src/dht/DhtNodeRpcLocal.ts +4 -4
  116. package/src/dht/DhtNodeRpcRemote.ts +15 -17
  117. package/src/dht/ExternalApiRpcLocal.ts +15 -6
  118. package/src/dht/ExternalApiRpcRemote.ts +5 -4
  119. package/src/dht/PeerManager.ts +20 -20
  120. package/src/dht/contact/Contact.ts +2 -2
  121. package/src/dht/contact/ContactList.ts +7 -7
  122. package/src/dht/contact/RandomContactList.ts +6 -6
  123. package/src/dht/contact/RpcRemote.ts +0 -8
  124. package/src/dht/contact/SortedContactList.ts +22 -22
  125. package/src/dht/discovery/DiscoverySession.ts +16 -16
  126. package/src/dht/discovery/PeerDiscovery.ts +32 -11
  127. package/src/dht/recursive-operation/RecursiveOperationManager.ts +14 -14
  128. package/src/dht/recursive-operation/RecursiveOperationSession.ts +11 -11
  129. package/src/dht/routing/Router.ts +5 -5
  130. package/src/dht/routing/RouterRpcLocal.ts +3 -3
  131. package/src/dht/routing/RoutingSession.ts +6 -8
  132. package/src/dht/store/LocalDataStore.ts +25 -33
  133. package/src/dht/store/StoreManager.ts +25 -29
  134. package/src/dht/store/StoreRpcLocal.ts +11 -9
  135. package/src/exports.ts +2 -0
  136. package/src/helpers/AddressTools.ts +2 -0
  137. package/src/helpers/PeerID.ts +4 -4
  138. package/src/helpers/peerIdFromPeerDescriptor.ts +4 -4
  139. package/src/helpers/versionCompatibility.ts +13 -0
  140. package/src/identifiers.ts +20 -0
  141. package/src/proto/packages/dht/protos/DhtRpc.ts +18 -10
  142. package/test/RandomGraphSimulation.ts +3 -2
  143. package/test/benchmark/Find.test.ts +4 -3
  144. package/test/benchmark/KademliaCorrectness.test.ts +4 -4
  145. package/test/benchmark/SortedContactListBenchmark.test.ts +15 -14
  146. package/test/benchmark/kademlia-simulation/Contact.ts +7 -8
  147. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
  148. package/test/benchmark/kademlia-simulation/SimulationNode.ts +10 -11
  149. package/test/data/generateGroundTruthData.ts +5 -4
  150. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
  151. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
  152. package/test/end-to-end/memory-leak.test.ts +3 -2
  153. package/test/integration/ConnectionManager.test.ts +3 -3
  154. package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -1
  155. package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
  156. package/test/integration/DhtNodeRpcRemote.test.ts +3 -2
  157. package/test/integration/Find.test.ts +3 -3
  158. package/test/integration/Layer1-scale.test.ts +3 -3
  159. package/test/integration/Mock-Layer1-Layer0.test.ts +6 -5
  160. package/test/integration/ReplicateData.test.ts +25 -23
  161. package/test/integration/RouteMessage.test.ts +9 -10
  162. package/test/integration/RouterRpcRemote.test.ts +1 -1
  163. package/test/integration/ScaleDownDht.test.ts +4 -4
  164. package/test/integration/SimultaneousConnections.test.ts +7 -14
  165. package/test/integration/Store.test.ts +17 -7
  166. package/test/integration/StoreAndDelete.test.ts +11 -10
  167. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -6
  168. package/test/integration/StoreRpcRemote.test.ts +3 -5
  169. package/test/unit/AddressTools.test.ts +4 -0
  170. package/test/unit/LocalDataStore.test.ts +37 -29
  171. package/test/unit/PeerManager.test.ts +7 -8
  172. package/test/unit/RandomContactList.test.ts +3 -3
  173. package/test/unit/RecursiveOperationManager.test.ts +2 -1
  174. package/test/unit/RecursiveOperationSession.test.ts +2 -3
  175. package/test/unit/Router.test.ts +2 -2
  176. package/test/unit/RoutingSession.test.ts +2 -2
  177. package/test/unit/SortedContactList.test.ts +6 -6
  178. package/test/unit/StoreManager.test.ts +26 -23
  179. package/test/unit/versionCompatibility.test.ts +16 -0
  180. package/test/utils/customMatchers.ts +3 -2
  181. package/test/utils/mock/mockDataEntry.ts +8 -6
  182. package/test/utils/utils.ts +4 -4
  183. package/tsconfig.browser.json +2 -1
  184. package/tsconfig.jest.json +2 -1
  185. package/tsconfig.node.json +2 -1
  186. package/dist/src/helpers/nodeId.d.ts +0 -6
  187. package/dist/src/helpers/nodeId.js +0 -31
  188. package/dist/src/helpers/nodeId.js.map +0 -1
  189. package/src/helpers/nodeId.ts +0 -28
@@ -5,7 +5,7 @@ import { PeerDescriptor, RouteMessageAck, RouteMessageError, RouteMessageWrapper
5
5
  import { IRouterRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
6
6
  import { DuplicateDetector } from './DuplicateDetector'
7
7
  import { RoutingMode } from './RoutingSession'
8
- import { getNodeIdFromBinary } from '../../helpers/nodeId'
8
+ import { getDhtAddressFromRaw } from '../../identifiers'
9
9
 
10
10
  interface RouterRpcLocalConfig {
11
11
  doRouteMessage: (routedMessage: RouteMessageWrapper, mode?: RoutingMode) => RouteMessageAck
@@ -37,7 +37,7 @@ export class RouterRpcLocal implements IRouterRpc {
37
37
  async routeMessage(routedMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
38
38
  if (this.config.duplicateRequestDetector.isMostLikelyDuplicate(routedMessage.requestId)) {
39
39
  logger.trace(`Routing message ${routedMessage.requestId} from ${getNodeIdFromPeerDescriptor(routedMessage.sourcePeer!)} `
40
- + `to ${getNodeIdFromBinary(routedMessage.target)} is likely a duplicate`)
40
+ + `to ${getDhtAddressFromRaw(routedMessage.target)} is likely a duplicate`)
41
41
  return createRouteMessageAck(routedMessage, RouteMessageError.DUPLICATE)
42
42
  }
43
43
  logger.trace(`Processing received routeMessage ${routedMessage.requestId}`)
@@ -56,7 +56,7 @@ export class RouterRpcLocal implements IRouterRpc {
56
56
  async forwardMessage(forwardMessage: RouteMessageWrapper): Promise<RouteMessageAck> {
57
57
  if (this.config.duplicateRequestDetector.isMostLikelyDuplicate(forwardMessage.requestId)) {
58
58
  logger.trace(`Forwarding message ${forwardMessage.requestId} from ${getNodeIdFromPeerDescriptor(forwardMessage.sourcePeer!)} `
59
- + `to ${getNodeIdFromBinary(forwardMessage.target)} is likely a duplicate`)
59
+ + `to ${getDhtAddressFromRaw(forwardMessage.target)} is likely a duplicate`)
60
60
  return createRouteMessageAck(forwardMessage, RouteMessageError.DUPLICATE)
61
61
  }
62
62
  logger.trace(`Processing received forward routeMessage ${forwardMessage.requestId}`)
@@ -12,7 +12,7 @@ import { Contact } from '../contact/Contact'
12
12
  import { RecursiveOperationRpcRemote } from '../recursive-operation/RecursiveOperationRpcRemote'
13
13
  import { EXISTING_CONNECTION_TIMEOUT } from '../contact/RpcRemote'
14
14
  import { getPreviousPeer } from './getPreviousPeer'
15
- import { NodeID, getNodeIdFromBinary } from '../../helpers/nodeId'
15
+ import { DhtAddress, getDhtAddressFromRaw } from '../../identifiers'
16
16
 
17
17
  const logger = new Logger(module)
18
18
 
@@ -28,7 +28,6 @@ class RemoteContact extends Contact {
28
28
  this.routerRpcRemote = new RouterRpcRemote(
29
29
  localPeerDescriptor,
30
30
  peer.getPeerDescriptor(),
31
- peer.getServiceId(),
32
31
  rpcCommunicator,
33
32
  RouterRpcClient,
34
33
  EXISTING_CONNECTION_TIMEOUT
@@ -36,7 +35,6 @@ class RemoteContact extends Contact {
36
35
  this.recursiveOperationRpcRemote = new RecursiveOperationRpcRemote(
37
36
  localPeerDescriptor,
38
37
  peer.getPeerDescriptor(),
39
- peer.getServiceId(),
40
38
  rpcCommunicator,
41
39
  RecursiveOperationRpcClient,
42
40
  EXISTING_CONNECTION_TIMEOUT
@@ -69,16 +67,16 @@ interface RoutingSessionConfig {
69
67
  rpcCommunicator: RoutingRpcCommunicator
70
68
  localPeerDescriptor: PeerDescriptor
71
69
  routedMessage: RouteMessageWrapper
72
- connections: Map<NodeID, DhtNodeRpcRemote>
70
+ connections: Map<DhtAddress, DhtNodeRpcRemote>
73
71
  parallelism: number
74
72
  mode: RoutingMode
75
- excludedNodeIds?: Set<NodeID>
73
+ excludedNodeIds?: Set<DhtAddress>
76
74
  }
77
75
 
78
76
  export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
79
77
 
80
78
  public readonly sessionId = v4()
81
- private ongoingRequests: Set<NodeID> = new Set()
79
+ private ongoingRequests: Set<DhtAddress> = new Set()
82
80
  private contactList: SortedContactList<RemoteContact>
83
81
  private failedHopCounter = 0
84
82
  private successfulHopCounter = 0
@@ -91,7 +89,7 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
91
89
  const previousPeer = getPreviousPeer(config.routedMessage)
92
90
  const previousId = previousPeer ? getNodeIdFromPeerDescriptor(previousPeer) : undefined
93
91
  this.contactList = new SortedContactList({
94
- referenceId: getNodeIdFromBinary(config.routedMessage.target),
92
+ referenceId: getDhtAddressFromRaw(config.routedMessage.target),
95
93
  maxSize: 10000, // TODO use config option or named constant?
96
94
  allowToContainReferenceId: true,
97
95
  nodeIdDistanceLimit: previousId,
@@ -100,7 +98,7 @@ export class RoutingSession extends EventEmitter<RoutingSessionEvents> {
100
98
  })
101
99
  }
102
100
 
103
- private onRequestFailed(nodeId: NodeID) {
101
+ private onRequestFailed(nodeId: DhtAddress) {
104
102
  logger.trace('onRequestFailed() sessionId: ' + this.sessionId)
105
103
  if (this.stopped) {
106
104
  return
@@ -1,9 +1,6 @@
1
- import { PeerID, PeerIDKey } from '../../helpers/PeerID'
2
1
  import { DataEntry } from '../../proto/packages/dht/protos/DhtRpc'
3
2
  import { MapWithTtl } from '../../helpers/MapWithTtl'
4
- import { NodeID, getNodeIdFromBinary } from '../../helpers/nodeId'
5
-
6
- type Key = Uint8Array
3
+ import { DhtAddress, getDhtAddressFromRaw } from '../../identifiers'
7
4
 
8
5
  export class LocalDataStore {
9
6
 
@@ -15,31 +12,30 @@ export class LocalDataStore {
15
12
 
16
13
  // A map into which each node can store one value per data key
17
14
  // The first key is the key of the data, the second key is the
18
- // NodeID of the creator of the data
19
- private store: Map<PeerIDKey, MapWithTtl<NodeID, DataEntry>> = new Map()
15
+ // DhtAddress of the creator of the data
16
+ private store: Map<DhtAddress, MapWithTtl<DhtAddress, DataEntry>> = new Map()
20
17
 
21
18
  public storeEntry(dataEntry: DataEntry): boolean {
22
- const dataKey = PeerID.fromValue(dataEntry.key).toKey()
23
- const creatorNodeId = getNodeIdFromBinary(dataEntry.creator)
24
- if (!this.store.has(dataKey)) {
25
- this.store.set(dataKey, new MapWithTtl((e) => Math.min(e.ttl, this.maxTtl)))
19
+ const key = getDhtAddressFromRaw(dataEntry.key)
20
+ const creatorNodeId = getDhtAddressFromRaw(dataEntry.creator)
21
+ if (!this.store.has(key)) {
22
+ this.store.set(key, new MapWithTtl((e) => Math.min(e.ttl, this.maxTtl)))
26
23
  }
27
- if (this.store.get(dataKey)!.has(creatorNodeId)) {
24
+ if (this.store.get(key)!.has(creatorNodeId)) {
28
25
  const storedMillis = (dataEntry.createdAt!.seconds * 1000) + (dataEntry.createdAt!.nanos / 1000000)
29
- const oldLocalEntry = this.store.get(dataKey)!.get(creatorNodeId)!
26
+ const oldLocalEntry = this.store.get(key)!.get(creatorNodeId)!
30
27
  const oldStoredMillis = (oldLocalEntry.createdAt!.seconds * 1000) + (oldLocalEntry.createdAt!.nanos / 1000000)
31
28
  // do nothing if old entry is newer than the one being replicated
32
29
  if (oldStoredMillis >= storedMillis) {
33
30
  return false
34
31
  }
35
32
  }
36
- this.store.get(dataKey)!.set(creatorNodeId, dataEntry)
33
+ this.store.get(key)!.set(creatorNodeId, dataEntry)
37
34
  return true
38
35
  }
39
36
 
40
- public markAsDeleted(key: Key, creator: NodeID): boolean {
41
- const dataKey = PeerID.fromValue(key).toKey()
42
- const item = this.store.get(dataKey)
37
+ public markAsDeleted(key: DhtAddress, creator: DhtAddress): boolean {
38
+ const item = this.store.get(key)
43
39
  if ((item === undefined) || !item.has(creator)) {
44
40
  return false
45
41
  }
@@ -54,37 +50,33 @@ export class LocalDataStore {
54
50
  }
55
51
  }
56
52
 
57
- public getEntries(key: Key): Map<NodeID, DataEntry> {
58
- const dataEntries = new Map<NodeID, DataEntry>
59
- const mapKey = PeerID.fromValue(key).toKey()
60
- this.store.get(mapKey)?.forEach((value, key) => {
61
- dataEntries.set(key, value)
53
+ public getEntries(key: DhtAddress): Map<DhtAddress, DataEntry> {
54
+ const dataEntries = new Map<DhtAddress, DataEntry>
55
+ this.store.get(key)?.forEach((value, creator) => {
56
+ dataEntries.set(creator, value)
62
57
  })
63
58
  return dataEntries
64
59
  }
65
60
 
66
- public setStale(key: Key, creator: NodeID, stale: boolean): void {
67
- const mapKey = PeerID.fromValue(key).toKey()
68
- const storedEntry = this.store.get(mapKey)?.get(creator)
61
+ public setStale(key: DhtAddress, creator: DhtAddress, stale: boolean): void {
62
+ const storedEntry = this.store.get(key)?.get(creator)
69
63
  if (storedEntry) {
70
64
  storedEntry.stale = stale
71
65
  }
72
66
  }
73
67
 
74
- public setAllEntriesAsStale(key: Key): void {
75
- const mapKey = PeerID.fromValue(key).toKey()
76
- this.store.get(mapKey)?.forEach((value) => {
68
+ public setAllEntriesAsStale(key: DhtAddress): void {
69
+ this.store.get(key)?.forEach((value) => {
77
70
  value.stale = true
78
71
  })
79
72
  }
80
73
 
81
- public deleteEntry(key: Key, creator: NodeID): void {
82
- const mapKey = PeerID.fromValue(key).toKey()
83
- const storedEntry = this.store.get(mapKey)?.get(creator)
74
+ public deleteEntry(key: DhtAddress, creator: DhtAddress): void {
75
+ const storedEntry = this.store.get(key)?.get(creator)
84
76
  if (storedEntry) {
85
- this.store.get(mapKey)?.delete(creator)
86
- if (this.store.get(mapKey)?.size() === 0) {
87
- this.store.delete(mapKey)
77
+ this.store.get(key)?.delete(creator)
78
+ if (this.store.get(key)?.size() === 0) {
79
+ this.store.delete(key)
88
80
  }
89
81
  }
90
82
  }
@@ -7,7 +7,7 @@ import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
7
7
  import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
8
8
  import { RecursiveOperationManager } from '../recursive-operation/RecursiveOperationManager'
9
9
  import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
10
- import { Logger, executeSafePromise, hexToBinary } from '@streamr/utils'
10
+ import { Logger, executeSafePromise } from '@streamr/utils'
11
11
  import { LocalDataStore } from './LocalDataStore'
12
12
  import { StoreRpcRemote } from './StoreRpcRemote'
13
13
  import { Timestamp } from '../../proto/google/protobuf/timestamp'
@@ -15,7 +15,7 @@ import { SortedContactList } from '../contact/SortedContactList'
15
15
  import { Contact } from '../contact/Contact'
16
16
  import { ServiceID } from '../../types/ServiceID'
17
17
  import { findIndex } from 'lodash'
18
- import { NodeID, areEqualNodeIds, getNodeIdFromBinary, getNodeIdFromDataKey } from '../../helpers/nodeId'
18
+ import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
19
19
  import { StoreRpcLocal } from './StoreRpcLocal'
20
20
  import { getDistance } from '../PeerManager'
21
21
 
@@ -27,7 +27,7 @@ interface StoreManagerConfig {
27
27
  serviceId: ServiceID
28
28
  highestTtl: number
29
29
  redundancyFactor: number
30
- getClosestNeighborsTo: (id: Uint8Array, n?: number) => PeerDescriptor[]
30
+ getClosestNeighborsTo: (dataKey: DhtAddress, n?: number) => PeerDescriptor[]
31
31
  createRpcRemote: (contact: PeerDescriptor) => StoreRpcRemote
32
32
  }
33
33
 
@@ -46,7 +46,7 @@ export class StoreManager {
46
46
  const rpcLocal = new StoreRpcLocal({
47
47
  localDataStore: this.config.localDataStore,
48
48
  replicateDataToNeighbors: (incomingPeer: PeerDescriptor, dataEntry: DataEntry) => this.replicateDataToNeighbors(incomingPeer, dataEntry),
49
- selfIsWithinRedundancyFactor: (key: Uint8Array): boolean => this.selfIsWithinRedundancyFactor(key)
49
+ selfIsWithinRedundancyFactor: (key: DhtAddress): boolean => this.selfIsWithinRedundancyFactor(key)
50
50
  })
51
51
  this.config.rpcCommunicator.registerRpcMethod(StoreDataRequest, StoreDataResponse, 'storeData',
52
52
  (request: StoreDataRequest) => rpcLocal.storeData(request))
@@ -63,28 +63,25 @@ export class StoreManager {
63
63
  private replicateAndUpdateStaleState(dataEntry: DataEntry, newNode: PeerDescriptor): void {
64
64
  const newNodeId = getNodeIdFromPeerDescriptor(newNode)
65
65
  // TODO use config option or named constant?
66
- const closestToData = this.config.getClosestNeighborsTo(dataEntry.key, 10)
66
+ const closestToData = this.config.getClosestNeighborsTo(getDhtAddressFromRaw(dataEntry.key), 10)
67
67
  const sortedList = new SortedContactList<Contact>({
68
- referenceId: getNodeIdFromDataKey(dataEntry.key),
68
+ referenceId: getDhtAddressFromRaw(dataEntry.key),
69
69
  maxSize: 20, // TODO use config option or named constant?
70
70
  allowToContainReferenceId: true,
71
71
  emitEvents: false
72
72
  })
73
73
  sortedList.addContact(new Contact(this.config.localPeerDescriptor))
74
74
  closestToData.forEach((neighbor) => {
75
- if (!areEqualNodeIds(newNodeId, getNodeIdFromPeerDescriptor(neighbor))) {
75
+ if (newNodeId !== getNodeIdFromPeerDescriptor(neighbor)) {
76
76
  sortedList.addContact(new Contact(neighbor))
77
77
  }
78
78
  })
79
- const selfIsPrimaryStorer = areEqualNodeIds(
80
- sortedList.getClosestContactId(),
81
- getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
82
- )
79
+ const selfIsPrimaryStorer = (sortedList.getClosestContactId() === getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor))
83
80
  if (selfIsPrimaryStorer) {
84
81
  sortedList.addContact(new Contact(newNode))
85
82
  const sorted = sortedList.getContactIds()
86
83
  // findIndex should never return -1 here because we just added the new node to the list
87
- const index = findIndex(sorted, (nodeId) => areEqualNodeIds(nodeId, newNodeId))
84
+ const index = findIndex(sorted, (nodeId) => (nodeId === newNodeId))
88
85
  // if new node is within the storageRedundancyFactor closest nodes to the data
89
86
  // do replicate data to it
90
87
  if (index < this.config.redundancyFactor) {
@@ -92,8 +89,8 @@ export class StoreManager {
92
89
  await this.replicateDataToContact(dataEntry, newNode)
93
90
  })
94
91
  }
95
- } else if (!this.selfIsWithinRedundancyFactor(dataEntry.key)) {
96
- this.config.localDataStore.setStale(dataEntry.key, getNodeIdFromBinary(dataEntry.creator), true)
92
+ } else if (!this.selfIsWithinRedundancyFactor(getDhtAddressFromRaw(dataEntry.key))) {
93
+ this.config.localDataStore.setStale(getDhtAddressFromRaw(dataEntry.key), getDhtAddressFromRaw(dataEntry.creator), true)
97
94
  }
98
95
  }
99
96
 
@@ -106,7 +103,7 @@ export class StoreManager {
106
103
  }
107
104
  }
108
105
 
109
- public async storeDataToDht(key: Uint8Array, data: Any, creator: NodeID): Promise<PeerDescriptor[]> {
106
+ public async storeDataToDht(key: DhtAddress, data: Any, creator: DhtAddress): Promise<PeerDescriptor[]> {
110
107
  logger.debug(`Storing data to DHT ${this.config.serviceId}`)
111
108
  const result = await this.config.recursiveOperationManager.execute(key, RecursiveOperation.FIND_NODE)
112
109
  const closestNodes = result.closestNodes
@@ -116,9 +113,9 @@ export class StoreManager {
116
113
  for (let i = 0; i < closestNodes.length && successfulNodes.length < this.config.redundancyFactor; i++) {
117
114
  if (areEqualPeerDescriptors(this.config.localPeerDescriptor, closestNodes[i])) {
118
115
  this.config.localDataStore.storeEntry({
119
- key,
116
+ key: getRawFromDhtAddress(key),
120
117
  data,
121
- creator: hexToBinary(creator),
118
+ creator: getRawFromDhtAddress(creator),
122
119
  createdAt,
123
120
  storedAt: Timestamp.now(),
124
121
  ttl,
@@ -131,9 +128,9 @@ export class StoreManager {
131
128
  const rpcRemote = this.config.createRpcRemote(closestNodes[i])
132
129
  try {
133
130
  await rpcRemote.storeData({
134
- key,
131
+ key: getRawFromDhtAddress(key),
135
132
  data,
136
- creator: hexToBinary(creator),
133
+ creator: getRawFromDhtAddress(creator),
137
134
  createdAt,
138
135
  ttl
139
136
  })
@@ -146,22 +143,21 @@ export class StoreManager {
146
143
  return successfulNodes
147
144
  }
148
145
 
149
- private selfIsWithinRedundancyFactor(dataKey: Uint8Array): boolean {
146
+ private selfIsWithinRedundancyFactor(dataKey: DhtAddress): boolean {
150
147
  const closestNeighbors = this.config.getClosestNeighborsTo(dataKey, this.config.redundancyFactor)
151
148
  if (closestNeighbors.length < this.config.redundancyFactor) {
152
149
  return true
153
150
  } else {
154
- const localNodeId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
155
- const furthestCloseNeighbor = getNodeIdFromPeerDescriptor(closestNeighbors[closestNeighbors.length - 1])
156
- const dataId = getNodeIdFromDataKey(dataKey)
157
- return getDistance(dataId, localNodeId) < getDistance(dataId, furthestCloseNeighbor)
151
+ const furthestCloseNeighbor = closestNeighbors[closestNeighbors.length - 1]
152
+ const dataKeyRaw = getRawFromDhtAddress(dataKey)
153
+ return getDistance(dataKeyRaw, this.config.localPeerDescriptor.nodeId) < getDistance(dataKeyRaw, furthestCloseNeighbor.nodeId)
158
154
  }
159
155
  }
160
156
 
161
157
  private async replicateDataToClosestNodes(): Promise<void> {
162
158
  const dataEntries = Array.from(this.config.localDataStore.values())
163
159
  await Promise.all(dataEntries.map(async (dataEntry) => {
164
- const neighbors = this.config.getClosestNeighborsTo(dataEntry.key, this.config.redundancyFactor)
160
+ const neighbors = this.config.getClosestNeighborsTo(getDhtAddressFromRaw(dataEntry.key), this.config.redundancyFactor)
165
161
  await Promise.all(neighbors.map(async (neighbor) => {
166
162
  const rpcRemote = this.config.createRpcRemote(neighbor)
167
163
  try {
@@ -178,9 +174,9 @@ export class StoreManager {
178
174
  const localNodeId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
179
175
  const incomingNodeId = getNodeIdFromPeerDescriptor(incomingPeer)
180
176
  // TODO use config option or named constant?
181
- const closestToData = this.config.getClosestNeighborsTo(dataEntry.key, 10)
177
+ const closestToData = this.config.getClosestNeighborsTo(getDhtAddressFromRaw(dataEntry.key), 10)
182
178
  const sortedList = new SortedContactList<Contact>({
183
- referenceId: getNodeIdFromDataKey(dataEntry.key),
179
+ referenceId: getDhtAddressFromRaw(dataEntry.key),
184
180
  maxSize: this.config.redundancyFactor,
185
181
  allowToContainReferenceId: true,
186
182
  emitEvents: false
@@ -189,7 +185,7 @@ export class StoreManager {
189
185
  closestToData.forEach((neighbor) => {
190
186
  sortedList.addContact(new Contact(neighbor))
191
187
  })
192
- const selfIsPrimaryStorer = areEqualNodeIds(sortedList.getClosestContactId(), localNodeId)
188
+ const selfIsPrimaryStorer = (sortedList.getClosestContactId() === localNodeId)
193
189
  const targets = selfIsPrimaryStorer
194
190
  // if we are the closest to the data, replicate to all storageRedundancyFactor nearest
195
191
  ? sortedList.getAllContacts()
@@ -197,7 +193,7 @@ export class StoreManager {
197
193
  : [sortedList.getAllContacts()[0]]
198
194
  targets.forEach((contact) => {
199
195
  const contactNodeId = getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())
200
- if (!areEqualNodeIds(incomingNodeId, contactNodeId) && !areEqualNodeIds(localNodeId, contactNodeId)) {
196
+ if ((incomingNodeId !== contactNodeId) && (localNodeId !== contactNodeId)) {
201
197
  setImmediate(() => {
202
198
  executeSafePromise(async () => {
203
199
  await this.replicateDataToContact(dataEntry, contact.getPeerDescriptor())
@@ -11,11 +11,12 @@ import {
11
11
  import { IStoreRpc } from '../../proto/packages/dht/protos/DhtRpc.server'
12
12
  import { DhtCallContext } from '../../rpc-protocol/DhtCallContext'
13
13
  import { LocalDataStore } from './LocalDataStore'
14
+ import { DhtAddress, getDhtAddressFromRaw } from '../../identifiers'
14
15
 
15
16
  interface StoreRpcLocalConfig {
16
17
  localDataStore: LocalDataStore
17
18
  replicateDataToNeighbors: (incomingPeer: PeerDescriptor, dataEntry: DataEntry) => void
18
- selfIsWithinRedundancyFactor: (key: Uint8Array) => boolean
19
+ selfIsWithinRedundancyFactor: (key: DhtAddress) => boolean
19
20
  }
20
21
 
21
22
  const logger = new Logger(module)
@@ -30,15 +31,15 @@ export class StoreRpcLocal implements IStoreRpc {
30
31
 
31
32
  async storeData(request: StoreDataRequest): Promise<StoreDataResponse> {
32
33
  logger.trace('storeData()')
33
- const { key, data, creator, createdAt, ttl } = request
34
+ const key = getDhtAddressFromRaw(request.key)
34
35
  const selfIsOneOfClosestPeers = this.config.selfIsWithinRedundancyFactor(key)
35
36
  this.config.localDataStore.storeEntry({
36
- key,
37
- data,
38
- creator,
39
- createdAt,
37
+ key: request.key,
38
+ data: request.data,
39
+ creator: request.creator,
40
+ createdAt: request.createdAt,
40
41
  storedAt: Timestamp.now(),
41
- ttl,
42
+ ttl: request.ttl,
42
43
  stale: !selfIsOneOfClosestPeers,
43
44
  deleted: false
44
45
  })
@@ -55,8 +56,9 @@ export class StoreRpcLocal implements IStoreRpc {
55
56
  if (wasStored) {
56
57
  this.config.replicateDataToNeighbors((context as DhtCallContext).incomingSourceDescriptor!, request.entry!)
57
58
  }
58
- if (!this.config.selfIsWithinRedundancyFactor(dataEntry.key)) {
59
- this.config.localDataStore.setAllEntriesAsStale(dataEntry.key)
59
+ const key = getDhtAddressFromRaw(dataEntry.key)
60
+ if (!this.config.selfIsWithinRedundancyFactor(key)) {
61
+ this.config.localDataStore.setAllEntriesAsStale(key)
60
62
  }
61
63
  logger.trace('server-side replicateData() at end')
62
64
  return {}
package/src/exports.ts CHANGED
@@ -19,3 +19,5 @@ export { ManagedConnection } from './connection/ManagedConnection'
19
19
  export { ConnectionType } from './connection/IConnection'
20
20
  export { PeerID } from './helpers/PeerID'
21
21
  export { ServiceID } from './types/ServiceID'
22
+ export { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw, getRawFromDhtAddress } from './identifiers'
23
+ export { getNodeIdFromPeerDescriptor } from './helpers/peerIdFromPeerDescriptor'
@@ -1,10 +1,12 @@
1
1
  import ipaddr from 'ipaddr.js'
2
2
 
3
3
  // IPv4 private address ranges as specified by RFC 1918
4
+ // and private loopback addresses
4
5
  const IPv4PrivateRanges = [
5
6
  '10.0.0.0/8',
6
7
  '172.16.0.0/12',
7
8
  '192.168.0.0/16',
9
+ '127.0.0.0/8'
8
10
  ].map((a) => ipaddr.parseCIDR(a))
9
11
 
10
12
  export function isPrivateIPv4(address: string): boolean {
@@ -2,7 +2,7 @@ import { BrandedString, binaryToHex } from '@streamr/utils'
2
2
  import { UUID } from './UUID'
3
3
  import { IllegalArguments } from './errors'
4
4
  import crypto from 'crypto'
5
- import { NodeID, getNodeIdFromBinary } from './nodeId'
5
+ import { DhtAddress, getDhtAddressFromRaw } from '../identifiers'
6
6
 
7
7
  export type PeerIDKey = BrandedString<'PeerIDKey'>
8
8
 
@@ -69,15 +69,15 @@ export class PeerID {
69
69
  }
70
70
 
71
71
  toString(): string {
72
- return PeerID.textDecoder.decode(this.data) //utf8ArrayToString(this.data)
72
+ return PeerID.textDecoder.decode(this.data)
73
73
  }
74
74
 
75
75
  toKey(): PeerIDKey {
76
76
  return this.key
77
77
  }
78
78
 
79
- toNodeId(): NodeID {
80
- return getNodeIdFromBinary(this.data)
79
+ toNodeId(): DhtAddress {
80
+ return getDhtAddressFromRaw(this.data)
81
81
  }
82
82
 
83
83
  get value(): Uint8Array {
@@ -1,7 +1,7 @@
1
- import { areEqualBinaries, binaryToHex } from '@streamr/utils'
1
+ import { areEqualBinaries } from '@streamr/utils'
2
2
  import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc'
3
3
  import { PeerID, PeerIDKey, createPeerIDKey } from './PeerID'
4
- import { NodeID } from './nodeId'
4
+ import { DhtAddress, getDhtAddressFromRaw } from '../identifiers'
5
5
 
6
6
  export const peerIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerID => {
7
7
  return PeerID.fromValue(peerDescriptor.nodeId)
@@ -9,8 +9,8 @@ export const peerIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerID
9
9
 
10
10
  // TODO could use this in trackerless-network (instead of copy-pasted same implementation)
11
11
  // and move this to nodeId.ts
12
- export const getNodeIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): NodeID => {
13
- return binaryToHex(peerDescriptor.nodeId) as unknown as NodeID
12
+ export const getNodeIdFromPeerDescriptor = (peerDescriptor: PeerDescriptor): DhtAddress => {
13
+ return getDhtAddressFromRaw(peerDescriptor.nodeId)
14
14
  }
15
15
 
16
16
  export const keyFromPeerDescriptor = (peerDescriptor: PeerDescriptor): PeerIDKey => {
@@ -0,0 +1,13 @@
1
+ // Is able to compare versions such as 1.2.3 and 1.2.4
2
+ // can also compare versions such as 100.0.0-pretestnet.0 and 100.0.0-pretestnet.40
3
+ export const isCompatibleVersion = (version1: string, version2: string): boolean => {
4
+ const minorVersion1 = excludePatchVersion(version1)
5
+ const minorVersion2 = excludePatchVersion(version2)
6
+ return minorVersion1 === minorVersion2
7
+ }
8
+
9
+ export const excludePatchVersion = (version: string): string => {
10
+ const versionParts = version.split('.')
11
+ versionParts.pop()
12
+ return versionParts.join('.')
13
+ }
@@ -0,0 +1,20 @@
1
+ import { BrandedString, binaryToHex, hexToBinary } 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
+ export type DhtAddress = BrandedString<'DhtAddress'>
8
+ export type DhtAddressRaw = Uint8Array
9
+
10
+ export const getDhtAddressFromRaw = (raw: DhtAddressRaw): DhtAddress => {
11
+ return binaryToHex(raw) as unknown as DhtAddress
12
+ }
13
+
14
+ export const getRawFromDhtAddress = (address: DhtAddress): DhtAddressRaw => {
15
+ return hexToBinary(address) as unknown as DhtAddressRaw
16
+ }
17
+
18
+ export const createRandomDhtAddress = (): DhtAddress => {
19
+ return getDhtAddressFromRaw(crypto.randomBytes(KADEMLIA_ID_LENGTH_IN_BYTES))
20
+ }
@@ -189,10 +189,6 @@ export interface PingResponse {
189
189
  * @generated from protobuf message dht.LeaveNotice
190
190
  */
191
191
  export interface LeaveNotice {
192
- /**
193
- * @generated from protobuf field: string serviceId = 1;
194
- */
195
- serviceId: string;
196
192
  }
197
193
  /**
198
194
  * @generated from protobuf message dht.PeerDescriptor
@@ -334,6 +330,10 @@ export interface HandshakeRequest {
334
330
  * @generated from protobuf field: optional dht.PeerDescriptor targetPeerDescriptor = 2;
335
331
  */
336
332
  targetPeerDescriptor?: PeerDescriptor;
333
+ /**
334
+ * @generated from protobuf field: string version = 3;
335
+ */
336
+ version: string;
337
337
  }
338
338
  /**
339
339
  * @generated from protobuf message dht.HandshakeResponse
@@ -347,6 +347,10 @@ export interface HandshakeResponse {
347
347
  * @generated from protobuf field: optional dht.HandshakeError error = 2;
348
348
  */
349
349
  error?: HandshakeError;
350
+ /**
351
+ * @generated from protobuf field: string version = 3;
352
+ */
353
+ version: string;
350
354
  }
351
355
  /**
352
356
  * @generated from protobuf message dht.Message
@@ -615,7 +619,11 @@ export enum HandshakeError {
615
619
  /**
616
620
  * @generated from protobuf enum value: INVALID_TARGET_PEER_DESCRIPTOR = 1;
617
621
  */
618
- INVALID_TARGET_PEER_DESCRIPTOR = 1
622
+ INVALID_TARGET_PEER_DESCRIPTOR = 1,
623
+ /**
624
+ * @generated from protobuf enum value: UNSUPPORTED_VERSION = 2;
625
+ */
626
+ UNSUPPORTED_VERSION = 2
619
627
  }
620
628
  // Wraps all messages
621
629
 
@@ -824,9 +832,7 @@ export const PingResponse = new PingResponse$Type();
824
832
  // @generated message type with reflection information, may provide speed optimized methods
825
833
  class LeaveNotice$Type extends MessageType$<LeaveNotice> {
826
834
  constructor() {
827
- super("dht.LeaveNotice", [
828
- { no: 1, name: "serviceId", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
829
- ]);
835
+ super("dht.LeaveNotice", []);
830
836
  }
831
837
  }
832
838
  /**
@@ -928,7 +934,8 @@ class HandshakeRequest$Type extends MessageType$<HandshakeRequest> {
928
934
  constructor() {
929
935
  super("dht.HandshakeRequest", [
930
936
  { no: 1, name: "sourcePeerDescriptor", kind: "message", T: () => PeerDescriptor },
931
- { no: 2, name: "targetPeerDescriptor", kind: "message", T: () => PeerDescriptor }
937
+ { no: 2, name: "targetPeerDescriptor", kind: "message", T: () => PeerDescriptor },
938
+ { no: 3, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
932
939
  ]);
933
940
  }
934
941
  }
@@ -941,7 +948,8 @@ class HandshakeResponse$Type extends MessageType$<HandshakeResponse> {
941
948
  constructor() {
942
949
  super("dht.HandshakeResponse", [
943
950
  { no: 1, name: "sourcePeerDescriptor", kind: "message", T: () => PeerDescriptor },
944
- { no: 2, name: "error", kind: "enum", opt: true, T: () => ["dht.HandshakeError", HandshakeError] }
951
+ { no: 2, name: "error", kind: "enum", opt: true, T: () => ["dht.HandshakeError", HandshakeError] },
952
+ { no: 3, name: "version", kind: "scalar", T: 9 /*ScalarType.STRING*/ }
945
953
  ]);
946
954
  }
947
955
  }
@@ -2,13 +2,14 @@
2
2
 
3
3
  import KBucket from 'k-bucket'
4
4
  import { range } from 'lodash'
5
+ import { DhtAddressRaw } from '../src/identifiers'
5
6
 
6
- const compareIds = (id1: Uint8Array, id2: Uint8Array) => {
7
+ const compareIds = (id1: DhtAddressRaw, id2: DhtAddressRaw) => {
7
8
  const sorted = [id1, id2].sort()
8
9
  return KBucket.distance(sorted[0], sorted[1])
9
10
  }
10
11
 
11
- const generateIDs = (count: number): Uint8Array[] => {
12
+ const generateIDs = (count: number): DhtAddressRaw[] => {
12
13
  return range(count).map((i) => new Uint8Array([i, 1, 1]))
13
14
  }
14
15
 
@@ -9,6 +9,7 @@ import { PeerID } from '../../src/helpers/PeerID'
9
9
  import { getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../src/helpers/peerIdFromPeerDescriptor'
10
10
  import { Logger, wait } from '@streamr/utils'
11
11
  import { debugVars } from '../../src/helpers/debugHelpers'
12
+ import { getDhtAddressFromRaw } from '../../src/identifiers'
12
13
 
13
14
  const logger = new Logger(module)
14
15
 
@@ -28,10 +29,10 @@ describe('Find correctness', () => {
28
29
  beforeEach(async () => {
29
30
 
30
31
  nodes = []
31
- entryPoint = await createMockConnectionDhtNode(simulator, Uint8Array.from(dhtIds[0].data), undefined)
32
+ entryPoint = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[0].data)), undefined)
32
33
 
33
34
  for (let i = 1; i < NUM_NODES; i++) {
34
- const node = await createMockConnectionDhtNode(simulator, Uint8Array.from(dhtIds[i].data), undefined)
35
+ const node = await createMockConnectionDhtNode(simulator, getDhtAddressFromRaw(Uint8Array.from(dhtIds[i].data)), undefined)
35
36
  nodes.push(node)
36
37
  }
37
38
  })
@@ -65,7 +66,7 @@ describe('Find correctness', () => {
65
66
 
66
67
  logger.info('starting find')
67
68
  const targetId = Uint8Array.from(dhtIds[9].data)
68
- const results = await nodes[159].executeRecursiveOperation(targetId, RecursiveOperation.FIND_NODE)
69
+ const results = await nodes[159].executeRecursiveOperation(getDhtAddressFromRaw(targetId), RecursiveOperation.FIND_NODE)
69
70
  logger.info('find over')
70
71
  expect(results.closestNodes).toBeGreaterThanOrEqual(5)
71
72
  expect(PeerID.fromValue(targetId).equals(peerIdFromPeerDescriptor(results.closestNodes[0])))