Skip to content

Commit

Permalink
Due to cargo issue, rollback logger, undo features
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Mar 30, 2018
1 parent f9b99a0 commit da624d7
Show file tree
Hide file tree
Showing 27 changed files with 728 additions and 5,118 deletions.
2 changes: 0 additions & 2 deletions libproto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ serde = "1.0"
serde_derive = "1.0"
serde_json = "1.0"
log = "0.4"
grpc = "0.2.1"
tls-api = "0.1.14"

[features]
default = []
Expand Down
29 changes: 0 additions & 29 deletions libproto/README.md

This file was deleted.

91 changes: 8 additions & 83 deletions libproto/src/autoimpl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,12 +156,6 @@ macro_rules! loop_macro_for_structs {
Status,
Transaction,
UnverifiedTransaction,
ActionParams,
EnvInfo,
InvokeRequest,
InvokeResponse,
KV,
Log,
InnerMessage,
Proposal,
SignedProposal,
Expand All @@ -170,22 +164,16 @@ macro_rules! loop_macro_for_structs {
ExecutedHeader,
ExecutedInfo,
ExecutedResult,
LoadRequest,
LoadResponse,
LogEntry,
Receipt,
ReceiptErrorWithOption,
ReceiptWithOption,
RegisterRequest,
RegisterResponse,
StateRoot,
BatchRequest,
Call,
Request,
FullTransaction,
Response,
SnapshotReq,
SnapshotResp,
SyncRequest,
SyncResponse,
// Generate ALL-PROTOS automatically end.
Expand All @@ -196,7 +184,7 @@ macro_rules! loop_macro_for_structs {
macro_rules! loop_macro_for_structs_in_msg {
($macro:ident) => {
$macro!(
// Generate MSG-PROTOS struct automatically begin:
// Generate MSG-PROTOS automatically begin:
RawBytes,
Request,
Response,
Expand All @@ -216,9 +204,7 @@ macro_rules! loop_macro_for_structs_in_msg {
VerifyBlockReq,
VerifyBlockResp,
ExecutedResult,
SnapshotReq,
SnapshotResp,
// Generate MSG-PROTOS struct automatically end.
// Generate MSG-PROTOS automatically end.
);
}
}
Expand All @@ -238,8 +224,7 @@ loop_macro_for_structs_in_msg!(impl_convert_for_struct_in_msg);
/// | 2 | u8 | Reserved |
/// |-------+------+------------------------------------------------|
/// | 3 | u4 | Reserved |
/// | | u1 | Reserved |
/// | | u1 | Compress: true 1, false 0 |
/// | | u2 | Reserved |
/// | | u2 | OperateType |
/// |-------+------+------------------------------------------------|
/// | 4~7 | u32 | Origin |
Expand Down Expand Up @@ -309,46 +294,18 @@ impl Message {
}
}

fn set_compressed(&mut self, c: bool) {
self.let_raw_be_ok();
let c_val: u8 = if c { 0b00000100 } else { 0b00000000 };
self.raw[3] = (self.raw[3] & 0b11111011) + (c_val & 0b00000100);
}

pub fn get_compressed(&self) -> bool {
if self.is_raw_ok() {
(self.raw[3] & 0b00000100) != 0
} else {
false // default
}
}

pub fn set_content(&mut self, v: MsgClass) {
let im: InnerMessage = v.into();
let im_vec: Vec<u8> = im.try_into().unwrap();
let mut im_compress = snappy::cita_compress(&im_vec[..]);
self.raw.drain(8..);
match snappy::cita_compress_to(&im_vec[..], &mut self.raw) {
Ok(true) => {
self.set_compressed(true);
}
Ok(false) | Err(_) => {
self.set_compressed(false);
self.raw.extend_from_slice(&im_vec[..]);
}
}
self.raw.append(&mut im_compress);
}

pub fn take_content(&mut self) -> Option<MsgClass> {
let im_opt = if self.get_compressed() {
let mut im_vec: Vec<u8> = Vec::new();
match snappy::cita_decompress_to(&self.raw[8..], &mut im_vec) {
Ok(_) => InnerMessage::try_from(&im_vec).ok(),
Err(_) => None,
}
} else {
InnerMessage::try_from(&self.raw[8..]).ok()
};
if let Some(mut im) = im_opt {
let im_vec = snappy::cita_decompress(&self.raw[8..]);
let im_rst = InnerMessage::try_from(&im_vec);
if let Ok(mut im) = im_rst {
im.take_content()
} else {
None
Expand Down Expand Up @@ -470,18 +427,6 @@ impl Message {
_ => None,
}
}
pub fn take_snapshot_req(&mut self) -> Option<SnapshotReq> {
match self.take_content() {
Some(MsgClass::SnapshotReq(v)) => Some(v),
_ => None,
}
}
pub fn take_snapshot_resp(&mut self) -> Option<SnapshotResp> {
match self.take_content() {
Some(MsgClass::SnapshotResp(v)) => Some(v),
_ => None,
}
}
// Generate MSG-PROTOS methods automatically end.
}

Expand Down Expand Up @@ -671,24 +616,4 @@ mod tests {
assert!(msg.take_response().is_some());
assert!(msg.take_request().is_none());
}

#[test]
fn compress_and_decompress() {
use super::Message;
use std::convert::Into;
use util::snappy::CITA_SKIP_COMPRESS_SIZE;

let raw_bytes: Vec<u8> = vec![1, 2, 3, 4];
let mut msg: Message = raw_bytes.clone().into();
assert!(!msg.get_compressed());
let raw_bytes_opt = msg.take_raw_bytes();
assert!(raw_bytes_opt.is_some());
assert_eq!(raw_bytes_opt.unwrap(), raw_bytes);
let raw_bytes: Vec<u8> = [1; CITA_SKIP_COMPRESS_SIZE + 1].to_vec();
let mut msg: Message = raw_bytes.clone().into();
assert!(msg.get_compressed());
let raw_bytes_opt = msg.take_raw_bytes();
assert!(raw_bytes_opt.is_some());
assert_eq!(raw_bytes_opt.unwrap(), raw_bytes);
}
}
2 changes: 0 additions & 2 deletions libproto/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
#![feature(try_from)]

extern crate cita_crypto as crypto;
extern crate grpc;
#[macro_use]
extern crate log as rlog;
extern crate protobuf;
extern crate rlp;
extern crate rustc_serialize;
#[macro_use]
extern crate serde_derive;
extern crate tls_api;
extern crate util;

pub mod protos;
Expand Down
1 change: 0 additions & 1 deletion libproto/src/protos/blockchain.proto
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ message Transaction {
uint64 quota = 3;
uint64 valid_until_block = 4;
bytes data = 5;
uint32 version = 6;
}

message UnverifiedTransaction {
Expand Down
Loading

0 comments on commit da624d7

Please sign in to comment.