Skip to content

Commit

Permalink
Merge pull request #2121 from joshuef/SimplifyNetV
Browse files Browse the repository at this point in the history
feat: remove version string restriction
  • Loading branch information
RolandSherwin authored Sep 19, 2024
2 parents 299f5fc + 2895fc9 commit d66b7d2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 44 deletions.
9 changes: 2 additions & 7 deletions sn_peers_acquisition/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,15 @@ use lazy_static::lazy_static;
use libp2p::{multiaddr::Protocol, Multiaddr};
use rand::{seq::SliceRandom, thread_rng};
use reqwest::Client;
#[cfg(feature = "network-contacts")]
use sn_protocol::version::get_network_version;
use std::time::Duration;
use tracing::*;
use url::Url;

#[cfg(feature = "network-contacts")]
lazy_static! {
// URL containing the multi-addresses of the bootstrap nodes.
pub static ref NETWORK_CONTACTS_URL: String = {
let version = get_network_version();
let version_prefix = if !version.is_empty() { format!("{version}-") } else { version.to_string() };
format!("https://sn-testnet.s3.eu-west-2.amazonaws.com/{version_prefix}network-contacts")
};
pub static ref NETWORK_CONTACTS_URL: String =
"https://sn-testnet.s3.eu-west-2.amazonaws.com/network-contacts".to_string();
}

// The maximum number of retries to be performed while trying to get peers from a URL.
Expand Down
41 changes: 4 additions & 37 deletions sn_protocol/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,69 +13,36 @@ lazy_static! {
/// The node version used during Identify Behaviour.
pub static ref IDENTIFY_NODE_VERSION_STR: String =
format!(
"safe{}/node/{}/{}",
write_network_version_with_slash(),
"safe/node/{}/{}",
get_truncate_version_str(),
get_key_version_str(),
);

/// The client version used during Identify Behaviour.
pub static ref IDENTIFY_CLIENT_VERSION_STR: String =
format!(
"safe{}/client/{}/{}",
write_network_version_with_slash(),
"safe/client/{}/{}",
get_truncate_version_str(),
get_key_version_str(),
);

/// The req/response protocol version
pub static ref REQ_RESPONSE_VERSION_STR: String =
format!(
"/safe{}/node/{}/{}",
write_network_version_with_slash(),
"/safe/node/{}/{}",
get_truncate_version_str(),
get_key_version_str(),
);

/// The identify protocol version
pub static ref IDENTIFY_PROTOCOL_STR: String =
format!(
"safe{}/{}/{}",
write_network_version_with_slash(),
"safe/{}/{}",
get_truncate_version_str(),
get_key_version_str(),
);
}

/// Get the network version string.
/// If the network version mode env variable is set to `restricted`, then the git branch is used as the version.
/// Else any non empty string is used as the version string.
/// If the env variable is empty or not set, then we do not apply any network versioning.
pub fn get_network_version() -> &'static str {
// Set this env variable to provide custom network versioning. If it is set to 'restricted', then the git branch name
// is used as the version string. Else we directly use the passed in string as the version.
match option_env!("NETWORK_VERSION_MODE") {
Some(value) => {
if value == "restricted" {
sn_build_info::git_branch()
} else {
value
}
}
_ => "",
}
}

/// Helper to write the network version with `/` appended if it is not empty
fn write_network_version_with_slash() -> String {
let version = get_network_version();
if version.is_empty() {
version.to_string()
} else {
format!("/{version}")
}
}

// Protocol support shall be downward compatible for patch only version update.
// i.e. versions of `A.B.X` or `A.B.X-alpha.Y` shall be considered as a same protocol of `A.B`
fn get_truncate_version_str() -> String {
Expand Down

0 comments on commit d66b7d2

Please sign in to comment.