Commit 2f5e366ed4730353ef624eaca74ad09d79944654
Fix detection of peer from discovery-swarm
Andre Staltz committed on 2/28/2017, 1:00:20 PMParent: 02fa1bcfc3a0826a69118454100ee777075c1b3b
Files changed
src/index.ts | changed |
src/index.ts | ||
---|---|---|
@@ -42,13 +42,8 @@ | ||
42 | 42 … | size: number; |
43 | 43 … | path: string; |
44 | 44 … | } |
45 | 45 … | |
46 | -interface BotIdentity { | |
47 | - id: string; | |
48 | - qr: QRSVG; | |
49 | -} | |
50 | - | |
51 | 46 … | const idQR = qr.svgObject(bot.id); |
52 | 47 … | |
53 | 48 … | bot.address((err, addr) => { |
54 | 49 … | if (err) { |
@@ -63,9 +58,9 @@ | ||
63 | 58 … | // Setup Discovery Swarm ======================================================= |
64 | 59 … | var peer = swarm({ |
65 | 60 … | maxConnections: 1000, |
66 | 61 … | utp: true, |
67 | - id: bot.id, | |
62 … | + id: 'ssb:' + bot.id, | |
68 | 63 … | }); |
69 | 64 … | |
70 | 65 … | peer.listen(SWARM_PORT) |
71 | 66 … | peer.join('ssb-discovery-swarm', {announce: true}, function () {}); |
@@ -73,18 +68,21 @@ | ||
73 | 68 … | peer.on('connection', function (connection, _info) { |
74 | 69 … | const info = _info; |
75 | 70 … | info.id = info.id.toString('ascii'); |
76 | 71 … | 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 … | + } | |
87 | 85 … | }) |
88 | 86 … | |
89 | 87 … | // Setup Express app =========================================================== |
90 | 88 … | const app = express(); |
Built with git-ssb-web