Preemptive strike

Should that blob have been passed to a recycler, it would have
had too high a reference count.
This commit is contained in:
Greg Fitzgerald
2018-06-25 19:43:44 -06:00
committed by Greg Fitzgerald
parent 14d624ee40
commit 6e568c69a7

View File

@ -269,9 +269,10 @@ fn recv_window(
//send a contiguous set of blocks //send a contiguous set of blocks
let mut contq = VecDeque::new(); let mut contq = VecDeque::new();
while let Some(b) = dq.pop_front() { while let Some(b) = dq.pop_front() {
let b_ = b.clone(); let (pix, meta_size) = {
let p = b.write().expect("'b' write lock in fn recv_window"); let p = b.write().expect("'b' write lock in fn recv_window");
let pix = p.get_index()? as usize; (p.get_index()? as usize, p.meta.size)
};
if pix > *received { if pix > *received {
*received = pix; *received = pix;
} }
@ -288,12 +289,11 @@ fn recv_window(
//TODO, after the block are authenticated //TODO, after the block are authenticated
//if we get different blocks at the same index //if we get different blocks at the same index
//that is a network failure/attack //that is a network failure/attack
trace!("window w: {} size: {}", w, p.meta.size); trace!("window w: {} size: {}", w, meta_size);
drop(p);
{ {
let mut window = locked_window.write().unwrap(); let mut window = locked_window.write().unwrap();
if window[w].is_none() { if window[w].is_none() {
window[w] = Some(b_); window[w] = Some(b);
} else if let Some(cblob) = &window[w] { } else if let Some(cblob) = &window[w] {
if cblob.read().unwrap().get_index().unwrap() != pix as u64 { if cblob.read().unwrap().get_index().unwrap() != pix as u64 {
warn!("overrun blob at index {:}", w); warn!("overrun blob at index {:}", w);
@ -834,14 +834,15 @@ mod test {
for v in 0..10 { for v in 0..10 {
let i = 9 - v; let i = 9 - v;
let b = resp_recycler.allocate(); let b = resp_recycler.allocate();
let b_ = b.clone(); {
let mut w = b.write().unwrap(); let mut w = b.write().unwrap();
w.set_index(i).unwrap(); w.set_index(i).unwrap();
w.set_id(me_id).unwrap(); w.set_id(me_id).unwrap();
assert_eq!(i, w.get_index().unwrap()); assert_eq!(i, w.get_index().unwrap());
w.meta.size = PACKET_DATA_SIZE; w.meta.size = PACKET_DATA_SIZE;
w.meta.set_addr(&tn.data.gossip_addr); w.meta.set_addr(&tn.data.gossip_addr);
msgs.push_back(b_); }
msgs.push_back(b);
} }
s_responder.send(msgs).expect("send"); s_responder.send(msgs).expect("send");
let mut num = 0; let mut num = 0;