Skip to content

Commit 683931c

Browse files
committed
feat: helper to get neighbor address of local peer, given its public IP address
1 parent 7b7067b commit 683931c

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

stackslib/src/net/db.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,21 @@ impl LocalPeer {
185185
)),
186186
}
187187
}
188+
189+
/// Best-effort attempt to calculate a publicly-routable neighbor address for local peer
190+
pub fn to_public_neighbor_addr(&self) -> NeighborAddress {
191+
if let Some((peer_addr, peer_port)) = self.public_ip_address.as_ref() {
192+
NeighborAddress {
193+
addrbytes: peer_addr.clone(),
194+
port: *peer_port,
195+
public_key_hash: Hash160::from_node_public_key(&StacksPublicKey::from_private(
196+
&self.private_key,
197+
)),
198+
}
199+
} else {
200+
self.to_neighbor_addr()
201+
}
202+
}
188203
}
189204

190205
impl FromRow<LocalPeer> for LocalPeer {

0 commit comments

Comments
 (0)