uses std::net::IpAddr type for Packet.Meta.addr
This commit is contained in:
parent
aa9f7ed7e8
commit
73a7741c49
|
@ -37,7 +37,7 @@ fn bench_packet_discard(bencher: &mut Bencher) {
|
||||||
.map(|_| {
|
.map(|_| {
|
||||||
let mut addr = [0u16; 8];
|
let mut addr = [0u16; 8];
|
||||||
thread_rng().fill(&mut addr);
|
thread_rng().fill(&mut addr);
|
||||||
addr
|
std::net::IpAddr::from(addr)
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
|
|
|
@ -286,7 +286,7 @@ mod tests {
|
||||||
solana_logger::setup();
|
solana_logger::setup();
|
||||||
let mut batch = PacketBatch::default();
|
let mut batch = PacketBatch::default();
|
||||||
batch.packets.resize(10, Packet::default());
|
batch.packets.resize(10, Packet::default());
|
||||||
batch.packets[3].meta.addr = [1u16; 8];
|
batch.packets[3].meta.addr = std::net::IpAddr::from([1u16; 8]);
|
||||||
let mut batches = vec![batch];
|
let mut batches = vec![batch];
|
||||||
let max = 3;
|
let max = 3;
|
||||||
SigVerifyStage::discard_excess_packets(&mut batches, max);
|
SigVerifyStage::discard_excess_packets(&mut batches, max);
|
||||||
|
|
|
@ -3,7 +3,7 @@ use {
|
||||||
serde::Serialize,
|
serde::Serialize,
|
||||||
std::{
|
std::{
|
||||||
fmt, io,
|
fmt, io,
|
||||||
net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr},
|
net::{IpAddr, Ipv4Addr, SocketAddr},
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -13,16 +13,15 @@ use {
|
||||||
/// 8 bytes is the size of the fragment header
|
/// 8 bytes is the size of the fragment header
|
||||||
pub const PACKET_DATA_SIZE: usize = 1280 - 40 - 8;
|
pub const PACKET_DATA_SIZE: usize = 1280 - 40 - 8;
|
||||||
|
|
||||||
#[derive(Clone, Default, Debug, PartialEq)]
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
pub struct Meta {
|
pub struct Meta {
|
||||||
pub size: usize,
|
pub size: usize,
|
||||||
pub forwarded: bool,
|
pub forwarded: bool,
|
||||||
pub repair: bool,
|
pub repair: bool,
|
||||||
pub discard: bool,
|
pub discard: bool,
|
||||||
pub addr: [u16; 8],
|
pub addr: IpAddr,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
pub v6: bool,
|
|
||||||
pub is_tracer_tx: bool,
|
pub is_tracer_tx: bool,
|
||||||
pub is_simple_vote_tx: bool,
|
pub is_simple_vote_tx: bool,
|
||||||
}
|
}
|
||||||
|
@ -92,40 +91,26 @@ impl PartialEq for Packet {
|
||||||
|
|
||||||
impl Meta {
|
impl Meta {
|
||||||
pub fn addr(&self) -> SocketAddr {
|
pub fn addr(&self) -> SocketAddr {
|
||||||
if !self.v6 {
|
SocketAddr::new(self.addr, self.port)
|
||||||
let addr = [
|
|
||||||
self.addr[0] as u8,
|
|
||||||
self.addr[1] as u8,
|
|
||||||
self.addr[2] as u8,
|
|
||||||
self.addr[3] as u8,
|
|
||||||
];
|
|
||||||
let ipv4: Ipv4Addr = From::<[u8; 4]>::from(addr);
|
|
||||||
SocketAddr::new(IpAddr::V4(ipv4), self.port)
|
|
||||||
} else {
|
|
||||||
let ipv6: Ipv6Addr = From::<[u16; 8]>::from(self.addr);
|
|
||||||
SocketAddr::new(IpAddr::V6(ipv6), self.port)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_addr(&mut self, a: &SocketAddr) {
|
pub fn set_addr(&mut self, socket_addr: &SocketAddr) {
|
||||||
match *a {
|
self.addr = socket_addr.ip();
|
||||||
SocketAddr::V4(v4) => {
|
self.port = socket_addr.port();
|
||||||
let ip = v4.ip().octets();
|
}
|
||||||
self.addr[0] = u16::from(ip[0]);
|
}
|
||||||
self.addr[1] = u16::from(ip[1]);
|
|
||||||
self.addr[2] = u16::from(ip[2]);
|
impl Default for Meta {
|
||||||
self.addr[3] = u16::from(ip[3]);
|
fn default() -> Self {
|
||||||
self.addr[4] = 0;
|
Self {
|
||||||
self.addr[5] = 0;
|
size: 0,
|
||||||
self.addr[6] = 0;
|
forwarded: false,
|
||||||
self.addr[7] = 0;
|
repair: false,
|
||||||
self.v6 = false;
|
discard: false,
|
||||||
}
|
addr: IpAddr::V4(Ipv4Addr::UNSPECIFIED),
|
||||||
SocketAddr::V6(v6) => {
|
port: 0,
|
||||||
self.addr = v6.ip().segments();
|
is_tracer_tx: false,
|
||||||
self.v6 = true;
|
is_simple_vote_tx: false,
|
||||||
}
|
}
|
||||||
}
|
|
||||||
self.port = a.port();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,7 @@ use {
|
||||||
std::{
|
std::{
|
||||||
cmp::Reverse,
|
cmp::Reverse,
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
net::UdpSocket,
|
net::{IpAddr, UdpSocket},
|
||||||
sync::{
|
sync::{
|
||||||
atomic::{AtomicBool, Ordering},
|
atomic::{AtomicBool, Ordering},
|
||||||
mpsc::{Receiver, RecvTimeoutError, SendError, Sender},
|
mpsc::{Receiver, RecvTimeoutError, SendError, Sender},
|
||||||
|
@ -130,14 +130,14 @@ struct SendStats {
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct StreamerSendStats {
|
struct StreamerSendStats {
|
||||||
host_map: HashMap<[u16; 8], SendStats>,
|
host_map: HashMap<IpAddr, SendStats>,
|
||||||
since: Option<Instant>,
|
since: Option<Instant>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl StreamerSendStats {
|
impl StreamerSendStats {
|
||||||
fn report_stats(
|
fn report_stats(
|
||||||
name: &'static str,
|
name: &'static str,
|
||||||
host_map: HashMap<[u16; 8], SendStats>,
|
host_map: HashMap<IpAddr, SendStats>,
|
||||||
sample_duration: Option<Duration>,
|
sample_duration: Option<Duration>,
|
||||||
) {
|
) {
|
||||||
const MAX_REPORT_ENTRIES: usize = 5;
|
const MAX_REPORT_ENTRIES: usize = 5;
|
||||||
|
|
Loading…
Reference in New Issue