Skip to content

Commit

Permalink
Create network.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
KOSASIH authored Aug 11, 2024
1 parent 08ae48f commit 73ec612
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions pi-nexus-blockchain/src/network.rs
Original file line number Diff line number Diff line change
@@ -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");
});
}
}
}

0 comments on commit 73ec612

Please sign in to comment.