@streamr/dht 100.1.1 → 100.1.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 +8 -10
- package/dist/src/dht/contact/ContactList.d.ts +0 -1
- package/dist/src/dht/contact/ContactList.js +0 -1
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +0 -2
- package/dist/src/dht/contact/SortedContactList.js +0 -18
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/package.json +8 -10
- package/src/dht/contact/ContactList.ts +1 -1
- package/src/dht/contact/SortedContactList.ts +0 -20
- package/test/unit/SortedContactList.test.ts +0 -24
- package/test/benchmark/kademlia-simulation/Contact.ts +0 -32
- package/test/benchmark/kademlia-simulation/KademliaSimulation.ts +0 -94
- package/test/benchmark/kademlia-simulation/SimulationNode.ts +0 -129
- package/test/data/generateGroundTruthData.ts +0 -71
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamr/dht",
|
|
3
|
-
"version": "100.1.
|
|
3
|
+
"version": "100.1.2",
|
|
4
4
|
"description": "Streamr Network DHT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,18 +23,16 @@
|
|
|
23
23
|
"test-unit": "jest test/unit",
|
|
24
24
|
"test-integration": "jest --bail test/integration",
|
|
25
25
|
"test-end-to-end": "jest --bail test/end-to-end",
|
|
26
|
-
"benchmark": "jest test/benchmark"
|
|
27
|
-
"prepare-kademlia-simulation": "cd test/data && node --max-old-space-size=8096 -- ../../../../node_modules/.bin/ts-node -P ../../tsconfig.node.json generateGroundTruthData.ts",
|
|
28
|
-
"run-kademlia-simulation": "ts-node --project tsconfig.node.json $NODE_DEBUG_OPTION --files test/benchmark/kademlia-simulation/KademliaSimulation.ts"
|
|
26
|
+
"benchmark": "jest test/benchmark"
|
|
29
27
|
},
|
|
30
28
|
"dependencies": {
|
|
31
29
|
"@js-sdsl/ordered-map": "^4.4.2",
|
|
32
30
|
"@protobuf-ts/runtime": "^2.8.2",
|
|
33
31
|
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
34
|
-
"@streamr/autocertifier-client": "100.1.
|
|
35
|
-
"@streamr/cdn-location": "100.1.
|
|
36
|
-
"@streamr/proto-rpc": "100.1.
|
|
37
|
-
"@streamr/utils": "100.1.
|
|
32
|
+
"@streamr/autocertifier-client": "100.1.2",
|
|
33
|
+
"@streamr/cdn-location": "100.1.2",
|
|
34
|
+
"@streamr/proto-rpc": "100.1.2",
|
|
35
|
+
"@streamr/utils": "100.1.2",
|
|
38
36
|
"eventemitter3": "^5.0.0",
|
|
39
37
|
"heap": "^0.2.6",
|
|
40
38
|
"ipaddr.js": "^2.0.1",
|
|
@@ -49,7 +47,7 @@
|
|
|
49
47
|
},
|
|
50
48
|
"devDependencies": {
|
|
51
49
|
"@streamr/browser-test-runner": "^0.0.1",
|
|
52
|
-
"@streamr/test-utils": "100.1.
|
|
50
|
+
"@streamr/test-utils": "100.1.2",
|
|
53
51
|
"@types/express": "^4.17.21",
|
|
54
52
|
"@types/heap": "^0.2.34",
|
|
55
53
|
"@types/k-bucket": "^5.0.1",
|
|
@@ -57,7 +55,7 @@
|
|
|
57
55
|
"@types/uuid": "^9.0.8",
|
|
58
56
|
"@types/websocket": "^1.0.10",
|
|
59
57
|
"@types/ws": "^8.5.10",
|
|
60
|
-
"express": "^4.
|
|
58
|
+
"express": "^4.19.2",
|
|
61
59
|
"jest-leak-detector": "^27.3.1",
|
|
62
60
|
"patch-package": "^8.0.0",
|
|
63
61
|
"ts-essentials": "^9.4.1",
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ContactList = exports.ContactState = void 0;
|
|
7
7
|
const eventemitter3_1 = __importDefault(require("eventemitter3"));
|
|
8
8
|
class ContactState {
|
|
9
|
-
contacted = false;
|
|
10
9
|
active = false;
|
|
11
10
|
contact;
|
|
12
11
|
constructor(contact) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/ContactList.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;AAGxC,MAAa,YAAY;
|
|
1
|
+
{"version":3,"file":"ContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/ContactList.ts"],"names":[],"mappings":";;;;;;AAAA,kEAAwC;AAGxC,MAAa,YAAY;IAEd,MAAM,GAAG,KAAK,CAAA;IACd,OAAO,CAAG;IAEjB,YAAY,OAAU;QAClB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IAC1B,CAAC;CACJ;AARD,oCAQC;AAOD,MAAa,WAAuD,SAAQ,uBAAuB;IAErF,YAAY,GAAqC,IAAI,GAAG,EAAE,CAAA;IACpE,sCAAsC;IAC5B,UAAU,GAAiB,EAAE,CAAA;IAC7B,WAAW,CAAY;IACvB,OAAO,CAAQ;IACf,wBAAwB,CAAA;IAElC,YACI,WAAuB,EACvB,OAAe,EACf,wBAAwB,GAAG,EAAE;QAE7B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,WAAW,GAAG,WAAW,CAAA;QAC9B,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;QACtB,IAAI,CAAC,wBAAwB,GAAG,wBAAwB,CAAA;IAC5D,CAAC;IAEM,UAAU,CAAC,EAAc;QAC5B,OAAO,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IACpC,CAAC;IAEM,OAAO;QACV,OAAO,IAAI,CAAC,UAAU,CAAC,MAAM,CAAA;IACjC,CAAC;IAEM,KAAK;QACR,IAAI,CAAC,YAAY,CAAC,KAAK,EAAE,CAAA;QACzB,IAAI,CAAC,UAAU,GAAG,EAAE,CAAA;IACxB,CAAC;IAEM,IAAI;QACP,IAAI,CAAC,kBAAkB,EAAE,CAAA;QACzB,IAAI,CAAC,KAAK,EAAE,CAAA;IAChB,CAAC;CACJ;AArCD,kCAqCC"}
|
|
@@ -22,10 +22,8 @@ export declare class SortedContactList<C extends {
|
|
|
22
22
|
addContacts(contacts: C[]): void;
|
|
23
23
|
getContact(id: DhtAddress): ContactState<C> | undefined;
|
|
24
24
|
has(id: DhtAddress): boolean;
|
|
25
|
-
setContacted(contactId: DhtAddress): void;
|
|
26
25
|
setActive(contactId: DhtAddress): void;
|
|
27
26
|
getClosestContacts(limit?: number): C[];
|
|
28
|
-
getUncontactedContacts(num: number): C[];
|
|
29
27
|
getActiveContacts(limit?: number): C[];
|
|
30
28
|
compareIds(id1: DhtAddress, id2: DhtAddress): number;
|
|
31
29
|
private distanceToReferenceId;
|
|
@@ -66,11 +66,6 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
66
66
|
has(id) {
|
|
67
67
|
return this.contactsById.has(id);
|
|
68
68
|
}
|
|
69
|
-
setContacted(contactId) {
|
|
70
|
-
if (this.contactsById.has(contactId)) {
|
|
71
|
-
this.contactsById.get(contactId).contacted = true;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
69
|
setActive(contactId) {
|
|
75
70
|
if (this.contactsById.has(contactId)) {
|
|
76
71
|
this.contactsById.get(contactId).active = true;
|
|
@@ -82,19 +77,6 @@ class SortedContactList extends eventemitter3_1.default {
|
|
|
82
77
|
? ret
|
|
83
78
|
: ret.slice(0, limit);
|
|
84
79
|
}
|
|
85
|
-
getUncontactedContacts(num) {
|
|
86
|
-
const ret = [];
|
|
87
|
-
for (const contactId of this.contactIds) {
|
|
88
|
-
const contact = this.contactsById.get(contactId);
|
|
89
|
-
if (!contact.contacted) {
|
|
90
|
-
ret.push(contact.contact);
|
|
91
|
-
if (ret.length >= num) {
|
|
92
|
-
return ret;
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return ret;
|
|
97
|
-
}
|
|
98
80
|
getActiveContacts(limit) {
|
|
99
81
|
const ret = [];
|
|
100
82
|
this.contactIds.forEach((contactId) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SortedContactList.js","sourceRoot":"","sources":["../../../../src/dht/contact/SortedContactList.ts"],"names":[],"mappings":";;;;;;AAAA,+CAAoD;AACpD,mCAAsC;AACtC,kEAAwC;AACxC,gDAA4C;AAC5C,mDAAoE;AAepE,MAAa,iBAA6D,SAAQ,uBAAuB;IAE7F,MAAM,CAAyB;IAC/B,YAAY,GAAqC,IAAI,GAAG,EAAE,CAAA;IAC1D,UAAU,GAAiB,EAAE,CAAA;IAErC,YACI,MAA+B;QAE/B,KAAK,EAAE,CAAA;QACP,IAAI,CAAC,MAAM,GAAG,MAAM,CAAA;QACpB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;IAChD,CAAC;IAEM,mBAAmB;QACtB,OAAO,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAA;IAC7B,CAAC;IAEM,aAAa;QAChB,OAAO,IAAI,CAAC,UAAU,CAAA;IAC1B,CAAC;IAEM,UAAU,CAAC,OAAU;QACxB,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,EAAE,CAAA;QACrC,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,KAAK,SAAS,IAAI,IAAI,CAAC,MAAM,CAAC,eAAe,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE,CAAC;YAC1F,OAAM;QACV,CAAC;QACD,IAAI,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,yBAAyB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,KAAK,SAAS,CAAC,CAAC;YACnF,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,KAAK,SAAS,IAAI,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,mBAAmB,EAAE,SAAS,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YACrH,OAAM;QACV,CAAC;QACD,IAAI,CAAC,IAAI,C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
"name": "@streamr/dht",
|
|
3
|
-
"version": "100.1.
|
|
3
|
+
"version": "100.1.2",
|
|
4
4
|
"description": "Streamr Network DHT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,18 +23,16 @@
|
|
|
23
23
|
"test-unit": "jest test/unit",
|
|
24
24
|
"test-integration": "jest --bail test/integration",
|
|
25
25
|
"test-end-to-end": "jest --bail test/end-to-end",
|
|
26
|
-
"benchmark": "jest test/benchmark"
|
|
27
|
-
"prepare-kademlia-simulation": "cd test/data && node --max-old-space-size=8096 -- ../../../../node_modules/.bin/ts-node -P ../../tsconfig.node.json generateGroundTruthData.ts",
|
|
28
|
-
"run-kademlia-simulation": "ts-node --project tsconfig.node.json $NODE_DEBUG_OPTION --files test/benchmark/kademlia-simulation/KademliaSimulation.ts"
|
|
26
|
+
"benchmark": "jest test/benchmark"
|
|
29
27
|
},
|
|
30
28
|
"dependencies": {
|
|
31
29
|
"@js-sdsl/ordered-map": "^4.4.2",
|
|
32
30
|
"@protobuf-ts/runtime": "^2.8.2",
|
|
33
31
|
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
34
|
-
"@streamr/autocertifier-client": "100.1.
|
|
35
|
-
"@streamr/cdn-location": "100.1.
|
|
36
|
-
"@streamr/proto-rpc": "100.1.
|
|
37
|
-
"@streamr/utils": "100.1.
|
|
32
|
+
"@streamr/autocertifier-client": "100.1.2",
|
|
33
|
+
"@streamr/cdn-location": "100.1.2",
|
|
34
|
+
"@streamr/proto-rpc": "100.1.2",
|
|
35
|
+
"@streamr/utils": "100.1.2",
|
|
38
36
|
"eventemitter3": "^5.0.0",
|
|
39
37
|
"heap": "^0.2.6",
|
|
40
38
|
"ipaddr.js": "^2.0.1",
|
|
@@ -49,7 +47,7 @@
|
|
|
49
47
|
},
|
|
50
48
|
"devDependencies": {
|
|
51
49
|
"@streamr/browser-test-runner": "^0.0.1",
|
|
52
|
-
"@streamr/test-utils": "100.1.
|
|
50
|
+
"@streamr/test-utils": "100.1.2",
|
|
53
51
|
"@types/express": "^4.17.21",
|
|
54
52
|
"@types/heap": "^0.2.34",
|
|
55
53
|
"@types/k-bucket": "^5.0.1",
|
|
@@ -57,7 +55,7 @@
|
|
|
57
55
|
"@types/uuid": "^9.0.8",
|
|
58
56
|
"@types/websocket": "^1.0.10",
|
|
59
57
|
"@types/ws": "^8.5.10",
|
|
60
|
-
"express": "^4.
|
|
58
|
+
"express": "^4.19.2",
|
|
61
59
|
"jest-leak-detector": "^27.3.1",
|
|
62
60
|
"patch-package": "^8.0.0",
|
|
63
61
|
"ts-essentials": "^9.4.1",
|
|
@@ -96,12 +96,6 @@ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
96
96
|
return this.contactsById.has(id)
|
|
97
97
|
}
|
|
98
98
|
|
|
99
|
-
public setContacted(contactId: DhtAddress): void {
|
|
100
|
-
if (this.contactsById.has(contactId)) {
|
|
101
|
-
this.contactsById.get(contactId)!.contacted = true
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
99
|
public setActive(contactId: DhtAddress): void {
|
|
106
100
|
if (this.contactsById.has(contactId)) {
|
|
107
101
|
this.contactsById.get(contactId)!.active = true
|
|
@@ -115,20 +109,6 @@ export class SortedContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
115
109
|
: ret.slice(0, limit)
|
|
116
110
|
}
|
|
117
111
|
|
|
118
|
-
public getUncontactedContacts(num: number): C[] {
|
|
119
|
-
const ret: C[] = []
|
|
120
|
-
for (const contactId of this.contactIds) {
|
|
121
|
-
const contact = this.contactsById.get(contactId)!
|
|
122
|
-
if (!contact.contacted) {
|
|
123
|
-
ret.push(contact.contact)
|
|
124
|
-
if (ret.length >= num) {
|
|
125
|
-
return ret
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
return ret
|
|
130
|
-
}
|
|
131
|
-
|
|
132
112
|
public getActiveContacts(limit?: number): C[] {
|
|
133
113
|
const ret: C[] = []
|
|
134
114
|
this.contactIds.forEach((contactId) => {
|
|
@@ -27,30 +27,6 @@ describe('SortedContactList', () => {
|
|
|
27
27
|
expect(list.compareIds(item1.getNodeId(), item4.getNodeId())).toBe(-3)
|
|
28
28
|
})
|
|
29
29
|
|
|
30
|
-
it('orders itself correctly', async () => {
|
|
31
|
-
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: true, emitEvents: false })
|
|
32
|
-
list.addContact(item3)
|
|
33
|
-
list.addContact(item2)
|
|
34
|
-
list.addContact(item1)
|
|
35
|
-
const contacts = list.getUncontactedContacts(3)
|
|
36
|
-
expect(contacts.length).toEqual(3)
|
|
37
|
-
expect(contacts[0]).toEqual(item1)
|
|
38
|
-
expect(contacts[1]).toEqual(item2)
|
|
39
|
-
expect(contacts[2]).toEqual(item3)
|
|
40
|
-
})
|
|
41
|
-
|
|
42
|
-
it('handles contacted nodes correctly', async () => {
|
|
43
|
-
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 10, allowToContainReferenceId: false, emitEvents: false })
|
|
44
|
-
list.addContact(item3)
|
|
45
|
-
list.addContact(item2)
|
|
46
|
-
list.addContact(item1)
|
|
47
|
-
list.setContacted(item2.getNodeId())
|
|
48
|
-
const contacts = list.getUncontactedContacts(3)
|
|
49
|
-
expect(contacts.length).toEqual(2)
|
|
50
|
-
expect(contacts[0]).toEqual(item1)
|
|
51
|
-
expect(contacts[1]).toEqual(item3)
|
|
52
|
-
})
|
|
53
|
-
|
|
54
30
|
it('cannot exceed maxSize', async () => {
|
|
55
31
|
const list = new SortedContactList({ referenceId: item0.getNodeId(), maxSize: 3, allowToContainReferenceId: false, emitEvents: true })
|
|
56
32
|
const onContactRemoved = jest.fn()
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
import type { SimulationNode } from './SimulationNode'
|
|
2
|
-
import { NodeType, PeerDescriptor } from '../../../src/proto/packages/dht/protos/DhtRpc'
|
|
3
|
-
import { DhtAddress, DhtAddressRaw, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
4
|
-
|
|
5
|
-
export class Contact {
|
|
6
|
-
private static counter = 0
|
|
7
|
-
|
|
8
|
-
public ownId: DhtAddress
|
|
9
|
-
public id: DhtAddressRaw
|
|
10
|
-
public vectorClock = 0
|
|
11
|
-
public dhtNode: SimulationNode | undefined
|
|
12
|
-
|
|
13
|
-
constructor(ownId: DhtAddress, dhtNode?: SimulationNode) {
|
|
14
|
-
this.ownId = ownId
|
|
15
|
-
this.vectorClock = Contact.counter++
|
|
16
|
-
this.dhtNode = dhtNode
|
|
17
|
-
this.id = getRawFromDhtAddress(ownId)
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
getPeerDescriptor(): PeerDescriptor {
|
|
21
|
-
const peerDescriptor: PeerDescriptor = {
|
|
22
|
-
nodeId: getRawFromDhtAddress(this.ownId),
|
|
23
|
-
type: NodeType.NODEJS
|
|
24
|
-
}
|
|
25
|
-
return peerDescriptor
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
getNodeId(): DhtAddress {
|
|
29
|
-
return this.ownId
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
|
|
3
|
-
import { SimulationNode } from './SimulationNode'
|
|
4
|
-
import fs from 'fs'
|
|
5
|
-
import { getDhtAddressFromRaw } from '../../../src/identifiers'
|
|
6
|
-
|
|
7
|
-
export class KademliaSimulation {
|
|
8
|
-
|
|
9
|
-
private static readonly NUM_NODES = 1000
|
|
10
|
-
private static readonly ID_LENGTH = 8
|
|
11
|
-
|
|
12
|
-
private readonly nodeNamesById: Record<string, number> = {}
|
|
13
|
-
private readonly nodes: SimulationNode[] = []
|
|
14
|
-
|
|
15
|
-
private readonly dhtIds: Array<{ type: string, data: Array<number> }>
|
|
16
|
-
private readonly groundTruth: Record<string, Array<{ name: string, distance: number, id: { type: string, data: Array<number> } }>>
|
|
17
|
-
|
|
18
|
-
constructor() {
|
|
19
|
-
if (!fs.existsSync('test/data/nodeids.json')) {
|
|
20
|
-
throw new Error('Cannot find test/data/nodeids.json, please run "npm run prepare-kademlia-simulation first"')
|
|
21
|
-
}
|
|
22
|
-
this.dhtIds = JSON.parse(fs.readFileSync('test/data/nodeids.json').toString())
|
|
23
|
-
this.groundTruth = JSON.parse(fs.readFileSync('test/data/orderedneighbors.json').toString())
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
public run(): void {
|
|
27
|
-
for (let i = 0; i < KademliaSimulation.NUM_NODES; i++) {
|
|
28
|
-
const node = new SimulationNode(getDhtAddressFromRaw(Buffer.from(this.dhtIds[i].data.slice(0, KademliaSimulation.ID_LENGTH))))
|
|
29
|
-
this.nodeNamesById[JSON.stringify(node.getContact().id)] = i
|
|
30
|
-
this.nodes.push(node)
|
|
31
|
-
node.joinDht(this.nodes[0])
|
|
32
|
-
|
|
33
|
-
process.stdout.write('.')
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
let minimumCorrectNeighbors = Number.MAX_SAFE_INTEGER
|
|
37
|
-
|
|
38
|
-
let sumCorrectNeighbors = 0
|
|
39
|
-
let sumKbucketSize = 1
|
|
40
|
-
let sumOutgoingRpcCalls = 0
|
|
41
|
-
let maxOutgoingRpcCalls = 0
|
|
42
|
-
|
|
43
|
-
for (let i = this.nodes.length - 1; i >= 0; i--) {
|
|
44
|
-
|
|
45
|
-
const outgoingRpcCallCount = this.nodes[i].getOutgoingRpcCallCount()
|
|
46
|
-
console.log('-----------')
|
|
47
|
-
console.log('Node: ' + i)
|
|
48
|
-
console.log('Kbucket size: ' + this.nodes[i].getKBucketSize())
|
|
49
|
-
console.log('Num incoming RPC calls: ' + this.nodes[i].getIncomingRpcCallCount())
|
|
50
|
-
console.log('Num outgoing RPC calls: ' + outgoingRpcCallCount)
|
|
51
|
-
|
|
52
|
-
sumOutgoingRpcCalls += outgoingRpcCallCount
|
|
53
|
-
|
|
54
|
-
if (maxOutgoingRpcCalls < outgoingRpcCallCount) {
|
|
55
|
-
maxOutgoingRpcCalls = outgoingRpcCallCount
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const kademliaNeighbors = this.nodes[i].getNeightborList().getContactIds()
|
|
59
|
-
|
|
60
|
-
let correctNeighbors = 0
|
|
61
|
-
for (let j = 0; j < this.groundTruth[i + ''].length; j++) {
|
|
62
|
-
if (this.groundTruth[i + ''][j].name != (this.nodeNamesById[JSON.stringify(kademliaNeighbors[j])] + '')) {
|
|
63
|
-
break
|
|
64
|
-
}
|
|
65
|
-
correctNeighbors++
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
if (correctNeighbors < minimumCorrectNeighbors) {
|
|
69
|
-
minimumCorrectNeighbors = correctNeighbors
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
console.log('Correct neighbors: ' + correctNeighbors)
|
|
73
|
-
|
|
74
|
-
if (i > 0) {
|
|
75
|
-
sumKbucketSize += this.nodes[i].getKBucketSize()
|
|
76
|
-
sumCorrectNeighbors += correctNeighbors
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const avgCorrectNeighbors = sumCorrectNeighbors / (KademliaSimulation.NUM_NODES - 1)
|
|
81
|
-
const avgKbucketSize = sumKbucketSize / (KademliaSimulation.NUM_NODES - 1)
|
|
82
|
-
const avgOutgoingRpcCallCount = sumOutgoingRpcCalls / (KademliaSimulation.NUM_NODES - 1)
|
|
83
|
-
|
|
84
|
-
console.log('----------- Simulation results ------------------')
|
|
85
|
-
console.log('Minimum correct neighbors: ' + minimumCorrectNeighbors)
|
|
86
|
-
console.log('Average correct neighbors: ' + avgCorrectNeighbors)
|
|
87
|
-
console.log('Average Kbucket size: ' + avgKbucketSize)
|
|
88
|
-
console.log('Average number of outgoing RPC calls: ' + avgOutgoingRpcCallCount)
|
|
89
|
-
console.log('MAX number of outgoing RPC calls: ' + maxOutgoingRpcCalls)
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
const simulation = new KademliaSimulation()
|
|
94
|
-
simulation.run()
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import KBucket from 'k-bucket'
|
|
2
|
-
import { Contact } from './Contact'
|
|
3
|
-
import { SortedContactList } from '../../../src/dht/contact/SortedContactList'
|
|
4
|
-
import { DhtAddress, getRawFromDhtAddress } from '../../../src/identifiers'
|
|
5
|
-
|
|
6
|
-
export class SimulationNode {
|
|
7
|
-
|
|
8
|
-
private numberOfNodesPerKBucket = 1
|
|
9
|
-
private K = 8
|
|
10
|
-
private ALPHA = 1
|
|
11
|
-
|
|
12
|
-
private bucket: KBucket<Contact>
|
|
13
|
-
private ownContact: Contact
|
|
14
|
-
|
|
15
|
-
private incomingRpcCallCount = 0
|
|
16
|
-
private outgoingRpcCallCount = 0
|
|
17
|
-
|
|
18
|
-
private neighborList: SortedContactList<Contact>
|
|
19
|
-
private ownId: DhtAddress
|
|
20
|
-
|
|
21
|
-
constructor(ownId: DhtAddress) {
|
|
22
|
-
this.ownId = ownId
|
|
23
|
-
this.ownContact = new Contact(this.ownId, this)
|
|
24
|
-
this.bucket = new KBucket({
|
|
25
|
-
localNodeId: getRawFromDhtAddress(this.ownId),
|
|
26
|
-
numberOfNodesPerKBucket: this.numberOfNodesPerKBucket
|
|
27
|
-
})
|
|
28
|
-
|
|
29
|
-
this.neighborList = new SortedContactList({
|
|
30
|
-
referenceId: this.ownId,
|
|
31
|
-
maxSize: 1000,
|
|
32
|
-
allowToContainReferenceId: false,
|
|
33
|
-
emitEvents: false
|
|
34
|
-
})
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
// For simulation use
|
|
38
|
-
|
|
39
|
-
public getNeightborList(): SortedContactList<Contact> {
|
|
40
|
-
return this.neighborList
|
|
41
|
-
}
|
|
42
|
-
public getContact(): Contact {
|
|
43
|
-
return this.ownContact
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
public getKBucketSize(): number {
|
|
47
|
-
return this.bucket.count()
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
public getIncomingRpcCallCount(): number {
|
|
51
|
-
return this.incomingRpcCallCount
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
public getOutgoingRpcCallCount(): number {
|
|
55
|
-
return this.outgoingRpcCallCount
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// RPC call
|
|
59
|
-
|
|
60
|
-
public getClosestNodesTo(id: DhtAddress, caller: SimulationNode): Contact[] {
|
|
61
|
-
this.incomingRpcCallCount++
|
|
62
|
-
const idValue = getRawFromDhtAddress(id)
|
|
63
|
-
const ret = this.bucket.closest(idValue)
|
|
64
|
-
if (!this.bucket.get(idValue)) {
|
|
65
|
-
const contact = new Contact(id, caller)
|
|
66
|
-
this.bucket.add(contact)
|
|
67
|
-
this.neighborList.addContact(contact)
|
|
68
|
-
}
|
|
69
|
-
return ret
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private findMoreContacts(contactList: Contact[], shortlist: SortedContactList<Contact>) {
|
|
73
|
-
contactList.forEach((contact) => {
|
|
74
|
-
shortlist.setContacted(contact.getNodeId())
|
|
75
|
-
shortlist.setActive(contact.getNodeId())
|
|
76
|
-
this.outgoingRpcCallCount++
|
|
77
|
-
const returnedContacts = contact.dhtNode!.getClosestNodesTo(this.ownId, this)
|
|
78
|
-
shortlist.addContacts(returnedContacts)
|
|
79
|
-
returnedContacts.forEach((returnedContact: Contact) => {
|
|
80
|
-
if (!this.bucket.get(returnedContact.id)) {
|
|
81
|
-
this.bucket.add(returnedContact)
|
|
82
|
-
}
|
|
83
|
-
})
|
|
84
|
-
})
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
public joinDht(entryPoint: SimulationNode): void {
|
|
88
|
-
if (entryPoint.getContact().getNodeId() === this.ownId) {
|
|
89
|
-
return
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
this.bucket.add(entryPoint.getContact())
|
|
93
|
-
const closest = this.bucket.closest(getRawFromDhtAddress(this.ownId), this.ALPHA)
|
|
94
|
-
|
|
95
|
-
this.neighborList.addContacts(closest)
|
|
96
|
-
|
|
97
|
-
/* eslint-disable no-constant-condition */
|
|
98
|
-
while (true) {
|
|
99
|
-
let oldClosestContactId = this.neighborList.getClosestContactId()
|
|
100
|
-
let uncontacted = this.neighborList.getUncontactedContacts(this.ALPHA)
|
|
101
|
-
if (uncontacted.length === 0) {
|
|
102
|
-
return
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
this.findMoreContacts(uncontacted, this.neighborList)
|
|
106
|
-
|
|
107
|
-
if (oldClosestContactId === this.neighborList.getClosestContactId()) {
|
|
108
|
-
uncontacted = this.neighborList.getUncontactedContacts(this.K)
|
|
109
|
-
if (uncontacted.length === 0) {
|
|
110
|
-
return
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
while (true) {
|
|
114
|
-
oldClosestContactId = this.neighborList.getClosestContactId()
|
|
115
|
-
this.findMoreContacts(uncontacted, this.neighborList)
|
|
116
|
-
|
|
117
|
-
if (this.neighborList.getActiveContacts().length >= this.K ||
|
|
118
|
-
(oldClosestContactId === this.neighborList.getClosestContactId())) {
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
uncontacted = this.neighborList.getUncontactedContacts(this.ALPHA)
|
|
122
|
-
if (uncontacted.length === 0) {
|
|
123
|
-
return
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import fs from 'fs'
|
|
2
|
-
import crypto from 'crypto'
|
|
3
|
-
import KBucket from 'k-bucket'
|
|
4
|
-
import { DhtAddressRaw } from '../../src/identifiers'
|
|
5
|
-
|
|
6
|
-
const ID_LENGTH = 20
|
|
7
|
-
const NUM_NODES = 900
|
|
8
|
-
const NUM_NEAREST = 10
|
|
9
|
-
|
|
10
|
-
const generateId = function(): DhtAddressRaw {
|
|
11
|
-
return crypto.randomBytes(ID_LENGTH)
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const findNNearestNeighbors = function(ownIndex: number, ownId: DhtAddressRaw, nodes: Array<DhtAddressRaw>, n: number): Array<number> {
|
|
15
|
-
const retIndex: Array<number> = []
|
|
16
|
-
|
|
17
|
-
for (let i = 0; i < n; i++) {
|
|
18
|
-
let closestIndex: number = Number.MAX_VALUE
|
|
19
|
-
let closestDistance: number = Number.MAX_VALUE
|
|
20
|
-
|
|
21
|
-
for (let j = 0; j < nodes.length; j++) {
|
|
22
|
-
if (j == ownIndex || retIndex.includes(j)) {
|
|
23
|
-
continue
|
|
24
|
-
}
|
|
25
|
-
const distance = KBucket.distance(ownId, nodes[j])
|
|
26
|
-
if (distance < closestDistance) {
|
|
27
|
-
closestDistance = distance
|
|
28
|
-
closestIndex = j
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
retIndex.push(closestIndex)
|
|
32
|
-
}
|
|
33
|
-
return retIndex
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const writer = fs.createWriteStream('nodeids.json', {})
|
|
37
|
-
const neighborWriter = fs.createWriteStream('orderedneighbors.json', {})
|
|
38
|
-
|
|
39
|
-
neighborWriter.write('{\n')
|
|
40
|
-
|
|
41
|
-
const nodes: Array<DhtAddressRaw> = []
|
|
42
|
-
|
|
43
|
-
// generate nodeIds
|
|
44
|
-
|
|
45
|
-
for (let i = 0; i < NUM_NODES; i++) {
|
|
46
|
-
const id = generateId()
|
|
47
|
-
nodes.push(id)
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
writer.write(JSON.stringify(nodes, null, 4))
|
|
51
|
-
writer.end()
|
|
52
|
-
|
|
53
|
-
for (let i = 0; i < NUM_NODES; i++) {
|
|
54
|
-
|
|
55
|
-
const neighborIds = findNNearestNeighbors(i, nodes[i], nodes, NUM_NEAREST)
|
|
56
|
-
|
|
57
|
-
const neighborNames: Array<{ name: number, distance: number, id: DhtAddressRaw }> = []
|
|
58
|
-
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
|
59
|
-
for (let j = 0; j < neighborIds.length; j++) {
|
|
60
|
-
neighborNames.push({ name: neighborIds[j], distance: KBucket.distance(nodes[i], nodes[neighborIds[j]]), id: nodes[neighborIds[j]] })
|
|
61
|
-
}
|
|
62
|
-
neighborWriter.write('"' + i + '": ' + JSON.stringify(neighborNames))
|
|
63
|
-
process.stdout.write('.')
|
|
64
|
-
|
|
65
|
-
if (i != NUM_NODES - 1) {
|
|
66
|
-
neighborWriter.write(',\n')
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
neighborWriter.write('}')
|
|
71
|
-
neighborWriter.end()
|