@streamr/dht 100.0.0-testnet-two.0 → 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 +66 -0
- 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/Handshaker.d.ts +1 -1
- package/dist/src/connection/Handshaker.js +14 -5
- package/dist/src/connection/Handshaker.js.map +1 -1
- package/dist/src/connection/ManagedConnection.d.ts +3 -3
- package/dist/src/connection/ManagedConnection.js +3 -3
- package/dist/src/connection/ManagedConnection.js.map +1 -1
- 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 +11 -3
- package/dist/src/connection/webrtc/WebrtcConnectorRpcLocal.js.map +1 -1
- package/dist/src/connection/websocket/WebsocketConnector.js +18 -8
- 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 +23 -18
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcLocal.d.ts +4 -3
- package/dist/src/dht/DhtNodeRpcLocal.js +3 -2
- package/dist/src/dht/DhtNodeRpcLocal.js.map +1 -1
- package/dist/src/dht/DhtNodeRpcRemote.d.ts +6 -5
- package/dist/src/dht/DhtNodeRpcRemote.js +10 -11
- 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 -12
- 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/helpers/versionCompatibility.d.ts +2 -0
- package/dist/src/helpers/versionCompatibility.js +18 -0
- package/dist/src/helpers/versionCompatibility.js.map +1 -0
- package/dist/src/identifiers.d.ts +6 -0
- package/dist/src/identifiers.js +23 -0
- package/dist/src/identifiers.js.map +1 -0
- package/dist/src/proto/packages/dht/protos/DhtRpc.d.ts +13 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.js +9 -5
- package/dist/src/proto/packages/dht/protos/DhtRpc.js.map +1 -1
- package/package.json +5 -5
- package/protos/DhtRpc.proto +3 -1
- package/src/connection/ConnectionLockHandler.ts +15 -15
- package/src/connection/ConnectionLockRpcLocal.ts +3 -3
- package/src/connection/ConnectionManager.ts +4 -7
- package/src/connection/Handshaker.ts +21 -6
- package/src/connection/ManagedConnection.ts +10 -6
- 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 +11 -5
- package/src/connection/websocket/WebsocketConnector.ts +19 -11
- package/src/dht/DhtNode.ts +33 -31
- package/src/dht/DhtNodeRpcLocal.ts +4 -4
- package/src/dht/DhtNodeRpcRemote.ts +15 -17
- 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 -16
- 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/helpers/versionCompatibility.ts +13 -0
- package/src/identifiers.ts +20 -0
- package/src/proto/packages/dht/protos/DhtRpc.ts +18 -10
- 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/unit/versionCompatibility.test.ts +16 -0
- package/test/utils/customMatchers.ts +3 -2
- package/test/utils/mock/mockDataEntry.ts +8 -6
- package/test/utils/utils.ts +4 -4
- package/tsconfig.browser.json +2 -1
- package/tsconfig.jest.json +2 -1
- package/tsconfig.node.json +2 -1
- 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
|
@@ -1,38 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LocalDataStore = void 0;
|
|
4
|
-
const PeerID_1 = require("../../helpers/PeerID");
|
|
5
4
|
const MapWithTtl_1 = require("../../helpers/MapWithTtl");
|
|
6
|
-
const
|
|
5
|
+
const identifiers_1 = require("../../identifiers");
|
|
7
6
|
class LocalDataStore {
|
|
8
7
|
constructor(maxTtl) {
|
|
9
8
|
// A map into which each node can store one value per data key
|
|
10
9
|
// The first key is the key of the data, the second key is the
|
|
11
|
-
//
|
|
10
|
+
// DhtAddress of the creator of the data
|
|
12
11
|
this.store = new Map();
|
|
13
12
|
this.maxTtl = maxTtl;
|
|
14
13
|
}
|
|
15
14
|
storeEntry(dataEntry) {
|
|
16
|
-
const
|
|
17
|
-
const creatorNodeId = (0,
|
|
18
|
-
if (!this.store.has(
|
|
19
|
-
this.store.set(
|
|
15
|
+
const key = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key);
|
|
16
|
+
const creatorNodeId = (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.creator);
|
|
17
|
+
if (!this.store.has(key)) {
|
|
18
|
+
this.store.set(key, new MapWithTtl_1.MapWithTtl((e) => Math.min(e.ttl, this.maxTtl)));
|
|
20
19
|
}
|
|
21
|
-
if (this.store.get(
|
|
20
|
+
if (this.store.get(key).has(creatorNodeId)) {
|
|
22
21
|
const storedMillis = (dataEntry.createdAt.seconds * 1000) + (dataEntry.createdAt.nanos / 1000000);
|
|
23
|
-
const oldLocalEntry = this.store.get(
|
|
22
|
+
const oldLocalEntry = this.store.get(key).get(creatorNodeId);
|
|
24
23
|
const oldStoredMillis = (oldLocalEntry.createdAt.seconds * 1000) + (oldLocalEntry.createdAt.nanos / 1000000);
|
|
25
24
|
// do nothing if old entry is newer than the one being replicated
|
|
26
25
|
if (oldStoredMillis >= storedMillis) {
|
|
27
26
|
return false;
|
|
28
27
|
}
|
|
29
28
|
}
|
|
30
|
-
this.store.get(
|
|
29
|
+
this.store.get(key).set(creatorNodeId, dataEntry);
|
|
31
30
|
return true;
|
|
32
31
|
}
|
|
33
32
|
markAsDeleted(key, creator) {
|
|
34
|
-
const
|
|
35
|
-
const item = this.store.get(dataKey);
|
|
33
|
+
const item = this.store.get(key);
|
|
36
34
|
if ((item === undefined) || !item.has(creator)) {
|
|
37
35
|
return false;
|
|
38
36
|
}
|
|
@@ -47,32 +45,28 @@ class LocalDataStore {
|
|
|
47
45
|
}
|
|
48
46
|
getEntries(key) {
|
|
49
47
|
const dataEntries = new Map;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
dataEntries.set(key, value);
|
|
48
|
+
this.store.get(key)?.forEach((value, creator) => {
|
|
49
|
+
dataEntries.set(creator, value);
|
|
53
50
|
});
|
|
54
51
|
return dataEntries;
|
|
55
52
|
}
|
|
56
53
|
setStale(key, creator, stale) {
|
|
57
|
-
const
|
|
58
|
-
const storedEntry = this.store.get(mapKey)?.get(creator);
|
|
54
|
+
const storedEntry = this.store.get(key)?.get(creator);
|
|
59
55
|
if (storedEntry) {
|
|
60
56
|
storedEntry.stale = stale;
|
|
61
57
|
}
|
|
62
58
|
}
|
|
63
59
|
setAllEntriesAsStale(key) {
|
|
64
|
-
|
|
65
|
-
this.store.get(mapKey)?.forEach((value) => {
|
|
60
|
+
this.store.get(key)?.forEach((value) => {
|
|
66
61
|
value.stale = true;
|
|
67
62
|
});
|
|
68
63
|
}
|
|
69
64
|
deleteEntry(key, creator) {
|
|
70
|
-
const
|
|
71
|
-
const storedEntry = this.store.get(mapKey)?.get(creator);
|
|
65
|
+
const storedEntry = this.store.get(key)?.get(creator);
|
|
72
66
|
if (storedEntry) {
|
|
73
|
-
this.store.get(
|
|
74
|
-
if (this.store.get(
|
|
75
|
-
this.store.delete(
|
|
67
|
+
this.store.get(key)?.delete(creator);
|
|
68
|
+
if (this.store.get(key)?.size() === 0) {
|
|
69
|
+
this.store.delete(key);
|
|
76
70
|
}
|
|
77
71
|
}
|
|
78
72
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"LocalDataStore.js","sourceRoot":"","sources":["../../../../src/dht/store/LocalDataStore.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"LocalDataStore.js","sourceRoot":"","sources":["../../../../src/dht/store/LocalDataStore.ts"],"names":[],"mappings":";;;AACA,yDAAqD;AACrD,mDAAoE;AAEpE,MAAa,cAAc;IAIvB,YAAY,MAAc;QAI1B,8DAA8D;QAC9D,8DAA8D;QAC9D,wCAAwC;QAChC,UAAK,GAAuD,IAAI,GAAG,EAAE,CAAA;QANzE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;IACxB,CAAC;IAOM,UAAU,CAAC,SAAoB;QAClC,MAAM,GAAG,GAAG,IAAA,kCAAoB,EAAC,SAAS,CAAC,GAAG,CAAC,CAAA;QAC/C,MAAM,aAAa,GAAG,IAAA,kCAAoB,EAAC,SAAS,CAAC,OAAO,CAAC,CAAA;QAC7D,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;YACtB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,uBAAU,CAAC,CAAC,CAAC,EAAE,EAA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ACnC,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;aACzB;SACJ;IACL,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;QAC5C,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;CACJ;AAnFD,wCAmFC"}
|
|
@@ -5,7 +5,7 @@ import { RecursiveOperationManager } from '../recursive-operation/RecursiveOpera
|
|
|
5
5
|
import { LocalDataStore } from './LocalDataStore';
|
|
6
6
|
import { StoreRpcRemote } from './StoreRpcRemote';
|
|
7
7
|
import { ServiceID } from '../../types/ServiceID';
|
|
8
|
-
import {
|
|
8
|
+
import { DhtAddress } from '../../identifiers';
|
|
9
9
|
interface StoreManagerConfig {
|
|
10
10
|
rpcCommunicator: RoutingRpcCommunicator;
|
|
11
11
|
recursiveOperationManager: RecursiveOperationManager;
|
|
@@ -14,7 +14,7 @@ interface StoreManagerConfig {
|
|
|
14
14
|
serviceId: ServiceID;
|
|
15
15
|
highestTtl: number;
|
|
16
16
|
redundancyFactor: number;
|
|
17
|
-
getClosestNeighborsTo: (
|
|
17
|
+
getClosestNeighborsTo: (dataKey: DhtAddress, n?: number) => PeerDescriptor[];
|
|
18
18
|
createRpcRemote: (contact: PeerDescriptor) => StoreRpcRemote;
|
|
19
19
|
}
|
|
20
20
|
export declare class StoreManager {
|
|
@@ -24,7 +24,7 @@ export declare class StoreManager {
|
|
|
24
24
|
onNewContact(peerDescriptor: PeerDescriptor): void;
|
|
25
25
|
private replicateAndUpdateStaleState;
|
|
26
26
|
private replicateDataToContact;
|
|
27
|
-
storeDataToDht(key:
|
|
27
|
+
storeDataToDht(key: DhtAddress, data: Any, creator: DhtAddress): Promise<PeerDescriptor[]>;
|
|
28
28
|
private selfIsWithinRedundancyFactor;
|
|
29
29
|
private replicateDataToClosestNodes;
|
|
30
30
|
private replicateDataToNeighbors;
|
|
@@ -8,7 +8,7 @@ const timestamp_1 = require("../../proto/google/protobuf/timestamp");
|
|
|
8
8
|
const SortedContactList_1 = require("../contact/SortedContactList");
|
|
9
9
|
const Contact_1 = require("../contact/Contact");
|
|
10
10
|
const lodash_1 = require("lodash");
|
|
11
|
-
const
|
|
11
|
+
const identifiers_1 = require("../../identifiers");
|
|
12
12
|
const StoreRpcLocal_1 = require("./StoreRpcLocal");
|
|
13
13
|
const PeerManager_1 = require("../PeerManager");
|
|
14
14
|
const logger = new utils_1.Logger(module);
|
|
@@ -34,25 +34,25 @@ class StoreManager {
|
|
|
34
34
|
replicateAndUpdateStaleState(dataEntry, newNode) {
|
|
35
35
|
const newNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(newNode);
|
|
36
36
|
// TODO use config option or named constant?
|
|
37
|
-
const closestToData = this.config.getClosestNeighborsTo(dataEntry.key, 10);
|
|
37
|
+
const closestToData = this.config.getClosestNeighborsTo((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), 10);
|
|
38
38
|
const sortedList = new SortedContactList_1.SortedContactList({
|
|
39
|
-
referenceId: (0,
|
|
39
|
+
referenceId: (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key),
|
|
40
40
|
maxSize: 20,
|
|
41
41
|
allowToContainReferenceId: true,
|
|
42
42
|
emitEvents: false
|
|
43
43
|
});
|
|
44
44
|
sortedList.addContact(new Contact_1.Contact(this.config.localPeerDescriptor));
|
|
45
45
|
closestToData.forEach((neighbor) => {
|
|
46
|
-
if (
|
|
46
|
+
if (newNodeId !== (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(neighbor)) {
|
|
47
47
|
sortedList.addContact(new Contact_1.Contact(neighbor));
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
|
-
const selfIsPrimaryStorer = (
|
|
50
|
+
const selfIsPrimaryStorer = (sortedList.getClosestContactId() === (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.config.localPeerDescriptor));
|
|
51
51
|
if (selfIsPrimaryStorer) {
|
|
52
52
|
sortedList.addContact(new Contact_1.Contact(newNode));
|
|
53
53
|
const sorted = sortedList.getContactIds();
|
|
54
54
|
// findIndex should never return -1 here because we just added the new node to the list
|
|
55
|
-
const index = (0, lodash_1.findIndex)(sorted, (nodeId) => (
|
|
55
|
+
const index = (0, lodash_1.findIndex)(sorted, (nodeId) => (nodeId === newNodeId));
|
|
56
56
|
// if new node is within the storageRedundancyFactor closest nodes to the data
|
|
57
57
|
// do replicate data to it
|
|
58
58
|
if (index < this.config.redundancyFactor) {
|
|
@@ -61,8 +61,8 @@ class StoreManager {
|
|
|
61
61
|
});
|
|
62
62
|
}
|
|
63
63
|
}
|
|
64
|
-
else if (!this.selfIsWithinRedundancyFactor(dataEntry.key)) {
|
|
65
|
-
this.config.localDataStore.setStale(dataEntry.key, (0,
|
|
64
|
+
else if (!this.selfIsWithinRedundancyFactor((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key))) {
|
|
65
|
+
this.config.localDataStore.setStale((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.creator), true);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
68
|
async replicateDataToContact(dataEntry, contact) {
|
|
@@ -84,9 +84,9 @@ class StoreManager {
|
|
|
84
84
|
for (let i = 0; i < closestNodes.length && successfulNodes.length < this.config.redundancyFactor; i++) {
|
|
85
85
|
if ((0, peerIdFromPeerDescriptor_1.areEqualPeerDescriptors)(this.config.localPeerDescriptor, closestNodes[i])) {
|
|
86
86
|
this.config.localDataStore.storeEntry({
|
|
87
|
-
key,
|
|
87
|
+
key: (0, identifiers_1.getRawFromDhtAddress)(key),
|
|
88
88
|
data,
|
|
89
|
-
creator: (0,
|
|
89
|
+
creator: (0, identifiers_1.getRawFromDhtAddress)(creator),
|
|
90
90
|
createdAt,
|
|
91
91
|
storedAt: timestamp_1.Timestamp.now(),
|
|
92
92
|
ttl,
|
|
@@ -99,9 +99,9 @@ class StoreManager {
|
|
|
99
99
|
const rpcRemote = this.config.createRpcRemote(closestNodes[i]);
|
|
100
100
|
try {
|
|
101
101
|
await rpcRemote.storeData({
|
|
102
|
-
key,
|
|
102
|
+
key: (0, identifiers_1.getRawFromDhtAddress)(key),
|
|
103
103
|
data,
|
|
104
|
-
creator: (0,
|
|
104
|
+
creator: (0, identifiers_1.getRawFromDhtAddress)(creator),
|
|
105
105
|
createdAt,
|
|
106
106
|
ttl
|
|
107
107
|
});
|
|
@@ -120,16 +120,15 @@ class StoreManager {
|
|
|
120
120
|
return true;
|
|
121
121
|
}
|
|
122
122
|
else {
|
|
123
|
-
const
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
return (0, PeerManager_1.getDistance)(dataId, localNodeId) < (0, PeerManager_1.getDistance)(dataId, furthestCloseNeighbor);
|
|
123
|
+
const furthestCloseNeighbor = closestNeighbors[closestNeighbors.length - 1];
|
|
124
|
+
const dataKeyRaw = (0, identifiers_1.getRawFromDhtAddress)(dataKey);
|
|
125
|
+
return (0, PeerManager_1.getDistance)(dataKeyRaw, this.config.localPeerDescriptor.nodeId) < (0, PeerManager_1.getDistance)(dataKeyRaw, furthestCloseNeighbor.nodeId);
|
|
127
126
|
}
|
|
128
127
|
}
|
|
129
128
|
async replicateDataToClosestNodes() {
|
|
130
129
|
const dataEntries = Array.from(this.config.localDataStore.values());
|
|
131
130
|
await Promise.all(dataEntries.map(async (dataEntry) => {
|
|
132
|
-
const neighbors = this.config.getClosestNeighborsTo(dataEntry.key, this.config.redundancyFactor);
|
|
131
|
+
const neighbors = this.config.getClosestNeighborsTo((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), this.config.redundancyFactor);
|
|
133
132
|
await Promise.all(neighbors.map(async (neighbor) => {
|
|
134
133
|
const rpcRemote = this.config.createRpcRemote(neighbor);
|
|
135
134
|
try {
|
|
@@ -146,9 +145,9 @@ class StoreManager {
|
|
|
146
145
|
const localNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(this.config.localPeerDescriptor);
|
|
147
146
|
const incomingNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(incomingPeer);
|
|
148
147
|
// TODO use config option or named constant?
|
|
149
|
-
const closestToData = this.config.getClosestNeighborsTo(dataEntry.key, 10);
|
|
148
|
+
const closestToData = this.config.getClosestNeighborsTo((0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key), 10);
|
|
150
149
|
const sortedList = new SortedContactList_1.SortedContactList({
|
|
151
|
-
referenceId: (0,
|
|
150
|
+
referenceId: (0, identifiers_1.getDhtAddressFromRaw)(dataEntry.key),
|
|
152
151
|
maxSize: this.config.redundancyFactor,
|
|
153
152
|
allowToContainReferenceId: true,
|
|
154
153
|
emitEvents: false
|
|
@@ -157,7 +156,7 @@ class StoreManager {
|
|
|
157
156
|
closestToData.forEach((neighbor) => {
|
|
158
157
|
sortedList.addContact(new Contact_1.Contact(neighbor));
|
|
159
158
|
});
|
|
160
|
-
const selfIsPrimaryStorer = (
|
|
159
|
+
const selfIsPrimaryStorer = (sortedList.getClosestContactId() === localNodeId);
|
|
161
160
|
const targets = selfIsPrimaryStorer
|
|
162
161
|
// if we are the closest to the data, replicate to all storageRedundancyFactor nearest
|
|
163
162
|
? sortedList.getAllContacts()
|
|
@@ -165,7 +164,7 @@ class StoreManager {
|
|
|
165
164
|
: [sortedList.getAllContacts()[0]];
|
|
166
165
|
targets.forEach((contact) => {
|
|
167
166
|
const contactNodeId = (0, peerIdFromPeerDescriptor_1.getNodeIdFromPeerDescriptor)(contact.getPeerDescriptor());
|
|
168
|
-
if (
|
|
167
|
+
if ((incomingNodeId !== contactNodeId) && (localNodeId !== contactNodeId)) {
|
|
169
168
|
setImmediate(() => {
|
|
170
169
|
(0, utils_1.executeSafePromise)(async () => {
|
|
171
170
|
await this.replicateDataToContact(dataEntry, contact.getPeerDescriptor());
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreManager.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreManager.ts"],"names":[],"mappings":";;;AAAA,mEAG+C;AAK/C,qFAA6G;AAC7G,
|
|
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,mCAAkC;AAClC,mDAA0F;AAC1F,mDAA+C;AAC/C,gDAA4C;AAc5C,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,YAAY;IAIrB,YAAY,MAA0B;QAClC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,uBAAuB,EAAE,CAAA;IAClC,CAAC;IAEO,uBAAuB;QAC3B,MAAM,QAAQ,GAAG,IAAI,6BAAa,CAAC;YAC/B,cAAc,EAAE,IAAI,CAAC,MAAM,CAAC,cAAc;YAC1C,wBAAwB,EAAE,CAAC,YAA4B,EAAE,SAAoB,EAAE,EAAE,CAAC,IAAI,CAAC,wBAAwB,CAAC,YAAY,EAAE,SAAS,CAAC;YACxI,4BAA4B,EAAE,CAAC,GAAe,EAAW,EAAE,CAAC,IAAI,CAAC,4BAA4B,CAAC,GAAG,CAAC;SACrG,CAAC,CAAA;QACF,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,iBAAiB,CAAC,yBAAgB,EAAE,0BAAiB,EAAE,WAAW,EAC1F,CAAC,OAAyB,EAAE,EAAE,CAAC,QAAQ,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAA;QAC/D,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,uBAAuB,CAAC,6BAAoB,EAAE,eAAe,EACrF,CAAC,OAA6B,EAAE,OAA0B,EAAE,EAAE,CAAC,QAAQ,C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f/empty';
|
|
|
3
3
|
import { DataEntry, PeerDescriptor, ReplicateDataRequest, StoreDataRequest, StoreDataResponse } from '../../proto/packages/dht/protos/DhtRpc';
|
|
4
4
|
import { IStoreRpc } from '../../proto/packages/dht/protos/DhtRpc.server';
|
|
5
5
|
import { LocalDataStore } from './LocalDataStore';
|
|
6
|
+
import { DhtAddress } from '../../identifiers';
|
|
6
7
|
interface StoreRpcLocalConfig {
|
|
7
8
|
localDataStore: LocalDataStore;
|
|
8
9
|
replicateDataToNeighbors: (incomingPeer: PeerDescriptor, dataEntry: DataEntry) => void;
|
|
9
|
-
selfIsWithinRedundancyFactor: (key:
|
|
10
|
+
selfIsWithinRedundancyFactor: (key: DhtAddress) => boolean;
|
|
10
11
|
}
|
|
11
12
|
export declare class StoreRpcLocal implements IStoreRpc {
|
|
12
13
|
private readonly config;
|
|
@@ -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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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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A,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":";;;;;;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,WAA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AO,MAAM,CAAC,YAAY,CAAC,IAAI,GAAG,GAAG,GAAG,OAAO,CAAC,GAAG,MAAM,CAAC,YAAY,CAAC,OAAO,GAAG,GAAG,GAAG,IAAI,CAAC,CAAA;IAChG,CAAC;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,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,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.excludePatchVersion = exports.isCompatibleVersion = void 0;
|
|
4
|
+
// Is able to compare versions such as 1.2.3 and 1.2.4
|
|
5
|
+
// can also compare versions such as 100.0.0-pretestnet.0 and 100.0.0-pretestnet.40
|
|
6
|
+
const isCompatibleVersion = (version1, version2) => {
|
|
7
|
+
const minorVersion1 = (0, exports.excludePatchVersion)(version1);
|
|
8
|
+
const minorVersion2 = (0, exports.excludePatchVersion)(version2);
|
|
9
|
+
return minorVersion1 === minorVersion2;
|
|
10
|
+
};
|
|
11
|
+
exports.isCompatibleVersion = isCompatibleVersion;
|
|
12
|
+
const excludePatchVersion = (version) => {
|
|
13
|
+
const versionParts = version.split('.');
|
|
14
|
+
versionParts.pop();
|
|
15
|
+
return versionParts.join('.');
|
|
16
|
+
};
|
|
17
|
+
exports.excludePatchVersion = excludePatchVersion;
|
|
18
|
+
//# sourceMappingURL=versionCompatibility.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"versionCompatibility.js","sourceRoot":"","sources":["../../../src/helpers/versionCompatibility.ts"],"names":[],"mappings":";;;AAAA,sDAAsD;AACtD,mFAAmF;AAC5E,MAAM,mBAAmB,GAAG,CAAC,QAAgB,EAAE,QAAgB,EAAW,EAAE;IAC/E,MAAM,aAAa,GAAG,IAAA,2BAAmB,EAAC,QAAQ,CAAC,CAAA;IACnD,MAAM,aAAa,GAAG,IAAA,2BAAmB,EAAC,QAAQ,CAAC,CAAA;IACnD,OAAO,aAAa,KAAK,aAAa,CAAA;AAC1C,CAAC,CAAA;AAJY,QAAA,mBAAmB,uBAI/B;AAEM,MAAM,mBAAmB,GAAG,CAAC,OAAe,EAAU,EAAE;IAC3D,MAAM,YAAY,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;IACvC,YAAY,CAAC,GAAG,EAAE,CAAA;IAClB,OAAO,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AACjC,CAAC,CAAA;AAJY,QAAA,mBAAmB,uBAI/B"}
|
|
@@ -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"}
|