diff --git a/Cargo.lock b/Cargo.lock index e8f81fed..ac61b8e9 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", ] diff --git a/Cargo.toml b/Cargo.toml index 200591b3..e3f5feff 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -11,4 +11,5 @@ libp2p = { version = "*", path = "../rust-libp2p" } multibase = "*" multihash = "*" parity-multihash = { version = "*", path = "../rust-libp2p/misc/multihash" } +protobuf = "2.0.2" tokio = "*" diff --git a/src/bitswap/bitswap.proto b/src/bitswap/bitswap.proto new file mode 100644 index 00000000..23733a34 --- /dev/null +++ b/src/bitswap/bitswap.proto @@ -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 +} diff --git a/src/bitswap/mod.rs b/src/bitswap/mod.rs index 4c4bc5d5..2725d5ea 100644 --- a/src/bitswap/mod.rs +++ b/src/bitswap/mod.rs @@ -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>, diff --git a/src/bitswap/protobuf_structs/bitswap.rs b/src/bitswap/protobuf_structs/bitswap.rs new file mode 100644 index 00000000..552594a8 --- /dev/null +++ b/src/bitswap/protobuf_structs/bitswap.rs @@ -0,0 +1,1015 @@ +// This file is generated by rust-protobuf 2.0.2. Do not edit +// @generated + +// https://github.com/Manishearth/rust-clippy/issues/702 +#![allow(unknown_lints)] +#![allow(clippy)] + +#![cfg_attr(rustfmt, rustfmt_skip)] + +#![allow(box_pointers)] +#![allow(dead_code)] +#![allow(missing_docs)] +#![allow(non_camel_case_types)] +#![allow(non_snake_case)] +#![allow(non_upper_case_globals)] +#![allow(trivial_casts)] +#![allow(unsafe_code)] +#![allow(unused_imports)] +#![allow(unused_results)] + +use protobuf::Message as Message_imported_for_functions; +use protobuf::ProtobufEnum as ProtobufEnum_imported_for_functions; + +#[derive(PartialEq,Clone,Default)] +pub struct Message { + // message fields + pub wantlist: ::protobuf::SingularPtrField, + pub blocks: ::protobuf::RepeatedField<::std::vec::Vec>, + pub payload: ::protobuf::RepeatedField, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +impl Message { + pub fn new() -> Message { + ::std::default::Default::default() + } + + // .Message.Wantlist wantlist = 1; + + pub fn clear_wantlist(&mut self) { + self.wantlist.clear(); + } + + pub fn has_wantlist(&self) -> bool { + self.wantlist.is_some() + } + + // Param is passed by value, moved + pub fn set_wantlist(&mut self, v: Message_Wantlist) { + self.wantlist = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_wantlist(&mut self) -> &mut Message_Wantlist { + if self.wantlist.is_none() { + self.wantlist.set_default(); + } + self.wantlist.as_mut().unwrap() + } + + // Take field + pub fn take_wantlist(&mut self) -> Message_Wantlist { + self.wantlist.take().unwrap_or_else(|| Message_Wantlist::new()) + } + + pub fn get_wantlist(&self) -> &Message_Wantlist { + self.wantlist.as_ref().unwrap_or_else(|| Message_Wantlist::default_instance()) + } + + // repeated bytes blocks = 2; + + pub fn clear_blocks(&mut self) { + self.blocks.clear(); + } + + // Param is passed by value, moved + pub fn set_blocks(&mut self, v: ::protobuf::RepeatedField<::std::vec::Vec>) { + self.blocks = v; + } + + // Mutable pointer to the field. + pub fn mut_blocks(&mut self) -> &mut ::protobuf::RepeatedField<::std::vec::Vec> { + &mut self.blocks + } + + // Take field + pub fn take_blocks(&mut self) -> ::protobuf::RepeatedField<::std::vec::Vec> { + ::std::mem::replace(&mut self.blocks, ::protobuf::RepeatedField::new()) + } + + pub fn get_blocks(&self) -> &[::std::vec::Vec] { + &self.blocks + } + + // repeated .Message.Block payload = 3; + + pub fn clear_payload(&mut self) { + self.payload.clear(); + } + + // Param is passed by value, moved + pub fn set_payload(&mut self, v: ::protobuf::RepeatedField) { + self.payload = v; + } + + // Mutable pointer to the field. + pub fn mut_payload(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.payload + } + + // Take field + pub fn take_payload(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.payload, ::protobuf::RepeatedField::new()) + } + + pub fn get_payload(&self) -> &[Message_Block] { + &self.payload + } +} + +impl ::protobuf::Message for Message { + fn is_initialized(&self) -> bool { + for v in &self.wantlist { + if !v.is_initialized() { + return false; + } + }; + for v in &self.payload { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.wantlist)?; + }, + 2 => { + ::protobuf::rt::read_repeated_bytes_into(wire_type, is, &mut self.blocks)?; + }, + 3 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.payload)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if let Some(ref v) = self.wantlist.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + for value in &self.blocks { + my_size += ::protobuf::rt::bytes_size(2, &value); + }; + for value in &self.payload { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if let Some(ref v) = self.wantlist.as_ref() { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + for v in &self.blocks { + os.write_bytes(2, &v)?; + }; + for v in &self.payload { + os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any + } + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> Message { + Message::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, + }; + unsafe { + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "wantlist", + |m: &Message| { &m.wantlist }, + |m: &mut Message| { &mut m.wantlist }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "blocks", + |m: &Message| { &m.blocks }, + |m: &mut Message| { &mut m.blocks }, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "payload", + |m: &Message| { &m.payload }, + |m: &mut Message| { &mut m.payload }, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Message", + fields, + file_descriptor_proto() + ) + }) + } + } + + fn default_instance() -> &'static Message { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Message, + }; + unsafe { + instance.get(Message::new) + } + } +} + +impl ::protobuf::Clear for Message { + fn clear(&mut self) { + self.clear_wantlist(); + self.clear_blocks(); + self.clear_payload(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Message { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Message { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Message_Wantlist { + // message fields + pub entries: ::protobuf::RepeatedField, + pub full: bool, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +impl Message_Wantlist { + pub fn new() -> Message_Wantlist { + ::std::default::Default::default() + } + + // repeated .Message.Wantlist.Entry entries = 1; + + pub fn clear_entries(&mut self) { + self.entries.clear(); + } + + // Param is passed by value, moved + pub fn set_entries(&mut self, v: ::protobuf::RepeatedField) { + self.entries = v; + } + + // Mutable pointer to the field. + pub fn mut_entries(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.entries + } + + // Take field + pub fn take_entries(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.entries, ::protobuf::RepeatedField::new()) + } + + pub fn get_entries(&self) -> &[Message_Wantlist_Entry] { + &self.entries + } + + // bool full = 2; + + pub fn clear_full(&mut self) { + self.full = false; + } + + // Param is passed by value, moved + pub fn set_full(&mut self, v: bool) { + self.full = v; + } + + pub fn get_full(&self) -> bool { + self.full + } +} + +impl ::protobuf::Message for Message_Wantlist { + fn is_initialized(&self) -> bool { + for v in &self.entries { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.entries)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_bool()?; + self.full = tmp; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + for value in &self.entries { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + if self.full != false { + my_size += 2; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + for v in &self.entries { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + if self.full != false { + os.write_bool(2, self.full)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any + } + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> Message_Wantlist { + Message_Wantlist::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, + }; + unsafe { + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "entries", + |m: &Message_Wantlist| { &m.entries }, + |m: &mut Message_Wantlist| { &mut m.entries }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "full", + |m: &Message_Wantlist| { &m.full }, + |m: &mut Message_Wantlist| { &mut m.full }, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Message_Wantlist", + fields, + file_descriptor_proto() + ) + }) + } + } + + fn default_instance() -> &'static Message_Wantlist { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Message_Wantlist, + }; + unsafe { + instance.get(Message_Wantlist::new) + } + } +} + +impl ::protobuf::Clear for Message_Wantlist { + fn clear(&mut self) { + self.clear_entries(); + self.clear_full(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Message_Wantlist { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Message_Wantlist { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Message_Wantlist_Entry { + // message fields + pub block: ::std::vec::Vec, + pub priority: i32, + pub cancel: bool, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +impl Message_Wantlist_Entry { + pub fn new() -> Message_Wantlist_Entry { + ::std::default::Default::default() + } + + // bytes block = 1; + + pub fn clear_block(&mut self) { + self.block.clear(); + } + + // Param is passed by value, moved + pub fn set_block(&mut self, v: ::std::vec::Vec) { + self.block = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_block(&mut self) -> &mut ::std::vec::Vec { + &mut self.block + } + + // Take field + pub fn take_block(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.block, ::std::vec::Vec::new()) + } + + pub fn get_block(&self) -> &[u8] { + &self.block + } + + // int32 priority = 2; + + pub fn clear_priority(&mut self) { + self.priority = 0; + } + + // Param is passed by value, moved + pub fn set_priority(&mut self, v: i32) { + self.priority = v; + } + + pub fn get_priority(&self) -> i32 { + self.priority + } + + // bool cancel = 3; + + pub fn clear_cancel(&mut self) { + self.cancel = false; + } + + // Param is passed by value, moved + pub fn set_cancel(&mut self, v: bool) { + self.cancel = v; + } + + pub fn get_cancel(&self) -> bool { + self.cancel + } +} + +impl ::protobuf::Message for Message_Wantlist_Entry { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.block)?; + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_int32()?; + self.priority = tmp; + }, + 3 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_bool()?; + self.cancel = tmp; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.block.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.block); + } + if self.priority != 0 { + my_size += ::protobuf::rt::value_size(2, self.priority, ::protobuf::wire_format::WireTypeVarint); + } + if self.cancel != false { + my_size += 2; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if !self.block.is_empty() { + os.write_bytes(1, &self.block)?; + } + if self.priority != 0 { + os.write_int32(2, self.priority)?; + } + if self.cancel != false { + os.write_bool(3, self.cancel)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any + } + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> Message_Wantlist_Entry { + Message_Wantlist_Entry::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, + }; + unsafe { + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "block", + |m: &Message_Wantlist_Entry| { &m.block }, + |m: &mut Message_Wantlist_Entry| { &mut m.block }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeInt32>( + "priority", + |m: &Message_Wantlist_Entry| { &m.priority }, + |m: &mut Message_Wantlist_Entry| { &mut m.priority }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "cancel", + |m: &Message_Wantlist_Entry| { &m.cancel }, + |m: &mut Message_Wantlist_Entry| { &mut m.cancel }, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Message_Wantlist_Entry", + fields, + file_descriptor_proto() + ) + }) + } + } + + fn default_instance() -> &'static Message_Wantlist_Entry { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Message_Wantlist_Entry, + }; + unsafe { + instance.get(Message_Wantlist_Entry::new) + } + } +} + +impl ::protobuf::Clear for Message_Wantlist_Entry { + fn clear(&mut self) { + self.clear_block(); + self.clear_priority(); + self.clear_cancel(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Message_Wantlist_Entry { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Message_Wantlist_Entry { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Message_Block { + // message fields + pub prefix: ::std::vec::Vec, + pub data: ::std::vec::Vec, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +impl Message_Block { + pub fn new() -> Message_Block { + ::std::default::Default::default() + } + + // bytes prefix = 1; + + pub fn clear_prefix(&mut self) { + self.prefix.clear(); + } + + // Param is passed by value, moved + pub fn set_prefix(&mut self, v: ::std::vec::Vec) { + self.prefix = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_prefix(&mut self) -> &mut ::std::vec::Vec { + &mut self.prefix + } + + // Take field + pub fn take_prefix(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.prefix, ::std::vec::Vec::new()) + } + + pub fn get_prefix(&self) -> &[u8] { + &self.prefix + } + + // bytes data = 2; + + pub fn clear_data(&mut self) { + self.data.clear(); + } + + // Param is passed by value, moved + pub fn set_data(&mut self, v: ::std::vec::Vec) { + self.data = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_data(&mut self) -> &mut ::std::vec::Vec { + &mut self.data + } + + // Take field + pub fn take_data(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.data, ::std::vec::Vec::new()) + } + + pub fn get_data(&self) -> &[u8] { + &self.data + } +} + +impl ::protobuf::Message for Message_Block { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.prefix)?; + }, + 2 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.data)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.prefix.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.prefix); + } + if !self.data.is_empty() { + my_size += ::protobuf::rt::bytes_size(2, &self.data); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if !self.prefix.is_empty() { + os.write_bytes(1, &self.prefix)?; + } + if !self.data.is_empty() { + os.write_bytes(2, &self.data)?; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any + } + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + Self::descriptor_static() + } + + fn new() -> Message_Block { + Message_Block::new() + } + + fn descriptor_static() -> &'static ::protobuf::reflect::MessageDescriptor { + static mut descriptor: ::protobuf::lazy::Lazy<::protobuf::reflect::MessageDescriptor> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::reflect::MessageDescriptor, + }; + unsafe { + descriptor.get(|| { + let mut fields = ::std::vec::Vec::new(); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "prefix", + |m: &Message_Block| { &m.prefix }, + |m: &mut Message_Block| { &mut m.prefix }, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "data", + |m: &Message_Block| { &m.data }, + |m: &mut Message_Block| { &mut m.data }, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Message_Block", + fields, + file_descriptor_proto() + ) + }) + } + } + + fn default_instance() -> &'static Message_Block { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Message_Block, + }; + unsafe { + instance.get(Message_Block::new) + } + } +} + +impl ::protobuf::Clear for Message_Block { + fn clear(&mut self) { + self.clear_prefix(); + self.clear_data(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Message_Block { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Message_Block { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\rbitswap.proto\"\xd6\x02\n\x07Message\x12-\n\x08wantlist\x18\x01\x20\ + \x01(\x0b2\x11.Message.WantlistR\x08wantlist\x12\x16\n\x06blocks\x18\x02\ + \x20\x03(\x0cR\x06blocks\x12(\n\x07payload\x18\x03\x20\x03(\x0b2\x0e.Mes\ + sage.BlockR\x07payload\x1a\xa4\x01\n\x08Wantlist\x121\n\x07entries\x18\ + \x01\x20\x03(\x0b2\x17.Message.Wantlist.EntryR\x07entries\x12\x12\n\x04f\ + ull\x18\x02\x20\x01(\x08R\x04full\x1aQ\n\x05Entry\x12\x14\n\x05block\x18\ + \x01\x20\x01(\x0cR\x05block\x12\x1a\n\x08priority\x18\x02\x20\x01(\x05R\ + \x08priority\x12\x16\n\x06cancel\x18\x03\x20\x01(\x08R\x06cancel\x1a3\n\ + \x05Block\x12\x16\n\x06prefix\x18\x01\x20\x01(\x0cR\x06prefix\x12\x12\n\ + \x04data\x18\x02\x20\x01(\x0cR\x04dataJ\x9e\n\n\x06\x12\x04\0\0\x1c\x01\ + \n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x1c\x01\n\ + \n\n\x03\x04\0\x01\x12\x03\x02\x08\x0f\n\x0c\n\x04\x04\0\x03\0\x12\x04\ + \x03\x02\x11\x03\n\x0c\n\x05\x04\0\x03\0\x01\x12\x03\x03\n\x12\n\x0e\n\ + \x06\x04\0\x03\0\x03\0\x12\x04\x04\x04\x0b\x11\n\x0e\n\x07\x04\0\x03\0\ + \x03\0\x01\x12\x03\x04\x0c\x11\nQ\n\x08\x04\0\x03\0\x03\0\x02\0\x12\x03\ + \x06\x18(\x1a@\x20the\x20block\x20cid\x20(cidV0\x20in\x20bitswap\x201.0.\ + 0,\x20cidV1\x20in\x20bitswap\x201.1.0)\n\n\x11\n\t\x04\0\x03\0\x03\0\x02\ + \0\x04\x12\x04\x06\x18\x04\x13\n\x10\n\t\x04\0\x03\0\x03\0\x02\0\x05\x12\ + \x03\x06\x18\x1d\n\x10\n\t\x04\0\x03\0\x03\0\x02\0\x01\x12\x03\x06\x1e#\ + \n\x10\n\t\x04\0\x03\0\x03\0\x02\0\x03\x12\x03\x06&'\n:\n\x08\x04\0\x03\ + \0\x03\0\x02\x01\x12\x03\x08\x18+\x1a)\x20the\x20priority\x20(normalized\ + ).\x20default\x20to\x201\n\n\x11\n\t\x04\0\x03\0\x03\0\x02\x01\x04\x12\ + \x04\x08\x18\x06(\n\x10\n\t\x04\0\x03\0\x03\0\x02\x01\x05\x12\x03\x08\ + \x18\x1d\n\x10\n\t\x04\0\x03\0\x03\0\x02\x01\x01\x12\x03\x08\x1e&\n\x10\ + \n\t\x04\0\x03\0\x03\0\x02\x01\x03\x12\x03\x08)*\n0\n\x08\x04\0\x03\0\ + \x03\0\x02\x02\x12\x03\n\x18(\x1a\x1f\x20whether\x20this\x20revokes\x20a\ + n\x20entry\n\n\x11\n\t\x04\0\x03\0\x03\0\x02\x02\x04\x12\x04\n\x18\x08+\ + \n\x10\n\t\x04\0\x03\0\x03\0\x02\x02\x05\x12\x03\n\x18\x1c\n\x10\n\t\x04\ + \0\x03\0\x03\0\x02\x02\x01\x12\x03\n\x1d#\n\x10\n\t\x04\0\x03\0\x03\0\ + \x02\x02\x03\x12\x03\n&'\n+\n\x06\x04\0\x03\0\x02\0\x12\x03\x0e\x04\x1f\ + \x1a\x1c\x20a\x20list\x20of\x20wantlist\x20entries\n\n\x0e\n\x07\x04\0\ + \x03\0\x02\0\x04\x12\x03\x0e\x04\x0c\n\x0e\n\x07\x04\0\x03\0\x02\0\x06\ + \x12\x03\x0e\r\x12\n\x0e\n\x07\x04\0\x03\0\x02\0\x01\x12\x03\x0e\x13\x1a\ + \n\x0e\n\x07\x04\0\x03\0\x02\0\x03\x12\x03\x0e\x1d\x1e\nD\n\x06\x04\0\ + \x03\0\x02\x01\x12\x03\x10\x04\x12\x1a5\x20whether\x20this\x20is\x20the\ + \x20full\x20wantlist.\x20default\x20to\x20false\n\n\x0f\n\x07\x04\0\x03\ + \0\x02\x01\x04\x12\x04\x10\x04\x0e\x1f\n\x0e\n\x07\x04\0\x03\0\x02\x01\ + \x05\x12\x03\x10\x04\x08\n\x0e\n\x07\x04\0\x03\0\x02\x01\x01\x12\x03\x10\ + \t\r\n\x0e\n\x07\x04\0\x03\0\x02\x01\x03\x12\x03\x10\x10\x11\n\x0c\n\x04\ + \x04\0\x03\x01\x12\x04\x13\x02\x17\x03\n\x0c\n\x05\x04\0\x03\x01\x01\x12\ + \x03\x13\n\x0f\nY\n\x06\x04\0\x03\x01\x02\0\x12\x03\x15\x04\x15\x1aJ\x20\ + CID\x20prefix\x20(cid\x20version,\x20multicodec\x20and\x20multihash\x20p\ + refix\x20(type\x20+\x20length)\n\n\x0f\n\x07\x04\0\x03\x01\x02\0\x04\x12\ + \x04\x15\x04\x13\x11\n\x0e\n\x07\x04\0\x03\x01\x02\0\x05\x12\x03\x15\x04\ + \t\n\x0e\n\x07\x04\0\x03\x01\x02\0\x01\x12\x03\x15\n\x10\n\x0e\n\x07\x04\ + \0\x03\x01\x02\0\x03\x12\x03\x15\x13\x14\n\r\n\x06\x04\0\x03\x01\x02\x01\ + \x12\x03\x16\x04\x13\n\x0f\n\x07\x04\0\x03\x01\x02\x01\x04\x12\x04\x16\ + \x04\x15\x15\n\x0e\n\x07\x04\0\x03\x01\x02\x01\x05\x12\x03\x16\x04\t\n\ + \x0e\n\x07\x04\0\x03\x01\x02\x01\x01\x12\x03\x16\n\x0e\n\x0e\n\x07\x04\0\ + \x03\x01\x02\x01\x03\x12\x03\x16\x11\x12\n\x0b\n\x04\x04\0\x02\0\x12\x03\ + \x19\x02\x18\n\r\n\x05\x04\0\x02\0\x04\x12\x04\x19\x02\x17\x03\n\x0c\n\ + \x05\x04\0\x02\0\x06\x12\x03\x19\x02\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\ + \x03\x19\x0b\x13\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x19\x16\x17\n3\n\ + \x04\x04\0\x02\x01\x12\x03\x1a\x02\x1c\"&\x20used\x20to\x20send\x20Block\ + s\x20in\x20bitswap\x201.0.0\n\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\x1a\ + \x02\n\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x1a\x0b\x10\n\x0c\n\x05\x04\ + \0\x02\x01\x01\x12\x03\x1a\x11\x17\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\ + \x1a\x1a\x1b\n3\n\x04\x04\0\x02\x02\x12\x03\x1b\x02\x1d\"&\x20used\x20to\ + \x20send\x20Blocks\x20in\x20bitswap\x201.1.0\n\n\x0c\n\x05\x04\0\x02\x02\ + \x04\x12\x03\x1b\x02\n\n\x0c\n\x05\x04\0\x02\x02\x06\x12\x03\x1b\x0b\x10\ + \n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x1b\x11\x18\n\x0c\n\x05\x04\0\x02\ + \x02\x03\x12\x03\x1b\x1b\x1cb\x06proto3\ +"; + +static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, +}; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + unsafe { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) + } +} diff --git a/src/bitswap/protobuf_structs/mod.rs b/src/bitswap/protobuf_structs/mod.rs new file mode 100644 index 00000000..59dc03ea --- /dev/null +++ b/src/bitswap/protobuf_structs/mod.rs @@ -0,0 +1 @@ +pub mod bitswap; diff --git a/src/bitswap/regen_bitswap_proto.sh b/src/bitswap/regen_bitswap_proto.sh new file mode 100644 index 00000000..aa5fbb68 --- /dev/null +++ b/src/bitswap/regen_bitswap_proto.sh @@ -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