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

fix websocket alpn correctly on utls #590

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b5d2062
Add dns reverse mapping
nekohasekai Mar 23, 2023
a86afa0
Add L3 routing support
nekohasekai Mar 21, 2023
cbf0099
Add fakeip support
nekohasekai Mar 25, 2023
f98cfdf
Add multi-peer support for wireguard outbound
nekohasekai Mar 31, 2023
eb57cbc
clash api: download clash-dashboard if external-ui directory is empty
nekohasekai Apr 9, 2023
be00e19
clash-api: Add Clash.Meta APIs
nekohasekai Apr 11, 2023
c6fc411
Use HTTPS URLTest source
nekohasekai Apr 13, 2023
cc94dfa
Fix wireguard reconnect
nekohasekai Apr 13, 2023
81c4312
URLTest improvements
nekohasekai Apr 13, 2023
4dbf958
Add headers option for HTTP outbound
nekohasekai Apr 14, 2023
c0d6dde
shadowsocks: Multi-user support for legacy AEAD inbound
nekohasekai Apr 14, 2023
988d733
Add deadline interface
nekohasekai Apr 17, 2023
922acce
Update badtls
nekohasekai Apr 18, 2023
73e72e9
Improve VLESS request
nekohasekai Apr 18, 2023
2e98777
Ignore system tun stack bind interface error
nekohasekai Apr 20, 2023
f61c560
Update wireguard-go
nekohasekai Apr 20, 2023
9c28709
Improve multiplex
nekohasekai Apr 20, 2023
ccb872a
Add filemanager api
nekohasekai Apr 21, 2023
f568bb9
Add debug http server
nekohasekai Apr 22, 2023
d8810b6
Update gVisor to 20230417.0
nekohasekai Apr 22, 2023
8545e41
Improve multiplex
nekohasekai Apr 23, 2023
bec606e
documentation: Update changelog
nekohasekai Apr 22, 2023
6b64ebd
Migrate multiplex to library
nekohasekai Apr 23, 2023
50827bc
Add multiplexer for VLESS outbound
nekohasekai Apr 24, 2023
26bfcbd
clash-api: Reset outbounds in DELETE /connections
nekohasekai Apr 24, 2023
3765785
Improve direct copy
nekohasekai Apr 24, 2023
e3286d6
Fix h2mux buffer to large
nekohasekai Apr 25, 2023
2a76b8f
Fix documentation
nekohasekai Apr 25, 2023
7050011
Improve DNS caching
nekohasekai Apr 25, 2023
955028d
Fix cached packets order
nekohasekai Apr 25, 2023
974b2a3
Fix UVariantLen usage
H1JK Apr 25, 2023
c5067af
Enable mkdocs search in documentation
Larvan2 Apr 25, 2023
115507f
documentation: Fix fakeip link broken
Weltolk Apr 25, 2023
841ef1a
Set TCP keepalive for WireGuard gVisor TCP connections
nekohasekai Apr 26, 2023
d2d3c82
Fix wait copy packet
nekohasekai Apr 28, 2023
d08b82b
Reimplemented shadowsocks client
nekohasekai Apr 28, 2023
08f4384
Fix incorrect use of sort.Slice
XYenon Apr 30, 2023
d3b41df
documentation: Update changelog
nekohasekai Apr 30, 2023
c6e6621
Fix shadowsocks key length error message
nekohasekai May 1, 2023
b0a978d
Fix write cached packets
nekohasekai May 1, 2023
e556dfa
Update dependencies
nekohasekai May 3, 2023
e02317a
documentation: Update changelog
nekohasekai May 3, 2023
ee01faf
fix websocket alpn correctly on utls
sJJdGG May 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ install:
fmt:
@gofumpt -l -w .
@gofmt -s -w .
@gci write --custom-order -s "standard,prefix(github.com/sagernet/),default" .
@gci write --custom-order -s standard -s "prefix(github.com/sagernet/)" -s "default" .

fmt_install:
go install -v mvdan.cc/gofumpt@latest
Expand Down
7 changes: 7 additions & 0 deletions adapter/experimental.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ type ClashServer interface {
PreStarter
Mode() string
StoreSelected() bool
StoreFakeIP() bool
CacheFile() ClashCacheFile
HistoryStorage() *urltest.HistoryStorage
RoutedConnection(ctx context.Context, conn net.Conn, metadata InboundContext, matchedRule Rule) (net.Conn, Tracker)
Expand All @@ -22,6 +23,7 @@ type ClashServer interface {
type ClashCacheFile interface {
LoadSelected(group string) string
StoreSelected(group string, selected string) error
FakeIPStorage
}

type Tracker interface {
Expand All @@ -33,6 +35,11 @@ type OutboundGroup interface {
All() []string
}

type URLTestGroup interface {
OutboundGroup
URLTest(ctx context.Context, url string) (map[string]uint16, error)
}

func OutboundTag(detour Outbound) string {
if group, isGroup := detour.(OutboundGroup); isGroup {
return group.Now()
Expand Down
23 changes: 23 additions & 0 deletions adapter/fakeip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package adapter

import (
"net/netip"

"github.com/sagernet/sing-dns"
)

type FakeIPStore interface {
Service
Contains(address netip.Addr) bool
Create(domain string, strategy dns.DomainStrategy) (netip.Addr, error)
Lookup(address netip.Addr) (string, bool)
Reset() error
}

type FakeIPStorage interface {
FakeIPMetadata() *FakeIPMetadata
FakeIPSaveMetadata(metadata *FakeIPMetadata) error
FakeIPStore(address netip.Addr, domain string) error
FakeIPLoad(address netip.Addr) (string, bool)
FakeIPReset() error
}
50 changes: 50 additions & 0 deletions adapter/fakeip_metadata.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package adapter

import (
"bytes"
"encoding"
"encoding/binary"
"io"
"net/netip"

"github.com/sagernet/sing/common"
)

type FakeIPMetadata struct {
Inet4Range netip.Prefix
Inet6Range netip.Prefix
Inet4Current netip.Addr
Inet6Current netip.Addr
}

func (m *FakeIPMetadata) MarshalBinary() (data []byte, err error) {
var buffer bytes.Buffer
for _, marshaler := range []encoding.BinaryMarshaler{m.Inet4Range, m.Inet6Range, m.Inet4Current, m.Inet6Current} {
data, err = marshaler.MarshalBinary()
if err != nil {
return
}
common.Must(binary.Write(&buffer, binary.BigEndian, uint16(len(data))))
buffer.Write(data)
}
data = buffer.Bytes()
return
}

func (m *FakeIPMetadata) UnmarshalBinary(data []byte) error {
reader := bytes.NewReader(data)
for _, unmarshaler := range []encoding.BinaryUnmarshaler{&m.Inet4Range, &m.Inet6Range, &m.Inet4Current, &m.Inet6Current} {
var length uint16
common.Must(binary.Read(reader, binary.BigEndian, &length))
element := make([]byte, length)
_, err := io.ReadFull(reader, element)
if err != nil {
return err
}
err = unmarshaler.UnmarshalBinary(element)
if err != nil {
return err
}
}
return nil
}
2 changes: 1 addition & 1 deletion adapter/inbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type InjectableInbound interface {
type InboundContext struct {
Inbound string
InboundType string
IPVersion int
IPVersion uint8
Network string
Source M.Socksaddr
Destination M.Socksaddr
Expand Down
6 changes: 6 additions & 0 deletions adapter/outbound.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"net"

"github.com/sagernet/sing-tun"
N "github.com/sagernet/sing/common/network"
)

Expand All @@ -17,3 +18,8 @@ type Outbound interface {
NewConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
NewPacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
}

type IPOutbound interface {
Outbound
NewIPConnection(ctx context.Context, conn tun.RouteContext, metadata InboundContext) (tun.DirectDestination, error)
}
15 changes: 15 additions & 0 deletions adapter/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,13 @@ type Router interface {
Outbound(tag string) (Outbound, bool)
DefaultOutbound(network string) Outbound

FakeIPStore() FakeIPStore

RouteConnection(ctx context.Context, conn net.Conn, metadata InboundContext) error
RoutePacketConnection(ctx context.Context, conn N.PacketConn, metadata InboundContext) error
RouteIPConnection(ctx context.Context, conn tun.RouteContext, metadata InboundContext) tun.RouteAction

NatRequired(outbound string) bool

GeoIPReader() *geoip.Reader
LoadGeosite(code string) (Rule, error)
Expand All @@ -40,7 +45,9 @@ type Router interface {
NetworkMonitor() tun.NetworkUpdateMonitor
InterfaceMonitor() tun.DefaultInterfaceMonitor
PackageManager() tun.PackageManager

Rules() []Rule
IPRules() []IPRule

TimeService

Expand All @@ -49,6 +56,8 @@ type Router interface {

V2RayServer() V2RayServer
SetV2RayServer(server V2RayServer)

ResetNetwork() error
}

type routerContextKey struct{}
Expand Down Expand Up @@ -77,6 +86,12 @@ type Rule interface {
type DNSRule interface {
Rule
DisableCache() bool
RewriteTTL() *uint32
}

type IPRule interface {
Rule
Action() tun.ActionType
}

type InterfaceUpdateListener interface {
Expand Down
3 changes: 2 additions & 1 deletion box.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func New(options Options) (*Box, error) {
defaultLogWriter = io.Discard
}
logFactory, err := log.New(log.Options{
Context: ctx,
Options: common.PtrValueOrDefault(options.Log),
Observable: needClashAPI,
DefaultWriter: defaultLogWriter,
Expand Down Expand Up @@ -142,7 +143,7 @@ func New(options Options) (*Box, error) {
preServices := make(map[string]adapter.Service)
postServices := make(map[string]adapter.Service)
if needClashAPI {
clashServer, err := experimental.NewClashServer(router, logFactory.(log.ObservableFactory), common.PtrValueOrDefault(options.Experimental.ClashAPI))
clashServer, err := experimental.NewClashServer(ctx, router, logFactory.(log.ObservableFactory), common.PtrValueOrDefault(options.Experimental.ClashAPI))
if err != nil {
return nil, E.Cause(err, "create clash api server")
}
Expand Down
17 changes: 12 additions & 5 deletions cmd/internal/build_libbox/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"path/filepath"
"strings"

_ "github.com/sagernet/gomobile/event/key"
"github.com/sagernet/sing-box/cmd/internal/build_shared"
Expand Down Expand Up @@ -38,18 +39,23 @@ func main() {
var (
sharedFlags []string
debugFlags []string
sharedTags []string
debugTags []string
)

func init() {
sharedFlags = append(sharedFlags, "-trimpath")
sharedFlags = append(sharedFlags, "-ldflags")

currentTag, err := build_shared.ReadTag()
if err != nil {
currentTag = "unknown"
}
sharedFlags = append(sharedFlags, "-X github.com/sagernet/sing-box/constant.Version="+currentTag+" -s -w -buildid=")
debugFlags = append(debugFlags, "-X github.com/sagernet/sing-box/constant.Version="+currentTag)

sharedTags = append(sharedTags, "with_gvisor", "with_quic", "with_wireguard", "with_utls", "with_clash_api")
sharedTags = append(sharedTags, "test_sing_shadowsocks2")
debugTags = append(debugTags, "debug")
}

func buildAndroid() {
Expand All @@ -70,9 +76,9 @@ func buildAndroid() {

args = append(args, "-tags")
if !debugEnabled {
args = append(args, "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api")
args = append(args, strings.Join(sharedTags, ","))
} else {
args = append(args, "with_gvisor,with_quic,with_wireguard,with_utls,with_clash_api,debug")
args = append(args, strings.Join(append(sharedTags, debugTags...), ","))
}
args = append(args, "./experimental/libbox")

Expand Down Expand Up @@ -109,11 +115,12 @@ func buildiOS() {
args = append(args, debugFlags...)
}

tags := append(sharedTags, "with_low_memory", "with_conntrack")
args = append(args, "-tags")
if !debugEnabled {
args = append(args, "with_gvisor,with_quic,with_utls,with_clash_api,with_low_memory,with_conntrack")
args = append(args, strings.Join(tags, ","))
} else {
args = append(args, "with_gvisor,with_quic,with_utls,with_clash_api,with_low_memory,with_conntrack,debug")
args = append(args, strings.Join(append(tags, debugTags...), ","))
}
args = append(args, "./experimental/libbox")

Expand Down
44 changes: 0 additions & 44 deletions cmd/sing-box/debug.go

This file was deleted.

4 changes: 2 additions & 2 deletions common/badjsonmerge/merge_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestMergeJSON(t *testing.T) {
{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{
Network: N.NetworkTCP,
Network: []string{N.NetworkTCP},
Outbound: "direct",
},
},
Expand All @@ -42,7 +42,7 @@ func TestMergeJSON(t *testing.T) {
{
Type: C.RuleTypeDefault,
DefaultOptions: option.DefaultRule{
Network: N.NetworkUDP,
Network: []string{N.NetworkUDP},
Outbound: "direct",
},
},
Expand Down