Skip to main content

Refractium

Struct Refractium 

Source
pub struct Refractium { /* private fields */ }
Expand description

The main engine for the Refractium proxy.

Refractium manages the lifecycle of TCP and UDP servers, protocol identification, and backend health monitoring. It is designed to be highly concurrent and supports atomic routing table updates via reload_routes.

§Examples

use refractium::{Refractium, Http, types::{ProtocolRoute, ForwardTarget}};
use std::sync::Arc;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let routes = vec![ProtocolRoute {
        protocol: Arc::new(Http),
        sni: None,
        forward_to: ForwardTarget::Single("127.0.0.1:8080".to_string()),
    }];

    let refractium = Refractium::builder()
        .routes(routes, Vec::new())
        .build()?;

    refractium.run_tcp("0.0.0.0:80".parse()?).await?;
    Ok(())
}

Implementations§

Source§

impl Refractium

Source

pub const fn builder() -> RefractiumBuilder

Returns a new RefractiumBuilder with default settings.

Source

pub async fn reload_routes( &self, tcp: Vec<ProtocolRoute>, udp: Vec<ProtocolRoute>, )

Atomically reloads the routing table for all active servers.

This method updates the internal load balancers and starts monitoring any new backend addresses. Active connections are not dropped during the reload.

Source

pub fn cancel_token(&self) -> CancellationToken

Returns the CancellationToken used by the engine.

This can be used to trigger a graceful shutdown from external logic.

Source

pub async fn run_tcp(&self, addr: SocketAddr) -> Result<()>

Starts the TCP server on the provided address.

This method will block until the server is shut down or an unrecoverable error occurs.

§Errors

Returns a crate::errors::RefractiumError::BindError if the address is already in use or other IO errors occur during startup.

Source

pub async fn run_udp(&self, addr: SocketAddr) -> Result<()>

Starts the UDP server on the provided address.

§Errors

Returns a crate::errors::RefractiumError::BindError if the address is already in use.

Source

pub async fn run_both(&self, addr: SocketAddr) -> Result<()>

Starts both TCP and UDP servers concurrently.

§Errors

Returns an error if either the TCP or UDP server fails to bind.

Source

pub async fn report_health(&self)

Prints a visual health report of all configured backends to stdout.

This is mainly used for debugging or CLI reporting.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more