mirror of
https://github.com/fumiama/WireGold.git
synced 2025-09-27 03:25:54 +08:00
fix(nat): hello packet dead loop
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
package config
|
||||
|
||||
const ShowDebugLog = false
|
||||
const ShowDebugLog = true
|
||||
|
8
gold/head/hello.go
Normal file
8
gold/head/hello.go
Normal file
@@ -0,0 +1,8 @@
|
||||
package head
|
||||
|
||||
type Hello uint8
|
||||
|
||||
const (
|
||||
HelloPing Hello = iota
|
||||
HelloPong
|
||||
)
|
@@ -226,13 +226,18 @@ func (m *Me) dispatch(packet *head.Packet, addr p2p.EndPoint, index int, finish
|
||||
}
|
||||
switch packet.Proto {
|
||||
case head.ProtoHello:
|
||||
n, err := p.WriteAndPut(head.NewPacket(head.ProtoHello, m.SrcPort(), p.peerip, m.DstPort(), nil), false)
|
||||
if err == nil {
|
||||
if config.ShowDebugLog {
|
||||
logrus.Debugln("[listen] @", index, "send", n, "bytes hello ack packet")
|
||||
switch {
|
||||
case len(packet.Body()) == 0:
|
||||
logrus.Warnln("[listen] @", index, "recv old hello packet, do nothing")
|
||||
case packet.Body()[0] == byte(head.HelloPing):
|
||||
n, err := p.WriteAndPut(head.NewPacket(head.ProtoHello, m.SrcPort(), p.peerip, m.DstPort(), []byte{byte(head.HelloPong)}), false)
|
||||
if err == nil {
|
||||
logrus.Infoln("[listen] @", index, "recv hello, send", n, "bytes hello ack packet")
|
||||
} else {
|
||||
logrus.Errorln("[listen] @", index, "send hello ack packet error:", err)
|
||||
}
|
||||
} else {
|
||||
logrus.Errorln("[listen] @", index, "send hello ack packet error:", err)
|
||||
default:
|
||||
logrus.Infoln("[listen] @", index, "recv hello ack packet, do nothing")
|
||||
}
|
||||
packet.Put()
|
||||
case head.ProtoNotify:
|
||||
|
@@ -35,7 +35,7 @@ func (l *Link) keepAlive(dur int64) {
|
||||
logrus.Infoln("[nat] re-connect me succeeded")
|
||||
}
|
||||
}
|
||||
n, err := l.WriteAndPut(head.NewPacket(head.ProtoHello, l.me.srcport, l.peerip, l.me.dstport, nil), false)
|
||||
n, err := l.WriteAndPut(head.NewPacket(head.ProtoHello, l.me.srcport, l.peerip, l.me.dstport, []byte{byte(head.HelloPing)}), false)
|
||||
if err == nil {
|
||||
logrus.Infoln("[nat] send", n, "bytes keep alive packet")
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user