|
|
@@ -20,6 +20,7 @@ const (
|
|
|
maxPollDelay = 10 * time.Second
|
|
|
pollDelayMultiplier = 2.0
|
|
|
pollLimit = 16
|
|
|
+ windowSize = 1000
|
|
|
)
|
|
|
|
|
|
type packet struct {
|
|
|
@@ -30,7 +31,6 @@ type packet struct {
|
|
|
type seqStatus struct {
|
|
|
needSeqByte bool
|
|
|
seqByte byte
|
|
|
- received bool
|
|
|
}
|
|
|
|
|
|
type xicmpConnClient struct {
|
|
|
@@ -129,12 +129,14 @@ func (c *xicmpConnClient) encode(p []byte) ([]byte, error) {
|
|
|
c.seqStatus[c.seq] = &seqStatus{
|
|
|
needSeqByte: needSeqByte,
|
|
|
seqByte: seqByte,
|
|
|
- received: false,
|
|
|
}
|
|
|
|
|
|
+ delete(c.seqStatus, int(uint16(c.seq-windowSize)))
|
|
|
+
|
|
|
c.seq++
|
|
|
|
|
|
if c.seq == 65536 {
|
|
|
+ delete(c.seqStatus, int(uint16(c.seq-windowSize)))
|
|
|
c.seq = 1
|
|
|
}
|
|
|
|
|
|
@@ -168,16 +170,14 @@ func (c *xicmpConnClient) recvLoop() {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
+ c.mutex.Lock()
|
|
|
seqStatus, ok := c.seqStatus[echo.Seq]
|
|
|
+ c.mutex.Unlock()
|
|
|
|
|
|
if !ok {
|
|
|
continue
|
|
|
}
|
|
|
|
|
|
- if seqStatus.received {
|
|
|
- continue
|
|
|
- }
|
|
|
-
|
|
|
if seqStatus.needSeqByte {
|
|
|
if len(echo.Data) <= 1 {
|
|
|
continue
|
|
|
@@ -189,7 +189,9 @@ func (c *xicmpConnClient) recvLoop() {
|
|
|
}
|
|
|
|
|
|
if len(echo.Data) > 0 {
|
|
|
- seqStatus.received = true
|
|
|
+ c.mutex.Lock()
|
|
|
+ delete(c.seqStatus, echo.Seq)
|
|
|
+ c.mutex.Unlock()
|
|
|
|
|
|
buf := make([]byte, len(echo.Data))
|
|
|
copy(buf, echo.Data)
|