Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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,242 changes: 1,195 additions & 47 deletions Cargo.lock

Large diffs are not rendered by default.

23 changes: 23 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ struct Args {
adjustment_interval: Option<u64>,
#[clap(long)]
token: Option<String>,
#[clap(long = "max-token-changes-per-connection")]
max_token_changes_per_connection: Option<u32>,
#[clap(long)]
tp_address: Option<String>,
#[clap(long)]
Expand All @@ -64,6 +66,7 @@ struct Args {
#[derive(Serialize, Deserialize)]
struct ConfigFile {
token: Option<String>,
max_token_changes_per_connection: Option<u32>,
tp_address: Option<String>,
interval: Option<u64>,
delay: Option<u64>,
Expand All @@ -85,6 +88,7 @@ impl ConfigFile {
pub fn default() -> Self {
ConfigFile {
token: None,
max_token_changes_per_connection: None,
tp_address: None,
interval: None,
delay: None,
Expand All @@ -107,6 +111,7 @@ impl ConfigFile {
#[derive(Debug)]
pub struct Configuration {
token: Option<String>,
max_token_changes_per_connection: u32,
tp_address: Option<String>,
interval: u64,
delay: u64,
Expand All @@ -129,6 +134,7 @@ impl Configuration {
#[allow(clippy::too_many_arguments)]
pub fn new(
token: Option<String>,
max_token_changes_per_connection: u32,
tp_address: Option<String>,
interval: u64,
delay: u64,
Expand All @@ -149,6 +155,7 @@ impl Configuration {
) -> Self {
Configuration {
token,
max_token_changes_per_connection,
tp_address,
interval,
delay,
Expand Down Expand Up @@ -179,6 +186,7 @@ impl Configuration {
fn default_for_tests() -> Self {
Self::new(
Some("test_token".to_string()),
0,
None,
120_000,
0,
Expand Down Expand Up @@ -217,6 +225,10 @@ impl Configuration {
Self::cfg().token.clone()
}

pub fn max_token_changes_per_connection() -> u32 {
Self::cfg().max_token_changes_per_connection
}

pub fn tp_address() -> Option<String> {
Self::cfg().tp_address.clone()
}
Expand Down Expand Up @@ -349,6 +361,16 @@ impl Configuration {
.or_else(|| std::env::var("TOKEN").ok());
println!("User Token: {token:?}");

let max_token_changes_per_connection = args
.max_token_changes_per_connection
.or(config.max_token_changes_per_connection)
.or_else(|| {
std::env::var("MAX_TOKEN_CHANGES_PER_CONNECTION")
.ok()
.and_then(|s| s.parse().ok())
})
.unwrap_or(0);

let signature = match args.signature {
Some(s) => {
if s.len() == 2 {
Expand Down Expand Up @@ -469,6 +491,7 @@ impl Configuration {

Configuration {
token,
max_token_changes_per_connection,
tp_address,
interval,
delay,
Expand Down
15 changes: 10 additions & 5 deletions src/ingress/sv1_ingress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,7 @@ pub fn start_listen_for_downstream(
let down_addr: String = Configuration::downstream_listening_addr()
.unwrap_or(crate::DEFAULT_LISTEN_ADDRESS.to_string());
let downstream_addr: SocketAddr = down_addr.parse().expect("Invalid listen address");
info!(
"Trying to bind to address {} for downstream(miner) connections",
downstream_addr
);
let downstream_listener = TcpListener::bind(downstream_addr)
let downstream_listener = bind_downstream_listener(downstream_addr)
.await
.expect("impossible to bind downstream");
info!(
Expand All @@ -49,6 +45,15 @@ pub fn start_listen_for_downstream(
})
.into()
}

pub async fn bind_downstream_listener(downstream_addr: SocketAddr) -> std::io::Result<TcpListener> {
info!(
"Trying to bind to address {} for downstream(miner) connections",
downstream_addr
);
TcpListener::bind(downstream_addr).await
}

struct Downstream {}

impl Downstream {
Expand Down
2 changes: 2 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ mod shared;
mod shutdown;
mod translator;

pub use ingress::sv1_ingress::bind_downstream_listener;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you export it?


const TRANSLATOR_BUFFER_SIZE: usize = 32;
const MIN_EXTRANONCE_SIZE: u16 = 6;
const MIN_EXTRANONCE2_SIZE: u16 = 5;
Expand Down
2 changes: 2 additions & 0 deletions src/translator/downstream/accept_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub async fn start_accept_connection(
upstream_difficulty_config: Arc<Mutex<UpstreamDifficultyConfig>>,
mut downstreams: Receiver<(Sender<String>, Receiver<String>, IpAddr)>,
stats_sender: crate::api::stats::StatsSender,
shared_token_state: Arc<Mutex<super::downstream::TokenChangeTracker>>,
tx_update_token: Sender<String>,
) -> Result<(), Error<'static>> {
let handle = {
Expand Down Expand Up @@ -102,6 +103,7 @@ pub async fn start_accept_connection(
task_manager.clone(),
initial_difficulty,
stats_sender.clone(),
shared_token_state.clone(),
tx_update_token.clone(),
)
.await
Expand Down
2 changes: 2 additions & 0 deletions src/translator/downstream/diff_management.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ mod test {
Arc::new(Mutex::new(upstream_config)),
crate::api::stats::StatsSender::new(),
first_job,
String::new(),
1,
tx_update_token,
);
downstream.difficulty_mgmt.estimated_downstream_hash_rate = start_hashrate as f32;
Expand Down
Loading
Loading