From 9dda9324947ffce869b10aa6e34a1d51bc030b06 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Mon, 30 Dec 2019 10:51:35 +0800 Subject: [PATCH 1/4] Fix: reject should support udp and return dial error --- adapters/outbound/reject.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/adapters/outbound/reject.go b/adapters/outbound/reject.go index b053508228..5ef615400c 100644 --- a/adapters/outbound/reject.go +++ b/adapters/outbound/reject.go @@ -2,6 +2,7 @@ package outbound import ( "context" + "errors" "io" "net" "time" @@ -17,11 +18,16 @@ func (r *Reject) DialContext(ctx context.Context, metadata *C.Metadata) (C.Conn, return newConn(&NopConn{}, r), nil } +func (r *Reject) DialUDP(metadata *C.Metadata) (C.PacketConn, net.Addr, error) { + return nil, nil, errors.New("match reject rule") +} + func NewReject() *Reject { return &Reject{ Base: &Base{ name: "REJECT", tp: C.Reject, + udp: true, }, } } From b19a49335fdbccc60794903c01e230e074d41169 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Mon, 30 Dec 2019 23:01:24 +0800 Subject: [PATCH 2/4] Fix: http vehicle shouldn't save file --- adapters/provider/vehicle.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/adapters/provider/vehicle.go b/adapters/provider/vehicle.go index 8314319456..0b94936887 100644 --- a/adapters/provider/vehicle.go +++ b/adapters/provider/vehicle.go @@ -92,15 +92,12 @@ func (h *HTTPVehicle) Read() ([]byte, error) { if err != nil { return nil, err } + buf, err := ioutil.ReadAll(resp.Body) if err != nil { return nil, err } - if err := ioutil.WriteFile(h.path, buf, fileMode); err != nil { - return nil, err - } - return buf, nil } From 38458cc4d0de6f074b7585dd76d03b7ef3c4f3f4 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Tue, 31 Dec 2019 12:30:42 +0800 Subject: [PATCH 3/4] Migration: change geoip address --- Dockerfile | 4 +--- config/initial.go | 38 ++++++-------------------------------- 2 files changed, 7 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index bd0d05c904..ba3c66cd1b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,9 +1,7 @@ FROM golang:alpine as builder RUN apk add --no-cache make git && \ - wget http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz -O /tmp/GeoLite2-Country.tar.gz && \ - tar zxvf /tmp/GeoLite2-Country.tar.gz -C /tmp && \ - mv /tmp/GeoLite2-Country_*/GeoLite2-Country.mmdb /Country.mmdb + wget -O /Country.mmdb https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb WORKDIR /clash-src COPY . /clash-src RUN go mod download && \ diff --git a/config/initial.go b/config/initial.go index 63ff427fb0..e151e74c89 100644 --- a/config/initial.go +++ b/config/initial.go @@ -1,56 +1,30 @@ package config import ( - "archive/tar" - "compress/gzip" "fmt" "io" "net/http" "os" - "strings" C "github.com/Dreamacro/clash/constant" "github.com/Dreamacro/clash/log" ) func downloadMMDB(path string) (err error) { - resp, err := http.Get("http://geolite.maxmind.com/download/geoip/database/GeoLite2-Country.tar.gz") + resp, err := http.Get("https://github.com/Dreamacro/maxmind-geoip/releases/latest/download/Country.mmdb") if err != nil { return } defer resp.Body.Close() - gr, err := gzip.NewReader(resp.Body) + f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) if err != nil { - return - } - defer gr.Close() - - tr := tar.NewReader(gr) - for { - h, err := tr.Next() - if err == io.EOF { - break - } else if err != nil { - return err - } - - if !strings.HasSuffix(h.Name, "GeoLite2-Country.mmdb") { - continue - } - - f, err := os.OpenFile(path, os.O_CREATE|os.O_WRONLY, 0644) - if err != nil { - return err - } - defer f.Close() - _, err = io.Copy(f, tr) - if err != nil { - return err - } + return err } + defer f.Close() + _, err = io.Copy(f, resp.Body) - return nil + return err } // Init prepare necessary files From 50704eaeeb26f1446fb37b4ca6ee6b5acb506714 Mon Sep 17 00:00:00 2001 From: Dreamacro <305009791@qq.com> Date: Tue, 31 Dec 2019 14:47:00 +0800 Subject: [PATCH 4/4] Fix: udp crash --- tunnel/tunnel.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tunnel/tunnel.go b/tunnel/tunnel.go index 3a8285bc31..61f0897170 100644 --- a/tunnel/tunnel.go +++ b/tunnel/tunnel.go @@ -188,7 +188,7 @@ func (t *Tunnel) handleUDPConn(packet *inbound.PacketAdapter) { lockKey := key + "-lock" wg, loaded := t.natTable.GetOrCreateLock(lockKey) - isFakeIP := dns.DefaultResolver.IsFakeIP(metadata.DstIP) + isFakeIP := dns.DefaultResolver != nil && dns.DefaultResolver.IsFakeIP(metadata.DstIP) go func() { if !loaded {