mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-11-25 19:01:43 +00:00
Compare commits
324
Commits
v1.0.1
..
v1.0-beta3
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5f5cb023c | ||
|
|
5813e0ce7a | ||
|
|
5a9c2b1e80 | ||
|
|
bda34fdb3b | ||
|
|
426b677eb8 | ||
|
|
67c7e9fd86 | ||
|
|
d8028a8632 | ||
|
|
374743d022 | ||
|
|
cd98ea5008 | ||
|
|
dbda0ed98a | ||
|
|
f5e0ead01c | ||
|
|
44818701bc | ||
|
|
e0f7387dff | ||
|
|
d440a01792 | ||
|
|
665c84ee42 | ||
|
|
e0de96eb4c | ||
|
|
c6ef276811 | ||
|
|
1701aaf78c | ||
|
|
122daa4bfb | ||
|
|
561a9e5275 | ||
|
|
de2453fce9 | ||
|
|
d59d40c118 | ||
|
|
3469df001f | ||
|
|
0d8cfa3031 | ||
|
|
0289586880 | ||
|
|
e46427c7fc | ||
|
|
3ea59d9a8e | ||
|
|
e85dfc6adf | ||
|
|
d0703b78fa | ||
|
|
432e6adf3e | ||
|
|
a057754035 | ||
|
|
0348ace253 | ||
|
|
c5e38203eb | ||
|
|
9ac31d0233 | ||
|
|
9d8d1cd69d | ||
|
|
07a0381f8b | ||
|
|
f841459004 | ||
|
|
78a26fc139 | ||
|
|
9f6628445e | ||
|
|
fa017b5977 | ||
|
|
58f4a970f2 | ||
|
|
021aa8faed | ||
|
|
83f6e037d6 | ||
|
|
baf153434d | ||
|
|
d481bd7993 | ||
|
|
e859c0a6ef | ||
|
|
59a39e66b1 | ||
|
|
fd5ac69a35 | ||
|
|
a940703ae1 | ||
|
|
350729cde8 | ||
|
|
2e14cd6d66 | ||
|
|
f703524f04 | ||
|
|
aa4435c775 | ||
|
|
31a2e368cc | ||
|
|
97e284e65e | ||
|
|
a6baab92f3 | ||
|
|
7c76e0c3ee | ||
|
|
591a4fcf8e | ||
|
|
71dac85600 | ||
|
|
ad90ddd327 | ||
|
|
03f457f3d0 | ||
|
|
a878256367 | ||
|
|
553f78ed55 | ||
|
|
1bc7d2237e | ||
|
|
132222013b | ||
|
|
2008fb552a | ||
|
|
236c034c62 | ||
|
|
f87baf08d3 | ||
|
|
22aa0c2f40 | ||
|
|
88469d4aaa | ||
|
|
1413c5022a | ||
|
|
aa8cdaee22 | ||
|
|
9f6ff54a76 | ||
|
|
e750c747c6 | ||
|
|
9edfe7d9d3 | ||
|
|
c9b7acd22c | ||
|
|
2ba2f0298c | ||
|
|
a24a2b475a | ||
|
|
4005452772 | ||
|
|
d4b7e221f0 | ||
|
|
77c98fd042 | ||
|
|
082872b2f3 | ||
|
|
6253e2e24c | ||
|
|
4216afe62f | ||
|
|
8fec78a5cd | ||
|
|
7ba0a14e97 | ||
|
|
3a442347a5 | ||
|
|
c4f4fd97d6 | ||
|
|
ac0ead1473 | ||
|
|
83cea9475d | ||
|
|
dc6bb7ab1b | ||
|
|
c71f6ba377 | ||
|
|
b1b1ab5350 | ||
|
|
7613b8dbfe | ||
|
|
e4cece6095 | ||
|
|
bcefe8716f | ||
|
|
746b5d8be0 | ||
|
|
f13ecbd9bb | ||
|
|
e839beb73b | ||
|
|
b797cdf91e | ||
|
|
84e4677a94 | ||
|
|
0377a11719 | ||
|
|
d0fa79044a | ||
|
|
f381f8d35a | ||
|
|
92e1e5b893 | ||
|
|
8e8b4dba22 | ||
|
|
767cd55817 | ||
|
|
eb0ef439d6 | ||
|
|
0bf78c0a8a | ||
|
|
12d7e19f32 | ||
|
|
d1c3dd0ee1 | ||
|
|
3dfa99efe1 | ||
|
|
d7bd221a47 | ||
|
|
1b7a3b4a74 | ||
|
|
c8424ed8fd | ||
|
|
150df1ae8e | ||
|
|
5ca9d77176 | ||
|
|
aa89fcc29d | ||
|
|
7ead0de26b | ||
|
|
f22c2690ec | ||
|
|
738bb0eabc | ||
|
|
002a519a17 | ||
|
|
f51128f772 | ||
|
|
d6a0aa7ccf | ||
|
|
ca94a2ddcb | ||
|
|
835ae1217b | ||
|
|
c165969399 | ||
|
|
88c69a06dc | ||
|
|
cd5e7055d2 | ||
|
|
3157593b6b | ||
|
|
c8399a297e | ||
|
|
529cfe2d9a | ||
|
|
50869c6cd2 | ||
|
|
44fcfab9aa | ||
|
|
340fce9f1c | ||
|
|
51bbf93ff2 | ||
|
|
f8d13d79c7 | ||
|
|
b0ed1dc106 | ||
|
|
ef8dde2b70 | ||
|
|
97870c9288 | ||
|
|
c9226aeaaf | ||
|
|
7b30815938 | ||
|
|
517a89fa9c | ||
|
|
cf80073f27 | ||
|
|
43353ca5a4 | ||
|
|
b79b19c470 | ||
|
|
ccdfab378a | ||
|
|
0e6b4df8f1 | ||
|
|
79a4b18ec7 | ||
|
|
e05ee55545 | ||
|
|
ecaddd897e | ||
|
|
8ca6c246a8 | ||
|
|
55d9a0ef2f | ||
|
|
4067e0f25c | ||
|
|
6d78cf6b58 | ||
|
|
df6635c620 | ||
|
|
2c6d239525 | ||
|
|
0f74f6cd60 | ||
|
|
6ee10c03d1 | ||
|
|
587739e95c | ||
|
|
01bace7769 | ||
|
|
dfa10d4ebe | ||
|
|
f691bd5ce1 | ||
|
|
64dbac8138 | ||
|
|
1c3c154d6d | ||
|
|
32201cacda | ||
|
|
5f566b140f | ||
|
|
03890151d7 | ||
|
|
8e4de29409 | ||
|
|
f6f3390490 | ||
|
|
d4cce1b5b9 | ||
|
|
44068500bf | ||
|
|
8ce263669e | ||
|
|
6b4824ffba | ||
|
|
9a8918cb9e | ||
|
|
b1c2440371 | ||
|
|
37b11e614c | ||
|
|
14b6200fd8 | ||
|
|
7966b80476 | ||
|
|
b526ab2746 | ||
|
|
0e0a892b7e | ||
|
|
fe3649cd27 | ||
|
|
e014220508 | ||
|
|
d06fd03dd8 | ||
|
|
0eed0ca11a | ||
|
|
c57ea9e47c | ||
|
|
70b4577dbe | ||
|
|
5f1f55fbe7 | ||
|
|
2d3d46eb34 | ||
|
|
2ce09b6ffd | ||
|
|
d3378a575c | ||
|
|
9b9b5ebb72 | ||
|
|
0f7f800e95 | ||
|
|
457de86819 | ||
|
|
83154eadd3 | ||
|
|
c0a2f77258 | ||
|
|
c240f1b359 | ||
|
|
aa074a2063 | ||
|
|
f008d0bde3 | ||
|
|
0347a7c038 | ||
|
|
75508bccb5 | ||
|
|
593799a988 | ||
|
|
816d7b734c | ||
|
|
5491895a60 | ||
|
|
9394674b63 | ||
|
|
146008a631 | ||
|
|
cc78f0347d | ||
|
|
1f05420745 | ||
|
|
32e2730ec6 | ||
|
|
29c329dc52 | ||
|
|
7d8a7c5c7d | ||
|
|
9e9e6f7ee6 | ||
|
|
fde33fbb30 | ||
|
|
67edc163cb | ||
|
|
fe8e984608 | ||
|
|
7d340e7ef9 | ||
|
|
af19ba6119 | ||
|
|
8666631732 | ||
|
|
ce4b7231e2 | ||
|
|
21641be9d1 | ||
|
|
5f6f33c464 | ||
|
|
4abf669d09 | ||
|
|
187de6c738 | ||
|
|
884c0cf595 | ||
|
|
9f8978bbcf | ||
|
|
bcdf71deb3 | ||
|
|
7bc7b72c61 | ||
|
|
e531e89b4b | ||
|
|
e5e24ef51d | ||
|
|
c4e46c35b5 | ||
|
|
139127f1e4 | ||
|
|
3838d3070d | ||
|
|
8004ff51f0 | ||
|
|
385c42e638 | ||
|
|
6327c4b40c | ||
|
|
45643fbed1 | ||
|
|
6ac1b395cf | ||
|
|
c5b3e8b042 | ||
|
|
c7fabe40ed | ||
|
|
3fb011712b | ||
|
|
6b1a68908d | ||
|
|
d1e83882e5 | ||
|
|
cf845d946e | ||
|
|
4094c94971 | ||
|
|
ae36e35de7 | ||
|
|
a4b5c61e25 | ||
|
|
9caa37c12a | ||
|
|
9871ed955b | ||
|
|
afc2f509a4 | ||
|
|
fe5618c35d | ||
|
|
8619e07d66 | ||
|
|
eb35d6793e | ||
|
|
a25db09aac | ||
|
|
8969a15858 | ||
|
|
377f3f83a2 | ||
|
|
5a3de62c50 | ||
|
|
2c2eb31e18 | ||
|
|
e13b72afca | ||
|
|
b9086b31e6 | ||
|
|
de2db7c2d2 | ||
|
|
238afda9da | ||
|
|
e7d557fd9e | ||
|
|
4fc763cfa2 | ||
|
|
b47f3adbb3 | ||
|
|
862e3c430c | ||
|
|
dc127e2994 | ||
|
|
3c1190e2c3 | ||
|
|
a104d18277 | ||
|
|
6048b1e270 | ||
|
|
0ef2e330e3 | ||
|
|
b417bd5be4 | ||
|
|
7f84191748 | ||
|
|
29f78248dc | ||
|
|
638f8a52d1 | ||
|
|
4432cc2253 | ||
|
|
730144cc26 | ||
|
|
c463d0cf80 | ||
|
|
8eecae92b2 | ||
|
|
6832451561 | ||
|
|
41925b6606 | ||
|
|
211d97ff8a | ||
|
|
8fa953a516 | ||
|
|
7f8c9ffa30 | ||
|
|
f448b6b977 | ||
|
|
e0cfc33fe2 | ||
|
|
76236a0b75 | ||
|
|
0cb9d79044 | ||
|
|
eeaee94e5e | ||
|
|
ddbdac7d97 | ||
|
|
b44a1cd823 | ||
|
|
d6d02b9924 | ||
|
|
3699a57847 | ||
|
|
d45007b501 | ||
|
|
9c256afc1a | ||
|
|
538a1f5909 | ||
|
|
ecac383477 | ||
|
|
8a761d7e3b | ||
|
|
651c4b539a | ||
|
|
81330d32e0 | ||
|
|
3696e81eb4 | ||
|
|
46f28a9de9 | ||
|
|
dcd7ca78fc | ||
|
|
86a38a1c7e | ||
|
|
2d9203ee74 | ||
|
|
8392567962 | ||
|
|
f76102dab5 | ||
|
|
43cf0441db | ||
|
|
792dc83778 | ||
|
|
718b4afbf3 | ||
|
|
13f41f59d6 | ||
|
|
ca5b782106 | ||
|
|
8e7f215514 | ||
|
|
4fc4eb09b0 | ||
|
|
18e3f43df3 | ||
|
|
28b865acf0 | ||
|
|
dd56b2584b | ||
|
|
70c0812606 | ||
|
|
ef5cfd59d4 | ||
|
|
85a695caa1 | ||
|
|
30444057bd | ||
|
|
6eae8e361f | ||
|
|
7c57eb70e8 | ||
|
|
9f4c0ff624 | ||
|
|
60691819b1 |
@@ -1,5 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PROJECTS=$(dirname "$0")/../..
|
||||
go get -x github.com/sagernet/$1@$(git -C $PROJECTS/$1 rev-parse HEAD)
|
||||
|
||||
go get -x github.com/sagernet/sing@$(git -C $PROJECTS/sing rev-parse HEAD)
|
||||
go get -x github.com/sagernet/sing-dns@$(git -C $PROJECTS/sing-dns rev-parse HEAD)
|
||||
go get -x github.com/sagernet/sing-tun@$(git -C $PROJECTS/sing-tun rev-parse HEAD)
|
||||
go get -x github.com/sagernet/sing-shadowsocks@$(git -C $PROJECTS/sing-shadowsocks rev-parse HEAD)
|
||||
go get -x github.com/sagernet/sing-vmess@$(git -C $PROJECTS/sing-vmess rev-parse HEAD)
|
||||
go mod tidy
|
||||
|
||||
@@ -4,7 +4,6 @@ on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
- dev-next
|
||||
paths-ignore:
|
||||
- '**.md'
|
||||
- '.github/**'
|
||||
@@ -12,7 +11,6 @@ on:
|
||||
pull_request:
|
||||
branches:
|
||||
- dev
|
||||
- dev-next
|
||||
|
||||
jobs:
|
||||
build:
|
||||
|
||||
@@ -2,7 +2,7 @@ name: Generate Documents
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- dev
|
||||
- main
|
||||
paths:
|
||||
- docs/**
|
||||
- .github/workflows/mkdocs.yml
|
||||
|
||||
+2
-2
@@ -7,8 +7,8 @@ ENV GOPROXY ${GOPROXY}
|
||||
ENV CGO_ENABLED=0
|
||||
RUN set -ex \
|
||||
&& apk add git build-base \
|
||||
&& export COMMIT=$(git rev-parse --short HEAD) \
|
||||
&& go build -v -trimpath -tags 'no_gvisor,with_quic,with_wireguard,with_acme' \
|
||||
&& export COMMIT=$(git rev-parse HEAD) \
|
||||
&& go build -v -trimpath -tags 'with_quic,with_acme,with_wireguard,with_clash_api' \
|
||||
-o /go/bin/sing-box \
|
||||
-ldflags "-X github.com/sagernet/sing-box/constant.Commit=${COMMIT} -w -s -buildid=" \
|
||||
./cmd/sing-box
|
||||
|
||||
@@ -38,7 +38,7 @@ func format() error {
|
||||
return E.Cause(err, "read config")
|
||||
}
|
||||
var options option.Options
|
||||
err = options.UnmarshalJSON(configContent)
|
||||
err = json.Unmarshal(configContent, &options)
|
||||
if err != nil {
|
||||
return E.Cause(err, "decode config")
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/sing-box"
|
||||
"github.com/sagernet/sing-box/common/json"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
@@ -45,7 +46,7 @@ func readConfig() (option.Options, error) {
|
||||
return option.Options{}, E.Cause(err, "read config")
|
||||
}
|
||||
var options option.Options
|
||||
err = options.UnmarshalJSON(configContent)
|
||||
err = json.Unmarshal(configContent, &options)
|
||||
if err != nil {
|
||||
return option.Options{}, E.Cause(err, "decode config")
|
||||
}
|
||||
|
||||
@@ -1,13 +1,6 @@
|
||||
package baderror
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"strings"
|
||||
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
import "strings"
|
||||
|
||||
func Contains(err error, msgList ...string) bool {
|
||||
for _, msg := range msgList {
|
||||
@@ -17,46 +10,3 @@ func Contains(err error, msgList ...string) bool {
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func WrapH2(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
err = E.Unwrap(err)
|
||||
if err == io.ErrUnexpectedEOF {
|
||||
return io.EOF
|
||||
}
|
||||
if Contains(err, "client disconnected", "body closed by handler") {
|
||||
return net.ErrClosed
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func WrapGRPC(err error) error {
|
||||
// grpc uses stupid internal error types
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if Contains(err, "EOF") {
|
||||
return io.EOF
|
||||
}
|
||||
if Contains(err, "Canceled") {
|
||||
return context.Canceled
|
||||
}
|
||||
if Contains(err,
|
||||
"the client connection is closing",
|
||||
"server closed the stream without sending trailers") {
|
||||
return net.ErrClosed
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func WrapQUIC(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if Contains(err, "canceled with error code 0") {
|
||||
return net.ErrClosed
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
package baderror
|
||||
|
||||
import (
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
)
|
||||
|
||||
func WrapGRPC(err error) error {
|
||||
// grpc uses stupid internal error types
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
if Contains(err, "EOF") {
|
||||
return io.EOF
|
||||
}
|
||||
if Contains(err, "Canceled") {
|
||||
return context.Canceled
|
||||
}
|
||||
if Contains(err,
|
||||
"the client connection is closing",
|
||||
"server closed the stream without sending trailers") {
|
||||
return net.ErrClosed
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
package baderror
|
||||
|
||||
import (
|
||||
"io"
|
||||
"net"
|
||||
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
)
|
||||
|
||||
func WrapH2(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
err = E.Unwrap(err)
|
||||
if err == io.ErrUnexpectedEOF {
|
||||
return io.EOF
|
||||
}
|
||||
if Contains(err, "client disconnected", "body closed by handler") {
|
||||
return net.ErrClosed
|
||||
}
|
||||
return err
|
||||
}
|
||||
@@ -10,12 +10,15 @@ import (
|
||||
)
|
||||
|
||||
func New(router adapter.Router, options option.DialerOptions) N.Dialer {
|
||||
var dialer N.Dialer
|
||||
if options.Detour == "" {
|
||||
dialer = NewDefault(router, options)
|
||||
return NewDefault(router, options)
|
||||
} else {
|
||||
dialer = NewDetour(router, options.Detour)
|
||||
return NewDetour(router, options.Detour)
|
||||
}
|
||||
}
|
||||
|
||||
func NewOutbound(router adapter.Router, options option.OutboundDialerOptions) N.Dialer {
|
||||
dialer := New(router, options.DialerOptions)
|
||||
domainStrategy := dns.DomainStrategy(options.DomainStrategy)
|
||||
if domainStrategy != dns.DomainStrategyAsIS || options.Detour == "" {
|
||||
dialer = NewResolveDialer(router, dialer, domainStrategy, time.Duration(options.FallbackDelay))
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
package constant
|
||||
|
||||
var (
|
||||
Version = "1.0.1"
|
||||
Version = "1.0-beta3"
|
||||
Commit = ""
|
||||
)
|
||||
|
||||
+1
-27
@@ -1,35 +1,9 @@
|
||||
#### 1.0.1
|
||||
|
||||
* Fix match 4in6 address in ip_cidr
|
||||
* Fix clash api log level format error
|
||||
* Fix clash api unknown proxy type
|
||||
|
||||
#### 1.0
|
||||
|
||||
* Fix wireguard reconnect
|
||||
* Fix naive inbound
|
||||
* Fix json format error message
|
||||
* Fix processing vmess termination signal
|
||||
* Fix hysteria stream error
|
||||
* Fix listener close when proxyproto failed
|
||||
|
||||
#### 1.0-rc1
|
||||
|
||||
* Fix write log timestamp
|
||||
* Fix write zero
|
||||
* Fix dial parallel in direct outbound
|
||||
* Fix write trojan udp
|
||||
* Fix DNS routing
|
||||
* Add attribute support for geosite
|
||||
* Update documentation for [Dial Fields](/configuration/shared/dial)
|
||||
|
||||
#### 1.0-beta3
|
||||
|
||||
* Add [chained inbound](/configuration/shared/listen#detour) support
|
||||
* Add process_path rule item
|
||||
* Add macOS redirect support
|
||||
* Add ShadowTLS [Inbound](/configuration/inbound/shadowtls), [Outbound](/configuration/outbound/shadowtls)
|
||||
and [Examples](/examples/shadowtls)
|
||||
* Add ShadowTLS [Inbound](/configuration/inbound/shadowtls), [Outbound](/configuration/outbound/shadowtls) and [Examples](/examples/shadowtls)
|
||||
* Fix search android package in non-owner users
|
||||
* Fix socksaddr type condition
|
||||
* Fix smux session status
|
||||
|
||||
@@ -16,14 +16,12 @@
|
||||
|
||||
### Fields
|
||||
|
||||
| Field | Available Context |
|
||||
|-----------------------------------------------------------------------------------|-------------------|
|
||||
| `bind_interface` /`bind_address` /`routing_mark` /`reuse_addr` /`connect_timeout` | `detour` not set |
|
||||
|
||||
#### detour
|
||||
|
||||
The tag of the upstream outbound.
|
||||
|
||||
Other dial fields will be ignored when enabled.
|
||||
|
||||
#### bind_interface
|
||||
|
||||
The network interface to bind to.
|
||||
@@ -59,16 +57,13 @@ One of `prefer_ipv4` `prefer_ipv6` `ipv4_only` `ipv6_only`.
|
||||
|
||||
If set, the requested domain name will be resolved to IP before connect.
|
||||
|
||||
| Outbound | Effected domains | Fallback Value |
|
||||
|----------|--------------------------|-------------------------------------------|
|
||||
| `direct` | Domain in request | Take `inbound.domain_strategy` if not set |
|
||||
| others | Domain in server address | / |
|
||||
`dns.strategy` will be used if empty.
|
||||
|
||||
#### fallback_delay
|
||||
|
||||
The length of time to wait before spawning a RFC 6555 Fast Fallback connection.
|
||||
That is, is the amount of time to wait for connection to succeed before assuming
|
||||
that IPv4/IPv6 is misconfigured and falling back to other type of addresses.
|
||||
That is, is the amount of time to wait for IPv6 to succeed before assuming
|
||||
that IPv6 is misconfigured and falling back to IPv4 if `prefer_ipv4` is set.
|
||||
If zero, a default delay of 300ms is used.
|
||||
|
||||
Only take effect when `domain_strategy` is set.
|
||||
Only take effect when `domain_strategy` is `prefer_ipv4` or `prefer_ipv6`.
|
||||
@@ -35,7 +35,7 @@
|
||||
"password": "8JCsPssfgS8tiRwiMlhARg==",
|
||||
"detour": "shadowtls-out",
|
||||
"multiplex": {
|
||||
"enabled": true,
|
||||
"enabled": 1,
|
||||
"max_connections": 4,
|
||||
"min_streams": 4
|
||||
}
|
||||
@@ -52,4 +52,4 @@
|
||||
}
|
||||
]
|
||||
}
|
||||
```
|
||||
```
|
||||
@@ -11,7 +11,7 @@ the public internet.
|
||||
|
||||
##### on Linux
|
||||
|
||||
`auto-route` cannot automatically hijack DNS requests with `systemd-resolved` enabled, you can switch to NetworkManager.
|
||||
`auto-route` cannot automatically hijack DNS requests with `systemd-resoled` enabled, you can switch to NetworkManager.
|
||||
|
||||
#### System proxy
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
|
||||
##### Linux
|
||||
|
||||
`auto-route` 无法自动劫持 DNS 请求如果 `systemd-resolved` 开启, 您可以切换到 NetworkManager.
|
||||
`auto-route` 无法自动劫持 DNS 请求如果 `systemd-resoled` 开启, 您可以切换到 NetworkManager.
|
||||
|
||||
#### 系统代理
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ func getConfigs(logFactory log.Factory) func(w http.ResponseWriter, r *http.Requ
|
||||
logLevel := logFactory.Level()
|
||||
if logLevel == log.LevelTrace {
|
||||
logLevel = log.LevelDebug
|
||||
} else if logLevel < log.LevelError {
|
||||
} else if logLevel > log.LevelError {
|
||||
logLevel = log.LevelError
|
||||
}
|
||||
render.JSON(w, r, &configSchema{
|
||||
|
||||
@@ -75,13 +75,11 @@ func proxyInfo(server *Server, detour adapter.Outbound) *badjson.JSONObject {
|
||||
clashType = "Shadowsocks"
|
||||
case C.TypeVMess:
|
||||
clashType = "Vmess"
|
||||
case C.TypeTrojan:
|
||||
clashType = "Trojan"
|
||||
case C.TypeSelector:
|
||||
clashType = "Selector"
|
||||
isGroup = true
|
||||
default:
|
||||
clashType = "Socks"
|
||||
clashType = "Unknown"
|
||||
}
|
||||
info.Put("type", clashType)
|
||||
info.Put("name", detour.Tag())
|
||||
|
||||
@@ -20,11 +20,11 @@ require (
|
||||
github.com/pires/go-proxyproto v0.6.2
|
||||
github.com/sagernet/certmagic v0.0.0-20220819042630-4a57f8b6853a
|
||||
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb
|
||||
github.com/sagernet/sing v0.0.0-20220903085538-02b9ca1cc133
|
||||
github.com/sagernet/sing v0.0.0-20220829115648-e09c9f3fc812
|
||||
github.com/sagernet/sing-dns v0.0.0-20220822023312-3e086b06d666
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6
|
||||
github.com/sagernet/sing-tun v0.0.0-20220828031750-185b6c880a83
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220907073918-72d7fdf6825f
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220829020559-33915075430c
|
||||
github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195
|
||||
github.com/spf13/cobra v1.5.0
|
||||
github.com/stretchr/testify v1.8.0
|
||||
@@ -39,8 +39,6 @@ require (
|
||||
gvisor.dev/gvisor v0.0.0-20220819163037-ba6e795b139a
|
||||
)
|
||||
|
||||
//replace github.com/sagernet/sing => ../sing
|
||||
|
||||
require (
|
||||
github.com/ajg/form v1.5.1 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
|
||||
@@ -135,16 +135,16 @@ github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb h1:wc0yQ+SBn4TaTY
|
||||
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb/go.mod h1:MIccjRKnPTjWwAOpl+AUGWOkzyTd9tERytudxu+1ra4=
|
||||
github.com/sagernet/sing v0.0.0-20220812082120-05f9836bff8f/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||
github.com/sagernet/sing v0.0.0-20220903085538-02b9ca1cc133 h1:krnb8wKEFIdXhmJYlhJMbEcPsJFISy2fz90uHVz7hMU=
|
||||
github.com/sagernet/sing v0.0.0-20220903085538-02b9ca1cc133/go.mod h1:kZvzh1VDa/Dg/Bt5WaYKU0jl5ept8KKDpl3Ay4gRtRQ=
|
||||
github.com/sagernet/sing v0.0.0-20220829115648-e09c9f3fc812 h1:z5AqoJcMy+MaD9pstLt08c95t2Txlzvp5pk4lqXBQPc=
|
||||
github.com/sagernet/sing v0.0.0-20220829115648-e09c9f3fc812/go.mod h1:kZvzh1VDa/Dg/Bt5WaYKU0jl5ept8KKDpl3Ay4gRtRQ=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220822023312-3e086b06d666 h1:XUTocA/Ek0dFxUX+xJCWMPPFZCn2GC/uLrBjTSr1vHY=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220822023312-3e086b06d666/go.mod h1:eDyH7AJmqBGjZQdQmpZIzlbTREudZuWDExMuGKgjRVM=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6 h1:JJfDeYYhWunvtxsU/mOVNTmFQmnzGx9dY034qG6G3g4=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6/go.mod h1:EX3RbZvrwAkPI2nuGa78T2iQXmrkT+/VQtskjou42xM=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220828031750-185b6c880a83 h1:SoWiHYuOCVedqA7T/CJSZUUrcPGKQb2wFKEq8DphiAI=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220828031750-185b6c880a83/go.mod h1:76r07HS1WRcEI4mE9pFsohfTBUt1j/G9Avz6DaOP3VU=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220907073918-72d7fdf6825f h1:6l9aXZqAl1JqXJWi89KHpWnM/moQUPGG+XiwMc+yD0A=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220907073918-72d7fdf6825f/go.mod h1:u66Vv7NHXJWfeAmhh7JuJp/cwxmuQlM56QoZ7B7Mmd0=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220829020559-33915075430c h1:92Gn78/z/t6CkzZ4XWG/uPiCxhUmjPULFEHFMDY6K8k=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220829020559-33915075430c/go.mod h1:82O6gzbxLha/W/jxSVQbsqf2lVdRTjMIgyLug0lpJps=
|
||||
github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195 h1:5VBIbVw9q7aKbrFdT83mjkyvQ+VaRsQ6yflTepfln38=
|
||||
github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195/go.mod h1:yedWtra8nyGJ+SyI+ziwuaGMzBatbB10P1IOOZbbSK8=
|
||||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
||||
|
||||
@@ -40,11 +40,7 @@ func (a *myInboundAdapter) loopTCPIn() {
|
||||
for {
|
||||
conn, err := tcpListener.Accept()
|
||||
if err != nil {
|
||||
if E.IsClosed(err) {
|
||||
return
|
||||
}
|
||||
a.logger.Error("accept: ", err)
|
||||
continue
|
||||
return
|
||||
}
|
||||
go a.injectTCP(conn, adapter.InboundContext{})
|
||||
}
|
||||
|
||||
+6
-6
@@ -20,6 +20,7 @@ import (
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/auth"
|
||||
"github.com/sagernet/sing/common/buf"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
@@ -360,7 +361,7 @@ func (c *naiveH1Conn) WriteBuffer(buffer *buf.Buffer) error {
|
||||
n, err = bufio.Copy(w, c.Conn)
|
||||
}
|
||||
return n, wrapHttpError(err)
|
||||
}
|
||||
}*/
|
||||
|
||||
func (c *naiveH1Conn) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
if c.writePadding < kFirstPaddings {
|
||||
@@ -370,14 +371,13 @@ func (c *naiveH1Conn) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
}
|
||||
return n, wrapHttpError(err)
|
||||
}
|
||||
*/
|
||||
|
||||
func (c *naiveH1Conn) Upstream() any {
|
||||
return c.Conn
|
||||
}
|
||||
|
||||
func (c *naiveH1Conn) ReaderReplaceable() bool {
|
||||
return c.readPadding == kFirstPaddings
|
||||
return c.readRemaining == kFirstPaddings
|
||||
}
|
||||
|
||||
func (c *naiveH1Conn) WriterReplaceable() bool {
|
||||
@@ -539,7 +539,7 @@ func (c *naiveH2Conn) WriteBuffer(buffer *buf.Buffer) error {
|
||||
n, err = bufio.Copy(w, c.reader)
|
||||
}
|
||||
return n, wrapHttpError(err)
|
||||
}
|
||||
}*/
|
||||
|
||||
func (c *naiveH2Conn) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
if c.writePadding < kFirstPaddings {
|
||||
@@ -548,7 +548,7 @@ func (c *naiveH2Conn) ReadFrom(r io.Reader) (n int64, err error) {
|
||||
n, err = bufio.Copy(c.writer, r)
|
||||
}
|
||||
return n, wrapHttpError(err)
|
||||
}*/
|
||||
}
|
||||
|
||||
func (c *naiveH2Conn) Close() error {
|
||||
return common.Close(
|
||||
@@ -586,7 +586,7 @@ func (c *naiveH2Conn) UpstreamWriter() any {
|
||||
}
|
||||
|
||||
func (c *naiveH2Conn) ReaderReplaceable() bool {
|
||||
return c.readPadding == kFirstPaddings
|
||||
return c.readRemaining == kFirstPaddings
|
||||
}
|
||||
|
||||
func (c *naiveH2Conn) WriterReplaceable() bool {
|
||||
|
||||
+2
-2
@@ -71,7 +71,7 @@ func (f Formatter) Format(ctx context.Context, level Level, tag string, message
|
||||
case f.DisableTimestamp:
|
||||
message = levelString + " " + message
|
||||
case f.FullTimestamp:
|
||||
message = timestamp.Format(f.TimestampFormat) + " " + levelString + " " + message
|
||||
message = F.ToString(int(timestamp.Sub(f.BaseTime)/time.Second)) + " " + levelString + " " + message
|
||||
default:
|
||||
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
|
||||
}
|
||||
@@ -136,7 +136,7 @@ func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string
|
||||
case f.DisableTimestamp:
|
||||
message = levelString + " " + message
|
||||
case f.FullTimestamp:
|
||||
message = timestamp.Format(f.TimestampFormat) + " " + levelString + " " + message
|
||||
message = F.ToString(int(timestamp.Sub(f.BaseTime)/time.Second)) + " " + levelString + " " + message
|
||||
default:
|
||||
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
|
||||
}
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ type DirectInboundOptions struct {
|
||||
}
|
||||
|
||||
type DirectOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
OverrideAddress string `json:"override_address,omitempty"`
|
||||
OverridePort uint16 `json:"override_port,omitempty"`
|
||||
ProxyProtocol uint8 `json:"proxy_protocol,omitempty"`
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ type HysteriaInboundOptions struct {
|
||||
}
|
||||
|
||||
type HysteriaOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
Up string `json:"up,omitempty"`
|
||||
UpMbps int `json:"up_mbps,omitempty"`
|
||||
|
||||
@@ -113,6 +113,10 @@ type DialerOptions struct {
|
||||
ReuseAddr bool `json:"reuse_addr,omitempty"`
|
||||
ConnectTimeout Duration `json:"connect_timeout,omitempty"`
|
||||
TCPFastOpen bool `json:"tcp_fast_open,omitempty"`
|
||||
}
|
||||
|
||||
type OutboundDialerOptions struct {
|
||||
DialerOptions
|
||||
DomainStrategy DomainStrategy `json:"domain_strategy,omitempty"`
|
||||
FallbackDelay Duration `json:"fallback_delay,omitempty"`
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ type ShadowsocksDestination struct {
|
||||
}
|
||||
|
||||
type ShadowsocksOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
Method string `json:"method"`
|
||||
Password string `json:"password"`
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ type ShadowTLSHandshakeOptions struct {
|
||||
}
|
||||
|
||||
type ShadowTLSOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
||||
}
|
||||
|
||||
+2
-2
@@ -15,7 +15,7 @@ type HTTPMixedInboundOptions struct {
|
||||
}
|
||||
|
||||
type SocksOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
Version string `json:"version,omitempty"`
|
||||
Username string `json:"username,omitempty"`
|
||||
@@ -25,7 +25,7 @@ type SocksOutboundOptions struct {
|
||||
}
|
||||
|
||||
type HTTPOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
Username string `json:"username,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package option
|
||||
|
||||
type SSHOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
User string `json:"user,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package option
|
||||
|
||||
type TorOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ExecutablePath string `json:"executable_path,omitempty"`
|
||||
ExtraArgs []string `json:"extra_args,omitempty"`
|
||||
DataDirectory string `json:"data_directory,omitempty"`
|
||||
|
||||
+1
-1
@@ -15,7 +15,7 @@ type TrojanUser struct {
|
||||
}
|
||||
|
||||
type TrojanOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
Password string `json:"password"`
|
||||
Network NetworkList `json:"network,omitempty"`
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ type VMessUser struct {
|
||||
}
|
||||
|
||||
type VMessOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
UUID string `json:"uuid"`
|
||||
Security string `json:"security"`
|
||||
|
||||
+1
-1
@@ -1,7 +1,7 @@
|
||||
package option
|
||||
|
||||
type WireGuardOutboundOptions struct {
|
||||
DialerOptions
|
||||
OutboundDialerOptions
|
||||
ServerOptions
|
||||
LocalAddress Listable[string] `json:"local_address"`
|
||||
PrivateKey string `json:"private_key"`
|
||||
|
||||
+3
-59
@@ -4,14 +4,12 @@ import (
|
||||
"context"
|
||||
"net"
|
||||
"net/netip"
|
||||
"time"
|
||||
|
||||
"github.com/sagernet/sing-box/adapter"
|
||||
"github.com/sagernet/sing-box/common/dialer"
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/log"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing-dns"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
@@ -19,16 +17,11 @@ import (
|
||||
"github.com/pires/go-proxyproto"
|
||||
)
|
||||
|
||||
var (
|
||||
_ adapter.Outbound = (*Direct)(nil)
|
||||
_ N.ParallelDialer = (*Direct)(nil)
|
||||
)
|
||||
var _ adapter.Outbound = (*Direct)(nil)
|
||||
|
||||
type Direct struct {
|
||||
myOutboundAdapter
|
||||
dialer N.Dialer
|
||||
domainStrategy dns.DomainStrategy
|
||||
fallbackDelay time.Duration
|
||||
overrideOption int
|
||||
overrideDestination M.Socksaddr
|
||||
proxyProto uint8
|
||||
@@ -43,10 +36,8 @@ func NewDirect(router adapter.Router, logger log.ContextLogger, tag string, opti
|
||||
logger: logger,
|
||||
tag: tag,
|
||||
},
|
||||
domainStrategy: dns.DomainStrategy(options.DomainStrategy),
|
||||
fallbackDelay: time.Duration(options.FallbackDelay),
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
proxyProto: options.ProxyProtocol,
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
proxyProto: options.ProxyProtocol,
|
||||
}
|
||||
if options.ProxyProtocol > 2 {
|
||||
return nil, E.New("invalid proxy protocol option: ", options.ProxyProtocol)
|
||||
@@ -108,53 +99,6 @@ func (h *Direct) DialContext(ctx context.Context, network string, destination M.
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (h *Direct) DialParallel(ctx context.Context, network string, destination M.Socksaddr, destinationAddresses []netip.Addr) (net.Conn, error) {
|
||||
ctx, metadata := adapter.AppendContext(ctx)
|
||||
originDestination := metadata.Destination
|
||||
metadata.Outbound = h.tag
|
||||
metadata.Destination = destination
|
||||
switch h.overrideOption {
|
||||
case 1, 2:
|
||||
// override address
|
||||
return h.DialContext(ctx, network, destination)
|
||||
case 3:
|
||||
destination.Port = h.overrideDestination.Port
|
||||
}
|
||||
network = N.NetworkName(network)
|
||||
switch network {
|
||||
case N.NetworkTCP:
|
||||
h.logger.InfoContext(ctx, "outbound connection to ", destination)
|
||||
case N.NetworkUDP:
|
||||
h.logger.InfoContext(ctx, "outbound packet connection to ", destination)
|
||||
}
|
||||
var domainStrategy dns.DomainStrategy
|
||||
if h.domainStrategy != dns.DomainStrategyAsIS {
|
||||
domainStrategy = h.domainStrategy
|
||||
} else {
|
||||
domainStrategy = metadata.DomainStrategy
|
||||
}
|
||||
conn, err := N.DialParallel(ctx, h.dialer, network, destination, destinationAddresses, domainStrategy == dns.DomainStrategyPreferIPv6, h.fallbackDelay)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if h.proxyProto > 0 {
|
||||
source := metadata.Source
|
||||
if !source.IsValid() {
|
||||
source = M.SocksaddrFromNet(conn.LocalAddr())
|
||||
}
|
||||
if originDestination.Addr.Is6() {
|
||||
source = M.SocksaddrFrom(netip.AddrFrom16(source.Addr.As16()), source.Port)
|
||||
}
|
||||
header := proxyproto.HeaderProxyFromAddrs(h.proxyProto, source.TCPAddr(), originDestination.TCPAddr())
|
||||
_, err = header.WriteTo(conn)
|
||||
if err != nil {
|
||||
conn.Close()
|
||||
return nil, E.Cause(err, "write proxy protocol header")
|
||||
}
|
||||
}
|
||||
return conn, nil
|
||||
}
|
||||
|
||||
func (h *Direct) ListenPacket(ctx context.Context, destination M.Socksaddr) (net.PacketConn, error) {
|
||||
ctx, metadata := adapter.AppendContext(ctx)
|
||||
metadata.Outbound = h.tag
|
||||
|
||||
+10
-4
@@ -77,9 +77,12 @@ func (d *DNS) handleConnection(ctx context.Context, conn net.Conn, metadata adap
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
metadataInQuery := metadata
|
||||
if len(message.Questions) > 0 {
|
||||
question := message.Questions[0]
|
||||
metadata.Domain = string(question.Name.Data[:question.Name.Length-1])
|
||||
}
|
||||
go func() error {
|
||||
response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message)
|
||||
response, err := d.router.Exchange(ctx, &message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -122,10 +125,13 @@ func (d *DNS) NewPacketConnection(ctx context.Context, conn N.PacketConn, metada
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(message.Questions) > 0 {
|
||||
question := message.Questions[0]
|
||||
metadata.Domain = string(question.Name.Data[:question.Name.Length-1])
|
||||
}
|
||||
timeout.Update()
|
||||
metadataInQuery := metadata
|
||||
go func() error {
|
||||
response, err := d.router.Exchange(adapter.WithContext(ctx, &metadataInQuery), &message)
|
||||
response, err := d.router.Exchange(ctx, &message)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
+1
-1
@@ -24,7 +24,7 @@ type HTTP struct {
|
||||
}
|
||||
|
||||
func NewHTTP(router adapter.Router, logger log.ContextLogger, tag string, options option.HTTPOutboundOptions) (*HTTP, error) {
|
||||
detour, err := dialer.NewTLS(dialer.New(router, options.DialerOptions), options.Server, common.PtrValueOrDefault(options.TLS))
|
||||
detour, err := dialer.NewTLS(dialer.NewOutbound(router, options.OutboundDialerOptions), options.Server, common.PtrValueOrDefault(options.TLS))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ func NewHysteria(ctx context.Context, router adapter.Router, logger log.ContextL
|
||||
tag: tag,
|
||||
},
|
||||
ctx: ctx,
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
serverAddr: options.ServerOptions.Build(),
|
||||
tlsConfig: tlsConfig,
|
||||
quicConfig: quicConfig,
|
||||
|
||||
@@ -44,7 +44,7 @@ func NewShadowsocks(ctx context.Context, router adapter.Router, logger log.Conte
|
||||
logger: logger,
|
||||
tag: tag,
|
||||
},
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
method: method,
|
||||
serverAddr: options.ServerOptions.Build(),
|
||||
uot: options.UoT,
|
||||
|
||||
@@ -34,7 +34,7 @@ func NewShadowTLS(ctx context.Context, router adapter.Router, logger log.Context
|
||||
logger: logger,
|
||||
tag: tag,
|
||||
},
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
serverAddr: options.ServerOptions.Build(),
|
||||
}
|
||||
if options.TLS == nil || !options.TLS.Enabled {
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ type Socks struct {
|
||||
}
|
||||
|
||||
func NewSocks(router adapter.Router, logger log.ContextLogger, tag string, options option.SocksOutboundOptions) (*Socks, error) {
|
||||
detour := dialer.New(router, options.DialerOptions)
|
||||
detour := dialer.NewOutbound(router, options.OutboundDialerOptions)
|
||||
var version socks.Version
|
||||
var err error
|
||||
if options.Version != "" {
|
||||
|
||||
+1
-1
@@ -47,7 +47,7 @@ func NewSSH(ctx context.Context, router adapter.Router, logger log.ContextLogger
|
||||
tag: tag,
|
||||
},
|
||||
ctx: ctx,
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
serverAddr: options.ServerOptions.Build(),
|
||||
user: options.User,
|
||||
hostKeyAlgorithms: options.HostKeyAlgorithms,
|
||||
|
||||
+1
-1
@@ -66,7 +66,7 @@ func NewTor(ctx context.Context, router adapter.Router, logger log.ContextLogger
|
||||
tag: tag,
|
||||
},
|
||||
ctx: ctx,
|
||||
proxy: NewProxyListener(ctx, logger, dialer.New(router, options.DialerOptions)),
|
||||
proxy: NewProxyListener(ctx, logger, dialer.NewOutbound(router, options.OutboundDialerOptions)),
|
||||
startConf: &startConf,
|
||||
options: options.Options,
|
||||
}, nil
|
||||
|
||||
+3
-4
@@ -13,7 +13,6 @@ import (
|
||||
"github.com/sagernet/sing-box/option"
|
||||
"github.com/sagernet/sing-box/transport/v2ray"
|
||||
"github.com/sagernet/sing/common"
|
||||
"github.com/sagernet/sing/common/bufio"
|
||||
E "github.com/sagernet/sing/common/exceptions"
|
||||
M "github.com/sagernet/sing/common/metadata"
|
||||
N "github.com/sagernet/sing/common/network"
|
||||
@@ -41,7 +40,7 @@ func NewTrojan(ctx context.Context, router adapter.Router, logger log.ContextLog
|
||||
logger: logger,
|
||||
tag: tag,
|
||||
},
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
serverAddr: options.ServerOptions.Build(),
|
||||
key: trojan.Key(options.Password),
|
||||
}
|
||||
@@ -126,7 +125,7 @@ func (h *trojanDialer) DialContext(ctx context.Context, network string, destinat
|
||||
case N.NetworkTCP:
|
||||
return trojan.NewClientConn(conn, h.key, destination), nil
|
||||
case N.NetworkUDP:
|
||||
return &bufio.BindPacketConn{PacketConn: trojan.NewClientPacketConn(conn, h.key), Addr: destination}, nil
|
||||
return trojan.NewClientPacketConn(conn, h.key), nil
|
||||
default:
|
||||
return nil, E.Extend(N.ErrUnknownNetwork, network)
|
||||
}
|
||||
@@ -137,5 +136,5 @@ func (h *trojanDialer) ListenPacket(ctx context.Context, destination M.Socksaddr
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return conn.(net.PacketConn), nil
|
||||
return conn.(*trojan.ClientPacketConn), nil
|
||||
}
|
||||
|
||||
+1
-1
@@ -42,7 +42,7 @@ func NewVMess(ctx context.Context, router adapter.Router, logger log.ContextLogg
|
||||
logger: logger,
|
||||
tag: tag,
|
||||
},
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
serverAddr: options.ServerOptions.Build(),
|
||||
}
|
||||
var err error
|
||||
|
||||
@@ -64,7 +64,7 @@ func NewWireGuard(ctx context.Context, router adapter.Router, logger log.Context
|
||||
},
|
||||
ctx: ctx,
|
||||
serverAddr: options.ServerOptions.Build(),
|
||||
dialer: dialer.New(router, options.DialerOptions),
|
||||
dialer: dialer.NewOutbound(router, options.OutboundDialerOptions),
|
||||
}
|
||||
var endpointIp netip.Addr
|
||||
if !outbound.serverAddr.IsFqdn() {
|
||||
@@ -275,7 +275,6 @@ func (c *wireClientBind) Open(port uint16) (fns []conn.ReceiveFunc, actualPort u
|
||||
func (c *wireClientBind) receive(b []byte) (n int, ep conn.Endpoint, err error) {
|
||||
udpConn, err := c.connect()
|
||||
if err != nil {
|
||||
err = &wireError{err}
|
||||
return
|
||||
}
|
||||
n, err = udpConn.Read(b)
|
||||
@@ -333,6 +332,10 @@ func (w *wireError) Temporary() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (w *wireError) Unwrap() error {
|
||||
return w.cause
|
||||
}
|
||||
|
||||
type wireConn struct {
|
||||
net.Conn
|
||||
access sync.Mutex
|
||||
|
||||
@@ -10,7 +10,7 @@ DIR=$(dirname "$0")
|
||||
PROJECT=$DIR/../..
|
||||
|
||||
pushd $PROJECT
|
||||
go install -v -trimpath -ldflags "-s -w -buildid=" -tags no_gvisor,with_quic,with_wireguard,with_acme ./cmd/sing-box
|
||||
go install -v -trimpath -ldflags "-s -w -buildid=" -tags "no_gvisor" ./cmd/sing-box
|
||||
popd
|
||||
|
||||
sudo cp $(go env GOPATH)/bin/sing-box /usr/local/bin/
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e -o pipefail
|
||||
curl -Lo go.tar.gz https://go.dev/dl/go1.19.linux-amd64.tar.gz
|
||||
curl -o go.tar.gz https://go.dev/dl/go1.19.linux-amd64.tar.gz
|
||||
sudo rm -rf /usr/local/go
|
||||
sudo tar -C /usr/local -xzf go.tar.gz
|
||||
rm go.tar.gz
|
||||
@@ -10,7 +10,7 @@ DIR=$(dirname "$0")
|
||||
PROJECT=$DIR/../..
|
||||
|
||||
pushd $PROJECT
|
||||
go install -v -trimpath -ldflags "-s -w -buildid=" -tags no_gvisor,with_quic,with_wireguard,with_acme ./cmd/sing-box
|
||||
go install -v -trimpath -ldflags "-s -w -buildid=" -tags no_gvisor,with_quic,with_acme ./cmd/sing-box
|
||||
popd
|
||||
|
||||
sudo systemctl stop sing-box
|
||||
|
||||
@@ -52,7 +52,6 @@ func (r *Router) Exchange(ctx context.Context, message *dnsmessage.Message) (*dn
|
||||
case dnsmessage.TypeAAAA:
|
||||
metadata.IPVersion = 6
|
||||
}
|
||||
metadata.Domain = string(message.Questions[0].Name.Data[:message.Questions[0].Name.Length-1])
|
||||
}
|
||||
ctx, transport, strategy := r.matchDNS(ctx)
|
||||
ctx, cancel := context.WithTimeout(ctx, C.DNSTimeout)
|
||||
@@ -69,8 +68,6 @@ func (r *Router) Exchange(ctx context.Context, message *dnsmessage.Message) (*dn
|
||||
|
||||
func (r *Router) Lookup(ctx context.Context, domain string, strategy dns.DomainStrategy) ([]netip.Addr, error) {
|
||||
r.dnsLogger.DebugContext(ctx, "lookup domain ", domain)
|
||||
ctx, metadata := adapter.AppendContext(ctx)
|
||||
metadata.Domain = domain
|
||||
ctx, transport, transportStrategy := r.matchDNS(ctx)
|
||||
if strategy == dns.DomainStrategyAsIS {
|
||||
strategy = transportStrategy
|
||||
|
||||
+3
-11
@@ -59,13 +59,13 @@ func NewIPCIDRItem(isSource bool, prefixStrings []string) (*IPCIDRItem, error) {
|
||||
|
||||
func (r *IPCIDRItem) Match(metadata *adapter.InboundContext) bool {
|
||||
if r.isSource {
|
||||
return r.match(metadata.Source.Addr)
|
||||
return r.ipSet.Contains(metadata.Source.Addr)
|
||||
} else {
|
||||
if metadata.Destination.IsIP() {
|
||||
return r.match(metadata.Destination.Addr)
|
||||
return r.ipSet.Contains(metadata.Destination.Addr)
|
||||
} else {
|
||||
for _, address := range metadata.DestinationAddresses {
|
||||
if r.match(address) {
|
||||
if r.ipSet.Contains(address) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
@@ -74,14 +74,6 @@ func (r *IPCIDRItem) Match(metadata *adapter.InboundContext) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (r *IPCIDRItem) match(address netip.Addr) bool {
|
||||
if address.Is4In6() {
|
||||
return r.ipSet.Contains(netip.AddrFrom4(address.As4()))
|
||||
} else {
|
||||
return r.ipSet.Contains(address)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *IPCIDRItem) String() string {
|
||||
return r.description
|
||||
}
|
||||
|
||||
@@ -22,10 +22,6 @@ func startInstance(t *testing.T, options option.Options) {
|
||||
options.Log = &option.LogOptions{
|
||||
Level: "trace",
|
||||
}
|
||||
} else {
|
||||
options.Log = &option.LogOptions{
|
||||
Level: "warning",
|
||||
}
|
||||
}
|
||||
var instance *box.Box
|
||||
var err error
|
||||
|
||||
@@ -183,7 +183,6 @@ func testPingPongWithConn(t *testing.T, port uint16, cc func() (net.Conn, error)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
pingCh, pongCh, test := newPingPongPair()
|
||||
go func() {
|
||||
@@ -246,7 +245,6 @@ func testPingPongWithPacketConn(t *testing.T, port uint16, pcc func() (net.Packe
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer pc.Close()
|
||||
|
||||
go func() {
|
||||
if _, err := pc.WriteTo([]byte("ping"), rAddr); err != nil {
|
||||
@@ -303,7 +301,6 @@ func testLargeDataWithConn(t *testing.T, port uint16, cc func() (net.Conn, error
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer c.Close()
|
||||
|
||||
go func() {
|
||||
c, err := l.Accept()
|
||||
@@ -435,7 +432,6 @@ func testLargeDataWithPacketConn(t *testing.T, port uint16, pcc func() (net.Pack
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer pc.Close()
|
||||
|
||||
go func() {
|
||||
sendHash, err := writeRandData(pc, rAddr)
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
{
|
||||
"log": {
|
||||
"loglevel": "debug"
|
||||
},
|
||||
"inbounds": [
|
||||
{
|
||||
"listen": "127.0.0.1",
|
||||
"port": "1080",
|
||||
"protocol": "socks",
|
||||
"settings": {
|
||||
"auth": "noauth",
|
||||
"udp": true,
|
||||
"ip": "127.0.0.1"
|
||||
}
|
||||
}
|
||||
],
|
||||
"outbounds": [
|
||||
{
|
||||
"protocol": "vmess",
|
||||
"settings": {
|
||||
"vnext": [
|
||||
{
|
||||
"address": "127.0.0.1",
|
||||
"port": 1234,
|
||||
"users": [
|
||||
{
|
||||
"id": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"streamSettings": {
|
||||
"network": "ws",
|
||||
"security": "tls",
|
||||
"tlsSettings": {
|
||||
"serverName": "example.org",
|
||||
"certificates": [
|
||||
{
|
||||
"certificateFile": "/path/to/certificate.crt",
|
||||
"keyFile": "/path/to/private.key"
|
||||
}
|
||||
]
|
||||
},
|
||||
"wsSettings": {
|
||||
"maxEarlyData": 2048,
|
||||
"earlyDataHeaderName": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
{
|
||||
"log": {
|
||||
"loglevel": "debug"
|
||||
},
|
||||
"inbounds": [
|
||||
{
|
||||
"listen": "0.0.0.0",
|
||||
"port": 1234,
|
||||
"protocol": "vmess",
|
||||
"settings": {
|
||||
"clients": [
|
||||
{
|
||||
"id": "b831381d-6324-4d53-ad4f-8cda48b30811"
|
||||
}
|
||||
]
|
||||
},
|
||||
"streamSettings": {
|
||||
"network": "ws",
|
||||
"security": "tls",
|
||||
"tlsSettings": {
|
||||
"serverName": "example.org",
|
||||
"certificates": [
|
||||
{
|
||||
"certificateFile": "/path/to/certificate.crt",
|
||||
"keyFile": "/path/to/private.key"
|
||||
}
|
||||
]
|
||||
},
|
||||
"wsSettings": {
|
||||
"maxEarlyData": 2048,
|
||||
"earlyDataHeaderName": ""
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"outbounds": [
|
||||
{
|
||||
"protocol": "freedom"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -10,6 +10,9 @@ import (
|
||||
|
||||
func TestProxyProtocol(t *testing.T) {
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
+7
-9
@@ -10,15 +10,13 @@ require (
|
||||
github.com/docker/docker v20.10.17+incompatible
|
||||
github.com/docker/go-connections v0.4.0
|
||||
github.com/gofrs/uuid v4.2.0+incompatible
|
||||
github.com/sagernet/sing v0.0.0-20220903085538-02b9ca1cc133
|
||||
github.com/sagernet/sing v0.0.0-20220829115648-e09c9f3fc812
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6
|
||||
github.com/spyzhov/ajson v0.7.1
|
||||
github.com/stretchr/testify v1.8.0
|
||||
golang.org/x/net v0.0.0-20220826154423-83b083e8dc8b
|
||||
)
|
||||
|
||||
//replace github.com/sagernet/sing => ../../sing
|
||||
|
||||
require (
|
||||
berty.tech/go-libtor v1.0.385 // indirect
|
||||
github.com/Microsoft/go-winio v0.5.1 // indirect
|
||||
@@ -61,25 +59,25 @@ require (
|
||||
github.com/sagernet/go-tun2socks v1.16.12-0.20220818015926-16cb67876a61 // indirect
|
||||
github.com/sagernet/netlink v0.0.0-20220826133217-3fb4ff92ea17 // indirect
|
||||
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb // indirect
|
||||
github.com/sagernet/sing-dns v0.0.0-20220903082137-b1102b8fc961 // indirect
|
||||
github.com/sagernet/sing-dns v0.0.0-20220822023312-3e086b06d666 // indirect
|
||||
github.com/sagernet/sing-tun v0.0.0-20220828031750-185b6c880a83 // indirect
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220907073918-72d7fdf6825f // indirect
|
||||
github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195 // indirect
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220829020559-33915075430c // indirect
|
||||
github.com/sagernet/smux v0.0.0-20220812084127-e2d085ee3939 // indirect
|
||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||
github.com/vishvananda/netns v0.0.0-20211101163701-50045581ed74 // indirect
|
||||
go.uber.org/atomic v1.10.0 // indirect
|
||||
go.uber.org/multierr v1.6.0 // indirect
|
||||
go.uber.org/zap v1.22.0 // indirect
|
||||
go4.org/netipx v0.0.0-20220812043211-3cc044ffd68d // indirect
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 // indirect
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d // indirect
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
|
||||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
|
||||
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 // indirect
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
|
||||
golang.org/x/text v0.3.7 // indirect
|
||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 // indirect
|
||||
golang.org/x/tools v0.1.11-0.20220513221640-090b14e8501f // indirect
|
||||
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 // indirect
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220829161405-d1d08426b27b // indirect
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478 // indirect
|
||||
google.golang.org/genproto v0.0.0-20210722135532-667f2b7c528f // indirect
|
||||
google.golang.org/grpc v1.49.0 // indirect
|
||||
google.golang.org/protobuf v1.28.1 // indirect
|
||||
|
||||
+14
-14
@@ -155,18 +155,18 @@ github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb h1:wc0yQ+SBn4TaTY
|
||||
github.com/sagernet/quic-go v0.0.0-20220818150011-de611ab3e2bb/go.mod h1:MIccjRKnPTjWwAOpl+AUGWOkzyTd9tERytudxu+1ra4=
|
||||
github.com/sagernet/sing v0.0.0-20220812082120-05f9836bff8f/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||
github.com/sagernet/sing v0.0.0-20220817130738-ce854cda8522/go.mod h1:QVsS5L/ZA2Q5UhQwLrn0Trw+msNd/NPGEhBKR/ioWiY=
|
||||
github.com/sagernet/sing v0.0.0-20220903085538-02b9ca1cc133 h1:krnb8wKEFIdXhmJYlhJMbEcPsJFISy2fz90uHVz7hMU=
|
||||
github.com/sagernet/sing v0.0.0-20220903085538-02b9ca1cc133/go.mod h1:kZvzh1VDa/Dg/Bt5WaYKU0jl5ept8KKDpl3Ay4gRtRQ=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220903082137-b1102b8fc961 h1:5JeqhvCGV6AQQiAO0V67Loh2eyO3JNjIQnvRF8NnTE0=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220903082137-b1102b8fc961/go.mod h1:vKBBy4mNJRaFuJ8H6kYIOPofsZ1JT5mgdwIlebtvnZ4=
|
||||
github.com/sagernet/sing v0.0.0-20220829115648-e09c9f3fc812 h1:z5AqoJcMy+MaD9pstLt08c95t2Txlzvp5pk4lqXBQPc=
|
||||
github.com/sagernet/sing v0.0.0-20220829115648-e09c9f3fc812/go.mod h1:kZvzh1VDa/Dg/Bt5WaYKU0jl5ept8KKDpl3Ay4gRtRQ=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220822023312-3e086b06d666 h1:XUTocA/Ek0dFxUX+xJCWMPPFZCn2GC/uLrBjTSr1vHY=
|
||||
github.com/sagernet/sing-dns v0.0.0-20220822023312-3e086b06d666/go.mod h1:eDyH7AJmqBGjZQdQmpZIzlbTREudZuWDExMuGKgjRVM=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6 h1:JJfDeYYhWunvtxsU/mOVNTmFQmnzGx9dY034qG6G3g4=
|
||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220819002358-7461bb09a8f6/go.mod h1:EX3RbZvrwAkPI2nuGa78T2iQXmrkT+/VQtskjou42xM=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220828031750-185b6c880a83 h1:SoWiHYuOCVedqA7T/CJSZUUrcPGKQb2wFKEq8DphiAI=
|
||||
github.com/sagernet/sing-tun v0.0.0-20220828031750-185b6c880a83/go.mod h1:76r07HS1WRcEI4mE9pFsohfTBUt1j/G9Avz6DaOP3VU=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220907073918-72d7fdf6825f h1:6l9aXZqAl1JqXJWi89KHpWnM/moQUPGG+XiwMc+yD0A=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220907073918-72d7fdf6825f/go.mod h1:u66Vv7NHXJWfeAmhh7JuJp/cwxmuQlM56QoZ7B7Mmd0=
|
||||
github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195 h1:5VBIbVw9q7aKbrFdT83mjkyvQ+VaRsQ6yflTepfln38=
|
||||
github.com/sagernet/smux v0.0.0-20220831015742-e0f1988e3195/go.mod h1:yedWtra8nyGJ+SyI+ziwuaGMzBatbB10P1IOOZbbSK8=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220829020559-33915075430c h1:92Gn78/z/t6CkzZ4XWG/uPiCxhUmjPULFEHFMDY6K8k=
|
||||
github.com/sagernet/sing-vmess v0.0.0-20220829020559-33915075430c/go.mod h1:82O6gzbxLha/W/jxSVQbsqf2lVdRTjMIgyLug0lpJps=
|
||||
github.com/sagernet/smux v0.0.0-20220812084127-e2d085ee3939 h1:pB1Dh1NbwVrLhQhotr4O4Hs3yhiBzmg3AvnUyYjL4x4=
|
||||
github.com/sagernet/smux v0.0.0-20220812084127-e2d085ee3939/go.mod h1:yedWtra8nyGJ+SyI+ziwuaGMzBatbB10P1IOOZbbSK8=
|
||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
github.com/sirupsen/logrus v1.8.1 h1:dJKuHgqk1NNQlqoA6BTlM1Wf9DOH3NBjQyu0h9+AZZE=
|
||||
github.com/sirupsen/logrus v1.8.1/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||
@@ -205,8 +205,8 @@ golang.org/x/crypto v0.0.0-20190404164418-38d8ce5564a5/go.mod h1:WFFai1msRO1wXaE
|
||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90 h1:Y/gsMcFOcR+6S6f3YeMKl5g+dZMEWqcz5Czj/GWYbkM=
|
||||
golang.org/x/crypto v0.0.0-20220829220503-c86fa9a7ed90/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d h1:3qF+Z8Hkrw9sOhrFHti9TlB1Hkac1x+DNRkv0XQiFjo=
|
||||
golang.org/x/crypto v0.0.0-20220826181053-bd7e27e6170d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e h1:+WEEuIdZHnUeJJmEUjyYC2gfUMj69yZXw17EnHg/otA=
|
||||
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e/go.mod h1:Kr81I6Kryrl9sr8s2FK3vxD90NdsKWRuOIl2O4CvYbA=
|
||||
@@ -275,8 +275,8 @@ golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBc
|
||||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220731174439-a90be440212d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261 h1:v6hYoSR9T5oet+pMXwUWkbiVqx/63mlHjefrHmxwfeY=
|
||||
golang.org/x/sys v0.0.0-20220829200755-d48e67d00261/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 h1:UiNENfZ8gDvpiWw7IpOMQ27spWmThO1RwwdQVbJahJM=
|
||||
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 h1:JGgROgKl9N8DuW20oFS5gxc+lE67/N3FcwmBPMe7ArY=
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
|
||||
@@ -311,8 +311,8 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T
|
||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224 h1:Ug9qvr1myri/zFN6xL17LSCBGFDnphBBhzmILHsM5TY=
|
||||
golang.zx2c4.com/wintun v0.0.0-20211104114900-415007cec224/go.mod h1:deeaetjYA+DHMHg+sMSMI58GrEteJUUzzw7en6TJQcI=
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220829161405-d1d08426b27b h1:qgrKnOfe1zyURRNdmDlGbN32i38Zjmw0B1+TMdHcOvg=
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220829161405-d1d08426b27b/go.mod h1:6y4CqPAy54NwiN4nC8K+R1eMpQDB1P2d25qmunh2RSA=
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478 h1:vDy//hdR+GnROE3OdYbQKt9rdtNdHkDtONvpRwmls/0=
|
||||
golang.zx2c4.com/wireguard v0.0.0-20220703234212-c31a7b1ab478/go.mod h1:bVQfyl2sCM/QIIGHpWbFGfHPuDvqnCNkT6MQLTCjO/U=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
|
||||
@@ -14,6 +14,9 @@ func TestHysteriaSelf(t *testing.T) {
|
||||
}
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -89,6 +92,9 @@ func TestHysteriaInbound(t *testing.T) {
|
||||
}
|
||||
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeHysteria,
|
||||
@@ -139,6 +145,9 @@ func TestHysteriaOutbound(t *testing.T) {
|
||||
},
|
||||
})
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -13,6 +13,9 @@ func TestChainedInbound(t *testing.T) {
|
||||
method := shadowaead_2022.List[0]
|
||||
password := mkBase64(t, 16)
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -59,8 +62,10 @@ func TestChainedInbound(t *testing.T) {
|
||||
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
|
||||
Method: method,
|
||||
Password: password,
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: "detour-out",
|
||||
OutboundDialerOptions: option.OutboundDialerOptions{
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: "detour-out",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -37,6 +37,9 @@ func testShadowsocksMux(t *testing.T, protocol string) {
|
||||
method := shadowaead_2022.List[0]
|
||||
password := mkBase64(t, 16)
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -98,6 +101,9 @@ func testShadowsocksMux(t *testing.T, protocol string) {
|
||||
func testVMessMux(t *testing.T, protocol string) {
|
||||
user, _ := uuid.NewV4()
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -13,6 +13,9 @@ import (
|
||||
func TestNaiveInboundWithNginx(t *testing.T) {
|
||||
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeNaive,
|
||||
@@ -59,6 +62,9 @@ func TestNaiveInboundWithNginx(t *testing.T) {
|
||||
func TestNaiveInbound(t *testing.T) {
|
||||
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeNaive,
|
||||
@@ -104,6 +110,9 @@ func TestNaiveHTTP3Inbound(t *testing.T) {
|
||||
}
|
||||
caPem, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeNaive,
|
||||
|
||||
@@ -77,6 +77,9 @@ func testShadowsocksInboundWithShadowsocksRust(t *testing.T, method string, pass
|
||||
Cmd: []string{"-s", F.ToString("127.0.0.1:", serverPort), "-b", F.ToString("0.0.0.0:", clientPort), "-m", method, "-k", password, "-U"},
|
||||
})
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeShadowsocks,
|
||||
@@ -102,6 +105,9 @@ func testShadowsocksOutboundWithShadowsocksRust(t *testing.T, method string, pas
|
||||
Cmd: []string{"-s", F.ToString("0.0.0.0:", serverPort), "-m", method, "-k", password, "-U"},
|
||||
})
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -132,6 +138,9 @@ func testShadowsocksOutboundWithShadowsocksRust(t *testing.T, method string, pas
|
||||
|
||||
func testShadowsocksSelf(t *testing.T, method string, password string) {
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -190,6 +199,9 @@ func TestShadowsocksUoT(t *testing.T) {
|
||||
method := shadowaead_2022.List[0]
|
||||
password := mkBase64(t, 16)
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -60,11 +60,10 @@ func TestShadowTLS(t *testing.T) {
|
||||
ShadowsocksOptions: option.ShadowsocksOutboundOptions{
|
||||
Method: method,
|
||||
Password: password,
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: "detour",
|
||||
},
|
||||
MultiplexOptions: &option.MultiplexOptions{
|
||||
Enabled: true,
|
||||
OutboundDialerOptions: option.OutboundDialerOptions{
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: "detour",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -96,7 +95,7 @@ func TestShadowTLS(t *testing.T) {
|
||||
}},
|
||||
},
|
||||
})
|
||||
testSuit(t, clientPort, testPort)
|
||||
testTCP(t, clientPort, testPort)
|
||||
}
|
||||
|
||||
func TestShadowTLSOutbound(t *testing.T) {
|
||||
@@ -132,8 +131,10 @@ func TestShadowTLSOutbound(t *testing.T) {
|
||||
{
|
||||
Type: C.TypeSocks,
|
||||
SocksOptions: option.SocksOutboundOptions{
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: "detour",
|
||||
OutboundDialerOptions: option.OutboundDialerOptions{
|
||||
DialerOptions: option.DialerOptions{
|
||||
Detour: "detour",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
@@ -20,6 +20,9 @@ func TestTrojanOutbound(t *testing.T) {
|
||||
},
|
||||
})
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -55,6 +58,9 @@ func TestTrojanOutbound(t *testing.T) {
|
||||
func TestTrojanSelf(t *testing.T) {
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -27,6 +27,9 @@ func testV2RayGRPCInbound(t *testing.T, forceLite bool) {
|
||||
require.NoError(t, err)
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeVMess,
|
||||
@@ -122,6 +125,9 @@ func testV2RayGRPCOutbound(t *testing.T, forceLite bool) {
|
||||
},
|
||||
})
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -11,6 +11,31 @@ import (
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestV2RayWebscoketSelf(t *testing.T) {
|
||||
t.Run("basic", func(t *testing.T) {
|
||||
testV2RayTransportSelf(t, &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
})
|
||||
})
|
||||
t.Run("v2ray early data", func(t *testing.T) {
|
||||
testV2RayTransportSelf(t, &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
WebsocketOptions: option.V2RayWebsocketOptions{
|
||||
MaxEarlyData: 2048,
|
||||
},
|
||||
})
|
||||
})
|
||||
t.Run("xray early data", func(t *testing.T) {
|
||||
testV2RayTransportSelf(t, &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
WebsocketOptions: option.V2RayWebsocketOptions{
|
||||
MaxEarlyData: 2048,
|
||||
EarlyDataHeaderName: "Sec-WebSocket-Protocol",
|
||||
},
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
func TestV2RayHTTPSelf(t *testing.T) {
|
||||
testV2RayTransportSelf(t, &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeHTTP,
|
||||
@@ -44,6 +69,9 @@ func testVMessTransportSelf(t *testing.T, server *option.V2RayTransportOptions,
|
||||
require.NoError(t, err)
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -120,6 +148,9 @@ func testTrojanTransportSelf(t *testing.T, server *option.V2RayTransportOptions,
|
||||
require.NoError(t, err)
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -198,6 +229,9 @@ func TestVMessQUICSelf(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -273,6 +307,9 @@ func testV2RayTransportNOTLSSelf(t *testing.T, transport *option.V2RayTransportO
|
||||
user, err := uuid.DefaultGenerator.NewV4()
|
||||
require.NoError(t, err)
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -1,197 +0,0 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
"github.com/sagernet/sing-box/option"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
"github.com/spyzhov/ajson"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestV2RayWebsocket(t *testing.T) {
|
||||
t.Run("self", func(t *testing.T) {
|
||||
testV2RayTransportSelf(t, &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
})
|
||||
})
|
||||
t.Run("self-early-data", func(t *testing.T) {
|
||||
testV2RayTransportSelf(t, &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
WebsocketOptions: option.V2RayWebsocketOptions{
|
||||
MaxEarlyData: 2048,
|
||||
},
|
||||
})
|
||||
})
|
||||
t.Run("self-xray-early-data", func(t *testing.T) {
|
||||
testV2RayTransportSelf(t, &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
WebsocketOptions: option.V2RayWebsocketOptions{
|
||||
MaxEarlyData: 2048,
|
||||
EarlyDataHeaderName: "Sec-WebSocket-Protocol",
|
||||
},
|
||||
})
|
||||
})
|
||||
t.Run("inbound", func(t *testing.T) {
|
||||
testV2RayWebsocketInbound(t, 0, "")
|
||||
})
|
||||
t.Run("inbound-early-data", func(t *testing.T) {
|
||||
testV2RayWebsocketInbound(t, 2048, "")
|
||||
})
|
||||
t.Run("inbound-xray-early-data", func(t *testing.T) {
|
||||
testV2RayWebsocketInbound(t, 2048, "Sec-WebSocket-Protocol")
|
||||
})
|
||||
t.Run("outbound", func(t *testing.T) {
|
||||
testV2RayWebsocketOutbound(t, 0, "")
|
||||
})
|
||||
t.Run("outbound-early-data", func(t *testing.T) {
|
||||
testV2RayWebsocketOutbound(t, 2048, "")
|
||||
})
|
||||
t.Run("outbound-xray-early-data", func(t *testing.T) {
|
||||
testV2RayWebsocketOutbound(t, 2048, "Sec-WebSocket-Protocol")
|
||||
})
|
||||
}
|
||||
|
||||
func testV2RayWebsocketInbound(t *testing.T, maxEarlyData uint32, earlyDataHeaderName string) {
|
||||
userId, err := uuid.DefaultGenerator.NewV4()
|
||||
require.NoError(t, err)
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
startInstance(t, option.Options{
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeVMess,
|
||||
VMessOptions: option.VMessInboundOptions{
|
||||
ListenOptions: option.ListenOptions{
|
||||
Listen: option.ListenAddress(netip.IPv4Unspecified()),
|
||||
ListenPort: serverPort,
|
||||
},
|
||||
Users: []option.VMessUser{
|
||||
{
|
||||
Name: "sekai",
|
||||
UUID: userId.String(),
|
||||
},
|
||||
},
|
||||
TLS: &option.InboundTLSOptions{
|
||||
Enabled: true,
|
||||
ServerName: "example.org",
|
||||
CertificatePath: certPem,
|
||||
KeyPath: keyPem,
|
||||
},
|
||||
Transport: &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
WebsocketOptions: option.V2RayWebsocketOptions{
|
||||
MaxEarlyData: maxEarlyData,
|
||||
EarlyDataHeaderName: earlyDataHeaderName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
content, err := os.ReadFile("config/vmess-ws-client.json")
|
||||
require.NoError(t, err)
|
||||
config, err := ajson.Unmarshal(content)
|
||||
require.NoError(t, err)
|
||||
|
||||
config.MustKey("inbounds").MustIndex(0).MustKey("port").SetNumeric(float64(clientPort))
|
||||
outbound := config.MustKey("outbounds").MustIndex(0)
|
||||
settings := outbound.MustKey("settings").MustKey("vnext").MustIndex(0)
|
||||
settings.MustKey("port").SetNumeric(float64(serverPort))
|
||||
user := settings.MustKey("users").MustIndex(0)
|
||||
user.MustKey("id").SetString(userId.String())
|
||||
wsSettings := outbound.MustKey("streamSettings").MustKey("wsSettings")
|
||||
wsSettings.MustKey("maxEarlyData").SetNumeric(float64(maxEarlyData))
|
||||
wsSettings.MustKey("earlyDataHeaderName").SetString(earlyDataHeaderName)
|
||||
content, err = ajson.Marshal(config)
|
||||
require.NoError(t, err)
|
||||
|
||||
startDockerContainer(t, DockerOptions{
|
||||
Image: ImageV2RayCore,
|
||||
Ports: []uint16{serverPort, testPort},
|
||||
EntryPoint: "v2ray",
|
||||
Stdin: content,
|
||||
Bind: map[string]string{
|
||||
certPem: "/path/to/certificate.crt",
|
||||
keyPem: "/path/to/private.key",
|
||||
},
|
||||
})
|
||||
|
||||
testSuitSimple(t, clientPort, testPort)
|
||||
}
|
||||
|
||||
func testV2RayWebsocketOutbound(t *testing.T, maxEarlyData uint32, earlyDataHeaderName string) {
|
||||
userId, err := uuid.DefaultGenerator.NewV4()
|
||||
require.NoError(t, err)
|
||||
_, certPem, keyPem := createSelfSignedCertificate(t, "example.org")
|
||||
|
||||
content, err := os.ReadFile("config/vmess-ws-server.json")
|
||||
require.NoError(t, err)
|
||||
config, err := ajson.Unmarshal(content)
|
||||
require.NoError(t, err)
|
||||
|
||||
inbound := config.MustKey("inbounds").MustIndex(0)
|
||||
inbound.MustKey("port").SetNumeric(float64(serverPort))
|
||||
inbound.MustKey("settings").MustKey("clients").MustIndex(0).MustKey("id").SetString(userId.String())
|
||||
wsSettings := inbound.MustKey("streamSettings").MustKey("wsSettings")
|
||||
wsSettings.MustKey("maxEarlyData").SetNumeric(float64(maxEarlyData))
|
||||
wsSettings.MustKey("earlyDataHeaderName").SetString(earlyDataHeaderName)
|
||||
content, err = ajson.Marshal(config)
|
||||
require.NoError(t, err)
|
||||
|
||||
startDockerContainer(t, DockerOptions{
|
||||
Image: ImageV2RayCore,
|
||||
Ports: []uint16{serverPort, testPort},
|
||||
EntryPoint: "v2ray",
|
||||
Stdin: content,
|
||||
Env: []string{"V2RAY_VMESS_AEAD_FORCED=false"},
|
||||
Bind: map[string]string{
|
||||
certPem: "/path/to/certificate.crt",
|
||||
keyPem: "/path/to/private.key",
|
||||
},
|
||||
})
|
||||
startInstance(t, option.Options{
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
Tag: "mixed-in",
|
||||
MixedOptions: option.HTTPMixedInboundOptions{
|
||||
ListenOptions: option.ListenOptions{
|
||||
Listen: option.ListenAddress(netip.IPv4Unspecified()),
|
||||
ListenPort: clientPort,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Outbounds: []option.Outbound{
|
||||
{
|
||||
Type: C.TypeVMess,
|
||||
Tag: "vmess-out",
|
||||
VMessOptions: option.VMessOutboundOptions{
|
||||
ServerOptions: option.ServerOptions{
|
||||
Server: "127.0.0.1",
|
||||
ServerPort: serverPort,
|
||||
},
|
||||
UUID: userId.String(),
|
||||
Security: "zero",
|
||||
TLS: &option.OutboundTLSOptions{
|
||||
Enabled: true,
|
||||
ServerName: "example.org",
|
||||
CertificatePath: certPem,
|
||||
},
|
||||
Transport: &option.V2RayTransportOptions{
|
||||
Type: C.V2RayTransportTypeWebsocket,
|
||||
WebsocketOptions: option.V2RayWebsocketOptions{
|
||||
MaxEarlyData: maxEarlyData,
|
||||
EarlyDataHeaderName: earlyDataHeaderName,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
testSuitSimple(t, clientPort, testPort)
|
||||
}
|
||||
@@ -182,6 +182,9 @@ func testVMessInboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, al
|
||||
})
|
||||
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeVMess,
|
||||
@@ -228,6 +231,9 @@ func testVMessOutboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, g
|
||||
})
|
||||
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
@@ -261,6 +267,9 @@ func testVMessOutboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, g
|
||||
|
||||
func testVMessSelf(t *testing.T, security string, uuid uuid.UUID, alterId int, globalPadding bool, authenticatedLength bool, packetAddr bool) {
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -21,6 +21,9 @@ func TestWireGuard(t *testing.T) {
|
||||
})
|
||||
time.Sleep(5 * time.Second)
|
||||
startInstance(t, option.Options{
|
||||
Log: &option.LogOptions{
|
||||
Level: "error",
|
||||
},
|
||||
Inbounds: []option.Inbound{
|
||||
{
|
||||
Type: C.TypeMixed,
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"syscall"
|
||||
|
||||
"github.com/sagernet/quic-go"
|
||||
"github.com/sagernet/sing-box/common/baderror"
|
||||
"github.com/sagernet/sing/common"
|
||||
)
|
||||
|
||||
@@ -39,16 +38,6 @@ type StreamWrapper struct {
|
||||
quic.Stream
|
||||
}
|
||||
|
||||
func (s *StreamWrapper) Read(p []byte) (n int, err error) {
|
||||
n, err = s.Stream.Read(p)
|
||||
return n, baderror.WrapQUIC(err)
|
||||
}
|
||||
|
||||
func (s *StreamWrapper) Write(p []byte) (n int, err error) {
|
||||
n, err = s.Stream.Write(p)
|
||||
return n, baderror.WrapQUIC(err)
|
||||
}
|
||||
|
||||
func (s *StreamWrapper) LocalAddr() net.Addr {
|
||||
return s.Conn.LocalAddr()
|
||||
}
|
||||
@@ -61,6 +50,14 @@ func (s *StreamWrapper) Upstream() any {
|
||||
return s.Stream
|
||||
}
|
||||
|
||||
func (s *StreamWrapper) ReaderReplaceable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *StreamWrapper) WriterReplaceable() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func (s *StreamWrapper) Close() error {
|
||||
s.CancelRead(0)
|
||||
s.Stream.Close()
|
||||
|
||||
@@ -167,9 +167,6 @@ func (c *EarlyWebsocketConn) SetWriteDeadline(t time.Time) error {
|
||||
|
||||
func wrapError(err error) error {
|
||||
if websocket.IsCloseError(err, websocket.CloseNormalClosure) {
|
||||
return io.EOF
|
||||
}
|
||||
if websocket.IsCloseError(err, websocket.CloseAbnormalClosure) {
|
||||
return net.ErrClosed
|
||||
}
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user