mirror of
https://github.com/LBRYFoundation/tracker.git
synced 2025-08-30 08:51:30 +00:00
Respect a clients AF Optional Support - config driven
This commit is contained in:
parent
1d9b2bc322
commit
26de6d2e9c
2 changed files with 23 additions and 14 deletions
|
@ -45,6 +45,7 @@ type NetConfig struct {
|
||||||
AllowIPSpoofing bool `json:"allow_ip_spoofing"`
|
AllowIPSpoofing bool `json:"allow_ip_spoofing"`
|
||||||
DualStackedPeers bool `json:"dual_stacked_peers"`
|
DualStackedPeers bool `json:"dual_stacked_peers"`
|
||||||
RealIPHeader string `json:"real_ip_header"`
|
RealIPHeader string `json:"real_ip_header"`
|
||||||
|
RespectAF bool `json:"respect_af"`
|
||||||
|
|
||||||
PreferredSubnet bool `json:"preferred_subnet,omitempty"`
|
PreferredSubnet bool `json:"preferred_subnet,omitempty"`
|
||||||
PreferredIPv4Subnet int `json:"preferred_ipv4_subnet,omitempty"`
|
PreferredIPv4Subnet int `json:"preferred_ipv4_subnet,omitempty"`
|
||||||
|
@ -113,6 +114,7 @@ var DefaultConfig = Config{
|
||||||
NetConfig: NetConfig{
|
NetConfig: NetConfig{
|
||||||
AllowIPSpoofing: true,
|
AllowIPSpoofing: true,
|
||||||
DualStackedPeers: true,
|
DualStackedPeers: true,
|
||||||
|
RespectAF: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
ClientWhitelistEnabled: false,
|
ClientWhitelistEnabled: false,
|
||||||
|
|
|
@ -129,13 +129,8 @@ func (pm *PeerMap) AppendPeers(ipv4s, ipv6s PeerList, ann *Announce, wanted int)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ann.HasIPv6() && peer.HasIPv6() {
|
// Add the peers optionally respecting AF
|
||||||
ipv6s = append(ipv6s, peer)
|
appendPeers(&ipv4s, &ipv6s, ann, &peer, &count)
|
||||||
count++
|
|
||||||
} else if peer.HasIPv4() {
|
|
||||||
ipv4s = append(ipv4s, peer)
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return ipv4s, ipv6s
|
return ipv4s, ipv6s
|
||||||
|
@ -174,19 +169,31 @@ func (pm *PeerMap) AppendSubnetPeers(ipv4s, ipv6s PeerList, ann *Announce, wante
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if ann.HasIPv6() && peer.HasIPv6() {
|
// Add the peers optionally respecting AF
|
||||||
ipv6s = append(ipv6s, peer)
|
appendPeers(&ipv4s, &ipv6s, ann, &peer, &count)
|
||||||
count++
|
|
||||||
} else if peer.HasIPv4() {
|
|
||||||
ipv4s = append(ipv4s, peer)
|
|
||||||
count++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ipv4s, ipv6s
|
return ipv4s, ipv6s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optionally Respect AF for peers returned and avoid copy-pasta
|
||||||
|
func appendPeers(ipv4s, ipv6s *PeerList, ann *Announce, peer *Peer, count *int) {
|
||||||
|
// v6 to only v6 announcements
|
||||||
|
if ann.HasIPv6() && peer.HasIPv6() {
|
||||||
|
*ipv6s = append(*ipv6s, *peer)
|
||||||
|
*count++
|
||||||
|
// v4 to only dual stacked requests if we are respecting AF of annoucement
|
||||||
|
} else if ann.Config.RespectAF && ann.HasIPv4() && peer.HasIPv4() {
|
||||||
|
*ipv4s = append(*ipv4s, *peer)
|
||||||
|
*count++
|
||||||
|
// Default everything else to get IPv4 if we are not respecting AF
|
||||||
|
} else if !ann.Config.RespectAF && peer.HasIPv4() {
|
||||||
|
*ipv4s = append(*ipv4s, *peer)
|
||||||
|
*count++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// peersEquivalent checks if two peers represent the same entity.
|
// peersEquivalent checks if two peers represent the same entity.
|
||||||
func peersEquivalent(a, b *Peer) bool {
|
func peersEquivalent(a, b *Peer) bool {
|
||||||
return a.ID == b.ID || a.UserID != 0 && a.UserID == b.UserID
|
return a.ID == b.ID || a.UserID != 0 && a.UserID == b.UserID
|
||||||
|
|
Loading…
Add table
Reference in a new issue