$ show hypercube1024/firefly
Firefly is a high-performance asynchronous networking framework for the JVM, written in Java and Kotlin. It provides a comprehensive set of I/O primitives including HTTP/1.1, HTTP/2, WebSocket (RFC 6455), TCP, and UDP, with both client and server implementations. The framework is designed around Kotlin coroutines and Java NIO2 (AIO), offering non-blocking, backpressure-aware streams and a router-based HTTP server with support for content negotiation, CORS, static file serving, and HTTP/2 upgrade. It also includes built-in SLF4J logging with XML configuration, a JSON serialization service, a WeChat enterprise bot module, and a JNI helper for native code integration. The codebase is modular (firefly-common, firefly-net, firefly-slf4j, firefly-serialization, firefly-wechat, firefly-example) and demonstrates deep protocol-level craftsmanship with custom HPACK, Huffman coding, and state-machine parsers. While primarily a library for building network services, it also serves as a reference implementation for protocol handling on the JVM.
The LLM identified 6 files worth highlighting for reuse:
Implements a lightweight actor model with a dispatcher and mailbox for message-driven concurrency. The AbstractActor provides a robust foundation for building event-loop-based services without external dependencies. It manages actor state, lifecycle, and message delivery with support for blocking tasks and asynchronous processing through AbstractAsyncActor. This is a self-contained pattern that can be extracted for any JVM project requiring actor-based concurrency.
A fixed-capacity ternary trie implementation optimized for string lookups (e.g., HTTP header names). It provides O(1) worst-case lookup for known keys and supports case-insensitive operations. The implementation is memory-efficient and avoids hash collisions. This is a reusable data structure for any project requiring fast, deterministic string search with a known key set.
Wraps Java's SSLEngine with Kotlin coroutines to provide a suspend-based API for TLS handshakes and encrypted I/O. It handles ALPN negotiation, buffer management, and handshake state transitions. The abstract class allows easy customization (e.g., checking certificate validity) while providing a clean async interface. This pattern is reusable for any JVM network library needing TLS support with coroutines.
A configurable CORS handler for the Firefly HTTP server that implements the Cross-Origin Resource Sharing specification. It supports whitelist of origins, methods, headers, and preflight caching. The handler can be mounted as a router filter and demonstrates a clean intercepting filter pattern for HTTP middleware. This is a standalone component that can be adapted for any JVM HTTP server framework.
A complete HPACK encoder for HTTP/2 header compression (RFC 7541). It implements both static and dynamic table management, Huffman coding, and integer encoding (NBitInteger). The encoder is a core component of the HTTP/2 stack but is self-contained and can be extracted for any project that needs to compress HTTP headers according to the HPACK specification. The code is carefully optimized and includes thorough test coverage from the RFC examples.
A utility class providing essential operations on Java NIO ByteBuffers, including methods for appending, flipping, filling, flushing, merging, and converting between buffer representations. It also offers hex conversion and capacity management. The class is widely used throughout the framework and provides a consistent, tested interface for buffer manipulation. It is a high-quality utility that can be reused in any Java NIO project.