Skip to content

Commit 6013b20

Browse files
committed
add is_listening API to TranslatorSv2
1 parent 4f33fa1 commit 6013b20

File tree

3 files changed

+12
-19
lines changed

3 files changed

+12
-19
lines changed

roles/tests-integration/lib/mod.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ pub async fn start_sv2_translator(upstream: SocketAddr) -> (TranslatorSv2, Socke
203203
)
204204
.expect("failed");
205205
let listening_address = get_available_address();
206-
let listening_port = listening_address.port();
207206
let hashrate = measure_hashrate(1) as f32 / 100.0;
208207
let min_individual_miner_hashrate = hashrate;
209208
let shares_per_minute = 60.0;
@@ -229,8 +228,7 @@ pub async fn start_sv2_translator(upstream: SocketAddr) -> (TranslatorSv2, Socke
229228
upstream_difficulty_config,
230229
);
231230
let downstream_conf = translator_sv2::proxy_config::DownstreamConfig::new(
232-
listening_address.ip().to_string(),
233-
listening_port,
231+
listening_address,
234232
downstream_difficulty_config,
235233
);
236234

roles/translator/src/lib/mod.rs

+5-7
Original file line numberDiff line numberDiff line change
@@ -266,16 +266,10 @@ impl TranslatorSv2 {
266266
);
267267
proxy::Bridge::start(b.clone());
268268

269-
// Format `Downstream` connection address
270-
let downstream_addr = SocketAddr::new(
271-
IpAddr::from_str(&proxy_config.downstream_address).unwrap(),
272-
proxy_config.downstream_port,
273-
);
274-
275269
let task_collector_downstream = task_collector_init_task.clone();
276270
// Accept connections from one or more SV1 Downstream roles (SV1 Mining Devices)
277271
downstream_sv1::Downstream::accept_connections(
278-
downstream_addr,
272+
proxy_config.listen_address,
279273
tx_sv1_bridge,
280274
tx_sv1_notify,
281275
status::Sender::DownstreamListener(tx_status.clone()),
@@ -297,6 +291,10 @@ impl TranslatorSv2 {
297291
pub fn shutdown(&self) {
298292
self.shutdown.notify_one();
299293
}
294+
295+
pub fn is_listening(&self) -> bool {
296+
std::net::TcpStream::connect(self.config.listen_address).is_ok()
297+
}
300298
}
301299

302300
fn kill_tasks(task_collector: Arc<Mutex<Vec<(AbortHandle, String)>>>) {

roles/translator/src/lib/proxy_config.rs

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
use key_utils::Secp256k1PublicKey;
22
use serde::Deserialize;
3+
use std::net::SocketAddr;
34

45
#[derive(Debug, Deserialize, Clone)]
56
pub struct ProxyConfig {
67
pub upstream_address: String,
78
pub upstream_port: u16,
89
pub upstream_authority_pubkey: Secp256k1PublicKey,
9-
pub downstream_address: String,
10-
pub downstream_port: u16,
10+
pub listen_address: SocketAddr,
1111
pub max_supported_version: u16,
1212
pub min_supported_version: u16,
1313
pub min_extranonce2_size: u16,
@@ -39,16 +39,14 @@ impl UpstreamConfig {
3939
}
4040

4141
pub struct DownstreamConfig {
42-
address: String,
43-
port: u16,
42+
listen_address: SocketAddr,
4443
difficulty_config: DownstreamDifficultyConfig,
4544
}
4645

4746
impl DownstreamConfig {
48-
pub fn new(address: String, port: u16, difficulty_config: DownstreamDifficultyConfig) -> Self {
47+
pub fn new(listen_address: SocketAddr, difficulty_config: DownstreamDifficultyConfig) -> Self {
4948
Self {
50-
address,
51-
port,
49+
listen_address,
5250
difficulty_config,
5351
}
5452
}
@@ -66,8 +64,7 @@ impl ProxyConfig {
6664
upstream_address: upstream.address,
6765
upstream_port: upstream.port,
6866
upstream_authority_pubkey: upstream.authority_pubkey,
69-
downstream_address: downstream.address,
70-
downstream_port: downstream.port,
67+
listen_address: downstream.listen_address,
7168
max_supported_version,
7269
min_supported_version,
7370
min_extranonce2_size,

0 commit comments

Comments
 (0)