2
0
mirror of https://github.com/Revertron/Alfis synced 2024-11-07 09:20:31 +00:00

First signed block number changed to 35 to be able to get more signers.

Refactored cloning of Arcs.
This commit is contained in:
Revertron 2021-03-23 11:41:50 +01:00
parent 4ddacd2f57
commit 046c06beeb
8 changed files with 34 additions and 34 deletions

View File

@ -5,7 +5,7 @@ pub const BLOCK_DIFFICULTY: u32 = 20;
pub const LOCKER_DIFFICULTY: u32 = 14;
pub const KEYSTORE_DIFFICULTY: usize = 23;
pub const LOCKER_BLOCK_START: u64 = 16;
pub const LOCKER_BLOCK_START: u64 = 35;
pub const LOCKER_BLOCK_LOCKERS: u64 = 7;
pub const LOCKER_BLOCK_SIGNS: u64 = 4;
pub const LOCKER_BLOCK_TIME: i64 = 300;

View File

@ -80,7 +80,7 @@ impl ForwardingDnsResolver {
impl DnsResolver for ForwardingDnsResolver {
fn get_context(&self) -> Arc<ServerContext> {
self.context.clone()
Arc::clone(&self.context)
}
fn perform(&mut self, qname: &str, qtype: QueryType) -> Result<DnsPacket> {
@ -114,7 +114,7 @@ impl RecursiveDnsResolver {
impl DnsResolver for RecursiveDnsResolver {
fn get_context(&self) -> Arc<ServerContext> {
self.context.clone()
Arc::clone(&self.context)
}
fn perform(&mut self, qname: &str, qtype: QueryType) -> Result<DnsPacket> {
@ -242,7 +242,7 @@ mod tests {
None => panic!(),
}
let mut resolver = context.create_resolver(context.clone());
let mut resolver = context.create_resolver(Arc::clone(&context));
// First verify that we get a match back
{
@ -303,7 +303,7 @@ mod tests {
Ok(packet)
}));
let mut resolver = context.create_resolver(context.clone());
let mut resolver = context.create_resolver(Arc::clone(&context));
// Expect failure when no name servers are available
if let Ok(_) = resolver.resolve("google.com", QueryType::A, true) {
@ -319,7 +319,7 @@ mod tests {
Ok(packet)
}));
let mut resolver = context.create_resolver(context.clone());
let mut resolver = context.create_resolver(Arc::clone(&context));
// Expect failure when no name servers are available
if let Ok(_) = resolver.resolve("google.com", QueryType::A, true) {
@ -383,7 +383,7 @@ mod tests {
Ok(packet)
}));
let mut resolver = context.create_resolver(context.clone());
let mut resolver = context.create_resolver(Arc::clone(&context));
// Expect failure when no name servers are available
if let Ok(_) = resolver.resolve("google.com", QueryType::A, true) {
@ -493,7 +493,7 @@ mod tests {
Ok(packet)
}));
let mut resolver = context.create_resolver(context.clone());
let mut resolver = context.create_resolver(Arc::clone(&context));
// Insert name servers
let mut nameservers = Vec::new();

View File

@ -111,7 +111,7 @@ pub fn execute_query(context: Arc<ServerContext>, request: &DnsPacket) -> DnsPac
let question = &request.questions[0];
packet.questions.push(question.clone());
let mut resolver = context.create_resolver(context.clone());
let mut resolver = context.create_resolver(Arc::clone(&context));
let rescode = match resolver.resolve(&question.name, question.qtype, request.header.recursion_desired) {
Ok(result) => {
let rescode = result.header.rescode;
@ -188,7 +188,7 @@ impl DnsServer for DnsUdpServer {
}
};
let context = self.context.clone();
let context = Arc::clone(&self.context);
let request_cond = self.request_cond.clone();
let request_queue = self.request_queue.clone();
@ -222,7 +222,7 @@ impl DnsServer for DnsUdpServer {
// Create a response buffer, and ask the context for an appropriate resolver
let mut res_buffer = VectorPacketBuffer::new();
let mut packet = execute_query(context.clone(), &request);
let mut packet = execute_query(Arc::clone(&context), &request);
let _ = packet.write(&mut res_buffer, size_limit);
// Fire off the response
@ -298,7 +298,7 @@ impl DnsServer for DnsTcpServer {
let (tx, rx) = channel();
self.senders.push(tx);
let context = self.context.clone();
let context = Arc::clone(&self.context);
let name = "DnsTcpServer-request-".to_string() + &thread_id.to_string();
let _ = Builder::new().name(name).spawn(move || {
@ -322,7 +322,7 @@ impl DnsServer for DnsTcpServer {
let mut res_buffer = VectorPacketBuffer::new();
let mut packet = execute_query(context.clone(), &request);
let mut packet = execute_query(Arc::clone(&context), &request);
ignore_or_report!(packet.write(&mut res_buffer, 0xFFFF), "Failed to write packet to buffer");
// As is the case for incoming queries, we need to send a 2 byte length
@ -446,7 +446,7 @@ mod tests {
// A successful resolve
{
let res = execute_query(context.clone(), &build_query("google.com", QueryType::A));
let res = execute_query(Arc::clone(&context), &build_query("google.com", QueryType::A));
assert_eq!(1, res.answers.len());
match res.answers[0] {
@ -460,7 +460,7 @@ mod tests {
// A successful resolve, that also resolves a CNAME without recursive lookup
{
let res = execute_query(
context.clone(),
Arc::clone(&context),
&build_query("www.facebook.com", QueryType::CNAME),
);
assert_eq!(2, res.answers.len());
@ -483,7 +483,7 @@ mod tests {
// A successful resolve, that also resolves a CNAME through recursive lookup
{
let res = execute_query(
context.clone(),
Arc::clone(&context),
&build_query("www.microsoft.com", QueryType::CNAME),
);
assert_eq!(2, res.answers.len());
@ -505,7 +505,7 @@ mod tests {
// An unsuccessful resolve, but without any error
{
let res = execute_query(context.clone(), &build_query("yahoo.com", QueryType::A));
let res = execute_query(Arc::clone(&context), &build_query("yahoo.com", QueryType::A));
assert_eq!(ResultCode::NXDOMAIN, res.header.rescode);
assert_eq!(0, res.answers.len());
};
@ -521,7 +521,7 @@ mod tests {
// This should generate an error code, since recursive resolves are
// no longer allowed
{
let res = execute_query(context.clone(), &build_query("yahoo.com", QueryType::A));
let res = execute_query(Arc::clone(&context), &build_query("yahoo.com", QueryType::A));
assert_eq!(ResultCode::REFUSED, res.header.rescode);
assert_eq!(0, res.answers.len());
};
@ -529,7 +529,7 @@ mod tests {
// Send a query without a question, which should fail with an error code
{
let query_packet = DnsPacket::new();
let res = execute_query(context.clone(), &query_packet);
let res = execute_query(Arc::clone(&context), &query_packet);
assert_eq!(ResultCode::FORMERR, res.header.rescode);
assert_eq!(0, res.answers.len());
};

View File

@ -9,17 +9,17 @@ use log::{debug, error, info, LevelFilter, trace, warn};
/// Starts UDP and TCP DNS-servers
pub fn start_dns_server(context: &Arc<Mutex<Context>>, settings: &Settings) {
let server_context = create_server_context(context.clone(), &settings);
let server_context = create_server_context(Arc::clone(&context), &settings);
if server_context.enable_udp {
let udp_server = DnsUdpServer::new(server_context.clone(), settings.dns.threads);
let udp_server = DnsUdpServer::new(Arc::clone(&server_context), settings.dns.threads);
if let Err(e) = udp_server.run_server() {
error!("Failed to bind UDP listener: {:?}", e);
}
}
if server_context.enable_tcp {
let tcp_server = DnsTcpServer::new(server_context.clone(), settings.dns.threads);
let tcp_server = DnsTcpServer::new(Arc::clone(&server_context), settings.dns.threads);
if let Err(e) = tcp_server.run_server() {
error!("Failed to bind TCP listener: {:?}", e);
}

View File

@ -140,7 +140,7 @@ pub fn create_key(context: Arc<Mutex<Context>>) {
let miners_count = Arc::new(AtomicUsize::new(0));
{ context.lock().unwrap().bus.post(Event::KeyGeneratorStarted); }
for _cpu in 0..num_cpus::get() {
let context = context.clone();
let context = Arc::clone(&context);
let mining = mining.clone();
let miners_count = miners_count.clone();
thread::spawn(move || {

View File

@ -105,11 +105,11 @@ fn main() {
let context: Arc<Mutex<Context>> = Arc::new(Mutex::new(Context::new(env!("CARGO_PKG_VERSION").to_owned(), settings, keystore, chain)));
dns_utils::start_dns_server(&context, &settings_copy);
let mut miner_obj = Miner::new(context.clone());
let mut miner_obj = Miner::new(Arc::clone(&context));
miner_obj.start_mining_thread();
let miner: Arc<Mutex<Miner>> = Arc::new(Mutex::new(miner_obj));
let mut network = Network::new(context.clone());
let mut network = Network::new(Arc::clone(&context));
network.start().expect("Error starting network component");
create_genesis_if_needed(&context, &miner);
@ -120,7 +120,7 @@ fn main() {
}
} else {
#[cfg(feature = "webgui")]
web_ui::run_interface(context.clone(), miner.clone());
web_ui::run_interface(Arc::clone(&context), miner.clone());
}
// Without explicitly detaching the console cmd won't redraw it's prompt.

View File

@ -27,7 +27,7 @@ pub struct Miner {
impl Miner {
pub fn new(context: Arc<Mutex<Context>>) -> Self {
Miner {
context: context.clone(),
context,
blocks: Arc::new(Mutex::new(Vec::new())),
running: Arc::new(AtomicBool::new(false)),
mining: Arc::new(AtomicBool::new(false)),
@ -47,7 +47,7 @@ impl Miner {
}
pub fn start_mining_thread(&mut self) {
let context = self.context.clone();
let context = Arc::clone(&self.context);
let blocks = self.blocks.clone();
let running = self.running.clone();
let mining = self.mining.clone();
@ -66,7 +66,7 @@ impl Miner {
info!("Got new block to mine");
let block = lock.remove(0);
mining.store(true, Ordering::SeqCst);
Miner::mine_internal(context.clone(), block, mining.clone());
Miner::mine_internal(Arc::clone(&context), block, mining.clone());
} else {
let _ = cond_var.wait(lock).expect("Error in wait lock!");
}

View File

@ -48,7 +48,7 @@ impl Network {
let mut events = Events::with_capacity(64);
let mut poll = Poll::new().expect("Unable to create poll");
poll.registry().register(&mut server, SERVER, Interest::READABLE).expect("Error registering poll");
let context = self.context.clone();
let context = Arc::clone(&self.context);
thread::spawn(move || {
// Give UI some time to appear :)
thread::sleep(Duration::from_millis(2000));
@ -100,7 +100,7 @@ impl Network {
poll.registry().reregister(&mut server, SERVER, Interest::READABLE).expect("Error reregistering server");
}
token => {
if !handle_connection_event(context.clone(), &mut peers, &poll.registry(), &event) {
if !handle_connection_event(Arc::clone(&context), &mut peers, &poll.registry(), &event) {
let _ = peers.close_peer(poll.registry(), &token);
let mut context = context.lock().unwrap();
let blocks_count = context.chain.height();
@ -121,7 +121,7 @@ impl Network {
}
(height, context.chain.last_hash())
};
mine_locker_block(context.clone());
mine_locker_block(Arc::clone(&context));
peers.send_pings(poll.registry(), height, hash);
peers.connect_new_peers(poll.registry(), &mut unique_token);
}
@ -147,7 +147,7 @@ fn handle_connection_event(context: Arc<Mutex<Context>>, peers: &mut Peers, regi
match Message::from_bytes(data) {
Ok(message) => {
let m = format!("{:?}", &message);
let new_state = handle_message(context.clone(), message, peers, &event.token());
let new_state = handle_message(Arc::clone(&context), message, peers, &event.token());
let peer = peers.get_mut_peer(&event.token()).unwrap();
debug!("Got message from {}: {:?}", &peer.get_addr(), &m);
let stream = peer.get_stream();
@ -377,7 +377,7 @@ fn handle_message(context: Arc<Mutex<Context>>, message: Message, peers: &mut Pe
return State::Banned;
}
}
let context = context.clone();
let context = Arc::clone(&context);
let peers_count = peers.get_peers_active_count();
thread::spawn(move || {
let mut context = context.lock().unwrap();