@streamr/dht 100.0.0-testnet-two.2 → 100.0.0-testnet-two.4

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 (51) hide show
  1. package/dist/package.json +5 -5
  2. package/dist/src/connection/ConnectionManager.d.ts +5 -4
  3. package/dist/src/connection/ConnectionManager.js +29 -35
  4. package/dist/src/connection/ConnectionManager.js.map +1 -1
  5. package/dist/src/connection/simulator/SimulatorConnection.js +21 -22
  6. package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
  7. package/dist/src/connection/simulator/SimulatorConnector.js +4 -3
  8. package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
  9. package/dist/src/connection/webrtc/NodeWebrtcConnection.js +11 -8
  10. package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
  11. package/dist/src/connection/websocket/WebsocketConnector.js +4 -3
  12. package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
  13. package/dist/src/dht/DhtNode.js +5 -6
  14. package/dist/src/dht/DhtNode.js.map +1 -1
  15. package/dist/src/dht/DhtNodeRpcRemote.js +4 -4
  16. package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
  17. package/dist/src/dht/PeerManager.js +24 -19
  18. package/dist/src/dht/PeerManager.js.map +1 -1
  19. package/dist/src/dht/discovery/PeerDiscovery.js +3 -2
  20. package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
  21. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +4 -4
  22. package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
  23. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +2 -2
  24. package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
  25. package/dist/src/dht/routing/RouterRpcRemote.js +4 -2
  26. package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
  27. package/dist/src/dht/store/LocalDataStore.d.ts +1 -2
  28. package/dist/src/dht/store/LocalDataStore.js +11 -10
  29. package/dist/src/dht/store/LocalDataStore.js.map +1 -1
  30. package/dist/src/dht/store/StoreManager.js +16 -12
  31. package/dist/src/dht/store/StoreManager.js.map +1 -1
  32. package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -2
  33. package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
  34. package/package.json +5 -5
  35. package/src/connection/ConnectionManager.ts +32 -41
  36. package/src/connection/simulator/SimulatorConnection.ts +21 -23
  37. package/src/connection/simulator/SimulatorConnector.ts +4 -3
  38. package/src/connection/webrtc/NodeWebrtcConnection.ts +11 -10
  39. package/src/connection/websocket/WebsocketConnector.ts +4 -3
  40. package/src/dht/DhtNode.ts +5 -6
  41. package/src/dht/DhtNodeRpcRemote.ts +4 -4
  42. package/src/dht/PeerManager.ts +24 -19
  43. package/src/dht/discovery/PeerDiscovery.ts +3 -2
  44. package/src/dht/recursive-operation/RecursiveOperationManager.ts +4 -4
  45. package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +2 -2
  46. package/src/dht/routing/RouterRpcRemote.ts +4 -4
  47. package/src/dht/store/LocalDataStore.ts +10 -11
  48. package/src/dht/store/StoreManager.ts +16 -12
  49. package/src/helpers/peerIdFromPeerDescriptor.ts +0 -2
  50. package/test/integration/ReplicateData.test.ts +19 -13
  51. package/test/unit/LocalDataStore.test.ts +15 -23
@@ -33,10 +33,11 @@ class StoreManager {
33
33
  }
34
34
  replicateAndUpdateStaleState(dataEntry, newNode) {
35
35
  const newNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(newNode);
36
+ const key = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key);
36
37
  // TODO use config option or named constant?
37
- const closestToData = this.config.getClosestNeighborsTo((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), 10);
38
+ const closestToData = this.config.getClosestNeighborsTo(key, 10);
38
39
  const sortedList = new SortedContactList_1.SortedContactList({
39
- referenceId: (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key),
40
+ referenceId: key,
40
41
  maxSize: 20,
41
42
  allowToContainReferenceId: true,
42
43
  emitEvents: false
@@ -61,8 +62,8 @@ class StoreManager {
61
62
  });
62
63
  }
63
64
  }
64
- else if (!this.selfIsWithinRedundancyFactor((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key))) {
65
- this.config.localDataStore.setStale((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.creator), true);
65
+ else if (!this.selfIsWithinRedundancyFactor(key)) {
66
+ this.config.localDataStore.setStale(key, (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.creator), true);
66
67
  }
67
68
  }
68
69
  async replicateDataToContact(dataEntry, contact) {
@@ -82,11 +83,13 @@ class StoreManager {
82
83
  const ttl = this.config.highestTtl; // ToDo: make TTL decrease according to some nice curve
83
84
  const createdAt = timestamp_1.Timestamp.now();
84
85
  for (let i = 0; i < closestNodes.length && successfulNodes.length < this.config.redundancyFactor; i++) {
86
+ const keyRaw = (0, identifiers_1.getRawFromDhtAddress)(key);
87
+ const creatorRaw = (0, identifiers_1.getRawFromDhtAddress)(creator);
85
88
  if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.config.localPeerDescriptor, closestNodes[i])) {
86
89
  this.config.localDataStore.storeEntry({
87
- key: (0, identifiers_1.getRawFromDhtAddress)(key),
90
+ key: keyRaw,
88
91
  data,
89
- creator: (0, identifiers_1.getRawFromDhtAddress)(creator),
92
+ creator: creatorRaw,
90
93
  createdAt,
91
94
  storedAt: timestamp_1.Timestamp.now(),
92
95
  ttl,
@@ -99,9 +102,9 @@ class StoreManager {
99
102
  const rpcRemote = this.config.createRpcRemote(closestNodes[i]);
100
103
  try {
101
104
  await rpcRemote.storeData({
102
- key: (0, identifiers_1.getRawFromDhtAddress)(key),
105
+ key: keyRaw,
103
106
  data,
104
- creator: (0, identifiers_1.getRawFromDhtAddress)(creator),
107
+ creator: creatorRaw,
105
108
  createdAt,
106
109
  ttl
107
110
  });
@@ -144,10 +147,11 @@ class StoreManager {
144
147
  // sort own contact list according to data id
145
148
  const localNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.config.localPeerDescriptor);
146
149
  const incomingNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(incomingPeer);
150
+ const key = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key);
147
151
  // TODO use config option or named constant?
148
- const closestToData = this.config.getClosestNeighborsTo((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), 10);
152
+ const closestToData = this.config.getClosestNeighborsTo(key, 10);
149
153
  const sortedList = new SortedContactList_1.SortedContactList({
150
- referenceId: (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key),
154
+ referenceId: key,
151
155
  maxSize: this.config.redundancyFactor,
152
156
  allowToContainReferenceId: true,
153
157
  emitEvents: false
@@ -163,13 +167,13 @@ class StoreManager {
163
167
  // if we are not the closest node to the data, replicate only to the closest one to the data
164
168
  : [sortedList.getAllContacts()[0]];
165
169
  targets.forEach((contact) => {
166
- const contactNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor());
170
+ const contactNodeId = contact.getNodeId();
167
171
  if ((incomingNodeId !== contactNodeId) && (localNodeId !== contactNodeId)) {
168
172
  setImmediate(() => {
169
173
  (0, utils_1.executeSafePromise)(async () => {
170
174
  await this.replicateDataToContact(dataEntry, contact.getPeerDescriptor());
171
175
  logger.trace('replicateDataToContact() returned', {
172
- node: (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor()),
176
+ node: contactNodeId,
173
177
  replicateOnlyToClosest: !selfIsPrimaryStorer
174
178
  });
175
179
  });
@@ -1 +1 @@
1
- {"version":3,"file":"StoreManager.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreManager.ts"],"names":[],"mappings":";;;AAAA,mE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,CAAC,SAAS,EAAE,CAAA;YACzC,IAAI,CAAC,cAAc,KAAK,aAAa,CAAC,IAAI,CAAC,WAAW,KAAK,aAAa,CAAC,EAAE;gBACvE,YAAY,CAAC,GAAG,EAAE;oBACd,IAAA,0BAAkB,EAAC,KAAK,IAAI,EAAE;wBAC1B,MAAM,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,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;aACL;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAA;IAC5C,CAAC;CACJ;AArLD,oCAqLC"}
@@ -8,8 +8,6 @@ const peerIdFromPeerDescriptor = (peerDescriptor) => {
8
8
  return PeerID_1.PeerID.fromValue(peerDescriptor.nodeId);
9
9
  };
10
10
  exports.peerIdFromPeerDescriptor = peerIdFromPeerDescriptor;
11
- // TODO could use this in trackerless-network (instead of copy-pasted same implementation)
12
- // and move this to nodeId.ts
13
11
  const getNodeIdFromPeerDescriptor = (peerDescriptor) => {
14
12
  return (0, identifiers_1.getDhtAddressFromRaw)(peerDescriptor.nodeId);
15
13
  };
@@ -1 +1 @@
1
- {"version":3,"file":"peerIdFromPeerDescriptor.js","sourceRoot":"","sources":["../../../src/helpers/peerIdFromPeerDescriptor.ts"],"names":[],"mappings":";;;AAAA,0CAAiD;AAEjD,qCAA6D;AAC7D,gDAAiE;AAE1D,MAAM,wBAAwB,GAAG,CAAC,cAA8B,EAAU,EAAE;IAC/E,OAAO,eAAM,CAAC,SAAS,CAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AAClD,CAAC,CAAA;AAFY,QAAA,wBAAwB,4B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A+B,EAAE,eAA+B,EAAW,EAAE;IACjH,OAAO,IAAA,wBAAgB,EAAC,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;AAC3E,CAAC,CAAA;AAFY,QAAA,uBAAuB,2BAEnC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@streamr/dht",
3
- "version": "100.0.0-testnet-two.2",
3
+ "version": "100.0.0-testnet-two.4",
4
4
  "description": "Streamr Network DHT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -31,9 +31,9 @@
31
31
  "dependencies": {
32
32
  "@protobuf-ts/runtime": "^2.8.2",
33
33
  "@protobuf-ts/runtime-rpc": "^2.8.2",
34
- "@streamr/autocertifier-client": "100.0.0-testnet-two.2",
35
- "@streamr/proto-rpc": "100.0.0-testnet-two.2",
36
- "@streamr/utils": "100.0.0-testnet-two.2",
34
+ "@streamr/autocertifier-client": "100.0.0-testnet-two.4",
35
+ "@streamr/proto-rpc": "100.0.0-testnet-two.4",
36
+ "@streamr/utils": "100.0.0-testnet-two.4",
37
37
  "eventemitter3": "^5.0.0",
38
38
  "heap": "^0.2.6",
39
39
  "ipaddr.js": "^2.0.1",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "devDependencies": {
47
47
  "@streamr/browser-test-runner": "^0.0.1",
48
- "@streamr/test-utils": "100.0.0-testnet-two.2",
48
+ "@streamr/test-utils": "100.0.0-testnet-two.4",
49
49
  "@types/express": "^4.17.21",
50
50
  "@types/heap": "^0.2.34",
51
51
  "@types/k-bucket": "^5.0.1",
@@ -1,6 +1,5 @@
1
1
  import { CountMetric, LevelMetric, Logger, Metric, MetricsContext, MetricsDefinition, RateMetric, waitForEvent3 } from '@streamr/utils'
2
2
  import { EventEmitter } from 'eventemitter3'
3
- import { Contact } from '../dht/contact/Contact'
4
3
  import { SortedContactList } from '../dht/contact/SortedContactList'
5
4
  import { DuplicateDetector } from '../dht/routing/DuplicateDetector'
6
5
  import * as Err from '../helpers/errors'
@@ -9,7 +8,6 @@ import {
9
8
  getNodeIdFromPeerDescriptor,
10
9
  peerIdFromPeerDescriptor
11
10
  } from '../helpers/peerIdFromPeerDescriptor'
12
- import { protoToString } from '../helpers/protoToString'
13
11
  import {
14
12
  DisconnectMode,
15
13
  DisconnectNotice,
@@ -65,8 +63,8 @@ enum ConnectionManagerState {
65
63
  export interface ConnectionLocker {
66
64
  lockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void
67
65
  unlockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void
68
- weakLockConnection(targetDescriptor: PeerDescriptor): void
69
- weakUnlockConnection(targetDescriptor: PeerDescriptor): void
66
+ weakLockConnection(nodeId: DhtAddress): void
67
+ weakUnlockConnection(nodeId: DhtAddress): void
70
68
  }
71
69
 
72
70
  export interface PortRange {
@@ -154,7 +152,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
154
152
  if (this.connections.size <= maxConnections) {
155
153
  return
156
154
  }
157
- const disconnectionCandidates = new SortedContactList<Contact>({
155
+ const disconnectionCandidates = new SortedContactList<ManagedConnection>({
158
156
  referenceId: getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()),
159
157
  maxSize: 100000, // TODO use config option or named constant?
160
158
  allowToContainReferenceId: false,
@@ -163,15 +161,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
163
161
  this.connections.forEach((connection) => {
164
162
  if (!this.locks.isLocked(connection.getNodeId()) && Date.now() - connection.getLastUsed() > lastUsedLimit) {
165
163
  logger.trace('disconnecting in timeout interval: ' + getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()))
166
- disconnectionCandidates.addContact(new Contact(connection.getPeerDescriptor()!))
164
+ disconnectionCandidates.addContact(connection)
167
165
  }
168
166
  })
169
167
  const sortedCandidates = disconnectionCandidates.getAllContacts()
170
168
  const targetNum = this.connections.size - maxConnections
171
169
  for (let i = 0; i < sortedCandidates.length && i < targetNum; i++) {
172
- logger.trace('garbageCollecting ' + getNodeIdFromPeerDescriptor(sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor()))
173
- this.gracefullyDisconnectAsync(sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor(),
174
- DisconnectMode.NORMAL).catch((_e) => { })
170
+ const peerDescriptor = sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor()!
171
+ logger.trace('garbageCollecting ' + getNodeIdFromPeerDescriptor(peerDescriptor))
172
+ this.gracefullyDisconnectAsync(peerDescriptor, DisconnectMode.NORMAL).catch((_e) => { })
175
173
  }
176
174
  }
177
175
 
@@ -258,12 +256,12 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
258
256
  if (this.isConnectionToSelf(peerDescriptor)) {
259
257
  throw new Err.CannotConnectToSelf('Cannot send to self')
260
258
  }
261
- logger.trace(`Sending message to: ${getNodeIdFromPeerDescriptor(peerDescriptor)}`)
259
+ const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
260
+ logger.trace(`Sending message to: ${nodeId}`)
262
261
  message = {
263
262
  ...message,
264
263
  sourceDescriptor: this.getLocalPeerDescriptor()
265
264
  }
266
- const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
267
265
  let connection = this.connections.get(nodeId)
268
266
  if (!connection && opts.connect) {
269
267
  connection = this.connectorFacade.createConnection(peerDescriptor)
@@ -345,7 +343,6 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
345
343
  let message: Message | undefined
346
344
  try {
347
345
  message = Message.fromBinary(data)
348
- logger.trace(`received protojson: ${protoToString(message, Message)}`)
349
346
  } catch (e) {
350
347
  logger.debug(`Parsing incoming data into Message failed: ${e}`)
351
348
  return
@@ -366,26 +363,22 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
366
363
  }
367
364
 
368
365
  private onDisconnected(connection: ManagedConnection, gracefulLeave: boolean) {
369
- logger.trace(getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()) + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
370
-
371
366
  const nodeId = getNodeIdFromPeerDescriptor(connection.getPeerDescriptor()!)
367
+ logger.trace(nodeId + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
372
368
  const storedConnection = this.connections.get(nodeId)
373
369
  if (storedConnection && storedConnection.connectionId.equals(connection.connectionId)) {
374
370
  this.locks.clearAllLocks(nodeId)
375
371
  this.connections.delete(nodeId)
376
- logger.trace(getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor())
377
- + ' deleted connection in onDisconnected() gracefulLeave: ' + gracefulLeave)
372
+ logger.trace(nodeId + ' deleted connection in onDisconnected() gracefulLeave: ' + gracefulLeave)
378
373
  this.emit('disconnected', connection.getPeerDescriptor()!, gracefulLeave)
379
374
  this.onConnectionCountChange()
380
375
  } else {
381
- logger.trace(getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor())
382
- + ' onDisconnected() did nothing, no such connection in connectionManager')
376
+ logger.trace(nodeId + ' onDisconnected() did nothing, no such connection in connectionManager')
383
377
  if (storedConnection) {
384
- logger.trace(getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor())
385
- + ' connectionIds do not match ' + storedConnection.connectionId.toString() + ' ' + connection.connectionId.toString())
378
+ const connectionId = storedConnection.connectionId.toString()
379
+ logger.trace(nodeId + ' connectionIds do not match ' + connectionId + ' ' + connection.connectionId.toString())
386
380
  }
387
381
  }
388
-
389
382
  }
390
383
 
391
384
  private onNewConnection(connection: ManagedConnection): boolean {
@@ -411,16 +404,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
411
404
  }
412
405
 
413
406
  private acceptNewConnection(newConnection: ManagedConnection): boolean {
414
- logger.trace(getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!) + ' acceptIncomingConnection()')
415
- const newPeerID = peerIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
416
407
  const nodeId = getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
408
+ logger.trace(nodeId + ' acceptIncomingConnection()')
417
409
  if (this.connections.has(nodeId)) {
410
+ const newPeerID = peerIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
418
411
  if (newPeerID.hasSmallerHashThan(peerIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
419
- logger.trace(getNodeIdOrUnknownFromPeerDescriptor(newConnection.getPeerDescriptor())
420
- + ' acceptIncomingConnection() replace current connection')
412
+ logger.trace(nodeId + ' acceptIncomingConnection() replace current connection')
421
413
  // replace the current connection
422
414
  const oldConnection = this.connections.get(nodeId)!
423
- logger.trace('replaced: ' + getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!))
415
+ logger.trace('replaced: ' + nodeId)
424
416
  const buffer = oldConnection.stealOutputBuffer()
425
417
 
426
418
  for (const data of buffer) {
@@ -434,22 +426,22 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
434
426
  }
435
427
  }
436
428
 
437
- logger.trace(getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!) + ' added to connections at acceptIncomingConnection')
429
+ logger.trace(nodeId + ' added to connections at acceptIncomingConnection')
438
430
  this.connections.set(nodeId, newConnection)
439
431
 
440
432
  return true
441
433
  }
442
434
 
443
435
  private async closeConnection(peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string): Promise<void> {
444
- logger.trace(getNodeIdFromPeerDescriptor(peerDescriptor) + ' ' + 'closeConnection() ' + reason)
445
- const id = getNodeIdFromPeerDescriptor(peerDescriptor)
446
- this.locks.clearAllLocks(id)
447
- if (this.connections.has(id)) {
448
- const connectionToClose = this.connections.get(id)!
436
+ const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
437
+ logger.trace(nodeId + ' ' + 'closeConnection() ' + reason)
438
+ this.locks.clearAllLocks(nodeId)
439
+ if (this.connections.has(nodeId)) {
440
+ const connectionToClose = this.connections.get(nodeId)!
449
441
  await connectionToClose.close(gracefulLeave)
450
442
 
451
443
  } else {
452
- logger.trace(getNodeIdFromPeerDescriptor(peerDescriptor) + ' ' + 'closeConnection() this.connections did not have the id')
444
+ logger.trace(nodeId + ' ' + 'closeConnection() this.connections did not have the id')
453
445
  this.emit('disconnected', peerDescriptor, false)
454
446
  }
455
447
  }
@@ -488,19 +480,17 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
488
480
  }
489
481
  }
490
482
 
491
- public weakLockConnection(targetDescriptor: PeerDescriptor): void {
492
- if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
483
+ public weakLockConnection(nodeId: DhtAddress): void {
484
+ if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
493
485
  return
494
486
  }
495
- const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
496
487
  this.locks.addWeakLocked(nodeId)
497
488
  }
498
489
 
499
- public weakUnlockConnection(targetDescriptor: PeerDescriptor): void {
500
- if (this.state === ConnectionManagerState.STOPPED || areEqualPeerDescriptors(targetDescriptor, this.getLocalPeerDescriptor())) {
490
+ public weakUnlockConnection(nodeId: DhtAddress): void {
491
+ if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
501
492
  return
502
493
  }
503
- const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
504
494
  this.locks.removeWeakLocked(nodeId)
505
495
  }
506
496
 
@@ -541,7 +531,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
541
531
  }
542
532
 
543
533
  private async doGracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
544
- logger.trace(getNodeIdFromPeerDescriptor(targetDescriptor) + ' gracefullyDisconnectAsync()')
534
+ const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
535
+ logger.trace(nodeId + ' gracefullyDisconnectAsync()')
545
536
  const rpcRemote = new ConnectionLockRpcRemote(
546
537
  this.getLocalPeerDescriptor(),
547
538
  targetDescriptor,
@@ -551,7 +542,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
551
542
  try {
552
543
  await rpcRemote.gracefulDisconnect(disconnectMode)
553
544
  } catch (ex) {
554
- logger.trace(getNodeIdFromPeerDescriptor(targetDescriptor) + ' remote.gracefulDisconnect() failed' + ex)
545
+ logger.trace(nodeId + ' remote.gracefulDisconnect() failed' + ex)
555
546
  }
556
547
  }
557
548
 
@@ -45,38 +45,34 @@ export class SimulatorConnection extends Connection implements IConnection {
45
45
  this.simulator.send(this, data)
46
46
 
47
47
  } else {
48
- logger.error(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
49
- 'tried to send() on a stopped connection')
48
+ const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
49
+ const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
50
+ logger.error(localNodeId + ', ' + targetNodeId + 'tried to send() on a stopped connection')
50
51
  }
51
52
  }
52
53
 
53
54
  public async close(gracefulLeave: boolean): Promise<void> {
54
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
55
- + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' close()')
55
+ const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
56
+ const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
56
57
 
58
+ logger.trace(localNodeId + ', ' + targetNodeId + ' close()')
57
59
  if (!this.stopped) {
58
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', '
59
- + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' close() not stopped')
60
+ logger.trace(localNodeId + ', ' + targetNodeId + ' close() not stopped')
60
61
  this.stopped = true
61
62
 
62
63
  try {
63
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
64
- ' close() calling simulator.disconnect()')
64
+ logger.trace(localNodeId + ', ' + targetNodeId + ' close() calling simulator.disconnect()')
65
65
  this.simulator.close(this)
66
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
67
- ' close() simulator.disconnect returned')
66
+ logger.trace(localNodeId + ', ' + targetNodeId + ' close() simulator.disconnect returned')
68
67
  } catch (e) {
69
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
70
- 'close aborted' + e)
68
+ logger.trace(localNodeId + ', ' + targetNodeId + 'close aborted' + e)
71
69
  } finally {
72
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
73
- ' calling this.doDisconnect')
70
+ logger.trace(localNodeId + ', ' + targetNodeId + ' calling this.doDisconnect')
74
71
  this.doDisconnect(gracefulLeave)
75
72
  }
76
73
 
77
74
  } else {
78
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', ' + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) +
79
- ' close() tried to close a stopped connection')
75
+ logger.trace(localNodeId + ', ' + targetNodeId + ' close() tried to close a stopped connection')
80
76
  }
81
77
  }
82
78
 
@@ -109,7 +105,8 @@ export class SimulatorConnection extends Connection implements IConnection {
109
105
 
110
106
  public handleIncomingDisconnection(): void {
111
107
  if (!this.stopped) {
112
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' handleIncomingDisconnection()')
108
+ const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
109
+ logger.trace(localNodeId + ' handleIncomingDisconnection()')
113
110
  this.stopped = true
114
111
  this.doDisconnect(false)
115
112
  } else {
@@ -118,23 +115,24 @@ export class SimulatorConnection extends Connection implements IConnection {
118
115
  }
119
116
 
120
117
  public destroy(): void {
118
+ const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
121
119
  if (!this.stopped) {
122
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' destroy()')
120
+ logger.trace(localNodeId + ' destroy()')
123
121
  this.removeAllListeners()
124
122
  this.close(false).catch((_e) => { })
125
123
  } else {
126
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' tried to call destroy() a stopped connection')
124
+ logger.trace(localNodeId + ' tried to call destroy() a stopped connection')
127
125
  }
128
126
  }
129
127
 
130
128
  private doDisconnect(gracefulLeave: boolean) {
131
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ' doDisconnect()')
129
+ const localNodeId = getNodeIdFromPeerDescriptor(this.localPeerDescriptor)
130
+ const targetNodeId = getNodeIdFromPeerDescriptor(this.targetPeerDescriptor)
131
+ logger.trace(localNodeId + ' doDisconnect()')
132
132
  this.stopped = true
133
133
 
134
- logger.trace(getNodeIdFromPeerDescriptor(this.localPeerDescriptor) + ', '
135
- + getNodeIdFromPeerDescriptor(this.targetPeerDescriptor) + ' doDisconnect emitting')
134
+ logger.trace(localNodeId + ', ' + targetNodeId + ' doDisconnect emitting')
136
135
 
137
136
  this.emit('disconnected', gracefulLeave)
138
-
139
137
  }
140
138
  }
@@ -62,7 +62,8 @@ export class SimulatorConnector {
62
62
  }
63
63
 
64
64
  public handleIncomingConnection(sourceConnection: SimulatorConnection): void {
65
- logger.trace(getNodeIdFromPeerDescriptor(sourceConnection.localPeerDescriptor) + ' incoming connection, stopped: ' + this.stopped)
65
+ const localNodeId = getNodeIdFromPeerDescriptor(sourceConnection.localPeerDescriptor)
66
+ logger.trace(localNodeId + ' incoming connection, stopped: ' + this.stopped)
66
67
  if (this.stopped) {
67
68
  return
68
69
  }
@@ -74,10 +75,10 @@ export class SimulatorConnector {
74
75
  logger.trace('connected')
75
76
 
76
77
  managedConnection.once('handshakeRequest', () => {
77
- logger.trace(getNodeIdFromPeerDescriptor(sourceConnection.localPeerDescriptor) + ' incoming handshake request')
78
+ logger.trace(localNodeId + ' incoming handshake request')
78
79
 
79
80
  if (this.onNewConnection(managedConnection)) {
80
- logger.trace(getNodeIdFromPeerDescriptor(sourceConnection.localPeerDescriptor) + ' calling acceptHandshake')
81
+ logger.trace(localNodeId + ' calling acceptHandshake')
81
82
  managedConnection.acceptHandshake()
82
83
  } else {
83
84
  managedConnection.rejectHandshake(HandshakeError.DUPLICATE_CONNECTION)
@@ -80,7 +80,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
80
80
 
81
81
  public start(isOffering: boolean): void {
82
82
  const nodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
83
- logger.trace(`Starting new connection for peer ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`, { isOffering })
83
+ logger.trace(`Starting new connection for peer ${nodeId}`, { isOffering })
84
84
  this.connection = new PeerConnection(nodeId, {
85
85
  iceServers: this.iceServers.map(iceServerAsString),
86
86
  maxMessageSize: this.maxMessageSize,
@@ -112,12 +112,13 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
112
112
 
113
113
  public async setRemoteDescription(description: string, type: string): Promise<void> {
114
114
  if (this.connection) {
115
+ const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
115
116
  try {
116
- logger.trace(`Setting remote descriptor for peer: ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`)
117
+ logger.trace(`Setting remote descriptor for peer: ${remoteNodeId}`)
117
118
  this.connection.setRemoteDescription(description, type as DescriptionType)
118
119
  this.remoteDescriptionSet = true
119
120
  } catch (err) {
120
- logger.debug(`Failed to set remote descriptor for peer ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`)
121
+ logger.debug(`Failed to set remote descriptor for peer ${remoteNodeId}`)
121
122
  }
122
123
  } else {
123
124
  this.doClose(false, `Tried to set description for non-existent connection`)
@@ -127,11 +128,12 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
127
128
  public addRemoteCandidate(candidate: string, mid: string): void {
128
129
  if (this.connection) {
129
130
  if (this.remoteDescriptionSet) {
131
+ const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
130
132
  try {
131
- logger.trace(`Setting remote candidate for peer: ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`)
133
+ logger.trace(`Setting remote candidate for peer: ${remoteNodeId}`)
132
134
  this.connection.addRemoteCandidate(candidate, mid)
133
135
  } catch (err) {
134
- logger.debug(`Failed to set remote candidate for peer ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`)
136
+ logger.debug(`Failed to set remote candidate for peer ${remoteNodeId}`)
135
137
  }
136
138
  } else {
137
139
  // TODO: should queue candidates until remote description is set?
@@ -147,7 +149,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
147
149
  try {
148
150
  this.dataChannel!.sendMessageBinary(data as Buffer)
149
151
  } catch (err) {
150
- logger.debug('Failed to send binary message to ' + getNodeIdFromPeerDescriptor(this.remotePeerDescriptor) + err)
152
+ const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
153
+ logger.debug('Failed to send binary message to ' + remoteNodeId + err)
151
154
  }
152
155
  }
153
156
  }
@@ -158,10 +161,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IConne
158
161
 
159
162
  private doClose(gracefulLeave: boolean, reason?: string): void {
160
163
  if (!this.closed) {
161
- logger.trace(
162
- `Closing Node WebRTC Connection to ${getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)}`
163
- + `${(reason !== undefined) ? `, reason: ${reason}` : ''}`
164
- )
164
+ const remoteNodeId = getNodeIdFromPeerDescriptor(this.remotePeerDescriptor)
165
+ logger.trace(`Closing Node WebRTC Connection to ${remoteNodeId}` + `${(reason !== undefined) ? `, reason: ${reason}` : ''}`)
165
166
 
166
167
  this.closed = true
167
168
 
@@ -241,7 +241,7 @@ export class WebsocketConnector {
241
241
  )
242
242
  managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
243
243
 
244
- this.connectingConnections.set(getNodeIdFromPeerDescriptor(targetPeerDescriptor), managedConnection)
244
+ this.connectingConnections.set(nodeId, managedConnection)
245
245
 
246
246
  const delFunc = () => {
247
247
  if (this.connectingConnections.has(nodeId)) {
@@ -283,9 +283,10 @@ export class WebsocketConnector {
283
283
  undefined,
284
284
  targetPeerDescriptor
285
285
  )
286
- managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(getNodeIdFromPeerDescriptor(targetPeerDescriptor)))
286
+ const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
287
+ managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(nodeId))
287
288
  managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
288
- this.ongoingConnectRequests.set(getNodeIdFromPeerDescriptor(targetPeerDescriptor), managedConnection)
289
+ this.ongoingConnectRequests.set(nodeId, managedConnection)
289
290
  return managedConnection
290
291
  }
291
292
 
@@ -384,13 +384,12 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
384
384
  }
385
385
 
386
386
  private handleMessage(message: Message): void {
387
+ const nodeId = getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
387
388
  if (message.serviceId === this.config.serviceId) {
388
- logger.trace('callig this.handleMessageFromPeer ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
389
- + ' ' + message.serviceId + ' ' + message.messageId)
389
+ logger.trace('calling this.handleMessageFromPeer ' + nodeId + ' ' + message.serviceId + ' ' + message.messageId)
390
390
  this.rpcCommunicator?.handleMessageFromPeer(message)
391
391
  } else {
392
- logger.trace('emit "message" ' + getNodeIdFromPeerDescriptor(message.sourceDescriptor!)
393
- + ' ' + message.serviceId + ' ' + message.messageId)
392
+ logger.trace('emit "message" ' + nodeId + ' ' + message.serviceId + ' ' + message.messageId)
394
393
  this.emit('message', message)
395
394
  }
396
395
  }
@@ -406,7 +405,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
406
405
 
407
406
  public getClosestContacts(limit?: number): PeerDescriptor[] {
408
407
  return this.peerManager!.getClosestContactsTo(
409
- getNodeIdFromPeerDescriptor(this.localPeerDescriptor!),
408
+ this.getNodeId(),
410
409
  limit).map((peer) => peer.getPeerDescriptor()
411
410
  )
412
411
  }
@@ -462,7 +461,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
462
461
  if (this.peerDiscovery!.isJoinOngoing() && connectedEntryPoints.length > 0) {
463
462
  return this.storeDataViaPeer(key, data, sample(connectedEntryPoints)!)
464
463
  }
465
- return this.storeManager!.storeDataToDht(key, data, creator ?? getNodeIdFromPeerDescriptor(this.localPeerDescriptor!))
464
+ return this.storeManager!.storeDataToDht(key, data, creator ?? this.getNodeId())
466
465
  }
467
466
 
468
467
  public async storeDataViaPeer(key: DhtAddress, data: Any, peer: PeerDescriptor): Promise<PeerDescriptor[]> {