Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Fix preferred seeds configuration
Merged did:key:z6MksFqX...wzpT opened 2 years ago

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.

6 files changed +28 -39 8858cefc 3560e006
modified radicle-cli/examples/rad-config.md
@@ -5,14 +5,16 @@ In its simplest form, `rad config` prints the current configuration.
$ rad config
{
  "publicExplorer": "https://app.radicle.xyz/nodes/$host/$rid$path",
-
  "preferredSeeds": [],
+
  "preferredSeeds": [
+
    "z6MkrLMMsiPWUcNPHcRajuMi9mDfYckSoJyPwwnknocNYPm7@seed.radicle.garden:8776"
+
  ],
  "web": {
    "pinned": {
      "repositories": []
    }
  },
  "cli": {
-
    "hints": false
+
    "hints": true
  },
  "node": {
    "alias": "alice",
@@ -23,7 +25,7 @@ $ rad config
    },
    "connect": [],
    "externalAddresses": [],
-
    "network": "test",
+
    "network": "main",
    "relay": true,
    "limits": {
      "routingMaxSize": 1000,
modified radicle-cli/tests/commands.rs
@@ -10,7 +10,7 @@ use radicle::node::Handle as _;
use radicle::node::{Alias, DEFAULT_TIMEOUT};
use radicle::prelude::RepoId;
use radicle::profile;
-
use radicle::profile::{Home, PreferredSeeds};
+
use radicle::profile::Home;
use radicle::storage::{ReadStorage, RemoteRepository};
use radicle::test::fixtures;

@@ -237,7 +237,8 @@ fn rad_inspect() {
#[test]
fn rad_config() {
    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();

    test(
@@ -1216,7 +1217,7 @@ fn rad_init_sync_preferred() {
        .spawn();

    let bob = environment.profile(profile::Config {
-
        preferred_seeds: PreferredSeeds::from(vec![alice.address()]),
+
        preferred_seeds: vec![alice.address()],
        ..config::profile("bob")
    });
    let mut bob = Node::new(bob).spawn();
@@ -1248,7 +1249,7 @@ fn rad_init_sync_timeout() {
        .spawn();

    let bob = environment.profile(profile::Config {
-
        preferred_seeds: PreferredSeeds::from(vec![alice.address()]),
+
        preferred_seeds: vec![alice.address()],
        ..config::profile("bob")
    });
    let mut bob = Node::new(bob).spawn();
@@ -1824,7 +1825,7 @@ fn rad_patch_open_explore() {
        .spawn();

    let bob = environment.profile(profile::Config {
-
        preferred_seeds: PreferredSeeds::from(vec![seed.address()]),
+
        preferred_seeds: vec![seed.address()],
        ..config::profile("bob")
    });
    let mut bob = Node::new(bob).spawn();
modified radicle-node/src/test/environment.rs
@@ -22,7 +22,7 @@ use radicle::node::Database;
use radicle::node::{Alias, POLICIES_DB_FILE};
use radicle::node::{ConnectOptions, Handle as _};
use radicle::profile;
-
use radicle::profile::{Home, PreferredSeeds, Profile};
+
use radicle::profile::{Home, Profile};
use radicle::rad;
use radicle::storage::{ReadStorage as _, RemoteRepository as _, SignRepository as _};
use radicle::test::fixtures;
@@ -91,7 +91,7 @@ impl Environment {
            node: node::Config::test(alias),
            cli: cli::Config { hints: false },
            public_explorer: explorer::Explorer::default(),
-
            preferred_seeds: PreferredSeeds::from(vec![]),
+
            preferred_seeds: vec![],
            web: web::Config::default(),
        }
    }
modified radicle/src/node/address.rs
@@ -171,7 +171,7 @@ impl KnownAddress {
pub enum Source {
    /// An address that was shared by another peer.
    Peer,
-
    /// An bootstrap node address.
+
    /// A bootstrap node address.
    Bootstrap,
    /// An address that came from some source external to the system, eg.
    /// specified by the user or added directly to the address manager.
modified radicle/src/node/config.rs
@@ -64,6 +64,14 @@ impl Network {
            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.
modified radicle/src/profile.rs
@@ -14,7 +14,7 @@ use std::io::Write;
use std::path::{Path, PathBuf};
use std::{fs, io, str::FromStr};

-
use serde::{Deserialize, Serialize};
+
use serde::Serialize;
use thiserror::Error;

use crate::crypto::ssh::agent::Agent;
@@ -122,7 +122,7 @@ pub struct Config {
    /// Preferred seeds. These seeds will be used for explorer links
    /// and in other situations when a seed needs to be chosen.
    #[serde(default)]
-
    pub preferred_seeds: PreferredSeeds,
+
    pub preferred_seeds: Vec<node::config::ConnectAddress>,
    /// Web configuration.
    #[serde(default)]
    pub web: web::Config,
@@ -136,12 +136,14 @@ pub struct Config {
impl Config {
    /// Create a new, default configuration.
    pub fn new(alias: Alias) -> Self {
+
        let node = node::Config::new(alias);
+

        Self {
            public_explorer: Explorer::default(),
-
            preferred_seeds: PreferredSeeds::default(),
+
            preferred_seeds: node.network.public_seeds(),
            web: web::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)]
pub struct Profile {
    pub home: Home,