@streamr/dht 100.1.1 → 100.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (56) hide show
  1. package/dist/package.json +8 -10
  2. package/dist/src/connection/ConnectionManager.js +4 -6
  3. package/dist/src/connection/ConnectionManager.js.map +1 -1
  4. package/dist/src/dht/DhtNode.js +3 -1
  5. package/dist/src/dht/DhtNode.js.map +1 -1
  6. package/dist/src/dht/PeerManager.d.ts +4 -3
  7. package/dist/src/dht/PeerManager.js +54 -58
  8. package/dist/src/dht/PeerManager.js.map +1 -1
  9. package/dist/src/dht/contact/ContactList.d.ts +2 -8
  10. package/dist/src/dht/contact/ContactList.js +1 -10
  11. package/dist/src/dht/contact/ContactList.js.map +1 -1
  12. package/dist/src/dht/contact/RandomContactList.js +3 -10
  13. package/dist/src/dht/contact/RandomContactList.js.map +1 -1
  14. package/dist/src/dht/contact/RingContactList.d.ts +2 -2
  15. package/dist/src/dht/contact/RingContactList.js +6 -5
  16. package/dist/src/dht/contact/RingContactList.js.map +1 -1
  17. package/dist/src/dht/contact/SortedContactList.d.ts +4 -8
  18. package/dist/src/dht/contact/SortedContactList.js +24 -51
  19. package/dist/src/dht/contact/SortedContactList.js.map +1 -1
  20. package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -7
  21. package/dist/src/dht/discovery/PeerDiscovery.js +2 -2
  22. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  23. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +1 -2
  24. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  25. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +2 -3
  26. package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
  27. package/dist/src/dht/routing/RoutingSession.js +2 -3
  28. package/dist/src/dht/routing/RoutingSession.js.map +1 -1
  29. package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
  30. package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -1
  31. package/dist/src/dht/store/StoreManager.js +6 -7
  32. package/dist/src/dht/store/StoreManager.js.map +1 -1
  33. package/package.json +8 -10
  34. package/src/connection/ConnectionManager.ts +4 -6
  35. package/src/connection/webrtc/BrowserWebrtcConnection.ts +21 -28
  36. package/src/dht/DhtNode.ts +3 -1
  37. package/src/dht/PeerManager.ts +54 -58
  38. package/src/dht/contact/ContactList.ts +2 -12
  39. package/src/dht/contact/RandomContactList.ts +4 -11
  40. package/src/dht/contact/RingContactList.ts +7 -5
  41. package/src/dht/contact/SortedContactList.ts +27 -58
  42. package/src/dht/discovery/PeerDiscovery.ts +7 -3
  43. package/src/dht/recursive-operation/RecursiveOperationManager.ts +1 -2
  44. package/src/dht/recursive-operation/RecursiveOperationSession.ts +2 -3
  45. package/src/dht/routing/RoutingSession.ts +2 -3
  46. package/src/dht/routing/RoutingTablesCache.ts +3 -1
  47. package/src/dht/store/StoreManager.ts +7 -8
  48. package/test/benchmark/SortedContactListBenchmark.test.ts +9 -52
  49. package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +1 -2
  50. package/test/integration/ReplicateData.test.ts +1 -2
  51. package/test/unit/PeerManager.test.ts +56 -7
  52. package/test/unit/SortedContactList.test.ts +17 -36
  53. package/test/benchmark/kademlia-simulation/Contact.ts +0 -32
  54. package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +0 -94
  55. package/test/benchmark/kademlia-simulation/SimulationNode.ts +0 -129
  56. package/test/data/generateGroundTruthData.ts +0 -71
@@ -1 +1 @@
1
- {"version":3,"file":"StoreManager.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreManager.ts"],"names":[],"mappings":";;;AAAA,mEAG+C;AAK/C,0CAA2D;AAG3D,qEAAiE;AACjE,oEAAgE;AAChE,gDAA4C;AAE5C,mDAAgJ;AAChJ,mDAA+C;AAC/C,gDAA4C;AAc5C,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEj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AC,iBAAiB,EAAE,CAAC,CAAA;wBACzE,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE;4BAC9C,IAAI,EAAE,aAAa;4BACnB,sBAAsB,EAAE,CAAC,mBAAmB;yBAC/C,CAAC,CAAA;oBACN,CAAC,CAAC,CAAA;gBACN,CAAC,CAAC,CAAA;YACN,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAA;IAC5C,CAAC;CACJ;AA9KD,oCA8KC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamr/dht",
3
- "version": "100.1.1",
3
+ "version": "100.2.0",
4
4
  "description": "Streamr Network DHT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -23,18 +23,16 @@
23
23
  "test-unit": "jest test/unit",
24
24
  "test-integration": "jest --bail test/integration",
25
25
  "test-end-to-end": "jest --bail test/end-to-end",
26
- "benchmark": "jest test/benchmark",
27
- "prepare-kademlia-simulation": "cd test/data && node --max-old-space-size=8096 -- ../../../../node_modules/.bin/ts-node -P ../../tsconfig.node.json generateGroundTruthData.ts",
28
- "run-kademlia-simulation": "ts-node --project tsconfig.node.json $NODE_DEBUG_OPTION --files test/benchmark/kademlia-simulation/KademliaSimulation.ts"
26
+ "benchmark": "jest test/benchmark"
29
27
  },
30
28
  "dependencies": {
31
29
  "@js-sdsl/ordered-map": "^4.4.2",
32
30
  "@protobuf-ts/runtime": "^2.8.2",
33
31
  "@protobuf-ts/runtime-rpc": "^2.8.2",
34
- "@streamr/autocertifier-client": "100.1.1",
35
- "@streamr/cdn-location": "100.1.1",
36
- "@streamr/proto-rpc": "100.1.1",
37
- "@streamr/utils": "100.1.1",
32
+ "@streamr/autocertifier-client": "100.2.0",
33
+ "@streamr/cdn-location": "100.2.0",
34
+ "@streamr/proto-rpc": "100.2.0",
35
+ "@streamr/utils": "100.2.0",
38
36
  "eventemitter3": "^5.0.0",
39
37
  "heap": "^0.2.6",
40
38
  "ipaddr.js": "^2.0.1",
@@ -49,7 +47,7 @@
49
47
  },
50
48
  "devDependencies": {
51
49
  "@streamr/browser-test-runner": "^0.0.1",
52
- "@streamr/test-utils": "100.1.1",
50
+ "@streamr/test-utils": "100.2.0",
53
51
  "@types/express": "^4.17.21",
54
52
  "@types/heap": "^0.2.34",
55
53
  "@types/k-bucket": "^5.0.1",
@@ -57,7 +55,7 @@
57
55
  "@types/uuid": "^9.0.8",
58
56
  "@types/websocket": "^1.0.10",
59
57
  "@types/ws": "^8.5.10",
60
- "express": "^4.18.3",
58
+ "express": "^4.19.2",
61
59
  "jest-leak-detector": "^27.3.1",
62
60
  "patch-package": "^8.0.0",
63
61
  "ts-essentials": "^9.4.1",
@@ -156,8 +156,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
156
156
  const disconnectionCandidates = new SortedContactList<ManagedConnection>({
157
157
  referenceId: getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()),
158
158
  maxSize: 100000, // TODO use config option or named constant?
159
- allowToContainReferenceId: false,
160
- emitEvents: false
159
+ allowToContainReferenceId: false
161
160
  })
162
161
  this.connections.forEach((connection, key) => {
163
162
  // TODO: Investigate why multiple invalid WS client connections to the same
@@ -172,10 +171,9 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
172
171
  disconnectionCandidates.addContact(connection)
173
172
  }
174
173
  })
175
- const sortedCandidates = disconnectionCandidates.getAllContacts()
176
- const targetNum = this.connections.size - maxConnections
177
- for (let i = 0; i < sortedCandidates.length && i < targetNum; i++) {
178
- const peerDescriptor = sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor()!
174
+ const disconnectables = disconnectionCandidates.getFurthestContacts(this.connections.size - maxConnections)
175
+ for (const disconnectable of disconnectables) {
176
+ const peerDescriptor = disconnectable.getPeerDescriptor()!
179
177
  logger.trace('garbageCollecting ' + getNodeIdFromPeerDescriptor(peerDescriptor))
180
178
  this.gracefullyDisconnectAsync(peerDescriptor, DisconnectMode.NORMAL).catch((_e) => { })
181
179
  }
@@ -68,23 +68,18 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
68
68
 
69
69
  if (isOffering) {
70
70
  this.peerConnection.onnegotiationneeded = async () => {
71
- try {
72
- if (this.peerConnection !== undefined) {
73
- this.makingOffer = true
74
- try {
75
- await this.peerConnection.setLocalDescription()
76
- } catch (err) {
77
- logger.warn('error', { err })
78
- }
79
- if (this.peerConnection.localDescription !== null) {
80
- this.emit('localDescription', this.peerConnection.localDescription?.sdp, this.peerConnection.localDescription?.type)
81
- }
71
+ if (this.peerConnection !== undefined) {
72
+ this.makingOffer = true
73
+ try {
74
+ await this.peerConnection.setLocalDescription()
75
+ } catch (err) {
76
+ logger.warn('Failed to set local description', { err })
77
+ }
78
+ if (this.peerConnection.localDescription !== null) {
79
+ this.emit('localDescription', this.peerConnection.localDescription?.sdp, this.peerConnection.localDescription?.type)
82
80
  }
83
- } catch (err) {
84
- logger.error('error', { err })
85
- } finally {
86
- this.makingOffer = false
87
81
  }
82
+ this.makingOffer = false
88
83
  }
89
84
 
90
85
  const dataChannel = this.peerConnection.createDataChannel('streamrDataChannel')
@@ -107,14 +102,14 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
107
102
  try {
108
103
  await this.peerConnection?.setRemoteDescription({ sdp: description, type: type.toLowerCase() as RTCSdpType })
109
104
  } catch (err) {
110
- logger.warn('error', { err })
105
+ logger.warn('Failed to set remote description', { err })
111
106
  }
112
107
 
113
108
  if ((type.toLowerCase() === RtcDescription.OFFER) && (this.peerConnection !== undefined)) {
114
109
  try {
115
110
  await this.peerConnection.setLocalDescription()
116
111
  } catch (err) {
117
- logger.warn('error', { err })
112
+ logger.warn('Failed to set local description', { err })
118
113
  }
119
114
  if (this.peerConnection.localDescription !== null) {
120
115
  this.emit('localDescription', this.peerConnection.localDescription.sdp, this.peerConnection.localDescription.type)
@@ -123,13 +118,11 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
123
118
  }
124
119
 
125
120
  public addRemoteCandidate(candidate: string, mid: string): void {
126
- try {
127
- this.peerConnection?.addIceCandidate({ candidate: candidate, sdpMid: mid }).then(() => { return }).catch((err: any) => {
128
- logger.warn('error', { err })
121
+ this.peerConnection?.addIceCandidate({ candidate: candidate, sdpMid: mid })
122
+ .then(() => { return })
123
+ .catch((err) => {
124
+ logger.warn('Failed to add ICE candidate', { err })
129
125
  })
130
- } catch (err) {
131
- logger.warn('error', { err })
132
- }
133
126
  }
134
127
 
135
128
  public isOpen(): boolean {
@@ -155,8 +148,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
155
148
  if (this.dataChannel !== undefined) {
156
149
  try {
157
150
  this.dataChannel.close()
158
- } catch (e) {
159
- logger.warn(`dc.close() errored: ${e}`)
151
+ } catch (err) {
152
+ logger.warn('Failed to close data channel', { err })
160
153
  }
161
154
  }
162
155
 
@@ -165,8 +158,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
165
158
  if (this.peerConnection !== undefined) {
166
159
  try {
167
160
  this.peerConnection.close()
168
- } catch (e) {
169
- logger.warn(`conn.close() errored: ${e}`)
161
+ } catch (err) {
162
+ logger.warn('Failed to close connection', { err })
170
163
  }
171
164
  }
172
165
  this.peerConnection = undefined
@@ -200,7 +193,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
200
193
  }
201
194
 
202
195
  dataChannel.onerror = (err) => {
203
- logger.warn(`dc.onError: ${err}`)
196
+ logger.warn('Data channel error', { err })
204
197
  }
205
198
 
206
199
  dataChannel.onmessage = (msg) => {
@@ -340,9 +340,11 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
340
340
  && this.config.entryPoints.length > 0
341
341
  ) {
342
342
  setImmediate(async () => {
343
+ const contactedPeers = new Set<DhtAddress>()
344
+ const distantJoinContactPeers = new Set<DhtAddress>()
343
345
  // TODO should we catch possible promise rejection?
344
346
  await Promise.all(this.config.entryPoints!.map((entryPoint) =>
345
- this.peerDiscovery!.rejoinDht(entryPoint)
347
+ this.peerDiscovery!.rejoinDht(entryPoint, contactedPeers, distantJoinContactPeers)
346
348
  ))
347
349
  })
348
350
  }
@@ -51,59 +51,58 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
51
51
  // * 'connections' are the nodes that are connected to this node on Layer0
52
52
  // * 'contacts' are all non-unresponsive nodes that we know about
53
53
 
54
- // The kademlia k-bucket
55
- private bucket: KBucket<DhtNodeRpcRemote>
54
+ private neighbors: KBucket<DhtNodeRpcRemote>
56
55
  // Nodes that are connected to this node on Layer0
57
56
  public readonly connections: Map<DhtAddress, DhtNodeRpcRemote> = new Map()
58
- // All nodes that we know about
59
- private contacts: SortedContactList<DhtNodeRpcRemote>
60
- private randomPeers: RandomContactList<DhtNodeRpcRemote>
57
+ private closestContacts: SortedContactList<DhtNodeRpcRemote>
58
+ private activeContacts: Set<DhtAddress>
61
59
  private ringContacts: RingContactList<DhtNodeRpcRemote>
60
+ private randomContacts: RandomContactList<DhtNodeRpcRemote>
62
61
  private stopped: boolean = false
63
62
  private readonly config: PeerManagerConfig
64
63
 
65
64
  constructor(config: PeerManagerConfig) {
66
65
  super()
67
66
  this.config = config
68
- this.bucket = new KBucket<DhtNodeRpcRemote>({
67
+ this.neighbors = new KBucket<DhtNodeRpcRemote>({
69
68
  localNodeId: getRawFromDhtAddress(this.config.localNodeId),
70
69
  numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
71
70
  numberOfNodesToPing: this.config.numberOfNodesPerKBucket
72
71
  })
73
- this.ringContacts = new RingContactList<DhtNodeRpcRemote>(getRingIdRawFromPeerDescriptor(this.config.localPeerDescriptor), true)
72
+ this.ringContacts = new RingContactList<DhtNodeRpcRemote>(getRingIdRawFromPeerDescriptor(this.config.localPeerDescriptor))
74
73
  this.ringContacts.on('ringContactAdded', (peerDescriptor: PeerDescriptor, closestPeers: RingContacts) => {
75
74
  this.emit('ringContactAdded', peerDescriptor, closestPeers)
76
75
  })
77
76
  this.ringContacts.on('ringContactRemoved', (peerDescriptor: PeerDescriptor, closestPeers: RingContacts) => {
78
77
  this.emit('ringContactRemoved', peerDescriptor, closestPeers)
79
78
  })
80
- this.bucket.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
81
- this.bucket.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
82
- this.bucket.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
83
- this.bucket.on('updated', () => {
79
+ this.neighbors.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
80
+ this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
81
+ this.neighbors.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
82
+ this.neighbors.on('updated', () => {
84
83
  // TODO: Update contact info to the connection manager and reconnect
85
84
  })
86
- this.contacts = new SortedContactList({
85
+ this.closestContacts = new SortedContactList({
87
86
  referenceId: this.config.localNodeId,
88
87
  maxSize: this.config.maxContactListSize,
89
- allowToContainReferenceId: false,
90
- emitEvents: true
88
+ allowToContainReferenceId: false
91
89
  })
92
- this.contacts.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) => {
90
+ this.closestContacts.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) => {
93
91
  if (this.stopped) {
94
92
  return
95
93
  }
96
94
  this.emit('contactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
97
- this.randomPeers.addContact(this.config.createDhtNodeRpcRemote(removedContact.getPeerDescriptor()))
95
+ this.randomContacts.addContact(this.config.createDhtNodeRpcRemote(removedContact.getPeerDescriptor()))
98
96
  })
99
- this.contacts.on('contactAdded', (contactAdded: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
97
+ this.closestContacts.on('contactAdded', (contactAdded: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
100
98
  this.emit('contactAdded', contactAdded.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
101
99
  )
102
- this.randomPeers = new RandomContactList(this.config.localNodeId, this.config.maxContactListSize)
103
- this.randomPeers.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
100
+ this.activeContacts = new Set()
101
+ this.randomContacts = new RandomContactList(this.config.localNodeId, this.config.maxContactListSize)
102
+ this.randomContacts.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
104
103
  this.emit('randomContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
105
104
  )
106
- this.randomPeers.on('contactAdded', (contactAdded: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
105
+ this.randomContacts.on('contactAdded', (contactAdded: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
107
106
  this.emit('randomContactAdded', contactAdded.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
108
107
  )
109
108
  }
@@ -115,15 +114,13 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
115
114
  const sortingList: SortedContactList<DhtNodeRpcRemote> = new SortedContactList({
116
115
  referenceId: this.config.localNodeId,
117
116
  maxSize: 100, // TODO use config option or named constant?
118
- allowToContainReferenceId: false,
119
- emitEvents: false
117
+ allowToContainReferenceId: false
120
118
  })
121
119
  sortingList.addContacts(oldContacts)
122
- const sortedContacts = sortingList.getAllContacts()
123
- const removableNodeId = sortedContacts[sortedContacts.length - 1].getNodeId()
120
+ const removableNodeId = sortingList.getFurthestContacts(1)[0].getNodeId()
124
121
  this.config.connectionLocker?.weakUnlockConnection(removableNodeId, this.config.lockId)
125
- this.bucket.remove(getRawFromDhtAddress(removableNodeId))
126
- this.bucket.add(newContact)
122
+ this.neighbors.remove(getRawFromDhtAddress(removableNodeId))
123
+ this.neighbors.add(newContact)
127
124
  }
128
125
 
129
126
  private onKBucketRemoved(nodeId: DhtAddress): void {
@@ -132,7 +129,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
132
129
  }
133
130
  this.config.connectionLocker?.weakUnlockConnection(nodeId, this.config.lockId)
134
131
  logger.trace(`Removed contact ${nodeId}`)
135
- if (this.bucket.count() === 0) {
132
+ if (this.neighbors.count() === 0) {
136
133
  this.emit('kBucketEmpty')
137
134
  }
138
135
  }
@@ -180,9 +177,9 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
180
177
  }
181
178
 
182
179
  private getClosestActiveContactNotInBucket(): DhtNodeRpcRemote | undefined {
183
- for (const contactId of this.contacts.getContactIds()) {
184
- if (!this.bucket.get(getRawFromDhtAddress(contactId)) && this.contacts.isActive(contactId)) {
185
- return this.contacts.getContact(contactId)!.contact
180
+ for (const contactId of this.closestContacts.getContactIds()) {
181
+ if (!this.neighbors.get(getRawFromDhtAddress(contactId)) && this.activeContacts.has(contactId)) {
182
+ return this.closestContacts.getContact(contactId)!
186
183
  }
187
184
  }
188
185
  return undefined
@@ -207,7 +204,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
207
204
  logger.trace('disconnected: ' + nodeId)
208
205
  this.connections.delete(nodeId)
209
206
  if (this.config.isLayer0) {
210
- this.bucket.remove(getRawFromDhtAddress(nodeId))
207
+ this.neighbors.remove(getRawFromDhtAddress(nodeId))
211
208
  if (gracefulLeave === true) {
212
209
  logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
213
210
  this.removeContact(nodeId)
@@ -222,25 +219,26 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
222
219
  return
223
220
  }
224
221
  logger.trace(`Removing contact ${nodeId}`)
225
- this.ringContacts.removeContact(this.contacts.getContact(nodeId)?.contact)
226
- this.bucket.remove(getRawFromDhtAddress(nodeId))
227
- this.contacts.removeContact(nodeId)
228
- this.randomPeers.removeContact(nodeId)
222
+ this.ringContacts.removeContact(this.closestContacts.getContact(nodeId))
223
+ this.neighbors.remove(getRawFromDhtAddress(nodeId))
224
+ this.closestContacts.removeContact(nodeId)
225
+ this.activeContacts.delete(nodeId)
226
+ this.randomContacts.removeContact(nodeId)
229
227
  }
230
228
 
231
229
  stop(): void {
232
230
  this.stopped = true
233
- this.bucket.toArray().forEach((rpcRemote: DhtNodeRpcRemote) => {
231
+ this.neighbors.toArray().forEach((rpcRemote: DhtNodeRpcRemote) => {
234
232
  rpcRemote.leaveNotice()
235
- this.bucket.remove(rpcRemote.id)
233
+ this.neighbors.remove(rpcRemote.id)
236
234
  })
237
- this.bucket.removeAllListeners()
235
+ this.neighbors.removeAllListeners()
238
236
  this.ringContacts.getAllContacts().forEach((rpcRemote) => {
239
237
  rpcRemote.leaveNotice()
240
238
  this.ringContacts.removeContact(rpcRemote)
241
239
  })
242
- this.contacts.stop()
243
- this.randomPeers.stop()
240
+ this.closestContacts.stop()
241
+ this.randomContacts.stop()
244
242
  this.connections.clear()
245
243
  }
246
244
 
@@ -248,11 +246,10 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
248
246
  const closest = new SortedContactList<DhtNodeRpcRemote>({
249
247
  referenceId,
250
248
  allowToContainReferenceId: true,
251
- emitEvents: false,
252
249
  excludedNodeIds,
253
250
  maxSize: limit
254
251
  })
255
- this.bucket.toArray().forEach((contact) => closest.addContact(contact))
252
+ this.neighbors.toArray().forEach((contact) => closest.addContact(contact))
256
253
  return closest.getAllContacts()
257
254
  }
258
255
 
@@ -261,11 +258,10 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
261
258
  const closest = new SortedContactList<DhtNodeRpcRemote>({
262
259
  referenceId,
263
260
  allowToContainReferenceId: true,
264
- emitEvents: false,
265
261
  excludedNodeIds,
266
262
  maxSize: limit
267
263
  })
268
- this.contacts.getAllContacts().map((contact) => closest.addContact(contact))
264
+ this.closestContacts.getAllContacts().map((contact) => closest.addContact(contact))
269
265
  return closest.getAllContacts()
270
266
  }
271
267
 
@@ -274,14 +270,14 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
274
270
  limit?: number,
275
271
  excludedIds?: Set<DhtAddress>
276
272
  ): { left: DhtNodeRpcRemote[], right: DhtNodeRpcRemote[] } {
277
- const closest = new RingContactList<DhtNodeRpcRemote>(ringIdRaw, false, excludedIds)
278
- this.contacts.getAllContacts().map((contact) => closest.addContact(contact))
273
+ const closest = new RingContactList<DhtNodeRpcRemote>(ringIdRaw, excludedIds)
274
+ this.closestContacts.getAllContacts().map((contact) => closest.addContact(contact))
279
275
  this.ringContacts.getAllContacts().map((contact) => closest.addContact(contact))
280
276
  return closest.getClosestContacts(limit ?? 8)
281
277
  }
282
278
 
283
279
  getContactCount(excludedNodeIds?: Set<DhtAddress>): number {
284
- return this.contacts.getSize(excludedNodeIds)
280
+ return this.closestContacts.getSize(excludedNodeIds)
285
281
  }
286
282
 
287
283
  getConnectionCount(): number {
@@ -289,15 +285,15 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
289
285
  }
290
286
 
291
287
  getNeighborCount(): number {
292
- return this.bucket.count()
288
+ return this.neighbors.count()
293
289
  }
294
290
 
295
291
  getNeighbors(): PeerDescriptor[] {
296
- return this.bucket.toArray().map((rpcRemote: DhtNodeRpcRemote) => rpcRemote.getPeerDescriptor())
292
+ return this.neighbors.toArray().map((rpcRemote: DhtNodeRpcRemote) => rpcRemote.getPeerDescriptor())
297
293
  }
298
294
 
299
295
  setContactActive(nodeId: DhtAddress): void {
300
- this.contacts.setActive(nodeId)
296
+ this.activeContacts.add(nodeId)
301
297
  }
302
298
 
303
299
  addContact(peerDescriptor: PeerDescriptor): void {
@@ -308,18 +304,18 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
308
304
  if (nodeId !== this.config.localNodeId) {
309
305
  logger.trace(`Adding new contact ${nodeId}`)
310
306
  const remote = this.config.createDhtNodeRpcRemote(peerDescriptor)
311
- const isInBucket = (this.bucket.get(peerDescriptor.nodeId) !== null)
312
- const isInContacts = (this.contacts.getContact(nodeId) !== undefined)
307
+ const isInNeighbors = (this.neighbors.get(peerDescriptor.nodeId) !== null)
308
+ const isInClosestContacts = (this.closestContacts.getContact(nodeId) !== undefined)
313
309
  const isInRingContacts = this.ringContacts.getContact(peerDescriptor) !== undefined
314
310
 
315
- if (isInBucket || isInContacts) {
316
- this.randomPeers.addContact(remote)
311
+ if (isInNeighbors || isInClosestContacts) {
312
+ this.randomContacts.addContact(remote)
317
313
  }
318
- if (!isInBucket) {
319
- this.bucket.add(remote)
314
+ if (!isInNeighbors) {
315
+ this.neighbors.add(remote)
320
316
  }
321
- if (!isInContacts) {
322
- this.contacts.addContact(remote)
317
+ if (!isInClosestContacts) {
318
+ this.closestContacts.addContact(remote)
323
319
  }
324
320
  if (!isInRingContacts) {
325
321
  this.ringContacts.addContact(remote)
@@ -1,16 +1,6 @@
1
1
  import EventEmitter from 'eventemitter3'
2
2
  import { DhtAddress } from '../../identifiers'
3
3
 
4
- export class ContactState<C> {
5
- public contacted = false
6
- public active = false
7
- public contact: C
8
-
9
- constructor(contact: C) {
10
- this.contact = contact
11
- }
12
- }
13
-
14
4
  export interface Events<C> {
15
5
  contactRemoved: (removedContact: C, closestContacts: C[]) => void
16
6
  contactAdded: (contactAdded: C, closestContacts: C[]) => void
@@ -18,7 +8,7 @@ export interface Events<C> {
18
8
 
19
9
  export class ContactList<C extends { getNodeId: () => DhtAddress }> extends EventEmitter<Events<C>> {
20
10
 
21
- protected contactsById: Map<DhtAddress, ContactState<C>> = new Map()
11
+ protected contactsById: Map<DhtAddress, C> = new Map()
22
12
  // TODO move this to SortedContactList
23
13
  protected contactIds: DhtAddress[] = []
24
14
  protected localNodeId: DhtAddress
@@ -36,7 +26,7 @@ export class ContactList<C extends { getNodeId: () => DhtAddress }> extends Even
36
26
  this.defaultContactQueryLimit = defaultContactQueryLimit
37
27
  }
38
28
 
39
- public getContact(id: DhtAddress): ContactState<C> | undefined {
29
+ public getContact(id: DhtAddress): C | undefined {
40
30
  return this.contactsById.get(id)
41
31
  }
42
32
 
@@ -1,5 +1,5 @@
1
1
  import { DhtAddress } from '../../identifiers'
2
- import { ContactList, ContactState } from './ContactList'
2
+ import { ContactList } from './ContactList'
3
3
 
4
4
  export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extends ContactList<C> {
5
5
 
@@ -27,7 +27,7 @@ export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extend
27
27
  this.removeContact(toRemove)
28
28
  }
29
29
  this.contactIds.push(contact.getNodeId())
30
- this.contactsById.set(contact.getNodeId(), new ContactState(contact))
30
+ this.contactsById.set(contact.getNodeId(), contact)
31
31
  this.emit(
32
32
  'contactAdded',
33
33
  contact,
@@ -39,7 +39,7 @@ export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extend
39
39
 
40
40
  removeContact(id: DhtAddress): boolean {
41
41
  if (this.contactsById.has(id)) {
42
- const removed = this.contactsById.get(id)!.contact
42
+ const removed = this.contactsById.get(id)!
43
43
  const index = this.contactIds.findIndex((nodeId) => (nodeId === id))
44
44
  this.contactIds.splice(index, 1)
45
45
  this.contactsById.delete(id)
@@ -50,13 +50,6 @@ export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extend
50
50
  }
51
51
 
52
52
  public getContacts(limit = this.defaultContactQueryLimit): C[] {
53
- const ret: C[] = []
54
- this.contactIds.forEach((contactId) => {
55
- const contact = this.contactsById.get(contactId)
56
- if (contact) {
57
- ret.push(contact.contact)
58
- }
59
- })
60
- return ret.slice(0, limit)
53
+ return this.contactIds.slice(0, limit).map((contactId) => this.contactsById.get(contactId)!)
61
54
  }
62
55
  }
@@ -19,12 +19,10 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
19
19
  private readonly excludedIds: Set<DhtAddress>
20
20
  private readonly leftNeighbors: OrderedMap<RingDistance, C>
21
21
  private readonly rightNeighbors: OrderedMap<RingDistance, C>
22
- private readonly emitEvents: boolean
23
22
 
24
- constructor(rawReferenceId: RingIdRaw, emitEvents: boolean, excludedIds?: Set<DhtAddress>) {
23
+ constructor(rawReferenceId: RingIdRaw, excludedIds?: Set<DhtAddress>) {
25
24
  super()
26
25
  this.referenceId = getRingIdFromRaw(rawReferenceId)
27
- this.emitEvents = emitEvents
28
26
  this.excludedIds = excludedIds ?? new Set()
29
27
  this.leftNeighbors = new OrderedMap<RingDistance, C>()
30
28
  this.rightNeighbors = new OrderedMap<RingDistance, C>()
@@ -60,7 +58,7 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
60
58
  }
61
59
  }
62
60
 
63
- if (this.emitEvents && (elementAdded || elementRemoved)) {
61
+ if (this.hasEventListeners() && (elementAdded || elementRemoved)) {
64
62
  const closestContacts = this.getClosestContacts()
65
63
  const closestDescriptors = {
66
64
  left: closestContacts.left.map((c) => c.getPeerDescriptor()),
@@ -92,7 +90,7 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
92
90
  elementRemoved = true
93
91
  }
94
92
 
95
- if (this.emitEvents && elementRemoved) {
93
+ if (this.hasEventListeners() && elementRemoved) {
96
94
  const closestContacts = this.getClosestContacts()
97
95
  const closestDescriptors = { left: closestContacts.left.map((c) => c.getPeerDescriptor()),
98
96
  right: closestContacts.right.map((c) => c.getPeerDescriptor()) }
@@ -148,4 +146,8 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
148
146
  }
149
147
  return ret
150
148
  }
149
+
150
+ private hasEventListeners(): boolean {
151
+ return this.eventNames().length > 0
152
+ }
151
153
  }