Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add meek #258

Merged
merged 10 commits into from
Aug 6, 2023
Merged
29 changes: 29 additions & 0 deletions component/outbound/dialer/v2ray/v2ray.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/daeuniverse/softwind/protocol/direct"
"github.com/daeuniverse/softwind/protocol/http"
"github.com/daeuniverse/softwind/transport/grpc"
"github.com/daeuniverse/softwind/transport/meek"
jsoniter "github.com/json-iterator/go"
)

Expand Down Expand Up @@ -166,6 +167,26 @@ func (s *V2Ray) Dialer(option *dialer.GlobalOption, nextDialer netproxy.Dialer)
if err != nil {
return nil, nil, err
}
case "meek":
if strings.HasPrefix(s.Path, "https://") && s.TLS != "tls" && s.TLS != "utls" {
return nil, nil, fmt.Errorf("%w: meek: tls should be enabled", dialer.InvalidParameterErr)
}

u := url.URL{
Scheme: "meek",
Host: net.JoinHostPort(s.Add, s.Port),
RawQuery: url.Values{
"url": []string{s.Path},
"alpn": []string{s.Alpn},
"serverName": []string{s.SNI},
"skipCertVerify": []string{common.BoolToString(s.AllowInsecure || option.AllowInsecure)},
}.Encode(),
}

d, err = meek.NewDialer(u.String(), d)
if err != nil {
return nil, nil, err
}
default:
return nil, nil, fmt.Errorf("%w: network: %v", dialer.UnexpectedFieldErr, s.Net)
}
Expand Down Expand Up @@ -213,6 +234,11 @@ func ParseVlessURL(vless string) (data *V2Ray, err error) {
if data.Net == "grpc" {
data.Path = u.Query().Get("serviceName")
}

if data.Net == "meek" {
data.Path = u.Query().Get("url")
}

if data.Type == "" {
data.Type = "none"
}
Expand Down Expand Up @@ -327,7 +353,10 @@ func (s *V2Ray) ExportToURL() string {
common.SetValue(&query, "path", s.Path)
case "grpc":
common.SetValue(&query, "serviceName", s.Path)
case "meek":
common.SetValue(&query, "url", s.Host)
}

//TODO: QUIC
if s.TLS != "none" {
common.SetValue(&query, "sni", s.Host) // FIXME: it may be different from ws's host
Expand Down
4 changes: 3 additions & 1 deletion control/control_plane.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package control
import (
"context"
"fmt"
"github.com/daeuniverse/softwind/transport/meek"
"net"
"net/netip"
"os"
Expand Down Expand Up @@ -276,8 +277,9 @@ func NewControlPlane(
}

// Filter out groups.
// FIXME: Ugly code here: reset grpc clients manually.
// FIXME: Ugly code here: reset grpc and meek clients manually.
grpc.CleanGlobalClientConnectionCache()
meek.CleanGlobalRoundTripperCache()
dialerSet := outbound.NewDialerSetFromLinks(option, tagToNodeList)
deferFuncs = append(deferFuncs, dialerSet.Close)
for _, group := range groups {
Expand Down
1 change: 1 addition & 0 deletions docs/en/proxy-protocols.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
- [x] TLS
- [x] gRPC
- [x] h2
- [x] Meek
- [x] Shadowsocks
- [x] AEAD Ciphers
- [x] Stream Ciphers
Expand Down
1 change: 1 addition & 0 deletions docs/zh/proxy-protocols.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- [x] WS
- [x] TLS
- [x] gRPC
- [x] Meek
- [x] Shadowsocks
- [x] AEAD Ciphers
- [x] Stream Ciphers
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/bits-and-blooms/bloom/v3 v3.5.0
github.com/cilium/ebpf v0.11.0
github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d
github.com/daeuniverse/softwind v0.0.0-20230805041143-2db4e28c8922
github.com/daeuniverse/softwind v0.0.0-20230806140139-8dd211d63c60
github.com/gorilla/websocket v1.5.0
github.com/json-iterator/go v1.1.12
github.com/miekg/dns v1.1.55
Expand All @@ -34,7 +34,7 @@ require (
github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20230705174524-200ffdc848b8 // indirect
github.com/klauspost/compress v1.16.7 // indirect
github.com/mzz2017/quic-go v0.0.0-20230805032040-5e9a02f54eac // indirect
github.com/mzz2017/quic-go v0.0.0-20230806040851-f9ecab3bb42a // indirect
github.com/onsi/ginkgo/v2 v2.11.0 // indirect
github.com/quic-go/qtls-go1-20 v0.3.1 // indirect
golang.org/x/mod v0.12.0 // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ github.com/cilium/ebpf v0.11.0/go.mod h1:WE7CZAnqOL2RouJ4f1uyNhqr2P4CCvXFIqdRDUg
github.com/cpuguy83/go-md2man/v2 v2.0.2/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d h1:hnC39MjR7xt5kZjrKlef7DXKFDkiX8MIcDXYC/6Jf9Q=
github.com/daeuniverse/dae-config-dist/go/dae_config v0.0.0-20230604120805-1c27619b592d/go.mod h1:VGWGgv7pCP5WGyHGUyb9+nq/gW0yBm+i/GfCNATOJ1M=
github.com/daeuniverse/softwind v0.0.0-20230805041143-2db4e28c8922 h1:TQkiCTLMY82prw7vfGqOtSCWOuX9MvnCa3g6ufvPgxg=
github.com/daeuniverse/softwind v0.0.0-20230805041143-2db4e28c8922/go.mod h1:hL69hHFjobbgKxTJ5cknnuZT1DCglxdl30uJ3dS8nco=
github.com/daeuniverse/softwind v0.0.0-20230806140139-8dd211d63c60 h1:3h6gBNiPvaEINMKJWwjAz6TojZ4MpSj+fLWj/uvqrRs=
github.com/daeuniverse/softwind v0.0.0-20230806140139-8dd211d63c60/go.mod h1:SXBNF3LXl1cfYKxoRJO/aK5ycoTNdou280mM9cGZYr4=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
Expand Down Expand Up @@ -91,8 +91,8 @@ github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
github.com/mzz2017/disk-bloom v1.0.1 h1:rEF9MiXd9qMW3ibRpqcerLXULoTgRlM21yqqJl1B90M=
github.com/mzz2017/disk-bloom v1.0.1/go.mod h1:JLHETtUu44Z6iBmsqzkOtFlRvXSlKnxjwiBRDapizDI=
github.com/mzz2017/quic-go v0.0.0-20230805032040-5e9a02f54eac h1:luSUVeRYonUjk7Pxx8zViDj9Vpf42DZmfR/CbQcXKt0=
github.com/mzz2017/quic-go v0.0.0-20230805032040-5e9a02f54eac/go.mod h1:DBA25b2LoPhrfSzOPE8KcDOicysx00qvvnqe0BpA8DQ=
github.com/mzz2017/quic-go v0.0.0-20230806040851-f9ecab3bb42a h1:clBJMmZdRtli4Tko2ZdQ+3n1cA4Es/0ao3tB5vXvctY=
github.com/mzz2017/quic-go v0.0.0-20230806040851-f9ecab3bb42a/go.mod h1:DBA25b2LoPhrfSzOPE8KcDOicysx00qvvnqe0BpA8DQ=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
Expand Down