Skip to content

Commit

Permalink
Merge branch 'dev' into clashr
Browse files Browse the repository at this point in the history
  • Loading branch information
Doris committed Jan 1, 2020
2 parents a11e1d3 + aea4d11 commit 8171da0
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
4 changes: 1 addition & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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 && \
Expand Down
6 changes: 6 additions & 0 deletions adapters/outbound/reject.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package outbound

import (
"context"
"errors"
"io"
"net"
"time"
Expand All @@ -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,
},
}
}
Expand Down
5 changes: 1 addition & 4 deletions adapters/provider/vehicle.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
38 changes: 6 additions & 32 deletions config/initial.go
Original file line number Diff line number Diff line change
@@ -1,56 +1,30 @@
package config

import (
"archive/tar"
"compress/gzip"
"fmt"
"io"
"net/http"
"os"
"strings"

C "github.com/whojave/clash/constant"
"github.com/whojave/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
Expand Down
2 changes: 1 addition & 1 deletion tunnel/tunnel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 8171da0

Please sign in to comment.