Skip to content

Commit dc9d2df

Browse files
committed
feat: Use rendezvous in peer-pad
Requires patches from mkg20001/js-ipfs#feat/rendezvou applied to js-ipfs for now
1 parent ecb6d2a commit dc9d2df

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/backend/index.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ const generateSymmetricalKey = require('./keys').generateSymmetrical
1212
const awaitIpfsInit = require('./await-ipfs-init')
1313
const Network = require('./network')
1414
const migrateIpfsRepoIfNecessary = require('./migrate-ipfs-repo-if-necessary')
15+
const crypto = require('crypto')
16+
const dblSha256 = (data) => crypto.createHash('sha256').update(crypto.createHash('sha256').update(data).digest()).digest('hex')
1517

1618
class Backend extends EventEmitter {
1719
constructor (options) {
@@ -28,6 +30,7 @@ class Backend extends EventEmitter {
2830

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

3235
// ---- start js-ipfs
3336

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

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

4553
// ---- initialize keys
4654
this._keys = await parseKeys(b58Decode(options.readKey), options.writeKey && b58Decode(options.writeKey))

src/backend/ipfs.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ function maybeCreateIPFS (_ipfs) {
2222
console.log('creating IPFS')
2323
ipfs = new IPFS({
2424
EXPERIMENTAL: {
25-
pubsub: true
25+
pubsub: true,
26+
relay: {
27+
enabled: true
28+
}
2629
},
2730
config: {
2831
Addresses: {
2932
Swarm: [
30-
'/dns4/ws-star1.par.dwebops.pub/tcp/443/wss/p2p-websocket-star'
3133
]
3234
}
3335
}

0 commit comments

Comments
 (0)