Socket
Socket
Sign inDemoInstall

ssb-conn-hub

Package Overview
Dependencies
Maintainers
1
Versions
25
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ssb-conn-hub - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

1

lib/index.d.ts

@@ -19,2 +19,3 @@ import { ConnectionData as Data, Address } from './types';

disconnect(address: Address): Promise<boolean>;
update(address: Address, data: Partial<Data>): boolean;
reset(): void;

@@ -21,0 +22,0 @@ entries(): IterableIterator<[string, Data]>;

@@ -343,2 +343,13 @@ "use strict";

};
ConnHub.prototype.update = function (address, data) {
this._assertNotClosed();
this._assertValidAddress(address);
if (this._peers.has(address)) {
this._setPeer(address, data);
return true;
}
else {
return false;
}
};
ConnHub.prototype.reset = function () {

@@ -345,0 +356,0 @@ var e_2, _a;

2

package.json
{
"name": "ssb-conn-hub",
"description": "Module that manages active connections to SSB peers",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://github.com/staltz/ssb-conn-hub",

@@ -6,0 +6,0 @@ "main": "lib/index.js",

@@ -28,2 +28,3 @@ # ssb-conn-hub

- Rejects with an error indicating why the disconnection failed
* `connHub.update(address, data)`: update the metadata of a peer currently in connection with us, where the peer is known by its `address` and the new data is in `data`. If the peer is not registered in ConnHub, this method performs no operations and returns false. Returns true if the update has succeeded.
* `connHub.reset()`: closes all connections, basically resetting this instance as if it had just been started

@@ -30,0 +31,0 @@ * `connHub.entries()`: returns a new `Iterator` object that gives `[address, data]` pairs, where data has the state and key of the peer

@@ -292,2 +292,14 @@ import {ConnectionData as Data, ListenEvent, Address} from './types';

public update(address: Address, data: Partial<Data>): boolean {
this._assertNotClosed();
this._assertValidAddress(address);
if (this._peers.has(address)) {
this._setPeer(address, data);
return true;
} else {
return false;
}
}
public reset() {

@@ -294,0 +306,0 @@ this._assertNotClosed();

@@ -67,2 +67,50 @@ const tape = require('tape');

tape('update() returns true when the peer is in ConnHub', t => {
const connHub = new ConnHub(ssbServer);
let i = 0;
pull(
connHub.listen(),
pull.drain(ev => {
++i;
if (i === 1) {
t.equals(ev.type, 'connecting', '1st event is connecting');
const a1 = [...connHub.entries()];
t.equals(a1.length, 1, 'There is one entry');
t.equals(a1[0].length, 2, 'The entry is a tuple');
t.equals(typeof a1[0][1].foo, 'undefined', 'Field "foo" is undefined');
const result = connHub.update(TEST_ADDR, {foo: 'bar'});
t.strictEqual(result, true, 'Returns true');
const a2 = [...connHub.entries()];
t.equals(a2.length, 1, 'There is one entry');
t.equals(a2[0].length, 2, 'The entry is a tuple');
t.equals(a2[0][1].foo, 'bar', 'Field "foo" equals "bar"');
} else if (i === 2) {
t.equals(ev.type, 'connecting-failed', '2nd is connecting-failed');
t.end();
} else {
t.fail('listen() should not emit further events');
}
}),
);
connHub.connect(TEST_ADDR).then(
() => {
t.fail('The connection should not succeed');
},
_err => {},
);
});
tape('update() returns false when the peer is not in ConnHub', t => {
const connHub = new ConnHub(ssbServer);
const result = connHub.update(TEST_ADDR, {foo: 'bar'});
t.strictEqual(result, false, 'Returns false');
t.end();
});
tape('liveEntries() emits all entries as they update', t => {

@@ -69,0 +117,0 @@ const connHub = new ConnHub(ssbServer);

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