@streamr/dht 100.0.0-testnet-two.2 → 100.0.0-testnet-two.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/package.json +5 -5
- package/dist/src/connection/ConnectionManager.d.ts +5 -4
- package/dist/src/connection/ConnectionManager.js +29 -33
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnection.js +21 -22
- package/dist/src/connection/simulator/SimulatorConnection.js.map +1 -1
- package/dist/src/connection/simulator/SimulatorConnector.js +4 -3
- package/dist/src/connection/simulator/SimulatorConnector.js.map +1 -1
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js +11 -8
- package/dist/src/connection/webrtc/NodeWebrtcConnection.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +4 -3
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.js +5 -6
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.js +4 -4
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.js +24 -19
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +3 -2
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +4 -4
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js +2 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationRpcRemote.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcRemote.js +4 -2
- package/dist/src/dht/routing/RouterRpcRemote.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +1 -2
- package/dist/src/dht/store/LocalDataStore.js +11 -10
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.js +16 -12
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +0 -2
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/package.json +5 -5
- package/src/connection/ConnectionManager.ts +32 -39
- package/src/connection/simulator/SimulatorConnection.ts +21 -23
- package/src/connection/simulator/SimulatorConnector.ts +4 -3
- package/src/connection/webrtc/NodeWebrtcConnection.ts +11 -10
- package/src/connection/websocket/WebsocketConnector.ts +4 -3
- package/src/dht/DhtNode.ts +5 -6
- package/src/dht/DhtNodeRpcRemote.ts +4 -4
- package/src/dht/PeerManager.ts +24 -19
- package/src/dht/discovery/PeerDiscovery.ts +3 -2
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +4 -4
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +2 -2
- package/src/dht/routing/RouterRpcRemote.ts +4 -4
- package/src/dht/store/LocalDataStore.ts +10 -11
- package/src/dht/store/StoreManager.ts +16 -12
- package/src/helpers/peerIdFromPeerDescriptor.ts +0 -2
- package/test/integration/ReplicateData.test.ts +19 -13
- 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(
|
|
38
|
+
const closestToData = this.config.getClosestNeighborsTo(key, 10);
|
|
38
39
|
const sortedList = new SortedContactList_1.SortedContactList({
|
|
39
|
-
referenceId:
|
|
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(
|
|
65
|
-
this.config.localDataStore.setStale(
|
|
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:
|
|
90
|
+
key: keyRaw,
|
|
88
91
|
data,
|
|
89
|
-
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:
|
|
105
|
+
key: keyRaw,
|
|
103
106
|
data,
|
|
104
|
-
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(
|
|
152
|
+
const closestToData = this.config.getClosestNeighborsTo(key, 10);
|
|
149
153
|
const sortedList = new SortedContactList_1.SortedContactList({
|
|
150
|
-
referenceId:
|
|
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 =
|
|
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:
|
|
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,mEAG+C;AAK/C,qFAA6G;AAC7G,0CAA2D;AAG3D,qEAAiE;AACjE,oEAAgE;AAChE,gDAA4C;AAE5C,mCA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AQ,CAAC,CAAC,CAAA;QAChD,CAAC,CAAC,CAAA;QACF,MAAM,mBAAmB,GAAG,CAAC,UAAU,CAAC,mBAAmB,EAAE,KAAK,WAAW,CAAC,CAAA;QAC9E,MAAM,OAAO,GAAG,mBAAmB;YAC/B,sFAAsF;YACtF,CAAC,CAAC,UAAU,CAAC,cAAc,EAAE;YAC7B,4FAA4F;YAC5F,CAAC,CAAC,CAAC,UAAU,CAAC,cAAc,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;QACtC,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACxB,MAAM,aAAa,GAAG,OAAO,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,4BAEpC;
|
|
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,4BAEpC;AAEM,MAAM,2BAA2B,GAAG,CAAC,cAA8B,EAAc,EAAE;IACtF,OAAO,IAAA,kCAAoB,EAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AACtD,CAAC,CAAA;AAFY,QAAA,2BAA2B,+BAEvC;AAEM,MAAM,qBAAqB,GAAG,CAAC,cAA8B,EAAa,EAAE;IAC/E,OAAO,IAAA,wBAAe,EAAC,cAAc,CAAC,MAAM,CAAC,CAAA;AACjD,CAAC,CAAA;AAFY,QAAA,qBAAqB,yBAEjC;AAEM,MAAM,uBAAuB,GAAG,CAAC,eAA+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.
|
|
3
|
+
"version": "100.0.0-testnet-two.3",
|
|
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.
|
|
35
|
-
"@streamr/proto-rpc": "100.0.0-testnet-two.
|
|
36
|
-
"@streamr/utils": "100.0.0-testnet-two.
|
|
34
|
+
"@streamr/autocertifier-client": "100.0.0-testnet-two.3",
|
|
35
|
+
"@streamr/proto-rpc": "100.0.0-testnet-two.3",
|
|
36
|
+
"@streamr/utils": "100.0.0-testnet-two.3",
|
|
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.
|
|
48
|
+
"@streamr/test-utils": "100.0.0-testnet-two.3",
|
|
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'
|
|
@@ -65,8 +64,8 @@ enum ConnectionManagerState {
|
|
|
65
64
|
export interface ConnectionLocker {
|
|
66
65
|
lockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void
|
|
67
66
|
unlockConnection(targetDescriptor: PeerDescriptor, lockId: LockID): void
|
|
68
|
-
weakLockConnection(
|
|
69
|
-
weakUnlockConnection(
|
|
67
|
+
weakLockConnection(nodeId: DhtAddress): void
|
|
68
|
+
weakUnlockConnection(nodeId: DhtAddress): void
|
|
70
69
|
}
|
|
71
70
|
|
|
72
71
|
export interface PortRange {
|
|
@@ -154,7 +153,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
154
153
|
if (this.connections.size <= maxConnections) {
|
|
155
154
|
return
|
|
156
155
|
}
|
|
157
|
-
const disconnectionCandidates = new SortedContactList<
|
|
156
|
+
const disconnectionCandidates = new SortedContactList<ManagedConnection>({
|
|
158
157
|
referenceId: getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()),
|
|
159
158
|
maxSize: 100000, // TODO use config option or named constant?
|
|
160
159
|
allowToContainReferenceId: false,
|
|
@@ -163,15 +162,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
163
162
|
this.connections.forEach((connection) => {
|
|
164
163
|
if (!this.locks.isLocked(connection.getNodeId()) && Date.now() - connection.getLastUsed() > lastUsedLimit) {
|
|
165
164
|
logger.trace('disconnecting in timeout interval: ' + getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()))
|
|
166
|
-
disconnectionCandidates.addContact(
|
|
165
|
+
disconnectionCandidates.addContact(connection)
|
|
167
166
|
}
|
|
168
167
|
})
|
|
169
168
|
const sortedCandidates = disconnectionCandidates.getAllContacts()
|
|
170
169
|
const targetNum = this.connections.size - maxConnections
|
|
171
170
|
for (let i = 0; i < sortedCandidates.length && i < targetNum; i++) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
const peerDescriptor = sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor()!
|
|
172
|
+
logger.trace('garbageCollecting ' + getNodeIdFromPeerDescriptor(peerDescriptor))
|
|
173
|
+
this.gracefullyDisconnectAsync(peerDescriptor, DisconnectMode.NORMAL).catch((_e) => { })
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
|
|
@@ -258,12 +257,12 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
258
257
|
if (this.isConnectionToSelf(peerDescriptor)) {
|
|
259
258
|
throw new Err.CannotConnectToSelf('Cannot send to self')
|
|
260
259
|
}
|
|
261
|
-
|
|
260
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
261
|
+
logger.trace(`Sending message to: ${nodeId}`)
|
|
262
262
|
message = {
|
|
263
263
|
...message,
|
|
264
264
|
sourceDescriptor: this.getLocalPeerDescriptor()
|
|
265
265
|
}
|
|
266
|
-
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
267
266
|
let connection = this.connections.get(nodeId)
|
|
268
267
|
if (!connection && opts.connect) {
|
|
269
268
|
connection = this.connectorFacade.createConnection(peerDescriptor)
|
|
@@ -366,26 +365,22 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
366
365
|
}
|
|
367
366
|
|
|
368
367
|
private onDisconnected(connection: ManagedConnection, gracefulLeave: boolean) {
|
|
369
|
-
logger.trace(getNodeIdOrUnknownFromPeerDescriptor(connection.getPeerDescriptor()) + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
370
|
-
|
|
371
368
|
const nodeId = getNodeIdFromPeerDescriptor(connection.getPeerDescriptor()!)
|
|
369
|
+
logger.trace(nodeId + ' onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
372
370
|
const storedConnection = this.connections.get(nodeId)
|
|
373
371
|
if (storedConnection && storedConnection.connectionId.equals(connection.connectionId)) {
|
|
374
372
|
this.locks.clearAllLocks(nodeId)
|
|
375
373
|
this.connections.delete(nodeId)
|
|
376
|
-
logger.trace(
|
|
377
|
-
+ ' deleted connection in onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
374
|
+
logger.trace(nodeId + ' deleted connection in onDisconnected() gracefulLeave: ' + gracefulLeave)
|
|
378
375
|
this.emit('disconnected', connection.getPeerDescriptor()!, gracefulLeave)
|
|
379
376
|
this.onConnectionCountChange()
|
|
380
377
|
} else {
|
|
381
|
-
logger.trace(
|
|
382
|
-
+ ' onDisconnected() did nothing, no such connection in connectionManager')
|
|
378
|
+
logger.trace(nodeId + ' onDisconnected() did nothing, no such connection in connectionManager')
|
|
383
379
|
if (storedConnection) {
|
|
384
|
-
|
|
385
|
-
|
|
380
|
+
const connectionId = storedConnection.connectionId.toString()
|
|
381
|
+
logger.trace(nodeId + ' connectionIds do not match ' + connectionId + ' ' + connection.connectionId.toString())
|
|
386
382
|
}
|
|
387
383
|
}
|
|
388
|
-
|
|
389
384
|
}
|
|
390
385
|
|
|
391
386
|
private onNewConnection(connection: ManagedConnection): boolean {
|
|
@@ -411,16 +406,15 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
411
406
|
}
|
|
412
407
|
|
|
413
408
|
private acceptNewConnection(newConnection: ManagedConnection): boolean {
|
|
414
|
-
logger.trace(getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!) + ' acceptIncomingConnection()')
|
|
415
|
-
const newPeerID = peerIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
|
|
416
409
|
const nodeId = getNodeIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
|
|
410
|
+
logger.trace(nodeId + ' acceptIncomingConnection()')
|
|
417
411
|
if (this.connections.has(nodeId)) {
|
|
412
|
+
const newPeerID = peerIdFromPeerDescriptor(newConnection.getPeerDescriptor()!)
|
|
418
413
|
if (newPeerID.hasSmallerHashThan(peerIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
|
|
419
|
-
logger.trace(
|
|
420
|
-
+ ' acceptIncomingConnection() replace current connection')
|
|
414
|
+
logger.trace(nodeId + ' acceptIncomingConnection() replace current connection')
|
|
421
415
|
// replace the current connection
|
|
422
416
|
const oldConnection = this.connections.get(nodeId)!
|
|
423
|
-
logger.trace('replaced: ' +
|
|
417
|
+
logger.trace('replaced: ' + nodeId)
|
|
424
418
|
const buffer = oldConnection.stealOutputBuffer()
|
|
425
419
|
|
|
426
420
|
for (const data of buffer) {
|
|
@@ -434,22 +428,22 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
434
428
|
}
|
|
435
429
|
}
|
|
436
430
|
|
|
437
|
-
logger.trace(
|
|
431
|
+
logger.trace(nodeId + ' added to connections at acceptIncomingConnection')
|
|
438
432
|
this.connections.set(nodeId, newConnection)
|
|
439
433
|
|
|
440
434
|
return true
|
|
441
435
|
}
|
|
442
436
|
|
|
443
437
|
private async closeConnection(peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string): Promise<void> {
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
this.locks.clearAllLocks(
|
|
447
|
-
if (this.connections.has(
|
|
448
|
-
const connectionToClose = this.connections.get(
|
|
438
|
+
const nodeId = getNodeIdFromPeerDescriptor(peerDescriptor)
|
|
439
|
+
logger.trace(nodeId + ' ' + 'closeConnection() ' + reason)
|
|
440
|
+
this.locks.clearAllLocks(nodeId)
|
|
441
|
+
if (this.connections.has(nodeId)) {
|
|
442
|
+
const connectionToClose = this.connections.get(nodeId)!
|
|
449
443
|
await connectionToClose.close(gracefulLeave)
|
|
450
444
|
|
|
451
445
|
} else {
|
|
452
|
-
logger.trace(
|
|
446
|
+
logger.trace(nodeId + ' ' + 'closeConnection() this.connections did not have the id')
|
|
453
447
|
this.emit('disconnected', peerDescriptor, false)
|
|
454
448
|
}
|
|
455
449
|
}
|
|
@@ -488,19 +482,17 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
488
482
|
}
|
|
489
483
|
}
|
|
490
484
|
|
|
491
|
-
public weakLockConnection(
|
|
492
|
-
if (this.state === ConnectionManagerState.STOPPED ||
|
|
485
|
+
public weakLockConnection(nodeId: DhtAddress): void {
|
|
486
|
+
if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
|
|
493
487
|
return
|
|
494
488
|
}
|
|
495
|
-
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
496
489
|
this.locks.addWeakLocked(nodeId)
|
|
497
490
|
}
|
|
498
491
|
|
|
499
|
-
public weakUnlockConnection(
|
|
500
|
-
if (this.state === ConnectionManagerState.STOPPED ||
|
|
492
|
+
public weakUnlockConnection(nodeId: DhtAddress): void {
|
|
493
|
+
if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
|
|
501
494
|
return
|
|
502
495
|
}
|
|
503
|
-
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
504
496
|
this.locks.removeWeakLocked(nodeId)
|
|
505
497
|
}
|
|
506
498
|
|
|
@@ -541,7 +533,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
541
533
|
}
|
|
542
534
|
|
|
543
535
|
private async doGracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
|
|
544
|
-
|
|
536
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
537
|
+
logger.trace(nodeId + ' gracefullyDisconnectAsync()')
|
|
545
538
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
546
539
|
this.getLocalPeerDescriptor(),
|
|
547
540
|
targetDescriptor,
|
|
@@ -551,7 +544,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
551
544
|
try {
|
|
552
545
|
await rpcRemote.gracefulDisconnect(disconnectMode)
|
|
553
546
|
} catch (ex) {
|
|
554
|
-
logger.trace(
|
|
547
|
+
logger.trace(nodeId + ' remote.gracefulDisconnect() failed' + ex)
|
|
555
548
|
}
|
|
556
549
|
}
|
|
557
550
|
|
|
@@ -45,38 +45,34 @@ export class SimulatorConnection extends Connection implements IConnection {
|
|
|
45
45
|
this.simulator.send(this, data)
|
|
46
46
|
|
|
47
47
|
} else {
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
55
|
-
|
|
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(
|
|
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(
|
|
64
|
-
' close() calling simulator.disconnect()')
|
|
64
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() calling simulator.disconnect()')
|
|
65
65
|
this.simulator.close(this)
|
|
66
|
-
logger.trace(
|
|
67
|
-
' close() simulator.disconnect returned')
|
|
66
|
+
logger.trace(localNodeId + ', ' + targetNodeId + ' close() simulator.disconnect returned')
|
|
68
67
|
} catch (e) {
|
|
69
|
-
logger.trace(
|
|
70
|
-
'close aborted' + e)
|
|
68
|
+
logger.trace(localNodeId + ', ' + targetNodeId + 'close aborted' + e)
|
|
71
69
|
} finally {
|
|
72
|
-
logger.trace(
|
|
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(
|
|
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
|
-
|
|
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(
|
|
120
|
+
logger.trace(localNodeId + ' destroy()')
|
|
123
121
|
this.removeAllListeners()
|
|
124
122
|
this.close(false).catch((_e) => { })
|
|
125
123
|
} else {
|
|
126
|
-
logger.trace(
|
|
124
|
+
logger.trace(localNodeId + ' tried to call destroy() a stopped connection')
|
|
127
125
|
}
|
|
128
126
|
}
|
|
129
127
|
|
|
130
128
|
private doDisconnect(gracefulLeave: boolean) {
|
|
131
|
-
|
|
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(
|
|
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
|
-
|
|
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(
|
|
78
|
+
logger.trace(localNodeId + ' incoming handshake request')
|
|
78
79
|
|
|
79
80
|
if (this.onNewConnection(managedConnection)) {
|
|
80
|
-
logger.trace(
|
|
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 ${
|
|
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: ${
|
|
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 ${
|
|
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: ${
|
|
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 ${
|
|
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
|
-
|
|
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
|
-
|
|
162
|
-
|
|
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(
|
|
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
|
-
|
|
286
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetPeerDescriptor)
|
|
287
|
+
managedConnection.on('disconnected', () => this.ongoingConnectRequests.delete(nodeId))
|
|
287
288
|
managedConnection.setRemotePeerDescriptor(targetPeerDescriptor)
|
|
288
|
-
this.ongoingConnectRequests.set(
|
|
289
|
+
this.ongoingConnectRequests.set(nodeId, managedConnection)
|
|
289
290
|
return managedConnection
|
|
290
291
|
}
|
|
291
292
|
|
package/src/dht/DhtNode.ts
CHANGED
|
@@ -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('
|
|
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" ' +
|
|
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
|
-
|
|
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 ??
|
|
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[]> {
|
|
@@ -41,7 +41,7 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
|
|
|
41
41
|
}
|
|
42
42
|
|
|
43
43
|
async getClosestPeers(nodeId: DhtAddress): Promise<PeerDescriptor[]> {
|
|
44
|
-
logger.trace(`Requesting getClosestPeers on ${this.serviceId} from ${
|
|
44
|
+
logger.trace(`Requesting getClosestPeers on ${this.serviceId} from ${this.getNodeId()}`)
|
|
45
45
|
const request: ClosestPeersRequest = {
|
|
46
46
|
nodeId: getRawFromDhtAddress(nodeId),
|
|
47
47
|
requestId: v4()
|
|
@@ -56,7 +56,7 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
|
|
|
56
56
|
}
|
|
57
57
|
|
|
58
58
|
async ping(): Promise<boolean> {
|
|
59
|
-
logger.trace(`Requesting ping on ${this.serviceId} from ${
|
|
59
|
+
logger.trace(`Requesting ping on ${this.serviceId} from ${this.getNodeId()}`)
|
|
60
60
|
const request: PingRequest = {
|
|
61
61
|
requestId: v4()
|
|
62
62
|
}
|
|
@@ -67,13 +67,13 @@ export class DhtNodeRpcRemote extends RpcRemote<DhtNodeRpcClient> implements KBu
|
|
|
67
67
|
return true
|
|
68
68
|
}
|
|
69
69
|
} catch (err) {
|
|
70
|
-
logger.trace(`ping failed on ${this.serviceId} to ${
|
|
70
|
+
logger.trace(`ping failed on ${this.serviceId} to ${this.getNodeId()}: ${err}`)
|
|
71
71
|
}
|
|
72
72
|
return false
|
|
73
73
|
}
|
|
74
74
|
|
|
75
75
|
leaveNotice(): void {
|
|
76
|
-
logger.trace(`Sending leaveNotice on ${this.serviceId} from ${
|
|
76
|
+
logger.trace(`Sending leaveNotice on ${this.serviceId} from ${this.getNodeId()}`)
|
|
77
77
|
const options = this.formDhtRpcOptions({
|
|
78
78
|
notification: true
|
|
79
79
|
})
|