Commit Graph

603 Commits

Author SHA1 Message Date
Alexis Sellier 3ae7e305bd
node: Simplify configuration
This is a change to the `config.json` file which removes certain options
that are best not touched and changes some options to make them easier
to work with.

1. We change the default journaling mode to "wal" and remove the config
   option.
2. We remove the option to set the peer connection "target", as it's not
   a good idea to set this to a different value, as it affects the
   network.
3. We combine seeding policy & scope, since there's no need to set the
   scope when the policy is "block". In that case, we always want to
   block "all" remotes. The new policy configuration has the following
   schema:

   { seedingPolicy: { default: "block" | "allow", scope?: "all" | "followed" } }

   The "scope" key is not used when "default" is set to "block".

4. We add an `extra` field to the node config for options that are not
   recognized. We use this to warn the user.
2024-06-04 14:08:15 +02:00
cloudhead 0834e0fc7d
node: Implement staggered broadcast for gossip
We use the *staggered broadcast* technique when relaying gossip messages
to reduce message amplification. In our basic simulation, it brings
amplification down from 3.5 to 1.5.

The idea is simply to accumulate gossip messages and relay them after a fixed
interval of time. This has two effects:

1) Old messages that haven't been sent yet are replaced by newer ones,
   so only one message is sent after the delay.
2) Because nodes have their own intervals, messages are not all sent at
   the same time, which reduces the chance of messages crossing paths.

For now we only turn this on for inventory messages, since this is the
least likely to be noticed by users, and also the most problematic
currently.
2024-05-24 16:44:22 +02:00
cloudhead 3075a399e9
node: Add test for message amplification 2024-05-24 16:44:22 +02:00
cloudhead 1a8b2f5e2c
node: Fix subscription 'since' timestamp
It was always effectively set to "now" because we insert rows into the
gossip table on startup.
2024-05-24 12:24:20 +02:00
cloudhead a85e7f7442
node: Set TCP_KEEPALIVE on sockets
Ensures dead connections are not kept around longer than necessary.
Note that the ping/pong mechanism is more expensive and checks that the
session is active and healthy, while TCP_KEEPALIVE is lower level,
cheaper, and checks that the connection is still alive.
2024-05-22 14:46:08 +02:00
cloudhead 90deb20405
node: Set socket options for inbounds too
We were only setting socket options for outbound connections.
2024-05-22 14:38:31 +02:00
cloudhead 3403a66d0f
node: Ignore messages from newer protocol versions
This allows for protocol upgrades without breaking old nodes.
2024-05-22 13:56:47 +02:00
cloudhead 30c9b0db0b
cli: Add `rad node debug` command 2024-05-21 16:00:30 +02:00
Fintan Halpenny d46b0b6d11
radicle: Fix file limit setting for FreeBSD
On FreeBSD systems, the file limits are of type `i64` in comparison to
`u64` on Linux systems.

Also fix `rad web` command name on Windows and FreeBSD.

Co-authored-by: cloudhead <cloudhead@radicle.xyz>
Co-authored-by: Shawn Webb <shawn.webb@hardenedbsd.org>
2024-05-21 13:48:44 +02:00
cloudhead 191278f0d9
cli: Use current local tip in `rad sync status`
In the case of an out-of-sync local node, we were showing the wrong tip.
Additionally, mark your tip as unannounced if it isn't announced. This
isn't fool-proof, but can be useful to debug certain issues.
2024-05-21 13:32:40 +02:00
cloudhead f78e5a4281
node: Update sync status for private repos
Only public repos were being updated on node initialization.
2024-05-21 13:32:40 +02:00
cloudhead 9f36320d83
node: Don't fail connection if TCP_NODELAY errors 2024-05-21 12:34:38 +02:00
Fintan Halpenny 064ece32ac
node: reduce default upload-pack timeout
From empirical testing, the `FETCH_TIMEOUT` can be set to a lower value of 3s.
For a repository that is about 300MiB, the process will successfully send all
packfile bytes and the references will be written.

The `--timeout` option is also used in the `git-upload-pack` process for good
measure.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-17 21:05:50 +02:00
Fintan Halpenny de434bb437
node: simplify upload-pack reader joining
The `join` method is equivalent to the custom loop that was written for joining
the `reader` thread in upload-pack.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-17 21:05:50 +02:00
Fintan Halpenny 740106d759
cli: upload-pack events
Introduce an `UploadPack` type for keeping track of relevant data from
upload-pack events and displaying progress to the terminal.

It keeps track of the number of remotes that are being uploaded to as well as
the throughput of transmitted data.

The `Progress` events are logged rather than being displayed since they don't
provide any useful details to the user.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-17 21:05:43 +02:00
Fintan Halpenny d56d619f56
fetch: remove `.keep` files
A `.keep` file in the `objects/pack` directory acts as a lock to ensure that
operations like `git gc` do not clean up `.idx` files while a fetch is being
performed. It is safe to remove the `.keep` file once a fetch has completed and
a reference points to a given object in the packfile.

To ensure this happens in `radicle-fetch`, a newtype `Keepfile` is introduced.
It uses special `Drop` semantics by attempting to remove the file when the
object is dropped -- logging a warning if it fails to do so.

`FetchState` is augmented to keep a set of the `Keepfile`s. This ensures that
when the fetch completes, either successfully or with a failure, when
`FetchState` is dropped then so are the `Keepfile`s.

We ensure that the expected behaviour of removing the `.keep`files occurs by
adding a check in `e2e::test_replication` to check Alice's repository's packs.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-16 15:47:14 +02:00
cloudhead 8402b85ad9
cli: Simplify private repo fetching
* Remove `rad sync --force` flag
* Remove `rad clone --private` flag

These flags are no longer necessary. Simplify specifying which seed
to fetch from with `--seed` is enough.
2024-05-16 15:46:24 +02:00
cloudhead ca7db1620c
node: Improve Tor configuration flexibility
*Breaking change* The `tor` configuration field is no longer
supported. Users must remove that field from their config.

Allows for a mixed mode, where regular addresses bypass the Tor proxy,
while onion addresses go through it.

When `onion.mode` is set to "forward", Tor connections are fowarded to
the global proxy, and if it isn't set, to the OS's DNS resolution.

For mixed mode, a global proxy simply isn't set, so that IP/DNS is not
proxied.
2024-05-16 14:53:52 +02:00
cloudhead a6cb4d0f48
node: Implement IP-based banning
The previous banning implementation didn't work, since it included port
numbers in the address value.

Here, we keep a separate table with (node, ip) pairs and update this
table when a node connects or is banned.
2024-05-15 12:10:23 +02:00
Fintan Halpenny 344fe3a901
node: increase `FETCH_TIMEOUT`
After empirically testing HardenedBSD[[0]], which has a total blob size of
42GiB, and its largest checkout is 1.26GiB (using `git-sizer`[[1]]), it was
found that letting the background process fetch the repository with a timeout of
1 hour is enough (a very generous estimate).

This deemed sufficient, since cases smaller than this will report back that they
are done before this time. For cases larger than this, more research will be
needed.

[0]: https://git.hardenedbsd.org/hardenedbsd/HardenedBSD
[1]: https://github.com/github/git-sizer

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-15 10:07:56 +01:00
Fintan Halpenny 027bfbef67
node: stream timeout semantics for `Node::call`
The timeout for a `UnixStream` will interrupt a `read` even when more data is
available. The preference would be that the timeout applies to each read, where
the timeout is reset again once a read is successful. This better supports
streaming semantics expected for the `Handle::subscribe` method.

To achieve this, the `LineIter` type holds the `UnixStream` and timeout
`Duration`. The `Iterator` implementation can then use `read_line` to progress
the stream one line at a time, and the timeout only applies to each read.

Co-authored-by: Alexis Sellier <alexis@radicle.xyz>
Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-15 10:07:56 +01:00
Fintan Halpenny c8a24d5584
node: report upload-pack progress
Emit the `UploadPack` events from the `upload_pack` method.

A wrapper type, `Reporter`, is introduced for implementing a `Write` instance
that will parse the given bytes as `gix_protocol::RemoteProgress`, if possible,
and emit it via the `Emitter`, and then write the bytes to the underlying
writer. This allows any subscribers to see the progress of an upload-pack, i.e.
`Compressing objects`, `Counting object`, `Enumerating objects`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-15 10:07:56 +01:00
Fintan Halpenny f0648c2a18
radicle: move Emitter to events module
Move the events Emitter to the `radicle::node::events` module to allow it to be
used outside of `radicle-node`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-15 10:07:56 +01:00
Fintan Halpenny fd4c4cd0af
node: dynamic fetch timeout via channels
Instead of using `DEFAULT_CHANNEL_TIMEOUT`, the timeout is dynamically set
per-fetch by the caller.

This passed via the `Io::Fetch` variant -- when initiating a fetch, and the
`Control::Open` variant when responding to a fetch.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-05-15 10:07:55 +01:00
cloudhead 21cced05c1
node: Allow for "WAL" mode in sqlite
This solves concurrency issues between the node and http daemon.
2024-05-14 16:34:30 +02:00
cloudhead 25c6660a59
node: Use inventory cache for checking missing
Use the cache when checking whether we're missing an inventory.
This is a lot faster.
2024-05-13 16:37:02 +02:00
cloudhead 8e541dcf58
node: Set TCP NO_DELAY for node connections
Just experimenting. I think this will be a better default for the type
of data exchanged between nodes.
2024-05-13 16:12:41 +02:00
Alexis Sellier 930f9b0a7e
node: Don't always connect to Tor addresses
Only connect if Tor is configured.
2024-05-10 13:38:02 +02:00
Alexis Sellier 9766c67671
node: Fix tor proxy issue for regular addresses
This should allow using a Tor proxy for regular connections.
2024-05-09 21:45:48 +02:00
cloudhead 6ab3bfcba0
node: Use banning for repeated offenders
When the penalty score for a node reaches a certain threshold, we ban
the node.

Banned nodes are not allowed to connect to us.
2024-05-07 14:49:02 +02:00
cloudhead 9a82aae993
node: Reset connection attempts when stable
Instead of resetting the number of attempts on connection, reset it when
the connection is stable, ie. after some time has passed.

This prevents connection retries from happening in succession when a
peer is disconnected during the initial handshake, as is the case with
invalid subscribe timestamps.
2024-05-07 14:49:02 +02:00
cloudhead ef4efe3200
node: Improve logging for storage check 2024-05-07 14:49:02 +02:00
cloudhead 7484d737d5
node: Re-use inventory message timestamps
If our inventory hasn't updated, don't issue a new inventory
announcement, simply use the previous message.

This avoids identical inventories propagating over the network and using
up resources.
2024-05-07 14:49:02 +02:00
cloudhead 88a4029789
node: Use `BoundedVec` for inbox 2024-05-07 14:49:02 +02:00
cloudhead f212dbb2ee
node: Make sure we bound peer message inboxes 2024-05-07 14:49:02 +02:00
cloudhead 43b0b2b426
node: Always go through proxy with Tor
Force the proxy for regular connections, when Tor is configured.
2024-05-06 22:27:46 +02:00
cloudhead 153be9ede4
node: Improve session type definition 2024-05-06 22:22:39 +02:00
Dr Maxim Orlovsky a3cce22f7a
node: Patch dependencies for Tor/socks5 support 2024-05-06 22:19:36 +02:00
cloudhead 2801403182
signals: Move signal handling to its own crate
We're going to share this code with `radicle-term`.
2024-05-03 14:30:51 +02:00
cloudhead 0d880e12e1
node: Respect relay config on subscribe
Don't relay when a subscribe message is received, unless our relay
configuration allows us.
2024-05-02 13:48:47 +02:00
cloudhead a9b94b0ad6
node: New relay configuration for nodes
Relay now has three values: "always", "never" and "auto".

The first two operate like the previous `true`/`false`. The
new (default) value turns relaying on for nodes with public (external)
addresses and off for nodes without. This should reduce redundant traffic on
the network, that was causing the rate limiters to trigger.
2024-05-02 11:45:29 +02:00
cloudhead afe13b9e47
node: Don't rate-limit persistent peers 2024-05-01 11:06:28 +02:00
cloudhead eece90e9f7
node: Fix naming/spelling of "limitter" module 2024-04-30 14:24:09 +02:00
cloudhead e5df616ead
node: Protect against non-monotonic clocks
Many (most?) system clocks are not monotonic, and even though we're
getting a `LocalTime`, which *is* monotonic when using `now()`, it is
constructed from a `SystemTime` which isn't.
2024-04-30 10:56:37 +02:00
cloudhead bb5355fcb1
node: Promote rate-limitting log to "debug" 2024-04-29 18:02:26 +02:00
cloudhead 55c4de0239
Remove outdated Dockerfiles 2024-04-29 18:02:07 +02:00
cloudhead b31fbde159
node: Add `log` to node config 2024-04-29 15:59:17 +02:00
cloudhead 7126d05130
node: Use constant delay for refreshing node ann
We use a shorter, constant delay, so that it is the same on all nodes.
2024-04-29 12:49:59 +02:00
cloudhead a815640a3b
node: Always try to relay node announcements
They are cached and will often be old. They should still be relayed.
2024-04-29 12:28:30 +02:00
cloudhead fe5757d122
Tidy up environment variables
* Try to use constants instead of strings
* Move crypto seed override out of radicle-crypto
* Use GIT_COMMITTER_DATE for commit overrides
* Use RAD_LOCAL_TIME as general time override
* Allow variables to be used in release mode
2024-04-26 10:38:54 +02:00