Enables ENR auto-update based on new listen address (#610)

This commit is contained in:
Age Manning
2019-11-20 15:03:50 +11:00
committed by Paul Hauner
parent e1de30bd64
commit 62d66f1c10
4 changed files with 64 additions and 3 deletions

View File

@@ -103,6 +103,24 @@ impl<TSubstream> Discovery<TSubstream> {
})
}
/// Allows the application layer to update the `ip` and `port` of the local ENR. The second
/// parameter defines whether the port is a TPC port. If false, this is interpreted as a UDP
/// port.
pub fn update_local_enr(&mut self, socket: std::net::SocketAddr, is_tcp: bool) {
// discv5 checks to see if an update is necessary before performing it, so we do not
// need to check here
if self.discovery.update_local_enr_socket(socket, is_tcp) {
let enr = self.discovery.local_enr();
info!(
self.log,
"ENR Updated";
"enr" => enr.to_base64(),
"seq" => enr.seq(),
"address" => format!("{:?}", socket));
}
}
/// Return the nodes local ENR.
pub fn local_enr(&self) -> &Enr {
self.discovery.local_enr()
}