Commit Graph

304 Commits

Author SHA1 Message Date
Alexis Sellier 8205f8ad4e
Update `fastrand` dependency to 1.9.0 2023-04-14 13:15:52 +02:00
Alexis Sellier 267aba5901
node: Announce inventory only if it changed
Previously we were announcing inventories all the time, due to
relying on the timestamp changing on insertion.

We change this to only announce our inventory when it actually changes.
2023-04-14 13:15:52 +02:00
Alexis Sellier 7d1e3d489b
cli: Add `patch archive` sub-command 2023-04-10 10:17:37 +02:00
Alexis Sellier 33461e4be1
Set patch status to `merged` automatically
When a merge is applied to a patch, we check whether the threshold
of delegates has been reached, at which point we set the patch status
to `merged`.

This requires threading the identity document oid through the "apply"
process.
2023-04-05 10:32:45 +02:00
Alexis Sellier b6fa4a4b2a
cli: Some improvements to `rad merge` 2023-04-03 16:06:24 +02:00
Alexis Sellier cf37950828
node: Rename control socket
The old name, `radicle.sock` didn't tell us much about the purpose
of this socket.
2023-03-31 17:29:58 +02:00
Slack Coder 0b7f169c8b
cli: Support revision id in `rad merge`
Revision IDs are globally unique.  Users will be able to use the
Revision ID in place of its patch ID.

Make `rad merge` refuse to merge an older revision unless the `--force`
option is given.
2023-03-31 17:24:55 +02:00
Fintan Halpenny 8404b5925d
radicle: force new or initial construction of LWWReg
Using LWWReg::from will always set the clock value to the default,
which can end up being used wrong.

Instead, introduce a constructor method `initial` to indicate that it
should be used on initial construction, while `new` should be used for
newer values of the register.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-31 15:49:55 +02:00
Alexis Sellier 3f389f37ea
node: Make sure we retry on lock contention
This fixes an issue that came up in tests where we would be reading
and writing to the database at the same time, and it would fail with
an error due to the lock being contended on.
2023-03-31 14:07:45 +02:00
Alexis Sellier b20f81eb0c
Use cached canonical `rad/id` refs
We were recomputing the `rad/id` ref every time it was accessed.
2023-03-31 13:52:12 +02:00
Sebastian Martinez 87f47cdc67
Reduce pub accessors in patch and issue cob structs
Replaces pub accessors to struct fields with methods
Also creates some methods to compute necessary information

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-31 13:44:37 +02:00
Fintan Halpenny c618c3e443
node: remove Namespaces::One
The One variant caused many paint points for fetching logic, where it
was not necessary. It was only constructed in one place, which could
be replaced by using the variant that holds a set of keys.

Remove the Namespaces::One variant and rename Namespaces::Many to
Namespaces::Trusted.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-31 12:23:32 +01:00
Fintan Halpenny adf6312a55
node: fetch trusted peers on clone
When a repository does not yet exist during a fetch, i.e. a clone,
then only delegates are being fetched.

Augment Namespaces::Many to hold the trusted and optional delegate peers
separately. Doing so allows the construction of the variant without
the repository existing, but tracking relationships existing.

This variant can then be used to build refspecs for both the trusted
peers and delegates when doing a cloning fetch.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-31 12:23:31 +01:00
Fintan Halpenny db0ceddf6b
node: multistep fetching logic
The previous fetching logic had some pitfalls regarding its logic:

* Fetched 'rad' references could end up not being verifiable and leaving
  the storage in a corrupt state
* Forced pushes would be prohibited, since they would be rejected by
  the client side due to the refspecs being used.

The new approach is to stage a fetch in 2 steps. The first step is to
fetch the relevant `rad/id` and `rad/sigrefs` for verification. For
all remotes that are verified, fetch all references listed in their
respective `rad/sigrefs`, using the `+` marker in the refspec,
allowing to update for any force pushes -- note that this becomes a
safe operation since the `sigrefs` are signed by the remote that
created them.

To prevent unverifiable 'rad' references from polluting storage, all
fetch negotiations are done in a staging repository set up in a
temporary directory. All successful fetches are then transferred,
using the 'file://' protocol, from the temporary directory into the
radicle storage.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-31 12:19:36 +01:00
Sebastian Martinez 91efbd9630
Rename `patch::State::Proposed to `patch::State::Open`
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-30 10:46:57 +02:00
Sebastian Martinez 8907ddb8a5
httpd: Add `patch::Action::Lifecycle`
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-30 10:46:57 +02:00
Sebastian Martinez c9aaaec2ee
cob: Add `patch::Action::EditRevision`
To be able to change the description of a patch revision, without the
need to create a new revision.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-30 10:42:49 +02:00
Sebastian Martinez fa15ca59f1
cob: Use `LWWReg::new` instead of `LWWReg::from`
Using LWWReg::from was giving subsequent actions
the same clock value as their predecessors.

This resulted in a Reject not being able
to turn into an Accept on a second review of a patch.

The solution is to use the clock value that was produced for the Op
and pass that into new, avoiding the call to from.

Co-authored-by: Fintan Halpenny <fintan.halpenny@gmail.com>
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-30 10:40:21 +02:00
Fintan Halpenny af99d6f47a
radicle: set identity head on init
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-27 10:13:04 +01:00
Fintan Halpenny a32101ab75
radicle: canoncial refs/rad/id
Introduce a canonical reference for refs/rad/id to aid in discovering
information about a repository without knowing a peer -- e.g. if a
peer wants to clone a new repository it needs to find out which peers
are delegates for that project, but does not know what their NIDs are
up front.

The approach mirrors the canonical `head` for a repository and
introduces useful constructors for `Doc`/`DocAt`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-27 10:13:03 +01:00
Han Xu b030e9ea80
node: Only fetch from tracked nodes
The tracked nodes include nodes marked tracked in the db, and
the delegates and `Namespaces::All` if it is a new repo.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2023-03-25 12:27:29 +01:00
Sebastian Martinez a5746b4f08
httpd: Add reactions to issue and patch json
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-25 12:04:53 +01:00
Sebastian Martinez 564886b165
httpd: Add `path` property to `CodeLocation`
For the web client to be able to show file we need to provide
the web client with the file path.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-23 11:41:13 +01:00
Alexis Sellier 71cf289c52
Skip hidden files in repository listing 2023-03-22 18:25:31 +01:00
Alexis Sellier e103ffbb95
Improve invalid RID error 2023-03-22 18:25:31 +01:00
Sebastian Martinez f2d31aa9c0
httpd: Add patch update endpoint
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-22 13:53:19 +01:00
Han Xu 241c41a632
node: Queue pending fetches in Session
Pending fetches are drained one at a time after the previous fetch is
completed.

Signed-off-by: Han Xu <keepsimple@gmail.com>
2023-03-22 08:46:27 +01:00
Sebastian Martinez f9980f7205
radicle: Fix `canonicalize_home` test on macos
Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-21 18:40:55 +01:00
Alexis Sellier ab74e54949
term: Implement new output widget system
We implement a new `Element` trait which allows for more complex output
to be drawn, such as vertical and horizontal stacks.

We adapt `Table` to work within this system.

We refresh the output of `rad patch show` to use these new tools.
2023-03-21 12:43:44 +01:00
Sebastian Martinez 73221e43d7
httpd: Add more revision properties to patch
For display purposes in the web client, we add with this commit the
some needed properties to the revisions in the patch endpoint.

Signed-off-by: Sebastian Martinez <me@sebastinez.dev>
2023-03-20 18:43:06 +01:00
Alexis Sellier cf1acf7e24
Fix patch `description` method
The description is not actually optional, so don't return an `Option`.
2023-03-18 12:24:17 +01:00
Alexis Sellier 5828b917f9
node: Fail fast when repository can't be read
It's not a good idea to have fallible operations run after `FetchOk`
is received, since there's no easy way to communicate the error
to the remote at that point. What would then happen is that the fetch
just "hangs", since nothing is there to cancel it.

Hence, we compute namespaces earlier in the process, and store the
namespaces in the session. If there is a failure, the fetch is
never initiated.
2023-03-15 16:22:43 +01:00
Alexis Sellier bd436d4369
cli: Open tracking DB in read-only mode 2023-03-15 12:59:49 +01:00
Alexis Sellier 05d7090326
node: Remove `Handle::inventory` method 2023-03-15 12:59:49 +01:00
Alexis Sellier caaa7581e6
node: Remove `Routing` command
Replaced by direct DB access.
2023-03-15 12:59:49 +01:00
Alexis Sellier 40c58b45ed
node: Move `routing` to `radicle` crate 2023-03-15 12:59:49 +01:00
Alexis Sellier b558c742e6
node: Rename `repo_entries` to `repo_policies`
Do the same thing for `node_entries` etc.
2023-03-15 12:59:49 +01:00
Alexis Sellier 9b6ede8fc5
cli: Use tracking DB access for `node` command 2023-03-15 12:59:49 +01:00
Alexis Sellier cf8113765c
node: Move tracking store to `radicle` crate 2023-03-15 12:59:49 +01:00
Fintan Halpenny de8e92d48c
radicle: safe Reaction construction
The Reaction type needs to ensure that the `char` stored for its value
meets certain requirements -- via its `new` constructor.

To ensure Reaction is always constructed correctly, the `pub` accessor
is removed, and the Deserialize implementation is implemented by hand
-- as opposed to using derive.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-14 14:31:12 +01:00
Fintan Halpenny 0337574750
radicle: log when Ops::try_from fails
If Ops::try_from fails in from_history then it means that some
operations failed to be parsed.

If this happens, then a warning should be logged so that these failure
cases can be more easily traced.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-14 14:31:12 +01:00
Alexis Sellier 7266729924
Make Patch `state` field similar to Issue
Since they are similar objects, they should have similar structure.
This also makes it easier to add state metadata like for issues.
2023-03-13 13:55:12 +01:00
Alexis Sellier 8e5627d28a
node: Rename `tracked_repo` -> `repo_policies`
I was finding the current naming misleading, as the returned entries
could be for blocked repos/nodes.
2023-03-13 11:41:07 +01:00
Alexis Sellier 4f062ef2c6
node: Fetch missing inventory
Periodically, make sure we try to fetch inventory that is tracked
but missing from local storage.

We decide not to fetch immediately on `TrackRepo`, as this limits
the command's flexibility. For example, when `rad clone` is used,
we want to be able to fetch manually after tracking.
2023-03-13 11:38:33 +01:00
Alexis Sellier aacacf872f
cob: Use `EntryId` as the operation identifier
By introducing a small limitation: only allowing entries in the change
graph to be addressable, instead of individual operations; we
drastically simplify the CRDT implementation.

There are four advantages:

1. Op ids are just regular SHA-1s
2. There's no need for relative IDs, ops never refer to other ops within the
   same commit
3. There's no need for a nonce, since commits can't collide, and neither can op IDs
4. `OpId` can just be an alias of `EntryId`

The disadvantage of course, is that we have to be mindful of how we
create op transactions, since each transaction creates an addressable
unit. For example, we must not include multiple patch revisions in the
same transaction.
2023-03-09 17:08:56 +01:00
Fintan Halpenny e937cdd79a
node: improve fetch
The fetch implementation will potentially fetch the local operator's
remote, which is unnecessary and could result in deleted data.

Fix this by threading the local operator's public key and add an
ignore refspec to the fetch arguments, i.e.

    ^refs/namespaces/<local>/*

The implementation also strictly fetches all or one namespace. This is
improved upon by introducing a new variant for specifying a set of
namespaces.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-08 11:29:34 +00:00
Fintan Halpenny 3b015a9325
radicle: accept Scope as track_repo argument
The method `track_repo` only accepted the RID as the argument for
tracking.

Instead, allow passing Scope as an argument for tracking a
repository.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-08 11:29:34 +00:00
Fintan Halpenny b82584617b
node: store Scope in tracking config
The tracking configuration has no way of consulting for a configured
scope.

This change allows the storing of this scope inside the tracking
`Config` -- currently unused.

The default Scope is chosen as Trusted, so that nodes do not
implicitly track any other node. If this behaviour is desired -- for
example, for seed nodes -- then All should be chosen.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-08 11:29:34 +00:00
Fintan Halpenny 5902236d0a
radicle: remove DelegatesOnly scope
The DelegatesOnly scope is very limited and causes more confusion than
it solves.

The Trusted scope subsumes DelegatesOnly since it implies delegates
along with any tracked nodes. This feels more natural to use and so
DelegatesOnly is removed -- leaving only Trusted and All.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-08 11:29:34 +00:00
Fintan Halpenny 39be7db1e9
radicle: make alias optional
Previously the alias field was simply a string which could possibly be
empty. Some checks were made to see if this string was empty.

Instead, make the logic more obvious by making the alias field
optional.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-08 11:29:34 +00:00