Socket
Socket
Sign inDemoInstall

ssb-conn-db

Package Overview
Dependencies
16
Maintainers
1
Versions
21
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.7 to 0.0.8

db.png

18

lib/migration.js

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

Object.defineProperty(exports, "__esModule", { value: true });
var ref = require('ssb-ref');
function migrateOne(old) {

@@ -24,3 +25,9 @@ if (!old)

if (!old.address) {
throw new Error('Cannot migrate entry without field "address"');
try {
old.address = ref.toMultiServerAddress(old);
}
catch (err) {
throw new Error('Cannot migrate entry without field "address" ' +
'or legacy {host,port,key}');
}
}

@@ -43,4 +50,9 @@ var copy;

return olds.reduce(function (obj, old) {
var _a = __read(migrateOne(old), 2), address = _a[0], data = _a[1];
obj[address] = data;
try {
var _a = __read(migrateOne(old), 2), address = _a[0], data = _a[1];
obj[address] = data;
}
catch (err) {
console.warn(err.message || err);
}
return obj;

@@ -47,0 +59,0 @@ }, {});

3

package.json
{
"name": "ssb-conn-db",
"description": "Module that manages a local registry of connectable peers",
"version": "0.0.7",
"version": "0.0.8",
"homepage": "https://github.com/staltz/ssb-conn-db",

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

"pull-notify": "~0.1.1",
"ssb-ref": "~2.13.9",
"multiserver-address": "~1.0.1"

@@ -17,0 +18,0 @@ },

# ssb-conn-db
Module that manages a local registry of connectable peers. For use with the SSB CONN family of modules.
Module that manages a local registry of connectable peers. For use with the SSB CONN family of modules. See also [ssb-conn-hub](https://github.com/staltz/ssb-conn-hub).
*Visual metaphor: a shelf of binders used for archival, holding static data on peers
and their previous addresses used for connections.*
![db.png](./db.png)
## Usage

@@ -6,0 +11,0 @@

import {AddressData} from './types';
const ref = require('ssb-ref');

@@ -6,3 +7,10 @@ export function migrateOne(old: any): [string, AddressData] {

if (!old.address) {
throw new Error('Cannot migrate entry without field "address"');
try {
old.address = ref.toMultiServerAddress(old);
} catch (err) {
throw new Error(
'Cannot migrate entry without field "address" ' +
'or legacy {host,port,key}',
);
}
}

@@ -25,6 +33,10 @@

return olds.reduce((obj: any, old: any) => {
const [address, data] = migrateOne(old);
obj[address] = data;
try {
const [address, data] = migrateOne(old);
obj[address] = data;
} catch (err) {
console.warn(err.message || err);
}
return obj;
}, {});
}

@@ -145,1 +145,35 @@ const tape = require('tape');

});
tape('init: migrate legacy {host,port,key} without crashing', function(t) {
const dirPath = path.join(__dirname, './legacy-addr');
const connJSONPath = path.join(dirPath, './conn.json');
const gossipJSONPath = path.join(dirPath, './gossip.json');
t.ok(!fs.existsSync(connJSONPath), 'conn.json does not exist');
t.ok(fs.existsSync(gossipJSONPath), 'gossip.json exists');
const gossipDataBefore = fs.readFileSync(gossipJSONPath, 'utf8');
const connDB = new ConnDB({path: dirPath});
t.ok(connDB, 'connDB instance was created');
setTimeout(() => {
t.ok(fs.existsSync(connJSONPath), 'conn.json exists');
t.ok(fs.existsSync(gossipJSONPath), 'gossip.json exists');
const gossipDataAfter = fs.readFileSync(gossipJSONPath, 'utf8');
t.equals(gossipDataBefore, gossipDataAfter, 'gossip.json stayed untouched');
const entries = Array.from(connDB.entries());
t.true(entries.length === 1, 'connDB has one address');
t.equals(
entries[0][0],
'net:bloor.ansuz.xyz:8008~shs:dABVXEERk+yJSzdrDRUfF8R6FlXG7h9PaXKXlt8ma78=',
'address looks good',
);
fs.unlinkSync(connJSONPath);
t.pass('teardown');
t.end();
}, 500);
});
SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc