XICMP finalmask: Refine seq (#5652)

Example: https://github.com/XTLS/Xray-core/pull/5633#issue-3881559866
This commit is contained in:
LjhAUMEM
2026-02-06 16:44:50 +08:00
committed by GitHub
parent 0710c2b195
commit 957e5a6b15

View File

@@ -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)