Skip to content

Commit be67698

Browse files
committed
periodically check if peers are still valid, terminate connections when they're not
1 parent 2cbe8f1 commit be67698

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

src/mesh/agents/peer/PeerGroupAgent.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,9 @@ class PeerGroupAgent implements Agent {
207207
//console.log(this.peerGroupId + ' has ' + this.getPeers().length + ' peers')
208208

209209
this.cleanUp();
210-
this.queryForOnlinePeers();
210+
await this.queryForOnlinePeers();
211211
this.deduplicateConnections();
212+
await this.checkPeers();
212213
} finally {
213214
this.tickLock.release();
214215
}
@@ -499,6 +500,21 @@ class PeerGroupAgent implements Agent {
499500

500501
}
501502

503+
private async checkPeers() {
504+
for (const [endpoint, connIds] of this.connectionsPerEndpoint.entries()) {
505+
if (await this.peerSource.getPeerForEndpoint(endpoint) === undefined) {
506+
for (const connId of connIds) {
507+
try {
508+
this.getNetworkAgent().releaseConnectionIfExists(connId, this.getAgentId());
509+
} catch (e) {
510+
PeerGroupAgent.controlLog.warning('Error attempting to release connection ' + connId, e);
511+
}
512+
}
513+
}
514+
}
515+
516+
}
517+
502518
// Connection deduplication logic.
503519

504520
// Note: ATM the PeerGroupAgent will aggressively deduplicate all connections that go to the

0 commit comments

Comments
 (0)