From 4e0b0b3d1ce50dd4fe5b8e78e905e2851f36846c Mon Sep 17 00:00:00 2001 From: Revertron Date: Mon, 29 Mar 2021 11:10:48 +0200 Subject: [PATCH] Added mining threads count option. --- alfis.toml | 25 +++++++++++++++++++++---- src/blockchain/filter.rs | 3 ++- src/blockchain/transaction.rs | 2 +- src/keys.rs | 7 ++++++- src/miner.rs | 9 +++++++-- src/settings.rs | 11 ++++++++++- src/webview/index.html | 2 +- src/webview/styles.css | 5 +++++ 8 files changed, 53 insertions(+), 11 deletions(-) diff --git a/alfis.toml b/alfis.toml index 22b1801..7285b69 100644 --- a/alfis.toml +++ b/alfis.toml @@ -1,18 +1,35 @@ -# Settings +# Main settings + +# The hash of first block in a chain to know with which nodes to work origin = "00000102C2F9BFD2803284D93327F089D60FC72A06F19AF2384567F2646B8348" +# A path to your key file to load autamatically key_file = "default.key" +# Your node will listen on that address for other nodes to connect listen = "[::]:4244" +# Set true if you want your IP to participate in peer-exchange, or false otherwise public = true # Bootstrap nodes + +# All bootstap nodes #peers = ["test-ip4.alfis.name:4244", "test-ip6.alfis.name:4244"] -peers = ["[300:1251::1]:4244"] +# Yggdrasil nodes only +peers = ["test-ip6.alfis.name:4244"] # DNS server options [dns] +# Your DNS resolver will be listening on this address and port (Usual port is 53) listen = "127.0.0.1:5300" +# How many threads to spawn by DNS server threads = 20 -#AdGuard DNS servers to filter ads and trackers +# AdGuard DNS servers to filter ads and trackers #forwarders = ["94.140.14.14:53", "94.140.15.15:53"] +# Wyrd servers forwarders = ["[301:2522::53]:53", "[303:8b1a::53]:53"] -#forwarders = ["[301:2522::53]:53", "[301:2923::53]:53", "94.140.14.14:53", "94.140.15.15:53"] +# Cloudflare servers +#forwarders = ["1.1.1.1:53", "1.0.0.1:53"] + +#Mining options +[mining] +# How many CPU threads to spawn for mining +threads = 0 \ No newline at end of file diff --git a/src/blockchain/filter.rs b/src/blockchain/filter.rs index 8234a0b..127413c 100644 --- a/src/blockchain/filter.rs +++ b/src/blockchain/filter.rs @@ -32,7 +32,7 @@ impl DnsFilter for BlockchainFilter { subdomain = String::from(parts[2]); } } - debug!("Searching domain {} and record {}", &search, &subdomain); + debug!("Searching record type '{:?}', name '{}' for domain '{}'", &qtype, &subdomain, &search); let data = self.context.lock().unwrap().chain.get_domain_info(&search); match data { @@ -129,6 +129,7 @@ impl DnsFilter for BlockchainFilter { } } + //debug!("Answers: {:?}", &answers); return if !answers.is_empty() { // Create DnsPacket let mut packet = DnsPacket::new(); diff --git a/src/blockchain/transaction.rs b/src/blockchain/transaction.rs index 32fe748..81ab9d0 100644 --- a/src/blockchain/transaction.rs +++ b/src/blockchain/transaction.rs @@ -69,7 +69,7 @@ impl fmt::Debug for Transaction { impl Serialize for Transaction { fn serialize(&self, serializer: S) -> Result<::Ok, ::Error> where S: Serializer { - let mut structure = serializer.serialize_struct("Transaction", 4).unwrap(); + let mut structure = serializer.serialize_struct("Transaction", 5).unwrap(); structure.serialize_field("identity", &self.identity)?; structure.serialize_field("confirmation", &self.confirmation)?; structure.serialize_field("method", &self.method)?; diff --git a/src/keys.rs b/src/keys.rs index f43e7c5..382661b 100644 --- a/src/keys.rs +++ b/src/keys.rs @@ -157,7 +157,12 @@ pub fn create_key(context: Arc>) { let mining = Arc::new(AtomicBool::new(true)); let miners_count = Arc::new(AtomicUsize::new(0)); { context.lock().unwrap().bus.post(Event::KeyGeneratorStarted); } - for _cpu in 0..num_cpus::get() { + let threads = context.lock().unwrap().settings.mining.threads; + let threads = match threads { + 0 => num_cpus::get(), + _ => threads + }; + for _cpu in 0..threads { let context = Arc::clone(&context); let mining = mining.clone(); let miners_count = miners_count.clone(); diff --git a/src/miner.rs b/src/miner.rs index d4bda19..0a23f6d 100644 --- a/src/miner.rs +++ b/src/miner.rs @@ -142,8 +142,13 @@ impl Miner { let thread_spawn_interval = Duration::from_millis(10); let live_threads = Arc::new(AtomicU32::new(0u32)); let cpus = num_cpus::get(); - debug!("Starting {} threads for mining", cpus); - for _cpu in 0..cpus { + let threads = context.lock().unwrap().settings.mining.threads; + let threads = match threads { + 0 => cpus, + _ => threads + }; + debug!("Starting {} threads for mining", threads); + for _cpu in 0..threads { let context = Arc::clone(&context); let job = job.clone(); let mining = Arc::clone(&mining); diff --git a/src/settings.rs b/src/settings.rs index 2cfc808..18a43f5 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -21,6 +21,8 @@ pub struct Settings { pub peers: Vec, #[serde(default)] pub dns: Dns, + #[serde(default)] + pub mining: Mining, } impl Settings { @@ -69,7 +71,8 @@ impl Default for Settings { listen: String::from("[::]:4244"), public: false, peers: vec![], - dns: Default::default() + dns: Default::default(), + mining: Mining::default() } } } @@ -89,6 +92,12 @@ impl Default for Dns { } } +#[derive(Clone, Debug, Default, Serialize, Deserialize)] +pub struct Mining { + #[serde(default)] + pub threads: usize +} + fn default_listen() -> String { String::from("[::]:4244") } diff --git a/src/webview/index.html b/src/webview/index.html index 2a0f7be..01028e8 100644 --- a/src/webview/index.html +++ b/src/webview/index.html @@ -1,5 +1,5 @@ - + diff --git a/src/webview/styles.css b/src/webview/styles.css index 7f151f2..78e3a97 100644 --- a/src/webview/styles.css +++ b/src/webview/styles.css @@ -1,3 +1,8 @@ +html { + overflow-y: auto; + min-width: 768px; +} + .container { margin: 10pt; }