How zerotier/zerotierone works
Based on our analysis of the ZeroTier source and README, you are dealing with a highly modular (and cross‑platform) distributed virtual networking system. The repository contains separate directories for the core virtual switch (“node”), the integrated service layer (“service”), a network controller (“controller”), the operating system–dependent integration layer (“osdep”), and even support for Java–based JNI wrappers (in “java”) along with Windows-specific UI (in “windows”) and packaging (in “pkg”). In addition, there is a rich “ext” folder that houses many third–party libraries plus extra components (like Prometheus metrics, rule compilers, and support for multiple architectures). The README makes it clear that ZeroTier implements two major virtual layers: a secure peer-to-peer network layer (VL1) and an Ethernet emulation layer (VL2) with SDN features.
Main Components
• Core Virtual Ethernet Switch (node):
– This is the heart of the data plane; it implements network packet processing, encryption/decryption, tunneling, switching and virtual routing.
– It is designed to be embeddable and platform‐independent (notice the non‑usage of C++11 features to allow embedded builds).
• Network Controller (controller):
– Acts much like an SDN controller managing membership, configuration, and other control functions (e.g., assigning network IDs, controlling access rules).
– It works closely with the service layer and supplies the “control plane” for ZeroTier.
• Service and API Layer (service):
– Wraps the core node and provides interfaces (JSON API) for configuration, joining/leaving networks, and running the node as a daemon.
– Offers administrative access (via CLI, API, and Prometheus metrics endpoints).
• OS Dependent Layer (osdep):
– Contains the libraries and drivers required to interface with native networking (e.g., creating tap devices on Linux, Windows Ethernet tap drivers, macOS helpers).
• External Interfaces and Clients:
– Command-line “zerotier-cli” tool, the Java JNI wrapper (for mobile/Android platforms), and Windows UI components.
– Also include the Prometheus Metrics endpoint and the HTTP / App server for hosting single page apps.
• Packaging/Deployment Components:
– The “pkg” directory (with subfolders for various platforms like Synology, QNAP, Snap, etc.) indicates that installers and deployment scripts are built around the core components.
• The node should be shown communicating with the controller (control messages) so that configuration changes and network membership decisions are exchanged.
• The OS dep layer must be depicted as a supporting “infrastructure adapter” that the node/service uses to create virtual network interfaces and handle OS-specific events.
• External API paths (e.g., the JSON API on port 9993, Prometheus Metrics endpoint) that allow administrators or external clients (CLI, web UI, mobile app) to configure or query the system.
Architectural Patterns and Design Principles
• The architecture is layered: a clear separation between the core virtual switch, the higher-level service control and configuration, and the OS integration.
• There is a micro‑service–like decomposition internally: the control plane (controller) is decoupled from the data plane (node), and deployment is further aided by “ext” and “pkg” support.
• Peer-to-peer communications (VL1) and Ethernet virtualization (VL2) are the underlying design idioms.
• Security is built in (end-to-end encryption, secret keys, access tokens for API/metrics).
• Cross-platform portability and modularity are evident – even a rule compiler written in JavaScript is segregated from the main functionality.
Relevant Technologies and Frameworks
• C/C++ are predominant in the core system.
• For OS integration, platform-specific libraries are used (e.g., Windows driver code, macOS network tap wrappers).
• Prometheus client libraries are embedded to expose metrics.
• The use of JSON for API control and integration (see local.conf configuration and CLI command interactions).
• In addition, packaging builds (CMake, Makefiles, Visual Studio solutions) are used; the “ext” folder shows third–party native libraries for crypto, networking protocols, etc.