• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

rng-dynamics / ping-fox / 4429964531

pending completion
4429964531

push

github

GitHub
Raise test coverage

478 of 528 relevant lines covered (90.53%)

2.98 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.3
/src/ping_data_buffer.rs
1
use crate::icmp::v4::SequenceNumber;
2
use crate::ping_error::PingError;
3
use crate::records::PingReceiveRecordData;
4
use crate::records::PingSendRecord;
5
use crate::records::PingSendRecordReceiver;
6
use crate::PingReceiveData;
7
use crate::PingResult;
8
use std::collections::HashMap;
9
use std::net::IpAddr;
10
use std::time::Instant;
11

12
pub(crate) struct PingDataBuffer {
13
    ping_send_record_rx: PingSendRecordReceiver,
14
    send_records: HashMap<(SequenceNumber, IpAddr), (usize, Instant)>,
15
}
16

17
impl PingDataBuffer {
18
    pub(crate) fn new(ping_send_record_rx: PingSendRecordReceiver) -> Self {
5✔
19
        Self { ping_send_record_rx, send_records: HashMap::new() }
5✔
20
    }
5✔
21

22
    pub(crate) fn process_send_records(&mut self) -> usize {
3✔
23
        let mut n_send_records: usize = 0;
3✔
24
        while let Ok(send_record) = self.ping_send_record_rx.try_recv() {
6✔
25
            let PingSendRecord { payload_size, ip_addr, sequence_number, send_time } = send_record;
3✔
26
            self.send_records
3✔
27
                .insert((sequence_number, ip_addr), (payload_size, send_time));
3✔
28
            n_send_records += 1;
3✔
29
        }
3✔
30
        n_send_records
3✔
31
    }
3✔
32

33
    pub(crate) fn process_receive_record(&mut self, data: &PingReceiveRecordData) -> PingResult<PingReceiveData> {
3✔
34
        let PingReceiveRecordData { package_size, ip_addr, ttl, sequence_number, receive_time } = *data;
3✔
35
        match self.send_records.get(&(sequence_number, ip_addr)) {
3✔
36
            None => Err(PingError { message: "could not find matching data in send-records buffer".to_owned() }.into()),
×
37
            Some(&(_payload_size, send_time)) => {
3✔
38
                self.send_records.remove(&(sequence_number, ip_addr));
3✔
39
                Ok(PingReceiveData {
3✔
40
                    package_size,
3✔
41
                    ip_addr,
3✔
42
                    ttl: ttl.into(),
3✔
43
                    sequence_number: sequence_number.into(),
3✔
44
                    ping_duration: receive_time - send_time,
3✔
45
                })
3✔
46
            }
47
        }
48
    }
3✔
49
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc