Skip to content

Commit ed9c41b

Browse files
committed
fix(agent): fix broadcast and snarkos_get RPCs failing for specified bind addresses
1 parent 142fb0f commit ed9c41b

File tree

3 files changed

+14
-9
lines changed

3 files changed

+14
-9
lines changed

crates/snops-agent/src/cli.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,14 @@ impl Cli {
101101
std::process::exit(0);
102102
}
103103

104+
pub fn get_local_ip(&self) -> IpAddr {
105+
if self.bind_addr.is_unspecified() {
106+
IpAddr::V4(Ipv4Addr::LOCALHOST)
107+
} else {
108+
self.bind_addr
109+
}
110+
}
111+
104112
pub fn endpoint_and_uri(&self) -> (String, Uri) {
105113
// get the endpoint
106114
let endpoint = self

crates/snops-agent/src/metrics/mod.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
pub mod tps;
22

3-
use std::{
4-
collections::HashMap,
5-
net::{IpAddr, Ipv4Addr, SocketAddr},
6-
sync::Arc,
7-
time::Duration,
8-
};
3+
use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration};
94

105
use self::tps::TpsMetric;
116
use crate::state::GlobalState;
@@ -39,7 +34,7 @@ pub fn init(state: Arc<GlobalState>) {
3934
let response = match client
4035
.get(format!(
4136
"http://{}/",
42-
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), state.cli.ports.metrics)
37+
SocketAddr::new(state.cli.get_local_ip(), state.cli.ports.metrics)
4338
))
4439
.send()
4540
.await

crates/snops-agent/src/rpc/control.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ impl AgentService for AgentRpcServer {
428428
.network;
429429

430430
let url = format!(
431-
"http://127.0.0.1:{}/{network}{route}",
431+
"http://{}:{}/{network}{route}",
432+
self.state.cli.get_local_ip(),
432433
self.state.cli.ports.rest
433434
);
434435
let response = reqwest::get(&url)
@@ -460,7 +461,8 @@ impl AgentService for AgentRpcServer {
460461
.network;
461462

462463
let url = format!(
463-
"http://127.0.0.1:{}/{network}/transaction/broadcast",
464+
"http://{}:{}/{network}/transaction/broadcast",
465+
self.state.cli.get_local_ip(),
464466
self.state.cli.ports.rest
465467
);
466468
let response = reqwest::Client::new()

0 commit comments

Comments
 (0)