Changed origin block index to 1. Added "locker" blocks - mining, exchange etc. Removed unnecesarry creation of 'zones' directory on startup. Changed bind port of DNS-UDP socket to random (fixes inability to start several copies of Alfis). Sped up block exchange by sending additional pings when we have more blocks than other peers. Fixed unnecesarry double requests of blocks. Totally reworked block checking on arrival. Added target tags for logging in main. Added a commandline flag to list all blocks in DB and exit.
This commit is contained in:
+26
-2
@@ -1,6 +1,8 @@
|
||||
use crate::p2p::State;
|
||||
use std::net::SocketAddr;
|
||||
use std::collections::HashMap;
|
||||
use mio::net::TcpStream;
|
||||
use crate::p2p::State;
|
||||
use crate::Block;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Peer {
|
||||
@@ -11,11 +13,13 @@ pub struct Peer {
|
||||
inbound: bool,
|
||||
public: bool,
|
||||
active: bool,
|
||||
received_block: u64,
|
||||
fork: HashMap<u64, Block>
|
||||
}
|
||||
|
||||
impl Peer {
|
||||
pub fn new(addr: SocketAddr, stream: TcpStream, state: State, inbound: bool) -> Self {
|
||||
Peer { addr, stream, state, height: 0, inbound, public: false, active: false }
|
||||
Peer { addr, stream, state, height: 0, inbound, public: false, active: false, received_block: 0, fork: HashMap::new() }
|
||||
}
|
||||
|
||||
pub fn get_addr(&self) -> SocketAddr {
|
||||
@@ -46,6 +50,18 @@ impl Peer {
|
||||
self.height > height
|
||||
}
|
||||
|
||||
pub fn is_lower(&self, height: u64) -> bool {
|
||||
self.height < height
|
||||
}
|
||||
|
||||
pub fn set_received_block(&mut self, index: u64) {
|
||||
self.received_block = index;
|
||||
}
|
||||
|
||||
pub fn has_more_blocks(&self, height: u64) -> bool {
|
||||
self.height > self.received_block && self.height > height && self.get_state().is_idle()
|
||||
}
|
||||
|
||||
pub fn is_public(&self) -> bool {
|
||||
self.public
|
||||
}
|
||||
@@ -70,6 +86,14 @@ impl Peer {
|
||||
self.inbound
|
||||
}
|
||||
|
||||
pub fn add_fork_block(&mut self, block: Block) {
|
||||
self.fork.insert(block.index, block);
|
||||
}
|
||||
|
||||
pub fn get_fork(&self) -> &HashMap<u64, Block> {
|
||||
&self.fork
|
||||
}
|
||||
|
||||
/// If loopback address then we care about ip and port.
|
||||
/// If regular address then we only care about the ip and ignore the port.
|
||||
pub fn equals(&self, addr: &SocketAddr) -> bool {
|
||||
|
||||
Reference in New Issue
Block a user