How eycorsican/leaf works
• Leaf CLI: Represented by the leaf-cli directory (with its own Cargo.toml and main.rs). This component handles user interactions and command-line operations.
• Leaf Plugins: Modules like leaf-plugins/shadowsocks provide plugin support. This demonstrates the framework’s extensibility.
• Core Engine (Leaf): The “leaf” directory is the heart of the system. Within it, show further breakdown:
• Application Layer (“app”): Contains API-related components, inbound/outbound handling, DNS client, NAT management, logger, and dispatcher modules.
• Configuration Module (“config”): Responsible for reading and parsing different configuration formats (INI, JSON, Proto).
• Proxy Layer (“proxy”): Contains support for multiple proxy protocols and transports (e.g., AMux, QUIC, direct, shadowsocks, socks, TLS, trojan, and many more). It is organized in subdirectories that handle protocol-specific logic.
• Platform/Mobile Support (“mobile”): Contains mobile bindings and wrappers for iOS/Android.
• Core Utility Modules (“common”): These provide cross-cutting utilities like crypto, IO, networking, and system calls.
• Testing: The “tests” folder shows various test cases that verify the functionality of different proxy mechanisms.
Relationships and Interactions
• How the API server (inside the “app/api” directory) interacts with dispatchers and listeners for incoming traffic.
Architectural Patterns
• Modular Design: The project is organized into distinct modules (app, config, common, proxy) that interact through well-defined interfaces.
• Plugin Architecture: The “leaf-plugins” directory signals that the system is designed to allow easy addition or replacement of protocol handlers (e.g., Shadowsocks).
• Layered Approach: Clearly separate the presentation/command-line layer (leaf-cli) from the business logic (core engine) and integration layers (FFI/mobile).
Relevant Technologies and Technologies
• Rust/Cargo: Indicate that the entire project is built using Cargo with multiple packages.
• C FFI Integration: Note the usage of cbindgen for generating C-compatible headers.
• Multiplexing Transports: Highlight AMux and QUIC as key strategies for reducing handshake overhead and improving efficiency.
• Transparent Proxying: Include TUN inbound modules for VPN-like behavior, especially used in mobile and gateway modes.
• Testing and CI/CD: Acknowledge the presence of GitHub workflows for continuous integration and release management.
Final Touches
• That every component’s internal relations (e.g., the division within the “leaf” directory into application logic, routing, protocol handling) are either explicitly shown or noted.