Skip to content
This repository was archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
Merge pull request #39 from ipfs/feat/id
Browse files Browse the repository at this point in the history
feat/id
  • Loading branch information
daviddias committed Dec 11, 2015
2 parents 45b30b9 + 91a358f commit 540cfa4
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 10 deletions.
20 changes: 18 additions & 2 deletions src/cli/commands/id.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
var Command = require('ronin').Command
var IPFS = require('../../ipfs-core')

module.exports = Command.extend({
desc: '',
desc: 'Shows IPFS Node ID info',

run: function (name) {}
options: {
format: {
alias: 'f',
type: 'string'
}
},

run: function (name) {
var node = new IPFS()
node.id(function (err, id) {
if (err) {
return console.error(err)
}
console.log(id)
})
}
})
37 changes: 29 additions & 8 deletions src/ipfs-core/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,7 @@ function IPFS () {
callback = opts
opts = {}
}

if (!repo.exists()) {
callback(new Error('Repo does not exist, you must init repo first'))
} else { repo.load() }
repoExists(callback)

repo.config.read(function (err, config) {
if (err) {
Expand All @@ -54,7 +51,27 @@ function IPFS () {
})
}

self.id = function (format, callback) {}
self.id = function (opts, callback) {
if (typeof opts === 'function') {
callback = opts
opts = {}
}
repoExists(callback)

repo.config.read(function (err, config) {
if (err) {
return callback(err)
}
callback(null, {
ID: config.Identity.PeerID,
// TODO needs https://github.com/diasdavid/js-peer-id/blob/master/src/index.js#L76
PublicKey: '',
Addresses: config.Addresses,
AgentVersion: 'js-ipfs',
ProtocolVersion: '9000'
})
})
}

self.repo = {
init: function (bits, force, empty, callback) {
Expand All @@ -66,13 +83,17 @@ function IPFS () {
callback = opts
opts = {}
}
if (!repo.exists()) {
callback(new Error('Repo does not exist, you must init repo first'))
} else { repo.load() }
repoExists(callback)

repo.version.read(callback)
},

gc: function () {}
}

function repoExists (callback) {
if (!repo.exists()) {
callback(new Error('Repo does not exist, you must init repo first'))
} else { repo.load() }
}
}
8 changes: 8 additions & 0 deletions tests/jsipfs-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,12 @@ describe('IPFS Repo Tests', function () {
done()
})
})

it('check id info', function (done) {
node.id(function (err, id) {
expect(err).to.equal(null)
expect(id).to.be.a('object')
done()
})
})
})

0 comments on commit 540cfa4

Please sign in to comment.