aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Ball <chris@printf.net>2015-05-26 21:58:48 -0400
committerChris Ball <chris@printf.net>2015-05-26 21:58:48 -0400
commit62575ab19c870d8925ae0e896aa55eaf1f7b0bd1 (patch)
tree0d9c081b7e909f0b24628159ffb4f5b254bafefe
parent02d7e716a9abf07d532842222374de581319768f (diff)
Use JSON format in README for key file
-rwxr-xr-xgit-remote-gitswarm4
-rwxr-xr-xgitswarmd36
2 files changed, 22 insertions, 18 deletions
diff --git a/git-remote-gitswarm b/git-remote-gitswarm
index 20f9000..8b405e0 100755
--- a/git-remote-gitswarm
+++ b/git-remote-gitswarm
@@ -29,7 +29,7 @@ if (matches) {
var reponame = matches[2]
dht.on('ready', function () {
var val = new Buffer(key, 'hex')
- dht.get(val, function(err, res) {
+ dht.get(val, function (err, res) {
if (err) {
return console.error(err)
}
@@ -69,7 +69,7 @@ function get_infohash (ref) {
console.warn('\nOkay, we want to get: ' + chalk.green(ref) + '\n')
process.stdin.setEncoding('utf8')
- process.stdin.on('readable', function() {
+ process.stdin.on('readable', function () {
var chunk = process.stdin.read()
if (chunk === 'capabilities\n') {
process.stdout.write('fetch\n\n')
diff --git a/gitswarmd b/gitswarmd
index c3feee6..ed1ff9d 100755
--- a/gitswarmd
+++ b/gitswarmd
@@ -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([