Skip to content

Commit

Permalink
feat: Use rendezvous in peer-pad
Browse files Browse the repository at this point in the history
Requires patches from mkg20001/js-ipfs#feat/rendezvou applied to
js-ipfsfor now
  • Loading branch information
mkg20001 committed Jun 12, 2018
1 parent ecb6d2a commit a9c830f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const generateSymmetricalKey = require('./keys').generateSymmetrical
const awaitIpfsInit = require('./await-ipfs-init')
const Network = require('./network')
const migrateIpfsRepoIfNecessary = require('./migrate-ipfs-repo-if-necessary')
const crypto = require('crypto')
const dblSha256 = (data) => crypto.createHash('sha256').update(crypto.createHash('sha256').update(data).digest()).digest('hex')

class Backend extends EventEmitter {
constructor (options) {
Expand All @@ -28,6 +30,7 @@ class Backend extends EventEmitter {

async start () {
const options = this._options
this.padId = 'pad#' + dblSha256(options.readKey) // hash readKey so we don't give the rendezvous access by registering with it as id

// ---- start js-ipfs

Expand All @@ -41,6 +44,11 @@ class Backend extends EventEmitter {

// if IPFS node is not online yet, delay the start until it is
await awaitIpfsInit(this.ipfs)
this.ipfs.rendezvous.register(this.padId) // register on pad namespace for discovery
this.ipfs.rendezvous.on('ns:' + this.padId, peer => { // HACK: should discover over libp2p discovery instead
console.log('discovered peer %s', peer.multiaddrs.toArray().map(String).join(', '))
this.ipfs._libp2pNode.dial(peer, console.log)
})

// ---- initialize keys
this._keys = await parseKeys(b58Decode(options.readKey), options.writeKey && b58Decode(options.writeKey))
Expand Down
5 changes: 4 additions & 1 deletion src/backend/ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,14 @@ function maybeCreateIPFS (_ipfs) {
ipfs = new IPFS({
EXPERIMENTAL: {
pubsub: true
pubsub: true,
relay: {
enabled: true
}
},
config: {
Addresses: {
Swarm: [
'/dns4/ws-star1.par.dwebops.pub/tcp/443/wss/p2p-websocket-star'
]
}
}
Expand Down

0 comments on commit a9c830f

Please sign in to comment.