Optimize adopted relay name to show (#2188)

* Optimize adopted relay name to show

DNSCrypt relay requires ServerAddrStr;
ODoH relay requires ProviderName, port 443 can be either present or not;
raw stamp can be both.

Displaying specified stamp makes it easier to debug.

* Fix pasto
This commit is contained in:
lifenjoiner 2022-08-26 01:28:04 +08:00 committed by GitHub
parent 41f192a907
commit 4881186dcf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 16 deletions

View File

@ -434,16 +434,19 @@ func route(proxy *Proxy, name string, serverProto stamps.StampProtoType) (*Relay
return nil, nil return nil, nil
} }
relayStamps := make([]stamps.ServerStamp, 0) relayStamps := make([]stamps.ServerStamp, 0)
relayStampToName := make(map[string]string)
for _, relayName := range relayNames { for _, relayName := range relayNames {
if relayStamp, err := stamps.NewServerStampFromString(relayName); err == nil { if relayStamp, err := stamps.NewServerStampFromString(relayName); err == nil {
if relayStamp.Proto == relayProto { if relayStamp.Proto == relayProto {
relayStamps = append(relayStamps, relayStamp) relayStamps = append(relayStamps, relayStamp)
relayStampToName[relayStamp.String()] = relayName
} }
} else if relayName == "*" { } else if relayName == "*" {
proxy.serversInfo.RLock() proxy.serversInfo.RLock()
for _, registeredServer := range proxy.serversInfo.registeredRelays { for _, registeredServer := range proxy.serversInfo.registeredRelays {
if registeredServer.stamp.Proto == relayProto { if registeredServer.stamp.Proto == relayProto {
relayStamps = append(relayStamps, registeredServer.stamp) relayStamps = append(relayStamps, registeredServer.stamp)
relayStampToName[registeredServer.stamp.String()] = registeredServer.name
} }
} }
proxy.serversInfo.RUnlock() proxy.serversInfo.RUnlock()
@ -454,12 +457,7 @@ func route(proxy *Proxy, name string, serverProto stamps.StampProtoType) (*Relay
for _, registeredServer := range proxy.serversInfo.registeredRelays { for _, registeredServer := range proxy.serversInfo.registeredRelays {
if registeredServer.name == relayName && registeredServer.stamp.Proto == relayProto { if registeredServer.name == relayName && registeredServer.stamp.Proto == relayProto {
relayStamps = append(relayStamps, registeredServer.stamp) relayStamps = append(relayStamps, registeredServer.stamp)
break relayStampToName[registeredServer.stamp.String()] = relayName
}
}
for _, registeredServer := range proxy.serversInfo.registeredServers {
if registeredServer.name == relayName && registeredServer.stamp.Proto == relayProto {
relayStamps = append(relayStamps, registeredServer.stamp)
break break
} }
} }
@ -479,16 +477,7 @@ func route(proxy *Proxy, name string, serverProto stamps.StampProtoType) (*Relay
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 relayName := relayStampToName[relayCandidateStamp.String()]
proxy.serversInfo.RLock()
for _, registeredServer := range proxy.serversInfo.registeredRelays {
if registeredServer.stamp.Proto == relayProto &&
registeredServer.stamp.ServerAddrStr == relayCandidateStamp.ServerAddrStr {
relayName = registeredServer.name
break
}
}
proxy.serversInfo.RUnlock()
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)