Commit Graph

497 Commits

Author SHA1 Message Date
Alexis Sellier 786ce40f95
node: Add connection limits
The limits are roughly modeled after the Bitcoin network.
2024-03-08 23:24:34 +01:00
cloudhead 091f7b7e98
node: Don't limit LAN addresses
These are defacto trusted.
2024-02-26 13:42:06 +01:00
cloudhead 9c9bbbe7bb
node: Expose listen addresses 2024-02-26 12:35:20 +01:00
cloudhead b0fbbeed6b
node: Upgrade dependencies
Fixes issue with improperly closed connections.
2024-02-26 11:47:03 +01:00
Fintan Halpenny 985b0af3f6
radicle: implement caching for issues and patches
Implement caching for the `Issue` and `Patch` COB. This is achieved by
having the `Transaction::initial` and `Transaction::commit` methods
take a cache which can update the newly created/updated object. The
`Store::remove` method also takes the cache for removing the object
from the cache, as well as the repository.

This meant that the `*Mut` types for the respective COBs are required
to carry a cache alongside the repository store. Identities will not
be cached, and so this is always set to `NoCache` -- which performs no
caching, and always succeeds.

To perform cache reading for issues and patches, the `cache::Issues`
and `cache::Patches` traits are introduced. They capture the minimal
amount of methods that are needed for the `rad issue` and `rad patch`
CLI commands.

The implementor for each of these traits is there respective `Cache`
types, which combines their backing repository store and the SQLite
database. They both provide convenience methods:
- `create` (and `draft` for patches)
- `get_mut`
- `remove`
which can be used instead of their repository store counterparts.

All uses of the repository stores (where needed) are replaced with
`Cache` types.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-02-23 16:03:21 +01:00
cloudhead c63aaaceac
cli: Fix `id` COB notifications in `rad inbox` 2024-02-23 11:35:54 +01:00
cloudhead 9576a6496b
node: Various small fixes 2024-02-12 11:37:31 +01:00
cloudhead 4307bdaae4
sim: Change a few things in the simulator
1. Simplify latency calculation to be more predictable, otherwise,
   setting a latency is not super useful.
2. Turn a hard error into a log. It's not worth fixing it now though, as
   it isn't a problem for the tests.
2024-02-12 11:37:31 +01:00
cloudhead d1f4161ee9
sim: Track messages received in simulator
This is going to be useful for testing message amplification in the
network protocol.

We also reset the state of a few things everytime the simulator is run.
2024-02-12 11:37:31 +01:00
cloudhead 286c639e26
node: Make sure node is "active" when connected
This ensures `last_active` is never `0` for connected peers.
2024-02-12 11:37:31 +01:00
cloudhead d6d90c6fdc
node: Track peer latency
This is useful for a bunch of different network optimizations we're
going to be working on.
2024-02-12 11:36:35 +01:00
cloudhead f46d396e12
clippy: Fix lint 2024-02-07 14:56:26 +01:00
cloudhead d901b911c6
node: Drop self-connections
Also try to avoid initiating a self-connection even if the NID of our
node has changed.
2024-02-07 14:30:42 +01:00
cloudhead fe55de181d
cli: Add new `rad inbox` command
Shows you updates on local repositories.

Included here is a basic implementation of a notification system. A new
database is created and updated after every fetch, with refs that have
changed.

The `rad inbox` command can then list items in the database and delete
them.
2024-02-06 11:40:58 +01:00
cloudhead 98c94de5e3
Various small improvements across crates
Most of these changes should be self-explanatory.

* Atomic fetch was no longer used
* The default policy when initializing should be 'all', as it is with
  `rad init`.
2024-02-06 10:37:44 +01:00
cloudhead 15d1709831
node: Ensure dequeued fetches are correct
Dequeued fetches were always fetching all refs, instead of fetching the
specific refs that were initially requested. We fix that by storing the
refs to fetch in the fetch queue.
2024-01-31 13:40:13 +01:00
cloudhead 159944f7b5
node: Small log line correction 2024-01-31 13:40:13 +01:00
cloudhead 3560e0066d
Fix preferred seeds configuration
When using `network: "test"`, we shouldn't default to any public seed
node. This change makes sure that the "preferredSeeds" configuration var
is only given a value when `network` is `main`.
2024-01-31 12:09:09 +01:00
cloudhead 8858cefc89
node: Make sure we properly disconnect outbounds
The previous change to the wire protocol introduced a bug: outbound
peers that failed to connect fully would not notify the service on
disconnect. This change fixes it.
2024-01-30 14:47:10 +01:00
cloudhead 131103cb53
Fix code around default policies
Make the code a little clearer and ensure that we are always calling the
`Config` and not the `Store`, so that we fallback on the default policy.
2024-01-25 21:11:08 +01:00
cloudhead aa9c6542ab
node: Fixes to wire protocol logic
* Make sure we cleanup pending peer states when disconnecting before
  handshake.
* Make sure we don't panic if a peer disconnects before being fully
  connected.
2024-01-25 15:35:19 +01:00
Fintan Halpenny 49584f4e73
radicle: pinned repositories configuration
Introduce pinned repositories to the `profile::Config`, i.e.
`config.json`.

This is used for pinning repositories in the httpd `/projects` handle.

To allow returning all repositories, an `all` query parameter is also
included.

This is non-backwards compatible change, since we introduce the `show`
query parameter which, if not supplied, will default to `pinned`.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2024-01-24 10:55:27 +01:00
cloudhead f87dfba9cd
Rename `Id` to `RepoId`
Rename the type to make it clearer and consistent with `NodeId`.
2024-01-22 15:51:44 +01:00
cloudhead 7b3d380ceb
node: Fix connection attempt tracking
When a DNS error occured, the `dial` call failed and we didn't get a
connection attempt, just a disconnect. We fix that by always calling
back into the service when we attempt a connection.
2024-01-19 16:32:01 +01:00
cloudhead 0fbfbc5721
Make sure `preferredSeeds` has a default
If the user already has a config, the preferred seeds list is not
populated. We fix that here by giving it a default value.
2024-01-19 16:30:24 +01:00
cloudhead ebdaf0edd9
General dependency update
Left out some of the `gix-*` dependencies to be done separately after
review.
2024-01-18 13:30:26 +01:00
cloudhead 045b3e7175
node: Increase process ulimit on start
Users have been having issues with the process soft file limit.
We set that to a reasonably high value to avoid problems.
2024-01-17 17:34:25 +01:00
cloudhead ed006261d8
Make sure `sqlite` is always bundled
We don't want to use the system sqlite.
2024-01-17 12:12:07 +01:00
cloudhead 1e2776cb08
cli: Output explore URLs on push 2024-01-12 13:24:11 +01:00
cloudhead fd38d88e14
cli: Hint about how to start node
In some cases, we can hint to the user about how they can start their
node.

We also remove the `CallError` type that was redundant.
2024-01-12 11:20:42 +01:00
cloudhead 25ca4c8b92
node: Upgrade `netservices` and `io-reactor`
There was an issue with the old version due to the use of `RawFd` as
peer IDs, since they are not unique for the lifetime of a process.

With this change, we use the new `ResourceId` type, though these are not
immediately available, as they are generated when the resource is
registered.
2024-01-11 12:03:53 +01:00
cloudhead 073c55fa3b
node: Don't panic on initialization error 2024-01-10 15:23:05 +01:00
cloudhead c94df2d5cd
node: Make inventory announcements more robust
Allow some margin of error when sending multiple inventory announcements
at a time. Previously, they might end up with the same timestamp, so
only the first announcement would be processed by nodes. Now, we ensure
that the timestamp is updated.
2023-12-20 15:44:02 +01:00
Fintan Halpenny 47a440a384
radicle: expose shared logger
To be able to use log setup across the different components of
heartwood, expose a `logger` module from `radicle`. This also includes
a `test` logger.

These modules are guarded behind a `logger` feature flag, so that
other crates are not bringing any uneeded dependencies.

This allows logging to be setup in `radicle-cli-test` so that when a
test fails, the log output is present for debugging purposes.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-20 15:11:10 +01:00
cloudhead 9cf6fab7c8
node: Small fix to allow reconnections
We weren't allowing reconnections after a failed attempt previously.
2023-12-20 12:16:31 +01:00
Fintan Halpenny 8eac221f4c
node: Properly handle dequeued fetch results
When a peer is performing a background and foreground fetch from two
different peers, the background fetch result was being used as the
result for the foreground fetch. This results in inconsistencies,
since the foreground peer has new updates from themselves.

The reason for this issue was the fetches that were queued were not
correctly being handled, and the other peer's results were being
returned instead.

This fixes the queueing and dequeueing by ensuring that the queued
fetch occurs, passing the correct result channel. This fetch will then
be subsequently dequeued correctly and the foreground fetch obtains
the correct result.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-19 15:02:14 +01:00
Fintan Halpenny a6ba1b0103
node: inspect outdated sigrefs test
This test is flakey and requires further investigation. Some extra
assertions are added to ensure that the expected behaviour is
happening upon fetching. It is unknown if the fetch queue is behaving
properly, and it's suspected that some existing fetch results might be
used for queued fetches.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-19 15:02:14 +01:00
cloudhead 13db55014b
cli: Show URL on `rad init` 2023-12-19 14:15:30 +01:00
cloudhead 6eb2772235
node: Improve flexibility of test environment
Allows us to pass full configs (profile or node) when creating test
nodes or profiles.
2023-12-19 14:15:30 +01:00
cloudhead 6f7c2dca91
node: Introduce connection penalty system
Previously, we might ban a node if we're having trouble connecting to
it, but this could be due to internet connectivity issues.

We introduce a penalty score for nodes, that increases if there are
connection issues or the node misbehaves, and decreases on successful
connections.

When connected to new nodes, we sort them so that low-penalty nodes are
attempted first.
2023-12-15 16:00:09 +01:00
Fintan Halpenny 76c969c755
node: relax converge criteria
Some test flakes would occur due to the `converge` function looping
forever. It was noticed that in these cases the log output would look
like:

    test: Node z6MkqTKLVnFdVF24PQiDoQffbTPT7U5igghS3XWuFJLfah1P has
    {(Id(rad:z39WuDs9hrqmCr9shjoz6dn2Abqyz),
    PublicKey(z6MkemMxfWhRQFKy4UPX7FsN8GjLAZ9T65rbmDsUn7fchioP)),
    (Id(rad:z39WuDs9hrqmCr9shjoz6dn2Abqyz),
    PublicKey(z6MkpdPJp7naAurUjCpwef1BDD5jfPhAvwfinaGd7pVh227j)),
    (Id(rad:z39WuDs9hrqmCr9shjoz6dn2Abqyz),
    PublicKey(z6MkqTKLVnFdVF24PQiDoQffbTPT7U5igghS3XWuFJLfah1P))}

with further investigation, the variable `all_routes` was found to be
smaller than the calculated routes.

Instead of checking `==`, instead check that
`routes.is_superset(&all_routes)`, which means that `routes` must be
equal to `all_routes`, but allows it have extra entries.

Signed-off-by: Fintan Halpenny <Fintan Halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-14 10:52:04 +01:00
cloudhead 99aeae19ea
node: Fix node announcements not being received
Since node announcements are stored and retrieved from disk (due to the
PoW), the timestamp on it is never updated. This means it can be too old
to cache and not sent/received by nodes. Fix this by having a max age.
2023-12-14 10:41:59 +01:00
Fintan Halpenny 63469fd3bc
node: init policies DB early
Instead of creating the DB policies handle when needed, construct the
handle when the `Worker` pool is being constructed.

This replaces the usage of the DB handle with the `Worker`'s field
instead.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-13 14:20:15 +01:00
Fintan Halpenny e894b6512d
node: prevent fetch response if no repo policy
If a node had removed a seeding policy and another node fetched from
it, then it would perform the fetch.

Instead, check the policy during the authorization step and prevent
the fetch is the resulting policy is `Block`.

Note that the policy will be `Block` iff the `Block` policy was
specifically set or the `Block` is the default policy for the node.

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-13 14:19:46 +01:00
Fintan Halpenny 9f544ef8c1
nix: switch to use nix flakes
Nix Flakes[[0]] are a more modular way of expressing nix derivations.

The `flake.nix` file describes:
- How to build the project, or components of a projet, via `nix build`
- What "checks" can run for a project, which can be executed via
  `nix flake check`
- What binaries can be run, e.g. `nix run .#rad` to execute the CLI

This approach is preferable since a lot of the Nix ecosystem is using
Flakes -- despite it still being marked as experimental.

One interesting benefit, that needs confirming, is that a check can be
run from a remote Git source. So if someone creates a patch on
Radicle, someone else with the `nix` binary can execute:

         nix flake check git+https://app.radicle.xyz/nodes/seed.radicle.xyz/rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5?refs=patches/<patch id>

This means that anyone with `nix` can check patches without having to
fetch the patch itself.

Another obvious benefit will be that it allows the Radicle binaries to
enter the Nix ecosystem.

The big caveat to both of the above is that, currently, the tests are
failing while running `nix flake check`. They are currently disabled
with `doCheck = false`. They are potentially failing due to some
strange sandboxing issues which are being looked into.

[0]: https://nixos.wiki/wiki/Flakes

Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com>
X-Clacks-Overhead: GNU Terry Pratchett
2023-12-13 12:25:12 +01:00
cloudhead d773659d66
cli: Don't fork on clone
Since forking creates your `rad/sigrefs`, which then needs to be backed
up forever, we avoid forking on `rad clone`. This should make little or
no difference for users, as the "fork" will be created on `git push`.
2023-12-13 12:14:06 +01:00
cloudhead bfdf82a69a
node: Small initialization changes
* Connect to nodes at the end, not the beginning
* Skip sync-status stuff if we're not seeding the repo
* Move debug message to be higher signal
2023-12-11 16:29:39 +01:00
cloudhead 6ca7da2768
radicle: Rename many more methods using new naming 2023-12-06 10:02:00 +01:00
cloudhead 1b026ae0ee
node: Rename node `tracking` module 2023-12-06 10:00:45 +01:00
cloudhead e65595c4c7
node: Rename commands with new "seed" nomenclature 2023-12-06 09:56:58 +01:00