mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
stop channel once seed process is done and disconnect.
This commit is contained in:
@@ -10,6 +10,7 @@ use std::net::{SocketAddr, TcpStream};
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
use crate::error;
|
||||
use crate::net::error::{NetError, NetResult};
|
||||
use crate::net::message_subscriber::{
|
||||
MessageSubscriber, MessageSubscriberPtr, MessageSubscription,
|
||||
@@ -87,6 +88,13 @@ impl Channel {
|
||||
self.stop_subscriber.notify(stop_err).await;
|
||||
}
|
||||
|
||||
fn is_eof_error(err: &error::Error) -> bool {
|
||||
match err {
|
||||
error::Error::Io(io_err) => io_err.kind() == std::io::ErrorKind::UnexpectedEof,
|
||||
_ => false
|
||||
}
|
||||
}
|
||||
|
||||
async fn receive_loop(self: Arc<Self>) -> NetResult<()> {
|
||||
let stop_sub = self.clone().subscribe_stop().await;
|
||||
let reader = &mut *self.reader.lock().await;
|
||||
@@ -97,7 +105,11 @@ impl Channel {
|
||||
match message_result {
|
||||
Ok(message) => Ok(Arc::new(message)),
|
||||
Err(err) => {
|
||||
error!("Read error on channel: {}", err);
|
||||
if Self::is_eof_error(&err) {
|
||||
info!("Closing channel {} disconnected", self.address());
|
||||
} else {
|
||||
error!("Read error on channel: {}", err);
|
||||
}
|
||||
self.stop().await;
|
||||
Err(NetError::ChannelStopped)
|
||||
}
|
||||
|
||||
@@ -343,6 +343,7 @@ pub async fn read_packet<R: AsyncRead + Unpin>(stream: &mut R) -> Result<Packet>
|
||||
// Packets have a 4 byte header of magic digits
|
||||
// This is used for network debugging
|
||||
let mut magic = [0u8; 4];
|
||||
//debug!("reading magic...");
|
||||
stream.read_exact(&mut magic).await?;
|
||||
//debug!("read magic {:?}", magic);
|
||||
if magic != MAGIC_BYTES {
|
||||
|
||||
@@ -94,9 +94,11 @@ impl SeedSession {
|
||||
let protocol_ping = ProtocolPing::new(channel.clone(), settings.clone());
|
||||
protocol_ping.start(executor.clone()).await;
|
||||
|
||||
let protocol_seed = ProtocolSeed::new(channel, hosts, settings.clone());
|
||||
let protocol_seed = ProtocolSeed::new(channel.clone(), hosts, settings.clone());
|
||||
protocol_seed.start(executor.clone()).await?;
|
||||
|
||||
channel.stop().await;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user