git ssb

3+

andrestaltz / easy-ssb-pub



Commit 2f5e366ed4730353ef624eaca74ad09d79944654

Fix detection of peer from discovery-swarm

Andre Staltz committed on 2/28/2017, 1:00:20 PM
Parent: 02fa1bcfc3a0826a69118454100ee777075c1b3b

Files changed

src/index.tschanged
src/index.tsView
@@ -42,13 +42,8 @@
4242 size: number;
4343 path: string;
4444 }
4545
46-interface BotIdentity {
47- id: string;
48- qr: QRSVG;
49-}
50-
5146 const idQR = qr.svgObject(bot.id);
5247
5348 bot.address((err, addr) => {
5449 if (err) {
@@ -63,9 +58,9 @@
6358 // Setup Discovery Swarm =======================================================
6459 var peer = swarm({
6560 maxConnections: 1000,
6661 utp: true,
67- id: bot.id,
62 + id: 'ssb:' + bot.id,
6863 });
6964
7065 peer.listen(SWARM_PORT)
7166 peer.join('ssb-discovery-swarm', {announce: true}, function () {});
@@ -73,18 +68,21 @@
7368 peer.on('connection', function (connection, _info) {
7469 const info = _info;
7570 info.id = info.id.toString('ascii');
7671 info._peername = connection._peername;
77- debug('Discovery swarm found peer %s:%s', info.host, info.port);
78- const addr = `${info.host}:${info.port}:${info.id}`;
79- debug(`Connecting to SSB peer ${addr} found through discovery swarm`);
80- bot.gossip.connect(`${info.host}:${info.port}:${info.id}`, function (err) {
81- if (err) {
82- console.error(err);
83- } else {
84- debug('Successfully connected to remote SSB peer ' + addr);
85- }
86- });
72 + if (info.id.indexOf('ssb:') === 0 && info.host) {
73 + debug('Discovery swarm found peer %s:%s', info.host, info.port);
74 + const remotePublicKey = info.id.split('ssb:')[1];
75 + const addr = `${info.host}:${info.port}:${remotePublicKey}`;
76 + debug(`Connecting to SSB peer ${addr} found through discovery swarm`);
77 + bot.gossip.connect(`${info.host}:${info.port}:${remotePublicKey}`, function (err) {
78 + if (err) {
79 + console.error(err);
80 + } else {
81 + debug('Successfully connected to remote SSB peer ' + addr);
82 + }
83 + });
84 + }
8785 })
8886
8987 // Setup Express app ===========================================================
9088 const app = express();

Built with git-ssb-web