This repository was archived by the owner on Feb 12, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 16 files changed +199
-1
lines changed Expand file tree Collapse file tree 16 files changed +199
-1
lines changed Original file line number Diff line number Diff line change @@ -40,3 +40,4 @@ test/test-data/go-ipfs-repo/LOG.old
4040
4141# while testing npm5
4242package-lock.json
43+ yarn.lock
Original file line number Diff line number Diff line change 1111 "./src/core/runtime/config-nodejs.json" : " ./src/core/runtime/config-browser.json" ,
1212 "./src/core/runtime/libp2p-nodejs.js" : " ./src/core/runtime/libp2p-browser.js" ,
1313 "./src/core/runtime/repo-nodejs.js" : " ./src/core/runtime/repo-browser.js" ,
14+ "./src/core/runtime/dns-nodejs.js" : " ./src/core/runtime/dns-browser.js" ,
1415 "./test/utils/create-repo-nodejs.js" : " ./test/utils/create-repo-browser.js" ,
1516 "stream" : " readable-stream"
1617 },
Original file line number Diff line number Diff line change 1+ 'use strict'
2+ const print = require ( '../utils' ) . print
3+
4+ module . exports = {
5+ command : 'dns <domain>' ,
6+
7+ describe : 'Resolve DNS links' ,
8+
9+ builder : {
10+ format : {
11+ type : 'string'
12+ }
13+ } ,
14+
15+ handler ( argv ) {
16+ argv . ipfs . dns ( argv [ 'domain' ] , ( err , path ) => {
17+ if ( err ) {
18+ throw err
19+ }
20+
21+ print ( path )
22+ } )
23+ }
24+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ // dns-nodejs gets replaced by dns-browser when webpacked/browserified
4+ const dns = require ( '../runtime/dns-nodejs' )
5+ const promisify = require ( 'promisify-es6' )
6+
7+ module . exports = ( ) => {
8+ return promisify ( ( domain , opts , callback ) => {
9+ if ( typeof domain !== 'string' ) {
10+ return callback ( new Error ( 'Invalid arguments, domain must be a string' ) )
11+ }
12+
13+ if ( typeof opts === 'function' ) {
14+ callback = opts
15+ opts = { }
16+ }
17+
18+ dns ( domain , opts , callback )
19+ } )
20+ }
Original file line number Diff line number Diff line change @@ -20,3 +20,4 @@ exports.files = require('./files')
2020exports . bitswap = require ( './bitswap' )
2121exports . pubsub = require ( './pubsub' )
2222exports . dht = require ( './dht' )
23+ exports . dns = require ( './dns' )
Original file line number Diff line number Diff line change @@ -94,6 +94,7 @@ class IPFS extends EventEmitter {
9494 this . ping = components . ping ( this )
9595 this . pubsub = components . pubsub ( this )
9696 this . dht = components . dht ( this )
97+ this . dns = components . dns ( this )
9798
9899 if ( this . _options . EXPERIMENTAL . pubsub ) {
99100 this . log ( 'EXPERIMENTAL pubsub is enabled' )
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ module . exports = ( domain , opts , callback ) => {
4+ domain = encodeURIComponent ( domain )
5+ let url = `https://ipfs.io/api/v0/dns?arg=${ domain } `
6+
7+ for ( const prop in opts ) {
8+ url += `&${ prop } =${ opts [ prop ] } `
9+ }
10+
11+ window . fetch ( url , { mode : 'cors' } )
12+ . then ( ( response ) => {
13+ return response . json ( )
14+ } )
15+ . then ( ( response ) => {
16+ if ( response . Path ) {
17+ return callback ( null , response . Path )
18+ } else {
19+ return callback ( new Error ( response . Message ) )
20+ }
21+ } )
22+ . catch ( ( error ) => {
23+ callback ( error )
24+ } )
25+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const dns = require ( 'dns' )
4+
5+ module . exports = ( domain , opts , callback ) => {
6+ dns . resolveTxt ( domain , ( err , records ) => {
7+ if ( err ) {
8+ return callback ( err , null )
9+ }
10+
11+ // TODO: implement recursive option
12+
13+ for ( const record of records ) {
14+ if ( record [ 0 ] . startsWith ( 'dnslink=' ) ) {
15+ return callback ( null , record [ 0 ] . substr ( 8 , record [ 0 ] . length - 1 ) )
16+ }
17+ }
18+
19+ callback ( new Error ( 'domain does not have a txt dnslink entry' ) )
20+ } )
21+ }
Original file line number Diff line number Diff line change 1+ 'use strict'
2+
3+ const boom = require ( 'boom' )
4+
5+ exports = module . exports
6+
7+ exports . get = ( request , reply ) => {
8+ if ( ! request . query . arg ) {
9+ return reply ( {
10+ Message : "Argument 'domain' is required" ,
11+ Code : 0
12+ } ) . code ( 400 ) . takeover ( )
13+ }
14+
15+ request . server . app . ipfs . dns ( request . query . arg , ( err , path ) => {
16+ if ( err ) {
17+ return reply ( boom . badRequest ( err ) )
18+ }
19+
20+ return reply ( {
21+ Path : path
22+ } )
23+ } )
24+ }
Original file line number Diff line number Diff line change @@ -12,3 +12,4 @@ exports.bitswap = require('./bitswap')
1212exports . file = require ( './file' )
1313exports . files = require ( './files' )
1414exports . pubsub = require ( './pubsub' )
15+ exports . dns = require ( './dns' )
You can’t perform that action at this time.
0 commit comments