Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
removed identity topics
  • Loading branch information
ong-jonas committed Oct 23, 2023
commit fed8fe6971f6617bbf4866f3aef631f03348eef7
15 changes: 5 additions & 10 deletions src/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
//!

use borsh::{BorshSerialize, BorshDeserialize};
use libp2p::gossipsub::{IdentTopic, TopicHash};
use libp2p::gossipsub::IdentTopic;
use pchain_types::{
blockchain::TransactionV1,
cryptography::{PublicAddress, Sha256Hash},
Expand Down Expand Up @@ -81,7 +81,10 @@ impl TryFrom<(libp2p::gossipsub::Message, pchain_types::cryptography::PublicAddr
let (topic_hash, data) = (message.topic, message.data);
let mut data = data.as_slice();

let topic = identify_topics(topic_hash, local_public_address)?;
let topic = config::fullnode_topics(local_public_address)
.into_iter()
.find(|t| t.clone().hash() == topic_hash)
.ok_or(InvalidTopicError)?;

match topic {
HotStuffRsBroadcast | HotStuffRsSend(_) => {
Expand All @@ -100,14 +103,6 @@ impl TryFrom<(libp2p::gossipsub::Message, pchain_types::cryptography::PublicAddr
}
}

fn identify_topics(topic_hash: TopicHash, addr: PublicAddress) -> Result<Topic, InvalidTopicError> {
let topic = config::fullnode_topics(addr)
.into_iter()
.find(|t| t.clone().hash() == topic_hash)
.ok_or(InvalidTopicError)?;
Ok(topic)
}

#[derive(Debug)]
pub struct InvalidTopicError;

Expand Down
6 changes: 3 additions & 3 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ impl Peer {
/// 3. Spawns an asynchronous [tokio] task and enters the main event loop, returning a mpsc Sender used for sending
/// [PeerCommand] to the internal thread.
pub async fn start(config: Config, handlers: Vec<Box<dyn Fn(PublicAddress, Message) + Send>>) -> Result<Peer, PeerStartError> {
let swarm = set_up_transport(&config).await?;
let swarm = establish_network_connections(swarm, &config)?;
let mut swarm = set_up_transport(&config).await?;
swarm = establish_network_connections(swarm, &config)?;
let (handle, sender) = main_loop(swarm, &config, handlers)?;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"main_loop" doesn't seem to be a good naming...?

Copy link
Collaborator Author

@ong-jonas ong-jonas Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i agree, maybe "spawn_event_loop" , "start_event_detection" or "spawn_events_handler" ? any suggestions?

Ok(
Peer {
Expand Down Expand Up @@ -263,7 +263,7 @@ fn main_loop(mut swarm: libp2p::Swarm<Behaviour>, config: &Config, message_handl
}
}

// 3. Deliver messages when a NetworkEvent is received
// 3. Forward subscribed messages to Message Handlers when a NetworkEvent is received
if let Some(event) = event {
match event {
SwarmEvent::Behaviour(NetworkEvent::Gossip(gossipsub::Event::Message {
Expand Down