Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7407d20
Add support for multiple upstream connections and configuration loading
bansalayush247 May 26, 2025
33373df
Merge branch 'make-hashpower-configurable'
bansalayush247 May 27, 2025
e480555
Refactor upstream connection handling and router initialization for m…
bansalayush247 May 27, 2025
0067de8
Refactor code for improved readability and maintainability; remove un…
bansalayush247 May 27, 2025
2bd9ea1
Refactor ProxyState and Router for Multi-Upstream Management
bansalayush247 Jun 3, 2025
a02ba62
Enhance multi-upstream functionality: update pool addresses, add deta…
bansalayush247 Jun 3, 2025
c2e6088
Update pool addresses in config and refactor multi-upstream handling …
bansalayush247 Jun 3, 2025
534e435
Implement custom hashrate distribution for multi-upstream management;…
bansalayush247 Jun 4, 2025
5b10e1f
Fix type annotation for abort_handles in monitor function
bansalayush247 Jun 4, 2025
b0221a1
Merge branch 'master' of https://github.com/Bansalayush247/demand-cli
bansalayush247 Jun 4, 2025
8162d3e
feat(router): Enhance Router functionality for multi-pool support
bansalayush247 Jun 5, 2025
893bc22
feat(router): Add hashrate distribution check and improve detailed co…
bansalayush247 Jun 5, 2025
9d4f3cb
feat(router): Refactor hashrate distribution logging for clarity and …
bansalayush247 Jun 5, 2025
b0eae5b
fix(main): Remove debug print statement for config in main function
bansalayush247 Jun 5, 2025
b24c082
feat: Implement hashrate distribution with multi-upstream support
bansalayush247 Jun 6, 2025
572cdfe
Merge master into feature-hashrate-distribution
bansalayush247 Jun 6, 2025
9c464ec
feat: Remove unused aggregated_receiver and clean up code
bansalayush247 Jun 6, 2025
c109d43
feat(router): Update Router struct and methods for improved pool addr…
bansalayush247 Jun 6, 2025
bca55c2
refactor: Clean up code formatting and remove unnecessary whitespace …
bansalayush247 Jun 7, 2025
c476a18
refactor: Remove redundant logging and improve hashrate distribution …
bansalayush247 Jun 7, 2025
dd56427
Delete config.toml
bansalayush247 Jun 7, 2025
4007aca
refactor: clean up configuration structures in code
bansalayush247 Jun 7, 2025
79edbb2
feat: Add multi-upstream hashrate distribution support
bansalayush247 Jun 8, 2025
78f6c7a
Merge branch 'feature-hashrate-distribution' of https://github.com/Ba…
bansalayush247 Jun 8, 2025
1b3e12b
Remove cpuminer-opt directory
bansalayush247 Jun 8, 2025
1302954
feat: Implement ConnectionManager for managing upstream connections a…
bansalayush247 Jun 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/target
/cpuminer-opt
29 changes: 28 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ use std::{
use tracing::{error, info, warn};

use crate::{HashUnit, DEFAULT_SV1_HASHPOWER};

lazy_static! {
pub static ref CONFIG: Configuration = Configuration::load_config();
}

#[derive(Parser)]
struct Args {
#[clap(long)]
Expand Down Expand Up @@ -39,12 +41,14 @@ struct Args {
config_file: Option<PathBuf>,
#[clap(long = "api-server-port", short = 's')]
api_server_port: Option<String>,
#[clap(long = "hashrate-distribution", value_delimiter = ',')]
hashrate_distribution: Option<Vec<f32>>,
}

#[derive(Serialize, Deserialize)]
struct ConfigFile {
token: Option<String>,
tp_address: Option<String>,
token: Option<String>,
pool_addresses: Option<Vec<String>>,
test_pool_addresses: Option<Vec<String>>,
interval: Option<u64>,
Expand All @@ -55,6 +59,7 @@ struct ConfigFile {
test: Option<bool>,
listening_addr: Option<String>,
api_server_port: Option<String>,
hashrate_distribution: Option<Vec<f32>>,
}

pub struct Configuration {
Expand All @@ -70,7 +75,9 @@ pub struct Configuration {
test: bool,
listening_addr: Option<String>,
api_server_port: String,
hashrate_distribution: Option<Vec<f32>>,
}

impl Configuration {
pub fn token() -> Option<String> {
CONFIG.token.clone()
Expand Down Expand Up @@ -137,6 +144,14 @@ impl Configuration {
CONFIG.test
}

pub fn hashrate_distribution() -> Option<Vec<f32>> {
CONFIG.hashrate_distribution.clone()
}

pub fn wants_hashrate_distribution() -> bool {
CONFIG.hashrate_distribution.is_some()
}

// Loads config from CLI, file, or env vars with precedence: CLI > file > env.
fn load_config() -> Self {
let args = Args::parse();
Expand All @@ -157,6 +172,7 @@ impl Configuration {
test: None,
listening_addr: None,
api_server_port: None,
hashrate_distribution: None,
});

let token = args
Expand Down Expand Up @@ -285,6 +301,16 @@ impl Configuration {
.unwrap_or("off".to_string());

let test = args.test || config.test.unwrap_or(false) || std::env::var("TEST").is_ok();
let hashrate_distribution = args
.hashrate_distribution
.or(config.hashrate_distribution)
.or_else(|| {
std::env::var("HASHRATE_DISTRIBUTION").ok().and_then(|s| {
s.split(',')
.map(|s| s.trim().parse::<f32>().ok())
.collect::<Option<Vec<f32>>>()
})
});

Configuration {
token,
Expand All @@ -299,6 +325,7 @@ impl Configuration {
test,
listening_addr,
api_server_port,
hashrate_distribution,
}
}
}
Expand Down
Loading