morpheus_network::client::native

Struct NativeHttpClient

Source
pub struct NativeHttpClient<D: NetworkDevice> {
    iface: NetInterface<D>,
    config: NativeClientConfig,
    socket: Option<SocketHandle>,
    get_time_ms: fn() -> u64,
}
Expand description

Native bare-metal HTTP client.

Generic over NetworkDevice so it works with any driver:

  • VirtIO (QEMU, KVM)
  • Intel NICs (future)
  • Realtek NICs (future)
  • etc.

Fields§

§iface: NetInterface<D>

Network interface with TCP/IP stack.

§config: NativeClientConfig

Client configuration.

§socket: Option<SocketHandle>

Current TCP socket handle (if connected).

§get_time_ms: fn() -> u64

Function to get current time in milliseconds. Must be provided by the caller (platform-specific).

Implementations§

Source§

impl<D: NetworkDevice> NativeHttpClient<D>

Source

pub fn new(device: D, net_config: NetConfig, get_time_ms: fn() -> u64) -> Self

Create a new native HTTP client.

§Arguments
  • device - Network device to use
  • net_config - IP configuration (DHCP or static)
  • get_time_ms - Function returning current time in milliseconds
Source

pub fn with_config( device: D, net_config: NetConfig, client_config: NativeClientConfig, get_time_ms: fn() -> u64, ) -> Self

Create with custom configuration.

Source

fn now(&self) -> u64

Get current timestamp.

Source

pub fn poll(&mut self)

Poll the network interface.

Source

pub fn is_network_ready(&self) -> bool

Check if network is ready (has IP address).

Source

pub fn ip_address(&self) -> Option<Ipv4Addr>

Get current IP address.

Source

pub fn wait_for_network(&mut self, timeout_ms: u64) -> Result<()>

Wait for network to be ready (DHCP complete or static configured).

Source

pub fn resolve_host(&mut self, host: &str) -> Result<Ipv4Addr>

Resolve hostname to IP address using DNS or hardcoded fallbacks.

Source

fn try_dns_query(&mut self, host: &str) -> Result<Ipv4Addr>

Attempt DNS resolution via UDP query.

Source

fn lookup_hardcoded_dns(&self, host: &str) -> Result<Ipv4Addr>

Lookup host in hardcoded DNS table.

Source

fn connect(&mut self, ip: Ipv4Addr, port: u16) -> Result<()>

Connect to a remote host.

Source

fn close_existing_socket(&mut self)

Close any existing socket.

Source

fn create_tcp_socket(&mut self) -> Result<SocketHandle>

Create a new TCP socket.

Source

fn initiate_connection( &mut self, handle: SocketHandle, ip: Ipv4Addr, port: u16, ) -> Result<()>

Initiate TCP connection.

Source

fn wait_for_connection(&mut self, handle: SocketHandle) -> Result<()>

Wait for TCP connection to complete.

Source

fn send_all(&mut self, data: &[u8]) -> Result<()>

Send all data and wait for transmission to complete.

Source

fn recv(&mut self, buffer: &mut [u8]) -> Result<usize>

Receive data with timeout.

Source

fn read_headers(&mut self) -> Result<Vec<u8>>

Read HTTP headers until \r\n\r\n found.

Source

fn read_full_response(&mut self) -> Result<Vec<u8>>

Read full HTTP response (headers + body).

Source

fn read_remaining_body( &mut self, response_data: &mut Vec<u8>, body_start: usize, content_length: Option<usize>, ) -> Result<()>

Read remaining body data based on Content-Length.

Source

fn stream_response_body<F>( &mut self, initial_body: &[u8], content_length: Option<usize>, callback: &mut F, ) -> Result<usize>
where F: FnMut(&[u8]) -> Result<()>,

Stream response body to callback.

Source

fn do_request(&mut self, request: &Request) -> Result<Response>

Execute a basic HTTP request and return full response.

Source

fn do_request_with_redirects(&mut self, request: Request) -> Result<Response>

Execute request with automatic redirect following.

Source

fn build_redirect_request( &self, original: &Request, location: &str, ) -> Result<Request>

Build a new request for a redirect location.

Source

pub fn get(&mut self, url: &str) -> Result<Response>

Simple GET request returning full response.

Source

pub fn get_streaming<F>(&mut self, url: &str, callback: F) -> Result<usize>
where F: FnMut(&[u8]) -> Result<()>,

GET request with streaming callback for large downloads.

Source

fn execute_streaming_request<F>( &mut self, url: &Url, callback: &mut F, ) -> Result<usize>
where F: FnMut(&[u8]) -> Result<()>,

Execute a streaming HTTP request.

Source

fn stream_response<F>(&mut self, callback: &mut F) -> Result<usize>
where F: FnMut(&[u8]) -> Result<()>,

Stream the HTTP response to the callback.

Source

pub fn close(&mut self)

Close any active connection.

Source

pub fn interface(&self) -> &NetInterface<D>

Get reference to the network interface.

Source

pub fn interface_mut(&mut self) -> &mut NetInterface<D>

Get mutable reference to the network interface.

Trait Implementations§

Source§

impl<D: NetworkDevice> Drop for NativeHttpClient<D>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<D: NetworkDevice> HttpClient for NativeHttpClient<D>

Source§

fn request(&mut self, request: &Request) -> Result<Response>

Execute an HTTP request.
Source§

fn request_with_progress( &mut self, request: &Request, _progress: ProgressCallback, ) -> Result<Response>

Execute request with progress tracking.
Source§

fn is_ready(&self) -> bool

Check if client is ready to make requests.

Auto Trait Implementations§

§

impl<D> Freeze for NativeHttpClient<D>
where D: Freeze,

§

impl<D> RefUnwindSafe for NativeHttpClient<D>
where D: RefUnwindSafe,

§

impl<D> Send for NativeHttpClient<D>
where D: Send,

§

impl<D> Sync for NativeHttpClient<D>
where D: Sync,

§

impl<D> Unpin for NativeHttpClient<D>
where D: Unpin,

§

impl<D> !UnwindSafe for NativeHttpClient<D>

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, 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.