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`.
This commit is contained in:
cloudhead 2024-01-29 16:45:21 +01:00
parent 8858cefc89
commit 3560e0066d
No known key found for this signature in database
6 changed files with 28 additions and 39 deletions

View File

@ -5,14 +5,16 @@ In its simplest form, `rad config` prints the current configuration.
$ rad config $ rad config
{ {
"publicExplorer": "https://app.radicle.xyz/nodes/$host/$rid$path", "publicExplorer": "https://app.radicle.xyz/nodes/$host/$rid$path",
"preferredSeeds": [], "preferredSeeds": [
"z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@seed.radicle.garden:8776"
],
"web": { "web": {
"pinned": { "pinned": {
"repositories": [] "repositories": []
} }
}, },
"cli": { "cli": {
"hints": false "hints": true
}, },
"node": { "node": {
"alias": "alice", "alias": "alice",
@ -23,7 +25,7 @@ $ rad config
}, },
"connect": [], "connect": [],
"externalAddresses": [], "externalAddresses": [],
"network": "test", "network": "main",
"relay": true, "relay": true,
"limits": { "limits": {
"routingMaxSize": 1000, "routingMaxSize": 1000,

View File

@ -10,7 +10,7 @@ use radicle::node::Handle as _;
use radicle::node::{Alias, DEFAULT_TIMEOUT}; use radicle::node::{Alias, DEFAULT_TIMEOUT};
use radicle::prelude::RepoId; use radicle::prelude::RepoId;
use radicle::profile; use radicle::profile;
use radicle::profile::{Home, PreferredSeeds}; use radicle::profile::Home;
use radicle::storage::{ReadStorage, RemoteRepository}; use radicle::storage::{ReadStorage, RemoteRepository};
use radicle::test::fixtures; use radicle::test::fixtures;
@ -237,7 +237,8 @@ fn rad_inspect() {
#[test] #[test]
fn rad_config() { fn rad_config() {
let mut environment = Environment::new(); let mut environment = Environment::new();
let profile = environment.profile(config::profile("alice")); let alias = Alias::new("alice");
let profile = environment.profile(profile::Config::new(alias));
let working = tempfile::tempdir().unwrap(); let working = tempfile::tempdir().unwrap();
test( test(
@ -1216,7 +1217,7 @@ fn rad_init_sync_preferred() {
.spawn(); .spawn();
let bob = environment.profile(profile::Config { let bob = environment.profile(profile::Config {
preferred_seeds: PreferredSeeds::from(vec![alice.address()]), preferred_seeds: vec![alice.address()],
..config::profile("bob") ..config::profile("bob")
}); });
let mut bob = Node::new(bob).spawn(); let mut bob = Node::new(bob).spawn();
@ -1248,7 +1249,7 @@ fn rad_init_sync_timeout() {
.spawn(); .spawn();
let bob = environment.profile(profile::Config { let bob = environment.profile(profile::Config {
preferred_seeds: PreferredSeeds::from(vec![alice.address()]), preferred_seeds: vec![alice.address()],
..config::profile("bob") ..config::profile("bob")
}); });
let mut bob = Node::new(bob).spawn(); let mut bob = Node::new(bob).spawn();
@ -1824,7 +1825,7 @@ fn rad_patch_open_explore() {
.spawn(); .spawn();
let bob = environment.profile(profile::Config { let bob = environment.profile(profile::Config {
preferred_seeds: PreferredSeeds::from(vec![seed.address()]), preferred_seeds: vec![seed.address()],
..config::profile("bob") ..config::profile("bob")
}); });
let mut bob = Node::new(bob).spawn(); let mut bob = Node::new(bob).spawn();

View File

@ -22,7 +22,7 @@ use radicle::node::Database;
use radicle::node::{Alias, POLICIES_DB_FILE}; use radicle::node::{Alias, POLICIES_DB_FILE};
use radicle::node::{ConnectOptions, Handle as _}; use radicle::node::{ConnectOptions, Handle as _};
use radicle::profile; use radicle::profile;
use radicle::profile::{Home, PreferredSeeds, Profile}; use radicle::profile::{Home, Profile};
use radicle::rad; use radicle::rad;
use radicle::storage::{ReadStorage as _, RemoteRepository as _, SignRepository as _}; use radicle::storage::{ReadStorage as _, RemoteRepository as _, SignRepository as _};
use radicle::test::fixtures; use radicle::test::fixtures;
@ -91,7 +91,7 @@ impl Environment {
node: node::Config::test(alias), node: node::Config::test(alias),
cli: cli::Config { hints: false }, cli: cli::Config { hints: false },
public_explorer: explorer::Explorer::default(), public_explorer: explorer::Explorer::default(),
preferred_seeds: PreferredSeeds::from(vec![]), preferred_seeds: vec![],
web: web::Config::default(), web: web::Config::default(),
} }
} }

View File

@ -171,7 +171,7 @@ impl KnownAddress {
pub enum Source { pub enum Source {
/// An address that was shared by another peer. /// An address that was shared by another peer.
Peer, Peer,
/// An bootstrap node address. /// A bootstrap node address.
Bootstrap, Bootstrap,
/// An address that came from some source external to the system, eg. /// An address that came from some source external to the system, eg.
/// specified by the user or added directly to the address manager. /// specified by the user or added directly to the address manager.

View File

@ -64,6 +64,14 @@ impl Network {
Self::Test => vec![], Self::Test => vec![],
} }
} }
/// Public seeds for this network.
pub fn public_seeds(&self) -> Vec<ConnectAddress> {
match self {
Self::Main => vec![seeds::RADICLE_COMMUNITY_NODE.clone()],
Self::Test => vec![],
}
}
} }
/// Configuration parameters defining attributes of minima and maxima. /// Configuration parameters defining attributes of minima and maxima.

View File

@ -14,7 +14,7 @@ use std::io::Write;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::{fs, io, str::FromStr}; use std::{fs, io, str::FromStr};
use serde::{Deserialize, Serialize}; use serde::Serialize;
use thiserror::Error; use thiserror::Error;
use crate::crypto::ssh::agent::Agent; use crate::crypto::ssh::agent::Agent;
@ -122,7 +122,7 @@ pub struct Config {
/// Preferred seeds. These seeds will be used for explorer links /// Preferred seeds. These seeds will be used for explorer links
/// and in other situations when a seed needs to be chosen. /// and in other situations when a seed needs to be chosen.
#[serde(default)] #[serde(default)]
pub preferred_seeds: PreferredSeeds, pub preferred_seeds: Vec<node::config::ConnectAddress>,
/// Web configuration. /// Web configuration.
#[serde(default)] #[serde(default)]
pub web: web::Config, pub web: web::Config,
@ -136,12 +136,14 @@ pub struct Config {
impl Config { impl Config {
/// Create a new, default configuration. /// Create a new, default configuration.
pub fn new(alias: Alias) -> Self { pub fn new(alias: Alias) -> Self {
let node = node::Config::new(alias);
Self { Self {
public_explorer: Explorer::default(), public_explorer: Explorer::default(),
preferred_seeds: PreferredSeeds::default(), preferred_seeds: node.network.public_seeds(),
web: web::Config::default(), web: web::Config::default(),
cli: cli::Config::default(), cli: cli::Config::default(),
node: node::Config::new(alias), node,
} }
} }
@ -193,30 +195,6 @@ impl Config {
} }
} }
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(transparent)]
pub struct PreferredSeeds(Vec<node::config::ConnectAddress>);
impl From<Vec<node::config::ConnectAddress>> for PreferredSeeds {
fn from(value: Vec<node::config::ConnectAddress>) -> Self {
Self(value)
}
}
impl Default for PreferredSeeds {
fn default() -> Self {
Self(vec![node::config::seeds::RADICLE_COMMUNITY_NODE.clone()])
}
}
impl std::ops::Deref for PreferredSeeds {
type Target = Vec<node::config::ConnectAddress>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Profile { pub struct Profile {
pub home: Home, pub home: Home,