2023-09-10 20:18:33 +03:30
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import "C"
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
2024-01-29 21:55:01 +01:00
|
|
|
"fmt"
|
2023-09-10 20:18:33 +03:30
|
|
|
|
|
|
|
|
"github.com/hiddify/libcore/bridge"
|
2024-02-08 11:31:39 +01:00
|
|
|
"github.com/hiddify/libcore/config"
|
2023-09-10 20:18:33 +03:30
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var statusPropagationPort int64
|
|
|
|
|
var status = Stopped
|
|
|
|
|
|
|
|
|
|
type StatusMessage struct {
|
|
|
|
|
Status string `json:"status"`
|
|
|
|
|
Alert *string `json:"alert"`
|
|
|
|
|
Message *string `json:"message"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func propagateStatus(newStatus string) {
|
|
|
|
|
status = newStatus
|
|
|
|
|
|
|
|
|
|
msg, _ := json.Marshal(StatusMessage{Status: status})
|
|
|
|
|
bridge.SendStringToPort(statusPropagationPort, string(msg))
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-06 11:27:57 +01:00
|
|
|
func stopAndAlert(alert string, err error) (resultErr error) {
|
2024-02-14 15:49:47 +01:00
|
|
|
defer config.DeferPanicToError("stopAndAlert", func(err error) {
|
|
|
|
|
resultErr = err
|
|
|
|
|
})
|
|
|
|
|
status = Stopped
|
|
|
|
|
message := err.Error()
|
|
|
|
|
fmt.Printf("Error: %s: %s\n", alert, message)
|
|
|
|
|
msg, _ := json.Marshal(StatusMessage{Status: status, Alert: &alert, Message: &message})
|
|
|
|
|
bridge.SendStringToPort(statusPropagationPort, string(msg))
|
|
|
|
|
|
2024-02-08 11:31:39 +01:00
|
|
|
config.DeactivateTunnelService()
|
2024-02-13 16:52:58 +01:00
|
|
|
if commandServer != nil {
|
|
|
|
|
commandServer.SetService(nil)
|
|
|
|
|
}
|
|
|
|
|
if box != nil {
|
|
|
|
|
box.Close()
|
|
|
|
|
box = nil
|
|
|
|
|
}
|
|
|
|
|
if commandServer != nil {
|
|
|
|
|
commandServer.Close()
|
|
|
|
|
}
|
2023-09-22 23:25:38 +03:30
|
|
|
return nil
|
2023-09-10 20:18:33 +03:30
|
|
|
}
|