platform: Improve status

This commit is contained in:
世界 2023-08-04 17:13:46 +08:00
parent c40140bbae
commit 59987747e5
No known key found for this signature in database
GPG key ID: CD109927C34A63C4
11 changed files with 64 additions and 39 deletions

View file

@ -7,7 +7,7 @@ const (
TypeDirect = "direct" TypeDirect = "direct"
TypeBlock = "block" TypeBlock = "block"
TypeDNS = "dns" TypeDNS = "dns"
TypeSocks = "socks" TypeSOCKS = "socks"
TypeHTTP = "http" TypeHTTP = "http"
TypeMixed = "mixed" TypeMixed = "mixed"
TypeShadowsocks = "shadowsocks" TypeShadowsocks = "shadowsocks"
@ -27,3 +27,46 @@ const (
TypeSelector = "selector" TypeSelector = "selector"
TypeURLTest = "urltest" TypeURLTest = "urltest"
) )
func ProxyDisplayName(proxyType string) string {
switch proxyType {
case TypeDirect:
return "Direct"
case TypeBlock:
return "Block"
case TypeDNS:
return "DNS"
case TypeSOCKS:
return "SOCKS"
case TypeHTTP:
return "HTTP"
case TypeShadowsocks:
return "Shadowsocks"
case TypeVMess:
return "VMess"
case TypeTrojan:
return "Trojan"
case TypeNaive:
return "Naive"
case TypeWireGuard:
return "WireGuard"
case TypeHysteria:
return "Hysteria"
case TypeTor:
return "Tor"
case TypeSSH:
return "SSH"
case TypeShadowTLS:
return "ShadowTLS"
case TypeShadowsocksR:
return "ShadowsocksR"
case TypeVLESS:
return "VLESS"
case TypeSelector:
return "Selector"
case TypeURLTest:
return "URLTest"
default:
return "Unknown"
}
}

View file

@ -63,38 +63,10 @@ func proxyInfo(server *Server, detour adapter.Outbound) *badjson.JSONObject {
var info badjson.JSONObject var info badjson.JSONObject
var clashType string var clashType string
switch detour.Type() { switch detour.Type() {
case C.TypeDirect:
clashType = "Direct"
case C.TypeBlock: case C.TypeBlock:
clashType = "Reject" clashType = "Reject"
case C.TypeSocks:
clashType = "Socks"
case C.TypeHTTP:
clashType = "HTTP"
case C.TypeShadowsocks:
clashType = "Shadowsocks"
case C.TypeVMess:
clashType = "VMess"
case C.TypeTrojan:
clashType = "Trojan"
case C.TypeHysteria:
clashType = "Hysteria"
case C.TypeWireGuard:
clashType = "WireGuard"
case C.TypeShadowsocksR:
clashType = "ShadowsocksR"
case C.TypeVLESS:
clashType = "VLESS"
case C.TypeTor:
clashType = "Tor"
case C.TypeSSH:
clashType = "SSH"
case C.TypeSelector:
clashType = "Selector"
case C.TypeURLTest:
clashType = "URLTest"
default: default:
clashType = "Direct" clashType = C.ProxyDisplayName(detour.Type())
} }
info.Put("type", clashType) info.Put("type", clashType)
info.Put("name", detour.Tag()) info.Put("name", detour.Tag())

View file

@ -4,6 +4,7 @@ import (
"encoding/binary" "encoding/binary"
"io" "io"
"net" "net"
"time"
"github.com/sagernet/sing-box/adapter" "github.com/sagernet/sing-box/adapter"
"github.com/sagernet/sing-box/common/urltest" "github.com/sagernet/sing-box/common/urltest"
@ -71,6 +72,11 @@ func (s *CommandServer) handleGroupConn(conn net.Conn) error {
} }
} }
select { select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(2 * time.Second):
}
select {
case <-ctx.Done(): case <-ctx.Done():
return ctx.Err() return ctx.Err()
case <-s.urlTestUpdate: case <-s.urlTestUpdate:

View file

@ -48,3 +48,7 @@ func Version() string {
func FormatBytes(length int64) string { func FormatBytes(length int64) string {
return humanize.IBytes(uint64(length)) return humanize.IBytes(uint64(length))
} }
func ProxyDisplayType(proxyType string) string {
return C.ProxyDisplayName(proxyType)
}

View file

@ -24,7 +24,7 @@ func New(ctx context.Context, router adapter.Router, logger log.ContextLogger, o
return NewTProxy(ctx, router, logger, options.Tag, options.TProxyOptions), nil return NewTProxy(ctx, router, logger, options.Tag, options.TProxyOptions), nil
case C.TypeDirect: case C.TypeDirect:
return NewDirect(ctx, router, logger, options.Tag, options.DirectOptions), nil return NewDirect(ctx, router, logger, options.Tag, options.DirectOptions), nil
case C.TypeSocks: case C.TypeSOCKS:
return NewSocks(ctx, router, logger, options.Tag, options.SocksOptions), nil return NewSocks(ctx, router, logger, options.Tag, options.SocksOptions), nil
case C.TypeHTTP: case C.TypeHTTP:
return NewHTTP(ctx, router, logger, options.Tag, options.HTTPOptions) return NewHTTP(ctx, router, logger, options.Tag, options.HTTPOptions)

View file

@ -27,7 +27,7 @@ type Socks struct {
func NewSocks(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.SocksInboundOptions) *Socks { func NewSocks(ctx context.Context, router adapter.Router, logger log.ContextLogger, tag string, options option.SocksInboundOptions) *Socks {
inbound := &Socks{ inbound := &Socks{
myInboundAdapter{ myInboundAdapter{
protocol: C.TypeSocks, protocol: C.TypeSOCKS,
network: []string{N.NetworkTCP}, network: []string{N.NetworkTCP},
ctx: ctx, ctx: ctx,
router: router, router: router,

View file

@ -38,7 +38,7 @@ func (h Inbound) MarshalJSON() ([]byte, error) {
v = h.TProxyOptions v = h.TProxyOptions
case C.TypeDirect: case C.TypeDirect:
v = h.DirectOptions v = h.DirectOptions
case C.TypeSocks: case C.TypeSOCKS:
v = h.SocksOptions v = h.SocksOptions
case C.TypeHTTP: case C.TypeHTTP:
v = h.HTTPOptions v = h.HTTPOptions
@ -79,7 +79,7 @@ func (h *Inbound) UnmarshalJSON(bytes []byte) error {
v = &h.TProxyOptions v = &h.TProxyOptions
case C.TypeDirect: case C.TypeDirect:
v = &h.DirectOptions v = &h.DirectOptions
case C.TypeSocks: case C.TypeSOCKS:
v = &h.SocksOptions v = &h.SocksOptions
case C.TypeHTTP: case C.TypeHTTP:
v = &h.HTTPOptions v = &h.HTTPOptions

View file

@ -36,7 +36,7 @@ func (h Outbound) MarshalJSON() ([]byte, error) {
v = h.DirectOptions v = h.DirectOptions
case C.TypeBlock, C.TypeDNS: case C.TypeBlock, C.TypeDNS:
v = nil v = nil
case C.TypeSocks: case C.TypeSOCKS:
v = h.SocksOptions v = h.SocksOptions
case C.TypeHTTP: case C.TypeHTTP:
v = h.HTTPOptions v = h.HTTPOptions
@ -81,7 +81,7 @@ func (h *Outbound) UnmarshalJSON(bytes []byte) error {
v = &h.DirectOptions v = &h.DirectOptions
case C.TypeBlock, C.TypeDNS: case C.TypeBlock, C.TypeDNS:
v = nil v = nil
case C.TypeSocks: case C.TypeSOCKS:
v = &h.SocksOptions v = &h.SocksOptions
case C.TypeHTTP: case C.TypeHTTP:
v = &h.HTTPOptions v = &h.HTTPOptions

View file

@ -27,7 +27,7 @@ func New(ctx context.Context, router adapter.Router, logger log.ContextLogger, t
return NewBlock(logger, tag), nil return NewBlock(logger, tag), nil
case C.TypeDNS: case C.TypeDNS:
return NewDNS(router, tag), nil return NewDNS(router, tag), nil
case C.TypeSocks: case C.TypeSOCKS:
return NewSocks(router, logger, tag, options.SocksOptions) return NewSocks(router, logger, tag, options.SocksOptions)
case C.TypeHTTP: case C.TypeHTTP:
return NewHTTP(router, logger, tag, options.HTTPOptions) return NewHTTP(router, logger, tag, options.HTTPOptions)

View file

@ -39,7 +39,7 @@ func NewSocks(router adapter.Router, logger log.ContextLogger, tag string, optio
} }
outbound := &Socks{ outbound := &Socks{
myOutboundAdapter: myOutboundAdapter{ myOutboundAdapter: myOutboundAdapter{
protocol: C.TypeSocks, protocol: C.TypeSOCKS,
network: options.Network.Build(), network: options.Network.Build(),
router: router, router: router,
logger: logger, logger: logger,

View file

@ -491,7 +491,7 @@ func testVLESSXrayInbound(t *testing.T, flow string) {
}, },
}, },
{ {
Type: C.TypeSocks, Type: C.TypeSOCKS,
Tag: "vless-out", Tag: "vless-out",
SocksOptions: option.SocksOutboundOptions{ SocksOptions: option.SocksOutboundOptions{
ServerOptions: option.ServerOptions{ ServerOptions: option.ServerOptions{