Socket
Socket
Sign inDemoInstall

ssb-conn

Package Overview
Dependencies
Maintainers
1
Versions
92
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssb-conn - npm Package Compare versions

Comparing version 0.1.0 to 0.1.1

1

lib/conn-scheduler.d.ts

@@ -8,3 +8,2 @@ export declare class ConnScheduler {

private hasScheduledAnUpdate;
private readonly myCapsHash;
private hops;

@@ -11,0 +10,0 @@ constructor(ssb: any, config: any);

45

lib/conn-scheduler.js

@@ -17,3 +17,2 @@ "use strict";

const Ref = require('ssb-ref');
const Keys = require('ssb-keys');
const debug = require('debug')('ssb:conn:scheduler');

@@ -52,2 +51,8 @@ require('zii');

}
function neverJustOne(x) {
if (x === 1)
return x + 1;
else
return x;
}
const minute = 60e3;

@@ -104,3 +109,2 @@ const hour = 60 * 60e3;

this.hasScheduledAnUpdate = false;
this.myCapsHash = Keys.hash(config.caps.shs);
this.hops = {};

@@ -145,3 +149,3 @@ this.ssb.post((msg) => {

const excess = peersUp.length > quota * 2 ? peersUp.length - quota : 0;
const freeSlots = Math.max(quota - peersUp.length, 0);
const freeSlots = neverJustOne(Math.max(quota - peersUp.length, 0));
peersUp

@@ -267,3 +271,3 @@ .z(sortByStateChange)

const key = Ref.getKeyFromAddress(address);
if (this.weBlockThem([address, { key, pool: 'db' }])) {
if (this.weBlockThem([address, { key }])) {
this.ssb.conn.forget(address);

@@ -288,7 +292,12 @@ }

`shs:${btPeer.id.replace(/^\@/, '').replace(/\.ed25519$/, '')}`;
this.ssb.conn.stage(address, {
type: 'bt',
note: btPeer.displayName,
key: btPeer.id,
});
const entry = [
address,
{ type: 'bt', note: btPeer.displayName, key: btPeer.id },
];
if (this.weFollowThem(entry)) {
this.ssb.conn.connect(...entry);
}
else {
this.ssb.conn.stage(...entry);
}
}

@@ -303,10 +312,16 @@ }));

if (this.ssb.lan && this.ssb.lan.start && this.ssb.lan.discoveredPeers) {
pull(this.ssb.lan.discoveredPeers(), pull.drain(({ address, capsHash, verified }) => {
pull(this.ssb.lan.discoveredPeers(), pull.drain(({ address, verified }) => {
const peer = Ref.parseAddress(address);
const isLegacy = !capsHash;
const capsHashOkay = isLegacy || capsHash === this.myCapsHash;
const verifiedOkay = isLegacy || verified;
if (peer && peer.key && capsHashOkay && verifiedOkay) {
this.ssb.conn.stage(address, { type: 'lan', key: peer.key });
if (!peer || !peer.key)
return;
const entry = [
address,
{ type: 'lan', key: peer.key, verified },
];
if (this.weFollowThem(entry)) {
this.ssb.conn.connect(...entry);
}
else {
this.ssb.conn.stage(...entry);
}
}));

@@ -313,0 +328,0 @@ this.ssb.lan.start();

{
"name": "ssb-conn",
"description": "SSB plugin for establishing and managing peer connections",
"version": "0.1.0",
"version": "0.1.1",
"homepage": "https://github.com/staltz/ssb-conn",

@@ -27,3 +27,2 @@ "main": "lib/index.js",

"secret-stack-decorators": "1.0.0",
"ssb-keys": "^7.1.3",
"ssb-ref": "^2.13.9",

@@ -41,4 +40,4 @@ "ssb-typescript": "^1.4.0",

"ssb-caps": "~1.0.1",
"ssb-server": "~15.0.1",
"ssb-lan": "~0.0.2",
"ssb-server": "~15.1.0",
"ssb-lan": "~0.1.1",
"secret-stack": ">=6.2.0",

@@ -55,2 +54,2 @@ "tape": "^4.9.2",

"license": "MIT"
}
}
import ConnHub = require('ssb-conn-hub');
import ConnQuery = require('ssb-conn-query');
import {ListenEvent as HubEvent} from 'ssb-conn-hub/lib/types';
import {StagedData} from 'ssb-conn-staging/lib/types';
import {Peer} from 'ssb-conn-query/lib/types';

@@ -15,3 +16,2 @@ import {Discovery as LANDiscovery} from 'ssb-lan/lib/types';

const Ref = require('ssb-ref');
const Keys = require('ssb-keys');
const debug = require('debug')('ssb:conn:scheduler');

@@ -75,2 +75,7 @@ require('zii');

function neverJustOne(x: number) {
if (x === 1) return x + 1;
else return x;
}
const minute = 60e3;

@@ -89,3 +94,2 @@ const hour = 60 * 60e3;

private hasScheduledAnUpdate: boolean;
private readonly myCapsHash: string;
private hops: Record<FeedId, number>;

@@ -100,3 +104,2 @@

this.hasScheduledAnUpdate = false;
this.myCapsHash = Keys.hash(config.caps.shs);
this.hops = {};

@@ -140,3 +143,3 @@

private weBlockThem = ([_addr, data]: Peer) => {
private weBlockThem = ([_addr, data]: [string, {key?: string}]) => {
if (!data || !data.key) return false;

@@ -146,3 +149,3 @@ return this.hops[data.key] === -1;

private weFollowThem = ([_addr, data]: Peer) => {
private weFollowThem = ([_addr, data]: [string, {key?: string}]) => {
if (!data || !data.key) return false;

@@ -160,3 +163,3 @@ return this.hops[data.key] > 0;

const excess = peersUp.length > quota * 2 ? peersUp.length - quota : 0;
const freeSlots = Math.max(quota - peersUp.length, 0);
const freeSlots = neverJustOne(Math.max(quota - peersUp.length, 0));

@@ -322,3 +325,3 @@ // Disconnect from excess

const key = Ref.getKeyFromAddress(address);
if (this.weBlockThem([address, {key, pool: 'db'}])) {
if (this.weBlockThem([address, {key}])) {
this.ssb.conn.forget(address);

@@ -347,7 +350,11 @@ } else {

this.ssb.conn.stage(address, {
type: 'bt',
note: btPeer.displayName,
key: btPeer.id,
});
const entry: [string, Partial<StagedData>] = [
address,
{type: 'bt', note: btPeer.displayName, key: btPeer.id},
];
if (this.weFollowThem(entry)) {
this.ssb.conn.connect(...entry);
} else {
this.ssb.conn.stage(...entry);
}
}

@@ -367,9 +374,14 @@ }),

this.ssb.lan.discoveredPeers(),
pull.drain(({address, capsHash, verified}: LANDiscovery) => {
pull.drain(({address, verified}: LANDiscovery) => {
const peer = Ref.parseAddress(address);
const isLegacy = !capsHash;
const capsHashOkay = isLegacy || capsHash === this.myCapsHash;
const verifiedOkay = isLegacy || verified;
if (peer && peer.key && capsHashOkay && verifiedOkay) {
this.ssb.conn.stage(address, {type: 'lan', key: peer.key});
if (!peer || !peer.key) return;
const entry: [string, Partial<StagedData>] = [
address,
{type: 'lan', key: peer.key, verified},
];
if (this.weFollowThem(entry)) {
this.ssb.conn.connect(...entry);
} else {
this.ssb.conn.stage(...entry);
}

@@ -376,0 +388,0 @@ }),

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc