diff --git a/Cargo.lock b/Cargo.lock index 8afcd1f638451b..b35807952526ff 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1475,14 +1475,38 @@ dependencies = [ "zeroize", ] +[[package]] +name = "darling" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d706e75d87e35569db781a9b5e2416cff1236a47ed380831f959382ccd5f858" +dependencies = [ + "darling_core 0.10.2", + "darling_macro 0.10.2", +] + [[package]] name = "darling" version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0558d22a7b463ed0241e993f76f09f30b126687447751a8638587b864e4b3944" dependencies = [ - "darling_core", - "darling_macro", + "darling_core 0.20.1", + "darling_macro 0.20.1", +] + +[[package]] +name = "darling_core" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0c960ae2da4de88a91b2d920c2a7233b400bc33cb28453a2987822d8392519b" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim 0.9.3", + "syn 1.0.109", ] [[package]] @@ -1499,13 +1523,24 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "darling_macro" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9b5a2f4ac4969822c62224815d069952656cadc7084fdca9751e6d959189b72" +dependencies = [ + "darling_core 0.10.2", + "quote", + "syn 1.0.109", +] + [[package]] name = "darling_macro" version = "0.20.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "29a358ff9f12ec09c3e61fef9b5a9902623a695a46a917b07f269bff1445611a" dependencies = [ - "darling_core", + "darling_core 0.20.1", "quote", "syn 2.0.38", ] @@ -1578,6 +1613,31 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "derive_builder" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2658621297f2cf68762a6f7dc0bb7e1ff2cfd6583daef8ee0fed6f7ec468ec0" +dependencies = [ + "darling 0.10.2", + "derive_builder_core", + "proc-macro2", + "quote", + "syn 1.0.109", +] + +[[package]] +name = "derive_builder_core" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2791ea3e372c8495c0bc2033991d76b512cd799d07491fbd6890124db9458bef" +dependencies = [ + "darling 0.10.2", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "derive_more" version = "0.99.16" @@ -1702,6 +1762,18 @@ dependencies = [ "syn 2.0.38", ] +[[package]] +name = "dns-lookup" +version = "1.0.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53ecafc952c4528d9b51a458d1a8904b81783feff9fde08ab6ed2545ff396872" +dependencies = [ + "cfg-if 1.0.0", + "libc", + "socket2 0.4.9", + "winapi 0.3.9", +] + [[package]] name = "doc-comment" version = "0.3.3" @@ -1782,6 +1854,24 @@ dependencies = [ "cfg-if 1.0.0", ] +[[package]] +name = "endian-type" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c34f04666d835ff5d62e058c3995147c06f42fe86ff053337632bca83e42702d" + +[[package]] +name = "enum-as-inner" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "570d109b813e904becc80d8d5da38376818a143348413f7149f1340fe04754d4" +dependencies = [ + "heck", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "enum-iterator" version = "1.4.1" @@ -2561,6 +2651,20 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "hyper-system-resolver" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eea26c5d0b6ab9d72219f65000af310f042a740926f7b2fa3553e774036e2e7" +dependencies = [ + "derive_builder", + "dns-lookup", + "hyper", + "tokio", + "tower-service", + "tracing", +] + [[package]] name = "hyper-timeout" version = "0.4.1" @@ -2616,6 +2720,17 @@ dependencies = [ "unicode-normalization", ] +[[package]] +name = "idna" +version = "0.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" +dependencies = [ + "matches", + "unicode-bidi", + "unicode-normalization", +] + [[package]] name = "idna" version = "0.4.0" @@ -3280,6 +3395,15 @@ dependencies = [ "winapi 0.3.9", ] +[[package]] +name = "nibble_vec" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77a5d83df9f36fe23f0c3648c6bbb8b0298bb5f1939c8f2704431371f4b84d43" +dependencies = [ + "smallvec", +] + [[package]] name = "nix" version = "0.26.4" @@ -4155,6 +4279,27 @@ dependencies = [ "autotools", ] +[[package]] +name = "public-ip" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7b4c40db5262d93298c363a299f8bc1b3a956a78eecddba3bc0e58b76e2f419a" +dependencies = [ + "dns-lookup", + "futures-core", + "futures-util", + "http", + "hyper", + "hyper-system-resolver", + "pin-project-lite", + "thiserror", + "tokio", + "tracing", + "tracing-futures", + "trust-dns-client", + "trust-dns-proto", +] + [[package]] name = "qstring" version = "0.7.2" @@ -4238,6 +4383,16 @@ dependencies = [ "proc-macro2", ] +[[package]] +name = "radix_trie" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c069c179fcdc6a2fe24d8d18305cf085fdbd4f922c041943e203685d6a1c58fd" +dependencies = [ + "endian-type", + "nibble_vec", +] + [[package]] name = "rand" version = "0.4.6" @@ -4900,7 +5055,7 @@ version = "2.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "881b6f881b17d13214e5d494c939ebab463d01264ce1811e9d4ac3a882e7695f" dependencies = [ - "darling", + "darling 0.20.1", "proc-macro2", "quote", "syn 2.0.38", @@ -5569,6 +5724,7 @@ dependencies = [ "hyper", "hyper-staticfile", "log", + "public-ip", "rustc_version 0.4.0", "serde", "serde_json", @@ -7966,6 +8122,12 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" +[[package]] +name = "strsim" +version = "0.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6446ced80d6c486436db5c078dde11a9f73d42b57fb273121e160b84f63d894c" + [[package]] name = "strsim" version = "0.10.0" @@ -8631,6 +8793,18 @@ dependencies = [ "lazy_static", ] +[[package]] +name = "tracing-futures" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97d095ae15e245a057c8e8451bab9b3ee1e1f68e9ba2b4fbc18d0ac5237835f2" +dependencies = [ + "futures 0.3.28", + "futures-task", + "pin-project", + "tracing", +] + [[package]] name = "tracing-opentelemetry" version = "0.17.2" @@ -8660,6 +8834,51 @@ version = "0.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0de5f738ceab88e2491a94ddc33c3feeadfa95fedc60363ef110845df12f3878" +[[package]] +name = "trust-dns-client" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5b4ef9b9bde0559b78a4abb00339143750085f05e5a453efb7b8bef1061f09dc" +dependencies = [ + "cfg-if 1.0.0", + "data-encoding", + "futures-channel", + "futures-util", + "lazy_static", + "log", + "radix_trie", + "rand 0.8.5", + "thiserror", + "time", + "tokio", + "trust-dns-proto", +] + +[[package]] +name = "trust-dns-proto" +version = "0.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca94d4e9feb6a181c690c4040d7a24ef34018d8313ac5044a61d21222ae24e31" +dependencies = [ + "async-trait", + "cfg-if 1.0.0", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.2.3", + "ipnet", + "lazy_static", + "log", + "rand 0.8.5", + "smallvec", + "thiserror", + "tinyvec", + "tokio", + "url 2.4.1", +] + [[package]] name = "try-lock" version = "0.2.3" diff --git a/Cargo.toml b/Cargo.toml index 509ffb6047ac9e..d45ac175886528 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -268,6 +268,7 @@ prost = "0.11.9" prost-build = "0.11.9" prost-types = "0.11.9" protobuf-src = "1.1.0" +public-ip = "0.2.2" qstring = "0.7.2" qualifier_attr = { version = "0.2.2", default-features = false } quinn = "0.10.2" diff --git a/cargo-registry/Cargo.toml b/cargo-registry/Cargo.toml index 43aed1f4fa2097..dbaefa64f5d719 100644 --- a/cargo-registry/Cargo.toml +++ b/cargo-registry/Cargo.toml @@ -16,6 +16,7 @@ git2 = { workspace = true } hyper = { workspace = true, features = ["full"] } hyper-staticfile = { workspace = true } log = { workspace = true } +public-ip = { workspace = true } serde = { workspace = true, features = ["derive"] } serde_json = { workspace = true } solana-clap-utils = { workspace = true } diff --git a/cargo-registry/src/client.rs b/cargo-registry/src/client.rs index 17432f0ebe27cd..5763276b906fa2 100644 --- a/cargo-registry/src/client.rs +++ b/cargo-registry/src/client.rs @@ -37,6 +37,7 @@ impl<'a> ClientConfig<'a> { pub struct Client { pub rpc_client: Arc, pub port: u16, + pub use_public_ip: bool, websocket_url: String, commitment: commitment_config::CommitmentConfig, cli_signers: Vec, @@ -112,6 +113,13 @@ impl Client { .takes_value(true) .help("Cargo registry's local TCP port. The server will bind to this port and wait for requests."), ) + .arg( + Arg::with_name("use_public_ip") + .long("public-ip") + .global(true) + .takes_value(false) + .help("Should the registry server use public IP"), + ) .arg( Arg::with_name("commitment") .long("commitment") @@ -192,6 +200,8 @@ impl Client { let port = value_t_or_exit!(matches, "port", u16); + let use_public_ip = matches.is_present("use_public_ip"); + Ok(Client { rpc_client: Arc::new(RpcClient::new_with_timeouts_and_commitment( json_rpc_url.to_string(), @@ -200,6 +210,7 @@ impl Client { confirm_transaction_initial_timeout, )), port, + use_public_ip, websocket_url, commitment, cli_signers: vec![payer_keypair, authority_keypair], diff --git a/cargo-registry/src/main.rs b/cargo-registry/src/main.rs index 0749875824c072..d416fe40ecf040 100644 --- a/cargo-registry/src/main.rs +++ b/cargo-registry/src/main.rs @@ -306,7 +306,22 @@ impl CargoRegistryService { async fn main() { solana_logger::setup_with_default("solana=info"); let client = Arc::new(Client::new().expect("Failed to get RPC Client instance")); - let port = client.port; + + // Use "INADDR_ANY" IP address for server bind() + let bind_addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), client.port); + + // If requested, configure index to use the public IP address + if client.use_public_ip { + let Some(ip) = public_ip::addr().await else { + panic!("Failed to find the public IP address"); + }; + DummyGitIndex::create_or_update_git_repo( + PathBuf::from("/tmp/dummy-git"), + &SocketAddr::new(ip, client.port), + ); + } else { + DummyGitIndex::create_or_update_git_repo(PathBuf::from("/tmp/dummy-git"), &bind_addr); + }; let registry_service = make_service_fn(move |_| { let client_inner = client.clone(); @@ -317,11 +332,8 @@ async fn main() { } }); - let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(0, 0, 0, 0)), port); - DummyGitIndex::create_or_update_git_repo(PathBuf::from("/tmp/dummy-git"), &addr); - - let server = Server::bind(&addr).serve(registry_service); - info!("Server running on on http://{}", addr); + let server = Server::bind(&bind_addr).serve(registry_service); + info!("Server running on on http://{}", bind_addr); let _ = server.await; }