pub struct UdpOptions { /* private fields */ }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
impl UdpOptions
Sourcepub fn new() -> UdpOptions
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.
Sourcepub fn amplification_factor(self, factor: u8) -> UdpOptions
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).
Sourcepub fn amplification_window(self, window: Duration) -> UdpOptions
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.
Sourcepub fn verification_lifetime(self, lifetime: Duration) -> UdpOptions
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.
Sourcepub fn verified_table(self, entries: u32) -> UdpOptions
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.
Sourcepub fn source_budget(self, budget: UdpBudget) -> UdpOptions
pub fn source_budget(self, budget: UdpBudget) -> UdpOptions
The budget of each source (each prefix of UdpOptions::source_prefix).
Sourcepub fn source_prefix(self, policy: PrefixPolicy) -> UdpOptions
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.
Sourcepub fn new_source_burst(self, datagrams: u32) -> UdpOptions
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.
Sourcepub fn global_budget(self, budget: UdpBudget) -> UdpOptions
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.
Sourcepub fn source_table(self, entries: u32) -> UdpOptions
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).
Sourcepub fn packet_info(self, on: bool) -> UdpOptions
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.
Sourcepub fn ipv6_only(self, on: bool) -> UdpOptions
pub fn ipv6_only(self, on: bool) -> UdpOptions
IPV6_V6ONLY for IPv6 addresses (on by default).