重构部分代码

fix: vless ws 配置缺少 path 字段
This commit is contained in:
2024-03-21 00:02:38 +08:00
committed by Nite07
parent 86885f6b47
commit 1a7944f7a1
33 changed files with 757 additions and 548 deletions

View File

@ -51,8 +51,8 @@ type Config struct {
Log *LogOptions `json:"log,omitempty"`
DNS *DNSOptions `json:"dns,omitempty"`
NTP *NTPOptions `json:"ntp,omitempty"`
Inbounds Listable[Inbound] `json:"inbounds,omitempty"`
Outbounds Listable[Outbound] `json:"outbounds,omitempty"`
Inbounds []Inbound `json:"inbounds,omitempty"`
Outbounds []Outbound `json:"outbounds,omitempty"`
Route *RouteOptions `json:"route,omitempty"`
Experimental *ExperimentalOptions `json:"experimental,omitempty"`
}
@ -65,12 +65,12 @@ type LogOptions struct {
}
type DNSOptions struct {
Servers Listable[DNSServerOptions] `json:"servers,omitempty"`
Rules Listable[DNSRule] `json:"rules,omitempty"`
Final string `json:"final,omitempty"`
ReverseMapping bool `json:"reverse_mapping,omitempty"`
FakeIP *DNSFakeIPOptions `json:"fakeip,omitempty"`
Strategy string `json:"strategy,omitempty"`
Servers Listable[DNSServerOptions] `json:"servers,omitempty"`
Rules Listable[DNSRule] `json:"rules,omitempty"`
Final string `json:"final,omitempty"`
ReverseMapping bool `json:"reverse_mapping,omitempty"`
FakeIP *DNSFakeIPOptions `json:"fakeip,omitempty"`
Strategy string `json:"strategy,omitempty"`
DisableCache bool `json:"disable_cache,omitempty"`
DisableExpire bool `json:"disable_expire,omitempty"`
IndependentCache bool `json:"independent_cache,omitempty"`
@ -162,29 +162,29 @@ type Inbound struct {
Tag string `json:"tag,omitempty"`
InterfaceName string `json:"interface_name,omitempty"`
MTU uint32 `json:"mtu,omitempty"`
GSO bool `json:"gso,omitempty"`
Inet4Address Listable[string] `json:"inet4_address,omitempty"`
Inet6Address Listable[string] `json:"inet6_address,omitempty"`
AutoRoute bool `json:"auto_route,omitempty"`
StrictRoute bool `json:"strict_route,omitempty"`
Inet4RouteAddress Listable[string] `json:"inet4_route_address,omitempty"`
Inet6RouteAddress Listable[string] `json:"inet6_route_address,omitempty"`
Inet4RouteExcludeAddress Listable[string] `json:"inet4_route_exclude_address,omitempty"`
Inet6RouteExcludeAddress Listable[string] `json:"inet6_route_exclude_address,omitempty"`
IncludeInterface Listable[string] `json:"include_interface,omitempty"`
ExcludeInterface Listable[string] `json:"exclude_interface,omitempty"`
IncludeUID Listable[uint32] `json:"include_uid,omitempty"`
IncludeUIDRange Listable[string] `json:"include_uid_range,omitempty"`
ExcludeUID Listable[uint32] `json:"exclude_uid,omitempty"`
ExcludeUIDRange Listable[string] `json:"exclude_uid_range,omitempty"`
IncludeAndroidUser Listable[int] `json:"include_android_user,omitempty"`
IncludePackage Listable[string] `json:"include_package,omitempty"`
ExcludePackage Listable[string] `json:"exclude_package,omitempty"`
EndpointIndependentNat bool `json:"endpoint_independent_nat,omitempty"`
GSO bool `json:"gso,omitempty"`
Inet4Address Listable[string] `json:"inet4_address,omitempty"`
Inet6Address Listable[string] `json:"inet6_address,omitempty"`
AutoRoute bool `json:"auto_route,omitempty"`
StrictRoute bool `json:"strict_route,omitempty"`
Inet4RouteAddress Listable[string] `json:"inet4_route_address,omitempty"`
Inet6RouteAddress Listable[string] `json:"inet6_route_address,omitempty"`
Inet4RouteExcludeAddress Listable[string] `json:"inet4_route_exclude_address,omitempty"`
Inet6RouteExcludeAddress Listable[string] `json:"inet6_route_exclude_address,omitempty"`
IncludeInterface Listable[string] `json:"include_interface,omitempty"`
ExcludeInterface Listable[string] `json:"exclude_interface,omitempty"`
IncludeUID Listable[uint32] `json:"include_uid,omitempty"`
IncludeUIDRange Listable[string] `json:"include_uid_range,omitempty"`
ExcludeUID Listable[uint32] `json:"exclude_uid,omitempty"`
ExcludeUIDRange Listable[string] `json:"exclude_uid_range,omitempty"`
IncludeAndroidUser Listable[int] `json:"include_android_user,omitempty"`
IncludePackage Listable[string] `json:"include_package,omitempty"`
ExcludePackage Listable[string] `json:"exclude_package,omitempty"`
EndpointIndependentNat bool `json:"endpoint_independent_nat,omitempty"`
UDPTimeout string `json:"udp_timeout,omitempty"`
Stack string `json:"stack,omitempty"`
Platform *TunPlatformOptions `json:"platform,omitempty"`
SniffEnabled bool `json:"sniff,omitempty"`
Stack string `json:"stack,omitempty"`
Platform *TunPlatformOptions `json:"platform,omitempty"`
SniffEnabled bool `json:"sniff,omitempty"`
SniffOverrideDestination bool `json:"sniff_override_destination,omitempty"`
SniffTimeout string `json:"sniff_timeout,omitempty"`
DomainStrategy string `json:"domain_strategy,omitempty"`
@ -203,111 +203,12 @@ type HTTPProxyOptions struct {
MatchDomain Listable[string] `json:"match_domain,omitempty"`
}
type Outbound struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
Detour string `json:"detour,omitempty"`
BindInterface string `json:"bind_interface,omitempty"`
Inet4BindAddress string `json:"inet4_bind_address,omitempty"`
Inet6BindAddress string `json:"inet6_bind_address,omitempty"`
ProtectPath string `json:"protect_path,omitempty"`
RoutingMark int `json:"routing_mark,omitempty"`
ReuseAddr bool `json:"reuse_addr,omitempty"`
ConnectTimeout string `json:"connect_timeout,omitempty"`
TCPFastOpen bool `json:"tcp_fast_open,omitempty"`
TCPMultiPath bool `json:"tcp_multi_path,omitempty"`
UDPFragment *bool `json:"udp_fragment,omitempty"`
DomainStrategy string `json:"domain_strategy,omitempty"`
FallbackDelay string `json:"fallback_delay,omitempty"`
OverrideAddress string `json:"override_address,omitempty"`
OverridePort uint16 `json:"override_port,omitempty"`
ProxyProtocol uint8 `json:"proxy_protocol,omitempty"`
Server string `json:"server,omitempty"`
ServerPort uint16 `json:"server_port,omitempty"`
Version string `json:"version,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Network string `json:"network,omitempty"`
UDPOverTCP *UDPOverTCPOptions `json:"udp_over_tcp,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"`
Path string `json:"path,omitempty"`
Headers map[string]Listable[string] `json:"headers,omitempty"`
Method string `json:"method,omitempty"`
Plugin string `json:"plugin,omitempty"`
PluginOptions string `json:"plugin_opts,omitempty"`
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
UUID string `json:"uuid,omitempty"`
Security string `json:"security,omitempty"`
AlterId int `json:"alter_id,omitempty"`
GlobalPadding bool `json:"global_padding,omitempty"`
AuthenticatedLength bool `json:"authenticated_length,omitempty"`
PacketEncoding string `json:"packet_encoding,omitempty"`
Transport *V2RayTransportOptions `json:"transport,omitempty"`
SystemInterface bool `json:"system_interface,omitempty"`
GSO bool `json:"gso,omitempty"`
InterfaceName string `json:"interface_name,omitempty"`
LocalAddress Listable[string] `json:"local_address,omitempty"`
PrivateKey string `json:"private_key,omitempty"`
Peers Listable[WireGuardPeer] `json:"peers,omitempty"`
PeerPublicKey string `json:"peer_public_key,omitempty"`
PreSharedKey string `json:"pre_shared_key,omitempty"`
Reserved Listable[uint8] `json:"reserved,omitempty"`
Workers int `json:"workers,omitempty"`
MTU uint32 `json:"mtu,omitempty"`
Up string `json:"up,omitempty"`
UpMbps int `json:"up_mbps,omitempty"`
Down string `json:"down,omitempty"`
DownMbps int `json:"down_mbps,omitempty"`
Obfs *Obfs `json:"obfs,omitempty"`
Auth Listable[byte] `json:"auth,omitempty"`
AuthString string `json:"auth_str,omitempty"`
ReceiveWindowConn uint64 `json:"recv_window_conn,omitempty"`
ReceiveWindow uint64 `json:"recv_window,omitempty"`
DisableMTUDiscovery bool `json:"disable_mtu_discovery,omitempty"`
ExecutablePath string `json:"executable_path,omitempty"`
ExtraArgs Listable[string] `json:"extra_args,omitempty"`
DataDirectory string `json:"data_directory,omitempty"`
Options map[string]string `json:"torrc,omitempty"`
User string `json:"user,omitempty"`
PrivateKeyPath string `json:"private_key_path,omitempty"`
PrivateKeyPassphrase string `json:"private_key_passphrase,omitempty"`
HostKey Listable[string] `json:"host_key,omitempty"`
HostKeyAlgorithms Listable[string] `json:"host_key_algorithms,omitempty"`
ClientVersion string `json:"client_version,omitempty"`
ObfsParam string `json:"obfs_param,omitempty"`
Protocol string `json:"protocol,omitempty"`
ProtocolParam string `json:"protocol_param,omitempty"`
Flow string `json:"flow,omitempty"`
CongestionControl string `json:"congestion_control,omitempty"`
UDPRelayMode string `json:"udp_relay_mode,omitempty"`
UDPOverStream bool `json:"udp_over_stream,omitempty"`
ZeroRTTHandshake bool `json:"zero_rtt_handshake,omitempty"`
Heartbeat string `json:"heartbeat,omitempty"`
BrutalDebug bool `json:"brutal_debug,omitempty"`
Default string `json:"default,omitempty"`
Outbounds Listable[string] `json:"outbounds,omitempty"`
URL string `json:"url,omitempty"`
Interval string `json:"interval,omitempty"`
Tolerance uint16 `json:"tolerance,omitempty"`
IdleTimeout string `json:"idle_timeout,omitempty"`
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
}
type WireGuardPeer struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
PublicKey string `json:"public_key,omitempty"`
PreSharedKey string `json:"pre_shared_key,omitempty"`
AllowedIPs Listable[string] `json:"allowed_ips,omitempty"`
Reserved Listable[uint8] `json:"reserved,omitempty"`
}
type RouteOptions struct {
GeoIP *GeoIPOptions `json:"geoip,omitempty"`
Geosite *GeositeOptions `json:"geosite,omitempty"`
Rules Listable[Rule] `json:"rules,omitempty"`
RuleSet Listable[RuleSet] `json:"rule_set,omitempty"`
Final string `json:"final,omitempty"`
GeoIP *GeoIPOptions `json:"geoip,omitempty"`
Geosite *GeositeOptions `json:"geosite,omitempty"`
Rules Listable[Rule] `json:"rules,omitempty"`
RuleSet Listable[RuleSet] `json:"rule_set,omitempty"`
Final string `json:"final,omitempty"`
FindProcess bool `json:"find_process,omitempty"`
AutoDetectInterface bool `json:"auto_detect_interface,omitempty"`
OverrideAndroidVPN bool `json:"override_android_vpn,omitempty"`

8
model/direct.go Normal file
View File

@ -0,0 +1,8 @@
package model
type DirectOutboundOptions struct {
DialerOptions
OverrideAddress string `json:"override_address,omitempty"`
OverridePort uint16 `json:"override_port,omitempty"`
ProxyProtocol uint8 `json:"proxy_protocol,omitempty"`
}

16
model/group.go Normal file
View File

@ -0,0 +1,16 @@
package model
type SelectorOutboundOptions struct {
Outbounds []string `json:"outbounds"`
Default string `json:"default,omitempty"`
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
}
type URLTestOutboundOptions struct {
Outbounds []string `json:"outbounds"`
URL string `json:"url,omitempty"`
Interval string `json:"interval,omitempty"`
Tolerance uint16 `json:"tolerance,omitempty"`
IdleTimeout string `json:"idle_timeout,omitempty"`
InterruptExistConnections bool `json:"interrupt_exist_connections,omitempty"`
}

View File

@ -1,18 +1,18 @@
package model
type Hysteria struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
Up string `json:"up,omitempty"`
UpMbps int `json:"up_mbps,omitempty"`
Down string `json:"down,omitempty"`
DownMbps int `json:"down_mbps,omitempty"`
Obfs string `json:"obfs,omitempty"`
Auth []byte `json:"auth,omitempty"`
AuthString string `json:"auth_str,omitempty"`
ReceiveWindowConn uint64 `json:"recv_window_conn,omitempty"`
ReceiveWindow uint64 `json:"recv_window,omitempty"`
DisableMTUDiscovery bool `json:"disable_mtu_discovery,omitempty"`
Network string `json:"network,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"`
type HysteriaOutboundOptions struct {
DialerOptions
ServerOptions
Up string `json:"up,omitempty"`
UpMbps int `json:"up_mbps,omitempty"`
Down string `json:"down,omitempty"`
DownMbps int `json:"down_mbps,omitempty"`
Obfs string `json:"obfs,omitempty"`
Auth []byte `json:"auth,omitempty"`
AuthString string `json:"auth_str,omitempty"`
ReceiveWindowConn uint64 `json:"recv_window_conn,omitempty"`
ReceiveWindow uint64 `json:"recv_window,omitempty"`
DisableMTUDiscovery bool `json:"disable_mtu_discovery,omitempty"`
Network string `json:"network,omitempty"`
OutboundTLSOptionsContainer
}

View File

@ -5,14 +5,14 @@ type Hysteria2Obfs struct {
Password string `json:"password,omitempty"`
}
type Hysteria2 struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
UpMbps int `json:"up_mbps,omitempty"`
DownMbps int `json:"down_mbps,omitempty"`
Obfs *Hysteria2Obfs `json:"obfs,omitempty"`
Password string `json:"password,omitempty"`
Network string `json:"network,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"`
BrutalDebug bool `json:"brutal_debug,omitempty"`
type Hysteria2OutboundOptions struct {
DialerOptions
ServerOptions
UpMbps int `json:"up_mbps,omitempty"`
DownMbps int `json:"down_mbps,omitempty"`
Obfs *Hysteria2Obfs `json:"obfs,omitempty"`
Password string `json:"password,omitempty"`
Network string `json:"network,omitempty"`
OutboundTLSOptionsContainer
BrutalDebug bool `json:"brutal_debug,omitempty"`
}

167
model/outbound.go Normal file
View File

@ -0,0 +1,167 @@
package model
import (
"encoding/json"
"errors"
"reflect"
C "sub2sing-box/constant"
"sub2sing-box/util"
)
type _Outbound 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 Outbound _Outbound
func (h *Outbound) RawOptions() (any, error) {
var rawOptionsPtr any
switch h.Type {
case C.TypeDirect:
rawOptionsPtr = &h.DirectOptions
case C.TypeBlock, C.TypeDNS:
rawOptionsPtr = nil
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, errors.New("missing outbound type")
default:
return nil, errors.New("unknown outbound type: " + h.Type)
}
return rawOptionsPtr, nil
}
func (h *Outbound) MarshalJSON() ([]byte, error) {
rawOptions, err := h.RawOptions()
if err != nil {
return nil, err
}
result, err := util.MergeAndMarshal(struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
}{
Type: h.Type,
Tag: h.Tag,
}, rawOptions)
if err != nil {
return nil, err
}
return []byte(result), nil
}
func (h *Outbound) UnmarshalJSON(bytes []byte) error {
err := json.Unmarshal(bytes, (*_Outbound)(h))
if err != nil {
return err
}
rawOptions, err := h.RawOptions()
if err != nil {
return err
}
if rawOptions == nil {
return nil
}
err = json.Unmarshal(bytes, rawOptions)
if err != nil {
return err
}
rawOptionsType := reflect.TypeOf(rawOptions).Elem()
hValue := reflect.ValueOf(h).Elem()
for i := 0; i < hValue.NumField(); i++ {
fieldType := hValue.Field(i).Type()
if fieldType == rawOptionsType {
hValue.Field(i).Set(reflect.ValueOf(rawOptions).Elem())
return nil
}
}
return errors.New("unknown outbound type: " + h.Type)
}
func (h *Outbound) GetOutbounds() []string {
if h.Type == C.TypeSelector {
return h.SelectorOptions.Outbounds
}
if h.Type == C.TypeURLTest {
return h.URLTestOptions.Outbounds
}
return nil
}
func (h *Outbound) SetOutbounds(outbounds []string) {
if h.Type == C.TypeSelector {
h.SelectorOptions.Outbounds = outbounds
}
if h.Type == C.TypeURLTest {
h.URLTestOptions.Outbounds = outbounds
}
}
type DialerOptions struct {
Detour string `json:"detour,omitempty"`
BindInterface string `json:"bind_interface,omitempty"`
Inet4BindAddress string `json:"inet4_bind_address,omitempty"`
Inet6BindAddress string `json:"inet6_bind_address,omitempty"`
ProtectPath string `json:"protect_path,omitempty"`
RoutingMark int `json:"routing_mark,omitempty"`
ReuseAddr bool `json:"reuse_addr,omitempty"`
ConnectTimeout string `json:"connect_timeout,omitempty"`
TCPFastOpen bool `json:"tcp_fast_open,omitempty"`
TCPMultiPath bool `json:"tcp_multi_path,omitempty"`
UDPFragment *bool `json:"udp_fragment,omitempty"`
UDPFragmentDefault bool `json:"-"`
DomainStrategy string `json:"domain_strategy,omitempty"`
FallbackDelay string `json:"fallback_delay,omitempty"`
IsWireGuardListener bool `json:"-"`
}
type ServerOptions struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
}

View File

@ -1,94 +0,0 @@
package model
import (
"encoding/json"
)
type Proxy struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
Shadowsocks `json:"-"`
VMess `json:"-"`
VLESS `json:"-"`
Trojan `json:"-"`
TUIC `json:"-"`
Hysteria `json:"-"`
Hysteria2 `json:"-"`
}
func (p *Proxy) MarshalJSON() ([]byte, error) {
switch p.Type {
case "shadowsocks":
return json.Marshal(&struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
Shadowsocks
}{
Type: p.Type,
Tag: p.Tag,
Shadowsocks: p.Shadowsocks,
})
case "vmess":
return json.Marshal(&struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
VMess
}{
Type: p.Type,
Tag: p.Tag,
VMess: p.VMess,
})
case "vless":
return json.Marshal(&struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
VLESS
}{
Type: p.Type,
Tag: p.Tag,
VLESS: p.VLESS,
})
case "trojan":
return json.Marshal(&struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
Trojan
}{
Type: p.Type,
Tag: p.Tag,
Trojan: p.Trojan,
})
case "tuic":
return json.Marshal(&struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
TUIC
}{
Type: p.Type,
Tag: p.Tag,
TUIC: p.TUIC,
})
case "hysteria":
return json.Marshal(&struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
Hysteria
}{
Type: p.Type,
Tag: p.Tag,
Hysteria: p.Hysteria,
})
case "hysteria2":
return json.Marshal(&struct {
Type string `json:"type"`
Tag string `json:"tag,omitempty"`
Hysteria2
}{
Type: p.Type,
Tag: p.Tag,
Hysteria2: p.Hysteria2,
})
default:
return json.Marshal(p)
}
}

View File

@ -1,8 +1,8 @@
package model
type Shadowsocks struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
type ShadowsocksOutboundOptions struct {
DialerOptions
ServerOptions
Method string `json:"method"`
Password string `json:"password"`
Plugin string `json:"plugin,omitempty"`

13
model/shadowsocksr.go Normal file
View File

@ -0,0 +1,13 @@
package model
type ShadowsocksROutboundOptions struct {
DialerOptions
ServerOptions
Method string `json:"method"`
Password string `json:"password"`
Obfs string `json:"obfs,omitempty"`
ObfsParam string `json:"obfs_param,omitempty"`
Protocol string `json:"protocol,omitempty"`
ProtocolParam string `json:"protocol_param,omitempty"`
Network string `json:"network,omitempty"`
}

19
model/shadowtls.go Normal file
View File

@ -0,0 +1,19 @@
package model
type ShadowTLSUser struct {
Name string `json:"name,omitempty"`
Password string `json:"password,omitempty"`
}
type ShadowTLSHandshakeOptions struct {
ServerOptions
DialerOptions
}
type ShadowTLSOutboundOptions struct {
DialerOptions
ServerOptions
Version int `json:"version,omitempty"`
Password string `json:"password,omitempty"`
OutboundTLSOptionsContainer
}

21
model/simple.go Normal file
View File

@ -0,0 +1,21 @@
package model
type SocksOutboundOptions struct {
DialerOptions
ServerOptions
Version string `json:"version,omitempty"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Network Listable[string] `json:"network,omitempty"`
UDPOverTCP *UDPOverTCPOptions `json:"udp_over_tcp,omitempty"`
}
type HTTPOutboundOptions struct {
DialerOptions
ServerOptions
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
OutboundTLSOptionsContainer
Path string `json:"path,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}

View File

@ -1,15 +1,32 @@
package model
import (
C "sub2sing-box/constant"
"golang.org/x/text/collate"
"golang.org/x/text/language"
)
type SortByNumber []Outbound
func (a SortByNumber) Len() int { return len(a) }
func (a SortByNumber) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortByNumber) Less(i, j int) bool { return len(a[i].Outbounds) < len(a[j].Outbounds) }
func (a SortByNumber) Len() int { return len(a) }
func (a SortByNumber) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortByNumber) Less(i, j int) bool {
var size1, size2 int
if a[i].Type == C.TypeSelector {
size1 = len(a[i].SelectorOptions.Outbounds)
}
if a[i].Type == C.TypeURLTest {
size1 = len(a[j].URLTestOptions.Outbounds)
}
if a[j].Type == C.TypeSelector {
size2 = len(a[j].SelectorOptions.Outbounds)
}
if a[j].Type == C.TypeURLTest {
size2 = len(a[j].URLTestOptions.Outbounds)
}
return size1 < size2
}
type SortByTag []Outbound

14
model/ssh.go Normal file
View File

@ -0,0 +1,14 @@
package model
type SSHOutboundOptions struct {
DialerOptions
ServerOptions
User string `json:"user,omitempty"`
Password string `json:"password,omitempty"`
PrivateKey Listable[string] `json:"private_key,omitempty"`
PrivateKeyPath string `json:"private_key_path,omitempty"`
PrivateKeyPassphrase string `json:"private_key_passphrase,omitempty"`
HostKey Listable[string] `json:"host_key,omitempty"`
HostKeyAlgorithms Listable[string] `json:"host_key_algorithms,omitempty"`
ClientVersion string `json:"client_version,omitempty"`
}

View File

@ -34,3 +34,7 @@ type OutboundRealityOptions struct {
PublicKey string `json:"public_key,omitempty"`
ShortID string `json:"short_id,omitempty"`
}
type OutboundTLSOptionsContainer struct {
TLS *OutboundTLSOptions `json:"tls,omitempty"`
}

9
model/tor.go Normal file
View File

@ -0,0 +1,9 @@
package model
type TorOutboundOptions struct {
DialerOptions
ExecutablePath string `json:"executable_path,omitempty"`
ExtraArgs []string `json:"extra_args,omitempty"`
DataDirectory string `json:"data_directory,omitempty"`
Options map[string]string `json:"torrc,omitempty"`
}

View File

@ -1,11 +1,11 @@
package model
type Trojan struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
Password string `json:"password"`
Network string `json:"network,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"`
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
Transport *V2RayTransportOptions `json:"transport,omitempty"`
type TrojanOutboundOptions struct {
DialerOptions
ServerOptions
Password string `json:"password"`
Network string `json:"network,omitempty"`
OutboundTLSOptionsContainer
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
Transport *V2RayTransportOptions `json:"transport,omitempty"`
}

View File

@ -1,15 +1,15 @@
package model
type TUIC struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
UUID string `json:"uuid,omitempty"`
Password string `json:"password,omitempty"`
CongestionControl string `json:"congestion_control,omitempty"`
UDPRelayMode string `json:"udp_relay_mode,omitempty"`
UDPOverStream bool `json:"udp_over_stream,omitempty"`
ZeroRTTHandshake bool `json:"zero_rtt_handshake,omitempty"`
Heartbeat string `json:"heartbeat,omitempty"`
Network string `json:"network,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"`
type TUICOutboundOptions struct {
DialerOptions
ServerOptions
UUID string `json:"uuid,omitempty"`
Password string `json:"password,omitempty"`
CongestionControl string `json:"congestion_control,omitempty"`
UDPRelayMode string `json:"udp_relay_mode,omitempty"`
UDPOverStream bool `json:"udp_over_stream,omitempty"`
ZeroRTTHandshake bool `json:"zero_rtt_handshake,omitempty"`
Heartbeat string `json:"heartbeat,omitempty"`
Network string `json:"network,omitempty"`
OutboundTLSOptionsContainer
}

View File

@ -53,8 +53,8 @@ func (o *V2RayTransportOptions) MarshalJSON() ([]byte, error) {
}
type V2RayHTTPOptions struct {
Host Listable[string] `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Host Listable[string] `json:"host,omitempty"`
Path string `json:"path,omitempty"`
Method string `json:"method,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
IdleTimeout string `json:"idle_timeout,omitempty"`

View File

@ -1,12 +1,12 @@
package model
type VLESS struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
UUID string `json:"uuid"`
Flow string `json:"flow,omitempty"`
Network string `json:"network,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"`
type VLESSOutboundOptions struct {
DialerOptions
ServerOptions
UUID string `json:"uuid"`
Flow string `json:"flow,omitempty"`
Network string `json:"network,omitempty"`
OutboundTLSOptionsContainer
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
Transport *V2RayTransportOptions `json:"transport,omitempty"`
PacketEncoding *string `json:"packet_encoding,omitempty"`

View File

@ -18,17 +18,17 @@ type VmessJson struct {
Fp string `json:"fp"`
}
type VMess struct {
Server string `json:"server"`
ServerPort uint16 `json:"server_port"`
UUID string `json:"uuid"`
Security string `json:"security"`
AlterId int `json:"alter_id,omitempty"`
GlobalPadding bool `json:"global_padding,omitempty"`
AuthenticatedLength bool `json:"authenticated_length,omitempty"`
Network string `json:"network,omitempty"`
TLS *OutboundTLSOptions `json:"tls,omitempty"`
PacketEncoding string `json:"packet_encoding,omitempty"`
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
Transport *V2RayTransportOptions `json:"transport,omitempty"`
type VMessOutboundOptions struct {
DialerOptions
ServerOptions
UUID string `json:"uuid"`
Security string `json:"security"`
AlterId int `json:"alter_id,omitempty"`
GlobalPadding bool `json:"global_padding,omitempty"`
AuthenticatedLength bool `json:"authenticated_length,omitempty"`
Network string `json:"network,omitempty"`
OutboundTLSOptionsContainer
PacketEncoding string `json:"packet_encoding,omitempty"`
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
Transport *V2RayTransportOptions `json:"transport,omitempty"`
}

28
model/wireguard.go Normal file
View File

@ -0,0 +1,28 @@
package model
import "net/netip"
type WireGuardOutboundOptions struct {
DialerOptions
SystemInterface bool `json:"system_interface,omitempty"`
GSO bool `json:"gso,omitempty"`
InterfaceName string `json:"interface_name,omitempty"`
LocalAddress Listable[netip.Prefix] `json:"local_address"`
PrivateKey string `json:"private_key"`
Peers []WireGuardPeer `json:"peers,omitempty"`
ServerOptions
PeerPublicKey string `json:"peer_public_key"`
PreSharedKey string `json:"pre_shared_key,omitempty"`
Reserved []uint8 `json:"reserved,omitempty"`
Workers int `json:"workers,omitempty"`
MTU uint32 `json:"mtu,omitempty"`
Network string `json:"network,omitempty"`
}
type WireGuardPeer struct {
ServerOptions
PublicKey string `json:"public_key,omitempty"`
PreSharedKey string `json:"pre_shared_key,omitempty"`
AllowedIPs Listable[string] `json:"allowed_ips,omitempty"`
Reserved []uint8 `json:"reserved,omitempty"`
}