Commit Graph

2584 Commits

Author SHA1 Message Date
Matthias Beyer b0af48aa03 To not allocate in good case
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-08-19 10:57:37 +01:00
Lorenz Leutgeb 0200e84aea bootstrap: Add IPv6, IPv4, Onion addresses
This should allow bootstrapping when DNS is not available or a
connection via Tor is desired.
2025-08-18 17:39:20 +02:00
Matthias Beyer 6a1b13bb66 cli: Use human-panic
Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-08-17 20:53:53 +02:00
Matthias Beyer f6f3be437b cli/issue: Optimize how the issues are collected
This patch optimizes how the issues are collected.
Before, the issues where pushed to a new instance of `Vec`, which was
not preallocated to the size of the iterator.
This could be slow when a large number of issues is returned by the
iterator.

With the `Iterator::collect` function, the `FromIterator` implementation
of `Vec` is used, which makes use of `Iterator::size_hint` for
optimizing how much space is preallocated when collecting into the
`Vec`.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-08-17 20:22:56 +02:00
Matthias Beyer b49ff9e5af radicle: Implement Iterator::size_hint() for optimizations
This patch adds an implementation of the Iterator::size_hint() trait
function so that the compiler can optimize allocations on the collecting
side of the iterator better.

From the trait function docs:

> size_hint() is primarily intended to be used for optimizations such
> as reserving space for the elements of the iterator, but must not be
> trusted to e.g., omit bounds checks in unsafe code. An incorrect
> implementation of size_hint() should not lead to memory safety
> violations.

Source: https://doc.rust-lang.org/stable/std/iter/trait.Iterator.html#method.size_hint

And:

> Vec may use any or none of the following strategies, depending on the
> supplied iterator:
>
>  *  preallocate based on Iterator::size_hint() and panic if the number
>     of items is outside the provided lower/upper bounds

Source: https://doc.rust-lang.org/stable/std/iter/trait.FromIterator.html

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-08-17 20:22:56 +02:00
Matthias Beyer 1e66c57643 refactor: Replace return Err(anyhow!()) with anyhow::bail!()
This is equivalent to before, but reduces cognitive load when browsing
the source.

Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
2025-08-17 20:17:11 +02:00
Fintan Halpenny 01bed73a60 cli: fix error formatting
Missed using `format!` to actually emit the error when the sync fails.
2025-08-15 11:40:25 +01:00
Lorenz Leutgeb ed5b2659c8 cli: Gracefully handle failure to link log file
Not linking `node.log` is not ideal, but also not a critical failure.
It's better to swallow that instead of crashing.
2025-08-15 10:13:51 +01:00
Lorenz Leutgeb de78cf7874 cli: Add verbose printing of authors
To allow users to see the full DID of authors of issues, introduce a
boolean to the `Author` struct and wire it through.

While doing that, also remove `--debug` options from `rad issue` and
`rad patch` as they have been obsolete since the introduction of `rad
cob [log|show]` for quite some time.

See:
 - https://radicle.zulipchat.com/#narrow/channel/369873-support/topic/help.20with.20seeing.20full.20nid/with/531390047
2025-08-14 16:15:19 +01:00
Lorenz Leutgeb c8b6a13d64 cli/sync/status: Refactor output table
A new table style that is more narrow, and follows the recent change
to `rad node status`.
2025-08-13 13:45:22 +01:00
Lorenz Leutgeb c089727e90 term, cli, remote-helper: Status Symbols
Symbols signaling status of a process and similar are duplicated in
three different crates. Also two different symbols to signal success are
used:

  1. ✓ (      Check Mark, U+2713)
  2. ✔ (Heavy Check Mark, U+2714)

Work against that by referring to `radicle-term` from the other crates.
2025-08-13 13:45:21 +01:00
Lorenz Leutgeb 1cd3ad0784 node: Remove useless caching of node announcement
When initializing the `radicle-node` process, see
`radicle-node/src/runtime.rs`, an attempt is made to read from a node
announcement file.

This file is never written, therefore all of these reads fail.

Even though this caching mechanism might make sense or might have made
sense at some point, it is dead code now, and therefore removed.

Also, the fact that the file name was defined in the `radicle` crate is
ugly.
2025-08-13 10:27:00 +01:00
Fintan Halpenny efa7efacc4 radicle: Announcer test set constructions
Ensures that preferred seeds that are not synced are made part of the `to_sync`
set, and the Announcer is constructed without an error.

As well as this, ensure that the `synced` and `to_sync` sets do not overlap by
constructing the `to_sync` and removing any `synced` elements from it.
2025-08-13 11:09:49 +02:00
Fintan Halpenny c15288a690 radicle: note about Announcer::can_continue
Making a note of that `Announcer::can_continue` might never be able to hit the
`Break` case. It could be defensive programming, so I'm going to leave it in for
the time being.
2025-08-13 11:09:49 +02:00
Fintan Halpenny 1b33229dd2 radicle: test Announcer::timed_out on success
Ensure that if the Announcer has reached a success case, that if
`Announcer::timed_out` is called, it will still return the success.
2025-08-13 11:09:49 +02:00
Fintan Halpenny 11156619b3 radicle: Announcer test repeated sync
The Announcer should ensure that repeated syncs maintain the sync and unsynced
sets correctly.

The second sync will update the `Duration` of the sync.
2025-08-13 11:09:49 +02:00
Fintan Halpenny ce2d3eb071 radicle: Announcer test synced with unknown node
Adds a test case to show that the Announcer is allowed to mark an "unknown" node
as synced.

There may be a case where gossip reached a node that the current node was not
aware of. This should be allowed and should count towards the final replication
factor.
2025-08-13 11:09:49 +02:00
Fintan Halpenny ca7231e652 radicle: Announcer test adapting the replication target
The replication target should be constrained to the number of nodes to sync
with, if the original value exceeds that number.
2025-08-13 11:09:49 +02:00
Fintan Halpenny 685c84e598 radicle: Announcer with replication factor of 0
Ensures that the Announcer will still announce to preferred seeds when the
replication factor is 0.
2025-08-13 11:09:49 +02:00
Fintan Halpenny 4307eb35b5 radicle: Announcer test AlreadySynced for preferred seeds 2025-08-13 11:09:49 +02:00
Fintan Halpenny 376a5566c2 radicle: Announcer test preferred seeds only 2025-08-13 11:09:49 +02:00
Fintan Halpenny 84f11f5e31 radicle: Announcer ensures local node is ignored
Adds test cases to ensure that the local node is ignored from the announcement
process.
2025-08-13 11:09:49 +02:00
Fintan Halpenny 8a6e55502c radicle: Announcer can exit on preferred seeds or replication factor
The `Announcer` logic was subtly different to the fetching logic, where the
preferred seeds need to be announced to *and* the replication factor had to be
reached.

This patch relaxes that constraint, and allows it to hit either targets before
exiting.

This also surfaced an issue with the with the `Progress` calculation, where
calculating the `unsynced` used the `synced` value to subtract. However, this
was not required because `to_sync` is mutated, so the value is simply
`to_sync.len()`. A test case was added to ensure this is correct by checking
that invariant that the total between synced and unsynced nodes always matches
the total of synced and unsynced progress.
2025-08-13 11:09:49 +02:00
Fintan Halpenny d147094812 fix: upgrade radicle-crypto
The upgrade of the `radicle-crypto` crate was missed when upgrading
semver versions.

Unfortunately, since it is at the base of the dependency tree, all
crates that depend on it require an additional upgrade.
2025-08-13 09:20:42 +01:00
Fintan Halpenny 0e48723b41 release: prepare crates
The `radicle` crate required a bump `0.16.1 -> 0.17`.

Due to this, all its dependents are also bumped
- `radicle-cli`: `0.14.0` -> `0.15.0`
- `radicle-fetch`: `0.12.0` -> `0.13.0`
- `radicle-node`: `0.12.0` -> `0.13.0`
- `radicle-remote-helper`: `0.11.0` -> `0.12.0`
- `radicle-schemars`: `0.1.0` -> `0.2.0`

The following also required upgrading:
- `radicle-ssh`: `0.9.0` -> `0.10.0`
- `radicle-systemd`: `0.9.0` -> `0.10.0`
- `radicle-term`: `0.13.0` -> `0.14.0`
2025-08-12 12:13:49 +02:00
Fintan Halpenny 70009f7af2 release: 1.3.0 CHANGELOG 2025-08-12 12:13:49 +02:00
Lorenz Leutgeb 944d394247 node: Restrict use of systemd to Linux not Unix
Building with Zigbuild for macOS caused build issues. Strengthen the
condition for using systemd from the Unix family to Linux specifically.
2025-08-12 12:13:49 +02:00
Fintan Halpenny 11d29b280a nix: Update nix packages to 25.05 2025-08-12 08:38:57 +01:00
Fintan Halpenny a8dac56ca6 node: add radicle-protocol to dev-dependencies
If one attempted to compile the test target for `radicle-node` by itself, it
would result in a compiler error – due to missing trait implementations that are
provided by `radicle-protocol/test`.

It would compile fine when `--all` is used due to cargo unifying feature sets,
so it went unnoticed until now.

This fixes the issue by adding `radicle-protocol` to the `dev-dependencies` and
enabling the `test` feature flag.
2025-08-07 09:36:20 +01:00
Lorenz Leutgeb d7b48b9e29 radicle: Move logging setup calls to binaries 2025-08-07 08:30:59 +01:00
Lorenz Leutgeb b2a41025ce node: Enable logging via systemd journal 2025-08-07 08:30:59 +01:00
Lorenz Leutgeb c7f3c47f9a systemd: Add module for logging to the journal 2025-08-07 08:30:59 +01:00
Lorenz Leutgeb 2776e003dc systemd: Move socket activation to module 2025-08-07 08:30:59 +01:00
Fintan Halpenny 7a9d4512f9 radicle: fix Canonical::quorum doc link 2025-08-05 15:00:26 +01:00
Lorenz Leutgeb 5d467418be term: Revert using inquire to spawn editor
This is morally a revert of 70fb0d3fef
while additionally getting to compile
`crates/radicle-term/src/editor.rs` on Windows.

To get the changes that were made on top of the revert, check

  git diff 70fb0d3fef~1 <this commit> -- crates/radicle-term/src/editor.rs

There were reports of the inquire editor being unrealiable.
2025-08-05 15:09:43 +02:00
Lorenz Leutgeb 4934473b86 cli/node: Improve log rotation
Only the latest log was kept as `node.log.old`. Now, log files are
numbered (`node.log.1`, `node.log.2` and so on). Also `node.log` is now
a hard link to the current log file. `rad node stop` will delete
`node.log` (note that `node.log.x` stays intact) and `rad node start`
will delete `node.log` before it creates `node.log.y` in case the node
crashed.

Also, when running in foreground mode, now a log file is created. It
just contains the hint that the node was started in foreground mode,
just to avoid confusion.

The implementation is split into a sans I/O part as `struct LogRotator`,
while the I/O counterpart is captured by `struct LogRotatorFileSystem`.
2025-08-04 17:13:11 +02:00
Lorenz Leutgeb 3d352f23e6 canonical: Support Annotated Tags
The logic for computing canonical references conflated the semantics of
annotated and lighweight tags, yielding confusing/wrong results. The
main culprit was the call to `peel_to_commit` in
`impl ReadRepository for Repository`, peeling tag objects away.

To resolve this, we separate out quroum computation per object type: one
implementation for commits, and one for tags.

Also move  move canonical error types and methods into their own
module to have a cleaner file structure for the main logic.

Capture the `BTreeMap<Oid, u8>` type into a `Votes` struct, with its own API.

We were getting the objects from the repository twice – once in `Canonical::new`
and once again in `ensure_commit_or_tag` – so the latter was removed.

Use an `enum CanonicalObject` to specify which object types the canonical
process supports.

During `converges`, separate commits and tags, and ensure that we are only
looking at objects of one type. Note, that Fintan think this is actually the
*wrong* place to do it because we already filter the objects – so we should
keep track of that information higher up the callstack.

Co-authored-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2025-08-04 17:00:54 +02:00
Erik Kundt 54fd8c40a0 node: clean up logging
Do not print errors to stderr anymore if logger is not enabled
2025-07-30 13:41:17 +01:00
Fintan Halpenny 174792813a node: register backtrace
To better help debugging when things go wrong after `radicle-node` crashes,
`RUST_BACKTRACE` is registered in the `main`. According to this [StackOverflow
answer][so], this should not affect performance

[so]: https://stackoverflow.com/questions/29421727/how-much-overhead-does-rust-backtrace-1-have/45402131#45402131
2025-07-30 13:41:17 +01:00
Fintan Halpenny 0aaa81f82a cli: mention binary names as part of unknown
When we fail to get the info for the binary names of `radicle-node` and
`git-remote-rad`, we still mention the binary name which is usually a part of
their output.
2025-07-28 11:38:24 +01:00
Lorenz Leutgeb fdb1ac4e3a radicle: Fix clippy::result_large_err
After upgrading from Rust 1.85 to 1.88 in 586eefc, clippy started
warning about large error types. Box action to make
`radicle::cob::patch::Error` lighter.
2025-07-27 23:32:39 +02:00
Lorenz Leutgeb 5bab3f9cc0 clippy: Allow doc_overindented_list_items
After upgrading from Rust 1.85 to 1.88 in 586eefc3e4,
clippy now warns about "overindented" lines in comments. I did not
manage to fix this by hand without breaking the second level of the
lists in question.

See
 - https://rust-lang.github.io/rust-clippy/master/index.html#doc_overindented_list_items
 - https://github.com/rust-lang/rust-clippy/issues/14275
2025-07-27 23:32:02 +02:00
Lorenz Leutgeb 9068033789 chore: Automated fixes generated by clippy 2025-07-25 11:25:05 +02:00
Lorenz Leutgeb 586eefc3e4 rust-toolchain: 1.85 → 1.88 2025-07-24 17:43:12 +02:00
Sebastian Martinez efeefd0daa chore(debian/changelog): update package version to match upstream 2025-07-23 11:34:20 +02:00
Fintan Halpenny 2a47bc0c7d term: provide default HELP message
Provide a default message that informs the user of the `(e)`, `(enter)`, and
`(esc)` functionality.

Unfortunately, it is not possible to provide any message that is better
customised to each case, due to `inquire` requiring a `'a` lifetime on all its
inputs – this rules out providing any kind of `String` input.

The first paramter of `Editor::new` can already be used to provide more
contextual information. The second parameter is left configurable, but for now
`Editor::HELP` is used everywhere.
2025-07-23 10:31:15 +02:00
Fintan Halpenny a998ce691d ssh: provide path on connect error
Provide the path that is being used for connecting to the SSH agent, when an I/O
error occurs.
2025-07-23 10:31:15 +02:00
Lorenz Leutgeb 8224819fed radicle/profile: Enable home detection on Windows
To avoid that users on Windows have to explcitly set `HOME`, also accept
`USERPROFILE` which is considered equivalent.

To avoid repeating to join `.radicle`, split the logic up into two
phases. Also take care to provide a good error message, as this error is
fatal and user-facing.
2025-07-23 10:31:15 +02:00
Lorenz Leutgeb 1e0a14ddcf ssh: Remove dependency on log 2025-07-23 10:31:15 +02:00
Lorenz Leutgeb 8e6279a382 ssh: Remove dependency on byteorder 2025-07-23 10:31:15 +02:00