Remove Blobs and switch to Packets (#6937)

* Remove Blobs and switch to Packets

* Fix some gossip messages not respecting MTU size

* Failure to serialize is not fatal

* Add log macros

* Remove unused extern

* Apparently macro use is required

* Explicitly scope macro

* Fix test compile
This commit is contained in:
Sagar Dhawan
2019-11-14 10:24:53 -08:00
committed by GitHub
parent d6cbb02c92
commit f108f483b7
14 changed files with 279 additions and 712 deletions

View File

@ -5,7 +5,7 @@ use crate::{
};
use serde::Serialize;
pub use solana_sdk::packet::{Meta, Packet, PACKET_DATA_SIZE};
use std::{io, mem, net::SocketAddr};
use std::{mem, net::SocketAddr};
pub const NUM_PACKETS: usize = 1024 * 8;
@ -76,6 +76,10 @@ impl Packets {
m.meta.set_addr(&addr);
}
}
pub fn is_empty(&self) -> bool {
self.packets.is_empty()
}
}
pub fn to_packets_chunked<T: Serialize>(xs: &[T], chunks: usize) -> Vec<Packets> {
@ -84,10 +88,7 @@ pub fn to_packets_chunked<T: Serialize>(xs: &[T], chunks: usize) -> Vec<Packets>
let mut p = Packets::default();
p.packets.resize(x.len(), Packet::default());
for (i, o) in x.iter().zip(p.packets.iter_mut()) {
let mut wr = io::Cursor::new(&mut o.data[..]);
bincode::serialize_into(&mut wr, &i).expect("serialize request");
let len = wr.position() as usize;
o.meta.size = len;
Packet::populate_packet(o, None, i).expect("serialize request");
}
out.push(p);
}
@ -98,6 +99,17 @@ pub fn to_packets<T: Serialize>(xs: &[T]) -> Vec<Packets> {
to_packets_chunked(xs, NUM_PACKETS)
}
pub fn to_packets_with_destination<T: Serialize>(dests_and_data: &[(SocketAddr, T)]) -> Packets {
let mut out = Packets::default();
out.packets.resize(dests_and_data.len(), Packet::default());
for (dest_and_data, o) in dests_and_data.iter().zip(out.packets.iter_mut()) {
if let Err(e) = Packet::populate_packet(o, Some(&dest_and_data.0), &dest_and_data.1) {
error!("Couldn't write to packet {:?}. Data skipped.", e);
}
}
out
}
pub fn limited_deserialize<T>(data: &[u8]) -> bincode::Result<T>
where
T: serde::de::DeserializeOwned,