1use serde::{Deserialize, Serialize};
2use std::time::Duration;
3use thiserror::Error;
4
5#[derive(Debug, Error)]
7pub enum ProtocolError {
8 #[error("Network error: {0}")]
9 NetworkError(String),
10
11 #[error("Consensus error: {0}")]
12 ConsensusError(String),
13
14 #[error("Crypto error: {0}")]
15 CryptoError(String),
16
17 #[error("State error: {0}")]
18 StateError(String),
19
20 #[error("Internal error: {0}")]
21 Internal(String),
22
23 #[error("Invalid message: {0}")]
24 InvalidMessage(String),
25}
26
27#[derive(Debug, Clone)]
29pub enum ProtocolEvent {
30 MessageReceived {
32 id: String,
34 payload: Vec<u8>,
36 source: Vec<u8>,
38 },
39
40 MessageFinalized {
42 id: String,
44 time: Duration,
46 },
47
48 StateChanged {
50 old_state: ProtocolState,
52 new_state: ProtocolState,
54 },
55
56 Error {
58 error: String,
60 context: String,
62 },
63}
64
65#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
67pub enum ProtocolState {
68 Initial,
70 Handshaking,
72 Running,
74 Stopping,
76 Stopped,
78 Error,
80}
81
82#[derive(Debug, Clone, Default)]
84pub struct ProtocolMetrics {
85 pub messages_per_second: f64,
87 pub avg_finalization_time: Duration,
89 pub memory_usage: usize,
91 pub active_rounds: usize,
93}