diff options
| author | Chris Ball <chris@printf.net> | 2015-05-13 18:14:00 -0400 |
|---|---|---|
| committer | Chris Ball <chris@printf.net> | 2015-05-13 18:14:00 -0400 |
| commit | fc6dd65738833a3219a4ac8fbe550a0b23ef5761 (patch) | |
| tree | 968b5a68918c421dbe9abcaa57946a9f18245ef7 | |
| parent | e78082c5e3b4adc56a54d6b012c079302dfcb534 (diff) | |
Wait for the DHT to be ready
| -rwxr-xr-x | gitswarmd | 88 |
1 files changed, 45 insertions, 43 deletions
@@ -21,51 +21,53 @@ 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) { - var arr = line.toString().split(' ') - if (arr.length === 2) { - var sha = arr[0].toString() - // First four chars are git-upload-pack's length-of-line metadata. - sha = sha.substring(4) - 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, 30000, function (err) { - if (err !== null) { - console.log('Announced ' + sha) - } - }) +dht.on('ready', function () { + // 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) { + var arr = line.toString().split(' ') + if (arr.length === 2) { + var sha = arr[0].toString() + // First four chars are git-upload-pack's length-of-line metadata. + sha = sha.substring(4) + 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, 30000, 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) } }) }) - upload.stdout.on('end', function () { - console.log('end') - }) - upload.on('exit', function (code) { - if (code !== 0) { - die('Failed: ' + code) - } - }) -}) -net.createServer(function (socket) { - var wire = new Protocol() - 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)) - wire.use('ut_gitswarm') - }) -}).listen(30000) + net.createServer(function (socket) { + var wire = new Protocol() + 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)) + wire.use('ut_gitswarm') + }) + }).listen(30000) +}) |
