Skip to main content

UdpOptions

Struct UdpOptions 

Source
pub struct UdpOptions { /* private fields */ }
Available on crate feature udp only.
Expand description

Options for UdpSocket::bind_with.

use net_io::{UdpBudget, UdpOptions};
let options = UdpOptions::new()
    .amplification_factor(3) // a QUIC handshake (RFC 9000)
    .global_budget(UdpBudget { datagrams_per_sec: 50_000, bytes_per_sec: 60_000_000, burst: 5_000 });

Implementations§

Source§

impl UdpOptions

Source

pub fn new() -> UdpOptions

Factor 1, a 10 s window, UdpBudget::SOURCE_DEFAULT per source prefix (/32 for IPv4, /64 for IPv6) with a first burst of 16, UdpBudget::GLOBAL_DEFAULT for the socket, 65,536 sources, verification for 60 s and up to 65,536 verified peers, IPv6-only for IPv6 addresses.

Source

pub fn amplification_factor(self, factor: u8) -> UdpOptions

How many times the bytes received from an unverified source may be sent back to it (1 by default, at most 3; decision D-034).

Source

pub fn amplification_window(self, window: Duration) -> UdpOptions

How long received bytes count toward a source’s send allowance (10 s by default, at least 1 s, at most 1 hour). The allowance spans the current and the previous window, so a reply just after a window boundary is not refused.

Source

pub fn verification_lifetime(self, lifetime: Duration) -> UdpOptions

How long one UdpSocket::mark_verified lasts (60 s by default, at least 1 s, at most 1 day). Each call starts it again, so a protocol that proves its peer on every authenticated datagram never sees it lapse; a peer that went away stops being an unlimited target once it does.

Source

pub fn verified_table(self, entries: u32) -> UdpOptions

How many verified peers (address and port) are held (65,536 by default, about 100 bytes each). Past that, a new verification takes the place of one that lapsed or was least recently verified; that peer is limited again until it is verified again.

Source

pub fn source_budget(self, budget: UdpBudget) -> UdpOptions

The budget of each source (each prefix of UdpOptions::source_prefix).

Source

pub fn source_prefix(self, policy: PrefixPolicy) -> UdpOptions

How addresses are grouped into sources for the budgets (PrefixPolicy::DEFAULT: /32 for IPv4 and /64 for IPv6, as the TCP per-source cap groups them; PrefixPolicy::HOST budgets every address on its own). An IPv6 host usually owns a whole /64 and can send from any address in it, so a budget per address would give it millions. The send allowance and verification stay per address whatever the policy.

Source

pub fn new_source_burst(self, datagrams: u32) -> UdpOptions

How many datagrams a source not in the table may send at once (16 by default, never more than the source budget’s burst). Its bucket then fills to the full burst at the budget’s rate, so a source that keeps sending sees no difference after a moment, while a spoofer that rotates sources, or pushes its own entry out of a full table, gets this much per entry instead of a full burst.

Source

pub fn global_budget(self, budget: UdpBudget) -> UdpOptions

The budget of the whole socket (UdpBudget::GLOBAL_DEFAULT by default): what all sources together may send, so a flood from many sources, spoofed or not, reaches the caller at this rate at most.

Source

pub fn source_table(self, entries: u32) -> UdpOptions

How many sources are tracked (65,536 by default): budgets per source prefix and send allowances per address, each table bounded by this, about 200 bytes per source in all (12.5 MiB for a full default table).

Source

pub fn packet_info(self, on: bool) -> UdpOptions

IPV6_V6ONLY for an IPv6 address (on by default). Off, an IPv6 socket also receives IPv4; sources are reported as IPv4 and replies to them work. Reports each datagram’s destination address in Datagram::destination, for a socket bound to a wildcard that must answer from the address it was asked on. One recvmsg per datagram instead of recvfrom. Unix only: bind_with fails with Unsupported on Windows, and recv_batch does not fill it.

Source

pub fn ipv6_only(self, on: bool) -> UdpOptions

IPV6_V6ONLY for IPv6 addresses (on by default).

Trait Implementations§

Source§

impl Clone for UdpOptions

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for UdpOptions

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for UdpOptions

Source§

fn default() -> UdpOptions

Returns the “default value” for a type. Read more
Source§

impl Eq for UdpOptions

Source§

impl PartialEq for UdpOptions

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for UdpOptions

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.