Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hostnames in config #861

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
44 changes: 17 additions & 27 deletions roles/jd-client/src/lib/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ pub mod status;
pub mod template_receiver;
pub mod upstream_sv2;

use std::{sync::atomic::AtomicBool, time::Duration};
use std::{net::ToSocketAddrs, sync::atomic::AtomicBool, time::Duration};

use job_declarator::JobDeclarator;
use proxy_config::ProxyConfig;
Expand Down Expand Up @@ -191,12 +191,12 @@ impl JobDeclaratorClient {
.unwrap();

// Initialize JD part
let mut parts = proxy_config.tp_address.split(':');
let ip_tp = parts.next().unwrap().to_string();
let port_tp = parts.next().unwrap().parse::<u16>().unwrap();
let tp_addr = proxy_config.tp_address.to_socket_addrs()
.unwrap_or_else(|e| panic!("Invalid tproxy address {}: {}", proxy_config.tp_address, e))
.next().unwrap();

TemplateRx::connect(
SocketAddr::new(IpAddr::from_str(ip_tp.as_str()).unwrap(), port_tp),
tp_addr,
recv_solution,
status::Sender::TemplateReceiver(tx_status.clone()),
None,
Expand All @@ -223,20 +223,9 @@ impl JobDeclaratorClient {
.unwrap_or(false);

// Format `Upstream` connection address
let mut parts = upstream_config.pool_address.split(':');
let address = parts
.next()
.unwrap_or_else(|| panic!("Invalid pool address {}", upstream_config.pool_address));
let port = parts
.next()
.and_then(|p| p.parse::<u16>().ok())
.unwrap_or_else(|| panic!("Invalid pool address {}", upstream_config.pool_address));
let upstream_addr = SocketAddr::new(
IpAddr::from_str(address).unwrap_or_else(|_| {
panic!("Invalid pool address {}", upstream_config.pool_address)
}),
port,
);
let upstream_addr = upstream_config.pool_address.to_socket_addrs()
.unwrap_or_else(|_| panic!("Invalid pool address {}", upstream_config.pool_address))
.next().unwrap();

// When Downstream receive a share that meets bitcoin target it transformit in a
// SubmitSolution and send it to the TemplateReceiver
Expand Down Expand Up @@ -288,15 +277,16 @@ impl JobDeclaratorClient {
);

// Initialize JD part
let mut parts = proxy_config.tp_address.split(':');
let ip_tp = parts.next().unwrap().to_string();
let port_tp = parts.next().unwrap().parse::<u16>().unwrap();
let tp_addr = proxy_config.tp_address.to_socket_addrs()
.unwrap_or_else(|e| panic!("Invalid tproxy address {}: {}", proxy_config.tp_address, e))
.next().unwrap();

let jd_addr = upstream_config.jd_address.to_socket_addrs()
.unwrap_or_else(|e| panic!("Invalid jds address {}: {}", upstream_config.jd_address, e))
.next().unwrap();

let mut parts = upstream_config.jd_address.split(':');
let ip_jd = parts.next().unwrap().to_string();
let port_jd = parts.next().unwrap().parse::<u16>().unwrap();
let jd = match JobDeclarator::new(
SocketAddr::new(IpAddr::from_str(ip_jd.as_str()).unwrap(), port_jd),
jd_addr,
upstream_config.authority_pubkey.into_bytes(),
proxy_config.clone(),
upstream.clone(),
Expand Down Expand Up @@ -333,7 +323,7 @@ impl JobDeclaratorClient {
.unwrap();

TemplateRx::connect(
SocketAddr::new(IpAddr::from_str(ip_tp.as_str()).unwrap(), port_tp),
tp_addr,
recv_solution,
status::Sender::TemplateReceiver(tx_status.clone()),
Some(jd.clone()),
Expand Down
3 changes: 2 additions & 1 deletion roles/pool/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#![allow(special_module_name)]
use async_channel::{bounded, unbounded};

use std::net::ToSocketAddrs;
use tracing::{error, info, warn};
mod lib;
use lib::{
Expand Down Expand Up @@ -123,7 +124,7 @@ async fn main() {
};
let tp_authority_public_key = config.tp_authority_public_key;
let template_rx_res = TemplateRx::connect(
config.tp_address.parse().unwrap(),
config.tp_address.to_socket_addrs().unwrap().next().unwrap(),
s_new_t,
s_prev_hash,
r_solution,
Expand Down
18 changes: 13 additions & 5 deletions roles/translator/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use proxy_config::ProxyConfig;
use rand::Rng;
use roles_logic_sv2::utils::Mutex;
use std::{
net::{IpAddr, SocketAddr},
net::{IpAddr, SocketAddr, ToSocketAddrs},
str::FromStr,
sync::Arc,
};
Expand Down Expand Up @@ -185,11 +185,19 @@ async fn start<'a>(
let (tx_sv2_set_new_prev_hash, rx_sv2_set_new_prev_hash) = bounded(10);

// Format `Upstream` connection address
let upstream_addr = SocketAddr::new(
IpAddr::from_str(&proxy_config.upstream_address)
.expect("Failed to parse upstream address!"),
let upstream_addr = (
proxy_config.upstream_address.as_str(),
proxy_config.upstream_port,
);
)
.to_socket_addrs()
.unwrap_or_else(|e| {
panic!(
"Invalid upstream address {}:{}: {}",
proxy_config.upstream_address, proxy_config.upstream_port, e
)
})
.next()
.unwrap();

let diff_config = Arc::new(Mutex::new(proxy_config.upstream_difficulty_config.clone()));
let task_collector_upstream = task_collector.clone();
Expand Down