File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ const generateSymmetricalKey = require('./keys').generateSymmetrical
1212const awaitIpfsInit = require ( './await-ipfs-init' )
1313const Network = require ( './network' )
1414const 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
1618class 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 ) )
Original file line number Diff line number Diff 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 }
You can’t perform that action at this time.
0 commit comments