aboutsummaryrefslogtreecommitdiff
path: root/src/rpc
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-03-21 10:45:34 +0100
committerAlex Auvolat <alex@adnab.me>2024-03-21 10:45:34 +0100
commit961b4f9af36a7fb5d3a661ac19e8f2c168bb48ae (patch)
tree1022e5606f9fd538df5704fbd3a43df5ffdc013f /src/rpc
parent5225a81dee21603950e7944cd93c40fdb1bd8feb (diff)
downloadgarage-961b4f9af36a7fb5d3a661ac19e8f2c168bb48ae.tar.gz
garage-961b4f9af36a7fb5d3a661ac19e8f2c168bb48ae.zip
[net-fixes] fix issues with local peer address (fix #761)
Diffstat (limited to 'src/rpc')
-rw-r--r--src/rpc/system.rs15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/rpc/system.rs b/src/rpc/system.rs
index 54d589d2..9da1b176 100644
--- a/src/rpc/system.rs
+++ b/src/rpc/system.rs
@@ -16,7 +16,7 @@ use tokio::sync::{watch, Notify};
use garage_net::endpoint::{Endpoint, EndpointHandler};
use garage_net::message::*;
-use garage_net::peering::PeeringManager;
+use garage_net::peering::{PeerConnState, PeeringManager};
use garage_net::util::parse_and_resolve_peer_addr_async;
use garage_net::{NetApp, NetworkKey, NodeID, NodeKey};
@@ -142,7 +142,7 @@ pub struct NodeStatus {
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct KnownNodeInfo {
pub id: Uuid,
- pub addr: SocketAddr,
+ pub addr: Option<SocketAddr>,
pub is_up: bool,
pub last_seen_secs_ago: Option<u64>,
pub status: NodeStatus,
@@ -381,7 +381,11 @@ impl System {
.iter()
.map(|n| KnownNodeInfo {
id: n.id.into(),
- addr: n.addr,
+ addr: match n.state {
+ PeerConnState::Ourself => self.rpc_public_addr,
+ PeerConnState::Connected { addr } => Some(addr),
+ _ => None,
+ },
is_up: n.is_up(),
last_seen_secs_ago: n
.last_seen
@@ -722,7 +726,10 @@ impl System {
.peering
.get_peer_list()
.iter()
- .map(|n| (n.id.into(), n.addr))
+ .filter_map(|n| match n.state {
+ PeerConnState::Connected { addr } => Some((n.id.into(), addr)),
+ _ => None,
+ })
.collect::<Vec<_>>();
// Before doing it, we read the current peer list file (if it exists)