Skip to content

Commit d393979

Browse files
committed
feat: bitswap 1.3.0 initial spec proposal
1 parent 2c70750 commit d393979

1 file changed

Lines changed: 89 additions & 0 deletions

File tree

BITSWAP.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ There are multiple Bitswap versions and more may evolve over time. We give brief
3838
- `/ipfs/bitswap/1.0.0` - Initial version
3939
- `/ipfs/bitswap/1.1.0` - Support CIDv1
4040
- `/ipfs/bitswap/1.2.0` - Support Wantlist Have's and Have/DontHave responses
41+
- `/ipfs/bitswap/1.3.0` - Support adding tokens in Bitswap requests/responses and BlockTooBig error message
4142

4243
## Bitswap 1.0.0
4344

@@ -196,6 +197,94 @@ message Message {
196197
}
197198
```
198199

200+
## Bitswap 1.3.0
201+
202+
Bitswap 1.3.0 extends the Bitswap 1.2.0 protocol with the following changes:
203+
1. Having a list of tokens that may be sent with the message and referenced within the message
204+
2. Allowing each entry in the wantlist to contain a set of tokens
205+
3. Allowing responses (both BlockPresences and Blocks) to contain a set of tokens
206+
4. Adding an `AuthRequired` BlockPresence
207+
5. Adding a `BlockTooBig` BlockPresence
208+
209+
### Interaction Pattern
210+
211+
Given that a client C wants to fetch data from some server S:
212+
213+
1. C opens a stream `s_want` to S and sends a message for the blocks it wants
214+
1. C may either send a complete wantlist, or an update to an outstanding wantlist
215+
2. C may reuse this stream to send new wants
216+
3. For each of the items in the wantlist C may ask if S has the block (i.e. a Have request) or for S to send the block (i.e. a block request). C may also ask S to send back a DontHave message in the event it doesn't have the block
217+
4. For each of the items in the wantlist C may append any `tokens` they want. Recommended tokens include those that would convince S to give C the blocks they want.
218+
2. S responds back on a stream `s_receive`. S may reuse this stream to send back subsequent responses
219+
1. If C sends S a Have request for data S has (and is willing to give to C) it should respond with a Have, although it may instead respond with the block itself (e.g. if the block is very small)
220+
1. For each of the items that S sends back Blocks or BlockPresences for they may append any `tokens` they want
221+
2. If C sends S a Have request for data S has but is not currently willing to give to C, S may respond with an `AuthRequired` BlockPresence
222+
1. For each of the items that S sends back Blocks or BlockPresences for they may append any `tokens` they want. Recommended tokens include those that would inform C how they could convince S to give them access to the blocks they want.
223+
2. If C sends S a Have request for data S does not have (or has but is not willing to tell C it has) and C has requested for DontHave responses then S should respond with DontHave
224+
3. S may choose to include the number of bytes that are pending to be sent to C in the response message
225+
4. If C asked for a block that S has but it is bigger than the maximum block size it should return `BlockTooBig`
226+
3. When C no longer needs a block it previously asked for it should send a Cancel message for that request to any peers that have not already responded about that particular block. It should particularly send Cancel messages for Block requests (as opposed to Have requests) that have not yet been answered.
227+
228+
### Tokens
229+
230+
The major change in this protocol version is the introduction of the ability to pass tokens along with requests and responses. A token is defined as `<multicode><data>` where the multicode is an identifier in the multicodec table, and the data is token-specific data associated with that code.
231+
232+
Users who require additional codes for their new token formats should do one of:
233+
- Register their code in the table
234+
- For non-deployed testing purposes only - use a code in the application reserved range of the code table
235+
- Note: if codes in the application reserved range will not be reservable in the code table which means that the code may conflict with another one used in the ecosystem which could cause application problems on collision. It is high recommended to not use these codes outside of testing or early development.
236+
237+
To save space within the message the list of tokens used within the message are declared within the top level message and all other references to tokens are instead to the indices within the token list in the top level message.
238+
239+
### Wire Format
240+
241+
```
242+
message Message {
243+
244+
message Wantlist {
245+
enum WantType {
246+
Block = 0;
247+
Have = 1;
248+
}
249+
250+
message Entry {
251+
bytes block = 1; // CID of the block
252+
int32 priority = 2; // the priority (normalized). default to 1
253+
bool cancel = 3; // whether this revokes an entry
254+
WantType wantType = 4; // Note: defaults to enum 0, ie Block
255+
bool sendDontHave = 5; // Note: defaults to false
256+
repeated tokens int32 = 6; // the indices of the tokens in the token list
257+
}
258+
259+
repeated Entry entries = 1; // a list of wantlist entries
260+
bool full = 2; // whether this is the full wantlist. default to false
261+
}
262+
message Block {
263+
bytes prefix = 1; // CID prefix (all of the CID components except for the digest of the multihash)
264+
bytes data = 2;
265+
repeated tokens int32 = 3; // the indices of the tokens in the token list
266+
}
267+
268+
enum BlockPresenceType {
269+
Have = 0;
270+
DontHave = 1;
271+
AuthRequired = 2;
272+
BlockTooBig = 3;
273+
}
274+
message BlockPresence {
275+
bytes cid = 1;
276+
BlockPresenceType type = 2;
277+
repeated tokens int32 = 3; // the indices of the tokens in the token list
278+
}
279+
280+
Wantlist wantlist = 1;
281+
repeated Block payload = 3;
282+
repeated BlockPresence blockPresences = 4;
283+
int32 pendingBytes = 5;
284+
repeated bytes tokens = 6; // Each token is of the form <multicode><token-data> where the multicode identifies what the data is for
285+
}
286+
```
287+
199288
# Implementations
200289

201290
- <https://github.com/ipfs/go-bitswap>

0 commit comments

Comments
 (0)