|
|
@@ -141,7 +141,7 @@ impl Channel {
|
|
|
/// Starts the channel. Runs a receive loop to start receiving messages or
|
|
|
/// handles a network failure.
|
|
|
pub fn start(self: Arc<Self>, executor: Arc<Executor<'_>>) {
|
|
|
- debug!(target: "net::channel", "Channel::start() [START, address={}]", self.address());
|
|
|
+ debug!(target: "net::channel::start()", "START, address={}", self.address());
|
|
|
let self2 = self.clone();
|
|
|
self.receive_task.clone().start(
|
|
|
self.clone().main_receive_loop(),
|
|
|
@@ -149,31 +149,28 @@ impl Channel {
|
|
|
Error::NetworkServiceStopped,
|
|
|
executor,
|
|
|
);
|
|
|
- debug!(target: "net::channel", "Channel::start() [END, address={}]", self.address());
|
|
|
+ debug!(target: "net::channel::start()", "END, address={}", self.address());
|
|
|
}
|
|
|
|
|
|
/// Stops the channel. Steps through each component of the channel
|
|
|
/// connection and sends a stop signal. Notifies all subscribers that
|
|
|
/// the channel has been closed.
|
|
|
pub async fn stop(&self) {
|
|
|
- debug!(target: "net::channel", "Channel::stop() [START, address={}]", self.address());
|
|
|
+ debug!(target: "net::channel::stop()", "START, address={}", self.address());
|
|
|
if !(*self.stopped.lock().await) {
|
|
|
*self.stopped.lock().await = true;
|
|
|
|
|
|
self.stop_subscriber.notify(Error::ChannelStopped).await;
|
|
|
self.receive_task.stop().await;
|
|
|
self.message_subsystem.trigger_error(Error::ChannelStopped).await;
|
|
|
- debug!(target: "net::channel", "Channel::stop() [END, address={}]", self.address());
|
|
|
+ debug!(target: "net::channel::stop()", "END, address={}", self.address());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/// Creates a subscription to a stopped signal.
|
|
|
/// If the channel is stopped then this will return a ChannelStopped error.
|
|
|
pub async fn subscribe_stop(&self) -> Result<Subscription<Error>> {
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::subscribe_stop() [START, address={}]",
|
|
|
- self.address()
|
|
|
- );
|
|
|
+ debug!(target: "net::channel::subscribe_stop()", "START, address={}", self.address());
|
|
|
|
|
|
{
|
|
|
let stopped = *self.stopped.lock().await;
|
|
|
@@ -183,10 +180,7 @@ impl Channel {
|
|
|
}
|
|
|
|
|
|
let sub = self.stop_subscriber.clone().subscribe().await;
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::subscribe_stop() [END, address={}]",
|
|
|
- self.address()
|
|
|
- );
|
|
|
+ debug!(target: "net::channel::subscribe_stop()", "END, address={}", self.address());
|
|
|
|
|
|
Ok(sub)
|
|
|
}
|
|
|
@@ -195,10 +189,11 @@ impl Channel {
|
|
|
/// creates a new payload and sends it over the TCP connection as a
|
|
|
/// packet. Returns an error if something goes wrong.
|
|
|
pub async fn send<M: message::Message>(&self, message: M) -> Result<()> {
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::send() [START, command={:?}, address={}]",
|
|
|
- M::name(),
|
|
|
- self.address()
|
|
|
+ debug!(
|
|
|
+ target: "net::channel::send()",
|
|
|
+ "START, command={:?}, address={}",
|
|
|
+ M::name(),
|
|
|
+ self.address()
|
|
|
);
|
|
|
|
|
|
{
|
|
|
@@ -212,16 +207,17 @@ impl Channel {
|
|
|
let result = match self.send_message(message).await {
|
|
|
Ok(()) => Ok(()),
|
|
|
Err(err) => {
|
|
|
- error!(target: "net::channel", "Channel send error for [{}]: {}", self.address(), err);
|
|
|
+ error!(target: "net::channel::send()", "Channel send error for [{}]: {}", self.address(), err);
|
|
|
self.stop().await;
|
|
|
Err(Error::ChannelStopped)
|
|
|
}
|
|
|
};
|
|
|
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::send() [END, command={:?}, address={}]",
|
|
|
- M::name(),
|
|
|
- self.address()
|
|
|
+ debug!(
|
|
|
+ target: "net::channel::send()",
|
|
|
+ "END, command={:?}, address={}",
|
|
|
+ M::name(),
|
|
|
+ self.address()
|
|
|
);
|
|
|
{
|
|
|
let info = &mut *self.info.lock().await;
|
|
|
@@ -256,16 +252,18 @@ impl Channel {
|
|
|
|
|
|
/// Subscribe to a messages on the message subsystem.
|
|
|
pub async fn subscribe_msg<M: message::Message>(&self) -> Result<MessageSubscription<M>> {
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::subscribe_msg() [START, command={:?}, address={}]",
|
|
|
- M::name(),
|
|
|
- self.address()
|
|
|
+ debug!(
|
|
|
+ target: "net::channel::subscribe_msg()",
|
|
|
+ "START, command={:?}, address={}",
|
|
|
+ M::name(),
|
|
|
+ self.address()
|
|
|
);
|
|
|
let sub = self.message_subsystem.subscribe::<M>().await;
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::subscribe_msg() [END, command={:?}, address={}]",
|
|
|
- M::name(),
|
|
|
- self.address()
|
|
|
+ debug!(
|
|
|
+ target: "net::channel::subscribe_msg()",
|
|
|
+ "END, command={:?}, address={}",
|
|
|
+ M::name(),
|
|
|
+ self.address()
|
|
|
);
|
|
|
sub
|
|
|
}
|
|
|
@@ -309,10 +307,7 @@ impl Channel {
|
|
|
/// Run the receive loop. Start receiving messages or handle network
|
|
|
/// failure.
|
|
|
async fn main_receive_loop(self: Arc<Self>) -> Result<()> {
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::receive_loop() [START, address={}]",
|
|
|
- self.address()
|
|
|
- );
|
|
|
+ debug!(target: "net::channel::main_receive_loop()", "START, address={}", self.address());
|
|
|
|
|
|
let reader = &mut *self.reader.lock().await;
|
|
|
|
|
|
@@ -321,13 +316,23 @@ impl Channel {
|
|
|
Ok(packet) => packet,
|
|
|
Err(err) => {
|
|
|
if Self::is_eof_error(err.clone()) {
|
|
|
- info!(target: "net::channel", "Inbound connection {} disconnected", self.address());
|
|
|
+ info!(
|
|
|
+ target: "net::channel::main_receive_loop()",
|
|
|
+ "Inbound connection {} disconnected",
|
|
|
+ self.address()
|
|
|
+ );
|
|
|
} else {
|
|
|
- error!(target: "net::channel", "Read error on channel {}: {}", self.address(), err);
|
|
|
+ error!(
|
|
|
+ target: "net::channel::main_receive_loop()",
|
|
|
+ "Read error on channel {}: {}",
|
|
|
+ self.address(),
|
|
|
+ err
|
|
|
+ );
|
|
|
}
|
|
|
- debug!(target: "net::channel",
|
|
|
- "Channel::receive_loop() stopping channel {}",
|
|
|
- self.address()
|
|
|
+ debug!(
|
|
|
+ target: "net::channel::main_receive_loop()",
|
|
|
+ "Channel::receive_loop() stopping channel {}",
|
|
|
+ self.address()
|
|
|
);
|
|
|
self.stop().await;
|
|
|
return Err(Error::ChannelStopped)
|
|
|
@@ -352,7 +357,11 @@ impl Channel {
|
|
|
/// Handle network errors. Panic if error passes silently, otherwise
|
|
|
/// broadcast the error.
|
|
|
async fn handle_stop(self: Arc<Self>, result: Result<()>) {
|
|
|
- debug!(target: "net::channel", "Channel::handle_stop() [START, address={}]", self.address());
|
|
|
+ debug!(
|
|
|
+ target: "net::channel::handle_stop()",
|
|
|
+ "START, address={}",
|
|
|
+ self.address()
|
|
|
+ );
|
|
|
match result {
|
|
|
Ok(()) => panic!("Channel task should never complete without error status"),
|
|
|
Err(err) => {
|
|
|
@@ -360,7 +369,11 @@ impl Channel {
|
|
|
self.message_subsystem.trigger_error(err).await;
|
|
|
}
|
|
|
}
|
|
|
- debug!(target: "net::channel", "Channel::handle_stop() [END, address={}]", self.address());
|
|
|
+ debug!(
|
|
|
+ target: "net::channel::handle_stop()",
|
|
|
+ "END, address={}",
|
|
|
+ self.address()
|
|
|
+ );
|
|
|
}
|
|
|
|
|
|
fn session(&self) -> Arc<dyn Session> {
|