Comparing version 0.9.3 to 0.10.0
@@ -11,3 +11,3 @@ export declare class ConnScheduler { | ||
constructor(ssb: any, config: any); | ||
private updateHops; | ||
private loadHops; | ||
private conf; | ||
@@ -18,4 +18,6 @@ private isCurrentlyDownloading; | ||
private updateTheseConnections; | ||
private updateConnectionsNow; | ||
private updateConnectionsSoon; | ||
private updateStagingNow; | ||
private updateHubNow; | ||
private updateNow; | ||
private updateSoon; | ||
private populateWithSeeds; | ||
@@ -22,0 +24,0 @@ private setupPubDiscovery; |
@@ -84,3 +84,3 @@ "use strict"; | ||
} | ||
this.updateHops(); | ||
this.loadHops(); | ||
this.populateWithSeeds(); | ||
@@ -90,3 +90,3 @@ this.setupPubDiscovery(); | ||
this.setupBluetoothDiscovery(); | ||
const int = setInterval(() => this.updateConnectionsSoon(), 2e3); | ||
const int = setInterval(() => this.updateSoon(), 2e3); | ||
if (int.unref) | ||
@@ -96,4 +96,4 @@ int.unref(); | ||
onNetwork(() => this.ssb.conn.hub().reset()); | ||
pull(this.ssb.conn.hub().listen(), pull.filter((ev) => ev.type === 'disconnected'), pull.drain(() => this.updateConnectionsSoon(200))); | ||
this.updateConnectionsSoon(); | ||
pull(this.ssb.conn.hub().listen(), pull.filter((ev) => ev.type === 'disconnected'), pull.drain(() => this.updateSoon(200))); | ||
this.updateSoon(); | ||
}; | ||
@@ -120,3 +120,3 @@ this.stop = () => { | ||
if (msg.value.content && msg.value.content.type === 'contact') { | ||
this.updateHops(); | ||
this.loadHops(); | ||
} | ||
@@ -126,3 +126,3 @@ }); | ||
} | ||
updateHops() { | ||
loadHops() { | ||
if (!this.ssb.friends || !this.ssb.friends.hops) { | ||
@@ -174,14 +174,28 @@ debug('Warning: ssb-friends is missing, scheduling will miss some info'); | ||
} | ||
updateConnectionsNow() { | ||
if (this.hasSsbDb && !this.ssb.ready()) | ||
return; | ||
if (this.isCurrentlyDownloading()) | ||
return; | ||
if (this.isLoadingHops) | ||
return; | ||
updateStagingNow() { | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('db') | ||
.filter(p => !this.weBlockThem(p)) | ||
.filter(([, data]) => data.autoconnect === false) | ||
.forEach(([addr, data]) => this.ssb.conn.stage(addr, data)); | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(this.weBlockThem) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'lan') | ||
.filter(([, data]) => data.stagingUpdated + 10e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'bt') | ||
.filter(([, data]) => data.stagingUpdated + 30e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
} | ||
updateHubNow() { | ||
if (this.conf('seed', true)) { | ||
@@ -204,3 +218,3 @@ this.updateTheseConnections(p => p[1].source === 'seed', { | ||
this.updateTheseConnections(p => p[1].type === 'room', { | ||
quota: 2, | ||
quota: 10, | ||
backoffStep: 5e3, | ||
@@ -247,14 +261,2 @@ backoffMax: 5 * minute, | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'lan') | ||
.filter(([, data]) => data.stagingUpdated + 10e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'bt') | ||
.filter(([, data]) => data.stagingUpdated + 30e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
this.ssb.conn | ||
.query() | ||
.peersInConnection() | ||
@@ -275,3 +277,13 @@ .filter(peer => { | ||
} | ||
updateConnectionsSoon(period = 1000) { | ||
updateNow() { | ||
if (this.hasSsbDb && !this.ssb.ready()) | ||
return; | ||
if (this.isCurrentlyDownloading()) | ||
return; | ||
if (this.isLoadingHops) | ||
return; | ||
this.updateStagingNow(); | ||
this.updateHubNow(); | ||
} | ||
updateSoon(period = 1000) { | ||
if (this.closed) | ||
@@ -284,3 +296,3 @@ return; | ||
const timer = setTimeout(() => { | ||
this.updateConnectionsNow(); | ||
this.updateNow(); | ||
this.hasScheduledAnUpdate = false; | ||
@@ -287,0 +299,0 @@ }, fuzzyPeriod); |
{ | ||
"name": "ssb-conn", | ||
"description": "SSB plugin for establishing and managing peer connections", | ||
"version": "0.9.3", | ||
"version": "0.10.0", | ||
"homepage": "https://github.com/staltz/ssb-conn", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -111,3 +111,3 @@ import ConnQuery = require('ssb-conn-query'); | ||
if (msg.value.content && msg.value.content.type === 'contact') { | ||
this.updateHops(); | ||
this.loadHops(); | ||
} | ||
@@ -118,3 +118,3 @@ }); | ||
private updateHops() { | ||
private loadHops() { | ||
if (!this.ssb.friends || !this.ssb.friends.hops) { | ||
@@ -192,7 +192,3 @@ debug('Warning: ssb-friends is missing, scheduling will miss some info'); | ||
private updateConnectionsNow() { | ||
if (this.hasSsbDb && !this.ssb.ready()) return; | ||
if (this.isCurrentlyDownloading()) return; | ||
if (this.isLoadingHops) return; | ||
private updateStagingNow() { | ||
// Stage all db peers with autoconnect=false | ||
@@ -202,5 +198,31 @@ this.ssb.conn | ||
.peersConnectable('db') | ||
.filter(p => !this.weBlockThem(p)) | ||
.filter(([, data]) => data.autoconnect === false) | ||
.forEach(([addr, data]) => this.ssb.conn.stage(addr, data)); | ||
// Purge staged peers that are now blocked | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(this.weBlockThem) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
// Purge some old staged LAN peers | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'lan') | ||
.filter(([, data]) => data.stagingUpdated! + 10e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
// Purge some old staged Bluetooth peers | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'bt') | ||
.filter(([, data]) => data.stagingUpdated! + 30e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
} | ||
private updateHubNow() { | ||
if (this.conf('seed', true)) { | ||
@@ -225,5 +247,5 @@ this.updateTheseConnections(p => p[1].source === 'seed', { | ||
// Connect to at least 2 rooms, prioritized over pubs | ||
// Connect to rooms, up to 10 of them, prioritized over pubs | ||
this.updateTheseConnections(p => p[1].type === 'room', { | ||
quota: 2, | ||
quota: 10, | ||
backoffStep: 5e3, | ||
@@ -277,18 +299,2 @@ backoffMax: 5 * minute, | ||
// Purge some old staged LAN peers | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'lan') | ||
.filter(([, data]) => data.stagingUpdated! + 10e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
// Purge some old staged Bluetooth peers | ||
this.ssb.conn | ||
.query() | ||
.peersConnectable('staging') | ||
.filter(([, data]) => data.type === 'bt') | ||
.filter(([, data]) => data.stagingUpdated! + 30e3 < Date.now()) | ||
.forEach(([addr]) => this.ssb.conn.unstage(addr)); | ||
// Purge some ongoing frustrating connection attempts | ||
@@ -315,3 +321,12 @@ this.ssb.conn | ||
private updateConnectionsSoon(period: number = 1000) { | ||
private updateNow() { | ||
if (this.hasSsbDb && !this.ssb.ready()) return; | ||
if (this.isCurrentlyDownloading()) return; | ||
if (this.isLoadingHops) return; | ||
this.updateStagingNow(); | ||
this.updateHubNow(); | ||
} | ||
private updateSoon(period: number = 1000) { | ||
if (this.closed) return; | ||
@@ -324,3 +339,3 @@ if (this.hasScheduledAnUpdate) return; | ||
const timer = setTimeout(() => { | ||
this.updateConnectionsNow(); | ||
this.updateNow(); | ||
this.hasScheduledAnUpdate = false; | ||
@@ -477,3 +492,3 @@ }, fuzzyPeriod); | ||
// Upon init, load some follow-and-blocks data | ||
this.updateHops(); | ||
this.loadHops(); | ||
@@ -489,3 +504,3 @@ // Upon init, populate with seeds | ||
// Upon regular time intervals, attempt to make connections | ||
const int = setInterval(() => this.updateConnectionsSoon(), 2e3); | ||
const int = setInterval(() => this.updateSoon(), 2e3); | ||
if (int.unref) int.unref(); | ||
@@ -503,7 +518,7 @@ | ||
pull.filter((ev: HubEvent) => ev.type === 'disconnected'), | ||
pull.drain(() => this.updateConnectionsSoon(200)), | ||
pull.drain(() => this.updateSoon(200)), | ||
); | ||
// Upon init, attempt to make some connections | ||
this.updateConnectionsSoon(); | ||
this.updateSoon(); | ||
}; | ||
@@ -510,0 +525,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
131654
2383