Correct ENR update and log formatting (#651)

This commit is contained in:
Age Manning 2019-11-30 17:49:45 +11:00 committed by GitHub
parent cbe8dd96b2
commit e025217185
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 5 deletions

View File

@ -77,7 +77,7 @@ impl<TSubstream> Discovery<TSubstream> {
None => String::from(""),
};
info!(log, "ENR Initialised"; "ENR" => local_enr.to_base64(), "Seq" => local_enr.seq());
info!(log, "ENR Initialised"; "enr" => local_enr.to_base64(), "seq" => local_enr.seq());
debug!(log, "Discv5 Node ID Initialised"; "node_id" => format!("{}",local_enr.node_id()));
// the last parameter enables IP limiting. 2 Nodes on the same /24 subnet per bucket and 10
@ -110,8 +110,8 @@ 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
/// Allows the application layer to update the `IP` and `port` of the local ENR. The second
/// parameter defines whether the port is a TCP 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
@ -251,7 +251,7 @@ where
}
Ok(Async::NotReady) => break,
Err(e) => {
warn!(self.log, "Discovery peer search failed"; "Error" => format!("{:?}", e));
warn!(self.log, "Discovery peer search failed"; "error" => format!("{:?}", e));
}
}
}
@ -266,7 +266,7 @@ where
// query.
}
Discv5Event::SocketUpdated(socket) => {
info!(self.log, "Address updated"; "IP" => format!("{}",socket.ip()));
info!(self.log, "Address updated"; "ip" => format!("{}",socket.ip()), "port" => format!("{}", socket.port()));
metrics::inc_counter(&metrics::ADDRESS_UPDATE_COUNT);
let mut address = Multiaddr::from(socket.ip());
address.push(Protocol::Tcp(self.tcp_port));

View File

@ -204,6 +204,11 @@ where
&mut self,
out: <RPCProtocol as InboundUpgrade<TSubstream>>::Output,
) {
// update the keep alive timeout if there are no more remaining outbound streams
if let KeepAlive::Until(_) = self.keep_alive {
self.keep_alive = KeepAlive::Until(Instant::now() + self.inactive_timeout);
}
let (req, substream) = out;
// drop the stream and return a 0 id for goodbye "requests"
if let r @ RPCRequest::Goodbye(_) = req {

View File

@ -219,6 +219,7 @@ impl Stream for Service {
if !self.verified_listen_address {
let multiaddr = Swarm::listeners(&self.swarm).next();
if let Some(multiaddr) = multiaddr {
self.verified_listen_address = true;
if let Some(socket_addr) = multiaddr_to_socket_addr(multiaddr) {
self.swarm.update_local_enr_socket(socket_addr, true);
}