Skip to main content

Crate arnelify_server

Crate arnelify_server 

Source
Expand description
Arnelify Logo

Arnelify Server for Rust Rust Cargo

§About

Arnelify® Server for Rust — a multi-language server with HTTP 3.0 and WebTransport support.

All supported protocols:

#ProtocolTransport
1TCP1HTTP 1.1
2TCP1HTTP 2.0
3TCP1WebSocket
4TCP2HTTP 3.0
5TCP2WebTransport

§Minimal Requirements

Important: It’s strongly recommended to use in a container that has been built from the gcc v15.2.0 image.

  • CPU: Apple M1 / Intel Core i7 / AMD Ryzen 7
  • OS: Debian 11 / MacOS 15 / Windows 10 with WSL2.
  • RAM: 4 GB

§Installation

Run in terminal:

cargo add arnelify_server

§TCP2 / WebTransport

WebTransport - is a modern protocol for low-latency, bidirectional data transfer in browsers and applications. It works over Next Generation HTTP 3.0 and Next Generation TCP2 (QUIC), allowing multiple streams and messages in parallel.

§Configuration

OptionDescription
BLOCK_SIZE_KBThe size of the allocated memory used for processing large packets.
CERT_PEMPath to the TLS cert-file in PEM format.
COMPRESSIONIf this option is enabled, the server will use BROTLI compression if the client application supports it. This setting increases CPU resource consumption. The server will not use compression if the data size exceeds the value of BLOCK_SIZE_KB.
HANDSHAKE_TIMEOUTMaximum time in seconds to complete the TLS handshake.
KEY_PEMPath to the TLS private key-file in PEM format.
MAX_MESSAGE_SIZE_MBMaximum size of a single message the server will accept from a client.
PING_TIMEOUTMaximum time the server will wait for a ping from the client.
PORTDefines which port the server will listen on.
SEND_TIMEOUTMaximum time for the client to receive a response from the server.
THREAD_LIMITDefines the maximum number of threads that will handle requests.

§Examples

use arnelify_server::tcp2::{
    WebTransport, WebTransportBytes, WebTransportCtx, WebTransportHandler, 
    WebTransportLogger, WebTransportOpts, WebTransportStream,
};

use std::sync::{Arc, Mutex};

type JSON = serde_json::Value;

fn main() {
    let wt_opts = WebTransportOpts {
        block_size_kb: 64,
        cert_pem: String::from("certs/cert.pem"),
        compression: true,
        handshake_timeout: 30,
        key_pem: String::from("certs/key.pem"),
        max_message_size_kb: 30,
        ping_timeout: 30,
        port: 4433,
        send_timeout: 30,
        thread_limit: 4,
    };

    let wt = WebTransport::new(wt_opts);

    let wt_logger: Arc<WebTransportLogger> = Arc::new(
        move |_level, message| {
            println!("[Arnelify Server]: {}", message);
        },
    );

    wt.logger(wt_logger);

    let wt_handler: Arc<WebTransportHandler> = Arc::new(
        move |ctx: Arc<Mutex<WebTransportCtx>>,
              bytes: Arc<Mutex<WebTransportBytes>>,
              stream: Arc<Mutex<WebTransportStream>>| {

            let json: JSON = {
                let ctx_lock = ctx.lock().unwrap();
                ctx_lock.clone()
            };

            let bytes_vec = {
                let bytes_lock = bytes.lock().unwrap();
                bytes_lock.clone()
            };

            let mut stream_lock = stream.lock().unwrap();
            stream_lock.push(&json, &bytes_vec);
            stream_lock.close();
        },
    );

    wt.on("connect", wt_handler);
    wt.start();
}

§TCP2 / HTTP 3.0

HTTP 3.0 - is the latest version of the HTTP protocol, built on top of Next Generation TCP2 (QUIC) instead of TCP1. It provides faster and more reliable connections by reducing handshake latency and improving packet loss recovery.

§Configuration

OptionDescription
ALLOW_EMPTY_FILESIf this option is enabled, the server will not reject empty files.
BLOCK_SIZE_KBThe size of the allocated memory used for processing large packets.
CERT_PEMPath to the TLS cert-file in PEM format.
CHARSETDefines the encoding that the server will recommend to all client applications.
COMPRESSIONIf this option is enabled, the server will use BROTLI compression if the client application supports it. This setting increases CPU resource consumption. The server will not use compression if the data size exceeds the value of BLOCK_SIZE_KB.
KEEP_EXTENSIONSIf this option is enabled, file extensions will be preserved.
KEY_PEMPath to the TLS private key-file in PEM format.
MAX_FIELDSDefines the maximum number of fields in the received form.
MAX_FIELDS_SIZE_TOTAL_MBDefines the maximum total size of all fields in the form. This option does not include file sizes.
MAX_FILESDefines the maximum number of files in the form.
MAX_FILES_SIZE_TOTAL_MBDefines the maximum total size of all files in the form.
MAX_FILE_SIZE_MBDefines the maximum size of a single file in the form.
PORTDefines which port the server will listen on.
STORAGE_PATHSpecifies the upload directory for storage.
THREAD_LIMITDefines the maximum number of threads that will handle requests.

§Examples

use arnelify_server::tcp2::{
    Http3, Http3Ctx, Http3Handler, Http3Logger, Http3Opts,
    Http3Stream,
};

use std::sync::{Arc, Mutex};

type JSON = serde_json::Value;

fn main() {
    let http3_opts = Http3Opts {
        allow_empty_files: false,
        block_size_kb: 64,
        cert_pem: String::from("certs/cert.pem"),
        charset: String::from("utf-8"),
        compression: true,
        keep_alive: 30,
        keep_extensions: true,
        key_pem: String::from("certs/key.pem"),
        max_fields: 10,
        max_fields_size_total_mb: 1,
        max_files: 3,
        max_files_size_total_mb: 60,
        max_file_size_mb: 60,
        port: 4433,
        storage_path: String::from("/var/www/rs/storage"),
        thread_limit: 4,
    };

    let http3 = Http3::new(http3_opts);

    let http3_logger: Arc<Http3Logger> = Arc::new(
        move |_level, message| {
            println!("[Arnelify Server]: {}", message);
        },
    );

    http3.logger(http3_logger);

    let http3_handler: Arc<Http3Handler> = Arc::new(
        move |ctx: Arc<Mutex<Http3Ctx>>,
              stream: Arc<Mutex<Http3Stream>>| {

            let json: JSON = {
                let ctx_lock = ctx.lock().unwrap();
                ctx_lock.clone()
            };

            let mut stream_lock = stream.lock().unwrap();
            stream_lock.set_code(200);
            stream_lock.push_json(&json, false);
            stream_lock.end();
        },
    );

    http3.on("/", http3_handler);
    http3.start();
}

§TCP1 / WebSocket

WebSocket - is a protocol that enables full-duplex, bidirectional communication between a client and server over a single TCP1 connection.

§Configuration

OptionDescription
BLOCK_SIZE_KBThe size of the allocated memory used for processing large packets.
COMPRESSIONIf this option is enabled, the server will use BROTLI compression if the client application supports it. This setting increases CPU resource consumption. The server will not use compression if the data size exceeds the value of BLOCK_SIZE_KB.
HANDSHAKE_TIMEOUTMaximum time in seconds to complete the TLS handshake.
MAX_MESSAGE_SIZE_MBMaximum size of a single message the server will accept from a client.
PING_TIMEOUTMaximum time the server will wait for a ping from the client.
PORTDefines which port the server will listen on.
SEND_TIMEOUTMaximum time for the client to receive a response from the server.
THREAD_LIMITDefines the maximum number of threads that will handle requests.

§Examples

use arnelify_server::tcp1::{
    WebSocket, WebSocketBytes, WebSocketCtx, WebSocketHandler, 
    WebSocketLogger, WebSocketOpts, WebSocketStream,
};

use std::sync::{Arc, Mutex};

type JSON = serde_json::Value;

fn main() {
    let ws_opts = WebSocketOpts {
        block_size_kb: 64,
        compression: false,
        handshake_timeout: 30,
        max_message_size_kb: 30,
        ping_timeout: 30,
        port: 4433,
        send_timeout: 30,
        thread_limit: 4,
    };

    let ws = WebSocket::new(ws_opts);

    let ws_logger: Arc<WebSocketLogger> = Arc::new(
        move |_level, message| {
            println!("[Arnelify Server]: {}", message);
        },
    );

    ws.logger(ws_logger);

    let ws_handler: Arc<WebSocketHandler> = Arc::new(
        move |ctx: Arc<Mutex<WebSocketCtx>>,
              bytes: Arc<Mutex<WebSocketBytes>>,
              stream: Arc<Mutex<WebSocketStream>>| {

            let json: JSON = {
                let ctx_lock = ctx.lock().unwrap();
                ctx_lock.clone()
            };

            let bytes_vec = {
                let bytes_lock = bytes.lock().unwrap();
                bytes_lock.clone()
            };

            let mut stream_lock = stream.lock().unwrap();
            stream_lock.push(&json, &bytes_vec);
            stream_lock.close();
        },
    );

    ws.on("connect", ws_handler);
    ws.start();
}

§TCP1 / HTTP 2.0

HTTP 2.0 - is a revision of the HTTP protocol that improves performance over HTTP 1.1. It introduces multiplexed streams, allowing multiple requests and responses to be sent over a single TCP1 connection simultaneously.

§Configuration

OptionDescription
ALLOW_EMPTY_FILESIf this option is enabled, the server will not reject empty files.
BLOCK_SIZE_KBThe size of the allocated memory used for processing large packets.
CERT_PEMPath to the TLS cert-file in PEM format.
CHARSETDefines the encoding that the server will recommend to all client applications.
COMPRESSIONIf this option is enabled, the server will use BROTLI compression if the client application supports it. This setting increases CPU resource consumption. The server will not use compression if the data size exceeds the value of BLOCK_SIZE_KB.
KEEP_EXTENSIONSIf this option is enabled, file extensions will be preserved.
KEY_PEMPath to the TLS private key-file in PEM format.
MAX_FIELDSDefines the maximum number of fields in the received form.
MAX_FIELDS_SIZE_TOTAL_MBDefines the maximum total size of all fields in the form. This option does not include file sizes.
MAX_FILESDefines the maximum number of files in the form.
MAX_FILES_SIZE_TOTAL_MBDefines the maximum total size of all files in the form.
MAX_FILE_SIZE_MBDefines the maximum size of a single file in the form.
PORTDefines which port the server will listen on.
STORAGE_PATHSpecifies the upload directory for storage.
THREAD_LIMITDefines the maximum number of threads that will handle requests.

§Examples

use arnelify_server::tcp1::{
    Http2, Http2Ctx, Http2Handler, Http2Logger, Http2Opts,
    Http2Stream,
};

use std::sync::{Arc, Mutex};

type JSON = serde_json::Value;

fn main() {
    let http2_opts = Http2Opts {
        allow_empty_files: false,
        block_size_kb: 1024,
        cert_pem: String::from("certs/cert.pem"),
        charset: String::from("utf-8"),
        compression: true,
        keep_alive: 30,
        keep_extensions: true,
        key_pem: String::from("certs/key.pem"),
        max_fields: 10,
        max_fields_size_total_mb: 1,
        max_files: 1,
        max_files_size_total_mb: 10,
        max_file_size_mb: 10,
        port: 4433,
        storage_path: String::from("/var/www/rs/storage"),
        thread_limit: 4,
    };

    let http2 = Http2::new(http2_opts);

    let http2_logger: Arc<Http2Logger> = Arc::new(
        move |_level, message| {
            println!("[Arnelify Server]: {}", message);
        },
    );

    http2.logger(http2_logger);

    let http2_handler: Arc<Http2Handler> = Arc::new(
        move |ctx: Arc<Mutex<Http2Ctx>>,
              stream: Arc<Mutex<Http2Stream>>| {

            let json: JSON = {
                let ctx_lock = ctx.lock().unwrap();
                ctx_lock.clone()
            };

            let mut stream_lock = stream.lock().unwrap();
            stream_lock.set_code(200);
            stream_lock.push_json(&json, false);
            stream_lock.end();
        },
    );

    http2.on("/", http2_handler);
    http2.start();
}

§TCP1 / HTTP 1.1

HTTP 1.1 - is a widely used version of the HTTP protocol that relies on TCP1 connections for communication.

§Configuration

OptionDescription
ALLOW_EMPTY_FILESIf this option is enabled, the server will not reject empty files.
BLOCK_SIZE_KBThe size of the allocated memory used for processing large packets.
CHARSETDefines the encoding that the server will recommend to all client applications.
COMPRESSIONIf this option is enabled, the server will use BROTLI compression if the client application supports it. This setting increases CPU resource consumption. The server will not use compression if the data size exceeds the value of BLOCK_SIZE_KB.
KEEP_EXTENSIONSIf this option is enabled, file extensions will be preserved.
MAX_FIELDSDefines the maximum number of fields in the received form.
MAX_FIELDS_SIZE_TOTAL_MBDefines the maximum total size of all fields in the form. This option does not include file sizes.
MAX_FILESDefines the maximum number of files in the form.
MAX_FILES_SIZE_TOTAL_MBDefines the maximum total size of all files in the form.
MAX_FILE_SIZE_MBDefines the maximum size of a single file in the form.
PORTDefines which port the server will listen on.
STORAGE_PATHSpecifies the upload directory for storage.
THREAD_LIMITDefines the maximum number of threads that will handle requests.

§Examples

use arnelify_server::tcp1::{
    Http1, Http1Ctx, Http1Handler, Http1Logger, Http1Opts, 
    Http1Stream,
};

use std::sync::{Arc, Mutex};

type JSON = serde_json::Value;

fn main() {
    let http1_opts = Http1Opts {
        allow_empty_files: false,
        block_size_kb: 64,
        charset: String::from("utf-8"),
        compression: true,
        keep_alive: 30,
        keep_extensions: true,
        max_fields: 10,
        max_fields_size_total_mb: 1,
        max_files: 3,
        max_files_size_total_mb: 60,
        max_file_size_mb: 60,
        port: 4433,
        storage_path: String::from("/var/www/rs/storage"),
        thread_limit: 4,
    };

    let http1 = Http1::new(http1_opts);

    let http1_logger: Arc<Http1Logger> = Arc::new(move |_level, message| {
        println!("[Arnelify Server]: {}", message);
    });

    http1.logger(http1_logger);

    let http1_handler: Arc<Http1Handler> = Arc::new(
        move |ctx: Arc<Mutex<Http1Ctx>>, stream: Arc<Mutex<Http1Stream>>| {
            let json: JSON = {
                let ctx_lock = ctx.lock().unwrap();
                ctx_lock.clone()
            };

            let mut stream_lock = stream.lock().unwrap();
            stream_lock.set_code(200);
            stream_lock.push_json(&json, false);
            stream_lock.end();
        },
    );

    http1.on("/", http1_handler);
    http1.start();
}

§MIT License

This software is licensed under the MIT License. The original author’s name, logo, and the original name of the software must be included in all copies or substantial portions of the software.

§Contributing

Join us to help improve this software, fix bugs or implement new functionality. Active participation will help keep the software up-to-date, reliable, and aligned with the needs of its users.

Run in terminal:

docker compose up -d --build
docker ps
docker exec -it <CONTAINER ID> bash

For TCP2 / WebTransport:

cargo run --bin test_wt

For TCP2 / HTTP 3.0:

cargo run --bin test_http3

For TCP1 / WebSocket:

cargo run --bin test_ws

For TCP1 / HTTP 2.0:

cargo run --bin test_http2

For TCP1 / HTTP 1.1:

cargo run --bin test_http1

§Release Notes

Version 0.9.4 — a multi-language server with HTTP 3.0 and WebTransport support.

We are excited to introduce the Arnelify Server for Rust! Please note that this version is raw and still in active development.

Change Log:

  • Async Multi-Threading.
  • Block processing in “on-the-fly” mode.
  • BROTLI compression (still in development).
  • FFI, PYO3 and NEON support.
  • Significant refactoring and optimizations.

Please use this version with caution, as it may contain bugs and unfinished features. We are actively working on improving and expanding the server’s capabilities, and we welcome your feedback and suggestions.

Re-exports§

pub use tcp1::Http1;
pub use tcp1::Http1Ctx;
pub use tcp1::Http1Handler;
pub use tcp1::Http1Logger;
pub use tcp1::Http1Opts;
pub use tcp1::Http1Stream;
pub use tcp1::Http2;
pub use tcp1::Http2Handler;
pub use tcp1::Http2Logger;
pub use tcp1::Http2Opts;
pub use tcp1::Http2Stream;
pub use tcp1::WebSocket;
pub use tcp1::WebSocketBytes;
pub use tcp1::WebSocketCtx;
pub use tcp1::WebSocketHandler;
pub use tcp1::WebSocketLogger;
pub use tcp1::WebSocketOpts;
pub use tcp1::WebSocketStream;
pub use tcp2::Http3;
pub use tcp2::Http3Handler;
pub use tcp2::Http3Logger;
pub use tcp2::Http3Opts;
pub use tcp2::Http3Stream;
pub use tcp2::WebTransport;
pub use tcp2::WebTransportBytes;
pub use tcp2::WebTransportCtx;
pub use tcp2::WebTransportHandler;
pub use tcp2::WebTransportLogger;
pub use tcp2::WebTransportOpts;
pub use tcp2::WebTransportStream;

Modules§

tcp1
tcp2

Enums§

Http2Ctx
Represents any valid JSON value.
Http3Ctx
Represents any valid JSON value.

Functions§

http1_add_header
http1_create
http1_destroy
http1_end
http1_logger
http1_on
http1_push_bytes
http1_push_file
http1_push_json
http1_set_code
http1_set_compression
http1_set_headers
http1_start
http1_stop
http2_add_header
http2_create
http2_destroy
http2_end
http2_logger
http2_on
http2_push_bytes
http2_push_file
http2_push_json
http2_set_code
http2_set_compression
http2_set_headers
http2_start
http2_stop
http3_add_header
http3_create
http3_destroy
http3_end
http3_logger
http3_on
http3_push_bytes
http3_push_file
http3_push_json
http3_set_code
http3_set_compression
http3_set_headers
http3_start
http3_stop
ws_close
ws_create
ws_destroy
ws_logger
ws_on
ws_push
ws_push_bytes
ws_push_json
ws_start
ws_stop
wt_close
wt_create
wt_destroy
wt_logger
wt_on
wt_push
wt_push_bytes
wt_push_json
wt_start
wt_stop