diff options
| author | Chris Ball <chris@printf.net> | 2015-05-26 21:58:48 -0400 |
|---|---|---|
| committer | Chris Ball <chris@printf.net> | 2015-05-26 21:58:48 -0400 |
| commit | 62575ab19c870d8925ae0e896aa55eaf1f7b0bd1 (patch) | |
| tree | 0d9c081b7e909f0b24628159ffb4f5b254bafefe /gitswarmd | |
| parent | 02d7e716a9abf07d532842222374de581319768f (diff) | |
Use JSON format in README for key file
Diffstat (limited to 'gitswarmd')
| -rwxr-xr-x | gitswarmd | 36 |
1 files changed, 20 insertions, 16 deletions
@@ -1,6 +1,5 @@ #!/usr/bin/env node -var createTorrent = require('create-torrent') var DHT = require('bittorrent-dht') var EC = require('elliptic').ec var ed25519 = new EC('ed25519') @@ -25,15 +24,18 @@ dht.listen(6882) var announcedRefs = {} var announcedRepos = {} -var keyfile = fs.readFileSync('ed25519.key').toString().split('\n') -var pub = keyfile[0] -var priv = keyfile[1] -var keypair = ed25519.keyPair({ - priv: priv, - privEnc: 'hex', - pub: pub, - pubEnc: 'hex', -}) +var key = read_keyfile() +console.log(key) + +function read_keyfile () { + var key = JSON.parse(fs.readFileSync('ed25519.key').toString()) + return ed25519.keyPair({ + priv: key.priv, + privEnc: 'hex', + pub: key.pub, + pubEnc: 'hex' + }) +} function bpad (n, buf) { if (buf.length === n) return buf @@ -45,7 +47,7 @@ function bpad (n, buf) { } } -console.log(keypair) +console.log(key) dht.on('ready', function () { // Spider all */.git dirs and announce all refs. var repos = glob.sync('*/.git/git-daemon-export-ok') @@ -95,13 +97,15 @@ dht.on('ready', function () { function publish_mutable_key () { var json = JSON.stringify(announcedRepos) - var len = json.length - var value = new Buffer(90) + if (json.length > 950) { + console.error("Can't publish mutable key: doesn't fit in 950 bytes.") + return false + } + var value = new Buffer(json.length) value.write(json) - value.fill(' ', json.length) - var sig = keypair.sign(value) + var sig = key.sign(value) var opts = { - k: bpad(32, Buffer(keypair.getPublic().x.toArray())), + k: bpad(32, Buffer(key.getPublic().x.toArray())), seq: 0, v: value, sig: Buffer.concat([ |
