2020-01-13 16:53:28 +00:00
|
|
|
use crate::{
|
2020-04-24 10:56:04 +00:00
|
|
|
message::{self, InCommingMessage, MessageBuffer, OutGoingMessage},
|
2020-03-22 13:47:21 +00:00
|
|
|
scheduler::Scheduler,
|
2020-04-08 14:26:42 +00:00
|
|
|
types::{Mid, Pid, Prio, Promises, Requestor::User, Sid},
|
2020-01-13 16:53:28 +00:00
|
|
|
};
|
2020-04-08 14:26:42 +00:00
|
|
|
use async_std::{io, sync::RwLock, task};
|
2020-03-22 13:47:21 +00:00
|
|
|
use futures::{
|
|
|
|
channel::{mpsc, oneshot},
|
|
|
|
sink::SinkExt,
|
|
|
|
stream::StreamExt,
|
2019-12-20 13:56:01 +00:00
|
|
|
};
|
2020-04-24 10:56:04 +00:00
|
|
|
use prometheus::Registry;
|
2020-03-22 13:47:21 +00:00
|
|
|
use serde::{de::DeserializeOwned, Serialize};
|
2020-02-04 15:42:04 +00:00
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
2020-03-22 13:47:21 +00:00
|
|
|
sync::{
|
|
|
|
atomic::{AtomicBool, Ordering},
|
|
|
|
Arc,
|
|
|
|
},
|
2020-02-04 15:42:04 +00:00
|
|
|
};
|
2020-01-13 16:53:28 +00:00
|
|
|
use tracing::*;
|
2020-03-22 13:47:21 +00:00
|
|
|
use tracing_futures::Instrument;
|
2020-01-13 16:53:28 +00:00
|
|
|
use uvth::ThreadPool;
|
2019-12-20 13:56:01 +00:00
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
|
2019-12-20 13:56:01 +00:00
|
|
|
pub enum Address {
|
|
|
|
Tcp(std::net::SocketAddr),
|
|
|
|
Udp(std::net::SocketAddr),
|
2020-03-10 00:07:36 +00:00
|
|
|
Mpsc(u64),
|
2019-12-20 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct Participant {
|
2020-03-22 13:47:21 +00:00
|
|
|
local_pid: Pid,
|
2020-02-10 17:25:47 +00:00
|
|
|
remote_pid: Pid,
|
2020-03-22 13:47:21 +00:00
|
|
|
stream_open_sender: RwLock<mpsc::UnboundedSender<(Prio, Promises, oneshot::Sender<Stream>)>>,
|
|
|
|
stream_opened_receiver: RwLock<mpsc::UnboundedReceiver<Stream>>,
|
|
|
|
closed: AtomicBool,
|
|
|
|
disconnect_sender: Option<mpsc::UnboundedSender<Pid>>,
|
2019-12-20 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
#[derive(Debug)]
|
2020-02-04 15:42:04 +00:00
|
|
|
pub struct Stream {
|
2020-03-22 13:47:21 +00:00
|
|
|
pid: Pid,
|
2020-02-04 15:42:04 +00:00
|
|
|
sid: Sid,
|
2020-03-22 13:47:21 +00:00
|
|
|
mid: Mid,
|
|
|
|
prio: Prio,
|
|
|
|
promises: Promises,
|
|
|
|
msg_send_sender: std::sync::mpsc::Sender<(Prio, Pid, Sid, OutGoingMessage)>,
|
|
|
|
msg_recv_receiver: mpsc::UnboundedReceiver<InCommingMessage>,
|
2020-04-08 14:26:42 +00:00
|
|
|
closed: Arc<AtomicBool>,
|
2020-03-22 13:47:21 +00:00
|
|
|
shutdown_sender: Option<mpsc::UnboundedSender<Sid>>,
|
2020-02-04 15:42:04 +00:00
|
|
|
}
|
2019-12-20 13:56:01 +00:00
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum NetworkError {
|
|
|
|
NetworkClosed,
|
|
|
|
ListenFailed(std::io::Error),
|
|
|
|
}
|
2020-03-22 13:47:21 +00:00
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum ParticipantError {
|
|
|
|
ParticipantClosed,
|
|
|
|
}
|
2020-03-22 13:47:21 +00:00
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
#[derive(Debug, PartialEq)]
|
|
|
|
pub enum StreamError {
|
|
|
|
StreamClosed,
|
|
|
|
}
|
2020-03-22 13:47:21 +00:00
|
|
|
|
2020-02-21 15:10:55 +00:00
|
|
|
pub struct Network {
|
2020-03-22 13:47:21 +00:00
|
|
|
local_pid: Pid,
|
|
|
|
participants: RwLock<HashMap<Pid, Arc<Participant>>>,
|
2020-04-08 14:26:42 +00:00
|
|
|
listen_sender:
|
|
|
|
RwLock<mpsc::UnboundedSender<(Address, oneshot::Sender<async_std::io::Result<()>>)>>,
|
|
|
|
connect_sender:
|
|
|
|
RwLock<mpsc::UnboundedSender<(Address, oneshot::Sender<io::Result<Participant>>)>>,
|
2020-03-22 13:47:21 +00:00
|
|
|
connected_receiver: RwLock<mpsc::UnboundedReceiver<Participant>>,
|
|
|
|
shutdown_sender: Option<oneshot::Sender<()>>,
|
2019-12-20 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-21 15:10:55 +00:00
|
|
|
impl Network {
|
2020-04-24 10:56:04 +00:00
|
|
|
pub fn new(participant_id: Pid, thread_pool: &ThreadPool, registry: Option<&Registry>) -> Self {
|
2020-03-22 13:47:21 +00:00
|
|
|
//let participants = RwLock::new(vec![]);
|
|
|
|
let p = participant_id;
|
2020-04-08 14:26:42 +00:00
|
|
|
debug!(?p, ?User, "starting Network");
|
2020-03-22 13:47:21 +00:00
|
|
|
let (scheduler, listen_sender, connect_sender, connected_receiver, shutdown_sender) =
|
2020-04-24 10:56:04 +00:00
|
|
|
Scheduler::new(participant_id, registry);
|
2020-03-22 13:47:21 +00:00
|
|
|
thread_pool.execute(move || {
|
2020-04-08 14:26:42 +00:00
|
|
|
trace!(?p, ?User, "starting sheduler in own thread");
|
2020-03-22 13:47:21 +00:00
|
|
|
let _handle = task::block_on(
|
|
|
|
scheduler
|
|
|
|
.run()
|
|
|
|
.instrument(tracing::info_span!("scheduler", ?p)),
|
|
|
|
);
|
2020-05-04 13:27:58 +00:00
|
|
|
trace!(?p, ?User, "stopping sheduler and his own thread");
|
2020-03-22 13:47:21 +00:00
|
|
|
});
|
2019-12-20 13:56:01 +00:00
|
|
|
Self {
|
2020-03-22 13:47:21 +00:00
|
|
|
local_pid: participant_id,
|
|
|
|
participants: RwLock::new(HashMap::new()),
|
|
|
|
listen_sender: RwLock::new(listen_sender),
|
|
|
|
connect_sender: RwLock::new(connect_sender),
|
|
|
|
connected_receiver: RwLock::new(connected_receiver),
|
|
|
|
shutdown_sender: Some(shutdown_sender),
|
2019-12-20 13:56:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
pub async fn listen(&self, address: Address) -> Result<(), NetworkError> {
|
|
|
|
let (result_sender, result_receiver) = oneshot::channel::<async_std::io::Result<()>>();
|
|
|
|
debug!(?address, ?User, "listening on address");
|
|
|
|
self.listen_sender
|
|
|
|
.write()
|
|
|
|
.await
|
|
|
|
.send((address, result_sender))
|
|
|
|
.await?;
|
|
|
|
match result_receiver.await? {
|
|
|
|
//waiting guarantees that we either listened sucessfully or get an error like port in
|
|
|
|
// use
|
|
|
|
Ok(()) => Ok(()),
|
|
|
|
Err(e) => Err(NetworkError::ListenFailed(e)),
|
|
|
|
}
|
2019-12-20 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
pub async fn connect(&self, address: Address) -> Result<Arc<Participant>, NetworkError> {
|
2020-04-08 14:26:42 +00:00
|
|
|
let (pid_sender, pid_receiver) = oneshot::channel::<io::Result<Participant>>();
|
|
|
|
debug!(?address, ?User, "connect to address");
|
2020-03-22 13:47:21 +00:00
|
|
|
self.connect_sender
|
|
|
|
.write()
|
|
|
|
.await
|
|
|
|
.send((address, pid_sender))
|
2020-04-08 14:26:42 +00:00
|
|
|
.await?;
|
|
|
|
let participant = pid_receiver.await??;
|
|
|
|
let pid = participant.remote_pid;
|
|
|
|
debug!(
|
|
|
|
?pid,
|
|
|
|
?User,
|
|
|
|
"received Participant id from remote and return to user"
|
|
|
|
);
|
|
|
|
let participant = Arc::new(participant);
|
|
|
|
self.participants
|
|
|
|
.write()
|
2020-03-22 13:47:21 +00:00
|
|
|
.await
|
2020-04-08 14:26:42 +00:00
|
|
|
.insert(participant.remote_pid, participant.clone());
|
|
|
|
Ok(participant)
|
2020-03-22 13:47:21 +00:00
|
|
|
}
|
2020-03-10 00:07:36 +00:00
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
pub async fn connected(&self) -> Result<Arc<Participant>, NetworkError> {
|
2020-04-08 14:26:42 +00:00
|
|
|
let participant = self.connected_receiver.write().await.next().await?;
|
|
|
|
let participant = Arc::new(participant);
|
|
|
|
self.participants
|
|
|
|
.write()
|
|
|
|
.await
|
|
|
|
.insert(participant.remote_pid, participant.clone());
|
|
|
|
Ok(participant)
|
2019-12-20 13:56:01 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
pub async fn disconnect(&self, participant: Arc<Participant>) -> Result<(), NetworkError> {
|
|
|
|
// Remove, Close and try_unwrap error when unwrap fails!
|
2020-04-08 14:26:42 +00:00
|
|
|
let pid = participant.remote_pid;
|
|
|
|
debug!(?pid, "removing participant from network");
|
|
|
|
self.participants.write().await.remove(&pid)?;
|
2020-03-22 13:47:21 +00:00
|
|
|
participant.closed.store(true, Ordering::Relaxed);
|
2020-01-13 16:53:28 +00:00
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
if Arc::try_unwrap(participant).is_err() {
|
|
|
|
warn!(
|
|
|
|
"you are disconnecting and still keeping a reference to this participant, this is \
|
|
|
|
a bad idea. Participant will only be dropped when you drop your last reference"
|
|
|
|
);
|
|
|
|
};
|
|
|
|
Ok(())
|
2020-02-10 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
pub async fn participants(&self) -> HashMap<Pid, Arc<Participant>> {
|
|
|
|
self.participants.read().await.clone()
|
|
|
|
}
|
|
|
|
}
|
2020-02-10 17:25:47 +00:00
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
impl Participant {
|
|
|
|
pub(crate) fn new(
|
|
|
|
local_pid: Pid,
|
|
|
|
remote_pid: Pid,
|
|
|
|
stream_open_sender: mpsc::UnboundedSender<(Prio, Promises, oneshot::Sender<Stream>)>,
|
|
|
|
stream_opened_receiver: mpsc::UnboundedReceiver<Stream>,
|
|
|
|
disconnect_sender: mpsc::UnboundedSender<Pid>,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
local_pid,
|
|
|
|
remote_pid,
|
|
|
|
stream_open_sender: RwLock::new(stream_open_sender),
|
|
|
|
stream_opened_receiver: RwLock::new(stream_opened_receiver),
|
|
|
|
closed: AtomicBool::new(false),
|
|
|
|
disconnect_sender: Some(disconnect_sender),
|
2020-03-04 15:52:30 +00:00
|
|
|
}
|
2020-02-10 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
pub async fn open(&self, prio: u8, promises: Promises) -> Result<Stream, ParticipantError> {
|
2020-04-08 14:26:42 +00:00
|
|
|
//use this lock for now to make sure that only one open at a time is made,
|
|
|
|
// TODO: not sure if we can paralise that, check in future
|
|
|
|
let mut stream_open_sender = self.stream_open_sender.write().await;
|
|
|
|
if self.closed.load(Ordering::Relaxed) {
|
|
|
|
warn!(?self.remote_pid, "participant is closed but another open is tried on it");
|
|
|
|
return Err(ParticipantError::ParticipantClosed);
|
|
|
|
}
|
2020-03-22 13:47:21 +00:00
|
|
|
let (sid_sender, sid_receiver) = oneshot::channel();
|
2020-04-08 14:26:42 +00:00
|
|
|
if stream_open_sender
|
2020-03-22 13:47:21 +00:00
|
|
|
.send((prio, promises, sid_sender))
|
|
|
|
.await
|
2020-04-08 14:26:42 +00:00
|
|
|
.is_err()
|
|
|
|
{
|
|
|
|
debug!(?self.remote_pid, ?User, "stream_open_sender failed, closing participant");
|
|
|
|
self.closed.store(true, Ordering::Relaxed);
|
|
|
|
return Err(ParticipantError::ParticipantClosed);
|
|
|
|
}
|
2020-03-22 13:47:21 +00:00
|
|
|
match sid_receiver.await {
|
|
|
|
Ok(stream) => {
|
|
|
|
let sid = stream.sid;
|
2020-04-08 14:26:42 +00:00
|
|
|
debug!(?sid, ?self.remote_pid, ?User, "opened stream");
|
2020-03-22 13:47:21 +00:00
|
|
|
Ok(stream)
|
|
|
|
},
|
2020-04-08 14:26:42 +00:00
|
|
|
Err(_) => {
|
|
|
|
debug!(?self.remote_pid, ?User, "sid_receiver failed, closing participant");
|
|
|
|
self.closed.store(true, Ordering::Relaxed);
|
|
|
|
Err(ParticipantError::ParticipantClosed)
|
|
|
|
},
|
2020-03-04 15:52:30 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-21 15:10:55 +00:00
|
|
|
|
|
|
|
pub async fn opened(&self) -> Result<Stream, ParticipantError> {
|
2020-04-08 14:26:42 +00:00
|
|
|
//use this lock for now to make sure that only one open at a time is made,
|
|
|
|
// TODO: not sure if we can paralise that, check in future
|
|
|
|
let mut stream_opened_receiver = self.stream_opened_receiver.write().await;
|
|
|
|
if self.closed.load(Ordering::Relaxed) {
|
|
|
|
warn!(?self.remote_pid, "participant is closed but another open is tried on it");
|
|
|
|
return Err(ParticipantError::ParticipantClosed);
|
|
|
|
}
|
|
|
|
match stream_opened_receiver.next().await {
|
|
|
|
Some(stream) => {
|
|
|
|
let sid = stream.sid;
|
|
|
|
debug!(?sid, ?self.remote_pid, "receive opened stream");
|
|
|
|
Ok(stream)
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
debug!(?self.remote_pid, "stream_opened_receiver failed, closing participant");
|
|
|
|
self.closed.store(true, Ordering::Relaxed);
|
|
|
|
Err(ParticipantError::ParticipantClosed)
|
|
|
|
},
|
2020-02-21 15:10:55 +00:00
|
|
|
}
|
2020-02-10 17:25:47 +00:00
|
|
|
}
|
2020-04-08 14:26:42 +00:00
|
|
|
|
|
|
|
pub fn remote_pid(&self) -> Pid { self.remote_pid }
|
2020-02-10 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Stream {
|
2020-03-10 00:07:36 +00:00
|
|
|
pub(crate) fn new(
|
2020-03-22 13:47:21 +00:00
|
|
|
pid: Pid,
|
2020-03-10 00:07:36 +00:00
|
|
|
sid: Sid,
|
2020-03-22 13:47:21 +00:00
|
|
|
prio: Prio,
|
|
|
|
promises: Promises,
|
|
|
|
msg_send_sender: std::sync::mpsc::Sender<(Prio, Pid, Sid, OutGoingMessage)>,
|
|
|
|
msg_recv_receiver: mpsc::UnboundedReceiver<InCommingMessage>,
|
2020-04-08 14:26:42 +00:00
|
|
|
closed: Arc<AtomicBool>,
|
2020-03-22 13:47:21 +00:00
|
|
|
shutdown_sender: mpsc::UnboundedSender<Sid>,
|
2020-03-10 00:07:36 +00:00
|
|
|
) -> Self {
|
|
|
|
Self {
|
2020-03-22 13:47:21 +00:00
|
|
|
pid,
|
2020-03-10 00:07:36 +00:00
|
|
|
sid,
|
2020-03-22 13:47:21 +00:00
|
|
|
mid: 0,
|
|
|
|
prio,
|
|
|
|
promises,
|
|
|
|
msg_send_sender,
|
|
|
|
msg_recv_receiver,
|
2020-04-08 14:26:42 +00:00
|
|
|
closed,
|
2020-03-22 13:47:21 +00:00
|
|
|
shutdown_sender: Some(shutdown_sender),
|
2020-03-10 00:07:36 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-10 17:25:47 +00:00
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
pub fn send<M: Serialize>(&mut self, msg: M) -> Result<(), StreamError> {
|
2020-04-24 10:56:04 +00:00
|
|
|
self.send_raw(Arc::new(message::serialize(&msg)))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn send_raw(&mut self, messagebuffer: Arc<MessageBuffer>) -> Result<(), StreamError> {
|
2020-04-08 14:26:42 +00:00
|
|
|
if self.closed.load(Ordering::Relaxed) {
|
|
|
|
return Err(StreamError::StreamClosed);
|
|
|
|
}
|
2020-04-24 10:56:04 +00:00
|
|
|
debug!(?messagebuffer, ?User, "sending a message");
|
2020-03-22 13:47:21 +00:00
|
|
|
self.msg_send_sender
|
|
|
|
.send((self.prio, self.pid, self.sid, OutGoingMessage {
|
2020-03-04 15:52:30 +00:00
|
|
|
buffer: messagebuffer,
|
2020-03-04 00:37:36 +00:00
|
|
|
cursor: 0,
|
2020-03-22 13:47:21 +00:00
|
|
|
mid: self.mid,
|
2020-03-04 00:37:36 +00:00
|
|
|
sid: self.sid,
|
2020-04-08 14:26:42 +00:00
|
|
|
}))?;
|
2020-03-22 13:47:21 +00:00
|
|
|
self.mid += 1;
|
2020-02-21 15:10:55 +00:00
|
|
|
Ok(())
|
2020-02-10 17:25:47 +00:00
|
|
|
}
|
|
|
|
|
2020-03-04 10:59:19 +00:00
|
|
|
pub async fn recv<M: DeserializeOwned>(&mut self) -> Result<M, StreamError> {
|
2020-04-24 10:56:04 +00:00
|
|
|
Ok(message::deserialize(self.recv_raw().await?))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub async fn recv_raw(&mut self) -> Result<MessageBuffer, StreamError> {
|
2020-04-08 14:26:42 +00:00
|
|
|
//no need to access self.closed here, as when this stream is closed the Channel
|
|
|
|
// is closed which will trigger a None
|
|
|
|
let msg = self.msg_recv_receiver.next().await?;
|
2020-04-24 10:56:04 +00:00
|
|
|
info!(?msg, ?User, "delivering a message");
|
|
|
|
Ok(msg.buffer)
|
2020-02-10 17:25:47 +00:00
|
|
|
}
|
2020-03-22 13:47:21 +00:00
|
|
|
}
|
2020-03-10 00:07:36 +00:00
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
impl Drop for Network {
|
|
|
|
fn drop(&mut self) {
|
2020-04-08 14:26:42 +00:00
|
|
|
let pid = self.local_pid;
|
|
|
|
debug!(?pid, "shutting down Network");
|
|
|
|
self.shutdown_sender
|
|
|
|
.take()
|
|
|
|
.unwrap()
|
|
|
|
.send(())
|
|
|
|
.expect("scheduler is closed, but nobody other should be able to close it");
|
2020-03-10 00:07:36 +00:00
|
|
|
}
|
2020-03-22 13:47:21 +00:00
|
|
|
}
|
2020-03-10 00:07:36 +00:00
|
|
|
|
2020-03-22 13:47:21 +00:00
|
|
|
impl Drop for Participant {
|
|
|
|
fn drop(&mut self) {
|
2020-04-08 14:26:42 +00:00
|
|
|
// ignore closed, as we need to send it even though we disconnected the
|
|
|
|
// participant from network
|
|
|
|
let pid = self.remote_pid;
|
|
|
|
debug!(?pid, "shutting down Participant");
|
|
|
|
task::block_on(async {
|
|
|
|
self.disconnect_sender
|
|
|
|
.take()
|
|
|
|
.unwrap()
|
|
|
|
.send(self.remote_pid)
|
|
|
|
.await
|
|
|
|
.expect("something is wrong in internal scheduler coding")
|
|
|
|
});
|
2020-03-10 00:07:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Drop for Stream {
|
|
|
|
fn drop(&mut self) {
|
2020-04-08 14:26:42 +00:00
|
|
|
// a send if closed is unecessary but doesnt hurt, we must not crash here
|
2020-03-22 13:47:21 +00:00
|
|
|
if !self.closed.load(Ordering::Relaxed) {
|
2020-04-08 14:26:42 +00:00
|
|
|
let sid = self.sid;
|
|
|
|
let pid = self.pid;
|
|
|
|
debug!(?pid, ?sid, "shutting down Stream");
|
|
|
|
if task::block_on(self.shutdown_sender.take().unwrap().send(self.sid)).is_err() {
|
|
|
|
warn!(
|
|
|
|
"Other side got already dropped, probably due to timing, other side will \
|
|
|
|
handle this gracefully"
|
|
|
|
);
|
|
|
|
};
|
2020-03-22 13:47:21 +00:00
|
|
|
}
|
2020-03-10 00:07:36 +00:00
|
|
|
}
|
2020-02-10 17:25:47 +00:00
|
|
|
}
|
2020-04-08 14:26:42 +00:00
|
|
|
|
|
|
|
impl std::fmt::Debug for Participant {
|
|
|
|
#[inline]
|
|
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
|
|
let status = if self.closed.load(Ordering::Relaxed) {
|
|
|
|
"[CLOSED]"
|
|
|
|
} else {
|
|
|
|
"[OPEN]"
|
|
|
|
};
|
|
|
|
write!(
|
|
|
|
f,
|
|
|
|
"Participant {{{} local_pid: {:?}, remote_pid: {:?} }}",
|
|
|
|
status, &self.local_pid, &self.remote_pid,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<std::sync::mpsc::SendError<T>> for StreamError {
|
|
|
|
fn from(_err: std::sync::mpsc::SendError<T>) -> Self { StreamError::StreamClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<std::sync::mpsc::SendError<T>> for ParticipantError {
|
|
|
|
fn from(_err: std::sync::mpsc::SendError<T>) -> Self { ParticipantError::ParticipantClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> From<std::sync::mpsc::SendError<T>> for NetworkError {
|
|
|
|
fn from(_err: std::sync::mpsc::SendError<T>) -> Self { NetworkError::NetworkClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<async_std::io::Error> for NetworkError {
|
|
|
|
fn from(err: async_std::io::Error) -> Self { NetworkError::ListenFailed(err) }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::option::NoneError> for StreamError {
|
|
|
|
fn from(_err: std::option::NoneError) -> Self { StreamError::StreamClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::option::NoneError> for ParticipantError {
|
|
|
|
fn from(_err: std::option::NoneError) -> Self { ParticipantError::ParticipantClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<std::option::NoneError> for NetworkError {
|
|
|
|
fn from(_err: std::option::NoneError) -> Self { NetworkError::NetworkClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<mpsc::SendError> for ParticipantError {
|
|
|
|
fn from(_err: mpsc::SendError) -> Self { ParticipantError::ParticipantClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<mpsc::SendError> for NetworkError {
|
|
|
|
fn from(_err: mpsc::SendError) -> Self { NetworkError::NetworkClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<oneshot::Canceled> for ParticipantError {
|
|
|
|
fn from(_err: oneshot::Canceled) -> Self { ParticipantError::ParticipantClosed }
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<oneshot::Canceled> for NetworkError {
|
|
|
|
fn from(_err: oneshot::Canceled) -> Self { NetworkError::NetworkClosed }
|
|
|
|
}
|