[feature] using xray api and more

Improve DB performance
[api] backward compatibility: add client by update

Co-Authored-By: Alireza Ahmadi <alireza7@gmail.com>
This commit is contained in:
MHSanaei
2023-06-05 00:32:19 +03:30
parent 1030bcf321
commit 70f250dfe1
8 changed files with 533 additions and 178 deletions

View File

@@ -18,6 +18,7 @@ var result string
type XrayService struct {
inboundService InboundService
settingService SettingService
xrayAPI xray.XrayAPI
}
func (s *XrayService) IsXrayRunning() bool {
@@ -143,7 +144,9 @@ func (s *XrayService) GetXrayTraffic() ([]*xray.Traffic, []*xray.ClientTraffic,
if !s.IsXrayRunning() {
return nil, nil, errors.New("xray is not running")
}
return p.GetTraffic(true)
s.xrayAPI.Init(p.GetAPIPort())
defer s.xrayAPI.Close()
return s.xrayAPI.GetTraffic(true)
}
func (s *XrayService) RestartXray(isForce bool) error {
@@ -158,7 +161,7 @@ func (s *XrayService) RestartXray(isForce bool) error {
if p != nil && p.IsRunning() {
if !isForce && p.GetConfig().Equals(xrayConfig) {
logger.Debug("not need to restart xray")
logger.Debug("It does not need to restart xray")
return nil
}
p.Stop()
@@ -166,7 +169,11 @@ func (s *XrayService) RestartXray(isForce bool) error {
p = xray.NewProcess(xrayConfig)
result = ""
return p.Start()
err = p.Start()
if err != nil {
return err
}
return nil
}
func (s *XrayService) StopXray() error {