mirror of
https://github.com/bestnite/sub2sing-box.git
synced 2025-10-25 16:51:01 +00:00
init
This commit is contained in:
20
model/hysteria.go
Normal file
20
model/hysteria.go
Normal file
@@ -0,0 +1,20 @@
|
||||
package model
|
||||
|
||||
type Hysteria struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
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"`
|
||||
}
|
||||
46
model/hysteria2.go
Normal file
46
model/hysteria2.go
Normal file
@@ -0,0 +1,46 @@
|
||||
package model
|
||||
|
||||
type Hysteria2Obfs struct {
|
||||
Type string `json:"type,omitempty"`
|
||||
Password string `json:"password,omitempty"`
|
||||
}
|
||||
|
||||
type Hysteria2 struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
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"`
|
||||
}
|
||||
|
||||
// func (h *Hysteria2OutboundOptions) MarshalJSON() ([]byte, error) {
|
||||
// val := reflect.ValueOf(h)
|
||||
// out := make(map[string]interface{})
|
||||
// typ := val.Type()
|
||||
// for i := 0; i < val.NumField(); i++ {
|
||||
// field := val.Field(i)
|
||||
// fieldType := typ.Field(i)
|
||||
// if field.Kind() == reflect.Struct {
|
||||
// for j := 0; j < field.NumField(); j++ {
|
||||
// subField := field.Field(j)
|
||||
// subFieldType := fieldType.Type.Field(j)
|
||||
// jsonTag := subFieldType.Tag.Get("json")
|
||||
// if jsonTag != "" && jsonTag != "-" {
|
||||
// out[jsonTag] = subField.Interface()
|
||||
// }
|
||||
// }
|
||||
// } else {
|
||||
// jsonTag := fieldType.Tag.Get("json")
|
||||
// if jsonTag != "" && jsonTag != "-" {
|
||||
// out[jsonTag] = field.Interface()
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return json.Marshal(out)
|
||||
// }
|
||||
17
model/multiplex.go
Normal file
17
model/multiplex.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
type OutboundMultiplexOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Protocol string `json:"protocol,omitempty"`
|
||||
MaxConnections int `json:"max_connections,omitempty"`
|
||||
MinStreams int `json:"min_streams,omitempty"`
|
||||
MaxStreams int `json:"max_streams,omitempty"`
|
||||
Padding bool `json:"padding,omitempty"`
|
||||
Brutal *BrutalOptions `json:"brutal,omitempty"`
|
||||
}
|
||||
|
||||
type BrutalOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
UpMbps int `json:"up_mbps,omitempty"`
|
||||
DownMbps int `json:"down_mbps,omitempty"`
|
||||
}
|
||||
79
model/proxy.go
Normal file
79
model/proxy.go
Normal file
@@ -0,0 +1,79 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type Proxy struct {
|
||||
Type string `json:"type"`
|
||||
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"`
|
||||
Shadowsocks
|
||||
}{
|
||||
Type: p.Type,
|
||||
Shadowsocks: p.Shadowsocks,
|
||||
})
|
||||
case "vmess":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
VMess
|
||||
}{
|
||||
Type: p.Type,
|
||||
VMess: p.VMess,
|
||||
})
|
||||
case "vless":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
VLESS
|
||||
}{
|
||||
Type: p.Type,
|
||||
VLESS: p.VLESS,
|
||||
})
|
||||
case "trojan":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
Trojan
|
||||
}{
|
||||
Type: p.Type,
|
||||
Trojan: p.Trojan,
|
||||
})
|
||||
case "tuic":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
TUIC
|
||||
}{
|
||||
Type: p.Type,
|
||||
TUIC: p.TUIC,
|
||||
})
|
||||
case "hysteria":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
Hysteria
|
||||
}{
|
||||
Type: p.Type,
|
||||
Hysteria: p.Hysteria,
|
||||
})
|
||||
case "hysteria2":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
Hysteria2
|
||||
}{
|
||||
Type: p.Type,
|
||||
Hysteria2: p.Hysteria2,
|
||||
})
|
||||
default:
|
||||
return json.Marshal(p)
|
||||
}
|
||||
}
|
||||
16
model/shadowsocks.go
Normal file
16
model/shadowsocks.go
Normal file
@@ -0,0 +1,16 @@
|
||||
package model
|
||||
|
||||
type NetworkList string
|
||||
|
||||
type Shadowsocks struct {
|
||||
Tag string `json:"tag,omitempty"`
|
||||
Server string `json:"server"`
|
||||
ServerPort uint16 `json:"server_port"`
|
||||
Method string `json:"method"`
|
||||
Password string `json:"password"`
|
||||
Plugin string `json:"plugin,omitempty"`
|
||||
PluginOptions string `json:"plugin_opts,omitempty"`
|
||||
Network string `json:"network,omitempty"`
|
||||
UDPOverTCP *UDPOverTCPOptions `json:"udp_over_tcp,omitempty"`
|
||||
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
|
||||
}
|
||||
36
model/tls.go
Normal file
36
model/tls.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
type OutboundTLSOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
DisableSNI bool `json:"disable_sni,omitempty"`
|
||||
ServerName string `json:"server_name,omitempty"`
|
||||
Insecure bool `json:"insecure,omitempty"`
|
||||
ALPN []string `json:"alpn,omitempty"`
|
||||
MinVersion string `json:"min_version,omitempty"`
|
||||
MaxVersion string `json:"max_version,omitempty"`
|
||||
CipherSuites []string `json:"cipher_suites,omitempty"`
|
||||
Certificate []string `json:"certificate,omitempty"`
|
||||
CertificatePath string `json:"certificate_path,omitempty"`
|
||||
ECH *OutboundECHOptions `json:"ech,omitempty"`
|
||||
UTLS *OutboundUTLSOptions `json:"utls,omitempty"`
|
||||
Reality *OutboundRealityOptions `json:"reality,omitempty"`
|
||||
}
|
||||
|
||||
type OutboundECHOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
PQSignatureSchemesEnabled bool `json:"pq_signature_schemes_enabled,omitempty"`
|
||||
DynamicRecordSizingDisabled bool `json:"dynamic_record_sizing_disabled,omitempty"`
|
||||
Config []string `json:"config,omitempty"`
|
||||
ConfigPath string `json:"config_path,omitempty"`
|
||||
}
|
||||
|
||||
type OutboundUTLSOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Fingerprint string `json:"fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
type OutboundRealityOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
PublicKey string `json:"public_key,omitempty"`
|
||||
ShortID string `json:"short_id,omitempty"`
|
||||
}
|
||||
13
model/trojan.go
Normal file
13
model/trojan.go
Normal file
@@ -0,0 +1,13 @@
|
||||
package model
|
||||
|
||||
type Trojan struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
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"`
|
||||
}
|
||||
17
model/tuic.go
Normal file
17
model/tuic.go
Normal file
@@ -0,0 +1,17 @@
|
||||
package model
|
||||
|
||||
type TUIC struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
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 Duration `json:"heartbeat,omitempty"`
|
||||
Network string `json:"network,omitempty"`
|
||||
TLS *OutboundTLSOptions `json:"tls,omitempty"`
|
||||
}
|
||||
5
model/types.go
Normal file
5
model/types.go
Normal file
@@ -0,0 +1,5 @@
|
||||
package model
|
||||
|
||||
import "time"
|
||||
|
||||
type Duration time.Duration
|
||||
6
model/udp_over_tcp.go
Normal file
6
model/udp_over_tcp.go
Normal file
@@ -0,0 +1,6 @@
|
||||
package model
|
||||
|
||||
type UDPOverTCPOptions struct {
|
||||
Enabled bool `json:"enabled,omitempty"`
|
||||
Version uint8 `json:"version,omitempty"`
|
||||
}
|
||||
85
model/v2ray_transport.go
Normal file
85
model/v2ray_transport.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type V2RayTransportOptions struct {
|
||||
Type string `json:"type"`
|
||||
HTTPOptions V2RayHTTPOptions `json:"-"`
|
||||
WebsocketOptions V2RayWebsocketOptions `json:"-"`
|
||||
QUICOptions V2RayQUICOptions `json:"-"`
|
||||
GRPCOptions V2RayGRPCOptions `json:"-"`
|
||||
HTTPUpgradeOptions V2RayHTTPUpgradeOptions `json:"-"`
|
||||
}
|
||||
|
||||
func (o *V2RayTransportOptions) MarshalJSON() ([]byte, error) {
|
||||
switch o.Type {
|
||||
case "ws":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
*V2RayWebsocketOptions
|
||||
}{
|
||||
Type: o.Type,
|
||||
V2RayWebsocketOptions: &o.WebsocketOptions,
|
||||
})
|
||||
case "quic":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
*V2RayQUICOptions
|
||||
}{
|
||||
Type: o.Type,
|
||||
V2RayQUICOptions: &o.QUICOptions,
|
||||
})
|
||||
case "grpc":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
*V2RayGRPCOptions
|
||||
}{
|
||||
Type: o.Type,
|
||||
V2RayGRPCOptions: &o.GRPCOptions,
|
||||
})
|
||||
case "http":
|
||||
return json.Marshal(&struct {
|
||||
Type string `json:"type"`
|
||||
*V2RayHTTPOptions
|
||||
}{
|
||||
Type: o.Type,
|
||||
V2RayHTTPOptions: &o.HTTPOptions,
|
||||
})
|
||||
default:
|
||||
return json.Marshal(&struct{}{})
|
||||
}
|
||||
}
|
||||
|
||||
type V2RayHTTPOptions struct {
|
||||
Host []string `json:"host,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Method string `json:"method,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
IdleTimeout Duration `json:"idle_timeout,omitempty"`
|
||||
PingTimeout Duration `json:"ping_timeout,omitempty"`
|
||||
}
|
||||
|
||||
type V2RayWebsocketOptions struct {
|
||||
Path string `json:"path,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
MaxEarlyData uint32 `json:"max_early_data,omitempty"`
|
||||
EarlyDataHeaderName string `json:"early_data_header_name,omitempty"`
|
||||
}
|
||||
|
||||
type V2RayQUICOptions struct{}
|
||||
|
||||
type V2RayGRPCOptions struct {
|
||||
ServiceName string `json:"service_name,omitempty"`
|
||||
IdleTimeout Duration `json:"idle_timeout,omitempty"`
|
||||
PingTimeout Duration `json:"ping_timeout,omitempty"`
|
||||
PermitWithoutStream bool `json:"permit_without_stream,omitempty"`
|
||||
ForceLite bool `json:"-"` // for test
|
||||
}
|
||||
|
||||
type V2RayHTTPUpgradeOptions struct {
|
||||
Host string `json:"host,omitempty"`
|
||||
Path string `json:"path,omitempty"`
|
||||
Headers map[string]string `json:"headers,omitempty"`
|
||||
}
|
||||
15
model/vless.go
Normal file
15
model/vless.go
Normal file
@@ -0,0 +1,15 @@
|
||||
package model
|
||||
|
||||
type VLESS struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
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"`
|
||||
Multiplex *OutboundMultiplexOptions `json:"multiplex,omitempty"`
|
||||
Transport *V2RayTransportOptions `json:"transport,omitempty"`
|
||||
PacketEncoding *string `json:"packet_encoding,omitempty"`
|
||||
}
|
||||
36
model/vmess.go
Normal file
36
model/vmess.go
Normal file
@@ -0,0 +1,36 @@
|
||||
package model
|
||||
|
||||
type VmessJson struct {
|
||||
V string `json:"v"`
|
||||
Ps string `json:"ps"`
|
||||
Add string `json:"add"`
|
||||
Port interface{} `json:"port"`
|
||||
Id string `json:"id"`
|
||||
Aid interface{} `json:"aid"`
|
||||
Scy string `json:"scy"`
|
||||
Net string `json:"net"`
|
||||
Type string `json:"type"`
|
||||
Host string `json:"host"`
|
||||
Path string `json:"path"`
|
||||
Tls string `json:"tls"`
|
||||
Sni string `json:"sni"`
|
||||
Alpn string `json:"alpn"`
|
||||
Fp string `json:"fp"`
|
||||
}
|
||||
|
||||
type VMess struct {
|
||||
Type string `json:"type"`
|
||||
Tag string `json:"tag,omitempty"`
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user