Skip to content

Commit

Permalink
WIP cleaned synthetic-link
Browse files Browse the repository at this point in the history
  • Loading branch information
fixxxedpoint committed Dec 16, 2022
1 parent 542d26d commit 251955c
Showing 1 changed file with 21 additions and 11 deletions.
32 changes: 21 additions & 11 deletions scripts/synthetic-network/synthetic-link/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::ops::RangeInclusive;
use std::{borrow::Borrow, ops::RangeInclusive};

use anyhow::bail;
use reqwest::Client;
use serde::{Deserialize, Serialize};
use serde_repr::{Deserialize_repr, Serialize_repr};
Expand Down Expand Up @@ -102,12 +103,30 @@ impl Default for Flow {
}
}

#[derive(Serialize_repr, Deserialize_repr, Clone)]
#[repr(u8)]
pub enum Protocol {
Icmp = 1,
Tcp = 6,
Udp = 17,
All = 0,
}

#[derive(Serialize, Deserialize, Clone)]
#[serde(from = "PortRangeSerde", into = "PortRangeSerde")]
pub struct PortRange(RangeInclusive<u16>);

impl PortRange {
pub fn range(&self) -> &RangeInclusive<u16> {
pub fn new(port_min: u16, port_max: u16) -> anyhow::Result<Self> {
if port_min > port_max {
bail!("port_min is larger than port_max");
}
Ok(PortRange(port_min..=port_max))
}
}

impl Borrow<RangeInclusive<u16>> for PortRange {
fn borrow(&self) -> &RangeInclusive<u16> {
&self.0
}
}
Expand Down Expand Up @@ -162,15 +181,6 @@ impl Into<IpPatternSerde> for IpPattern {
}
}

#[derive(Serialize_repr, Deserialize_repr, Clone)]
#[repr(u8)]
pub enum Protocol {
Icmp = 1,
Tcp = 6,
Udp = 17,
All = 0,
}

pub struct SyntheticNetworkClient {
client: Client,
url: String,
Expand Down

0 comments on commit 251955c

Please sign in to comment.