Skip to content

Commit

Permalink
add is_listening API to TranslatorSv2
Browse files Browse the repository at this point in the history
  • Loading branch information
plebhash committed Feb 1, 2025
1 parent db3fc1d commit eb48675
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 19 deletions.
4 changes: 1 addition & 3 deletions roles/tests-integration/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ pub async fn start_sv2_translator(upstream: SocketAddr) -> (TranslatorSv2, Socke
)
.expect("failed");
let listening_address = get_available_address();
let listening_port = listening_address.port();
let hashrate = measure_hashrate(1) as f32 / 100.0;
let min_individual_miner_hashrate = hashrate;
let shares_per_minute = 60.0;
Expand All @@ -229,8 +228,7 @@ pub async fn start_sv2_translator(upstream: SocketAddr) -> (TranslatorSv2, Socke
upstream_difficulty_config,
);
let downstream_conf = translator_sv2::proxy_config::DownstreamConfig::new(
listening_address.ip().to_string(),
listening_port,
listening_address,
downstream_difficulty_config,
);

Expand Down
12 changes: 5 additions & 7 deletions roles/translator/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,16 +266,10 @@ impl TranslatorSv2 {
);
proxy::Bridge::start(b.clone());

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

let task_collector_downstream = task_collector_init_task.clone();
// Accept connections from one or more SV1 Downstream roles (SV1 Mining Devices)
downstream_sv1::Downstream::accept_connections(
downstream_addr,
proxy_config.listen_address,
tx_sv1_bridge,
tx_sv1_notify,
status::Sender::DownstreamListener(tx_status.clone()),
Expand All @@ -297,6 +291,10 @@ impl TranslatorSv2 {
pub fn shutdown(&self) {
self.shutdown.notify_one();
}

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

fn kill_tasks(task_collector: Arc<Mutex<Vec<(AbortHandle, String)>>>) {
Expand Down
15 changes: 6 additions & 9 deletions roles/translator/src/lib/proxy_config.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use key_utils::Secp256k1PublicKey;
use serde::Deserialize;
use std::net::SocketAddr;

#[derive(Debug, Deserialize, Clone)]
pub struct ProxyConfig {
pub upstream_address: String,
pub upstream_port: u16,
pub upstream_authority_pubkey: Secp256k1PublicKey,
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 @@ -39,16 +39,14 @@ impl UpstreamConfig {
}

pub struct DownstreamConfig {
address: String,
port: u16,
listen_address: SocketAddr,
difficulty_config: DownstreamDifficultyConfig,
}

impl DownstreamConfig {
pub fn new(address: String, port: u16, difficulty_config: DownstreamDifficultyConfig) -> Self {
pub fn new(listen_address: SocketAddr, difficulty_config: DownstreamDifficultyConfig) -> Self {
Self {
address,
port,
listen_address,
difficulty_config,
}
}
Expand All @@ -66,8 +64,7 @@ impl ProxyConfig {
upstream_address: upstream.address,
upstream_port: upstream.port,
upstream_authority_pubkey: upstream.authority_pubkey,
downstream_address: downstream.address,
downstream_port: downstream.port,
listen_address: downstream.listen_address,
max_supported_version,
min_supported_version,
min_extranonce2_size,
Expand Down

0 comments on commit eb48675

Please sign in to comment.