src: rename Node and methods

This commit is contained in:
Ujjwal Sharma 2021-03-31 15:58:08 +05:30 committed by mirsal
parent ba917197fe
commit 7ebae99890
2 changed files with 11 additions and 7 deletions

View File

@ -8,7 +8,7 @@ mod keypair;
use keypair::SSBKeypair;
mod network;
use network::Node;
use network::Peer;
type Config = toml::map::Map<String, toml::Value>;
@ -46,6 +46,10 @@ async fn main() {
let (amt, peer) = socket.recv_from(&mut buf).await.unwrap();
let buf = &mut buf[..amt];
let packet = String::from_utf8(buf.to_vec()).unwrap();
println!("{} {}", peer, Node::from_base64(&packet).to_base64());
println!(
"{} {}",
peer,
Peer::from_discovery_packet(&packet).to_discovery_packet()
);
}
}

View File

@ -9,15 +9,15 @@ enum Protocol {
Wss,
}
pub struct Node {
pub struct Peer {
protocol: Protocol,
host: IpAddr,
port: u16,
pubkey: PublicKey,
}
impl Node {
pub fn to_base64(&self) -> String {
impl Peer {
pub fn to_discovery_packet(&self) -> String {
let proto = match self.protocol {
Protocol::Net => "net",
Protocol::Ws => "ws",
@ -32,7 +32,7 @@ impl Node {
)
}
pub fn from_base64(packet: &str) -> Self {
pub fn from_discovery_packet(packet: &str) -> Self {
let mut packet = packet.splitn(4, ':');
let protocol = match packet.next().unwrap() {
"net" => Protocol::Net,
@ -50,7 +50,7 @@ impl Node {
.parse()
.unwrap();
let pubkey = SSBPublicKey::from_base64(packet.next().unwrap());
Node {
Peer {
protocol,
host,
port,