chore: tuic-server support restful api patch
This commit is contained in:
parent
4b1d4a3e20
commit
01e382285d
3 changed files with 63 additions and 6 deletions
|
@ -124,6 +124,7 @@ func GetGeneral() *config.General {
|
||||||
IPv6: !resolver.DisableIPv6,
|
IPv6: !resolver.DisableIPv6,
|
||||||
GeodataLoader: G.LoaderName(),
|
GeodataLoader: G.LoaderName(),
|
||||||
Tun: P.GetTunConf(),
|
Tun: P.GetTunConf(),
|
||||||
|
TuicServer: P.GetTuicConf(),
|
||||||
Interface: dialer.DefaultInterface.Load(),
|
Interface: dialer.DefaultInterface.Load(),
|
||||||
Sniffing: tunnel.IsSniffing(),
|
Sniffing: tunnel.IsSniffing(),
|
||||||
TCPConcurrent: dialer.GetDial(),
|
TCPConcurrent: dialer.GetDial(),
|
||||||
|
|
|
@ -41,7 +41,7 @@ type configSchema struct {
|
||||||
TProxyPort *int `json:"tproxy-port"`
|
TProxyPort *int `json:"tproxy-port"`
|
||||||
MixedPort *int `json:"mixed-port"`
|
MixedPort *int `json:"mixed-port"`
|
||||||
Tun *tunSchema `json:"tun"`
|
Tun *tunSchema `json:"tun"`
|
||||||
TuicServer *config.TuicServer `json:"tuic-server"`
|
TuicServer *tuicServerSchema `json:"tuic-server"`
|
||||||
ShadowSocksConfig *string `json:"ss-config"`
|
ShadowSocksConfig *string `json:"ss-config"`
|
||||||
VmessConfig *string `json:"vmess-config"`
|
VmessConfig *string `json:"vmess-config"`
|
||||||
TcptunConfig *string `json:"tcptun-config"`
|
TcptunConfig *string `json:"tcptun-config"`
|
||||||
|
@ -82,6 +82,19 @@ type tunSchema struct {
|
||||||
UDPTimeout *int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
|
UDPTimeout *int64 `yaml:"udp-timeout" json:"udp-timeout,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tuicServerSchema struct {
|
||||||
|
Enable bool `yaml:"enable" json:"enable"`
|
||||||
|
Listen *string `yaml:"listen" json:"listen"`
|
||||||
|
Token *[]string `yaml:"token" json:"token"`
|
||||||
|
Certificate *string `yaml:"certificate" json:"certificate"`
|
||||||
|
PrivateKey *string `yaml:"private-key" json:"private-key"`
|
||||||
|
CongestionController *string `yaml:"congestion-controller" json:"congestion-controller,omitempty"`
|
||||||
|
MaxIdleTime *int `yaml:"max-idle-time" json:"max-idle-time,omitempty"`
|
||||||
|
AuthenticationTimeout *int `yaml:"authentication-timeout" json:"authentication-timeout,omitempty"`
|
||||||
|
ALPN *[]string `yaml:"alpn" json:"alpn,omitempty"`
|
||||||
|
MaxUdpRelayPacketSize *int `yaml:"max-udp-relay-packet-size" json:"max-udp-relay-packet-size,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
func getConfigs(w http.ResponseWriter, r *http.Request) {
|
func getConfigs(w http.ResponseWriter, r *http.Request) {
|
||||||
general := executor.GetGeneral()
|
general := executor.GetGeneral()
|
||||||
render.JSON(w, r, general)
|
render.JSON(w, r, general)
|
||||||
|
@ -161,6 +174,40 @@ func pointerOrDefaultTun(p *tunSchema, def config.Tun) config.Tun {
|
||||||
return def
|
return def
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func pointerOrDefaultTuicServer(p *tuicServerSchema, def config.TuicServer) config.TuicServer {
|
||||||
|
if p != nil {
|
||||||
|
def.Enable = p.Enable
|
||||||
|
if p.Listen != nil {
|
||||||
|
def.Listen = *p.Listen
|
||||||
|
}
|
||||||
|
if p.Token != nil {
|
||||||
|
def.Token = *p.Token
|
||||||
|
}
|
||||||
|
if p.Certificate != nil {
|
||||||
|
def.Certificate = *p.Certificate
|
||||||
|
}
|
||||||
|
if p.PrivateKey != nil {
|
||||||
|
def.PrivateKey = *p.PrivateKey
|
||||||
|
}
|
||||||
|
if p.CongestionController != nil {
|
||||||
|
def.CongestionController = *p.CongestionController
|
||||||
|
}
|
||||||
|
if p.MaxIdleTime != nil {
|
||||||
|
def.MaxIdleTime = *p.MaxIdleTime
|
||||||
|
}
|
||||||
|
if p.AuthenticationTimeout != nil {
|
||||||
|
def.AuthenticationTimeout = *p.AuthenticationTimeout
|
||||||
|
}
|
||||||
|
if p.ALPN != nil {
|
||||||
|
def.ALPN = *p.ALPN
|
||||||
|
}
|
||||||
|
if p.MaxUdpRelayPacketSize != nil {
|
||||||
|
def.MaxUdpRelayPacketSize = *p.MaxUdpRelayPacketSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
|
||||||
func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
||||||
general := &configSchema{}
|
general := &configSchema{}
|
||||||
if err := render.DecodeJSON(r.Body, general); err != nil {
|
if err := render.DecodeJSON(r.Body, general); err != nil {
|
||||||
|
@ -204,9 +251,7 @@ func patchConfigs(w http.ResponseWriter, r *http.Request) {
|
||||||
P.ReCreateVmess(pointerOrDefaultString(general.VmessConfig, ports.VmessConfig), tcpIn, udpIn)
|
P.ReCreateVmess(pointerOrDefaultString(general.VmessConfig, ports.VmessConfig), tcpIn, udpIn)
|
||||||
P.ReCreateTcpTun(pointerOrDefaultString(general.TcptunConfig, ports.TcpTunConfig), tcpIn, udpIn)
|
P.ReCreateTcpTun(pointerOrDefaultString(general.TcptunConfig, ports.TcpTunConfig), tcpIn, udpIn)
|
||||||
P.ReCreateUdpTun(pointerOrDefaultString(general.UdptunConfig, ports.UdpTunConfig), tcpIn, udpIn)
|
P.ReCreateUdpTun(pointerOrDefaultString(general.UdptunConfig, ports.UdpTunConfig), tcpIn, udpIn)
|
||||||
if general.TuicServer != nil {
|
P.ReCreateTuic(pointerOrDefaultTuicServer(general.TuicServer, P.LastTuicConf), tcpIn, udpIn)
|
||||||
P.ReCreateTuic(*general.TuicServer, tcpIn, udpIn)
|
|
||||||
}
|
|
||||||
|
|
||||||
if general.Mode != nil {
|
if general.Mode != nil {
|
||||||
tunnel.SetMode(*general.Mode)
|
tunnel.SetMode(*general.Mode)
|
||||||
|
|
|
@ -64,7 +64,8 @@ var (
|
||||||
autoRedirMux sync.Mutex
|
autoRedirMux sync.Mutex
|
||||||
tcMux sync.Mutex
|
tcMux sync.Mutex
|
||||||
|
|
||||||
LastTunConf config.Tun
|
LastTunConf config.Tun
|
||||||
|
LastTuicConf config.TuicServer
|
||||||
)
|
)
|
||||||
|
|
||||||
type Ports struct {
|
type Ports struct {
|
||||||
|
@ -88,6 +89,13 @@ func GetTunConf() config.Tun {
|
||||||
return tunLister.Config()
|
return tunLister.Config()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func GetTuicConf() config.TuicServer {
|
||||||
|
if tuicListener == nil {
|
||||||
|
return config.TuicServer{Enable: false}
|
||||||
|
}
|
||||||
|
return tuicListener.Config()
|
||||||
|
}
|
||||||
|
|
||||||
func AllowLan() bool {
|
func AllowLan() bool {
|
||||||
return allowLan
|
return allowLan
|
||||||
}
|
}
|
||||||
|
@ -395,7 +403,10 @@ func ReCreateUdpTun(config string, tcpIn chan<- C.ConnContext, udpIn chan<- *inb
|
||||||
|
|
||||||
func ReCreateTuic(config config.TuicServer, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) {
|
func ReCreateTuic(config config.TuicServer, tcpIn chan<- C.ConnContext, udpIn chan<- *inbound.PacketAdapter) {
|
||||||
tuicMux.Lock()
|
tuicMux.Lock()
|
||||||
defer tuicMux.Unlock()
|
defer func() {
|
||||||
|
LastTuicConf = config
|
||||||
|
tuicMux.Unlock()
|
||||||
|
}()
|
||||||
shouldIgnore := false
|
shouldIgnore := false
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
Loading…
Reference in a new issue