commit 5301123872be1d60c8d9162ce220f7dd019ba391 Author: Vladimir Komendantskiy Date: Thu Mar 15 00:03:21 2018 +0000 initial commit: elements of profobuf interface diff --git a/Cargo.toml b/Cargo.toml new file mode 100644 index 0000000..4af49ed --- /dev/null +++ b/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "hbbft" +version = "0.1.0" +authors = ["Vladimir Komendantskiy "] + +[dependencies] +log = "0.4.1" +simple_logger = "0.5" +tokio = "0.1" +tokio-io = "0.1" +tokio-timer = "0.1" +futures = "0.1" +reed-solomon-erasure = "3.0" +merkle = { git = "https://github.com/vkomenda/merkle.rs", branch = "public-proof" } +ring = "^0.12" +rand = "*" +error-chain = "0.11" +protobuf = "1.4.4" + +[build-dependencies] +protoc-rust = "1.4.4" diff --git a/README.md b/README.md new file mode 100644 index 0000000..7856b59 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Implementation of the paper "Honey Badger of BFT Protocols" in Rust + +This is a modular library of consensus. There are *going to be* +[examples](./examples/README.md) illustrating the use of this algorithm. \ No newline at end of file diff --git a/build.rs b/build.rs new file mode 100644 index 0000000..1fffcb3 --- /dev/null +++ b/build.rs @@ -0,0 +1,9 @@ +extern crate protoc_rust; + +fn main() { + protoc_rust::run(protoc_rust::Args { + out_dir: "src/proto", + input: &["proto/message.proto"], + includes: &["proto"], + }).expect("protoc"); +} diff --git a/examples/README.md b/examples/README.md new file mode 100644 index 0000000..ba7eb29 --- /dev/null +++ b/examples/README.md @@ -0,0 +1 @@ +## Examples for the hbbft library \ No newline at end of file diff --git a/proto/message.proto b/proto/message.proto new file mode 100644 index 0000000..5fc5a36 --- /dev/null +++ b/proto/message.proto @@ -0,0 +1,49 @@ +syntax = "proto3"; + +message MessageProto { + oneof payload { + BroadcastProto broadcast = 1; + AgreementProto agreement = 2; + } +} + +message BroadcastProto { + oneof payload { + ValueProto value = 1; + EchoProto echo = 2; + ReadyProto ready = 3; + } +} + +message ValueProto { + ProofProto proof = 1; +} + +message EchoProto { + ProofProto proof = 1; +} + +message ReadyProto { + bytes root_hash = 1; +} + +message ProofProto { + bytes root_hash = 1; + LemmaProto lemma = 2; + bytes value = 3; +} + +message LemmaProto { + bytes node_hash = 1; + LemmaProto sub_lemma = 2; + + oneof sibling_hash { + bytes left_sibling_hash = 3; + bytes right_sibling_hash = 4; + } + +} + +message AgreementProto { + // TODO +} \ No newline at end of file diff --git a/src/agreement/mod.rs b/src/agreement/mod.rs new file mode 100644 index 0000000..85807d9 --- /dev/null +++ b/src/agreement/mod.rs @@ -0,0 +1,4 @@ +//! Binary Byzantine agreement protocol from a common coin protocol. + +use futures::{Future, Stream}; +use futures::future::*; diff --git a/src/broadcast/mod.rs b/src/broadcast/mod.rs new file mode 100644 index 0000000..5daf12c --- /dev/null +++ b/src/broadcast/mod.rs @@ -0,0 +1,69 @@ +//! Reliable broadcast algorithm. +use std::collections::{HashMap, HashSet}; +use std::net::{TcpStream, TcpListener, SocketAddr}; +use errors::ResultExt; +use task::{Error, MessageLoop, Task}; +use proto::message::{MessageProto, ValueProto, EchoProto, ReadyProto}; +use merkle::*; + +/// A broadcast task is an instance of `Task`, a message-handling task with a +/// main loop. +pub struct BroadcastTask { + /// The underlying task that handles sending and receiving messages. + task: Task, + /// Messages of type Value received so far, keyed with the root hash for + /// easy access. + values: HashMap, Proof>, + /// Messages of type Echo received so far, keyed with the root hash for + /// easy access. + echos: HashMap, Proof>, + /// Messages of type Ready received so far. That is, the root hashes in + /// those messages. + readys: HashSet> +} + +impl BroadcastTask { + pub fn new(stream: TcpStream) -> Self { + BroadcastTask { + task: Task::new(stream), + values: Default::default(), + echos: Default::default(), + readys: Default::default() + } + } +} + +impl MessageLoop for BroadcastTask { + fn run(&mut self) { + loop { + match self.task.receive_message() { + Ok(message) => self.on_message_received(message).unwrap(), + Err(Error::ProtobufError(e)) => warn!("Protobuf error {}", e), + Err(e) => { + warn!("Critical error {:?}", e); + break; + } + } + } + } + + fn on_message_received(&mut self, message: MessageProto) -> Result<(), Error> { + if message.has_broadcast() { + let broadcast = message.get_broadcast(); + if broadcast.has_value() { + let value = broadcast.get_value(); + } + else if broadcast.has_echo() { + let echo = broadcast.get_echo(); + } + else if broadcast.has_ready() { + let ready = broadcast.get_ready(); + } + return Ok(()); + } + else { + warn!("Unexpected message type"); + return Err(Error::ProtocolError); + } + } +} diff --git a/src/errors.rs b/src/errors.rs new file mode 100644 index 0000000..4dd1f31 --- /dev/null +++ b/src/errors.rs @@ -0,0 +1,4 @@ +//! Template-assisted definition of the crate's error strategy. + +error_chain! { +} diff --git a/src/lib.rs b/src/lib.rs new file mode 100644 index 0000000..92f9d86 --- /dev/null +++ b/src/lib.rs @@ -0,0 +1,15 @@ +#[macro_use] +extern crate error_chain; +#[macro_use] +extern crate log; +extern crate protobuf; +extern crate ring; +extern crate merkle; +extern crate futures; + +mod errors; +mod proto; +mod task; + +pub mod broadcast; +pub mod agreement; diff --git a/src/proto/message.rs b/src/proto/message.rs new file mode 100644 index 0000000..ef8ddf6 --- /dev/null +++ b/src/proto/message.rs @@ -0,0 +1,2082 @@ +// 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 MessageProto { + // message oneof groups + payload: ::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 MessageProto {} + +#[derive(Clone,PartialEq)] +pub enum MessageProto_oneof_payload { + broadcast(BroadcastProto), + agreement(AgreementProto), +} + +impl MessageProto { + pub fn new() -> MessageProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static MessageProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const MessageProto, + }; + unsafe { + instance.get(MessageProto::new) + } + } + + // .BroadcastProto broadcast = 1; + + pub fn clear_broadcast(&mut self) { + self.payload = ::std::option::Option::None; + } + + pub fn has_broadcast(&self) -> bool { + match self.payload { + ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_broadcast(&mut self, v: BroadcastProto) { + self.payload = ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(v)) + } + + // Mutable pointer to the field. + pub fn mut_broadcast(&mut self) -> &mut BroadcastProto { + if let ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(_)) = self.payload { + } else { + self.payload = ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(BroadcastProto::new())); + } + match self.payload { + ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_broadcast(&mut self) -> BroadcastProto { + if self.has_broadcast() { + match self.payload.take() { + ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(v)) => v, + _ => panic!(), + } + } else { + BroadcastProto::new() + } + } + + pub fn get_broadcast(&self) -> &BroadcastProto { + match self.payload { + ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(ref v)) => v, + _ => BroadcastProto::default_instance(), + } + } + + // .AgreementProto agreement = 2; + + pub fn clear_agreement(&mut self) { + self.payload = ::std::option::Option::None; + } + + pub fn has_agreement(&self) -> bool { + match self.payload { + ::std::option::Option::Some(MessageProto_oneof_payload::agreement(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_agreement(&mut self, v: AgreementProto) { + self.payload = ::std::option::Option::Some(MessageProto_oneof_payload::agreement(v)) + } + + // Mutable pointer to the field. + pub fn mut_agreement(&mut self) -> &mut AgreementProto { + if let ::std::option::Option::Some(MessageProto_oneof_payload::agreement(_)) = self.payload { + } else { + self.payload = ::std::option::Option::Some(MessageProto_oneof_payload::agreement(AgreementProto::new())); + } + match self.payload { + ::std::option::Option::Some(MessageProto_oneof_payload::agreement(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_agreement(&mut self) -> AgreementProto { + if self.has_agreement() { + match self.payload.take() { + ::std::option::Option::Some(MessageProto_oneof_payload::agreement(v)) => v, + _ => panic!(), + } + } else { + AgreementProto::new() + } + } + + pub fn get_agreement(&self) -> &AgreementProto { + match self.payload { + ::std::option::Option::Some(MessageProto_oneof_payload::agreement(ref v)) => v, + _ => AgreementProto::default_instance(), + } + } +} + +impl ::protobuf::Message for MessageProto { + fn is_initialized(&self) -> bool { + if let Some(MessageProto_oneof_payload::broadcast(ref v)) = self.payload { + if !v.is_initialized() { + return false; + } + } + if let Some(MessageProto_oneof_payload::agreement(ref v)) = self.payload { + if !v.is_initialized() { + return false; + } + } + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.payload = ::std::option::Option::Some(MessageProto_oneof_payload::broadcast(is.read_message()?)); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.payload = ::std::option::Option::Some(MessageProto_oneof_payload::agreement(is.read_message()?)); + }, + _ => { + ::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 ::std::option::Option::Some(ref v) = self.payload { + match v { + &MessageProto_oneof_payload::broadcast(ref v) => { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }, + &MessageProto_oneof_payload::agreement(ref v) => { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }, + }; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if let ::std::option::Option::Some(ref v) = self.payload { + match v { + &MessageProto_oneof_payload::broadcast(ref v) => { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }, + &MessageProto_oneof_payload::agreement(ref v) => { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }, + }; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any + } + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for MessageProto { + fn new() -> MessageProto { + MessageProto::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_message_accessor::<_, BroadcastProto>( + "broadcast", + MessageProto::has_broadcast, + MessageProto::get_broadcast, + )); + fields.push(::protobuf::reflect::accessor::make_singular_message_accessor::<_, AgreementProto>( + "agreement", + MessageProto::has_agreement, + MessageProto::get_agreement, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "MessageProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for MessageProto { + fn clear(&mut self) { + self.clear_broadcast(); + self.clear_agreement(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for MessageProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for MessageProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct BroadcastProto { + // message oneof groups + payload: ::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 BroadcastProto {} + +#[derive(Clone,PartialEq)] +pub enum BroadcastProto_oneof_payload { + value(ValueProto), + echo(EchoProto), + ready(ReadyProto), +} + +impl BroadcastProto { + pub fn new() -> BroadcastProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static BroadcastProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const BroadcastProto, + }; + unsafe { + instance.get(BroadcastProto::new) + } + } + + // .ValueProto value = 1; + + pub fn clear_value(&mut self) { + self.payload = ::std::option::Option::None; + } + + pub fn has_value(&self) -> bool { + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::value(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: ValueProto) { + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::value(v)) + } + + // Mutable pointer to the field. + pub fn mut_value(&mut self) -> &mut ValueProto { + if let ::std::option::Option::Some(BroadcastProto_oneof_payload::value(_)) = self.payload { + } else { + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::value(ValueProto::new())); + } + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::value(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_value(&mut self) -> ValueProto { + if self.has_value() { + match self.payload.take() { + ::std::option::Option::Some(BroadcastProto_oneof_payload::value(v)) => v, + _ => panic!(), + } + } else { + ValueProto::new() + } + } + + pub fn get_value(&self) -> &ValueProto { + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::value(ref v)) => v, + _ => ValueProto::default_instance(), + } + } + + // .EchoProto echo = 2; + + pub fn clear_echo(&mut self) { + self.payload = ::std::option::Option::None; + } + + pub fn has_echo(&self) -> bool { + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_echo(&mut self, v: EchoProto) { + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(v)) + } + + // Mutable pointer to the field. + pub fn mut_echo(&mut self) -> &mut EchoProto { + if let ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(_)) = self.payload { + } else { + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(EchoProto::new())); + } + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_echo(&mut self) -> EchoProto { + if self.has_echo() { + match self.payload.take() { + ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(v)) => v, + _ => panic!(), + } + } else { + EchoProto::new() + } + } + + pub fn get_echo(&self) -> &EchoProto { + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(ref v)) => v, + _ => EchoProto::default_instance(), + } + } + + // .ReadyProto ready = 3; + + pub fn clear_ready(&mut self) { + self.payload = ::std::option::Option::None; + } + + pub fn has_ready(&self) -> bool { + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_ready(&mut self, v: ReadyProto) { + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(v)) + } + + // Mutable pointer to the field. + pub fn mut_ready(&mut self) -> &mut ReadyProto { + if let ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(_)) = self.payload { + } else { + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(ReadyProto::new())); + } + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_ready(&mut self) -> ReadyProto { + if self.has_ready() { + match self.payload.take() { + ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(v)) => v, + _ => panic!(), + } + } else { + ReadyProto::new() + } + } + + pub fn get_ready(&self) -> &ReadyProto { + match self.payload { + ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(ref v)) => v, + _ => ReadyProto::default_instance(), + } + } +} + +impl ::protobuf::Message for BroadcastProto { + fn is_initialized(&self) -> bool { + if let Some(BroadcastProto_oneof_payload::value(ref v)) = self.payload { + if !v.is_initialized() { + return false; + } + } + if let Some(BroadcastProto_oneof_payload::echo(ref v)) = self.payload { + if !v.is_initialized() { + return false; + } + } + if let Some(BroadcastProto_oneof_payload::ready(ref v)) = self.payload { + if !v.is_initialized() { + return false; + } + } + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::value(is.read_message()?)); + }, + 2 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::echo(is.read_message()?)); + }, + 3 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.payload = ::std::option::Option::Some(BroadcastProto_oneof_payload::ready(is.read_message()?)); + }, + _ => { + ::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 ::std::option::Option::Some(ref v) = self.payload { + match v { + &BroadcastProto_oneof_payload::value(ref v) => { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }, + &BroadcastProto_oneof_payload::echo(ref v) => { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }, + &BroadcastProto_oneof_payload::ready(ref v) => { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + }, + }; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if let ::std::option::Option::Some(ref v) = self.payload { + match v { + &BroadcastProto_oneof_payload::value(ref v) => { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }, + &BroadcastProto_oneof_payload::echo(ref v) => { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }, + &BroadcastProto_oneof_payload::ready(ref v) => { + os.write_tag(3, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + }, + }; + } + os.write_unknown_fields(self.get_unknown_fields())?; + ::std::result::Result::Ok(()) + } + + fn get_cached_size(&self) -> u32 { + self.cached_size.get() + } + + fn get_unknown_fields(&self) -> &::protobuf::UnknownFields { + &self.unknown_fields + } + + fn mut_unknown_fields(&mut self) -> &mut ::protobuf::UnknownFields { + &mut self.unknown_fields + } + + fn as_any(&self) -> &::std::any::Any { + self as &::std::any::Any + } + fn as_any_mut(&mut self) -> &mut ::std::any::Any { + self as &mut ::std::any::Any + } + fn into_any(self: Box) -> ::std::boxed::Box<::std::any::Any> { + self + } + + fn descriptor(&self) -> &'static ::protobuf::reflect::MessageDescriptor { + ::protobuf::MessageStatic::descriptor_static(None::) + } +} + +impl ::protobuf::MessageStatic for BroadcastProto { + fn new() -> BroadcastProto { + BroadcastProto::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_message_accessor::<_, ValueProto>( + "value", + BroadcastProto::has_value, + BroadcastProto::get_value, + )); + fields.push(::protobuf::reflect::accessor::make_singular_message_accessor::<_, EchoProto>( + "echo", + BroadcastProto::has_echo, + BroadcastProto::get_echo, + )); + fields.push(::protobuf::reflect::accessor::make_singular_message_accessor::<_, ReadyProto>( + "ready", + BroadcastProto::has_ready, + BroadcastProto::get_ready, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "BroadcastProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for BroadcastProto { + fn clear(&mut self) { + self.clear_value(); + self.clear_echo(); + self.clear_ready(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for BroadcastProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for BroadcastProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct ValueProto { + // message fields + pub proof: ::protobuf::SingularPtrField, + // 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 ValueProto {} + +impl ValueProto { + pub fn new() -> ValueProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static ValueProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ValueProto, + }; + unsafe { + instance.get(ValueProto::new) + } + } + + // .ProofProto proof = 1; + + pub fn clear_proof(&mut self) { + self.proof.clear(); + } + + pub fn has_proof(&self) -> bool { + self.proof.is_some() + } + + // Param is passed by value, moved + pub fn set_proof(&mut self, v: ProofProto) { + self.proof = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_proof(&mut self) -> &mut ProofProto { + if self.proof.is_none() { + self.proof.set_default(); + } + self.proof.as_mut().unwrap() + } + + // Take field + pub fn take_proof(&mut self) -> ProofProto { + self.proof.take().unwrap_or_else(|| ProofProto::new()) + } + + pub fn get_proof(&self) -> &ProofProto { + self.proof.as_ref().unwrap_or_else(|| ProofProto::default_instance()) + } + + fn get_proof_for_reflect(&self) -> &::protobuf::SingularPtrField { + &self.proof + } + + fn mut_proof_for_reflect(&mut self) -> &mut ::protobuf::SingularPtrField { + &mut self.proof + } +} + +impl ::protobuf::Message for ValueProto { + fn is_initialized(&self) -> bool { + for v in &self.proof { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.proof)?; + }, + _ => { + ::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.proof.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if let Some(ref v) = self.proof.as_ref() { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + 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 ValueProto { + fn new() -> ValueProto { + ValueProto::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_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "proof", + ValueProto::get_proof_for_reflect, + ValueProto::mut_proof_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "ValueProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for ValueProto { + fn clear(&mut self) { + self.clear_proof(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for ValueProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for ValueProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct EchoProto { + // message fields + pub proof: ::protobuf::SingularPtrField, + // 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 EchoProto {} + +impl EchoProto { + pub fn new() -> EchoProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static EchoProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const EchoProto, + }; + unsafe { + instance.get(EchoProto::new) + } + } + + // .ProofProto proof = 1; + + pub fn clear_proof(&mut self) { + self.proof.clear(); + } + + pub fn has_proof(&self) -> bool { + self.proof.is_some() + } + + // Param is passed by value, moved + pub fn set_proof(&mut self, v: ProofProto) { + self.proof = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_proof(&mut self) -> &mut ProofProto { + if self.proof.is_none() { + self.proof.set_default(); + } + self.proof.as_mut().unwrap() + } + + // Take field + pub fn take_proof(&mut self) -> ProofProto { + self.proof.take().unwrap_or_else(|| ProofProto::new()) + } + + pub fn get_proof(&self) -> &ProofProto { + self.proof.as_ref().unwrap_or_else(|| ProofProto::default_instance()) + } + + fn get_proof_for_reflect(&self) -> &::protobuf::SingularPtrField { + &self.proof + } + + fn mut_proof_for_reflect(&mut self) -> &mut ::protobuf::SingularPtrField { + &mut self.proof + } +} + +impl ::protobuf::Message for EchoProto { + fn is_initialized(&self) -> bool { + for v in &self.proof { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.proof)?; + }, + _ => { + ::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.proof.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if let Some(ref v) = self.proof.as_ref() { + os.write_tag(1, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + 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 EchoProto { + fn new() -> EchoProto { + EchoProto::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_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "proof", + EchoProto::get_proof_for_reflect, + EchoProto::mut_proof_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "EchoProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for EchoProto { + fn clear(&mut self) { + self.clear_proof(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for EchoProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for EchoProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct ReadyProto { + // message fields + pub root_hash: ::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 ReadyProto {} + +impl ReadyProto { + pub fn new() -> ReadyProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static ReadyProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ReadyProto, + }; + unsafe { + instance.get(ReadyProto::new) + } + } + + // bytes root_hash = 1; + + pub fn clear_root_hash(&mut self) { + self.root_hash.clear(); + } + + // Param is passed by value, moved + pub fn set_root_hash(&mut self, v: ::std::vec::Vec) { + self.root_hash = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_root_hash(&mut self) -> &mut ::std::vec::Vec { + &mut self.root_hash + } + + // Take field + pub fn take_root_hash(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.root_hash, ::std::vec::Vec::new()) + } + + pub fn get_root_hash(&self) -> &[u8] { + &self.root_hash + } + + fn get_root_hash_for_reflect(&self) -> &::std::vec::Vec { + &self.root_hash + } + + fn mut_root_hash_for_reflect(&mut self) -> &mut ::std::vec::Vec { + &mut self.root_hash + } +} + +impl ::protobuf::Message for ReadyProto { + fn is_initialized(&self) -> bool { + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.root_hash)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.root_hash.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.root_hash); + } + my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields()); + self.cached_size.set(my_size); + my_size + } + + fn write_to_with_cached_sizes(&self, os: &mut ::protobuf::CodedOutputStream) -> ::protobuf::ProtobufResult<()> { + if !self.root_hash.is_empty() { + os.write_bytes(1, &self.root_hash)?; + } + 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 ReadyProto { + fn new() -> ReadyProto { + ReadyProto::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_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "root_hash", + ReadyProto::get_root_hash_for_reflect, + ReadyProto::mut_root_hash_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "ReadyProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for ReadyProto { + fn clear(&mut self) { + self.clear_root_hash(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for ReadyProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for ReadyProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct ProofProto { + // message fields + pub root_hash: ::std::vec::Vec, + pub lemma: ::protobuf::SingularPtrField, + pub value: ::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 ProofProto {} + +impl ProofProto { + pub fn new() -> ProofProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static ProofProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ProofProto, + }; + unsafe { + instance.get(ProofProto::new) + } + } + + // bytes root_hash = 1; + + pub fn clear_root_hash(&mut self) { + self.root_hash.clear(); + } + + // Param is passed by value, moved + pub fn set_root_hash(&mut self, v: ::std::vec::Vec) { + self.root_hash = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_root_hash(&mut self) -> &mut ::std::vec::Vec { + &mut self.root_hash + } + + // Take field + pub fn take_root_hash(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.root_hash, ::std::vec::Vec::new()) + } + + pub fn get_root_hash(&self) -> &[u8] { + &self.root_hash + } + + fn get_root_hash_for_reflect(&self) -> &::std::vec::Vec { + &self.root_hash + } + + fn mut_root_hash_for_reflect(&mut self) -> &mut ::std::vec::Vec { + &mut self.root_hash + } + + // .LemmaProto lemma = 2; + + pub fn clear_lemma(&mut self) { + self.lemma.clear(); + } + + pub fn has_lemma(&self) -> bool { + self.lemma.is_some() + } + + // Param is passed by value, moved + pub fn set_lemma(&mut self, v: LemmaProto) { + self.lemma = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_lemma(&mut self) -> &mut LemmaProto { + if self.lemma.is_none() { + self.lemma.set_default(); + } + self.lemma.as_mut().unwrap() + } + + // Take field + pub fn take_lemma(&mut self) -> LemmaProto { + self.lemma.take().unwrap_or_else(|| LemmaProto::new()) + } + + pub fn get_lemma(&self) -> &LemmaProto { + self.lemma.as_ref().unwrap_or_else(|| LemmaProto::default_instance()) + } + + fn get_lemma_for_reflect(&self) -> &::protobuf::SingularPtrField { + &self.lemma + } + + fn mut_lemma_for_reflect(&mut self) -> &mut ::protobuf::SingularPtrField { + &mut self.lemma + } + + // bytes value = 3; + + pub fn clear_value(&mut self) { + self.value.clear(); + } + + // Param is passed by value, moved + pub fn set_value(&mut self, v: ::std::vec::Vec) { + self.value = 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 { + &mut self.value + } + + // Take field + pub fn take_value(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.value, ::std::vec::Vec::new()) + } + + pub fn get_value(&self) -> &[u8] { + &self.value + } + + fn get_value_for_reflect(&self) -> &::std::vec::Vec { + &self.value + } + + fn mut_value_for_reflect(&mut self) -> &mut ::std::vec::Vec { + &mut self.value + } +} + +impl ::protobuf::Message for ProofProto { + fn is_initialized(&self) -> bool { + for v in &self.lemma { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.root_hash)?; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.lemma)?; + }, + 3 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.value)?; + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.root_hash.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.root_hash); + } + if let Some(ref v) = self.lemma.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + if !self.value.is_empty() { + my_size += ::protobuf::rt::bytes_size(3, &self.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 !self.root_hash.is_empty() { + os.write_bytes(1, &self.root_hash)?; + } + if let Some(ref v) = self.lemma.as_ref() { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + if !self.value.is_empty() { + os.write_bytes(3, &self.value)?; + } + 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 ProofProto { + fn new() -> ProofProto { + ProofProto::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_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "root_hash", + ProofProto::get_root_hash_for_reflect, + ProofProto::mut_root_hash_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "lemma", + ProofProto::get_lemma_for_reflect, + ProofProto::mut_lemma_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "value", + ProofProto::get_value_for_reflect, + ProofProto::mut_value_for_reflect, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "ProofProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for ProofProto { + fn clear(&mut self) { + self.clear_root_hash(); + self.clear_lemma(); + self.clear_value(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for ProofProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for ProofProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct LemmaProto { + // message fields + pub node_hash: ::std::vec::Vec, + pub sub_lemma: ::protobuf::SingularPtrField, + // message oneof groups + sibling_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 LemmaProto {} + +#[derive(Clone,PartialEq)] +pub enum LemmaProto_oneof_sibling_hash { + left_sibling_hash(::std::vec::Vec), + right_sibling_hash(::std::vec::Vec), +} + +impl LemmaProto { + pub fn new() -> LemmaProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static LemmaProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const LemmaProto, + }; + unsafe { + instance.get(LemmaProto::new) + } + } + + // bytes node_hash = 1; + + pub fn clear_node_hash(&mut self) { + self.node_hash.clear(); + } + + // Param is passed by value, moved + pub fn set_node_hash(&mut self, v: ::std::vec::Vec) { + self.node_hash = v; + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_node_hash(&mut self) -> &mut ::std::vec::Vec { + &mut self.node_hash + } + + // Take field + pub fn take_node_hash(&mut self) -> ::std::vec::Vec { + ::std::mem::replace(&mut self.node_hash, ::std::vec::Vec::new()) + } + + pub fn get_node_hash(&self) -> &[u8] { + &self.node_hash + } + + fn get_node_hash_for_reflect(&self) -> &::std::vec::Vec { + &self.node_hash + } + + fn mut_node_hash_for_reflect(&mut self) -> &mut ::std::vec::Vec { + &mut self.node_hash + } + + // .LemmaProto sub_lemma = 2; + + pub fn clear_sub_lemma(&mut self) { + self.sub_lemma.clear(); + } + + pub fn has_sub_lemma(&self) -> bool { + self.sub_lemma.is_some() + } + + // Param is passed by value, moved + pub fn set_sub_lemma(&mut self, v: LemmaProto) { + self.sub_lemma = ::protobuf::SingularPtrField::some(v); + } + + // Mutable pointer to the field. + // If field is not initialized, it is initialized with default value first. + pub fn mut_sub_lemma(&mut self) -> &mut LemmaProto { + if self.sub_lemma.is_none() { + self.sub_lemma.set_default(); + } + self.sub_lemma.as_mut().unwrap() + } + + // Take field + pub fn take_sub_lemma(&mut self) -> LemmaProto { + self.sub_lemma.take().unwrap_or_else(|| LemmaProto::new()) + } + + pub fn get_sub_lemma(&self) -> &LemmaProto { + self.sub_lemma.as_ref().unwrap_or_else(|| LemmaProto::default_instance()) + } + + fn get_sub_lemma_for_reflect(&self) -> &::protobuf::SingularPtrField { + &self.sub_lemma + } + + fn mut_sub_lemma_for_reflect(&mut self) -> &mut ::protobuf::SingularPtrField { + &mut self.sub_lemma + } + + // bytes left_sibling_hash = 3; + + pub fn clear_left_sibling_hash(&mut self) { + self.sibling_hash = ::std::option::Option::None; + } + + pub fn has_left_sibling_hash(&self) -> bool { + match self.sibling_hash { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_left_sibling_hash(&mut self, v: ::std::vec::Vec) { + self.sibling_hash = ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(v)) + } + + // Mutable pointer to the field. + pub fn mut_left_sibling_hash(&mut self) -> &mut ::std::vec::Vec { + if let ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(_)) = self.sibling_hash { + } else { + self.sibling_hash = ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(::std::vec::Vec::new())); + } + match self.sibling_hash { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_left_sibling_hash(&mut self) -> ::std::vec::Vec { + if self.has_left_sibling_hash() { + match self.sibling_hash.take() { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(v)) => v, + _ => panic!(), + } + } else { + ::std::vec::Vec::new() + } + } + + pub fn get_left_sibling_hash(&self) -> &[u8] { + match self.sibling_hash { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(ref v)) => v, + _ => &[], + } + } + + // bytes right_sibling_hash = 4; + + pub fn clear_right_sibling_hash(&mut self) { + self.sibling_hash = ::std::option::Option::None; + } + + pub fn has_right_sibling_hash(&self) -> bool { + match self.sibling_hash { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(..)) => true, + _ => false, + } + } + + // Param is passed by value, moved + pub fn set_right_sibling_hash(&mut self, v: ::std::vec::Vec) { + self.sibling_hash = ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(v)) + } + + // Mutable pointer to the field. + pub fn mut_right_sibling_hash(&mut self) -> &mut ::std::vec::Vec { + if let ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(_)) = self.sibling_hash { + } else { + self.sibling_hash = ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(::std::vec::Vec::new())); + } + match self.sibling_hash { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(ref mut v)) => v, + _ => panic!(), + } + } + + // Take field + pub fn take_right_sibling_hash(&mut self) -> ::std::vec::Vec { + if self.has_right_sibling_hash() { + match self.sibling_hash.take() { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(v)) => v, + _ => panic!(), + } + } else { + ::std::vec::Vec::new() + } + } + + pub fn get_right_sibling_hash(&self) -> &[u8] { + match self.sibling_hash { + ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(ref v)) => v, + _ => &[], + } + } +} + +impl ::protobuf::Message for LemmaProto { + fn is_initialized(&self) -> bool { + for v in &self.sub_lemma { + if !v.is_initialized() { + return false; + } + }; + true + } + + fn merge_from(&mut self, is: &mut ::protobuf::CodedInputStream) -> ::protobuf::ProtobufResult<()> { + while !is.eof()? { + let (field_number, wire_type) = is.read_tag_unpack()?; + match field_number { + 1 => { + ::protobuf::rt::read_singular_proto3_bytes_into(wire_type, is, &mut self.node_hash)?; + }, + 2 => { + ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.sub_lemma)?; + }, + 3 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.sibling_hash = ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::left_sibling_hash(is.read_bytes()?)); + }, + 4 => { + if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited { + return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type)); + } + self.sibling_hash = ::std::option::Option::Some(LemmaProto_oneof_sibling_hash::right_sibling_hash(is.read_bytes()?)); + }, + _ => { + ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?; + }, + }; + } + ::std::result::Result::Ok(()) + } + + // Compute sizes of nested messages + #[allow(unused_variables)] + fn compute_size(&self) -> u32 { + let mut my_size = 0; + if !self.node_hash.is_empty() { + my_size += ::protobuf::rt::bytes_size(1, &self.node_hash); + } + if let Some(ref v) = self.sub_lemma.as_ref() { + let len = v.compute_size(); + my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len; + } + if let ::std::option::Option::Some(ref v) = self.sibling_hash { + match v { + &LemmaProto_oneof_sibling_hash::left_sibling_hash(ref v) => { + my_size += ::protobuf::rt::bytes_size(3, &v); + }, + &LemmaProto_oneof_sibling_hash::right_sibling_hash(ref v) => { + 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 !self.node_hash.is_empty() { + os.write_bytes(1, &self.node_hash)?; + } + if let Some(ref v) = self.sub_lemma.as_ref() { + os.write_tag(2, ::protobuf::wire_format::WireTypeLengthDelimited)?; + os.write_raw_varint32(v.get_cached_size())?; + v.write_to_with_cached_sizes(os)?; + } + if let ::std::option::Option::Some(ref v) = self.sibling_hash { + match v { + &LemmaProto_oneof_sibling_hash::left_sibling_hash(ref v) => { + os.write_bytes(3, v)?; + }, + &LemmaProto_oneof_sibling_hash::right_sibling_hash(ref v) => { + 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 LemmaProto { + fn new() -> LemmaProto { + LemmaProto::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_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeBytes>( + "node_hash", + LemmaProto::get_node_hash_for_reflect, + LemmaProto::mut_node_hash_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_ptr_field_accessor::<_, ::protobuf::types::ProtobufTypeMessage>( + "sub_lemma", + LemmaProto::get_sub_lemma_for_reflect, + LemmaProto::mut_sub_lemma_for_reflect, + )); + fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor::<_>( + "left_sibling_hash", + LemmaProto::has_left_sibling_hash, + LemmaProto::get_left_sibling_hash, + )); + fields.push(::protobuf::reflect::accessor::make_singular_bytes_accessor::<_>( + "right_sibling_hash", + LemmaProto::has_right_sibling_hash, + LemmaProto::get_right_sibling_hash, + )); + ::protobuf::reflect::MessageDescriptor::new::( + "LemmaProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for LemmaProto { + fn clear(&mut self) { + self.clear_node_hash(); + self.clear_sub_lemma(); + self.clear_left_sibling_hash(); + self.clear_right_sibling_hash(); + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for LemmaProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for LemmaProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +#[derive(PartialEq,Clone,Default)] +pub struct AgreementProto { + // 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 AgreementProto {} + +impl AgreementProto { + pub fn new() -> AgreementProto { + ::std::default::Default::default() + } + + pub fn default_instance() -> &'static AgreementProto { + static mut instance: ::protobuf::lazy::Lazy = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const AgreementProto, + }; + unsafe { + instance.get(AgreementProto::new) + } + } +} + +impl ::protobuf::Message for AgreementProto { + 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 { + _ => { + ::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; + 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<()> { + 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 AgreementProto { + fn new() -> AgreementProto { + AgreementProto::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 fields = ::std::vec::Vec::new(); + ::protobuf::reflect::MessageDescriptor::new::( + "AgreementProto", + fields, + file_descriptor_proto() + ) + }) + } + } +} + +impl ::protobuf::Clear for AgreementProto { + fn clear(&mut self) { + self.unknown_fields.clear(); + } +} + +impl ::std::fmt::Debug for AgreementProto { + fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { + ::protobuf::text_format::fmt(self, f) + } +} + +impl ::protobuf::reflect::ProtobufValue for AgreementProto { + fn as_ref(&self) -> ::protobuf::reflect::ProtobufValueRef { + ::protobuf::reflect::ProtobufValueRef::Message(self) + } +} + +static file_descriptor_proto_data: &'static [u8] = b"\ + \n\rmessage.proto\"{\n\x0cMessageProto\x12/\n\tbroadcast\x18\x01\x20\x01\ + (\x0b2\x0f.BroadcastProtoH\0R\tbroadcast\x12/\n\tagreement\x18\x02\x20\ + \x01(\x0b2\x0f.AgreementProtoH\0R\tagreementB\t\n\x07payload\"\x87\x01\n\ + \x0eBroadcastProto\x12#\n\x05value\x18\x01\x20\x01(\x0b2\x0b.ValueProtoH\ + \0R\x05value\x12\x20\n\x04echo\x18\x02\x20\x01(\x0b2\n.EchoProtoH\0R\x04\ + echo\x12#\n\x05ready\x18\x03\x20\x01(\x0b2\x0b.ReadyProtoH\0R\x05readyB\ + \t\n\x07payload\"/\n\nValueProto\x12!\n\x05proof\x18\x01\x20\x01(\x0b2\ + \x0b.ProofProtoR\x05proof\".\n\tEchoProto\x12!\n\x05proof\x18\x01\x20\ + \x01(\x0b2\x0b.ProofProtoR\x05proof\")\n\nReadyProto\x12\x1b\n\troot_has\ + h\x18\x01\x20\x01(\x0cR\x08rootHash\"b\n\nProofProto\x12\x1b\n\troot_has\ + h\x18\x01\x20\x01(\x0cR\x08rootHash\x12!\n\x05lemma\x18\x02\x20\x01(\x0b\ + 2\x0b.LemmaProtoR\x05lemma\x12\x14\n\x05value\x18\x03\x20\x01(\x0cR\x05v\ + alue\"\xc1\x01\n\nLemmaProto\x12\x1b\n\tnode_hash\x18\x01\x20\x01(\x0cR\ + \x08nodeHash\x12(\n\tsub_lemma\x18\x02\x20\x01(\x0b2\x0b.LemmaProtoR\x08\ + subLemma\x12,\n\x11left_sibling_hash\x18\x03\x20\x01(\x0cH\0R\x0fleftSib\ + lingHash\x12.\n\x12right_sibling_hash\x18\x04\x20\x01(\x0cH\0R\x10rightS\ + iblingHashB\x0e\n\x0csibling_hash\"\x10\n\x0eAgreementProtob\x06proto3\ +"; + +static mut file_descriptor_proto_lazy: ::protobuf::lazy::Lazy<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::lazy::Lazy { + lock: ::protobuf::lazy::ONCE_INIT, + ptr: 0 as *const ::protobuf::descriptor::FileDescriptorProto, +}; + +fn parse_descriptor_proto() -> ::protobuf::descriptor::FileDescriptorProto { + ::protobuf::parse_from_bytes(file_descriptor_proto_data).unwrap() +} + +pub fn file_descriptor_proto() -> &'static ::protobuf::descriptor::FileDescriptorProto { + unsafe { + file_descriptor_proto_lazy.get(|| { + parse_descriptor_proto() + }) + } +} diff --git a/src/proto/mod.rs b/src/proto/mod.rs new file mode 100644 index 0000000..9ac3fc6 --- /dev/null +++ b/src/proto/mod.rs @@ -0,0 +1,126 @@ +//! Construction of messages from protobuf buffers. +pub mod message; + +use ring::digest::Algorithm; +use merkle::proof::{Proof, Lemma, Positioned}; +//use protobuf::Message; +use self::message::*; +use protobuf::error::ProtobufResult; +use protobuf::core::parse_from_bytes; + +/// Kinds of message sent by nodes participating in consensus. +enum Message { + Broadcast(BroadcastMessage), + Agreement(AgreementMessage) +} + +/// The three kinds of message sent during the reliable broadcast stage of the +/// consensus algorithm. +enum BroadcastMessage { + Value(Proof), + Echo(Proof), + Ready(Vec) +} + +/// Messages sent during the binary Byzantine agreement stage. +enum AgreementMessage { + // TODO + Phantom(T) +} + +impl Message { + pub fn from_protobuf(algorithm: &'static Algorithm, + mut proto: message::MessageProto) -> Option + where T: From>, + { + if proto.has_broadcast() { + proto.take_broadcast().into_broadcast(algorithm) + .map(|b| Message::Broadcast(b)) + } + else { + // TODO + None + } + } +} + +impl BroadcastProto { + pub fn into_broadcast(mut self, + algorithm: &'static Algorithm) + -> Option> + where T: From>, + { + if self.has_value() { + self.take_value().take_proof().into_proof(algorithm) + .map(|p| BroadcastMessage::Value(p)) + } + else if self.has_echo() { + self.take_echo().take_proof().into_proof(algorithm) + .map(|p| BroadcastMessage::Echo(p)) + } + else if self.has_ready() { + let h = self.take_ready().take_root_hash(); + Some(BroadcastMessage::Ready(h)) + } + else { + None + } + } +} + +impl ProofProto { + pub fn into_proof(mut self, + algorithm: &'static Algorithm) + -> Option> + where T: From> + { + if !self.has_lemma() { + return None; + } + + self.take_lemma().into_lemma().map(|lemma| { + Proof::new( + algorithm, + self.take_root_hash(), + lemma, + self.take_value().into(), + ) + }) + } +} + +impl LemmaProto { + pub fn into_lemma(mut self) -> Option { + let node_hash = self.take_node_hash(); + + let sibling_hash = if self.has_left_sibling_hash() { + Some(Positioned::Left(self.take_left_sibling_hash())) + } else if self.has_right_sibling_hash() { + Some(Positioned::Right(self.take_right_sibling_hash())) + } else { + None + }; + + if self.has_sub_lemma() { + // If a `sub_lemma` is present is the Protobuf, + // then we expect it to unserialize to a valid `Lemma`, + // otherwise we return `None` + self.take_sub_lemma().into_lemma().map(|sub_lemma| { + Lemma { + node_hash: node_hash, + sibling_hash: sibling_hash, + sub_lemma: Some(Box::new(sub_lemma)), + } + }) + } else { + // We might very well not have a sub_lemma, + // in which case we just set it to `None`, + // but still return a potentially valid `Lemma`. + Some(Lemma { + node_hash: node_hash, + sibling_hash: sibling_hash, + sub_lemma: None, + }) + } + } +} diff --git a/src/task.rs b/src/task.rs new file mode 100644 index 0000000..aa281b0 --- /dev/null +++ b/src/task.rs @@ -0,0 +1,145 @@ +//! Protobuf message IO task structure. The generic, shared behaviour is +//! contained in the implementation of `Task` while any specific behaviour +//! should be defined by means of the `MessageLoop` trait interface. + +use std::{cmp,io}; +use std::io::Read; +use std::net::TcpStream; +use protobuf; +use protobuf::Message as ProtoBufMessage; +use proto::message::{MessageProto}; + +/// A magic key to put right before each message. An atavism of primitive serial +/// protocols. +/// +/// TODO: Replace it with a proper handshake at connection initiation. +const FRAME_START: u32 = 0x2C0FFEE5; + +#[derive(Debug)] +pub enum Error { + IoError(io::Error), + EncodeError, + DecodeError, + FrameStartMismatch, + ProtocolError, + ProtobufError(protobuf::ProtobufError), +} + +impl From for Error { + fn from(err: io::Error) -> Error { Error::IoError(err) } +} + +impl From for Error { + fn from(err: protobuf::ProtobufError) -> Error { Error::ProtobufError(err) } +} + +fn encode_u32_to_be(value: u32, buffer: &mut[u8]) -> Result<(), Error> { + if buffer.len() < 4 { + return Err(Error::EncodeError); + } + let value = value.to_le(); + buffer[0] = ((value & 0xFF000000) >> 24) as u8; + buffer[1] = ((value & 0x00FF0000) >> 16) as u8; + buffer[2] = ((value & 0x0000FF00) >> 8) as u8; + buffer[3] = (value & 0x000000FF) as u8; + Ok(()) +} + +fn decode_u32_from_be(buffer: &[u8]) -> Result { + if buffer.len() < 4 { + return Err(Error::DecodeError); + } + let mut result: u32 = buffer[0] as u32; + result = result << 8; + result += buffer[1] as u32; + result = result << 8; + result += buffer[2] as u32; + result = result << 8; + result += buffer[3] as u32; + Ok(result) +} + +/// A trait allowing custom definitions of the main loop and the received +/// message callback. +pub trait MessageLoop { + fn run(&mut self); + fn on_message_received(&mut self, + message: MessageProto) + -> Result<(), Error>; +} + +pub struct Task { + stream: TcpStream, + buffer: [u8; 1024], +} + +/// Placeholder `MessageLoop` definition for a generic `Task`. +impl MessageLoop for Task { + fn run(&mut self) {} + fn on_message_received(&mut self, _: MessageProto) -> Result<(), Error> { + Ok(()) + } +} + +/// A message handling task. +impl Task where Self: MessageLoop { + pub fn new(stream: TcpStream) -> Task { + Task { + stream, + buffer: [0; 1024] + } + } + + pub fn receive_message(&mut self) -> Result { + self.stream.read_exact(&mut self.buffer[0..4])?; + let frame_start = decode_u32_from_be(&self.buffer[0..4])?; + if frame_start != FRAME_START { + return Err(Error::FrameStartMismatch); + }; + self.stream.read_exact(&mut self.buffer[0..4])?; + let size = decode_u32_from_be(&self.buffer[0..4])? as usize; + + let mut message: Vec = Vec::new(); + message.reserve(size); + while message.len() < size { + let num_to_read = cmp::min(self.buffer.len(), size - message.len()); + let (slice, _) = self.buffer.split_at_mut(num_to_read); + self.stream.read_exact(slice)?; + message.extend_from_slice(slice); + } + let message = protobuf::parse_from_bytes::(&message)?; + Ok(message) + } + + pub fn send_message(&mut self, message: &MessageProto) -> Result<(), Error> { + let mut buffer: [u8; 4] = [0; 4]; + // Wrap stream + let mut stream = protobuf::CodedOutputStream::new(&mut self.stream); + // Write magic number + encode_u32_to_be(FRAME_START, &mut buffer[0..4])?; + stream.write_raw_bytes(&buffer)?; + // Write message size + encode_u32_to_be(message.compute_size(), &mut buffer[0..4])?; + stream.write_raw_bytes(&buffer)?; + // Write message + message.write_to(&mut stream)?; + // Flush + stream.flush()?; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use task::*; + + /// Test the requirement that composing encoding with decoding yields the + /// identity. + #[test] + fn encode_decode_identity() { + let mut buffer: [u8; 4] = [0; 4]; + encode_u32_to_be(FRAME_START, &mut buffer[0..4]).unwrap(); + let frame_start = decode_u32_from_be(&buffer[0..4]).unwrap(); + assert_eq!(frame_start, FRAME_START); + } +}