Skip to content

Commit 1017438

Browse files
committed
feat: add get_peer_address_if_connected helper method
Add a helper method that returns a peer's socket address by first checking active connections and falling back to stored peer information if no active connection exists. This provides a convenient way to look up peer addresses with a preference for currently active connections.
1 parent 22cb1df commit 1017438

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/lib.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,23 @@ impl Node {
11441144
},
11451145
}
11461146
}
1147+
1148+
/// Returns the address of a peer if we're already connected to them.
1149+
fn get_peer_address_if_connected(&self, node_id: &PublicKey) -> Option<SocketAddress> {
1150+
// First check if we have an active connection with an address
1151+
if let Some(peer) = self.peer_manager.peer_by_node_id(node_id) {
1152+
if let Some(addr) = peer.socket_address {
1153+
return Some(addr);
1154+
}
1155+
}
1156+
1157+
// If not, check if we have a stored address for this peer
1158+
if let Some(peer_info) = self.peer_store.get_peer(node_id) {
1159+
return Some(peer_info.address);
1160+
}
1161+
1162+
None
1163+
}
11471164

11481165
/// Connect to a node and open a new unannounced channel.
11491166
///
@@ -1215,6 +1232,7 @@ impl Node {
12151232
return Err(Error::ChannelCreationFailed);
12161233
}
12171234
}
1235+
12181236

12191237
/// Manually sync the LDK and BDK wallets with the current chain state and update the fee rate
12201238
/// cache.

0 commit comments

Comments
 (0)