Measure both data and cover message counts (#40)
This commit is contained in:
parent
2e85190a22
commit
5a0412ff83
|
@ -193,8 +193,8 @@ impl MixNode {
|
||||||
state: MixnodeState {
|
state: MixnodeState {
|
||||||
node_id: id,
|
node_id: id,
|
||||||
step_id: 0,
|
step_id: 0,
|
||||||
data_messages_generated: HashMap::new(),
|
messages_generated: HashMap::new(),
|
||||||
data_messages_fully_unwrapped: HashMap::new(),
|
messages_fully_unwrapped: HashMap::new(),
|
||||||
},
|
},
|
||||||
data_msg_lottery_update_time_sender,
|
data_msg_lottery_update_time_sender,
|
||||||
data_msg_lottery_interval,
|
data_msg_lottery_interval,
|
||||||
|
@ -279,11 +279,12 @@ impl Node for MixNode {
|
||||||
let waker = futures::task::noop_waker();
|
let waker = futures::task::noop_waker();
|
||||||
let mut cx = futures::task::Context::from_waker(&waker);
|
let mut cx = futures::task::Context::from_waker(&waker);
|
||||||
|
|
||||||
|
// Generate a data message probabilistically
|
||||||
if let Poll::Ready(Some(_)) = pin!(&mut self.data_msg_lottery_interval).poll_next(&mut cx) {
|
if let Poll::Ready(Some(_)) = pin!(&mut self.data_msg_lottery_interval).poll_next(&mut cx) {
|
||||||
if self.data_msg_lottery.run() {
|
if self.data_msg_lottery.run() {
|
||||||
let payload = Payload::new();
|
let payload = Payload::new();
|
||||||
self.state
|
self.state
|
||||||
.data_messages_generated
|
.messages_generated
|
||||||
.insert(payload.id(), self.state.step_id);
|
.insert(payload.id(), self.state.step_id);
|
||||||
let message = self
|
let message = self
|
||||||
.crypto_processor
|
.crypto_processor
|
||||||
|
@ -292,9 +293,9 @@ impl Node for MixNode {
|
||||||
self.persistent_sender.send(message).unwrap();
|
self.persistent_sender.send(message).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TODO: Generate cover message with probability
|
|
||||||
|
// Handle incoming messages
|
||||||
for network_message in self.receive() {
|
for network_message in self.receive() {
|
||||||
// println!(">>>>> Node {}, message: {message:?}", self.id);
|
|
||||||
self.forward(
|
self.forward(
|
||||||
network_message.payload().clone(),
|
network_message.payload().clone(),
|
||||||
Some(network_message.from),
|
Some(network_message.from),
|
||||||
|
@ -313,14 +314,23 @@ impl Node for MixNode {
|
||||||
MixOutgoingMessage::FullyUnwrapped(payload) => {
|
MixOutgoingMessage::FullyUnwrapped(payload) => {
|
||||||
let payload = Payload::load(payload);
|
let payload = Payload::load(payload);
|
||||||
self.state
|
self.state
|
||||||
.data_messages_fully_unwrapped
|
.messages_fully_unwrapped
|
||||||
.insert(payload.id(), self.state.step_id);
|
.insert(payload.id(), self.state.step_id);
|
||||||
//TODO: create a tracing event
|
//TODO: create a tracing event
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if let Poll::Ready(Some(msg)) = pin!(&mut self.cover_traffic).poll_next(&mut cx) {
|
|
||||||
let message = self.crypto_processor.wrap_message(&msg).unwrap();
|
// Generate a cover message probabilistically
|
||||||
|
if let Poll::Ready(Some(_)) = pin!(&mut self.cover_traffic).poll_next(&mut cx) {
|
||||||
|
let payload = Payload::new();
|
||||||
|
self.state
|
||||||
|
.messages_generated
|
||||||
|
.insert(payload.id(), self.state.step_id);
|
||||||
|
let message = self
|
||||||
|
.crypto_processor
|
||||||
|
.wrap_message(payload.as_bytes())
|
||||||
|
.unwrap();
|
||||||
self.persistent_sender.send(message).unwrap();
|
self.persistent_sender.send(message).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -338,8 +348,7 @@ impl Node for MixNode {
|
||||||
match ward {
|
match ward {
|
||||||
WardCondition::Max(_) => false,
|
WardCondition::Max(_) => false,
|
||||||
WardCondition::Sum(condition) => {
|
WardCondition::Sum(condition) => {
|
||||||
*condition.step_result.borrow_mut() +=
|
*condition.step_result.borrow_mut() += self.state.messages_fully_unwrapped.len();
|
||||||
self.state.data_messages_fully_unwrapped.len();
|
|
||||||
false
|
false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,8 +16,8 @@ pub struct MixnodeState {
|
||||||
#[serde(serialize_with = "serialize_node_id_as_index")]
|
#[serde(serialize_with = "serialize_node_id_as_index")]
|
||||||
pub node_id: NodeId,
|
pub node_id: NodeId,
|
||||||
pub step_id: usize,
|
pub step_id: usize,
|
||||||
pub data_messages_generated: HashMap<PayloadId, usize>,
|
pub messages_generated: HashMap<PayloadId, usize>,
|
||||||
pub data_messages_fully_unwrapped: HashMap<PayloadId, usize>,
|
pub messages_fully_unwrapped: HashMap<PayloadId, usize>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
|
|
Loading…
Reference in New Issue