Move src/netutil.rs into its own crate
This commit is contained in:
		
							
								
								
									
										17
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										17
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							| @@ -1744,13 +1744,11 @@ dependencies = [ | |||||||
|  "hashbrown 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", |  "hashbrown 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", |  "hex-literal 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", |  "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", |  | ||||||
|  "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", |  "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", |  "libc 0.2.45 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", |  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", |  "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", |  "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "pnet_datalink 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", |  | ||||||
|  "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", |  "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", |  "rand_chacha 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", |  "rayon 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
| @@ -1777,6 +1775,7 @@ dependencies = [ | |||||||
|  "solana-lualoader 0.11.0", |  "solana-lualoader 0.11.0", | ||||||
|  "solana-metrics 0.11.0", |  "solana-metrics 0.11.0", | ||||||
|  "solana-native-loader 0.11.0", |  "solana-native-loader 0.11.0", | ||||||
|  |  "solana-netutil 0.11.0", | ||||||
|  "solana-noop 0.11.0", |  "solana-noop 0.11.0", | ||||||
|  "solana-sdk 0.11.0", |  "solana-sdk 0.11.0", | ||||||
|  "solana-storage-program 0.11.0", |  "solana-storage-program 0.11.0", | ||||||
| @@ -2113,6 +2112,20 @@ dependencies = [ | |||||||
|  "solana-sdk 0.11.0", |  "solana-sdk 0.11.0", | ||||||
| ] | ] | ||||||
|  |  | ||||||
|  | [[package]] | ||||||
|  | name = "solana-netutil" | ||||||
|  | version = "0.11.0" | ||||||
|  | dependencies = [ | ||||||
|  |  "ipnetwork 0.12.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  |  "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  |  "nix 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  |  "pnet_datalink 0.21.0 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  |  "rand 0.6.1 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  |  "reqwest 0.9.5 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  |  "socket2 0.3.8 (registry+https://github.com/rust-lang/crates.io-index)", | ||||||
|  |  "solana-logger 0.11.0", | ||||||
|  | ] | ||||||
|  |  | ||||||
| [[package]] | [[package]] | ||||||
| name = "solana-noop" | name = "solana-noop" | ||||||
| version = "0.11.0" | version = "0.11.0" | ||||||
|   | |||||||
| @@ -34,13 +34,11 @@ dirs = "1.0.2" | |||||||
| generic-array = { version = "0.12.0", default-features = false, features = ["serde"] } | generic-array = { version = "0.12.0", default-features = false, features = ["serde"] } | ||||||
| hex-literal = "0.1.1" | hex-literal = "0.1.1" | ||||||
| indexmap = "1.0" | indexmap = "1.0" | ||||||
| ipnetwork = "0.12.7" |  | ||||||
| itertools = "0.8.0" | itertools = "0.8.0" | ||||||
| libc = "0.2.45" | libc = "0.2.45" | ||||||
| log = "0.4.2" | log = "0.4.2" | ||||||
| matches = "0.1.6" | matches = "0.1.6" | ||||||
| nix = "0.12.0" | nix = "0.12.0" | ||||||
| pnet_datalink = "0.21.0" |  | ||||||
| rand = "0.6.1" | rand = "0.6.1" | ||||||
| rand_chacha = "0.1.0" | rand_chacha = "0.1.0" | ||||||
| rayon = "1.0.0" | rayon = "1.0.0" | ||||||
| @@ -67,6 +65,7 @@ solana-logger = { path = "logger", version = "0.11.0" } | |||||||
| solana-lualoader = { path = "programs/native/lua_loader", version = "0.11.0" } | solana-lualoader = { path = "programs/native/lua_loader", version = "0.11.0" } | ||||||
| solana-metrics = { path = "metrics", version = "0.11.0" } | solana-metrics = { path = "metrics", version = "0.11.0" } | ||||||
| solana-native-loader = { path = "programs/native/native_loader", version = "0.11.0" } | solana-native-loader = { path = "programs/native/native_loader", version = "0.11.0" } | ||||||
|  | solana-netutil = { path = "netutil", version = "0.11.0" } | ||||||
| solana-noop = { path = "programs/native/noop", version = "0.11.0" } | solana-noop = { path = "programs/native/noop", version = "0.11.0" } | ||||||
| solana-sdk = { path = "sdk", version = "0.11.0" } | solana-sdk = { path = "sdk", version = "0.11.0" } | ||||||
| solana-storage-program = { path = "programs/native/storage", version = "0.11.0" } | solana-storage-program = { path = "programs/native/storage", version = "0.11.0" } | ||||||
|   | |||||||
| @@ -12,6 +12,7 @@ cd "$(dirname "$0")/.." | |||||||
| # | # | ||||||
| CRATES=( | CRATES=( | ||||||
|   logger |   logger | ||||||
|  |   netutil | ||||||
|   sdk |   sdk | ||||||
|   keygen |   keygen | ||||||
|   metrics |   metrics | ||||||
|   | |||||||
							
								
								
									
										24
									
								
								netutil/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								netutil/Cargo.toml
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,24 @@ | |||||||
|  | [package] | ||||||
|  | name = "solana-netutil" | ||||||
|  | version = "0.11.0" | ||||||
|  | description = "Solana Network Utilities" | ||||||
|  | authors = ["Solana Maintainers <maintainers@solana.com>"] | ||||||
|  | repository = "https://github.com/solana-labs/solana" | ||||||
|  | license = "Apache-2.0" | ||||||
|  | homepage = "https://solana.com/" | ||||||
|  | edition = "2018" | ||||||
|  |  | ||||||
|  | [dependencies] | ||||||
|  | log = "0.4.2" | ||||||
|  | ipnetwork = "0.12.7" | ||||||
|  | nix = "0.12.0" | ||||||
|  | pnet_datalink = "0.21.0" | ||||||
|  | rand = "0.6.1" | ||||||
|  | reqwest = "0.9.0" | ||||||
|  | socket2 = "0.3.8" | ||||||
|  |  | ||||||
|  | [dev-dependencies] | ||||||
|  | solana-logger = { path = "../logger", version = "0.11.0" } | ||||||
|  |  | ||||||
|  | [lib] | ||||||
|  | name = "solana_netutil" | ||||||
| @@ -1,5 +1,5 @@ | |||||||
| //! The `netutil` module assists with networking
 | //! The `netutil` module assists with networking
 | ||||||
| 
 | use log::trace; | ||||||
| use nix::sys::socket::setsockopt; | use nix::sys::socket::setsockopt; | ||||||
| use nix::sys::socket::sockopt::{ReuseAddr, ReusePort}; | use nix::sys::socket::sockopt::{ReuseAddr, ReusePort}; | ||||||
| use pnet_datalink as datalink; | use pnet_datalink as datalink; | ||||||
| @@ -203,10 +203,8 @@ pub fn find_available_port_in_range(range: (u16, u16)) -> io::Result<u16> { | |||||||
| 
 | 
 | ||||||
| #[cfg(test)] | #[cfg(test)] | ||||||
| mod tests { | mod tests { | ||||||
| 
 |     use super::*; | ||||||
|     use crate::netutil::*; |  | ||||||
|     use ipnetwork::IpNetwork; |     use ipnetwork::IpNetwork; | ||||||
|     use pnet_datalink as datalink; |  | ||||||
| 
 | 
 | ||||||
|     #[test] |     #[test] | ||||||
|     fn test_find_eth0ish_ip_addr() { |     fn test_find_eth0ish_ip_addr() { | ||||||
| @@ -1,8 +1,7 @@ | |||||||
| use crate::cluster_info::{NodeInfo, FULLNODE_PORT_RANGE}; | use crate::cluster_info::{NodeInfo, FULLNODE_PORT_RANGE}; | ||||||
| use crate::netutil::bind_in_range; |  | ||||||
| use crate::thin_client::ThinClient; | use crate::thin_client::ThinClient; | ||||||
|  |  | ||||||
| pub fn mk_client(r: &NodeInfo) -> ThinClient { | pub fn mk_client(r: &NodeInfo) -> ThinClient { | ||||||
|     let (_, transactions_socket) = bind_in_range(FULLNODE_PORT_RANGE).unwrap(); |     let (_, transactions_socket) = solana_netutil::bind_in_range(FULLNODE_PORT_RANGE).unwrap(); | ||||||
|     ThinClient::new(r.rpc, r.tpu, transactions_socket) |     ThinClient::new(r.rpc, r.tpu, transactions_socket) | ||||||
| } | } | ||||||
|   | |||||||
| @@ -20,7 +20,6 @@ use crate::crds_gossip_error::CrdsGossipError; | |||||||
| use crate::crds_gossip_pull::CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS; | use crate::crds_gossip_pull::CRDS_GOSSIP_PULL_CRDS_TIMEOUT_MS; | ||||||
| use crate::crds_value::{CrdsValue, CrdsValueLabel, LeaderId}; | use crate::crds_value::{CrdsValue, CrdsValueLabel, LeaderId}; | ||||||
| use crate::db_ledger::{DbLedger, LedgerColumnFamily, MetaCf, DEFAULT_SLOT_HEIGHT}; | use crate::db_ledger::{DbLedger, LedgerColumnFamily, MetaCf, DEFAULT_SLOT_HEIGHT}; | ||||||
| use crate::netutil::{bind_in_range, bind_to, find_available_port_in_range, multi_bind_in_range}; |  | ||||||
| use crate::packet::{to_blob, Blob, SharedBlob, BLOB_SIZE}; | use crate::packet::{to_blob, Blob, SharedBlob, BLOB_SIZE}; | ||||||
| use crate::result::Result; | use crate::result::Result; | ||||||
| use crate::rpc::RPC_PORT; | use crate::rpc::RPC_PORT; | ||||||
| @@ -32,6 +31,7 @@ use log::Level; | |||||||
| use rand::{thread_rng, Rng}; | use rand::{thread_rng, Rng}; | ||||||
| use rayon::prelude::*; | use rayon::prelude::*; | ||||||
| use solana_metrics::{influxdb, submit}; | use solana_metrics::{influxdb, submit}; | ||||||
|  | use solana_netutil::{bind_in_range, bind_to, find_available_port_in_range, multi_bind_in_range}; | ||||||
| use solana_sdk::hash::Hash; | use solana_sdk::hash::Hash; | ||||||
| use solana_sdk::pubkey::Pubkey; | use solana_sdk::pubkey::Pubkey; | ||||||
| use solana_sdk::signature::{Keypair, KeypairUtil, Signable, Signature}; | use solana_sdk::signature::{Keypair, KeypairUtil, Signable, Signature}; | ||||||
|   | |||||||
| @@ -43,7 +43,6 @@ pub mod leader_scheduler; | |||||||
| pub mod ledger; | pub mod ledger; | ||||||
| pub mod ledger_write_stage; | pub mod ledger_write_stage; | ||||||
| pub mod mint; | pub mod mint; | ||||||
| pub mod netutil; |  | ||||||
| pub mod packet; | pub mod packet; | ||||||
| pub mod poh; | pub mod poh; | ||||||
| pub mod poh_recorder; | pub mod poh_recorder; | ||||||
|   | |||||||
| @@ -107,7 +107,7 @@ mod tests { | |||||||
|     use super::*; |     use super::*; | ||||||
|     use crate::cluster_info::ClusterInfo; |     use crate::cluster_info::ClusterInfo; | ||||||
|     use crate::contact_info::ContactInfo; |     use crate::contact_info::ContactInfo; | ||||||
|     use crate::netutil::bind_in_range; |     use solana_netutil::bind_in_range; | ||||||
|     use solana_sdk::pubkey::Pubkey; |     use solana_sdk::pubkey::Pubkey; | ||||||
|     use std::net::UdpSocket; |     use std::net::UdpSocket; | ||||||
|     use std::net::{Ipv4Addr, SocketAddr}; |     use std::net::{Ipv4Addr, SocketAddr}; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user