Skip to content

Commit

Permalink
Send empty packet if bind port and src port are different
Browse files Browse the repository at this point in the history
  • Loading branch information
inada-s committed Jul 23, 2023
1 parent a9f004b commit da36462
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion gdxsv/lbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"go.uber.org/zap"
pb "google.golang.org/protobuf/proto"
"net"
"strconv"
"strings"
"sync"
"time"
Expand Down Expand Up @@ -165,8 +166,20 @@ func (lbs *Lbs) serveUDP(port int) {
peer := lbs.FindPeer(pkt.HelloLbsData.UserId)
if peer != nil {
peer.udpAddr = *remoteAddr
logger.Info("set peer.udpAddr",
peer.logger.Info("set peer.udpAddr",
zap.String("user_id", peer.UserID), zap.String("addr", peer.udpAddr.String()))
if bindPortStr, ok := peer.PlatformInfo["udp_port"]; ok {
bindPort, err := strconv.Atoi(bindPortStr)
if err == nil && bindPort != remoteAddr.Port {
peer.logger.Info("Bind port and source port are different",
zap.Int("bind_port", bindPort), zap.Int("src_port", remoteAddr.Port))
var empty []byte
_, err = udpConn.WriteToUDP(empty, &net.UDPAddr{IP: remoteAddr.IP, Port: bindPort})
if err != nil {
peer.logger.Warn("error when sending empty message", zap.Error(err))
}
}
}
}
})
}
Expand Down

0 comments on commit da36462

Please sign in to comment.