diff options
| author | Chris Ball <chris@printf.net> | 2015-05-04 14:12:20 -0400 |
|---|---|---|
| committer | Chris Ball <chris@printf.net> | 2015-05-04 14:50:25 -0400 |
| commit | 3eeaa7bfd8d0a40a175d77203d12edb29d586cd6 (patch) | |
| tree | ea810c9e87906fa8fadee2977321e043e3b22a88 /gitswarmd | |
Initial commits
Diffstat (limited to 'gitswarmd')
| -rwxr-xr-x | gitswarmd | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/gitswarmd b/gitswarmd new file mode 100755 index 0000000..960b4d8 --- /dev/null +++ b/gitswarmd @@ -0,0 +1,55 @@ +#!/usr/bin/env node + +var spawn = require('child_process').spawn +var glob = require('glob') +var WebTorrent = require('webtorrent') +var DHT = require('bittorrent-dht') + +function die (error) { + console.error(error) + process.exit(1) +} + +var dht = new DHT({ + bootstrap: ['three.printf.net:6881'] +}) +dht.listen(20000) + +var announcedRefs = {} + +// Spider all */.git dirs and announce all refs. +var repos = glob.sync('*/.git/git-daemon-export-ok') +repos.forEach(function (repo) { + console.log('in repo ' + repo) + repo = repo.replace(/git-daemon-export-ok$/, '') + console.log(repo) + var upload = spawn('git-upload-pack', ['--strict', repo]) + upload.stdout.on('data', function (line) { + var lines = line.toString().split('\n') + lines.forEach(function (line) { + arr = line.toString().split(' ') + if (arr.length == 2) { + var sha = arr[0].toString() + var ref = arr[1].toString() + if (ref.search(/^refs\/heads\//) !== -1 || ref.search(/^refs\/remotes\//) !== -1) { + console.log('Announcing ' + sha + ' for ref ' + ref + ' on repo ' + repo) + announcedRefs[sha] = repo + console.log(announcedRefs) + dht.announce(sha, 20000, function (err) { + if (err !== null) + console.log('Announced ' + sha) + }) + } + } + }) + }) + upload.stdout.on('end', function () { + console.log('end') + }) + upload.on('exit', function (code) { + if (code != 0) + die('Failed: ' + code) + }) +}) + + |
