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

WIP: exchange spec #53

Closed
wants to merge 2 commits into from
Closed
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
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

[![](https://img.shields.io/badge/made%20by-Protocol%20Labs-blue.svg?style=flat-square)](http://ipn.io)
[![](https://img.shields.io/badge/project-IPFS-blue.svg?style=flat-square)](http://ipfs.io/)
[![](https://img.shields.io/badge/freejs-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)
[![](https://img.shields.io/badge/freenode-%23ipfs-blue.svg?style=flat-square)](http://webchat.freenode.net/?channels=%23ipfs)

This repository contains the specs for the IPFS Protocol and associated
> This repository contains the specs for the IPFS Protocol and associated
subsystems. Some day we will hopefully transform these specs into RFCs.
For now, they assume a high level of familiarity with the concepts.


![](ipfs-splash.png)

## Work In Progress
Expand Down
108 changes: 108 additions & 0 deletions exchange/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
Block Exchange Spec
===================

> A free market for Content-Addressed data transactions.

# Table of Contents

- Description
- Implementation Details
- bitswap
- http-exchange

# Description

The IPFS Block Exchange takes care of negotiating bulk data transfers. Once nodes know each other -- and are connected -- the exchange protocols govern how the transfer of content-addressed blocks occurs.

The Block Exchange is an interface that is satisfied by various kinds of implementations. For example:

- bitswap: our main protocol for exchanging data. It is a generalization of BitTorrent to work with arbitrary (and not known apriori) DAGs.
- http-exchange: a simple exchange can be implemented with HTTP clients and servers.

# Implementations

## bitswap

> bitswap is the primary Block Exchange Protocol available for IPFS, it follows the Block Exchange Specs expectations and interface.

### notes

- Jeromy's Coffee Talks on Bitswap - https://www.youtube.com/watch?v=9UjqJTCg_h4
- in a nutshell:
- tell other peers what we want
- types of messages
- I want a block
- no longer want a block
- here is a block
- drop the want list of a peer if we loose the connection with it
- attack in every front to get the block (send list to all peers + search the DHT)
- don’t look for every block in DHT, only for one, because it is assumed for a node that has a block to have the rest of the blocks
- bloom filters to aid the decision of whom to ask
- interface (similar to datastore/blockstore interface)
- getBlock
- hasBlock
- putBlock
- needs to understand serialization (cbor + protobufs)

### architecture

```bash
┌────────────────────────────┐
│ bitswap │
└────────────────────────────┘
┌─────────┴────┬────────────┬─────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌────────────┐ ┌───────┐ ┌───────────────┐
│ vault │ │ door │ │ scout │ │ auction-house │
└─────────┘ └────────────┘ └───────┘ └───────────────┘
│ ▲ │

│ │ │

▼ │ │
┌─────────┐ ┌───────────────┐
│ipfs-repo│ │ libp2p │◀ ─ ┘
└─────────┘ └───────────────┘
```
Copy link
Member Author

Choose a reason for hiding this comment

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

This is how I'm organising the pieces of bitswap so far :) check below for descriptions


##### bitswap

Implements the interface specified by this spec

##### vault

Simple connector to IPFS repo for the remaining parts bitswap know how to store and get blocks

##### door

Mounts on top of libp2p as `/bitswap/a.b.c`, where `a.b.c` is the major, minor and patch version of the protocol respectively. `door` receives all the incoming messages, parses them depending on tis wire format (see wire messages below for wire format notes) and forwards it the respective entity inside bitswap that will part this message.

##### scout

`scout` is our want manager, it keeps peers informed of what is our want list (and what we don't want anymore), makes sure to inform new peers as we get connected. `scout` is also responsible for making the decision of which peers to contact in the DHT depending on what are the blocks we are looking for at a certain moment.

##### auction house

`auction-house` keeps track of what blocks my peer wants, what others peer wants list are, peers bandwith, reputation and other important metricts that will enable bitswap to become smarter.

### interface

`fn get(Multihash: key) -> (Vec<u8>: block, Err: err)`
`fn put(Multihash: key, Vec<u8>: block) -> Err: err`

Q: bitswap should not expect an already serialized block so that we can pick the serialization format inside when passing it around.
Copy link
Member Author

Choose a reason for hiding this comment

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

@whyrusleeping I'm trying to come with a best way to enable cbor and protobuf to coexist. We will need to make it very explicit or just let bitswap figure out how to encode something.

Also, right now blocks in datastore are stored as .data, we can have .data for serialized protobufs and .cbor for serialized IPLD objects.

Thoughts?

Copy link

Choose a reason for hiding this comment

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

.data is very generic. How about .proto for Protobufs, and .cbor for serialized IPLD.


### wire messages

bitswap wire format can vary between protobuf (legacy) and cbor (IPLD).

Types of messages:

- here is my want list
- I have a block
- I no longer want a block

Copy link
Member Author

Choose a reason for hiding this comment

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

We will also need to do some multicodec handshake on how we pass bitswap messages or we can encapsulate everything in a protobuf always and just let the protobuf tell which type the block being passed on the wire is. // @whyrusleeping

Copy link
Member

Choose a reason for hiding this comment

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

'I have a block' isn't a bitswap message, its on the dht.

Copy link
Member Author

Choose a reason for hiding this comment

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

oh, I meant, "Here is a block I have that you wanted"

## http-exchange
Binary file added exchange/graphs/bitswap-arch.monopic
Binary file not shown.
19 changes: 19 additions & 0 deletions exchange/graphs/bitswap-arch.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
┌────────────────────────────┐
│ bitswap │
└────────────────────────────┘
┌─────────┴────┬────────────┬─────────────┐
│ │ │ │
▼ ▼ ▼ ▼
┌─────────┐ ┌────────────┐ ┌───────┐ ┌───────────────┐
│ vault │ │ door │ │ scout │ │ auction house │
└─────────┘ └────────────┘ └───────┘ └───────────────┘
│ ▲ │

│ │ │

▼ │ │
┌─────────┐ ┌───────────────┐
│ipfs-repo│ │ libp2p │◀ ─ ┘
└─────────┘ └───────────────┘