mirror of
https://github.com/fumiama/WireGold.git
synced 2026-06-13 05:31:08 +08:00
fix(link): trans handling
This commit is contained in:
@@ -98,47 +98,55 @@ func (m *Me) wait(data []byte, addr p2p.EndPoint) (h head.PacketBytes) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ok := false
|
||||||
header.B(func(buf []byte, p *head.Packet) {
|
header.B(func(buf []byte, p *head.Packet) {
|
||||||
peer := m.extractPeer(p.Src(), p.Dst(), addr)
|
peer := m.extractPeer(p.Src(), p.Dst(), addr)
|
||||||
if peer == nil {
|
if peer == nil {
|
||||||
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !peer.IsToMe(p.Dst()) { // 提前处理转发
|
if !peer.IsToMe(p.Dst()) { // 提前处理转发
|
||||||
if !peer.allowtrans {
|
if !peer.allowtrans {
|
||||||
logrus.Warnln("[recv] refused to trans packet to", p.Dst().String()+":"+strconv.Itoa(int(p.DstPort)))
|
logrus.Warnln("[recv] refused to trans packet to", p.Dst().String()+":"+strconv.Itoa(int(p.DstPort)))
|
||||||
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// 转发
|
// 转发
|
||||||
lnk := m.router.NextHop(p.Dst().String())
|
lnk := m.router.NextHop(p.Dst().String())
|
||||||
if lnk == nil {
|
if lnk == nil {
|
||||||
logrus.Warnln("[recv] transfer drop packet: nil nexthop")
|
logrus.Warnln("[recv] transfer drop packet: nil nexthop")
|
||||||
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if head.DecTTL(data) { // need drop
|
if head.DecTTL(data) { // need drop
|
||||||
logrus.Warnln("[recv] transfer drop packet: zero ttl")
|
logrus.Warnln("[recv] transfer drop packet: zero ttl")
|
||||||
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
go lnk.write2peer(pbuf.ParseBytes(data...).Copy(), seq)
|
go lnk.write2peer(pbuf.ParseBytes(data...).Copy(), seq)
|
||||||
if config.ShowDebugLog {
|
if config.ShowDebugLog {
|
||||||
logrus.Debugln("[listen] trans", len(data), "bytes packet to", p.Dst().String()+":"+strconv.Itoa(int(p.DstPort)))
|
logrus.Debugln("[listen] trans", len(data), "bytes packet to", p.Dst().String()+":"+strconv.Itoa(int(p.DstPort)))
|
||||||
}
|
}
|
||||||
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if !p.Proto.HasMore() {
|
if !p.Proto.HasMore() {
|
||||||
ok := p.WriteDataSegment(data, buf)
|
ok := p.WriteDataSegment(data, buf)
|
||||||
if !ok {
|
if !ok {
|
||||||
logrus.Errorln("[recv]", strconv.FormatUint(uint64(seq), 16), "unexpected !ok")
|
logrus.Errorln("[recv]", strconv.FormatUint(uint64(seq), 16), "unexpected !ok")
|
||||||
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if config.ShowDebugLog {
|
if config.ShowDebugLog {
|
||||||
logrus.Debugln("[recv]", strconv.FormatUint(uint64(seq), 16), len(data), "bytes full data waited")
|
logrus.Debugln("[recv]", strconv.FormatUint(uint64(seq), 16), len(data), "bytes full data waited")
|
||||||
}
|
}
|
||||||
h = header
|
h = header
|
||||||
|
ok = true
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
if h.HasInit() {
|
if ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +157,7 @@ func (m *Me) wait(data []byte, addr p2p.EndPoint) (h head.PacketBytes) {
|
|||||||
if config.ShowDebugLog {
|
if config.ShowDebugLog {
|
||||||
logrus.Debugln("[recv]", strconv.FormatUint(uint64(seq&0xffff), 16), "get frag part isnew:", !got)
|
logrus.Debugln("[recv]", strconv.FormatUint(uint64(seq&0xffff), 16), "get frag part isnew:", !got)
|
||||||
}
|
}
|
||||||
ok := false
|
ok = false
|
||||||
h.B(func(buf []byte, p *head.Packet) {
|
h.B(func(buf []byte, p *head.Packet) {
|
||||||
ok = p.WriteDataSegment(data, buf)
|
ok = p.WriteDataSegment(data, buf)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|||||||
Reference in New Issue
Block a user