diff --git a/framemgr.go b/framemgr.go index 0ed69d5..0783151 100644 --- a/framemgr.go +++ b/framemgr.go @@ -231,6 +231,9 @@ func (fm *FrameMgr) addToRecvWin(rf *Frame) bool { if !fm.isIdInRange((int)(rf.Id), FRAME_MAX_ID) { loggo.Debug("recv frame not in range %d %d", rf.Id, fm.recvid) + if !fm.isIdOld((int)(rf.Id), FRAME_MAX_ID) { + return true + } return false } @@ -257,18 +260,6 @@ func (fm *FrameMgr) addToRecvWin(rf *Frame) bool { return true } -func (fm *FrameMgr) compareId(l int, r int) int { - - if l < fm.recvid { - l += FRAME_MAX_ID - } - if r < fm.recvid { - r += FRAME_MAX_ID - } - - return l - r -} - func (fm *FrameMgr) combineWindowToRecvBuffer() { for { @@ -401,3 +392,34 @@ func (fm *FrameMgr) isIdInRange(id int, maxid int) bool { } return false } + +func (fm *FrameMgr) compareId(l int, r int) int { + + if l < fm.recvid { + l += FRAME_MAX_ID + } + if r < fm.recvid { + r += FRAME_MAX_ID + } + + return l - r +} + +func (fm *FrameMgr) isIdOld(id int, maxid int) bool { + if id > fm.recvid { + return false + } + + end := fm.recvid + fm.windowsize*2 + if end >= maxid { + if id >= end-maxid && id < fm.recvid { + return true + } + } else { + if id < fm.recvid { + return true + } + } + + return false +} diff --git a/pingtunnel_test.go b/pingtunnel_test.go index ded56f2..3a51a2b 100644 --- a/pingtunnel_test.go +++ b/pingtunnel_test.go @@ -79,4 +79,16 @@ func Test0001(t *testing.T) { fm.recvid = 10 fm.windowsize = 10000 fmt.Println("fm.isIdInRange = ", fm.isIdInRange(0, FRAME_MAX_ID)) + + fm.recvid = 7 + fm.windowsize = 5 + fmt.Println("fm.isIdOld = ", fm.isIdOld(2, 10)) + + fm.recvid = 7 + fm.windowsize = 5 + fmt.Println("fm.isIdOld = ", fm.isIdOld(1, 10)) + + fm.recvid = 3 + fm.windowsize = 5 + fmt.Println("fm.isIdOld = ", fm.isIdOld(1, 10)) }