56
56
solana_measure:: measure:: Measure ,
57
57
solana_net_utils:: {
58
58
bind_common, bind_common_in_range, bind_in_range, bind_in_range_with_config,
59
- bind_more_with_config, bind_two_in_range_with_offset_and_config ,
60
- find_available_port_in_range , multi_bind_in_range , PortRange , SocketConfig ,
61
- VALIDATOR_PORT_RANGE ,
59
+ bind_more_with_config, bind_to_localhost , bind_to_unspecified ,
60
+ bind_two_in_range_with_offset_and_config , find_available_port_in_range ,
61
+ multi_bind_in_range , PortRange , SocketConfig , VALIDATOR_PORT_RANGE ,
62
62
} ,
63
63
solana_perf:: {
64
64
data_budget:: DataBudget ,
@@ -224,7 +224,7 @@ impl ClusterInfo {
224
224
GOSSIP_PING_CACHE_CAPACITY ,
225
225
) ) ,
226
226
stats : GossipStats :: default ( ) ,
227
- socket : UdpSocket :: bind ( "0.0.0.0:0" ) . unwrap ( ) ,
227
+ socket : bind_to_unspecified ( ) . unwrap ( ) ,
228
228
local_message_pending_push_queue : Mutex :: default ( ) ,
229
229
contact_debug_interval : DEFAULT_CONTACT_DEBUG_INTERVAL_MILLIS ,
230
230
instance : RwLock :: new ( NodeInstance :: new ( & mut thread_rng ( ) , id, timestamp ( ) ) ) ,
@@ -2626,8 +2626,6 @@ impl Node {
2626
2626
num_quic_endpoints : usize ,
2627
2627
) -> Self {
2628
2628
let localhost_ip_addr = IpAddr :: V4 ( Ipv4Addr :: LOCALHOST ) ;
2629
- let localhost_bind_addr = format ! ( "{localhost_ip_addr:?}:0" ) ;
2630
- let unspecified_bind_addr = format ! ( "{:?}:0" , IpAddr :: V4 ( Ipv4Addr :: UNSPECIFIED ) ) ;
2631
2629
let port_range = ( 1024 , 65535 ) ;
2632
2630
2633
2631
let udp_config = SocketConfig { reuseport : false } ;
@@ -2646,8 +2644,8 @@ impl Node {
2646
2644
let ( gossip_port, ( gossip, ip_echo) ) =
2647
2645
bind_common_in_range ( localhost_ip_addr, port_range) . unwrap ( ) ;
2648
2646
let gossip_addr = SocketAddr :: new ( localhost_ip_addr, gossip_port) ;
2649
- let tvu = UdpSocket :: bind ( & localhost_bind_addr ) . unwrap ( ) ;
2650
- let tvu_quic = UdpSocket :: bind ( & localhost_bind_addr ) . unwrap ( ) ;
2647
+ let tvu = bind_to_localhost ( ) . unwrap ( ) ;
2648
+ let tvu_quic = bind_to_localhost ( ) . unwrap ( ) ;
2651
2649
let ( ( _tpu_forwards_port, tpu_forwards) , ( _tpu_forwards_quic_port, tpu_forwards_quic) ) =
2652
2650
bind_two_in_range_with_offset_and_config (
2653
2651
localhost_ip_addr,
@@ -2660,24 +2658,23 @@ impl Node {
2660
2658
let tpu_forwards_quic =
2661
2659
bind_more_with_config ( tpu_forwards_quic, num_quic_endpoints, quic_config. clone ( ) )
2662
2660
. unwrap ( ) ;
2663
- let tpu_vote = UdpSocket :: bind ( & localhost_bind_addr) . unwrap ( ) ;
2664
- let tpu_vote_quic = UdpSocket :: bind ( & localhost_bind_addr) . unwrap ( ) ;
2665
-
2661
+ let tpu_vote = bind_to_localhost ( ) . unwrap ( ) ;
2662
+ let tpu_vote_quic = bind_to_localhost ( ) . unwrap ( ) ;
2666
2663
let tpu_vote_quic =
2667
2664
bind_more_with_config ( tpu_vote_quic, num_quic_endpoints, quic_config) . unwrap ( ) ;
2668
2665
2669
- let repair = UdpSocket :: bind ( & localhost_bind_addr ) . unwrap ( ) ;
2670
- let repair_quic = UdpSocket :: bind ( & localhost_bind_addr ) . unwrap ( ) ;
2666
+ let repair = bind_to_localhost ( ) . unwrap ( ) ;
2667
+ let repair_quic = bind_to_localhost ( ) . unwrap ( ) ;
2671
2668
let rpc_port = find_available_port_in_range ( localhost_ip_addr, port_range) . unwrap ( ) ;
2672
2669
let rpc_addr = SocketAddr :: new ( localhost_ip_addr, rpc_port) ;
2673
2670
let rpc_pubsub_port = find_available_port_in_range ( localhost_ip_addr, port_range) . unwrap ( ) ;
2674
2671
let rpc_pubsub_addr = SocketAddr :: new ( localhost_ip_addr, rpc_pubsub_port) ;
2675
- let broadcast = vec ! [ UdpSocket :: bind ( & unspecified_bind_addr ) . unwrap( ) ] ;
2676
- let retransmit_socket = UdpSocket :: bind ( & unspecified_bind_addr ) . unwrap ( ) ;
2677
- let serve_repair = UdpSocket :: bind ( & localhost_bind_addr ) . unwrap ( ) ;
2678
- let serve_repair_quic = UdpSocket :: bind ( & localhost_bind_addr ) . unwrap ( ) ;
2679
- let ancestor_hashes_requests = UdpSocket :: bind ( & unspecified_bind_addr ) . unwrap ( ) ;
2680
- let ancestor_hashes_requests_quic = UdpSocket :: bind ( & unspecified_bind_addr ) . unwrap ( ) ;
2672
+ let broadcast = vec ! [ bind_to_unspecified ( ) . unwrap( ) ] ;
2673
+ let retransmit_socket = bind_to_unspecified ( ) . unwrap ( ) ;
2674
+ let serve_repair = bind_to_localhost ( ) . unwrap ( ) ;
2675
+ let serve_repair_quic = bind_to_localhost ( ) . unwrap ( ) ;
2676
+ let ancestor_hashes_requests = bind_to_unspecified ( ) . unwrap ( ) ;
2677
+ let ancestor_hashes_requests_quic = bind_to_unspecified ( ) . unwrap ( ) ;
2681
2678
2682
2679
let mut info = ContactInfo :: new (
2683
2680
* pubkey,
@@ -3019,7 +3016,7 @@ pub fn push_messages_to_peer(
3019
3016
"push_messages_to_peer" ,
3020
3017
& reqs,
3021
3018
) ;
3022
- let sock = UdpSocket :: bind ( "0.0.0.0:0" ) . unwrap ( ) ;
3019
+ let sock = bind_to_unspecified ( ) . unwrap ( ) ;
3023
3020
packet:: send_to ( & packet_batch, & sock, socket_addr_space) ?;
3024
3021
Ok ( ( ) )
3025
3022
}
@@ -3152,6 +3149,7 @@ mod tests {
3152
3149
} ,
3153
3150
itertools:: izip,
3154
3151
solana_ledger:: shred:: Shredder ,
3152
+ solana_net_utils:: bind_to,
3155
3153
solana_sdk:: signature:: { Keypair , Signer } ,
3156
3154
solana_vote_program:: { vote_instruction, vote_state:: Vote } ,
3157
3155
std:: {
@@ -4395,7 +4393,12 @@ mod tests {
4395
4393
4396
4394
let cluster_info44 = Arc :: new ( {
4397
4395
let mut node = Node :: new_localhost_with_pubkey ( & keypair44. pubkey ( ) ) ;
4398
- node. sockets . gossip = UdpSocket :: bind ( "127.0.0.1:65534" ) . unwrap ( ) ;
4396
+ node. sockets . gossip = bind_to (
4397
+ IpAddr :: V4 ( Ipv4Addr :: LOCALHOST ) ,
4398
+ /*port*/ 65534 ,
4399
+ /*reuseport:*/ false ,
4400
+ )
4401
+ . unwrap ( ) ;
4399
4402
info ! ( "{:?}" , node) ;
4400
4403
ClusterInfo :: new ( node. info , keypair44. clone ( ) , SocketAddrSpace :: Unspecified )
4401
4404
} ) ;
0 commit comments