diff options
| author | Chris Ball <chris@printf.net> | 2015-05-29 12:17:00 -0400 |
|---|---|---|
| committer | Chris Ball <chris@printf.net> | 2015-05-29 12:17:00 -0400 |
| commit | 5cf08cb421526181eb41e4db0e33508fbe9b887e (patch) | |
| tree | a0f362c0d85d47be567c710241e5f211265a1069 | |
| parent | 71169788e850b9de658359f89c2fa191b22f9b45 (diff) | |
gittorrentd: Use a random peerId on handshake, else swarm disconnects
| -rwxr-xr-x | gittorrentd | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/gittorrentd b/gittorrentd index c6065bf..e584b14 100755 --- a/gittorrentd +++ b/gittorrentd @@ -6,12 +6,22 @@ var ed25519 = new EC('ed25519') var exec = require('child_process').exec var glob = require('glob') var fs = require('fs') +var hat = require('hat') var net = require('net') var Protocol = require('bittorrent-protocol') var spawn = require('child_process').spawn var ut_gittorrent = require('ut_gittorrent') var ut_metadata = require('ut_metadata') var WebTorrent = require('webtorrent') +var zeroFill = require('zero-fill') + +// BitTorrent client version string (used in peer ID). +// Generated from package.json major and minor version. For example: +// '0.16.1' -> '0016' +// '1.2.5' -> '0102' +// +var VERSION = require('./package.json').version + .match(/([0-9]+)/g).slice(0, 2).map(zeroFill(2)).join('') function die (error) { console.error(error) @@ -160,7 +170,8 @@ dht.on('ready', function () { socket.pipe(wire).pipe(socket) wire.on('handshake', function (infoHash, peerId) { console.log('Received handshake for ' + infoHash) - wire.handshake(new Buffer(infoHash), new Buffer(peerId)) + var myPeerId = new Buffer('-WW' + VERSION + '-' + hat(48), 'utf8') + wire.handshake(new Buffer(infoHash), new Buffer(myPeerId)) }) wire.ut_gittorrent.on('generatePack', function (sha) { console.error('calling git pack-objects') |
