@streamr/dht 100.0.0-testnet-two.1 → 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 (170) hide show
  1. package/dist/package.json +5 -5
  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/ManagedConnection.d.ts +2 -2
  8. package/dist/src/connection/simulator/Simulator.js.map +1 -1
  9. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  10. package/dist/src/connection/webrtc/WebrtcConnector.js +1 -1
  11. package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
  12. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
  13. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
  14. package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
  15. package/dist/src/connection/websocket/WebsocketConnector.js +2 -2
  16. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  17. package/dist/src/dht/DhtNode.d.ts +9 -8
  18. package/dist/src/dht/DhtNode.js +21 -16
  19. package/dist/src/dht/DhtNode.js.map +1 -1
  20. package/dist/src/dht/DhtNodeRpcLocal.d.ts +2 -1
  21. package/dist/src/dht/DhtNodeRpcLocal.js +2 -1
  22. package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
  23. package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
  24. package/dist/src/dht/DhtNodeRpcRemote.js +9 -7
  25. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  26. package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
  27. package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
  28. package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
  29. package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -2
  30. package/dist/src/dht/ExternalApiRpcRemote.js +3 -2
  31. package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
  32. package/dist/src/dht/PeerManager.d.ts +9 -9
  33. package/dist/src/dht/PeerManager.js +12 -12
  34. package/dist/src/dht/PeerManager.js.map +1 -1
  35. package/dist/src/dht/contact/Contact.d.ts +2 -2
  36. package/dist/src/dht/contact/ContactList.d.ts +7 -7
  37. package/dist/src/dht/contact/ContactList.js.map +1 -1
  38. package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
  39. package/dist/src/dht/contact/RandomContactList.js +2 -3
  40. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  41. package/dist/src/dht/contact/RpcRemote.d.ts +1 -4
  42. package/dist/src/dht/contact/RpcRemote.js +1 -5
  43. package/dist/src/dht/contact/RpcRemote.js.map +1 -1
  44. package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
  45. package/dist/src/dht/contact/SortedContactList.js +5 -5
  46. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  47. package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -2
  48. package/dist/src/dht/discovery/DiscoverySession.js +9 -9
  49. package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
  50. package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -1
  51. package/dist/src/dht/discovery/PeerDiscovery.js +16 -9
  52. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  53. package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
  54. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +12 -11
  55. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  56. package/dist/src/dht/recursive-operation/RecursiveOperationSession.d.ts +2 -1
  57. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +6 -6
  58. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  59. package/dist/src/dht/routing/Router.d.ts +2 -2
  60. package/dist/src/dht/routing/Router.js +2 -2
  61. package/dist/src/dht/routing/Router.js.map +1 -1
  62. package/dist/src/dht/routing/RouterRpcLocal.js +3 -3
  63. package/dist/src/dht/routing/RouterRpcLocal.js.map +1 -1
  64. package/dist/src/dht/routing/RoutingSession.d.ts +3 -3
  65. package/dist/src/dht/routing/RoutingSession.js +4 -4
  66. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  67. package/dist/src/dht/store/LocalDataStore.d.ts +6 -8
  68. package/dist/src/dht/store/LocalDataStore.js +18 -24
  69. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  70. package/dist/src/dht/store/StoreManager.d.ts +3 -3
  71. package/dist/src/dht/store/StoreManager.js +20 -21
  72. package/dist/src/dht/store/StoreManager.js.map +1 -1
  73. package/dist/src/dht/store/StoreRpcLocal.d.ts +2 -1
  74. package/dist/src/dht/store/StoreRpcLocal.js +10 -8
  75. package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
  76. package/dist/src/exports.d.ts +2 -0
  77. package/dist/src/exports.js +6 -1
  78. package/dist/src/exports.js.map +1 -1
  79. package/dist/src/helpers/AddressTools.js +2 -0
  80. package/dist/src/helpers/AddressTools.js.map +1 -1
  81. package/dist/src/helpers/PeerID.d.ts +2 -2
  82. package/dist/src/helpers/PeerID.js +3 -3
  83. package/dist/src/helpers/PeerID.js.map +1 -1
  84. package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -2
  85. package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -1
  86. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
  87. package/dist/src/identifiers.d.ts +6 -0
  88. package/dist/src/identifiers.js +23 -0
  89. package/dist/src/identifiers.js.map +1 -0
  90. package/package.json +5 -5
  91. package/src/connection/ConnectionLockHandler.ts +15 -15
  92. package/src/connection/ConnectionLockRpcLocal.ts +3 -3
  93. package/src/connection/ConnectionManager.ts +4 -7
  94. package/src/connection/ManagedConnection.ts +2 -2
  95. package/src/connection/simulator/Simulator.ts +2 -2
  96. package/src/connection/simulator/SimulatorConnector.ts +2 -2
  97. package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
  98. package/src/connection/webrtc/WebrtcConnector.ts +2 -3
  99. package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -3
  100. package/src/connection/websocket/WebsocketConnector.ts +5 -6
  101. package/src/dht/DhtNode.ts +31 -29
  102. package/src/dht/DhtNodeRpcLocal.ts +3 -2
  103. package/src/dht/DhtNodeRpcRemote.ts +14 -12
  104. package/src/dht/ExternalApiRpcLocal.ts +15 -6
  105. package/src/dht/ExternalApiRpcRemote.ts +5 -4
  106. package/src/dht/PeerManager.ts +20 -20
  107. package/src/dht/contact/Contact.ts +2 -2
  108. package/src/dht/contact/ContactList.ts +7 -7
  109. package/src/dht/contact/RandomContactList.ts +6 -6
  110. package/src/dht/contact/RpcRemote.ts +0 -8
  111. package/src/dht/contact/SortedContactList.ts +22 -22
  112. package/src/dht/discovery/DiscoverySession.ts +16 -14
  113. package/src/dht/discovery/PeerDiscovery.ts +32 -11
  114. package/src/dht/recursive-operation/RecursiveOperationManager.ts +14 -14
  115. package/src/dht/recursive-operation/RecursiveOperationSession.ts +11 -11
  116. package/src/dht/routing/Router.ts +5 -5
  117. package/src/dht/routing/RouterRpcLocal.ts +3 -3
  118. package/src/dht/routing/RoutingSession.ts +6 -8
  119. package/src/dht/store/LocalDataStore.ts +25 -33
  120. package/src/dht/store/StoreManager.ts +25 -29
  121. package/src/dht/store/StoreRpcLocal.ts +11 -9
  122. package/src/exports.ts +2 -0
  123. package/src/helpers/AddressTools.ts +2 -0
  124. package/src/helpers/PeerID.ts +4 -4
  125. package/src/helpers/peerIdFromPeerDescriptor.ts +4 -4
  126. package/src/identifiers.ts +20 -0
  127. package/test/RandomGraphSimulation.ts +3 -2
  128. package/test/benchmark/Find.test.ts +4 -3
  129. package/test/benchmark/KademliaCorrectness.test.ts +4 -4
  130. package/test/benchmark/SortedContactListBenchmark.test.ts +15 -14
  131. package/test/benchmark/kademlia-simulation/Contact.ts +7 -8
  132. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
  133. package/test/benchmark/kademlia-simulation/SimulationNode.ts +10 -11
  134. package/test/data/generateGroundTruthData.ts +5 -4
  135. package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
  136. package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
  137. package/test/end-to-end/memory-leak.test.ts +3 -2
  138. package/test/integration/ConnectionManager.test.ts +3 -3
  139. package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -1
  140. package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
  141. package/test/integration/DhtNodeRpcRemote.test.ts +3 -2
  142. package/test/integration/Find.test.ts +3 -3
  143. package/test/integration/Layer1-scale.test.ts +3 -3
  144. package/test/integration/Mock-Layer1-Layer0.test.ts +6 -5
  145. package/test/integration/ReplicateData.test.ts +25 -23
  146. package/test/integration/RouteMessage.test.ts +9 -10
  147. package/test/integration/RouterRpcRemote.test.ts +1 -1
  148. package/test/integration/ScaleDownDht.test.ts +4 -4
  149. package/test/integration/SimultaneousConnections.test.ts +7 -14
  150. package/test/integration/Store.test.ts +17 -7
  151. package/test/integration/StoreAndDelete.test.ts +11 -10
  152. package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -6
  153. package/test/integration/StoreRpcRemote.test.ts +3 -5
  154. package/test/unit/AddressTools.test.ts +4 -0
  155. package/test/unit/LocalDataStore.test.ts +37 -29
  156. package/test/unit/PeerManager.test.ts +7 -8
  157. package/test/unit/RandomContactList.test.ts +3 -3
  158. package/test/unit/RecursiveOperationManager.test.ts +2 -1
  159. package/test/unit/RecursiveOperationSession.test.ts +2 -3
  160. package/test/unit/Router.test.ts +2 -2
  161. package/test/unit/RoutingSession.test.ts +2 -2
  162. package/test/unit/SortedContactList.test.ts +6 -6
  163. package/test/unit/StoreManager.test.ts +26 -23
  164. package/test/utils/customMatchers.ts +3 -2
  165. package/test/utils/mock/mockDataEntry.ts +8 -6
  166. package/test/utils/utils.ts +4 -4
  167. package/dist/src/helpers/nodeId.d.ts +0 -6
  168. package/dist/src/helpers/nodeId.js +0 -31
  169. package/dist/src/helpers/nodeId.js.map +0 -1
  170. package/src/helpers/nodeId.ts +0 -28
@@ -2,26 +2,26 @@ import { ContactState, Events } from './ContactList'
2
2
  import { sortedIndexBy } from 'lodash'
3
3
  import EventEmitter from 'eventemitter3'
4
4
  import { getDistance } from '../PeerManager'
5
- import { NodeID, areEqualNodeIds } from '../../helpers/nodeId'
5
+ import { DhtAddress, getRawFromDhtAddress } from '../../identifiers'
6
6
 
7
7
  export interface SortedContactListConfig {
8
- referenceId: NodeID // all contacts in this list are in sorted by the distance to this ID
8
+ referenceId: DhtAddress // all contacts in this list are in sorted by the distance to this ID
9
9
  allowToContainReferenceId: boolean
10
10
  // TODO could maybe optimize this by removing the flag and then we'd check whether we have
11
11
  // any listeners before we emit the event
12
12
  emitEvents: boolean
13
13
  maxSize?: number
14
14
  // if set, the list can't contain any contacts which are futher away than this limit
15
- nodeIdDistanceLimit?: NodeID
15
+ nodeIdDistanceLimit?: DhtAddress
16
16
  // if set, the list can't contain contacts with these ids
17
- excludedNodeIds?: Set<NodeID>
17
+ excludedNodeIds?: Set<DhtAddress>
18
18
  }
19
19
 
20
- export class SortedContactList<C extends { getNodeId: () => NodeID }> extends EventEmitter<Events<C>> {
20
+ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extends EventEmitter<Events<C>> {
21
21
 
22
22
  private config: SortedContactListConfig
23
- private contactsById: Map<NodeID, ContactState<C>> = new Map()
24
- private contactIds: NodeID[] = []
23
+ private contactsById: Map<DhtAddress, ContactState<C>> = new Map()
24
+ private contactIds: DhtAddress[] = []
25
25
 
26
26
  constructor(
27
27
  config: SortedContactListConfig
@@ -31,11 +31,11 @@ export class SortedContactList<C extends { getNodeId: () => NodeID }> extends Ev
31
31
  this.compareIds = this.compareIds.bind(this)
32
32
  }
33
33
 
34
- public getClosestContactId(): NodeID {
34
+ public getClosestContactId(): DhtAddress {
35
35
  return this.contactIds[0]
36
36
  }
37
37
 
38
- public getContactIds(): NodeID[] {
38
+ public getContactIds(): DhtAddress[] {
39
39
  return this.contactIds
40
40
  }
41
41
 
@@ -44,7 +44,7 @@ export class SortedContactList<C extends { getNodeId: () => NodeID }> extends Ev
44
44
  return
45
45
  }
46
46
 
47
- if ((!this.config.allowToContainReferenceId && areEqualNodeIds(this.config.referenceId, contact.getNodeId())) ||
47
+ if ((!this.config.allowToContainReferenceId && (this.config.referenceId === contact.getNodeId())) ||
48
48
  (this.config.nodeIdDistanceLimit !== undefined && this.compareIds(this.config.nodeIdDistanceLimit, contact.getNodeId()) < 0)) {
49
49
  return
50
50
  }
@@ -53,7 +53,7 @@ export class SortedContactList<C extends { getNodeId: () => NodeID }> extends Ev
53
53
  this.contactsById.set(contact.getNodeId(), new ContactState(contact))
54
54
 
55
55
  // eslint-disable-next-line max-len
56
- const index = sortedIndexBy(this.contactIds, contact.getNodeId(), (id: NodeID) => { return this.distanceToReferenceId(id) })
56
+ const index = sortedIndexBy(this.contactIds, contact.getNodeId(), (id: DhtAddress) => { return this.distanceToReferenceId(id) })
57
57
  this.contactIds.splice(index, 0, contact.getNodeId())
58
58
  } else if (this.compareIds(this.contactIds[this.config.maxSize - 1], contact.getNodeId()) > 0) {
59
59
  const removedId = this.contactIds.pop()
@@ -62,7 +62,7 @@ export class SortedContactList<C extends { getNodeId: () => NodeID }> extends Ev
62
62
  this.contactsById.set(contact.getNodeId(), new ContactState(contact))
63
63
 
64
64
  // eslint-disable-next-line max-len
65
- const index = sortedIndexBy(this.contactIds, contact.getNodeId(), (id: NodeID) => { return this.distanceToReferenceId(id) })
65
+ const index = sortedIndexBy(this.contactIds, contact.getNodeId(), (id: DhtAddress) => { return this.distanceToReferenceId(id) })
66
66
  this.contactIds.splice(index, 0, contact.getNodeId())
67
67
  if (this.config.emitEvents) {
68
68
  this.emit(
@@ -86,17 +86,17 @@ export class SortedContactList<C extends { getNodeId: () => NodeID }> extends Ev
86
86
  contacts.forEach((contact) => this.addContact(contact))
87
87
  }
88
88
 
89
- public getContact(id: NodeID): ContactState<C> | undefined {
89
+ public getContact(id: DhtAddress): ContactState<C> | undefined {
90
90
  return this.contactsById.get(id)
91
91
  }
92
92
 
93
- public setContacted(contactId: NodeID): void {
93
+ public setContacted(contactId: DhtAddress): void {
94
94
  if (this.contactsById.has(contactId)) {
95
95
  this.contactsById.get(contactId)!.contacted = true
96
96
  }
97
97
  }
98
98
 
99
- public setActive(contactId: NodeID): void {
99
+ public setActive(contactId: DhtAddress): void {
100
100
  if (this.contactsById.has(contactId)) {
101
101
  this.contactsById.get(contactId)!.active = true
102
102
  }
@@ -146,23 +146,23 @@ export class SortedContactList<C extends { getNodeId: () => NodeID }> extends Ev
146
146
  }
147
147
  }
148
148
 
149
- public compareIds(id1: NodeID, id2: NodeID): number {
149
+ public compareIds(id1: DhtAddress, id2: DhtAddress): number {
150
150
  const distance1 = this.distanceToReferenceId(id1)
151
151
  const distance2 = this.distanceToReferenceId(id2)
152
152
  return distance1 - distance2
153
153
  }
154
154
 
155
155
  // TODO inline this method?
156
- private distanceToReferenceId(id: NodeID): number {
157
- // TODO maybe this class should store the referenceId also as UInt8Array so that we don't need to convert it here?
158
- return getDistance(this.config.referenceId, id)
156
+ private distanceToReferenceId(id: DhtAddress): number {
157
+ // TODO maybe this class should store the referenceId also as DhtAddressRaw so that we don't need to convert it here?
158
+ return getDistance(getRawFromDhtAddress(this.config.referenceId), getRawFromDhtAddress(id))
159
159
  }
160
160
 
161
- public removeContact(id: NodeID): boolean {
161
+ public removeContact(id: DhtAddress): boolean {
162
162
  if (this.contactsById.has(id)) {
163
163
  const removed = this.contactsById.get(id)!.contact
164
164
  // TODO use sortedIndexBy?
165
- const index = this.contactIds.findIndex((nodeId) => areEqualNodeIds(nodeId, id))
165
+ const index = this.contactIds.findIndex((nodeId) => (nodeId === id))
166
166
  this.contactIds.splice(index, 1)
167
167
  this.contactsById.delete(id)
168
168
  if (this.config.emitEvents) {
@@ -177,7 +177,7 @@ export class SortedContactList<C extends { getNodeId: () => NodeID }> extends Ev
177
177
  return false
178
178
  }
179
179
 
180
- public isActive(id: NodeID): boolean {
180
+ public isActive(id: DhtAddress): boolean {
181
181
  return this.contactsById.has(id) ? this.contactsById.get(id)!.active : false
182
182
  }
183
183
 
@@ -5,7 +5,7 @@ import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
5
5
  import { PeerManager, getDistance } from '../PeerManager'
6
6
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
7
7
  import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
8
- import { NodeID, getNodeIdFromBinary } from '../../helpers/nodeId'
8
+ import { DhtAddress, getRawFromDhtAddress } from '../../identifiers'
9
9
 
10
10
  const logger = new Logger(module)
11
11
 
@@ -14,20 +14,21 @@ interface DiscoverySessionEvents {
14
14
  }
15
15
 
16
16
  interface DiscoverySessionConfig {
17
- targetId: Uint8Array
17
+ targetId: DhtAddress
18
18
  parallelism: number
19
19
  noProgressLimit: number
20
20
  peerManager: PeerManager
21
+ // Note that contacted peers will be mutated by the DiscoverySession or other parallel sessions
22
+ contactedPeers: Set<DhtAddress>
21
23
  }
22
24
 
23
25
  export class DiscoverySession {
24
-
26
+
25
27
  public readonly id = v4()
26
28
  private stopped = false
27
29
  private emitter = new EventEmitter<DiscoverySessionEvents>()
28
30
  private noProgressCounter = 0
29
- private ongoingClosestPeersRequests: Set<NodeID> = new Set()
30
- private contactedPeers: Set<NodeID> = new Set()
31
+ private ongoingClosestPeersRequests: Set<DhtAddress> = new Set()
31
32
  private readonly config: DiscoverySessionConfig
32
33
 
33
34
  constructor(config: DiscoverySessionConfig) {
@@ -46,22 +47,23 @@ export class DiscoverySession {
46
47
  return []
47
48
  }
48
49
  logger.trace(`Getting closest peers from contact: ${getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())}`)
49
- this.contactedPeers.add(contact.getNodeId())
50
+ this.config.contactedPeers.add(contact.getNodeId())
50
51
  const returnedContacts = await contact.getClosestPeers(this.config.targetId)
51
52
  this.config.peerManager.handlePeerActive(contact.getNodeId())
52
53
  return returnedContacts
53
54
  }
54
55
 
55
- private onClosestPeersRequestSucceeded(nodeId: NodeID, contacts: PeerDescriptor[]) {
56
+ private onClosestPeersRequestSucceeded(nodeId: DhtAddress, contacts: PeerDescriptor[]) {
56
57
  if (!this.ongoingClosestPeersRequests.has(nodeId)) {
57
58
  return
58
59
  }
59
60
  this.ongoingClosestPeersRequests.delete(nodeId)
60
- const oldClosestNeighbor = this.config.peerManager.getClosestNeighborsTo(getNodeIdFromBinary(this.config.targetId), 1)[0]
61
- const oldClosestDistance = getDistance(getNodeIdFromBinary(this.config.targetId), oldClosestNeighbor.getNodeId())
61
+ const targetId = getRawFromDhtAddress(this.config.targetId)
62
+ const oldClosestNeighbor = this.config.peerManager.getClosestNeighborsTo(this.config.targetId, 1)[0]
63
+ const oldClosestDistance = getDistance(targetId, getRawFromDhtAddress(oldClosestNeighbor.getNodeId()))
62
64
  this.addNewContacts(contacts)
63
- const newClosestNeighbor = this.config.peerManager.getClosestNeighborsTo(getNodeIdFromBinary(this.config.targetId), 1)[0]
64
- const newClosestDistance = getDistance(getNodeIdFromBinary(this.config.targetId), newClosestNeighbor.getNodeId())
65
+ const newClosestNeighbor = this.config.peerManager.getClosestNeighborsTo(this.config.targetId, 1)[0]
66
+ const newClosestDistance = getDistance(targetId, getRawFromDhtAddress(newClosestNeighbor.getNodeId()))
65
67
  if (newClosestDistance >= oldClosestDistance) {
66
68
  this.noProgressCounter++
67
69
  }
@@ -80,9 +82,9 @@ export class DiscoverySession {
80
82
  return
81
83
  }
82
84
  const uncontacted = this.config.peerManager.getClosestContactsTo(
83
- getNodeIdFromBinary(this.config.targetId),
85
+ this.config.targetId,
84
86
  this.config.parallelism,
85
- this.contactedPeers
87
+ this.config.contactedPeers
86
88
  )
87
89
  if (uncontacted.length === 0 || this.noProgressCounter >= this.config.noProgressLimit) {
88
90
  this.emitter.emit('discoveryCompleted')
@@ -105,7 +107,7 @@ export class DiscoverySession {
105
107
  }
106
108
 
107
109
  public async findClosestNodes(timeout: number): Promise<void> {
108
- if (this.config.peerManager.getNumberOfContacts(this.contactedPeers) === 0) {
110
+ if (this.config.peerManager.getNumberOfContacts(this.config.contactedPeers) === 0) {
109
111
  return
110
112
  }
111
113
  // TODO add abortController and signal it in stop()
@@ -1,11 +1,11 @@
1
1
  import { DiscoverySession } from './DiscoverySession'
2
2
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
3
- import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor, peerIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
3
+ import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
4
4
  import { PeerDescriptor } from '../../proto/packages/dht/protos/DhtRpc'
5
5
  import { Logger, scheduleAtInterval, setAbortableTimeout } from '@streamr/utils'
6
6
  import { ConnectionManager } from '../../connection/ConnectionManager'
7
7
  import { PeerManager } from '../PeerManager'
8
- import { createRandomNodeId } from '../../helpers/nodeId'
8
+ import { DhtAddress, createRandomDhtAddress } from '../../identifiers'
9
9
  import { ServiceID } from '../../types/ServiceID'
10
10
 
11
11
  interface PeerDiscoveryConfig {
@@ -35,7 +35,27 @@ export class PeerDiscovery {
35
35
  this.abortController = new AbortController()
36
36
  }
37
37
 
38
- async joinDht(entryPointDescriptor: PeerDescriptor, doAdditionalRandomPeerDiscovery = true, retry = true): Promise<void> {
38
+ async joinDht(
39
+ entryPoints: PeerDescriptor[],
40
+ doAdditionalRandomPeerDiscovery = true,
41
+ retry = true
42
+ ): Promise<void> {
43
+ const contactedPeers = new Set<DhtAddress>()
44
+ await Promise.all(entryPoints.map((entryPoint) => this.joinThroughEntryPoint(
45
+ entryPoint,
46
+ contactedPeers,
47
+ doAdditionalRandomPeerDiscovery,
48
+ retry
49
+ )))
50
+ }
51
+
52
+ async joinThroughEntryPoint(
53
+ entryPointDescriptor: PeerDescriptor,
54
+ // Note that this set is mutated by DiscoverySession
55
+ contactedPeers: Set<DhtAddress>,
56
+ doAdditionalRandomPeerDiscovery = true,
57
+ retry = true
58
+ ): Promise<void> {
39
59
  if (this.isStopped()) {
40
60
  return
41
61
  }
@@ -49,22 +69,23 @@ export class PeerDiscovery {
49
69
  }
50
70
  this.config.connectionManager?.lockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`)
51
71
  this.config.peerManager.handleNewPeers([entryPointDescriptor])
52
- const targetId = peerIdFromPeerDescriptor(this.config.localPeerDescriptor).value
53
- const sessions = [this.createSession(targetId)]
72
+ const targetId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
73
+ const sessions = [this.createSession(targetId, contactedPeers)]
54
74
  if (doAdditionalRandomPeerDiscovery) {
55
- sessions.push(this.createSession(createRandomNodeId()))
75
+ sessions.push(this.createSession(createRandomDhtAddress(), contactedPeers))
56
76
  }
57
77
  await this.runSessions(sessions, entryPointDescriptor, retry)
58
78
  this.config.connectionManager?.unlockConnection(entryPointDescriptor, `${this.config.serviceId}::joinDht`)
59
79
 
60
80
  }
61
81
 
62
- private createSession(targetId: Uint8Array): DiscoverySession {
82
+ private createSession(targetId: DhtAddress, contactedPeers: Set<DhtAddress>): DiscoverySession {
63
83
  const sessionOptions = {
64
84
  targetId,
65
85
  parallelism: this.config.parallelism,
66
86
  noProgressLimit: this.config.joinNoProgressLimit,
67
- peerManager: this.config.peerManager
87
+ peerManager: this.config.peerManager,
88
+ contactedPeers
68
89
  }
69
90
  return new DiscoverySession(sessionOptions)
70
91
  }
@@ -100,7 +121,7 @@ export class PeerDiscovery {
100
121
  logger.debug(`Rejoining DHT ${this.config.serviceId}`)
101
122
  this.rejoinOngoing = true
102
123
  try {
103
- await this.joinDht(entryPoint)
124
+ await this.joinThroughEntryPoint(entryPoint, new Set())
104
125
  logger.debug(`Rejoined DHT successfully ${this.config.serviceId}!`)
105
126
  } catch (err) {
106
127
  logger.warn(`Rejoining DHT ${this.config.serviceId} failed`)
@@ -132,8 +153,8 @@ export class PeerDiscovery {
132
153
  )
133
154
  await Promise.allSettled(
134
155
  nodes.map(async (peer: DhtNodeRpcRemote) => {
135
- const contacts = await peer.getClosestPeers(this.config.localPeerDescriptor.nodeId!)
136
- this.config.peerManager.handleNewPeers(contacts)
156
+ const contacts = await peer.getClosestPeers(getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor))
157
+ this.config.peerManager.handleNewPeers(contacts)
137
158
  })
138
159
  )
139
160
  }
@@ -10,7 +10,7 @@ import {
10
10
  import { Router } from '../routing/Router'
11
11
  import { RoutingMode } from '../routing/RoutingSession'
12
12
  import { areEqualPeerDescriptors, getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
13
- import { Logger, areEqualBinaries, hexToBinary, runAndWaitForEvents3, wait } from '@streamr/utils'
13
+ import { Logger, areEqualBinaries, runAndWaitForEvents3, wait } from '@streamr/utils'
14
14
  import { RoutingRpcCommunicator } from '../../transport/RoutingRpcCommunicator'
15
15
  import { RecursiveOperationSessionRpcRemote } from './RecursiveOperationSessionRpcRemote'
16
16
  import { RecursiveOperationSession, RecursiveOperationSessionEvents } from './RecursiveOperationSession'
@@ -24,13 +24,13 @@ import { getPreviousPeer } from '../routing/getPreviousPeer'
24
24
  import { createRouteMessageAck } from '../routing/RouterRpcLocal'
25
25
  import { ServiceID } from '../../types/ServiceID'
26
26
  import { RecursiveOperationRpcLocal } from './RecursiveOperationRpcLocal'
27
- import { NodeID, getNodeIdFromBinary } from '../../helpers/nodeId'
27
+ import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
28
28
  import { getDistance } from '../PeerManager'
29
29
 
30
30
  interface RecursiveOperationManagerConfig {
31
31
  rpcCommunicator: RoutingRpcCommunicator
32
32
  sessionTransport: ITransport
33
- connections: Map<NodeID, DhtNodeRpcRemote>
33
+ connections: Map<DhtAddress, DhtNodeRpcRemote>
34
34
  router: Router
35
35
  localPeerDescriptor: PeerDescriptor
36
36
  serviceId: ServiceID
@@ -75,7 +75,7 @@ export class RecursiveOperationManager {
75
75
  }
76
76
 
77
77
  public async execute(
78
- targetId: Uint8Array,
78
+ targetId: DhtAddress,
79
79
  operation: RecursiveOperation,
80
80
  excludedPeer?: PeerDescriptor,
81
81
  waitForCompletion = true
@@ -154,7 +154,6 @@ export class RecursiveOperationManager {
154
154
  const rpcRemote = new RecursiveOperationSessionRpcRemote(
155
155
  this.config.localPeerDescriptor,
156
156
  targetPeerDescriptor,
157
- serviceId,
158
157
  remoteCommunicator,
159
158
  RecursiveOperationSessionRpcClient,
160
159
  // TODO use config option or named constant?
@@ -169,15 +168,15 @@ export class RecursiveOperationManager {
169
168
  if (this.stopped) {
170
169
  return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
171
170
  }
172
- const targetId = getNodeIdFromBinary(routedMessage.target)
171
+ const targetId = getDhtAddressFromRaw(routedMessage.target)
173
172
  const request = (routedMessage.message!.body as { recursiveOperationRequest: RecursiveOperationRequest }).recursiveOperationRequest
174
173
  // TODO use config option or named constant?
175
- const closestPeersToDestination = this.getClosestConnections(routedMessage.target, 5)
174
+ const closestPeersToDestination = this.getClosestConnections(targetId, 5)
176
175
  const dataEntries = (request.operation === RecursiveOperation.FETCH_DATA)
177
- ? Array.from(this.config.localDataStore.getEntries(hexToBinary(targetId)).values())
176
+ ? Array.from(this.config.localDataStore.getEntries(targetId).values())
178
177
  : []
179
178
  if (request.operation === RecursiveOperation.DELETE_DATA) {
180
- this.config.localDataStore.markAsDeleted(hexToBinary(targetId), getNodeIdFromPeerDescriptor(routedMessage.sourcePeer!))
179
+ this.config.localDataStore.markAsDeleted(targetId, getNodeIdFromPeerDescriptor(routedMessage.sourcePeer!))
181
180
  }
182
181
  if (areEqualBinaries(this.config.localPeerDescriptor.nodeId, routedMessage.target)) {
183
182
  // TODO this is also very similar case to what we do at line 255, could simplify the code paths?
@@ -212,10 +211,10 @@ export class RecursiveOperationManager {
212
211
  }
213
212
  }
214
213
 
215
- private getClosestConnections(nodeId: Uint8Array, limit: number): PeerDescriptor[] {
214
+ private getClosestConnections(referenceId: DhtAddress, limit: number): PeerDescriptor[] {
216
215
  const connectedPeers = Array.from(this.config.connections.values())
217
216
  const closestPeers = new SortedContactList<DhtNodeRpcRemote>({
218
- referenceId: getNodeIdFromBinary(nodeId),
217
+ referenceId,
219
218
  maxSize: limit,
220
219
  allowToContainReferenceId: true,
221
220
  emitEvents: false
@@ -224,9 +223,10 @@ export class RecursiveOperationManager {
224
223
  return closestPeers.getClosestContacts(limit).map((peer) => peer.getPeerDescriptor())
225
224
  }
226
225
 
227
- private isPeerCloserToIdThanSelf(peer: PeerDescriptor, compareToId: NodeID): boolean {
228
- const distance1 = getDistance(getNodeIdFromPeerDescriptor(peer), compareToId)
229
- const distance2 = getDistance(getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor), compareToId)
226
+ private isPeerCloserToIdThanSelf(peer: PeerDescriptor, nodeIdOrDataKey: DhtAddress): boolean {
227
+ const nodeIdOrDataKeyRaw = getRawFromDhtAddress(nodeIdOrDataKey)
228
+ const distance1 = getDistance(peer.nodeId, nodeIdOrDataKeyRaw)
229
+ const distance2 = getDistance(this.config.localPeerDescriptor.nodeId, nodeIdOrDataKeyRaw)
230
230
  return distance1 < distance2
231
231
  }
232
232
 
@@ -19,7 +19,7 @@ import { RecursiveOperationResult } from './RecursiveOperationManager'
19
19
  import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
20
20
  import { ServiceID } from '../../types/ServiceID'
21
21
  import { RecursiveOperationSessionRpcLocal } from './RecursiveOperationSessionRpcLocal'
22
- import { NodeID, areEqualNodeIds, getNodeIdFromBinary } from '../../helpers/nodeId'
22
+ import { DhtAddress, getDhtAddressFromRaw, getRawFromDhtAddress } from '../../identifiers'
23
23
 
24
24
  export interface RecursiveOperationSessionEvents {
25
25
  completed: () => void
@@ -27,7 +27,7 @@ export interface RecursiveOperationSessionEvents {
27
27
 
28
28
  export interface RecursiveOperationSessionConfig {
29
29
  transport: ITransport
30
- targetId: Uint8Array
30
+ targetId: DhtAddress
31
31
  localPeerDescriptor: PeerDescriptor
32
32
  waitedRoutingPathCompletions: number
33
33
  operation: RecursiveOperation
@@ -39,9 +39,9 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
39
39
  private readonly id = v4()
40
40
  private readonly rpcCommunicator: ListeningRpcCommunicator
41
41
  private results: SortedContactList<Contact>
42
- private foundData: Map<NodeID, DataEntry> = new Map()
43
- private allKnownHops: Set<NodeID> = new Set()
44
- private reportedHops: Set<NodeID> = new Set()
42
+ private foundData: Map<DhtAddress, DataEntry> = new Map()
43
+ private allKnownHops: Set<DhtAddress> = new Set()
44
+ private reportedHops: Set<DhtAddress> = new Set()
45
45
  private timeoutTask?: NodeJS.Timeout
46
46
  private completionEventEmitted = false
47
47
  private noCloserNodesReceivedCounter = 0
@@ -51,7 +51,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
51
51
  super()
52
52
  this.config = config
53
53
  this.results = new SortedContactList({
54
- referenceId: getNodeIdFromBinary(config.targetId),
54
+ referenceId: config.targetId,
55
55
  maxSize: 10, // TODO use config option or named constant?
56
56
  allowToContainReferenceId: true,
57
57
  emitEvents: false
@@ -94,7 +94,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
94
94
  const routeMessage: RouteMessageWrapper = {
95
95
  message: msg,
96
96
  requestId: v4(),
97
- target: this.config.targetId,
97
+ target: getRawFromDhtAddress(this.config.targetId),
98
98
  sourcePeer: this.config.localPeerDescriptor,
99
99
  reachableThrough: [],
100
100
  routingPath: []
@@ -103,7 +103,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
103
103
  }
104
104
 
105
105
  private isCompleted(): boolean {
106
- const unreportedHops: Set<NodeID> = new Set(this.allKnownHops)
106
+ const unreportedHops: Set<DhtAddress> = new Set(this.allKnownHops)
107
107
  this.reportedHops.forEach((id) => {
108
108
  unreportedHops.delete(id)
109
109
  })
@@ -146,7 +146,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
146
146
  const localNodeId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
147
147
  routingPath.forEach((desc) => {
148
148
  const newNodeId = getNodeIdFromPeerDescriptor(desc)
149
- if (!areEqualNodeIds(localNodeId, newNodeId)) {
149
+ if (localNodeId !== newNodeId) {
150
150
  this.allKnownHops.add(newNodeId)
151
151
  }
152
152
  })
@@ -155,7 +155,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
155
155
  private setHopAsReported(desc: PeerDescriptor) {
156
156
  const localNodeId = getNodeIdFromPeerDescriptor(this.config.localPeerDescriptor)
157
157
  const newNodeId = getNodeIdFromPeerDescriptor(desc)
158
- if (!areEqualNodeIds(localNodeId, newNodeId)) {
158
+ if (localNodeId !== newNodeId) {
159
159
  this.reportedHops.add(newNodeId)
160
160
  }
161
161
  if (this.isCompleted()) {
@@ -172,7 +172,7 @@ export class RecursiveOperationSession extends EventEmitter<RecursiveOperationSe
172
172
 
173
173
  private processFoundData(dataEntries: DataEntry[]): void {
174
174
  dataEntries.forEach((entry) => {
175
- const creatorNodeId = getNodeIdFromBinary(entry.creator)
175
+ const creatorNodeId = getDhtAddressFromRaw(entry.creator)
176
176
  const existingEntry = this.foundData.get(creatorNodeId)
177
177
  if (!existingEntry || existingEntry.createdAt! < entry.createdAt!
178
178
  || (existingEntry.createdAt! <= entry.createdAt! && entry.deleted)) {
@@ -11,12 +11,12 @@ import { ConnectionManager } from '../../connection/ConnectionManager'
11
11
  import { DhtNodeRpcRemote } from '../DhtNodeRpcRemote'
12
12
  import { v4 } from 'uuid'
13
13
  import { RouterRpcLocal, createRouteMessageAck } from './RouterRpcLocal'
14
- import { NodeID, getNodeIdFromBinary } from '../../helpers/nodeId'
14
+ import { DhtAddress, getDhtAddressFromRaw } from '../../identifiers'
15
15
 
16
16
  export interface RouterConfig {
17
17
  rpcCommunicator: RoutingRpcCommunicator
18
18
  localPeerDescriptor: PeerDescriptor
19
- connections: Map<NodeID, DhtNodeRpcRemote>
19
+ connections: Map<DhtAddress, DhtNodeRpcRemote>
20
20
  addContact: (contact: PeerDescriptor, setActive?: boolean) => void
21
21
  connectionManager?: ConnectionManager
22
22
  }
@@ -30,7 +30,7 @@ const logger = new Logger(module)
30
30
 
31
31
  export class Router {
32
32
 
33
- private readonly forwardingTable: Map<NodeID, ForwardingTableEntry> = new Map()
33
+ private readonly forwardingTable: Map<DhtAddress, ForwardingTableEntry> = new Map()
34
34
  private ongoingRoutingSessions: Map<string, RoutingSession> = new Map()
35
35
  // TODO use config option or named constant?
36
36
  private readonly duplicateRequestDetector: DuplicateDetector = new DuplicateDetector(100000, 100)
@@ -118,7 +118,7 @@ export class Router {
118
118
  return createRouteMessageAck(routedMessage, RouteMessageError.STOPPED)
119
119
  }
120
120
  logger.trace(`Routing message ${routedMessage.requestId} from ${getNodeIdFromPeerDescriptor(routedMessage.sourcePeer!)} `
121
- + `to ${getNodeIdFromBinary(routedMessage.target)}`)
121
+ + `to ${getDhtAddressFromRaw(routedMessage.target)}`)
122
122
  const session = this.createRoutingSession(routedMessage, mode, excludedPeer)
123
123
  const contacts = session.updateAndGetRoutablePeers()
124
124
  if (contacts.length > 0) {
@@ -154,7 +154,7 @@ export class Router {
154
154
  }
155
155
 
156
156
  private createRoutingSession(routedMessage: RouteMessageWrapper, mode: RoutingMode, excludedNode?: PeerDescriptor): RoutingSession {
157
- const excludedNodeIds = new Set<NodeID>(routedMessage.routingPath.map((descriptor) => getNodeIdFromPeerDescriptor(descriptor)))
157
+ const excludedNodeIds = new Set<DhtAddress>(routedMessage.routingPath.map((descriptor) => getNodeIdFromPeerDescriptor(descriptor)))
158
158
  if (excludedNode) {
159
159
  excludedNodeIds.add(getNodeIdFromPeerDescriptor(excludedNode))
160
160
  }
@@ -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