diff --git a/README.md b/README.md index 65ad2fd..bb00581 100644 --- a/README.md +++ b/README.md @@ -116,47 +116,47 @@ glider -config CONFIGPATH -listen :8080 -verbose ## Usage ```bash -glider 0.9.0 usage: +glider 0.10.0 usage: -checkinterval int - proxy check interval(seconds) (default 30) + proxy check interval(seconds) (default 30) -checktimeout int - proxy check timeout(seconds) (default 10) + proxy check timeout(seconds) (default 10) -checkwebsite string - proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80 (default "www.apple.com") + proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80 (default "www.apple.com") -config string - config file path + config file path -dns string - local dns server listen address + local dns server listen address -dnsalwaystcp - always use tcp to query upstream dns servers no matter there is a forwarder or not + always use tcp to query upstream dns servers no matter there is a forwarder or not -dnsmaxttl int - maximum TTL value for entries in the CACHE(seconds) (default 1800) + maximum TTL value for entries in the CACHE(seconds) (default 1800) -dnsminttl int - minimum TTL value for entries in the CACHE(seconds) + minimum TTL value for entries in the CACHE(seconds) -dnsrecord value - custom dns record, format: domain/ip + custom dns record, format: domain/ip -dnsserver value - remote dns server address + remote dns server address -dnstimeout int - timeout value used in multiple dnsservers switch(seconds) (default 3) + timeout value used in multiple dnsservers switch(seconds) (default 3) -forward value - forward url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS[,SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS] + forward url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS[,SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS] -include value - include file + include file -interface string - source ip or source interface + source ip or source interface -listen value - listen url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS + listen url, format: SCHEME://[USER|METHOD:PASSWORD@][HOST]:PORT?PARAMS -maxfailures int - max failures to change forwarder status to disabled (default 3) + max failures to change forwarder status to disabled (default 3) -rulefile value - rule file path + rule file path -rules-dir string - rule file folder + rule file folder -strategy string - forward strategy, default: rr (default "rr") + forward strategy, default: rr (default "rr") -verbose - verbose mode + verbose mode Available Schemes: mixed: serve as a http/socks5 proxy on the same port. (default) @@ -221,19 +221,19 @@ Proxy over tls server: tls://host:port?cert=PATH&key=PATH,ss://method:pass@ Websocket scheme: - ws://host:port[/path] + ws://host:port[/path][?host=HOST] Websocket with a specified proxy protocol: - ws://host:port[/path],scheme:// - ws://host:port[/path],http://[user:pass@] - ws://host:port[/path],socks5://[user:pass@] - ws://host:port[/path],vmess://[security:]uuid@?alterID=num + ws://host:port[/path][?host=HOST],scheme:// + ws://host:port[/path][?host=HOST],http://[user:pass@] + ws://host:port[/path][?host=HOST],socks5://[user:pass@] + ws://host:port[/path][?host=HOST],vmess://[security:]uuid@?alterID=num TLS and Websocket with a specified proxy protocol: - tls://host:port[?skipVerify=true],ws://[@/path],scheme:// - tls://host:port[?skipVerify=true],ws://[@/path],http://[user:pass@] - tls://host:port[?skipVerify=true],ws://[@/path],socks5://[user:pass@] - tls://host:port[?skipVerify=true],ws://[@/path],vmess://[security:]uuid@?alterID=num + tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],scheme:// + tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],http://[user:pass@] + tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],socks5://[user:pass@] + tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],vmess://[security:]uuid@?alterID=num Unix domain socket scheme: unix://path diff --git a/conf.go b/conf.go index 7ca88bf..f94b701 100644 --- a/conf.go +++ b/conf.go @@ -185,21 +185,21 @@ func usage() { fmt.Fprintf(w, "\n") fmt.Fprintf(w, "Websocket scheme:\n") - fmt.Fprintf(w, " ws://host:port[/path]\n") + fmt.Fprintf(w, " ws://host:port[/path][?host=HOST]\n") fmt.Fprintf(w, "\n") fmt.Fprintf(w, "Websocket with a specified proxy protocol:\n") - fmt.Fprintf(w, " ws://host:port[/path],scheme://\n") - fmt.Fprintf(w, " ws://host:port[/path],http://[user:pass@]\n") - fmt.Fprintf(w, " ws://host:port[/path],socks5://[user:pass@]\n") - fmt.Fprintf(w, " ws://host:port[/path],vmess://[security:]uuid@?alterID=num\n") + fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],scheme://\n") + fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],http://[user:pass@]\n") + fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],socks5://[user:pass@]\n") + fmt.Fprintf(w, " ws://host:port[/path][?host=HOST],vmess://[security:]uuid@?alterID=num\n") fmt.Fprintf(w, "\n") fmt.Fprintf(w, "TLS and Websocket with a specified proxy protocol:\n") - fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],scheme://\n") - fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],http://[user:pass@]\n") - fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],socks5://[user:pass@]\n") - fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path],vmess://[security:]uuid@?alterID=num\n") + fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],scheme://\n") + fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],http://[user:pass@]\n") + fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],socks5://[user:pass@]\n") + fmt.Fprintf(w, " tls://host:port[?skipVerify=true],ws://[@/path[?host=HOST]],vmess://[security:]uuid@?alterID=num\n") fmt.Fprintf(w, "\n") fmt.Fprintf(w, "Unix domain socket scheme:\n") diff --git a/dns/client.go b/dns/client.go index d94fd03..18a738d 100644 --- a/dns/client.go +++ b/dns/client.go @@ -288,7 +288,7 @@ func (c *Client) GenResponse(domain string, ip string) (*Message, error) { } func getKey(q *Question) string { - qtype := "" + var qtype string switch q.QTYPE { case QTypeA: qtype = "A" diff --git a/proxy/ws/ws.go b/proxy/ws/ws.go index c0b98ce..3c75151 100644 --- a/proxy/ws/ws.go +++ b/proxy/ws/ws.go @@ -15,6 +15,7 @@ import ( type WS struct { dialer proxy.Dialer addr string + host string client *Client } @@ -27,7 +28,7 @@ func init() { func NewWS(s string, d proxy.Dialer) (*WS, error) { u, err := url.Parse(s) if err != nil { - log.F("parse url err: %s", err) + log.F("[ws] parse url err: %s", err) return nil, err } @@ -38,21 +39,26 @@ func NewWS(s string, d proxy.Dialer) (*WS, error) { addr = d.Addr() } - colonPos := strings.LastIndex(addr, ":") - if colonPos == -1 { - colonPos = len(addr) + query := u.Query() + host := query.Get("host") + if host == "" { + colonPos := strings.LastIndex(addr, ":") + if colonPos == -1 { + colonPos = len(addr) + } + host = addr[:colonPos] } - serverName := addr[:colonPos] - client, err := NewClient(serverName, u.Path) + client, err := NewClient(host, u.Path) if err != nil { - log.F("create ws client err: %s", err) + log.F("[ws] create ws client error: %s", err) return nil, err } p := &WS{ dialer: d, addr: addr, + host: host, client: client, } @@ -84,5 +90,5 @@ func (s *WS) Dial(network, addr string) (net.Conn, error) { // DialUDP connects to the given address via the proxy. func (s *WS) DialUDP(network, addr string) (net.PacketConn, net.Addr, error) { - return nil, nil, errors.New("ws client does not support udp now") + return nil, nil, errors.New("[ws] ws client does not support udp now") } diff --git a/strategy/strategy.go b/strategy/strategy.go index 4494545..06f5d43 100644 --- a/strategy/strategy.go +++ b/strategy/strategy.go @@ -36,7 +36,7 @@ func (p priSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } type Proxy struct { config *Config fwdrs priSlice - avail []*Forwarder // avaliable forwarders + avail []*Forwarder // available forwarders mu sync.RWMutex index uint32 priority uint32