ssb-conn
Advanced tools
Comparing version 0.17.0 to 0.18.0
@@ -16,3 +16,3 @@ export declare class ConnScheduler { | ||
private weBlockThem; | ||
private weShouldConnectToThem; | ||
private weFollowThem; | ||
private maxWaitToConnect; | ||
@@ -19,0 +19,0 @@ private updateTheseConnections; |
@@ -100,3 +100,3 @@ "use strict"; | ||
}; | ||
this.weShouldConnectToThem = ([_addr, data]) => { | ||
this.weFollowThem = ([_addr, data]) => { | ||
var _a, _b, _c; | ||
@@ -313,4 +313,4 @@ if (!((_a = data) === null || _a === void 0 ? void 0 : _a.key)) | ||
.peersConnectable('staging') | ||
.filter(this.weShouldConnectToThem) | ||
.z(take(3 - conn.query().peersInConnection().length)) | ||
.filter(this.weFollowThem) | ||
.z(take(3 - conn.query().peersInConnection().filter(this.weFollowThem).length)) | ||
.forEach(([addr, data]) => conn.connect(addr, data)); | ||
@@ -436,3 +436,3 @@ conn | ||
}; | ||
if (this.weShouldConnectToThem([address, data])) { | ||
if (this.weFollowThem([address, data])) { | ||
this.ssb.conn.connect(address, data); | ||
@@ -461,3 +461,3 @@ } | ||
}; | ||
if (this.weShouldConnectToThem([address, data])) { | ||
if (this.weFollowThem([address, data])) { | ||
this.ssb.conn.connect(address, data); | ||
@@ -464,0 +464,0 @@ } |
@@ -6,2 +6,3 @@ import { Callback, Peer } from './types'; | ||
private readonly conn; | ||
private deprecationWarned; | ||
private latestWarning; | ||
@@ -14,2 +15,3 @@ constructor(ssb: any, cfg: any); | ||
private idToAddr; | ||
private deprecationWarning; | ||
peers: () => any; | ||
@@ -16,0 +18,0 @@ get: (addr: Peer | string) => any; |
@@ -80,3 +80,3 @@ "use strict"; | ||
this.get = (addr) => { | ||
console.error('DEPRECATED gossip.get() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('get'); | ||
if (ref.isFeed(addr)) { | ||
@@ -100,3 +100,3 @@ for (let [address, data] of this.conn.db().entries()) { | ||
var _a, _b; | ||
console.error('DEPRECATED gossip.connect() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('connect'); | ||
let addressString; | ||
@@ -117,3 +117,3 @@ try { | ||
this.disconnect = (addr, cb) => { | ||
console.error('DEPRECATED gossip.disconnect() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('disconnect'); | ||
let addressString; | ||
@@ -130,3 +130,3 @@ try { | ||
this.changes = () => { | ||
console.error('DEPRECATED gossip.changes() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('changes'); | ||
return this.notify.listen(); | ||
@@ -136,3 +136,3 @@ }; | ||
var _a; | ||
console.error('DEPRECATED gossip.add() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('add'); | ||
const [addressString, parsed] = validateAddr(addr); | ||
@@ -166,3 +166,3 @@ if (parsed.key === this.ssb.id) | ||
this.remove = (addr) => { | ||
console.error('DEPRECATED gossip.remove() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('remove'); | ||
const [addressString] = validateAddr(addr); | ||
@@ -179,3 +179,3 @@ this.conn.hub().disconnect(addressString); | ||
this.reconnect = () => { | ||
console.error('DEPRECATED gossip.reconnect() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('reconnect'); | ||
this.conn.hub().reset(); | ||
@@ -199,2 +199,3 @@ }; | ||
} | ||
this.deprecationWarned = {}; | ||
} | ||
@@ -232,2 +233,8 @@ setupConnectionListeners() { | ||
} | ||
deprecationWarning(method) { | ||
if (this.deprecationWarned[method]) | ||
return; | ||
console.error(`DEPRECATED gossip.${method}() was called. Use ssb-conn instead`); | ||
this.deprecationWarned[method] = true; | ||
} | ||
}; | ||
@@ -234,0 +241,0 @@ __decorate([ |
{ | ||
"name": "ssb-conn", | ||
"description": "SSB plugin for establishing and managing peer connections", | ||
"version": "0.17.0", | ||
"version": "0.18.0", | ||
"homepage": "https://github.com/staltz/ssb-conn", | ||
@@ -6,0 +6,0 @@ "main": "lib/index.js", |
@@ -135,3 +135,3 @@ <div style="text-align:center" align="center"> | ||
* Whether the CONN scheduler should look into the SSB database looking for | ||
* messages of type 'pub' and add them to CONN. | ||
* messages of type 'pub' and add them to CONN. Default is `true`. | ||
*/ | ||
@@ -138,0 +138,0 @@ "populatePubs": boolean, |
@@ -175,3 +175,3 @@ import ConnQuery = require('ssb-conn-query'); | ||
private weShouldConnectToThem = ([_addr, data]: [string, {key?: string}]) => { | ||
private weFollowThem = ([_addr, data]: [string, {key?: string}]) => { | ||
if (!data?.key) return false; | ||
@@ -330,4 +330,8 @@ const h = this.hops[data.key]; | ||
.peersConnectable('staging') | ||
.filter(this.weShouldConnectToThem) | ||
.z(take(3 - conn.query().peersInConnection().length)) | ||
.filter(this.weFollowThem) | ||
.z( | ||
take( | ||
3 - conn.query().peersInConnection().filter(this.weFollowThem).length, | ||
), | ||
) | ||
.forEach(([addr, data]) => conn.connect(addr, data)); | ||
@@ -479,3 +483,3 @@ | ||
}; | ||
if (this.weShouldConnectToThem([address, data])) { | ||
if (this.weFollowThem([address, data])) { | ||
this.ssb.conn.connect(address, data); | ||
@@ -506,3 +510,3 @@ } else { | ||
}; | ||
if (this.weShouldConnectToThem([address, data])) { | ||
if (this.weFollowThem([address, data])) { | ||
this.ssb.conn.connect(address, data); | ||
@@ -509,0 +513,0 @@ } else { |
@@ -62,2 +62,3 @@ import {ListenEvent as HubEvent} from 'ssb-conn-hub/lib/types'; | ||
private readonly conn: CONN; | ||
private deprecationWarned: Partial<Record<keyof Gossip, boolean>>; | ||
@@ -82,2 +83,4 @@ /** | ||
} | ||
this.deprecationWarned = {}; | ||
} | ||
@@ -135,2 +138,11 @@ | ||
private deprecationWarning(method: keyof Gossip) { | ||
if (this.deprecationWarned[method]) return; | ||
console.error( | ||
`DEPRECATED gossip.${method}() was called. Use ssb-conn instead`, | ||
); | ||
this.deprecationWarned[method] = true; | ||
} | ||
@muxrpc('sync') | ||
@@ -172,3 +184,3 @@ public peers: () => any = () => { | ||
public get: (addr: Peer | string) => any = (addr: Peer | string) => { | ||
console.error('DEPRECATED gossip.get() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('get'); | ||
if (ref.isFeed(addr)) { | ||
@@ -196,5 +208,3 @@ for (let [address, data] of this.conn.db().entries()) { | ||
public connect = (addr: Peer | string, cb: Callback<any>) => { | ||
console.error( | ||
'DEPRECATED gossip.connect() was called. Use ssb-conn instead', | ||
); | ||
this.deprecationWarning('connect'); | ||
let addressString: string; | ||
@@ -218,5 +228,3 @@ try { | ||
public disconnect = (addr: Peer | string, cb: any) => { | ||
console.error( | ||
'DEPRECATED gossip.disconnect() was called. Use ssb-conn instead', | ||
); | ||
this.deprecationWarning('disconnect'); | ||
let addressString: string; | ||
@@ -235,5 +243,3 @@ try { | ||
public changes = () => { | ||
console.error( | ||
'DEPRECATED gossip.changes() was called. Use ssb-conn instead', | ||
); | ||
this.deprecationWarning('changes'); | ||
return this.notify.listen(); | ||
@@ -244,3 +250,3 @@ }; | ||
public add = (addr: Peer | string, source: Peer['source']) => { | ||
console.error('DEPRECATED gossip.add() was called. Use ssb-conn instead'); | ||
this.deprecationWarning('add'); | ||
const [addressString, parsed] = validateAddr(addr); | ||
@@ -282,5 +288,3 @@ if (parsed.key === this.ssb.id) return; | ||
public remove = (addr: Peer | string) => { | ||
console.error( | ||
'DEPRECATED gossip.remove() was called. Use ssb-conn instead', | ||
); | ||
this.deprecationWarning('remove'); | ||
const [addressString] = validateAddr(addr); | ||
@@ -302,5 +306,3 @@ | ||
public reconnect = () => { | ||
console.error( | ||
'DEPRECATED gossip.reconnect() was called. Use ssb-conn instead', | ||
); | ||
this.deprecationWarning('reconnect'); | ||
this.conn.hub().reset(); | ||
@@ -307,0 +309,0 @@ }; |
141727
2547