|
|
@@ -32,7 +32,14 @@ use log::{debug, error, trace, warn};
|
|
|
use smol::Executor;
|
|
|
|
|
|
use super::{Event, EventGraphPtr, NULL_ID};
|
|
|
-use crate::{impl_p2p_message, net::*, system::timeout::timeout, Error, Result};
|
|
|
+use crate::{
|
|
|
+ event_graph::{deg, deg::degev, DegEvent},
|
|
|
+ impl_p2p_message,
|
|
|
+ net::*,
|
|
|
+ system::timeout::timeout,
|
|
|
+ util::time::NanoTimestamp,
|
|
|
+ Error, Result,
|
|
|
+};
|
|
|
|
|
|
/// Malicious behaviour threshold. If the threshold is reached, we will
|
|
|
/// drop the peer from our P2P connection.
|
|
|
@@ -174,6 +181,12 @@ impl ProtocolEventGraph {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
+ degev!(self, RecvMessage, {
|
|
|
+ info: vec![event_id.to_string()],
|
|
|
+ cmd: "EventPut".to_string(),
|
|
|
+ time: NanoTimestamp::current_time(),
|
|
|
+ });
|
|
|
+
|
|
|
// We received an event. Check if we already have it in our DAG.
|
|
|
// Check event is not older that current genesis event timestamp.
|
|
|
// Also check if we have the event's parents. In the case we do
|
|
|
@@ -341,6 +354,12 @@ impl ProtocolEventGraph {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
+ degev!(self, SendMessage, {
|
|
|
+ info: vec![event_id.to_string()],
|
|
|
+ cmd: "EventPut".to_string(),
|
|
|
+ time: NanoTimestamp::current_time(),
|
|
|
+ });
|
|
|
+
|
|
|
// Relay the event to other peers.
|
|
|
self.event_graph
|
|
|
.p2p
|
|
|
@@ -358,8 +377,8 @@ impl ProtocolEventGraph {
|
|
|
Err(_) => continue,
|
|
|
};
|
|
|
trace!(
|
|
|
- target: "event_graph::protocol::handle_multi_event_req()",
|
|
|
- "Got MultiEventReq: {:?} [{}]", event_ids, self.channel.address(),
|
|
|
+ target: "event_graph::protocol::handle_event_req()",
|
|
|
+ "Got EventReq: {:?} [{}]", event_ids, self.channel.address(),
|
|
|
);
|
|
|
|
|
|
// Check if node has finished syncing its DAG
|
|
|
@@ -371,6 +390,14 @@ impl ProtocolEventGraph {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
+ let info = event_ids.clone().into_iter().map(|x| x.to_string()).collect();
|
|
|
+
|
|
|
+ degev!(self, RecvMessage, {
|
|
|
+ info,
|
|
|
+ cmd: "EventReq".to_string(),
|
|
|
+ time: NanoTimestamp::current_time(),
|
|
|
+ });
|
|
|
+
|
|
|
// We received an event request from somebody.
|
|
|
// If we do have it, we will send it back to them as `EventRep`.
|
|
|
// Otherwise, we'll stay quiet. An honest node should always have
|
|
|
@@ -383,8 +410,8 @@ impl ProtocolEventGraph {
|
|
|
// against malicious event requests where they want us to keep
|
|
|
// reading our db and steal our bandwidth.
|
|
|
let mut events = vec![];
|
|
|
- for event_id in event_ids {
|
|
|
- if !self.event_graph.broadcasted_ids.read().await.contains(&event_id) {
|
|
|
+ for event_id in event_ids.iter() {
|
|
|
+ if !self.event_graph.broadcasted_ids.read().await.contains(event_id) {
|
|
|
let malicious_count = self.malicious_count.fetch_add(1, SeqCst);
|
|
|
if malicious_count + 1 == MALICIOUS_THRESHOLD {
|
|
|
error!(
|
|
|
@@ -410,7 +437,7 @@ impl ProtocolEventGraph {
|
|
|
target: "event_graph::protocol::handle_event_req()",
|
|
|
"Fetching event {:?} from DAG", event_id,
|
|
|
);
|
|
|
- events.push(self.event_graph.dag_get(&event_id).await.unwrap().unwrap());
|
|
|
+ events.push(self.event_graph.dag_get(event_id).await.unwrap().unwrap());
|
|
|
}
|
|
|
|
|
|
// Check if the incoming event is older than the genesis event. If so, something
|
|
|
@@ -442,6 +469,14 @@ impl ProtocolEventGraph {
|
|
|
//bcast_ids.remove(&event_id);
|
|
|
drop(bcast_ids);
|
|
|
|
|
|
+ let info = event_ids.into_iter().map(|x| x.to_string()).collect();
|
|
|
+
|
|
|
+ degev!(self, SendMessage, {
|
|
|
+ info,
|
|
|
+ cmd: "EventRep".to_string(),
|
|
|
+ time: NanoTimestamp::current_time(),
|
|
|
+ });
|
|
|
+
|
|
|
// Reply with the event
|
|
|
self.channel.send(&EventRep(events)).await?;
|
|
|
}
|
|
|
@@ -453,6 +488,11 @@ impl ProtocolEventGraph {
|
|
|
async fn handle_tip_req(self: Arc<Self>) -> Result<()> {
|
|
|
loop {
|
|
|
self.tip_req_sub.receive().await?;
|
|
|
+ degev!(self, RecvMessage, {
|
|
|
+ info: vec![],
|
|
|
+ cmd: "TipReq".to_string(),
|
|
|
+ time: NanoTimestamp::current_time(),
|
|
|
+ });
|
|
|
trace!(
|
|
|
target: "event_graph::protocol::handle_tip_req()",
|
|
|
"Got TipReq [{}]", self.channel.address(),
|
|
|
@@ -480,6 +520,21 @@ impl ProtocolEventGraph {
|
|
|
}
|
|
|
drop(bcast_ids);
|
|
|
|
|
|
+ let info = layers
|
|
|
+ .clone()
|
|
|
+ .into_values()
|
|
|
+ .map(|v| v.into_iter().map(|id| id.to_string()).collect::<Vec<_>>())
|
|
|
+ .collect::<Vec<_>>()
|
|
|
+ .concat();
|
|
|
+
|
|
|
+ degev!(self, SendMessage, {
|
|
|
+ info,
|
|
|
+ cmd: "TipRep".to_string(),
|
|
|
+ time: NanoTimestamp::current_time(),
|
|
|
+ });
|
|
|
+
|
|
|
+ let _ = self.event_graph.eventgraph_info(1, tinyjson::JsonValue::Array(vec![])).await;
|
|
|
+
|
|
|
self.channel.send(&TipRep(layers)).await?;
|
|
|
}
|
|
|
}
|