mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-25 18:11:28 +00:00
Minor fixes
This commit is contained in:
parent
45643fbed1
commit
6327c4b40c
3
box.go
3
box.go
|
@ -44,7 +44,8 @@ func New(ctx context.Context, options option.Options) (*Box, error) {
|
||||||
var observableLogFactory log.ObservableFactory
|
var observableLogFactory log.ObservableFactory
|
||||||
var logFile *os.File
|
var logFile *os.File
|
||||||
if logOptions.Disabled {
|
if logOptions.Disabled {
|
||||||
logFactory = log.NewNOPFactory()
|
observableLogFactory = log.NewNOPFactory()
|
||||||
|
logFactory = observableLogFactory
|
||||||
} else {
|
} else {
|
||||||
var logWriter io.Writer
|
var logWriter io.Writer
|
||||||
switch logOptions.Output {
|
switch logOptions.Output {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package clashapi
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
@ -85,7 +86,7 @@ func (s *Server) Start() error {
|
||||||
s.logger.Info("restful api listening at ", listener.Addr())
|
s.logger.Info("restful api listening at ", listener.Addr())
|
||||||
go func() {
|
go func() {
|
||||||
err = s.httpServer.Serve(listener)
|
err = s.httpServer.Serve(listener)
|
||||||
if err != nil && !E.IsClosed(err) {
|
if err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
s.logger.Error("external controller serve error: ", err)
|
s.logger.Error("external controller serve error: ", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
@ -243,6 +244,13 @@ func getLogs(logFactory log.ObservableFactory) func(w http.ResponseWriter, r *ht
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
subscription, done, err := logFactory.Subscribe()
|
||||||
|
if err != nil {
|
||||||
|
render.Status(r, http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
defer logFactory.UnSubscribe(subscription)
|
||||||
|
|
||||||
var wsConn *websocket.Conn
|
var wsConn *websocket.Conn
|
||||||
if websocket.IsWebSocketUpgrade(r) {
|
if websocket.IsWebSocketUpgrade(r) {
|
||||||
var err error
|
var err error
|
||||||
|
@ -257,14 +265,6 @@ func getLogs(logFactory log.ObservableFactory) func(w http.ResponseWriter, r *ht
|
||||||
render.Status(r, http.StatusOK)
|
render.Status(r, http.StatusOK)
|
||||||
}
|
}
|
||||||
|
|
||||||
subscription, done, err := logFactory.Subscribe()
|
|
||||||
if err != nil {
|
|
||||||
log.Warn(err)
|
|
||||||
render.Status(r, http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
defer logFactory.UnSubscribe(subscription)
|
|
||||||
|
|
||||||
buf := &bytes.Buffer{}
|
buf := &bytes.Buffer{}
|
||||||
var logEntry log.Entry
|
var logEntry log.Entry
|
||||||
for {
|
for {
|
||||||
|
|
|
@ -54,17 +54,17 @@ func (tt *tcpTracker) ID() string {
|
||||||
|
|
||||||
func (tt *tcpTracker) Read(b []byte) (int, error) {
|
func (tt *tcpTracker) Read(b []byte) (int, error) {
|
||||||
n, err := tt.Conn.Read(b)
|
n, err := tt.Conn.Read(b)
|
||||||
download := int64(n)
|
upload := int64(n)
|
||||||
tt.manager.PushDownloaded(download)
|
tt.manager.PushUploaded(upload)
|
||||||
tt.DownloadTotal.Add(download)
|
tt.UploadTotal.Add(upload)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (tt *tcpTracker) Write(b []byte) (int, error) {
|
func (tt *tcpTracker) Write(b []byte) (int, error) {
|
||||||
n, err := tt.Conn.Write(b)
|
n, err := tt.Conn.Write(b)
|
||||||
upload := int64(n)
|
download := int64(n)
|
||||||
tt.manager.PushUploaded(upload)
|
tt.manager.PushDownloaded(download)
|
||||||
tt.UploadTotal.Add(upload)
|
tt.DownloadTotal.Add(download)
|
||||||
return n, err
|
return n, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,21 +112,21 @@ func (ut *udpTracker) ID() string {
|
||||||
func (ut *udpTracker) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error) {
|
func (ut *udpTracker) ReadPacket(buffer *buf.Buffer) (destination M.Socksaddr, err error) {
|
||||||
destination, err = ut.PacketConn.ReadPacket(buffer)
|
destination, err = ut.PacketConn.ReadPacket(buffer)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
download := int64(buffer.Len())
|
upload := int64(buffer.Len())
|
||||||
ut.manager.PushDownloaded(download)
|
ut.manager.PushUploaded(upload)
|
||||||
ut.DownloadTotal.Add(download)
|
ut.UploadTotal.Add(upload)
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ut *udpTracker) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
func (ut *udpTracker) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
||||||
upload := int64(buffer.Len())
|
download := int64(buffer.Len())
|
||||||
err := ut.PacketConn.WritePacket(buffer, destination)
|
err := ut.PacketConn.WritePacket(buffer, destination)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
ut.manager.PushUploaded(upload)
|
ut.manager.PushDownloaded(download)
|
||||||
ut.UploadTotal.Add(upload)
|
ut.DownloadTotal.Add(download)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
6
go.mod
6
go.mod
|
@ -11,10 +11,10 @@ require (
|
||||||
github.com/gorilla/websocket v1.5.0
|
github.com/gorilla/websocket v1.5.0
|
||||||
github.com/logrusorgru/aurora v2.0.3+incompatible
|
github.com/logrusorgru/aurora v2.0.3+incompatible
|
||||||
github.com/oschwald/maxminddb-golang v1.9.0
|
github.com/oschwald/maxminddb-golang v1.9.0
|
||||||
github.com/sagernet/sing v0.0.0-20220718035659-3d74b823ed56
|
github.com/sagernet/sing v0.0.0-20220720054545-2af19486bb1f
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619
|
github.com/sagernet/sing-dns v0.0.0-20220720045209-c44590ebeb0f
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f
|
||||||
github.com/sagernet/sing-tun v0.0.0-20220717030718-f53aabff275f
|
github.com/sagernet/sing-tun v0.0.0-20220720051454-d35c334b46c9
|
||||||
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a
|
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a
|
||||||
github.com/spf13/cobra v1.5.0
|
github.com/spf13/cobra v1.5.0
|
||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.8.0
|
||||||
|
|
12
go.sum
12
go.sum
|
@ -35,14 +35,14 @@ github.com/oschwald/maxminddb-golang v1.9.0/go.mod h1:TK+s/Z2oZq0rSl4PSeAEoP0bgm
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||||
github.com/sagernet/sing v0.0.0-20220718035659-3d74b823ed56 h1:r6FHrtIE3dG9c6zl487QjxPFgADq/C0AiDwhpAZFKUw=
|
github.com/sagernet/sing v0.0.0-20220720054545-2af19486bb1f h1:eMaEhzlP5jFCd6xvLkeb8vMayLSuAPy446QSCZgdSGg=
|
||||||
github.com/sagernet/sing v0.0.0-20220718035659-3d74b823ed56/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
github.com/sagernet/sing v0.0.0-20220720054545-2af19486bb1f/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619 h1:oHbOmq1WS0XaZmXp6WpxzyB2xeyRIA1/L8EJKuNntfY=
|
github.com/sagernet/sing-dns v0.0.0-20220720045209-c44590ebeb0f h1:PCrkSLS+fQtBimPi/2WzjJqeTy0zJtBDaMLykyTAiwQ=
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619/go.mod h1:y2fpvoxukw3G7eApIZwkcpcG/NE4AB8pCQI0Qd8rMqk=
|
github.com/sagernet/sing-dns v0.0.0-20220720045209-c44590ebeb0f/go.mod h1:y2fpvoxukw3G7eApIZwkcpcG/NE4AB8pCQI0Qd8rMqk=
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f h1:F6yiuKbBoXgWiuoP7R0YA14pDEl3emxA1mL7M16Q7gc=
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f h1:F6yiuKbBoXgWiuoP7R0YA14pDEl3emxA1mL7M16Q7gc=
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f/go.mod h1:cDrLwa3zwY8AaW6a4sjipn4xgdIr3CT8TPqSW6iFOi0=
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f/go.mod h1:cDrLwa3zwY8AaW6a4sjipn4xgdIr3CT8TPqSW6iFOi0=
|
||||||
github.com/sagernet/sing-tun v0.0.0-20220717030718-f53aabff275f h1:o3YN4sFC7lQznAwutagPqBb23hal7MkgVq/VEvd7Vug=
|
github.com/sagernet/sing-tun v0.0.0-20220720051454-d35c334b46c9 h1:kzEyWi2iJcq1oNeCCRrJ1Oh/ogbHR0CZRZ/HMxzy+mo=
|
||||||
github.com/sagernet/sing-tun v0.0.0-20220717030718-f53aabff275f/go.mod h1:p7QbUBs2ejf6UQsiHyy1xGAWOk9JWQjZTHy8pOmkWmo=
|
github.com/sagernet/sing-tun v0.0.0-20220720051454-d35c334b46c9/go.mod h1:p7QbUBs2ejf6UQsiHyy1xGAWOk9JWQjZTHy8pOmkWmo=
|
||||||
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a h1:durFxTP1xsOMeDt8x0AV/9BXAPa8uMQRKzPaVkGSOS0=
|
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a h1:durFxTP1xsOMeDt8x0AV/9BXAPa8uMQRKzPaVkGSOS0=
|
||||||
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a/go.mod h1:VjqeHNWtDVoExWInXB7QsCeMp5RozlnJhMgfbW/n4I0=
|
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a/go.mod h1:VjqeHNWtDVoExWInXB7QsCeMp5RozlnJhMgfbW/n4I0=
|
||||||
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
github.com/spf13/cobra v1.5.0 h1:X+jTBEBqF0bHN+9cSMgmfuvv2VHJ9ezmFNf9Y/XstYU=
|
||||||
|
|
|
@ -324,7 +324,7 @@ func (a *myInboundAdapter) NewError(ctx context.Context, err error) {
|
||||||
|
|
||||||
func NewError(logger log.ContextLogger, ctx context.Context, err error) {
|
func NewError(logger log.ContextLogger, ctx context.Context, err error) {
|
||||||
common.Close(err)
|
common.Close(err)
|
||||||
if E.IsClosed(err) || E.IsCanceled(err) {
|
if E.IsClosedOrCanceled(err) {
|
||||||
logger.DebugContext(ctx, "connection closed")
|
logger.DebugContext(ctx, "connection closed")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -116,7 +116,11 @@ func (t *Tun) NewConnection(ctx context.Context, conn net.Conn, upstreamMetadata
|
||||||
}
|
}
|
||||||
t.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
t.logger.InfoContext(ctx, "inbound connection from ", metadata.Source)
|
||||||
t.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
t.logger.InfoContext(ctx, "inbound connection to ", metadata.Destination)
|
||||||
return t.router.RouteConnection(ctx, conn, metadata)
|
err := t.router.RouteConnection(ctx, conn, metadata)
|
||||||
|
if err != nil {
|
||||||
|
t.NewError(ctx, err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tun) NewPacketConnection(ctx context.Context, conn N.PacketConn, upstreamMetadata M.Metadata) error {
|
func (t *Tun) NewPacketConnection(ctx context.Context, conn N.PacketConn, upstreamMetadata M.Metadata) error {
|
||||||
|
@ -137,7 +141,11 @@ func (t *Tun) NewPacketConnection(ctx context.Context, conn N.PacketConn, upstre
|
||||||
}
|
}
|
||||||
t.logger.InfoContext(ctx, "inbound packet connection from ", metadata.Source)
|
t.logger.InfoContext(ctx, "inbound packet connection from ", metadata.Source)
|
||||||
t.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
t.logger.InfoContext(ctx, "inbound packet connection to ", metadata.Destination)
|
||||||
return t.router.RoutePacketConnection(ctx, conn, metadata)
|
err := t.router.RoutePacketConnection(ctx, conn, metadata)
|
||||||
|
if err != nil {
|
||||||
|
t.NewError(ctx, err)
|
||||||
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Tun) NewError(ctx context.Context, err error) {
|
func (t *Tun) NewError(ctx context.Context, err error) {
|
||||||
|
|
|
@ -75,7 +75,7 @@ func (f Formatter) Format(ctx context.Context, level Level, tag string, message
|
||||||
default:
|
default:
|
||||||
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
|
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
|
||||||
}
|
}
|
||||||
return message
|
return message + "\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string, message string, timestamp time.Time) (string, string) {
|
func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string, message string, timestamp time.Time) (string, string) {
|
||||||
|
@ -126,6 +126,8 @@ func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string
|
||||||
} else {
|
} else {
|
||||||
message = F.ToString("[", id, "] ", message)
|
message = F.ToString("[", id, "] ", message)
|
||||||
}
|
}
|
||||||
|
messageSimple = F.ToString("[", id, "] ", messageSimple)
|
||||||
|
|
||||||
}
|
}
|
||||||
switch {
|
switch {
|
||||||
case f.DisableTimestamp:
|
case f.DisableTimestamp:
|
||||||
|
@ -135,7 +137,7 @@ func (f Formatter) FormatWithSimple(ctx context.Context, level Level, tag string
|
||||||
default:
|
default:
|
||||||
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
|
message = levelString + "[" + xd(int(timestamp.Sub(f.BaseTime)/time.Second), 4) + "] " + message
|
||||||
}
|
}
|
||||||
return message, messageSimple
|
return message + "\n", messageSimple
|
||||||
}
|
}
|
||||||
|
|
||||||
func xd(value int, x int) string {
|
func xd(value int, x int) string {
|
||||||
|
|
18
log/nop.go
18
log/nop.go
|
@ -1,12 +1,17 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import "context"
|
import (
|
||||||
|
"context"
|
||||||
|
"os"
|
||||||
|
|
||||||
var _ Factory = (*nopFactory)(nil)
|
"github.com/sagernet/sing/common/observable"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ ObservableFactory = (*nopFactory)(nil)
|
||||||
|
|
||||||
type nopFactory struct{}
|
type nopFactory struct{}
|
||||||
|
|
||||||
func NewNOPFactory() Factory {
|
func NewNOPFactory() ObservableFactory {
|
||||||
return (*nopFactory)(nil)
|
return (*nopFactory)(nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,3 +71,10 @@ func (f *nopFactory) FatalContext(ctx context.Context, args ...any) {
|
||||||
|
|
||||||
func (f *nopFactory) PanicContext(ctx context.Context, args ...any) {
|
func (f *nopFactory) PanicContext(ctx context.Context, args ...any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (f *nopFactory) Subscribe() (subscription observable.Subscription[Entry], done <-chan struct{}, err error) {
|
||||||
|
return nil, nil, os.ErrInvalid
|
||||||
|
}
|
||||||
|
|
||||||
|
func (f *nopFactory) UnSubscribe(subscription observable.Subscription[Entry]) {
|
||||||
|
}
|
||||||
|
|
|
@ -71,7 +71,6 @@ func (l *observableLogger) Log(ctx context.Context, level Level, args []any) {
|
||||||
panic(message)
|
panic(message)
|
||||||
}
|
}
|
||||||
l.writer.Write([]byte(message))
|
l.writer.Write([]byte(message))
|
||||||
l.writer.Write([]byte{'\n'})
|
|
||||||
if level == LevelFatal {
|
if level == LevelFatal {
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,7 +92,7 @@ func NewDefaultRule(router adapter.Router, logger log.ContextLogger, options opt
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
if len(options.Protocol) > 0 {
|
if len(options.Protocol) > 0 {
|
||||||
item := NewUserItem(options.Protocol)
|
item := NewProtocolItem(options.Protocol)
|
||||||
rule.items = append(rule.items, item)
|
rule.items = append(rule.items, item)
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,7 +76,7 @@ func NewDefaultDNSRule(router adapter.Router, logger log.ContextLogger, options
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
if len(options.Protocol) > 0 {
|
if len(options.Protocol) > 0 {
|
||||||
item := NewUserItem(options.Protocol)
|
item := NewProtocolItem(options.Protocol)
|
||||||
rule.items = append(rule.items, item)
|
rule.items = append(rule.items, item)
|
||||||
rule.allItems = append(rule.allItems, item)
|
rule.allItems = append(rule.allItems, item)
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ require (
|
||||||
github.com/docker/docker v20.10.17+incompatible
|
github.com/docker/docker v20.10.17+incompatible
|
||||||
github.com/docker/go-connections v0.4.0
|
github.com/docker/go-connections v0.4.0
|
||||||
github.com/gofrs/uuid v4.2.0+incompatible
|
github.com/gofrs/uuid v4.2.0+incompatible
|
||||||
github.com/sagernet/sing v0.0.0-20220718035659-3d74b823ed56
|
github.com/sagernet/sing v0.0.0-20220720054545-2af19486bb1f
|
||||||
github.com/spyzhov/ajson v0.7.1
|
github.com/spyzhov/ajson v0.7.1
|
||||||
github.com/stretchr/testify v1.8.0
|
github.com/stretchr/testify v1.8.0
|
||||||
golang.org/x/net v0.0.0-20220708220712-1185a9018129
|
golang.org/x/net v0.0.0-20220708220712-1185a9018129
|
||||||
|
@ -39,9 +39,9 @@ require (
|
||||||
github.com/oschwald/maxminddb-golang v1.9.0 // indirect
|
github.com/oschwald/maxminddb-golang v1.9.0 // indirect
|
||||||
github.com/pkg/errors v0.9.1 // indirect
|
github.com/pkg/errors v0.9.1 // indirect
|
||||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619 // indirect
|
github.com/sagernet/sing-dns v0.0.0-20220720045209-c44590ebeb0f // indirect
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f // indirect
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f // indirect
|
||||||
github.com/sagernet/sing-tun v0.0.0-20220717030718-f53aabff275f // indirect
|
github.com/sagernet/sing-tun v0.0.0-20220720051454-d35c334b46c9 // indirect
|
||||||
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a // indirect
|
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a // indirect
|
||||||
github.com/sirupsen/logrus v1.8.1 // indirect
|
github.com/sirupsen/logrus v1.8.1 // indirect
|
||||||
github.com/vishvananda/netlink v1.1.0 // indirect
|
github.com/vishvananda/netlink v1.1.0 // indirect
|
||||||
|
|
12
test/go.sum
12
test/go.sum
|
@ -62,14 +62,14 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/sagernet/sing v0.0.0-20220718035659-3d74b823ed56 h1:r6FHrtIE3dG9c6zl487QjxPFgADq/C0AiDwhpAZFKUw=
|
github.com/sagernet/sing v0.0.0-20220720054545-2af19486bb1f h1:eMaEhzlP5jFCd6xvLkeb8vMayLSuAPy446QSCZgdSGg=
|
||||||
github.com/sagernet/sing v0.0.0-20220718035659-3d74b823ed56/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
github.com/sagernet/sing v0.0.0-20220720054545-2af19486bb1f/go.mod h1:GbtQfZSpmtD3cXeD1qX2LCMwY8dH+bnnInDTqd92IsM=
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619 h1:oHbOmq1WS0XaZmXp6WpxzyB2xeyRIA1/L8EJKuNntfY=
|
github.com/sagernet/sing-dns v0.0.0-20220720045209-c44590ebeb0f h1:PCrkSLS+fQtBimPi/2WzjJqeTy0zJtBDaMLykyTAiwQ=
|
||||||
github.com/sagernet/sing-dns v0.0.0-20220711062726-c64e938e4619/go.mod h1:y2fpvoxukw3G7eApIZwkcpcG/NE4AB8pCQI0Qd8rMqk=
|
github.com/sagernet/sing-dns v0.0.0-20220720045209-c44590ebeb0f/go.mod h1:y2fpvoxukw3G7eApIZwkcpcG/NE4AB8pCQI0Qd8rMqk=
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f h1:F6yiuKbBoXgWiuoP7R0YA14pDEl3emxA1mL7M16Q7gc=
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f h1:F6yiuKbBoXgWiuoP7R0YA14pDEl3emxA1mL7M16Q7gc=
|
||||||
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f/go.mod h1:cDrLwa3zwY8AaW6a4sjipn4xgdIr3CT8TPqSW6iFOi0=
|
github.com/sagernet/sing-shadowsocks v0.0.0-20220717063942-45a2ad9cd41f/go.mod h1:cDrLwa3zwY8AaW6a4sjipn4xgdIr3CT8TPqSW6iFOi0=
|
||||||
github.com/sagernet/sing-tun v0.0.0-20220717030718-f53aabff275f h1:o3YN4sFC7lQznAwutagPqBb23hal7MkgVq/VEvd7Vug=
|
github.com/sagernet/sing-tun v0.0.0-20220720051454-d35c334b46c9 h1:kzEyWi2iJcq1oNeCCRrJ1Oh/ogbHR0CZRZ/HMxzy+mo=
|
||||||
github.com/sagernet/sing-tun v0.0.0-20220717030718-f53aabff275f/go.mod h1:p7QbUBs2ejf6UQsiHyy1xGAWOk9JWQjZTHy8pOmkWmo=
|
github.com/sagernet/sing-tun v0.0.0-20220720051454-d35c334b46c9/go.mod h1:p7QbUBs2ejf6UQsiHyy1xGAWOk9JWQjZTHy8pOmkWmo=
|
||||||
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a h1:durFxTP1xsOMeDt8x0AV/9BXAPa8uMQRKzPaVkGSOS0=
|
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a h1:durFxTP1xsOMeDt8x0AV/9BXAPa8uMQRKzPaVkGSOS0=
|
||||||
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a/go.mod h1:VjqeHNWtDVoExWInXB7QsCeMp5RozlnJhMgfbW/n4I0=
|
github.com/sagernet/sing-vmess v0.0.0-20220718031323-07c377156e4a/go.mod h1:VjqeHNWtDVoExWInXB7QsCeMp5RozlnJhMgfbW/n4I0=
|
||||||
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0=
|
||||||
|
|
|
@ -13,8 +13,13 @@ import (
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
serverPort uint16 = 10000 + iota
|
||||||
|
clientPort
|
||||||
|
testPort
|
||||||
|
)
|
||||||
|
|
||||||
func TestShadowsocks(t *testing.T) {
|
func TestShadowsocks(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
for _, method := range []string{
|
for _, method := range []string{
|
||||||
"aes-128-gcm",
|
"aes-128-gcm",
|
||||||
"aes-256-gcm",
|
"aes-256-gcm",
|
||||||
|
@ -33,7 +38,6 @@ func TestShadowsocks(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestShadowsocks2022(t *testing.T) {
|
func TestShadowsocks2022(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
for _, method16 := range []string{
|
for _, method16 := range []string{
|
||||||
"2022-blake3-aes-128-gcm",
|
"2022-blake3-aes-128-gcm",
|
||||||
} {
|
} {
|
||||||
|
@ -64,10 +68,6 @@ func TestShadowsocks2022(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testShadowsocksInboundWithShadowsocksRust(t *testing.T, method string, password string) {
|
func testShadowsocksInboundWithShadowsocksRust(t *testing.T, method string, password string) {
|
||||||
t.Parallel()
|
|
||||||
serverPort := mkPort(t)
|
|
||||||
clientPort := mkPort(t)
|
|
||||||
testPort := mkPort(t)
|
|
||||||
startDockerContainer(t, DockerOptions{
|
startDockerContainer(t, DockerOptions{
|
||||||
Image: ImageShadowsocksRustClient,
|
Image: ImageShadowsocksRustClient,
|
||||||
EntryPoint: "sslocal",
|
EntryPoint: "sslocal",
|
||||||
|
@ -96,10 +96,6 @@ func testShadowsocksInboundWithShadowsocksRust(t *testing.T, method string, pass
|
||||||
}
|
}
|
||||||
|
|
||||||
func testShadowsocksOutboundWithShadowsocksRust(t *testing.T, method string, password string) {
|
func testShadowsocksOutboundWithShadowsocksRust(t *testing.T, method string, password string) {
|
||||||
t.Parallel()
|
|
||||||
serverPort := mkPort(t)
|
|
||||||
clientPort := mkPort(t)
|
|
||||||
testPort := mkPort(t)
|
|
||||||
startDockerContainer(t, DockerOptions{
|
startDockerContainer(t, DockerOptions{
|
||||||
Image: ImageShadowsocksRustServer,
|
Image: ImageShadowsocksRustServer,
|
||||||
EntryPoint: "ssserver",
|
EntryPoint: "ssserver",
|
||||||
|
@ -139,10 +135,6 @@ func testShadowsocksOutboundWithShadowsocksRust(t *testing.T, method string, pas
|
||||||
}
|
}
|
||||||
|
|
||||||
func testShadowsocksSelf(t *testing.T, method string, password string) {
|
func testShadowsocksSelf(t *testing.T, method string, password string) {
|
||||||
t.Parallel()
|
|
||||||
serverPort := mkPort(t)
|
|
||||||
clientPort := mkPort(t)
|
|
||||||
testPort := mkPort(t)
|
|
||||||
startInstance(t, option.Options{
|
startInstance(t, option.Options{
|
||||||
Log: &option.LogOptions{
|
Log: &option.LogOptions{
|
||||||
Level: "error",
|
Level: "error",
|
||||||
|
|
|
@ -14,7 +14,6 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestVMess(t *testing.T) {
|
func TestVMess(t *testing.T) {
|
||||||
t.Parallel()
|
|
||||||
for _, security := range []string{
|
for _, security := range []string{
|
||||||
"zero",
|
"zero",
|
||||||
} {
|
} {
|
||||||
|
@ -32,7 +31,6 @@ func TestVMess(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testVMess0(t *testing.T, security string) {
|
func testVMess0(t *testing.T, security string) {
|
||||||
t.Parallel()
|
|
||||||
user, err := uuid.DefaultGenerator.NewV4()
|
user, err := uuid.DefaultGenerator.NewV4()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Run("self", func(t *testing.T) {
|
t.Run("self", func(t *testing.T) {
|
||||||
|
@ -56,7 +54,6 @@ func testVMess0(t *testing.T, security string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testVMess1(t *testing.T, security string) {
|
func testVMess1(t *testing.T, security string) {
|
||||||
t.Parallel()
|
|
||||||
user, err := uuid.DefaultGenerator.NewV4()
|
user, err := uuid.DefaultGenerator.NewV4()
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
t.Run("self", func(t *testing.T) {
|
t.Run("self", func(t *testing.T) {
|
||||||
|
@ -104,17 +101,11 @@ func testVMess1(t *testing.T, security string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func testVMessInboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, authenticatedLength bool) {
|
func testVMessInboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, authenticatedLength bool) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
content, err := os.ReadFile("config/vmess-client.json")
|
content, err := os.ReadFile("config/vmess-client.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
config, err := ajson.Unmarshal(content)
|
config, err := ajson.Unmarshal(content)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
serverPort := mkPort(t)
|
|
||||||
clientPort := mkPort(t)
|
|
||||||
testPort := mkPort(t)
|
|
||||||
|
|
||||||
config.MustKey("inbounds").MustIndex(0).MustKey("port").SetNumeric(float64(clientPort))
|
config.MustKey("inbounds").MustIndex(0).MustKey("port").SetNumeric(float64(clientPort))
|
||||||
outbound := config.MustKey("outbounds").MustIndex(0).MustKey("settings").MustKey("vnext").MustIndex(0)
|
outbound := config.MustKey("outbounds").MustIndex(0).MustKey("settings").MustKey("vnext").MustIndex(0)
|
||||||
outbound.MustKey("port").SetNumeric(float64(serverPort))
|
outbound.MustKey("port").SetNumeric(float64(serverPort))
|
||||||
|
@ -165,17 +156,11 @@ func testVMessInboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, au
|
||||||
}
|
}
|
||||||
|
|
||||||
func testVMessOutboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, globalPadding bool, authenticatedLength bool, alterId int) {
|
func testVMessOutboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, globalPadding bool, authenticatedLength bool, alterId int) {
|
||||||
t.Parallel()
|
|
||||||
|
|
||||||
content, err := os.ReadFile("config/vmess-server.json")
|
content, err := os.ReadFile("config/vmess-server.json")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
config, err := ajson.Unmarshal(content)
|
config, err := ajson.Unmarshal(content)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
serverPort := mkPort(t)
|
|
||||||
clientPort := mkPort(t)
|
|
||||||
testPort := mkPort(t)
|
|
||||||
|
|
||||||
inbound := config.MustKey("inbounds").MustIndex(0)
|
inbound := config.MustKey("inbounds").MustIndex(0)
|
||||||
inbound.MustKey("port").SetNumeric(float64(serverPort))
|
inbound.MustKey("port").SetNumeric(float64(serverPort))
|
||||||
inbound.MustKey("settings").MustKey("clients").MustIndex(0).MustKey("id").SetString(uuid.String())
|
inbound.MustKey("settings").MustKey("clients").MustIndex(0).MustKey("id").SetString(uuid.String())
|
||||||
|
@ -228,10 +213,6 @@ func testVMessOutboundWithV2Ray(t *testing.T, security string, uuid uuid.UUID, g
|
||||||
}
|
}
|
||||||
|
|
||||||
func testVMessSelf(t *testing.T, security string, uuid uuid.UUID, globalPadding bool, authenticatedLength bool) {
|
func testVMessSelf(t *testing.T, security string, uuid uuid.UUID, globalPadding bool, authenticatedLength bool) {
|
||||||
t.Parallel()
|
|
||||||
serverPort := mkPort(t)
|
|
||||||
clientPort := mkPort(t)
|
|
||||||
testPort := mkPort(t)
|
|
||||||
startInstance(t, option.Options{
|
startInstance(t, option.Options{
|
||||||
Log: &option.LogOptions{
|
Log: &option.LogOptions{
|
||||||
Level: "error",
|
Level: "error",
|
||||||
|
|
Loading…
Reference in a new issue