diff --git a/pi-nexus-blockchain/src/network.rs b/pi-nexus-blockchain/src/network.rs new file mode 100644 index 000000000..8871f094e --- /dev/null +++ b/pi-nexus-blockchain/src/network.rs @@ -0,0 +1,27 @@ +// network.rs (new) + +use crate::blockchain::Blockchain; +use tokio::net::TcpListener; +use tokio::prelude::*; + +pub struct Node { + blockchain: Blockchain, + listener: TcpListener, +} + +impl Node { + pub async fn new(blockchain: Blockchain, addr: &str) -> Self { + let listener = TcpListener::bind(addr).await.unwrap(); + Node { blockchain, listener } + } + + pub async fn start(self) { + println!("Node started on {}", self.listener.local_addr().unwrap()); + while let Ok((mut socket, _)) = self.listener.accept().await { + tokio::spawn(async move { + // TO DO: implement handle incoming connection logic + println!("Incoming connection"); + }); + } + } +}