Flare Core
flare-core is a production-oriented long-connection toolkit for Rust.
It provides the transport foundation for realtime systems such as instant
messaging gateways, chat rooms, push channels, collaboration tools, and
low-latency application backends.
The crate focuses on transport-level concerns: WebSocket, QUIC, TCP, connection negotiation, heartbeats, reconnection, serialization, compression, encryption, and extensible message pipelines. IM product semantics such as sequence allocation, inbox sync, push policy, and business rules should live in higher-level crates or services.
API documentation: docs.rs/flare-core
Highlights
- Transports: WebSocket, QUIC, optional TCP, and native protocol racing.
- Negotiation: CONNECT / CONNECT_ACK / NEGOTIATION_READY flow for format, compression, and encryption alignment.
- Codecs: Protobuf and JSON with pluggable serializers.
- Reliability basics: heartbeat policy, active detection, reconnect hooks, connection snapshots, and slow-consumer isolation.
- Security hooks: token authentication, TLS support, certificate pinning, and AES-256-GCM encryption when enabled.
- Runtime targets: native Tokio applications and wasm32 WebSocket clients.
- Extension points: custom serializers, compressors, encryptors, middleware, observers, and server event handlers.
Installation
[]
= "1.0.1"
Server-only gateway:
= { = "1.0.1", = false, = [
"server",
"websocket",
"quic",
"compression-gzip",
"encryption-aes-gcm",
] }
Native client:
= { = "1.0.1", = false, = [
"client",
"websocket",
"quic",
"compression-gzip",
"encryption-aes-gcm",
] }
TCP and full feature sets:
= { = "1.0.1", = ["tcp"] }
= { = "1.0.1", = ["full"] }
WASM WebSocket client:
= { = "1.0.1", = false, = ["wasm"] }
Feature Flags
| Feature | Default | Description |
|---|---|---|
client |
yes | Client builders, transports, negotiation, reconnect, and send APIs. |
server |
yes | Native server builders, connection management, and event handling. |
websocket |
yes | WebSocket transport. |
quic |
yes | Native QUIC transport. |
tcp |
no | TCP transport with length-prefixed frames. |
wasm |
no | wasm32 WebSocket client stack. |
compression-gzip |
yes | Gzip compression support. |
encryption-aes-gcm |
yes | AES-256-GCM encryption support. |
full |
no | Default capabilities plus TCP. |
At runtime, use flare_core::common::FeatureSet::current() to inspect the
compiled capability set.
Architecture
Application ServerEventHandler | MessageListener | Authenticator
|
Core ServerCore | ClientCore | ConnectionManager | MessagePipeline
|
Transport HybridServer | HybridClient | WebSocket | QUIC | TCP
Connection lifecycle:
- Establish a transport connection.
- Send CONNECT metadata for serialization, compression, encryption, and authentication.
- Receive CONNECT_ACK and align both parser profiles.
- Emit NEGOTIATION_READY and start heartbeat processing.
- Exchange application frames.
- Disconnect, reconnect, or clean up connection state.
Builder families:
| Mode | Builder | Integration style | Typical use |
|---|---|---|---|
| Simple | ServerBuilder / ClientBuilder |
closures | prototypes and small demos |
| Observer | Observer*Builder |
observer traits | connection-aware integrations |
| Flare | FlareServerBuilder / FlareClientBuilder |
traits and pipeline | production-facing integrations |
Quick Start
Minimal Flare-mode server:
use async_trait;
use Result;
use ;
use ServerEventHandler;
use FlareServerBuilder;
use Arc;
;
async
Run the chat examples from the repository checkout:
RUST_LOG=info
RUST_LOG=info
TCP example:
RUST_LOG=info
More examples are documented in the repository: examples/README.md.
Native And WASM Support
| Capability | Native | WASM |
|---|---|---|
| WebSocket client | yes | yes |
| QUIC client | yes | no |
| TCP client | yes, with tcp |
no |
| Native protocol racing | yes | no |
FlareClientBuilder |
yes | yes, WebSocket only |
| Hybrid server / QUIC server | yes | no |
| Negotiated heartbeat | yes | yes |
For browser demos, see examples/wasm_websocket_client.
Verification
The repository verification script runs formatting, linting, native tests, feature matrix checks, wasm checks, and example builds:
For a focused pre-publish check:
Note: historical doctest snippets in lower-level module comments are not used as the release gate yet. The public README and crate-level docs are kept in English for crates.io and docs.rs.
Performance Baseline
The current baseline covers frame encoding, message parsing, pipeline processing, connection lifecycle, and in-memory fanout. It does not model higher-level IM semantics such as sequence allocation, sync, inbox storage, or push delivery.
Test environment for the published baseline:
| Item | Value |
|---|---|
| CPU | Apple M1 Pro, 10 cores |
| Memory | 16 GiB |
| OS | macOS Darwin 25.3.0 |
| Rust | 1.94.1 |
| Build | release mode, single-process benchmark |
Summary:
| Benchmark | Throughput |
|---|---|
| Protobuf 256B round-trip | 1,017,824 ops/s |
| JSON 256B round-trip | 197,954 ops/s |
| Protobuf + Gzip 1KB round-trip | 51,015 ops/s |
| Pipeline parse + validation | 1,405,371 ops/s |
| Connection add + active + remove | 1,457,953 ops/s |
| Broadcast 1,000 x 256B bytes | ~4,188 broadcasts/s |
| Broadcast 1,000 x 256B frame | ~2,789 broadcasts/s |
| Timeout cleanup, 1,000 connections | ~0.727 ms/op |
Full report: docs/performance-baseline.md.
Documentation
| Resource | Link |
|---|---|
| API reference | docs.rs/flare-core |
| Examples | examples/README.md |
| Performance report | docs/performance-baseline.md |
| Issues | GitHub Issues |
License
Licensed under the MIT License.