mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-01-09 22:57:59 -05:00
net,dht,error: Include the endpoint address in connector error messages so upstream code can log it. In transport mixing scenarios, the mixed URL will appear in logs.
This commit is contained in:
@@ -566,7 +566,7 @@ impl<H: DhtHandler> Dht<H> {
|
||||
return Err(Error::ConnectTimeout);
|
||||
};
|
||||
if connect_res.is_err() {
|
||||
warn!(target: "dht::get_channel()", "Error while connecting to {addr}: {}", connect_res.unwrap_err());
|
||||
warn!(target: "dht::get_channel()", "Error while connecting: {}", connect_res.unwrap_err());
|
||||
continue;
|
||||
}
|
||||
let (_, channel) = connect_res.unwrap();
|
||||
|
||||
@@ -115,8 +115,8 @@ pub enum Error {
|
||||
#[error("Transport request exceeds number of accepted transports")]
|
||||
InvalidTransportRequest,
|
||||
|
||||
#[error("Connection failed")]
|
||||
ConnectFailed,
|
||||
#[error("Connection failed: {0}")]
|
||||
ConnectFailed(String),
|
||||
|
||||
#[cfg(feature = "system")]
|
||||
#[error(transparent)]
|
||||
@@ -146,8 +146,8 @@ pub enum Error {
|
||||
#[error("Accept a new tls connection from the listener {0} failed")]
|
||||
AcceptTlsConnectionFailed(String),
|
||||
|
||||
#[error("Connector stopped")]
|
||||
ConnectorStopped,
|
||||
#[error("Connector stopped: {0}")]
|
||||
ConnectorStopped(String),
|
||||
|
||||
#[error("Network operation failed")]
|
||||
NetworkOperationFailed,
|
||||
|
||||
@@ -59,7 +59,7 @@ impl Connector {
|
||||
let hosts = self.session.upgrade().unwrap().p2p().hosts();
|
||||
if hosts.container.contains(HostColor::Black as usize, url) || hosts.block_all_ports(url) {
|
||||
warn!(target: "net::connector::connect", "Peer {url} is blacklisted");
|
||||
return Err(Error::ConnectFailed)
|
||||
return Err(Error::ConnectFailed(format!("[{url}]: Peer is blacklisted")));
|
||||
}
|
||||
|
||||
let settings = self.settings.read().await;
|
||||
@@ -86,7 +86,11 @@ impl Connector {
|
||||
(url.clone(), false)
|
||||
};
|
||||
|
||||
let dialer = Dialer::new(endpoint.clone(), datastore, Some(i2p_socks5_proxy)).await?;
|
||||
let dialer = match Dialer::new(endpoint.clone(), datastore, Some(i2p_socks5_proxy)).await {
|
||||
Ok(dialer) => dialer,
|
||||
Err(err) => return Err(Error::ConnectFailed(format!("[{endpoint}]: {err}"))),
|
||||
};
|
||||
|
||||
let timeout = Duration::from_secs(outbound_connect_timeout);
|
||||
|
||||
let stop_fut = async {
|
||||
@@ -121,10 +125,10 @@ impl Connector {
|
||||
.ipv6_available
|
||||
.store(false, Ordering::SeqCst);
|
||||
}
|
||||
Err(e.into())
|
||||
Err(Error::ConnectFailed(format!("[{endpoint}]: {e}")))
|
||||
}
|
||||
|
||||
Either::Right((_, _)) => Err(Error::ConnectorStopped),
|
||||
Either::Right((_, _)) => Err(Error::ConnectorStopped(format!("[{endpoint}]"))),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1133,7 +1133,7 @@ impl Hosts {
|
||||
// This will error if we are already connected to this peer, this peer
|
||||
// is suspended, or this peer is currently being inserted into the hostlist.
|
||||
// None of these scenarios should ever happen.
|
||||
if let Err(e) = self.try_register(address.clone(), HostState::Connected(channel.clone())) {
|
||||
if let Err(e) = self.try_register(address, HostState::Connected(channel.clone())) {
|
||||
warn!(target: "net::hosts::register_channel", "Error while registering channel {channel:?}: {e:?}");
|
||||
return
|
||||
}
|
||||
|
||||
@@ -185,7 +185,7 @@ impl Slot {
|
||||
}
|
||||
|
||||
match self.connector.connect(&self.addr).await {
|
||||
Ok((url, channel)) => {
|
||||
Ok((_, channel)) => {
|
||||
info!(
|
||||
target: "net::manual_session",
|
||||
"[P2P] Manual outbound connected [{}]",
|
||||
@@ -209,12 +209,25 @@ impl Slot {
|
||||
);
|
||||
}
|
||||
Err(e) => {
|
||||
self.handle_failure(e, &url);
|
||||
warn!(
|
||||
target: "net::manual_session",
|
||||
"[P2P] Unable to connect to manual outbound [{}]: {e}",
|
||||
channel.display_address(),
|
||||
);
|
||||
|
||||
// Free up this addr for future operations.
|
||||
self.p2p().hosts().unregister(channel.address());
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
self.handle_failure(e, &self.addr);
|
||||
warn!(
|
||||
target: "net::manual_session",
|
||||
"[P2P] Unable to connect to manual outbound: {e}",
|
||||
);
|
||||
|
||||
// Free up this addr for future operations.
|
||||
self.p2p().hosts().unregister(&self.addr);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,17 +241,6 @@ impl Slot {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_failure(&self, error: Error, addr: &Url) {
|
||||
warn!(
|
||||
target: "net::manual_session",
|
||||
"[P2P] Unable to connect to manual outbound [{}]: {error}",
|
||||
self.addr
|
||||
);
|
||||
|
||||
// Free up this addr for future operations.
|
||||
self.p2p().hosts().unregister(addr);
|
||||
}
|
||||
|
||||
fn session(&self) -> ManualSessionPtr {
|
||||
self.session.upgrade().unwrap()
|
||||
}
|
||||
|
||||
@@ -306,7 +306,7 @@ impl Slot {
|
||||
addr: host.clone(),
|
||||
});
|
||||
|
||||
let (addr, channel) = match self.try_connect(host.clone(), last_seen).await {
|
||||
let (_, channel) = match self.try_connect(host.clone(), last_seen).await {
|
||||
Ok(connect_info) => connect_info,
|
||||
Err(err) => {
|
||||
debug!(
|
||||
@@ -397,15 +397,15 @@ impl Slot {
|
||||
Err(err) => {
|
||||
info!(
|
||||
target: "net::outbound_session::try_connect()",
|
||||
"[P2P] Unable to connect outbound slot #{} [{addr}]: {err}",
|
||||
"[P2P] Unable to connect outbound slot #{} {err}",
|
||||
self.slot
|
||||
);
|
||||
|
||||
// Immediately return if the Connector has stopped.
|
||||
// This indicates a shutdown of the P2P network and
|
||||
// should not result in hostlist modifications.
|
||||
if let Error::ConnectorStopped = err {
|
||||
return Err(Error::ConnectFailed);
|
||||
if let Error::ConnectorStopped(message) = err {
|
||||
return Err(Error::ConnectFailed(message));
|
||||
}
|
||||
|
||||
// At this point we failed to connect. We'll downgrade this peer now.
|
||||
@@ -415,9 +415,9 @@ impl Slot {
|
||||
self.p2p().hosts().try_register(addr.clone(), HostState::Suspend).unwrap();
|
||||
|
||||
// Notify that channel processing failed
|
||||
self.p2p().hosts().channel_publisher.notify(Err(Error::ConnectFailed)).await;
|
||||
self.p2p().hosts().channel_publisher.notify(Err(err.clone())).await;
|
||||
|
||||
Err(Error::ConnectFailed)
|
||||
Err(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,7 +163,7 @@ impl RefineSession {
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
debug!(target: "net::refinery::handshake_node()", "Failed to connect to {addr}, ({e})");
|
||||
debug!(target: "net::refinery::handshake_node()", "Failed to connect ({e})");
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ impl Slot {
|
||||
}
|
||||
|
||||
match self.connector.connect(&self.addr).await {
|
||||
Ok((url, ch)) => {
|
||||
Ok((_, ch)) => {
|
||||
info!(
|
||||
target: "net::session::seedsync_session",
|
||||
"[P2P] Connected seed [{}]",
|
||||
@@ -242,7 +242,12 @@ impl Slot {
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
self.handle_failure(e, ch.address());
|
||||
warn!(
|
||||
target: "net::session::seedsync_session",
|
||||
"[P2P] Unable to connect to seed [{}]: {e}",
|
||||
ch.display_address()
|
||||
);
|
||||
self.handle_failure(ch.address());
|
||||
|
||||
continue
|
||||
}
|
||||
@@ -250,7 +255,11 @@ impl Slot {
|
||||
}
|
||||
|
||||
Err(e) => {
|
||||
self.handle_failure(e, &self.addr);
|
||||
warn!(
|
||||
target: "net::session::seedsync_session",
|
||||
"[P2P] Unable to connect to seed: {e}",
|
||||
);
|
||||
self.handle_failure(&self.addr);
|
||||
|
||||
continue
|
||||
}
|
||||
@@ -262,13 +271,7 @@ impl Slot {
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_failure(&self, error: Error, addr: &Url) {
|
||||
warn!(
|
||||
target: "net::session::seedsync_session",
|
||||
"[P2P] Unable to connect to seed [{}]: {error}",
|
||||
self.addr
|
||||
);
|
||||
|
||||
fn handle_failure(&self, addr: &Url) {
|
||||
self.failed.store(true, SeqCst);
|
||||
|
||||
// Free up this addr for future operations.
|
||||
|
||||
Reference in New Issue
Block a user