Skip to main content

selium_abi/
net.rs

1use rkyv::{Archive, Deserialize, Serialize};
2
3use crate::GuestResourceId;
4
5/// Network transport protocols supported by the ABI.
6#[repr(u8)]
7#[derive(Debug, Copy, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
8#[rkyv(bytecheck())]
9pub enum NetProtocol {
10    /// QUIC over UDP with TLS 1.3.
11    Quic = 0,
12    /// HTTP/1.1 over TCP (cleartext).
13    Http = 1,
14    /// HTTP/2 over TLS 1.3.
15    Https = 2,
16}
17
18/// Arguments for creating a network listener.
19#[derive(Debug, Clone, PartialEq, Archive, Serialize, Deserialize)]
20#[rkyv(bytecheck())]
21pub struct NetCreateListener {
22    /// Protocol to use for the listener.
23    pub protocol: NetProtocol,
24    /// Authority or hostname to bind to.
25    pub domain: String,
26    /// Port number to bind to.
27    pub port: u16,
28    /// Optional TLS configuration handle for QUIC/HTTPS listeners.
29    pub tls: Option<GuestResourceId>,
30}
31
32/// Reply containing guest-visible handles for a created listener.
33#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
34#[rkyv(bytecheck())]
35pub struct NetCreateListenerReply {
36    /// Listener handle registered in the instance registry.
37    pub handle: GuestResourceId,
38}
39
40/// Request to accept the next inbound connection on a listener.
41#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
42#[rkyv(bytecheck())]
43pub struct NetAccept {
44    /// Handle of the listener to accept on.
45    pub handle: GuestResourceId,
46}
47
48/// Reply containing guest-visible handles for an accepted connection.
49#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
50#[rkyv(bytecheck())]
51pub struct NetAcceptReply {
52    /// Reader handle registered in the instance registry.
53    pub reader: GuestResourceId,
54    /// Writer handle registered in the instance registry.
55    pub writer: GuestResourceId,
56    /// Address of remote caller (used for debugging).
57    pub remote_addr: String,
58}
59
60/// Arguments for connecting to a remote endpoint.
61#[derive(Debug, Clone, PartialEq, Archive, Serialize, Deserialize)]
62#[rkyv(bytecheck())]
63pub struct NetConnect {
64    /// Protocol to use for the connection.
65    pub protocol: NetProtocol,
66    /// Authority or hostname of the remote peer.
67    pub domain: String,
68    /// Port number of the remote peer.
69    pub port: u16,
70    /// Optional TLS configuration handle for QUIC/HTTPS connections.
71    pub tls: Option<GuestResourceId>,
72}
73
74/// Reply containing guest-visible handles for a connected session.
75#[derive(Debug, Clone, PartialEq, Eq, Archive, Serialize, Deserialize)]
76#[rkyv(bytecheck())]
77pub struct NetConnectReply {
78    /// Reader handle registered in the instance registry.
79    pub reader: GuestResourceId,
80    /// Writer handle registered in the instance registry.
81    pub writer: GuestResourceId,
82    /// Address of remote connection (used for debugging).
83    pub remote_addr: String,
84}