3 releases (breaking)

0.3.0 Aug 30, 2024
0.2.0 Dec 31, 2022
0.1.0 Nov 14, 2021

#6 in #daemon-process


Used in cnspr

GPL-3.0-or-later

265KB
9K SLoC

CNSPRCY (alpha)

CNSPRCY is a daemon process that connects your personal computing devices (i.e. desktop, laptop & phone but not wearables). By constantly attempting to establish and then maintain connections between the devices, it can act as a central source of information for applications and scripts that need to exchange data between your devices. Additionally, if a dedicated connection isn't required, messages can simply be sent in-protocol, invoking scripts (called "event handlers") on the receiving device.

The same daemon process runs on each device, operating a fully decentralized mesh network, using gossip-style event propagation to reduce and equally share the load across devices. It knows the status of all peers (i.e. whether they are reachable) at all times, and it exposes this information, including the IP addresses and latencies when available, over a UNIX socket. This socket can either be queried directly using JSON, or via the provided CLI application.

Because not all applications & scripts need to open a dedicated connection, CNSPRCY also makes it trivial to send messages between devices. Messages are part of the protocol and sent over the connections the daemon already maintains - as such they are also encrypted & authenticated using the ChaCha20-Poly1305 cipher suite. On the receiving device, a script is invoked with the message content and originator. To decide which script (obviously it may also be a binary) is invoked, each message contains a user-defined tag, which maps onto the directory structure and filenames in the handler directory. For more information, see event_handlers.md.

CNSPRCY only targets (recent) distributions of Linux. It is written entirely in (async) Rust, using the Tokio runtime. Its central inspiration is the serf "service orchestration and management tool", and it tries to bring it from its data-center / server context to that of personal computers.

Current State

This Rust crate provides the cnsprcy library, which the is used to implement the cnspr binary (also in this repository, under the cnspr branch). This binary which resembles the serf binary, acting as both the daemon process (./cnspr serve) and the client querying it (see ./cnspr help).
Furthermore, it can automatically monitor changes to the available network interfaces using the netlink protocol and maintains a persistent, eventually-consistent distributed datastore, which exposes a simple key-value interface. At this point, CNSPRCY is alpha-quality software and, while the underlying protocol and architecture of the daemon is reasonably well fleshed out, several important features are missing.

Among these is a mechanism for devices to discover each other in the same local network. This will be modeled (somewhat) after the way it is done in Syncthing, mainly using IP multicast (though likely mDNS Service Discovery) and perhaps eventually using a global "rendezvous" server.

More importantly, there are serious concerns about the security of the protocol as it stands (being based on on symmetric encryption with one key shared between all nodes).

Funding

This project was awarded a grant through the NGI Assure Fund, a fund established by NLnet with financial support from the European Commission's Next Generation Internet programme, under the aegis of DG Communications Networks, Content and Technology under grant agreement No 957073.

Dependencies

~41–55MB
~1M SLoC