From 2fcef7b00c7b3780014106b8ec95ec4925c5eba5 Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Wed, 8 Aug 2018 00:03:32 +0800 Subject: [PATCH] ws: fixed a bug when ws used as a middle layer protocol(tls,ws,vmess) --- README.md | 12 +++++++++--- dns/client.go | 4 +++- proxy/ws/ws.go | 5 +++++ 3 files changed, 17 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 94c1fc8..32978f0 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ DNS Forwarding Server (udp2tcp): IPSet Management: - Add ip/cidrs from rule files on startup -- Add resolved ips for domains from rule files by dns forwarding server +- Add resolved ips for domains from rule files by dns forwarding server General: @@ -109,19 +109,25 @@ glider -config CONFIGPATH -listen :8080 -verbose ## Usage ```bash -glider v0.6.5 usage: +glider v0.6.6 usage: -checkduration int - proxy check duration(seconds) (default 30) + proxy check interval(seconds) (default 30) -checkwebsite string proxy check HTTP(NOT HTTPS) website address, format: HOST[:PORT], default port: 80 (default "www.apple.com") -config string config file path -dns string dns forwarder server listen address + -dnsmaxttl int + maximum TTL value for entries in the CACHE(seconds) (default 1800) + -dnsminttl int + minimum TTL value for entries in the CACHE(seconds) -dnsrecord value custom dns record, format: domain/ip -dnsserver value remote dns server + -dnstimeout int + 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] -ipset string diff --git a/dns/client.go b/dns/client.go index 074f1e6..247ef38 100644 --- a/dns/client.go +++ b/dns/client.go @@ -91,7 +91,9 @@ func (c *Client) Exchange(reqBytes []byte, clientAddr string, preferTCP bool) ([ if answer.IP != "" { ips = append(ips, answer.IP) } - ttl = int(answer.TTL) + if answer.TTL != 0 { + ttl = int(answer.TTL) + } } } diff --git a/proxy/ws/ws.go b/proxy/ws/ws.go index 14d6162..3f6bf48 100644 --- a/proxy/ws/ws.go +++ b/proxy/ws/ws.go @@ -32,6 +32,11 @@ func NewWS(s string, dialer proxy.Dialer) (*WS, error) { addr := u.Host + // TODO: + if addr == "" { + addr = dialer.Addr() + } + colonPos := strings.LastIndex(addr, ":") if colonPos == -1 { colonPos = len(addr)