@streamr/dht 100.0.0-testnet-two.1 → 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/ConnectionLockHandler.d.ts +11 -11
- package/dist/src/connection/ConnectionLockHandler.js.map +1 -1
- package/dist/src/connection/ConnectionLockRpcLocal.d.ts +3 -3
- package/dist/src/connection/ConnectionManager.d.ts +5 -4
- package/dist/src/connection/ConnectionManager.js +32 -36
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +2 -2
- package/dist/src/connection/simulator/Simulator.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/webrtc/WebrtcConnector.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnector.js.map +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.d.ts +2 -2
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js +1 -1
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +6 -5
- package/dist/src/connection/websocket/WebsocketConnector.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +9 -8
- package/dist/src/dht/DhtNode.js +26 -22
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js +2 -1
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
- package/dist/src/dht/DhtNodeRpcRemote.js +9 -7
- package/dist/src/dht/DhtNodeRpcRemote.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcLocal.d.ts +3 -3
- package/dist/src/dht/ExternalApiRpcLocal.js +3 -2
- package/dist/src/dht/ExternalApiRpcLocal.js.map +1 -1
- package/dist/src/dht/ExternalApiRpcRemote.d.ts +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js +3 -2
- package/dist/src/dht/ExternalApiRpcRemote.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +9 -9
- package/dist/src/dht/PeerManager.js +35 -30
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/Contact.d.ts +2 -2
- package/dist/src/dht/contact/ContactList.d.ts +7 -7
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.d.ts +4 -4
- package/dist/src/dht/contact/RandomContactList.js +2 -3
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RpcRemote.d.ts +1 -4
- package/dist/src/dht/contact/RpcRemote.js +1 -5
- package/dist/src/dht/contact/RpcRemote.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +13 -13
- package/dist/src/dht/contact/SortedContactList.js +5 -5
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/DiscoverySession.d.ts +3 -2
- package/dist/src/dht/discovery/DiscoverySession.js +9 -9
- package/dist/src/dht/discovery/DiscoverySession.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +3 -1
- package/dist/src/dht/discovery/PeerDiscovery.js +18 -10
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.d.ts +3 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +15 -14
- 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/recursive-operation/RecursiveOperationSession.d.ts +2 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +6 -6
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/routing/Router.d.ts +2 -2
- package/dist/src/dht/routing/Router.js +2 -2
- package/dist/src/dht/routing/Router.js.map +1 -1
- package/dist/src/dht/routing/RouterRpcLocal.js +3 -3
- package/dist/src/dht/routing/RouterRpcLocal.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/routing/RoutingSession.d.ts +3 -3
- package/dist/src/dht/routing/RoutingSession.js +4 -4
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/store/LocalDataStore.d.ts +6 -9
- package/dist/src/dht/store/LocalDataStore.js +27 -32
- package/dist/src/dht/store/LocalDataStore.js.map +1 -1
- package/dist/src/dht/store/StoreManager.d.ts +3 -3
- package/dist/src/dht/store/StoreManager.js +26 -23
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/dist/src/dht/store/StoreRpcLocal.d.ts +2 -1
- package/dist/src/dht/store/StoreRpcLocal.js +10 -8
- package/dist/src/dht/store/StoreRpcLocal.js.map +1 -1
- package/dist/src/exports.d.ts +2 -0
- package/dist/src/exports.js +6 -1
- package/dist/src/exports.js.map +1 -1
- package/dist/src/helpers/AddressTools.js +2 -0
- package/dist/src/helpers/AddressTools.js.map +1 -1
- package/dist/src/helpers/PeerID.d.ts +2 -2
- package/dist/src/helpers/PeerID.js +3 -3
- package/dist/src/helpers/PeerID.js.map +1 -1
- package/dist/src/helpers/peerIdFromPeerDescriptor.d.ts +2 -2
- package/dist/src/helpers/peerIdFromPeerDescriptor.js +2 -3
- package/dist/src/helpers/peerIdFromPeerDescriptor.js.map +1 -1
- package/dist/src/identifiers.d.ts +6 -0
- package/dist/src/identifiers.js +23 -0
- package/dist/src/identifiers.js.map +1 -0
- package/package.json +5 -5
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +3 -3
- package/src/connection/ConnectionManager.ts +36 -46
- package/src/connection/ManagedConnection.ts +2 -2
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnection.ts +21 -23
- package/src/connection/simulator/SimulatorConnector.ts +6 -5
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/NodeWebrtcConnection.ts +11 -10
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -3
- package/src/connection/websocket/WebsocketConnector.ts +9 -9
- package/src/dht/DhtNode.ts +36 -35
- package/src/dht/DhtNodeRpcLocal.ts +3 -2
- package/src/dht/DhtNodeRpcRemote.ts +14 -12
- package/src/dht/ExternalApiRpcLocal.ts +15 -6
- package/src/dht/ExternalApiRpcRemote.ts +5 -4
- package/src/dht/PeerManager.ts +43 -38
- package/src/dht/contact/Contact.ts +2 -2
- package/src/dht/contact/ContactList.ts +7 -7
- package/src/dht/contact/RandomContactList.ts +6 -6
- package/src/dht/contact/RpcRemote.ts +0 -8
- package/src/dht/contact/SortedContactList.ts +22 -22
- package/src/dht/discovery/DiscoverySession.ts +16 -14
- package/src/dht/discovery/PeerDiscovery.ts +34 -12
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +17 -17
- package/src/dht/recursive-operation/RecursiveOperationRpcRemote.ts +2 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +11 -11
- package/src/dht/routing/Router.ts +5 -5
- package/src/dht/routing/RouterRpcLocal.ts +3 -3
- package/src/dht/routing/RouterRpcRemote.ts +4 -4
- package/src/dht/routing/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +31 -40
- package/src/dht/store/StoreManager.ts +31 -31
- package/src/dht/store/StoreRpcLocal.ts +11 -9
- package/src/exports.ts +2 -0
- package/src/helpers/AddressTools.ts +2 -0
- package/src/helpers/PeerID.ts +4 -4
- package/src/helpers/peerIdFromPeerDescriptor.ts +4 -6
- package/src/identifiers.ts +20 -0
- package/test/RandomGraphSimulation.ts +3 -2
- package/test/benchmark/Find.test.ts +4 -3
- package/test/benchmark/KademliaCorrectness.test.ts +4 -4
- package/test/benchmark/SortedContactListBenchmark.test.ts +15 -14
- package/test/benchmark/kademlia-simulation/Contact.ts +7 -8
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +2 -2
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +10 -11
- package/test/data/generateGroundTruthData.ts +5 -4
- package/test/end-to-end/Layer0Webrtc-Layer1.test.ts +2 -2
- package/test/end-to-end/RecoveryFromFailedAutoCertification.test.ts +1 -1
- package/test/end-to-end/memory-leak.test.ts +3 -2
- package/test/integration/ConnectionManager.test.ts +3 -3
- package/test/integration/DhtJoinPeerDiscovery.test.ts +2 -1
- package/test/integration/DhtNodeExternalAPI.test.ts +7 -7
- package/test/integration/DhtNodeRpcRemote.test.ts +3 -2
- package/test/integration/Find.test.ts +3 -3
- package/test/integration/Layer1-scale.test.ts +3 -3
- package/test/integration/Mock-Layer1-Layer0.test.ts +6 -5
- package/test/integration/ReplicateData.test.ts +38 -30
- package/test/integration/RouteMessage.test.ts +9 -10
- package/test/integration/RouterRpcRemote.test.ts +1 -1
- package/test/integration/ScaleDownDht.test.ts +4 -4
- package/test/integration/SimultaneousConnections.test.ts +7 -14
- package/test/integration/Store.test.ts +17 -7
- package/test/integration/StoreAndDelete.test.ts +11 -10
- package/test/integration/StoreOnDhtWithTwoNodes.test.ts +7 -6
- package/test/integration/StoreRpcRemote.test.ts +3 -5
- package/test/unit/AddressTools.test.ts +4 -0
- package/test/unit/LocalDataStore.test.ts +41 -41
- package/test/unit/PeerManager.test.ts +7 -8
- package/test/unit/RandomContactList.test.ts +3 -3
- package/test/unit/RecursiveOperationManager.test.ts +2 -1
- package/test/unit/RecursiveOperationSession.test.ts +2 -3
- package/test/unit/Router.test.ts +2 -2
- package/test/unit/RoutingSession.test.ts +2 -2
- package/test/unit/SortedContactList.test.ts +6 -6
- package/test/unit/StoreManager.test.ts +26 -23
- package/test/utils/customMatchers.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +8 -6
- package/test/utils/utils.ts +4 -4
- package/dist/src/helpers/nodeId.d.ts +0 -6
- package/dist/src/helpers/nodeId.js +0 -31
- package/dist/src/helpers/nodeId.js.map +0 -1
- package/src/helpers/nodeId.ts +0 -28
|
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.StoreRpcLocal = void 0;
|
|
4
4
|
const utils_1 = require("@streamr/utils");
|
|
5
5
|
const timestamp_1 = require("../../proto/google/protobuf/timestamp");
|
|
6
|
+
const identifiers_1 = require("../../identifiers");
|
|
6
7
|
const logger = new utils_1.Logger(module);
|
|
7
8
|
class StoreRpcLocal {
|
|
8
9
|
constructor(config) {
|
|
@@ -10,15 +11,15 @@ class StoreRpcLocal {
|
|
|
10
11
|
}
|
|
11
12
|
async storeData(request) {
|
|
12
13
|
logger.trace('storeData()');
|
|
13
|
-
const
|
|
14
|
+
const key = (0, identifiers_1.getDhtAddressFromRaw)(request.key);
|
|
14
15
|
const selfIsOneOfClosestPeers = this.config.selfIsWithinRedundancyFactor(key);
|
|
15
16
|
this.config.localDataStore.storeEntry({
|
|
16
|
-
key,
|
|
17
|
-
data,
|
|
18
|
-
creator,
|
|
19
|
-
createdAt,
|
|
17
|
+
key: request.key,
|
|
18
|
+
data: request.data,
|
|
19
|
+
creator: request.creator,
|
|
20
|
+
createdAt: request.createdAt,
|
|
20
21
|
storedAt: timestamp_1.Timestamp.now(),
|
|
21
|
-
ttl,
|
|
22
|
+
ttl: request.ttl,
|
|
22
23
|
stale: !selfIsOneOfClosestPeers,
|
|
23
24
|
deleted: false
|
|
24
25
|
});
|
|
@@ -34,8 +35,9 @@ class StoreRpcLocal {
|
|
|
34
35
|
if (wasStored) {
|
|
35
36
|
this.config.replicateDataToNeighbors(context.incomingSourceDescriptor, request.entry);
|
|
36
37
|
}
|
|
37
|
-
|
|
38
|
-
|
|
38
|
+
const key = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key);
|
|
39
|
+
if (!this.config.selfIsWithinRedundancyFactor(key)) {
|
|
40
|
+
this.config.localDataStore.setAllEntriesAsStale(key);
|
|
39
41
|
}
|
|
40
42
|
logger.trace('server-side replicateData() at end');
|
|
41
43
|
return {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreRpcLocal.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreRpcLocal.ts"],"names":[],"mappings":";;;AACA,0CAAuC;AAEvC,qEAAiE;
|
|
1
|
+
{"version":3,"file":"StoreRpcLocal.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreRpcLocal.ts"],"names":[],"mappings":";;;AACA,0CAAuC;AAEvC,qEAAiE;AAUjE,mDAAoE;AAQpE,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,aAAa;IAItB,YAAY,MAA2B;QACnC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,OAAyB;QACrC,MAAM,CAAC,KAAK,CAAC,aAAa,CAAC,CAAA;QAC3B,MAAM,GAAG,GAAG,IAAA,kCAAoB,EAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QAC7C,MAAM,uBAAuB,GAAG,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,GAAG,CAAC,CAAA;QAC7E,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC;YAClC,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;YACxB,SAAS,EAAE,OAAO,CAAC,SAAS;YAC5B,QAAQ,EAAE,qBAAS,CAAC,GAAG,EAAE;YACzB,GAAG,EAAE,OAAO,CAAC,GAAG;YAChB,KAAK,EAAE,CAAC,uBAAuB;YAC/B,OAAO,EAAE,KAAK;SACjB,CAAC,CAAA;QACF,IAAI,CAAC,uBAAuB,EAAE;YAC1B,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAA;SACvD;QACD,OAAO,EAAE,CAAA;IACb,CAAC;IAEM,KAAK,CAAC,aAAa,CAAC,OAA6B,EAAE,OAA0B;QAChF,MAAM,CAAC,KAAK,CAAC,6BAA6B,CAAC,CAAA;QAC3C,MAAM,SAAS,GAAG,OAAO,CAAC,KAAM,CAAA;QAChC,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,UAAU,CAAC,SAAS,CAAC,CAAA;QAClE,IAAI,SAAS,EAAE;YACX,IAAI,CAAC,MAAM,CAAC,wBAAwB,CAAE,OAA0B,CAAC,wBAAyB,EAAE,OAAO,CAAC,KAAM,CAAC,CAAA;SAC9G;QACD,MAAM,GAAG,GAAG,IAAA,kCAAoB,EAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAC/C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,4BAA4B,CAAC,GAAG,CAAC,EAAE;YAChD,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC,GAAG,CAAC,CAAA;SACvD;QACD,MAAM,CAAC,KAAK,CAAC,oCAAoC,CAAC,CAAA;QAClD,OAAO,EAAE,CAAA;IACb,CAAC;CACJ;AA1CD,sCA0CC"}
|
package/dist/src/exports.d.ts
CHANGED
|
@@ -19,3 +19,5 @@ export { ManagedConnection } from './connection/ManagedConnection';
|
|
|
19
19
|
export { ConnectionType } from './connection/IConnection';
|
|
20
20
|
export { PeerID } from './helpers/PeerID';
|
|
21
21
|
export { ServiceID } from './types/ServiceID';
|
|
22
|
+
export { DhtAddress, DhtAddressRaw, getDhtAddressFromRaw, getRawFromDhtAddress } from './identifiers';
|
|
23
|
+
export { getNodeIdFromPeerDescriptor } from './helpers/peerIdFromPeerDescriptor';
|
package/dist/src/exports.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PeerID = exports.ConnectionType = exports.ManagedConnection = exports.ClientWebsocket = exports.DhtCallContext = exports.areEqualPeerDescriptors = exports.EXISTING_CONNECTION_TIMEOUT = exports.RpcRemote = exports.DefaultConnectorFacade = exports.ConnectionManager = exports.DataEntry = exports.NodeType = exports.Message = exports.PeerDescriptor = exports.getRegionDelayMatrix = exports.getRandomRegion = exports.SimulatorTransport = exports.LatencyType = exports.Simulator = exports.RoutingRpcCommunicator = exports.ListeningRpcCommunicator = exports.DhtNode = void 0;
|
|
3
|
+
exports.getNodeIdFromPeerDescriptor = exports.getRawFromDhtAddress = exports.getDhtAddressFromRaw = exports.PeerID = exports.ConnectionType = exports.ManagedConnection = exports.ClientWebsocket = exports.DhtCallContext = exports.areEqualPeerDescriptors = exports.EXISTING_CONNECTION_TIMEOUT = exports.RpcRemote = exports.DefaultConnectorFacade = exports.ConnectionManager = exports.DataEntry = exports.NodeType = exports.Message = exports.PeerDescriptor = exports.getRegionDelayMatrix = exports.getRandomRegion = exports.SimulatorTransport = exports.LatencyType = exports.Simulator = exports.RoutingRpcCommunicator = exports.ListeningRpcCommunicator = exports.DhtNode = void 0;
|
|
4
4
|
var DhtNode_1 = require("./dht/DhtNode");
|
|
5
5
|
Object.defineProperty(exports, "DhtNode", { enumerable: true, get: function () { return DhtNode_1.DhtNode; } });
|
|
6
6
|
var ListeningRpcCommunicator_1 = require("./transport/ListeningRpcCommunicator");
|
|
@@ -39,4 +39,9 @@ var IConnection_1 = require("./connection/IConnection");
|
|
|
39
39
|
Object.defineProperty(exports, "ConnectionType", { enumerable: true, get: function () { return IConnection_1.ConnectionType; } });
|
|
40
40
|
var PeerID_1 = require("./helpers/PeerID");
|
|
41
41
|
Object.defineProperty(exports, "PeerID", { enumerable: true, get: function () { return PeerID_1.PeerID; } });
|
|
42
|
+
var identifiers_1 = require("./identifiers");
|
|
43
|
+
Object.defineProperty(exports, "getDhtAddressFromRaw", { enumerable: true, get: function () { return identifiers_1.getDhtAddressFromRaw; } });
|
|
44
|
+
Object.defineProperty(exports, "getRawFromDhtAddress", { enumerable: true, get: function () { return identifiers_1.getRawFromDhtAddress; } });
|
|
45
|
+
var peerIdFromPeerDescriptor_2 = require("./helpers/peerIdFromPeerDescriptor");
|
|
46
|
+
Object.defineProperty(exports, "getNodeIdFromPeerDescriptor", { enumerable: true, get: function () { return peerIdFromPeerDescriptor_2.getNodeIdFromPeerDescriptor; } });
|
|
42
47
|
//# sourceMappingURL=exports.js.map
|
package/dist/src/exports.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exports.js","sourceRoot":"","sources":["../../src/exports.ts"],"names":[],"mappings":";;;AAAA,yCAAsE;AAA7D,kGAAA,OAAO,OAAA;AAChB,iFAA+E;AAAtE,oIAAA,wBAAwB,OAAA;AACjC,6EAA2E;AAAlE,gIAAA,sBAAsB,OAAA;AAC/B,8DAAyE;AAAhE,sGAAA,SAAS,OAAA;AAAE,wGAAA,WAAW,OAAA;AAC/B,gFAA8E;AAArE,wHAAA,kBAAkB,OAAA;AAC3B,sDAAoF;AAA3E,wGAAA,eAAe,OAAA;AAAE,6GAAA,oBAAoB,OAAA;AAC9C,6DAAiG;AAAxF,wGAAA,cAAc,OAAA;AAAE,iGAAA,OAAO,OAAA;AAAE,kGAAA,QAAQ,OAAA;AAAE,mGAAA,SAAS,OAAA;AAErD,oEAA+G;AAAtG,sHAAA,iBAAiB,OAAA;AAE1B,gEAAqE;AAA5D,yHAAA,sBAAsB,OAAA;AAE/B,qDAAgF;AAAvE,sGAAA,SAAS,OAAA;AAAE,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AAAE,mHAAA,oBAAoB,OAAA;AAC9E,+EAAgF;AAAvE,uIAAA,2BAA2B,OAAA"}
|
|
@@ -6,10 +6,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.getAddressFromIceCandidate = exports.isPrivateIPv4 = void 0;
|
|
7
7
|
const ipaddr_js_1 = __importDefault(require("ipaddr.js"));
|
|
8
8
|
// IPv4 private address ranges as specified by RFC 1918
|
|
9
|
+
// and private loopback addresses
|
|
9
10
|
const IPv4PrivateRanges = [
|
|
10
11
|
'10.0.0.0/8',
|
|
11
12
|
'172.16.0.0/12',
|
|
12
13
|
'192.168.0.0/16',
|
|
14
|
+
'127.0.0.0/8'
|
|
13
15
|
].map((a) => ipaddr_js_1.default.parseCIDR(a));
|
|
14
16
|
function isPrivateIPv4(address) {
|
|
15
17
|
if (ipaddr_js_1.default.IPv4.isValid(address)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddressTools.js","sourceRoot":"","sources":["../../../src/helpers/AddressTools.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA8B;AAE9B,uDAAuD;AACvD,MAAM,iBAAiB,GAAG;IACtB,YAAY;IACZ,eAAe;IACf,gBAAgB;
|
|
1
|
+
{"version":3,"file":"AddressTools.js","sourceRoot":"","sources":["../../../src/helpers/AddressTools.ts"],"names":[],"mappings":";;;;;;AAAA,0DAA8B;AAE9B,uDAAuD;AACvD,iCAAiC;AACjC,MAAM,iBAAiB,GAAG;IACtB,YAAY;IACZ,eAAe;IACf,gBAAgB;IAChB,aAAa;CAChB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,mBAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,CAAA;AAEjC,SAAgB,aAAa,CAAC,OAAe;IACzC,IAAI,mBAAM,CAAC,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE;QAC9B,MAAM,EAAE,GAAG,mBAAM,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAA;QACrC,KAAK,MAAM,KAAK,IAAI,iBAAiB,EAAE;YACnC,IAAI,EAAE,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE;gBACjB,OAAO,IAAI,CAAA;aACd;SACJ;KACJ;IAED,OAAO,KAAK,CAAA;AAChB,CAAC;AAXD,sCAWC;AAED,SAAgB,0BAA0B,CAAC,SAAiB;IACxD,MAAM,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACvE,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC,IAAI,mBAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAA;AAClF,CAAC;AAHD,gEAGC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BrandedString } from '@streamr/utils';
|
|
2
|
-
import {
|
|
2
|
+
import { DhtAddress } from '../identifiers';
|
|
3
3
|
export type PeerIDKey = BrandedString<'PeerIDKey'>;
|
|
4
4
|
export declare const createPeerIDKey: (nodeId: Uint8Array) => PeerIDKey;
|
|
5
5
|
export declare class PeerID {
|
|
@@ -20,7 +20,7 @@ export declare class PeerID {
|
|
|
20
20
|
equals(other: PeerID): boolean;
|
|
21
21
|
toString(): string;
|
|
22
22
|
toKey(): PeerIDKey;
|
|
23
|
-
toNodeId():
|
|
23
|
+
toNodeId(): DhtAddress;
|
|
24
24
|
get value(): Uint8Array;
|
|
25
25
|
hasSmallerHashThan(other: PeerID): boolean;
|
|
26
26
|
private static offeringHash;
|
|
@@ -8,7 +8,7 @@ const utils_1 = require("@streamr/utils");
|
|
|
8
8
|
const UUID_1 = require("./UUID");
|
|
9
9
|
const errors_1 = require("./errors");
|
|
10
10
|
const crypto_1 = __importDefault(require("crypto"));
|
|
11
|
-
const
|
|
11
|
+
const identifiers_1 = require("../identifiers");
|
|
12
12
|
const createPeerIDKey = (nodeId) => {
|
|
13
13
|
return (0, utils_1.binaryToHex)(nodeId);
|
|
14
14
|
};
|
|
@@ -59,13 +59,13 @@ class PeerID {
|
|
|
59
59
|
return (Buffer.compare(this.data, other.value) === 0);
|
|
60
60
|
}
|
|
61
61
|
toString() {
|
|
62
|
-
return PeerID.textDecoder.decode(this.data);
|
|
62
|
+
return PeerID.textDecoder.decode(this.data);
|
|
63
63
|
}
|
|
64
64
|
toKey() {
|
|
65
65
|
return this.key;
|
|
66
66
|
}
|
|
67
67
|
toNodeId() {
|
|
68
|
-
return (0,
|
|
68
|
+
return (0, identifiers_1.getDhtAddressFromRaw)(this.data);
|
|
69
69
|
}
|
|
70
70
|
get value() {
|
|
71
71
|
return this.data;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PeerID.js","sourceRoot":"","sources":["../../../src/helpers/PeerID.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA2D;AAC3D,iCAA6B;AAC7B,qCAA2C;AAC3C,oDAA2B;AAC3B,
|
|
1
|
+
{"version":3,"file":"PeerID.js","sourceRoot":"","sources":["../../../src/helpers/PeerID.ts"],"names":[],"mappings":";;;;;;AAAA,0CAA2D;AAC3D,iCAA6B;AAC7B,qCAA2C;AAC3C,oDAA2B;AAC3B,gDAAiE;AAI1D,MAAM,eAAe,GAAG,CAAC,MAAkB,EAAa,EAAE;IAC7D,OAAO,IAAA,mBAAW,EAAC,MAAM,CAAc,CAAA;AAC3C,CAAC,CAAA;AAFY,QAAA,eAAe,mBAE3B;AAED,MAAa,MAAM;IAQf,YAAsB,EAAE,EAAE,EAAE,KAAK,EAAE,WAAW,KAAgE,EAAE;QAC5G,IAAI,EAAE,KAAK,SAAS,EAAE;YAClB,IAAI,CAAC,IAAI,GAAG,IAAI,UAAU,CAAC,EAAE,CAAC,CAAA;YAC9B,MAAM,KAAK,GAAG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AAC;IAEO,MAAM,CAAC,YAAY,CAAC,MAAc;QACtC,MAAM,MAAM,GAAG,gBAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,EAAE,CAAA;QAC/D,OAAO,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAA;IAChC,CAAC;;AAnFL,wBAoFC;AAnFG,oDAAoD;AAC5B,kBAAW,GAAG,IAAI,WAAW,EAAE,CAAA;AAC/B,kBAAW,GAAG,IAAI,WAAW,EAAE,CAAA"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { PeerDescriptor } from '../proto/packages/dht/protos/DhtRpc';
|
|
2
2
|
import { PeerID, PeerIDKey } from './PeerID';
|
|
3
|
-
import {
|
|
3
|
+
import { DhtAddress } from '../identifiers';
|
|
4
4
|
export declare const peerIdFromPeerDescriptor: (peerDescriptor: PeerDescriptor) => PeerID;
|
|
5
|
-
export declare const getNodeIdFromPeerDescriptor: (peerDescriptor: PeerDescriptor) =>
|
|
5
|
+
export declare const getNodeIdFromPeerDescriptor: (peerDescriptor: PeerDescriptor) => DhtAddress;
|
|
6
6
|
export declare const keyFromPeerDescriptor: (peerDescriptor: PeerDescriptor) => PeerIDKey;
|
|
7
7
|
export declare const areEqualPeerDescriptors: (peerDescriptor1: PeerDescriptor, peerDescriptor2: PeerDescriptor) => boolean;
|
|
@@ -3,14 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.areEqualPeerDescriptors = exports.keyFromPeerDescriptor = exports.getNodeIdFromPeerDescriptor = exports.peerIdFromPeerDescriptor = void 0;
|
|
4
4
|
const utils_1 = require("@streamr/utils");
|
|
5
5
|
const PeerID_1 = require("./PeerID");
|
|
6
|
+
const identifiers_1 = require("../identifiers");
|
|
6
7
|
const peerIdFromPeerDescriptor = (peerDescriptor) => {
|
|
7
8
|
return PeerID_1.PeerID.fromValue(peerDescriptor.nodeId);
|
|
8
9
|
};
|
|
9
10
|
exports.peerIdFromPeerDescriptor = peerIdFromPeerDescriptor;
|
|
10
|
-
// TODO could use this in trackerless-network (instead of copy-pasted same implementation)
|
|
11
|
-
// and move this to nodeId.ts
|
|
12
11
|
const getNodeIdFromPeerDescriptor = (peerDescriptor) => {
|
|
13
|
-
return (0,
|
|
12
|
+
return (0, identifiers_1.getDhtAddressFromRaw)(peerDescriptor.nodeId);
|
|
14
13
|
};
|
|
15
14
|
exports.getNodeIdFromPeerDescriptor = getNodeIdFromPeerDescriptor;
|
|
16
15
|
const keyFromPeerDescriptor = (peerDescriptor) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"peerIdFromPeerDescriptor.js","sourceRoot":"","sources":["../../../src/helpers/peerIdFromPeerDescriptor.ts"],"names":[],"mappings":";;;AAAA,
|
|
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"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { BrandedString } from '@streamr/utils';
|
|
2
|
+
export type DhtAddress = BrandedString<'DhtAddress'>;
|
|
3
|
+
export type DhtAddressRaw = Uint8Array;
|
|
4
|
+
export declare const getDhtAddressFromRaw: (raw: DhtAddressRaw) => DhtAddress;
|
|
5
|
+
export declare const getRawFromDhtAddress: (address: DhtAddress) => DhtAddressRaw;
|
|
6
|
+
export declare const createRandomDhtAddress: () => DhtAddress;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.createRandomDhtAddress = exports.getRawFromDhtAddress = exports.getDhtAddressFromRaw = void 0;
|
|
7
|
+
const utils_1 = require("@streamr/utils");
|
|
8
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
9
|
+
// https://www.scs.stanford.edu/~dm/home/papers/kpos.pdf
|
|
10
|
+
const KADEMLIA_ID_LENGTH_IN_BYTES = 20;
|
|
11
|
+
const getDhtAddressFromRaw = (raw) => {
|
|
12
|
+
return (0, utils_1.binaryToHex)(raw);
|
|
13
|
+
};
|
|
14
|
+
exports.getDhtAddressFromRaw = getDhtAddressFromRaw;
|
|
15
|
+
const getRawFromDhtAddress = (address) => {
|
|
16
|
+
return (0, utils_1.hexToBinary)(address);
|
|
17
|
+
};
|
|
18
|
+
exports.getRawFromDhtAddress = getRawFromDhtAddress;
|
|
19
|
+
const createRandomDhtAddress = () => {
|
|
20
|
+
return (0, exports.getDhtAddressFromRaw)(crypto_1.default.randomBytes(KADEMLIA_ID_LENGTH_IN_BYTES));
|
|
21
|
+
};
|
|
22
|
+
exports.createRandomDhtAddress = createRandomDhtAddress;
|
|
23
|
+
//# sourceMappingURL=identifiers.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"identifiers.js","sourceRoot":"","sources":["../../src/identifiers.ts"],"names":[],"mappings":";;;;;;AAAA,0CAAwE;AACxE,oDAA2B;AAE3B,wDAAwD;AACxD,MAAM,2BAA2B,GAAG,EAAE,CAAA;AAK/B,MAAM,oBAAoB,GAAG,CAAC,GAAkB,EAAc,EAAE;IACnE,OAAO,IAAA,mBAAW,EAAC,GAAG,CAA0B,CAAA;AACpD,CAAC,CAAA;AAFY,QAAA,oBAAoB,wBAEhC;AAEM,MAAM,oBAAoB,GAAG,CAAC,OAAmB,EAAiB,EAAE;IACvE,OAAO,IAAA,mBAAW,EAAC,OAAO,CAA6B,CAAA;AAC3D,CAAC,CAAA;AAFY,QAAA,oBAAoB,wBAEhC;AAEM,MAAM,sBAAsB,GAAG,GAAe,EAAE;IACnD,OAAO,IAAA,4BAAoB,EAAC,gBAAM,CAAC,WAAW,CAAC,2BAA2B,CAAC,CAAC,CAAA;AAChF,CAAC,CAAA;AAFY,QAAA,sBAAsB,0BAElC"}
|
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,17 +1,17 @@
|
|
|
1
1
|
// Connection locks are independent of the existence of connections
|
|
2
2
|
// that is why this class is needed
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { DhtAddress } from '../identifiers'
|
|
5
5
|
|
|
6
6
|
export type LockID = string
|
|
7
7
|
|
|
8
8
|
export class ConnectionLockHandler {
|
|
9
9
|
|
|
10
|
-
private localLocks: Map<
|
|
11
|
-
private remoteLocks: Map<
|
|
10
|
+
private localLocks: Map<DhtAddress, Set<LockID>> = new Map()
|
|
11
|
+
private remoteLocks: Map<DhtAddress, Set<LockID>> = new Map()
|
|
12
12
|
// TODO: remove weakLocks use localLocks instead. When opening weakLocks from the ConnectioManager,
|
|
13
13
|
// simply do not send lock requests.
|
|
14
|
-
private weakLocks: Set<
|
|
14
|
+
private weakLocks: Set<DhtAddress> = new Set()
|
|
15
15
|
|
|
16
16
|
public getNumberOfLocalLockedConnections(): number {
|
|
17
17
|
return this.localLocks.size
|
|
@@ -25,7 +25,7 @@ export class ConnectionLockHandler {
|
|
|
25
25
|
return this.weakLocks.size
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
public isLocalLocked(id:
|
|
28
|
+
public isLocalLocked(id: DhtAddress, lockId?: LockID): boolean {
|
|
29
29
|
if (lockId === undefined) {
|
|
30
30
|
return this.localLocks.has(id)
|
|
31
31
|
} else {
|
|
@@ -33,7 +33,7 @@ export class ConnectionLockHandler {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
public isRemoteLocked(id:
|
|
36
|
+
public isRemoteLocked(id: DhtAddress, lockId?: LockID): boolean {
|
|
37
37
|
if (lockId === undefined) {
|
|
38
38
|
return this.remoteLocks.has(id)
|
|
39
39
|
} else {
|
|
@@ -45,33 +45,33 @@ export class ConnectionLockHandler {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
private isWeakLocked(id:
|
|
48
|
+
private isWeakLocked(id: DhtAddress): boolean {
|
|
49
49
|
return this.weakLocks.has(id)
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
public isLocked(id:
|
|
52
|
+
public isLocked(id: DhtAddress): boolean {
|
|
53
53
|
return (this.isLocalLocked(id) || this.isRemoteLocked(id) || this.isWeakLocked(id))
|
|
54
54
|
}
|
|
55
55
|
|
|
56
|
-
public addLocalLocked(id:
|
|
56
|
+
public addLocalLocked(id: DhtAddress, lockId: LockID): void {
|
|
57
57
|
if (!this.localLocks.has(id)) {
|
|
58
58
|
this.localLocks.set(id, new Set())
|
|
59
59
|
}
|
|
60
60
|
this.localLocks.get(id)!.add(lockId)
|
|
61
61
|
}
|
|
62
62
|
|
|
63
|
-
public addRemoteLocked(id:
|
|
63
|
+
public addRemoteLocked(id: DhtAddress, lockId: LockID): void {
|
|
64
64
|
if (!this.remoteLocks.has(id)) {
|
|
65
65
|
this.remoteLocks.set(id, new Set())
|
|
66
66
|
}
|
|
67
67
|
this.remoteLocks.get(id)!.add(lockId)
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
public addWeakLocked(id:
|
|
70
|
+
public addWeakLocked(id: DhtAddress): void {
|
|
71
71
|
this.weakLocks.add(id)
|
|
72
72
|
}
|
|
73
73
|
|
|
74
|
-
public removeLocalLocked(id:
|
|
74
|
+
public removeLocalLocked(id: DhtAddress, lockId: LockID): void {
|
|
75
75
|
if (this.localLocks.has(id)) {
|
|
76
76
|
this.localLocks.get(id)?.delete(lockId)
|
|
77
77
|
if (this.localLocks.get(id)?.size === 0) {
|
|
@@ -80,7 +80,7 @@ export class ConnectionLockHandler {
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
-
public removeRemoteLocked(id:
|
|
83
|
+
public removeRemoteLocked(id: DhtAddress, lockId: LockID): void {
|
|
84
84
|
if (this.remoteLocks.has(id)) {
|
|
85
85
|
this.remoteLocks.get(id)?.delete(lockId)
|
|
86
86
|
if (this.remoteLocks.get(id)?.size === 0) {
|
|
@@ -89,11 +89,11 @@ export class ConnectionLockHandler {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
-
public removeWeakLocked(id:
|
|
92
|
+
public removeWeakLocked(id: DhtAddress): void {
|
|
93
93
|
this.weakLocks.delete(id)
|
|
94
94
|
}
|
|
95
95
|
|
|
96
|
-
public clearAllLocks(id:
|
|
96
|
+
public clearAllLocks(id: DhtAddress): void {
|
|
97
97
|
this.localLocks.delete(id)
|
|
98
98
|
this.remoteLocks.delete(id)
|
|
99
99
|
this.weakLocks.delete(id)
|
|
@@ -17,11 +17,11 @@ import { IConnectionLockRpc } from '../proto/packages/dht/protos/DhtRpc.server'
|
|
|
17
17
|
import { DhtCallContext } from '../rpc-protocol/DhtCallContext'
|
|
18
18
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
19
19
|
import { LockID } from './ConnectionLockHandler'
|
|
20
|
-
import {
|
|
20
|
+
import { DhtAddress } from '../identifiers'
|
|
21
21
|
|
|
22
22
|
interface ConnectionLockRpcLocalConfig {
|
|
23
|
-
addRemoteLocked: (id:
|
|
24
|
-
removeRemoteLocked: (id:
|
|
23
|
+
addRemoteLocked: (id: DhtAddress, lockId: LockID) => void
|
|
24
|
+
removeRemoteLocked: (id: DhtAddress, lockId: LockID) => void
|
|
25
25
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => void
|
|
26
26
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
27
27
|
}
|
|
@@ -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'
|
|
@@ -31,7 +30,7 @@ import { ConnectionLockRpcRemote } from './ConnectionLockRpcRemote'
|
|
|
31
30
|
import { WEBRTC_CLEANUP } from './webrtc/NodeWebrtcConnection'
|
|
32
31
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
33
32
|
import { ConnectionLockRpcLocal } from './ConnectionLockRpcLocal'
|
|
34
|
-
import {
|
|
33
|
+
import { DhtAddress } from '../identifiers'
|
|
35
34
|
|
|
36
35
|
export interface ConnectionManagerConfig {
|
|
37
36
|
maxConnections?: number
|
|
@@ -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 {
|
|
@@ -106,7 +105,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
106
105
|
private readonly duplicateMessageDetector: DuplicateDetector = new DuplicateDetector(100000, 100)
|
|
107
106
|
private readonly metrics: ConnectionManagerMetrics
|
|
108
107
|
private locks = new ConnectionLockHandler()
|
|
109
|
-
private connections: Map<
|
|
108
|
+
private connections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
110
109
|
private readonly connectorFacade: ConnectorFacade
|
|
111
110
|
private rpcCommunicator?: RoutingRpcCommunicator
|
|
112
111
|
private disconnectorIntervalRef?: NodeJS.Timeout
|
|
@@ -134,8 +133,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
134
133
|
rpcRequestTimeout: 10000 // TODO use config option or named constant?
|
|
135
134
|
})
|
|
136
135
|
const lockRpcLocal = new ConnectionLockRpcLocal({
|
|
137
|
-
addRemoteLocked: (id:
|
|
138
|
-
removeRemoteLocked: (id:
|
|
136
|
+
addRemoteLocked: (id: DhtAddress, lockId: LockID) => this.locks.addRemoteLocked(id, lockId),
|
|
137
|
+
removeRemoteLocked: (id: DhtAddress, lockId: LockID) => this.locks.removeRemoteLocked(id, lockId),
|
|
139
138
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => {
|
|
140
139
|
// TODO should we have some handling for this floating promise?
|
|
141
140
|
this.closeConnection(peerDescriptor, gracefulLeave, reason)
|
|
@@ -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
|
}
|
|
@@ -462,7 +456,6 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
462
456
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
463
457
|
this.getLocalPeerDescriptor(),
|
|
464
458
|
targetDescriptor,
|
|
465
|
-
'DUMMY',
|
|
466
459
|
this.rpcCommunicator!,
|
|
467
460
|
ConnectionLockRpcClient
|
|
468
461
|
)
|
|
@@ -481,7 +474,6 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
481
474
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
482
475
|
this.getLocalPeerDescriptor(),
|
|
483
476
|
targetDescriptor,
|
|
484
|
-
'DUMMY',
|
|
485
477
|
this.rpcCommunicator!,
|
|
486
478
|
ConnectionLockRpcClient
|
|
487
479
|
)
|
|
@@ -490,19 +482,17 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
490
482
|
}
|
|
491
483
|
}
|
|
492
484
|
|
|
493
|
-
public weakLockConnection(
|
|
494
|
-
if (this.state === ConnectionManagerState.STOPPED ||
|
|
485
|
+
public weakLockConnection(nodeId: DhtAddress): void {
|
|
486
|
+
if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
|
|
495
487
|
return
|
|
496
488
|
}
|
|
497
|
-
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
498
489
|
this.locks.addWeakLocked(nodeId)
|
|
499
490
|
}
|
|
500
491
|
|
|
501
|
-
public weakUnlockConnection(
|
|
502
|
-
if (this.state === ConnectionManagerState.STOPPED ||
|
|
492
|
+
public weakUnlockConnection(nodeId: DhtAddress): void {
|
|
493
|
+
if (this.state === ConnectionManagerState.STOPPED || (nodeId === getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()))) {
|
|
503
494
|
return
|
|
504
495
|
}
|
|
505
|
-
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
506
496
|
this.locks.removeWeakLocked(nodeId)
|
|
507
497
|
}
|
|
508
498
|
|
|
@@ -543,18 +533,18 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
543
533
|
}
|
|
544
534
|
|
|
545
535
|
private async doGracefullyDisconnectAsync(targetDescriptor: PeerDescriptor, disconnectMode: DisconnectMode): Promise<void> {
|
|
546
|
-
|
|
536
|
+
const nodeId = getNodeIdFromPeerDescriptor(targetDescriptor)
|
|
537
|
+
logger.trace(nodeId + ' gracefullyDisconnectAsync()')
|
|
547
538
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
548
539
|
this.getLocalPeerDescriptor(),
|
|
549
540
|
targetDescriptor,
|
|
550
|
-
'DUMMY',
|
|
551
541
|
this.rpcCommunicator!,
|
|
552
542
|
ConnectionLockRpcClient
|
|
553
543
|
)
|
|
554
544
|
try {
|
|
555
545
|
await rpcRemote.gracefulDisconnect(disconnectMode)
|
|
556
546
|
} catch (ex) {
|
|
557
|
-
logger.trace(
|
|
547
|
+
logger.trace(nodeId + ' remote.gracefulDisconnect() failed' + ex)
|
|
558
548
|
}
|
|
559
549
|
}
|
|
560
550
|
|