Skip to content

Commit

Permalink
Fix p2p candidate address generation
Browse files Browse the repository at this point in the history
  • Loading branch information
inada-s committed Jul 14, 2023
1 parent 5180e2e commit bf30b74
Showing 1 changed file with 31 additions and 15 deletions.
46 changes: 31 additions & 15 deletions gdxsv/lbs_lobby.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"hash/fnv"
"io"
"math/rand"
"net"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -657,8 +658,8 @@ func (l *LbsLobby) makeP2PMatchingMsg(b *LbsBattle, participants []*LbsPeer) ([]
SessionId: int32(hash.Sum32()),
PlayerCount: int32(len(participants)),
PeerId: 0,
TimeoutMinMs: 6500,
TimeoutMaxMs: 10000,
TimeoutMinMs: 7500,
TimeoutMaxMs: 7500,
Candidates: nil,
RuleBin: SerializeRule(b.Rule),
Users: nil,
Expand Down Expand Up @@ -689,35 +690,50 @@ func (l *LbsLobby) makeP2PMatchingMsg(b *LbsBattle, participants []*LbsPeer) ([]
for i, p := range participants {
ips := map[string]bool{}
ports := map[string]bool{}
addrs := map[string]bool{}

ips["127.0.0.1"] = true
ips[p.IP()] = true
ips[p.PlatformInfo["local_ip"]] = true
ips[p.PlatformInfo["public_ipv4"]] = true
ips[p.PlatformInfo["public_ipv6"]] = true
ports[p.PlatformInfo["udp_port"]] = true
ports[fmt.Sprint(p.udpAddr.Port)] = true

for ip := range ips {
for port := range ports {
if ip == "" || port == "" || port == "0" {
continue
}
addrs[net.JoinHostPort(ip, port)] = true
}
}

portInt, err := strconv.ParseInt(port, 10, 32)
if err != nil {
logger.Warn("ParseInt error", zap.Error(err))
continue
}
if p.udpAddr.IP != nil {
addrs[p.udpAddr.String()] = true
}

p.udpAddr.IP.IsLoopback()

matching.Candidates = append(matching.Candidates, &proto.PlayerAddress{
UserId: p.UserID,
PeerId: int32(i),
Ip: ip,
Port: int32(portInt),
Team: int32(p.Team),
})
for addr := range addrs {
ip, port, err := net.SplitHostPort(addr)
if err != nil {
logger.Warn("net.SplitHostPort error", zap.Error(err))
continue
}

portInt, err := strconv.ParseInt(port, 10, 32)
if err != nil {
logger.Warn("ParseInt error", zap.Error(err))
continue
}

matching.Candidates = append(matching.Candidates, &proto.PlayerAddress{
UserId: p.UserID,
PeerId: int32(i),
Ip: ip,
Port: int32(portInt),
Team: int32(p.Team),
})
}
}

Expand Down

0 comments on commit bf30b74

Please sign in to comment.