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"
TypeBlock = "block"
TypeDNS = "dns"
TypeSocks = "socks"
TypeSOCKS = "socks"
TypeHTTP = "http"
TypeMixed = "mixed"
TypeShadowsocks = "shadowsocks"
@ -27,3 +27,46 @@ const (
TypeSelector = "selector"
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 clashType string
switch detour.Type() {
case C.TypeDirect:
clashType = "Direct"
case C.TypeBlock:
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:
clashType = "Direct"
clashType = C.ProxyDisplayName(detour.Type())
}
info.Put("type", clashType)
info.Put("name", detour.Tag())

View File

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

View File

@ -48,3 +48,7 @@ func Version() string {
func FormatBytes(length int64) string {
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
case C.TypeDirect:
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
case C.TypeHTTP:
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 {
inbound := &Socks{
myInboundAdapter{
protocol: C.TypeSocks,
protocol: C.TypeSOCKS,
network: []string{N.NetworkTCP},
ctx: ctx,
router: router,

View File

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

View File

@ -36,7 +36,7 @@ func (h Outbound) MarshalJSON() ([]byte, error) {
v = h.DirectOptions
case C.TypeBlock, C.TypeDNS:
v = nil
case C.TypeSocks:
case C.TypeSOCKS:
v = h.SocksOptions
case C.TypeHTTP:
v = h.HTTPOptions
@ -81,7 +81,7 @@ func (h *Outbound) UnmarshalJSON(bytes []byte) error {
v = &h.DirectOptions
case C.TypeBlock, C.TypeDNS:
v = nil
case C.TypeSocks:
case C.TypeSOCKS:
v = &h.SocksOptions
case C.TypeHTTP:
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
case C.TypeDNS:
return NewDNS(router, tag), nil
case C.TypeSocks:
case C.TypeSOCKS:
return NewSocks(router, logger, tag, options.SocksOptions)
case C.TypeHTTP:
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{
myOutboundAdapter: myOutboundAdapter{
protocol: C.TypeSocks,
protocol: C.TypeSOCKS,
network: options.Network.Build(),
router: router,
logger: logger,

View File

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