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
Next Next commit
fixed network tests
  • Loading branch information
ong-jonas committed Oct 13, 2023
commit 1777c61ca9833ff6c96bd1c176f01c9630677dc4
19 changes: 9 additions & 10 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,10 +135,9 @@ pub(crate) async fn start(peer: PeerBuilder) -> Result<Peer, Box<dyn Error>> {
log::info!("Publishing (Topic: {:?})", topic);
if topic == Topic::HotStuffRsSend(local_public_address) {
// send to myself
let _ = peer
.handlers
.iter()
.map(|handler| handler(local_public_address, message.clone()));
peer.handlers.iter()
.for_each(|handler| handler(local_public_address,message.clone()));

} else if let Err(e) = swarm.behaviour_mut().publish(topic, message)
{
log::debug!("Failed to pulish the message. {:?}", e);
Expand All @@ -165,14 +164,13 @@ pub(crate) async fn start(peer: PeerBuilder) -> Result<Peer, Box<dyn Error>> {
let public_addr: PublicAddress = public_addr.into();
if swarm.behaviour().is_subscribed(&message) {
// Send it to ourselves if we subscribed to this topic
match identify_topic(message.topic, public_addr) {
Some(t) => {
match identify_topic(message.topic, local_public_address) {
Some(topic) => {
if let Ok(message) =
deserialize_message(message.data, t)
deserialize_message(message.data, topic)
{
let _ = peer.handlers.iter().map(|handler| {
handler(local_public_address, message.clone())
});
peer.handlers.iter()
.for_each(|handler| handler(public_addr,message.clone()));
}
}
None => continue,
Expand Down Expand Up @@ -230,6 +228,7 @@ async fn build_transport(

/// Identify the [crate::messages::Topic] of the message
fn identify_topic(topic_hash: TopicHash, public_addr: PublicAddress) -> Option<Topic> {
//address for fullnode_topics should be the local peer address
config::fullnode_topics(public_addr)
.into_iter()
.find(|t| t.clone().hash() == topic_hash)
Expand Down
6 changes: 3 additions & 3 deletions src/peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ impl PeerBuilder {
}
}

pub fn configuration(&mut self, config: Config) -> &mut Self {
pub fn configuration(mut self, config: Config) -> PeerBuilder {
self.config = Some(config);
self
}

pub fn on_receive_msg(
&mut self,
mut self,
handlers: impl Fn(PublicAddress, Message) + Send + 'static,
) -> &mut Self {
) -> PeerBuilder {
self.handlers = Some(Box::new(handlers));
self
}
Expand Down
Loading