How nordsecurity/libdrop works
Project Type and Purpose
• libdrop is a modular Rust library for peer-to-peer and WAN file transfers over meshnets, with a CLI/server example (udrop) and multi-language bindings via UniFFI.
• It’s not a traditional “microservices” deployment but a collection of inter-dependent crates (modules) that compose the core library plus example services and binding tools.
File Structure
• drop-core: Core domain types & logic (status, events).
• drop-config: Configuration loader/validator.
• drop-auth: HTTP auth layer for clients/servers.
• drop-storage: Database layer (PostgreSQL migrations, sync, types).
• drop-transfer: Transfer engine (protocol v6, WS client/server, file I/O, manager, tasks).
• drop-analytics: Instrumentation & analytics hooks.
• norddrop: CLI/UDL layer for UniFFI, exposes norddrop_version(), config, device interfaces.
• uniffi-bindgen & contrib/swift_package/bindings: Binding-generation utilities (Python, Swift).
• udrop example (in drop-transfer/examples/udrop.rs and run.py server): Illustrative server/client binaries.
• test/: Scenario-based Python test harness orchestrating containerized end-to-end tests.
README for Insights
• Example server spun up via run.py server run in a Docker container.
• Client example via cargo run --example udrop.
• Database is external (PostgreSQL) with migrations in drop-storage.
Main Components & Relationships
A. Frontend/CLI
– Components: norddrop CLI, udrop client binary, Python test harness.
– Interacts with drop-transfer (over TCP/WS) or drop-auth (HTTP).
B. Transfer Service
– drop-transfer WS server & protocol v6 listener.
– Exposes TCP/WS endpoints for incoming file streams.
– Depends on: drop-auth (to authenticate), drop-storage (to persist events/metadata), drop-core (domain logic), drop-analytics (emit metrics).
C. Authentication Layer
– drop-auth HTTP endpoints for login/permission tokens.
– Used by both client and server to secure transfers.
D. Storage Layer
– drop-storage crate + PostgreSQL instance.
– Responsibilities: schema migrations, message/event persistence, retry/sync cleanup.
E. Core Library
– drop-core central types (status, event definitions) used by all other crates.
F. Configuration & Analytics
– drop-config loads YAML/ENV parameters.
– drop-analytics instrumentation shims embedded in transfer/auth.
G. Binding Generation
– uniffi-bindgen + contrib scripts generate language bindings (Swift, Python).
– Produces multi-language library wrappers for embedding in mobile/desktop apps.
H. External Services
– PostgreSQL database (for drop-storage).
– Moose tracker (peer discovery over meshnet).
Architectural Patterns & Design Principles
• Module decomposition: Each crate encapsulates a clear responsibility (Single Responsibility Principle).
• Layered architecture:
– Presentation (CLI/test harness)
– Application (transfer, auth, analytics)
– Domain (core)
– Infrastructure (storage/DB, config)
• Asynchronous event-driven flows in drop-transfer: use tasks/manager to orchestrate transfers.
• Protocol isolation: Network protocols (v6, WS) abstracted under protocol/ submodule.