Add bitswap protobufs.
This commit is contained in:
parent
cbd7cb422d
commit
619d7520ed
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -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)",
|
||||
]
|
||||
|
||||
|
@ -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
29
src/bitswap/bitswap.proto
Normal 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
|
||||
}
|
@ -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>>,
|
||||
|
1015
src/bitswap/protobuf_structs/bitswap.rs
Normal file
1015
src/bitswap/protobuf_structs/bitswap.rs
Normal file
File diff suppressed because it is too large
Load Diff
1
src/bitswap/protobuf_structs/mod.rs
Normal file
1
src/bitswap/protobuf_structs/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod bitswap;
|
13
src/bitswap/regen_bitswap_proto.sh
Normal file
13
src/bitswap/regen_bitswap_proto.sh
Normal 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
|
Loading…
Reference in New Issue
Block a user