Commit Graph

85 Commits

Author SHA1 Message Date
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 cf8113765c
node: Move tracking store to `radicle` crate 2023-03-15 12:59:49 +01:00
Alexis Sellier cd12741bf2
node: Prevent redundant [re-]connections
It was possible to trigger multiple connection attempts to the same
peer, since we didn't track connection attempts that hadn't yet
returned to the service via `Service::attempted`.

With this change, we add an extra `Initial` state to sessions, so
that redundant connections are not attempted when one is already under
way.
2023-03-14 13:42:59 +01:00
Alexis Sellier 413238a1e0
node: Implement exponential back-off for reconnect
Instead of immediately attempting reconnection when a persistent
peer disconnects, wait some amount of time, increasing on every
attempt.
2023-03-13 17:43:49 +01:00
Alexis Sellier db38f2df76
node: Handle `FetchOk` never being received
It's possible for a peer to disconnect before responding with `FetchOk`.
In that case, we make sure to return to any pending fetch request with
an error.
2023-03-08 16:22:42 +01:00
Fintan Halpenny 1e8f5b2259
node: determine fetching namespace based on repo policy
To determine the correct Namespaces to use, the repo Policy and Scope
are consulted.

If the policy is Block then this is a failure state and is reported to
the other end.

Otherwise, if the policy is Track, then the scope is checked. For the
Trusted Scope then the Namespaces should consist of all tracked nodes
and delegates for the given repository. However, the repository might
not exist and so it is necessary for the whole repository to be
fetched.

For the All Scope, all Namespaces are fetched.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-08 11:33:41 +00: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 546b402467
node: return full tracking policy
Instead of returning tuples for `repo_entry` and `node_entry`, return
the `Repo` and `Node` types, respectively.

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
Fintan Halpenny e408b0d62c
node: use enum for fetch direction
A fetch is a client-server interaction and so there are two sides to
this interaction. These sides are generally referred to as receive --
the client side -- and upload -- the server side.

The `Fetch` type indicated whether it was doing a receive or upload by
using a field `initiated: bool`. However, this can be confusing when
you pair it with the `namespaces: Namespaces` field, since only the
receive side should be sending what refspecs it wants and the upload
side responds with those matching refspecs.

A better way to represent this is using an enum for which direction
the fetch is being considered, where the receive side contains the
Namespaces. To borrow from Noise, the variant names are 'Initiator'
for the client and 'Responder' for the server.

The resulting code then makes decisions based on what variant of the
enum was passed.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-08 10:12:54 +00:00
Alexis Sellier c3a5aced07
node: Handle case of crossing fetch requests
It is possible for a pair of nodes to concurrently ask each other
to fetch some repo. These "crossing" requests are problematic,
because the nodes end up waiting for each other to reply, and
the reply never comes.

With this change, the node pair agrees on proceeding with one of
the fetches, while canceling the other.
2023-03-07 16:22:22 +01:00
Fintan Halpenny 1f837c6572
node: implement tracking and routing
The routing function for Node was not implemented and there were no
functions for getting any tracking information.

This implements routing, tracked_repos, and tracked_nodes. To
accomplish this it was necessary to add associated types to the
Handler trait so that implementations could differ in the types they
use for returning this data, i.e. the control socket needs to use a
channel while the Node needs to return serializable data.

Currently, the Node uses a `Vec` but it would be more beneficial to
return an Iterator directly to ensure we are not always hitting the
heap.

To allow for the tracking types to be used across radicle-node (the
crate) and in radicle::node (the module), it was necessary to move
the types to the common place, i.e. radicle::node. At the same time,
new structs were added to make it easier to refer to tracked repos vs
tracked nodes.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-07 15:38:41 +01:00
Alexis Sellier 85df613682
cli: Implement automatic issue announcement 2023-03-07 08:40:20 +01:00
Fintan Halpenny c70dc71b18
node: improve seeds information
Previously, the seeds information would only consist of the connected
NodeIds.

Improve on this by adding any disconnected and fetching seeds as
well. A seed can either be disconnected, connected, or fetching --
where fetching implies connected.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-02-27 17:48:11 +01:00
Alexis Sellier 11da344e3a
node: Add `--tracking-policy` flag
Sets the default tracking policy.
2023-02-27 13:46:40 +01:00
Alexis Sellier a7d2fa95cd
node: Remove redundant handshake
With `NoiseXK` handshake implemented, there is no longer a need to
have an `Initialize` message and an extra state in the session.
2023-02-16 15:10:31 +01:00
Alexis Sellier 71561a8e12
node: Move state transition code to session 2023-02-16 15:09:53 +01:00
Alexis Sellier 011923f1df
node: Buffer gossips until fetch is completed
This change ensures that gossip messages are buffered if we try to
send them during a fetch, and sent after the fetch completes.
2023-02-16 15:09:53 +01:00
Alexis Sellier 0f81f8a7aa
node: Take session reference when writing messages
This ensures that we have an existing session when sending messages.
It also will allow us to check the session's state.
2023-02-16 15:09:53 +01:00
Alexis Sellier 950fae209d
Make `ReadStorage` more usable
Previously, we were not able to access a `ReadRepository` instance
through `ReadStorage`. With this change, we are able to.
2023-02-15 22:08:20 +01:00
Alexis Sellier 89fcc6de1c
node: Subscribe on track-repo
We re-subscribe after our tracking policy has been changed so that
peers are informed of our interests.
2023-02-15 22:07:51 +01:00
Alexis Sellier 8cbc3c2403
node: Move to NoiseXK
Move from NoiseNN with a custom authentication protocol, to NoiseXK.
Uses ECDH on the ed25519 curve via the `ec25519` library.
2023-02-15 22:05:04 +01:00
Alexis Sellier ee513ccf7e
node: Complete the "relay" seed test
These are the final changes to get the "relay" scenario passing.
There are still some issues left, though it's done as far as the
test is concerned.
2023-02-14 20:31:40 +01:00
Alexis Sellier 7919c7ea61
node: Use millisecond precision for timestamps
Previously we used seconds, which could result in false positives
when checking for stale announcements, if things happened too quickly.
2023-02-14 20:31:40 +01:00
Alexis Sellier 2f1a18470e
node: Fix filter construction and policy code 2023-02-12 17:07:57 +01:00
Alexis Sellier 42b4d95f93
node: Improve output of `Session::fetch` function 2023-02-12 16:22:51 +01:00
Alexis Sellier bd7c5a0daa
node: Add ability to have default tracking policy
When a specific tracking policy isn't found, we allow setting a default.
To preserve existing behavior, the default is `Block`, ie. if a node
isn't tracked explicitly, it is blocked.

However, this change allows for using `Track` as the default, which
is a way to track everything without having to know the entities in
advance.
2023-02-12 16:22:51 +01:00
Alexis Sellier 7bdedd0ffd
node: Fix bug with persistent peer reconnect
We weren't updating the sessions map when a persistent peer
was re-attempted. It would then panic when `connected` was called,
because the state would be `Disconnected`.
2023-02-07 10:47:35 +01:00
Alexis Sellier 45e31a5192
Communicate fetch results through control socket
This allows a CLI to report to the user what fetch requests were
fulfilled, and which ones failed.
2023-02-07 10:46:12 +01:00
Fintan Halpenny 3f48c2c516
Rust 1.67
Rust 1.67 was announced[0]. Update the necessary files for running
1.67 and fix the clippy suggestions for string interpolation.

[0]: https://blog.rust-lang.org/2023/01/26/Rust-1.67.0.html

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-02-04 19:30:29 +01:00
Alexis Sellier be77eebc3d
node: Only try to fetch from connected nodes 2023-01-30 11:20:33 +01:00
Alexis Sellier be95222fb5
node: Fix bug in upload-pack
We were not properly exiting one of the threads that was copying
data from the stream to the upload-pack process. This is a fix.
2023-01-27 15:09:17 +01:00
Alexis Sellier ef950d515a
node: Fully integrate worker fetch into service 2023-01-25 10:21:57 +01:00
Alexis Sellier ec2e7d7ee1
node: Refactor fetch response code
Only user-requested fetches require a response.

Signed-off-by: Alexis Sellier <self@cloudhead.io>
2023-01-25 10:21:57 +01:00
Alexis Sellier 3bc07195f5
Migrate to `localtime` from `nakamoto`
The only thing we needed nakamoto for was `LocalTime`.

Signed-off-by: Alexis Sellier <self@cloudhead.io>
2023-01-18 18:03:11 +01:00
Alexis Sellier 3bedb4438e
node: Fix a few logging-related things
Signed-off-by: Alexis Sellier <self@cloudhead.io>
2023-01-17 11:01:36 +01:00
Alexis Sellier 63e7248847
node: Complete Noise handshake integration
Co-authored-by: Dr. Maxim Orlovsky <dr.orlovsky@gmail.com>
Signed-off-by: Alexis Sellier <self@cloudhead.io>
2023-01-17 11:01:36 +01:00
Alexis Sellier 6d420813f5
node: Fix attempted session state
We shouldn't be marking attempted peers as "connected". We should wait
for the connection to be properly established.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2023-01-13 15:44:01 +01:00
Alexis Sellier 438ae84304
node: Implement E2E node test
There are few unrelated changes in this commit that I wasn't able to
split out, mostly due to laziness, so I'll list them here:

* The node startup logic is moved out of the main function, and into a
  dedicated functionin `client.rs`.
* There is a tentative worker implementation that is untested, and
  handles git replication both ways. It's likely lacking in various ways
  but I wanted to get it in there anyway.
* `Address` was moved from `radicle-node` to `radicle`, because it's
  needed to send `Connect` commands from the node handle.
* The `netservices` dependency was updated.
* Finally, there is a first end-to-end node test, which currently
  doesn't use NoiseXK, but uses the new reactor in `netservices`.

Signed-off-by: Alexis Sellier <self@cloudhead.io>
2023-01-12 20:34:31 +01:00
Dr. Maxim Orlovsky a7b1c19746
node: Implement worker thread handover
Also implements listener behavior.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2023-01-05 15:16:38 +01:00
Alexis Sellier f26674a5a9
Upgrade Rust to 1.66
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-15 20:55:26 +01:00
Dr Maxim Orlovsky aa02c52a2f
node: Integrate new Noise_XK transport
This is a large change that introduces transport encryption via
a Noise_XK handshake. The inner `Service` now works directly
with `NodeId` and doesn't need to interact with socket addresses.

The transport logic takes place in `wire::transport`, and the
established sessions are passed down to `Service`.

Note that the i/o implementation in the `poll-reactor` crate still
needs testing, and there is still work to be done to integrate the
Git transport as part of this architecture.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-13 14:59:06 +01:00
Slack Coder e7f2637126
node: Limit number of Refs in RefAnnouncements
Use the BoundedVec to limit the supported number of refs in
RefAnnouncement messages.  The size (235) is the maximum supported by
message wire size.

To reduce the complexity of the changes, BoundedVec is used again
instead of using a new bounded Refs or BTreeMap.  This requires
defining new Decode/Encode logic for Ref's element types, and
workarounds for arbitrary instances.

Signed-off-by: Slack Coder <slackcoder@server.ky>
2022-12-09 21:54:10 +01:00
Alexis Sellier 1007756238
node: Add tracking configuration store
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-07 15:41:56 +01:00
Alexis Sellier db3568db2f
Update `sqlite` dependency to 0.30.3
Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-07 15:41:56 +01:00
Alexis Sellier f9c81ab382
Replace `quickcheck` with `qcheck`
The latter is a fork of the former, which adds const generics
and a bunch of other quality of life improvements that aren't
in the original crate due to it being unmaintained.

Signed-off-by: Alexis Sellier <alexis@radicle.xyz>
2022-12-04 20:40:54 +01:00
Slack Coder fe60305455
node: Define naive message vector limits
Restrict message size decoding by limiting Message's vector size.
Introduce the BoundedVec type to do this on the type level for
convenience and clarity.

Signed-off-by: Slack Coder <slackcoder@server.ky>
2022-12-01 14:54:40 +01:00
Dr Maxim Orlovsky da55e521a1
Use socket addr instead of Ip for the address book 2022-11-29 17:58:38 +01:00