mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-06-23 21:21:06 +00:00
Show the remote PeerId in the handler's logs (#2057)
This commit is contained in:
@@ -93,9 +93,10 @@ where
|
|||||||
{
|
{
|
||||||
type Handler = CustomProtoHandler<TMessage, TSubstream>;
|
type Handler = CustomProtoHandler<TMessage, TSubstream>;
|
||||||
|
|
||||||
fn into_handler(self, _: &PeerId) -> Self::Handler {
|
fn into_handler(self, remote_peer_id: &PeerId) -> Self::Handler {
|
||||||
CustomProtoHandler {
|
CustomProtoHandler {
|
||||||
protocol: self.protocol,
|
protocol: self.protocol,
|
||||||
|
remote_peer_id: remote_peer_id.clone(),
|
||||||
state: ProtocolState::Init {
|
state: ProtocolState::Init {
|
||||||
substreams: SmallVec::new(),
|
substreams: SmallVec::new(),
|
||||||
init_deadline: Delay::new(Instant::now() + Duration::from_secs(5))
|
init_deadline: Delay::new(Instant::now() + Duration::from_secs(5))
|
||||||
@@ -114,6 +115,10 @@ pub struct CustomProtoHandler<TMessage, TSubstream> {
|
|||||||
/// State of the communications with the remote.
|
/// State of the communications with the remote.
|
||||||
state: ProtocolState<TMessage, TSubstream>,
|
state: ProtocolState<TMessage, TSubstream>,
|
||||||
|
|
||||||
|
/// Identifier of the node we're talking to. Used only for logging purposes and shouldn't have
|
||||||
|
/// any influence on the behaviour.
|
||||||
|
remote_peer_id: PeerId,
|
||||||
|
|
||||||
/// Queue of events to send to the outside.
|
/// Queue of events to send to the outside.
|
||||||
///
|
///
|
||||||
/// This queue must only ever be modified to insert elements at the back, or remove the first
|
/// This queue must only ever be modified to insert elements at the back, or remove the first
|
||||||
@@ -360,7 +365,8 @@ where
|
|||||||
fn enable(&mut self, endpoint: Endpoint) {
|
fn enable(&mut self, endpoint: Endpoint) {
|
||||||
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
||||||
ProtocolState::Poisoned => {
|
ProtocolState::Poisoned => {
|
||||||
error!(target: "sub-libp2p", "Handler is in poisoned state");
|
error!(target: "sub-libp2p", "Handler with {:?} is in poisoned state",
|
||||||
|
self.remote_peer_id);
|
||||||
ProtocolState::Poisoned
|
ProtocolState::Poisoned
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -416,7 +422,8 @@ where
|
|||||||
fn disable(&mut self) {
|
fn disable(&mut self) {
|
||||||
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
||||||
ProtocolState::Poisoned => {
|
ProtocolState::Poisoned => {
|
||||||
error!(target: "sub-libp2p", "Handler is in poisoned state");
|
error!(target: "sub-libp2p", "Handler with {:?} is in poisoned state",
|
||||||
|
self.remote_peer_id);
|
||||||
ProtocolState::Poisoned
|
ProtocolState::Poisoned
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -473,7 +480,8 @@ where
|
|||||||
let return_value;
|
let return_value;
|
||||||
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
||||||
ProtocolState::Poisoned => {
|
ProtocolState::Poisoned => {
|
||||||
error!(target: "sub-libp2p", "Handler is in poisoned state; shutting down");
|
error!(target: "sub-libp2p", "Handler with {:?} is in poisoned state",
|
||||||
|
self.remote_peer_id);
|
||||||
return_value = None;
|
return_value = None;
|
||||||
ProtocolState::Poisoned
|
ProtocolState::Poisoned
|
||||||
}
|
}
|
||||||
@@ -481,7 +489,8 @@ where
|
|||||||
ProtocolState::Init { substreams, mut init_deadline } => {
|
ProtocolState::Init { substreams, mut init_deadline } => {
|
||||||
match init_deadline.poll() {
|
match init_deadline.poll() {
|
||||||
Ok(Async::Ready(())) =>
|
Ok(Async::Ready(())) =>
|
||||||
error!(target: "sub-libp2p", "Handler initialization process is too long"),
|
error!(target: "sub-libp2p", "Handler initialization process is too long \
|
||||||
|
with {:?}", self.remote_peer_id),
|
||||||
Ok(Async::NotReady) => {}
|
Ok(Async::NotReady) => {}
|
||||||
Err(_) => error!(target: "sub-libp2p", "Tokio timer has errored")
|
Err(_) => error!(target: "sub-libp2p", "Tokio timer has errored")
|
||||||
}
|
}
|
||||||
@@ -596,13 +605,15 @@ where
|
|||||||
) {
|
) {
|
||||||
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
self.state = match mem::replace(&mut self.state, ProtocolState::Poisoned) {
|
||||||
ProtocolState::Poisoned => {
|
ProtocolState::Poisoned => {
|
||||||
error!(target: "sub-libp2p", "Handler is in poisoned state");
|
error!(target: "sub-libp2p", "Handler with {:?} is in poisoned state",
|
||||||
|
self.remote_peer_id);
|
||||||
ProtocolState::Poisoned
|
ProtocolState::Poisoned
|
||||||
}
|
}
|
||||||
|
|
||||||
ProtocolState::Init { mut substreams, init_deadline } => {
|
ProtocolState::Init { mut substreams, init_deadline } => {
|
||||||
if substream.endpoint() == Endpoint::Dialer {
|
if substream.endpoint() == Endpoint::Dialer {
|
||||||
error!(target: "sub-libp2p", "Opened dialing substream before initialization");
|
error!(target: "sub-libp2p", "Opened dialing substream with {:?} before \
|
||||||
|
initialization", self.remote_peer_id);
|
||||||
}
|
}
|
||||||
substreams.push(substream);
|
substreams.push(substream);
|
||||||
ProtocolState::Init { substreams, init_deadline }
|
ProtocolState::Init { substreams, init_deadline }
|
||||||
@@ -646,7 +657,7 @@ where
|
|||||||
|
|
||||||
ProtocolState::BackCompat { substream: existing, mut shutdown } => {
|
ProtocolState::BackCompat { substream: existing, mut shutdown } => {
|
||||||
warn!(target: "sub-libp2p", "Received extra substream after having already one \
|
warn!(target: "sub-libp2p", "Received extra substream after having already one \
|
||||||
open in backwards-compatibility mode");
|
open in backwards-compatibility mode with {:?}", self.remote_peer_id);
|
||||||
substream.shutdown();
|
substream.shutdown();
|
||||||
shutdown.push(substream);
|
shutdown.push(substream);
|
||||||
ProtocolState::BackCompat { substream: existing, shutdown }
|
ProtocolState::BackCompat { substream: existing, shutdown }
|
||||||
@@ -665,7 +676,8 @@ where
|
|||||||
state.shutdown.push(substream);
|
state.shutdown.push(substream);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
debug!(target: "sub-libp2p", "Opened spurious outbound substream");
|
debug!(target: "sub-libp2p", "Opened spurious outbound substream with {:?}",
|
||||||
|
self.remote_peer_id);
|
||||||
substream.shutdown();
|
substream.shutdown();
|
||||||
state.shutdown.push(substream);
|
state.shutdown.push(substream);
|
||||||
}
|
}
|
||||||
@@ -712,7 +724,7 @@ where
|
|||||||
state.shutdown.push(substream);
|
state.shutdown.push(substream);
|
||||||
} else {
|
} else {
|
||||||
warn!(target: "sub-libp2p", "Libp2p layer received response to a \
|
warn!(target: "sub-libp2p", "Libp2p layer received response to a \
|
||||||
non-existing request ID {:?}", request_id);
|
non-existing request ID {:?} with {:?}", request_id, self.remote_peer_id);
|
||||||
}
|
}
|
||||||
} else if let Some(mut outgoing_substream) = state.outgoing_substream.take() {
|
} else if let Some(mut outgoing_substream) = state.outgoing_substream.take() {
|
||||||
outgoing_substream.send_message(message);
|
outgoing_substream.send_message(message);
|
||||||
@@ -732,7 +744,8 @@ where
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_ => debug!(target: "sub-libp2p", "Tried to send message over closed protocol")
|
_ => debug!(target: "sub-libp2p", "Tried to send message over closed protocol \
|
||||||
|
with {:?}", self.remote_peer_id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user