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
Next Next commit
renamed NetworkHandle to Peer
  • Loading branch information
ong-jonas committed Oct 9, 2023
commit e36f22ea34152f369cbf0d8fbaf9a1748c0af302
6 changes: 3 additions & 3 deletions src/engine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ use crate::{
message_gate::MessageGateChain,
messages::{Envelope, Topic},
network_handle::SendCommand,
NetworkHandle,
Peer,
};

/// [start] p2p networking peer and return the handle [NetworkHandle] of this process.
pub(crate) async fn start(
config: Config,
subscribe_topics: Vec<Topic>,
message_gates: MessageGateChain,
) -> Result<NetworkHandle, Box<dyn Error>> {
) -> Result<Peer, Box<dyn Error>> {
let local_public_address: PublicAddress =
conversions::PublicAddress::try_from(config.keypair.public())
.expect("Invalid PublicKey from configuration")
Expand Down Expand Up @@ -189,7 +189,7 @@ pub(crate) async fn start(
}
});

Ok(NetworkHandle {sender})
Ok(Peer {sender})
}

async fn build_transport(
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub mod messages;
pub mod message_gate;

pub mod network_handle;
pub use network_handle::NetworkHandle;
pub use network_handle::Peer;

pub(crate) mod behaviour;

Expand Down
6 changes: 3 additions & 3 deletions src/network_handle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@ use crate::message_gate::MessageGateChain;
use crate::messages::{DroppedTxMessage, Message, Topic};
use pchain_types::{blockchain::TransactionV1, cryptography::PublicAddress};

/// [NetworkHandle] provides inter-process messaging between application and the p2p
/// [Peer] provides inter-process messaging between application and the p2p
/// network. It started the main thread for the p2p network and handles for the [tokio::task]
/// by calling [crate::engine::start].
#[derive(Clone)]
pub struct NetworkHandle {
pub struct Peer {
/// mpsc sender for delivering message to p2p network
pub(crate) sender: tokio::sync::mpsc::Sender<SendCommand>,
}

impl NetworkHandle {
impl Peer {
pub async fn start(
config: Config,
subscribe_topics: Vec<Topic>,
Expand Down
6 changes: 3 additions & 3 deletions tests/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use pchain_network::{
config::{Config, PeerInfo},
message_gate::{MessageGate, MessageGateChain},
messages::{Topic, Envelope, Message},
NetworkHandle,
Peer,
};
use pchain_types::{blockchain::TransactionV1, cryptography::PublicAddress};

Expand Down Expand Up @@ -290,7 +290,7 @@ pub async fn node(
boot_nodes: Vec<PeerInfo>,
gate_topic: Option<Topic>,
subscribe_topics: Vec<Topic>,
) -> (PublicAddress, NetworkHandle, MessageCounts) {
) -> (PublicAddress, Peer, MessageCounts) {
let keypair: Keypair = Keypair::generate_ed25519();
let address = public_address(&keypair.public());
let config = Config::with_keypair(
Expand All @@ -311,7 +311,7 @@ pub async fn node(
};
let message_chain = MessageGateChain::new().append(gate.clone());

let node = pchain_network::NetworkHandle::start(config, subscribe_topics, message_chain)
let node = pchain_network::Peer::start(config, subscribe_topics, message_chain)
.await;

(address, node, gate)
Expand Down