FastMM documentation
FastMM C++ API 0.6.0
Public headers, tier 1 and tier 2
Loading...
Searching...
No Matches
fastmm::net Namespace Reference

Classes

struct  BackoffConfig
 
class  Connection
 
struct  ConnectionConfig
 
struct  ConnectionStats
 
struct  DatagramHandlerArchetype
 A handler that accepts every datagram: the shape poll() is checked against. More...
 
struct  DatagramSourceStats
 
struct  DatagramSubscription
 
struct  DpdkConfig
 
class  DpdkDatagramSource
 
struct  DpdkStats
 
struct  DpdkSubscription
 
class  EcdsaP256Key
 
class  Ed25519Key
 A parsed Ed25519 key (private, or public only for verification). Move-only. More...
 
class  ExponentialBackoff
 
class  FixedHexString
 Fixed-capacity, NUL-terminated hex string (no heap). size() excludes the terminator. More...
 
class  HmacSha256Key
 HMAC-SHA256 with the key schedule precomputed (see the header comment). More...
 
class  HttpClient
 
struct  HttpClientConfig
 
struct  HttpClientStats
 
struct  HttpResponse
 
class  IoHandler
 
class  KernelDatagramSource
 
struct  KernelSourceConfig
 
struct  KernelSourceOpen
 Outcome of open(). err is 0 or -errno of the step that failed, for subscription line. More...
 
struct  McastInterface
 Interface for multicast membership and IP_MULTICAST_IF: an IPv4 address or an interface index. More...
 
class  QueryBuilder
 Builds "k1=v1\&k2=v2" into a fixed buffer, percent-encoding values. More...
 
class  Reactor
 
struct  RxMeta
 
class  UdpSocket
 
struct  Url
 
class  WsClient
 
struct  WsClientConfig
 
struct  WsStats
 
struct  XdpConfig
 
class  XdpDatagramSource
 
class  XdpFilter
 The BPF objects of one interface: subscription hash map, XSKMAP, per-CPU fallback counter and the program, plus its XDP link once attached. More...
 
struct  XdpInterfaceQueues
 
struct  XdpInterfaceStatus
 
struct  XdpSocketStats
 XDP_STATISTICS of one socket, as of the last refresh_stats(). More...
 
struct  XdpStats
 
struct  XdpSubscription
 

Concepts

concept  ConnectionHandler
 
concept  WsClientHandler
 
concept  DatagramSource
 

Typedefs

using TimerId = std::uint64_t
 
using Sha1Digest = std::array< std::uint8_t, kSha1Size >
 
using Sha256Digest = std::array< std::uint8_t, kSha256Size >
 
using HexSha256 = FixedHexString< kSha256Size >
 
using HexSha384 = FixedHexString< kSha384Size >
 
using HexSha512 = FixedHexString< kSha512Size >
 
using HttpResponseCallback = std::function< void(const HttpResponse &)>
 
using HttpTargetMaker = std::function< std::string()>
 Makes a request's target (path and query) when the request is written.
 

Enumerations

enum class  IoEvent : std::uint32_t { None = 0 , Read = 1 , Write = 2 , ReadWrite = 3 }
 
enum class  ReactorBackend : std::uint8_t { Epoll , IoUring }
 
enum class  ConnState : std::uint8_t {
  Idle , Resolving , Connecting , TlsHandshake ,
  WsHandshake , Authenticating , Subscribing , Live ,
  Stale , Closing , Backoff
}
 
enum class  WsProgress : std::uint8_t { TcpConnected , UpgradeSent }
 Milestones before the upgrade completes, so owners can report fine-grained states. More...
 
enum class  WsState : std::uint8_t {
  Idle , Connecting , Upgrading , Open ,
  Closing , Closed
}
 
enum class  HttpClientState : std::uint8_t { Idle , Connecting , Ready , Closed }
 
enum class  XdpMode : std::uint8_t { Auto , ZeroCopy , NativeCopy , Generic }
 Attach and bind mode. More...
 

Functions

constexpr IoEvent operator| (IoEvent a, IoEvent b) noexcept
 
constexpr bool has (IoEvent set, IoEvent flag) noexcept
 
std::string_view to_string (ReactorBackend backend) noexcept
 "epoll" / "io_uring", the spelling of [engine] net_backend.
 
bool parse_reactor_backend (std::string_view text, ReactorBackend &out) noexcept
 Parses "epoll" / "io_uring". Returns false (and leaves out alone) for anything else.
 
std::string_view to_string (ConnState s) noexcept
 
void validate_connection_config (const ConnectionConfig &cfg, Url &url)
 Throws std::invalid_argument on a bad URL; fills url (views into cfg.url).
 
bool hmac_sha256 (std::string_view key, std::string_view data, std::span< std::uint8_t, kSha256Size > out) noexcept
 HMAC-SHA256(key, data).
 
HexSha256 hmac_sha256_hex (std::string_view key, std::string_view data) noexcept
 
HexSha384 hmac_sha384_hex (std::string_view key, std::string_view data) noexcept
 HMAC-SHA384(key, data) as lowercase hex (Gemini signs its requests and the WebSocket upgrade with it).
 
HexSha512 hmac_sha512_hex (std::string_view key, std::string_view data) noexcept
 HMAC-SHA512(key, data) as lowercase hex (Gate APIv4 signs REST requests and WebSocket logins with it) and SHA-512(data) as lowercase hex (the body digest inside a Gate signature string).
 
HexSha512 sha512_hex (std::string_view data) noexcept
 
bool sha1 (std::string_view data, std::span< std::uint8_t, kSha1Size > out) noexcept
 
bool sha256 (std::string_view data, std::span< std::uint8_t, kSha256Size > out) noexcept
 
Sha1Digest sha1 (std::string_view data) noexcept
 
Sha256Digest sha256 (std::string_view data) noexcept
 
constexpr std::size_t base64_encoded_size (std::size_t n) noexcept
 RFC 4648 §4 base64 with '=' padding. base64_encoded_size(n) is the exact output size.
 
constexpr std::size_t base64_max_decoded_size (std::size_t n) noexcept
 
std::size_t base64_encode (std::span< const std::uint8_t > in, std::span< char > out) noexcept
 Writes into out (must be >= base64_encoded_size(in.size())); returns bytes written or 0 if the output is too small.
 
std::string base64_encode (std::span< const std::uint8_t > in)
 
std::string base64_encode (std::string_view in)
 
constexpr std::size_t base64url_encoded_size (std::size_t n) noexcept
 RFC 4648 §5 base64url without padding, the encoding of JWS/JWT segments.
 
std::size_t base64url_encode (std::span< const std::uint8_t > in, std::span< char > out) noexcept
 
std::string base64url_encode (std::string_view in)
 
std::size_t base64url_decode (std::string_view in, std::span< std::uint8_t > out) noexcept
 Unpadded base64url; SIZE_MAX on malformed input or insufficient output space.
 
std::size_t base64_decode (std::string_view in, std::span< std::uint8_t > out) noexcept
 Decodes standard base64 (padding required, no whitespace).
 
bool base64_decode (std::string_view in, std::string &out)
 
bool random_bytes (std::span< std::uint8_t > out) noexcept
 CSPRNG (RAND_bytes). Returns false if the RNG is unavailable.
 
std::string ed25519_sign_base64 (std::string_view private_key_pem, std::string_view data)
 Ed25519 signature (base64) of data using a PEM-encoded PKCS#8 private key.
 
constexpr bool is_url_unreserved (char c) noexcept
 RFC 3986 unreserved characters pass through; everything else becomes %XX.
 
std::size_t percent_encode (std::string_view in, std::span< char > out) noexcept
 Returns bytes written, or 0 if out is too small (worst case 3 * in.size()).
 
bool parse_ipv4 (std::string_view text, std::uint32_t &out_be) noexcept
 Parses dotted-quad IPv4 into network byte order. Returns false on anything else.
 
constexpr bool is_ipv4_multicast (std::uint32_t addr_be) noexcept
 
int enable_hw_timestamps (std::string_view ifname) noexcept
 SIOCSHWTSTAMP on ifname: hardware timestamps for all received packets, TX off.
 
constexpr std::string_view to_string (XdpMode m) noexcept
 
std::string xdp_capability_error ()
 "" when the process has CAP_NET_ADMIN, CAP_NET_RAW, CAP_BPF (or CAP_SYS_ADMIN) and CAP_IPC_LOCK in its effective set; otherwise names the missing ones and the setcap command.
 
std::string xdp_kernel_error ()
 "" on Linux 5.11 or later; otherwise the reason.
 
bool dpdk_available () noexcept
 True when this build has the DPDK backend.
 

Variables

constexpr TimerId kInvalidTimer = 0
 
constexpr std::size_t kSha1Size = 20
 
constexpr std::size_t kSha256Size = 32
 
constexpr std::size_t kSha384Size = 48
 
constexpr std::size_t kSha512Size = 64
 
constexpr std::size_t kEd25519SignatureSize = 64
 
constexpr std::size_t kEd25519Base64Size = 88
 base64_encoded_size(64)
 
constexpr std::size_t kEs256SignatureSize = 64
 ECDSA on P-256 with SHA-256 (JWS "ES256", RFC 7518 §3.4): the signature is r || s, 32 bytes each, big-endian.
 

Typedef Documentation

◆ TimerId

using fastmm::net::TimerId = typedef std::uint64_t

◆ Sha1Digest

using fastmm::net::Sha1Digest = typedef std::array<std::uint8_t, kSha1Size>

◆ Sha256Digest

using fastmm::net::Sha256Digest = typedef std::array<std::uint8_t, kSha256Size>

◆ HexSha256

◆ HexSha384

◆ HexSha512

◆ HttpResponseCallback

using fastmm::net::HttpResponseCallback = typedef std::function<void(const HttpResponse&)>

◆ HttpTargetMaker

using fastmm::net::HttpTargetMaker = typedef std::function<std::string()>

Makes a request's target (path and query) when the request is written.

Empty: the request is not sent and fails with NetError::Canceled.

Enumeration Type Documentation

◆ IoEvent

enum class fastmm::net::IoEvent : std::uint32_t
strong
Enumerator
None 
Read 
Write 
ReadWrite 

◆ ReactorBackend

enum class fastmm::net::ReactorBackend : std::uint8_t
strong
Enumerator
Epoll 
IoUring 

◆ ConnState

enum class fastmm::net::ConnState : std::uint8_t
strong
Enumerator
Idle 
Resolving 
Connecting 
TlsHandshake 
WsHandshake 
Authenticating 
Subscribing 
Live 
Stale 

Live, but nothing received for stale_ms (sub-state of Live)

Closing 
Backoff 

◆ WsProgress

enum class fastmm::net::WsProgress : std::uint8_t
strong

Milestones before the upgrade completes, so owners can report fine-grained states.

Enumerator
TcpConnected 

TCP established (TLS handshake starts next for TLS streams)

UpgradeSent 

transport ready, HTTP upgrade request written

◆ WsState

enum class fastmm::net::WsState : std::uint8_t
strong
Enumerator
Idle 
Connecting 
Upgrading 
Open 
Closing 
Closed 

◆ HttpClientState

enum class fastmm::net::HttpClientState : std::uint8_t
strong
Enumerator
Idle 
Connecting 
Ready 
Closed 

◆ XdpMode

enum class fastmm::net::XdpMode : std::uint8_t
strong

Attach and bind mode.

Auto tries ZeroCopy, then NativeCopy, then Generic. ZeroCopy native XDP (driver), socket bound with XDP_ZEROCOPY NativeCopy native XDP, socket bound with XDP_COPY Generic generic XDP (XDP_FLAGS_SKB_MODE), socket bound with XDP_COPY

Enumerator
Auto 
ZeroCopy 
NativeCopy 
Generic 

Function Documentation

◆ operator|()

constexpr IoEvent fastmm::net::operator| ( IoEvent  a,
IoEvent  b 
)
constexprnoexcept

◆ has()

constexpr bool fastmm::net::has ( IoEvent  set,
IoEvent  flag 
)
constexprnoexcept

◆ to_string() [1/3]

std::string_view fastmm::net::to_string ( ReactorBackend  backend)
noexcept

"epoll" / "io_uring", the spelling of [engine] net_backend.

◆ parse_reactor_backend()

bool fastmm::net::parse_reactor_backend ( std::string_view  text,
ReactorBackend &  out 
)
noexcept

Parses "epoll" / "io_uring". Returns false (and leaves out alone) for anything else.

◆ to_string() [2/3]

std::string_view fastmm::net::to_string ( ConnState  s)
noexcept

◆ validate_connection_config()

void fastmm::net::validate_connection_config ( const ConnectionConfig &  cfg,
Url &  url 
)

Throws std::invalid_argument on a bad URL; fills url (views into cfg.url).

◆ hmac_sha256()

bool fastmm::net::hmac_sha256 ( std::string_view  key,
std::string_view  data,
std::span< std::uint8_t, kSha256Size >  out 
)
noexcept

HMAC-SHA256(key, data).

out receives 32 bytes. Never throws; returns false on OpenSSL failure (should not happen for valid inputs).

◆ hmac_sha256_hex()

HexSha256 fastmm::net::hmac_sha256_hex ( std::string_view  key,
std::string_view  data 
)
noexcept

◆ hmac_sha384_hex()

HexSha384 fastmm::net::hmac_sha384_hex ( std::string_view  key,
std::string_view  data 
)
noexcept

HMAC-SHA384(key, data) as lowercase hex (Gemini signs its requests and the WebSocket upgrade with it).

Control path: the key schedule is not kept. Never fails for valid inputs.

◆ hmac_sha512_hex()

HexSha512 fastmm::net::hmac_sha512_hex ( std::string_view  key,
std::string_view  data 
)
noexcept

HMAC-SHA512(key, data) as lowercase hex (Gate APIv4 signs REST requests and WebSocket logins with it) and SHA-512(data) as lowercase hex (the body digest inside a Gate signature string).

Control path: no key schedule is kept. Never fail for valid inputs.

◆ sha512_hex()

HexSha512 fastmm::net::sha512_hex ( std::string_view  data)
noexcept

◆ sha1() [1/2]

bool fastmm::net::sha1 ( std::string_view  data,
std::span< std::uint8_t, kSha1Size >  out 
)
noexcept

◆ sha256() [1/2]

bool fastmm::net::sha256 ( std::string_view  data,
std::span< std::uint8_t, kSha256Size >  out 
)
noexcept

◆ sha1() [2/2]

Sha1Digest fastmm::net::sha1 ( std::string_view  data)
noexcept

◆ sha256() [2/2]

Sha256Digest fastmm::net::sha256 ( std::string_view  data)
noexcept

◆ base64_encoded_size()

constexpr std::size_t fastmm::net::base64_encoded_size ( std::size_t  n)
constexprnoexcept

RFC 4648 §4 base64 with '=' padding. base64_encoded_size(n) is the exact output size.

◆ base64_max_decoded_size()

constexpr std::size_t fastmm::net::base64_max_decoded_size ( std::size_t  n)
constexprnoexcept

◆ base64_encode() [1/3]

std::size_t fastmm::net::base64_encode ( std::span< const std::uint8_t >  in,
std::span< char >  out 
)
noexcept

Writes into out (must be >= base64_encoded_size(in.size())); returns bytes written or 0 if the output is too small.

◆ base64_encode() [2/3]

std::string fastmm::net::base64_encode ( std::span< const std::uint8_t >  in)

◆ base64_encode() [3/3]

std::string fastmm::net::base64_encode ( std::string_view  in)

◆ base64url_encoded_size()

constexpr std::size_t fastmm::net::base64url_encoded_size ( std::size_t  n)
constexprnoexcept

RFC 4648 §5 base64url without padding, the encoding of JWS/JWT segments.

Writes into out (>= base64url_encoded_size(in.size())); returns bytes written, 0 if out is too small.

◆ base64url_encode() [1/2]

std::size_t fastmm::net::base64url_encode ( std::span< const std::uint8_t >  in,
std::span< char >  out 
)
noexcept

◆ base64url_encode() [2/2]

std::string fastmm::net::base64url_encode ( std::string_view  in)

◆ base64url_decode()

std::size_t fastmm::net::base64url_decode ( std::string_view  in,
std::span< std::uint8_t >  out 
)
noexcept

Unpadded base64url; SIZE_MAX on malformed input or insufficient output space.

◆ base64_decode() [1/2]

std::size_t fastmm::net::base64_decode ( std::string_view  in,
std::span< std::uint8_t >  out 
)
noexcept

Decodes standard base64 (padding required, no whitespace).

Returns bytes written or SIZE_MAX on malformed input / insufficient output space.

◆ base64_decode() [2/2]

bool fastmm::net::base64_decode ( std::string_view  in,
std::string &  out 
)

◆ random_bytes()

bool fastmm::net::random_bytes ( std::span< std::uint8_t >  out)
noexcept

CSPRNG (RAND_bytes). Returns false if the RNG is unavailable.

◆ ed25519_sign_base64()

std::string fastmm::net::ed25519_sign_base64 ( std::string_view  private_key_pem,
std::string_view  data 
)

Ed25519 signature (base64) of data using a PEM-encoded PKCS#8 private key.

Returns an empty string if the key cannot be loaded or is not Ed25519. Parses the PEM on every call: keep an Ed25519Key for repeated signing.

◆ is_url_unreserved()

constexpr bool fastmm::net::is_url_unreserved ( char  c)
constexprnoexcept

RFC 3986 unreserved characters pass through; everything else becomes %XX.

◆ percent_encode()

std::size_t fastmm::net::percent_encode ( std::string_view  in,
std::span< char >  out 
)
inlinenoexcept

Returns bytes written, or 0 if out is too small (worst case 3 * in.size()).

◆ parse_ipv4()

bool fastmm::net::parse_ipv4 ( std::string_view  text,
std::uint32_t &  out_be 
)
noexcept

Parses dotted-quad IPv4 into network byte order. Returns false on anything else.

◆ is_ipv4_multicast()

constexpr bool fastmm::net::is_ipv4_multicast ( std::uint32_t  addr_be)
constexprnoexcept

< first octet 224..239, lowest byte in network order

◆ enable_hw_timestamps()

int fastmm::net::enable_hw_timestamps ( std::string_view  ifname)
noexcept

SIOCSHWTSTAMP on ifname: hardware timestamps for all received packets, TX off.

Needs CAP_NET_ADMIN and a NIC that supports it; the setting is device-wide and outlives the process. Returns 0 or -errno (-EOPNOTSUPP / -EINVAL without NIC support, -EPERM without the capability).

◆ to_string() [3/3]

constexpr std::string_view fastmm::net::to_string ( XdpMode  m)
constexprnoexcept

◆ xdp_capability_error()

std::string fastmm::net::xdp_capability_error ( )

"" when the process has CAP_NET_ADMIN, CAP_NET_RAW, CAP_BPF (or CAP_SYS_ADMIN) and CAP_IPC_LOCK in its effective set; otherwise names the missing ones and the setcap command.

◆ xdp_kernel_error()

std::string fastmm::net::xdp_kernel_error ( )

"" on Linux 5.11 or later; otherwise the reason.

◆ dpdk_available()

bool fastmm::net::dpdk_available ( )
noexcept

True when this build has the DPDK backend.

Variable Documentation

◆ kInvalidTimer

constexpr TimerId fastmm::net::kInvalidTimer = 0
inlineconstexpr

◆ kSha1Size

constexpr std::size_t fastmm::net::kSha1Size = 20
inlineconstexpr

◆ kSha256Size

constexpr std::size_t fastmm::net::kSha256Size = 32
inlineconstexpr

◆ kSha384Size

constexpr std::size_t fastmm::net::kSha384Size = 48
inlineconstexpr

◆ kSha512Size

constexpr std::size_t fastmm::net::kSha512Size = 64
inlineconstexpr

◆ kEd25519SignatureSize

constexpr std::size_t fastmm::net::kEd25519SignatureSize = 64
inlineconstexpr

◆ kEd25519Base64Size

constexpr std::size_t fastmm::net::kEd25519Base64Size = 88
inlineconstexpr

base64_encoded_size(64)

◆ kEs256SignatureSize

constexpr std::size_t fastmm::net::kEs256SignatureSize = 64
inlineconstexpr

ECDSA on P-256 with SHA-256 (JWS "ES256", RFC 7518 §3.4): the signature is r || s, 32 bytes each, big-endian.

Coinbase CDP API keys are such keys ("\--\---BEGIN EC PRIVATE KEY\--\---"). Signing draws a fresh random nonce (OpenSSL), so two signatures of the same data differ. Move-only; control path (OpenSSL allocates per signature).