-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_ext.rs
57 lines (51 loc) · 1.18 KB
/
command_ext.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use std::fmt;
use std::net::SocketAddr;
use lib::command::ClientCommand;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub enum NetworkCommand {
Propose {
command_view: CommandView,
},
Lock {
socket_addr: SocketAddr,
command_view: CommandView,
},
Commit {
command_view: CommandView,
},
// view change
Blame {
socket_addr: SocketAddr,
view: u128,
timer_expired: bool,
},
ViewChange {
socket_addr: SocketAddr,
new_view: u128,
highest_lock: CommandView,
},
Forward {
command: ClientCommand,
},
}
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
pub struct CommandView {
pub command: ClientCommand, // lock_value
pub view: u128, // lock_view
}
impl CommandView {
pub fn new() -> CommandView {
CommandView {
command: ClientCommand::Get {
key: "-".to_string(),
},
view: 0,
}
}
}
impl fmt::Display for NetworkCommand {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}", self)
}
}