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:
Revertron
2021-03-06 21:28:06 +01:00
parent 59df68d7c7
commit b0e78edb3d
12 changed files with 465 additions and 147 deletions
+9 -1
View File
@@ -6,6 +6,8 @@ use std::io::Write;
use std::path::Path;
use std::sync::{LockResult, RwLock, RwLockReadGuard, RwLockWriteGuard};
#[allow(unused_imports)]
use log::{trace, debug, info, warn, error};
use derive_more::{Display, From, Error};
use crate::dns::buffer::{PacketBuffer, StreamPacketBuffer, VectorPacketBuffer};
@@ -71,7 +73,13 @@ impl<'a> Zones {
}
pub fn load(&mut self) -> Result<()> {
let zones_dir = Path::new("zones").read_dir()?;
let zones_dir = match Path::new("zones").read_dir() {
Ok(result) => { result }
Err(_) => {
debug!("Authority dir (zones) not found, skipping.");
return Ok(());
}
};
for wrapped_filename in zones_dir {
let filename = match wrapped_filename {
+1 -5
View File
@@ -1,6 +1,5 @@
//! The `ServerContext in this thread holds the common state across the server
use std::fs;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::Arc;
@@ -70,7 +69,7 @@ impl ServerContext {
authority: Authority::new(),
cache: SynchronizedCache::new(),
filters: Vec::new(),
client: Box::new(DnsNetworkClient::new(34255)),
client: Box::new(DnsNetworkClient::new(10000 + (rand::random::<u16>() % 20000))),
dns_host: String::from("0.0.0.0"),
dns_port: 53,
api_port: 5380,
@@ -88,9 +87,6 @@ impl ServerContext {
}
pub fn initialize(&mut self) -> Result<()> {
// Create zones directory if it doesn't exist
fs::create_dir_all(self.zones_dir)?;
// Start UDP client thread
self.client.run()?;