BoomNet
Overview
BoomNet is a high-performance framework designed to facilitate the development of low-latency network applications, particularly focusing on TCP stream-oriented clients that utilise various protocols.
Installation
Simply declare dependency on boomnet in your Cargo.toml and select desired features.
[]
= { = "0.0.9", = ["full"]}
Design Principles
BoomNet is structured into multiple layers, with each subsequent layer building upon its predecessor, enhancing functionality and abstraction.
Stream
The first layer offers defines stream as abstractions over TCP connections, adhering to the following characteristics.
- Must implement
ReadandWritetraits for I/O operations. - Operates in a non-blocking manner.
- Integrates TLS using
rustls. - Supports recording and replaying network byte streams.
- Allows binding to specific network interfaces.
- Facilitates the implementation of TCP-oriented client protocols such as websocket, HTTP, and FIX.
Streams are designed to be fully generic, avoiding dynamic dispatch, and can be composed in flexible way.
let stream: = bind_and_connect?
.into_tls_stream
.into_recorded_stream;
Different protocols can then be applied on top of a stream.
let ws: = stream.into_websocket;
Selector
Selector provides abstraction over OS-specific mechanisms (like epoll) for efficiently monitoring socket readiness events.
Though primarily utilised internally, selectors are crucial for the IOService functionality, currently offering both
mio and direct (no-op) implementations.
let mut io_service = new?.into_io_service;
Service
The last layer manages lifecycle of endpoints and provides auxiliary services (e.g., asynchronous DNS resolution)
through the IOService, which internally relies on Selector.
Endpoint serves as application-level construct, binding the communication protocol with the application's
business logic. IOService oversees the connection lifecycle within endpoints.
Protocols
BoomNet aims to support a variety of protocols, including WebSocket, HTTP, and FIX, with WebSocket client functionality currently available.
Websocket
The websocket client protocol complies with the RFC 6455 specification, offering the following features.
- Compatibility with any stream.
- TCP batch-aware timestamps for frames read in the same batch.
- Not blocking on partial frame.
- Optimised for zero-copy read and write operations.
- Optional masking of outbound frames.
- Standalone usage or in conjunction with
SelectorandIOService.
Example Usage
The following example illustrates how to use websocket client in order to consume messages from the Binance cryptocurrency
exchange. First, we need to define and implement our Endpoint. The framework provides TlsWebsocketEndpoint trait
that we can use.
After defining the endpoint, it is registered with the IOService and polled within an event loop. The service handles
Endpoint connection management and reconnection in case of disconnection.
It is often required to expose some application state to the Endpoint. This can be achieved with user defined Context.
// use the marker trait
When implementing our TradeEndpoint we can use TlsWebsocketEndpointWithContext trait instead.
We will also need to create IOService that is Context aware.
let mut context = new;
let mut io_service = new?.into_io_service_with_context;
The Context must now be passed to the service poll method.
loop
Features
BoomNet's feature set is modular, allowing for tailored functionality based on project needs. The full feature enables
all available features, while individual components can be enabled as needed.
mio
Adds dependency on mio crate and enables MioSelector and MioStream.
tls
Adds dependency on rustls crate and enables TlsStream and more flexible TlsReadyStream.
ws
Adds support for Websocket protocol.