Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Use rendezvous in peer-pad
Requires patches from mkg20001/js-ipfs#feat/rendezvou applied to js-ipfs
for now
  • Loading branch information
mkg20001 committed Jun 12, 2018
commit dc9d2df69d6c6b4e08d9ee63d3d5ab459af163ca
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
6 changes: 4 additions & 2 deletions src/backend/ipfs.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@ function maybeCreateIPFS (_ipfs) {
console.log('creating 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