Skip to content

Commit

Permalink
add is_listening API to JobDeclaratorClient
Browse files Browse the repository at this point in the history
  • Loading branch information
plebhash committed Feb 1, 2025
1 parent 4e0e563 commit db3fc1d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 28 deletions.
13 changes: 4 additions & 9 deletions roles/jd-client/src/lib/job_declarator/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use roles_logic_sv2::{
template_distribution_sv2::SetNewPrevHash,
utils::{hash_lists_tuple, Mutex},
};
use std::{collections::HashMap, convert::TryInto, str::FromStr};
use std::{collections::HashMap, convert::TryInto};
use stratum_common::bitcoin::{util::psbt::serialize::Deserialize, Transaction};
use tokio::task::AbortHandle;
use tracing::{error, info};
Expand All @@ -25,7 +25,7 @@ use roles_logic_sv2::{
utils::Id,
};
use std::{
net::{IpAddr, SocketAddr},
net::SocketAddr,
sync::Arc,
};

Expand Down Expand Up @@ -90,17 +90,12 @@ impl JobDeclarator {
.await
.expect("impossible to connect");

let proxy_address = SocketAddr::new(
IpAddr::from_str(&config.downstream_address).unwrap(),
config.downstream_port,
);

info!(
"JD proxy: setupconnection Proxy address: {:?}",
proxy_address
config.listen_address
);

SetupConnectionHandler::setup(&mut receiver, &mut sender, proxy_address)
SetupConnectionHandler::setup(&mut receiver, &mut sender, config.listen_address)
.await
.unwrap();

Expand Down
21 changes: 7 additions & 14 deletions roles/jd-client/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,11 @@ impl JobDeclaratorClient {
}
}


pub fn is_listening(&self) -> bool {
std::net::TcpStream::connect(self.config.listen_address).is_ok()
}

async fn initialize_jd_as_solo_miner(
proxy_config: ProxyConfig,
tx_status: async_channel::Sender<status::Status<'static>>,
Expand All @@ -206,15 +211,9 @@ impl JobDeclaratorClient {
// SubmitSolution and send it to the TemplateReceiver
let (send_solution, recv_solution) = bounded(10);

// Format `Downstream` connection address
let downstream_addr = SocketAddr::new(
IpAddr::from_str(&proxy_config.downstream_address).unwrap(),
proxy_config.downstream_port,
);

// Wait for downstream to connect
let downstream = downstream::listen_for_downstream_mining(
downstream_addr,
proxy_config.listen_address,
None,
send_solution,
proxy_config.withhold,
Expand Down Expand Up @@ -319,12 +318,6 @@ impl JobDeclaratorClient {
panic!()
}

// Format `Downstream` connection address
let downstream_addr = SocketAddr::new(
IpAddr::from_str(&proxy_config.downstream_address).unwrap(),
proxy_config.downstream_port,
);

// Initialize JD part
let mut parts = proxy_config.tp_address.split(':');
let ip_tp = parts.next().unwrap().to_string();
Expand Down Expand Up @@ -355,7 +348,7 @@ impl JobDeclaratorClient {

// Wait for downstream to connect
let downstream = match downstream::listen_for_downstream_mining(
downstream_addr,
proxy_config.listen_address,
Some(upstream),
send_solution,
proxy_config.withhold,
Expand Down
9 changes: 4 additions & 5 deletions roles/jd-client/src/lib/proxy_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use key_utils::{Secp256k1PublicKey, Secp256k1SecretKey};
use roles_logic_sv2::{errors::Error, utils::CoinbaseOutput as CoinbaseOutput_};
use serde::Deserialize;
use std::time::Duration;
use std::net::SocketAddr;
use stratum_common::bitcoin::TxOut;

#[derive(Debug, Deserialize, Clone)]
Expand Down Expand Up @@ -36,8 +37,7 @@ impl TryFrom<&CoinbaseOutput> for CoinbaseOutput_ {

#[derive(Debug, Deserialize, Clone)]
pub struct ProxyConfig {
pub downstream_address: String,
pub downstream_port: u16,
pub listen_address: SocketAddr,
pub max_supported_version: u16,
pub min_supported_version: u16,
pub min_extranonce2_size: u16,
Expand Down Expand Up @@ -118,7 +118,7 @@ impl ProtocolConfig {

impl ProxyConfig {
pub fn new(
listening_address: std::net::SocketAddr,
listen_address: std::net::SocketAddr,
protocol_config: ProtocolConfig,
withhold: bool,
pool_config: PoolConfig,
Expand All @@ -127,8 +127,7 @@ impl ProxyConfig {
timeout: Duration,
) -> Self {
Self {
downstream_address: listening_address.ip().to_string(),
downstream_port: listening_address.port(),
listen_address,
max_supported_version: protocol_config.max_supported_version,
min_supported_version: protocol_config.min_supported_version,
min_extranonce2_size: protocol_config.min_extranonce2_size,
Expand Down

0 comments on commit db3fc1d

Please sign in to comment.