Skip to content

Commit

Permalink
fix: ensure socket options set before std conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tbraun96 committed Nov 23, 2024
1 parent 1267bff commit 28c33d1
Show file tree
Hide file tree
Showing 9 changed files with 15 additions and 195 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ rand = { default-features = false, version = "0.8.5" }
async-stream = { default-features = false, version = "0.3.3" }
sync_wrapper = { default-features = false, version = "1.0.0" }
async-recursion = { version = "1.0.4" }
rstest = { version = "0.18.2" }
rstest = { version = "0.23.0" }
bincode = { default-features = false, version = "1.3.3" }
serde = { version="1.0.152", default-features = false }
futures = { version = "0.3.25", default-features = false }
Expand Down
4 changes: 2 additions & 2 deletions citadel_proto/tests/connections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ pub mod tests {
#[rstest]
#[case("127.0.0.1:0")]
#[case("[::1]:0")]
#[timeout(Duration::from_secs(240))]
#[timeout(Duration::from_secs(60))]
#[tokio::test(flavor = "multi_thread")]
async fn test_tcp_or_tls(
#[case] addr: SocketAddr,
Expand Down Expand Up @@ -109,7 +109,7 @@ pub mod tests {
#[rstest]
#[case("127.0.0.1:0")]
#[case("[::1]:0")]
#[timeout(Duration::from_secs(240))]
#[timeout(Duration::from_secs(60))]
#[tokio::test(flavor = "multi_thread")]
async fn test_many_proto_conns(
#[case] addr: SocketAddr,
Expand Down
8 changes: 4 additions & 4 deletions citadel_sdk/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ mod tests {
}

#[rstest]
#[timeout(std::time::Duration::from_secs(90))]
#[case(
EncryptionAlgorithm::AES_GCM_256,
KemAlgorithm::Kyber,
Expand All @@ -108,6 +107,7 @@ mod tests {
KemAlgorithm::Kyber,
SigAlgorithm::Falcon1024
)]
#[timeout(std::time::Duration::from_secs(90))]
#[tokio::test]
async fn test_c2s_file_transfer_revfs(
#[case] enx: EncryptionAlgorithm,
Expand Down Expand Up @@ -173,12 +173,12 @@ mod tests {
}

#[rstest]
#[timeout(std::time::Duration::from_secs(90))]
#[case(
EncryptionAlgorithm::AES_GCM_256,
KemAlgorithm::Kyber,
SigAlgorithm::None
)]
#[timeout(std::time::Duration::from_secs(90))]
#[tokio::test]
async fn test_c2s_file_transfer_revfs_take(
#[case] enx: EncryptionAlgorithm,
Expand Down Expand Up @@ -246,12 +246,12 @@ mod tests {
}

#[rstest]
#[timeout(std::time::Duration::from_secs(90))]
#[case(
EncryptionAlgorithm::AES_GCM_256,
KemAlgorithm::Kyber,
SigAlgorithm::None
)]
#[timeout(std::time::Duration::from_secs(90))]
#[tokio::test]
async fn test_c2s_file_transfer_revfs_delete(
#[case] enx: EncryptionAlgorithm,
Expand Down Expand Up @@ -321,7 +321,7 @@ mod tests {

#[rstest]
#[case(SecrecyMode::BestEffort)]
#[timeout(Duration::from_secs(240))]
#[timeout(Duration::from_secs(60))]
#[tokio::test(flavor = "multi_thread")]
async fn test_p2p_file_transfer_revfs(
#[case] secrecy_mode: SecrecyMode,
Expand Down
2 changes: 1 addition & 1 deletion citadel_sdk/src/remote_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1341,7 +1341,6 @@ mod tests {
}

#[rstest]
#[timeout(std::time::Duration::from_secs(90))]
#[case(
EncryptionAlgorithm::AES_GCM_256,
KemAlgorithm::Kyber,
Expand All @@ -1352,6 +1351,7 @@ mod tests {
KemAlgorithm::Kyber,
SigAlgorithm::Falcon1024
)]
#[timeout(std::time::Duration::from_secs(90))]
#[tokio::test]
async fn test_c2s_file_transfer(
#[case] enx: EncryptionAlgorithm,
Expand Down
6 changes: 3 additions & 3 deletions citadel_sdk/tests/stress_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ mod tests {
#[rstest]
#[case(500, SecrecyMode::Perfect)]
#[case(500, SecrecyMode::BestEffort)]
#[timeout(std::time::Duration::from_secs(80))]
#[timeout(std::time::Duration::from_secs(240))]
#[tokio::test(flavor = "multi_thread")]
async fn stress_test_c2s_messaging(
#[case] message_count: usize,
Expand Down Expand Up @@ -265,7 +265,7 @@ mod tests {
#[rstest]
#[case(100, SecrecyMode::Perfect, None)]
#[case(100, SecrecyMode::BestEffort, Some("test-password"))]
#[timeout(std::time::Duration::from_secs(80))]
#[timeout(std::time::Duration::from_secs(240))]
#[tokio::test(flavor = "multi_thread")]
async fn stress_test_c2s_messaging_kyber(
#[case] message_count: usize,
Expand Down Expand Up @@ -448,7 +448,7 @@ mod tests {

#[rstest]
#[case(500, 3)]
#[timeout(std::time::Duration::from_secs(240))]
#[timeout(std::time::Duration::from_secs(90))]
#[tokio::test(flavor = "multi_thread")]
async fn stress_test_group_broadcast(#[case] message_count: usize, #[case] peer_count: usize) {
citadel_logging::setup_log();
Expand Down
91 changes: 0 additions & 91 deletions citadel_wire/examples/client_sym3.rs

This file was deleted.

89 changes: 0 additions & 89 deletions citadel_wire/examples/server_sym3.rs

This file was deleted.

2 changes: 1 addition & 1 deletion citadel_wire/src/standard/quic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -373,10 +373,10 @@ mod tests {
use std::net::SocketAddr;

#[rstest]
#[timeout(std::time::Duration::from_secs(3))]
#[case("127.0.0.1:0")]
#[case("[::1]:0")]
#[trace]
#[timeout(std::time::Duration::from_secs(5))]
#[tokio::test]
async fn test_quic(#[case] addr: SocketAddr) -> std::io::Result<()> {
citadel_logging::setup_log();
Expand Down
6 changes: 3 additions & 3 deletions citadel_wire/src/standard/socket_helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ fn setup_base_socket(addr: SocketAddr, socket: &Socket, reuse: bool) -> Result<(
}
}

socket.set_nonblocking(true)?;

if !cfg!(windows) && addr.is_ipv6() {
socket.set_only_v6(false)?;
}
Expand Down Expand Up @@ -66,15 +68,14 @@ fn get_udp_socket_inner<T: std::net::ToSocketAddrs>(
let socket = get_udp_socket_builder(domain)?;
setup_bind(addr, &socket, reuse)?;
let std_socket: std::net::UdpSocket = socket.into();
std_socket.set_nonblocking(true)?;
let tokio_socket = citadel_io::UdpSocket::from_std(std_socket)?;
Ok(tokio_socket)
}

fn windows_check(addr: SocketAddr) -> SocketAddr {
// if feature "localhost-testing" is enabled, and, we are not on mac, then, we will bind to 127.0.0.1
if cfg!(feature = "localhost-testing") && !cfg!(target_os = "macos") {
log::warn!(target: "citadel", "Localhost testing is enabled on non-mac OS will ensure bind is 127.0.0.1");
log::warn!(target: "citadel", "Localhost testing is enabled on non-mac OS. Will ensure bind is 127.0.0.1");
if addr.is_ipv4() {
SocketAddr::new(IpAddr::V4(std::net::Ipv4Addr::LOCALHOST), addr.port())
} else {
Expand Down Expand Up @@ -107,7 +108,6 @@ fn get_tcp_listener_inner<T: std::net::ToSocketAddrs>(
setup_bind(addr, &socket, reuse)?;
socket.listen(1024)?;
let std_tcp_socket: std::net::TcpListener = socket.into();
std_tcp_socket.set_nonblocking(true)?;
Ok(citadel_io::TcpListener::from_std(std_tcp_socket)?)
}

Expand Down

0 comments on commit 28c33d1

Please sign in to comment.