@streamr/dht 100.1.2 → 100.2.1
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 +6 -6
- package/dist/src/connection/ConnectionManager.js +4 -6
- package/dist/src/connection/ConnectionManager.js.map +1 -1
- package/dist/src/dht/DhtNode.d.ts +1 -0
- package/dist/src/dht/DhtNode.js +4 -5
- package/dist/src/dht/DhtNode.js.map +1 -1
- package/dist/src/dht/PeerManager.d.ts +4 -3
- package/dist/src/dht/PeerManager.js +60 -60
- package/dist/src/dht/PeerManager.js.map +1 -1
- package/dist/src/dht/contact/ContactList.d.ts +2 -7
- package/dist/src/dht/contact/ContactList.js +1 -9
- package/dist/src/dht/contact/ContactList.js.map +1 -1
- package/dist/src/dht/contact/RandomContactList.js +3 -10
- package/dist/src/dht/contact/RandomContactList.js.map +1 -1
- package/dist/src/dht/contact/RingContactList.d.ts +2 -2
- package/dist/src/dht/contact/RingContactList.js +6 -5
- package/dist/src/dht/contact/RingContactList.js.map +1 -1
- package/dist/src/dht/contact/SortedContactList.d.ts +5 -7
- package/dist/src/dht/contact/SortedContactList.js +24 -35
- package/dist/src/dht/contact/SortedContactList.js.map +1 -1
- package/dist/src/dht/discovery/PeerDiscovery.d.ts +2 -7
- package/dist/src/dht/discovery/PeerDiscovery.js +2 -2
- package/dist/src/dht/discovery/PeerDiscovery.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js +1 -2
- package/dist/src/dht/recursive-operation/RecursiveOperationManager.js.map +1 -1
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js +2 -3
- package/dist/src/dht/recursive-operation/RecursiveOperationSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingSession.js +2 -3
- package/dist/src/dht/routing/RoutingSession.js.map +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.d.ts +1 -1
- package/dist/src/dht/routing/RoutingTablesCache.js.map +1 -1
- package/dist/src/dht/store/StoreManager.js +6 -7
- package/dist/src/dht/store/StoreManager.js.map +1 -1
- package/package.json +6 -6
- package/src/connection/ConnectionManager.ts +4 -6
- package/src/connection/webrtc/BrowserWebrtcConnection.ts +21 -28
- package/src/dht/DhtNode.ts +6 -6
- package/src/dht/PeerManager.ts +60 -60
- package/src/dht/contact/ContactList.ts +2 -12
- package/src/dht/contact/RandomContactList.ts +4 -11
- package/src/dht/contact/RingContactList.ts +7 -5
- package/src/dht/contact/SortedContactList.ts +28 -41
- package/src/dht/discovery/PeerDiscovery.ts +7 -3
- package/src/dht/recursive-operation/RecursiveOperationManager.ts +1 -2
- package/src/dht/recursive-operation/RecursiveOperationSession.ts +2 -3
- package/src/dht/routing/RoutingSession.ts +2 -3
- package/src/dht/routing/RoutingTablesCache.ts +3 -1
- package/src/dht/store/StoreManager.ts +7 -8
- package/test/benchmark/SortedContactListBenchmark.test.ts +9 -52
- package/test/benchmark/hybrid-network-simulation/RingContactList.test.ts +1 -2
- package/test/integration/ReplicateData.test.ts +2 -3
- package/test/unit/PeerManager.test.ts +56 -7
- package/test/unit/SortedContactList.test.ts +21 -16
- package/test/utils/utils.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoreManager.js","sourceRoot":"","sources":["../../../../src/dht/store/StoreManager.ts"],"names":[],"mappings":";;;AAAA,mEAG+C;AAK/C,0CAA2D;AAG3D,qEAAiE;AACjE,oEAAgE;AAChE,gDAA4C;AAE5C,mDAAgJ;AAChJ,mDAA+C;AAC/C,gDAA4C;AAc5C,MAAM,MAAM,GAAG,IAAI,cAAM,CAAC,MAAM,CAAC,CAAA;AAEjC,MAAa,YAAY;IAEJ,MAAM,CAAoB;IAE3C,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,IAA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AAA;QAC9E,MAAM,WAAW,GAAG,mBAAmB;YACnC,sFAAsF;YACtF,CAAC,CAAC,SAAS;YACX,4FAA4F;YAC5F,CAAC,CAAC,CAAC,CAAA;QACP,MAAM,OAAO,GAAG,UAAU,CAAC,kBAAkB,CAAC,WAAW,CAAC,CAAA;QAC1D,OAAO,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;YACxB,MAAM,aAAa,GAAG,OAAO,CAAC,SAAS,EAAE,CAAA;YACzC,IAAI,CAAC,cAAc,KAAK,aAAa,CAAC,IAAI,CAAC,WAAW,KAAK,aAAa,CAAC,EAAE,CAAC;gBACxE,YAAY,CAAC,GAAG,EAAE;oBACd,IAAA,0BAAkB,EAAC,KAAK,IAAI,EAAE;wBAC1B,MAAM,IAAI,CAAC,sBAAsB,CAAC,SAAS,EAAE,OAAO,CAAC,iBAAiB,EAAE,CAAC,CAAA;wBACzE,MAAM,CAAC,KAAK,CAAC,mCAAmC,EAAE;4BAC9C,IAAI,EAAE,aAAa;4BACnB,sBAAsB,EAAE,CAAC,mBAAmB;yBAC/C,CAAC,CAAA;oBACN,CAAC,CAAC,CAAA;gBACN,CAAC,CAAC,CAAA;YACN,CAAC;QACL,CAAC,CAAC,CAAA;IACN,CAAC;IAED,KAAK,CAAC,OAAO;QACT,MAAM,IAAI,CAAC,2BAA2B,EAAE,CAAA;IAC5C,CAAC;CACJ;AA9KD,oCA8KC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@streamr/dht",
|
|
3
|
-
"version": "100.1
|
|
3
|
+
"version": "100.2.1",
|
|
4
4
|
"description": "Streamr Network DHT",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"@js-sdsl/ordered-map": "^4.4.2",
|
|
30
30
|
"@protobuf-ts/runtime": "^2.8.2",
|
|
31
31
|
"@protobuf-ts/runtime-rpc": "^2.8.2",
|
|
32
|
-
"@streamr/autocertifier-client": "100.1
|
|
33
|
-
"@streamr/cdn-location": "100.1
|
|
34
|
-
"@streamr/proto-rpc": "100.1
|
|
35
|
-
"@streamr/utils": "100.1
|
|
32
|
+
"@streamr/autocertifier-client": "100.2.1",
|
|
33
|
+
"@streamr/cdn-location": "100.2.1",
|
|
34
|
+
"@streamr/proto-rpc": "100.2.1",
|
|
35
|
+
"@streamr/utils": "100.2.1",
|
|
36
36
|
"eventemitter3": "^5.0.0",
|
|
37
37
|
"heap": "^0.2.6",
|
|
38
38
|
"ipaddr.js": "^2.0.1",
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@streamr/browser-test-runner": "^0.0.1",
|
|
50
|
-
"@streamr/test-utils": "100.1
|
|
50
|
+
"@streamr/test-utils": "100.2.1",
|
|
51
51
|
"@types/express": "^4.17.21",
|
|
52
52
|
"@types/heap": "^0.2.34",
|
|
53
53
|
"@types/k-bucket": "^5.0.1",
|
|
@@ -156,8 +156,7 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
156
156
|
const disconnectionCandidates = new SortedContactList<ManagedConnection>({
|
|
157
157
|
referenceId: getNodeIdFromPeerDescriptor(this.getLocalPeerDescriptor()),
|
|
158
158
|
maxSize: 100000, // TODO use config option or named constant?
|
|
159
|
-
allowToContainReferenceId: false
|
|
160
|
-
emitEvents: false
|
|
159
|
+
allowToContainReferenceId: false
|
|
161
160
|
})
|
|
162
161
|
this.connections.forEach((connection, key) => {
|
|
163
162
|
// TODO: Investigate why multiple invalid WS client connections to the same
|
|
@@ -172,10 +171,9 @@ export class ConnectionManager extends EventEmitter<TransportEvents> implements
|
|
|
172
171
|
disconnectionCandidates.addContact(connection)
|
|
173
172
|
}
|
|
174
173
|
})
|
|
175
|
-
const
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
const peerDescriptor = sortedCandidates[sortedCandidates.length - 1 - i].getPeerDescriptor()!
|
|
174
|
+
const disconnectables = disconnectionCandidates.getFurthestContacts(this.connections.size - maxConnections)
|
|
175
|
+
for (const disconnectable of disconnectables) {
|
|
176
|
+
const peerDescriptor = disconnectable.getPeerDescriptor()!
|
|
179
177
|
logger.trace('garbageCollecting ' + getNodeIdFromPeerDescriptor(peerDescriptor))
|
|
180
178
|
this.gracefullyDisconnectAsync(peerDescriptor, DisconnectMode.NORMAL).catch((_e) => { })
|
|
181
179
|
}
|
|
@@ -68,23 +68,18 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
68
68
|
|
|
69
69
|
if (isOffering) {
|
|
70
70
|
this.peerConnection.onnegotiationneeded = async () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
this.emit('localDescription', this.peerConnection.localDescription?.sdp, this.peerConnection.localDescription?.type)
|
|
81
|
-
}
|
|
71
|
+
if (this.peerConnection !== undefined) {
|
|
72
|
+
this.makingOffer = true
|
|
73
|
+
try {
|
|
74
|
+
await this.peerConnection.setLocalDescription()
|
|
75
|
+
} catch (err) {
|
|
76
|
+
logger.warn('Failed to set local description', { err })
|
|
77
|
+
}
|
|
78
|
+
if (this.peerConnection.localDescription !== null) {
|
|
79
|
+
this.emit('localDescription', this.peerConnection.localDescription?.sdp, this.peerConnection.localDescription?.type)
|
|
82
80
|
}
|
|
83
|
-
} catch (err) {
|
|
84
|
-
logger.error('error', { err })
|
|
85
|
-
} finally {
|
|
86
|
-
this.makingOffer = false
|
|
87
81
|
}
|
|
82
|
+
this.makingOffer = false
|
|
88
83
|
}
|
|
89
84
|
|
|
90
85
|
const dataChannel = this.peerConnection.createDataChannel('streamrDataChannel')
|
|
@@ -107,14 +102,14 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
107
102
|
try {
|
|
108
103
|
await this.peerConnection?.setRemoteDescription({ sdp: description, type: type.toLowerCase() as RTCSdpType })
|
|
109
104
|
} catch (err) {
|
|
110
|
-
logger.warn('
|
|
105
|
+
logger.warn('Failed to set remote description', { err })
|
|
111
106
|
}
|
|
112
107
|
|
|
113
108
|
if ((type.toLowerCase() === RtcDescription.OFFER) && (this.peerConnection !== undefined)) {
|
|
114
109
|
try {
|
|
115
110
|
await this.peerConnection.setLocalDescription()
|
|
116
111
|
} catch (err) {
|
|
117
|
-
logger.warn('
|
|
112
|
+
logger.warn('Failed to set local description', { err })
|
|
118
113
|
}
|
|
119
114
|
if (this.peerConnection.localDescription !== null) {
|
|
120
115
|
this.emit('localDescription', this.peerConnection.localDescription.sdp, this.peerConnection.localDescription.type)
|
|
@@ -123,13 +118,11 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
123
118
|
}
|
|
124
119
|
|
|
125
120
|
public addRemoteCandidate(candidate: string, mid: string): void {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
121
|
+
this.peerConnection?.addIceCandidate({ candidate: candidate, sdpMid: mid })
|
|
122
|
+
.then(() => { return })
|
|
123
|
+
.catch((err) => {
|
|
124
|
+
logger.warn('Failed to add ICE candidate', { err })
|
|
129
125
|
})
|
|
130
|
-
} catch (err) {
|
|
131
|
-
logger.warn('error', { err })
|
|
132
|
-
}
|
|
133
126
|
}
|
|
134
127
|
|
|
135
128
|
public isOpen(): boolean {
|
|
@@ -155,8 +148,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
155
148
|
if (this.dataChannel !== undefined) {
|
|
156
149
|
try {
|
|
157
150
|
this.dataChannel.close()
|
|
158
|
-
} catch (
|
|
159
|
-
logger.warn(
|
|
151
|
+
} catch (err) {
|
|
152
|
+
logger.warn('Failed to close data channel', { err })
|
|
160
153
|
}
|
|
161
154
|
}
|
|
162
155
|
|
|
@@ -165,8 +158,8 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
165
158
|
if (this.peerConnection !== undefined) {
|
|
166
159
|
try {
|
|
167
160
|
this.peerConnection.close()
|
|
168
|
-
} catch (
|
|
169
|
-
logger.warn(
|
|
161
|
+
} catch (err) {
|
|
162
|
+
logger.warn('Failed to close connection', { err })
|
|
170
163
|
}
|
|
171
164
|
}
|
|
172
165
|
this.peerConnection = undefined
|
|
@@ -200,7 +193,7 @@ export class NodeWebrtcConnection extends EventEmitter<Events> implements IWebrt
|
|
|
200
193
|
}
|
|
201
194
|
|
|
202
195
|
dataChannel.onerror = (err) => {
|
|
203
|
-
logger.warn(
|
|
196
|
+
logger.warn('Data channel error', { err })
|
|
204
197
|
}
|
|
205
198
|
|
|
206
199
|
dataChannel.onmessage = (msg) => {
|
package/src/dht/DhtNode.ts
CHANGED
|
@@ -77,6 +77,7 @@ export interface DhtNodeOptions {
|
|
|
77
77
|
region?: number
|
|
78
78
|
|
|
79
79
|
transport?: ITransport
|
|
80
|
+
connectionLocker?: ConnectionLocker
|
|
80
81
|
peerDescriptor?: PeerDescriptor
|
|
81
82
|
entryPoints?: PeerDescriptor[]
|
|
82
83
|
websocketHost?: string
|
|
@@ -193,13 +194,10 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
193
194
|
this.region = await getLocalRegion()
|
|
194
195
|
}
|
|
195
196
|
|
|
196
|
-
// If transport is given, do not create a ConnectionManager
|
|
197
197
|
if (this.config.transport) {
|
|
198
198
|
this.transport = this.config.transport
|
|
199
|
+
this.connectionLocker = this.config.connectionLocker
|
|
199
200
|
this.localPeerDescriptor = this.transport.getLocalPeerDescriptor()
|
|
200
|
-
if (this.config.transport instanceof ConnectionManager) {
|
|
201
|
-
this.connectionLocker = this.config.transport
|
|
202
|
-
}
|
|
203
201
|
} else {
|
|
204
202
|
const connectorFacadeConfig: DefaultConnectorFacadeConfig = {
|
|
205
203
|
transport: this,
|
|
@@ -310,7 +308,7 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
310
308
|
maxContactListSize: this.config.maxNeighborListSize,
|
|
311
309
|
localNodeId: this.getNodeId(),
|
|
312
310
|
localPeerDescriptor: this.localPeerDescriptor!,
|
|
313
|
-
connectionLocker: this.connectionLocker
|
|
311
|
+
connectionLocker: this.connectionLocker,
|
|
314
312
|
peerDiscoveryQueryBatchSize: this.config.peerDiscoveryQueryBatchSize,
|
|
315
313
|
isLayer0: (this.connectionLocker !== undefined),
|
|
316
314
|
createDhtNodeRpcRemote: (peerDescriptor: PeerDescriptor) => this.createDhtNodeRpcRemote(peerDescriptor),
|
|
@@ -340,9 +338,11 @@ export class DhtNode extends EventEmitter<Events> implements ITransport {
|
|
|
340
338
|
&& this.config.entryPoints.length > 0
|
|
341
339
|
) {
|
|
342
340
|
setImmediate(async () => {
|
|
341
|
+
const contactedPeers = new Set<DhtAddress>()
|
|
342
|
+
const distantJoinContactPeers = new Set<DhtAddress>()
|
|
343
343
|
// TODO should we catch possible promise rejection?
|
|
344
344
|
await Promise.all(this.config.entryPoints!.map((entryPoint) =>
|
|
345
|
-
this.peerDiscovery!.rejoinDht(entryPoint)
|
|
345
|
+
this.peerDiscovery!.rejoinDht(entryPoint, contactedPeers, distantJoinContactPeers)
|
|
346
346
|
))
|
|
347
347
|
})
|
|
348
348
|
}
|
package/src/dht/PeerManager.ts
CHANGED
|
@@ -51,59 +51,58 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
51
51
|
// * 'connections' are the nodes that are connected to this node on Layer0
|
|
52
52
|
// * 'contacts' are all non-unresponsive nodes that we know about
|
|
53
53
|
|
|
54
|
-
|
|
55
|
-
private bucket: KBucket<DhtNodeRpcRemote>
|
|
54
|
+
private neighbors: KBucket<DhtNodeRpcRemote>
|
|
56
55
|
// Nodes that are connected to this node on Layer0
|
|
57
56
|
public readonly connections: Map<DhtAddress, DhtNodeRpcRemote> = new Map()
|
|
58
|
-
|
|
59
|
-
private
|
|
60
|
-
private randomPeers: RandomContactList<DhtNodeRpcRemote>
|
|
57
|
+
private closestContacts: SortedContactList<DhtNodeRpcRemote>
|
|
58
|
+
private activeContacts: Set<DhtAddress>
|
|
61
59
|
private ringContacts: RingContactList<DhtNodeRpcRemote>
|
|
60
|
+
private randomContacts: RandomContactList<DhtNodeRpcRemote>
|
|
62
61
|
private stopped: boolean = false
|
|
63
62
|
private readonly config: PeerManagerConfig
|
|
64
63
|
|
|
65
64
|
constructor(config: PeerManagerConfig) {
|
|
66
65
|
super()
|
|
67
66
|
this.config = config
|
|
68
|
-
this.
|
|
67
|
+
this.neighbors = new KBucket<DhtNodeRpcRemote>({
|
|
69
68
|
localNodeId: getRawFromDhtAddress(this.config.localNodeId),
|
|
70
69
|
numberOfNodesPerKBucket: this.config.numberOfNodesPerKBucket,
|
|
71
70
|
numberOfNodesToPing: this.config.numberOfNodesPerKBucket
|
|
72
71
|
})
|
|
73
|
-
this.ringContacts = new RingContactList<DhtNodeRpcRemote>(getRingIdRawFromPeerDescriptor(this.config.localPeerDescriptor)
|
|
72
|
+
this.ringContacts = new RingContactList<DhtNodeRpcRemote>(getRingIdRawFromPeerDescriptor(this.config.localPeerDescriptor))
|
|
74
73
|
this.ringContacts.on('ringContactAdded', (peerDescriptor: PeerDescriptor, closestPeers: RingContacts) => {
|
|
75
74
|
this.emit('ringContactAdded', peerDescriptor, closestPeers)
|
|
76
75
|
})
|
|
77
76
|
this.ringContacts.on('ringContactRemoved', (peerDescriptor: PeerDescriptor, closestPeers: RingContacts) => {
|
|
78
77
|
this.emit('ringContactRemoved', peerDescriptor, closestPeers)
|
|
79
78
|
})
|
|
80
|
-
this.
|
|
81
|
-
this.
|
|
82
|
-
this.
|
|
83
|
-
this.
|
|
79
|
+
this.neighbors.on('ping', (oldContacts: DhtNodeRpcRemote[], newContact: DhtNodeRpcRemote) => this.onKBucketPing(oldContacts, newContact))
|
|
80
|
+
this.neighbors.on('removed', (contact: DhtNodeRpcRemote) => this.onKBucketRemoved(getNodeIdFromPeerDescriptor(contact.getPeerDescriptor())))
|
|
81
|
+
this.neighbors.on('added', (contact: DhtNodeRpcRemote) => this.onKBucketAdded(contact))
|
|
82
|
+
this.neighbors.on('updated', () => {
|
|
84
83
|
// TODO: Update contact info to the connection manager and reconnect
|
|
85
84
|
})
|
|
86
|
-
this.
|
|
85
|
+
this.closestContacts = new SortedContactList({
|
|
87
86
|
referenceId: this.config.localNodeId,
|
|
88
87
|
maxSize: this.config.maxContactListSize,
|
|
89
|
-
allowToContainReferenceId: false
|
|
90
|
-
emitEvents: true
|
|
88
|
+
allowToContainReferenceId: false
|
|
91
89
|
})
|
|
92
|
-
this.
|
|
90
|
+
this.closestContacts.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) => {
|
|
93
91
|
if (this.stopped) {
|
|
94
92
|
return
|
|
95
93
|
}
|
|
96
94
|
this.emit('contactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
97
|
-
this.
|
|
95
|
+
this.randomContacts.addContact(this.config.createDhtNodeRpcRemote(removedContact.getPeerDescriptor()))
|
|
98
96
|
})
|
|
99
|
-
this.
|
|
97
|
+
this.closestContacts.on('contactAdded', (contactAdded: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
|
|
100
98
|
this.emit('contactAdded', contactAdded.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
101
99
|
)
|
|
102
|
-
this.
|
|
103
|
-
this.
|
|
100
|
+
this.activeContacts = new Set()
|
|
101
|
+
this.randomContacts = new RandomContactList(this.config.localNodeId, this.config.maxContactListSize)
|
|
102
|
+
this.randomContacts.on('contactRemoved', (removedContact: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
|
|
104
103
|
this.emit('randomContactRemoved', removedContact.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
105
104
|
)
|
|
106
|
-
this.
|
|
105
|
+
this.randomContacts.on('contactAdded', (contactAdded: DhtNodeRpcRemote, activeContacts: DhtNodeRpcRemote[]) =>
|
|
107
106
|
this.emit('randomContactAdded', contactAdded.getPeerDescriptor(), activeContacts.map((c) => c.getPeerDescriptor()))
|
|
108
107
|
)
|
|
109
108
|
}
|
|
@@ -115,15 +114,13 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
115
114
|
const sortingList: SortedContactList<DhtNodeRpcRemote> = new SortedContactList({
|
|
116
115
|
referenceId: this.config.localNodeId,
|
|
117
116
|
maxSize: 100, // TODO use config option or named constant?
|
|
118
|
-
allowToContainReferenceId: false
|
|
119
|
-
emitEvents: false
|
|
117
|
+
allowToContainReferenceId: false
|
|
120
118
|
})
|
|
121
119
|
sortingList.addContacts(oldContacts)
|
|
122
|
-
const
|
|
123
|
-
const removableNodeId = sortedContacts[sortedContacts.length - 1].getNodeId()
|
|
120
|
+
const removableNodeId = sortingList.getFurthestContacts(1)[0].getNodeId()
|
|
124
121
|
this.config.connectionLocker?.weakUnlockConnection(removableNodeId, this.config.lockId)
|
|
125
|
-
this.
|
|
126
|
-
this.
|
|
122
|
+
this.neighbors.remove(getRawFromDhtAddress(removableNodeId))
|
|
123
|
+
this.neighbors.add(newContact)
|
|
127
124
|
}
|
|
128
125
|
|
|
129
126
|
private onKBucketRemoved(nodeId: DhtAddress): void {
|
|
@@ -132,7 +129,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
132
129
|
}
|
|
133
130
|
this.config.connectionLocker?.weakUnlockConnection(nodeId, this.config.lockId)
|
|
134
131
|
logger.trace(`Removed contact ${nodeId}`)
|
|
135
|
-
if (this.
|
|
132
|
+
if (this.neighbors.count() === 0) {
|
|
136
133
|
this.emit('kBucketEmpty')
|
|
137
134
|
}
|
|
138
135
|
}
|
|
@@ -180,9 +177,9 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
180
177
|
}
|
|
181
178
|
|
|
182
179
|
private getClosestActiveContactNotInBucket(): DhtNodeRpcRemote | undefined {
|
|
183
|
-
for (const contactId of this.
|
|
184
|
-
if (!this.
|
|
185
|
-
return this.
|
|
180
|
+
for (const contactId of this.closestContacts.getContactIds()) {
|
|
181
|
+
if (!this.neighbors.get(getRawFromDhtAddress(contactId)) && this.activeContacts.has(contactId)) {
|
|
182
|
+
return this.closestContacts.getContact(contactId)!
|
|
186
183
|
}
|
|
187
184
|
}
|
|
188
185
|
return undefined
|
|
@@ -207,7 +204,7 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
207
204
|
logger.trace('disconnected: ' + nodeId)
|
|
208
205
|
this.connections.delete(nodeId)
|
|
209
206
|
if (this.config.isLayer0) {
|
|
210
|
-
this.
|
|
207
|
+
this.neighbors.remove(getRawFromDhtAddress(nodeId))
|
|
211
208
|
if (gracefulLeave === true) {
|
|
212
209
|
logger.trace(nodeId + ' ' + 'onTransportDisconnected with gracefulLeave ' + gracefulLeave)
|
|
213
210
|
this.removeContact(nodeId)
|
|
@@ -222,25 +219,26 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
222
219
|
return
|
|
223
220
|
}
|
|
224
221
|
logger.trace(`Removing contact ${nodeId}`)
|
|
225
|
-
this.ringContacts.removeContact(this.
|
|
226
|
-
this.
|
|
227
|
-
this.
|
|
228
|
-
this.
|
|
222
|
+
this.ringContacts.removeContact(this.closestContacts.getContact(nodeId))
|
|
223
|
+
this.neighbors.remove(getRawFromDhtAddress(nodeId))
|
|
224
|
+
this.closestContacts.removeContact(nodeId)
|
|
225
|
+
this.activeContacts.delete(nodeId)
|
|
226
|
+
this.randomContacts.removeContact(nodeId)
|
|
229
227
|
}
|
|
230
228
|
|
|
231
229
|
stop(): void {
|
|
232
230
|
this.stopped = true
|
|
233
|
-
this.
|
|
231
|
+
this.neighbors.toArray().forEach((rpcRemote: DhtNodeRpcRemote) => {
|
|
234
232
|
rpcRemote.leaveNotice()
|
|
235
|
-
this.
|
|
233
|
+
this.neighbors.remove(rpcRemote.id)
|
|
236
234
|
})
|
|
237
|
-
this.
|
|
235
|
+
this.neighbors.removeAllListeners()
|
|
238
236
|
this.ringContacts.getAllContacts().forEach((rpcRemote) => {
|
|
239
237
|
rpcRemote.leaveNotice()
|
|
240
238
|
this.ringContacts.removeContact(rpcRemote)
|
|
241
239
|
})
|
|
242
|
-
this.
|
|
243
|
-
this.
|
|
240
|
+
this.closestContacts.stop()
|
|
241
|
+
this.randomContacts.stop()
|
|
244
242
|
this.connections.clear()
|
|
245
243
|
}
|
|
246
244
|
|
|
@@ -248,12 +246,11 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
248
246
|
const closest = new SortedContactList<DhtNodeRpcRemote>({
|
|
249
247
|
referenceId,
|
|
250
248
|
allowToContainReferenceId: true,
|
|
251
|
-
emitEvents: false,
|
|
252
249
|
excludedNodeIds,
|
|
253
250
|
maxSize: limit
|
|
254
251
|
})
|
|
255
|
-
this.
|
|
256
|
-
return closest.
|
|
252
|
+
this.neighbors.toArray().forEach((contact) => closest.addContact(contact))
|
|
253
|
+
return closest.getClosestContacts()
|
|
257
254
|
}
|
|
258
255
|
|
|
259
256
|
// TODO reduce copy-paste?
|
|
@@ -261,12 +258,13 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
261
258
|
const closest = new SortedContactList<DhtNodeRpcRemote>({
|
|
262
259
|
referenceId,
|
|
263
260
|
allowToContainReferenceId: true,
|
|
264
|
-
emitEvents: false,
|
|
265
261
|
excludedNodeIds,
|
|
266
262
|
maxSize: limit
|
|
267
263
|
})
|
|
268
|
-
|
|
269
|
-
|
|
264
|
+
for (const contact of this.closestContacts.getAllContactsInUndefinedOrder()) {
|
|
265
|
+
closest.addContact(contact)
|
|
266
|
+
}
|
|
267
|
+
return closest.getClosestContacts()
|
|
270
268
|
}
|
|
271
269
|
|
|
272
270
|
getClosestRingContactsTo(
|
|
@@ -274,14 +272,16 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
274
272
|
limit?: number,
|
|
275
273
|
excludedIds?: Set<DhtAddress>
|
|
276
274
|
): { left: DhtNodeRpcRemote[], right: DhtNodeRpcRemote[] } {
|
|
277
|
-
const closest = new RingContactList<DhtNodeRpcRemote>(ringIdRaw,
|
|
278
|
-
|
|
275
|
+
const closest = new RingContactList<DhtNodeRpcRemote>(ringIdRaw, excludedIds)
|
|
276
|
+
for (const contact of this.closestContacts.getAllContactsInUndefinedOrder()) {
|
|
277
|
+
closest.addContact(contact)
|
|
278
|
+
}
|
|
279
279
|
this.ringContacts.getAllContacts().map((contact) => closest.addContact(contact))
|
|
280
280
|
return closest.getClosestContacts(limit ?? 8)
|
|
281
281
|
}
|
|
282
282
|
|
|
283
283
|
getContactCount(excludedNodeIds?: Set<DhtAddress>): number {
|
|
284
|
-
return this.
|
|
284
|
+
return this.closestContacts.getSize(excludedNodeIds)
|
|
285
285
|
}
|
|
286
286
|
|
|
287
287
|
getConnectionCount(): number {
|
|
@@ -289,15 +289,15 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
289
289
|
}
|
|
290
290
|
|
|
291
291
|
getNeighborCount(): number {
|
|
292
|
-
return this.
|
|
292
|
+
return this.neighbors.count()
|
|
293
293
|
}
|
|
294
294
|
|
|
295
295
|
getNeighbors(): PeerDescriptor[] {
|
|
296
|
-
return this.
|
|
296
|
+
return this.neighbors.toArray().map((rpcRemote: DhtNodeRpcRemote) => rpcRemote.getPeerDescriptor())
|
|
297
297
|
}
|
|
298
298
|
|
|
299
299
|
setContactActive(nodeId: DhtAddress): void {
|
|
300
|
-
this.
|
|
300
|
+
this.activeContacts.add(nodeId)
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
addContact(peerDescriptor: PeerDescriptor): void {
|
|
@@ -308,18 +308,18 @@ export class PeerManager extends EventEmitter<PeerManagerEvents> {
|
|
|
308
308
|
if (nodeId !== this.config.localNodeId) {
|
|
309
309
|
logger.trace(`Adding new contact ${nodeId}`)
|
|
310
310
|
const remote = this.config.createDhtNodeRpcRemote(peerDescriptor)
|
|
311
|
-
const
|
|
312
|
-
const
|
|
311
|
+
const isInNeighbors = (this.neighbors.get(peerDescriptor.nodeId) !== null)
|
|
312
|
+
const isInClosestContacts = (this.closestContacts.getContact(nodeId) !== undefined)
|
|
313
313
|
const isInRingContacts = this.ringContacts.getContact(peerDescriptor) !== undefined
|
|
314
314
|
|
|
315
|
-
if (
|
|
316
|
-
this.
|
|
315
|
+
if (isInNeighbors || isInClosestContacts) {
|
|
316
|
+
this.randomContacts.addContact(remote)
|
|
317
317
|
}
|
|
318
|
-
if (!
|
|
319
|
-
this.
|
|
318
|
+
if (!isInNeighbors) {
|
|
319
|
+
this.neighbors.add(remote)
|
|
320
320
|
}
|
|
321
|
-
if (!
|
|
322
|
-
this.
|
|
321
|
+
if (!isInClosestContacts) {
|
|
322
|
+
this.closestContacts.addContact(remote)
|
|
323
323
|
}
|
|
324
324
|
if (!isInRingContacts) {
|
|
325
325
|
this.ringContacts.addContact(remote)
|
|
@@ -1,16 +1,6 @@
|
|
|
1
1
|
import EventEmitter from 'eventemitter3'
|
|
2
2
|
import { DhtAddress } from '../../identifiers'
|
|
3
3
|
|
|
4
|
-
export class ContactState<C> {
|
|
5
|
-
|
|
6
|
-
public active = false
|
|
7
|
-
public contact: C
|
|
8
|
-
|
|
9
|
-
constructor(contact: C) {
|
|
10
|
-
this.contact = contact
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
4
|
export interface Events<C> {
|
|
15
5
|
contactRemoved: (removedContact: C, closestContacts: C[]) => void
|
|
16
6
|
contactAdded: (contactAdded: C, closestContacts: C[]) => void
|
|
@@ -18,7 +8,7 @@ export interface Events<C> {
|
|
|
18
8
|
|
|
19
9
|
export class ContactList<C extends { getNodeId: () => DhtAddress }> extends EventEmitter<Events<C>> {
|
|
20
10
|
|
|
21
|
-
protected contactsById: Map<DhtAddress,
|
|
11
|
+
protected contactsById: Map<DhtAddress, C> = new Map()
|
|
22
12
|
// TODO move this to SortedContactList
|
|
23
13
|
protected contactIds: DhtAddress[] = []
|
|
24
14
|
protected localNodeId: DhtAddress
|
|
@@ -36,7 +26,7 @@ export class ContactList<C extends { getNodeId: () => DhtAddress }> extends Even
|
|
|
36
26
|
this.defaultContactQueryLimit = defaultContactQueryLimit
|
|
37
27
|
}
|
|
38
28
|
|
|
39
|
-
public getContact(id: DhtAddress):
|
|
29
|
+
public getContact(id: DhtAddress): C | undefined {
|
|
40
30
|
return this.contactsById.get(id)
|
|
41
31
|
}
|
|
42
32
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DhtAddress } from '../../identifiers'
|
|
2
|
-
import { ContactList
|
|
2
|
+
import { ContactList } from './ContactList'
|
|
3
3
|
|
|
4
4
|
export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extends ContactList<C> {
|
|
5
5
|
|
|
@@ -27,7 +27,7 @@ export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
27
27
|
this.removeContact(toRemove)
|
|
28
28
|
}
|
|
29
29
|
this.contactIds.push(contact.getNodeId())
|
|
30
|
-
this.contactsById.set(contact.getNodeId(),
|
|
30
|
+
this.contactsById.set(contact.getNodeId(), contact)
|
|
31
31
|
this.emit(
|
|
32
32
|
'contactAdded',
|
|
33
33
|
contact,
|
|
@@ -39,7 +39,7 @@ export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
39
39
|
|
|
40
40
|
removeContact(id: DhtAddress): boolean {
|
|
41
41
|
if (this.contactsById.has(id)) {
|
|
42
|
-
const removed = this.contactsById.get(id)
|
|
42
|
+
const removed = this.contactsById.get(id)!
|
|
43
43
|
const index = this.contactIds.findIndex((nodeId) => (nodeId === id))
|
|
44
44
|
this.contactIds.splice(index, 1)
|
|
45
45
|
this.contactsById.delete(id)
|
|
@@ -50,13 +50,6 @@ export class RandomContactList<C extends { getNodeId: () => DhtAddress }> extend
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
public getContacts(limit = this.defaultContactQueryLimit): C[] {
|
|
53
|
-
|
|
54
|
-
this.contactIds.forEach((contactId) => {
|
|
55
|
-
const contact = this.contactsById.get(contactId)
|
|
56
|
-
if (contact) {
|
|
57
|
-
ret.push(contact.contact)
|
|
58
|
-
}
|
|
59
|
-
})
|
|
60
|
-
return ret.slice(0, limit)
|
|
53
|
+
return this.contactIds.slice(0, limit).map((contactId) => this.contactsById.get(contactId)!)
|
|
61
54
|
}
|
|
62
55
|
}
|
|
@@ -19,12 +19,10 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
|
|
|
19
19
|
private readonly excludedIds: Set<DhtAddress>
|
|
20
20
|
private readonly leftNeighbors: OrderedMap<RingDistance, C>
|
|
21
21
|
private readonly rightNeighbors: OrderedMap<RingDistance, C>
|
|
22
|
-
private readonly emitEvents: boolean
|
|
23
22
|
|
|
24
|
-
constructor(rawReferenceId: RingIdRaw,
|
|
23
|
+
constructor(rawReferenceId: RingIdRaw, excludedIds?: Set<DhtAddress>) {
|
|
25
24
|
super()
|
|
26
25
|
this.referenceId = getRingIdFromRaw(rawReferenceId)
|
|
27
|
-
this.emitEvents = emitEvents
|
|
28
26
|
this.excludedIds = excludedIds ?? new Set()
|
|
29
27
|
this.leftNeighbors = new OrderedMap<RingDistance, C>()
|
|
30
28
|
this.rightNeighbors = new OrderedMap<RingDistance, C>()
|
|
@@ -60,7 +58,7 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
|
|
|
60
58
|
}
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
if (this.
|
|
61
|
+
if (this.hasEventListeners() && (elementAdded || elementRemoved)) {
|
|
64
62
|
const closestContacts = this.getClosestContacts()
|
|
65
63
|
const closestDescriptors = {
|
|
66
64
|
left: closestContacts.left.map((c) => c.getPeerDescriptor()),
|
|
@@ -92,7 +90,7 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
|
|
|
92
90
|
elementRemoved = true
|
|
93
91
|
}
|
|
94
92
|
|
|
95
|
-
if (this.
|
|
93
|
+
if (this.hasEventListeners() && elementRemoved) {
|
|
96
94
|
const closestContacts = this.getClosestContacts()
|
|
97
95
|
const closestDescriptors = { left: closestContacts.left.map((c) => c.getPeerDescriptor()),
|
|
98
96
|
right: closestContacts.right.map((c) => c.getPeerDescriptor()) }
|
|
@@ -148,4 +146,8 @@ export class RingContactList<C extends { getPeerDescriptor(): PeerDescriptor }>
|
|
|
148
146
|
}
|
|
149
147
|
return ret
|
|
150
148
|
}
|
|
149
|
+
|
|
150
|
+
private hasEventListeners(): boolean {
|
|
151
|
+
return this.eventNames().length > 0
|
|
152
|
+
}
|
|
151
153
|
}
|