mirror of
https://github.com/bestnite/sub2clash.git
synced 2025-06-17 20:53:18 +08:00
refactor
This commit is contained in:
51
model/proxy/anytls.go
Normal file
51
model/proxy/anytls.go
Normal file
@ -0,0 +1,51 @@
|
||||
package proxy
|
||||
|
||||
type Anytls struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
Alpn []string `yaml:"alpn,omitempty"`
|
||||
SNI string `yaml:"sni,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
IdleSessionCheckInterval int `yaml:"idle-session-check-interval,omitempty"`
|
||||
IdleSessionTimeout int `yaml:"idle-session-timeout,omitempty"`
|
||||
MinIdleSession int `yaml:"min-idle-session,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToAnytls(p Proxy) Anytls {
|
||||
return Anytls{
|
||||
Type: "anytls",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Password: p.Password,
|
||||
Alpn: p.Alpn,
|
||||
SNI: p.Sni,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
UDP: p.UDP,
|
||||
IdleSessionCheckInterval: p.IdleSessionCheckInterval,
|
||||
IdleSessionTimeout: p.IdleSessionTimeout,
|
||||
MinIdleSession: p.MinIdleSession,
|
||||
}
|
||||
}
|
||||
|
||||
type AnytlsMarshaler struct{}
|
||||
|
||||
func (m *AnytlsMarshaler) GetType() string {
|
||||
return "anytls"
|
||||
}
|
||||
|
||||
func (m *AnytlsMarshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToAnytls(p), nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
RegisterMarshaler(&AnytlsMarshaler{})
|
||||
}
|
68
model/proxy/hysteria.go
Normal file
68
model/proxy/hysteria.go
Normal file
@ -0,0 +1,68 @@
|
||||
package proxy
|
||||
|
||||
type Hysteria struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port,omitempty"`
|
||||
Ports string `yaml:"ports,omitempty"`
|
||||
Protocol string `yaml:"protocol,omitempty"`
|
||||
ObfsProtocol string `yaml:"obfs-protocol,omitempty"`
|
||||
Up string `yaml:"up"`
|
||||
UpSpeed int `yaml:"up-speed,omitempty"`
|
||||
Down string `yaml:"down"`
|
||||
DownSpeed int `yaml:"down-speed,omitempty"`
|
||||
Auth string `yaml:"auth,omitempty"`
|
||||
AuthStringOLD string `yaml:"auth_str,omitempty"`
|
||||
AuthString string `yaml:"auth-str,omitempty"`
|
||||
Obfs string `yaml:"obfs,omitempty"`
|
||||
SNI string `yaml:"sni,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
CustomCA string `yaml:"ca,omitempty"`
|
||||
CustomCAString string `yaml:"ca-str,omitempty"`
|
||||
ReceiveWindowConn int `yaml:"recv-window-conn,omitempty"`
|
||||
ReceiveWindow int `yaml:"recv-window,omitempty"`
|
||||
DisableMTUDiscovery bool `yaml:"disable-mtu-discovery,omitempty"`
|
||||
FastOpen bool `yaml:"fast-open,omitempty"`
|
||||
HopInterval int `yaml:"hop-interval,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToHysteria(p Proxy) Hysteria {
|
||||
return Hysteria{
|
||||
Type: "hysteria",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Ports: p.Ports,
|
||||
Protocol: p.Protocol,
|
||||
Up: p.Up,
|
||||
Down: p.Down,
|
||||
Auth: p.Auth,
|
||||
AuthStringOLD: p.AuthStringOLD,
|
||||
AuthString: p.AuthString,
|
||||
Obfs: p.Obfs,
|
||||
SNI: p.Sni,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
ALPN: p.Alpn,
|
||||
CustomCA: p.CustomCA,
|
||||
CustomCAString: p.CustomCAString,
|
||||
ReceiveWindowConn: p.ReceiveWindowConn,
|
||||
ReceiveWindow: p.ReceiveWindow,
|
||||
DisableMTUDiscovery: p.DisableMTUDiscovery,
|
||||
FastOpen: p.FastOpen,
|
||||
HopInterval: p.HopInterval,
|
||||
}
|
||||
}
|
||||
|
||||
type HysteriaMarshaler struct{}
|
||||
|
||||
func (m *HysteriaMarshaler) GetType() string {
|
||||
return "hysteria"
|
||||
}
|
||||
|
||||
func (m *HysteriaMarshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToHysteria(p), nil
|
||||
}
|
51
model/proxy/hysteria2.go
Normal file
51
model/proxy/hysteria2.go
Normal file
@ -0,0 +1,51 @@
|
||||
package proxy
|
||||
|
||||
type Hysteria2 struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Up string `yaml:"up,omitempty"`
|
||||
Down string `yaml:"down,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
Obfs string `yaml:"obfs,omitempty"`
|
||||
ObfsPassword string `yaml:"obfs-password,omitempty"`
|
||||
SNI string `yaml:"sni,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
CustomCA string `yaml:"ca,omitempty"`
|
||||
CustomCAString string `yaml:"ca-str,omitempty"`
|
||||
CWND int `yaml:"cwnd,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToHysteria2(p Proxy) Hysteria2 {
|
||||
return Hysteria2{
|
||||
Type: "hysteria2",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Up: p.Up,
|
||||
Down: p.Down,
|
||||
Password: p.Password,
|
||||
Obfs: p.Obfs,
|
||||
ObfsPassword: p.ObfsParam,
|
||||
SNI: p.Sni,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
ALPN: p.Alpn,
|
||||
CustomCA: p.CustomCA,
|
||||
CustomCAString: p.CustomCAString,
|
||||
CWND: p.CWND,
|
||||
}
|
||||
}
|
||||
|
||||
type Hysteria2Marshaler struct{}
|
||||
|
||||
func (m *Hysteria2Marshaler) GetType() string {
|
||||
return "hysteria2"
|
||||
}
|
||||
|
||||
func (m *Hysteria2Marshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToHysteria2(p), nil
|
||||
}
|
115
model/proxy/proxy.go
Normal file
115
model/proxy/proxy.go
Normal file
@ -0,0 +1,115 @@
|
||||
package proxy
|
||||
|
||||
type SmuxStruct struct {
|
||||
Enabled bool `yaml:"enable"`
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
Name string `yaml:"name,omitempty"`
|
||||
Server string `yaml:"server,omitempty"`
|
||||
Port int `yaml:"port,omitempty"`
|
||||
Type string `yaml:"type,omitempty"`
|
||||
Cipher string `yaml:"cipher,omitempty"`
|
||||
Username string `yaml:"username,omitempty"`
|
||||
Password string `yaml:"password,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
UUID string `yaml:"uuid,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
Flow string `yaml:"flow,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
Plugin string `yaml:"plugin,omitempty"`
|
||||
PluginOpts map[string]any `yaml:"plugin-opts,omitempty"`
|
||||
Smux SmuxStruct `yaml:"smux,omitempty"`
|
||||
Sni string `yaml:"sni,omitempty"`
|
||||
AllowInsecure bool `yaml:"allow-insecure,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Alpn []string `yaml:"alpn,omitempty"`
|
||||
XUDP bool `yaml:"xudp,omitempty"`
|
||||
Servername string `yaml:"servername,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
AlterID int `yaml:"alterId,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
Protocol string `yaml:"protocol,omitempty"`
|
||||
Obfs string `yaml:"obfs,omitempty"`
|
||||
ObfsParam string `yaml:"obfs-param,omitempty"`
|
||||
ProtocolParam string `yaml:"protocol-param,omitempty"`
|
||||
Remarks []string `yaml:"remarks,omitempty"`
|
||||
HTTPOpts HTTPOptions `yaml:"http-opts,omitempty"`
|
||||
HTTP2Opts HTTP2Options `yaml:"h2-opts,omitempty"`
|
||||
PacketAddr bool `yaml:"packet-addr,omitempty"`
|
||||
PacketEncoding string `yaml:"packet-encoding,omitempty"`
|
||||
GlobalPadding bool `yaml:"global-padding,omitempty"`
|
||||
AuthenticatedLength bool `yaml:"authenticated-length,omitempty"`
|
||||
UDPOverTCP bool `yaml:"udp-over-tcp,omitempty"`
|
||||
UDPOverTCPVersion int `yaml:"udp-over-tcp-version,omitempty"`
|
||||
SubName string `yaml:"-"`
|
||||
Up string `yaml:"up,omitempty"`
|
||||
Down string `yaml:"down,omitempty"`
|
||||
CustomCA string `yaml:"ca,omitempty"`
|
||||
CustomCAString string `yaml:"ca-str,omitempty"`
|
||||
CWND int `yaml:"cwnd,omitempty"`
|
||||
Auth string `yaml:"auth,omitempty"`
|
||||
ReceiveWindowConn int `yaml:"recv-window-conn,omitempty"`
|
||||
ReceiveWindow int `yaml:"recv-window,omitempty"`
|
||||
DisableMTUDiscovery bool `yaml:"disable-mtu-discovery,omitempty"`
|
||||
FastOpen bool `yaml:"fast-open,omitempty"`
|
||||
HopInterval int `yaml:"hop-interval,omitempty"`
|
||||
Ports string `yaml:"ports,omitempty"`
|
||||
AuthStringOLD string `yaml:"auth_str,omitempty"`
|
||||
AuthString string `yaml:"auth-str,omitempty"`
|
||||
Ip string `yaml:"ip,omitempty"`
|
||||
Ipv6 string `yaml:"ipv6,omitempty"`
|
||||
PrivateKey string `yaml:"private-key,omitempty"`
|
||||
Workers int `yaml:"workers,omitempty"`
|
||||
MTU int `yaml:"mtu,omitempty"`
|
||||
PersistentKeepalive int `yaml:"persistent-keepalive,omitempty"`
|
||||
Peers []WireGuardPeerOption `yaml:"peers,omitempty"`
|
||||
RemoteDnsResolve bool `yaml:"remote-dns-resolve,omitempty"`
|
||||
Dns []string `yaml:"dns,omitempty"`
|
||||
IdleSessionCheckInterval int `yaml:"idle-session-check-interval,omitempty"`
|
||||
IdleSessionTimeout int `yaml:"idle-session-timeout,omitempty"`
|
||||
MinIdleSession int `yaml:"min-idle-session,omitempty"`
|
||||
}
|
||||
|
||||
type WireGuardPeerOption struct {
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
PublicKey string `yaml:"public-key,omitempty"`
|
||||
PreSharedKey string `yaml:"pre-shared-key,omitempty"`
|
||||
Reserved []uint8 `yaml:"reserved,omitempty"`
|
||||
AllowedIPs []string `yaml:"allowed-ips,omitempty"`
|
||||
}
|
||||
|
||||
type _Proxy Proxy
|
||||
|
||||
func (p Proxy) MarshalYAML() (interface{}, error) {
|
||||
// 尝试使用注册的序列化器
|
||||
if marshaler, exists := GetMarshaler(p.Type); exists {
|
||||
return marshaler.MarshalProxy(p)
|
||||
}
|
||||
|
||||
// 保持向后兼容,对于未注册的类型使用原有逻辑
|
||||
switch p.Type {
|
||||
case "vmess":
|
||||
return ProxyToVmess(p), nil
|
||||
case "ss":
|
||||
return ProxyToShadowSocks(p), nil
|
||||
case "ssr":
|
||||
return ProxyToShadowSocksR(p), nil
|
||||
case "vless":
|
||||
return ProxyToVless(p), nil
|
||||
case "trojan":
|
||||
return ProxyToTrojan(p), nil
|
||||
case "hysteria":
|
||||
return ProxyToHysteria(p), nil
|
||||
case "hysteria2":
|
||||
return ProxyToHysteria2(p), nil
|
||||
case "anytls":
|
||||
return ProxyToAnytls(p), nil
|
||||
default:
|
||||
return _Proxy(p), nil
|
||||
}
|
||||
}
|
64
model/proxy/registry.go
Normal file
64
model/proxy/registry.go
Normal file
@ -0,0 +1,64 @@
|
||||
package proxy
|
||||
|
||||
import (
|
||||
"sync"
|
||||
)
|
||||
|
||||
// ProxyMarshaler 代理YAML序列化接口
|
||||
type ProxyMarshaler interface {
|
||||
// MarshalProxy 将通用Proxy对象序列化为特定协议的YAML结构
|
||||
MarshalProxy(p Proxy) (interface{}, error)
|
||||
// GetType 返回支持的协议类型
|
||||
GetType() string
|
||||
}
|
||||
|
||||
// marshalerRegistry YAML序列化器注册中心
|
||||
type marshalerRegistry struct {
|
||||
mu sync.RWMutex
|
||||
marshalers map[string]ProxyMarshaler // type -> marshaler
|
||||
}
|
||||
|
||||
var yamlRegistry = &marshalerRegistry{
|
||||
marshalers: make(map[string]ProxyMarshaler),
|
||||
}
|
||||
|
||||
// RegisterMarshaler 注册YAML序列化器
|
||||
func RegisterMarshaler(marshaler ProxyMarshaler) {
|
||||
yamlRegistry.mu.Lock()
|
||||
defer yamlRegistry.mu.Unlock()
|
||||
|
||||
yamlRegistry.marshalers[marshaler.GetType()] = marshaler
|
||||
}
|
||||
|
||||
// GetMarshaler 根据协议类型获取序列化器
|
||||
func GetMarshaler(proxyType string) (ProxyMarshaler, bool) {
|
||||
yamlRegistry.mu.RLock()
|
||||
defer yamlRegistry.mu.RUnlock()
|
||||
|
||||
marshaler, exists := yamlRegistry.marshalers[proxyType]
|
||||
return marshaler, exists
|
||||
}
|
||||
|
||||
// GetAllMarshalers 获取所有注册的序列化器
|
||||
func GetAllMarshalers() map[string]ProxyMarshaler {
|
||||
yamlRegistry.mu.RLock()
|
||||
defer yamlRegistry.mu.RUnlock()
|
||||
|
||||
result := make(map[string]ProxyMarshaler)
|
||||
for k, v := range yamlRegistry.marshalers {
|
||||
result[k] = v
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// GetSupportedTypes 获取所有支持的协议类型
|
||||
func GetSupportedTypes() []string {
|
||||
yamlRegistry.mu.RLock()
|
||||
defer yamlRegistry.mu.RUnlock()
|
||||
|
||||
types := make([]string, 0, len(yamlRegistry.marshalers))
|
||||
for proxyType := range yamlRegistry.marshalers {
|
||||
types = append(types, proxyType)
|
||||
}
|
||||
return types
|
||||
}
|
51
model/proxy/shadowsocks.go
Normal file
51
model/proxy/shadowsocks.go
Normal file
@ -0,0 +1,51 @@
|
||||
package proxy
|
||||
|
||||
type ShadowSocks struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
Cipher string `yaml:"cipher"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
Plugin string `yaml:"plugin,omitempty"`
|
||||
PluginOpts map[string]any `yaml:"plugin-opts,omitempty"`
|
||||
UDPOverTCP bool `yaml:"udp-over-tcp,omitempty"`
|
||||
UDPOverTCPVersion int `yaml:"udp-over-tcp-version,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToShadowSocks(p Proxy) ShadowSocks {
|
||||
return ShadowSocks{
|
||||
Type: "ss",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Password: p.Password,
|
||||
Cipher: p.Cipher,
|
||||
UDP: p.UDP,
|
||||
Plugin: p.Plugin,
|
||||
PluginOpts: p.PluginOpts,
|
||||
UDPOverTCP: p.UDPOverTCP,
|
||||
UDPOverTCPVersion: p.UDPOverTCPVersion,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
||||
|
||||
// ShadowsocksMarshaler Shadowsocks协议的YAML序列化器
|
||||
type ShadowsocksMarshaler struct{}
|
||||
|
||||
// GetType 返回协议类型
|
||||
func (m *ShadowsocksMarshaler) GetType() string {
|
||||
return "ss"
|
||||
}
|
||||
|
||||
// MarshalProxy 序列化Shadowsocks代理
|
||||
func (m *ShadowsocksMarshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToShadowSocks(p), nil
|
||||
}
|
||||
|
||||
// 注册序列化器
|
||||
func init() {
|
||||
RegisterMarshaler(&ShadowsocksMarshaler{})
|
||||
}
|
41
model/proxy/shadowsocksr.go
Normal file
41
model/proxy/shadowsocksr.go
Normal file
@ -0,0 +1,41 @@
|
||||
package proxy
|
||||
|
||||
type ShadowSocksR struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
Cipher string `yaml:"cipher"`
|
||||
Obfs string `yaml:"obfs"`
|
||||
ObfsParam string `yaml:"obfs-param,omitempty"`
|
||||
Protocol string `yaml:"protocol"`
|
||||
ProtocolParam string `yaml:"protocol-param,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToShadowSocksR(p Proxy) ShadowSocksR {
|
||||
return ShadowSocksR{
|
||||
Type: "ssr",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Password: p.Password,
|
||||
Cipher: p.Cipher,
|
||||
Obfs: p.Obfs,
|
||||
ObfsParam: p.ObfsParam,
|
||||
Protocol: p.Protocol,
|
||||
ProtocolParam: p.ProtocolParam,
|
||||
UDP: p.UDP,
|
||||
}
|
||||
}
|
||||
|
||||
type ShadowsocksRMarshaler struct{}
|
||||
|
||||
func (m *ShadowsocksRMarshaler) GetType() string {
|
||||
return "ssr"
|
||||
}
|
||||
|
||||
func (m *ShadowsocksRMarshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToShadowSocksR(p), nil
|
||||
}
|
49
model/proxy/trojan.go
Normal file
49
model/proxy/trojan.go
Normal file
@ -0,0 +1,49 @@
|
||||
package proxy
|
||||
|
||||
type Trojan struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
Password string `yaml:"password"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
SNI string `yaml:"sni,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToTrojan(p Proxy) Trojan {
|
||||
return Trojan{
|
||||
Type: "trojan",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
Password: p.Password,
|
||||
ALPN: p.Alpn,
|
||||
SNI: p.Sni,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
UDP: p.UDP,
|
||||
Network: p.Network,
|
||||
RealityOpts: p.RealityOpts,
|
||||
GrpcOpts: p.GrpcOpts,
|
||||
WSOpts: p.WSOpts,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
||||
|
||||
type TrojanMarshaler struct{}
|
||||
|
||||
func (m *TrojanMarshaler) GetType() string {
|
||||
return "trojan"
|
||||
}
|
||||
|
||||
func (m *TrojanMarshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToTrojan(p), nil
|
||||
}
|
67
model/proxy/vless.go
Normal file
67
model/proxy/vless.go
Normal file
@ -0,0 +1,67 @@
|
||||
package proxy
|
||||
|
||||
type Vless struct {
|
||||
Type string `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
UUID string `yaml:"uuid"`
|
||||
Flow string `yaml:"flow,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
PacketAddr bool `yaml:"packet-addr,omitempty"`
|
||||
XUDP bool `yaml:"xudp,omitempty"`
|
||||
PacketEncoding string `yaml:"packet-encoding,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
HTTPOpts HTTPOptions `yaml:"http-opts,omitempty"`
|
||||
HTTP2Opts HTTP2Options `yaml:"h2-opts,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
WSPath string `yaml:"ws-path,omitempty"`
|
||||
WSHeaders map[string]string `yaml:"ws-headers,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
ServerName string `yaml:"servername,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToVless(p Proxy) Vless {
|
||||
return Vless{
|
||||
Type: "vless",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
UUID: p.UUID,
|
||||
Flow: p.Flow,
|
||||
TLS: p.TLS,
|
||||
ALPN: p.Alpn,
|
||||
UDP: p.UDP,
|
||||
PacketAddr: p.PacketAddr,
|
||||
XUDP: p.XUDP,
|
||||
PacketEncoding: p.PacketEncoding,
|
||||
Network: p.Network,
|
||||
RealityOpts: p.RealityOpts,
|
||||
HTTPOpts: p.HTTPOpts,
|
||||
HTTP2Opts: p.HTTP2Opts,
|
||||
GrpcOpts: p.GrpcOpts,
|
||||
WSOpts: p.WSOpts,
|
||||
WSPath: p.WSOpts.Path,
|
||||
WSHeaders: p.WSOpts.Headers,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
ServerName: p.Servername,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
||||
|
||||
type VlessMarshaler struct{}
|
||||
|
||||
func (m *VlessMarshaler) GetType() string {
|
||||
return "vless"
|
||||
}
|
||||
|
||||
func (m *VlessMarshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToVless(p), nil
|
||||
}
|
114
model/proxy/vmess.go
Normal file
114
model/proxy/vmess.go
Normal file
@ -0,0 +1,114 @@
|
||||
package proxy
|
||||
|
||||
type HTTPOptions struct {
|
||||
Method string `yaml:"method,omitempty"`
|
||||
Path []string `yaml:"path,omitempty"`
|
||||
Headers map[string][]string `yaml:"headers,omitempty"`
|
||||
}
|
||||
|
||||
type HTTP2Options struct {
|
||||
Host []string `yaml:"host,omitempty"`
|
||||
Path string `yaml:"path,omitempty"`
|
||||
}
|
||||
|
||||
type GrpcOptions struct {
|
||||
GrpcServiceName string `yaml:"grpc-service-name,omitempty"`
|
||||
}
|
||||
|
||||
type RealityOptions struct {
|
||||
PublicKey string `yaml:"public-key"`
|
||||
ShortID string `yaml:"short-id,omitempty"`
|
||||
}
|
||||
|
||||
type WSOptions struct {
|
||||
Path string `yaml:"path,omitempty"`
|
||||
Headers map[string]string `yaml:"headers,omitempty"`
|
||||
MaxEarlyData int `yaml:"max-early-data,omitempty"`
|
||||
EarlyDataHeaderName string `yaml:"early-data-header-name,omitempty"`
|
||||
}
|
||||
|
||||
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 `yaml:"type"`
|
||||
Name string `yaml:"name"`
|
||||
Server string `yaml:"server"`
|
||||
Port int `yaml:"port"`
|
||||
UUID string `yaml:"uuid"`
|
||||
AlterID int `yaml:"alterId"`
|
||||
Cipher string `yaml:"cipher"`
|
||||
UDP bool `yaml:"udp,omitempty"`
|
||||
Network string `yaml:"network,omitempty"`
|
||||
TLS bool `yaml:"tls,omitempty"`
|
||||
ALPN []string `yaml:"alpn,omitempty"`
|
||||
SkipCertVerify bool `yaml:"skip-cert-verify,omitempty"`
|
||||
Fingerprint string `yaml:"fingerprint,omitempty"`
|
||||
ServerName string `yaml:"servername,omitempty"`
|
||||
RealityOpts RealityOptions `yaml:"reality-opts,omitempty"`
|
||||
HTTPOpts HTTPOptions `yaml:"http-opts,omitempty"`
|
||||
HTTP2Opts HTTP2Options `yaml:"h2-opts,omitempty"`
|
||||
GrpcOpts GrpcOptions `yaml:"grpc-opts,omitempty"`
|
||||
WSOpts WSOptions `yaml:"ws-opts,omitempty"`
|
||||
PacketAddr bool `yaml:"packet-addr,omitempty"`
|
||||
XUDP bool `yaml:"xudp,omitempty"`
|
||||
PacketEncoding string `yaml:"packet-encoding,omitempty"`
|
||||
GlobalPadding bool `yaml:"global-padding,omitempty"`
|
||||
AuthenticatedLength bool `yaml:"authenticated-length,omitempty"`
|
||||
ClientFingerprint string `yaml:"client-fingerprint,omitempty"`
|
||||
}
|
||||
|
||||
func ProxyToVmess(p Proxy) Vmess {
|
||||
return Vmess{
|
||||
Type: "vmess",
|
||||
Name: p.Name,
|
||||
Server: p.Server,
|
||||
Port: p.Port,
|
||||
UUID: p.UUID,
|
||||
AlterID: p.AlterID,
|
||||
Cipher: p.Cipher,
|
||||
UDP: p.UDP,
|
||||
Network: p.Network,
|
||||
TLS: p.TLS,
|
||||
ALPN: p.Alpn,
|
||||
SkipCertVerify: p.SkipCertVerify,
|
||||
Fingerprint: p.Fingerprint,
|
||||
ServerName: p.Servername,
|
||||
RealityOpts: p.RealityOpts,
|
||||
HTTPOpts: p.HTTPOpts,
|
||||
HTTP2Opts: p.HTTP2Opts,
|
||||
GrpcOpts: p.GrpcOpts,
|
||||
WSOpts: p.WSOpts,
|
||||
PacketAddr: p.PacketAddr,
|
||||
XUDP: p.XUDP,
|
||||
PacketEncoding: p.PacketEncoding,
|
||||
GlobalPadding: p.GlobalPadding,
|
||||
AuthenticatedLength: p.AuthenticatedLength,
|
||||
ClientFingerprint: p.ClientFingerprint,
|
||||
}
|
||||
}
|
||||
|
||||
type VmessMarshaler struct{}
|
||||
|
||||
func (m *VmessMarshaler) GetType() string {
|
||||
return "vmess"
|
||||
}
|
||||
|
||||
func (m *VmessMarshaler) MarshalProxy(p Proxy) (interface{}, error) {
|
||||
return ProxyToVmess(p), nil
|
||||
}
|
Reference in New Issue
Block a user