Skip to content

Commit

Permalink
refac: rename some unused variant names
Browse files Browse the repository at this point in the history
  • Loading branch information
ai-chen2050 committed Sep 19, 2024
1 parent c8279e0 commit cb9c3c6
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 46 deletions.
2 changes: 1 addition & 1 deletion demos/coll-tx/src/simple_utxo.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A simple utxo structure for testing case.
use std::io;
use sha2::{Sha256, Digest};
use sha2::Digest;

/// SimpleUTXO input
#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down
28 changes: 14 additions & 14 deletions demos/test_conflict/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
use std::collections::HashMap;

#[derive(Debug)]
struct VectorClock {
struct _VectorClock {
clock: HashMap<String, i64>,
}

impl VectorClock {
fn new() -> Self {
VectorClock {
impl _VectorClock {
fn _new() -> Self {
_VectorClock {
clock: HashMap::new(),
}
}

fn get_version(&self, node_id: &str) -> &i64 {
fn _get_version(&self, node_id: &str) -> &i64 {
self.clock.get(node_id).unwrap_or(&0)
}

fn update_version(&mut self, node_id: &str, version: i64) {
fn _update_version(&mut self, node_id: &str, version: i64) {
self.clock.insert(node_id.parse().unwrap(), version);
}

fn has_conflict(&self, other: &VectorClock,) -> bool {
fn _has_conflict(&self, other: &_VectorClock,) -> bool {
let mut all_greater = true;
let mut all_smaller = true;

Expand All @@ -44,15 +44,15 @@ mod tests {

#[test]
fn test_conflict() {
let mut clock1 = VectorClock::new();
clock1.update_version("A".to_string().as_str(), 1);
clock1.update_version("B".to_string().as_str(), 2);
let mut clock1 = _VectorClock::_new();
clock1._update_version("A".to_string().as_str(), 1);
clock1._update_version("B".to_string().as_str(), 2);

let mut clock2 = VectorClock::new();
clock2.update_version("A".to_string().as_str(), 2);
clock2.update_version("B".to_string().as_str(), 1);
let mut clock2 = _VectorClock::_new();
clock2._update_version("A".to_string().as_str(), 2);
clock2._update_version("B".to_string().as_str(), 1);

assert!(clock1.has_conflict(&clock2));
assert!(clock1._has_conflict(&clock2));
}
}

10 changes: 5 additions & 5 deletions demos/vlc-dag/src/db_client/lldb_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@ pub struct VLCLLDb {
env: Environment,
merge_log: DbHandle,
clock_infos: DbHandle,
cur_count: DbHandle,
_cur_count: DbHandle,
}

impl VLCLLDb {
pub fn new(path: &str, mode: Option<u32>) -> Self {
let mut USER_DIR_MODE: u32 = 0o777;
let mut user_dir_mode: u32 = 0o777;
if let Some(mode) = mode {
USER_DIR_MODE = mode;
user_dir_mode = mode;
}

let env = Environment::new()
.max_dbs(5)
.open(path, USER_DIR_MODE)
.open(path, user_dir_mode)
.expect("Failed to open the environment");

let merge_log = env
Expand All @@ -32,7 +32,7 @@ impl VLCLLDb {
.create_db("cur_count", DbFlags::empty())
.expect("Failed to create the cur_count database");

VLCLLDb { env, merge_log, clock_infos, cur_count }
VLCLLDb { env, merge_log, clock_infos, _cur_count: cur_count }
}

pub(crate) fn add_clock_infos(&mut self, key: String, clock_info: ClockInfo) {
Expand Down
20 changes: 10 additions & 10 deletions demos/vlc-dag/src/db_client/lldb_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ struct Commit {
message: String,
}

struct Repository {
struct _Repository {
env: Environment,
commits_db: DbHandle,
}

impl Repository {
impl _Repository {

fn new(path: &str, db: &str) -> Self {
fn _new(path: &str, db: &str) -> Self {
const USER_DIR: u32 = 0o777;
let env = Environment::new()
.max_dbs(5)
Expand All @@ -28,10 +28,10 @@ impl Repository {
.create_db(db, DbFlags::empty())
.expect("Failed to create the commits database");

Repository { env, commits_db }
_Repository { env, commits_db }
}

fn add_commit(&mut self, commit: &Commit) {
fn _add_commit(&mut self, commit: &Commit) {
// let db = self.env.get_default_db(DbFlags::empty()).unwrap();
let txn = self.env.new_transaction().unwrap();
let db = txn.bind(&self.commits_db);
Expand All @@ -50,28 +50,28 @@ mod tests {

#[test]
fn submit_to_repo() {
let mut repo = Repository::new("./db", "commit");
let mut repo = _Repository::_new("./db", "commit");

let commit1 = Commit {
id: "commit1".to_string(),
parent_ids: HashSet::new(),
message: "Initial commit".to_string(),
};
repo.add_commit(&commit1);
repo._add_commit(&commit1);

let commit2 = Commit {
id: "commit2".to_string(),
parent_ids: vec!["commit1".to_string()].into_iter().collect(),
message: "Add feature X".to_string(),
};
repo.add_commit(&commit2);
repo._add_commit(&commit2);

let commit3 = Commit {
id: "commit3".to_string(),
parent_ids: vec!["commit1".to_string()].into_iter().collect(),
message: "Add feature Y".to_string(),
};
repo.add_commit(&commit3);
repo._add_commit(&commit3);

let commit4 = Commit {
id: "commit4".to_string(),
Expand All @@ -80,6 +80,6 @@ mod tests {
.collect(),
message: "Merge feature X and Y".to_string(),
};
repo.add_commit(&commit4);
repo._add_commit(&commit4);
}
}
29 changes: 13 additions & 16 deletions demos/vlc-dag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,16 @@
pub mod db_client;

use clap::builder::Str;
// use clap::builder::Str;
use db_client::lldb_client::VLCLLDb;
use serde::{Deserialize, Serialize};
use std::time::UNIX_EPOCH;
use std::{cmp, time::SystemTime};
use std::collections::{BTreeSet, HashMap, HashSet};
use std::collections::{BTreeSet, HashMap};
use std::io::BufRead;
use std::sync::{Arc, RwLock};
use std::net::SocketAddr;
use tokio::net::UdpSocket;

use std::time;
use tokio::{task::JoinHandle};
use vlc::Clock;
use lmdb_rs as lmdb;

Expand Down Expand Up @@ -222,7 +219,7 @@ impl ServerState {
}
}

fn handle_diff_req(&mut self, msg: DiffReq, db: Arc<RwLock<VLCLLDb>>) -> Option<ServerMessage> {
fn handle_diff_req(&mut self, msg: DiffReq, _db: Arc<RwLock<VLCLLDb>>) -> Option<ServerMessage> {
// println!("Key-To-messageid: {:?}", self.clock_to_eventid);
if msg.from_clock.count == 0 {
let req = ServerMessage::DiffRsp(DiffRsp { diffs: self.items.clone(), from:self.clock_info.clone(), to: msg.from_clock.id });
Expand All @@ -239,7 +236,7 @@ impl ServerState {
}
}

fn handle_diff_rsp(&mut self, msg: DiffRsp, db: Arc<RwLock<VLCLLDb>>) -> bool {
fn handle_diff_rsp(&mut self, msg: DiffRsp, _db: Arc<RwLock<VLCLLDb>>) -> bool {
match self.clock_info.clock.partial_cmp(&msg.from.clock) {
Some(cmp::Ordering::Equal) => {},
Some(cmp::Ordering::Greater) => {},
Expand All @@ -262,7 +259,7 @@ impl ServerState {
false
}

fn handle_active_sync(&mut self, msg: ActiveSync, db: Arc<RwLock<VLCLLDb>>) -> (Option<ServerMessage>, bool){
fn handle_active_sync(&mut self, msg: ActiveSync, _db: Arc<RwLock<VLCLLDb>>) -> (Option<ServerMessage>, bool){
match self.clock_info.clock.partial_cmp(&msg.latest.clock) {
Some(cmp::Ordering::Equal) => return (None, false),
Some(cmp::Ordering::Greater) => return (None, false),
Expand Down Expand Up @@ -411,7 +408,6 @@ impl Server {
self.sinker_merge_log(&msg.latest).await;
}
}
_ => { println!("[broadcast_state]: not support ServerMessage ")}
}
}
Message::Terminate => {
Expand Down Expand Up @@ -462,22 +458,22 @@ impl Server {

/// direct send to someone node
async fn direct_send(&mut self, fmsg: ServerMessage) {
let mut index = 0;
let mut _index = 0;
let server_msg = Message::FromServer(fmsg.clone());
match fmsg.clone() {
ServerMessage::DiffReq(msg) => {
index = msg.to;
_index = msg.to;
}
ServerMessage::DiffRsp(msg) => {
index = msg.to;
_index = msg.to;
}
ServerMessage::ActiveSync(msg) => {
index = msg.to;
_index = msg.to;
}
_ => { return }
}

let msg_index: usize = index.try_into().unwrap();
let msg_index: usize = _index.try_into().unwrap();
if self.index != msg_index {
self.socket
.send_to(
Expand Down Expand Up @@ -549,9 +545,10 @@ fn get_suffix<T: PartialEq + Clone>(vec: &[T], target: T) -> Option<Vec<T>> {

#[cfg(test)]
mod tests {
use rand::Rng;

use super::*;
use rand::Rng;
use std::time;
use tokio::task::JoinHandle;

async fn start_servers(n_server: usize) -> (Configuration, Vec<JoinHandle<Vec<String>>>) {
let mut config = Configuration {
Expand Down

0 comments on commit cb9c3c6

Please sign in to comment.