-
Notifications
You must be signed in to change notification settings - Fork 162
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
90 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
use libp2p::{ | ||
gossipsub::{GossipsubMessage, MessageId, TopicHash}, | ||
PeerId, | ||
}; | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[allow(clippy::large_enum_variant)] | ||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub enum NetworkEvent { | ||
PeerConnected(PeerId), | ||
PeerDisconnected(PeerId), | ||
Gossipsub(GossipsubEvent), | ||
CancelLookupQuery(PeerId), | ||
} | ||
|
||
#[derive(Debug, Clone, Serialize, Deserialize)] | ||
pub enum GossipsubEvent { | ||
Subscribed { | ||
peer_id: PeerId, | ||
#[serde(with = "TopicHashDef")] | ||
topic: TopicHash, | ||
}, | ||
Unsubscribed { | ||
peer_id: PeerId, | ||
#[serde(with = "TopicHashDef")] | ||
topic: TopicHash, | ||
}, | ||
Message { | ||
from: PeerId, | ||
id: MessageId, | ||
#[serde(with = "GossipsubMessageDef")] | ||
message: GossipsubMessage, | ||
}, | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(remote = "TopicHash")] | ||
struct TopicHashDef { | ||
#[serde(getter = "TopicHash::to_string")] | ||
hash: String, | ||
} | ||
|
||
impl From<TopicHashDef> for TopicHash { | ||
fn from(t: TopicHashDef) -> Self { | ||
TopicHash::from_raw(t.hash) | ||
} | ||
} | ||
|
||
#[derive(Serialize, Deserialize)] | ||
#[serde(remote = "GossipsubMessage")] | ||
struct GossipsubMessageDef { | ||
source: Option<PeerId>, | ||
data: Vec<u8>, | ||
sequence_number: Option<u64>, | ||
#[serde(with = "TopicHashDef")] | ||
topic: TopicHash, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters