Skip to content
Closed
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
combine send_to and broadcast functions to publish
  • Loading branch information
ong-jonas committed Oct 9, 2023
commit 67b3b6adc9fe7279ddf425ef08e3bc100e3285ce
15 changes: 2 additions & 13 deletions src/behaviour.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,19 +136,8 @@ impl PeerBehaviour {
Ok(())
}

/// Send [Message] to peer with the given address
pub fn send_to(
&mut self,
address: PublicAddress,
msg: Message,
) -> Result<MessageId, PublishError> {
let topic = Topic::HotStuffRsSend(address).hash();
let content: Vec<u8> = msg.into();
self.gossip.publish(topic, content)
}

/// Broadcast [Message] with a specific topic
pub fn broadcast(
/// Publish [Message] to peers subscribed to the specific [Topic]
pub fn publish(
&mut self,
topic: IdentTopic,
msg: Message,
Expand Down
2 changes: 1 addition & 1 deletion src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ pub(crate) async fn start(
message_gates
.message_in(&Topic::HotStuffRsSend(local_public_address).hash(), envelope)
.await;
} else if let Err(e) = swarm.behaviour_mut().broadcast(topic.into(), message) {
} else if let Err(e) = swarm.behaviour_mut().publish(topic.into(), message) {
log::debug!("{:?}", e);
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@
//! // ...
//!
//! // 3. Start P2P network.
//! let network = pchain_network::NetworkHandle::start(network_config, subscribe_topics, message_gate_chain).await;
//! let network = pchain_network::Peer::start(network_config, subscribe_topics, message_gate_chain).await;
//!
//! // 4. Send out messages.
//! network.broadcast_mempool_tx_msg(txn);
//! network.broadcast_mempool_msg(txn);

pub mod config;
pub use config::Config;
Expand Down
4 changes: 2 additions & 2 deletions src/network_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//! This is the entry point to the pchain_network library. It starts a ParallelChain Network peer
//! and keeps the peer alive -- the peer stops working when the thread is dropped.
//!
//! To send a message in the P2P network, call `.broadcast_mempool_tx_msg()`, `broadcast_dropped_tx_msg`,
//! `broadcast_consensus_msg` or `.send_to()` directly.
//! To send a message in the P2P network, call `.broadcast_mempool_msg()`, `broadcast_dropped_txn_msg`,
//! `broadcast_hotstuff_rs_msg` or `.send_hotstuff_rs_msg()` directly.

use crate::Config;
use crate::engine;
Expand Down