Add bitswap protobufs.

This commit is contained in:
David Craven 2019-02-01 23:48:47 +01:00
parent cbd7cb422d
commit 619d7520ed
No known key found for this signature in database
GPG Key ID: DF438712EA50DBB1
7 changed files with 1062 additions and 0 deletions

1
Cargo.lock generated
View File

@ -562,6 +562,7 @@ dependencies = [
"multibase 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)",
"multihash 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
"parity-multihash 0.1.0",
"protobuf 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tokio 0.1.15 (registry+https://github.com/rust-lang/crates.io-index)",
]

View File

@ -11,4 +11,5 @@ libp2p = { version = "*", path = "../rust-libp2p" }
multibase = "*"
multihash = "*"
parity-multihash = { version = "*", path = "../rust-libp2p/misc/multihash" }
protobuf = "2.0.2"
tokio = "*"

29
src/bitswap/bitswap.proto Normal file
View File

@ -0,0 +1,29 @@
syntax = "proto3";
message Message {
message Wantlist {
message Entry {
// the block cid (cidV0 in bitswap 1.0.0, cidV1 in bitswap 1.1.0)
bytes block = 1;
// the priority (normalized). default to 1
int32 priority = 2;
// whether this revokes an entry
bool cancel = 3;
}
// a list of wantlist entries
repeated Entry entries = 1;
// whether this is the full wantlist. default to false
bool full = 2;
}
message Block {
// CID prefix (cid version, multicodec and multihash prefix (type + length)
bytes prefix = 1;
bytes data = 2;
}
Wantlist wantlist = 1;
repeated bytes blocks = 2; // used to send Blocks in bitswap 1.0.0
repeated Block payload = 3; // used to send Blocks in bitswap 1.1.0
}

View File

@ -6,6 +6,8 @@ use parity_multihash::Multihash;
use std::io::Error;
use std::sync::{Arc, Mutex};
mod protobuf_structs;
#[derive(Clone)]
pub struct Bitswap {
p2p: Arc<Mutex<Service>>,

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1 @@
pub mod bitswap;

View File

@ -0,0 +1,13 @@
#!/bin/sh
# This script regenerates the `bitswap_proto.rs` file from `bitswap.proto`.
docker run --rm -v `pwd`:/usr/code:z -w /usr/code rust /bin/bash -c " \
apt-get update; \
apt-get install -y protobuf-compiler; \
cargo install --version 2.0.2 protobuf-codegen; \
protoc --rust_out . bitswap.proto"
sudo chown $USER:$USER *.rs
mv -f bitswap.rs ./protobuf_structs/bitswap.rs