Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions bench-streamer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
use {
clap::{crate_description, crate_name, value_t_or_exit, Arg, Command},
crossbeam_channel::unbounded,
solana_net_utils::{bind_to_unspecified, SocketConfig},
solana_net_utils::{
bind_to_unspecified,
sockets::{multi_bind_in_range_with_config, SocketConfiguration},
},
solana_streamer::{
packet::{Packet, PacketBatchRecycler, PinnedPacketBatch, PACKET_DATA_SIZE},
sendmmsg::batch_send,
Expand Down Expand Up @@ -104,10 +107,10 @@ fn main() -> Result<()> {

let port = 0;
let ip_addr = IpAddr::V4(Ipv4Addr::UNSPECIFIED);
let (_port, read_sockets) = solana_net_utils::multi_bind_in_range_with_config(
let (_port, read_sockets) = multi_bind_in_range_with_config(
ip_addr,
(port, port + num_sockets as u16),
SocketConfig::default().reuseport(true),
SocketConfiguration::default(),
num_sockets,
)
.unwrap();
Expand Down
9 changes: 6 additions & 3 deletions bench-vote/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@ use {
solana_hash::Hash,
solana_keypair::Keypair,
solana_message::Message,
solana_net_utils::{bind_to_unspecified, SocketConfig},
solana_net_utils::{
bind_to_unspecified,
sockets::{multi_bind_in_range_with_config, SocketConfiguration as SocketConfig},
},
solana_pubkey::Pubkey,
solana_signer::Signer,
solana_streamer::{
Expand Down Expand Up @@ -187,8 +190,8 @@ fn main() -> Result<()> {
let mut read_channels = Vec::new();
let mut read_threads = Vec::new();
let recycler = PacketBatchRecycler::default();
let config = SocketConfig::default().reuseport(true);
let (port, read_sockets) = solana_net_utils::multi_bind_in_range_with_config(
let config = SocketConfig::default();
let (port, read_sockets) = multi_bind_in_range_with_config(
ip_addr,
(port, port + num_sockets as u16),
config,
Expand Down
8 changes: 5 additions & 3 deletions connection-cache/src/connection_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,9 @@ mod tests {
async_trait::async_trait,
rand::{Rng, SeedableRng},
rand_chacha::ChaChaRng,
solana_net_utils::SocketConfig,
solana_net_utils::sockets::{
bind_with_any_port_with_config, SocketConfiguration as SocketConfig,
},
solana_transaction_error::TransportResult,
std::{
net::{IpAddr, Ipv4Addr, SocketAddr, UdpSocket},
Expand Down Expand Up @@ -572,7 +574,7 @@ mod tests {
fn default() -> Self {
Self {
udp_socket: Arc::new(
solana_net_utils::bind_with_any_port_with_config(
bind_with_any_port_with_config(
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
SocketConfig::default(),
)
Expand All @@ -586,7 +588,7 @@ mod tests {
fn new() -> Result<Self, ClientError> {
Ok(Self {
udp_socket: Arc::new(
solana_net_utils::bind_with_any_port_with_config(
bind_with_any_port_with_config(
IpAddr::V4(Ipv4Addr::UNSPECIFIED),
SocketConfig::default(),
)
Expand Down
4 changes: 2 additions & 2 deletions docs/src/validator/tvu.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ Internally, TVU is actually bound with multiple sockets to improve kernel's hand

> **NOTE:** TPU sockets use similar logic

A node advertises one external ip/port for TVU while binding multiple sockets to that same port using SO_REUSEPORT:
A node advertises one external ip/port for TVU while binding multiple sockets to that same port:

```rust
let (tvu_port, tvu_sockets) = multi_bind_in_range_with_config(
bind_ip_addr,
port_range,
socket_config_reuseport,
socket_config,
num_tvu_sockets.get(),
)
.expect("tvu multi_bind");
Expand Down
78 changes: 31 additions & 47 deletions gossip/src/cluster_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,14 @@ use {
solana_keypair::{signable::Signable, Keypair},
solana_ledger::shred::Shred,
solana_net_utils::{
bind_common_in_range_with_config, bind_in_range, bind_in_range_with_config,
bind_more_with_config, bind_to_localhost, bind_to_unspecified, bind_to_with_config,
bind_two_in_range_with_offset_and_config, find_available_ports_in_range,
multi_bind_in_range_with_config,
sockets::{bind_gossip_port_in_range, localhost_port_range_for_tests},
PortRange, SocketConfig, VALIDATOR_PORT_RANGE,
bind_in_range, bind_to_localhost, bind_to_unspecified, find_available_ports_in_range,
sockets::{
bind_common_in_range_with_config, bind_gossip_port_in_range, bind_in_range_with_config,
bind_more_with_config, bind_to_with_config, bind_two_in_range_with_offset_and_config,
localhost_port_range_for_tests, multi_bind_in_range_with_config,
SocketConfiguration as SocketConfig,
},
PortRange, VALIDATOR_PORT_RANGE,
},
solana_perf::{
data_budget::DataBudget,
Expand Down Expand Up @@ -2368,7 +2370,7 @@ impl Node {
let localhost_ip_addr = IpAddr::V4(Ipv4Addr::LOCALHOST);
let port_range = localhost_port_range_for_tests();
let udp_config = SocketConfig::default();
let quic_config = SocketConfig::default().reuseport(true);
let quic_config = SocketConfig::default();
let ((_tpu_port, tpu), (_tpu_quic_port, tpu_quic)) =
bind_two_in_range_with_offset_and_config(
localhost_ip_addr,
Expand Down Expand Up @@ -2520,7 +2522,6 @@ impl Node {
bind_gossip_port_in_range(gossip_addr, port_range, bind_ip_addr);

let socket_config = SocketConfig::default();
let socket_config_reuseport = SocketConfig::default().reuseport(true);
let (tvu_port, tvu) = Self::bind_with_config(bind_ip_addr, port_range, socket_config);
let (tvu_quic_port, tvu_quic) =
Self::bind_with_config(bind_ip_addr, port_range, socket_config);
Expand All @@ -2530,39 +2531,31 @@ impl Node {
port_range,
QUIC_PORT_OFFSET,
socket_config,
socket_config_reuseport,
socket_config,
)
.unwrap();
let tpu_quic: Vec<UdpSocket> =
bind_more_with_config(tpu_quic, DEFAULT_QUIC_ENDPOINTS, socket_config_reuseport)
.unwrap();
bind_more_with_config(tpu_quic, DEFAULT_QUIC_ENDPOINTS, socket_config).unwrap();

let ((tpu_forwards_port, tpu_forwards), (_tpu_forwards_quic_port, tpu_forwards_quic)) =
bind_two_in_range_with_offset_and_config(
bind_ip_addr,
port_range,
QUIC_PORT_OFFSET,
socket_config,
socket_config_reuseport,
socket_config,
)
.unwrap();
let tpu_forwards_quic = bind_more_with_config(
tpu_forwards_quic,
DEFAULT_QUIC_ENDPOINTS,
socket_config_reuseport,
)
.unwrap();
let tpu_forwards_quic =
bind_more_with_config(tpu_forwards_quic, DEFAULT_QUIC_ENDPOINTS, socket_config)
.unwrap();

let (tpu_vote_port, tpu_vote) =
Self::bind_with_config(bind_ip_addr, port_range, socket_config);
let (tpu_vote_quic_port, tpu_vote_quic) =
Self::bind_with_config(bind_ip_addr, port_range, socket_config);
let tpu_vote_quic: Vec<UdpSocket> = bind_more_with_config(
tpu_vote_quic,
DEFAULT_QUIC_ENDPOINTS,
socket_config_reuseport,
)
.unwrap();
let tpu_vote_quic: Vec<UdpSocket> =
bind_more_with_config(tpu_vote_quic, DEFAULT_QUIC_ENDPOINTS, socket_config).unwrap();

let (_, retransmit_socket) =
Self::bind_with_config(bind_ip_addr, port_range, socket_config);
Expand Down Expand Up @@ -2674,12 +2667,11 @@ impl Node {
bind_gossip_port_in_range(&gossip_addr, port_range, bind_ip_addr);

let socket_config = SocketConfig::default();
let socket_config_reuseport = SocketConfig::default().reuseport(true);

let (tvu_port, tvu_sockets) = multi_bind_in_range_with_config(
bind_ip_addr,
port_range,
socket_config_reuseport,
socket_config,
num_tvu_receive_sockets.get(),
)
.expect("tvu multi_bind");
Expand All @@ -2688,20 +2680,19 @@ impl Node {
Self::bind_with_config(bind_ip_addr, port_range, socket_config);

let (tpu_port, tpu_sockets) =
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config_reuseport, 32)
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config, 32)
.expect("tpu multi_bind");

let (_tpu_port_quic, tpu_quic) = Self::bind_with_config(
bind_ip_addr,
(tpu_port + QUIC_PORT_OFFSET, tpu_port + QUIC_PORT_OFFSET + 1),
socket_config_reuseport,
socket_config,
);
let tpu_quic =
bind_more_with_config(tpu_quic, num_quic_endpoints.get(), socket_config_reuseport)
.unwrap();
bind_more_with_config(tpu_quic, num_quic_endpoints.get(), socket_config).unwrap();

let (tpu_forwards_port, tpu_forwards_sockets) =
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config_reuseport, 8)
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config, 8)
.expect("tpu_forwards multi_bind");

let (_tpu_forwards_port_quic, tpu_forwards_quic) = Self::bind_with_config(
Expand All @@ -2710,33 +2701,26 @@ impl Node {
tpu_forwards_port + QUIC_PORT_OFFSET,
tpu_forwards_port + QUIC_PORT_OFFSET + 1,
),
socket_config_reuseport,
socket_config,
);
let tpu_forwards_quic = bind_more_with_config(
tpu_forwards_quic,
num_quic_endpoints.get(),
socket_config_reuseport,
)
.unwrap();
let tpu_forwards_quic =
bind_more_with_config(tpu_forwards_quic, num_quic_endpoints.get(), socket_config)
.unwrap();

let (tpu_vote_port, tpu_vote_sockets) =
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config_reuseport, 1)
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config, 1)
.expect("tpu_vote multi_bind");

let (tpu_vote_quic_port, tpu_vote_quic) =
Self::bind_with_config(bind_ip_addr, port_range, socket_config);

let tpu_vote_quic = bind_more_with_config(
tpu_vote_quic,
num_quic_endpoints.get(),
socket_config_reuseport,
)
.unwrap();
let tpu_vote_quic =
bind_more_with_config(tpu_vote_quic, num_quic_endpoints.get(), socket_config).unwrap();

let (_, retransmit_sockets) = multi_bind_in_range_with_config(
bind_ip_addr,
port_range,
socket_config_reuseport,
socket_config,
num_tvu_retransmit_sockets.get(),
)
.expect("retransmit multi_bind");
Expand All @@ -2750,7 +2734,7 @@ impl Node {
Self::bind_with_config(bind_ip_addr, port_range, socket_config);

let (_, broadcast) =
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config_reuseport, 4)
multi_bind_in_range_with_config(bind_ip_addr, port_range, socket_config, 4)
.expect("broadcast multi_bind");

let (_, ancestor_hashes_requests) =
Expand Down
Loading
Loading