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

feat/id #39

Merged
merged 2 commits into from
Dec 11, 2015
Merged
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
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()
})
})
})