README.md 1.89 KB
Newer Older
Jeromy's avatar
Jeromy committed
1 2 3 4 5 6 7 8 9
#Welcome to Bitswap

Bitswap is the module that is responsible for requesting blocks over the
network from other ipfs peers.

##Main Operations
Bitswap has three main operations:

###GetBlocks
Jeromy's avatar
Jeromy committed
10 11
`GetBlocks` is a bitswap method used to request multiple blocks that are likely
to all be provided by the same peer (part of a single file, for example).
Jeromy's avatar
Jeromy committed
12 13 14 15 16

###GetBlock
`GetBlock` is a special case of `GetBlocks` that just requests a single block.

###HasBlock
Jeromy's avatar
Jeromy committed
17 18 19
`HasBlock` registers a local block with bitswap. Bitswap will then send that
block to any connected peers who want it (strategy allowing), and announce to
the DHT that the block is being provided.
Jeromy's avatar
Jeromy committed
20 21

##Internal Details
Jeromy's avatar
Jeromy committed
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
All `GetBlock` requests are relayed into a single for-select loop via channels.
Calls to `GetBlocks` will have `FindProviders` called for only the first key in
the set initially, This is an optimization attempting to cut down on the number
of RPCs required. After a timeout (specified by the strategies
`GetRebroadcastDelay`) Bitswap will iterate through all keys still in the local
wantlist, perform a find providers call for each, and sent the wantlist out to
those providers. This is the fallback behaviour for cases where our initial
assumption about one peer potentially having multiple blocks in a set does not
hold true.

When receiving messages, Bitswaps `ReceiveMessage` method is called. A bitswap
message may contain the wantlist of the peer who sent the message, and an array
of blocks that were on our local wantlist. Any blocks we receive in a bitswap
message will be passed to `HasBlock`, and the other peers wantlist gets updated
in the strategy by `bs.strategy.MessageReceived`.
If another peers wantlist is received, Bitswap will call its strategies
`ShouldSendBlockToPeer` method to determine whether or not the other peer will
be sent the block they are requesting (if we even have it).
Jeromy's avatar
Jeromy committed
40 41 42

##Outstanding TODOs:
- Ensure only one request active per key