Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Peer and Content Routing (DHT) #142

Merged
merged 4 commits into from
Aug 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
feat: support for DHT and without DHT at the same time
refactor(tests): make tests independent without require global set up steps
feat: move libp2p just to the network, take libp2p as a whole and not pieces
docs: Update README Documentation
  • Loading branch information
daviddias committed Aug 25, 2017
commit 84add4daeeb33aec413c3390889a3f3745192f2d
35 changes: 11 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,7 @@
> npm install ipfs-bitswap
```

### Use in Node.js

```js
const Bitswap = require('ipfs-bitswap')
```

### Use in a browser with browserify, webpack or any other bundler
### Use in Node.js or in the browser with browserify, webpack or any other bundler

```js
const Bitswap = require('ipfs-bitswap')
Expand All @@ -56,10 +50,6 @@ Loading this module through a script tag will make the `IpfsBitswap` object avai
<script src="https://unpkg.com/ipfs-bitswap/dist/index.js"></script>
```

## Usage

See https://ipfs.github.io/js-ipfs-bitswap

## API

See https://ipfs.github.io/js-ipfs-bitswap
Expand All @@ -73,24 +63,21 @@ See https://ipfs.github.io/js-ipfs-bitswap
```sh
» tree src
src
├── components
│   ├── decision
│   │   ├── engine.js
│   │   ├── index.js
│   │   └── ledger.js
│   ├── network # Handles peerSet and open new conns
│   │   └── index.js
│   └── want-manager # Keeps track of all blocks the peer wants (not the others which it is connected)
│   ├── index.js
│   └── msg-queue.js # Messages to send queue, one per peer
├── constants.js
├── decision-engine
│   ├── index.js
│   └── ledger.js
├── index.js
└── types
├── message # (Type) message that is put in the wire
├── network.js # Handles peerSet and open new conns
├─── want-manager # Keeps track of all blocks the peer (self) wants
│   ├── index.js
│   └── msg-queue.js # Messages to send queue, one per peer
└─── types
├── message # (Type) message that is put in the wire
│   ├── entry.js
│   ├── index.js
│   └── message.proto.js
└── wantlist # (Type) track wanted blocks
└── wantlist # (Type) track wanted blocks
├── entry.js
└── index.js
```
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A though. I've been the one documenting pretty much the whole Bitswap. I do like to document things and make them easier for other people to use and contribute (its like teaching), however, it is kind of hard to when I'm mostly the one pushing the docs, graphs and writing other ideas down. It would be very helpful when the way that things are designed change (or created), to get the contributor to document as well.

This tree is missing the new notifications.js and I'm sure a lot of other thoughts that went into this. Could you try to capture all of them in writing to the best of your ability so that future selfs or contributors don't have to hit a wall? Thank you :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dignifiedquire never received an acknowledgment here. Could you share your feedback?

Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
"description": "Node.js implementation of the Bitswap data exchange protocol used by IPFS",
"main": "src/index.js",
"browser": {
"./test/libp2p-bundle": false
"./test/utils/create-libp2p-node": false,
"./test/utils/create-temp-repo-nodejs.js": "./test/utils/create-temp-repo-browser.js"
},
"scripts": {
"test": "aegir-test",
Expand Down Expand Up @@ -39,10 +40,11 @@
"devDependencies": {
"aegir": "^11.0.2",
"benchmark": "^2.1.4",
"chai": "^4.1.0",
"chai": "^4.1.1",
"dirty-chai": "^2.0.1",
"ipfs-repo": "~0.17.0",
"libp2p": "^0.11.0",
"libp2p-kad-dht": "^0.4.1",
"libp2p-multiplex": "^0.4.4",
"libp2p-secio": "^0.7.1",
"libp2p-tcp": "^0.10.2",
Expand All @@ -58,7 +60,7 @@
"dependencies": {
"async": "^2.5.0",
"cids": "~0.5.1",
"debug": "^2.6.8",
"debug": "^3.0.0",
"ipfs-block": "~0.6.0",
"lodash.debounce": "^4.0.8",
"lodash.find": "^4.6.0",
Expand All @@ -75,6 +77,7 @@
"pull-length-prefixed": "^1.3.0",
"pull-pushable": "^2.1.1",
"pull-stream": "^3.6.0",
"safe-buffer": "^5.1.1",
"varint-decoder": "^0.1.1"
},
"contributors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const debug = require('debug')
const each = require('async/each')
const eachSeries = require('async/eachSeries')
const waterfall = require('async/waterfall')
const setImmediate = require('async/setImmediate')

const map = require('async/map')
const debounce = require('lodash.debounce')
const uniqWith = require('lodash.uniqwith')
Expand All @@ -15,8 +17,8 @@ const pullAllWith = require('lodash.pullallwith')
const log = debug('bitswap:engine')
log.error = debug('bitswap:engine:error')

const Message = require('../../types/message')
const Wantlist = require('../../types/wantlist')
const Message = require('../types/message')
const Wantlist = require('../types/wantlist')
const Ledger = require('./ledger')

const MAX_MESSAGE_SIZE = 512 * 1024
Expand Down Expand Up @@ -271,12 +273,14 @@ class DecisionEngine {
return l
}

start () {
start (callback) {
this._running = true
setImmediate(() => callback())
}

stop () {
stop (callback) {
this._running = false
setImmediate(() => callback())
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const Wantlist = require('../../types/wantlist')
const Wantlist = require('../types/wantlist')

class Ledger {
constructor (peerId) {
Expand Down
45 changes: 25 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,24 @@ const map = require('async/map')
const once = require('once')

const CONSTANTS = require('./constants')
const WantManager = require('./components/want-manager')
const Network = require('./components/network')
const DecisionEngine = require('./components/decision-engine')
const WantManager = require('./want-manager')
const Network = require('./network')
const DecisionEngine = require('./decision-engine')

const log = debug('bitswap')
log.error = debug('bitswap:error')

/**
*
*/
class Bitswap {
/**
* Create a new bitswap instance.
*
* @param {Libp2p} libp2p
* @param {Blockstore} blockstore
* @param {PeerBook} peerBook
* @returns {Bitswap}
*/
constructor (libp2p, blockstore, peerBook) {
this.libp2p = libp2p
constructor (libp2p, blockstore) {
// the network delivers messages
this.network = new Network(libp2p, peerBook, this)
this.network = new Network(libp2p, this)

// local database
this.blockstore = blockstore
Expand All @@ -54,6 +49,7 @@ class Bitswap {
_receiveMessage (peerId, incoming, callback) {
this.engine.messageReceived(peerId, incoming, (err) => {
if (err) {
// TODO: Q: why do we just log and not return here?
log('failed to receive message', incoming)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Understand why this Error is just logged and why the rest of the function continues.


Expand Down Expand Up @@ -272,7 +268,8 @@ class Bitswap {
})
}, cb),
(cb) => {
if (missing.length > 0) {
if (missing.length > 0) { // TODO: Q: why do we just log and not return here?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • This comment doesn't make sense anymore


addListeners(missing)
this.wm.wantBlocks(missing)

Expand Down Expand Up @@ -389,23 +386,31 @@ class Bitswap {
/**
* Start the bitswap node.
*
* @param {function(Error)} callback
*
* @returns {void}
*/
start () {
this.wm.run()
this.network.start()
this.engine.start()
start (callback) {
series([
(cb) => this.wm.start(cb),
(cb) => this.network.start(cb),
(cb) => this.engine.start(cb)
], callback)
}

/**
* Stooop the bitswap node.
* Stop the bitswap node.
*
* @param {function(Error)} callback
*
* @returns {void}
*/
stop () {
this.wm.stop(this.libp2p.peerInfo.id)
this.network.stop()
this.engine.stop()
stop (callback) {
series([
(cb) => this.wm.stop(cb),
(cb) => this.network.stop(cb),
(cb) => this.engine.stop(cb)
], callback)
}
}

Expand Down
Loading