Commit Graph

289 Commits

Author SHA1 Message Date
Alexis Sellier bda5d6f080
node: Tunnel git data without parsing packet-lines
Instead of parsing the worker requests and responses, which was causing issues
around packfile transmission, we use threads and pass the bytes
transparently.
2023-04-14 13:16:32 +02:00
Alexis Sellier a05de1fbf3
node: Test fetch with large repository
This is for stress-testing the replication.
2023-04-14 13:15:52 +02:00
Alexis Sellier ac3a03fea6
node: Set git-daemon keep-alive
Send a keep-alive packet every 3 seconds to make sure the client doesn't
timeout during pack building.
2023-04-14 13:15:52 +02:00
Alexis Sellier 273ce2744a
node: Add more information to worker result log 2023-04-14 13:15:52 +02:00
Alexis Sellier f4257eb953
node: Add setting for limiting fetch concurrency
Can be passed via `--limit-fetch-concurrency <num>`.
2023-04-14 13:15:52 +02:00
Alexis Sellier ea4294c79f
node: More realistic concurrent fetch test
This implements a test which can optionally use a lot more data by
setting `RAD_TEST_SCALE` to a higher value.
2023-04-14 13:15:52 +02:00
Alexis Sellier 8205f8ad4e
Update `fastrand` dependency to 1.9.0 2023-04-14 13:15:52 +02:00
Alexis Sellier 31647521fa
node: Properly close worker channels
We need to send a 'close' event to the worker channel for it to exit
without an error.

Also updated and improved a bunch of the logs.
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 7cbfde1e9b
node: Don't needlessly fetch or announce
* We shouldn't announce if no refs were updated.
* We shouldn't blindly fetch if we don't know if we have an item in
  storage.
2023-04-14 13:15:52 +02:00
Alexis Sellier f3d513783c
node: Don't fetch owned refs unless cloning
We shouldn't be fetching our own refs unless we are creating a clone.
2023-04-12 16:40:53 +02:00
Alexis Sellier c8e548fb1d
node: Make sure we have all refs in staging copy
Previous to this change, we just created a clone, which was missing
all the refs.
2023-04-12 11:43:43 +02:00
Alexis Sellier 097b5b4ca4
node: Improve worker code logging and errors 2023-04-12 11:28:12 +02:00
Alexis Sellier eeec2008e8
node: Allow most refs to be force-updated
Previously, during the "transfer" stage of a fetch, we used `force:
false`, which didn't allow refs to be force-updated.

This change makes it possible to fetch force-updated refs, but ensures
that the sigrefs branch is never force-updated.
2023-04-12 11:09:05 +02:00
Alexis Sellier 89b9eb53b7
node: Implement protocol multiplexing
To improve the reliability and flexibility of the protocol, we introduce
multiplexing over peer connections. This involves a new `Frame` type
that carries a stream-id and payload.

Three stream types are made available:

1. Control
2. Gossip
3. Git

This change brings the following improvements:

* Removed need to queue fetch requests
* Removed need to queue gossip messages
* Removed need for `Fetch` and `FetchOk` messages
* Service doesn't need to know about inbound fetches
* Removed one round-trip for fetch negotiation
* Removed special `done` git packet
* Removed session logic and state around Git/Fetch protocols
* Removed code around upgrading/downgrading transport
* Worker in responder mode is able to process any number of fetches
* Connections support any number of concurrent fetches

We had to introduce a few extra things however to make it all work:

* A `VarInt` type for variable-length integers, since we want the frames
  to be lightweight.
* A custom "tunnel" implementation, since we couldn't use the existing
  one anymore.

Overall the change removes more complexity than it adds, while improving
the protocol along the way.
2023-04-10 14:41:55 +02:00
Alexis Sellier ed4c266a51
node: Don't prune owned refs
Owned refs were being pruned on fetch.
2023-04-03 22:09:41 +02:00
Alexis Sellier c3e14c346b
node: Add `--force` option to start node
Forces the node to start even in the presence of an existing socket
file.
2023-03-31 17:30:55 +02:00
Slack Coder 6417a71e08
node: systemd file
Support users with systemd integration by providing a systemd service
file.  The file includes basic instructions for how to adapt to the
users context.

There are two scenarios it would be run in, as a system service, or as a
user service.  The scenario as a user service is problematic.
`radicle-node` relies on ssh-agent or a clear text RAD_PASSPHRASE.
2023-03-31 15:48:32 +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
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 f78e010c55
node: e2e test simulating a peer migrating their key
Previously, if a peer created a project which was replicated and then
moved to another setup, ultimately deleting that project, then they
would not be able to fetch it again since their remote namespace would
be excluded from the fetch.

This test confirms that a peer can remove their project and clone it
again from a peer that has replicated the project. This is simulated
by directly removing the project directory in the test and fetching
the project from the other peer.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-31 12:19:37 +01:00
Fintan Halpenny 6e08f0be59
node: enable test_fetch_trusted_remotes
With the latest fetch updates, the test for fetching trusted remotes
can be enabled.

The caveat is that its expected behaviour is to fetch the delegate
upon a clone and fetch all trusted peers on a subsequent
fetch. Fetching all trusted peers is left as a follow-up task.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-03-31 12:19:36 +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
Alexis Sellier 973f618cd3
node: Fix routing table update on refs
The announcer is always the one who must have the refs, not the relayer.
This was changed in a recent patch.
2023-03-30 10:24:09 +02:00
Alexis Sellier 7c41c5edff
node: Replace most sleeps with events
With the new event system, we can replace the thread sleeps by
waiting for events. This should speed tests up a lot and
be more reliable.
2023-03-30 10:24:06 +02:00
Fintan Halpenny a629f91b1e
node: set identity head after fetch
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
Alexis Sellier da9d63b284
node: Fix fetch requests code
We were not correctly deleting the fetch request, since only one
was kept per RID.
2023-03-24 13:25:40 +01:00
Alexis Sellier fe8953ab8b
node: Don't penalize peer for protocol mismatch
Instead of returning a non-transient disconnect reason, return
a transient one, since protocol mismatches can happen.
2023-03-24 13:23:43 +01:00
Alexis Sellier d3f4189324
node: Fix reconnection logic
First, we make sure to always attempt reconnection to persistent peers,
no matter the reason.

Second, we don't re-attempt connections when an inbound peer
disconnects. This minimizes the chance of connections crossing.

Third, we clean up `session::Error`, and don't use it to signal a
missing session, since it doesn't really belong there.
2023-03-24 13:20:34 +01:00
Alexis Sellier 4438a10498
node: Change ping interval to 1 minute
30 seconds is too chatty.
2023-03-24 13:19:36 +01:00
Alexis Sellier bfea229850
node: Relax `Service` storage trait bound 2023-03-23 18:08:06 +01:00
Alexis Sellier c427f41379
node: Fix periodic inventory announcement
1. We were announcing inventory every 30 seconds. This is now changed
   to 1 hour.
2. We were using a variable to track whether our inventory has been
   announced to the network, but this var was set based on what we
   tracked, not the inventory we had. This var has been removed.
2023-03-22 22:03:59 +01:00
Alexis Sellier dd97ac8384
node: Improve worker error handling
Better handle case where the connection to the daemon fails, in the
responder scenario.

Instead of trying to read the `done` packet once, we loop until we've
read it. This handles a scenario where the uploader fails before the
git protocol is initiated, and the fetcher is still sending git packets.
2023-03-22 12:22:44 +01:00
Alexis Sellier a9d1a71f7a
node: Add timestamp to test logger 2023-03-22 12:22:44 +01:00
Adam Szkoda 1455810d57
node: Add commit SHA-1 to log 2023-03-22 08:52:52 +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
Alexis Sellier ed1120f3eb
node: Don't relay redundant gossip messages
This change ensures that on `Subscribe`, we only relay the latest
announcement of each node, per announcement category.

Previously, we would relay all announcement, while only the last one
was relevant.
2023-03-17 17:10:10 +01:00
xphoniex a49eec9892
node: Add eventing system to `Handler` and `Service`
Signed-off-by: xphoniex <dj.2dixx@gmail.com>
2023-03-16 22:26:57 +01:00
Alexis Sellier ebfd445034
node: Use correct scope when getting namespaces
We were using the default scope instead of the entry scope.
2023-03-16 15:38:05 +01:00
Alexis Sellier 88c545bfdd
node: Make sure to only read packet-line header
If there is an unexpected error, eg. `BrokenPipe` in the upload process
process of the worker, we may have more than four bytes to read from the
remote socket. This change ensures that we don't attempt to read more
into a buffer of size `4`.
2023-03-16 15:26:16 +01:00
Alexis Sellier c46bc0cc82
node: Start periodic tasks
This change ensures that we start the periodic tasks "loop" by
scheduling the first wakeup during initialization.
2023-03-16 15:26:13 +01:00
Alexis Sellier fdfe1d508b
node: Use deserializer when decoding messages
For whatever reason, we weren't using the deserializer for message
decoding. This meant that if a message came in two pieces, it would
cause decoding problems, since the first piece would be discarded.
2023-03-16 15:26:13 +01:00
Alexis Sellier 17e3c975fb
node: Better error message when protocol mismatch 2023-03-16 15:26:13 +01:00
Alexis Sellier c4a66c20d0
node: Fix potential protocol mismatch on fetch
It's possible that the daemon or stream closes the git connection
without reading the final `done` packet. If this is the case, we
try to read it after either of the connections is closed.

This may potentially mitigate the issue where the node then receives
the `done` packet while in gossip mode, and disconnects the remote
for misbehavior.
2023-03-16 15:26:13 +01:00
Alexis Sellier 98ee9c46a9
node: Fix state mismatch between service and wire
Due to never removing peers from the peer map in the wire
protocol module, it was possible for there to be multiple
connected peers with the same Node ID. Some might be in a
"connected" state, while others might be "disconnected".

This caused a bug where a peer, although connected would
be considered disconnected by the wire module, because
when searching for a peer with that Node ID, the disconnected
one would return first.

To fix this, we make sure to remove peers from the map once
the connection is dropped.
2023-03-15 16:46:27 +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 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