pub trait PortAllocImpl {
type Id: Hash;
type PortAvailableArg;
const EPHEMERAL_RANGE: RangeInclusive<u16>;
// Required method
fn is_port_available(
&self,
id: &Self::Id,
port: u16,
arg: &Self::PortAvailableArg,
) -> bool;
// Provided method
fn rand_ephemeral<R: Rng>(rng: &mut R) -> EphemeralPort<Self> { ... }
}
Expand description
Trait that configures the behavior of port allocation.
PortAllocImpl
provides the types, custom behaviors, and port availability
checks necessary to operate the port allocation algorithm.
Required Associated Constants§
Sourceconst EPHEMERAL_RANGE: RangeInclusive<u16>
const EPHEMERAL_RANGE: RangeInclusive<u16>
The range of ports that can be allocated.
Local ports used in transport protocols are called Ephemeral Ports. Different transport protocols may define different ranges for the issued ports. Port allocation algorithms should guarantee to return a port in this range.
Required Associated Types§
Sourcetype Id: Hash
type Id: Hash
The “flow” identifier used to allocate port Ids.
The Id
is typically the 3 elements other other than the local port in
the 4-tuple (local IP:port, remote IP:port) that is used to uniquely
identify the flow information of a connection.
Sourcetype PortAvailableArg
type PortAvailableArg
An extra argument passed to is_port_available
.
Required Methods§
Sourcefn is_port_available(
&self,
id: &Self::Id,
port: u16,
arg: &Self::PortAvailableArg,
) -> bool
fn is_port_available( &self, id: &Self::Id, port: u16, arg: &Self::PortAvailableArg, ) -> bool
Checks if port
is available to be used for the flow id
.
Implementers return true
if the provided port
is available to be
used for a given flow id
. An available port is a port that would not
conflict for the given id
plus ideally the port is not in LISTEN or
CLOSED states for a given protocol (see RFC 6056).
Note: Callers must guarantee that the given port being checked is within
the EPHEMERAL_RANGE
.
Provided Methods§
Sourcefn rand_ephemeral<R: Rng>(rng: &mut R) -> EphemeralPort<Self>
fn rand_ephemeral<R: Rng>(rng: &mut R) -> EphemeralPort<Self>
Returns a random ephemeral port in EPHEMERAL_RANGE
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.