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

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ipfs/js-ipfs
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 2bcc8b7e2ea0
Choose a base ref
...
head repository: ipfs/js-ipfs
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7bd46d0e7e11
Choose a head ref
  • 7 commits
  • 95 files changed
  • 1 contributor

Commits on Jul 3, 2015

  1. peer ID module

    daviddias committed Jul 3, 2015

    Verified

    This commit was signed with the committer’s verified signature.
    so1ve Ray
    Copy the full SHA
    8a9b111 View commit details

Commits on Jul 5, 2015

  1. Copy the full SHA
    e824612 View commit details
  2. Copy the full SHA
    3bd3a0f View commit details
  3. add logging to discovery

    daviddias committed Jul 5, 2015
    Copy the full SHA
    975893a View commit details

Commits on Jul 6, 2015

  1. Copy the full SHA
    195e051 View commit details
  2. Copy the full SHA
    0c34ad5 View commit details

Commits on Aug 25, 2015

  1. deprecate this repo

    daviddias committed Aug 25, 2015
    Copy the full SHA
    7bd46d0 View commit details
Showing with 433 additions and 7 deletions.
  1. +2 −1 .gitignore
  2. +9 −2 README.md
  3. 0 Makefile → legacy-Makefile
  4. 0 index.js → legacy-index.js
  5. 0 {submodules → legacy-submodules}/README.md
  6. 0 {submodules → legacy-submodules}/ipfs-bitswap/index.js
  7. 0 {submodules → legacy-submodules}/ipfs-block/README.md
  8. 0 {submodules → legacy-submodules}/ipfs-block/index.js
  9. 0 {submodules → legacy-submodules}/ipfs-block/package.json
  10. 0 {submodules → legacy-submodules}/ipfs-blocks/README.md
  11. 0 {submodules → legacy-submodules}/ipfs-blocks/index.js
  12. 0 {submodules → legacy-submodules}/ipfs-blocks/package.json
  13. 0 {submodules → legacy-submodules}/ipfs-cli/README.md
  14. 0 {submodules → legacy-submodules}/ipfs-cli/add.js
  15. 0 {submodules → legacy-submodules}/ipfs-cli/cat.js
  16. 0 {submodules → legacy-submodules}/ipfs-cli/cli.js
  17. 0 {submodules → legacy-submodules}/ipfs-cli/index.js
  18. 0 {submodules → legacy-submodules}/ipfs-cli/ls.js
  19. 0 {submodules → legacy-submodules}/ipfs-cli/mount.js
  20. 0 {submodules → legacy-submodules}/ipfs-cli/package.json
  21. 0 {submodules → legacy-submodules}/ipfs-cli/refs.js
  22. 0 {submodules → legacy-submodules}/ipfs-core/index.js
  23. 0 {submodules → legacy-submodules}/ipfs-core/package.json
  24. 0 {submodules → legacy-submodules}/ipfs-core/try/ipfs-nc.js
  25. 0 {submodules → legacy-submodules}/ipfs-dht-routing/index.js
  26. 0 {submodules → legacy-submodules}/ipfs-dht/index.js
  27. 0 {submodules → legacy-submodules}/ipfs-dht/js/routing-table.js
  28. 0 {submodules → legacy-submodules}/ipfs-dht/package.json
  29. 0 {submodules → legacy-submodules}/ipfs-errors/index.js
  30. 0 {submodules → legacy-submodules}/ipfs-message/README.md
  31. 0 {submodules → legacy-submodules}/ipfs-message/index.js
  32. 0 {submodules → legacy-submodules}/ipfs-message/message.proto
  33. 0 {submodules → legacy-submodules}/ipfs-message/test.js
  34. 0 {submodules → legacy-submodules}/ipfs-mount/README.md
  35. 0 {submodules → legacy-submodules}/ipfs-mount/cli.js
  36. 0 {submodules → legacy-submodules}/ipfs-mount/destroy.js
  37. 0 {submodules → legacy-submodules}/ipfs-mount/fuse.js
  38. 0 {submodules → legacy-submodules}/ipfs-mount/index.js
  39. 0 {submodules → legacy-submodules}/ipfs-mount/package.json
  40. 0 {submodules → legacy-submodules}/ipfs-mount/umount.js
  41. 0 {submodules → legacy-submodules}/ipfs-network-pipe/README.md
  42. 0 {submodules → legacy-submodules}/ipfs-network-pipe/addr.js
  43. 0 {submodules → legacy-submodules}/ipfs-network-pipe/index.js
  44. 0 {submodules → legacy-submodules}/ipfs-network-pipe/package.json
  45. 0 {submodules → legacy-submodules}/ipfs-network-pipe/scoped-pair.js
  46. 0 {submodules → legacy-submodules}/ipfs-network-pipe/test.js
  47. 0 {submodules → legacy-submodules}/ipfs-network-pipe/wire.js
  48. 0 {submodules → legacy-submodules}/ipfs-network/README.md
  49. 0 {submodules → legacy-submodules}/ipfs-network/index.js
  50. 0 {submodules → legacy-submodules}/ipfs-network/test.js
  51. 0 {submodules → legacy-submodules}/ipfs-object/README.md
  52. 0 {submodules → legacy-submodules}/ipfs-object/index.js
  53. 0 {submodules → legacy-submodules}/ipfs-object/object.proto
  54. 0 {submodules → legacy-submodules}/ipfs-object/package.json
  55. 0 {submodules → legacy-submodules}/ipfs-object/test.js
  56. 0 {submodules → legacy-submodules}/ipfs-objects-git/README.md
  57. 0 {submodules → legacy-submodules}/ipfs-objects-git/block.js
  58. 0 {submodules → legacy-submodules}/ipfs-objects-git/commit.js
  59. 0 {submodules → legacy-submodules}/ipfs-objects-git/git-objects.proto
  60. 0 {submodules → legacy-submodules}/ipfs-objects-git/index.js
  61. 0 {submodules → legacy-submodules}/ipfs-objects-git/list.js
  62. 0 {submodules → legacy-submodules}/ipfs-objects-git/package.json
  63. 0 {submodules → legacy-submodules}/ipfs-objects-git/test.js
  64. 0 {submodules → legacy-submodules}/ipfs-objects-git/tree.js
  65. 0 {submodules → legacy-submodules}/ipfs-objects-git/types.js
  66. 0 {submodules → legacy-submodules}/ipfs-path-resolver/README.md
  67. 0 {submodules → legacy-submodules}/ipfs-path-resolver/index.js
  68. 0 {submodules → legacy-submodules}/ipfs-path-resolver/package.json
  69. 0 {submodules → legacy-submodules}/ipfs-path-resolver/test.js
  70. 0 {submodules → legacy-submodules}/ipfs-path/README.md
  71. 0 {submodules → legacy-submodules}/ipfs-path/index.js
  72. 0 {submodules → legacy-submodules}/ipfs-path/package.json
  73. 0 {submodules → legacy-submodules}/ipfs-path/test.js
  74. 0 {submodules → legacy-submodules}/ipfs-peer-book/README.md
  75. 0 {submodules → legacy-submodules}/ipfs-peer-book/index.js
  76. 0 {submodules → legacy-submodules}/ipfs-peer-book/package.json
  77. 0 {submodules → legacy-submodules}/ipfs-peer-book/test.js
  78. 0 {submodules → legacy-submodules}/ipfs-peer/README.md
  79. 0 {submodules → legacy-submodules}/ipfs-peer/index.js
  80. 0 {submodules → legacy-submodules}/ipfs-peer/package.json
  81. 0 {submodules → legacy-submodules}/ipfs-peer/test.js
  82. 0 {submodules → legacy-submodules}/ipfs-storage/README.md
  83. 0 {submodules → legacy-submodules}/ipfs-storage/index.js
  84. 0 {submodules → legacy-submodules}/ipfs-storage/package.json
  85. 0 {submodules → legacy-submodules}/ipfs-storage/test.js
  86. 0 {submodules → legacy-submodules}/npm-install.sh
  87. +17 −4 package.json
  88. +5 −0 src/index.js
  89. +107 −0 src/routing/discovery/mdns/index.js
  90. +76 −0 src/routing/index.js
  91. +46 −0 src/routing/routers/dht/index.js
  92. +79 −0 src/routing/routers/dht/peer/id.js
  93. +22 −0 src/routing/routers/dht/peer/index.js
  94. +20 −0 src/utils/ipfs-logger/package.json
  95. +50 −0 src/utils/ipfs-logger/src/index.js
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules/
**/node_modules/
**/*.log
11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
# ipfs implementation in node.
# THIS REPO IS DEPRECATED

### Check the new node-ipfs roadmap and respective code at: https://github.com/ipfs/node-ipfs

# This is a work in progress. it's not ready yet. we'll be pushing efforts into this implementation shortly. stay tuned + come hang out on irc.

===================================




> This is a work in progress. it's not ready yet. we'll be pushing efforts into this implementation shortly. stay tuned + come hang out on irc.
`#ipfs` on freenode.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
21 changes: 17 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{
"name": "ipfs",
"version": "0.1.1",
"version": "0.0.0",
"description": "ipfs implementation in node",
"main": "index.js",
"main": "src/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"start": "IPFS_LOG=* node src/index.js | ./node_modules/.bin/bunyan -o short"
},
"repository": {
"type": "git",
@@ -18,5 +19,17 @@
"bugs": {
"url": "https://github.com/jbenet/node-ipfs/issues"
},
"homepage": "https://github.com/jbenet/node-ipfs"
"homepage": "https://github.com/jbenet/node-ipfs",
"devDependencies": {
"standard": "^4.5.1"
},
"dependencies": {
"bs58": "^2.0.1",
"bunyan": "^1.4.0",
"k-bucket": "^0.5.0",
"multiaddr": "^0.1.2",
"multicast-dns": "^2.2.0",
"multihashing": "^0.1.2",
"network": "^0.1.3"
}
}
5 changes: 5 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var Routing = require('./routing')

var r = new Routing()

r.start()
107 changes: 107 additions & 0 deletions src/routing/discovery/mdns/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
var mdns = require('multicast-dns')()
var Id = require('./../../routers/dht/peer/id')
var Peer = require('./../../routers/dht/peer')
var Multiaddr = require('multiaddr')
var log = require('ipfs-logger').group('discovery')

exports = module.exports = sonar

function sonar (cb) {
var serviceTag = 'discovery.ipfs.io.local'

mdns.on('warning', function (err) {
cb(err)
})

mdns.on('response', function (response) {
if (!response.answers) {
return
}

var answers = {
ptr: {},
srv: {},
txt: {},
a: []
}

response.answers.forEach(function (answer) {
switch (answer.type) {
case 'PTR': answers.ptr = answer; break
case 'SRV': answers.srv = answer; break
case 'TXT': answers.txt = answer; break
case 'A': answers.a.push(answer); break
default: break
}
})

if (answers.ptr.name !== serviceTag) {
return
}

var b58Id = answers.txt.data
var port = answers.srv.data.port
var multiaddrs = []

answers.a.forEach(function (a) {
multiaddrs.push(new Multiaddr('/ip4/' + a.data + '/tcp/' + port))
})

log.info('peer found -', b58Id)
var peerId = Id.createFromB58String(b58Id)
cb(null, new Peer(peerId, multiaddrs))
})

mdns.on('query', function (query) {
// answer with PTR, SRV and A for several IP addr
})

setInterval(function () {
mdns.query({
questions: [{
name: serviceTag,
type: 'PTR'
}]
})
}, 1e3 * 5)
}

/* for reference
[ { name: 'discovery.ipfs.io.local',
type: 'PTR',
class: 1,
ttl: 120,
data: 'QmbBHw1Xx9pUpAbrVZUKTPL5Rsph5Q9GQhRvcWVBPFgGtC.discovery.ipfs.io.local' },
{ name: 'QmbBHw1Xx9pUpAbrVZUKTPL5Rsph5Q9GQhRvcWVBPFgGtC.discovery.ipfs.io.local',
type: 'SRV',
class: 1,
ttl: 120,
data: { priority: 10, weight: 1, port: 4001, target: 'lorien.local' } },
{ name: 'lorien.local',
type: 'A',
class: 1,
ttl: 120,
data: '127.0.0.1' },
{ name: 'lorien.local',
type: 'A',
class: 1,
ttl: 120,
data: '127.94.0.1' },
{ name: 'lorien.local',
type: 'A',
class: 1,
ttl: 120,
data: '172.16.38.224' },
{ name: 'QmbBHw1Xx9pUpAbrVZUKTPL5Rsph5Q9GQhRvcWVBPFgGtC.discovery.ipfs.io.local',
type: 'TXT',
class: 1,
ttl: 120,
data: 'QmbBHw1Xx9pUpAbrVZUKTPL5Rsph5Q9GQhRvcWVBPFgGtC' } ],
*/
76 changes: 76 additions & 0 deletions src/routing/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* routing/index.js Routing is the front door for everything that happens on the routing layer.
* Other modules present in the remaining layers should not require to interact with modules
* behind this level
*/

var mDNSDiscovery = require('./discovery/mdns')
var Peer = require('./routers/dht/peer')
var Id = require('./routers/dht/peer/id')
var network = require('network')
var Multiaddr = require('multiaddr')
var DHT = require('./routers/dht')

exports = module.exports = Routing

function Routing () {
var self = this

if (!(self instanceof Routing)) {
throw new Error('Routing should be called with new')
}

self.router
self.peer

// instantiate this peer

self.start = function (cb) {
network.get_private_ip(function (err, ip) {
if (err) {
cb(err)
}
var multiaddrs = []
multiaddrs.push(new Multiaddr('/ip4/' + ip + '/tcp/' + 4001))
self.peer = new Peer(Id.create(), multiaddrs)
self.useRouterDHT()
self.useDiscoveryMDNS()
if (cb) {
cb()
}
})
}

// routing interface

self.putValue = function (key, buf) {}
self.getValue = function (key) {}
self.provide = function (key) {}
self.findPeer = function (key) {}
self.ping = function (key) {}

// select strategies (plugins) used

self.useRouterDHT = function () {
self.router = new DHT(self.peer)
}

self.useRouterMDNS = function () {}

self.useDiscoveryBootstrapList = function () {}

self.useDiscoveryMDNS = function () {
mDNSDiscovery(function (err, peer) {
if (err) {
return console.log('mDNS Discovery err: ', err)
}
self.router.addPeer(peer)
})
}

self.useDiscoveryRandomWalk = function () {
// use router to find a random peer
}

}

46 changes: 46 additions & 0 deletions src/routing/routers/dht/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* DHT routing plugin for router
*/

var KBucket = require('k-bucket')
var log = require('ipfs-logger').group('router')

exports = module.exports = DHT

function DHT (peerSelf) {
var self = this

if (!(self instanceof DHT)) {
throw new Error('DHT must be called with new')
}

var kBucket = new KBucket({
localNodeId: peerSelf.id.toBytes(),
numberOfNodesPerKBucket: 20 // same as go-ipfs
})

kBucket.on('ping', function (oldContacts, newContact) {
log.info('kbucket ping')
log.info('old', oldContacts)
log.info('new', newContact)
// 1. ping each oldContact
// 2. those who respond should be readded (kBucket.add)
// 3. those who didn't respond should be removed (kBucket.remove)
// 4. if at least one is removed, then newContact can be added (kBucket.add)
})

self.addPeer = function (peer) {
log.info('New DHT candidate -', peer.id.toB58String())
kBucket.add({
id: peer.id.toBytes(),
peer: peer
})
}

self.candidatesToId = function (id) {
return kBucket.closest({
id: id.toBytes(),
n: 3
})
}
}
79 changes: 79 additions & 0 deletions src/routing/routers/dht/peer/id.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*
* Id is an object representation of a peer Id. a peer Id is a multihash
*/

var multihashing = require('multihashing')
var base58 = require('bs58')
var crypto = require('crypto')

exports = module.exports = Id

function Id (id, pubKey, privKey) {
var self = this

if (!(self instanceof Id)) {
throw new Error('Id must be called with new')
}

self.privKey = privKey
self.pubKey = pubKey
self.id = id // multihash - sha256 - buffer

// pretty print

self.toPrint = function () {
return {
id: id.toHexString(),
privKey: privKey.toString('hex'),
pubKey: pubKey.toString('hex')
}
}

// encode/decode functions

self.toHexString = function () {
return self.id.toString('hex')
}

self.toBytes = function () {
return self.id
}

self.toB58String = function () {
return base58.encode(self.id)
}

}

// generation

exports.create = function () {
var ecdh = crypto.createECDH('secp256k1')
ecdh.generateKeys()

var mhId = multihashing(ecdh.getPublicKey(), 'sha2-256')

return new Id(mhId, ecdh.getPrivateKey(), ecdh.getPublicKey())
}

exports.createFromHexString = function (str) {
return new Id(new Buffer(str), 'hex')
}

exports.createFromBytes = function (buf) {
return new Id(buf)
}

exports.createFromB58String = function (str) {
return new Id(new Buffer(base58.decode(str)))
}

exports.createFromPubKey = function (pubKey) {
var mhId = multihashing(pubKey, 'sha2-256')

return new Id(mhId, null, pubKey)
}

exports.createFromPrivKey = function () {
// TODO(daviddias) derive PubKey from priv
}
22 changes: 22 additions & 0 deletions src/routing/routers/dht/peer/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Peer represents a peer on the IPFS network
*/

var Id = require('./id.js')

exports = module.exports = Peer

function Peer (peerId, multiaddrs) {
var self = this

if (!(self instanceof Peer)) {
throw new Error('Peer must be called with new')
}

if (!(peerId instanceof Id)) {
throw new Error('Peer must be created with an instance of Id')
}

self.id = peerId
self.multiaddrs = multiaddrs
}
Loading