diff options
Diffstat (limited to 'p2p/src')
-rw-r--r-- | p2p/src/lib.rs | 3 | ||||
-rw-r--r-- | p2p/src/monitor.rs | 8 | ||||
-rw-r--r-- | p2p/src/peer/peer_id.rs | 4 | ||||
-rw-r--r-- | p2p/src/protocol.rs | 6 |
4 files changed, 15 insertions, 6 deletions
diff --git a/p2p/src/lib.rs b/p2p/src/lib.rs index 546353a..ebc51d8 100644 --- a/p2p/src/lib.rs +++ b/p2p/src/lib.rs @@ -63,7 +63,6 @@ pub mod protocol; pub use backend::{ArcBackend, Backend}; pub use config::Config; -pub use error::Error as P2pError; pub use peer::{ArcPeer, PeerID}; pub use version::Version; @@ -75,4 +74,4 @@ pub mod keypair { pub use karyon_core::crypto::{KeyPair, KeyPairType, PublicKey, SecretKey}; } -use error::{Error, Result}; +pub use error::{Error, Result}; diff --git a/p2p/src/monitor.rs b/p2p/src/monitor.rs index b7afb7c..4d6a46c 100644 --- a/p2p/src/monitor.rs +++ b/p2p/src/monitor.rs @@ -4,6 +4,9 @@ use karyon_core::event::{ArcEventSys, EventListener, EventSys, EventValue, Event use karyon_net::Endpoint; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + use crate::{Config, PeerID}; /// Responsible for network and system monitoring. @@ -37,7 +40,6 @@ use crate::{Config, PeerID}; /// ``` pub struct Monitor { event_sys: ArcEventSys<MonitorTopic>, - config: Arc<Config>, } @@ -77,6 +79,7 @@ impl Monitor { } #[derive(Clone, Debug, Eq, PartialEq, Hash)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum MonitorTopic { Conn, PeerPool, @@ -85,6 +88,7 @@ pub enum MonitorTopic { /// Defines connection-related events. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum ConnEvent { Connected(Endpoint), ConnectRetried(Endpoint), @@ -98,6 +102,7 @@ pub enum ConnEvent { /// Defines `PeerPool` events. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum PeerPoolEvent { NewPeer(PeerID), RemovePeer(PeerID), @@ -105,6 +110,7 @@ pub enum PeerPoolEvent { /// Defines `Discovery` events. #[derive(Clone, Debug)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub enum DiscoveryEvent { LookupStarted(Endpoint), LookupFailed(Endpoint), diff --git a/p2p/src/peer/peer_id.rs b/p2p/src/peer/peer_id.rs index f907aa7..a769c86 100644 --- a/p2p/src/peer/peer_id.rs +++ b/p2p/src/peer/peer_id.rs @@ -2,12 +2,16 @@ use bincode::{Decode, Encode}; use rand::{rngs::OsRng, RngCore}; use sha2::{Digest, Sha256}; +#[cfg(feature = "serde")] +use serde::{Deserialize, Serialize}; + use karyon_core::crypto::PublicKey; use crate::Error; /// Represents a unique identifier for a peer. #[derive(Clone, Debug, Eq, PartialEq, Hash, Decode, Encode)] +#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))] pub struct PeerID(pub [u8; 32]); impl std::fmt::Display for PeerID { diff --git a/p2p/src/protocol.rs b/p2p/src/protocol.rs index 951040b..d42f092 100644 --- a/p2p/src/protocol.rs +++ b/p2p/src/protocol.rs @@ -39,7 +39,7 @@ impl EventValue for ProtocolEvent { /// /// use karyon_p2p::{ /// protocol::{ArcProtocol, Protocol, ProtocolID, ProtocolEvent}, -/// Backend, PeerID, Config, Version, P2pError, ArcPeer, +/// Backend, PeerID, Config, Version, Error, ArcPeer, /// keypair::{KeyPair, KeyPairType}, /// }; /// @@ -57,7 +57,7 @@ impl EventValue for ProtocolEvent { /// /// #[async_trait] /// impl Protocol for NewProtocol { -/// async fn start(self: Arc<Self>) -> Result<(), P2pError> { +/// async fn start(self: Arc<Self>) -> Result<(), Error> { /// let listener = self.peer.register_listener::<Self>().await; /// loop { /// let event = listener.recv().await.unwrap(); @@ -76,7 +76,7 @@ impl EventValue for ProtocolEvent { /// Ok(()) /// } /// -/// fn version() -> Result<Version, P2pError> { +/// fn version() -> Result<Version, Error> { /// "0.2.0, >0.1.0".parse() /// } /// |