2023-08-28 13:08:43 +03:30
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "github.com/sagernet/sing-box/experimental/libbox"
|
|
|
|
|
|
|
|
|
|
var (
|
2023-10-23 19:22:37 +03:30
|
|
|
statusClient *libbox.CommandClient
|
|
|
|
|
groupClient *libbox.CommandClient
|
2023-08-28 13:08:43 +03:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func StartCommand(command int32, port int64) error {
|
|
|
|
|
switch command {
|
|
|
|
|
case libbox.CommandStatus:
|
2023-10-23 19:22:37 +03:30
|
|
|
statusClient = libbox.NewCommandClient(
|
|
|
|
|
&CommandClientHandler{port: port, name: "status"},
|
2023-08-28 13:08:43 +03:30
|
|
|
&libbox.CommandClientOptions{
|
|
|
|
|
Command: libbox.CommandStatus,
|
|
|
|
|
StatusInterval: 1000000000,
|
|
|
|
|
},
|
|
|
|
|
)
|
2023-10-23 19:22:37 +03:30
|
|
|
return statusClient.Connect()
|
2023-08-29 19:10:14 +03:30
|
|
|
case libbox.CommandGroup:
|
2023-10-23 19:22:37 +03:30
|
|
|
groupClient = libbox.NewCommandClient(
|
|
|
|
|
&CommandClientHandler{port: port, name: "group"},
|
2023-08-29 19:10:14 +03:30
|
|
|
&libbox.CommandClientOptions{
|
|
|
|
|
Command: libbox.CommandGroup,
|
|
|
|
|
StatusInterval: 1000000000,
|
|
|
|
|
},
|
|
|
|
|
)
|
2023-10-23 19:22:37 +03:30
|
|
|
return groupClient.Connect()
|
2023-08-28 13:08:43 +03:30
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func StopCommand(command int32) error {
|
|
|
|
|
switch command {
|
|
|
|
|
case libbox.CommandStatus:
|
2023-10-23 19:22:37 +03:30
|
|
|
err := statusClient.Disconnect()
|
|
|
|
|
statusClient = nil
|
2023-08-28 13:08:43 +03:30
|
|
|
return err
|
2023-08-29 19:10:14 +03:30
|
|
|
case libbox.CommandGroup:
|
2023-10-23 19:22:37 +03:30
|
|
|
err := groupClient.Disconnect()
|
|
|
|
|
groupClient = nil
|
2023-08-29 19:10:14 +03:30
|
|
|
return err
|
2023-08-28 13:08:43 +03:30
|
|
|
}
|
|
|
|
|
return nil
|
|
|
|
|
}
|