mirror of
https://github.com/nadoo/glider.git
synced 2025-02-23 01:15:41 +08:00
unix: support tunnel mode (#194)
This commit is contained in:
parent
c9f3c20bc1
commit
87f1f44912
@ -26,10 +26,8 @@ forward=http://1.1.1.1:8080,socks5://2.2.2.2:1080
|
||||
# multiple upstream proxies forwad strategy
|
||||
strategy=rr
|
||||
|
||||
# Used to connect via forwarders, if the host is unreachable, the forwarder
|
||||
# will be set to disabled.
|
||||
# MUST be a HTTP website server address, format: HOST[:PORT]. HTTPS NOT SUPPORTED.
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
|
||||
# check interval
|
||||
checkinterval=30
|
||||
@ -61,7 +59,7 @@ forward=socks5://192.168.1.10:1080
|
||||
forward=ss://method:pass@1.1.1.1:8443
|
||||
forward=http://192.168.2.1:8080,socks5://192.168.2.2:1080
|
||||
strategy=rr
|
||||
checkwebsite=www.apple.com
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
# DNS SERVER for domains in this rule file
|
||||
|
@ -12,10 +12,8 @@ forward=http://1.1.1.1:8080
|
||||
# High Availability mode: ha
|
||||
strategy=rr
|
||||
|
||||
# Used to connect via forwarders, if the host is unreachable, the forwarder
|
||||
# will be set to disabled.
|
||||
# MUST be a HTTP website server address, format: HOST[:PORT]. HTTPS NOT SUPPORTED.
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
|
||||
# check interval(seconds)
|
||||
checkinterval=30
|
||||
|
@ -8,7 +8,8 @@ forward=http://1.1.1.1:8080
|
||||
# High Availability mode: ha
|
||||
strategy=rr
|
||||
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
|
||||
|
@ -13,7 +13,8 @@ forward=http://1.1.1.1:8080
|
||||
# High Availability mode: ha
|
||||
strategy=rr
|
||||
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
|
||||
|
@ -10,7 +10,8 @@ forward=http://forwarder5:8080,socks6://forwarder3:1080
|
||||
# High Availability mode: ha
|
||||
strategy=rr
|
||||
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
|
||||
|
@ -10,7 +10,8 @@ forward=http://forwarder2:8080,socks5://forwarder3:1080
|
||||
# High Availability mode: ha
|
||||
strategy=rr
|
||||
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
|
||||
|
@ -11,7 +11,6 @@ forward=http://1.1.1.1:8080
|
||||
dns=:5353
|
||||
dnsserver=8.8.8.8:53
|
||||
strategy=rr
|
||||
checkwebsite=www.apple.com
|
||||
checkinterval=30
|
||||
```
|
||||
|
||||
|
@ -12,5 +12,6 @@ dnsserver=8.8.8.8:53
|
||||
|
||||
|
||||
strategy=rr
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
@ -38,8 +38,7 @@ rules-dir=rules.d
|
||||
forward=http://forwarder1:8080,socks5://forwarder2:1080
|
||||
forward=http://1.1.1.1:8080
|
||||
strategy=rr
|
||||
checkwebsite=www.apple.com
|
||||
checkinterval=30
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
|
||||
# specify a different dns server(if need)
|
||||
dnsserver=208.67.222.222:53
|
||||
|
@ -10,7 +10,8 @@ forward=http://forwarder5:8080,socks5://forwarder3:1080
|
||||
# High Availability mode: ha
|
||||
strategy=rr
|
||||
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
# as a ipset manager
|
||||
|
@ -9,7 +9,8 @@ forward=http://forwarder2:8080,socks5://forwarder3:1080
|
||||
# Round Robin mode: rr
|
||||
# High Availability mode: ha
|
||||
strategy=rr
|
||||
checkwebsite=www.apple.com
|
||||
# forwarder health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
# specify a different dns server(if need)
|
||||
|
@ -186,10 +186,12 @@ maxfailures=3
|
||||
# ----------------
|
||||
# We can check whether a forwarder is available.
|
||||
|
||||
# Used to connect via forwarders, if the host is unreachable, the forwarder
|
||||
# will be set to disabled.
|
||||
# MUST be a HTTP website server address, format: HOST[:PORT]. HTTPS NOT SUPPORTED.
|
||||
checkwebsite=www.apple.com
|
||||
# Forwarder health check:
|
||||
# check=tcp[://HOST:PORT]: tcp port connect check
|
||||
# check=http://HOST[:PORT][/URI][#expect=STRING_IN_RESP_LINE]
|
||||
# check=file://SCRIPT_PATH: run a check script, healthy when exitcode=0, environment variables: FORWARDER_ADDR
|
||||
# check=disable: disable health check
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
|
||||
# check interval(seconds)
|
||||
checkinterval=30
|
||||
|
@ -14,7 +14,7 @@ forward=http://192.168.2.1:8080,socks5://192.168.2.2:1080
|
||||
strategy=rr
|
||||
|
||||
# FORWARDER CHECK SETTINGS
|
||||
checkwebsite=www.apple.com
|
||||
check=http://www.msftconnecttest.com/connecttest.txt#expect=200
|
||||
checkinterval=30
|
||||
|
||||
# DNS SERVER for domains in this rule file
|
||||
|
@ -51,20 +51,16 @@ func NewUnixDialer(s string, d proxy.Dialer) (proxy.Dialer, error) {
|
||||
func NewUnixServer(s string, p proxy.Proxy) (proxy.Server, error) {
|
||||
transport := strings.Split(s, ",")
|
||||
|
||||
// prepare transport listener
|
||||
// TODO: check here
|
||||
if len(transport) < 2 {
|
||||
return nil, errors.New("[unix] malformd listener:" + s)
|
||||
}
|
||||
|
||||
unix, err := NewUnix(transport[0], nil, p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
unix.server, err = proxy.ServerFromURL(transport[1], p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
if len(transport) > 1 {
|
||||
unix.server, err = proxy.ServerFromURL(transport[1], p)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
return unix, nil
|
||||
@ -95,11 +91,29 @@ func (s *Unix) ListenAndServe() {
|
||||
|
||||
// Serve serves requests.
|
||||
func (s *Unix) Serve(c net.Conn) {
|
||||
// we know the internal server will close the connection after serve
|
||||
// defer c.Close()
|
||||
|
||||
if s.server != nil {
|
||||
s.server.Serve(c)
|
||||
return
|
||||
}
|
||||
|
||||
defer c.Close()
|
||||
|
||||
rc, dialer, err := s.proxy.Dial("unix", "")
|
||||
if err != nil {
|
||||
log.F("[unix] %s <-> %s via %s, error in dial: %v", c.RemoteAddr(), s.addr, dialer.Addr(), err)
|
||||
s.proxy.Record(dialer, false)
|
||||
return
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
log.F("[unix] %s <-> %s", c.RemoteAddr(), dialer.Addr())
|
||||
|
||||
if err = proxy.Relay(c, rc); err != nil {
|
||||
log.F("[unix] %s <-> %s, relay error: %v", c.RemoteAddr(), dialer.Addr(), err)
|
||||
// record remote conn failure only
|
||||
if !strings.Contains(err.Error(), s.addr) {
|
||||
s.proxy.Record(dialer, false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user