1
0
mirror of https://github.com/fumiama/WireGold.git synced 2026-06-07 17:00:24 +08:00
Files
WireGold/gold/link/nat.go
2022-01-01 15:14:17 +08:00

26 lines
558 B
Go

package link
import (
"time"
"github.com/sirupsen/logrus"
"github.com/fumiama/WireGold/gold/head"
)
// 保持 NAT
func (l *Link) keepAlive() {
if l.keepalive > 0 {
logrus.Infoln("[link.nat] start to keep alive")
t := time.NewTicker(time.Second * time.Duration(l.keepalive))
for range t.C {
n, err := l.Write(head.NewPacket(head.ProtoHello, 0, l.peerip, 0, nil), false)
if err == nil {
logrus.Infoln("[link] send", n, "bytes keep alive packet")
} else {
logrus.Errorln("[link] send keep alive packet error:", err)
}
}
}
}