Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasohland committed Dec 26, 2023
1 parent efd0a5a commit 6ccba6d
Show file tree
Hide file tree
Showing 20 changed files with 455 additions and 694 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ members = [
"tools/netzwerker",
"tools/rist-io",
]
resolver = "2"
6 changes: 3 additions & 3 deletions crates/rist-rs-bits/src/gre/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,9 +221,9 @@ mod test {
assert!(!gre.has_key());
assert!(!gre.has_sequence());
assert_eq!(gre.version(), 0);
assert!(matches!(gre.checksum(), None));
assert!(matches!(gre.sequence_number(), None));
assert!(matches!(gre.key(), None));
assert!(gre.checksum().is_none());
assert!(gre.sequence_number().is_none());
assert!(gre.key().is_none());
}

#[test]
Expand Down
4 changes: 2 additions & 2 deletions crates/rist-rs-bits/src/ip/v4/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ fn broken_total_len() {
]);

// broken total length -> no payload
assert!(matches!(ip.payload(), Err(_)));
assert!(ip.payload().is_err());
// options still valid because header is valid
assert!(matches!(ip.options(), Ok(_)));
assert!(ip.options().is_ok());
}
9 changes: 3 additions & 6 deletions crates/rist-rs-bits/src/rtp/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -280,14 +280,11 @@ mod test {
#[test]
fn invalid() {
// conversion from invalid length should fail
assert!(matches!(
RTPView::try_from(RTP_INVALID_LEN.as_slice()),
Err(_)
));
assert!(RTPView::try_from(RTP_INVALID_LEN.as_slice()).is_err());

let broken_padding = packet(&RTP_BROKEN_PADDING);
assert!(broken_padding.has_padding());
assert!(matches!(broken_padding.payload(), Err(_)));
assert!(matches!(broken_padding.padding_len().unwrap(), Err(_)))
assert!(broken_padding.payload().is_err());
assert!(broken_padding.padding_len().unwrap().is_err())
}
}
6 changes: 3 additions & 3 deletions crates/rist-rs-std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ version = "0.0.1"
[dependencies]
rand = "0.8"
rist-rs-core = { path = "../rist-rs-core", features = ["std"] }
rist-rs-transport-dtls-openssl = { path = "../rist-rs-transport-dtls-openssl", optional = true }
rist-rs-types = { path = "../rist-rs-types", features = ["std"] }
rist-rs-util = { path = "../rist-rs-util", features = ["std"] }
socket2 = { version = "0.4" }
slab = { version = "0.4" }
mio = { version = "0.8", features = ["net", "os-poll"] }
tracing = { version = "0.1", default-features = false }

[dev-dependencies]
tracing-subscriber = { version = "0.3" }

[features]
default = ["openssl"]
default = []
log = ["tracing/log"]
openssl = ["rist-rs-transport-dtls-openssl"]
68 changes: 68 additions & 0 deletions crates/rist-rs-std/examples/runtime_simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
use std::io;

use rist_rs_std::StdRuntime;
use rist_rs_types::traits::{
protocol::{Ctl, Protocol, ProtocolEvent, IOV},
runtime::Runtime,
};

#[derive(Clone, Debug)]
struct SimpleCtl;

impl Ctl for SimpleCtl {
type Error = io::Error;

type Output = ();

fn start() -> Self {
todo!()
}

fn shutdown() -> Self {
todo!()
}
}

struct Server {}

impl Server {
fn new() -> Self {
Self {}
}
}

impl<R> Protocol<R> for Server
where
R: Runtime,
{
type Ctl = SimpleCtl;

fn run(&mut self, rt: &mut R, iov: &[IOV<R, Self::Ctl>]) -> ProtocolEvent<R> {
let mut buf = [0u8; 1500];
for ev in iov {
match ev {
IOV::Readable(socket) => match rt.recv_from(*socket, &mut buf) {
Err(err) => tracing::error!(?err, "recv_from"),
Ok((len, addr)) => {
let packet = buf.split_at(len).0;
if let Err(err) = rt.send_to(*socket, packet, addr) {
tracing::error!(?err, "send_to")
}
}
},
IOV::Writeable(_) => {}
IOV::Error(socket, err) => {
tracing::error!(?socket, ?err, "error");
}
IOV::Ctl(_) => todo!(),
IOV::Empty => todo!(),
}
}
ProtocolEvent::asap(&rt.get_default_clock())
}
}

fn main() {
let rt = StdRuntime::new();
rt.run(Server::new());
}
Loading

0 comments on commit 6ccba6d

Please sign in to comment.