2020-04-24 10:56:04 +00:00
|
|
|
use crate::{
|
2020-05-24 23:17:03 +00:00
|
|
|
metrics::{CidFrameCache, NetworkMetrics},
|
2020-05-04 13:27:58 +00:00
|
|
|
types::{Cid, Frame, Mid, Pid, Sid},
|
2020-04-24 10:56:04 +00:00
|
|
|
};
|
2020-04-08 14:26:42 +00:00
|
|
|
use async_std::{
|
|
|
|
net::{TcpStream, UdpSocket},
|
|
|
|
prelude::*,
|
|
|
|
};
|
2020-05-04 13:27:58 +00:00
|
|
|
use futures::{
|
|
|
|
channel::{mpsc, oneshot},
|
|
|
|
future::FutureExt,
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
lock::Mutex,
|
2020-05-04 13:27:58 +00:00
|
|
|
select,
|
|
|
|
sink::SinkExt,
|
|
|
|
stream::StreamExt,
|
|
|
|
};
|
2020-04-08 14:26:42 +00:00
|
|
|
use std::{net::SocketAddr, sync::Arc};
|
|
|
|
use tracing::*;
|
|
|
|
|
2020-04-24 10:56:04 +00:00
|
|
|
// Reserving bytes 0, 10, 13 as i have enough space and want to make it easy to
|
|
|
|
// detect a invalid client, e.g. sending an empty line would make 10 first char
|
|
|
|
// const FRAME_RESERVED_1: u8 = 0;
|
|
|
|
const FRAME_HANDSHAKE: u8 = 1;
|
2020-05-26 13:06:03 +00:00
|
|
|
const FRAME_INIT: u8 = 2;
|
2020-04-24 10:56:04 +00:00
|
|
|
const FRAME_SHUTDOWN: u8 = 3;
|
|
|
|
const FRAME_OPEN_STREAM: u8 = 4;
|
|
|
|
const FRAME_CLOSE_STREAM: u8 = 5;
|
|
|
|
const FRAME_DATA_HEADER: u8 = 6;
|
|
|
|
const FRAME_DATA: u8 = 7;
|
|
|
|
const FRAME_RAW: u8 = 8;
|
|
|
|
//const FRAME_RESERVED_2: u8 = 10;
|
|
|
|
//const FRAME_RESERVED_3: u8 = 13;
|
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) enum Protocols {
|
|
|
|
Tcp(TcpProtocol),
|
|
|
|
Udp(UdpProtocol),
|
|
|
|
//Mpsc(MpscChannel),
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) struct TcpProtocol {
|
|
|
|
stream: TcpStream,
|
2020-04-24 10:56:04 +00:00
|
|
|
metrics: Arc<NetworkMetrics>,
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
pub(crate) struct UdpProtocol {
|
|
|
|
socket: Arc<UdpSocket>,
|
|
|
|
remote_addr: SocketAddr,
|
2020-04-24 10:56:04 +00:00
|
|
|
metrics: Arc<NetworkMetrics>,
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
data_in: Mutex<mpsc::UnboundedReceiver<Vec<u8>>>,
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 11:43:29 +00:00
|
|
|
//TODO: PERFORMACE: Use BufWriter and BufReader from std::io!
|
2020-04-08 14:26:42 +00:00
|
|
|
impl TcpProtocol {
|
2020-04-24 10:56:04 +00:00
|
|
|
pub(crate) fn new(stream: TcpStream, metrics: Arc<NetworkMetrics>) -> Self {
|
|
|
|
Self { stream, metrics }
|
|
|
|
}
|
2020-04-08 14:26:42 +00:00
|
|
|
|
2020-05-27 15:58:57 +00:00
|
|
|
/// read_except and if it fails, close the protocol
|
|
|
|
async fn read_except_or_close(
|
|
|
|
cid: Cid,
|
|
|
|
mut stream: &TcpStream,
|
|
|
|
mut bytes: &mut [u8],
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
w2c_cid_frame_s: &mut mpsc::UnboundedSender<(Cid, Frame)>,
|
2020-05-27 15:58:57 +00:00
|
|
|
) {
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
if let Err(e) = stream.read_exact(&mut bytes).await {
|
|
|
|
warn!(
|
|
|
|
?e,
|
|
|
|
"closing tcp protocol due to read error, sending close frame to gracefully \
|
|
|
|
shutdown"
|
|
|
|
);
|
|
|
|
w2c_cid_frame_s.send((cid, Frame::Shutdown)).await.unwrap();
|
2020-05-27 15:58:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
pub async fn read_from_wire(
|
2020-05-04 13:27:58 +00:00
|
|
|
&self,
|
|
|
|
cid: Cid,
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
w2c_cid_frame_s: &mut mpsc::UnboundedSender<(Cid, Frame)>,
|
2020-05-04 13:27:58 +00:00
|
|
|
end_receiver: oneshot::Receiver<()>,
|
|
|
|
) {
|
2020-05-26 13:06:03 +00:00
|
|
|
trace!("starting up tcp read()");
|
2020-05-24 23:17:03 +00:00
|
|
|
let mut metrics_cache = CidFrameCache::new(self.metrics.frames_wire_in_total.clone(), cid);
|
2020-05-27 15:58:57 +00:00
|
|
|
let throughput_cache = self
|
|
|
|
.metrics
|
|
|
|
.wire_in_throughput
|
|
|
|
.with_label_values(&[&cid.to_string()]);
|
2020-04-08 14:26:42 +00:00
|
|
|
let mut stream = self.stream.clone();
|
2020-05-04 13:27:58 +00:00
|
|
|
let mut end_receiver = end_receiver.fuse();
|
2020-05-27 15:58:57 +00:00
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
loop {
|
2020-04-24 10:56:04 +00:00
|
|
|
let mut bytes = [0u8; 1];
|
2020-05-04 13:27:58 +00:00
|
|
|
let r = select! {
|
|
|
|
r = stream.read_exact(&mut bytes).fuse() => r,
|
|
|
|
_ = end_receiver => break,
|
|
|
|
};
|
|
|
|
if r.is_err() {
|
|
|
|
info!("tcp stream closed, shutting down read");
|
2020-04-24 10:56:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
let frame_no = bytes[0];
|
|
|
|
let frame = match frame_no {
|
|
|
|
FRAME_HANDSHAKE => {
|
|
|
|
let mut bytes = [0u8; 19];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut bytes, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
let magic_number = [
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
];
|
|
|
|
Frame::Handshake {
|
|
|
|
magic_number,
|
|
|
|
version: [
|
|
|
|
u32::from_le_bytes([bytes[7], bytes[8], bytes[9], bytes[10]]),
|
|
|
|
u32::from_le_bytes([bytes[11], bytes[12], bytes[13], bytes[14]]),
|
|
|
|
u32::from_le_bytes([bytes[15], bytes[16], bytes[17], bytes[18]]),
|
|
|
|
],
|
|
|
|
}
|
2020-04-08 14:26:42 +00:00
|
|
|
},
|
2020-05-26 13:06:03 +00:00
|
|
|
FRAME_INIT => {
|
2020-04-24 10:56:04 +00:00
|
|
|
let mut bytes = [0u8; 16];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut bytes, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
let pid = Pid::from_le_bytes(bytes);
|
2020-05-26 13:06:03 +00:00
|
|
|
stream.read_exact(&mut bytes).await.unwrap();
|
|
|
|
let secret = u128::from_le_bytes(bytes);
|
|
|
|
Frame::Init { pid, secret }
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
|
|
|
FRAME_SHUTDOWN => Frame::Shutdown,
|
|
|
|
FRAME_OPEN_STREAM => {
|
|
|
|
let mut bytes = [0u8; 10];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut bytes, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
let sid = Sid::from_le_bytes([
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
bytes[7],
|
|
|
|
]);
|
|
|
|
let prio = bytes[8];
|
|
|
|
let promises = bytes[9];
|
|
|
|
Frame::OpenStream {
|
|
|
|
sid,
|
|
|
|
prio,
|
|
|
|
promises,
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
},
|
2020-04-24 10:56:04 +00:00
|
|
|
FRAME_CLOSE_STREAM => {
|
|
|
|
let mut bytes = [0u8; 8];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut bytes, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
let sid = Sid::from_le_bytes([
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
bytes[7],
|
|
|
|
]);
|
|
|
|
Frame::CloseStream { sid }
|
|
|
|
},
|
|
|
|
FRAME_DATA_HEADER => {
|
|
|
|
let mut bytes = [0u8; 24];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut bytes, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
let mid = Mid::from_le_bytes([
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
bytes[7],
|
|
|
|
]);
|
|
|
|
let sid = Sid::from_le_bytes([
|
|
|
|
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14],
|
|
|
|
bytes[15],
|
|
|
|
]);
|
|
|
|
let length = u64::from_le_bytes([
|
|
|
|
bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21],
|
|
|
|
bytes[22], bytes[23],
|
|
|
|
]);
|
|
|
|
Frame::DataHeader { mid, sid, length }
|
|
|
|
},
|
|
|
|
FRAME_DATA => {
|
|
|
|
let mut bytes = [0u8; 18];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut bytes, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
let mid = Mid::from_le_bytes([
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
bytes[7],
|
|
|
|
]);
|
|
|
|
let start = u64::from_le_bytes([
|
|
|
|
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14],
|
|
|
|
bytes[15],
|
|
|
|
]);
|
|
|
|
let length = u16::from_le_bytes([bytes[16], bytes[17]]);
|
|
|
|
let mut data = vec![0; length as usize];
|
2020-05-27 15:58:57 +00:00
|
|
|
throughput_cache.inc_by(length as i64);
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut data, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
Frame::Data { mid, start, data }
|
|
|
|
},
|
|
|
|
FRAME_RAW => {
|
|
|
|
let mut bytes = [0u8; 2];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut bytes, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
let length = u16::from_le_bytes([bytes[0], bytes[1]]);
|
|
|
|
let mut data = vec![0; length as usize];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut data, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
Frame::Raw(data)
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
// report a RAW frame, but cannot rely on the next 2 bytes to be a size.
|
|
|
|
// guessing 256 bytes, which might help to sort down issues
|
|
|
|
let mut data = vec![0; 256];
|
2020-06-08 09:47:39 +00:00
|
|
|
Self::read_except_or_close(cid, &stream, &mut data, w2c_cid_frame_s).await;
|
2020-04-24 10:56:04 +00:00
|
|
|
Frame::Raw(data)
|
|
|
|
},
|
|
|
|
};
|
2020-05-24 23:17:03 +00:00
|
|
|
metrics_cache.with_label_values(&frame).inc();
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
w2c_cid_frame_s.send((cid, frame)).await.unwrap();
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
2020-04-24 10:56:04 +00:00
|
|
|
trace!("shutting down tcp read()");
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
|
2020-05-27 15:58:57 +00:00
|
|
|
/// read_except and if it fails, close the protocol
|
|
|
|
async fn write_or_close(
|
|
|
|
stream: &mut TcpStream,
|
|
|
|
bytes: &[u8],
|
|
|
|
to_wire_receiver: &mut mpsc::UnboundedReceiver<Frame>,
|
|
|
|
) -> bool {
|
|
|
|
match stream.write_all(&bytes).await {
|
|
|
|
Err(e) => {
|
|
|
|
warn!(
|
|
|
|
?e,
|
|
|
|
"got an error writing to tcp, going to close this channel"
|
|
|
|
);
|
|
|
|
to_wire_receiver.close();
|
|
|
|
true
|
|
|
|
},
|
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-08 14:26:42 +00:00
|
|
|
//dezerialize here as this is executed in a seperate thread PER channel.
|
|
|
|
// Limites Throughput per single Receiver but stays in same thread (maybe as its
|
|
|
|
// in a threadpool) for TCP, UDP and MPSC
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
pub async fn write_to_wire(&self, cid: Cid, mut c2w_frame_r: mpsc::UnboundedReceiver<Frame>) {
|
2020-05-04 13:27:58 +00:00
|
|
|
trace!("starting up tcp write()");
|
2020-04-08 14:26:42 +00:00
|
|
|
let mut stream = self.stream.clone();
|
2020-05-24 23:17:03 +00:00
|
|
|
let mut metrics_cache = CidFrameCache::new(self.metrics.frames_wire_out_total.clone(), cid);
|
2020-05-27 15:58:57 +00:00
|
|
|
let throughput_cache = self
|
|
|
|
.metrics
|
|
|
|
.wire_out_throughput
|
|
|
|
.with_label_values(&[&cid.to_string()]);
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
while let Some(frame) = c2w_frame_r.next().await {
|
2020-05-24 23:17:03 +00:00
|
|
|
metrics_cache.with_label_values(&frame).inc();
|
2020-05-27 15:58:57 +00:00
|
|
|
if match frame {
|
2020-04-24 10:56:04 +00:00
|
|
|
Frame::Handshake {
|
|
|
|
magic_number,
|
|
|
|
version,
|
|
|
|
} => {
|
2020-05-27 15:58:57 +00:00
|
|
|
Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&FRAME_HANDSHAKE.to_be_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &magic_number, &mut c2w_frame_r).await
|
2020-05-27 15:58:57 +00:00
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&version[0].to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&version[1].to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&version[2].to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
2020-04-24 10:56:04 +00:00
|
|
|
.await
|
|
|
|
},
|
2020-05-26 13:06:03 +00:00
|
|
|
Frame::Init { pid, secret } => {
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
Self::write_or_close(&mut stream, &FRAME_INIT.to_be_bytes(), &mut c2w_frame_r)
|
2020-05-27 15:58:57 +00:00
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &pid.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
2020-05-27 15:58:57 +00:00
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&secret.to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
|
|
|
Frame::Shutdown => {
|
2020-05-27 15:58:57 +00:00
|
|
|
Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&FRAME_SHUTDOWN.to_be_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
|
|
|
Frame::OpenStream {
|
|
|
|
sid,
|
|
|
|
prio,
|
|
|
|
promises,
|
|
|
|
} => {
|
2020-05-27 15:58:57 +00:00
|
|
|
Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&FRAME_OPEN_STREAM.to_be_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &sid.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
|
|
|
|| Self::write_or_close(&mut stream, &prio.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
2020-05-27 15:58:57 +00:00
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&promises.to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
2020-04-24 10:56:04 +00:00
|
|
|
.await
|
|
|
|
},
|
|
|
|
Frame::CloseStream { sid } => {
|
2020-05-27 15:58:57 +00:00
|
|
|
Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&FRAME_CLOSE_STREAM.to_be_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &sid.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
|
|
|
Frame::DataHeader { mid, sid, length } => {
|
2020-05-27 15:58:57 +00:00
|
|
|
Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&FRAME_DATA_HEADER.to_be_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &mid.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
|
|
|
|| Self::write_or_close(&mut stream, &sid.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
2020-05-27 15:58:57 +00:00
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&length.to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
2020-04-24 10:56:04 +00:00
|
|
|
.await
|
|
|
|
},
|
|
|
|
Frame::Data { mid, start, data } => {
|
2020-05-27 15:58:57 +00:00
|
|
|
throughput_cache.inc_by(data.len() as i64);
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
Self::write_or_close(&mut stream, &FRAME_DATA.to_be_bytes(), &mut c2w_frame_r)
|
2020-05-27 15:58:57 +00:00
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &mid.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
|
|
|
|| Self::write_or_close(&mut stream, &start.to_le_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
2020-05-27 15:58:57 +00:00
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&(data.len() as u16).to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
2020-04-24 10:56:04 +00:00
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &data, &mut c2w_frame_r).await
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
|
|
|
Frame::Raw(data) => {
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
Self::write_or_close(&mut stream, &FRAME_RAW.to_be_bytes(), &mut c2w_frame_r)
|
|
|
|
.await
|
2020-05-27 15:58:57 +00:00
|
|
|
|| Self::write_or_close(
|
|
|
|
&mut stream,
|
|
|
|
&(data.len() as u16).to_le_bytes(),
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
&mut c2w_frame_r,
|
2020-05-27 15:58:57 +00:00
|
|
|
)
|
2020-04-24 10:56:04 +00:00
|
|
|
.await
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
|| Self::write_or_close(&mut stream, &data, &mut c2w_frame_r).await
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
2020-05-27 15:58:57 +00:00
|
|
|
} {
|
|
|
|
//failure
|
|
|
|
return;
|
2020-04-24 10:56:04 +00:00
|
|
|
}
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
2020-04-24 10:56:04 +00:00
|
|
|
trace!("shutting down tcp write()");
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl UdpProtocol {
|
|
|
|
pub(crate) fn new(
|
|
|
|
socket: Arc<UdpSocket>,
|
|
|
|
remote_addr: SocketAddr,
|
2020-04-24 10:56:04 +00:00
|
|
|
metrics: Arc<NetworkMetrics>,
|
2020-04-08 14:26:42 +00:00
|
|
|
data_in: mpsc::UnboundedReceiver<Vec<u8>>,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
socket,
|
|
|
|
remote_addr,
|
2020-04-24 10:56:04 +00:00
|
|
|
metrics,
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
data_in: Mutex::new(data_in),
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
pub async fn read_from_wire(
|
2020-05-04 13:27:58 +00:00
|
|
|
&self,
|
|
|
|
cid: Cid,
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
w2c_cid_frame_s: &mut mpsc::UnboundedSender<(Cid, Frame)>,
|
2020-05-04 13:27:58 +00:00
|
|
|
end_receiver: oneshot::Receiver<()>,
|
|
|
|
) {
|
|
|
|
trace!("starting up udp read()");
|
2020-05-24 23:17:03 +00:00
|
|
|
let mut metrics_cache = CidFrameCache::new(self.metrics.frames_wire_in_total.clone(), cid);
|
2020-05-27 15:58:57 +00:00
|
|
|
let throughput_cache = self
|
|
|
|
.metrics
|
|
|
|
.wire_in_throughput
|
|
|
|
.with_label_values(&[&cid.to_string()]);
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
let mut data_in = self.data_in.lock().await;
|
2020-05-04 13:27:58 +00:00
|
|
|
let mut end_receiver = end_receiver.fuse();
|
|
|
|
while let Some(bytes) = select! {
|
|
|
|
r = data_in.next().fuse() => r,
|
|
|
|
_ = end_receiver => None,
|
|
|
|
} {
|
2020-04-24 10:56:04 +00:00
|
|
|
trace!("got raw UDP message with len: {}", bytes.len());
|
|
|
|
let frame_no = bytes[0];
|
|
|
|
let frame = match frame_no {
|
|
|
|
FRAME_HANDSHAKE => {
|
|
|
|
let bytes = &bytes[1..20];
|
|
|
|
let magic_number = [
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
];
|
|
|
|
Frame::Handshake {
|
|
|
|
magic_number,
|
|
|
|
version: [
|
|
|
|
u32::from_le_bytes([bytes[7], bytes[8], bytes[9], bytes[10]]),
|
|
|
|
u32::from_le_bytes([bytes[11], bytes[12], bytes[13], bytes[14]]),
|
|
|
|
u32::from_le_bytes([bytes[15], bytes[16], bytes[17], bytes[18]]),
|
|
|
|
],
|
|
|
|
}
|
|
|
|
},
|
2020-05-26 13:06:03 +00:00
|
|
|
FRAME_INIT => {
|
2020-04-24 10:56:04 +00:00
|
|
|
let pid = Pid::from_le_bytes([
|
|
|
|
bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
|
|
|
|
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14],
|
|
|
|
bytes[15], bytes[16],
|
|
|
|
]);
|
2020-05-26 13:06:03 +00:00
|
|
|
let secret = u128::from_le_bytes([
|
|
|
|
bytes[17], bytes[18], bytes[19], bytes[20], bytes[21], bytes[22],
|
|
|
|
bytes[23], bytes[24], bytes[25], bytes[26], bytes[27], bytes[28],
|
|
|
|
bytes[29], bytes[30], bytes[31], bytes[32],
|
|
|
|
]);
|
|
|
|
Frame::Init { pid, secret }
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
|
|
|
FRAME_SHUTDOWN => Frame::Shutdown,
|
|
|
|
FRAME_OPEN_STREAM => {
|
|
|
|
let bytes = &bytes[1..11];
|
|
|
|
let sid = Sid::from_le_bytes([
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
bytes[7],
|
|
|
|
]);
|
|
|
|
let prio = bytes[8];
|
|
|
|
let promises = bytes[9];
|
|
|
|
Frame::OpenStream {
|
|
|
|
sid,
|
|
|
|
prio,
|
|
|
|
promises,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
FRAME_CLOSE_STREAM => {
|
|
|
|
let bytes = &bytes[1..9];
|
|
|
|
let sid = Sid::from_le_bytes([
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
bytes[7],
|
|
|
|
]);
|
|
|
|
Frame::CloseStream { sid }
|
|
|
|
},
|
|
|
|
FRAME_DATA_HEADER => {
|
|
|
|
let bytes = &bytes[1..25];
|
|
|
|
let mid = Mid::from_le_bytes([
|
|
|
|
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6],
|
|
|
|
bytes[7],
|
|
|
|
]);
|
|
|
|
let sid = Sid::from_le_bytes([
|
|
|
|
bytes[8], bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14],
|
|
|
|
bytes[15],
|
|
|
|
]);
|
|
|
|
let length = u64::from_le_bytes([
|
|
|
|
bytes[16], bytes[17], bytes[18], bytes[19], bytes[20], bytes[21],
|
|
|
|
bytes[22], bytes[23],
|
|
|
|
]);
|
|
|
|
Frame::DataHeader { mid, sid, length }
|
|
|
|
},
|
|
|
|
FRAME_DATA => {
|
|
|
|
let mid = Mid::from_le_bytes([
|
|
|
|
bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
|
|
|
|
bytes[8],
|
|
|
|
]);
|
|
|
|
let start = u64::from_le_bytes([
|
|
|
|
bytes[9], bytes[10], bytes[11], bytes[12], bytes[13], bytes[14], bytes[15],
|
|
|
|
bytes[16],
|
|
|
|
]);
|
|
|
|
let length = u16::from_le_bytes([bytes[17], bytes[18]]);
|
|
|
|
let mut data = vec![0; length as usize];
|
2020-05-27 15:58:57 +00:00
|
|
|
throughput_cache.inc_by(length as i64);
|
2020-04-24 10:56:04 +00:00
|
|
|
data.copy_from_slice(&bytes[19..]);
|
|
|
|
Frame::Data { mid, start, data }
|
|
|
|
},
|
|
|
|
FRAME_RAW => {
|
|
|
|
let length = u16::from_le_bytes([bytes[1], bytes[2]]);
|
|
|
|
let mut data = vec![0; length as usize];
|
|
|
|
data.copy_from_slice(&bytes[3..]);
|
|
|
|
Frame::Raw(data)
|
|
|
|
},
|
|
|
|
_ => Frame::Raw(bytes),
|
|
|
|
};
|
2020-05-24 23:17:03 +00:00
|
|
|
metrics_cache.with_label_values(&frame).inc();
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
w2c_cid_frame_s.send((cid, frame)).await.unwrap();
|
2020-04-24 10:56:04 +00:00
|
|
|
}
|
|
|
|
trace!("shutting down udp read()");
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
pub async fn write_to_wire(&self, cid: Cid, mut c2w_frame_r: mpsc::UnboundedReceiver<Frame>) {
|
2020-05-04 13:27:58 +00:00
|
|
|
trace!("starting up udp write()");
|
2020-04-24 10:56:04 +00:00
|
|
|
let mut buffer = [0u8; 2000];
|
2020-05-24 23:17:03 +00:00
|
|
|
let mut metrics_cache = CidFrameCache::new(self.metrics.frames_wire_out_total.clone(), cid);
|
2020-05-27 15:58:57 +00:00
|
|
|
let throughput_cache = self
|
|
|
|
.metrics
|
|
|
|
.wire_out_throughput
|
|
|
|
.with_label_values(&[&cid.to_string()]);
|
Fixing the DEADLOCK in handshake -> channel creation
- this bug was initially called imbris bug, as it happened on his runners and i couldn't reproduce it locally at fist :)
- When in a Handshake a seperate mpsc::Channel was created for (Cid, Frame) transport
however the protocol could already catch non handshake data any more and push in into this
mpsc::Channel.
Then this channel got dropped and a fresh one was created for the network::Channel.
These droped Frames are ofc a BUG!
I tried multiple things to solve this:
- dont create a new mpsc::Channel, but instead bind it to the Protocol itself and always use 1.
This would work theoretically, but in bParticipant side we are using 1 mpsc::Channel<(Cid, Frame)>
to handle ALL the network::channel.
If now ever Protocol would have it's own, and with that every network::Channel had it's own it would no longer work out
Bad Idea...
- using the first method but creating the mpsc::Channel inside the scheduler instead protocol neither works, as the
scheduler doesnt know the remote_pid yet
- i dont want a hack to say the protocol only listen to 2 messages and then stop no matter what
So i switched over to the simply method now:
- Do everything like before with 2 mpsc::Channels
- after the handshake. close the receiver and listen for all remaining (cid, frame) combinations
- when starting the channel, reapply them to the new sender/listener combination
- added tracing
- switched Protocol RwLock to Mutex, as it's only ever 1
- Additionally changed the layout and introduces the c2w_frame_s and w2s_cid_frame_s name schema
- Fixed a bug in scheduler which WOULD cause a DEADLOCK if handshake would fail
- fixd a but in api_send_send_main, i need to store the stream_p otherwise it's immeadiatly closed and a stream_a.send() isn't guaranteed
- add extra test to verify that a send message is received even if the Stream is already closed
- changed OutGoing to Outgoing
- fixed a bug that `metrics.tick()` was never called
- removed 2 unused nightly features and added `deny_code`
2020-06-03 07:13:00 +00:00
|
|
|
while let Some(frame) = c2w_frame_r.next().await {
|
2020-05-24 23:17:03 +00:00
|
|
|
metrics_cache.with_label_values(&frame).inc();
|
2020-04-24 10:56:04 +00:00
|
|
|
let len = match frame {
|
|
|
|
Frame::Handshake {
|
|
|
|
magic_number,
|
|
|
|
version,
|
|
|
|
} => {
|
|
|
|
let x = FRAME_HANDSHAKE.to_be_bytes();
|
|
|
|
buffer[0] = x[0];
|
|
|
|
buffer[1] = magic_number[0];
|
|
|
|
buffer[2] = magic_number[1];
|
|
|
|
buffer[3] = magic_number[2];
|
|
|
|
buffer[4] = magic_number[3];
|
|
|
|
buffer[5] = magic_number[4];
|
|
|
|
buffer[6] = magic_number[5];
|
|
|
|
buffer[7] = magic_number[6];
|
|
|
|
let x = version[0].to_le_bytes();
|
|
|
|
buffer[8] = x[0];
|
|
|
|
buffer[9] = x[1];
|
|
|
|
buffer[10] = x[2];
|
|
|
|
buffer[11] = x[3];
|
|
|
|
let x = version[1].to_le_bytes();
|
|
|
|
buffer[12] = x[0];
|
|
|
|
buffer[13] = x[1];
|
|
|
|
buffer[14] = x[2];
|
|
|
|
buffer[15] = x[3];
|
|
|
|
let x = version[2].to_le_bytes();
|
|
|
|
buffer[16] = x[0];
|
|
|
|
buffer[17] = x[1];
|
|
|
|
buffer[18] = x[2];
|
|
|
|
buffer[19] = x[3];
|
|
|
|
20
|
|
|
|
},
|
2020-05-26 13:06:03 +00:00
|
|
|
Frame::Init { pid, secret } => {
|
|
|
|
let x = FRAME_INIT.to_be_bytes();
|
2020-04-24 10:56:04 +00:00
|
|
|
buffer[0] = x[0];
|
|
|
|
let x = pid.to_le_bytes();
|
|
|
|
buffer[1] = x[0];
|
|
|
|
buffer[2] = x[1];
|
|
|
|
buffer[3] = x[2];
|
|
|
|
buffer[4] = x[3];
|
|
|
|
buffer[5] = x[4];
|
|
|
|
buffer[6] = x[5];
|
|
|
|
buffer[7] = x[6];
|
|
|
|
buffer[8] = x[7];
|
|
|
|
buffer[9] = x[8];
|
|
|
|
buffer[10] = x[9];
|
|
|
|
buffer[11] = x[10];
|
|
|
|
buffer[12] = x[11];
|
|
|
|
buffer[13] = x[12];
|
|
|
|
buffer[14] = x[13];
|
|
|
|
buffer[15] = x[14];
|
|
|
|
buffer[16] = x[15];
|
2020-05-26 13:06:03 +00:00
|
|
|
let x = secret.to_le_bytes();
|
|
|
|
buffer[17] = x[0];
|
|
|
|
buffer[18] = x[1];
|
|
|
|
buffer[19] = x[2];
|
|
|
|
buffer[20] = x[3];
|
|
|
|
buffer[21] = x[4];
|
|
|
|
buffer[22] = x[5];
|
|
|
|
buffer[23] = x[6];
|
|
|
|
buffer[24] = x[7];
|
|
|
|
buffer[25] = x[8];
|
|
|
|
buffer[26] = x[9];
|
|
|
|
buffer[27] = x[10];
|
|
|
|
buffer[28] = x[11];
|
|
|
|
buffer[29] = x[12];
|
|
|
|
buffer[30] = x[13];
|
|
|
|
buffer[31] = x[14];
|
|
|
|
buffer[32] = x[15];
|
|
|
|
33
|
2020-04-24 10:56:04 +00:00
|
|
|
},
|
|
|
|
Frame::Shutdown => {
|
|
|
|
let x = FRAME_SHUTDOWN.to_be_bytes();
|
|
|
|
buffer[0] = x[0];
|
|
|
|
1
|
|
|
|
},
|
|
|
|
Frame::OpenStream {
|
|
|
|
sid,
|
|
|
|
prio,
|
|
|
|
promises,
|
|
|
|
} => {
|
|
|
|
let x = FRAME_OPEN_STREAM.to_be_bytes();
|
|
|
|
buffer[0] = x[0];
|
|
|
|
let x = sid.to_le_bytes();
|
|
|
|
buffer[1] = x[0];
|
|
|
|
buffer[2] = x[1];
|
|
|
|
buffer[3] = x[2];
|
|
|
|
buffer[4] = x[3];
|
|
|
|
buffer[5] = x[4];
|
|
|
|
buffer[6] = x[5];
|
|
|
|
buffer[7] = x[6];
|
|
|
|
buffer[8] = x[7];
|
|
|
|
let x = prio.to_le_bytes();
|
|
|
|
buffer[9] = x[0];
|
|
|
|
let x = promises.to_le_bytes();
|
|
|
|
buffer[10] = x[0];
|
|
|
|
11
|
|
|
|
},
|
|
|
|
Frame::CloseStream { sid } => {
|
|
|
|
let x = FRAME_CLOSE_STREAM.to_be_bytes();
|
|
|
|
buffer[0] = x[0];
|
|
|
|
let x = sid.to_le_bytes();
|
|
|
|
buffer[1] = x[0];
|
|
|
|
buffer[2] = x[1];
|
|
|
|
buffer[3] = x[2];
|
|
|
|
buffer[4] = x[3];
|
|
|
|
buffer[5] = x[4];
|
|
|
|
buffer[6] = x[5];
|
|
|
|
buffer[7] = x[6];
|
|
|
|
buffer[8] = x[7];
|
|
|
|
9
|
|
|
|
},
|
|
|
|
Frame::DataHeader { mid, sid, length } => {
|
|
|
|
let x = FRAME_DATA_HEADER.to_be_bytes();
|
|
|
|
buffer[0] = x[0];
|
|
|
|
let x = mid.to_le_bytes();
|
|
|
|
buffer[1] = x[0];
|
|
|
|
buffer[2] = x[1];
|
|
|
|
buffer[3] = x[2];
|
|
|
|
buffer[4] = x[3];
|
|
|
|
buffer[5] = x[4];
|
|
|
|
buffer[6] = x[5];
|
|
|
|
buffer[7] = x[6];
|
|
|
|
buffer[8] = x[7];
|
|
|
|
let x = sid.to_le_bytes();
|
|
|
|
buffer[9] = x[0];
|
|
|
|
buffer[10] = x[1];
|
|
|
|
buffer[11] = x[2];
|
|
|
|
buffer[12] = x[3];
|
|
|
|
buffer[13] = x[4];
|
|
|
|
buffer[14] = x[5];
|
|
|
|
buffer[15] = x[6];
|
|
|
|
buffer[16] = x[7];
|
|
|
|
let x = length.to_le_bytes();
|
|
|
|
buffer[17] = x[0];
|
|
|
|
buffer[18] = x[1];
|
|
|
|
buffer[19] = x[2];
|
|
|
|
buffer[20] = x[3];
|
|
|
|
buffer[21] = x[4];
|
|
|
|
buffer[22] = x[5];
|
|
|
|
buffer[23] = x[6];
|
|
|
|
buffer[24] = x[7];
|
|
|
|
25
|
|
|
|
},
|
|
|
|
Frame::Data { mid, start, data } => {
|
|
|
|
let x = FRAME_DATA.to_be_bytes();
|
|
|
|
buffer[0] = x[0];
|
|
|
|
let x = mid.to_le_bytes();
|
|
|
|
buffer[1] = x[0];
|
|
|
|
buffer[2] = x[1];
|
|
|
|
buffer[3] = x[2];
|
|
|
|
buffer[4] = x[3];
|
|
|
|
buffer[5] = x[4];
|
|
|
|
buffer[6] = x[5];
|
|
|
|
buffer[7] = x[6];
|
|
|
|
buffer[8] = x[7];
|
|
|
|
let x = start.to_le_bytes();
|
|
|
|
buffer[9] = x[0];
|
|
|
|
buffer[10] = x[1];
|
|
|
|
buffer[11] = x[2];
|
|
|
|
buffer[12] = x[3];
|
|
|
|
buffer[13] = x[4];
|
|
|
|
buffer[14] = x[5];
|
|
|
|
buffer[15] = x[6];
|
|
|
|
buffer[16] = x[7];
|
|
|
|
let x = (data.len() as u16).to_le_bytes();
|
|
|
|
buffer[17] = x[0];
|
|
|
|
buffer[18] = x[1];
|
2020-06-08 09:47:39 +00:00
|
|
|
buffer[19..(data.len() + 19)].clone_from_slice(&data[..]);
|
2020-05-27 15:58:57 +00:00
|
|
|
throughput_cache.inc_by(data.len() as i64);
|
2020-04-24 10:56:04 +00:00
|
|
|
19 + data.len()
|
|
|
|
},
|
|
|
|
Frame::Raw(data) => {
|
|
|
|
let x = FRAME_RAW.to_be_bytes();
|
|
|
|
buffer[0] = x[0];
|
|
|
|
let x = (data.len() as u16).to_le_bytes();
|
|
|
|
buffer[1] = x[0];
|
|
|
|
buffer[2] = x[1];
|
2020-06-08 09:47:39 +00:00
|
|
|
buffer[3..(data.len() + 3)].clone_from_slice(&data[..]);
|
2020-04-24 10:56:04 +00:00
|
|
|
3 + data.len()
|
|
|
|
},
|
|
|
|
};
|
|
|
|
let mut start = 0;
|
|
|
|
while start < len {
|
|
|
|
trace!(?start, ?len, "splitting up udp frame in multiple packages");
|
|
|
|
match self
|
|
|
|
.socket
|
|
|
|
.send_to(&buffer[start..len], self.remote_addr)
|
|
|
|
.await
|
|
|
|
{
|
|
|
|
Ok(n) => {
|
|
|
|
start += n;
|
|
|
|
if n != len {
|
|
|
|
error!(
|
|
|
|
"THIS DOESNT WORK, as RECEIVER CURRENLTY ONLY HANDLES 1 FRAME per \
|
|
|
|
UDP message. splitting up will fail!"
|
|
|
|
);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Err(e) => error!(?e, "need to handle that error!"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trace!("shutting down udp write()");
|
2020-04-08 14:26:42 +00:00
|
|
|
}
|
|
|
|
}
|