### Configuration YAML Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.Config.html An example of how to structure the configuration in a YAML file. ```yaml inbound: type: xxx xxx: xxx outbound: type: xxx xxx: xxx log-level: trace # or debug, info, warn, error ``` -------------------------------- ### Outbound Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/enum.OutboundCfg.html A YAML-like example demonstrating how to structure the outbound configuration. ```yaml type: socks # or shadowquic or direct addr: "127.0.0.1:443" # "[::1]:443" xxx: xxx # other field depending on type ``` -------------------------------- ### SunnyQuicClientCfg Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.SunnyQuicClientCfg.html A YAML-style example of how to configure the client settings. ```yaml addr: "12.34.56.7:1089" # or "[12:ff::ff]:1089" for dualstack password: "12345678" username: "87654321" server-name: "echo.free.beeceptor.com" alpn: ["h3"] initial-mtu: 1400 congestion-control: bbr zero-rtt: true over-stream: false # true for udp over stream, false for udp over datagram ``` -------------------------------- ### DirectOutCfg Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.DirectOutCfg.html An example of how to configure the DNS strategy in a configuration file. ```yaml dns-strategy: prefer-ipv4 # or prefer-ipv6, ipv4-only, ipv6-only ``` -------------------------------- ### ShadowQuic Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.ShadowQuicClientCfg.html A sample configuration block for setting up the client. ```yaml addr: "12.34.56.7:1089" # or "[12:ff::ff]:1089" for dualstack password: "12345678" username: "87654321" server-name: "echo.free.beeceptor.com" # must be the same as jls_upstream in server alpn: ["h3"] initial-mtu: 1400 congestion-control: bbr zero-rtt: true over-stream: false # true for udp over stream, false for udp over datagram ``` -------------------------------- ### Inbound Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/enum.InboundCfg.html A YAML-style example showing how to define an inbound configuration. ```yaml type: socks # or shadowquic bind-addr: "0.0.0.0:443" # "[::]:443" xxx: xxx # other field depending on type ``` -------------------------------- ### SocksServerCfg Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.SocksServerCfg.html An example configuration format for the SOCKS server, typically used in YAML or similar configuration files. ```yaml bind-addr: "0.0.0.0:1089" # or "[::]:1089" for dualstack users: - username: "username" password: "password" ``` -------------------------------- ### Configure Mixed Server Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.MixedServerCfg.html Example configuration format for a mixed server instance. ```yaml type: mixed bind-addr: "0.0.0.0:1080" ``` -------------------------------- ### SunnyQuicServerCfg YAML Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.SunnyQuicServerCfg.html A sample configuration file format for initializing the SunnyQuic server. ```yaml bind-addr: "0.0.0.0:1443" users: - username: "zhangsan" password: "12345678" server-name: "echo.free.beeceptor.com" # must be the same as client alpn: ["h3"] congestion-control: bbr zero-rtt: true ``` -------------------------------- ### ShadowQuicServerCfg YAML Configuration Example Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.ShadowQuicServerCfg.html A sample configuration file demonstrating how to define server settings in YAML format. ```yaml bind-addr: "0.0.0.0:1443" users: - username: "zhangsan" password: "12345678" jls-upstream: addr: "echo.free.beeceptor.com:443" # domain/ip + port, domain must be the same as client. rate-limit: 1000000 # Limiting forwarding rate in unit of bps. optional, default is disabled server-name: "echo.free.beeceptor.com" # must be the same as client alpn: ["h3"] congestion-control: bbr zero-rtt: true ``` -------------------------------- ### accept() Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/struct.EndServer.html Get the next incoming connection attempt from a client. ```APIDOC ## pub fn accept(&self) -> Accept<'_> ### Description Get the next incoming connection attempt from a client. Yields `Incoming`s, or `None` if the endpoint is `close`d. ``` -------------------------------- ### Configure Bind Interface Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/enum.Interface.html Examples of how to specify the bind-interface configuration using an IP address or a device name. ```yaml # by ip address bind-interface: "127.0.0.1" # by interface name bind-interface: "eth0" ``` -------------------------------- ### Get and Set Socket TTL Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Examples for retrieving and configuring the IP_TTL option for a UDP socket. ```rust use tokio::net::UdpSocket; let sock = UdpSocket::bind("127.0.0.1:8080").await?; println!("{:?}", sock.ttl()?); ``` ```rust use tokio::net::UdpSocket; let sock = UdpSocket::bind("127.0.0.1:8080").await?; sock.set_ttl(60)?; ``` -------------------------------- ### Congestion Control Configuration Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/enum.CongestionControl.html Examples for configuring congestion control algorithms in a configuration file. ```yaml congestion-control: bbr # or cubic, new-reno, brutal ``` ```yaml congestion-control: brutal: bandwidth: 10000000 # default 10000000 bps ``` -------------------------------- ### Demonstrate ambiguous From implementation Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html An example of an discouraged implementation that causes ambiguity with Pin::from. ```rust struct Foo; // A type defined in this crate. impl From> for Pin { fn from(_: Box<()>) -> Pin { Pin::new(Foo) } } ``` -------------------------------- ### Configure TproxyServerCfg Binding Address Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.TproxyServerCfg.html Example configuration format for the bind-addr field. ```yaml bind-addr: "0.0.0.0:1089" # or "[::]:1089" for dualstack ``` -------------------------------- ### Result::is_ok_and Implementation Source: https://docs.rs/shadowquic/0.3.12/shadowquic/error/type.SResult.html Example of checking if a Result is Ok and matches a predicate. ```rust let x: Result = Ok(2); assert_eq!(x.is_ok_and(|x| x > 1), true); let x: Result = Ok(0); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Err("hey"); assert_eq!(x.is_ok_and(|x| x > 1), false); let x: Result = Ok("ownership".to_string()); assert_eq!(x.as_ref().is_ok_and(|x| x.len() > 1), true); println!("still alive {:?}", x); ``` -------------------------------- ### Extra Paths Configuration Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.SunnyQuicClientCfg.html Example configuration for defining additional network paths for multipath QUIC. ```yaml extra-paths: - "[12:ff::ff]:1089" ``` -------------------------------- ### Concurrent Send and Receive Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Example of using ready() to concurrently handle read and write operations on a single task without splitting the socket. ```rust use tokio::io::{self, Interest}; use tokio::net::UdpSocket; #[tokio::main] async fn main() -> io::Result<()> { let socket = UdpSocket::bind("127.0.0.1:8080").await?; socket.connect("127.0.0.1:8081").await?; loop { let ready = socket.ready(Interest::READABLE | Interest::WRITABLE).await?; if ready.is_readable() { // The buffer is **not** included in the async task and will only exist // on the stack. let mut data = [0; 1024]; match socket.try_recv(&mut data[..]) { Ok(n) => { println!("received {:?}", &data[..n]); } // False-positive, continue Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {} Err(e) => { return Err(e); } } } if ready.is_writable() { // Write some data match socket.try_send(b"hello world") { Ok(n) => { println!("sent {} bytes", n); } // False-positive, continue Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => {} Err(e) => { return Err(e); } } } } } ``` -------------------------------- ### handle_request Source: https://docs.rs/shadowquic/0.3.12/shadowquic/squic/outbound/fn.handle_request.html Handles a proxy request and starts a proxy task with the given squic connection. ```APIDOC ## Function: handle_request ### Description Handles a proxy request and starts a proxy task with the given squic connection. ### Signature `pub async fn handle_request(req: ProxyRequest, conn: SQConn, over_stream: bool) -> Result<(), SError>` ### Parameters - **req** (ProxyRequest) - The proxy request to handle. - **conn** (SQConn) - The squic connection to use for the task. - **over_stream** (bool) - Flag indicating if the request is over a stream. ### Returns - **Result<(), SError>** - Returns Ok(()) on success, or an SError if the operation fails. ``` -------------------------------- ### Result::is_ok and is_err Checks Source: https://docs.rs/shadowquic/0.3.12/shadowquic/error/type.SResult.html Examples of checking the status of a Result. ```rust let x: Result = Ok(-3); assert_eq!(x.is_ok(), true); let x: Result = Err("Some error message"); assert_eq!(x.is_ok(), false); ``` ```rust let x: Result = Ok(-3); assert_eq!(x.is_err(), false); let x: Result = Err("Some error message"); assert_eq!(x.is_err(), true); ``` -------------------------------- ### Construct Box from Raw Pointer Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Examples demonstrating how to reconstruct a Box from a raw pointer, either from a previous conversion or manual allocation. ```rust let x = Box::new(5); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` ```rust use std::alloc::{alloc, Layout}; unsafe { let ptr = alloc(Layout::new::()) as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw(ptr); } ``` -------------------------------- ### Convert Box to Raw Pointer Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Examples showing how to consume a Box into a raw pointer and handle subsequent cleanup. ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); let x = unsafe { Box::from_raw(ptr) }; ``` ```rust use std::alloc::{dealloc, Layout}; use std::ptr; let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { ptr::drop_in_place(ptr); dealloc(ptr as *mut u8, Layout::new::()); } ``` ```rust let x = Box::new(String::from("Hello")); let ptr = Box::into_raw(x); unsafe { drop(Box::from_raw(ptr)); } ``` -------------------------------- ### Configure SOCKS Outbound Address Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/struct.SocksClientCfg.html Example showing the format for the address field, supporting both IPv4/IPv6 and dualstack addresses. ```rust addr: "12.34.56.7:1089" # or "[12:ff::ff]:1089" for dualstack ``` -------------------------------- ### Retrieve Local Socket Address Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Example of retrieving the local address bound to a UdpSocket. ```rust use tokio::net::UdpSocket; let addr = "0.0.0.0:8080".parse::().unwrap(); let sock = UdpSocket::bind(addr).await?; // the address the socket is bound to let local_addr = sock.local_addr()?; ``` -------------------------------- ### Result::flatten Implementation Source: https://docs.rs/shadowquic/0.3.12/shadowquic/error/type.SResult.html Examples of flattening nested Result types. ```rust let x: Result, u32> = Ok(Ok("hello")); assert_eq!(Ok("hello"), x.flatten()); let x: Result, u32> = Ok(Err(6)); assert_eq!(Err(6), x.flatten()); let x: Result, u32> = Err(6); assert_eq!(Err(6), x.flatten()); ``` ```rust let x: Result, u32>, u32> = Ok(Ok(Ok("hello"))); assert_eq!(Ok(Ok("hello")), x.flatten()); assert_eq!(Ok("hello"), x.flatten().flatten()); ``` -------------------------------- ### Retrieve Socket Error Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Example demonstrating how to check for pending socket errors using the SO_ERROR option. ```rust use tokio::net::UdpSocket; use std::io; #[tokio::main] async fn main() -> io::Result<()> { // Create a socket let socket = UdpSocket::bind("0.0.0.0:8080").await?; if let Ok(Some(err)) = socket.take_error() { println!("Got error: {:?}", err); } Ok(()) } ``` -------------------------------- ### Convert Box to raw pointer with allocator Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Demonstrates consuming a Box into a raw pointer and allocator, with examples for automatic and manual cleanup. ```rust #![feature(allocator_api)] use std::alloc::System; let x = Box::new_in(String::from("Hello"), System); let (ptr, alloc) = Box::into_raw_with_allocator(x); let x = unsafe { Box::from_raw_in(ptr, alloc) }; ``` ```rust #![feature(allocator_api)] use std::alloc::{Allocator, Layout, System}; use std::ptr::{self, NonNull}; let x = Box::new_in(String::from("Hello"), System); let (ptr, alloc) = Box::into_raw_with_allocator(x); unsafe { ptr::drop_in_place(ptr); let non_null = NonNull::new_unchecked(ptr); alloc.deallocate(non_null.cast(), Layout::new::()); } ``` -------------------------------- ### Connect UDP Socket Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Example of connecting a UDP socket to a remote address to restrict send and receive operations. ```rust use tokio::net::UdpSocket; let sock = UdpSocket::bind("0.0.0.0:8080".parse::().unwrap()).await?; let remote_addr = "127.0.0.1:59600".parse::().unwrap(); sock.connect(remote_addr).await?; let mut buf = [0u8; 32]; // recv from remote_addr let len = sock.recv(&mut buf).await?; // send to remote_addr let _len = sock.send(&buf[..len]).await?; ``` -------------------------------- ### Retrieve Peer Socket Address Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Example of retrieving the address of a remote peer after connecting the socket. ```rust use tokio::net::UdpSocket; let addr = "0.0.0.0:8080".parse::().unwrap(); let peer = "127.0.0.1:11100".parse::().unwrap(); let sock = UdpSocket::bind(addr).await?; sock.connect(peer).await?; assert_eq!(peer, sock.peer_addr()?); ``` -------------------------------- ### Convert Box to NonNull pointer with allocator Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Demonstrates consuming a Box into a NonNull pointer and allocator, with examples for automatic and manual cleanup. ```rust #![feature(allocator_api)] use std::alloc::System; let x = Box::new_in(String::from("Hello"), System); let (non_null, alloc) = Box::into_non_null_with_allocator(x); let x = unsafe { Box::from_non_null_in(non_null, alloc) }; ``` ```rust #![feature(allocator_api)] use std::alloc::{Allocator, Layout, System}; let x = Box::new_in(String::from("Hello"), System); let (non_null, alloc) = Box::into_non_null_with_allocator(x); unsafe { non_null.drop_in_place(); alloc.deallocate(non_null.cast::(), Layout::new::()); } ``` -------------------------------- ### Construct Box from NonNull Pointer Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Examples for constructing a Box from a NonNull pointer, requiring the nightly-only box_vec_non_null feature. ```rust #![feature(box_vec_non_null)] let x = Box::new(5); let non_null = Box::into_non_null(x); let x = unsafe { Box::from_non_null(non_null) }; ``` ```rust #![feature(box_vec_non_null)] use std::alloc::{alloc, Layout}; use std::ptr::NonNull; unsafe { let non_null = NonNull::new(alloc(Layout::new::()).cast::()) .expect("allocation failed"); // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `non_null`. non_null.write(5); let x = Box::from_non_null(non_null); } ``` -------------------------------- ### pub async fn new(cfg: SunnyQuicServerCfg) -> Result Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/inbound/struct.SunnyQuicServer.html Creates a new instance of SunnyQuicServer using the provided configuration. ```APIDOC ## pub async fn new(cfg: SunnyQuicServerCfg) -> Result ### Description Initializes a new SunnyQuicServer instance with the specified configuration. ### Parameters - **cfg** (SunnyQuicServerCfg) - Required - The configuration object for the server. ### Returns - **Result** - Returns the new server instance or an error if initialization fails. ``` -------------------------------- ### SocksServer::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/socks/inbound/struct.SocksServer.html Creates a new instance of a SocksServer with the provided configuration. ```APIDOC ## pub async fn new(cfg: SocksServerCfg) -> Result ### Description Initializes a new SocksServer instance using the specified configuration. ### Parameters - **cfg** (SocksServerCfg) - Required - The configuration object for the SOCKS server. ### Returns - **Result** - Returns the initialized SocksServer or an error if initialization fails. ``` -------------------------------- ### Result::transpose Implementation Source: https://docs.rs/shadowquic/0.3.12/shadowquic/error/type.SResult.html Example of transposing a Result of an Option into an Option of a Result. ```rust #[derive(Debug, Eq, PartialEq)] struct SomeErr; let x: Result, SomeErr> = Ok(Some(5)); let y: Option> = Some(Ok(5)); assert_eq!(x.transpose(), y); ``` -------------------------------- ### ShadowQuicServer::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/inbound/struct.ShadowQuicServer.html Creates a new instance of the ShadowQuicServer using the provided configuration. ```APIDOC ## pub async fn new(cfg: ShadowQuicServerCfg) -> Result ### Description Initializes a new ShadowQuicServer instance with the specified configuration. ### Parameters - **cfg** (ShadowQuicServerCfg) - Required - The configuration object for the server. ### Returns - **Result** - Returns the initialized server instance or an error if initialization fails. ``` -------------------------------- ### new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/struct.EndServer.html Creates a new instance of the EndServer using the provided configuration. ```APIDOC ## fn new(cfg: &SunnyQuicServerCfg) -> Pin> + Send>> ### Description Initializes a new EndServer instance with the specified server configuration. ### Parameters - **cfg** (&SunnyQuicServerCfg) - Required - The configuration object for the QUIC server. ``` -------------------------------- ### ShadowQuicServer::init Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/inbound/struct.ShadowQuicServer.html Initializes the background job required for accepting connections. ```APIDOC ## fn init(&self) -> Pin> + Send + 'async_trait>> ### Description Starts the background job necessary to begin accepting incoming connections. ### Returns - **Result<(), SError>** - Returns Ok if the background job started successfully, or an error. ``` -------------------------------- ### Get default_over_stream configuration Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_over_stream.html Returns the default boolean configuration for stream handling. ```rust pub fn default_over_stream() -> bool ``` -------------------------------- ### ShadowQuicClient::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/outbound/struct.ShadowQuicClient.html Creates a new instance of ShadowQuicClient with the provided configuration. ```APIDOC ## pub fn new(cfg: ShadowQuicClientCfg) -> Self ### Description Initializes a new ShadowQuicClient instance using the specified configuration. ### Parameters - **cfg** (ShadowQuicClientCfg) - Required - The configuration object for the client. ``` -------------------------------- ### SunnyQuicClient::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/outbound/struct.SunnyQuicClient.html Creates a new instance of SunnyQuicClient with the provided configuration. ```APIDOC ## pub fn new(cfg: SunnyQuicClientCfg) -> Self ### Description Initializes a new SunnyQuicClient instance using the specified configuration. ### Parameters - **cfg** (SunnyQuicClientCfg) - Required - The configuration object for the client. ``` -------------------------------- ### new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/struct.EndClient.html Creates a new instance of EndClient using the provided configuration. ```APIDOC ## fn new<'life0, 'async_trait>(cfg: &'life0 Self::SC) -> Pin> + Send + 'async_trait>> ### Description Creates a new EndClient instance asynchronously using the provided configuration. ### Parameters - **cfg** (&Self::SC) - Required - The configuration for the ShadowQuicClient. ### Returns - **Future>** - A future that resolves to the new EndClient instance. ``` -------------------------------- ### SocksClient::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/socks/outbound/struct.SocksClient.html Creates a new instance of SocksClient using the provided configuration. ```APIDOC ## pub fn new(cfg: SocksClientCfg) -> Self ### Description Creates a new SocksClient instance with the specified configuration. ### Parameters - **cfg** (SocksClientCfg) - Required - The configuration object for the SOCKS client. ``` -------------------------------- ### Result::cloned Implementation Source: https://docs.rs/shadowquic/0.3.12/shadowquic/error/type.SResult.html Examples of using the cloned method on Result types containing references. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let cloned = x.cloned(); assert_eq!(cloned, Ok(12)); ``` -------------------------------- ### SunnyQuicClient::init_endpoint Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/outbound/struct.SunnyQuicClient.html Initializes the QUIC endpoint for the client. ```APIDOC ## pub async fn init_endpoint(&self) -> Result ### Description Asynchronously initializes the QUIC endpoint associated with this client. ### Returns - **Result** - Returns an EndClient on success, or an SError if initialization fails. ``` -------------------------------- ### Result::copied Implementation Source: https://docs.rs/shadowquic/0.3.12/shadowquic/error/type.SResult.html Examples of using the copied method on Result types containing references. ```rust let val = 12; let x: Result<&i32, i32> = Ok(&val); assert_eq!(x, Ok(&12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` ```rust let mut val = 12; let x: Result<&mut i32, i32> = Ok(&mut val); assert_eq!(x, Ok(&mut 12)); let copied = x.copied(); assert_eq!(copied, Ok(12)); ``` -------------------------------- ### QuicClient::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/quic/trait.QuicClient.html Creates a new instance of the QuicClient using the provided configuration. ```APIDOC ## fn new<'life0, 'async_trait>(cfg: &'life0 Self::SC) -> Pin> + Send + 'async_trait>> ### Description Initializes a new client instance based on the provided configuration object. ### Parameters - **cfg** (&Self::SC) - Required - The configuration object for the client. ``` -------------------------------- ### ShadowQuicClient::init_endpoint Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/outbound/struct.ShadowQuicClient.html Initializes the QUIC endpoint for the client. ```APIDOC ## pub async fn init_endpoint(&self) -> Result ### Description Asynchronously initializes the endpoint for the client, returning an EndClient or an error. ``` -------------------------------- ### accept Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/struct.EndServer.html Accepts an incoming QUIC connection. ```APIDOC ## fn accept(&self) -> Pin> + Send>> ### Description Waits for and accepts an incoming connection request on the server. ``` -------------------------------- ### Get strong reference count Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyUdpSend.html Retrieves the number of strong Arc pointers associated with an allocation. ```rust use std::sync::Arc; let five = Arc::new(5); let _also_five = Arc::clone(&five); // This assertion is deterministic because we haven't shared // the `Arc` between threads. assert_eq!(2, Arc::strong_count(&five)); ``` -------------------------------- ### Get weak reference count Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyUdpSend.html Retrieves the number of Weak pointers associated with an Arc allocation. ```rust use std::sync::Arc; let five = Arc::new(5); let _weak_five = Arc::downgrade(&five); // This assertion is deterministic because we haven't shared // the `Arc` or `Weak` between threads. assert_eq!(1, Arc::weak_count(&five)); ``` -------------------------------- ### Get default brutal bandwidth Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_brutal_bandwidth.html Returns the default bandwidth value as a 64-bit unsigned integer. ```rust pub fn default_brutal_bandwidth() -> u64 ``` -------------------------------- ### pub async fn add_user Source: https://docs.rs/shadowquic/0.3.12/shadowquic/squic/outbound/fn.add_user.html Adds a user to the specified QUIC connection using the provided credentials. ```APIDOC ## add_user ### Description Adds a new user to the provided QUIC connection. ### Signature `pub async fn add_user(sq_conn: &SQConn, username: &str, password: &str) -> SResult>` ### Parameters - **sq_conn** (&SQConn) - The QUIC connection instance. - **username** (&str) - The username to add. - **password** (&str) - The password for the user. ### Returns - **SResult>** - Returns an SResult containing a result indicating success or an SQExtError. ``` -------------------------------- ### Basic Box Pinning Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Demonstrates creating a pinned box. ```rust let foo = Box::new(()); let bar = Pin::from(foo); ``` -------------------------------- ### Get String length Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.UserName.html Returns the length of the string in bytes. Note that this may differ from the number of characters. ```rust let a = String::from("foo"); assert_eq!(a.len(), 3); let fancy_f = String::from("ƒoo"); assert_eq!(fancy_f.len(), 4); assert_eq!(fancy_f.chars().count(), 3); ``` -------------------------------- ### Get default MTU discovery state Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_mtu_discovery.html Returns the default boolean value for MTU discovery configuration. ```rust pub fn default_mtu_discovery() -> bool ``` -------------------------------- ### pub fn default_brutal_min_window() -> u64 Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_brutal_min_window.html Returns the default value for the brutal minimum window size as a 64-bit unsigned integer. ```APIDOC ## Function: default_brutal_min_window ### Description Returns the default configuration value for the brutal minimum window size used within the shadowquic library. ### Signature `pub fn default_brutal_min_window() -> u64` ### Returns - **u64**: The default brutal minimum window size. ``` -------------------------------- ### QuicClient::connect Source: https://docs.rs/shadowquic/0.3.12/shadowquic/quic/trait.QuicClient.html Establishes a connection to a remote QUIC server. ```APIDOC ## fn connect<'life0, 'life1, 'async_trait>(&'life0 self, addr: SocketAddr, server_name: &'life1 str) -> Pin> + Send + 'async_trait>> ### Description Initiates a connection to the specified address and verifies the server name. ### Parameters - **addr** (SocketAddr) - Required - The remote address to connect to. - **server_name** (&str) - Required - The expected server name for SNI. ``` -------------------------------- ### pub async fn update_config(&self, cfg: &SunnyQuicServerCfg) -> Result<(), SError> Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/inbound/struct.SunnyQuicServer.html Updates the configuration of an existing SunnyQuicServer instance. ```APIDOC ## pub async fn update_config(&self, cfg: &SunnyQuicServerCfg) -> Result<(), SError> ### Description Updates the server configuration dynamically. ### Parameters - **cfg** (&SunnyQuicServerCfg) - Required - The new configuration to apply. ### Returns - **Result<(), SError>** - Returns Ok(()) on success or an error if the update fails. ``` -------------------------------- ### ReplayStream::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/replay_stream/struct.ReplayStream.html Creates a new instance of ReplayStream with a specified prefix and inner stream. ```APIDOC ## pub fn new(prefix: Vec, inner: S) -> Self ### Description Creates a new ReplayStream instance. It takes a byte vector as a prefix and an inner stream to wrap. ### Parameters - **prefix** (Vec) - The prefix data to be used by the stream. - **inner** (S) - The inner stream object that implements the required traits. ``` -------------------------------- ### EndClient::connect Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/struct.EndClient.html Establishes a connection to a remote server using the EndClient instance. ```APIDOC ## fn connect(&self, addr: SocketAddr, server_name: &str) -> Pin> + Send>> ### Description Connects to a remote QUIC server at the specified address and verifies the server name. ### Parameters - **addr** (SocketAddr) - Required - The socket address of the server. - **server_name** (&str) - Required - The expected server name for TLS verification. ``` -------------------------------- ### pub fn default_mtu_discovery() -> bool Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_mtu_discovery.html Returns the default configuration value for MTU discovery. ```APIDOC ## Function: default_mtu_discovery ### Description Returns the default boolean value for MTU discovery configuration. ### Signature `pub fn default_mtu_discovery() -> bool` ### Returns - **bool** - The default MTU discovery setting. ``` -------------------------------- ### Initialize ReplayStream Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/replay_stream/struct.ReplayStream.html Constructor for creating a new ReplayStream instance with a prefix and an inner stream. ```rust pub fn new(prefix: Vec, inner: S) -> Self ``` -------------------------------- ### Get default brutal minimum sample count Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_brutal_min_sample_count.html Returns the default u64 value used for the brutal minimum sample count configuration. ```rust pub fn default_brutal_min_sample_count() -> u64 ``` -------------------------------- ### pub async fn run(self) -> Result<(), SError> Source: https://docs.rs/shadowquic/0.3.12/shadowquic/struct.Manager.html Executes the manager's main loop, handling inbound and outbound traffic processing. ```APIDOC ## pub async fn run(self) -> Result<(), SError> ### Description Executes the manager's main loop. This method consumes the Manager instance and processes inbound and outbound traffic until completion or error. ### Returns - **Result<(), SError>** - Returns Ok(()) on successful execution or an SError if the process fails. ``` -------------------------------- ### Get default brutal minimum acknowledgment rate Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_brutal_min_ack_rate.html Returns the default f64 value used for the brutal minimum acknowledgment rate configuration. ```rust pub fn default_brutal_min_ack_rate() -> f64 ``` -------------------------------- ### pub fn default_over_stream() -> bool Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_over_stream.html Retrieves the default configuration setting for stream handling. ```APIDOC ## Function: default_over_stream ### Description Returns the default boolean configuration value for stream operations within the shadowquic library. ### Signature `pub fn default_over_stream() -> bool` ### Returns - **bool** - The default stream configuration setting. ``` -------------------------------- ### Get mutable reference to Arc Source: https://docs.rs/shadowquic/0.3.12/shadowquic/squic/inbound/type.SunnyQuicUsers.html Use get_mut to obtain a mutable reference when no other pointers exist. It returns None if other Arc or Weak pointers are present. ```rust use std::sync::Arc; let mut x = Arc::new(3); *Arc::get_mut(&mut x).unwrap() = 4; assert_eq!(*x, 4); let _y = Arc::clone(&x); assert!(Arc::get_mut(&mut x).is_none()); ``` -------------------------------- ### connect Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/struct.EndClient.html Establishes a connection to a remote server using the specified address and server name. ```APIDOC ## fn connect<'life0, 'life1, 'async_trait>(&'life0 self, addr: SocketAddr, server_name: &'life1 str) -> Pin> + Send + 'async_trait>> ### Description Initiates a connection to a remote QUIC server. ### Parameters - **addr** (SocketAddr) - Required - The socket address of the server. - **server_name** (&str) - Required - The server name for SNI. ### Returns - **Future>** - A future that resolves to the connection object or a QUIC error. ``` -------------------------------- ### ShadowQuicServer::accept Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/inbound/struct.ShadowQuicServer.html Accepts an incoming proxy request. ```APIDOC ## fn accept(&mut self) -> Pin> + Send + 'async_trait>> ### Description Waits for and accepts an incoming proxy request from the server. ### Returns - **Result** - Returns the accepted ProxyRequest or an error if the operation fails. ``` -------------------------------- ### connect() Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/struct.EndServer.html Connect to a remote endpoint. ```APIDOC ## pub fn connect(&self, addr: SocketAddr, server_name: &str) -> Result ### Description Connect to a remote endpoint. `server_name` must be covered by the certificate presented by the server. ``` -------------------------------- ### handle_connection Source: https://docs.rs/shadowquic/0.3.12/shadowquic/squic/inbound/struct.SQServerConn.html Asynchronously handles an inbound QUIC connection. ```APIDOC ## pub async fn handle_connection(self: Arc, req_send: Sender) -> Result<(), SError> ### Description Handles the lifecycle of an inbound QUIC connection. This method processes requests received over the connection and sends them to the provided proxy request channel. ### Parameters - **req_send** (Sender) - Required - The channel sender used to forward proxy requests. ### Returns - **Result<(), SError>** - Returns Ok(()) on success, or an SError if the connection handling fails. ``` -------------------------------- ### Clone from reference Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Experimental API to allocate memory and clone a reference into it. ```rust #![feature(clone_from_ref)] let hello: Box = Box::clone_from_ref("hello"); ``` -------------------------------- ### Peek at datagrams using UdpSocket Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Demonstrates how to use the peek method to inspect incoming datagrams without removing them from the queue. ```rust use tokio::net::UdpSocket; use std::io; #[tokio::main] async fn main() -> io::Result<()> { let socket = UdpSocket::bind("127.0.0.1:8080").await?; let mut buf = vec![0u8; 32]; let len = socket.peek(&mut buf).await?; println!("peeked {:?} bytes", len); Ok(()) } ``` -------------------------------- ### SocksAddr::from_domain Source: https://docs.rs/shadowquic/0.3.12/shadowquic/msgs/socks5/struct.SocksAddr.html Creates a new SocksAddr instance from a domain name and port. ```APIDOC ## pub fn from_domain(name: String, port: u16) -> Self ### Description Creates a new SocksAddr instance using the provided domain name and port number. ### Parameters - **name** (String) - The domain name string. - **port** (u16) - The port number. ``` -------------------------------- ### Create New String Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.UserName.html Initializes an empty String without allocating an initial buffer. ```rust let s = String::new(); ``` -------------------------------- ### QuicClient::new_with_socket_factory Source: https://docs.rs/shadowquic/0.3.12/shadowquic/quic/trait.QuicClient.html Creates a new instance of the QuicClient using a specific configuration and a custom socket factory. ```APIDOC ## fn new_with_socket_factory<'life0, 'async_trait>(cfg: &'life0 Self::SC, socket_factory: Arc) -> Pin> + Send + 'async_trait>> ### Description Initializes a new client instance using a configuration and a custom socket factory for network operations. ### Parameters - **cfg** (&Self::SC) - Required - The configuration object. - **socket_factory** (Arc) - Required - The factory used to create sockets. ``` -------------------------------- ### open_bi Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/type.Connection.html Opens a new bidirectional stream. ```APIDOC ## fn open_bi(&self) -> Pin> + Send + 'async_trait>> ### Description Opens a new bidirectional stream on the connection. ### Returns A future that resolves to a tuple containing the SendStream, RecvStream, and a stream ID (u64), or a QuicErrorRepr on failure. ``` -------------------------------- ### Convert Box to NonNull and back Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Demonstrates converting a Box to a NonNull pointer and restoring it using Box::from_non_null for automatic cleanup. ```rust #![feature(box_vec_non_null)] let x = Box::new(String::from("Hello")); let non_null = Box::into_non_null(x); let x = unsafe { Box::from_non_null(non_null) }; ``` -------------------------------- ### pub async fn list_users(sq_conn: &SQConn) -> SResult, SQExtError>> Source: https://docs.rs/shadowquic/0.3.12/shadowquic/squic/outbound/fn.list_users.html Retrieves a list of users associated with the given QUIC connection. ```APIDOC ## list_users ### Description Retrieves a list of users over a provided QUIC connection. ### Signature `pub async fn list_users(sq_conn: &SQConn) -> SResult, SQExtError>>` ### Parameters - **sq_conn** (&SQConn) - Required - The QUIC connection instance to use for the request. ### Returns - **Result, SQExtError>** - A result containing a vector of user strings on success, or an SQExtError on failure. ``` -------------------------------- ### Construct Box from raw pointer Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Demonstrates recreating a Box from a raw pointer or manually allocating memory with the system allocator. ```rust #![feature(allocator_api)] use std::alloc::System; let x = Box::new_in(5, System); let (ptr, alloc) = Box::into_raw_with_allocator(x); let x = unsafe { Box::from_raw_in(ptr, alloc) }; ``` ```rust #![feature(allocator_api, slice_ptr_get)] use std::alloc::{Allocator, Layout, System}; unsafe { let ptr = System.allocate(Layout::new::())?.as_mut_ptr() as *mut i32; // In general .write is required to avoid attempting to destruct // the (uninitialized) previous contents of `ptr`, though for this // simple example `*ptr = 5` would have worked as well. ptr.write(5); let x = Box::from_raw_in(ptr, System); } ``` -------------------------------- ### Try clone from reference with allocator Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyUdpRecv.html Attempts to allocate memory and clone the source, returning an AllocError if allocation fails. Requires nightly-only features. ```rust #![feature(clone_from_ref)] #![feature(allocator_api)] use std::alloc::System; let hello: Box = Box::try_clone_from_ref_in("hello", System)?; ``` -------------------------------- ### Construct Arc from reference Source: https://docs.rs/shadowquic/0.3.12/shadowquic/squic/inbound/type.SunnyQuicUsers.html Demonstrates the use of the nightly-only clone_from_ref API to create an Arc from a reference. ```rust #![feature(clone_from_ref)] use std::sync::Arc; let hello: Arc = Arc::clone_from_ref("hello"); ``` -------------------------------- ### Write to Box Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Demonstrates writing a value into a Box. ```rust // reuse the box for a second value let c = Box::write(uninit, 6); assert_eq!(*c, 6); ``` -------------------------------- ### UserManager Methods Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/outbound/struct.ShadowQuicClient.html Methods for managing users within the ShadowQuicClient context. ```APIDOC ## User Management Methods ### add_user(user: AuthUser) Adds a new user for authentication. ### remove_user(username: &str) Removes a user by their username. ### list_users() Returns a list of all registered usernames. ### get_user_stats(username: &str) Retrieves statistics for a specific user. ### get_all_stats() Retrieves statistics for all users. ### kill_user_conns(username: &str) Terminates all active connections for a specific user. ``` -------------------------------- ### Wait for socket writability Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Demonstrates waiting for a socket to become writable before attempting to send data, handling potential false-positive readiness events. ```rust use tokio::net::UdpSocket; use std::io; #[tokio::main] async fn main() -> io::Result<()> { // Bind socket let socket = UdpSocket::bind("127.0.0.1:8080").await?; socket.connect("127.0.0.1:8081").await?; loop { // Wait for the socket to be writable socket.writable().await?; // Try to send data, this may still fail with `WouldBlock` // if the readiness event is a false positive. match socket.try_send(b"hello world") { Ok(n) => { break; } Err(ref e) if e.kind() == io::ErrorKind::WouldBlock => { continue; } Err(e) => { return Err(e); } } } Ok(()) } ``` -------------------------------- ### Peek from UdpSocket asynchronously Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Demonstrates using peek_from to inspect data and the sender address without consuming the packet. ```rust use tokio::net::UdpSocket; use std::io; #[tokio::main] async fn main() -> io::Result<()> { let socket = UdpSocket::bind("127.0.0.1:8080").await?; let mut buf = vec![0u8; 32]; let (len, addr) = socket.peek_from(&mut buf).await?; println!("peeked {:?} bytes from {:?}", len, addr); Ok()} ``` -------------------------------- ### default_brutal_min_window function signature Source: https://docs.rs/shadowquic/0.3.12/shadowquic/config/fn.default_brutal_min_window.html Displays the function signature for default_brutal_min_window. ```rust pub fn default_brutal_min_window() -> u64 ``` -------------------------------- ### ShadowQuicClient::get_conn Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/outbound/struct.ShadowQuicClient.html Retrieves the current QUIC connection. ```APIDOC ## pub async fn get_conn(&self) -> Result ### Description Asynchronously retrieves the active ShadowQuicConn associated with this client. ``` -------------------------------- ### Create String with Capacity Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.UserName.html Initializes a String with a pre-allocated buffer to avoid reallocations during growth. ```rust let mut s = String::with_capacity(10); // The String contains no chars, even though it has capacity for more assert_eq!(s.len(), 0); // These are all done without reallocating... let cap = s.capacity(); for _ in 0..10 { s.push('a'); } assert_eq!(s.capacity(), cap); // ...but this may make the string reallocate s.push('a'); ``` -------------------------------- ### SocksClient::handle Source: https://docs.rs/shadowquic/0.3.12/shadowquic/socks/outbound/struct.SocksClient.html Handles a proxy request using the SocksClient instance. ```APIDOC ## fn handle(&mut self, req: ProxyRequest) -> Pin> + Send + 'async_trait>> ### Description Processes an incoming proxy request asynchronously. ### Parameters - **req** (ProxyRequest) - Required - The proxy request to be handled. ### Returns - **Result<(), SError>** - Returns an empty result on success or an SError on failure. ``` -------------------------------- ### new_with_socket_factory Source: https://docs.rs/shadowquic/0.3.12/shadowquic/shadowquic/struct.EndClient.html Creates a new EndClient instance using a custom socket factory. ```APIDOC ## fn new_with_socket_factory<'life0, 'async_trait>(cfg: &'life0 Self::SC, socket_factory: Arc) -> Pin> + Send + 'async_trait>> ### Description Creates a new EndClient instance with a custom socket factory for advanced networking requirements. ### Parameters - **cfg** (&Self::SC) - Required - The configuration for the ShadowQuicClient. - **socket_factory** (Arc) - Required - A thread-safe factory for creating sockets. ### Returns - **Future>** - A future that resolves to the new EndClient instance. ``` -------------------------------- ### Create new Arc Source: https://docs.rs/shadowquic/0.3.12/shadowquic/squic/inbound/type.SunnyQuicUsers.html Constructs a new Arc instance containing the provided data. ```rust use std::sync::Arc; let five = Arc::new(5); ``` -------------------------------- ### Allocate memory with Box::new Source: https://docs.rs/shadowquic/0.3.12/shadowquic/type.AnyTcp.html Allocates memory on the heap and places the value into it. ```rust let five = Box::new(5); ``` -------------------------------- ### open_uni Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/type.Connection.html Opens a new unidirectional stream. ```APIDOC ## fn open_uni(&self) -> Pin> + Send + 'async_trait>> ### Description Opens a new unidirectional stream on the connection. ### Returns A future that resolves to a tuple containing the SendStream and a stream ID (u64), or a QuicErrorRepr on failure. ``` -------------------------------- ### try_io Source: https://docs.rs/shadowquic/0.3.12/shadowquic/utils/dual_socket/struct.DualSocket.html Executes a user-provided IO operation on the socket if it is ready. Manages readiness flags based on the closure's result. ```APIDOC ## try_io(&self, interest: Interest, f: impl FnOnce() -> Result) -> Result ### Description Tries to perform an IO operation on the socket. If the socket is ready, the closure is executed. If the closure returns WouldBlock, the readiness flag is cleared. ### Parameters - **interest** (Interest) - Required - The IO interest (read/write). - **f** (impl FnOnce) - Required - The closure performing the manual IO operation. ``` -------------------------------- ### SunnyQuicClient::get_conn Source: https://docs.rs/shadowquic/0.3.12/shadowquic/sunnyquic/outbound/struct.SunnyQuicClient.html Retrieves the current QUIC connection. ```APIDOC ## pub async fn get_conn(&self) -> Result ### Description Asynchronously retrieves the active QUIC connection for the client. ### Returns - **Result** - Returns the connection object on success, or an SError if the connection cannot be retrieved. ```