Commit Graph

1446 Commits

Author SHA1 Message Date
cloudhead 0ae3c00cd7
Use cascading deletes for removal of node rows
Instead of manually removing all rows in the address table, use
cascading deletes.
2023-11-13 16:01:18 +01:00
cloudhead 3cad39a3a9
node: Fix timestamp bug
We were using seconds when it's supposed to be milliseconds. Oops.
We should probably switch this type to `LocalTime` at some point.
2023-11-13 15:57:03 +01:00
cloudhead 269d21deca
node: Rewrite `seeds` method to use sync-status
We update the `seeds` method to use not only the routing table, but also
the sync status information for our owned refs.
2023-11-13 12:06:37 +01:00
cloudhead 9f45405c64
Add table and types for tracking sync status
We add the necessary database table to keep track of which node has
synced which of our repos. This will be useful for giving the user
information on the sync status of every local repository.
2023-11-13 12:03:24 +01:00
cloudhead 3aad82d158
node: Fix various small logic issues
* Set peer's `last_active` even if they are being throttled
* Make sure not to break out of loop in wire module
* Add some more logging
* Use different variable for session filtering to make it clearer
2023-11-13 11:54:40 +01:00
cloudhead 2903b4f09a
node: Don't connect to all peer's addresses
Instead of connecting to the first address of a peer, we attempted to
connect to all addresses, which caused problems.
2023-11-13 11:54:40 +01:00
cloudhead b675185538
node: Improve control socket API
We improve the API so that error messages can be sent back and are
always expected as potential responses to commands. This means that
`CommandResult` is always the type that is sent for commands.

This includes some breaking changes, for example the default "success"
message is simply `{}` instead of `{"status":"ok"}`.
2023-11-13 11:02:45 +01:00
cloudhead d88cce484a
radicle: Simplify canonical head quorum
Instead of trying to handle cases where delegate branches diverge, we
simply throw an error in those cases, which prevents the canonical head
from updating.

This simplifies the code a lot, and forces the user to take action when
such an event occures.
2023-11-10 13:42:16 +01:00
Fintan Halpenny cf08a3f731
node: run git gc on fetch
It is desirable to keep the Git repositories in Radicle efficient by
ensuring objects are packed and unreachable objects are removed.

Add a process call to `git gc` to achieve this. Two flags are used for
garbage collection: `--auto` and `--prune`. Their details are outlined below:

       --auto
           With this option, git gc checks whether any housekeeping is
           required; if not, it exits without performing any work.

       --prune=<date>
           Prune loose objects older than date (default is 2 weeks
           ago, overridable by the config variable
           gc.pruneExpire). --prune=now prunes loose objects
           regardless of their age and increases the risk of
           corruption if another process is writing to the repository
           concurrently; see "NOTES" below. --prune is on by default.

For `--prune` the default used is `1.hours.ago`. This was chosen over
`now` since that may be too aggressive after just fetching new data.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-10 11:44:25 +01:00
Fintan Halpenny dd16356e4e
node: fetch refs announcements
Ref announcements contain the namespace (NID) and the SHA of the new
`rad/sigrefs`. This information can be used by the fetch protocol to
fetch only those `Oid`s for those namespaces.

Add a new stage `SigrefsAnnouncement` that captures this behaviour by
only asking for the advertised `Oid`s and updating the corresponding
`rad/sigrefs` for each namespace. Note that this is a special case of
the `SpecialRefs` stage and so the protocol chooses between these two
by checking if there was announcement passed through. The following
stage, `DataRefs`, stays the same.

Note that this stage can only be activated via a `pull`, and `clone`
stays the same.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 17:47:10 +01:00
Fintan Halpenny d27cd0db0c
node: minimise refs announcement to key and Oid
The RefsAnnouncement previous announced its complete set of
`rad/sigrefs`. This was useful in that verification can occur on the
receiveing side immediately by verifying the refs and proceeding with
the fetch -- note that it did nothing with the ref information it
received.

This can be minimised to only advertising the namespace, i.e. the
NID, and the new SHA of the `rad/sigrefs`. This is represented by a
new message type, `RefsAt`, which contains the NID and the Oid.

For checking if an announcement is stale or fresh, the receiving
side can check the existence of the SHA in its Git repository.

The tests are appropriately modified to use NIDs and Oids.

To prepare for a follow-up change, the announcement data is also
threaded through for the fetch protocol to focus fetching only the
advertised set of Oids.

N.B.: because the refs aren't communicated, the verification happens
when fetching since the data needs to be fetched before
verifying. This is a trade-off with minimising the message payload for
verifying earlier.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 17:47:09 +01:00
Fintan Halpenny 61b06553b4
radicle: use git::raw::Error for reference_oid
The minimal error for the `ReadRepository::reference_oid` method is
`git::raw::Error`.

Change the error type from `git::ext::Error` to `git::raw::Error`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 17:47:07 +01:00
Fintan Halpenny 92f21d7f29
node: add conversion for BoundedVec to Vec
While there is a method, `unbound`, for converting a `BoundedVec` to
its inner `Vec`, it is common practice to implement the `From` trait.

Add the `From` conversion for `BoundedVec` and `Vec`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 17:47:05 +01:00
Fintan Halpenny 559f84d9f1
fetch: inpsect for Cache
Add debugging code for inspecting the in-memory Refdb of the Cache.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 17:47:03 +01:00
Fintan Halpenny 0640ea59ec
node: use tempdir for clone
When performing a clone there are two potential issues.

The existing issue is that when a repository is created to clone into,
it does not contain any data initially. This leaves other node
operations thinking that a repository does exist but when they try to
perform operations on it, those will fail. These will be surfaced as
warnings but the node will continue to operate.

The other issue, while writing fetch v2, is that if a clone fails,
then cleanup needs to be performed -- to remove the empty repository
from storage.

To tackle both these issues, a temporary directory is used in the
place of the repository. If a clone fails then the temporary directory
is dropped and nothing needs to be done. If the clone succeeds then it
can be safely moved to the storage.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 16:46:51 +01:00
Fintan Halpenny c22bf8475a
httpd: return the error message not found errors
It's difficult to debug errors that mention a resource not being
found, but not which resource was not found.

Return the error message for not found variants.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 16:46:42 +01:00
Fintan Halpenny 82a53e3a53
radicle: UserInfo for Repository::create
The fetch V2 improvements introduced a `UserInfo` type that is used to
set the Git config's name and email when cloning a repository. This
`UserInfo` can also be used when creating a new `Repository`.

The `Storage` type now takes a `UserInfo` so that it can be passed to
`Repository::create`, for creating a new repository.

For testing, this requires adding a new `fixtures::user` so that
testing `Storage` instances can be easily constructed.

It also means that the `radicle-cli` tests all changed with new SHAs
since the name and email are used as part of the hashing input.

N.b. the order of the timelines while testing the identity cob
changed. It's not clear why that is.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 16:43:34 +01:00
Fintan Halpenny 9f81de7ef3
cli: use `WriteStorage::remove` in `rm`
Instead of calling `std::fs::remove_dir_all` in the `rad rm` command,
use the `WriteStorage::remove` method.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-09 16:42:41 +01:00
Fintan Halpenny 703a6d8025
fetch: Ignore sigrefs that are behind
Previously, if a delegate's namespace was fetched and its rad/sigrefs
was behind the current state, then it would fail to perform the fetch.

Instead, when the ancestry path is checked the outcome can be used
during the update:
1. If the tip is equal, then the update can be marked as skipped.
2. If the tip is behind, then the update can be rejected, iff the
   policy does not allow it.
3. If the tip is ahead, then the update is a fast-forward.
4. If the tip is diverged, then the update results in a failure, iff
   the policy does not allow it.

The protocol also prunes any delegates's updates when the `rad/sigrefs`
is behind and returns an error if they are diverged.

For any non-delegates, it will simply prune them.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
2023-11-09 13:12:21 +01:00
cloudhead 9b7c48ab40
cli: Improve `rad diff`
* Properly show the user when a file was moved or copied.
* Don't require a radicle project in the current repo.
2023-11-09 13:04:40 +01:00
cloudhead 947f1bfc01
node: Use variable subscribe backlog delta
Previously, we would always ask nodes for messages from one hour ago.
This meant that we could miss messages if our node was offline for more
than an hour. This change uses a variable backlog by checking the
timestamp of the last gossip message we received.
2023-11-08 15:10:11 +01:00
cloudhead f0754330c9
Update `sqlite` dependency to 0.32.0 2023-11-08 15:08:01 +01:00
cloudhead f9df360171
node: Persist historical gossip messages
Instead of storing received gossip messages in an in-memory `BTreeMap`,
we persist them to the database (`addresses.db`). There are two reasons
for this:

1. Node restarts do not wipe the state, meaning that it is much less
   likely that some gossip message will get lost before reaching all
   nodes.
2. This will allow us in the next commit to know how far behind we are
   after a restart, to be able to request the correct time range of
   gossip messages that we missed while offline.

Note that we now share the addresses.db file between two connections and
stores, which we don't do anywhere else. Having multiple connections to
the same database is fine, but the way we're having to do it is a bit
awkward. In a future patch, we could pull out the database schema from the
`address` module and rename the database to make things clearer.
2023-11-08 13:15:56 +01:00
cloudhead 823a7e7c52
remote-helper: Allow commit roll-backs on push
This makes the divergence check on push slightly more lenient, by
allowing rolling back to a previous commit in the canonical branch
history.

Without this, it can become impossible to roll-back commits in certain
situations.
2023-11-07 15:16:26 +01:00
Sebastian Martinez 193ed2f675
radicle: Add missing embeds in `RevisionComment` 2023-11-06 14:51:33 +01:00
Fintan Halpenny 65118e6ce9
cli: simplify rad-clone-all
With the latest changes to fetching, `--scope all` will now clone all
remotes listed by the serving node.

Simplify by the `rad-clone-all` example by removing the extra fetch
and removing the corresponding TODO.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:07:40 +01:00
Fintan Halpenny d7abc0a8fc
node: remove git-daemon code
The git-daemon code is no longer needed since git-upload-pack is used
in its place.

Remove the git-daemon code from the runtime and worker.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:07:27 +01:00
Fintan Halpenny ea7f26dbdf
radicle: wire up radicle-fetch
Wire up the `radicle-fetch` crate to the fetch logic in the
`radicle-node` worker.

Any required traits for storage, identity, tracking, and transport
used by `radicle-fetch`.

The worker adds a new module to run the `git upload-pack` process and
pipes the `stdout`/`stdin` to the respective channels.

The `Worker` type required adding a `FetchConfig` to easily allow the
configuration of fetches and passing the signer and tracking store
location through to the fetch `Handle`.

The channels code is adapted to have a new writer that always flushes
when a call to `write_all` is made. This is necessary since the
Gitoxide code never calls `flush`, and so it will hang since no data
is sent until `flush` is called.

Since `UserInfo` is used to set up a newly cloned repository, this
changed some of the SHA1 hashes output in the CLI test examples. It
was also necessary to update the CLI's clone code to be deterministic
in its output for tests.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny 981172aa4f
radicle-fetch
The `radicle-fetch` crate introduces a method for fetching from a
server using Git protocol V2, which provides the implementation
control over performing a sequence of fetches and validation over
domain data.

The protocol is built on top of the suite of Gitoxide crates[[0]]. It
builds wrappers on top of Gitoxide's refdb, odb, and transport layers
-- as well as taking the ls-refs and fetch code straight from the code
base to simplify for the needs of this crate.

[0]: https://github.com/Byron/gitoxide

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny 87187d47e5
radicle: add remove to WriteStorage
Add the ability to remove a repository, given its RID.

This is useful in the case of attempting to clone a repository, and if
that process fails -- for example, if the repository is private --
then it's necessary to clean up the initially created repository.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny f1f32d8574
radicle: return verified doc
The `identity_doc_at` and `identity_doc` methods on `ReadRepository`
returned the unverified identity document. Every usage of these
methods would always verify the document after.

Simplify the code by calling verified in the methods and directly return the
verified identity document.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny adf3130431
radicle: add Special type
Add an enum to represent the special references, `rad/id` and
`rad/sigrefs`. These can be used for cases where it's more manageable
to work with the enum type over checking for reference string equality.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny 75b52e28b2
radicle: separate repository validation
Make the validation logic customisable by extracting it out into a
separate trait that can be defined by other crates.

The Repository validation logic stays the same.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny b503aa6be4
radicle: validations
Instead of returning the unsigned references, the validation of a
repository's remotes returns the set of validation errors. The caller
is then expected to handle these validation errors appropriately, for
example, by logging them and re-raising an error.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny dfdf2e20cc
radicle: add UserInfo to git
Add a type to capture user information that can be used for Git
configuration and signatures.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny ef6ae0fa84
radicle: move service tracking config to radicle::node
The `service::tracking` module has nothing specific to the
radicle-node code. This means that it can be moved to radicle under
the `node::tracking` module.

This makes it more resuable in other contexts, for example, for
fetching logic.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny c06b225877
radicle: add sigrefs ref name constructor
Similar to the `id` function, add a `sigrefs` function to construct
the reference name for a given remote's `rad/sigrefs`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
Fintan Halpenny 030419932e
radicle: Add SignedRefsAt type for signed refs
Introduce a SignedRefsAt type that combines a SignedRefs along with the Oid
it was loaded at.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-11-06 12:06:13 +01:00
cloudhead d150938b38
cli: Update tracking without a running node
This change allows users to track/untrack peers and repos without a
running node. This fixes a bug when running `rad init` without the node
running, where the repo would be tracked with a different scope than
what was specified on the CLI.
2023-11-03 17:17:07 +01:00
cloudhead a70664368e
radicle: Move some functions to `Home` type
Certain functions in `Profile` did not need to be in there and could be
moved in the more basic `Home` type.
2023-11-03 17:08:18 +01:00
cloudhead d15534df97
cli: Small clippy fix 2023-11-03 16:31:04 +01:00
cloudhead 84a95848b0
cli: Add pager to `rad diff`
Invokes a pager when the output doesn't fit on the screen.
2023-11-03 14:20:16 +01:00
cloudhead 135725d6f6
dag: Fix topological order
We were using a breadth-first search which doesn't work as-is for
topological ordering in all cases. Instead of using Kahn's algorithm
which is a little complex, we switch to a depth-first search.
2023-11-03 14:17:57 +01:00
Rūdolfs Ošiņš 342b05f88d
httpd: Don't panic when node is not running 2023-11-02 17:00:38 +01:00
cloudhead d8f8d29605
radicle: Fix timestamp issue with feature flag
The `stable-commit-ids` feature flag was being included in non-dev,
non-test builds because of how cargo works (or doesn't work).

For now, we ignore the tests that this affects, and they can be run with
the `RAD_COMMIT_TIME=1514817556` environment.
2023-11-01 17:24:47 +01:00
Michalis Zampetakis 0b6ede69e7
node: Add `listen` option to node config 2023-11-01 12:59:29 +01:00
Lars Wirzenius d67f9ea9bb
Add rudimentary Debian packaging for binaries
This is very much not up to the standards of an official Debian
package. To make a proper package of Radicle will require packaging
all the dependencies first, and the Radicle crates need to be
published to crates.io, among other things. This is just a lazy first
cut to see if there's any interest in a .deb.
2023-11-01 12:56:35 +01:00
Sebastian Martinez 15cf5c6100
httpd: Parse git URIs into `Embed`
Currently we only handle data Uris, but when a user sends a comment that
has a existing git Oid, due to editing a comment we also need to handle
this case.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-10-30 15:41:34 +01:00
Rūdolfs Ošiņš 1811c7b8bb
docs: Fix push option example
Signed-off-by: Rūdolfs Ošiņš <rudolfs@osins.org>
2023-10-30 15:36:46 +01:00
Fintan Halpenny d9be25a477
cli: Use alias fallback in `rad node`
The `AliasStore` mechanism was added but not used in the `rad node`
command. Since the launched node itself can display aliases based on
the address book, it would make sense if the `rad node` command could
do this as well.

Use the `Profile`'s `AliasStore` implementation to fallback to an
alias if the tracking store does not contain an alias -- essentially
using the address book instead.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-10-30 15:34:56 +01:00