1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-05 07:50:24 +08:00

fix: MTU in sendAllSameDst

This commit is contained in:
源文雨
2023-08-04 10:50:47 +08:00
parent 209c0c058a
commit 96e31e22e9
2 changed files with 7 additions and 2 deletions

View File

@@ -176,9 +176,14 @@ func (m *Me) sendAllSameDst(packet []byte) (n int) {
for len(ptr) > 20 && p.issame(ptr) {
totl := waterutil.IPv4TotalLength(ptr)
if int(totl) > len(ptr) {
logrus.Debugln("[me] wrap got invalid totl, break")
break
}
i += int(totl)
if i > int(m.mtu) {
logrus.Debugln("[me] wrap exceed mtu, break")
break
}
ptr = rem[i:]
logrus.Debugln("[me] wrap", totl, "bytes packet to send together")
}

View File

@@ -14,11 +14,11 @@ import (
func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) {
teatype := uint8(rand.Intn(16))
sndcnt := atomic.AddUintptr(&l.sendcount, 1)
logrus.Debugln("[send] count:", sndcnt, ", additional data:", uint16(sndcnt))
mtu := l.mtu
if l.mturandomrange > 0 {
mtu -= uint16(rand.Intn(int(l.mturandomrange))) & 0xfff8
}
logrus.Debugln("[send] mtu:", mtu, ", count:", sndcnt, ", additional data:", uint16(sndcnt))
if len(p.Data) <= int(mtu) {
if !istransfer {
p.FillHash()
@@ -44,7 +44,7 @@ func (l *Link) WriteAndPut(p *head.Packet, istransfer bool) (n int, err error) {
packet := head.SelectPacket()
*packet = *p
for ; int(totl)-i > int(mtu); i += int(mtu) {
logrus.Debugln("[send] split frag", i, ":", i+int(mtu), ", remain:", int(totl)-i-int(mtu))
logrus.Debugln("[send] split frag [", i, "~", i+int(mtu), "], remain:", int(totl)-i-int(mtu))
packet.Data = data[:int(mtu)]
cnt, err := l.write(packet, teatype, uint16(sndcnt), mtu, totl, uint16(i>>3), istransfer, true)
n += cnt