mirror of
https://github.com/DNSCrypt/dnscrypt-proxy.git
synced 2025-04-06 14:47:35 +03:00
Only find the farthest route on wildcards
This commit is contained in:
parent
0f54b2b34c
commit
1e10251407
1 changed files with 18 additions and 2 deletions
|
@ -323,8 +323,10 @@ func route(proxy *Proxy, name string) (*Relay, error) {
|
||||||
if routes == nil {
|
if routes == nil {
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
wildcard := false
|
||||||
relayNames, ok := (*routes)[name]
|
relayNames, ok := (*routes)[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
wildcard = true
|
||||||
relayNames, ok = (*routes)["*"]
|
relayNames, ok = (*routes)["*"]
|
||||||
}
|
}
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -338,6 +340,8 @@ func route(proxy *Proxy, name string) (*Relay, error) {
|
||||||
for _, registeredServer := range proxy.registeredRelays {
|
for _, registeredServer := range proxy.registeredRelays {
|
||||||
relayStamps = append(relayStamps, registeredServer.stamp)
|
relayStamps = append(relayStamps, registeredServer.stamp)
|
||||||
}
|
}
|
||||||
|
wildcard = true
|
||||||
|
break
|
||||||
} else {
|
} else {
|
||||||
for _, registeredServer := range proxy.registeredRelays {
|
for _, registeredServer := range proxy.registeredRelays {
|
||||||
if registeredServer.name == relayName {
|
if registeredServer.name == relayName {
|
||||||
|
@ -356,10 +360,22 @@ func route(proxy *Proxy, name string) (*Relay, error) {
|
||||||
if len(relayStamps) == 0 {
|
if len(relayStamps) == 0 {
|
||||||
return nil, fmt.Errorf("Empty relay set for [%v]", name)
|
return nil, fmt.Errorf("Empty relay set for [%v]", name)
|
||||||
}
|
}
|
||||||
relayCandidateStamp := findFarthestRoute(proxy, name, relayStamps)
|
var relayCandidateStamp *stamps.ServerStamp
|
||||||
|
if !wildcard || len(relayStamps) == 1 {
|
||||||
|
relayCandidateStamp = &relayStamps[rand.Intn(len(relayStamps))]
|
||||||
|
} else {
|
||||||
|
relayCandidateStamp = findFarthestRoute(proxy, name, relayStamps)
|
||||||
|
}
|
||||||
if relayCandidateStamp == nil {
|
if relayCandidateStamp == nil {
|
||||||
return nil, fmt.Errorf("No valid relay for server [%v]", name)
|
return nil, fmt.Errorf("No valid relay for server [%v]", name)
|
||||||
}
|
}
|
||||||
|
relayName := relayCandidateStamp.ServerAddrStr
|
||||||
|
for _, registeredServer := range proxy.registeredRelays {
|
||||||
|
if registeredServer.stamp.ServerAddrStr == relayCandidateStamp.ServerAddrStr {
|
||||||
|
relayName = registeredServer.name
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
switch relayCandidateStamp.Proto {
|
switch relayCandidateStamp.Proto {
|
||||||
case stamps.StampProtoTypeDNSCrypt, stamps.StampProtoTypeDNSCryptRelay:
|
case stamps.StampProtoTypeDNSCrypt, stamps.StampProtoTypeDNSCryptRelay:
|
||||||
relayUDPAddr, err := net.ResolveUDPAddr("udp", relayCandidateStamp.ServerAddrStr)
|
relayUDPAddr, err := net.ResolveUDPAddr("udp", relayCandidateStamp.ServerAddrStr)
|
||||||
|
@ -370,7 +386,7 @@ func route(proxy *Proxy, name string) (*Relay, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
dlog.Noticef("Anonymizing queries for [%v] via [%v]", name, relayCandidateStamp.ServerAddrStr)
|
dlog.Noticef("Anonymizing queries for [%v] via [%v]", name, relayName)
|
||||||
return &Relay{Proto: stamps.StampProtoTypeDNSCryptRelay, Dnscrypt: &DNSCryptRelay{RelayUDPAddr: relayUDPAddr, RelayTCPAddr: relayTCPAddr}}, nil
|
return &Relay{Proto: stamps.StampProtoTypeDNSCryptRelay, Dnscrypt: &DNSCryptRelay{RelayUDPAddr: relayUDPAddr, RelayTCPAddr: relayTCPAddr}}, nil
|
||||||
case stamps.StampProtoTypeODoHRelay:
|
case stamps.StampProtoTypeODoHRelay:
|
||||||
return &Relay{Proto: stamps.StampProtoTypeODoHRelay, ODoH: &ODoHRelay{}}, nil
|
return &Relay{Proto: stamps.StampProtoTypeODoHRelay, ODoH: &ODoHRelay{}}, nil
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue