@streamr/dht 100.0.0-testnet-two.1 → 100.0.0-testnet-two.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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.js +3 -3
- 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/SimulatorConnector.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 +2 -2
- 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 +21 -16
- 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 +12 -12
- 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 +16 -9
- 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 +12 -11
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.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/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 -8
- package/dist/src/dht/store/LocalDataStore.js +18 -24
- 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 +20 -21
- 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 -1
- 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 +4 -7
- package/src/connection/ManagedConnection.ts +2 -2
- package/src/connection/simulator/Simulator.ts +2 -2
- package/src/connection/simulator/SimulatorConnector.ts +2 -2
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +0 -4
- package/src/connection/webrtc/WebrtcConnector.ts +2 -3
- package/src/connection/webrtc/WebrtcConnectorRpcLocal.ts +2 -3
- package/src/connection/websocket/WebsocketConnector.ts +5 -6
- package/src/dht/DhtNode.ts +31 -29
- 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 +20 -20
- 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 +32 -11
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +14 -14
- 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/RoutingSession.ts +6 -8
- package/src/dht/store/LocalDataStore.ts +25 -33
- package/src/dht/store/StoreManager.ts +25 -29
- 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 -4
- 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 +25 -23
- 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 +37 -29
- 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
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,wHAAA,2BAA2B,OAAA;AAC/C,+EAA4E;AAAnE,mIAAA,uBAAuB,OAAA;AAEhC,gEAA8D;AAArD,gHAAA,cAAc,OAAA;AACvB,0EAAwE;AAA/D,kHAAA,eAAe,OAAA;AACxB,oEAAkE;AAAzD,sHAAA,iBAAiB,OAAA;AAC1B,wDAAyD;AAAhD,6GAAA,cAAc,OAAA;AACvB,2CAAyC;AAAhC,gGAAA,MAAM,OAAA"}
|
|
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,wHAAA,2BAA2B,OAAA;AAC/C,+EAA4E;AAAnE,mIAAA,uBAAuB,OAAA;AAEhC,gEAA8D;AAArD,gHAAA,cAAc,OAAA;AACvB,0EAAwE;AAA/D,kHAAA,eAAe,OAAA;AACxB,oEAAkE;AAAzD,sHAAA,iBAAiB,OAAA;AAC1B,wDAAyD;AAAhD,6GAAA,cAAc,OAAA;AACvB,2CAAyC;AAAhC,gGAAA,MAAM,OAAA;AAEf,6CAAqG;AAAjE,mHAAA,oBAAoB,OAAA;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":"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"}
|
|
@@ -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,6 +3,7 @@ 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
|
};
|
|
@@ -10,7 +11,7 @@ exports.peerIdFromPeerDescriptor = peerIdFromPeerDescriptor;
|
|
|
10
11
|
// TODO could use this in trackerless-network (instead of copy-pasted same implementation)
|
|
11
12
|
// and move this to nodeId.ts
|
|
12
13
|
const getNodeIdFromPeerDescriptor = (peerDescriptor) => {
|
|
13
|
-
return (0,
|
|
14
|
+
return (0, identifiers_1.getDhtAddressFromRaw)(peerDescriptor.nodeId);
|
|
14
15
|
};
|
|
15
16
|
exports.getNodeIdFromPeerDescriptor = getNodeIdFromPeerDescriptor;
|
|
16
17
|
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;AAED,0FAA0F;AAC1F,6BAA6B;AACtB,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.2",
|
|
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.2",
|
|
35
|
+
"@streamr/proto-rpc": "100.0.0-testnet-two.2",
|
|
36
|
+
"@streamr/utils": "100.0.0-testnet-two.2",
|
|
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.2",
|
|
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
|
}
|
|
@@ -31,7 +31,7 @@ import { ConnectionLockRpcRemote } from './ConnectionLockRpcRemote'
|
|
|
31
31
|
import { WEBRTC_CLEANUP } from './webrtc/NodeWebrtcConnection'
|
|
32
32
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
33
33
|
import { ConnectionLockRpcLocal } from './ConnectionLockRpcLocal'
|
|
34
|
-
import {
|
|
34
|
+
import { DhtAddress } from '../identifiers'
|
|
35
35
|
|
|
36
36
|
export interface ConnectionManagerConfig {
|
|
37
37
|
maxConnections?: number
|
|
@@ -106,7 +106,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
106
106
|
private readonly duplicateMessageDetector: DuplicateDetector = new DuplicateDetector(100000, 100)
|
|
107
107
|
private readonly metrics: ConnectionManagerMetrics
|
|
108
108
|
private locks = new ConnectionLockHandler()
|
|
109
|
-
private connections: Map<
|
|
109
|
+
private connections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
110
110
|
private readonly connectorFacade: ConnectorFacade
|
|
111
111
|
private rpcCommunicator?: RoutingRpcCommunicator
|
|
112
112
|
private disconnectorIntervalRef?: NodeJS.Timeout
|
|
@@ -134,8 +134,8 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
134
134
|
rpcRequestTimeout: 10000 // TODO use config option or named constant?
|
|
135
135
|
})
|
|
136
136
|
const lockRpcLocal = new ConnectionLockRpcLocal({
|
|
137
|
-
addRemoteLocked: (id:
|
|
138
|
-
removeRemoteLocked: (id:
|
|
137
|
+
addRemoteLocked: (id: DhtAddress, lockId: LockID) => this.locks.addRemoteLocked(id, lockId),
|
|
138
|
+
removeRemoteLocked: (id: DhtAddress, lockId: LockID) => this.locks.removeRemoteLocked(id, lockId),
|
|
139
139
|
closeConnection: (peerDescriptor: PeerDescriptor, gracefulLeave: boolean, reason?: string) => {
|
|
140
140
|
// TODO should we have some handling for this floating promise?
|
|
141
141
|
this.closeConnection(peerDescriptor, gracefulLeave, reason)
|
|
@@ -462,7 +462,6 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
462
462
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
463
463
|
this.getLocalPeerDescriptor(),
|
|
464
464
|
targetDescriptor,
|
|
465
|
-
'DUMMY',
|
|
466
465
|
this.rpcCommunicator!,
|
|
467
466
|
ConnectionLockRpcClient
|
|
468
467
|
)
|
|
@@ -481,7 +480,6 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
481
480
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
482
481
|
this.getLocalPeerDescriptor(),
|
|
483
482
|
targetDescriptor,
|
|
484
|
-
'DUMMY',
|
|
485
483
|
this.rpcCommunicator!,
|
|
486
484
|
ConnectionLockRpcClient
|
|
487
485
|
)
|
|
@@ -547,7 +545,6 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
547
545
|
const rpcRemote = new ConnectionLockRpcRemote(
|
|
548
546
|
this.getLocalPeerDescriptor(),
|
|
549
547
|
targetDescriptor,
|
|
550
|
-
'DUMMY',
|
|
551
548
|
this.rpcCommunicator!,
|
|
552
549
|
ConnectionLockRpcClient
|
|
553
550
|
)
|
|
@@ -6,7 +6,7 @@ import { Logger, runAndRaceEvents3, RunAndRaceEventsReturnType } from '@streamr/
|
|
|
6
6
|
import EventEmitter from 'eventemitter3'
|
|
7
7
|
import { getNodeIdFromPeerDescriptor } from '../helpers/peerIdFromPeerDescriptor'
|
|
8
8
|
import { getNodeIdOrUnknownFromPeerDescriptor } from './ConnectionManager'
|
|
9
|
-
import {
|
|
9
|
+
import { DhtAddress } from '../identifiers'
|
|
10
10
|
|
|
11
11
|
export interface ManagedConnectionEvents {
|
|
12
12
|
managedData: (bytes: Uint8Array, remotePeerDescriptor: PeerDescriptor) => void
|
|
@@ -156,7 +156,7 @@ export class ManagedConnection extends EventEmitter<Events> {
|
|
|
156
156
|
return this
|
|
157
157
|
}
|
|
158
158
|
|
|
159
|
-
public getNodeId():
|
|
159
|
+
public getNodeId(): DhtAddress {
|
|
160
160
|
return getNodeIdFromPeerDescriptor(this.remotePeerDescriptor!)
|
|
161
161
|
}
|
|
162
162
|
|
|
@@ -10,7 +10,7 @@ import { getRegionDelayMatrix } from './pings'
|
|
|
10
10
|
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
11
11
|
import Heap from 'heap'
|
|
12
12
|
import { debugVars } from '../../helpers/debugHelpers'
|
|
13
|
-
import {
|
|
13
|
+
import { DhtAddress } from '../../identifiers'
|
|
14
14
|
|
|
15
15
|
const logger = new Logger(module)
|
|
16
16
|
|
|
@@ -92,7 +92,7 @@ class CloseOperation extends SimulatorOperation {
|
|
|
92
92
|
|
|
93
93
|
export class Simulator extends EventEmitter<ConnectionSourceEvents> {
|
|
94
94
|
private stopped = false
|
|
95
|
-
private connectors: Map<
|
|
95
|
+
private connectors: Map<DhtAddress, SimulatorConnector> = new Map()
|
|
96
96
|
private latencyTable?: Array<Array<number>>
|
|
97
97
|
private associations: Map<ConnectionID, Association> = new Map()
|
|
98
98
|
|
|
@@ -9,13 +9,13 @@ import { ManagedConnection } from '../ManagedConnection'
|
|
|
9
9
|
import { Simulator } from './Simulator'
|
|
10
10
|
import { SimulatorConnection } from './SimulatorConnection'
|
|
11
11
|
import { getNodeIdFromPeerDescriptor } from '../../helpers/peerIdFromPeerDescriptor'
|
|
12
|
-
import {
|
|
12
|
+
import { DhtAddress } from '../../identifiers'
|
|
13
13
|
|
|
14
14
|
const logger = new Logger(module)
|
|
15
15
|
|
|
16
16
|
export class SimulatorConnector {
|
|
17
17
|
|
|
18
|
-
private connectingConnections: Map<
|
|
18
|
+
private connectingConnections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
19
19
|
private stopped = false
|
|
20
20
|
private localPeerDescriptor: PeerDescriptor
|
|
21
21
|
private simulator: Simulator
|
|
@@ -194,10 +194,6 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
194
194
|
logger.warn(`dc.onError: ${err}`)
|
|
195
195
|
}
|
|
196
196
|
|
|
197
|
-
dataChannel.onbufferedamountlow = () => {
|
|
198
|
-
//this.emitLowBackpressure()
|
|
199
|
-
}
|
|
200
|
-
|
|
201
197
|
dataChannel.onmessage = (msg) => {
|
|
202
198
|
logger.trace('dc.onmessage')
|
|
203
199
|
this.emit('data', new Uint8Array(msg.data))
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
import { PortRange } from '../ConnectionManager'
|
|
22
22
|
import { ServerCallContext } from '@protobuf-ts/runtime-rpc'
|
|
23
23
|
import { WebrtcConnectorRpcLocal } from './WebrtcConnectorRpcLocal'
|
|
24
|
-
import {
|
|
24
|
+
import { DhtAddress } from '../../identifiers'
|
|
25
25
|
|
|
26
26
|
const logger = new Logger(module)
|
|
27
27
|
|
|
@@ -58,7 +58,7 @@ export class WebrtcConnector {
|
|
|
58
58
|
|
|
59
59
|
private static readonly WEBRTC_CONNECTOR_SERVICE_ID = 'system/webrtc-connector'
|
|
60
60
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
61
|
-
private readonly ongoingConnectAttempts: Map<
|
|
61
|
+
private readonly ongoingConnectAttempts: Map<DhtAddress, ManagedWebrtcConnection> = new Map()
|
|
62
62
|
private localPeerDescriptor?: PeerDescriptor
|
|
63
63
|
private stopped = false
|
|
64
64
|
private config: WebrtcConnectorConfig
|
|
@@ -170,7 +170,6 @@ export class WebrtcConnector {
|
|
|
170
170
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
171
171
|
this.localPeerDescriptor!,
|
|
172
172
|
targetPeerDescriptor,
|
|
173
|
-
'DUMMY',
|
|
174
173
|
this.rpcCommunicator,
|
|
175
174
|
WebrtcConnectorRpcClient
|
|
176
175
|
)
|
|
@@ -18,7 +18,7 @@ import { ManagedConnection } from '../ManagedConnection'
|
|
|
18
18
|
import { ManagedWebrtcConnection } from '../ManagedWebrtcConnection'
|
|
19
19
|
import { NodeWebrtcConnection } from './NodeWebrtcConnection'
|
|
20
20
|
import { WebrtcConnectorRpcRemote } from './WebrtcConnectorRpcRemote'
|
|
21
|
-
import {
|
|
21
|
+
import { DhtAddress } from '../../identifiers'
|
|
22
22
|
import { version } from '../../../package.json'
|
|
23
23
|
import { isCompatibleVersion } from '../../helpers/versionCompatibility'
|
|
24
24
|
|
|
@@ -28,7 +28,7 @@ interface WebrtcConnectorRpcLocalConfig {
|
|
|
28
28
|
connect: (targetPeerDescriptor: PeerDescriptor) => ManagedConnection
|
|
29
29
|
onNewConnection: (connection: ManagedConnection) => boolean
|
|
30
30
|
// TODO pass accessor methods instead of passing a mutable entity
|
|
31
|
-
ongoingConnectAttempts: Map<
|
|
31
|
+
ongoingConnectAttempts: Map<DhtAddress, ManagedWebrtcConnection>
|
|
32
32
|
rpcCommunicator: ListeningRpcCommunicator
|
|
33
33
|
getLocalPeerDescriptor: () => PeerDescriptor
|
|
34
34
|
allowPrivateAddresses: boolean
|
|
@@ -68,7 +68,6 @@ export class WebrtcConnectorRpcLocal implements IWebrtcConnectorRpc {
|
|
|
68
68
|
const remoteConnector = new WebrtcConnectorRpcRemote(
|
|
69
69
|
this.config.getLocalPeerDescriptor(),
|
|
70
70
|
remotePeer,
|
|
71
|
-
'DUMMY',
|
|
72
71
|
this.config.rpcCommunicator,
|
|
73
72
|
WebrtcConnectorRpcClient
|
|
74
73
|
)
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
WebsocketConnectionRequest
|
|
13
13
|
} from '../../proto/packages/dht/protos/DhtRpc'
|
|
14
14
|
import { WebsocketConnectorRpcClient } from '../../proto/packages/dht/protos/DhtRpc.client'
|
|
15
|
-
import { Logger,
|
|
15
|
+
import { Logger, wait } from '@streamr/utils'
|
|
16
16
|
import { ManagedConnection } from '../ManagedConnection'
|
|
17
17
|
import { WebsocketServer } from './WebsocketServer'
|
|
18
18
|
import { sendConnectivityRequest } from '../connectivityChecker'
|
|
@@ -29,7 +29,7 @@ import { AutoCertifierClientFacade } from './AutoCertifierClientFacade'
|
|
|
29
29
|
import { attachConnectivityRequestHandler } from '../connectivityRequestHandler'
|
|
30
30
|
import * as Err from '../../helpers/errors'
|
|
31
31
|
import { Empty } from '../../proto/google/protobuf/empty'
|
|
32
|
-
import {
|
|
32
|
+
import { DhtAddress } from '../../identifiers'
|
|
33
33
|
import { version } from '../../../package.json'
|
|
34
34
|
import { isCompatibleVersion } from '../../helpers/versionCompatibility'
|
|
35
35
|
|
|
@@ -63,12 +63,12 @@ export class WebsocketConnector {
|
|
|
63
63
|
private static readonly WEBSOCKET_CONNECTOR_SERVICE_ID = 'system/websocket-connector'
|
|
64
64
|
private readonly rpcCommunicator: ListeningRpcCommunicator
|
|
65
65
|
private readonly websocketServer?: WebsocketServer
|
|
66
|
-
private readonly ongoingConnectRequests: Map<
|
|
66
|
+
private readonly ongoingConnectRequests: Map<DhtAddress, ManagedConnection> = new Map()
|
|
67
67
|
private host?: string
|
|
68
68
|
private autoCertifierClient?: AutoCertifierClientFacade
|
|
69
69
|
private selectedPort?: number
|
|
70
70
|
private localPeerDescriptor?: PeerDescriptor
|
|
71
|
-
private connectingConnections: Map<
|
|
71
|
+
private connectingConnections: Map<DhtAddress, ManagedConnection> = new Map()
|
|
72
72
|
private abortController = new AbortController()
|
|
73
73
|
private readonly config: WebsocketConnectorConfig
|
|
74
74
|
|
|
@@ -203,7 +203,7 @@ export class WebsocketConnector {
|
|
|
203
203
|
}
|
|
204
204
|
} catch (err) {
|
|
205
205
|
if (reattempt < ENTRY_POINT_CONNECTION_ATTEMPTS) {
|
|
206
|
-
const error = `Failed to connect to entrypoint with id ${
|
|
206
|
+
const error = `Failed to connect to entrypoint with id ${getNodeIdFromPeerDescriptor(entryPoint)} `
|
|
207
207
|
+ `and URL ${connectivityMethodToWebsocketUrl(entryPoint.websocket!)}`
|
|
208
208
|
logger.error(error, { error: err })
|
|
209
209
|
await wait(2000)
|
|
@@ -264,7 +264,6 @@ export class WebsocketConnector {
|
|
|
264
264
|
const remoteConnector = new WebsocketConnectorRpcRemote(
|
|
265
265
|
localPeerDescriptor,
|
|
266
266
|
targetPeerDescriptor,
|
|
267
|
-
'DUMMY',
|
|
268
267
|
this.rpcCommunicator,
|
|
269
268
|
WebsocketConnectorRpcClient
|
|
270
269
|
)
|