-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 291002c
Showing
7 changed files
with
3,274 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
## Collaborators | ||
|
||
hyperdrive-archive-swarm is only possible due to the excellent work of the following collaborators: | ||
|
||
<table><tbody><tr><th align="left">juliangruber</th><td><a href="https://github.com/juliangruber">GitHub/juliangruber</a></td></tr> | ||
<tr><th align="left">karissa</th><td><a href="https://github.com/karissa">GitHub/karissa</a></td></tr> | ||
<tr><th align="left">ogd</th><td><a href="https://github.com/ogd">GitHub/ogd</a></td></tr> | ||
<tr><th align="left">laurengarcia</th><td><a href="https://github.com/laurengarcia">GitHub/laurengarcia</a></td></tr> | ||
</tbody></table> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
var hyperdrive = require('hyperdrive') | ||
var ram = require('random-access-memory') | ||
var swarm = require('.') | ||
var Buffer = require('safe-buffer').Buffer | ||
|
||
var key = process.argv[2] && new Buffer(process.argv[2], 'hex') | ||
var archive = hyperdrive(ram, key) | ||
archive.ready(function (err) { | ||
if (err) throw err | ||
console.log('key', archive.key.toString('hex')) | ||
var sw = swarm(archive) | ||
sw.on('connection', function (peer, type) { | ||
console.log('got', peer, type) // type is 'webrtc-swarm' or 'discovery-swarm' | ||
console.log('connected to', sw.connections, 'peers') | ||
peer.on('close', function () { | ||
console.log('peer disconnected') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
var swarmDefaults = require('dat-swarm-defaults') | ||
var disc = require('discovery-swarm') | ||
var xtend = require('xtend') | ||
|
||
module.exports = HyperdriveSwarm | ||
|
||
function HyperdriveSwarm (archive, opts) { | ||
if (!(this instanceof HyperdriveSwarm)) return new HyperdriveSwarm(archive, opts) | ||
if (!opts) opts = {} | ||
|
||
var self = this | ||
this.archive = archive | ||
this.uploading = !(opts.upload === false) | ||
this.downloading = !(opts.download === false) | ||
this.live = !(opts.live === false) | ||
|
||
var isHyperdbInstance = !!(archive.get && archive.put && archive.replicate && archive.authorize) | ||
|
||
if (isHyperdbInstance && !archive.local) { | ||
throw new Error('hyperdiscovery swarm must be created after the local hyperdb instance is ready!') | ||
} | ||
|
||
// Discovery Swarm Options | ||
opts = xtend({ | ||
port: 3282, | ||
id: isHyperdbInstance ? archive.local.id.toString('hex') : archive.id, | ||
hash: false, | ||
stream: function (peer) { | ||
return archive.replicate(xtend({ | ||
live: self.live, | ||
upload: self.uploading, | ||
download: self.downloading | ||
}, isHyperdbInstance ? { | ||
userData: archive.local.key | ||
} : {})) | ||
} | ||
}, opts) | ||
|
||
this.swarm = disc(swarmDefaults(opts)) | ||
this.swarm.once('error', function () { | ||
self.swarm.listen(0) | ||
}) | ||
|
||
this.swarm.listen(opts.port) | ||
this.swarm.join(this.archive.discoveryKey) | ||
return this.swarm | ||
} |
Oops, something went wrong.