Skip to content

Commit

Permalink
quick and dirty proof of concept for sharing key on connect - thanks @…
Browse files Browse the repository at this point in the history
  • Loading branch information
e-e-e committed Jul 5, 2017
1 parent 484396c commit d878545
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
16 changes: 15 additions & 1 deletion hyperchat.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,21 @@ class Hyperchat extends events.EventEmitter {
if (err) throw err
this.emit('ready')
this.ready = true
this.swarm = hyperdiscovery(this.feed)
const archive = this.feed
this.swarm = hyperdiscovery(this.feed, {
stream: function (peer) {
const stream = archive.replicate({
live: true,
upload: true,
download: true,
userData: archive.key
})
stream.on('handshake', () => {
console.log('HANDSHAKE RECIEVER', stream.remoteUserData.toString('hex'))
})
return stream
}
})
this.swarm.once('connection', () => { this.emit('connection') })
})
}
Expand Down
17 changes: 16 additions & 1 deletion listener.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,22 @@ class Listener {

connect () {
console.log('Listening to:', this.key)
this.swarm = hyperdiscovery(this.feed)
const archive = this.feed
const receiver = this.receiver.feed
this.swarm = hyperdiscovery(this.feed, {
stream: function (peer) {
const stream = archive.replicate({
live: true,
upload: true,
download: true,
userData: receiver.key
})
stream.on('handshake', () => {
console.log('HANDSHAKE LISTENER', stream.remoteUserData.toString('hex'))
})
return stream
}
})
this.swarm.once('connection', () => {
this.lastVersion = this.feed.length
this.receiver.emit('listening', { key: this.key })
Expand Down

0 comments on commit d878545

Please sign in to comment.