osmia-consent-swarm
v1.0.1
Published
discovery-swarm with consent to upgrade to data transfer
Downloads
3
Maintainers
Readme
consent-swarm
discovery-swarm with two-way replication consent
npm install consent-swarm
Usage
var swarm = require('consent-swarm')
var sw = swarm()
sw.listen(1000)
sw.join('ubuntu-14.04') // can be any id/name/hash
sw.on('connection', function (connection) {
// here the client can send some data that might help the user
// make a decision if they want to continue the connection
// or only replicate parts of the data
connection.request({message: 'im-cool'})
connection.on('request', function (data) {
if (data.message === 'im-cool') {
connection.accept({message: 'ok sure'})
} else {
connection.reject({message: 'nope'})
}
})
connection.on('reject', function (data) {
console.log('rejected! reason:', data.message)
})
connection.on('accept', function (data) {
connection.write('some more stuff now, thanks for the consent buddy\n')
})
console.log('found + connected to peer')
})
sw.on('error', function (err) {
console.error(err)
})