Skip to content

Commit fa73b0f

Browse files
committed
Merge remote-tracking branch 'origin/Beta' into Meta
2 parents 667f42d + 3b76a8b commit fa73b0f

File tree

206 files changed

+12859
-3366
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

206 files changed

+12859
-3366
lines changed

.github/workflows/build.yaml

+7-5
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ jobs:
55
build:
66
runs-on: ubuntu-latest
77
steps:
8-
- name: Set up Go
9-
uses: actions/setup-go@v1
8+
- name: Check out code into the Go module directory
9+
uses: actions/checkout@v3
10+
- name: Setup Go
11+
uses: actions/setup-go@v3
1012
with:
11-
go-version: 1.18
12-
- name: Check out code
13-
uses: actions/checkout@v1
13+
go-version: '1.19'
14+
check-latest: true
15+
cache: true
1416
- name: Build
1517
run: make all
1618
- name: Release

.github/workflows/prerelease.yml

+5-16
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,15 @@ jobs:
1313
Build:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- name: Get latest go version
17-
id: version
18-
run: |
19-
echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g')
20-
- name: Setup Go
21-
uses: actions/setup-go@v3
22-
with:
23-
go-version: ${{ steps.version.outputs.go_version }}
24-
2516
- name: Check out code into the Go module directory
2617
uses: actions/checkout@v3
2718

28-
- name: Cache go module
29-
uses: actions/cache@v2
19+
- name: Setup Go
20+
uses: actions/setup-go@v3
3021
with:
31-
path: ~/go/pkg/mod
32-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
33-
restore-keys: |
34-
${{ runner.os }}-go-
35-
22+
go-version: '1.19'
23+
check-latest: true
24+
cache: true
3625

3726
- name: Test
3827
if: ${{github.ref_name=='Beta'}}

.github/workflows/release.yaml

+7-15
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,16 @@ jobs:
77
Build:
88
runs-on: ubuntu-latest
99
steps:
10-
- name: Get latest go version
11-
id: version
12-
run: |
13-
echo ::set-output name=go_version::$(curl -s https://raw.githubusercontent.com/actions/go-versions/main/versions-manifest.json | grep -oE '"version": "[0-9]{1}.[0-9]{1,}(.[0-9]{1,})?"' | head -1 | cut -d':' -f2 | sed 's/ //g; s/"//g')
14-
- name: Setup Go
15-
uses: actions/setup-go@v2
16-
with:
17-
go-version: ${{ steps.version.outputs.go_version }}
18-
1910
- name: Check out code into the Go module directory
2011
uses: actions/checkout@v3
21-
- name: Cache go module
22-
uses: actions/cache@v2
12+
13+
- name: Setup Go
14+
uses: actions/setup-go@v3
2315
with:
24-
path: ~/go/pkg/mod
25-
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
26-
restore-keys: |
27-
${{ runner.os }}-go-
16+
go-version: '1.19'
17+
check-latest: true
18+
cache: true
19+
2820
- name: Test
2921
run: |
3022
go test ./...

.golangci.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ linters:
88

99
linters-settings:
1010
gci:
11+
custom-order: true
1112
sections:
1213
- standard
1314
- prefix(github.com/Dreamacro/clash)
1415
- default
1516
staticcheck:
16-
go: '1.18'
17+
go: '1.19'

README.md

+38
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,43 @@ proxies:
232232
grpc-service-name: grpcname
233233
```
234234

235+
236+
Support outbound transport protocol `Wireguard`
237+
```yaml
238+
proxies:
239+
- name: "wg"
240+
type: wireguard
241+
server: 162.159.192.1
242+
port: 2480
243+
ip: 172.16.0.2
244+
ipv6: fd01:5ca1:ab1e:80fa:ab85:6eea:213f:f4a5
245+
private-key: eCtXsJZ27+4PbhDkHnB923tkUn2Gj59wZw5wFA75MnU=
246+
public-key: Cr8hWlKvtDt7nrvf+f0brNQQzabAqrjfBvas9pmowjo=
247+
udp: true
248+
```
249+
250+
Support outbound transport protocol `Tuic`
251+
```yaml
252+
proxies:
253+
- name: "tuic"
254+
server: www.example.com
255+
port: 10443
256+
type: tuic
257+
token: TOKEN
258+
# ip: 127.0.0.1 # for overwriting the DNS lookup result of the server address set in option 'server'
259+
# heartbeat-interval: 10000
260+
# alpn: [h3]
261+
# disable-sni: true
262+
reduce-rtt: true
263+
# request-timeout: 8000
264+
udp-relay-mode: native # Available: "native", "quic". Default: "native"
265+
# congestion-controller: bbr # Available: "cubic", "new_reno", "bbr". Default: "cubic"
266+
# max-udp-relay-packet-size: 1500
267+
# fast-open: true
268+
# skip-cert-verify: true
269+
270+
```
271+
235272
### IPTABLES configuration
236273
Work on Linux OS who's supported `iptables`
237274

@@ -306,6 +343,7 @@ the [GitHub Wiki](https://github.com/Dreamacro/clash/wiki/use-clash-as-a-library
306343
## Credits
307344

308345
* [Dreamacro/clash](https://github.com/Dreamacro/clash)
346+
* [SagerNet/sing-box](https://github.com/SagerNet/sing-box)
309347
* [riobard/go-shadowsocks2](https://github.com/riobard/go-shadowsocks2)
310348
* [v2ray/v2ray-core](https://github.com/v2ray/v2ray-core)
311349
* [WireGuard/wireguard-go](https://github.com/WireGuard/wireguard-go)

adapter/adapter.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ func (p *Proxy) MarshalJSON() ([]byte, error) {
9292
mapping["history"] = p.DelayHistory()
9393
mapping["name"] = p.Name()
9494
mapping["udp"] = p.SupportUDP()
95+
mapping["tfo"] = p.SupportTFO()
9596
return json.Marshal(mapping)
9697
}
9798

@@ -198,10 +199,9 @@ func urlToMetadata(rawURL string) (addr C.Metadata, err error) {
198199
}
199200

200201
addr = C.Metadata{
201-
AddrType: C.AtypDomainName,
202-
Host: u.Hostname(),
203-
DstIP: netip.Addr{},
204-
DstPort: port,
202+
Host: u.Hostname(),
203+
DstIP: netip.Addr{},
204+
DstPort: port,
205205
}
206206
return
207207
}

adapter/inbound/addition.go

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package inbound
2+
3+
import (
4+
C "github.com/Dreamacro/clash/constant"
5+
)
6+
7+
type Addition func(metadata *C.Metadata)
8+
9+
func (a Addition) Apply(metadata *C.Metadata) {
10+
a(metadata)
11+
}
12+
13+
func WithInName(name string) Addition {
14+
return func(metadata *C.Metadata) {
15+
metadata.InName = name
16+
}
17+
}
18+
19+
func WithSpecialRules(specialRules string) Addition {
20+
return func(metadata *C.Metadata) {
21+
metadata.SpecialRules = specialRules
22+
}
23+
}
24+
25+
func WithSpecialProxy(specialProxy string) Addition {
26+
return func(metadata *C.Metadata) {
27+
metadata.SpecialProxy = specialProxy
28+
}
29+
}

adapter/inbound/http.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ import (
99
)
1010

1111
// NewHTTP receive normal http request and return HTTPContext
12-
func NewHTTP(target socks5.Addr, source net.Addr, conn net.Conn) *context.ConnContext {
12+
func NewHTTP(target socks5.Addr, source net.Addr, conn net.Conn, additions ...Addition) *context.ConnContext {
1313
metadata := parseSocksAddr(target)
1414
metadata.NetWork = C.TCP
1515
metadata.Type = C.HTTP
16+
for _, addition := range additions {
17+
addition.Apply(metadata)
18+
}
1619
if ip, port, err := parseAddr(source.String()); err == nil {
1720
metadata.SrcIP = ip
1821
metadata.SrcPort = port
1922
}
23+
if ip, port, err := parseAddr(conn.LocalAddr().String()); err == nil {
24+
metadata.InIP = ip
25+
metadata.InPort = port
26+
}
2027
return context.NewConnContext(conn, metadata)
2128
}

adapter/inbound/https.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,19 @@ import (
99
)
1010

1111
// NewHTTPS receive CONNECT request and return ConnContext
12-
func NewHTTPS(request *http.Request, conn net.Conn) *context.ConnContext {
12+
func NewHTTPS(request *http.Request, conn net.Conn, additions ...Addition) *context.ConnContext {
1313
metadata := parseHTTPAddr(request)
1414
metadata.Type = C.HTTPS
15+
for _, addition := range additions {
16+
addition.Apply(metadata)
17+
}
1518
if ip, port, err := parseAddr(conn.RemoteAddr().String()); err == nil {
1619
metadata.SrcIP = ip
1720
metadata.SrcPort = port
1821
}
22+
if ip, port, err := parseAddr(conn.LocalAddr().String()); err == nil {
23+
metadata.InIP = ip
24+
metadata.InPort = port
25+
}
1926
return context.NewConnContext(conn, metadata)
2027
}

adapter/inbound/listen.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package inbound
2+
3+
import (
4+
"context"
5+
"net"
6+
7+
"github.com/database64128/tfo-go/v2"
8+
)
9+
10+
var (
11+
lc = tfo.ListenConfig{
12+
DisableTFO: true,
13+
}
14+
)
15+
16+
func SetTfo(open bool) {
17+
lc.DisableTFO = !open
18+
}
19+
20+
func ListenContext(ctx context.Context, network, address string) (net.Listener, error) {
21+
return lc.Listen(ctx, network, address)
22+
}
23+
24+
func Listen(network, address string) (net.Listener, error) {
25+
return ListenContext(context.Background(), network, address)
26+
}

adapter/inbound/packet.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,26 @@ func (s *PacketAdapter) Metadata() *C.Metadata {
1717
}
1818

1919
// NewPacket is PacketAdapter generator
20-
func NewPacket(target socks5.Addr, packet C.UDPPacket, source C.Type) *PacketAdapter {
20+
func NewPacket(target socks5.Addr, packet C.UDPPacket, source C.Type, additions ...Addition) C.PacketAdapter {
2121
metadata := parseSocksAddr(target)
2222
metadata.NetWork = C.UDP
2323
metadata.Type = source
24+
for _, addition := range additions {
25+
addition.Apply(metadata)
26+
}
2427
if ip, port, err := parseAddr(packet.LocalAddr().String()); err == nil {
2528
metadata.SrcIP = ip
2629
metadata.SrcPort = port
2730
}
31+
if p, ok := packet.(C.UDPPacketInAddr); ok {
32+
if ip, port, err := parseAddr(p.InAddr().String()); err == nil {
33+
metadata.InIP = ip
34+
metadata.InPort = port
35+
}
36+
}
2837

2938
return &PacketAdapter{
30-
UDPPacket: packet,
31-
metadata: metadata,
39+
packet,
40+
metadata,
3241
}
3342
}

adapter/inbound/socket.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,31 @@ import (
1010
)
1111

1212
// NewSocket receive TCP inbound and return ConnContext
13-
func NewSocket(target socks5.Addr, conn net.Conn, source C.Type) *context.ConnContext {
13+
func NewSocket(target socks5.Addr, conn net.Conn, source C.Type, additions ...Addition) *context.ConnContext {
1414
metadata := parseSocksAddr(target)
1515
metadata.NetWork = C.TCP
1616
metadata.Type = source
17+
for _, addition := range additions {
18+
addition.Apply(metadata)
19+
}
20+
1721
remoteAddr := conn.RemoteAddr()
22+
1823
// Filter when net.Addr interface is nil
1924
if remoteAddr != nil {
2025
if ip, port, err := parseAddr(remoteAddr.String()); err == nil {
2126
metadata.SrcIP = ip
2227
metadata.SrcPort = port
2328
}
2429
}
30+
localAddr := conn.LocalAddr()
31+
// Filter when net.Addr interface is nil
32+
if localAddr != nil {
33+
if ip, port, err := parseAddr(localAddr.String()); err == nil {
34+
metadata.InIP = ip
35+
metadata.InPort = port
36+
}
37+
}
2538

2639
return context.NewConnContext(conn, metadata)
2740
}
@@ -32,17 +45,12 @@ func NewInner(conn net.Conn, dst string, host string) *context.ConnContext {
3245
metadata.Type = C.INNER
3346
metadata.DNSMode = C.DNSMapping
3447
metadata.Host = host
35-
metadata.AddrType = C.AtypDomainName
3648
metadata.Process = C.ClashName
3749
if h, port, err := net.SplitHostPort(dst); err == nil {
3850
metadata.DstPort = port
3951
if host == "" {
4052
if ip, err := netip.ParseAddr(h); err == nil {
4153
metadata.DstIP = ip
42-
metadata.AddrType = C.AtypIPv4
43-
if ip.Is6() {
44-
metadata.AddrType = C.AtypIPv6
45-
}
4654
}
4755
}
4856
}

adapter/inbound/util.go

+5-14
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import (
1313
)
1414

1515
func parseSocksAddr(target socks5.Addr) *C.Metadata {
16-
metadata := &C.Metadata{
17-
AddrType: int(target[0]),
18-
}
16+
metadata := &C.Metadata{}
1917

2018
switch target[0] {
2119
case socks5.AtypDomainName:
@@ -45,21 +43,14 @@ func parseHTTPAddr(request *http.Request) *C.Metadata {
4543
host = strings.TrimRight(host, ".")
4644

4745
metadata := &C.Metadata{
48-
NetWork: C.TCP,
49-
AddrType: C.AtypDomainName,
50-
Host: host,
51-
DstIP: netip.Addr{},
52-
DstPort: port,
46+
NetWork: C.TCP,
47+
Host: host,
48+
DstIP: netip.Addr{},
49+
DstPort: port,
5350
}
5451

5552
ip, err := netip.ParseAddr(host)
5653
if err == nil {
57-
switch {
58-
case ip.Is6():
59-
metadata.AddrType = C.AtypIPv6
60-
default:
61-
metadata.AddrType = C.AtypIPv4
62-
}
6354
metadata.DstIP = ip
6455
}
6556

0 commit comments

Comments
 (0)