mirror of
https://github.com/shtorm-7/sing-box-extended.git
synced 2026-06-08 12:14:54 +03:00
Add vmess inbound/outbound
This commit is contained in:
@@ -12,15 +12,16 @@ import (
|
||||
type _Inbound struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
TunOptions TunInboundOptions `json:"-"`
|
||||
RedirectOptions RedirectInboundOptions `json:"-"`
|
||||
TProxyOptions TProxyInboundOptions `json:"-"`
|
||||
DNSOptions DNSInboundOptions `json:"-"`
|
||||
DirectOptions DirectInboundOptions `json:"-"`
|
||||
SocksOptions SocksInboundOptions `json:"-"`
|
||||
HTTPOptions HTTPMixedInboundOptions `json:"-"`
|
||||
MixedOptions HTTPMixedInboundOptions `json:"-"`
|
||||
ShadowsocksOptions ShadowsocksInboundOptions `json:"-"`
|
||||
TunOptions TunInboundOptions `json:"-"`
|
||||
RedirectOptions RedirectInboundOptions `json:"-"`
|
||||
TProxyOptions TProxyInboundOptions `json:"-"`
|
||||
DNSOptions DNSInboundOptions `json:"-"`
|
||||
VMessOptions VMessInboundOptions `json:"-"`
|
||||
}
|
||||
|
||||
type Inbound _Inbound
|
||||
@@ -28,20 +29,29 @@ type Inbound _Inbound
|
||||
func (h Inbound) Equals(other Inbound) bool {
|
||||
return h.Type == other.Type &&
|
||||
h.Tag == other.Tag &&
|
||||
h.TunOptions == other.TunOptions &&
|
||||
h.RedirectOptions == other.RedirectOptions &&
|
||||
h.TProxyOptions == other.TProxyOptions &&
|
||||
h.DNSOptions == other.DNSOptions &&
|
||||
h.DirectOptions == other.DirectOptions &&
|
||||
h.SocksOptions.Equals(other.SocksOptions) &&
|
||||
h.HTTPOptions.Equals(other.HTTPOptions) &&
|
||||
h.MixedOptions.Equals(other.MixedOptions) &&
|
||||
h.ShadowsocksOptions.Equals(other.ShadowsocksOptions) &&
|
||||
h.TunOptions == other.TunOptions &&
|
||||
h.RedirectOptions == other.RedirectOptions &&
|
||||
h.TProxyOptions == other.TProxyOptions &&
|
||||
h.DNSOptions == other.DNSOptions
|
||||
h.VMessOptions.Equals(other.VMessOptions)
|
||||
}
|
||||
|
||||
func (h Inbound) MarshalJSON() ([]byte, error) {
|
||||
var v any
|
||||
switch h.Type {
|
||||
case C.TypeTun:
|
||||
v = h.TunOptions
|
||||
case C.TypeRedirect:
|
||||
v = h.RedirectOptions
|
||||
case C.TypeTProxy:
|
||||
v = h.TProxyOptions
|
||||
case C.TypeDNS:
|
||||
v = h.DNSOptions
|
||||
case C.TypeDirect:
|
||||
v = h.DirectOptions
|
||||
case C.TypeSocks:
|
||||
@@ -52,14 +62,8 @@ func (h Inbound) MarshalJSON() ([]byte, error) {
|
||||
v = h.MixedOptions
|
||||
case C.TypeShadowsocks:
|
||||
v = h.ShadowsocksOptions
|
||||
case C.TypeTun:
|
||||
v = h.TunOptions
|
||||
case C.TypeRedirect:
|
||||
v = h.RedirectOptions
|
||||
case C.TypeTProxy:
|
||||
v = h.TProxyOptions
|
||||
case C.TypeDNS:
|
||||
v = h.DNSOptions
|
||||
case C.TypeVMess:
|
||||
v = h.VMessOptions
|
||||
default:
|
||||
return nil, E.New("unknown inbound type: ", h.Type)
|
||||
}
|
||||
@@ -73,6 +77,14 @@ func (h *Inbound) UnmarshalJSON(bytes []byte) error {
|
||||
}
|
||||
var v any
|
||||
switch h.Type {
|
||||
case C.TypeTun:
|
||||
v = &h.TunOptions
|
||||
case C.TypeRedirect:
|
||||
v = &h.RedirectOptions
|
||||
case C.TypeTProxy:
|
||||
v = &h.TProxyOptions
|
||||
case C.TypeDNS:
|
||||
v = &h.DNSOptions
|
||||
case C.TypeDirect:
|
||||
v = &h.DirectOptions
|
||||
case C.TypeSocks:
|
||||
@@ -83,16 +95,10 @@ func (h *Inbound) UnmarshalJSON(bytes []byte) error {
|
||||
v = &h.MixedOptions
|
||||
case C.TypeShadowsocks:
|
||||
v = &h.ShadowsocksOptions
|
||||
case C.TypeTun:
|
||||
v = &h.TunOptions
|
||||
case C.TypeRedirect:
|
||||
v = &h.RedirectOptions
|
||||
case C.TypeTProxy:
|
||||
v = &h.TProxyOptions
|
||||
case C.TypeDNS:
|
||||
v = &h.DNSOptions
|
||||
case C.TypeVMess:
|
||||
v = &h.VMessOptions
|
||||
default:
|
||||
return nil
|
||||
return E.New("unknown inbound type: ", h.Type)
|
||||
}
|
||||
err = UnmarshallExcluded(bytes, (*_Inbound)(h), v)
|
||||
if err != nil {
|
||||
@@ -173,6 +179,21 @@ type ShadowsocksDestination struct {
|
||||
ServerOptions
|
||||
}
|
||||
|
||||
type VMessInboundOptions struct {
|
||||
ListenOptions
|
||||
Users []VMessUser `json:"users,omitempty"`
|
||||
}
|
||||
|
||||
func (o VMessInboundOptions) Equals(other VMessInboundOptions) bool {
|
||||
return o.ListenOptions == other.ListenOptions &&
|
||||
common.ComparableSliceEquals(o.Users, other.Users)
|
||||
}
|
||||
|
||||
type VMessUser struct {
|
||||
Name string `json:"name"`
|
||||
UUID string `json:"uuid"`
|
||||
}
|
||||
|
||||
type TunInboundOptions struct {
|
||||
InterfaceName string `json:"interface_name,omitempty"`
|
||||
MTU uint32 `json:"mtu,omitempty"`
|
||||
|
||||
@@ -15,6 +15,7 @@ type _Outbound struct {
|
||||
SocksOptions SocksOutboundOptions `json:"-"`
|
||||
HTTPOptions HTTPOutboundOptions `json:"-"`
|
||||
ShadowsocksOptions ShadowsocksOutboundOptions `json:"-"`
|
||||
VMessOptions VMessOutboundOptions `json:"-"`
|
||||
}
|
||||
|
||||
type Outbound _Outbound
|
||||
@@ -24,14 +25,16 @@ func (h Outbound) MarshalJSON() ([]byte, error) {
|
||||
switch h.Type {
|
||||
case C.TypeDirect:
|
||||
v = h.DirectOptions
|
||||
case C.TypeBlock:
|
||||
v = nil
|
||||
case C.TypeSocks:
|
||||
v = h.SocksOptions
|
||||
case C.TypeHTTP:
|
||||
v = h.HTTPOptions
|
||||
case C.TypeShadowsocks:
|
||||
v = h.ShadowsocksOptions
|
||||
case C.TypeBlock:
|
||||
v = nil
|
||||
case C.TypeVMess:
|
||||
v = h.VMessOptions
|
||||
default:
|
||||
return nil, E.New("unknown outbound type: ", h.Type)
|
||||
}
|
||||
@@ -47,14 +50,16 @@ func (h *Outbound) UnmarshalJSON(bytes []byte) error {
|
||||
switch h.Type {
|
||||
case C.TypeDirect:
|
||||
v = &h.DirectOptions
|
||||
case C.TypeBlock:
|
||||
v = nil
|
||||
case C.TypeSocks:
|
||||
v = &h.SocksOptions
|
||||
case C.TypeHTTP:
|
||||
v = &h.HTTPOptions
|
||||
case C.TypeShadowsocks:
|
||||
v = &h.ShadowsocksOptions
|
||||
case C.TypeBlock:
|
||||
v = nil
|
||||
case C.TypeVMess:
|
||||
v = &h.VMessOptions
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -131,3 +136,14 @@ type ShadowsocksOutboundOptions struct {
|
||||
Password string `json:"password"`
|
||||
Network NetworkList `json:"network,omitempty"`
|
||||
}
|
||||
|
||||
type VMessOutboundOptions struct {
|
||||
OutboundDialerOptions
|
||||
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 NetworkList `json:"network,omitempty"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user