Commit Graph

390 Commits

Author SHA1 Message Date
cloudhead d973fd42f2
cli: Auto-connect on sync
This adds functionality so that on `rad sync` and `rad clone`, we
connect to known seeds if necessary, before attempting to fetch.

In passing, some related changes were made:

* The `rad sync` command's arguments were reworked:
  `--replicas <count>` can be used to specify a replica count when
    fetching
* The `rad patch` command no longer has a `--fetch` option
* It's now possible to tell the node not to automatically connect to
  peers in the background
* `AddressBook` is being used underneath `Seeds` to allow for shuffled
  iteration
2023-08-11 11:45:27 +02:00
cloudhead efb8de2728
Rename our custom `HashMap` to `RandomMap`
This makes it easier to distinguish with the stdlib.

Also, we add an env var that can control the RNG seed, for testing
purposes.
2023-08-10 16:51:02 +02:00
cloudhead 593f576ab4
node: Fix flaky limitter test
Ensures the addresses are different.
2023-08-09 17:07:21 +02:00
cloudhead fae518bca2
node: Improve `rad node connect` feedback
Only return once the connection is established or failed.

It's still not perfect, as several failure scenarios are not handled,
but it's an improvement.
2023-08-09 12:49:15 +02:00
cloudhead fb4a4e0079
node: Implement token-bucket rate limitter
Limit gossip messages and inbound connections.
For now, we don't limit git fetches.
2023-08-09 12:41:21 +02:00
cloudhead 260b1a428c
node: Move `address` field out of `State`
We move the session address to the top-level struct, since it's needed
in a bunch of places. This change is required for the rate-limiting
code that is coming next.
2023-08-09 12:41:21 +02:00
cloudhead 66799e2211
node: Improve address selection
Improve the logic when choosing addresses to connect to. Previously we
would wait much too long, even for good addresses. This was especially a
problem when the reason for disconnection was simply a node restart.
2023-08-09 12:39:33 +02:00
cloudhead 508cf4f68c
node: Connect to peers on startup
We run `maintain_connections` on initialization so that we're
immediately connected to some peers from our address book.
2023-08-09 12:39:33 +02:00
cloudhead 27865a26b2
node: Improve `maintain_connections` function
Ensure we don't try to connect to two addresses of the same node.
2023-08-09 12:39:33 +02:00
cloudhead dc7d67c1e2
node: Ignore non-routable addresses
We ignore addresses that are not globally routable when receiving them
in node announcement message, unless they are coming from a local peer.
2023-08-09 12:39:33 +02:00
cloudhead e888398519
node: Populate address book with bootstrap nodes
As a starting point, we populate the address book (if empty) with some
bootstrap nodes which are trusted.

To prevent these nodes being connected to during tests (including e2e
tests), we create a new constructor for `Config` that is used in tests.

Note that a `cfg(test)` check is not enough given that e2e tests don't
have that set.
2023-08-09 12:39:33 +02:00
Slack Coder df5c8c7d4f
docker: Make Dockerfile easier to read
Avoid long lines by separating commands and arguments with '\'.
2023-08-03 13:43:20 +02:00
Alexis Sellier 8a3133e137
node: Include addresses in `Command::Seeds` result
This will allow the CLI to connect to seeds on the go.

We also do some refactoring of some of the code involved in fulfilling
the `Seeds` command.
2023-08-01 15:48:44 +02:00
Alexis Sellier 693f0a2c44
node: Some small UX fixes
Fixes an error which said "invalid argument" the first time the node was
started.
2023-08-01 14:55:20 +02:00
Alexis Sellier 62aaec5f53
node: Delay logging until after version print
Previously we would show some logs before printing the version.
This fixes it.
2023-08-01 14:55:20 +02:00
Alexis Sellier 85b092872d
node: Support DNS address types at the wire level 2023-08-01 14:55:20 +02:00
Alexis Sellier 70e199dd09
node: Fix CLI help message
It was not accurate.
2023-08-01 14:55:20 +02:00
Alexis Sellier 41bff1b3bb
node: Make user connections persistent
While the node is running, connections made via the `Connect` command
should be retried.
2023-07-26 12:52:11 +02:00
Alexis Sellier 840fc496b8
node: Simplify control socket command parsing
Instead of using a command name plus arguments, we use a new `Command`
enum that is similar to the one in `radicle_node::service`. This way,
we're able to have more complex commands and parsing is simplified.
2023-07-26 12:35:55 +02:00
Alexis Sellier f639192dc6
cob: Remove CRDTs from COB state
It turns out that the CRDT formed by the union of Git DAGs
is enough to guarantee everything we need for COBs.

This changes the following things:
* COB operations no longer need to be commutative
* COB histories are traversed in the same deterministic order on all
  replicas
* It's now possible to implement RSMs on top of COBs, eg. scripting
* Lamport clocks have been removed
* `radicle-crdt` is no longer a dependency of `radicle`
* COBs are no longer instances of `Semilattice`
* The `Ops` type was removed in favor of having `Op` contain multiple
  actions
2023-07-25 15:29:27 +02:00
Vincenzo Palazzo a41f67d9ef
radicle: Import the new SQLite library with bundled binary
This commit addresses a workaround previously implemented to
include the SQLite library bundled inside the binary.

The upstream have successfully merged the patch that implements this
solution [1], allowing us to safely incorporate it
into our codebase.

[1] Link to the merged patch: https://github.com/stainless-steel/sqlite/pull/71/files

Fixes: 431a389944
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-07-25 12:30:03 +02:00
xphoniex 4869fe26e2
Add `-h` flag to binaries
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
2023-07-25 11:58:39 +02:00
Alexis Sellier 3119294367
Add `--version` flag to binaries
Help users confirm all their radicle binary versions by providing the
'--version' flag.

Move the print_version function to the radicle crate for use by the node
and remote-rad binaries, and remove tests to confirm the output format
as it is deemed redundant.

Co-Developed-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-07-25 11:36:50 +02:00
Alexis Sellier f92308cf25
cli: Make key encryption optional
By leaving the passphrase prompt blank, users can create unencrypted
keys.
2023-07-20 10:40:15 +02:00
Alexis Sellier 16a01a42bf
node: Delegate passphrase prompt to CLI
Instead of asking for the passphrase in `radicle-node`, we expect the
`RAD_PASSPHRASE` env var to be set.

This keeps `radicle-node` simpler and lower level, while the passphrase
prompt is still available via `rad node start`.
2023-07-15 12:44:14 +02:00
Alexis Sellier 4634913b66
radicle: Split out `SignRepository` trait
This new trait is used when only signing refs is needed, and not general
write access to a repository.

We also implement `ReadRepository` and `SignRepository` for
`DraftStore`.
2023-07-14 16:58:23 +02:00
Alexis Sellier 45ccbde226
Update `radicle-surf` and `git-ref-format` 2023-07-14 16:57:55 +02:00
Fintan Halpenny dfa7ba1df5
radicle: type safe tracking config
The tracking database can be opened in read-only or read-write
mode. Knowing which is being used is significant in concurrent
scenarios, e.g. it's safer to have a read-only handle on multiple
threads.

Provide static type information by signifying what kind of database
handle is being worked with, read or read-write.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-07-14 16:52:42 +02:00
Alexis Sellier 6b6f087c14
Use transaction to insert inventories
Instead of inserting inventory entries one by one, we use a transaction,
which is much faster.
2023-07-14 15:46:46 +02:00
Alexis Sellier eb701be033
node: Make node aliases required
This is a fairly substantial change, which adds a new configuration file
to the user's `$RAD_HOME` that includes node configuration, including
the alias, and also makes node aliases required.

When running `rad auth`, the user is now prompted for an alias, which
defaults to `$USER`.

When running `rad self`, the alias is now shown.

If the user runs radicle without a config file, the defaults are loaded,
and `$USER` is used as the alias.
2023-07-11 18:08:59 +02:00
xphoniex 37847d4c63
cli: Use `.aliases()` store for patches
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
2023-07-10 16:36:15 +02:00
xphoniex ff81b1a6ed
node: Use `str::trim_end_matches` for stripping '\0' in alias
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
2023-07-10 16:36:15 +02:00
Alexis Sellier 1a1e63d998
node: Implement `sessions` command
Returns session information through the control socket.

We also update `rad node status` to display sessions.
2023-07-04 00:26:31 +02:00
Alexis Sellier 0f3212a1b2
cli: `rad self` improvements
* Add `--home` flag
* Organize the information better

Now looks like this:

    DID             did🔑z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
    └╴Node ID (NID) z6MknSLrJoTcukLrE435hVNQT4JUhbvWLX4kUzqkEStBU8Vi
    SSH             running (823)
    ├╴Key (hash)    SHA256:UIedaL6Cxm6OUErh9GQUzzglSk7VpQlVTI1TAFB/HWA
    └╴Key (full)    ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIHahWSBEpuT1ESZbynOmBNkLBSnR32Ar4woZqSV2YNH1
    Home            [..]
    ├╴Storage       [..]/storage
    ├╴Keys          [..]/keys
    └╴Node          [..]/node
2023-06-30 14:41:00 +02:00
Alexis Sellier e32e28f8b4
cli: Implement `rad node stop` 2023-06-29 17:58:07 +02:00
Alexis Sellier e33661738c
Move unit files to `systemd` directory 2023-06-22 12:13:30 +02:00
Alexis Sellier 33870572d4
Improve unit files, add binary install to README
After going through the process of getting this working using the unit
files, I found a few issues that are fixed here.
2023-06-22 12:13:30 +02:00
Alexis Sellier bb099faa4f
node: Give useful thread names
For the purposes of debugging running nodes, it's useful to know which
threads are doing what. This allows tools like `htop` to reveal which
threads are running.
2023-06-20 11:18:14 +02:00
Alexis Sellier 765823c686
node: Add timeouts to daemon connection 2023-06-16 09:42:34 +02:00
Alexis Sellier e9ef0f4aa4
cli: Consolidate working copy remote setup
We consolidate the setup done by `rad checkout`, `rad clone` and `rad
remote add`, so that they all check for node aliases, and are all
capable of setting up tracking branches etc.
2023-06-13 11:09:42 +02:00
Alexis Sellier 5502676aa7
Fixes and improvements to alias handling
* Return the correct alias from a node announcement, stripping '\0'
  bytes.
* Accept `AliasStore` types as references and as owned.
* Store a `null` in the database if the alias received is empty.
2023-06-13 11:09:42 +02:00
Alexis Sellier a3f8305eb4
node: Reduce test flakiness
Most of the test flakiness was caused by the git-daemon not being able
to bind to a port. It seems like using an RNG was not a good enough
solution.

After this change, tests seem to be passing without issue.
2023-06-08 16:44:04 +02:00
Vincenzo Palazzo 431a389944
radicle: Use "bundled" sqlite dependency
Our build was faking the inclusion of SQLite and dynamically
linking it in the 'radicle' crate and other components.

This patch solves the following error and requires reinstallation
of the `radicle-cli`, `radicle-node`, and, if used, the `radicle-httpd`

```
✗ Sync failed: internal error: malformed database schema (node-policies) - near "strict": syntax error (code 11): malformed database schema (node-policies) - near "strict": syntax error (code 11)
```

Tested-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
2023-06-08 15:08:22 +02:00
Alexis Sellier 91404e4c37
node: Fix regression on control socket delete
The removal of the control socket on shutdown was mistakenly taken out.
We add it back here.
2023-06-07 11:39:23 +02:00
Alexis Sellier ff7338de17
node: Always send node announcement on handshake
Previously, we only sent the announcement when there were external
addresses. But it contains other information like the node alias,
therefore we always send it.

Since the proof-of-work can be expensive to compute everytime, we add
the ability to load the local node announcement from the file system.

We also change the proof-of-work parameters so that they are relaxed
when running in debug mode, instead of when running tests.

Finally, we remove the boolean validation of the PoW. Instead, we store
the work per-node, in the database, to be used in the future in case of
DoS attacks or network congestion.
2023-06-07 11:39:23 +02:00
xphoniex f526465f1b
radicle: Make addresses.db accessible from profile
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
2023-06-02 14:49:20 +02:00
Alexis Sellier 4652f309b4
Update to Rust 1.70 2023-06-02 14:40:44 +02:00
Alexis Sellier c400961cec
Update `io-reactor` and related dependencies 2023-05-27 20:43:56 +02:00
Alexis Sellier 664aa570e6
node: Spawn a thread for each control connection
Previously, only one connection to the node control socket could be
handled at a time. This usually worked fine, but if one connection hangs
for whatever reason, no other process can access the node.
2023-05-24 11:33:55 +02:00
Alexis Sellier b8c2f2a647
node: Rename `InvalidPacketLine` error variant
In case of timeout on reading the packet-line, we would get this error.
It would be confusing, as the packet-line wasn't invalid, just never
received.
2023-05-24 11:33:55 +02:00