Implemented P2P traffic encryption.
Changed serialization format of P2P messages. Refactored P2P network code.
This commit is contained in:
@@ -3,6 +3,7 @@ use std::collections::HashMap;
|
||||
use mio::net::TcpStream;
|
||||
use crate::p2p::State;
|
||||
use crate::Block;
|
||||
use crate::crypto::Chacha;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Peer {
|
||||
@@ -16,6 +17,7 @@ pub struct Peer {
|
||||
active: bool,
|
||||
reconnects: u32,
|
||||
received_block: u64,
|
||||
cipher: Option<Chacha>,
|
||||
fork: HashMap<u64, Block>
|
||||
}
|
||||
|
||||
@@ -32,10 +34,26 @@ impl Peer {
|
||||
active: false,
|
||||
reconnects: 0,
|
||||
received_block: 0,
|
||||
cipher: None,
|
||||
fork: HashMap::new()
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_cipher(&mut self, cipher: Chacha) {
|
||||
self.cipher = Some(cipher);
|
||||
}
|
||||
|
||||
pub fn get_cipher(&self) -> &Option<Chacha> {
|
||||
&self.cipher
|
||||
}
|
||||
|
||||
pub fn get_nonce(&self) -> &[u8; 12] {
|
||||
match &self.cipher {
|
||||
None => { &crate::crypto::ZERO_NONCE }
|
||||
Some(chacha) => { chacha.get_nonce() }
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_addr(&self) -> SocketAddr {
|
||||
self.addr.clone()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user