mirror of
https://github.com/p4gefau1t/trojan-go.git
synced 2024-04-21 12:21:34 +00:00
Feat: change the default behavior of IPOnDemand domain strategy (#329)
Co-authored-by: Loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com>
This commit is contained in:
co-authored by
Loyalsoldier
parent
5f0a25def0
commit
63d0f73d72
+25
-30
@@ -131,45 +131,40 @@ type Client struct {
|
||||
}
|
||||
|
||||
func (c *Client) Route(address *tunnel.Address) int {
|
||||
policy := -1
|
||||
var err error
|
||||
if c.domainStrategy == IPOnDemand {
|
||||
address, err = newIPAddress(address)
|
||||
if err != nil {
|
||||
return c.defaultPolicy
|
||||
}
|
||||
}
|
||||
if address.AddressType == tunnel.DomainName {
|
||||
for i := 0; i < 3; i++ {
|
||||
if c.domainStrategy == IPOnDemand {
|
||||
resolvedIP, err := newIPAddress(address)
|
||||
if err == nil {
|
||||
for i := Block; i <= Proxy; i++ {
|
||||
if matchIP(c.cidrs[i], resolvedIP.IP) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for i := Block; i <= Proxy; i++ {
|
||||
if matchDomain(c.domains[i], address.DomainName) {
|
||||
policy = i
|
||||
break
|
||||
return i
|
||||
}
|
||||
}
|
||||
if c.domainStrategy == IPIfNonMatch {
|
||||
resolvedIP, err := newIPAddress(address)
|
||||
if err == nil {
|
||||
for i := Block; i <= Proxy; i++ {
|
||||
if matchIP(c.cidrs[i], resolvedIP.IP) {
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := Block; i <= Proxy; i++ {
|
||||
if matchIP(c.cidrs[i], address.IP) {
|
||||
policy = i
|
||||
break
|
||||
return i
|
||||
}
|
||||
}
|
||||
}
|
||||
if policy == -1 && c.domainStrategy == IPIfNonMatch {
|
||||
address, err = newIPAddress(address)
|
||||
if err != nil {
|
||||
return c.defaultPolicy
|
||||
}
|
||||
for i := 0; i < 3; i++ {
|
||||
if matchIP(c.cidrs[i], address.IP) {
|
||||
policy = i
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if policy == -1 {
|
||||
policy = c.defaultPolicy
|
||||
}
|
||||
return policy
|
||||
return c.defaultPolicy
|
||||
}
|
||||
|
||||
func (c *Client) DialConn(address *tunnel.Address, overlay tunnel.Tunnel) (tunnel.Conn, error) {
|
||||
|
||||
Reference in New Issue
Block a user