From 177d639fab67b790f43bc0573d785271d8afb858 Mon Sep 17 00:00:00 2001 From: Bryan Newbold Date: Thu, 26 Oct 2017 21:10:19 -0700 Subject: refactor file/module names I had some early confusion around whether SLEEP refered to individual files or the collection of files making a register (it seems to mean the whole register). Will probably need to refactor again. --- src/bin/geniza-register.rs | 54 - src/bin/geniza-sleep.rs | 34 +- src/drive_proto.proto | 18 - src/drive_proto.rs | 893 ------------- src/lib.rs | 16 +- src/metadata_msg.proto | 18 + src/metadata_msg.rs | 893 +++++++++++++ src/network_msg.rs | 3199 ++++++++++++++++++++++++++++++++++++++++++++ src/network_msgs.proto | 81 ++ src/network_proto.proto | 81 -- src/network_proto.rs | 3199 -------------------------------------------- src/protocol.rs | 507 +++++++ src/register.rs | 556 -------- src/sleep.rs | 203 --- src/sleep_file.rs | 203 +++ src/sleep_register.rs | 556 ++++++++ src/sync.rs | 507 ------- 17 files changed, 5493 insertions(+), 5525 deletions(-) delete mode 100644 src/bin/geniza-register.rs delete mode 100644 src/drive_proto.proto delete mode 100644 src/drive_proto.rs create mode 100644 src/metadata_msg.proto create mode 100644 src/metadata_msg.rs create mode 100644 src/network_msg.rs create mode 100644 src/network_msgs.proto delete mode 100644 src/network_proto.proto delete mode 100644 src/network_proto.rs create mode 100644 src/protocol.rs delete mode 100644 src/register.rs delete mode 100644 src/sleep.rs create mode 100644 src/sleep_file.rs create mode 100644 src/sleep_register.rs delete mode 100644 src/sync.rs diff --git a/src/bin/geniza-register.rs b/src/bin/geniza-register.rs deleted file mode 100644 index a328bbc..0000000 --- a/src/bin/geniza-register.rs +++ /dev/null @@ -1,54 +0,0 @@ - -#[macro_use] -extern crate error_chain; -extern crate clap; -extern crate env_logger; -extern crate geniza; - -// TODO: more careful import -use geniza::*; -use std::path::Path; -use clap::{App, SubCommand}; - -fn run() -> Result<()> { - - env_logger::init().unwrap(); - - let matches = App::new("geniza-register") - .version(env!("CARGO_PKG_VERSION")) - .subcommand(SubCommand::with_name("info") - .about("Reads a SLEEP dir register and shows some basic metadata") - .arg_from_usage(" 'directory containing files'") - .arg_from_usage(" 'prefix for each data file'")) - .subcommand(SubCommand::with_name("create") - .about("Creates an SLEEP directory register (with header)") - .arg_from_usage(" 'directory containing files'") - .arg_from_usage(" 'prefix for each data file'")) - .get_matches(); - - - match matches.subcommand() { - ("info", Some(subm)) => { - let dir = Path::new(subm.value_of("DIR").unwrap()); - let prefix = subm.value_of("prefix").unwrap(); - let mut sdr = SleepDirRegister::open(dir, prefix, false)?; - //debug!(println!("{:?}", sdr)); - println!("Entry count: {}", sdr.len()?); - println!("Total size (bytes): {}", sdr.len_bytes()?); - }, - ("create", Some(subm)) => { - let dir = Path::new(subm.value_of("DIR").unwrap()); - let prefix = subm.value_of("prefix").unwrap(); - SleepDirRegister::create(dir, prefix)?; - println!("Done!"); - }, - _ => { - println!("Missing or unimplemented command!"); - println!("{}", matches.usage()); - ::std::process::exit(-1); - }, - } - Ok(()) -} - -quick_main!(run); diff --git a/src/bin/geniza-sleep.rs b/src/bin/geniza-sleep.rs index 10fc16b..17ff91b 100644 --- a/src/bin/geniza-sleep.rs +++ b/src/bin/geniza-sleep.rs @@ -18,22 +18,44 @@ fn run() -> Result<()> { let matches = App::new("geniza-sleep") .version(env!("CARGO_PKG_VERSION")) .subcommand(SubCommand::with_name("info") - .about("Reads a SLEEP file and shows some basic metadata") - .arg_from_usage(" 'SLEEP file to read'")) + .about("Reads a SLEEP dir register and shows some basic metadata") + .arg_from_usage(" 'directory containing files'") + .arg_from_usage(" 'prefix for each data file'")) .subcommand(SubCommand::with_name("create") - .about("Creates an empty SLEEP file (with header)") + .about("Creates an SLEEP directory register (with header)") + .arg_from_usage(" 'directory containing files'") + .arg_from_usage(" 'prefix for each data file'")) + .subcommand(SubCommand::with_name("file-info") + .about("Reads a single SLEEP file and shows some basic metadata") + .arg_from_usage(" 'SLEEP file to read'")) + .subcommand(SubCommand::with_name("file-create") + .about("Creates an empty single SLEEP file (with header)") .arg_from_usage(" 'SLEEP file to write (can't exist)'") .arg_from_usage(" 'Magic word to use (eg, 0x5025700)'") .arg_from_usage(" 'Size of each entry (bytes)'") .arg_from_usage(" 'Name of algorithm (empty string for none)'")) .subcommand(SubCommand::with_name("read-all") - .about("Reads a SLEEP file, iterates through all entries, prints raw bytes") + .about("Reads a single SLEEP file, iterates through all entries, prints raw bytes") .arg_from_usage(" 'SLEEP file to read'")) .get_matches(); match matches.subcommand() { ("info", Some(subm)) => { + let dir = Path::new(subm.value_of("DIR").unwrap()); + let prefix = subm.value_of("prefix").unwrap(); + let mut sdr = SleepDirRegister::open(dir, prefix, false)?; + //debug!(println!("{:?}", sdr)); + println!("Entry count: {}", sdr.len()?); + println!("Total size (bytes): {}", sdr.len_bytes()?); + }, + ("create", Some(subm)) => { + let dir = Path::new(subm.value_of("DIR").unwrap()); + let prefix = subm.value_of("prefix").unwrap(); + SleepDirRegister::create(dir, prefix)?; + println!("Done!"); + }, + ("file-info", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let sf = SleepFile::open(path, false)?; //debug!(println!("{:?}", sf)); @@ -42,7 +64,7 @@ fn run() -> Result<()> { println!("Entry Size (bytes): {}", sf.get_entry_size()); println!("Entry count: {}", sf.len()?); }, - ("create", Some(subm)) => { + ("file-create", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let algo_name = subm.value_of("algo_name").unwrap(); let algo_name = if algo_name.len() == 0 { @@ -57,7 +79,7 @@ fn run() -> Result<()> { algo_name)?; println!("Done!"); }, - ("read-all", Some(subm)) => { + ("file-read-all", Some(subm)) => { let path = Path::new(subm.value_of("FILE").unwrap()); let mut sf = SleepFile::open(path, false)?; for i in 0..sf.len()? { diff --git a/src/drive_proto.proto b/src/drive_proto.proto deleted file mode 100644 index cd36b30..0000000 --- a/src/drive_proto.proto +++ /dev/null @@ -1,18 +0,0 @@ -// From hyperdrive:lib/messages.js - -message Index { - required string type = 1; - optional bytes content = 2; -} - -message Stat { - required uint32 mode = 1; - optional uint32 uid = 2; - optional uint32 gid = 3; - optional uint64 size = 4; - optional uint64 blocks = 5; - optional uint64 offset = 6; - optional uint64 byteOffset = 7; - optional uint64 mtime = 8; - optional uint64 ctime = 9; -} diff --git a/src/drive_proto.rs b/src/drive_proto.rs deleted file mode 100644 index c30833a..0000000 --- a/src/drive_proto.rs +++ /dev/null @@ -1,893 +0,0 @@ -// This file is generated. 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 Index { - // message fields - field_type: ::protobuf::SingularField<::std::string::String>, - content: ::protobuf::SingularField<::std::vec::Vec>, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Index {} - -impl Index { - pub fn new() -> Index { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Index { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Index, - }; - unsafe { - instance.get(Index::new) - } - } - - // required string type = 1; - - pub fn clear_field_type(&mut self) { - self.field_type.clear(); - } - - pub fn has_field_type(&self) -> bool { - self.field_type.is_some() - } - - // Param is passed by value, moved - pub fn set_field_type(&mut self, v: ::std::string::String) { - self.field_type = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_field_type(&mut self) -> &mut ::std::string::String { - if self.field_type.is_none() { - self.field_type.set_default(); - } - self.field_type.as_mut().unwrap() - } - - // Take field - pub fn take_field_type(&mut self) -> ::std::string::String { - self.field_type.take().unwrap_or_else(|| ::std::string::String::new()) - } - - pub fn get_field_type(&self) -> &str { - match self.field_type.as_ref() { - Some(v) => &v, - None => "", - } - } - - fn get_field_type_for_reflect(&self) -> &::protobuf::SingularField<::std::string::String> { - &self.field_type - } - - fn mut_field_type_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::string::String> { - &mut self.field_type - } - - // optional bytes content = 2; - - pub fn clear_content(&mut self) { - self.content.clear(); - } - - pub fn has_content(&self) -> bool { - self.content.is_some() - } - - // Param is passed by value, moved - pub fn set_content(&mut self, v: ::std::vec::Vec) { - self.content = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_content(&mut self) -> &mut ::std::vec::Vec { - if self.content.is_none() { - self.content.set_default(); - } - self.content.as_mut().unwrap() - } - - // Take field - pub fn take_content(&mut self) -> ::std::vec::Vec { - self.content.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_content(&self) -> &[u8] { - match self.content.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_content_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.content - } - - fn mut_content_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.content - } -} - -impl ::protobuf::Message for Index { - fn is_initialized(&self) -> bool { - if self.field_type.is_none() { - 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_string_into(wire_type, is, &mut self.field_type)?; - }, - 2 => { - ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.content)?; - }, - _ => { - ::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.field_type.as_ref() { - my_size += ::protobuf::rt::string_size(1, &v); - } - if let Some(ref v) = self.content.as_ref() { - my_size += ::protobuf::rt::bytes_size(2, &v); - } - 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.field_type.as_ref() { - os.write_string(1, &v)?; - } - if let Some(ref v) = self.content.as_ref() { - os.write_bytes(2, &v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Index { - fn new() -> Index { - Index::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "type", - Index::get_field_type_for_reflect, - Index::mut_field_type_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "content", - Index::get_content_for_reflect, - Index::mut_content_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Index", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Index { - fn clear(&mut self) { - self.clear_field_type(); - self.clear_content(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Index { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Index { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Stat { - // message fields - mode: ::std::option::Option, - uid: ::std::option::Option, - gid: ::std::option::Option, - size: ::std::option::Option, - blocks: ::std::option::Option, - offset: ::std::option::Option, - byteOffset: ::std::option::Option, - mtime: ::std::option::Option, - ctime: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Stat {} - -impl Stat { - pub fn new() -> Stat { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Stat { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Stat, - }; - unsafe { - instance.get(Stat::new) - } - } - - // required uint32 mode = 1; - - pub fn clear_mode(&mut self) { - self.mode = ::std::option::Option::None; - } - - pub fn has_mode(&self) -> bool { - self.mode.is_some() - } - - // Param is passed by value, moved - pub fn set_mode(&mut self, v: u32) { - self.mode = ::std::option::Option::Some(v); - } - - pub fn get_mode(&self) -> u32 { - self.mode.unwrap_or(0) - } - - fn get_mode_for_reflect(&self) -> &::std::option::Option { - &self.mode - } - - fn mut_mode_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.mode - } - - // optional uint32 uid = 2; - - pub fn clear_uid(&mut self) { - self.uid = ::std::option::Option::None; - } - - pub fn has_uid(&self) -> bool { - self.uid.is_some() - } - - // Param is passed by value, moved - pub fn set_uid(&mut self, v: u32) { - self.uid = ::std::option::Option::Some(v); - } - - pub fn get_uid(&self) -> u32 { - self.uid.unwrap_or(0) - } - - fn get_uid_for_reflect(&self) -> &::std::option::Option { - &self.uid - } - - fn mut_uid_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.uid - } - - // optional uint32 gid = 3; - - pub fn clear_gid(&mut self) { - self.gid = ::std::option::Option::None; - } - - pub fn has_gid(&self) -> bool { - self.gid.is_some() - } - - // Param is passed by value, moved - pub fn set_gid(&mut self, v: u32) { - self.gid = ::std::option::Option::Some(v); - } - - pub fn get_gid(&self) -> u32 { - self.gid.unwrap_or(0) - } - - fn get_gid_for_reflect(&self) -> &::std::option::Option { - &self.gid - } - - fn mut_gid_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.gid - } - - // optional uint64 size = 4; - - pub fn clear_size(&mut self) { - self.size = ::std::option::Option::None; - } - - pub fn has_size(&self) -> bool { - self.size.is_some() - } - - // Param is passed by value, moved - pub fn set_size(&mut self, v: u64) { - self.size = ::std::option::Option::Some(v); - } - - pub fn get_size(&self) -> u64 { - self.size.unwrap_or(0) - } - - fn get_size_for_reflect(&self) -> &::std::option::Option { - &self.size - } - - fn mut_size_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.size - } - - // optional uint64 blocks = 5; - - pub fn clear_blocks(&mut self) { - self.blocks = ::std::option::Option::None; - } - - pub fn has_blocks(&self) -> bool { - self.blocks.is_some() - } - - // Param is passed by value, moved - pub fn set_blocks(&mut self, v: u64) { - self.blocks = ::std::option::Option::Some(v); - } - - pub fn get_blocks(&self) -> u64 { - self.blocks.unwrap_or(0) - } - - fn get_blocks_for_reflect(&self) -> &::std::option::Option { - &self.blocks - } - - fn mut_blocks_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.blocks - } - - // optional uint64 offset = 6; - - pub fn clear_offset(&mut self) { - self.offset = ::std::option::Option::None; - } - - pub fn has_offset(&self) -> bool { - self.offset.is_some() - } - - // Param is passed by value, moved - pub fn set_offset(&mut self, v: u64) { - self.offset = ::std::option::Option::Some(v); - } - - pub fn get_offset(&self) -> u64 { - self.offset.unwrap_or(0) - } - - fn get_offset_for_reflect(&self) -> &::std::option::Option { - &self.offset - } - - fn mut_offset_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.offset - } - - // optional uint64 byteOffset = 7; - - pub fn clear_byteOffset(&mut self) { - self.byteOffset = ::std::option::Option::None; - } - - pub fn has_byteOffset(&self) -> bool { - self.byteOffset.is_some() - } - - // Param is passed by value, moved - pub fn set_byteOffset(&mut self, v: u64) { - self.byteOffset = ::std::option::Option::Some(v); - } - - pub fn get_byteOffset(&self) -> u64 { - self.byteOffset.unwrap_or(0) - } - - fn get_byteOffset_for_reflect(&self) -> &::std::option::Option { - &self.byteOffset - } - - fn mut_byteOffset_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.byteOffset - } - - // optional uint64 mtime = 8; - - pub fn clear_mtime(&mut self) { - self.mtime = ::std::option::Option::None; - } - - pub fn has_mtime(&self) -> bool { - self.mtime.is_some() - } - - // Param is passed by value, moved - pub fn set_mtime(&mut self, v: u64) { - self.mtime = ::std::option::Option::Some(v); - } - - pub fn get_mtime(&self) -> u64 { - self.mtime.unwrap_or(0) - } - - fn get_mtime_for_reflect(&self) -> &::std::option::Option { - &self.mtime - } - - fn mut_mtime_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.mtime - } - - // optional uint64 ctime = 9; - - pub fn clear_ctime(&mut self) { - self.ctime = ::std::option::Option::None; - } - - pub fn has_ctime(&self) -> bool { - self.ctime.is_some() - } - - // Param is passed by value, moved - pub fn set_ctime(&mut self, v: u64) { - self.ctime = ::std::option::Option::Some(v); - } - - pub fn get_ctime(&self) -> u64 { - self.ctime.unwrap_or(0) - } - - fn get_ctime_for_reflect(&self) -> &::std::option::Option { - &self.ctime - } - - fn mut_ctime_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.ctime - } -} - -impl ::protobuf::Message for Stat { - fn is_initialized(&self) -> bool { - if self.mode.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint32()?; - self.mode = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint32()?; - self.uid = ::std::option::Option::Some(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_uint32()?; - self.gid = ::std::option::Option::Some(tmp); - }, - 4 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.size = ::std::option::Option::Some(tmp); - }, - 5 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.blocks = ::std::option::Option::Some(tmp); - }, - 6 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.offset = ::std::option::Option::Some(tmp); - }, - 7 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.byteOffset = ::std::option::Option::Some(tmp); - }, - 8 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.mtime = ::std::option::Option::Some(tmp); - }, - 9 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.ctime = ::std::option::Option::Some(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 let Some(v) = self.mode { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.uid { - my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.gid { - my_size += ::protobuf::rt::value_size(3, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.size { - my_size += ::protobuf::rt::value_size(4, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.blocks { - my_size += ::protobuf::rt::value_size(5, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.offset { - my_size += ::protobuf::rt::value_size(6, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.byteOffset { - my_size += ::protobuf::rt::value_size(7, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.mtime { - my_size += ::protobuf::rt::value_size(8, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.ctime { - my_size += ::protobuf::rt::value_size(9, v, ::protobuf::wire_format::WireTypeVarint); - } - 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(v) = self.mode { - os.write_uint32(1, v)?; - } - if let Some(v) = self.uid { - os.write_uint32(2, v)?; - } - if let Some(v) = self.gid { - os.write_uint32(3, v)?; - } - if let Some(v) = self.size { - os.write_uint64(4, v)?; - } - if let Some(v) = self.blocks { - os.write_uint64(5, v)?; - } - if let Some(v) = self.offset { - os.write_uint64(6, v)?; - } - if let Some(v) = self.byteOffset { - os.write_uint64(7, v)?; - } - if let Some(v) = self.mtime { - os.write_uint64(8, v)?; - } - if let Some(v) = self.ctime { - os.write_uint64(9, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Stat { - fn new() -> Stat { - Stat::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "mode", - Stat::get_mode_for_reflect, - Stat::mut_mode_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "uid", - Stat::get_uid_for_reflect, - Stat::mut_uid_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( - "gid", - Stat::get_gid_for_reflect, - Stat::mut_gid_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "size", - Stat::get_size_for_reflect, - Stat::mut_size_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "blocks", - Stat::get_blocks_for_reflect, - Stat::mut_blocks_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "offset", - Stat::get_offset_for_reflect, - Stat::mut_offset_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "byteOffset", - Stat::get_byteOffset_for_reflect, - Stat::mut_byteOffset_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "mtime", - Stat::get_mtime_for_reflect, - Stat::mut_mtime_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "ctime", - Stat::get_ctime_for_reflect, - Stat::mut_ctime_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Stat", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Stat { - fn clear(&mut self) { - self.clear_mode(); - self.clear_uid(); - self.clear_gid(); - self.clear_size(); - self.clear_blocks(); - self.clear_offset(); - self.clear_byteOffset(); - self.clear_mtime(); - self.clear_ctime(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Stat { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Stat { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\x10hyperdrive.proto\"5\n\x05Index\x12\x12\n\x04type\x18\x01\x20\x02(\ - \tR\x04type\x12\x18\n\x07content\x18\x02\x20\x01(\x0cR\x07content\"\xce\ - \x01\n\x04Stat\x12\x12\n\x04mode\x18\x01\x20\x02(\rR\x04mode\x12\x10\n\ - \x03uid\x18\x02\x20\x01(\rR\x03uid\x12\x10\n\x03gid\x18\x03\x20\x01(\rR\ - \x03gid\x12\x12\n\x04size\x18\x04\x20\x01(\x04R\x04size\x12\x16\n\x06blo\ - cks\x18\x05\x20\x01(\x04R\x06blocks\x12\x16\n\x06offset\x18\x06\x20\x01(\ - \x04R\x06offset\x12\x1e\n\nbyteOffset\x18\x07\x20\x01(\x04R\nbyteOffset\ - \x12\x14\n\x05mtime\x18\x08\x20\x01(\x04R\x05mtime\x12\x14\n\x05ctime\ - \x18\t\x20\x01(\x04R\x05ctimeJ\xd2\x06\n\x06\x12\x04\x02\0\x11\x01\n-\n\ - \x02\x04\0\x12\x04\x02\0\x05\x012!\x20From\x20hyperdrive:lib/messages.js\ - \n\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\r\n\x0b\n\x04\x04\0\x02\0\x12\x03\ - \x03\x02\x1b\n\x0c\n\x05\x04\0\x02\0\x04\x12\x03\x03\x02\n\n\x0c\n\x05\ - \x04\0\x02\0\x05\x12\x03\x03\x0b\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\ - \x03\x12\x16\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\ - \x04\0\x02\x01\x12\x03\x04\x02\x1d\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\ - \x04\x02\n\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x0b\x10\n\x0c\n\x05\ - \x04\0\x02\x01\x01\x12\x03\x04\x11\x18\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ - \x03\x04\x1b\x1c\n\n\n\x02\x04\x01\x12\x04\x07\0\x11\x01\n\n\n\x03\x04\ - \x01\x01\x12\x03\x07\x08\x0c\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\x02\ - \x1b\n\x0c\n\x05\x04\x01\x02\0\x04\x12\x03\x08\x02\n\n\x0c\n\x05\x04\x01\ - \x02\0\x05\x12\x03\x08\x0b\x11\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x08\ - \x12\x16\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x08\x19\x1a\n\x0b\n\x04\ - \x04\x01\x02\x01\x12\x03\t\x02\x1a\n\x0c\n\x05\x04\x01\x02\x01\x04\x12\ - \x03\t\x02\n\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\t\x0b\x11\n\x0c\n\ - \x05\x04\x01\x02\x01\x01\x12\x03\t\x12\x15\n\x0c\n\x05\x04\x01\x02\x01\ - \x03\x12\x03\t\x18\x19\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\n\x02\x1a\n\ - \x0c\n\x05\x04\x01\x02\x02\x04\x12\x03\n\x02\n\n\x0c\n\x05\x04\x01\x02\ - \x02\x05\x12\x03\n\x0b\x11\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x12\ - \x15\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\n\x18\x19\n\x0b\n\x04\x04\ - \x01\x02\x03\x12\x03\x0b\x02\x1b\n\x0c\n\x05\x04\x01\x02\x03\x04\x12\x03\ - \x0b\x02\n\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x0b\x0b\x11\n\x0c\n\ - \x05\x04\x01\x02\x03\x01\x12\x03\x0b\x12\x16\n\x0c\n\x05\x04\x01\x02\x03\ - \x03\x12\x03\x0b\x19\x1a\n\x0b\n\x04\x04\x01\x02\x04\x12\x03\x0c\x02\x1d\ - \n\x0c\n\x05\x04\x01\x02\x04\x04\x12\x03\x0c\x02\n\n\x0c\n\x05\x04\x01\ - \x02\x04\x05\x12\x03\x0c\x0b\x11\n\x0c\n\x05\x04\x01\x02\x04\x01\x12\x03\ - \x0c\x12\x18\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\x0c\x1b\x1c\n\x0b\n\ - \x04\x04\x01\x02\x05\x12\x03\r\x02\x1d\n\x0c\n\x05\x04\x01\x02\x05\x04\ - \x12\x03\r\x02\n\n\x0c\n\x05\x04\x01\x02\x05\x05\x12\x03\r\x0b\x11\n\x0c\ - \n\x05\x04\x01\x02\x05\x01\x12\x03\r\x12\x18\n\x0c\n\x05\x04\x01\x02\x05\ - \x03\x12\x03\r\x1b\x1c\n\x0b\n\x04\x04\x01\x02\x06\x12\x03\x0e\x02!\n\ - \x0c\n\x05\x04\x01\x02\x06\x04\x12\x03\x0e\x02\n\n\x0c\n\x05\x04\x01\x02\ - \x06\x05\x12\x03\x0e\x0b\x11\n\x0c\n\x05\x04\x01\x02\x06\x01\x12\x03\x0e\ - \x12\x1c\n\x0c\n\x05\x04\x01\x02\x06\x03\x12\x03\x0e\x1f\x20\n\x0b\n\x04\ - \x04\x01\x02\x07\x12\x03\x0f\x02\x1c\n\x0c\n\x05\x04\x01\x02\x07\x04\x12\ - \x03\x0f\x02\n\n\x0c\n\x05\x04\x01\x02\x07\x05\x12\x03\x0f\x0b\x11\n\x0c\ - \n\x05\x04\x01\x02\x07\x01\x12\x03\x0f\x12\x17\n\x0c\n\x05\x04\x01\x02\ - \x07\x03\x12\x03\x0f\x1a\x1b\n\x0b\n\x04\x04\x01\x02\x08\x12\x03\x10\x02\ - \x1c\n\x0c\n\x05\x04\x01\x02\x08\x04\x12\x03\x10\x02\n\n\x0c\n\x05\x04\ - \x01\x02\x08\x05\x12\x03\x10\x0b\x11\n\x0c\n\x05\x04\x01\x02\x08\x01\x12\ - \x03\x10\x12\x17\n\x0c\n\x05\x04\x01\x02\x08\x03\x12\x03\x10\x1a\x1b\ -"; - -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/lib.rs b/src/lib.rs index fbbe50a..3fd39ac 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -40,11 +40,11 @@ mod errors { pub use errors::*; // Organize code internally (files, modules), but pull it all into a flat namespace to export. -mod sleep; -pub use sleep::*; -mod register; -pub use register::*; -mod sync; -pub use sync::*; -pub mod network_proto; -pub mod drive_proto; +mod sleep_file; +pub use sleep_file::*; +mod sleep_register; +pub use sleep_register::*; +mod protocol; +pub use protocol::*; +pub mod network_msg; +pub mod metadata_msg; diff --git a/src/metadata_msg.proto b/src/metadata_msg.proto new file mode 100644 index 0000000..cd36b30 --- /dev/null +++ b/src/metadata_msg.proto @@ -0,0 +1,18 @@ +// From hyperdrive:lib/messages.js + +message Index { + required string type = 1; + optional bytes content = 2; +} + +message Stat { + required uint32 mode = 1; + optional uint32 uid = 2; + optional uint32 gid = 3; + optional uint64 size = 4; + optional uint64 blocks = 5; + optional uint64 offset = 6; + optional uint64 byteOffset = 7; + optional uint64 mtime = 8; + optional uint64 ctime = 9; +} diff --git a/src/metadata_msg.rs b/src/metadata_msg.rs new file mode 100644 index 0000000..c30833a --- /dev/null +++ b/src/metadata_msg.rs @@ -0,0 +1,893 @@ +// This file is generated. 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 Index { + // message fields + field_type: ::protobuf::SingularField<::std::string::String>, + content: ::protobuf::SingularField<::std::vec::Vec>, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Index {} + +impl Index { + pub fn new() -> Index { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Index { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Index, + }; + unsafe { + instance.get(Index::new) + } + } + + // required string type = 1; + + pub fn clear_field_type(&mut self) { + self.field_type.clear(); + } + + pub fn has_field_type(&self) -> bool { + self.field_type.is_some() + } + + // Param is passed by value, moved + pub fn set_field_type(&mut self, v: ::std::string::String) { + self.field_type = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_field_type(&mut self) -> &mut ::std::string::String { + if self.field_type.is_none() { + self.field_type.set_default(); + } + self.field_type.as_mut().unwrap() + } + + // Take field + pub fn take_field_type(&mut self) -> ::std::string::String { + self.field_type.take().unwrap_or_else(|| ::std::string::String::new()) + } + + pub fn get_field_type(&self) -> &str { + match self.field_type.as_ref() { + Some(v) => &v, + None => "", + } + } + + fn get_field_type_for_reflect(&self) -> &::protobuf::SingularField<::std::string::String> { + &self.field_type + } + + fn mut_field_type_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::string::String> { + &mut self.field_type + } + + // optional bytes content = 2; + + pub fn clear_content(&mut self) { + self.content.clear(); + } + + pub fn has_content(&self) -> bool { + self.content.is_some() + } + + // Param is passed by value, moved + pub fn set_content(&mut self, v: ::std::vec::Vec) { + self.content = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_content(&mut self) -> &mut ::std::vec::Vec { + if self.content.is_none() { + self.content.set_default(); + } + self.content.as_mut().unwrap() + } + + // Take field + pub fn take_content(&mut self) -> ::std::vec::Vec { + self.content.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_content(&self) -> &[u8] { + match self.content.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_content_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.content + } + + fn mut_content_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.content + } +} + +impl ::protobuf::Message for Index { + fn is_initialized(&self) -> bool { + if self.field_type.is_none() { + 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_string_into(wire_type, is, &mut self.field_type)?; + }, + 2 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.content)?; + }, + _ => { + ::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.field_type.as_ref() { + my_size += ::protobuf::rt::string_size(1, &v); + } + if let Some(ref v) = self.content.as_ref() { + my_size += ::protobuf::rt::bytes_size(2, &v); + } + 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.field_type.as_ref() { + os.write_string(1, &v)?; + } + if let Some(ref v) = self.content.as_ref() { + os.write_bytes(2, &v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Index { + fn new() -> Index { + Index::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "type", + Index::get_field_type_for_reflect, + Index::mut_field_type_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "content", + Index::get_content_for_reflect, + Index::mut_content_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Index", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Index { + fn clear(&mut self) { + self.clear_field_type(); + self.clear_content(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Index { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Index { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Stat { + // message fields + mode: ::std::option::Option, + uid: ::std::option::Option, + gid: ::std::option::Option, + size: ::std::option::Option, + blocks: ::std::option::Option, + offset: ::std::option::Option, + byteOffset: ::std::option::Option, + mtime: ::std::option::Option, + ctime: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Stat {} + +impl Stat { + pub fn new() -> Stat { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Stat { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Stat, + }; + unsafe { + instance.get(Stat::new) + } + } + + // required uint32 mode = 1; + + pub fn clear_mode(&mut self) { + self.mode = ::std::option::Option::None; + } + + pub fn has_mode(&self) -> bool { + self.mode.is_some() + } + + // Param is passed by value, moved + pub fn set_mode(&mut self, v: u32) { + self.mode = ::std::option::Option::Some(v); + } + + pub fn get_mode(&self) -> u32 { + self.mode.unwrap_or(0) + } + + fn get_mode_for_reflect(&self) -> &::std::option::Option { + &self.mode + } + + fn mut_mode_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.mode + } + + // optional uint32 uid = 2; + + pub fn clear_uid(&mut self) { + self.uid = ::std::option::Option::None; + } + + pub fn has_uid(&self) -> bool { + self.uid.is_some() + } + + // Param is passed by value, moved + pub fn set_uid(&mut self, v: u32) { + self.uid = ::std::option::Option::Some(v); + } + + pub fn get_uid(&self) -> u32 { + self.uid.unwrap_or(0) + } + + fn get_uid_for_reflect(&self) -> &::std::option::Option { + &self.uid + } + + fn mut_uid_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.uid + } + + // optional uint32 gid = 3; + + pub fn clear_gid(&mut self) { + self.gid = ::std::option::Option::None; + } + + pub fn has_gid(&self) -> bool { + self.gid.is_some() + } + + // Param is passed by value, moved + pub fn set_gid(&mut self, v: u32) { + self.gid = ::std::option::Option::Some(v); + } + + pub fn get_gid(&self) -> u32 { + self.gid.unwrap_or(0) + } + + fn get_gid_for_reflect(&self) -> &::std::option::Option { + &self.gid + } + + fn mut_gid_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.gid + } + + // optional uint64 size = 4; + + pub fn clear_size(&mut self) { + self.size = ::std::option::Option::None; + } + + pub fn has_size(&self) -> bool { + self.size.is_some() + } + + // Param is passed by value, moved + pub fn set_size(&mut self, v: u64) { + self.size = ::std::option::Option::Some(v); + } + + pub fn get_size(&self) -> u64 { + self.size.unwrap_or(0) + } + + fn get_size_for_reflect(&self) -> &::std::option::Option { + &self.size + } + + fn mut_size_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.size + } + + // optional uint64 blocks = 5; + + pub fn clear_blocks(&mut self) { + self.blocks = ::std::option::Option::None; + } + + pub fn has_blocks(&self) -> bool { + self.blocks.is_some() + } + + // Param is passed by value, moved + pub fn set_blocks(&mut self, v: u64) { + self.blocks = ::std::option::Option::Some(v); + } + + pub fn get_blocks(&self) -> u64 { + self.blocks.unwrap_or(0) + } + + fn get_blocks_for_reflect(&self) -> &::std::option::Option { + &self.blocks + } + + fn mut_blocks_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.blocks + } + + // optional uint64 offset = 6; + + pub fn clear_offset(&mut self) { + self.offset = ::std::option::Option::None; + } + + pub fn has_offset(&self) -> bool { + self.offset.is_some() + } + + // Param is passed by value, moved + pub fn set_offset(&mut self, v: u64) { + self.offset = ::std::option::Option::Some(v); + } + + pub fn get_offset(&self) -> u64 { + self.offset.unwrap_or(0) + } + + fn get_offset_for_reflect(&self) -> &::std::option::Option { + &self.offset + } + + fn mut_offset_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.offset + } + + // optional uint64 byteOffset = 7; + + pub fn clear_byteOffset(&mut self) { + self.byteOffset = ::std::option::Option::None; + } + + pub fn has_byteOffset(&self) -> bool { + self.byteOffset.is_some() + } + + // Param is passed by value, moved + pub fn set_byteOffset(&mut self, v: u64) { + self.byteOffset = ::std::option::Option::Some(v); + } + + pub fn get_byteOffset(&self) -> u64 { + self.byteOffset.unwrap_or(0) + } + + fn get_byteOffset_for_reflect(&self) -> &::std::option::Option { + &self.byteOffset + } + + fn mut_byteOffset_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.byteOffset + } + + // optional uint64 mtime = 8; + + pub fn clear_mtime(&mut self) { + self.mtime = ::std::option::Option::None; + } + + pub fn has_mtime(&self) -> bool { + self.mtime.is_some() + } + + // Param is passed by value, moved + pub fn set_mtime(&mut self, v: u64) { + self.mtime = ::std::option::Option::Some(v); + } + + pub fn get_mtime(&self) -> u64 { + self.mtime.unwrap_or(0) + } + + fn get_mtime_for_reflect(&self) -> &::std::option::Option { + &self.mtime + } + + fn mut_mtime_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.mtime + } + + // optional uint64 ctime = 9; + + pub fn clear_ctime(&mut self) { + self.ctime = ::std::option::Option::None; + } + + pub fn has_ctime(&self) -> bool { + self.ctime.is_some() + } + + // Param is passed by value, moved + pub fn set_ctime(&mut self, v: u64) { + self.ctime = ::std::option::Option::Some(v); + } + + pub fn get_ctime(&self) -> u64 { + self.ctime.unwrap_or(0) + } + + fn get_ctime_for_reflect(&self) -> &::std::option::Option { + &self.ctime + } + + fn mut_ctime_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.ctime + } +} + +impl ::protobuf::Message for Stat { + fn is_initialized(&self) -> bool { + if self.mode.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint32()?; + self.mode = ::std::option::Option::Some(tmp); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint32()?; + self.uid = ::std::option::Option::Some(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_uint32()?; + self.gid = ::std::option::Option::Some(tmp); + }, + 4 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.size = ::std::option::Option::Some(tmp); + }, + 5 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.blocks = ::std::option::Option::Some(tmp); + }, + 6 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.offset = ::std::option::Option::Some(tmp); + }, + 7 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.byteOffset = ::std::option::Option::Some(tmp); + }, + 8 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.mtime = ::std::option::Option::Some(tmp); + }, + 9 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.ctime = ::std::option::Option::Some(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 let Some(v) = self.mode { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.uid { + my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.gid { + my_size += ::protobuf::rt::value_size(3, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.size { + my_size += ::protobuf::rt::value_size(4, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.blocks { + my_size += ::protobuf::rt::value_size(5, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.offset { + my_size += ::protobuf::rt::value_size(6, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.byteOffset { + my_size += ::protobuf::rt::value_size(7, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.mtime { + my_size += ::protobuf::rt::value_size(8, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.ctime { + my_size += ::protobuf::rt::value_size(9, v, ::protobuf::wire_format::WireTypeVarint); + } + 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(v) = self.mode { + os.write_uint32(1, v)?; + } + if let Some(v) = self.uid { + os.write_uint32(2, v)?; + } + if let Some(v) = self.gid { + os.write_uint32(3, v)?; + } + if let Some(v) = self.size { + os.write_uint64(4, v)?; + } + if let Some(v) = self.blocks { + os.write_uint64(5, v)?; + } + if let Some(v) = self.offset { + os.write_uint64(6, v)?; + } + if let Some(v) = self.byteOffset { + os.write_uint64(7, v)?; + } + if let Some(v) = self.mtime { + os.write_uint64(8, v)?; + } + if let Some(v) = self.ctime { + os.write_uint64(9, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Stat { + fn new() -> Stat { + Stat::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( + "mode", + Stat::get_mode_for_reflect, + Stat::mut_mode_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( + "uid", + Stat::get_uid_for_reflect, + Stat::mut_uid_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint32>( + "gid", + Stat::get_gid_for_reflect, + Stat::mut_gid_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "size", + Stat::get_size_for_reflect, + Stat::mut_size_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "blocks", + Stat::get_blocks_for_reflect, + Stat::mut_blocks_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "offset", + Stat::get_offset_for_reflect, + Stat::mut_offset_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "byteOffset", + Stat::get_byteOffset_for_reflect, + Stat::mut_byteOffset_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "mtime", + Stat::get_mtime_for_reflect, + Stat::mut_mtime_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "ctime", + Stat::get_ctime_for_reflect, + Stat::mut_ctime_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Stat", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Stat { + fn clear(&mut self) { + self.clear_mode(); + self.clear_uid(); + self.clear_gid(); + self.clear_size(); + self.clear_blocks(); + self.clear_offset(); + self.clear_byteOffset(); + self.clear_mtime(); + self.clear_ctime(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Stat { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Stat { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\x10hyperdrive.proto\"5\n\x05Index\x12\x12\n\x04type\x18\x01\x20\x02(\ + \tR\x04type\x12\x18\n\x07content\x18\x02\x20\x01(\x0cR\x07content\"\xce\ + \x01\n\x04Stat\x12\x12\n\x04mode\x18\x01\x20\x02(\rR\x04mode\x12\x10\n\ + \x03uid\x18\x02\x20\x01(\rR\x03uid\x12\x10\n\x03gid\x18\x03\x20\x01(\rR\ + \x03gid\x12\x12\n\x04size\x18\x04\x20\x01(\x04R\x04size\x12\x16\n\x06blo\ + cks\x18\x05\x20\x01(\x04R\x06blocks\x12\x16\n\x06offset\x18\x06\x20\x01(\ + \x04R\x06offset\x12\x1e\n\nbyteOffset\x18\x07\x20\x01(\x04R\nbyteOffset\ + \x12\x14\n\x05mtime\x18\x08\x20\x01(\x04R\x05mtime\x12\x14\n\x05ctime\ + \x18\t\x20\x01(\x04R\x05ctimeJ\xd2\x06\n\x06\x12\x04\x02\0\x11\x01\n-\n\ + \x02\x04\0\x12\x04\x02\0\x05\x012!\x20From\x20hyperdrive:lib/messages.js\ + \n\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\r\n\x0b\n\x04\x04\0\x02\0\x12\x03\ + \x03\x02\x1b\n\x0c\n\x05\x04\0\x02\0\x04\x12\x03\x03\x02\n\n\x0c\n\x05\ + \x04\0\x02\0\x05\x12\x03\x03\x0b\x11\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\ + \x03\x12\x16\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x19\x1a\n\x0b\n\x04\ + \x04\0\x02\x01\x12\x03\x04\x02\x1d\n\x0c\n\x05\x04\0\x02\x01\x04\x12\x03\ + \x04\x02\n\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x0b\x10\n\x0c\n\x05\ + \x04\0\x02\x01\x01\x12\x03\x04\x11\x18\n\x0c\n\x05\x04\0\x02\x01\x03\x12\ + \x03\x04\x1b\x1c\n\n\n\x02\x04\x01\x12\x04\x07\0\x11\x01\n\n\n\x03\x04\ + \x01\x01\x12\x03\x07\x08\x0c\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\x02\ + \x1b\n\x0c\n\x05\x04\x01\x02\0\x04\x12\x03\x08\x02\n\n\x0c\n\x05\x04\x01\ + \x02\0\x05\x12\x03\x08\x0b\x11\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x08\ + \x12\x16\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\x08\x19\x1a\n\x0b\n\x04\ + \x04\x01\x02\x01\x12\x03\t\x02\x1a\n\x0c\n\x05\x04\x01\x02\x01\x04\x12\ + \x03\t\x02\n\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\t\x0b\x11\n\x0c\n\ + \x05\x04\x01\x02\x01\x01\x12\x03\t\x12\x15\n\x0c\n\x05\x04\x01\x02\x01\ + \x03\x12\x03\t\x18\x19\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\n\x02\x1a\n\ + \x0c\n\x05\x04\x01\x02\x02\x04\x12\x03\n\x02\n\n\x0c\n\x05\x04\x01\x02\ + \x02\x05\x12\x03\n\x0b\x11\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x12\ + \x15\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\n\x18\x19\n\x0b\n\x04\x04\ + \x01\x02\x03\x12\x03\x0b\x02\x1b\n\x0c\n\x05\x04\x01\x02\x03\x04\x12\x03\ + \x0b\x02\n\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x0b\x0b\x11\n\x0c\n\ + \x05\x04\x01\x02\x03\x01\x12\x03\x0b\x12\x16\n\x0c\n\x05\x04\x01\x02\x03\ + \x03\x12\x03\x0b\x19\x1a\n\x0b\n\x04\x04\x01\x02\x04\x12\x03\x0c\x02\x1d\ + \n\x0c\n\x05\x04\x01\x02\x04\x04\x12\x03\x0c\x02\n\n\x0c\n\x05\x04\x01\ + \x02\x04\x05\x12\x03\x0c\x0b\x11\n\x0c\n\x05\x04\x01\x02\x04\x01\x12\x03\ + \x0c\x12\x18\n\x0c\n\x05\x04\x01\x02\x04\x03\x12\x03\x0c\x1b\x1c\n\x0b\n\ + \x04\x04\x01\x02\x05\x12\x03\r\x02\x1d\n\x0c\n\x05\x04\x01\x02\x05\x04\ + \x12\x03\r\x02\n\n\x0c\n\x05\x04\x01\x02\x05\x05\x12\x03\r\x0b\x11\n\x0c\ + \n\x05\x04\x01\x02\x05\x01\x12\x03\r\x12\x18\n\x0c\n\x05\x04\x01\x02\x05\ + \x03\x12\x03\r\x1b\x1c\n\x0b\n\x04\x04\x01\x02\x06\x12\x03\x0e\x02!\n\ + \x0c\n\x05\x04\x01\x02\x06\x04\x12\x03\x0e\x02\n\n\x0c\n\x05\x04\x01\x02\ + \x06\x05\x12\x03\x0e\x0b\x11\n\x0c\n\x05\x04\x01\x02\x06\x01\x12\x03\x0e\ + \x12\x1c\n\x0c\n\x05\x04\x01\x02\x06\x03\x12\x03\x0e\x1f\x20\n\x0b\n\x04\ + \x04\x01\x02\x07\x12\x03\x0f\x02\x1c\n\x0c\n\x05\x04\x01\x02\x07\x04\x12\ + \x03\x0f\x02\n\n\x0c\n\x05\x04\x01\x02\x07\x05\x12\x03\x0f\x0b\x11\n\x0c\ + \n\x05\x04\x01\x02\x07\x01\x12\x03\x0f\x12\x17\n\x0c\n\x05\x04\x01\x02\ + \x07\x03\x12\x03\x0f\x1a\x1b\n\x0b\n\x04\x04\x01\x02\x08\x12\x03\x10\x02\ + \x1c\n\x0c\n\x05\x04\x01\x02\x08\x04\x12\x03\x10\x02\n\n\x0c\n\x05\x04\ + \x01\x02\x08\x05\x12\x03\x10\x0b\x11\n\x0c\n\x05\x04\x01\x02\x08\x01\x12\ + \x03\x10\x12\x17\n\x0c\n\x05\x04\x01\x02\x08\x03\x12\x03\x10\x1a\x1b\ +"; + +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/network_msg.rs b/src/network_msg.rs new file mode 100644 index 0000000..e9dae76 --- /dev/null +++ b/src/network_msg.rs @@ -0,0 +1,3199 @@ +// This file is generated. 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 Feed { + // message fields + discoveryKey: ::protobuf::SingularField<::std::vec::Vec>, + nonce: ::protobuf::SingularField<::std::vec::Vec>, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Feed {} + +impl Feed { + pub fn new() -> Feed { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Feed { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Feed, + }; + unsafe { + instance.get(Feed::new) + } + } + + // required bytes discoveryKey = 1; + + pub fn clear_discoveryKey(&mut self) { + self.discoveryKey.clear(); + } + + pub fn has_discoveryKey(&self) -> bool { + self.discoveryKey.is_some() + } + + // Param is passed by value, moved + pub fn set_discoveryKey(&mut self, v: ::std::vec::Vec) { + self.discoveryKey = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_discoveryKey(&mut self) -> &mut ::std::vec::Vec { + if self.discoveryKey.is_none() { + self.discoveryKey.set_default(); + } + self.discoveryKey.as_mut().unwrap() + } + + // Take field + pub fn take_discoveryKey(&mut self) -> ::std::vec::Vec { + self.discoveryKey.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_discoveryKey(&self) -> &[u8] { + match self.discoveryKey.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_discoveryKey_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.discoveryKey + } + + fn mut_discoveryKey_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.discoveryKey + } + + // optional bytes nonce = 2; + + pub fn clear_nonce(&mut self) { + self.nonce.clear(); + } + + pub fn has_nonce(&self) -> bool { + self.nonce.is_some() + } + + // Param is passed by value, moved + pub fn set_nonce(&mut self, v: ::std::vec::Vec) { + self.nonce = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_nonce(&mut self) -> &mut ::std::vec::Vec { + if self.nonce.is_none() { + self.nonce.set_default(); + } + self.nonce.as_mut().unwrap() + } + + // Take field + pub fn take_nonce(&mut self) -> ::std::vec::Vec { + self.nonce.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_nonce(&self) -> &[u8] { + match self.nonce.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_nonce_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.nonce + } + + fn mut_nonce_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.nonce + } +} + +impl ::protobuf::Message for Feed { + fn is_initialized(&self) -> bool { + if self.discoveryKey.is_none() { + 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_bytes_into(wire_type, is, &mut self.discoveryKey)?; + }, + 2 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.nonce)?; + }, + _ => { + ::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.discoveryKey.as_ref() { + my_size += ::protobuf::rt::bytes_size(1, &v); + } + if let Some(ref v) = self.nonce.as_ref() { + my_size += ::protobuf::rt::bytes_size(2, &v); + } + 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.discoveryKey.as_ref() { + os.write_bytes(1, &v)?; + } + if let Some(ref v) = self.nonce.as_ref() { + os.write_bytes(2, &v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Feed { + fn new() -> Feed { + Feed::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "discoveryKey", + Feed::get_discoveryKey_for_reflect, + Feed::mut_discoveryKey_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "nonce", + Feed::get_nonce_for_reflect, + Feed::mut_nonce_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Feed", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Feed { + fn clear(&mut self) { + self.clear_discoveryKey(); + self.clear_nonce(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Feed { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Feed { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Handshake { + // message fields + id: ::protobuf::SingularField<::std::vec::Vec>, + live: ::std::option::Option, + userData: ::protobuf::SingularField<::std::vec::Vec>, + extensions: ::protobuf::RepeatedField<::std::string::String>, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Handshake {} + +impl Handshake { + pub fn new() -> Handshake { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Handshake { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Handshake, + }; + unsafe { + instance.get(Handshake::new) + } + } + + // optional bytes id = 1; + + pub fn clear_id(&mut self) { + self.id.clear(); + } + + pub fn has_id(&self) -> bool { + self.id.is_some() + } + + // Param is passed by value, moved + pub fn set_id(&mut self, v: ::std::vec::Vec) { + self.id = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_id(&mut self) -> &mut ::std::vec::Vec { + if self.id.is_none() { + self.id.set_default(); + } + self.id.as_mut().unwrap() + } + + // Take field + pub fn take_id(&mut self) -> ::std::vec::Vec { + self.id.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_id(&self) -> &[u8] { + match self.id.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_id_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.id + } + + fn mut_id_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.id + } + + // optional bool live = 2; + + pub fn clear_live(&mut self) { + self.live = ::std::option::Option::None; + } + + pub fn has_live(&self) -> bool { + self.live.is_some() + } + + // Param is passed by value, moved + pub fn set_live(&mut self, v: bool) { + self.live = ::std::option::Option::Some(v); + } + + pub fn get_live(&self) -> bool { + self.live.unwrap_or(false) + } + + fn get_live_for_reflect(&self) -> &::std::option::Option { + &self.live + } + + fn mut_live_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.live + } + + // optional bytes userData = 3; + + pub fn clear_userData(&mut self) { + self.userData.clear(); + } + + pub fn has_userData(&self) -> bool { + self.userData.is_some() + } + + // Param is passed by value, moved + pub fn set_userData(&mut self, v: ::std::vec::Vec) { + self.userData = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_userData(&mut self) -> &mut ::std::vec::Vec { + if self.userData.is_none() { + self.userData.set_default(); + } + self.userData.as_mut().unwrap() + } + + // Take field + pub fn take_userData(&mut self) -> ::std::vec::Vec { + self.userData.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_userData(&self) -> &[u8] { + match self.userData.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_userData_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.userData + } + + fn mut_userData_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.userData + } + + // repeated string extensions = 4; + + pub fn clear_extensions(&mut self) { + self.extensions.clear(); + } + + // Param is passed by value, moved + pub fn set_extensions(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { + self.extensions = v; + } + + // Mutable pointer to the field. + pub fn mut_extensions(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { + &mut self.extensions + } + + // Take field + pub fn take_extensions(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { + ::std::mem::replace(&mut self.extensions, ::protobuf::RepeatedField::new()) + } + + pub fn get_extensions(&self) -> &[::std::string::String] { + &self.extensions + } + + fn get_extensions_for_reflect(&self) -> &::protobuf::RepeatedField<::std::string::String> { + &self.extensions + } + + fn mut_extensions_for_reflect(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { + &mut self.extensions + } +} + +impl ::protobuf::Message for Handshake { + 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_bytes_into(wire_type, is, &mut self.id)?; + }, + 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.live = ::std::option::Option::Some(tmp); + }, + 3 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.userData)?; + }, + 4 => { + ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.extensions)?; + }, + _ => { + ::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.id.as_ref() { + my_size += ::protobuf::rt::bytes_size(1, &v); + } + if let Some(v) = self.live { + my_size += 2; + } + if let Some(ref v) = self.userData.as_ref() { + my_size += ::protobuf::rt::bytes_size(3, &v); + } + for value in &self.extensions { + my_size += ::protobuf::rt::string_size(4, &value); + }; + 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.id.as_ref() { + os.write_bytes(1, &v)?; + } + if let Some(v) = self.live { + os.write_bool(2, v)?; + } + if let Some(ref v) = self.userData.as_ref() { + os.write_bytes(3, &v)?; + } + for v in &self.extensions { + os.write_string(4, &v)?; + }; + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Handshake { + fn new() -> Handshake { + Handshake::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "id", + Handshake::get_id_for_reflect, + Handshake::mut_id_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "live", + Handshake::get_live_for_reflect, + Handshake::mut_live_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "userData", + Handshake::get_userData_for_reflect, + Handshake::mut_userData_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( + "extensions", + Handshake::get_extensions_for_reflect, + Handshake::mut_extensions_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Handshake", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Handshake { + fn clear(&mut self) { + self.clear_id(); + self.clear_live(); + self.clear_userData(); + self.clear_extensions(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Handshake { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Handshake { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Info { + // message fields + uploading: ::std::option::Option, + downloading: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Info {} + +impl Info { + pub fn new() -> Info { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Info { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Info, + }; + unsafe { + instance.get(Info::new) + } + } + + // optional bool uploading = 1; + + pub fn clear_uploading(&mut self) { + self.uploading = ::std::option::Option::None; + } + + pub fn has_uploading(&self) -> bool { + self.uploading.is_some() + } + + // Param is passed by value, moved + pub fn set_uploading(&mut self, v: bool) { + self.uploading = ::std::option::Option::Some(v); + } + + pub fn get_uploading(&self) -> bool { + self.uploading.unwrap_or(false) + } + + fn get_uploading_for_reflect(&self) -> &::std::option::Option { + &self.uploading + } + + fn mut_uploading_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.uploading + } + + // optional bool downloading = 2; + + pub fn clear_downloading(&mut self) { + self.downloading = ::std::option::Option::None; + } + + pub fn has_downloading(&self) -> bool { + self.downloading.is_some() + } + + // Param is passed by value, moved + pub fn set_downloading(&mut self, v: bool) { + self.downloading = ::std::option::Option::Some(v); + } + + pub fn get_downloading(&self) -> bool { + self.downloading.unwrap_or(false) + } + + fn get_downloading_for_reflect(&self) -> &::std::option::Option { + &self.downloading + } + + fn mut_downloading_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.downloading + } +} + +impl ::protobuf::Message for Info { + 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 => { + 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.uploading = ::std::option::Option::Some(tmp); + }, + 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.downloading = ::std::option::Option::Some(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 let Some(v) = self.uploading { + my_size += 2; + } + if let Some(v) = self.downloading { + 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 let Some(v) = self.uploading { + os.write_bool(1, v)?; + } + if let Some(v) = self.downloading { + os.write_bool(2, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Info { + fn new() -> Info { + Info::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "uploading", + Info::get_uploading_for_reflect, + Info::mut_uploading_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "downloading", + Info::get_downloading_for_reflect, + Info::mut_downloading_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Info", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Info { + fn clear(&mut self) { + self.clear_uploading(); + self.clear_downloading(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Info { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Info { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Have { + // message fields + start: ::std::option::Option, + length: ::std::option::Option, + bitfield: ::protobuf::SingularField<::std::vec::Vec>, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Have {} + +impl Have { + pub fn new() -> Have { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Have { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Have, + }; + unsafe { + instance.get(Have::new) + } + } + + // required uint64 start = 1; + + pub fn clear_start(&mut self) { + self.start = ::std::option::Option::None; + } + + pub fn has_start(&self) -> bool { + self.start.is_some() + } + + // Param is passed by value, moved + pub fn set_start(&mut self, v: u64) { + self.start = ::std::option::Option::Some(v); + } + + pub fn get_start(&self) -> u64 { + self.start.unwrap_or(0) + } + + fn get_start_for_reflect(&self) -> &::std::option::Option { + &self.start + } + + fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.start + } + + // optional uint64 length = 2; + + pub fn clear_length(&mut self) { + self.length = ::std::option::Option::None; + } + + pub fn has_length(&self) -> bool { + self.length.is_some() + } + + // Param is passed by value, moved + pub fn set_length(&mut self, v: u64) { + self.length = ::std::option::Option::Some(v); + } + + pub fn get_length(&self) -> u64 { + self.length.unwrap_or(1u64) + } + + fn get_length_for_reflect(&self) -> &::std::option::Option { + &self.length + } + + fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.length + } + + // optional bytes bitfield = 3; + + pub fn clear_bitfield(&mut self) { + self.bitfield.clear(); + } + + pub fn has_bitfield(&self) -> bool { + self.bitfield.is_some() + } + + // Param is passed by value, moved + pub fn set_bitfield(&mut self, v: ::std::vec::Vec) { + self.bitfield = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_bitfield(&mut self) -> &mut ::std::vec::Vec { + if self.bitfield.is_none() { + self.bitfield.set_default(); + } + self.bitfield.as_mut().unwrap() + } + + // Take field + pub fn take_bitfield(&mut self) -> ::std::vec::Vec { + self.bitfield.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_bitfield(&self) -> &[u8] { + match self.bitfield.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_bitfield_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.bitfield + } + + fn mut_bitfield_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.bitfield + } +} + +impl ::protobuf::Message for Have { + fn is_initialized(&self) -> bool { + if self.start.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.start = ::std::option::Option::Some(tmp); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.length = ::std::option::Option::Some(tmp); + }, + 3 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.bitfield)?; + }, + _ => { + ::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(v) = self.start { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.length { + my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(ref v) = self.bitfield.as_ref() { + my_size += ::protobuf::rt::bytes_size(3, &v); + } + 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(v) = self.start { + os.write_uint64(1, v)?; + } + if let Some(v) = self.length { + os.write_uint64(2, v)?; + } + if let Some(ref v) = self.bitfield.as_ref() { + os.write_bytes(3, &v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Have { + fn new() -> Have { + Have::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "start", + Have::get_start_for_reflect, + Have::mut_start_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "length", + Have::get_length_for_reflect, + Have::mut_length_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "bitfield", + Have::get_bitfield_for_reflect, + Have::mut_bitfield_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Have", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Have { + fn clear(&mut self) { + self.clear_start(); + self.clear_length(); + self.clear_bitfield(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Have { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Have { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Unhave { + // message fields + start: ::std::option::Option, + length: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Unhave {} + +impl Unhave { + pub fn new() -> Unhave { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Unhave { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Unhave, + }; + unsafe { + instance.get(Unhave::new) + } + } + + // required uint64 start = 1; + + pub fn clear_start(&mut self) { + self.start = ::std::option::Option::None; + } + + pub fn has_start(&self) -> bool { + self.start.is_some() + } + + // Param is passed by value, moved + pub fn set_start(&mut self, v: u64) { + self.start = ::std::option::Option::Some(v); + } + + pub fn get_start(&self) -> u64 { + self.start.unwrap_or(0) + } + + fn get_start_for_reflect(&self) -> &::std::option::Option { + &self.start + } + + fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.start + } + + // optional uint64 length = 2; + + pub fn clear_length(&mut self) { + self.length = ::std::option::Option::None; + } + + pub fn has_length(&self) -> bool { + self.length.is_some() + } + + // Param is passed by value, moved + pub fn set_length(&mut self, v: u64) { + self.length = ::std::option::Option::Some(v); + } + + pub fn get_length(&self) -> u64 { + self.length.unwrap_or(1u64) + } + + fn get_length_for_reflect(&self) -> &::std::option::Option { + &self.length + } + + fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.length + } +} + +impl ::protobuf::Message for Unhave { + fn is_initialized(&self) -> bool { + if self.start.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.start = ::std::option::Option::Some(tmp); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.length = ::std::option::Option::Some(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 let Some(v) = self.start { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.length { + my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); + } + 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(v) = self.start { + os.write_uint64(1, v)?; + } + if let Some(v) = self.length { + os.write_uint64(2, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Unhave { + fn new() -> Unhave { + Unhave::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "start", + Unhave::get_start_for_reflect, + Unhave::mut_start_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "length", + Unhave::get_length_for_reflect, + Unhave::mut_length_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Unhave", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Unhave { + fn clear(&mut self) { + self.clear_start(); + self.clear_length(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Unhave { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Unhave { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Want { + // message fields + start: ::std::option::Option, + length: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Want {} + +impl Want { + pub fn new() -> Want { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Want { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Want, + }; + unsafe { + instance.get(Want::new) + } + } + + // required uint64 start = 1; + + pub fn clear_start(&mut self) { + self.start = ::std::option::Option::None; + } + + pub fn has_start(&self) -> bool { + self.start.is_some() + } + + // Param is passed by value, moved + pub fn set_start(&mut self, v: u64) { + self.start = ::std::option::Option::Some(v); + } + + pub fn get_start(&self) -> u64 { + self.start.unwrap_or(0) + } + + fn get_start_for_reflect(&self) -> &::std::option::Option { + &self.start + } + + fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.start + } + + // optional uint64 length = 2; + + pub fn clear_length(&mut self) { + self.length = ::std::option::Option::None; + } + + pub fn has_length(&self) -> bool { + self.length.is_some() + } + + // Param is passed by value, moved + pub fn set_length(&mut self, v: u64) { + self.length = ::std::option::Option::Some(v); + } + + pub fn get_length(&self) -> u64 { + self.length.unwrap_or(0) + } + + fn get_length_for_reflect(&self) -> &::std::option::Option { + &self.length + } + + fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.length + } +} + +impl ::protobuf::Message for Want { + fn is_initialized(&self) -> bool { + if self.start.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.start = ::std::option::Option::Some(tmp); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.length = ::std::option::Option::Some(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 let Some(v) = self.start { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.length { + my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); + } + 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(v) = self.start { + os.write_uint64(1, v)?; + } + if let Some(v) = self.length { + os.write_uint64(2, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Want { + fn new() -> Want { + Want::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "start", + Want::get_start_for_reflect, + Want::mut_start_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "length", + Want::get_length_for_reflect, + Want::mut_length_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Want", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Want { + fn clear(&mut self) { + self.clear_start(); + self.clear_length(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Want { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Want { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Unwant { + // message fields + start: ::std::option::Option, + length: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Unwant {} + +impl Unwant { + pub fn new() -> Unwant { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Unwant { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Unwant, + }; + unsafe { + instance.get(Unwant::new) + } + } + + // required uint64 start = 1; + + pub fn clear_start(&mut self) { + self.start = ::std::option::Option::None; + } + + pub fn has_start(&self) -> bool { + self.start.is_some() + } + + // Param is passed by value, moved + pub fn set_start(&mut self, v: u64) { + self.start = ::std::option::Option::Some(v); + } + + pub fn get_start(&self) -> u64 { + self.start.unwrap_or(0) + } + + fn get_start_for_reflect(&self) -> &::std::option::Option { + &self.start + } + + fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.start + } + + // optional uint64 length = 2; + + pub fn clear_length(&mut self) { + self.length = ::std::option::Option::None; + } + + pub fn has_length(&self) -> bool { + self.length.is_some() + } + + // Param is passed by value, moved + pub fn set_length(&mut self, v: u64) { + self.length = ::std::option::Option::Some(v); + } + + pub fn get_length(&self) -> u64 { + self.length.unwrap_or(0) + } + + fn get_length_for_reflect(&self) -> &::std::option::Option { + &self.length + } + + fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.length + } +} + +impl ::protobuf::Message for Unwant { + fn is_initialized(&self) -> bool { + if self.start.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.start = ::std::option::Option::Some(tmp); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.length = ::std::option::Option::Some(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 let Some(v) = self.start { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.length { + my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); + } + 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(v) = self.start { + os.write_uint64(1, v)?; + } + if let Some(v) = self.length { + os.write_uint64(2, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Unwant { + fn new() -> Unwant { + Unwant::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "start", + Unwant::get_start_for_reflect, + Unwant::mut_start_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "length", + Unwant::get_length_for_reflect, + Unwant::mut_length_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Unwant", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Unwant { + fn clear(&mut self) { + self.clear_start(); + self.clear_length(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Unwant { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Unwant { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Request { + // message fields + index: ::std::option::Option, + bytes: ::std::option::Option, + hash: ::std::option::Option, + nodes: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Request {} + +impl Request { + pub fn new() -> Request { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Request { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Request, + }; + unsafe { + instance.get(Request::new) + } + } + + // required uint64 index = 1; + + pub fn clear_index(&mut self) { + self.index = ::std::option::Option::None; + } + + pub fn has_index(&self) -> bool { + self.index.is_some() + } + + // Param is passed by value, moved + pub fn set_index(&mut self, v: u64) { + self.index = ::std::option::Option::Some(v); + } + + pub fn get_index(&self) -> u64 { + self.index.unwrap_or(0) + } + + fn get_index_for_reflect(&self) -> &::std::option::Option { + &self.index + } + + fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.index + } + + // optional uint64 bytes = 2; + + pub fn clear_bytes(&mut self) { + self.bytes = ::std::option::Option::None; + } + + pub fn has_bytes(&self) -> bool { + self.bytes.is_some() + } + + // Param is passed by value, moved + pub fn set_bytes(&mut self, v: u64) { + self.bytes = ::std::option::Option::Some(v); + } + + pub fn get_bytes(&self) -> u64 { + self.bytes.unwrap_or(0) + } + + fn get_bytes_for_reflect(&self) -> &::std::option::Option { + &self.bytes + } + + fn mut_bytes_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.bytes + } + + // optional bool hash = 3; + + pub fn clear_hash(&mut self) { + self.hash = ::std::option::Option::None; + } + + pub fn has_hash(&self) -> bool { + self.hash.is_some() + } + + // Param is passed by value, moved + pub fn set_hash(&mut self, v: bool) { + self.hash = ::std::option::Option::Some(v); + } + + pub fn get_hash(&self) -> bool { + self.hash.unwrap_or(false) + } + + fn get_hash_for_reflect(&self) -> &::std::option::Option { + &self.hash + } + + fn mut_hash_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.hash + } + + // optional uint64 nodes = 4; + + pub fn clear_nodes(&mut self) { + self.nodes = ::std::option::Option::None; + } + + pub fn has_nodes(&self) -> bool { + self.nodes.is_some() + } + + // Param is passed by value, moved + pub fn set_nodes(&mut self, v: u64) { + self.nodes = ::std::option::Option::Some(v); + } + + pub fn get_nodes(&self) -> u64 { + self.nodes.unwrap_or(0) + } + + fn get_nodes_for_reflect(&self) -> &::std::option::Option { + &self.nodes + } + + fn mut_nodes_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.nodes + } +} + +impl ::protobuf::Message for Request { + fn is_initialized(&self) -> bool { + if self.index.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.index = ::std::option::Option::Some(tmp); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.bytes = ::std::option::Option::Some(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.hash = ::std::option::Option::Some(tmp); + }, + 4 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.nodes = ::std::option::Option::Some(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 let Some(v) = self.index { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.bytes { + my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.hash { + my_size += 2; + } + if let Some(v) = self.nodes { + my_size += ::protobuf::rt::value_size(4, v, ::protobuf::wire_format::WireTypeVarint); + } + 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(v) = self.index { + os.write_uint64(1, v)?; + } + if let Some(v) = self.bytes { + os.write_uint64(2, v)?; + } + if let Some(v) = self.hash { + os.write_bool(3, v)?; + } + if let Some(v) = self.nodes { + os.write_uint64(4, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Request { + fn new() -> Request { + Request::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "index", + Request::get_index_for_reflect, + Request::mut_index_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "bytes", + Request::get_bytes_for_reflect, + Request::mut_bytes_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "hash", + Request::get_hash_for_reflect, + Request::mut_hash_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "nodes", + Request::get_nodes_for_reflect, + Request::mut_nodes_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Request", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Request { + fn clear(&mut self) { + self.clear_index(); + self.clear_bytes(); + self.clear_hash(); + self.clear_nodes(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Request { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Request { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Cancel { + // message fields + index: ::std::option::Option, + bytes: ::std::option::Option, + hash: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Cancel {} + +impl Cancel { + pub fn new() -> Cancel { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Cancel { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Cancel, + }; + unsafe { + instance.get(Cancel::new) + } + } + + // required uint64 index = 1; + + pub fn clear_index(&mut self) { + self.index = ::std::option::Option::None; + } + + pub fn has_index(&self) -> bool { + self.index.is_some() + } + + // Param is passed by value, moved + pub fn set_index(&mut self, v: u64) { + self.index = ::std::option::Option::Some(v); + } + + pub fn get_index(&self) -> u64 { + self.index.unwrap_or(0) + } + + fn get_index_for_reflect(&self) -> &::std::option::Option { + &self.index + } + + fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.index + } + + // optional uint64 bytes = 2; + + pub fn clear_bytes(&mut self) { + self.bytes = ::std::option::Option::None; + } + + pub fn has_bytes(&self) -> bool { + self.bytes.is_some() + } + + // Param is passed by value, moved + pub fn set_bytes(&mut self, v: u64) { + self.bytes = ::std::option::Option::Some(v); + } + + pub fn get_bytes(&self) -> u64 { + self.bytes.unwrap_or(0) + } + + fn get_bytes_for_reflect(&self) -> &::std::option::Option { + &self.bytes + } + + fn mut_bytes_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.bytes + } + + // optional bool hash = 3; + + pub fn clear_hash(&mut self) { + self.hash = ::std::option::Option::None; + } + + pub fn has_hash(&self) -> bool { + self.hash.is_some() + } + + // Param is passed by value, moved + pub fn set_hash(&mut self, v: bool) { + self.hash = ::std::option::Option::Some(v); + } + + pub fn get_hash(&self) -> bool { + self.hash.unwrap_or(false) + } + + fn get_hash_for_reflect(&self) -> &::std::option::Option { + &self.hash + } + + fn mut_hash_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.hash + } +} + +impl ::protobuf::Message for Cancel { + fn is_initialized(&self) -> bool { + if self.index.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.index = ::std::option::Option::Some(tmp); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.bytes = ::std::option::Option::Some(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.hash = ::std::option::Option::Some(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 let Some(v) = self.index { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.bytes { + my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(v) = self.hash { + 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 let Some(v) = self.index { + os.write_uint64(1, v)?; + } + if let Some(v) = self.bytes { + os.write_uint64(2, v)?; + } + if let Some(v) = self.hash { + os.write_bool(3, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Cancel { + fn new() -> Cancel { + Cancel::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "index", + Cancel::get_index_for_reflect, + Cancel::mut_index_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "bytes", + Cancel::get_bytes_for_reflect, + Cancel::mut_bytes_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( + "hash", + Cancel::get_hash_for_reflect, + Cancel::mut_hash_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Cancel", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Cancel { + fn clear(&mut self) { + self.clear_index(); + self.clear_bytes(); + self.clear_hash(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Cancel { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Cancel { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Data { + // message fields + index: ::std::option::Option, + value: ::protobuf::SingularField<::std::vec::Vec>, + nodes: ::protobuf::RepeatedField, + signature: ::protobuf::SingularField<::std::vec::Vec>, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Data {} + +impl Data { + pub fn new() -> Data { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Data { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Data, + }; + unsafe { + instance.get(Data::new) + } + } + + // required uint64 index = 1; + + pub fn clear_index(&mut self) { + self.index = ::std::option::Option::None; + } + + pub fn has_index(&self) -> bool { + self.index.is_some() + } + + // Param is passed by value, moved + pub fn set_index(&mut self, v: u64) { + self.index = ::std::option::Option::Some(v); + } + + pub fn get_index(&self) -> u64 { + self.index.unwrap_or(0) + } + + fn get_index_for_reflect(&self) -> &::std::option::Option { + &self.index + } + + fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.index + } + + // optional bytes value = 2; + + pub fn clear_value(&mut self) { + self.value.clear(); + } + + pub fn has_value(&self) -> bool { + self.value.is_some() + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: ::std::vec::Vec) { + self.value = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_value(&mut self) -> &mut ::std::vec::Vec { + if self.value.is_none() { + self.value.set_default(); + } + self.value.as_mut().unwrap() + } + + // Take field + pub fn take_value(&mut self) -> ::std::vec::Vec { + self.value.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_value(&self) -> &[u8] { + match self.value.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_value_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.value + } + + fn mut_value_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.value + } + + // repeated .Data.Node nodes = 3; + + pub fn clear_nodes(&mut self) { + self.nodes.clear(); + } + + // Param is passed by value, moved + pub fn set_nodes(&mut self, v: ::protobuf::RepeatedField) { + self.nodes = v; + } + + // Mutable pointer to the field. + pub fn mut_nodes(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.nodes + } + + // Take field + pub fn take_nodes(&mut self) -> ::protobuf::RepeatedField { + ::std::mem::replace(&mut self.nodes, ::protobuf::RepeatedField::new()) + } + + pub fn get_nodes(&self) -> &[Data_Node] { + &self.nodes + } + + fn get_nodes_for_reflect(&self) -> &::protobuf::RepeatedField { + &self.nodes + } + + fn mut_nodes_for_reflect(&mut self) -> &mut ::protobuf::RepeatedField { + &mut self.nodes + } + + // optional bytes signature = 4; + + pub fn clear_signature(&mut self) { + self.signature.clear(); + } + + pub fn has_signature(&self) -> bool { + self.signature.is_some() + } + + // Param is passed by value, moved + pub fn set_signature(&mut self, v: ::std::vec::Vec) { + self.signature = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_signature(&mut self) -> &mut ::std::vec::Vec { + if self.signature.is_none() { + self.signature.set_default(); + } + self.signature.as_mut().unwrap() + } + + // Take field + pub fn take_signature(&mut self) -> ::std::vec::Vec { + self.signature.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_signature(&self) -> &[u8] { + match self.signature.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_signature_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.signature + } + + fn mut_signature_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.signature + } +} + +impl ::protobuf::Message for Data { + fn is_initialized(&self) -> bool { + if self.index.is_none() { + return false; + } + for v in &self.nodes { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.index = ::std::option::Option::Some(tmp); + }, + 2 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.value)?; + }, + 3 => { + ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.nodes)?; + }, + 4 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.signature)?; + }, + _ => { + ::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(v) = self.index { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(ref v) = self.value.as_ref() { + my_size += ::protobuf::rt::bytes_size(2, &v); + } + for value in &self.nodes { + let len = value.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }; + if let Some(ref v) = self.signature.as_ref() { + my_size += ::protobuf::rt::bytes_size(4, &v); + } + 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(v) = self.index { + os.write_uint64(1, v)?; + } + if let Some(ref v) = self.value.as_ref() { + os.write_bytes(2, &v)?; + } + for v in &self.nodes { + os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }; + if let Some(ref v) = self.signature.as_ref() { + os.write_bytes(4, &v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Data { + fn new() -> Data { + Data::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "index", + Data::get_index_for_reflect, + Data::mut_index_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "value", + Data::get_value_for_reflect, + Data::mut_value_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "nodes", + Data::get_nodes_for_reflect, + Data::mut_nodes_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "signature", + Data::get_signature_for_reflect, + Data::mut_signature_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Data", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Data { + fn clear(&mut self) { + self.clear_index(); + self.clear_value(); + self.clear_nodes(); + self.clear_signature(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Data { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Data { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct Data_Node { + // message fields + index: ::std::option::Option, + hash: ::protobuf::SingularField<::std::vec::Vec>, + size: ::std::option::Option, + // special fields + unknown_fields: ::protobuf::UnknownFields, + cached_size: ::protobuf::CachedSize, +} + +// see codegen.rs for the explanation why impl Sync explicitly +unsafe impl ::std::marker::Sync for Data_Node {} + +impl Data_Node { + pub fn new() -> Data_Node { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static Data_Node { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const Data_Node, + }; + unsafe { + instance.get(Data_Node::new) + } + } + + // required uint64 index = 1; + + pub fn clear_index(&mut self) { + self.index = ::std::option::Option::None; + } + + pub fn has_index(&self) -> bool { + self.index.is_some() + } + + // Param is passed by value, moved + pub fn set_index(&mut self, v: u64) { + self.index = ::std::option::Option::Some(v); + } + + pub fn get_index(&self) -> u64 { + self.index.unwrap_or(0) + } + + fn get_index_for_reflect(&self) -> &::std::option::Option { + &self.index + } + + fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.index + } + + // required bytes hash = 2; + + pub fn clear_hash(&mut self) { + self.hash.clear(); + } + + pub fn has_hash(&self) -> bool { + self.hash.is_some() + } + + // Param is passed by value, moved + pub fn set_hash(&mut self, v: ::std::vec::Vec) { + self.hash = ::protobuf::SingularField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_hash(&mut self) -> &mut ::std::vec::Vec { + if self.hash.is_none() { + self.hash.set_default(); + } + self.hash.as_mut().unwrap() + } + + // Take field + pub fn take_hash(&mut self) -> ::std::vec::Vec { + self.hash.take().unwrap_or_else(|| ::std::vec::Vec::new()) + } + + pub fn get_hash(&self) -> &[u8] { + match self.hash.as_ref() { + Some(v) => &v, + None => &[], + } + } + + fn get_hash_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { + &self.hash + } + + fn mut_hash_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { + &mut self.hash + } + + // required uint64 size = 3; + + pub fn clear_size(&mut self) { + self.size = ::std::option::Option::None; + } + + pub fn has_size(&self) -> bool { + self.size.is_some() + } + + // Param is passed by value, moved + pub fn set_size(&mut self, v: u64) { + self.size = ::std::option::Option::Some(v); + } + + pub fn get_size(&self) -> u64 { + self.size.unwrap_or(0) + } + + fn get_size_for_reflect(&self) -> &::std::option::Option { + &self.size + } + + fn mut_size_for_reflect(&mut self) -> &mut ::std::option::Option { + &mut self.size + } +} + +impl ::protobuf::Message for Data_Node { + fn is_initialized(&self) -> bool { + if self.index.is_none() { + return false; + } + if self.hash.is_none() { + return false; + } + if self.size.is_none() { + 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 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.index = ::std::option::Option::Some(tmp); + }, + 2 => { + ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.hash)?; + }, + 3 => { + if wire_type != ::protobuf::wire_format::WireTypeVarint { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + let tmp = is.read_uint64()?; + self.size = ::std::option::Option::Some(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 let Some(v) = self.index { + my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); + } + if let Some(ref v) = self.hash.as_ref() { + my_size += ::protobuf::rt::bytes_size(2, &v); + } + if let Some(v) = self.size { + my_size += ::protobuf::rt::value_size(3, v, ::protobuf::wire_format::WireTypeVarint); + } + 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(v) = self.index { + os.write_uint64(1, v)?; + } + if let Some(ref v) = self.hash.as_ref() { + os.write_bytes(2, &v)?; + } + if let Some(v) = self.size { + os.write_uint64(3, v)?; + } + 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 { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for Data_Node { + fn new() -> Data_Node { + Data_Node::new() + } + + fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "index", + Data_Node::get_index_for_reflect, + Data_Node::mut_index_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "hash", + Data_Node::get_hash_for_reflect, + Data_Node::mut_hash_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( + "size", + Data_Node::get_size_for_reflect, + Data_Node::mut_size_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "Data_Node", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for Data_Node { + fn clear(&mut self) { + self.clear_index(); + self.clear_hash(); + self.clear_size(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for Data_Node { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for Data_Node { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\tdat.proto\"@\n\x04Feed\x12\"\n\x0cdiscoveryKey\x18\x01\x20\x02(\x0cR\ + \x0cdiscoveryKey\x12\x14\n\x05nonce\x18\x02\x20\x01(\x0cR\x05nonce\"k\n\ + \tHandshake\x12\x0e\n\x02id\x18\x01\x20\x01(\x0cR\x02id\x12\x12\n\x04liv\ + e\x18\x02\x20\x01(\x08R\x04live\x12\x1a\n\x08userData\x18\x03\x20\x01(\ + \x0cR\x08userData\x12\x1e\n\nextensions\x18\x04\x20\x03(\tR\nextensions\ + \"F\n\x04Info\x12\x1c\n\tuploading\x18\x01\x20\x01(\x08R\tuploading\x12\ + \x20\n\x0bdownloading\x18\x02\x20\x01(\x08R\x0bdownloading\"S\n\x04Have\ + \x12\x14\n\x05start\x18\x01\x20\x02(\x04R\x05start\x12\x19\n\x06length\ + \x18\x02\x20\x01(\x04:\x011R\x06length\x12\x1a\n\x08bitfield\x18\x03\x20\ + \x01(\x0cR\x08bitfield\"9\n\x06Unhave\x12\x14\n\x05start\x18\x01\x20\x02\ + (\x04R\x05start\x12\x19\n\x06length\x18\x02\x20\x01(\x04:\x011R\x06lengt\ + h\"4\n\x04Want\x12\x14\n\x05start\x18\x01\x20\x02(\x04R\x05start\x12\x16\ + \n\x06length\x18\x02\x20\x01(\x04R\x06length\"6\n\x06Unwant\x12\x14\n\ + \x05start\x18\x01\x20\x02(\x04R\x05start\x12\x16\n\x06length\x18\x02\x20\ + \x01(\x04R\x06length\"_\n\x07Request\x12\x14\n\x05index\x18\x01\x20\x02(\ + \x04R\x05index\x12\x14\n\x05bytes\x18\x02\x20\x01(\x04R\x05bytes\x12\x12\ + \n\x04hash\x18\x03\x20\x01(\x08R\x04hash\x12\x14\n\x05nodes\x18\x04\x20\ + \x01(\x04R\x05nodes\"H\n\x06Cancel\x12\x14\n\x05index\x18\x01\x20\x02(\ + \x04R\x05index\x12\x14\n\x05bytes\x18\x02\x20\x01(\x04R\x05bytes\x12\x12\ + \n\x04hash\x18\x03\x20\x01(\x08R\x04hash\"\xb8\x01\n\x04Data\x12\x14\n\ + \x05index\x18\x01\x20\x02(\x04R\x05index\x12\x14\n\x05value\x18\x02\x20\ + \x01(\x0cR\x05value\x12\x20\n\x05nodes\x18\x03\x20\x03(\x0b2\n.Data.Node\ + R\x05nodes\x12\x1c\n\tsignature\x18\x04\x20\x01(\x0cR\tsignature\x1aD\n\ + \x04Node\x12\x14\n\x05index\x18\x01\x20\x02(\x04R\x05index\x12\x12\n\x04\ + hash\x18\x02\x20\x02(\x0cR\x04hash\x12\x12\n\x04size\x18\x03\x20\x02(\ + \x04R\x04sizeJ\xce\x1a\n\x06\x12\x04\x04\0M\x01\n\x9f\x01\n\x02\x04\0\ + \x12\x04\x04\0\x07\x01\x1a7\x20type=0,\x20should\x20be\x20the\x20first\ + \x20message\x20sent\x20on\x20a\x20channel\n2Z\x20wire\x20format\x20is\ + \x20(
)\n\x20header\x20is\x20a\x20varint,\x20channe\ + l\x20<<\x204\x20|\x20<4-bit-type>\n\n\n\n\x03\x04\0\x01\x12\x03\x04\x08\ + \x0c\n\x0b\n\x04\x04\0\x02\0\x12\x03\x05\x02\"\n\x0c\n\x05\x04\0\x02\0\ + \x04\x12\x03\x05\x02\n\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x05\x0b\x10\n\ + \x0c\n\x05\x04\0\x02\0\x01\x12\x03\x05\x11\x1d\n\x0c\n\x05\x04\0\x02\0\ + \x03\x12\x03\x05\x20!\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x06\x02\x1b\n\ + \x0c\n\x05\x04\0\x02\x01\x04\x12\x03\x06\x02\n\n\x0c\n\x05\x04\0\x02\x01\ + \x05\x12\x03\x06\x0b\x10\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x06\x11\ + \x16\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x06\x19\x1a\nx\n\x02\x04\x01\ + \x12\x04\n\0\x0f\x01\x1al\x20type=1,\x20overall\x20connection\x20handsha\ + ke.\x20should\x20be\x20send\x20just\x20after\x20the\x20feed\x20message\ + \x20on\x20the\x20first\x20channel\x20only\n\n\n\n\x03\x04\x01\x01\x12\ + \x03\n\x08\x11\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x0b\x02\x18\n\x0c\n\x05\ + \x04\x01\x02\0\x04\x12\x03\x0b\x02\n\n\x0c\n\x05\x04\x01\x02\0\x05\x12\ + \x03\x0b\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x0b\x11\x13\n\x0c\ + \n\x05\x04\x01\x02\0\x03\x12\x03\x0b\x16\x17\nH\n\x04\x04\x01\x02\x01\ + \x12\x03\x0c\x02\x19\";\x20keep\x20the\x20connection\x20open\x20forever?\ + \x20both\x20ends\x20have\x20to\x20agree\n\n\x0c\n\x05\x04\x01\x02\x01\ + \x04\x12\x03\x0c\x02\n\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x0c\x0b\ + \x0f\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x0c\x10\x14\n\x0c\n\x05\x04\ + \x01\x02\x01\x03\x12\x03\x0c\x17\x18\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\ + \r\x02\x1e\n\x0c\n\x05\x04\x01\x02\x02\x04\x12\x03\r\x02\n\n\x0c\n\x05\ + \x04\x01\x02\x02\x05\x12\x03\r\x0b\x10\n\x0c\n\x05\x04\x01\x02\x02\x01\ + \x12\x03\r\x11\x19\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\r\x1c\x1d\n\ + \x0b\n\x04\x04\x01\x02\x03\x12\x03\x0e\x02!\n\x0c\n\x05\x04\x01\x02\x03\ + \x04\x12\x03\x0e\x02\n\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x0e\x0b\ + \x11\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0e\x12\x1c\n\x0c\n\x05\x04\ + \x01\x02\x03\x03\x12\x03\x0e\x1f\x20\n\xc4\x01\n\x02\x04\x02\x12\x04\x14\ + \0\x17\x01\x1a\xb7\x01\x20type=2,\x20message\x20indicating\x20state\x20c\ + hanges\x20etc.\n\x20initial\x20state\x20for\x20uploading/downloading\x20\ + is\x20true\n\x20if\x20both\x20ends\x20are\x20not\x20downloading\x20and\ + \x20not\x20live\x20it\x20is\x20safe\x20to\x20consider\x20the\x20stream\ + \x20ended\n\n\n\n\x03\x04\x02\x01\x12\x03\x14\x08\x0c\n\x0b\n\x04\x04\ + \x02\x02\0\x12\x03\x15\x02\x1e\n\x0c\n\x05\x04\x02\x02\0\x04\x12\x03\x15\ + \x02\n\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x15\x0b\x0f\n\x0c\n\x05\x04\ + \x02\x02\0\x01\x12\x03\x15\x10\x19\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\ + \x15\x1c\x1d\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x16\x02\x20\n\x0c\n\x05\ + \x04\x02\x02\x01\x04\x12\x03\x16\x02\n\n\x0c\n\x05\x04\x02\x02\x01\x05\ + \x12\x03\x16\x0b\x0f\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x16\x10\x1b\ + \n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x16\x1e\x1f\n&\n\x02\x04\x03\ + \x12\x04\x1a\0\x1e\x01\x1a\x1a\x20type=3,\x20what\x20do\x20we\x20have?\n\ + \n\n\n\x03\x04\x03\x01\x12\x03\x1a\x08\x0c\n\x0b\n\x04\x04\x03\x02\0\x12\ + \x03\x1b\x02\x1c\n\x0c\n\x05\x04\x03\x02\0\x04\x12\x03\x1b\x02\n\n\x0c\n\ + \x05\x04\x03\x02\0\x05\x12\x03\x1b\x0b\x11\n\x0c\n\x05\x04\x03\x02\0\x01\ + \x12\x03\x1b\x12\x17\n\x0c\n\x05\x04\x03\x02\0\x03\x12\x03\x1b\x1a\x1b\n\ + \x1c\n\x04\x04\x03\x02\x01\x12\x03\x1c\x02+\"\x0f\x20defaults\x20to\x201\ + \n\n\x0c\n\x05\x04\x03\x02\x01\x04\x12\x03\x1c\x02\n\n\x0c\n\x05\x04\x03\ + \x02\x01\x05\x12\x03\x1c\x0b\x11\n\x0c\n\x05\x04\x03\x02\x01\x01\x12\x03\ + \x1c\x12\x18\n\x0c\n\x05\x04\x03\x02\x01\x03\x12\x03\x1c\x1b\x1c\n\x0c\n\ + \x05\x04\x03\x02\x01\x08\x12\x03\x1c\x1d*\n\x0c\n\x05\x04\x03\x02\x01\ + \x07\x12\x03\x1c()\n\x0b\n\x04\x04\x03\x02\x02\x12\x03\x1d\x02\x1e\n\x0c\ + \n\x05\x04\x03\x02\x02\x04\x12\x03\x1d\x02\n\n\x0c\n\x05\x04\x03\x02\x02\ + \x05\x12\x03\x1d\x0b\x10\n\x0c\n\x05\x04\x03\x02\x02\x01\x12\x03\x1d\x11\ + \x19\n\x0c\n\x05\x04\x03\x02\x02\x03\x12\x03\x1d\x1c\x1d\n'\n\x02\x04\ + \x04\x12\x04!\0$\x01\x1a\x1b\x20type=4,\x20what\x20did\x20we\x20lose?\n\ + \n\n\n\x03\x04\x04\x01\x12\x03!\x08\x0e\n\x0b\n\x04\x04\x04\x02\0\x12\ + \x03\"\x02\x1c\n\x0c\n\x05\x04\x04\x02\0\x04\x12\x03\"\x02\n\n\x0c\n\x05\ + \x04\x04\x02\0\x05\x12\x03\"\x0b\x11\n\x0c\n\x05\x04\x04\x02\0\x01\x12\ + \x03\"\x12\x17\n\x0c\n\x05\x04\x04\x02\0\x03\x12\x03\"\x1a\x1b\n\x1c\n\ + \x04\x04\x04\x02\x01\x12\x03#\x02+\"\x0f\x20defaults\x20to\x201\n\n\x0c\ + \n\x05\x04\x04\x02\x01\x04\x12\x03#\x02\n\n\x0c\n\x05\x04\x04\x02\x01\ + \x05\x12\x03#\x0b\x11\n\x0c\n\x05\x04\x04\x02\x01\x01\x12\x03#\x12\x18\n\ + \x0c\n\x05\x04\x04\x02\x01\x03\x12\x03#\x1b\x1c\n\x0c\n\x05\x04\x04\x02\ + \x01\x08\x12\x03#\x1d*\n\x0c\n\x05\x04\x04\x02\x01\x07\x12\x03#()\n^\n\ + \x02\x04\x05\x12\x04'\0*\x01\x1aR\x20type=5,\x20what\x20do\x20we\x20want\ + ?\x20remote\x20should\x20start\x20sending\x20have\x20messages\x20in\x20t\ + his\x20range\n\n\n\n\x03\x04\x05\x01\x12\x03'\x08\x0c\n\x0b\n\x04\x04\ + \x05\x02\0\x12\x03(\x02\x1c\n\x0c\n\x05\x04\x05\x02\0\x04\x12\x03(\x02\n\ + \n\x0c\n\x05\x04\x05\x02\0\x05\x12\x03(\x0b\x11\n\x0c\n\x05\x04\x05\x02\ + \0\x01\x12\x03(\x12\x17\n\x0c\n\x05\x04\x05\x02\0\x03\x12\x03(\x1a\x1b\n\ + @\n\x04\x04\x05\x02\x01\x12\x03)\x02\x1d\"3\x20defaults\x20to\x20Infinit\ + y\x20or\x20feed.length\x20(if\x20not\x20live)\n\n\x0c\n\x05\x04\x05\x02\ + \x01\x04\x12\x03)\x02\n\n\x0c\n\x05\x04\x05\x02\x01\x05\x12\x03)\x0b\x11\ + \n\x0c\n\x05\x04\x05\x02\x01\x01\x12\x03)\x12\x18\n\x0c\n\x05\x04\x05\ + \x02\x01\x03\x12\x03)\x1b\x1c\n1\n\x02\x04\x06\x12\x04-\00\x01\x1a%\x20t\ + ype=6,\x20what\x20don't\x20we\x20want\x20anymore?\n\n\n\n\x03\x04\x06\ + \x01\x12\x03-\x08\x0e\n\x0b\n\x04\x04\x06\x02\0\x12\x03.\x02\x1c\n\x0c\n\ + \x05\x04\x06\x02\0\x04\x12\x03.\x02\n\n\x0c\n\x05\x04\x06\x02\0\x05\x12\ + \x03.\x0b\x11\n\x0c\n\x05\x04\x06\x02\0\x01\x12\x03.\x12\x17\n\x0c\n\x05\ + \x04\x06\x02\0\x03\x12\x03.\x1a\x1b\n@\n\x04\x04\x06\x02\x01\x12\x03/\ + \x02\x1d\"3\x20defaults\x20to\x20Infinity\x20or\x20feed.length\x20(if\ + \x20not\x20live)\n\n\x0c\n\x05\x04\x06\x02\x01\x04\x12\x03/\x02\n\n\x0c\ + \n\x05\x04\x06\x02\x01\x05\x12\x03/\x0b\x11\n\x0c\n\x05\x04\x06\x02\x01\ + \x01\x12\x03/\x12\x18\n\x0c\n\x05\x04\x06\x02\x01\x03\x12\x03/\x1b\x1c\n\ + \"\n\x02\x04\x07\x12\x043\08\x01\x1a\x16\x20type=7,\x20ask\x20for\x20dat\ + a\n\n\n\n\x03\x04\x07\x01\x12\x033\x08\x0f\n\x0b\n\x04\x04\x07\x02\0\x12\ + \x034\x02\x1c\n\x0c\n\x05\x04\x07\x02\0\x04\x12\x034\x02\n\n\x0c\n\x05\ + \x04\x07\x02\0\x05\x12\x034\x0b\x11\n\x0c\n\x05\x04\x07\x02\0\x01\x12\ + \x034\x12\x17\n\x0c\n\x05\x04\x07\x02\0\x03\x12\x034\x1a\x1b\n\x0b\n\x04\ + \x04\x07\x02\x01\x12\x035\x02\x1c\n\x0c\n\x05\x04\x07\x02\x01\x04\x12\ + \x035\x02\n\n\x0c\n\x05\x04\x07\x02\x01\x05\x12\x035\x0b\x11\n\x0c\n\x05\ + \x04\x07\x02\x01\x01\x12\x035\x12\x17\n\x0c\n\x05\x04\x07\x02\x01\x03\ + \x12\x035\x1a\x1b\n\x0b\n\x04\x04\x07\x02\x02\x12\x036\x02\x19\n\x0c\n\ + \x05\x04\x07\x02\x02\x04\x12\x036\x02\n\n\x0c\n\x05\x04\x07\x02\x02\x05\ + \x12\x036\x0b\x0f\n\x0c\n\x05\x04\x07\x02\x02\x01\x12\x036\x10\x14\n\x0c\ + \n\x05\x04\x07\x02\x02\x03\x12\x036\x17\x18\n\x0b\n\x04\x04\x07\x02\x03\ + \x12\x037\x02\x1c\n\x0c\n\x05\x04\x07\x02\x03\x04\x12\x037\x02\n\n\x0c\n\ + \x05\x04\x07\x02\x03\x05\x12\x037\x0b\x11\n\x0c\n\x05\x04\x07\x02\x03\ + \x01\x12\x037\x12\x17\n\x0c\n\x05\x04\x07\x02\x03\x03\x12\x037\x1a\x1b\n\ + &\n\x02\x04\x08\x12\x04;\0?\x01\x1a\x1a\x20type=8,\x20cancel\x20a\x20req\ + uest\n\n\n\n\x03\x04\x08\x01\x12\x03;\x08\x0e\n\x0b\n\x04\x04\x08\x02\0\ + \x12\x03<\x02\x1c\n\x0c\n\x05\x04\x08\x02\0\x04\x12\x03<\x02\n\n\x0c\n\ + \x05\x04\x08\x02\0\x05\x12\x03<\x0b\x11\n\x0c\n\x05\x04\x08\x02\0\x01\ + \x12\x03<\x12\x17\n\x0c\n\x05\x04\x08\x02\0\x03\x12\x03<\x1a\x1b\n\x0b\n\ + \x04\x04\x08\x02\x01\x12\x03=\x02\x1c\n\x0c\n\x05\x04\x08\x02\x01\x04\ + \x12\x03=\x02\n\n\x0c\n\x05\x04\x08\x02\x01\x05\x12\x03=\x0b\x11\n\x0c\n\ + \x05\x04\x08\x02\x01\x01\x12\x03=\x12\x17\n\x0c\n\x05\x04\x08\x02\x01\ + \x03\x12\x03=\x1a\x1b\n\x0b\n\x04\x04\x08\x02\x02\x12\x03>\x02\x19\n\x0c\ + \n\x05\x04\x08\x02\x02\x04\x12\x03>\x02\n\n\x0c\n\x05\x04\x08\x02\x02\ + \x05\x12\x03>\x0b\x0f\n\x0c\n\x05\x04\x08\x02\x02\x01\x12\x03>\x10\x14\n\ + \x0c\n\x05\x04\x08\x02\x02\x03\x12\x03>\x17\x18\n#\n\x02\x04\t\x12\x04B\ + \0M\x01\x1a\x17\x20type=9,\x20get\x20some\x20data\n\n\n\n\x03\x04\t\x01\ + \x12\x03B\x08\x0c\n\x0c\n\x04\x04\t\x03\0\x12\x04C\x02G\x03\n\x0c\n\x05\ + \x04\t\x03\0\x01\x12\x03C\n\x0e\n\r\n\x06\x04\t\x03\0\x02\0\x12\x03D\x04\ + \x1e\n\x0e\n\x07\x04\t\x03\0\x02\0\x04\x12\x03D\x04\x0c\n\x0e\n\x07\x04\ + \t\x03\0\x02\0\x05\x12\x03D\r\x13\n\x0e\n\x07\x04\t\x03\0\x02\0\x01\x12\ + \x03D\x14\x19\n\x0e\n\x07\x04\t\x03\0\x02\0\x03\x12\x03D\x1c\x1d\n\r\n\ + \x06\x04\t\x03\0\x02\x01\x12\x03E\x04\x1c\n\x0e\n\x07\x04\t\x03\0\x02\ + \x01\x04\x12\x03E\x04\x0c\n\x0e\n\x07\x04\t\x03\0\x02\x01\x05\x12\x03E\r\ + \x12\n\x0e\n\x07\x04\t\x03\0\x02\x01\x01\x12\x03E\x13\x17\n\x0e\n\x07\ + \x04\t\x03\0\x02\x01\x03\x12\x03E\x1a\x1b\n\r\n\x06\x04\t\x03\0\x02\x02\ + \x12\x03F\x04\x1d\n\x0e\n\x07\x04\t\x03\0\x02\x02\x04\x12\x03F\x04\x0c\n\ + \x0e\n\x07\x04\t\x03\0\x02\x02\x05\x12\x03F\r\x13\n\x0e\n\x07\x04\t\x03\ + \0\x02\x02\x01\x12\x03F\x14\x18\n\x0e\n\x07\x04\t\x03\0\x02\x02\x03\x12\ + \x03F\x1b\x1c\n\x0b\n\x04\x04\t\x02\0\x12\x03I\x02\x1c\n\x0c\n\x05\x04\t\ + \x02\0\x04\x12\x03I\x02\n\n\x0c\n\x05\x04\t\x02\0\x05\x12\x03I\x0b\x11\n\ + \x0c\n\x05\x04\t\x02\0\x01\x12\x03I\x12\x17\n\x0c\n\x05\x04\t\x02\0\x03\ + \x12\x03I\x1a\x1b\n\x0b\n\x04\x04\t\x02\x01\x12\x03J\x02\x1b\n\x0c\n\x05\ + \x04\t\x02\x01\x04\x12\x03J\x02\n\n\x0c\n\x05\x04\t\x02\x01\x05\x12\x03J\ + \x0b\x10\n\x0c\n\x05\x04\t\x02\x01\x01\x12\x03J\x11\x16\n\x0c\n\x05\x04\ + \t\x02\x01\x03\x12\x03J\x19\x1a\n\x0b\n\x04\x04\t\x02\x02\x12\x03K\x02\ + \x1a\n\x0c\n\x05\x04\t\x02\x02\x04\x12\x03K\x02\n\n\x0c\n\x05\x04\t\x02\ + \x02\x06\x12\x03K\x0b\x0f\n\x0c\n\x05\x04\t\x02\x02\x01\x12\x03K\x10\x15\ + \n\x0c\n\x05\x04\t\x02\x02\x03\x12\x03K\x18\x19\n\x0b\n\x04\x04\t\x02\ + \x03\x12\x03L\x02\x1f\n\x0c\n\x05\x04\t\x02\x03\x04\x12\x03L\x02\n\n\x0c\ + \n\x05\x04\t\x02\x03\x05\x12\x03L\x0b\x10\n\x0c\n\x05\x04\t\x02\x03\x01\ + \x12\x03L\x11\x1a\n\x0c\n\x05\x04\t\x02\x03\x03\x12\x03L\x1d\x1e\ +"; + +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/network_msgs.proto b/src/network_msgs.proto new file mode 100644 index 0000000..1b7bc2c --- /dev/null +++ b/src/network_msgs.proto @@ -0,0 +1,81 @@ +// wire format is (
) +// header is a varint, channel << 4 | <4-bit-type> + +// type=0, should be the first message sent on a channel +message Feed { + required bytes discoveryKey = 1; + optional bytes nonce = 2; +} + +// type=1, overall connection handshake. should be send just after the feed message on the first channel only +message Handshake { + optional bytes id = 1; + optional bool live = 2; // keep the connection open forever? both ends have to agree + optional bytes userData = 3; + repeated string extensions = 4; +} + +// type=2, message indicating state changes etc. +// initial state for uploading/downloading is true +// if both ends are not downloading and not live it is safe to consider the stream ended +message Info { + optional bool uploading = 1; + optional bool downloading = 2; +} + +// type=3, what do we have? +message Have { + required uint64 start = 1; + optional uint64 length = 2 [default = 1]; // defaults to 1 + optional bytes bitfield = 3; +} + +// type=4, what did we lose? +message Unhave { + required uint64 start = 1; + optional uint64 length = 2 [default = 1]; // defaults to 1 +} + +// type=5, what do we want? remote should start sending have messages in this range +message Want { + required uint64 start = 1; + optional uint64 length = 2; // defaults to Infinity or feed.length (if not live) +} + +// type=6, what don't we want anymore? +message Unwant { + required uint64 start = 1; + optional uint64 length = 2; // defaults to Infinity or feed.length (if not live) +} + +// type=7, ask for data +message Request { + required uint64 index = 1; + optional uint64 bytes = 2; + optional bool hash = 3; + optional uint64 nodes = 4; +} + +// type=8, cancel a request +message Cancel { + required uint64 index = 1; + optional uint64 bytes = 2; + optional bool hash = 3; +} + +// type=9, get some data +message Data { + message Node { + required uint64 index = 1; + required bytes hash = 2; + required uint64 size = 3; + } + + required uint64 index = 1; + optional bytes value = 2; + repeated Node nodes = 3; + optional bytes signature = 4; +} + +// type=15 (last massage) is an extension message +// that is encoded like this diff --git a/src/network_proto.proto b/src/network_proto.proto deleted file mode 100644 index 1b7bc2c..0000000 --- a/src/network_proto.proto +++ /dev/null @@ -1,81 +0,0 @@ -// wire format is (
) -// header is a varint, channel << 4 | <4-bit-type> - -// type=0, should be the first message sent on a channel -message Feed { - required bytes discoveryKey = 1; - optional bytes nonce = 2; -} - -// type=1, overall connection handshake. should be send just after the feed message on the first channel only -message Handshake { - optional bytes id = 1; - optional bool live = 2; // keep the connection open forever? both ends have to agree - optional bytes userData = 3; - repeated string extensions = 4; -} - -// type=2, message indicating state changes etc. -// initial state for uploading/downloading is true -// if both ends are not downloading and not live it is safe to consider the stream ended -message Info { - optional bool uploading = 1; - optional bool downloading = 2; -} - -// type=3, what do we have? -message Have { - required uint64 start = 1; - optional uint64 length = 2 [default = 1]; // defaults to 1 - optional bytes bitfield = 3; -} - -// type=4, what did we lose? -message Unhave { - required uint64 start = 1; - optional uint64 length = 2 [default = 1]; // defaults to 1 -} - -// type=5, what do we want? remote should start sending have messages in this range -message Want { - required uint64 start = 1; - optional uint64 length = 2; // defaults to Infinity or feed.length (if not live) -} - -// type=6, what don't we want anymore? -message Unwant { - required uint64 start = 1; - optional uint64 length = 2; // defaults to Infinity or feed.length (if not live) -} - -// type=7, ask for data -message Request { - required uint64 index = 1; - optional uint64 bytes = 2; - optional bool hash = 3; - optional uint64 nodes = 4; -} - -// type=8, cancel a request -message Cancel { - required uint64 index = 1; - optional uint64 bytes = 2; - optional bool hash = 3; -} - -// type=9, get some data -message Data { - message Node { - required uint64 index = 1; - required bytes hash = 2; - required uint64 size = 3; - } - - required uint64 index = 1; - optional bytes value = 2; - repeated Node nodes = 3; - optional bytes signature = 4; -} - -// type=15 (last massage) is an extension message -// that is encoded like this diff --git a/src/network_proto.rs b/src/network_proto.rs deleted file mode 100644 index e9dae76..0000000 --- a/src/network_proto.rs +++ /dev/null @@ -1,3199 +0,0 @@ -// This file is generated. 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 Feed { - // message fields - discoveryKey: ::protobuf::SingularField<::std::vec::Vec>, - nonce: ::protobuf::SingularField<::std::vec::Vec>, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Feed {} - -impl Feed { - pub fn new() -> Feed { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Feed { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Feed, - }; - unsafe { - instance.get(Feed::new) - } - } - - // required bytes discoveryKey = 1; - - pub fn clear_discoveryKey(&mut self) { - self.discoveryKey.clear(); - } - - pub fn has_discoveryKey(&self) -> bool { - self.discoveryKey.is_some() - } - - // Param is passed by value, moved - pub fn set_discoveryKey(&mut self, v: ::std::vec::Vec) { - self.discoveryKey = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_discoveryKey(&mut self) -> &mut ::std::vec::Vec { - if self.discoveryKey.is_none() { - self.discoveryKey.set_default(); - } - self.discoveryKey.as_mut().unwrap() - } - - // Take field - pub fn take_discoveryKey(&mut self) -> ::std::vec::Vec { - self.discoveryKey.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_discoveryKey(&self) -> &[u8] { - match self.discoveryKey.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_discoveryKey_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.discoveryKey - } - - fn mut_discoveryKey_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.discoveryKey - } - - // optional bytes nonce = 2; - - pub fn clear_nonce(&mut self) { - self.nonce.clear(); - } - - pub fn has_nonce(&self) -> bool { - self.nonce.is_some() - } - - // Param is passed by value, moved - pub fn set_nonce(&mut self, v: ::std::vec::Vec) { - self.nonce = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_nonce(&mut self) -> &mut ::std::vec::Vec { - if self.nonce.is_none() { - self.nonce.set_default(); - } - self.nonce.as_mut().unwrap() - } - - // Take field - pub fn take_nonce(&mut self) -> ::std::vec::Vec { - self.nonce.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_nonce(&self) -> &[u8] { - match self.nonce.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_nonce_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.nonce - } - - fn mut_nonce_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.nonce - } -} - -impl ::protobuf::Message for Feed { - fn is_initialized(&self) -> bool { - if self.discoveryKey.is_none() { - 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_bytes_into(wire_type, is, &mut self.discoveryKey)?; - }, - 2 => { - ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.nonce)?; - }, - _ => { - ::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.discoveryKey.as_ref() { - my_size += ::protobuf::rt::bytes_size(1, &v); - } - if let Some(ref v) = self.nonce.as_ref() { - my_size += ::protobuf::rt::bytes_size(2, &v); - } - 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.discoveryKey.as_ref() { - os.write_bytes(1, &v)?; - } - if let Some(ref v) = self.nonce.as_ref() { - os.write_bytes(2, &v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Feed { - fn new() -> Feed { - Feed::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "discoveryKey", - Feed::get_discoveryKey_for_reflect, - Feed::mut_discoveryKey_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "nonce", - Feed::get_nonce_for_reflect, - Feed::mut_nonce_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Feed", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Feed { - fn clear(&mut self) { - self.clear_discoveryKey(); - self.clear_nonce(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Feed { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Feed { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Handshake { - // message fields - id: ::protobuf::SingularField<::std::vec::Vec>, - live: ::std::option::Option, - userData: ::protobuf::SingularField<::std::vec::Vec>, - extensions: ::protobuf::RepeatedField<::std::string::String>, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Handshake {} - -impl Handshake { - pub fn new() -> Handshake { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Handshake { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Handshake, - }; - unsafe { - instance.get(Handshake::new) - } - } - - // optional bytes id = 1; - - pub fn clear_id(&mut self) { - self.id.clear(); - } - - pub fn has_id(&self) -> bool { - self.id.is_some() - } - - // Param is passed by value, moved - pub fn set_id(&mut self, v: ::std::vec::Vec) { - self.id = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_id(&mut self) -> &mut ::std::vec::Vec { - if self.id.is_none() { - self.id.set_default(); - } - self.id.as_mut().unwrap() - } - - // Take field - pub fn take_id(&mut self) -> ::std::vec::Vec { - self.id.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_id(&self) -> &[u8] { - match self.id.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_id_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.id - } - - fn mut_id_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.id - } - - // optional bool live = 2; - - pub fn clear_live(&mut self) { - self.live = ::std::option::Option::None; - } - - pub fn has_live(&self) -> bool { - self.live.is_some() - } - - // Param is passed by value, moved - pub fn set_live(&mut self, v: bool) { - self.live = ::std::option::Option::Some(v); - } - - pub fn get_live(&self) -> bool { - self.live.unwrap_or(false) - } - - fn get_live_for_reflect(&self) -> &::std::option::Option { - &self.live - } - - fn mut_live_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.live - } - - // optional bytes userData = 3; - - pub fn clear_userData(&mut self) { - self.userData.clear(); - } - - pub fn has_userData(&self) -> bool { - self.userData.is_some() - } - - // Param is passed by value, moved - pub fn set_userData(&mut self, v: ::std::vec::Vec) { - self.userData = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_userData(&mut self) -> &mut ::std::vec::Vec { - if self.userData.is_none() { - self.userData.set_default(); - } - self.userData.as_mut().unwrap() - } - - // Take field - pub fn take_userData(&mut self) -> ::std::vec::Vec { - self.userData.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_userData(&self) -> &[u8] { - match self.userData.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_userData_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.userData - } - - fn mut_userData_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.userData - } - - // repeated string extensions = 4; - - pub fn clear_extensions(&mut self) { - self.extensions.clear(); - } - - // Param is passed by value, moved - pub fn set_extensions(&mut self, v: ::protobuf::RepeatedField<::std::string::String>) { - self.extensions = v; - } - - // Mutable pointer to the field. - pub fn mut_extensions(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { - &mut self.extensions - } - - // Take field - pub fn take_extensions(&mut self) -> ::protobuf::RepeatedField<::std::string::String> { - ::std::mem::replace(&mut self.extensions, ::protobuf::RepeatedField::new()) - } - - pub fn get_extensions(&self) -> &[::std::string::String] { - &self.extensions - } - - fn get_extensions_for_reflect(&self) -> &::protobuf::RepeatedField<::std::string::String> { - &self.extensions - } - - fn mut_extensions_for_reflect(&mut self) -> &mut ::protobuf::RepeatedField<::std::string::String> { - &mut self.extensions - } -} - -impl ::protobuf::Message for Handshake { - 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_bytes_into(wire_type, is, &mut self.id)?; - }, - 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.live = ::std::option::Option::Some(tmp); - }, - 3 => { - ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.userData)?; - }, - 4 => { - ::protobuf::rt::read_repeated_string_into(wire_type, is, &mut self.extensions)?; - }, - _ => { - ::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.id.as_ref() { - my_size += ::protobuf::rt::bytes_size(1, &v); - } - if let Some(v) = self.live { - my_size += 2; - } - if let Some(ref v) = self.userData.as_ref() { - my_size += ::protobuf::rt::bytes_size(3, &v); - } - for value in &self.extensions { - my_size += ::protobuf::rt::string_size(4, &value); - }; - 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.id.as_ref() { - os.write_bytes(1, &v)?; - } - if let Some(v) = self.live { - os.write_bool(2, v)?; - } - if let Some(ref v) = self.userData.as_ref() { - os.write_bytes(3, &v)?; - } - for v in &self.extensions { - os.write_string(4, &v)?; - }; - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Handshake { - fn new() -> Handshake { - Handshake::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "id", - Handshake::get_id_for_reflect, - Handshake::mut_id_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "live", - Handshake::get_live_for_reflect, - Handshake::mut_live_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "userData", - Handshake::get_userData_for_reflect, - Handshake::mut_userData_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeString>( - "extensions", - Handshake::get_extensions_for_reflect, - Handshake::mut_extensions_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Handshake", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Handshake { - fn clear(&mut self) { - self.clear_id(); - self.clear_live(); - self.clear_userData(); - self.clear_extensions(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Handshake { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Handshake { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Info { - // message fields - uploading: ::std::option::Option, - downloading: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Info {} - -impl Info { - pub fn new() -> Info { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Info { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Info, - }; - unsafe { - instance.get(Info::new) - } - } - - // optional bool uploading = 1; - - pub fn clear_uploading(&mut self) { - self.uploading = ::std::option::Option::None; - } - - pub fn has_uploading(&self) -> bool { - self.uploading.is_some() - } - - // Param is passed by value, moved - pub fn set_uploading(&mut self, v: bool) { - self.uploading = ::std::option::Option::Some(v); - } - - pub fn get_uploading(&self) -> bool { - self.uploading.unwrap_or(false) - } - - fn get_uploading_for_reflect(&self) -> &::std::option::Option { - &self.uploading - } - - fn mut_uploading_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.uploading - } - - // optional bool downloading = 2; - - pub fn clear_downloading(&mut self) { - self.downloading = ::std::option::Option::None; - } - - pub fn has_downloading(&self) -> bool { - self.downloading.is_some() - } - - // Param is passed by value, moved - pub fn set_downloading(&mut self, v: bool) { - self.downloading = ::std::option::Option::Some(v); - } - - pub fn get_downloading(&self) -> bool { - self.downloading.unwrap_or(false) - } - - fn get_downloading_for_reflect(&self) -> &::std::option::Option { - &self.downloading - } - - fn mut_downloading_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.downloading - } -} - -impl ::protobuf::Message for Info { - 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 => { - 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.uploading = ::std::option::Option::Some(tmp); - }, - 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.downloading = ::std::option::Option::Some(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 let Some(v) = self.uploading { - my_size += 2; - } - if let Some(v) = self.downloading { - 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 let Some(v) = self.uploading { - os.write_bool(1, v)?; - } - if let Some(v) = self.downloading { - os.write_bool(2, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Info { - fn new() -> Info { - Info::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "uploading", - Info::get_uploading_for_reflect, - Info::mut_uploading_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "downloading", - Info::get_downloading_for_reflect, - Info::mut_downloading_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Info", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Info { - fn clear(&mut self) { - self.clear_uploading(); - self.clear_downloading(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Info { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Info { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Have { - // message fields - start: ::std::option::Option, - length: ::std::option::Option, - bitfield: ::protobuf::SingularField<::std::vec::Vec>, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Have {} - -impl Have { - pub fn new() -> Have { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Have { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Have, - }; - unsafe { - instance.get(Have::new) - } - } - - // required uint64 start = 1; - - pub fn clear_start(&mut self) { - self.start = ::std::option::Option::None; - } - - pub fn has_start(&self) -> bool { - self.start.is_some() - } - - // Param is passed by value, moved - pub fn set_start(&mut self, v: u64) { - self.start = ::std::option::Option::Some(v); - } - - pub fn get_start(&self) -> u64 { - self.start.unwrap_or(0) - } - - fn get_start_for_reflect(&self) -> &::std::option::Option { - &self.start - } - - fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.start - } - - // optional uint64 length = 2; - - pub fn clear_length(&mut self) { - self.length = ::std::option::Option::None; - } - - pub fn has_length(&self) -> bool { - self.length.is_some() - } - - // Param is passed by value, moved - pub fn set_length(&mut self, v: u64) { - self.length = ::std::option::Option::Some(v); - } - - pub fn get_length(&self) -> u64 { - self.length.unwrap_or(1u64) - } - - fn get_length_for_reflect(&self) -> &::std::option::Option { - &self.length - } - - fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.length - } - - // optional bytes bitfield = 3; - - pub fn clear_bitfield(&mut self) { - self.bitfield.clear(); - } - - pub fn has_bitfield(&self) -> bool { - self.bitfield.is_some() - } - - // Param is passed by value, moved - pub fn set_bitfield(&mut self, v: ::std::vec::Vec) { - self.bitfield = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_bitfield(&mut self) -> &mut ::std::vec::Vec { - if self.bitfield.is_none() { - self.bitfield.set_default(); - } - self.bitfield.as_mut().unwrap() - } - - // Take field - pub fn take_bitfield(&mut self) -> ::std::vec::Vec { - self.bitfield.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_bitfield(&self) -> &[u8] { - match self.bitfield.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_bitfield_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.bitfield - } - - fn mut_bitfield_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.bitfield - } -} - -impl ::protobuf::Message for Have { - fn is_initialized(&self) -> bool { - if self.start.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.start = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.length = ::std::option::Option::Some(tmp); - }, - 3 => { - ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.bitfield)?; - }, - _ => { - ::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(v) = self.start { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.length { - my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(ref v) = self.bitfield.as_ref() { - my_size += ::protobuf::rt::bytes_size(3, &v); - } - 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(v) = self.start { - os.write_uint64(1, v)?; - } - if let Some(v) = self.length { - os.write_uint64(2, v)?; - } - if let Some(ref v) = self.bitfield.as_ref() { - os.write_bytes(3, &v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Have { - fn new() -> Have { - Have::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "start", - Have::get_start_for_reflect, - Have::mut_start_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "length", - Have::get_length_for_reflect, - Have::mut_length_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "bitfield", - Have::get_bitfield_for_reflect, - Have::mut_bitfield_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Have", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Have { - fn clear(&mut self) { - self.clear_start(); - self.clear_length(); - self.clear_bitfield(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Have { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Have { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Unhave { - // message fields - start: ::std::option::Option, - length: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Unhave {} - -impl Unhave { - pub fn new() -> Unhave { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Unhave { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Unhave, - }; - unsafe { - instance.get(Unhave::new) - } - } - - // required uint64 start = 1; - - pub fn clear_start(&mut self) { - self.start = ::std::option::Option::None; - } - - pub fn has_start(&self) -> bool { - self.start.is_some() - } - - // Param is passed by value, moved - pub fn set_start(&mut self, v: u64) { - self.start = ::std::option::Option::Some(v); - } - - pub fn get_start(&self) -> u64 { - self.start.unwrap_or(0) - } - - fn get_start_for_reflect(&self) -> &::std::option::Option { - &self.start - } - - fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.start - } - - // optional uint64 length = 2; - - pub fn clear_length(&mut self) { - self.length = ::std::option::Option::None; - } - - pub fn has_length(&self) -> bool { - self.length.is_some() - } - - // Param is passed by value, moved - pub fn set_length(&mut self, v: u64) { - self.length = ::std::option::Option::Some(v); - } - - pub fn get_length(&self) -> u64 { - self.length.unwrap_or(1u64) - } - - fn get_length_for_reflect(&self) -> &::std::option::Option { - &self.length - } - - fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.length - } -} - -impl ::protobuf::Message for Unhave { - fn is_initialized(&self) -> bool { - if self.start.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.start = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.length = ::std::option::Option::Some(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 let Some(v) = self.start { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.length { - my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); - } - 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(v) = self.start { - os.write_uint64(1, v)?; - } - if let Some(v) = self.length { - os.write_uint64(2, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Unhave { - fn new() -> Unhave { - Unhave::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "start", - Unhave::get_start_for_reflect, - Unhave::mut_start_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "length", - Unhave::get_length_for_reflect, - Unhave::mut_length_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Unhave", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Unhave { - fn clear(&mut self) { - self.clear_start(); - self.clear_length(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Unhave { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Unhave { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Want { - // message fields - start: ::std::option::Option, - length: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Want {} - -impl Want { - pub fn new() -> Want { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Want { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Want, - }; - unsafe { - instance.get(Want::new) - } - } - - // required uint64 start = 1; - - pub fn clear_start(&mut self) { - self.start = ::std::option::Option::None; - } - - pub fn has_start(&self) -> bool { - self.start.is_some() - } - - // Param is passed by value, moved - pub fn set_start(&mut self, v: u64) { - self.start = ::std::option::Option::Some(v); - } - - pub fn get_start(&self) -> u64 { - self.start.unwrap_or(0) - } - - fn get_start_for_reflect(&self) -> &::std::option::Option { - &self.start - } - - fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.start - } - - // optional uint64 length = 2; - - pub fn clear_length(&mut self) { - self.length = ::std::option::Option::None; - } - - pub fn has_length(&self) -> bool { - self.length.is_some() - } - - // Param is passed by value, moved - pub fn set_length(&mut self, v: u64) { - self.length = ::std::option::Option::Some(v); - } - - pub fn get_length(&self) -> u64 { - self.length.unwrap_or(0) - } - - fn get_length_for_reflect(&self) -> &::std::option::Option { - &self.length - } - - fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.length - } -} - -impl ::protobuf::Message for Want { - fn is_initialized(&self) -> bool { - if self.start.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.start = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.length = ::std::option::Option::Some(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 let Some(v) = self.start { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.length { - my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); - } - 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(v) = self.start { - os.write_uint64(1, v)?; - } - if let Some(v) = self.length { - os.write_uint64(2, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Want { - fn new() -> Want { - Want::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "start", - Want::get_start_for_reflect, - Want::mut_start_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "length", - Want::get_length_for_reflect, - Want::mut_length_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Want", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Want { - fn clear(&mut self) { - self.clear_start(); - self.clear_length(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Want { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Want { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Unwant { - // message fields - start: ::std::option::Option, - length: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Unwant {} - -impl Unwant { - pub fn new() -> Unwant { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Unwant { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Unwant, - }; - unsafe { - instance.get(Unwant::new) - } - } - - // required uint64 start = 1; - - pub fn clear_start(&mut self) { - self.start = ::std::option::Option::None; - } - - pub fn has_start(&self) -> bool { - self.start.is_some() - } - - // Param is passed by value, moved - pub fn set_start(&mut self, v: u64) { - self.start = ::std::option::Option::Some(v); - } - - pub fn get_start(&self) -> u64 { - self.start.unwrap_or(0) - } - - fn get_start_for_reflect(&self) -> &::std::option::Option { - &self.start - } - - fn mut_start_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.start - } - - // optional uint64 length = 2; - - pub fn clear_length(&mut self) { - self.length = ::std::option::Option::None; - } - - pub fn has_length(&self) -> bool { - self.length.is_some() - } - - // Param is passed by value, moved - pub fn set_length(&mut self, v: u64) { - self.length = ::std::option::Option::Some(v); - } - - pub fn get_length(&self) -> u64 { - self.length.unwrap_or(0) - } - - fn get_length_for_reflect(&self) -> &::std::option::Option { - &self.length - } - - fn mut_length_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.length - } -} - -impl ::protobuf::Message for Unwant { - fn is_initialized(&self) -> bool { - if self.start.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.start = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.length = ::std::option::Option::Some(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 let Some(v) = self.start { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.length { - my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); - } - 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(v) = self.start { - os.write_uint64(1, v)?; - } - if let Some(v) = self.length { - os.write_uint64(2, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Unwant { - fn new() -> Unwant { - Unwant::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "start", - Unwant::get_start_for_reflect, - Unwant::mut_start_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "length", - Unwant::get_length_for_reflect, - Unwant::mut_length_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Unwant", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Unwant { - fn clear(&mut self) { - self.clear_start(); - self.clear_length(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Unwant { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Unwant { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Request { - // message fields - index: ::std::option::Option, - bytes: ::std::option::Option, - hash: ::std::option::Option, - nodes: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Request {} - -impl Request { - pub fn new() -> Request { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Request { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Request, - }; - unsafe { - instance.get(Request::new) - } - } - - // required uint64 index = 1; - - pub fn clear_index(&mut self) { - self.index = ::std::option::Option::None; - } - - pub fn has_index(&self) -> bool { - self.index.is_some() - } - - // Param is passed by value, moved - pub fn set_index(&mut self, v: u64) { - self.index = ::std::option::Option::Some(v); - } - - pub fn get_index(&self) -> u64 { - self.index.unwrap_or(0) - } - - fn get_index_for_reflect(&self) -> &::std::option::Option { - &self.index - } - - fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.index - } - - // optional uint64 bytes = 2; - - pub fn clear_bytes(&mut self) { - self.bytes = ::std::option::Option::None; - } - - pub fn has_bytes(&self) -> bool { - self.bytes.is_some() - } - - // Param is passed by value, moved - pub fn set_bytes(&mut self, v: u64) { - self.bytes = ::std::option::Option::Some(v); - } - - pub fn get_bytes(&self) -> u64 { - self.bytes.unwrap_or(0) - } - - fn get_bytes_for_reflect(&self) -> &::std::option::Option { - &self.bytes - } - - fn mut_bytes_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.bytes - } - - // optional bool hash = 3; - - pub fn clear_hash(&mut self) { - self.hash = ::std::option::Option::None; - } - - pub fn has_hash(&self) -> bool { - self.hash.is_some() - } - - // Param is passed by value, moved - pub fn set_hash(&mut self, v: bool) { - self.hash = ::std::option::Option::Some(v); - } - - pub fn get_hash(&self) -> bool { - self.hash.unwrap_or(false) - } - - fn get_hash_for_reflect(&self) -> &::std::option::Option { - &self.hash - } - - fn mut_hash_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.hash - } - - // optional uint64 nodes = 4; - - pub fn clear_nodes(&mut self) { - self.nodes = ::std::option::Option::None; - } - - pub fn has_nodes(&self) -> bool { - self.nodes.is_some() - } - - // Param is passed by value, moved - pub fn set_nodes(&mut self, v: u64) { - self.nodes = ::std::option::Option::Some(v); - } - - pub fn get_nodes(&self) -> u64 { - self.nodes.unwrap_or(0) - } - - fn get_nodes_for_reflect(&self) -> &::std::option::Option { - &self.nodes - } - - fn mut_nodes_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.nodes - } -} - -impl ::protobuf::Message for Request { - fn is_initialized(&self) -> bool { - if self.index.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.index = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.bytes = ::std::option::Option::Some(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.hash = ::std::option::Option::Some(tmp); - }, - 4 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.nodes = ::std::option::Option::Some(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 let Some(v) = self.index { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.bytes { - my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.hash { - my_size += 2; - } - if let Some(v) = self.nodes { - my_size += ::protobuf::rt::value_size(4, v, ::protobuf::wire_format::WireTypeVarint); - } - 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(v) = self.index { - os.write_uint64(1, v)?; - } - if let Some(v) = self.bytes { - os.write_uint64(2, v)?; - } - if let Some(v) = self.hash { - os.write_bool(3, v)?; - } - if let Some(v) = self.nodes { - os.write_uint64(4, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Request { - fn new() -> Request { - Request::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "index", - Request::get_index_for_reflect, - Request::mut_index_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "bytes", - Request::get_bytes_for_reflect, - Request::mut_bytes_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "hash", - Request::get_hash_for_reflect, - Request::mut_hash_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "nodes", - Request::get_nodes_for_reflect, - Request::mut_nodes_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Request", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Request { - fn clear(&mut self) { - self.clear_index(); - self.clear_bytes(); - self.clear_hash(); - self.clear_nodes(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Request { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Request { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Cancel { - // message fields - index: ::std::option::Option, - bytes: ::std::option::Option, - hash: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Cancel {} - -impl Cancel { - pub fn new() -> Cancel { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Cancel { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Cancel, - }; - unsafe { - instance.get(Cancel::new) - } - } - - // required uint64 index = 1; - - pub fn clear_index(&mut self) { - self.index = ::std::option::Option::None; - } - - pub fn has_index(&self) -> bool { - self.index.is_some() - } - - // Param is passed by value, moved - pub fn set_index(&mut self, v: u64) { - self.index = ::std::option::Option::Some(v); - } - - pub fn get_index(&self) -> u64 { - self.index.unwrap_or(0) - } - - fn get_index_for_reflect(&self) -> &::std::option::Option { - &self.index - } - - fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.index - } - - // optional uint64 bytes = 2; - - pub fn clear_bytes(&mut self) { - self.bytes = ::std::option::Option::None; - } - - pub fn has_bytes(&self) -> bool { - self.bytes.is_some() - } - - // Param is passed by value, moved - pub fn set_bytes(&mut self, v: u64) { - self.bytes = ::std::option::Option::Some(v); - } - - pub fn get_bytes(&self) -> u64 { - self.bytes.unwrap_or(0) - } - - fn get_bytes_for_reflect(&self) -> &::std::option::Option { - &self.bytes - } - - fn mut_bytes_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.bytes - } - - // optional bool hash = 3; - - pub fn clear_hash(&mut self) { - self.hash = ::std::option::Option::None; - } - - pub fn has_hash(&self) -> bool { - self.hash.is_some() - } - - // Param is passed by value, moved - pub fn set_hash(&mut self, v: bool) { - self.hash = ::std::option::Option::Some(v); - } - - pub fn get_hash(&self) -> bool { - self.hash.unwrap_or(false) - } - - fn get_hash_for_reflect(&self) -> &::std::option::Option { - &self.hash - } - - fn mut_hash_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.hash - } -} - -impl ::protobuf::Message for Cancel { - fn is_initialized(&self) -> bool { - if self.index.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.index = ::std::option::Option::Some(tmp); - }, - 2 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.bytes = ::std::option::Option::Some(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.hash = ::std::option::Option::Some(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 let Some(v) = self.index { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.bytes { - my_size += ::protobuf::rt::value_size(2, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(v) = self.hash { - 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 let Some(v) = self.index { - os.write_uint64(1, v)?; - } - if let Some(v) = self.bytes { - os.write_uint64(2, v)?; - } - if let Some(v) = self.hash { - os.write_bool(3, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Cancel { - fn new() -> Cancel { - Cancel::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "index", - Cancel::get_index_for_reflect, - Cancel::mut_index_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "bytes", - Cancel::get_bytes_for_reflect, - Cancel::mut_bytes_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeBool>( - "hash", - Cancel::get_hash_for_reflect, - Cancel::mut_hash_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Cancel", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Cancel { - fn clear(&mut self) { - self.clear_index(); - self.clear_bytes(); - self.clear_hash(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Cancel { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Cancel { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Data { - // message fields - index: ::std::option::Option, - value: ::protobuf::SingularField<::std::vec::Vec>, - nodes: ::protobuf::RepeatedField, - signature: ::protobuf::SingularField<::std::vec::Vec>, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Data {} - -impl Data { - pub fn new() -> Data { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Data { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Data, - }; - unsafe { - instance.get(Data::new) - } - } - - // required uint64 index = 1; - - pub fn clear_index(&mut self) { - self.index = ::std::option::Option::None; - } - - pub fn has_index(&self) -> bool { - self.index.is_some() - } - - // Param is passed by value, moved - pub fn set_index(&mut self, v: u64) { - self.index = ::std::option::Option::Some(v); - } - - pub fn get_index(&self) -> u64 { - self.index.unwrap_or(0) - } - - fn get_index_for_reflect(&self) -> &::std::option::Option { - &self.index - } - - fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.index - } - - // optional bytes value = 2; - - pub fn clear_value(&mut self) { - self.value.clear(); - } - - pub fn has_value(&self) -> bool { - self.value.is_some() - } - - // Param is passed by value, moved - pub fn set_value(&mut self, v: ::std::vec::Vec) { - self.value = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_value(&mut self) -> &mut ::std::vec::Vec { - if self.value.is_none() { - self.value.set_default(); - } - self.value.as_mut().unwrap() - } - - // Take field - pub fn take_value(&mut self) -> ::std::vec::Vec { - self.value.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_value(&self) -> &[u8] { - match self.value.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_value_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.value - } - - fn mut_value_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.value - } - - // repeated .Data.Node nodes = 3; - - pub fn clear_nodes(&mut self) { - self.nodes.clear(); - } - - // Param is passed by value, moved - pub fn set_nodes(&mut self, v: ::protobuf::RepeatedField) { - self.nodes = v; - } - - // Mutable pointer to the field. - pub fn mut_nodes(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.nodes - } - - // Take field - pub fn take_nodes(&mut self) -> ::protobuf::RepeatedField { - ::std::mem::replace(&mut self.nodes, ::protobuf::RepeatedField::new()) - } - - pub fn get_nodes(&self) -> &[Data_Node] { - &self.nodes - } - - fn get_nodes_for_reflect(&self) -> &::protobuf::RepeatedField { - &self.nodes - } - - fn mut_nodes_for_reflect(&mut self) -> &mut ::protobuf::RepeatedField { - &mut self.nodes - } - - // optional bytes signature = 4; - - pub fn clear_signature(&mut self) { - self.signature.clear(); - } - - pub fn has_signature(&self) -> bool { - self.signature.is_some() - } - - // Param is passed by value, moved - pub fn set_signature(&mut self, v: ::std::vec::Vec) { - self.signature = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_signature(&mut self) -> &mut ::std::vec::Vec { - if self.signature.is_none() { - self.signature.set_default(); - } - self.signature.as_mut().unwrap() - } - - // Take field - pub fn take_signature(&mut self) -> ::std::vec::Vec { - self.signature.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_signature(&self) -> &[u8] { - match self.signature.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_signature_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.signature - } - - fn mut_signature_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.signature - } -} - -impl ::protobuf::Message for Data { - fn is_initialized(&self) -> bool { - if self.index.is_none() { - return false; - } - for v in &self.nodes { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.index = ::std::option::Option::Some(tmp); - }, - 2 => { - ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.value)?; - }, - 3 => { - ::protobuf::rt::read_repeated_message_into(wire_type, is, &mut self.nodes)?; - }, - 4 => { - ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.signature)?; - }, - _ => { - ::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(v) = self.index { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(ref v) = self.value.as_ref() { - my_size += ::protobuf::rt::bytes_size(2, &v); - } - for value in &self.nodes { - let len = value.compute_size(); - my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; - }; - if let Some(ref v) = self.signature.as_ref() { - my_size += ::protobuf::rt::bytes_size(4, &v); - } - 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(v) = self.index { - os.write_uint64(1, v)?; - } - if let Some(ref v) = self.value.as_ref() { - os.write_bytes(2, &v)?; - } - for v in &self.nodes { - os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; - os.write_raw_varint32(v.get_cached_size())?; - v.write_to_with_cached_sizes(os)?; - }; - if let Some(ref v) = self.signature.as_ref() { - os.write_bytes(4, &v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Data { - fn new() -> Data { - Data::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "index", - Data::get_index_for_reflect, - Data::mut_index_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "value", - Data::get_value_for_reflect, - Data::mut_value_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_repeated_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( - "nodes", - Data::get_nodes_for_reflect, - Data::mut_nodes_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "signature", - Data::get_signature_for_reflect, - Data::mut_signature_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Data", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Data { - fn clear(&mut self) { - self.clear_index(); - self.clear_value(); - self.clear_nodes(); - self.clear_signature(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Data { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Data { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -#[derive(PartialEq,Clone,Default)] -pub struct Data_Node { - // message fields - index: ::std::option::Option, - hash: ::protobuf::SingularField<::std::vec::Vec>, - size: ::std::option::Option, - // special fields - unknown_fields: ::protobuf::UnknownFields, - cached_size: ::protobuf::CachedSize, -} - -// see codegen.rs for the explanation why impl Sync explicitly -unsafe impl ::std::marker::Sync for Data_Node {} - -impl Data_Node { - pub fn new() -> Data_Node { - ::std::default::Default::default() - } - - pub fn default_instance() -> &'static Data_Node { - static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { - lock: ::protobuf::lazy::ONCE_INIT, - ptr: 0 as *const Data_Node, - }; - unsafe { - instance.get(Data_Node::new) - } - } - - // required uint64 index = 1; - - pub fn clear_index(&mut self) { - self.index = ::std::option::Option::None; - } - - pub fn has_index(&self) -> bool { - self.index.is_some() - } - - // Param is passed by value, moved - pub fn set_index(&mut self, v: u64) { - self.index = ::std::option::Option::Some(v); - } - - pub fn get_index(&self) -> u64 { - self.index.unwrap_or(0) - } - - fn get_index_for_reflect(&self) -> &::std::option::Option { - &self.index - } - - fn mut_index_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.index - } - - // required bytes hash = 2; - - pub fn clear_hash(&mut self) { - self.hash.clear(); - } - - pub fn has_hash(&self) -> bool { - self.hash.is_some() - } - - // Param is passed by value, moved - pub fn set_hash(&mut self, v: ::std::vec::Vec) { - self.hash = ::protobuf::SingularField::some(v); - } - - // Mutable pointer to the field. - // If field is not initialized, it is initialized with default value first. - pub fn mut_hash(&mut self) -> &mut ::std::vec::Vec { - if self.hash.is_none() { - self.hash.set_default(); - } - self.hash.as_mut().unwrap() - } - - // Take field - pub fn take_hash(&mut self) -> ::std::vec::Vec { - self.hash.take().unwrap_or_else(|| ::std::vec::Vec::new()) - } - - pub fn get_hash(&self) -> &[u8] { - match self.hash.as_ref() { - Some(v) => &v, - None => &[], - } - } - - fn get_hash_for_reflect(&self) -> &::protobuf::SingularField<::std::vec::Vec> { - &self.hash - } - - fn mut_hash_for_reflect(&mut self) -> &mut ::protobuf::SingularField<::std::vec::Vec> { - &mut self.hash - } - - // required uint64 size = 3; - - pub fn clear_size(&mut self) { - self.size = ::std::option::Option::None; - } - - pub fn has_size(&self) -> bool { - self.size.is_some() - } - - // Param is passed by value, moved - pub fn set_size(&mut self, v: u64) { - self.size = ::std::option::Option::Some(v); - } - - pub fn get_size(&self) -> u64 { - self.size.unwrap_or(0) - } - - fn get_size_for_reflect(&self) -> &::std::option::Option { - &self.size - } - - fn mut_size_for_reflect(&mut self) -> &mut ::std::option::Option { - &mut self.size - } -} - -impl ::protobuf::Message for Data_Node { - fn is_initialized(&self) -> bool { - if self.index.is_none() { - return false; - } - if self.hash.is_none() { - return false; - } - if self.size.is_none() { - 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 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.index = ::std::option::Option::Some(tmp); - }, - 2 => { - ::protobuf::rt::read_singular_bytes_into(wire_type, is, &mut self.hash)?; - }, - 3 => { - if wire_type != ::protobuf::wire_format::WireTypeVarint { - return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); - } - let tmp = is.read_uint64()?; - self.size = ::std::option::Option::Some(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 let Some(v) = self.index { - my_size += ::protobuf::rt::value_size(1, v, ::protobuf::wire_format::WireTypeVarint); - } - if let Some(ref v) = self.hash.as_ref() { - my_size += ::protobuf::rt::bytes_size(2, &v); - } - if let Some(v) = self.size { - my_size += ::protobuf::rt::value_size(3, v, ::protobuf::wire_format::WireTypeVarint); - } - 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(v) = self.index { - os.write_uint64(1, v)?; - } - if let Some(ref v) = self.hash.as_ref() { - os.write_bytes(2, &v)?; - } - if let Some(v) = self.size { - os.write_uint64(3, v)?; - } - 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 { - ::protobuf::MessageStatic::descriptor_static(None::) - } -} - -impl ::protobuf::MessageStatic for Data_Node { - fn new() -> Data_Node { - Data_Node::new() - } - - fn descriptor_static(_: ::std::option::Option) -> &'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_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "index", - Data_Node::get_index_for_reflect, - Data_Node::mut_index_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_singular_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( - "hash", - Data_Node::get_hash_for_reflect, - Data_Node::mut_hash_for_reflect, - )); - fields.push(::protobuf::reflect::accessor::make_option_accessor::<_, ::protobuf::types::ProtobufTypeUint64>( - "size", - Data_Node::get_size_for_reflect, - Data_Node::mut_size_for_reflect, - )); - ::protobuf::reflect::MessageDescriptor::new::( - "Data_Node", - fields, - file_descriptor_proto() - ) - }) - } - } -} - -impl ::protobuf::Clear for Data_Node { - fn clear(&mut self) { - self.clear_index(); - self.clear_hash(); - self.clear_size(); - self.unknown_fields.clear(); - } -} - -impl ::std::fmt::Debug for Data_Node { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - ::protobuf::text_format::fmt(self, f) - } -} - -impl ::protobuf::reflect::ProtobufValue for Data_Node { - fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { - ::protobuf::reflect::ProtobufValueRef::Message(self) - } -} - -static file_descriptor_proto_data: &'static [u8] = b"\ - \n\tdat.proto\"@\n\x04Feed\x12\"\n\x0cdiscoveryKey\x18\x01\x20\x02(\x0cR\ - \x0cdiscoveryKey\x12\x14\n\x05nonce\x18\x02\x20\x01(\x0cR\x05nonce\"k\n\ - \tHandshake\x12\x0e\n\x02id\x18\x01\x20\x01(\x0cR\x02id\x12\x12\n\x04liv\ - e\x18\x02\x20\x01(\x08R\x04live\x12\x1a\n\x08userData\x18\x03\x20\x01(\ - \x0cR\x08userData\x12\x1e\n\nextensions\x18\x04\x20\x03(\tR\nextensions\ - \"F\n\x04Info\x12\x1c\n\tuploading\x18\x01\x20\x01(\x08R\tuploading\x12\ - \x20\n\x0bdownloading\x18\x02\x20\x01(\x08R\x0bdownloading\"S\n\x04Have\ - \x12\x14\n\x05start\x18\x01\x20\x02(\x04R\x05start\x12\x19\n\x06length\ - \x18\x02\x20\x01(\x04:\x011R\x06length\x12\x1a\n\x08bitfield\x18\x03\x20\ - \x01(\x0cR\x08bitfield\"9\n\x06Unhave\x12\x14\n\x05start\x18\x01\x20\x02\ - (\x04R\x05start\x12\x19\n\x06length\x18\x02\x20\x01(\x04:\x011R\x06lengt\ - h\"4\n\x04Want\x12\x14\n\x05start\x18\x01\x20\x02(\x04R\x05start\x12\x16\ - \n\x06length\x18\x02\x20\x01(\x04R\x06length\"6\n\x06Unwant\x12\x14\n\ - \x05start\x18\x01\x20\x02(\x04R\x05start\x12\x16\n\x06length\x18\x02\x20\ - \x01(\x04R\x06length\"_\n\x07Request\x12\x14\n\x05index\x18\x01\x20\x02(\ - \x04R\x05index\x12\x14\n\x05bytes\x18\x02\x20\x01(\x04R\x05bytes\x12\x12\ - \n\x04hash\x18\x03\x20\x01(\x08R\x04hash\x12\x14\n\x05nodes\x18\x04\x20\ - \x01(\x04R\x05nodes\"H\n\x06Cancel\x12\x14\n\x05index\x18\x01\x20\x02(\ - \x04R\x05index\x12\x14\n\x05bytes\x18\x02\x20\x01(\x04R\x05bytes\x12\x12\ - \n\x04hash\x18\x03\x20\x01(\x08R\x04hash\"\xb8\x01\n\x04Data\x12\x14\n\ - \x05index\x18\x01\x20\x02(\x04R\x05index\x12\x14\n\x05value\x18\x02\x20\ - \x01(\x0cR\x05value\x12\x20\n\x05nodes\x18\x03\x20\x03(\x0b2\n.Data.Node\ - R\x05nodes\x12\x1c\n\tsignature\x18\x04\x20\x01(\x0cR\tsignature\x1aD\n\ - \x04Node\x12\x14\n\x05index\x18\x01\x20\x02(\x04R\x05index\x12\x12\n\x04\ - hash\x18\x02\x20\x02(\x0cR\x04hash\x12\x12\n\x04size\x18\x03\x20\x02(\ - \x04R\x04sizeJ\xce\x1a\n\x06\x12\x04\x04\0M\x01\n\x9f\x01\n\x02\x04\0\ - \x12\x04\x04\0\x07\x01\x1a7\x20type=0,\x20should\x20be\x20the\x20first\ - \x20message\x20sent\x20on\x20a\x20channel\n2Z\x20wire\x20format\x20is\ - \x20(
)\n\x20header\x20is\x20a\x20varint,\x20channe\ - l\x20<<\x204\x20|\x20<4-bit-type>\n\n\n\n\x03\x04\0\x01\x12\x03\x04\x08\ - \x0c\n\x0b\n\x04\x04\0\x02\0\x12\x03\x05\x02\"\n\x0c\n\x05\x04\0\x02\0\ - \x04\x12\x03\x05\x02\n\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x05\x0b\x10\n\ - \x0c\n\x05\x04\0\x02\0\x01\x12\x03\x05\x11\x1d\n\x0c\n\x05\x04\0\x02\0\ - \x03\x12\x03\x05\x20!\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x06\x02\x1b\n\ - \x0c\n\x05\x04\0\x02\x01\x04\x12\x03\x06\x02\n\n\x0c\n\x05\x04\0\x02\x01\ - \x05\x12\x03\x06\x0b\x10\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x06\x11\ - \x16\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x06\x19\x1a\nx\n\x02\x04\x01\ - \x12\x04\n\0\x0f\x01\x1al\x20type=1,\x20overall\x20connection\x20handsha\ - ke.\x20should\x20be\x20send\x20just\x20after\x20the\x20feed\x20message\ - \x20on\x20the\x20first\x20channel\x20only\n\n\n\n\x03\x04\x01\x01\x12\ - \x03\n\x08\x11\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x0b\x02\x18\n\x0c\n\x05\ - \x04\x01\x02\0\x04\x12\x03\x0b\x02\n\n\x0c\n\x05\x04\x01\x02\0\x05\x12\ - \x03\x0b\x0b\x10\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\x0b\x11\x13\n\x0c\ - \n\x05\x04\x01\x02\0\x03\x12\x03\x0b\x16\x17\nH\n\x04\x04\x01\x02\x01\ - \x12\x03\x0c\x02\x19\";\x20keep\x20the\x20connection\x20open\x20forever?\ - \x20both\x20ends\x20have\x20to\x20agree\n\n\x0c\n\x05\x04\x01\x02\x01\ - \x04\x12\x03\x0c\x02\n\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\x0c\x0b\ - \x0f\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\x03\x0c\x10\x14\n\x0c\n\x05\x04\ - \x01\x02\x01\x03\x12\x03\x0c\x17\x18\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\ - \r\x02\x1e\n\x0c\n\x05\x04\x01\x02\x02\x04\x12\x03\r\x02\n\n\x0c\n\x05\ - \x04\x01\x02\x02\x05\x12\x03\r\x0b\x10\n\x0c\n\x05\x04\x01\x02\x02\x01\ - \x12\x03\r\x11\x19\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\r\x1c\x1d\n\ - \x0b\n\x04\x04\x01\x02\x03\x12\x03\x0e\x02!\n\x0c\n\x05\x04\x01\x02\x03\ - \x04\x12\x03\x0e\x02\n\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x0e\x0b\ - \x11\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0e\x12\x1c\n\x0c\n\x05\x04\ - \x01\x02\x03\x03\x12\x03\x0e\x1f\x20\n\xc4\x01\n\x02\x04\x02\x12\x04\x14\ - \0\x17\x01\x1a\xb7\x01\x20type=2,\x20message\x20indicating\x20state\x20c\ - hanges\x20etc.\n\x20initial\x20state\x20for\x20uploading/downloading\x20\ - is\x20true\n\x20if\x20both\x20ends\x20are\x20not\x20downloading\x20and\ - \x20not\x20live\x20it\x20is\x20safe\x20to\x20consider\x20the\x20stream\ - \x20ended\n\n\n\n\x03\x04\x02\x01\x12\x03\x14\x08\x0c\n\x0b\n\x04\x04\ - \x02\x02\0\x12\x03\x15\x02\x1e\n\x0c\n\x05\x04\x02\x02\0\x04\x12\x03\x15\ - \x02\n\n\x0c\n\x05\x04\x02\x02\0\x05\x12\x03\x15\x0b\x0f\n\x0c\n\x05\x04\ - \x02\x02\0\x01\x12\x03\x15\x10\x19\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\ - \x15\x1c\x1d\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x16\x02\x20\n\x0c\n\x05\ - \x04\x02\x02\x01\x04\x12\x03\x16\x02\n\n\x0c\n\x05\x04\x02\x02\x01\x05\ - \x12\x03\x16\x0b\x0f\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x16\x10\x1b\ - \n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x16\x1e\x1f\n&\n\x02\x04\x03\ - \x12\x04\x1a\0\x1e\x01\x1a\x1a\x20type=3,\x20what\x20do\x20we\x20have?\n\ - \n\n\n\x03\x04\x03\x01\x12\x03\x1a\x08\x0c\n\x0b\n\x04\x04\x03\x02\0\x12\ - \x03\x1b\x02\x1c\n\x0c\n\x05\x04\x03\x02\0\x04\x12\x03\x1b\x02\n\n\x0c\n\ - \x05\x04\x03\x02\0\x05\x12\x03\x1b\x0b\x11\n\x0c\n\x05\x04\x03\x02\0\x01\ - \x12\x03\x1b\x12\x17\n\x0c\n\x05\x04\x03\x02\0\x03\x12\x03\x1b\x1a\x1b\n\ - \x1c\n\x04\x04\x03\x02\x01\x12\x03\x1c\x02+\"\x0f\x20defaults\x20to\x201\ - \n\n\x0c\n\x05\x04\x03\x02\x01\x04\x12\x03\x1c\x02\n\n\x0c\n\x05\x04\x03\ - \x02\x01\x05\x12\x03\x1c\x0b\x11\n\x0c\n\x05\x04\x03\x02\x01\x01\x12\x03\ - \x1c\x12\x18\n\x0c\n\x05\x04\x03\x02\x01\x03\x12\x03\x1c\x1b\x1c\n\x0c\n\ - \x05\x04\x03\x02\x01\x08\x12\x03\x1c\x1d*\n\x0c\n\x05\x04\x03\x02\x01\ - \x07\x12\x03\x1c()\n\x0b\n\x04\x04\x03\x02\x02\x12\x03\x1d\x02\x1e\n\x0c\ - \n\x05\x04\x03\x02\x02\x04\x12\x03\x1d\x02\n\n\x0c\n\x05\x04\x03\x02\x02\ - \x05\x12\x03\x1d\x0b\x10\n\x0c\n\x05\x04\x03\x02\x02\x01\x12\x03\x1d\x11\ - \x19\n\x0c\n\x05\x04\x03\x02\x02\x03\x12\x03\x1d\x1c\x1d\n'\n\x02\x04\ - \x04\x12\x04!\0$\x01\x1a\x1b\x20type=4,\x20what\x20did\x20we\x20lose?\n\ - \n\n\n\x03\x04\x04\x01\x12\x03!\x08\x0e\n\x0b\n\x04\x04\x04\x02\0\x12\ - \x03\"\x02\x1c\n\x0c\n\x05\x04\x04\x02\0\x04\x12\x03\"\x02\n\n\x0c\n\x05\ - \x04\x04\x02\0\x05\x12\x03\"\x0b\x11\n\x0c\n\x05\x04\x04\x02\0\x01\x12\ - \x03\"\x12\x17\n\x0c\n\x05\x04\x04\x02\0\x03\x12\x03\"\x1a\x1b\n\x1c\n\ - \x04\x04\x04\x02\x01\x12\x03#\x02+\"\x0f\x20defaults\x20to\x201\n\n\x0c\ - \n\x05\x04\x04\x02\x01\x04\x12\x03#\x02\n\n\x0c\n\x05\x04\x04\x02\x01\ - \x05\x12\x03#\x0b\x11\n\x0c\n\x05\x04\x04\x02\x01\x01\x12\x03#\x12\x18\n\ - \x0c\n\x05\x04\x04\x02\x01\x03\x12\x03#\x1b\x1c\n\x0c\n\x05\x04\x04\x02\ - \x01\x08\x12\x03#\x1d*\n\x0c\n\x05\x04\x04\x02\x01\x07\x12\x03#()\n^\n\ - \x02\x04\x05\x12\x04'\0*\x01\x1aR\x20type=5,\x20what\x20do\x20we\x20want\ - ?\x20remote\x20should\x20start\x20sending\x20have\x20messages\x20in\x20t\ - his\x20range\n\n\n\n\x03\x04\x05\x01\x12\x03'\x08\x0c\n\x0b\n\x04\x04\ - \x05\x02\0\x12\x03(\x02\x1c\n\x0c\n\x05\x04\x05\x02\0\x04\x12\x03(\x02\n\ - \n\x0c\n\x05\x04\x05\x02\0\x05\x12\x03(\x0b\x11\n\x0c\n\x05\x04\x05\x02\ - \0\x01\x12\x03(\x12\x17\n\x0c\n\x05\x04\x05\x02\0\x03\x12\x03(\x1a\x1b\n\ - @\n\x04\x04\x05\x02\x01\x12\x03)\x02\x1d\"3\x20defaults\x20to\x20Infinit\ - y\x20or\x20feed.length\x20(if\x20not\x20live)\n\n\x0c\n\x05\x04\x05\x02\ - \x01\x04\x12\x03)\x02\n\n\x0c\n\x05\x04\x05\x02\x01\x05\x12\x03)\x0b\x11\ - \n\x0c\n\x05\x04\x05\x02\x01\x01\x12\x03)\x12\x18\n\x0c\n\x05\x04\x05\ - \x02\x01\x03\x12\x03)\x1b\x1c\n1\n\x02\x04\x06\x12\x04-\00\x01\x1a%\x20t\ - ype=6,\x20what\x20don't\x20we\x20want\x20anymore?\n\n\n\n\x03\x04\x06\ - \x01\x12\x03-\x08\x0e\n\x0b\n\x04\x04\x06\x02\0\x12\x03.\x02\x1c\n\x0c\n\ - \x05\x04\x06\x02\0\x04\x12\x03.\x02\n\n\x0c\n\x05\x04\x06\x02\0\x05\x12\ - \x03.\x0b\x11\n\x0c\n\x05\x04\x06\x02\0\x01\x12\x03.\x12\x17\n\x0c\n\x05\ - \x04\x06\x02\0\x03\x12\x03.\x1a\x1b\n@\n\x04\x04\x06\x02\x01\x12\x03/\ - \x02\x1d\"3\x20defaults\x20to\x20Infinity\x20or\x20feed.length\x20(if\ - \x20not\x20live)\n\n\x0c\n\x05\x04\x06\x02\x01\x04\x12\x03/\x02\n\n\x0c\ - \n\x05\x04\x06\x02\x01\x05\x12\x03/\x0b\x11\n\x0c\n\x05\x04\x06\x02\x01\ - \x01\x12\x03/\x12\x18\n\x0c\n\x05\x04\x06\x02\x01\x03\x12\x03/\x1b\x1c\n\ - \"\n\x02\x04\x07\x12\x043\08\x01\x1a\x16\x20type=7,\x20ask\x20for\x20dat\ - a\n\n\n\n\x03\x04\x07\x01\x12\x033\x08\x0f\n\x0b\n\x04\x04\x07\x02\0\x12\ - \x034\x02\x1c\n\x0c\n\x05\x04\x07\x02\0\x04\x12\x034\x02\n\n\x0c\n\x05\ - \x04\x07\x02\0\x05\x12\x034\x0b\x11\n\x0c\n\x05\x04\x07\x02\0\x01\x12\ - \x034\x12\x17\n\x0c\n\x05\x04\x07\x02\0\x03\x12\x034\x1a\x1b\n\x0b\n\x04\ - \x04\x07\x02\x01\x12\x035\x02\x1c\n\x0c\n\x05\x04\x07\x02\x01\x04\x12\ - \x035\x02\n\n\x0c\n\x05\x04\x07\x02\x01\x05\x12\x035\x0b\x11\n\x0c\n\x05\ - \x04\x07\x02\x01\x01\x12\x035\x12\x17\n\x0c\n\x05\x04\x07\x02\x01\x03\ - \x12\x035\x1a\x1b\n\x0b\n\x04\x04\x07\x02\x02\x12\x036\x02\x19\n\x0c\n\ - \x05\x04\x07\x02\x02\x04\x12\x036\x02\n\n\x0c\n\x05\x04\x07\x02\x02\x05\ - \x12\x036\x0b\x0f\n\x0c\n\x05\x04\x07\x02\x02\x01\x12\x036\x10\x14\n\x0c\ - \n\x05\x04\x07\x02\x02\x03\x12\x036\x17\x18\n\x0b\n\x04\x04\x07\x02\x03\ - \x12\x037\x02\x1c\n\x0c\n\x05\x04\x07\x02\x03\x04\x12\x037\x02\n\n\x0c\n\ - \x05\x04\x07\x02\x03\x05\x12\x037\x0b\x11\n\x0c\n\x05\x04\x07\x02\x03\ - \x01\x12\x037\x12\x17\n\x0c\n\x05\x04\x07\x02\x03\x03\x12\x037\x1a\x1b\n\ - &\n\x02\x04\x08\x12\x04;\0?\x01\x1a\x1a\x20type=8,\x20cancel\x20a\x20req\ - uest\n\n\n\n\x03\x04\x08\x01\x12\x03;\x08\x0e\n\x0b\n\x04\x04\x08\x02\0\ - \x12\x03<\x02\x1c\n\x0c\n\x05\x04\x08\x02\0\x04\x12\x03<\x02\n\n\x0c\n\ - \x05\x04\x08\x02\0\x05\x12\x03<\x0b\x11\n\x0c\n\x05\x04\x08\x02\0\x01\ - \x12\x03<\x12\x17\n\x0c\n\x05\x04\x08\x02\0\x03\x12\x03<\x1a\x1b\n\x0b\n\ - \x04\x04\x08\x02\x01\x12\x03=\x02\x1c\n\x0c\n\x05\x04\x08\x02\x01\x04\ - \x12\x03=\x02\n\n\x0c\n\x05\x04\x08\x02\x01\x05\x12\x03=\x0b\x11\n\x0c\n\ - \x05\x04\x08\x02\x01\x01\x12\x03=\x12\x17\n\x0c\n\x05\x04\x08\x02\x01\ - \x03\x12\x03=\x1a\x1b\n\x0b\n\x04\x04\x08\x02\x02\x12\x03>\x02\x19\n\x0c\ - \n\x05\x04\x08\x02\x02\x04\x12\x03>\x02\n\n\x0c\n\x05\x04\x08\x02\x02\ - \x05\x12\x03>\x0b\x0f\n\x0c\n\x05\x04\x08\x02\x02\x01\x12\x03>\x10\x14\n\ - \x0c\n\x05\x04\x08\x02\x02\x03\x12\x03>\x17\x18\n#\n\x02\x04\t\x12\x04B\ - \0M\x01\x1a\x17\x20type=9,\x20get\x20some\x20data\n\n\n\n\x03\x04\t\x01\ - \x12\x03B\x08\x0c\n\x0c\n\x04\x04\t\x03\0\x12\x04C\x02G\x03\n\x0c\n\x05\ - \x04\t\x03\0\x01\x12\x03C\n\x0e\n\r\n\x06\x04\t\x03\0\x02\0\x12\x03D\x04\ - \x1e\n\x0e\n\x07\x04\t\x03\0\x02\0\x04\x12\x03D\x04\x0c\n\x0e\n\x07\x04\ - \t\x03\0\x02\0\x05\x12\x03D\r\x13\n\x0e\n\x07\x04\t\x03\0\x02\0\x01\x12\ - \x03D\x14\x19\n\x0e\n\x07\x04\t\x03\0\x02\0\x03\x12\x03D\x1c\x1d\n\r\n\ - \x06\x04\t\x03\0\x02\x01\x12\x03E\x04\x1c\n\x0e\n\x07\x04\t\x03\0\x02\ - \x01\x04\x12\x03E\x04\x0c\n\x0e\n\x07\x04\t\x03\0\x02\x01\x05\x12\x03E\r\ - \x12\n\x0e\n\x07\x04\t\x03\0\x02\x01\x01\x12\x03E\x13\x17\n\x0e\n\x07\ - \x04\t\x03\0\x02\x01\x03\x12\x03E\x1a\x1b\n\r\n\x06\x04\t\x03\0\x02\x02\ - \x12\x03F\x04\x1d\n\x0e\n\x07\x04\t\x03\0\x02\x02\x04\x12\x03F\x04\x0c\n\ - \x0e\n\x07\x04\t\x03\0\x02\x02\x05\x12\x03F\r\x13\n\x0e\n\x07\x04\t\x03\ - \0\x02\x02\x01\x12\x03F\x14\x18\n\x0e\n\x07\x04\t\x03\0\x02\x02\x03\x12\ - \x03F\x1b\x1c\n\x0b\n\x04\x04\t\x02\0\x12\x03I\x02\x1c\n\x0c\n\x05\x04\t\ - \x02\0\x04\x12\x03I\x02\n\n\x0c\n\x05\x04\t\x02\0\x05\x12\x03I\x0b\x11\n\ - \x0c\n\x05\x04\t\x02\0\x01\x12\x03I\x12\x17\n\x0c\n\x05\x04\t\x02\0\x03\ - \x12\x03I\x1a\x1b\n\x0b\n\x04\x04\t\x02\x01\x12\x03J\x02\x1b\n\x0c\n\x05\ - \x04\t\x02\x01\x04\x12\x03J\x02\n\n\x0c\n\x05\x04\t\x02\x01\x05\x12\x03J\ - \x0b\x10\n\x0c\n\x05\x04\t\x02\x01\x01\x12\x03J\x11\x16\n\x0c\n\x05\x04\ - \t\x02\x01\x03\x12\x03J\x19\x1a\n\x0b\n\x04\x04\t\x02\x02\x12\x03K\x02\ - \x1a\n\x0c\n\x05\x04\t\x02\x02\x04\x12\x03K\x02\n\n\x0c\n\x05\x04\t\x02\ - \x02\x06\x12\x03K\x0b\x0f\n\x0c\n\x05\x04\t\x02\x02\x01\x12\x03K\x10\x15\ - \n\x0c\n\x05\x04\t\x02\x02\x03\x12\x03K\x18\x19\n\x0b\n\x04\x04\t\x02\ - \x03\x12\x03L\x02\x1f\n\x0c\n\x05\x04\t\x02\x03\x04\x12\x03L\x02\n\n\x0c\ - \n\x05\x04\t\x02\x03\x05\x12\x03L\x0b\x10\n\x0c\n\x05\x04\t\x02\x03\x01\ - \x12\x03L\x11\x1a\n\x0c\n\x05\x04\t\x02\x03\x03\x12\x03L\x1d\x1e\ -"; - -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/protocol.rs b/src/protocol.rs new file mode 100644 index 0000000..7a64f88 --- /dev/null +++ b/src/protocol.rs @@ -0,0 +1,507 @@ + +use std::net::TcpStream; +use std::time::Duration; +use std::io::{Read, Write}; +use std::cmp; +use crypto::digest::Digest; +use crypto::blake2b::Blake2b; +use sodiumoxide::crypto::stream::*; +use rand::{OsRng, Rng}; +use protobuf::Message; +use protobuf::parse_from_bytes; +use integer_encoding::{VarIntReader, VarIntWriter}; + +use errors::*; +use network_msg::*; +use metadata_msg::Index; + +#[derive(Debug)] +pub enum DatNetMessage { + Register(Feed), + Handshake(Handshake), + Status(Info), + Have(Have), + Unhave(Unhave), + Want(Want), + Unwant(Unwant), + Request(Request), + Cancel(Cancel), + Data(Data), +} + +fn msg_code(msg: &DatNetMessage) -> u8 { + match msg { + &DatNetMessage::Register(_) => 0, + &DatNetMessage::Handshake(_) => 1, + &DatNetMessage::Status(_) => 2, + &DatNetMessage::Have(_) => 3, + &DatNetMessage::Unhave(_) => 4, + &DatNetMessage::Want(_) => 5, + &DatNetMessage::Unwant(_) => 6, + &DatNetMessage::Request(_) => 7, + &DatNetMessage::Cancel(_) => 8, + &DatNetMessage::Data(_) => 9, + } +} + +fn msg_sugar(msg: &DatNetMessage) -> &Message { + match msg { + &DatNetMessage::Register(ref m) => m, + &DatNetMessage::Handshake(ref m) => m, + &DatNetMessage::Status(ref m) => m, + &DatNetMessage::Have(ref m) => m, + &DatNetMessage::Unhave(ref m) => m, + &DatNetMessage::Want(ref m) => m, + &DatNetMessage::Unwant(ref m) => m, + &DatNetMessage::Request(ref m) => m, + &DatNetMessage::Cancel(ref m) => m, + &DatNetMessage::Data(ref m) => m, + } +} + +/// This helper is pretty slow/inefficient; lots of copying memory +fn bytewise_stream_xor_ic_inplace(buf: &mut [u8], byte_offset: u64, nonce: &Nonce, key: &Key) { + + let mut offset = byte_offset; + + // We may have a partial-64-byte-block to finish encrypting first + let partial_offset: usize = (offset % 64) as usize; + let partial_len: usize = cmp::min(64 - partial_offset, buf.len()); + if partial_len != 0 { + let mut partial = vec![0; 64]; + for i in 0..partial_len { + partial[partial_offset+i] = buf[i]; + } + let partial_enc = stream_xor_ic(&partial, offset / 64, &nonce, &key); + offset += partial_len as u64; + for i in 0..partial_len { + buf[i] = partial_enc[partial_offset+i]; + } + } + if buf.len() > partial_len { + let main_enc = stream_xor_ic(&buf[partial_len..], offset / 64, &nonce, &key); + //offset += main_enc.len() as u64; + for i in 0..main_enc.len() { + buf[partial_len+i] = main_enc[i]; + } + } +} + +#[test] +fn test_bsxii_short() { + + let nonce = gen_nonce(); + let key = gen_key(); + + for size in [10, 100, 1234].iter() { + let mut a = vec![7; *size]; + let mut b = vec![7; *size]; + let c = vec![7; *size]; + + assert_eq!(a, b); + bytewise_stream_xor_ic_inplace(&mut a, 0, &nonce, &key); + bytewise_stream_xor_ic_inplace(&mut b, 0, &nonce, &key); + assert_eq!(a, b); + assert_ne!(a, c); + bytewise_stream_xor_ic_inplace(&mut a, 0, &nonce, &key); + assert_eq!(a, c); + } +} + +#[test] +fn test_bsxii_continued() { + + let nonce = gen_nonce(); + let key = gen_key(); + + let mut a = vec![7; 1234]; + let mut b = vec![7; 1234]; + let c = vec![7; 1234]; + + assert_eq!(a, b); + bytewise_stream_xor_ic_inplace(&mut a[0..10], 0, &nonce, &key); + bytewise_stream_xor_ic_inplace(&mut a[10..20], 10, &nonce, &key); + bytewise_stream_xor_ic_inplace(&mut b[0..20], 0, &nonce, &key); + assert_eq!(a, b); + bytewise_stream_xor_ic_inplace(&mut a[20..50], 20, &nonce, &key); + bytewise_stream_xor_ic_inplace(&mut a[50..500], 50, &nonce, &key); + bytewise_stream_xor_ic_inplace(&mut b[20..500], 20, &nonce, &key); + assert_ne!(a, c); + assert_eq!(a, b); + bytewise_stream_xor_ic_inplace(&mut a[500..1234], 500, &nonce, &key); + bytewise_stream_xor_ic_inplace(&mut a, 0, &nonce, &key); + assert_eq!(a, c); +} + +fn make_discovery_key(key: &[u8]) -> Vec { + // calculate discovery key + let mut discovery_key = [0; 32]; + let mut hash = Blake2b::new_keyed(32, key); + hash.input(&"hypercore".as_bytes()); + hash.result(&mut discovery_key); + discovery_key.to_vec() +} + +/// Represents a bi-directional connection to a network peer +/// +/// Spec says nonce is 32 bytes, by dat implementation (hypercore-protocol) is 24 bytes. +pub struct DatConnection { + id: [u8; 32], + remote_id: [u8; 32], + tcp: TcpStream, + live: bool, + key: Key, + discovery_key: [u8; 32], + data_key: [u8; 32], + data_discovery_key: [u8; 32], + tx_nonce: Nonce, + tx_offset: u64, + rx_nonce: Nonce, + rx_offset: u64, +} + +impl Read for DatConnection { + + /// Encrypted TCP read (after connection initialized). Uses XOR of an XSalsa20 stream, using + /// block offsets. + fn read(&mut self, buf: &mut [u8]) -> ::std::io::Result { + let len = self.tcp.read(buf)?; + bytewise_stream_xor_ic_inplace(&mut buf[0..len], self.rx_offset, &self.rx_nonce, &self.key); + self.rx_offset += len as u64; + + Ok(len) + } +} + +impl Write for DatConnection { + + /// Encrypted write to complement `read()`. + fn write(&mut self, buf: &[u8]) -> ::std::io::Result { + + // Don't mutate what we've been passed + let mut enc = vec![0; buf.len()]; + enc.copy_from_slice(buf); + + bytewise_stream_xor_ic_inplace(&mut enc, self.tx_offset, &self.tx_nonce, &self.key); + self.tx_offset += enc.len() as u64; + + self.tcp.write(&enc) + } + + fn flush(&mut self) -> ::std::io::Result<()> { + self.tcp.flush() + } +} + +impl DatConnection { + + pub fn connect(host_port: &str, key: &[u8], live: bool) -> Result { + + let timeout = Duration::new(7, 0); + let tx_nonce = gen_nonce(); + let mut local_id = [0; 32]; + let mut rng = OsRng::new()?; + rng.fill_bytes(&mut local_id); + + let mut dk = [0; 32]; + dk.copy_from_slice(&make_discovery_key(key)[0..32]); + + // Connect to server + info!("Connecting to {}", host_port); + // TODO: timeout on connect (socketaddr dance) + let tcp = TcpStream::connect(host_port)?; + tcp.set_read_timeout(Some(timeout))?; + tcp.set_write_timeout(Some(timeout))?; + + let mut dc = DatConnection { + id: local_id, + tcp, + live, + remote_id: [0; 32], + key: Key::from_slice(key).unwrap(), // TODO: + discovery_key: dk, + data_key: [0; 32], + data_discovery_key: [0; 32], + tx_nonce: tx_nonce, + tx_offset: 0, + rx_nonce: gen_nonce(), // dummy + rx_offset: 0, + }; + + // Exchange register/feed + dc.tcp.set_nodelay(true)?; // Faster handshake + // send register + let mut register_msg = Feed::new(); + register_msg.set_discoveryKey(dc.discovery_key.to_vec()); + register_msg.set_nonce((tx_nonce[0..24]).to_vec()); + dc.send_register(®ister_msg)?; + + // read register + let registration = dc.recv_register()?; + if registration.get_discoveryKey()[0..32] != dk[..] { + bail!("Remote peer not sharing same discovery key"); + } + let rn = registration.get_nonce(); + dc.rx_nonce = Nonce::from_slice(&rn).unwrap(); + + // send handshake + let mut handshake_msg = Handshake::new(); + handshake_msg.set_live(dc.live); + handshake_msg.set_id(dc.id.to_vec()); + dc.send_msg(&DatNetMessage::Handshake(handshake_msg), false)?; + + // read handshake + let (was_content, msg) = dc.recv_msg()?; + if was_content { + bail!("Expected metadata msg, not content"); + } + if let DatNetMessage::Handshake(handshake) = msg { + // TODO: more satisfying way to do this copy + let hid = handshake.get_id(); + for i in 0..32 { + dc.remote_id[i] = hid[i]; + } + } else { + bail!("Expected Handshake message, got something else"); + } + + // TODO: read data feed register here? + + // Fetch and configure key for data feed + dc.get_data_key()?; + + // Send (encrypted) Register/Feed message for data feed + let mut register_msg = Feed::new(); + register_msg.set_discoveryKey(dc.data_discovery_key.to_vec()); + dc.send_msg(&DatNetMessage::Register(register_msg), true)?; + + dc.tcp.set_nodelay(false)?; // Back to normal + + Ok(dc) + } + + fn send_msg(&mut self, dnm: &DatNetMessage, is_content: bool) -> Result<()> { + + let header_int: u8 = (is_content as u8) << 4 | (msg_code(dnm) & 0x0F); + let msg: &Message = msg_sugar(dnm); + let total_message_size = (msg.compute_size() as usize) + 1; + + trace!("SEND total_len={} header={} is_content={} type={:?}", + total_message_size, header_int, is_content, &dnm); + + // send both header varints, and data + self.write_varint(total_message_size as u64)?; + self.write_varint(header_int as u32)?; + + match dnm { + &DatNetMessage::Register(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Handshake(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Status(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Have(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Unhave(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Want(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Unwant(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Request(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Cancel(ref m) => m.write_to_writer(self)?, + &DatNetMessage::Data(ref m) => m.write_to_writer(self)?, + } + Ok(()) + } + + fn recv_msg(&mut self) -> Result<(bool, DatNetMessage)> { + + let total_len: u64 = self.read_varint()?; + let header: u8 = self.read_varint()?; + + let is_content = (header & (1 << 4)) != 0; + + trace!("RECV total_len={} header={} is_content={}", total_len, header, is_content); + + if header > 0x1F { + bail!("Invalid header received: {}", header); + } + + let msg_len = (total_len - 1) as usize; + let mut buf = vec![0; msg_len]; + self.read_exact(&mut buf[0..msg_len])?; + + let dnm = match header & 0x0F { + 0 => DatNetMessage::Register(parse_from_bytes::(&mut buf)?), + 1 => DatNetMessage::Handshake(parse_from_bytes::(&mut buf)?), + 2 => DatNetMessage::Status(parse_from_bytes::(&mut buf)?), + 3 => DatNetMessage::Have(parse_from_bytes::(&mut buf)?), + 4 => DatNetMessage::Unhave(parse_from_bytes::(&mut buf)?), + 5 => DatNetMessage::Want(parse_from_bytes::(&mut buf)?), + 6 => DatNetMessage::Unwant(parse_from_bytes::(&mut buf)?), + 7 => DatNetMessage::Request(parse_from_bytes::(&mut buf)?), + 8 => DatNetMessage::Cancel(parse_from_bytes::(&mut buf)?), + 9 => DatNetMessage::Data(parse_from_bytes::(&mut buf)?), + other => bail!("Unimplemented message type received: {}", other), + }; + trace!("\twas: {:?}", &dnm); + Ok((is_content, dnm)) + } + + /// Special unencrypted variant of `send_msg()`, used only during initial connection + /// establishment (eg, to check metadata discovery key and exchange nonces). After the + /// connection is initialized, send Register (aka Feed) messages as normal to add extra feeds. + fn send_register(&mut self, reg: &Feed) -> Result<()> { + // TODO: refactor this to take discovery key and nonce directly + + let header_int: u8 = 0; + let total_message_size = (reg.compute_size() as usize) + 1; + + trace!("SEND total_len={} header={} msg={:?}", + total_message_size, header_int, reg); + + self.tcp.write_varint(total_message_size as u64)?; + self.tcp.write_varint(header_int as u32)?; + reg.write_to_writer(&mut self.tcp)?; + Ok(()) + } + + /// Receive complement to `send_register()`. + fn recv_register(&mut self) -> Result { + // TODO: refactor this to return discovery key and nonce directly + + let total_len: u64 = self.tcp.read_varint()?; + let header: u8 = self.tcp.read_varint()?; + + if header != 0 { + bail!("Invalid register header received"); + } + + trace!("RECV total_len={} header={}", total_len, header); + + let msg_len = (total_len - 1) as usize; + let mut buf = vec![0; msg_len]; + self.tcp.read_exact(&mut buf[0..msg_len])?; + + let reg = parse_from_bytes::(&mut buf)?; + trace!("\twas: {:?}", reg); + Ok(reg) + } + + pub fn get_data_key(&mut self) -> Result<()> { + + // Status: downloading, not uploading + let mut sm = Info::new(); + sm.set_uploading(false); + sm.set_downloading(true); + self.send_msg(&DatNetMessage::Status(sm), false)?; + + // Have: nothing (so far) + let mut hm = Have::new(); + hm.set_start(0); + hm.set_length(0); + self.send_msg(&DatNetMessage::Have(hm), false)?; + + // UnHave: still nothing + let mut uhm = Unhave::new(); + uhm.set_start(0); + self.send_msg(&DatNetMessage::Unhave(uhm), false)?; + + // Want: just the first element + let mut wm = Want::new(); + wm.set_start(0); + wm.set_length(1); + self.send_msg(&DatNetMessage::Want(wm), false)?; + + // listen for Have + loop { + let (was_content, msg) = self.recv_msg()?; + if was_content { + continue; + } + if let DatNetMessage::Have(_) = msg { + break; + } else { + info!("Expected Have message, got: {:?}", &msg); + continue; + } + }; + + // Request + let mut rm = Request::new(); + rm.set_index(0); + self.send_msg(&DatNetMessage::Request(rm), false)?; + + loop { + let (was_content, msg) = self.recv_msg()?; + if was_content { + info!("Expected other message channel"); + continue; + } + if let DatNetMessage::Data(dm) = msg { + info!("Got metadata: {}", dm.get_index()); + if dm.get_index() == 0 { + let index_msg = parse_from_bytes::(&mut dm.get_value())?; + if index_msg.get_field_type() == "hyperdrive" { + let data_key = index_msg.get_content(); + if data_key.len() != 32 { + bail!("Received data key had wrong length: {}", data_key.len()); + } + info!("Got data discovery key"); + self.data_key.copy_from_slice(&data_key[0..32]); + self.data_discovery_key.copy_from_slice(&make_discovery_key(data_key)[0..32]); + return Ok(()); + } else { + unimplemented!("non-hyperdrive Index type: {}", index_msg.get_field_type()); + } + } + } else { + info!("Expected Data message, got: {:?}", &msg); + continue; + } + } + } + + pub fn receive_all(&mut self, is_content: bool, length: u64) -> Result<()> { + + // Status: downloading, not uploading + let mut sm = Info::new(); + sm.set_uploading(false); + sm.set_downloading(true); + self.send_msg(&DatNetMessage::Status(sm), is_content)?; + + // Have: nothing (so far) + let mut hm = Have::new(); + hm.set_start(0); + hm.set_length(0); + self.send_msg(&DatNetMessage::Have(hm), is_content)?; + + // UnHave: still nothing + let mut uhm = Unhave::new(); + uhm.set_start(0); + self.send_msg(&DatNetMessage::Unhave(uhm), is_content)?; + + // Want: everything + let mut wm = Want::new(); + wm.set_start(0); + self.send_msg(&DatNetMessage::Want(wm), is_content)?; + + // Request / Data loop + for i in 0..length { + let mut rm = Request::new(); + rm.set_index(i); + self.send_msg(&DatNetMessage::Request(rm), is_content)?; + + loop { + let (was_content, msg) = self.recv_msg()?; + if was_content != is_content{ + info!("Expected other message channel"); + continue; + } + if let DatNetMessage::Data(dm) = msg { + info!("Got content: {}", dm.get_index()); + break; + } else { + info!("Expected Data message, got: {:?}", &msg); + continue; + } + } + } + + Ok(()) + } +} diff --git a/src/register.rs b/src/register.rs deleted file mode 100644 index 0313497..0000000 --- a/src/register.rs +++ /dev/null @@ -1,556 +0,0 @@ - -use std::io::prelude::*; -use std::fs::File; -use std::path::Path; -use std::io::SeekFrom; -use integer_encoding::FixedInt; -use std::fs::OpenOptions; -use crypto::blake2b::Blake2b; -use crypto::digest::Digest; -use crypto::ed25519; -use rand::{Rng, OsRng}; - -use errors::*; -use sleep::*; - -/// Abstract access to Hypercore register -pub trait HyperRegister { - - /// Whether the register store contains the given (data) entry - fn has(&self, index: u64) -> Result; - - /// Whether the register store contains *all* known (data) entries - fn has_all(&self) -> Result; - - /// If the contiguous range of entries is in the store - fn has_range(&self, start: u64, end: u64) -> Result; - - /// Reads a single data entry from the store. - fn get_data_entry(&mut self, index: u64) -> Result>; - - /// Writes an entry to the store. Requires the private key to be present. - fn append(&mut self, data: &[u8]) -> Result; - - /// Count of data entries for this register. This is the total count (highest entry index plus - /// one); this particular store might be sparse. - fn len(&self) -> Result; - - /// Total size of this register in bytes. - fn len_bytes(&mut self) -> Result; - - /// [UNIMPLEMENTED] Intended to do a deeper merkel-tree verification of all stored data - fn verify(&mut self) -> Result<()>; - - /// Quick sanity checks on register store robust-ness - fn check(&mut self) -> Result<()>; - - /// Can this register be appended to? - fn writable(&self) -> bool; - - /// Returns a single tree entry (using tree indexing, not data indexing). - fn get_tree_entry(&mut self, index: u64) -> Result>; -} - -impl HyperRegister { - - fn hash_leaf(data: &[u8]) -> [u8; 40] { - let mut buf = [0; 40]; - u64::to_be(data.len() as u64) - .encode_fixed(&mut buf[32..40]); - let mut hash = Blake2b::new(32); - hash.input(&[0; 1]); - hash.input(&buf[32..40]); - hash.input(&data); - hash.result(&mut buf[0..32]); - buf - } - - fn hash_parent(lhash: &[u8], rhash: &[u8]) -> [u8; 40] { - let mut buf = [0; 40]; - // TODO: check overflow - let sum_size = u64::from_be(FixedInt::decode_fixed(&lhash[32..40])) + - u64::from_be(FixedInt::decode_fixed(&rhash[32..40])); - u64::to_be(sum_size as u64) - .encode_fixed(&mut buf[32..40]); - - let mut hash = Blake2b::new(32); - hash.input(&[1; 1]); - hash.input(&buf[32..40]); - hash.input(&lhash[..]); - hash.input(&rhash[..]); - hash.result(&mut buf[0..32]); - buf - } - - pub fn hash_roots(reg: &mut HyperRegister, index: u64) -> Result> { - let mut buf = [0; 40]; - let mut hash = Blake2b::new(32); - let mut index_buf = [0; 8]; - hash.input(&[2; 1]); - for ri in HyperRegister::tree_root_nodes(index) { - u64::to_be(ri).encode_fixed(&mut index_buf); - let node = reg.get_tree_entry(ri)?; - hash.input(&node[0..32]); - hash.input(&index_buf); - hash.input(&node[32..40]); - } - hash.result(&mut buf[0..32]); - Ok(buf.to_vec()) - - } - - fn tree_root_nodes(data_count: u64) -> Vec { - // Calculates the root notes for a given length (of data entries, not tree entries) - // TODO: this should be an iterator - // NB: this is a relatively "hot" function, gets called (repeatedly?) on every mutation, - // and potentially in inner loops of lookups. - if data_count == 0 { - return vec![]; - } - - // Convert the count to a (descending) list of power-of-2 components - let mut x = 0; - let mut components = vec![]; - while 2u64.pow(x) <= data_count { - if (data_count & 2u64.pow(x)) != 0 { - components.push(2u64.pow(x)); - } - x += 1; - } - components.reverse(); - - // Add and accumulate - let mut accum = 0; - let mut roots = vec![]; - for x in components { - roots.push(accum + (x - 1)); - accum += 2*x; - } - roots - } - - pub fn get_data_offset(reg: &mut HyperRegister, index: u64) -> Result { - // TODO: this is a naive (linear) implementation - // log(N) would go up previous parent nodes (eg, use root_nodes()) - let mut sum: u64 = 0; - for i in 0..index { - let leaf = reg.get_tree_entry(i*2)?; - sum += u64::from_be(FixedInt::decode_fixed(&leaf[32..40])); - } - Ok(sum) - } - - /// Every node has a parent, so this function won't fail unless index is over 2^62, in which - /// case it would overflow and panics instead. - fn tree_parent_index(index: u64) -> u64 { - for i in 0..62 { - // find lowest-significant zero bit - if (index & (1 << i)) == 0 { - // set that bit and clear next higher - return ((index | (1 << i))) & !(1 << (i+1)); - } - } - panic!("Parent lookup overflowed, huge index!"); - } - - /// Calling this on a leaf node is an error, as is calling very high node numbers (> 2^62) - fn tree_child_indices(index: u64) -> Result<(u64,u64)> { - if index % 2 == 0 { - bail!("Leaf tree nodes have no children"); - } - for i in 0..62 { - // find lowest-significant zero bit... - if (index & (1 << i)) == 0 { - // larger child has this bit high, next lower bit cleared - let right = ((index | (1 << i))) & !(1 << (i-1)); - // smaller child has next lower bit cleared - let left = index & !(1 << (i-1)); - return Ok((left, right)); - } - } - bail!("Child lookup overflowed, huge index!"); - } -} - -#[test] -fn test_tree_root_nodes() { - assert_eq!(HyperRegister::tree_root_nodes(0), vec![]); - assert_eq!(HyperRegister::tree_root_nodes(1), vec![0]); - assert_eq!(HyperRegister::tree_root_nodes(2), vec![1]); - assert_eq!(HyperRegister::tree_root_nodes(3), vec![1,4]); - assert_eq!(HyperRegister::tree_root_nodes(4), vec![3]); - assert_eq!(HyperRegister::tree_root_nodes(5), vec![3,8]); - assert_eq!(HyperRegister::tree_root_nodes(6), vec![3,9]); - assert_eq!(HyperRegister::tree_root_nodes(7), vec![3,9,12]); - assert_eq!(HyperRegister::tree_root_nodes(8), vec![7]); -} - -#[test] -fn test_tree_parent_index() { - assert_eq!(HyperRegister::tree_parent_index(0), 1); - assert_eq!(HyperRegister::tree_parent_index(1), 3); - assert_eq!(HyperRegister::tree_parent_index(2), 1); - assert_eq!(HyperRegister::tree_parent_index(3), 7); - assert_eq!(HyperRegister::tree_parent_index(4), 5); - assert_eq!(HyperRegister::tree_parent_index(5), 3); - assert_eq!(HyperRegister::tree_parent_index(6), 5); - assert_eq!(HyperRegister::tree_parent_index(7), 15); - assert_eq!(HyperRegister::tree_parent_index(8), 9); - assert_eq!(HyperRegister::tree_parent_index(9), 11); - assert_eq!(HyperRegister::tree_parent_index(21), 19); - assert_eq!(HyperRegister::tree_parent_index(22), 21); -} - -#[test] -fn test_tree_child_indices() { - assert!(HyperRegister::tree_child_indices(0).is_err()); - assert!(HyperRegister::tree_child_indices(1024).is_err()); - assert_eq!(HyperRegister::tree_child_indices(1).unwrap(), (0, 2)); - - assert_eq!(HyperRegister::tree_child_indices(3).unwrap(), (1, 5)); - assert_eq!(HyperRegister::tree_child_indices(5).unwrap(), (4, 6)); - assert_eq!(HyperRegister::tree_child_indices(7).unwrap(), (3, 11)); - assert_eq!(HyperRegister::tree_child_indices(9).unwrap(), (8, 10)); - assert_eq!(HyperRegister::tree_child_indices(11).unwrap(), (9, 13)); - assert_eq!(HyperRegister::tree_child_indices(13).unwrap(), (12, 14)); - assert_eq!(HyperRegister::tree_child_indices(15).unwrap(), (7, 23)); - assert_eq!(HyperRegister::tree_child_indices(19).unwrap(), (17, 21)); -} - -/// Implementation of HyperRegister using a local directory of SLEEP files -#[derive(Debug)] -pub struct SleepDirRegister { - tree_sleep: SleepFile, - sign_sleep: SleepFile, - bitfield_sleep: SleepFile, - data_file: Option, - // Except, these should be Ed25519 keys, not bytes - pub_key: Vec, - secret_key: Option>, -} - -fn read_key_file(path: &Path, is_secret: bool) -> Result> { - - let expected = if is_secret { 64 } else { 32 }; - let mut key = vec![]; - let mut key_file = OpenOptions::new() - .read(true) - .write(false) - .open(path)?; - key_file.read_to_end(&mut key)?; - if key.len() != expected { - bail!("Bad key file (len {} != {}): {:?}", key.len(), expected, path); - } - Ok(key) -} - -fn write_key_file(path: &Path, key: &[u8], is_secret: bool) -> Result<()> { - - let expected = if is_secret { 64 } else { 32 }; - if key.len() != expected { - bail!("Bad key file (len {} != {}): {:?}", key.len(), expected, path); - } - let mut key_file = OpenOptions::new() - .write(true) - .create_new(true) - .open(path)?; - key_file.write_all(&key)?; - Ok(()) -} - -impl SleepDirRegister { - - pub fn open(directory: &Path, prefix: &str, writable: bool) -> Result { - // read public key from disk - let pub_key: Vec = read_key_file( - &directory.join(Path::new(&(prefix.to_owned() + ".key"))), - false)?; - let mut secret_key = None; - if writable { - secret_key = Some(read_key_file( - &directory.join(Path::new(&(prefix.to_owned() + ".secret_key"))), - true)?); - } - let data_path = &(prefix.to_owned() + ".data"); - let data_path = Path::new(data_path); - let data_file = if data_path.is_file() { - Some(OpenOptions::new() - .read(true) - .write(writable) - .open(data_path)?) - } else { - None - }; - let tree_sleep = SleepFile::open( - &directory.join(Path::new(&(prefix.to_owned() + ".tree"))), writable)?; - let sign_sleep = SleepFile::open( - &directory.join(Path::new(&(prefix.to_owned() + ".signatures"))), writable)?; - let bitfield_sleep = SleepFile::open( - &directory.join(Path::new(&(prefix.to_owned() + ".bitfield"))), writable)?; - let mut sf = SleepDirRegister { - tree_sleep, - sign_sleep, - bitfield_sleep, - data_file, - pub_key, - secret_key, - }; - sf.check()?; - Ok(sf) - } - - /// In addition to what one would expect, also creates an Ed25519 key-pair using OsRng - pub fn create(directory: &Path, prefix: &str) -> Result { - let mut rand_seed = vec![0; 32]; - let mut rng = OsRng::new()?; - rng.fill_bytes(&mut rand_seed); - let (secret_key, pub_key) = ed25519::keypair(&rand_seed); - write_key_file( - &directory.join(Path::new(&(prefix.to_owned() + ".key"))), - &pub_key, - false)?; - write_key_file( - &directory.join(Path::new(&(prefix.to_owned() + ".secret_key"))), - &secret_key, - true)?; - let data_file = OpenOptions::new() - .read(true) - .write(true) - .create_new(true) - .open(directory.join(Path::new(&(prefix.to_owned() + ".data"))))?; - let tree_sleep = SleepFile::create( - &directory.join(Path::new(&(prefix.to_owned() + ".tree"))), - 0x05025702, - 40, - Some("BLAKE2b".to_string()))?; - let sign_sleep = SleepFile::create( - &directory.join(Path::new(&(prefix.to_owned() + ".signatures"))), - 0x05025701, - 64, - Some("Ed25519".to_string()))?; - let bitfield_sleep = SleepFile::create( - &directory.join(Path::new(&(prefix.to_owned() + ".bitfield"))), - 0x05025700, - 3328, - None)?; - let mut sf = SleepDirRegister { - tree_sleep, - sign_sleep, - bitfield_sleep, - data_file: Some(data_file), - pub_key: pub_key.to_vec(), - secret_key: Some(secret_key.to_vec()), - }; - sf.check()?; - Ok(sf) - } -} - -impl HyperRegister for SleepDirRegister { - - /// TODO: this version only works for "dense" registers: it just checks if the index is in the - /// total length, instead of using the bitfield. - fn has(&self, index: u64) -> Result { - return Ok(index < self.len()?); - } - - fn has_all(&self) -> Result { - self.has_range(0, self.len()?) - } - - fn has_range(&self, start: u64, end: u64) -> Result { - // This function is un-motivated and could be removed - assert!(end > start); - for i in start..end { - if !self.has(i)? { - return Ok(false); - } - } - Ok(true) - } - - fn get_data_entry(&mut self, index: u64) -> Result> { - - // Get metadata about chunk (offset and length) - let offset = HyperRegister::get_data_offset(self, index)?; - - // Do we even have this chunk? - if !self.has(index)? { - bail!("Don't have that chunk"); - } - - let data_file = if let Some(ref mut df) = self.data_file { - df - } else { - bail!("No data file in this register"); - }; - let leaf = self.tree_sleep.read(index*2)?; - let data_len = u64::from_be(FixedInt::decode_fixed(&leaf[32..40])); - // avoid foot-gun in development: cap at ~1 billion bytes - assert!(data_len < 2u64.pow(29)); - - // Read chunk - let mut data = vec![0; data_len as usize]; - data_file.seek(SeekFrom::Start(offset))?; - data_file.read_exact(&mut data)?; - - // TODO: check the hash? separate function? - Ok(data) - } - - fn get_tree_entry(&mut self, index: u64) -> Result> { - self.tree_sleep.read(index) - } - - fn append(&mut self, data: &[u8]) -> Result { - - if !self.data_file.is_some() { - bail!("No data file in this register"); - }; - - let index = self.len()?; - // 1. Hash data chunk - let leaf_hash = HyperRegister::hash_leaf(data); - - // 2. Append data to data file - if let Some(ref mut df) = self.data_file { - df.seek(SeekFrom::End(0))?; - df.write_all(data)?; - df.sync_data()?; - } - - // 3. Add hash to tree file, update merkel tree - self.tree_sleep.write(index*2, &leaf_hash)?; - let mut parent = HyperRegister::tree_parent_index(index*2); - while parent < index*2 { - let (left, right) = HyperRegister::tree_child_indices(parent)?; - let (left, right) = (self.tree_sleep.read(left)?, - self.tree_sleep.read(right)?); - let parent_hash = HyperRegister::hash_parent(&left[0..40], &right[0..40]); - self.tree_sleep.write(parent, &parent_hash[0..40])?; - parent = HyperRegister::tree_parent_index(parent); - } - - // 4. Add signature to signature file - let root_hash = HyperRegister::hash_roots(self, index+1)?; - let root_sig = ed25519::signature(&root_hash, &self.secret_key.clone().unwrap()); - self.sign_sleep.append(&root_sig)?; - - // 5. Update bitfile - Ok(index) - } - - fn len(&self) -> Result { - // Length in entry count. - let tree_len = self.tree_sleep.len()?; - if tree_len == 0 { - Ok(0) - } else if tree_len % 2 != 1 { - bail!("Even number of tree file SLEEP entries"); - } else { - Ok((self.tree_sleep.len()? / 2) + 1) - } - } - - fn len_bytes(&mut self) -> Result { - // TODO: this is a naive (linear) implementation - // log(N) would go up previous parent nodes (eg, use tree_root_nodes()) - let mut sum: u64 = 0; - for i in 0..self.len()? { - let leaf = self.get_tree_entry(i*2)?; - sum += u64::from_be(FixedInt::decode_fixed(&leaf[32..40])); - } - Ok(sum) - } - - fn verify(&mut self) -> Result<()> { - unimplemented!() - } - - fn check(&mut self) -> Result<()> { - let sign_len = self.sign_sleep.len()?; - let tree_len = self.tree_sleep.len()?; - if (tree_len == 0) && (sign_len == 0) { - return Ok(()) - } - if tree_len != (sign_len * 2) - 1 { - bail!("Inconsistent SLEEP signature/tree file sizes"); - } - let computed = self.len_bytes()?; - if let Some(ref df) = self.data_file { - let file_size = df.metadata()?.len(); - if file_size != computed { - bail!("Computed vs. data file size mismatch"); - } - } - Ok(()) - } - - /// Checks if we have the secret key (such that we can append to this register) - fn writable(&self) -> bool { - return self.secret_key.is_some() - } -} - -#[test] -fn test_sdr_open() { - - let mut sdr = SleepDirRegister::open( - Path::new("test-data/dat/simple/.dat/"), "metadata", false).unwrap(); - - // Values from 'dat log' - assert_eq!(sdr.len().unwrap(), 3); - assert_eq!(sdr.len_bytes().unwrap(), 145); - - let mut sdr = SleepDirRegister::open( - Path::new("test-data/dat/simple/.dat/"), "content", false).unwrap(); - - // Values from 'dat log' - assert_eq!(sdr.len().unwrap(), 2); - assert_eq!(sdr.len_bytes().unwrap(), 204); -} - -#[test] -fn test_sdr_create() { - - use tempdir::TempDir; - let tmp_dir = TempDir::new("geniza-test").unwrap(); - let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap(); - - assert_eq!(sdr.len().unwrap(), 0); - assert_eq!(sdr.len_bytes().unwrap(), 0); -} - -#[test] -fn test_sdr_append() { - - use tempdir::TempDir; - let tmp_dir = TempDir::new("geniza-test").unwrap(); - let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap(); - - sdr.append("hello world!".as_bytes()).unwrap(); - sdr.check().unwrap(); - assert_eq!(sdr.len().unwrap(), 1); - assert_eq!(sdr.len_bytes().unwrap(), 12); - let count = 100; // TODO: make this >1000 when things are faster - for _ in 0..count { - sdr.append(&[1,2,3,4,5]).unwrap(); - } - sdr.check().unwrap(); - assert_eq!(sdr.len().unwrap(), 1+count); - assert_eq!(sdr.len_bytes().unwrap(), 12 + (count*5)); -} - -#[test] -fn test_sdr_has() { - - use tempdir::TempDir; - let tmp_dir = TempDir::new("geniza-test").unwrap(); - let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap(); - - sdr.append("hello world!".as_bytes()).unwrap(); - sdr.check().unwrap(); - assert_eq!(sdr.has_all().unwrap(), true); - assert_eq!(sdr.has(0).unwrap(), true); - assert_eq!(sdr.has(40).unwrap(), false); -} diff --git a/src/sleep.rs b/src/sleep.rs deleted file mode 100644 index 36bf7a9..0000000 --- a/src/sleep.rs +++ /dev/null @@ -1,203 +0,0 @@ - -use std::io::prelude::*; -use std::io::SeekFrom; -use std::path::Path; -use std::fs::File; -use integer_encoding::FixedInt; -use std::fs::OpenOptions; - -use errors::*; - -/// Abstract access to SLEEP content -/// -/// Back-ends could be in RAM, on disk, remote HTTP, etc. -pub trait SleepStorage { - - /// Returns the 32-bit "magic word", indicating the content type, in native format (aka, not - /// necessarily big-endian). - fn get_magic(&self) -> u32; - - /// If the algorithm string is empty, returns None, otherwise the String (owned), decoded from - /// UTF-8. Encoded (bytes) representation is at most 24 bytes. - fn get_algorithm(&self) -> Option; - - /// Size (in bytes) of each entry for this SLEEP file. - fn get_entry_size(&self) -> u16; - - /// Returns a single raw entry at the given index (which is not a byte offset). - /// TODO: should write into a supplied buffer and return size. - fn read(&mut self, index: u64) -> Result>; - - /// Writes an entry at the given entry index (which is not a byte offset). - fn write(&mut self, index: u64, data: &[u8]) -> Result<()>; - - /// Writes a new entry at the end of the file - fn append(&mut self, data: &[u8]) -> Result<()>; - - /// Returns the count of entries, meaning the highest index entry plus one (not necessarily the - /// number of entries which have actually been written). - fn len(&self) -> Result; -} - -/// Local File implementation of SleepStorage -#[derive(Debug)] -pub struct SleepFile { - pub file: File, - magic: u32, - entry_size: u16, - // Option isn't necessary here... idiomatic? - algorithm_name: Option, -} - -impl SleepFile { - - // TODO: 'from' pre-existing File - - // Something here to allow paths as references or actual Path... - pub fn open(path: &Path, writable: bool) -> Result { - - let mut f = OpenOptions::new() - .read(true) - .write(writable) - .create(false) - .open(path)?; - let mut header = [0; 32]; - f.read_exact(&mut header)?; - let version: u8 = header[4]; - if version != 0 { - bail!("Invalid SLEEP header: version must be 0"); - } - let algo_len: u8 = header[7]; - if algo_len > 24 { - bail!("Invalid SLEEP header: can't have algo_len > 24"); - } - let algorithm_name = if algo_len == 0 { None } else { - Some(String::from_utf8_lossy(&header[8..(8+(algo_len as usize))]).into_owned()) - }; - let sf = SleepFile { - file: f, - magic: u32::from_be(FixedInt::decode_fixed(&header[0..4])), - entry_size: u16::from_be(FixedInt::decode_fixed(&header[5..7])), - algorithm_name: algorithm_name, - }; - // call length for consistency checks - sf.len()?; - Ok(sf) - } - - /// This function will *not* allow overwriting an existing file. - pub fn create(path: &Path, magic: u32, entry_size: u16, algo: Option) -> Result { - - let mut header = [0; 32]; - u32::to_be(magic).encode_fixed(&mut header[0..4]); - header[4] = 0; // version - u16::to_be(entry_size).encode_fixed(&mut header[5..7]); - if let Some(name) = algo.clone() { - let name = name.as_bytes(); - let algo_len = name.len(); - if algo_len > 24 { - bail!("Algorithm name must be 24 bytes at most"); - } - header[7] = algo_len as u8; - header[8..(8+algo_len)].clone_from_slice(name); - } else { - header[7] = 0; - }; - - let mut f = OpenOptions::new() - .read(true) - .write(true) - .create_new(true) - .open(path)?; - f.write_all(&header)?; - Ok(SleepFile { - file: f, - magic: magic, - entry_size: entry_size, - algorithm_name: algo, - }) - } -} - -impl SleepStorage for SleepFile { - - fn get_magic(&self) -> u32 { self.magic } - fn get_algorithm(&self) -> Option { self.algorithm_name.clone() } - fn get_entry_size(&self) -> u16 { self.entry_size } - - fn read(&mut self, index: u64) -> Result> { - let entry_size = self.entry_size as usize; - if index + 1 > self.len()? { - bail!("Tried to read beyond end of SLEEP file"); - } - let mut entry = vec![0; entry_size]; - self.file.seek(SeekFrom::Start(32 + (entry_size as u64) * index))?; - self.file.read_exact(&mut entry)?; - Ok(entry) - } - - fn write(&mut self, index: u64, data: &[u8]) -> Result<()> { - // TODO: need to extend file seek beyond end? - if data.len() != self.entry_size as usize { - bail!("Tried to write mis-sized data"); - } - self.file.seek(SeekFrom::Start(32 + (self.entry_size as u64) * index))?; - self.file.write_all(&data)?; - Ok(()) - } - - fn append(&mut self, data: &[u8]) -> Result<()> { - let index = self.len()?; - self.write(index, data) - } - - fn len(&self) -> Result { - let length = self.file.metadata()?.len(); - if length < 32 || (length - 32) % (self.entry_size as u64) != 0 { - bail!("Bad SLEEP file: missing header or not multiple of entry_size"); - } - return Ok((length - 32) / (self.entry_size as u64)) - } -} - -#[test] -fn test_sleep_open() { - - let sf = SleepFile::open( - Path::new("test-data/sleep/empty/empty.sleep"), false).unwrap(); - - assert_eq!(sf.len().unwrap(), 0); - assert_eq!(sf.get_magic(), 0x050257FF); - assert_eq!(sf.get_algorithm(), None); - assert_eq!(sf.get_entry_size(), 1); - - let sf = SleepFile::open( - Path::new("test-data/dat/simple/.dat/metadata.tree"), false).unwrap(); - - // Calculated from 'dat log' - assert_eq!(sf.len().unwrap(), 5); - assert_eq!(sf.get_magic(), 0x05025702); - assert_eq!(sf.get_algorithm(), Some("BLAKE2b".to_string())); - assert_eq!(sf.get_entry_size(), 40); -} - -#[test] -fn test_sleep_create() { - - use tempdir::TempDir; - let tmp_dir = TempDir::new("geniza-test").unwrap(); - - SleepFile::create( - &tmp_dir.path().join("empty2.sleep"), - 0x050257FF, - 1, - None).unwrap(); - - // TODO: binary diff against 'test-data/sleep/empty/empty.sleep' - - SleepFile::create( - &tmp_dir.path().join("simple_metadata.sleep"), - 0x05025702, - 40, - Some("BLAKE2b".into())).unwrap(); -} diff --git a/src/sleep_file.rs b/src/sleep_file.rs new file mode 100644 index 0000000..36bf7a9 --- /dev/null +++ b/src/sleep_file.rs @@ -0,0 +1,203 @@ + +use std::io::prelude::*; +use std::io::SeekFrom; +use std::path::Path; +use std::fs::File; +use integer_encoding::FixedInt; +use std::fs::OpenOptions; + +use errors::*; + +/// Abstract access to SLEEP content +/// +/// Back-ends could be in RAM, on disk, remote HTTP, etc. +pub trait SleepStorage { + + /// Returns the 32-bit "magic word", indicating the content type, in native format (aka, not + /// necessarily big-endian). + fn get_magic(&self) -> u32; + + /// If the algorithm string is empty, returns None, otherwise the String (owned), decoded from + /// UTF-8. Encoded (bytes) representation is at most 24 bytes. + fn get_algorithm(&self) -> Option; + + /// Size (in bytes) of each entry for this SLEEP file. + fn get_entry_size(&self) -> u16; + + /// Returns a single raw entry at the given index (which is not a byte offset). + /// TODO: should write into a supplied buffer and return size. + fn read(&mut self, index: u64) -> Result>; + + /// Writes an entry at the given entry index (which is not a byte offset). + fn write(&mut self, index: u64, data: &[u8]) -> Result<()>; + + /// Writes a new entry at the end of the file + fn append(&mut self, data: &[u8]) -> Result<()>; + + /// Returns the count of entries, meaning the highest index entry plus one (not necessarily the + /// number of entries which have actually been written). + fn len(&self) -> Result; +} + +/// Local File implementation of SleepStorage +#[derive(Debug)] +pub struct SleepFile { + pub file: File, + magic: u32, + entry_size: u16, + // Option isn't necessary here... idiomatic? + algorithm_name: Option, +} + +impl SleepFile { + + // TODO: 'from' pre-existing File + + // Something here to allow paths as references or actual Path... + pub fn open(path: &Path, writable: bool) -> Result { + + let mut f = OpenOptions::new() + .read(true) + .write(writable) + .create(false) + .open(path)?; + let mut header = [0; 32]; + f.read_exact(&mut header)?; + let version: u8 = header[4]; + if version != 0 { + bail!("Invalid SLEEP header: version must be 0"); + } + let algo_len: u8 = header[7]; + if algo_len > 24 { + bail!("Invalid SLEEP header: can't have algo_len > 24"); + } + let algorithm_name = if algo_len == 0 { None } else { + Some(String::from_utf8_lossy(&header[8..(8+(algo_len as usize))]).into_owned()) + }; + let sf = SleepFile { + file: f, + magic: u32::from_be(FixedInt::decode_fixed(&header[0..4])), + entry_size: u16::from_be(FixedInt::decode_fixed(&header[5..7])), + algorithm_name: algorithm_name, + }; + // call length for consistency checks + sf.len()?; + Ok(sf) + } + + /// This function will *not* allow overwriting an existing file. + pub fn create(path: &Path, magic: u32, entry_size: u16, algo: Option) -> Result { + + let mut header = [0; 32]; + u32::to_be(magic).encode_fixed(&mut header[0..4]); + header[4] = 0; // version + u16::to_be(entry_size).encode_fixed(&mut header[5..7]); + if let Some(name) = algo.clone() { + let name = name.as_bytes(); + let algo_len = name.len(); + if algo_len > 24 { + bail!("Algorithm name must be 24 bytes at most"); + } + header[7] = algo_len as u8; + header[8..(8+algo_len)].clone_from_slice(name); + } else { + header[7] = 0; + }; + + let mut f = OpenOptions::new() + .read(true) + .write(true) + .create_new(true) + .open(path)?; + f.write_all(&header)?; + Ok(SleepFile { + file: f, + magic: magic, + entry_size: entry_size, + algorithm_name: algo, + }) + } +} + +impl SleepStorage for SleepFile { + + fn get_magic(&self) -> u32 { self.magic } + fn get_algorithm(&self) -> Option { self.algorithm_name.clone() } + fn get_entry_size(&self) -> u16 { self.entry_size } + + fn read(&mut self, index: u64) -> Result> { + let entry_size = self.entry_size as usize; + if index + 1 > self.len()? { + bail!("Tried to read beyond end of SLEEP file"); + } + let mut entry = vec![0; entry_size]; + self.file.seek(SeekFrom::Start(32 + (entry_size as u64) * index))?; + self.file.read_exact(&mut entry)?; + Ok(entry) + } + + fn write(&mut self, index: u64, data: &[u8]) -> Result<()> { + // TODO: need to extend file seek beyond end? + if data.len() != self.entry_size as usize { + bail!("Tried to write mis-sized data"); + } + self.file.seek(SeekFrom::Start(32 + (self.entry_size as u64) * index))?; + self.file.write_all(&data)?; + Ok(()) + } + + fn append(&mut self, data: &[u8]) -> Result<()> { + let index = self.len()?; + self.write(index, data) + } + + fn len(&self) -> Result { + let length = self.file.metadata()?.len(); + if length < 32 || (length - 32) % (self.entry_size as u64) != 0 { + bail!("Bad SLEEP file: missing header or not multiple of entry_size"); + } + return Ok((length - 32) / (self.entry_size as u64)) + } +} + +#[test] +fn test_sleep_open() { + + let sf = SleepFile::open( + Path::new("test-data/sleep/empty/empty.sleep"), false).unwrap(); + + assert_eq!(sf.len().unwrap(), 0); + assert_eq!(sf.get_magic(), 0x050257FF); + assert_eq!(sf.get_algorithm(), None); + assert_eq!(sf.get_entry_size(), 1); + + let sf = SleepFile::open( + Path::new("test-data/dat/simple/.dat/metadata.tree"), false).unwrap(); + + // Calculated from 'dat log' + assert_eq!(sf.len().unwrap(), 5); + assert_eq!(sf.get_magic(), 0x05025702); + assert_eq!(sf.get_algorithm(), Some("BLAKE2b".to_string())); + assert_eq!(sf.get_entry_size(), 40); +} + +#[test] +fn test_sleep_create() { + + use tempdir::TempDir; + let tmp_dir = TempDir::new("geniza-test").unwrap(); + + SleepFile::create( + &tmp_dir.path().join("empty2.sleep"), + 0x050257FF, + 1, + None).unwrap(); + + // TODO: binary diff against 'test-data/sleep/empty/empty.sleep' + + SleepFile::create( + &tmp_dir.path().join("simple_metadata.sleep"), + 0x05025702, + 40, + Some("BLAKE2b".into())).unwrap(); +} diff --git a/src/sleep_register.rs b/src/sleep_register.rs new file mode 100644 index 0000000..e798cad --- /dev/null +++ b/src/sleep_register.rs @@ -0,0 +1,556 @@ + +use std::io::prelude::*; +use std::fs::File; +use std::path::Path; +use std::io::SeekFrom; +use integer_encoding::FixedInt; +use std::fs::OpenOptions; +use crypto::blake2b::Blake2b; +use crypto::digest::Digest; +use crypto::ed25519; +use rand::{Rng, OsRng}; + +use errors::*; +use sleep_file::*; + +/// Abstract access to Hypercore register +pub trait HyperRegister { + + /// Whether the register store contains the given (data) entry + fn has(&self, index: u64) -> Result; + + /// Whether the register store contains *all* known (data) entries + fn has_all(&self) -> Result; + + /// If the contiguous range of entries is in the store + fn has_range(&self, start: u64, end: u64) -> Result; + + /// Reads a single data entry from the store. + fn get_data_entry(&mut self, index: u64) -> Result>; + + /// Writes an entry to the store. Requires the private key to be present. + fn append(&mut self, data: &[u8]) -> Result; + + /// Count of data entries for this register. This is the total count (highest entry index plus + /// one); this particular store might be sparse. + fn len(&self) -> Result; + + /// Total size of this register in bytes. + fn len_bytes(&mut self) -> Result; + + /// [UNIMPLEMENTED] Intended to do a deeper merkel-tree verification of all stored data + fn verify(&mut self) -> Result<()>; + + /// Quick sanity checks on register store robust-ness + fn check(&mut self) -> Result<()>; + + /// Can this register be appended to? + fn writable(&self) -> bool; + + /// Returns a single tree entry (using tree indexing, not data indexing). + fn get_tree_entry(&mut self, index: u64) -> Result>; +} + +impl HyperRegister { + + fn hash_leaf(data: &[u8]) -> [u8; 40] { + let mut buf = [0; 40]; + u64::to_be(data.len() as u64) + .encode_fixed(&mut buf[32..40]); + let mut hash = Blake2b::new(32); + hash.input(&[0; 1]); + hash.input(&buf[32..40]); + hash.input(&data); + hash.result(&mut buf[0..32]); + buf + } + + fn hash_parent(lhash: &[u8], rhash: &[u8]) -> [u8; 40] { + let mut buf = [0; 40]; + // TODO: check overflow + let sum_size = u64::from_be(FixedInt::decode_fixed(&lhash[32..40])) + + u64::from_be(FixedInt::decode_fixed(&rhash[32..40])); + u64::to_be(sum_size as u64) + .encode_fixed(&mut buf[32..40]); + + let mut hash = Blake2b::new(32); + hash.input(&[1; 1]); + hash.input(&buf[32..40]); + hash.input(&lhash[..]); + hash.input(&rhash[..]); + hash.result(&mut buf[0..32]); + buf + } + + pub fn hash_roots(reg: &mut HyperRegister, index: u64) -> Result> { + let mut buf = [0; 40]; + let mut hash = Blake2b::new(32); + let mut index_buf = [0; 8]; + hash.input(&[2; 1]); + for ri in HyperRegister::tree_root_nodes(index) { + u64::to_be(ri).encode_fixed(&mut index_buf); + let node = reg.get_tree_entry(ri)?; + hash.input(&node[0..32]); + hash.input(&index_buf); + hash.input(&node[32..40]); + } + hash.result(&mut buf[0..32]); + Ok(buf.to_vec()) + + } + + fn tree_root_nodes(data_count: u64) -> Vec { + // Calculates the root notes for a given length (of data entries, not tree entries) + // TODO: this should be an iterator + // NB: this is a relatively "hot" function, gets called (repeatedly?) on every mutation, + // and potentially in inner loops of lookups. + if data_count == 0 { + return vec![]; + } + + // Convert the count to a (descending) list of power-of-2 components + let mut x = 0; + let mut components = vec![]; + while 2u64.pow(x) <= data_count { + if (data_count & 2u64.pow(x)) != 0 { + components.push(2u64.pow(x)); + } + x += 1; + } + components.reverse(); + + // Add and accumulate + let mut accum = 0; + let mut roots = vec![]; + for x in components { + roots.push(accum + (x - 1)); + accum += 2*x; + } + roots + } + + pub fn get_data_offset(reg: &mut HyperRegister, index: u64) -> Result { + // TODO: this is a naive (linear) implementation + // log(N) would go up previous parent nodes (eg, use root_nodes()) + let mut sum: u64 = 0; + for i in 0..index { + let leaf = reg.get_tree_entry(i*2)?; + sum += u64::from_be(FixedInt::decode_fixed(&leaf[32..40])); + } + Ok(sum) + } + + /// Every node has a parent, so this function won't fail unless index is over 2^62, in which + /// case it would overflow and panics instead. + fn tree_parent_index(index: u64) -> u64 { + for i in 0..62 { + // find lowest-significant zero bit + if (index & (1 << i)) == 0 { + // set that bit and clear next higher + return ((index | (1 << i))) & !(1 << (i+1)); + } + } + panic!("Parent lookup overflowed, huge index!"); + } + + /// Calling this on a leaf node is an error, as is calling very high node numbers (> 2^62) + fn tree_child_indices(index: u64) -> Result<(u64,u64)> { + if index % 2 == 0 { + bail!("Leaf tree nodes have no children"); + } + for i in 0..62 { + // find lowest-significant zero bit... + if (index & (1 << i)) == 0 { + // larger child has this bit high, next lower bit cleared + let right = ((index | (1 << i))) & !(1 << (i-1)); + // smaller child has next lower bit cleared + let left = index & !(1 << (i-1)); + return Ok((left, right)); + } + } + bail!("Child lookup overflowed, huge index!"); + } +} + +#[test] +fn test_tree_root_nodes() { + assert_eq!(HyperRegister::tree_root_nodes(0), vec![]); + assert_eq!(HyperRegister::tree_root_nodes(1), vec![0]); + assert_eq!(HyperRegister::tree_root_nodes(2), vec![1]); + assert_eq!(HyperRegister::tree_root_nodes(3), vec![1,4]); + assert_eq!(HyperRegister::tree_root_nodes(4), vec![3]); + assert_eq!(HyperRegister::tree_root_nodes(5), vec![3,8]); + assert_eq!(HyperRegister::tree_root_nodes(6), vec![3,9]); + assert_eq!(HyperRegister::tree_root_nodes(7), vec![3,9,12]); + assert_eq!(HyperRegister::tree_root_nodes(8), vec![7]); +} + +#[test] +fn test_tree_parent_index() { + assert_eq!(HyperRegister::tree_parent_index(0), 1); + assert_eq!(HyperRegister::tree_parent_index(1), 3); + assert_eq!(HyperRegister::tree_parent_index(2), 1); + assert_eq!(HyperRegister::tree_parent_index(3), 7); + assert_eq!(HyperRegister::tree_parent_index(4), 5); + assert_eq!(HyperRegister::tree_parent_index(5), 3); + assert_eq!(HyperRegister::tree_parent_index(6), 5); + assert_eq!(HyperRegister::tree_parent_index(7), 15); + assert_eq!(HyperRegister::tree_parent_index(8), 9); + assert_eq!(HyperRegister::tree_parent_index(9), 11); + assert_eq!(HyperRegister::tree_parent_index(21), 19); + assert_eq!(HyperRegister::tree_parent_index(22), 21); +} + +#[test] +fn test_tree_child_indices() { + assert!(HyperRegister::tree_child_indices(0).is_err()); + assert!(HyperRegister::tree_child_indices(1024).is_err()); + assert_eq!(HyperRegister::tree_child_indices(1).unwrap(), (0, 2)); + + assert_eq!(HyperRegister::tree_child_indices(3).unwrap(), (1, 5)); + assert_eq!(HyperRegister::tree_child_indices(5).unwrap(), (4, 6)); + assert_eq!(HyperRegister::tree_child_indices(7).unwrap(), (3, 11)); + assert_eq!(HyperRegister::tree_child_indices(9).unwrap(), (8, 10)); + assert_eq!(HyperRegister::tree_child_indices(11).unwrap(), (9, 13)); + assert_eq!(HyperRegister::tree_child_indices(13).unwrap(), (12, 14)); + assert_eq!(HyperRegister::tree_child_indices(15).unwrap(), (7, 23)); + assert_eq!(HyperRegister::tree_child_indices(19).unwrap(), (17, 21)); +} + +/// Implementation of HyperRegister using a local directory of SLEEP files +#[derive(Debug)] +pub struct SleepDirRegister { + tree_sleep: SleepFile, + sign_sleep: SleepFile, + bitfield_sleep: SleepFile, + data_file: Option, + // Except, these should be Ed25519 keys, not bytes + pub_key: Vec, + secret_key: Option>, +} + +fn read_key_file(path: &Path, is_secret: bool) -> Result> { + + let expected = if is_secret { 64 } else { 32 }; + let mut key = vec![]; + let mut key_file = OpenOptions::new() + .read(true) + .write(false) + .open(path)?; + key_file.read_to_end(&mut key)?; + if key.len() != expected { + bail!("Bad key file (len {} != {}): {:?}", key.len(), expected, path); + } + Ok(key) +} + +fn write_key_file(path: &Path, key: &[u8], is_secret: bool) -> Result<()> { + + let expected = if is_secret { 64 } else { 32 }; + if key.len() != expected { + bail!("Bad key file (len {} != {}): {:?}", key.len(), expected, path); + } + let mut key_file = OpenOptions::new() + .write(true) + .create_new(true) + .open(path)?; + key_file.write_all(&key)?; + Ok(()) +} + +impl SleepDirRegister { + + pub fn open(directory: &Path, prefix: &str, writable: bool) -> Result { + // read public key from disk + let pub_key: Vec = read_key_file( + &directory.join(Path::new(&(prefix.to_owned() + ".key"))), + false)?; + let mut secret_key = None; + if writable { + secret_key = Some(read_key_file( + &directory.join(Path::new(&(prefix.to_owned() + ".secret_key"))), + true)?); + } + let data_path = &(prefix.to_owned() + ".data"); + let data_path = Path::new(data_path); + let data_file = if data_path.is_file() { + Some(OpenOptions::new() + .read(true) + .write(writable) + .open(data_path)?) + } else { + None + }; + let tree_sleep = SleepFile::open( + &directory.join(Path::new(&(prefix.to_owned() + ".tree"))), writable)?; + let sign_sleep = SleepFile::open( + &directory.join(Path::new(&(prefix.to_owned() + ".signatures"))), writable)?; + let bitfield_sleep = SleepFile::open( + &directory.join(Path::new(&(prefix.to_owned() + ".bitfield"))), writable)?; + let mut sf = SleepDirRegister { + tree_sleep, + sign_sleep, + bitfield_sleep, + data_file, + pub_key, + secret_key, + }; + sf.check()?; + Ok(sf) + } + + /// In addition to what one would expect, also creates an Ed25519 key-pair using OsRng + pub fn create(directory: &Path, prefix: &str) -> Result { + let mut rand_seed = vec![0; 32]; + let mut rng = OsRng::new()?; + rng.fill_bytes(&mut rand_seed); + let (secret_key, pub_key) = ed25519::keypair(&rand_seed); + write_key_file( + &directory.join(Path::new(&(prefix.to_owned() + ".key"))), + &pub_key, + false)?; + write_key_file( + &directory.join(Path::new(&(prefix.to_owned() + ".secret_key"))), + &secret_key, + true)?; + let data_file = OpenOptions::new() + .read(true) + .write(true) + .create_new(true) + .open(directory.join(Path::new(&(prefix.to_owned() + ".data"))))?; + let tree_sleep = SleepFile::create( + &directory.join(Path::new(&(prefix.to_owned() + ".tree"))), + 0x05025702, + 40, + Some("BLAKE2b".to_string()))?; + let sign_sleep = SleepFile::create( + &directory.join(Path::new(&(prefix.to_owned() + ".signatures"))), + 0x05025701, + 64, + Some("Ed25519".to_string()))?; + let bitfield_sleep = SleepFile::create( + &directory.join(Path::new(&(prefix.to_owned() + ".bitfield"))), + 0x05025700, + 3328, + None)?; + let mut sf = SleepDirRegister { + tree_sleep, + sign_sleep, + bitfield_sleep, + data_file: Some(data_file), + pub_key: pub_key.to_vec(), + secret_key: Some(secret_key.to_vec()), + }; + sf.check()?; + Ok(sf) + } +} + +impl HyperRegister for SleepDirRegister { + + /// TODO: this version only works for "dense" registers: it just checks if the index is in the + /// total length, instead of using the bitfield. + fn has(&self, index: u64) -> Result { + return Ok(index < self.len()?); + } + + fn has_all(&self) -> Result { + self.has_range(0, self.len()?) + } + + fn has_range(&self, start: u64, end: u64) -> Result { + // This function is un-motivated and could be removed + assert!(end > start); + for i in start..end { + if !self.has(i)? { + return Ok(false); + } + } + Ok(true) + } + + fn get_data_entry(&mut self, index: u64) -> Result> { + + // Get metadata about chunk (offset and length) + let offset = HyperRegister::get_data_offset(self, index)?; + + // Do we even have this chunk? + if !self.has(index)? { + bail!("Don't have that chunk"); + } + + let data_file = if let Some(ref mut df) = self.data_file { + df + } else { + bail!("No data file in this register"); + }; + let leaf = self.tree_sleep.read(index*2)?; + let data_len = u64::from_be(FixedInt::decode_fixed(&leaf[32..40])); + // avoid foot-gun in development: cap at ~1 billion bytes + assert!(data_len < 2u64.pow(29)); + + // Read chunk + let mut data = vec![0; data_len as usize]; + data_file.seek(SeekFrom::Start(offset))?; + data_file.read_exact(&mut data)?; + + // TODO: check the hash? separate function? + Ok(data) + } + + fn get_tree_entry(&mut self, index: u64) -> Result> { + self.tree_sleep.read(index) + } + + fn append(&mut self, data: &[u8]) -> Result { + + if !self.data_file.is_some() { + bail!("No data file in this register"); + }; + + let index = self.len()?; + // 1. Hash data chunk + let leaf_hash = HyperRegister::hash_leaf(data); + + // 2. Append data to data file + if let Some(ref mut df) = self.data_file { + df.seek(SeekFrom::End(0))?; + df.write_all(data)?; + df.sync_data()?; + } + + // 3. Add hash to tree file, update merkel tree + self.tree_sleep.write(index*2, &leaf_hash)?; + let mut parent = HyperRegister::tree_parent_index(index*2); + while parent < index*2 { + let (left, right) = HyperRegister::tree_child_indices(parent)?; + let (left, right) = (self.tree_sleep.read(left)?, + self.tree_sleep.read(right)?); + let parent_hash = HyperRegister::hash_parent(&left[0..40], &right[0..40]); + self.tree_sleep.write(parent, &parent_hash[0..40])?; + parent = HyperRegister::tree_parent_index(parent); + } + + // 4. Add signature to signature file + let root_hash = HyperRegister::hash_roots(self, index+1)?; + let root_sig = ed25519::signature(&root_hash, &self.secret_key.clone().unwrap()); + self.sign_sleep.append(&root_sig)?; + + // 5. Update bitfile + Ok(index) + } + + fn len(&self) -> Result { + // Length in entry count. + let tree_len = self.tree_sleep.len()?; + if tree_len == 0 { + Ok(0) + } else if tree_len % 2 != 1 { + bail!("Even number of tree file SLEEP entries"); + } else { + Ok((self.tree_sleep.len()? / 2) + 1) + } + } + + fn len_bytes(&mut self) -> Result { + // TODO: this is a naive (linear) implementation + // log(N) would go up previous parent nodes (eg, use tree_root_nodes()) + let mut sum: u64 = 0; + for i in 0..self.len()? { + let leaf = self.get_tree_entry(i*2)?; + sum += u64::from_be(FixedInt::decode_fixed(&leaf[32..40])); + } + Ok(sum) + } + + fn verify(&mut self) -> Result<()> { + unimplemented!() + } + + fn check(&mut self) -> Result<()> { + let sign_len = self.sign_sleep.len()?; + let tree_len = self.tree_sleep.len()?; + if (tree_len == 0) && (sign_len == 0) { + return Ok(()) + } + if tree_len != (sign_len * 2) - 1 { + bail!("Inconsistent SLEEP signature/tree file sizes"); + } + let computed = self.len_bytes()?; + if let Some(ref df) = self.data_file { + let file_size = df.metadata()?.len(); + if file_size != computed { + bail!("Computed vs. data file size mismatch"); + } + } + Ok(()) + } + + /// Checks if we have the secret key (such that we can append to this register) + fn writable(&self) -> bool { + return self.secret_key.is_some() + } +} + +#[test] +fn test_sdr_open() { + + let mut sdr = SleepDirRegister::open( + Path::new("test-data/dat/simple/.dat/"), "metadata", false).unwrap(); + + // Values from 'dat log' + assert_eq!(sdr.len().unwrap(), 3); + assert_eq!(sdr.len_bytes().unwrap(), 145); + + let mut sdr = SleepDirRegister::open( + Path::new("test-data/dat/simple/.dat/"), "content", false).unwrap(); + + // Values from 'dat log' + assert_eq!(sdr.len().unwrap(), 2); + assert_eq!(sdr.len_bytes().unwrap(), 204); +} + +#[test] +fn test_sdr_create() { + + use tempdir::TempDir; + let tmp_dir = TempDir::new("geniza-test").unwrap(); + let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap(); + + assert_eq!(sdr.len().unwrap(), 0); + assert_eq!(sdr.len_bytes().unwrap(), 0); +} + +#[test] +fn test_sdr_append() { + + use tempdir::TempDir; + let tmp_dir = TempDir::new("geniza-test").unwrap(); + let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap(); + + sdr.append("hello world!".as_bytes()).unwrap(); + sdr.check().unwrap(); + assert_eq!(sdr.len().unwrap(), 1); + assert_eq!(sdr.len_bytes().unwrap(), 12); + let count = 100; // TODO: make this >1000 when things are faster + for _ in 0..count { + sdr.append(&[1,2,3,4,5]).unwrap(); + } + sdr.check().unwrap(); + assert_eq!(sdr.len().unwrap(), 1+count); + assert_eq!(sdr.len_bytes().unwrap(), 12 + (count*5)); +} + +#[test] +fn test_sdr_has() { + + use tempdir::TempDir; + let tmp_dir = TempDir::new("geniza-test").unwrap(); + let mut sdr = SleepDirRegister::create(tmp_dir.path(), "dummy").unwrap(); + + sdr.append("hello world!".as_bytes()).unwrap(); + sdr.check().unwrap(); + assert_eq!(sdr.has_all().unwrap(), true); + assert_eq!(sdr.has(0).unwrap(), true); + assert_eq!(sdr.has(40).unwrap(), false); +} diff --git a/src/sync.rs b/src/sync.rs deleted file mode 100644 index efa045a..0000000 --- a/src/sync.rs +++ /dev/null @@ -1,507 +0,0 @@ - -use std::net::TcpStream; -use std::time::Duration; -use std::io::{Read, Write}; -use std::cmp; -use crypto::digest::Digest; -use crypto::blake2b::Blake2b; -use sodiumoxide::crypto::stream::*; -use rand::{OsRng, Rng}; -use protobuf::Message; -use protobuf::parse_from_bytes; -use integer_encoding::{VarIntReader, VarIntWriter}; - -use errors::*; -use network_proto::*; -use drive_proto::Index; - -#[derive(Debug)] -pub enum DatNetMessage { - Register(Feed), - Handshake(Handshake), - Status(Info), - Have(Have), - Unhave(Unhave), - Want(Want), - Unwant(Unwant), - Request(Request), - Cancel(Cancel), - Data(Data), -} - -fn msg_code(msg: &DatNetMessage) -> u8 { - match msg { - &DatNetMessage::Register(_) => 0, - &DatNetMessage::Handshake(_) => 1, - &DatNetMessage::Status(_) => 2, - &DatNetMessage::Have(_) => 3, - &DatNetMessage::Unhave(_) => 4, - &DatNetMessage::Want(_) => 5, - &DatNetMessage::Unwant(_) => 6, - &DatNetMessage::Request(_) => 7, - &DatNetMessage::Cancel(_) => 8, - &DatNetMessage::Data(_) => 9, - } -} - -fn msg_sugar(msg: &DatNetMessage) -> &Message { - match msg { - &DatNetMessage::Register(ref m) => m, - &DatNetMessage::Handshake(ref m) => m, - &DatNetMessage::Status(ref m) => m, - &DatNetMessage::Have(ref m) => m, - &DatNetMessage::Unhave(ref m) => m, - &DatNetMessage::Want(ref m) => m, - &DatNetMessage::Unwant(ref m) => m, - &DatNetMessage::Request(ref m) => m, - &DatNetMessage::Cancel(ref m) => m, - &DatNetMessage::Data(ref m) => m, - } -} - -/// This helper is pretty slow/inefficient; lots of copying memory -fn bytewise_stream_xor_ic_inplace(buf: &mut [u8], byte_offset: u64, nonce: &Nonce, key: &Key) { - - let mut offset = byte_offset; - - // We may have a partial-64-byte-block to finish encrypting first - let partial_offset: usize = (offset % 64) as usize; - let partial_len: usize = cmp::min(64 - partial_offset, buf.len()); - if partial_len != 0 { - let mut partial = vec![0; 64]; - for i in 0..partial_len { - partial[partial_offset+i] = buf[i]; - } - let partial_enc = stream_xor_ic(&partial, offset / 64, &nonce, &key); - offset += partial_len as u64; - for i in 0..partial_len { - buf[i] = partial_enc[partial_offset+i]; - } - } - if buf.len() > partial_len { - let main_enc = stream_xor_ic(&buf[partial_len..], offset / 64, &nonce, &key); - //offset += main_enc.len() as u64; - for i in 0..main_enc.len() { - buf[partial_len+i] = main_enc[i]; - } - } -} - -#[test] -fn test_bsxii_short() { - - let nonce = gen_nonce(); - let key = gen_key(); - - for size in [10, 100, 1234].iter() { - let mut a = vec![7; *size]; - let mut b = vec![7; *size]; - let c = vec![7; *size]; - - assert_eq!(a, b); - bytewise_stream_xor_ic_inplace(&mut a, 0, &nonce, &key); - bytewise_stream_xor_ic_inplace(&mut b, 0, &nonce, &key); - assert_eq!(a, b); - assert_ne!(a, c); - bytewise_stream_xor_ic_inplace(&mut a, 0, &nonce, &key); - assert_eq!(a, c); - } -} - -#[test] -fn test_bsxii_continued() { - - let nonce = gen_nonce(); - let key = gen_key(); - - let mut a = vec![7; 1234]; - let mut b = vec![7; 1234]; - let c = vec![7; 1234]; - - assert_eq!(a, b); - bytewise_stream_xor_ic_inplace(&mut a[0..10], 0, &nonce, &key); - bytewise_stream_xor_ic_inplace(&mut a[10..20], 10, &nonce, &key); - bytewise_stream_xor_ic_inplace(&mut b[0..20], 0, &nonce, &key); - assert_eq!(a, b); - bytewise_stream_xor_ic_inplace(&mut a[20..50], 20, &nonce, &key); - bytewise_stream_xor_ic_inplace(&mut a[50..500], 50, &nonce, &key); - bytewise_stream_xor_ic_inplace(&mut b[20..500], 20, &nonce, &key); - assert_ne!(a, c); - assert_eq!(a, b); - bytewise_stream_xor_ic_inplace(&mut a[500..1234], 500, &nonce, &key); - bytewise_stream_xor_ic_inplace(&mut a, 0, &nonce, &key); - assert_eq!(a, c); -} - -fn make_discovery_key(key: &[u8]) -> Vec { - // calculate discovery key - let mut discovery_key = [0; 32]; - let mut hash = Blake2b::new_keyed(32, key); - hash.input(&"hypercore".as_bytes()); - hash.result(&mut discovery_key); - discovery_key.to_vec() -} - -/// Represents a bi-directional connection to a network peer -/// -/// Spec says nonce is 32 bytes, by dat implementation (hypercore-protocol) is 24 bytes. -pub struct DatConnection { - id: [u8; 32], - remote_id: [u8; 32], - tcp: TcpStream, - live: bool, - key: Key, - discovery_key: [u8; 32], - data_key: [u8; 32], - data_discovery_key: [u8; 32], - tx_nonce: Nonce, - tx_offset: u64, - rx_nonce: Nonce, - rx_offset: u64, -} - -impl Read for DatConnection { - - /// Encrypted TCP read (after connection initialized). Uses XOR of an XSalsa20 stream, using - /// block offsets. - fn read(&mut self, buf: &mut [u8]) -> ::std::io::Result { - let len = self.tcp.read(buf)?; - bytewise_stream_xor_ic_inplace(&mut buf[0..len], self.rx_offset, &self.rx_nonce, &self.key); - self.rx_offset += len as u64; - - Ok(len) - } -} - -impl Write for DatConnection { - - /// Encrypted write to complement `read()`. - fn write(&mut self, buf: &[u8]) -> ::std::io::Result { - - // Don't mutate what we've been passed - let mut enc = vec![0; buf.len()]; - enc.copy_from_slice(buf); - - bytewise_stream_xor_ic_inplace(&mut enc, self.tx_offset, &self.tx_nonce, &self.key); - self.tx_offset += enc.len() as u64; - - self.tcp.write(&enc) - } - - fn flush(&mut self) -> ::std::io::Result<()> { - self.tcp.flush() - } -} - -impl DatConnection { - - pub fn connect(host_port: &str, key: &[u8], live: bool) -> Result { - - let timeout = Duration::new(7, 0); - let tx_nonce = gen_nonce(); - let mut local_id = [0; 32]; - let mut rng = OsRng::new()?; - rng.fill_bytes(&mut local_id); - - let mut dk = [0; 32]; - dk.copy_from_slice(&make_discovery_key(key)[0..32]); - - // Connect to server - info!("Connecting to {}", host_port); - // TODO: timeout on connect (socketaddr dance) - let tcp = TcpStream::connect(host_port)?; - tcp.set_read_timeout(Some(timeout))?; - tcp.set_write_timeout(Some(timeout))?; - - let mut dc = DatConnection { - id: local_id, - tcp, - live, - remote_id: [0; 32], - key: Key::from_slice(key).unwrap(), // TODO: - discovery_key: dk, - data_key: [0; 32], - data_discovery_key: [0; 32], - tx_nonce: tx_nonce, - tx_offset: 0, - rx_nonce: gen_nonce(), // dummy - rx_offset: 0, - }; - - // Exchange register/feed - dc.tcp.set_nodelay(true)?; // Faster handshake - // send register - let mut register_msg = Feed::new(); - register_msg.set_discoveryKey(dc.discovery_key.to_vec()); - register_msg.set_nonce((tx_nonce[0..24]).to_vec()); - dc.send_register(®ister_msg)?; - - // read register - let registration = dc.recv_register()?; - if registration.get_discoveryKey()[0..32] != dk[..] { - bail!("Remote peer not sharing same discovery key"); - } - let rn = registration.get_nonce(); - dc.rx_nonce = Nonce::from_slice(&rn).unwrap(); - - // send handshake - let mut handshake_msg = Handshake::new(); - handshake_msg.set_live(dc.live); - handshake_msg.set_id(dc.id.to_vec()); - dc.send_msg(&DatNetMessage::Handshake(handshake_msg), false)?; - - // read handshake - let (was_content, msg) = dc.recv_msg()?; - if was_content { - bail!("Expected metadata msg, not content"); - } - if let DatNetMessage::Handshake(handshake) = msg { - // TODO: more satisfying way to do this copy - let hid = handshake.get_id(); - for i in 0..32 { - dc.remote_id[i] = hid[i]; - } - } else { - bail!("Expected Handshake message, got something else"); - } - - // TODO: read data feed register here? - - // Fetch and configure key for data feed - dc.get_data_key()?; - - // Send (encrypted) Register/Feed message for data feed - let mut register_msg = Feed::new(); - register_msg.set_discoveryKey(dc.data_discovery_key.to_vec()); - dc.send_msg(&DatNetMessage::Register(register_msg), true)?; - - dc.tcp.set_nodelay(false)?; // Back to normal - - Ok(dc) - } - - fn send_msg(&mut self, dnm: &DatNetMessage, is_content: bool) -> Result<()> { - - let header_int: u8 = (is_content as u8) << 4 | (msg_code(dnm) & 0x0F); - let msg: &Message = msg_sugar(dnm); - let total_message_size = (msg.compute_size() as usize) + 1; - - trace!("SEND total_len={} header={} is_content={} type={:?}", - total_message_size, header_int, is_content, &dnm); - - // send both header varints, and data - self.write_varint(total_message_size as u64)?; - self.write_varint(header_int as u32)?; - - match dnm { - &DatNetMessage::Register(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Handshake(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Status(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Have(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Unhave(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Want(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Unwant(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Request(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Cancel(ref m) => m.write_to_writer(self)?, - &DatNetMessage::Data(ref m) => m.write_to_writer(self)?, - } - Ok(()) - } - - fn recv_msg(&mut self) -> Result<(bool, DatNetMessage)> { - - let total_len: u64 = self.read_varint()?; - let header: u8 = self.read_varint()?; - - let is_content = (header & (1 << 4)) != 0; - - trace!("RECV total_len={} header={} is_content={}", total_len, header, is_content); - - if header > 0x1F { - bail!("Invalid header received: {}", header); - } - - let msg_len = (total_len - 1) as usize; - let mut buf = vec![0; msg_len]; - self.read_exact(&mut buf[0..msg_len])?; - - let dnm = match header & 0x0F { - 0 => DatNetMessage::Register(parse_from_bytes::(&mut buf)?), - 1 => DatNetMessage::Handshake(parse_from_bytes::(&mut buf)?), - 2 => DatNetMessage::Status(parse_from_bytes::(&mut buf)?), - 3 => DatNetMessage::Have(parse_from_bytes::(&mut buf)?), - 4 => DatNetMessage::Unhave(parse_from_bytes::(&mut buf)?), - 5 => DatNetMessage::Want(parse_from_bytes::(&mut buf)?), - 6 => DatNetMessage::Unwant(parse_from_bytes::(&mut buf)?), - 7 => DatNetMessage::Request(parse_from_bytes::(&mut buf)?), - 8 => DatNetMessage::Cancel(parse_from_bytes::(&mut buf)?), - 9 => DatNetMessage::Data(parse_from_bytes::(&mut buf)?), - other => bail!("Unimplemented message type received: {}", other), - }; - trace!("\twas: {:?}", &dnm); - Ok((is_content, dnm)) - } - - /// Special unencrypted variant of `send_msg()`, used only during initial connection - /// establishment (eg, to check metadata discovery key and exchange nonces). After the - /// connection is initialized, send Register (aka Feed) messages as normal to add extra feeds. - fn send_register(&mut self, reg: &Feed) -> Result<()> { - // TODO: refactor this to take discovery key and nonce directly - - let header_int: u8 = 0; - let total_message_size = (reg.compute_size() as usize) + 1; - - trace!("SEND total_len={} header={} msg={:?}", - total_message_size, header_int, reg); - - self.tcp.write_varint(total_message_size as u64)?; - self.tcp.write_varint(header_int as u32)?; - reg.write_to_writer(&mut self.tcp)?; - Ok(()) - } - - /// Receive complement to `send_register()`. - fn recv_register(&mut self) -> Result { - // TODO: refactor this to return discovery key and nonce directly - - let total_len: u64 = self.tcp.read_varint()?; - let header: u8 = self.tcp.read_varint()?; - - if header != 0 { - bail!("Invalid register header received"); - } - - trace!("RECV total_len={} header={}", total_len, header); - - let msg_len = (total_len - 1) as usize; - let mut buf = vec![0; msg_len]; - self.tcp.read_exact(&mut buf[0..msg_len])?; - - let reg = parse_from_bytes::(&mut buf)?; - trace!("\twas: {:?}", reg); - Ok(reg) - } - - pub fn get_data_key(&mut self) -> Result<()> { - - // Status: downloading, not uploading - let mut sm = Info::new(); - sm.set_uploading(false); - sm.set_downloading(true); - self.send_msg(&DatNetMessage::Status(sm), false)?; - - // Have: nothing (so far) - let mut hm = Have::new(); - hm.set_start(0); - hm.set_length(0); - self.send_msg(&DatNetMessage::Have(hm), false)?; - - // UnHave: still nothing - let mut uhm = Unhave::new(); - uhm.set_start(0); - self.send_msg(&DatNetMessage::Unhave(uhm), false)?; - - // Want: just the first element - let mut wm = Want::new(); - wm.set_start(0); - wm.set_length(1); - self.send_msg(&DatNetMessage::Want(wm), false)?; - - // listen for Have - loop { - let (was_content, msg) = self.recv_msg()?; - if was_content { - continue; - } - if let DatNetMessage::Have(_) = msg { - break; - } else { - info!("Expected Have message, got: {:?}", &msg); - continue; - } - }; - - // Request - let mut rm = Request::new(); - rm.set_index(0); - self.send_msg(&DatNetMessage::Request(rm), false)?; - - loop { - let (was_content, msg) = self.recv_msg()?; - if was_content { - info!("Expected other message channel"); - continue; - } - if let DatNetMessage::Data(dm) = msg { - info!("Got metadata: {}", dm.get_index()); - if dm.get_index() == 0 { - let index_msg = parse_from_bytes::(&mut dm.get_value())?; - if index_msg.get_field_type() == "hyperdrive" { - let data_key = index_msg.get_content(); - if data_key.len() != 32 { - bail!("Received data key had wrong length: {}", data_key.len()); - } - info!("Got data discovery key"); - self.data_key.copy_from_slice(&data_key[0..32]); - self.data_discovery_key.copy_from_slice(&make_discovery_key(data_key)[0..32]); - return Ok(()); - } else { - unimplemented!("non-hyperdrive Index type: {}", index_msg.get_field_type()); - } - } - } else { - info!("Expected Data message, got: {:?}", &msg); - continue; - } - } - } - - pub fn receive_all(&mut self, is_content: bool, length: u64) -> Result<()> { - - // Status: downloading, not uploading - let mut sm = Info::new(); - sm.set_uploading(false); - sm.set_downloading(true); - self.send_msg(&DatNetMessage::Status(sm), is_content)?; - - // Have: nothing (so far) - let mut hm = Have::new(); - hm.set_start(0); - hm.set_length(0); - self.send_msg(&DatNetMessage::Have(hm), is_content)?; - - // UnHave: still nothing - let mut uhm = Unhave::new(); - uhm.set_start(0); - self.send_msg(&DatNetMessage::Unhave(uhm), is_content)?; - - // Want: everything - let mut wm = Want::new(); - wm.set_start(0); - self.send_msg(&DatNetMessage::Want(wm), is_content)?; - - // Request / Data loop - for i in 0..length { - let mut rm = Request::new(); - rm.set_index(i); - self.send_msg(&DatNetMessage::Request(rm), is_content)?; - - loop { - let (was_content, msg) = self.recv_msg()?; - if was_content != is_content{ - info!("Expected other message channel"); - continue; - } - if let DatNetMessage::Data(dm) = msg { - info!("Got content: {}", dm.get_index()); - break; - } else { - info!("Expected Data message, got: {:?}", &msg); - continue; - } - } - } - - Ok(()) - } -} -- cgit v1.2.3