mirror of
https://codeberg.org/icewind/netnsd.git
synced 2026-06-03 17:14:06 +02:00
reload destination -> target and module fixes
This commit is contained in:
parent
645a6e9978
commit
5e5ee227fc
10 changed files with 69 additions and 42 deletions
|
|
@ -1,8 +1,8 @@
|
|||
mod destination;
|
||||
mod target;
|
||||
mod name;
|
||||
mod source;
|
||||
|
||||
pub use crate::config::destination::ForwardDestination;
|
||||
pub use crate::config::target::ForwardTarget;
|
||||
pub use crate::config::name::NamespaceName;
|
||||
pub use crate::config::source::ForwardSource;
|
||||
use serde::Deserialize;
|
||||
|
|
@ -80,7 +80,7 @@ pub struct NamespaceConfig {
|
|||
#[derive(Deserialize, Debug)]
|
||||
pub struct ForwardConfig {
|
||||
pub source: ForwardSource,
|
||||
pub destination: ForwardDestination,
|
||||
pub target: ForwardTarget,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
|
|||
|
|
@ -5,31 +5,31 @@ use std::net::{IpAddr, SocketAddr};
|
|||
use std::str::FromStr;
|
||||
|
||||
#[derive(Debug, PartialEq, Clone, Hash, Eq)]
|
||||
pub struct ForwardDestination {
|
||||
pub struct ForwardTarget {
|
||||
pub addr: SocketAddr,
|
||||
}
|
||||
|
||||
impl From<ForwardDestination> for SocketAddr {
|
||||
fn from(value: ForwardDestination) -> Self {
|
||||
impl From<ForwardTarget> for SocketAddr {
|
||||
fn from(value: ForwardTarget) -> Self {
|
||||
value.addr
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for ForwardDestination {
|
||||
impl Display for ForwardTarget {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.addr)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'de> Deserialize<'de> for ForwardDestination {
|
||||
impl<'de> Deserialize<'de> for ForwardTarget {
|
||||
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
|
||||
where
|
||||
D: Deserializer<'de>,
|
||||
{
|
||||
struct ForwardDestinationVisitor;
|
||||
struct ForwardTargetVisitor;
|
||||
|
||||
impl Visitor<'_> for ForwardDestinationVisitor {
|
||||
type Value = ForwardDestination;
|
||||
impl Visitor<'_> for ForwardTargetVisitor {
|
||||
type Value = ForwardTarget;
|
||||
|
||||
fn expecting(&self, formatter: &mut Formatter) -> std::fmt::Result {
|
||||
formatter
|
||||
|
|
@ -51,7 +51,7 @@ impl<'de> Deserialize<'de> for ForwardDestination {
|
|||
E: Error,
|
||||
{
|
||||
let ip = IpAddr::from([127, 0, 0, 1]);
|
||||
Ok(ForwardDestination {
|
||||
Ok(ForwardTarget {
|
||||
addr: SocketAddr::from((ip, v)),
|
||||
})
|
||||
}
|
||||
|
|
@ -76,11 +76,11 @@ impl<'de> Deserialize<'de> for ForwardDestination {
|
|||
let addr = v
|
||||
.parse()
|
||||
.map_err(|_| E::invalid_value(Unexpected::Str(v), &self))?;
|
||||
Ok(ForwardDestination { addr })
|
||||
Ok(ForwardTarget { addr })
|
||||
}
|
||||
}
|
||||
|
||||
deserializer.deserialize_any(ForwardDestinationVisitor)
|
||||
deserializer.deserialize_any(ForwardTargetVisitor)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -90,14 +90,14 @@ fn test_de() {
|
|||
|
||||
let addr_str = "127.0.0.1:80";
|
||||
let addr = SocketAddr::from_str("127.0.0.1:80").unwrap();
|
||||
fn port_addr(port: u16) -> ForwardDestination {
|
||||
ForwardDestination {
|
||||
fn port_addr(port: u16) -> ForwardTarget {
|
||||
ForwardTarget {
|
||||
addr: SocketAddr::new(IpAddr::from([127, 0, 0, 1]), port),
|
||||
}
|
||||
}
|
||||
|
||||
assert_de_tokens(&ForwardDestination { addr }, &[Token::String(addr_str)]);
|
||||
assert_de_tokens(&ForwardDestination { addr }, &[Token::Str(addr_str)]);
|
||||
assert_de_tokens(&ForwardTarget { addr }, &[Token::String(addr_str)]);
|
||||
assert_de_tokens(&ForwardTarget { addr }, &[Token::Str(addr_str)]);
|
||||
assert_de_tokens(&port_addr(80), &[Token::Str("80")]);
|
||||
|
||||
assert_de_tokens(&port_addr(80), &[Token::U8(80)]);
|
||||
|
|
@ -107,19 +107,19 @@ fn test_de() {
|
|||
assert_de_tokens(&port_addr(80), &[Token::I16(80)]);
|
||||
assert_de_tokens(&port_addr(80), &[Token::I64(80)]);
|
||||
|
||||
assert_de_tokens_error::<ForwardDestination>(
|
||||
assert_de_tokens_error::<ForwardTarget>(
|
||||
&[Token::I64(-80)],
|
||||
"invalid value: integer `-80`, expected Either a port as integer, or a string containing a socket address",
|
||||
);
|
||||
assert_de_tokens_error::<ForwardDestination>(
|
||||
assert_de_tokens_error::<ForwardTarget>(
|
||||
&[Token::U64(12345678)],
|
||||
"invalid value: integer `12345678`, expected Either a port as integer, or a string containing a socket address",
|
||||
);
|
||||
assert_de_tokens_error::<ForwardDestination>(
|
||||
assert_de_tokens_error::<ForwardTarget>(
|
||||
&[Token::Str("hello world")],
|
||||
"invalid value: string \"hello world\", expected Either a port as integer, or a string containing a socket address",
|
||||
);
|
||||
assert_de_tokens_error::<ForwardDestination>(
|
||||
assert_de_tokens_error::<ForwardTarget>(
|
||||
&[Token::Str("localhost:80")],
|
||||
"invalid value: string \"localhost:80\", expected Either a port as integer, or a string containing a socket address",
|
||||
);
|
||||
Loading…
Add table
Add a link
Reference in a new issue