|
|
@@ -16,10 +16,7 @@
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
-use std::{
|
|
|
- collections::{HashMap, VecDeque},
|
|
|
- fmt::Debug,
|
|
|
-};
|
|
|
+use std::{collections::VecDeque, fmt::Debug};
|
|
|
|
|
|
use async_std::sync::{Arc, Mutex};
|
|
|
use async_trait::async_trait;
|
|
|
@@ -31,11 +28,10 @@ use super::EventMsg;
|
|
|
use crate::{
|
|
|
event_graph::model::{Event, EventId, ModelPtr},
|
|
|
net,
|
|
|
- util::{async_util::sleep, time::Timestamp},
|
|
|
+ util::async_util::sleep,
|
|
|
Result,
|
|
|
};
|
|
|
|
|
|
-const UNREAD_EVENT_EXPIRE_TIME: u64 = 3600; // in seconds
|
|
|
const SIZE_OF_SEEN_BUFFER: usize = 65536;
|
|
|
// const MAX_CONFIRM: u8 = 3;
|
|
|
|
|
|
@@ -106,45 +102,6 @@ impl<T: Eq + PartialEq + Clone> Seen<T> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-pub type UnreadEventsPtr<T> = Arc<Mutex<UnreadEvents<T>>>;
|
|
|
-
|
|
|
-#[derive(Debug)]
|
|
|
-pub struct UnreadEvents<T: Send + Sync> {
|
|
|
- pub events: HashMap<EventId, Event<T>>,
|
|
|
-}
|
|
|
-
|
|
|
-impl<T> UnreadEvents<T>
|
|
|
-where
|
|
|
- T: Send + Sync + Encodable + Decodable + Clone + EventMsg,
|
|
|
-{
|
|
|
- pub fn new() -> UnreadEventsPtr<T> {
|
|
|
- Arc::new(Mutex::new(Self { events: HashMap::new() }))
|
|
|
- }
|
|
|
-
|
|
|
- fn _contains(&self, key: &EventId) -> bool {
|
|
|
- self.events.contains_key(key)
|
|
|
- }
|
|
|
-
|
|
|
- fn _get(&self, key: &EventId) -> Option<Event<T>> {
|
|
|
- self.events.get(key).cloned()
|
|
|
- }
|
|
|
-
|
|
|
- pub fn insert(&mut self, event: &Event<T>) {
|
|
|
- // prune expired events
|
|
|
- let mut prune_ids = vec![];
|
|
|
- for (id, e) in self.events.iter() {
|
|
|
- if e.timestamp.0 + (UNREAD_EVENT_EXPIRE_TIME * 1000) < Timestamp::current_time().0 {
|
|
|
- prune_ids.push(*id);
|
|
|
- }
|
|
|
- }
|
|
|
- for id in prune_ids {
|
|
|
- self.events.remove(&id);
|
|
|
- }
|
|
|
-
|
|
|
- self.events.insert(event.hash(), event.clone());
|
|
|
- }
|
|
|
-}
|
|
|
-
|
|
|
pub struct ProtocolEvent<T>
|
|
|
where
|
|
|
T: Send + Sync + Encodable + Decodable + Debug + 'static,
|