Skip to content
This repository has been archived by the owner on Nov 5, 2021. It is now read-only.

Commit

Permalink
ping.recvPackets: Don't reset the read buffer to a smaller buffer aft…
Browse files Browse the repository at this point in the history
…er reading every packet.

Instead, keep the read buffer same and use truncated bytes slice for data. See the following github issue for details:
#225

PiperOrigin-RevId: 239456052
  • Loading branch information
manugarg committed Mar 20, 2019
1 parent 11ff080 commit 930c4ac
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions probes/ping/ping.go
Expand Up @@ -325,7 +325,7 @@ func (p *Probe) recvPackets(runID uint16, tracker chan bool) {
}

// Read packet from the socket
n, peer, err := p.conn.read(pktbuf)
pktLen, peer, err := p.conn.read(pktbuf)

if err != nil {
p.l.Warning(err.Error())
Expand All @@ -335,12 +335,10 @@ func (p *Probe) recvPackets(runID uint16, tracker chan bool) {
}
continue
}
if n < minPacketSize {
p.l.Warning("packet too small: size (", strconv.FormatInt(int64(n), 10), ") < minPacketSize (16)")
if pktLen < minPacketSize {
p.l.Warning("packet too small: size (", strconv.FormatInt(int64(pktLen), 10), ") < minPacketSize (16), from peer: ", peer.String())
continue
}
// Reset pktbuf to only read bytes
pktbuf = pktbuf[:n]

// Record fetch time before further processing.
fetchTime := time.Now()
Expand Down Expand Up @@ -368,7 +366,7 @@ func (p *Probe) recvPackets(runID uint16, tracker chan bool) {
// ICMP packet body starts from the 5th byte
id: binary.BigEndian.Uint16(pktbuf[4:6]),
seq: binary.BigEndian.Uint16(pktbuf[6:8]),
data: pktbuf[8:],
data: pktbuf[8:pktLen],
}

rtt := time.Duration(pkt.tsUnix-bytesToTime(pkt.data)) * time.Nanosecond
Expand Down

0 comments on commit 930c4ac

Please sign in to comment.