aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Ball <chris@printf.net>2015-05-28 16:27:20 +0000
committerChris Ball <chris@printf.net>2015-05-28 17:04:55 +0000
commita98d0d58d7c699fa8b6e06883b8099e3a94f5bb0 (patch)
tree36d986c7e86bf444061dae9266177027cdd6c38a
parentd6eb750fe77bd29ae3392ba9ae4e20b66e0c2493 (diff)
Create peerId properly/randomly
-rwxr-xr-xgit-remote-gittorrent13
1 files changed, 12 insertions, 1 deletions
diff --git a/git-remote-gittorrent b/git-remote-gittorrent
index ef74a21..ea1bc38 100755
--- a/git-remote-gittorrent
+++ b/git-remote-gittorrent
@@ -4,12 +4,22 @@ var Chalk = require('chalk')
var DHT = require('bittorrent-dht')
var exec = require('child_process').exec
var fs = require('fs')
+var hat = require('hat')
var magnet = require('magnet-uri')
var prettyjson = require('prettyjson')
var spawn = require('child_process').spawn
var Swarm = require('bittorrent-swarm')
var ut_gittorrent = require('ut_gittorrent')
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)
@@ -92,7 +102,8 @@ function get_infohash (ref) {
swarm.addPeer(addr)
})
- var swarm = new Swarm(parsed.infoHash, 'cafebabecafebabecafecafebabecafebabecafe')
+ var peerId = new Buffer('-WW' + VERSION + '-' + hat(48), 'utf8')
+ var swarm = new Swarm(parsed.infoHash, peerId)
swarm.on('wire', function (wire, addr) {
console.warn('Adding swarm peer: ' + chalk.green(addr) + '\n')
wire.use(ut_gittorrent())