Skip to content

Commit

Permalink
fix(agent): fix broadcast and snarkos_get RPCs failing for specified …
Browse files Browse the repository at this point in the history
…bind addresses
  • Loading branch information
Meshiest committed Sep 10, 2024
1 parent 142fb0f commit ed9c41b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 9 deletions.
8 changes: 8 additions & 0 deletions crates/snops-agent/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,14 @@ impl Cli {
std::process::exit(0);
}

pub fn get_local_ip(&self) -> IpAddr {
if self.bind_addr.is_unspecified() {
IpAddr::V4(Ipv4Addr::LOCALHOST)
} else {
self.bind_addr
}
}

pub fn endpoint_and_uri(&self) -> (String, Uri) {
// get the endpoint
let endpoint = self
Expand Down
9 changes: 2 additions & 7 deletions crates/snops-agent/src/metrics/mod.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
pub mod tps;

use std::{
collections::HashMap,
net::{IpAddr, Ipv4Addr, SocketAddr},
sync::Arc,
time::Duration,
};
use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration};

use self::tps::TpsMetric;
use crate::state::GlobalState;
Expand Down Expand Up @@ -39,7 +34,7 @@ pub fn init(state: Arc<GlobalState>) {
let response = match client
.get(format!(
"http://{}/",
SocketAddr::new(IpAddr::V4(Ipv4Addr::LOCALHOST), state.cli.ports.metrics)
SocketAddr::new(state.cli.get_local_ip(), state.cli.ports.metrics)
))
.send()
.await
Expand Down
6 changes: 4 additions & 2 deletions crates/snops-agent/src/rpc/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,8 @@ impl AgentService for AgentRpcServer {
.network;

let url = format!(
"http://127.0.0.1:{}/{network}{route}",
"http://{}:{}/{network}{route}",
self.state.cli.get_local_ip(),
self.state.cli.ports.rest
);
let response = reqwest::get(&url)
Expand Down Expand Up @@ -460,7 +461,8 @@ impl AgentService for AgentRpcServer {
.network;

let url = format!(
"http://127.0.0.1:{}/{network}/transaction/broadcast",
"http://{}:{}/{network}/transaction/broadcast",
self.state.cli.get_local_ip(),
self.state.cli.ports.rest
);
let response = reqwest::Client::new()
Expand Down

0 comments on commit ed9c41b

Please sign in to comment.