Skip to content

Commit

Permalink
Move Stelline from tests to src/stelline. (#315)
Browse files Browse the repository at this point in the history
This PR moves Stelline to be a regular module gated by the unstable-stelline
feature.
  • Loading branch information
Philip-NLnetLabs authored May 15, 2024
1 parent 5c7dd73 commit 5586fff
Show file tree
Hide file tree
Showing 17 changed files with 142 additions and 133 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ smallvec = { version = "1.3", optional = true }
tokio = { version = "1.33", optional = true, features = ["io-util", "macros", "net", "time", "sync", "rt-multi-thread" ] }
tokio-rustls = { version = "0.26", optional = true, default-features = false }
tracing = { version = "0.1.40", optional = true }
tracing-subscriber = { version = "0.3.18", optional = true, features = ["env-filter"] }

# For testing in integration tests:
#mock_instant = { version = "0.4.0", optional = true }
Expand All @@ -62,6 +63,7 @@ zonefile = ["bytes", "serde", "std"]
# Unstable features
unstable-client-transport = [ "moka", "net", "tracing" ]
unstable-server-transport = ["arc-swap", "chrono/clock", "hex", "libc", "net", "tracing"]
unstable-stelline = ["tokio/test-util", "tracing", "tracing-subscriber", "unstable-server-transport", "zonefile"]
unstable-zonetree = ["futures", "parking_lot", "serde", "tokio", "tracing"]

# Test features
Expand All @@ -84,7 +86,6 @@ tokio = { version = "1.37", features = ["rt-multi-thread", "io-util
tokio-rustls = { version = "0.26", default-features = false, features = [ "ring", "logging", "tls12" ] }
tokio-test = "0.4"
tokio-tfo = { version = "0.2.0" }
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
webpki-roots = { version = "0.26" }

# For the "mysql-zone" example
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ pub mod net;
pub mod rdata;
pub mod resolv;
pub mod sign;
pub mod stelline;
pub mod test;
pub mod tsig;
pub mod utils;
Expand Down
File renamed without changes.
6 changes: 4 additions & 2 deletions tests/net/stelline/channel.rs → src/stelline/channel.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
// Using tokio::io::duplex() seems appealing but it can only create a channel
// between two ends, it isn't possible to create additional client ends for a
// single server end for example.
use std::boxed::Box;
use std::collections::HashMap;
use std::future::ready;
use std::future::Future;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::pin::Pin;
use std::sync::{Arc, Mutex};
use std::task::{Context, Poll};
use std::vec::Vec;
use std::{cmp, io};

use futures_util::FutureExt;
Expand All @@ -16,10 +18,10 @@ use tokio::sync::mpsc;
use tokio::sync::mpsc::error::TryRecvError;
use tracing::trace;

use domain::net::client::protocol::{
use crate::net::client::protocol::{
AsyncConnect, AsyncDgramRecv, AsyncDgramSend,
};
use domain::net::server::sock::{AsyncAccept, AsyncDgramSock};
use crate::net::server::sock::{AsyncAccept, AsyncDgramSock};

// If MSRV gets bumped to 1.69.0 we can replace these with a const SocketAddr.
pub const DEF_CLIENT_ADDR: IpAddr = IpAddr::V4(Ipv4Addr::LOCALHOST);
Expand Down
32 changes: 19 additions & 13 deletions tests/net/stelline/client.rs → src/stelline/client.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#![allow(clippy::type_complexity)]
use std::boxed::Box;
use std::collections::HashMap;
use std::future::{ready, Future};
use std::net::IpAddr;
use std::pin::Pin;
use std::rc::Rc;
use std::sync::Mutex;
use std::time::Duration;
use std::vec::Vec;

use bytes::Bytes;
/*
Expand All @@ -15,18 +17,16 @@ use mock_instant::MockClock;
use tracing::{debug, info_span, trace};
use tracing_subscriber::EnvFilter;

use domain::base::iana::Opcode;
use domain::base::opt::{ComposeOptData, OptData};
use domain::base::{Message, MessageBuilder};
use domain::net::client::request::{
use crate::base::iana::{Opcode, OptionCode};
use crate::base::opt::{ComposeOptData, OptData};
use crate::base::{Message, MessageBuilder};
use crate::net::client::request::{
ComposeRequest, Error, RequestMessage, SendRequest,
};

use crate::net::stelline::matches::match_msg;
use crate::net::stelline::parse_query;
use crate::net::stelline::parse_stelline::{
Entry, Reply, Stelline, StepType,
};
use super::matches::match_msg;
use super::parse_query;
use super::parse_stelline::{Entry, Reply, Stelline, StepType};

use super::channel::DEF_CLIENT_ADDR;

Expand Down Expand Up @@ -66,7 +66,7 @@ impl<'a> StellineError<'a> {

#[derive(Debug)]
pub enum StellineErrorCause {
ClientError(domain::net::client::request::Error),
ClientError(Error),
MismatchedAnswer,
MissingResponse,
MissingStepEntry,
Expand All @@ -75,8 +75,8 @@ pub enum StellineErrorCause {
MissingClient,
}

impl From<domain::net::client::request::Error> for StellineErrorCause {
fn from(err: domain::net::client::request::Error) -> Self {
impl From<Error> for StellineErrorCause {
fn from(err: Error) -> Self {
Self::ClientError(err)
}
}
Expand Down Expand Up @@ -554,6 +554,12 @@ impl CurrStepValue {
}
}

impl Default for CurrStepValue {
fn default() -> Self {
Self::new()
}
}

impl std::fmt::Display for CurrStepValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_fmt(format_args!("{}", self.get()))
Expand All @@ -567,7 +573,7 @@ struct RawOptData<'a> {
}

impl<'a> OptData for RawOptData<'a> {
fn code(&self) -> domain::base::iana::OptionCode {
fn code(&self) -> OptionCode {
u16::from_be_bytes(self.bytes[0..2].try_into().unwrap()).into()
}
}
Expand Down
9 changes: 5 additions & 4 deletions tests/net/stelline/connect.rs → src/stelline/connect.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
use std::boxed::Box;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;

use domain::net::client::protocol::AsyncConnect;
use crate::net::client::protocol::AsyncConnect;

use crate::net::stelline::client::CurrStepValue;
use crate::net::stelline::connection::Connection;
use crate::net::stelline::parse_stelline::Stelline;
use super::client::CurrStepValue;
use super::connection::Connection;
use super::parse_stelline::Stelline;

pub struct Connect {
stelline: Stelline,
Expand Down
11 changes: 6 additions & 5 deletions tests/net/stelline/connection.rs → src/stelline/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ use std::pin::Pin;
use std::sync::Arc;
use std::task::Waker;
use std::task::{Context, Poll};
use std::vec::Vec;

use crate::net::stelline::client::CurrStepValue;
use crate::net::stelline::parse_stelline::Stelline;
use crate::net::stelline::server::do_server;
use super::client::CurrStepValue;
use super::parse_stelline::Stelline;
use super::server::do_server;

use tokio::io::{AsyncRead, AsyncWrite, ReadBuf};

use domain::base::message_builder::AdditionalBuilder;
use domain::base::Message;
use crate::base::message_builder::AdditionalBuilder;
use crate::base::Message;

#[derive(Debug)]
pub struct Connection {
Expand Down
14 changes: 8 additions & 6 deletions tests/net/stelline/dgram.rs → src/stelline/dgram.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
//! Provide server-side of datagram protocols
use std::boxed::Box;
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;
use std::sync::Mutex as SyncMutex;
use std::task::{Context, Poll, Waker};
use std::vec::Vec;

use tokio::io::ReadBuf;

use domain::base::message_builder::AdditionalBuilder;
use domain::base::Message;
use domain::net::client::protocol::{
use crate::base::message_builder::AdditionalBuilder;
use crate::base::Message;
use crate::net::client::protocol::{
AsyncConnect, AsyncDgramRecv, AsyncDgramSend,
};

use crate::net::stelline::client::CurrStepValue;
use crate::net::stelline::parse_stelline::Stelline;
use crate::net::stelline::server::do_server;
use super::client::CurrStepValue;
use super::parse_stelline::Stelline;
use super::server::do_server;

#[derive(Clone, Debug)]
pub struct Dgram {
Expand Down
19 changes: 10 additions & 9 deletions tests/net/stelline/matches.rs → src/stelline/matches.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use crate::net::stelline::parse_query;
use crate::net::stelline::parse_stelline::{Entry, Matches, Reply};
use domain::base::iana::{Opcode, OptRcode, Rtype};
use domain::base::opt::{Opt, OptRecord};
use domain::base::{Message, ParsedName, QuestionSection, RecordSection};
use domain::dep::octseq::Octets;
use domain::rdata::ZoneRecordData;
use domain::zonefile::inplace::Entry as ZonefileEntry;
use super::parse_query;
use super::parse_stelline::{Entry, Matches, Reply};
use crate::base::iana::{Opcode, OptRcode, Rtype};
use crate::base::opt::{Opt, OptRecord};
use crate::base::{Message, ParsedName, QuestionSection, RecordSection};
use crate::dep::octseq::Octets;
use crate::rdata::ZoneRecordData;
use crate::zonefile::inplace::Entry as ZonefileEntry;
use std::vec::Vec;

pub fn match_msg<'a, Octs: AsRef<[u8]> + Clone + Octets + 'a>(
entry: &Entry,
Expand Down Expand Up @@ -340,7 +341,7 @@ fn match_section<
let mat_opt =
match_edns_bytes.map(|bytes| Opt::from_slice(bytes).unwrap());

if match_section.len() != msg_count.into() {
if match_section.len() != <u16 as Into<usize>>::into(msg_count) {
if verbose {
println!("match_section: expected section length {} doesn't match message count {}", match_section.len(), msg_count);
if !match_section.is_empty() {
Expand Down
1 change: 1 addition & 0 deletions tests/net/stelline/mod.rs → src/stelline/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#![cfg(feature = "unstable-stelline")]
pub mod channel;
pub mod client;
pub mod connect;
Expand Down
Loading

0 comments on commit 5586fff

Please sign in to comment.