ssb-conn
Advanced tools
Comparing version 0.14.0 to 0.15.0
@@ -22,2 +22,3 @@ export declare class ConnScheduler { | ||
private updateSoon; | ||
private markDefunct; | ||
private populateWithSeeds; | ||
@@ -24,0 +25,0 @@ private setupPubDiscovery; |
@@ -42,2 +42,8 @@ "use strict"; | ||
} | ||
function isDefunct(peer) { | ||
return peer[1].defunct !== true; | ||
} | ||
function notDefunct(peer) { | ||
return peer[1].defunct !== true; | ||
} | ||
function take(n) { | ||
@@ -109,10 +115,13 @@ return (arr) => arr.slice(0, Math.max(n, 0)); | ||
this.closed = false; | ||
for (let [address, { source, type, failure }] of this.ssb.conn.dbPeers()) { | ||
for (let peer of this.ssb.conn.dbPeers()) { | ||
const [address, { source, type, failure }] = peer; | ||
if (source === 'local' || | ||
source === 'bt' || | ||
type === 'lan' || | ||
type === 'bt' || | ||
((failure !== null && failure !== void 0 ? failure : 0)) > 200) { | ||
type === 'bt') { | ||
this.ssb.conn.forget(address); | ||
} | ||
if ((failure !== null && failure !== void 0 ? failure : 0 > 200)) { | ||
this.markDefunct(peer); | ||
} | ||
} | ||
@@ -210,2 +219,3 @@ this.loadHops(); | ||
peersDown | ||
.filter(notDefunct) | ||
.filter(p => !this.weBlockThem(p)) | ||
@@ -226,2 +236,3 @@ .filter(canBeConnected) | ||
.peersConnectable('db') | ||
.filter(notDefunct) | ||
.filter(p => !this.weBlockThem(p)) | ||
@@ -233,2 +244,3 @@ .filter(([, data]) => data.autoconnect === false) | ||
.peersConnectable('staging') | ||
.filter(isDefunct) | ||
.filter(this.weBlockThem) | ||
@@ -345,2 +357,5 @@ .forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
} | ||
markDefunct([addr, data]) { | ||
this.ssb.conn.db().replace(addr, { defunct: true, birth: data.birth }); | ||
} | ||
populateWithSeeds() { | ||
@@ -347,0 +362,0 @@ const seeds = this.config.seeds; |
{ | ||
"name": "ssb-conn", | ||
"description": "SSB plugin for establishing and managing peer connections", | ||
"version": "0.14.0", | ||
"version": "0.15.0", | ||
"homepage": "https://github.com/staltz/ssb-conn", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -108,2 +108,4 @@ <div style="text-align:center" align="center"> | ||
🔸 `defunct?: boolean`: a flag that (when `true`) indicates that this peer was deemed "no longer operative" by the default CONN scheduler, after hundreds of failed attempts were made to connect with it | ||
🔸 `name?: string`: a nickname for this peer, when there isn't an [ssb-about](https://github.com/ssbc/ssb-about) name | ||
@@ -185,3 +187,3 @@ | ||
In none of the cases above shall we connect to a peer that we block. In addition to the above, the following actions happen automatically every (approximately) 1 second: | ||
In none of the cases above shall we connect to a peer that we block, not those that are marked "defunct". In addition to the above, the following actions happen automatically every (approximately) 1 second: | ||
@@ -196,3 +198,3 @@ - Connect to (at most 3) staged peers we follow | ||
- For other types of peers, "too long" means 10sec | ||
- Stage non-blocked peers that are in ConnDB, marked as `autoconnect=false` | ||
- Stage non-blocked non-defunct peers that are in ConnDB marked as `autoconnect=false` | ||
- Unstage peers that have just been blocked by us | ||
@@ -207,3 +209,3 @@ - Unstage LAN peers that haven't been updated in ConnStaging in 10 seconds | ||
- Remove database entries for any LAN or Bluetooth peers (these are rediscovered just-in-time) | ||
- Remove database entries of peers that, after 200 attempts, we still fail to connect with | ||
- Mark database entries "defunct" if, after 200 attempts, we still fail to connect with them | ||
@@ -210,0 +212,0 @@ **Other events:** |
import ConnQuery = require('ssb-conn-query'); | ||
import {AddressData as DBData} from 'ssb-conn-db/lib/types'; | ||
import {ListenEvent as HubEvent} from 'ssb-conn-hub/lib/types'; | ||
@@ -49,2 +50,10 @@ import {StagedData} from 'ssb-conn-staging/lib/types'; | ||
function isDefunct(peer: Peer): boolean { | ||
return peer[1].defunct !== true; | ||
} | ||
function notDefunct(peer: Peer): boolean { | ||
return peer[1].defunct !== true; | ||
} | ||
function take(n: number) { | ||
@@ -214,2 +223,3 @@ return <T>(arr: Array<T>) => arr.slice(0, Math.max(n, 0)); | ||
peersDown | ||
.filter(notDefunct) | ||
.filter(p => !this.weBlockThem(p)) | ||
@@ -235,2 +245,3 @@ .filter(canBeConnected) | ||
.peersConnectable('db') | ||
.filter(notDefunct) | ||
.filter(p => !this.weBlockThem(p)) | ||
@@ -240,6 +251,7 @@ .filter(([, data]) => data.autoconnect === false) | ||
// Purge staged peers that are now blocked | ||
// Purge staged peers that are now blocked or defunct | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(isDefunct) | ||
.filter(this.weBlockThem) | ||
@@ -378,2 +390,6 @@ .forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
private markDefunct([addr, data]: [string, DBData]) { | ||
this.ssb.conn.db().replace(addr, {defunct: true, birth: data.birth}); | ||
} | ||
private populateWithSeeds() { | ||
@@ -511,3 +527,4 @@ // Populate gossip table with configured seeds (mainly used in testing) | ||
// Upon init, purge some undesired DB entries | ||
for (let [address, {source, type, failure}] of this.ssb.conn.dbPeers()) { | ||
for (let peer of this.ssb.conn.dbPeers()) { | ||
const [address, {source, type, failure}] = peer; | ||
if ( | ||
@@ -517,7 +534,9 @@ source === 'local' || | ||
type === 'lan' || | ||
type === 'bt' || | ||
(failure ?? 0) > 200 | ||
type === 'bt' | ||
) { | ||
this.ssb.conn.forget(address); | ||
} | ||
if (failure ?? 0 > 200) { | ||
this.markDefunct(peer); | ||
} | ||
} | ||
@@ -524,0 +543,0 @@ |
138859
2476
299