From d079910a998cc78402f5deb43271186f8bae5e5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Sun, 17 Nov 2024 16:54:27 +0800 Subject: [PATCH] Remove legacy inbound/outbound options --- box.go | 20 -------- option/inbound_legacy.go | 98 ------------------------------------ option/options.go | 5 -- option/outbound_legacy.go | 103 -------------------------------------- 4 files changed, 226 deletions(-) delete mode 100644 option/inbound_legacy.go delete mode 100644 option/outbound_legacy.go diff --git a/box.go b/box.go index d9abe15a..3b69617f 100644 --- a/box.go +++ b/box.go @@ -132,26 +132,6 @@ func New(options Options) (*Box, error) { if err != nil { return nil, E.Cause(err, "initialize router") } - //nolint:staticcheck - if len(options.LegacyInbounds) > 0 { - for _, legacyInbound := range options.LegacyInbounds { - options.Inbounds = append(options.Inbounds, option.Inbound{ - Type: legacyInbound.Type, - Tag: legacyInbound.Tag, - Options: common.Must1(legacyInbound.RawOptions()), - }) - } - } - //nolint:staticcheck - if len(options.LegacyOutbounds) > 0 { - for _, legacyOutbound := range options.LegacyOutbounds { - options.Outbounds = append(options.Outbounds, option.Outbound{ - Type: legacyOutbound.Type, - Tag: legacyOutbound.Tag, - Options: common.Must1(legacyOutbound.RawOptions()), - }) - } - } for i, inboundOptions := range options.Inbounds { var tag string if inboundOptions.Tag != "" { diff --git a/option/inbound_legacy.go b/option/inbound_legacy.go deleted file mode 100644 index e7f34678..00000000 --- a/option/inbound_legacy.go +++ /dev/null @@ -1,98 +0,0 @@ -package option - -import ( - C "github.com/sagernet/sing-box/constant" - E "github.com/sagernet/sing/common/exceptions" - "github.com/sagernet/sing/common/json" - "github.com/sagernet/sing/common/json/badjson" -) - -type _LegacyInbound struct { - Type string `json:"type"` - Tag string `json:"tag,omitempty"` - TunOptions TunInboundOptions `json:"-"` - RedirectOptions RedirectInboundOptions `json:"-"` - TProxyOptions TProxyInboundOptions `json:"-"` - DirectOptions DirectInboundOptions `json:"-"` - SocksOptions SocksInboundOptions `json:"-"` - HTTPOptions HTTPMixedInboundOptions `json:"-"` - MixedOptions HTTPMixedInboundOptions `json:"-"` - ShadowsocksOptions ShadowsocksInboundOptions `json:"-"` - VMessOptions VMessInboundOptions `json:"-"` - TrojanOptions TrojanInboundOptions `json:"-"` - NaiveOptions NaiveInboundOptions `json:"-"` - HysteriaOptions HysteriaInboundOptions `json:"-"` - ShadowTLSOptions ShadowTLSInboundOptions `json:"-"` - VLESSOptions VLESSInboundOptions `json:"-"` - TUICOptions TUICInboundOptions `json:"-"` - Hysteria2Options Hysteria2InboundOptions `json:"-"` -} - -type LegacyInbound _LegacyInbound - -func (h *LegacyInbound) RawOptions() (any, error) { - var rawOptionsPtr any - switch h.Type { - case C.TypeTun: - rawOptionsPtr = &h.TunOptions - case C.TypeRedirect: - rawOptionsPtr = &h.RedirectOptions - case C.TypeTProxy: - rawOptionsPtr = &h.TProxyOptions - case C.TypeDirect: - rawOptionsPtr = &h.DirectOptions - case C.TypeSOCKS: - rawOptionsPtr = &h.SocksOptions - case C.TypeHTTP: - rawOptionsPtr = &h.HTTPOptions - case C.TypeMixed: - rawOptionsPtr = &h.MixedOptions - case C.TypeShadowsocks: - rawOptionsPtr = &h.ShadowsocksOptions - case C.TypeVMess: - rawOptionsPtr = &h.VMessOptions - case C.TypeTrojan: - rawOptionsPtr = &h.TrojanOptions - case C.TypeNaive: - rawOptionsPtr = &h.NaiveOptions - case C.TypeHysteria: - rawOptionsPtr = &h.HysteriaOptions - case C.TypeShadowTLS: - rawOptionsPtr = &h.ShadowTLSOptions - case C.TypeVLESS: - rawOptionsPtr = &h.VLESSOptions - case C.TypeTUIC: - rawOptionsPtr = &h.TUICOptions - case C.TypeHysteria2: - rawOptionsPtr = &h.Hysteria2Options - case "": - return nil, E.New("missing inbound type") - default: - return nil, E.New("unknown inbound type: ", h.Type) - } - return rawOptionsPtr, nil -} - -func (h LegacyInbound) MarshalJSON() ([]byte, error) { - rawOptions, err := h.RawOptions() - if err != nil { - return nil, err - } - return badjson.MarshallObjects((_LegacyInbound)(h), rawOptions) -} - -func (h *LegacyInbound) UnmarshalJSON(bytes []byte) error { - err := json.Unmarshal(bytes, (*_LegacyInbound)(h)) - if err != nil { - return err - } - rawOptions, err := h.RawOptions() - if err != nil { - return err - } - err = badjson.UnmarshallExcluded(bytes, (*_LegacyInbound)(h), rawOptions) - if err != nil { - return err - } - return nil -} diff --git a/option/options.go b/option/options.go index d28b0ebc..13a16c08 100644 --- a/option/options.go +++ b/option/options.go @@ -17,11 +17,6 @@ type _Options struct { Outbounds []Outbound `json:"outbounds,omitempty"` Route *RouteOptions `json:"route,omitempty"` Experimental *ExperimentalOptions `json:"experimental,omitempty"` - - // Deprecated: use Inbounds instead - LegacyInbounds []LegacyInbound `json:"-"` - // Deprecated: use Outbounds instead - LegacyOutbounds []LegacyOutbound `json:"-"` } type Options _Options diff --git a/option/outbound_legacy.go b/option/outbound_legacy.go deleted file mode 100644 index d840884b..00000000 --- a/option/outbound_legacy.go +++ /dev/null @@ -1,103 +0,0 @@ -package option - -import ( - C "github.com/sagernet/sing-box/constant" - E "github.com/sagernet/sing/common/exceptions" - "github.com/sagernet/sing/common/json" - "github.com/sagernet/sing/common/json/badjson" -) - -type _LegacyOutbound struct { - Type string `json:"type"` - Tag string `json:"tag,omitempty"` - DirectOptions DirectOutboundOptions `json:"-"` - SocksOptions SOCKSOutboundOptions `json:"-"` - HTTPOptions HTTPOutboundOptions `json:"-"` - ShadowsocksOptions ShadowsocksOutboundOptions `json:"-"` - VMessOptions VMessOutboundOptions `json:"-"` - TrojanOptions TrojanOutboundOptions `json:"-"` - WireGuardOptions WireGuardOutboundOptions `json:"-"` - HysteriaOptions HysteriaOutboundOptions `json:"-"` - TorOptions TorOutboundOptions `json:"-"` - SSHOptions SSHOutboundOptions `json:"-"` - ShadowTLSOptions ShadowTLSOutboundOptions `json:"-"` - ShadowsocksROptions ShadowsocksROutboundOptions `json:"-"` - VLESSOptions VLESSOutboundOptions `json:"-"` - TUICOptions TUICOutboundOptions `json:"-"` - Hysteria2Options Hysteria2OutboundOptions `json:"-"` - SelectorOptions SelectorOutboundOptions `json:"-"` - URLTestOptions URLTestOutboundOptions `json:"-"` -} - -type LegacyOutbound _LegacyOutbound - -func (h *LegacyOutbound) RawOptions() (any, error) { - var rawOptionsPtr any - switch h.Type { - case C.TypeDirect: - rawOptionsPtr = &h.DirectOptions - case C.TypeBlock, C.TypeDNS: - rawOptionsPtr = new(StubOptions) - case C.TypeSOCKS: - rawOptionsPtr = &h.SocksOptions - case C.TypeHTTP: - rawOptionsPtr = &h.HTTPOptions - case C.TypeShadowsocks: - rawOptionsPtr = &h.ShadowsocksOptions - case C.TypeVMess: - rawOptionsPtr = &h.VMessOptions - case C.TypeTrojan: - rawOptionsPtr = &h.TrojanOptions - case C.TypeWireGuard: - rawOptionsPtr = &h.WireGuardOptions - case C.TypeHysteria: - rawOptionsPtr = &h.HysteriaOptions - case C.TypeTor: - rawOptionsPtr = &h.TorOptions - case C.TypeSSH: - rawOptionsPtr = &h.SSHOptions - case C.TypeShadowTLS: - rawOptionsPtr = &h.ShadowTLSOptions - case C.TypeShadowsocksR: - rawOptionsPtr = &h.ShadowsocksROptions - case C.TypeVLESS: - rawOptionsPtr = &h.VLESSOptions - case C.TypeTUIC: - rawOptionsPtr = &h.TUICOptions - case C.TypeHysteria2: - rawOptionsPtr = &h.Hysteria2Options - case C.TypeSelector: - rawOptionsPtr = &h.SelectorOptions - case C.TypeURLTest: - rawOptionsPtr = &h.URLTestOptions - case "": - return nil, E.New("missing outbound type") - default: - return nil, E.New("unknown outbound type: ", h.Type) - } - return rawOptionsPtr, nil -} - -func (h *LegacyOutbound) MarshalJSON() ([]byte, error) { - rawOptions, err := h.RawOptions() - if err != nil { - return nil, err - } - return badjson.MarshallObjects((*_LegacyOutbound)(h), rawOptions) -} - -func (h *LegacyOutbound) UnmarshalJSON(bytes []byte) error { - err := json.Unmarshal(bytes, (*_LegacyOutbound)(h)) - if err != nil { - return err - } - rawOptions, err := h.RawOptions() - if err != nil { - return err - } - err = badjson.UnmarshallExcluded(bytes, (*_LegacyOutbound)(h), rawOptions) - if err != nil { - return err - } - return nil -}