Merge pull request 'Makes backend infrastructure more stable, concurrent, and fault tolerant' (#6) from backend-runtime-stability-fixes into dev
Reviewed-on: #6
This commit is contained in:
commit
e456de9802
18 changed files with 424 additions and 177 deletions
|
@ -13,16 +13,14 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
// run arguments passed to docker
|
// run arguments passed to docker
|
||||||
"runArgs": [
|
"runArgs": ["--security-opt", "label=disable"],
|
||||||
"--security-opt", "label=disable"
|
|
||||||
],
|
|
||||||
|
|
||||||
"containerEnv": {
|
"containerEnv": {
|
||||||
// extensions to preload before other extensions
|
// extensions to preload before other extensions
|
||||||
"PRELOAD_EXTENSIONS": "arrterian.nix-env-selector"
|
"PRELOAD_EXTENSIONS": "arrterian.nix-env-selector"
|
||||||
},
|
},
|
||||||
|
|
||||||
// disable command overriding and updating remote user ID
|
// disable command overriding and updating remote user ID
|
||||||
"overrideCommand": false,
|
"overrideCommand": false,
|
||||||
"userEnvProbe": "loginShell",
|
"userEnvProbe": "loginShell",
|
||||||
"updateRemoteUserUID": false,
|
"updateRemoteUserUID": false,
|
||||||
|
@ -31,18 +29,14 @@
|
||||||
"onCreateCommand": "nix-shell --command 'echo done building nix dev environment'",
|
"onCreateCommand": "nix-shell --command 'echo done building nix dev environment'",
|
||||||
|
|
||||||
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
"forwardPorts": [
|
"forwardPorts": [8000],
|
||||||
3000
|
|
||||||
],
|
|
||||||
|
|
||||||
"customizations": {
|
"customizations": {
|
||||||
"vscode": {
|
"vscode": {
|
||||||
"extensions": [
|
"extensions": ["arrterian.nix-env-selector"]
|
||||||
"arrterian.nix-env-selector"
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Use 'postCreateCommand' to run commands after the container is created.
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
// "postCreateCommand": "go version",
|
// "postCreateCommand": "go version",
|
||||||
}
|
}
|
||||||
|
|
15
backend/api/backendruntime/core.go
Normal file
15
backend/api/backendruntime/core.go
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
package backendruntime
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
var (
|
||||||
|
AvailableBackends []*Backend
|
||||||
|
RunningBackends map[uint]*Runtime
|
||||||
|
TempDir string
|
||||||
|
isDevelopmentMode bool
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
RunningBackends = make(map[uint]*Runtime)
|
||||||
|
isDevelopmentMode = os.Getenv("HERMES_DEVELOPMENT_MODE") != ""
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.terah.dev/imterah/hermes/backend/backendlauncher"
|
"git.terah.dev/imterah/hermes/backend/backendlauncher"
|
||||||
|
@ -14,16 +15,6 @@ import (
|
||||||
"github.com/charmbracelet/log"
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
AvailableBackends []*Backend
|
|
||||||
RunningBackends map[uint]*Runtime
|
|
||||||
TempDir string
|
|
||||||
)
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
RunningBackends = make(map[uint]*Runtime)
|
|
||||||
}
|
|
||||||
|
|
||||||
func handleCommand(commandType string, command interface{}, sock net.Conn, rtcChan chan interface{}) error {
|
func handleCommand(commandType string, command interface{}, sock net.Conn, rtcChan chan interface{}) error {
|
||||||
bytes, err := commonbackend.Marshal(commandType, command)
|
bytes, err := commonbackend.Marshal(commandType, command)
|
||||||
|
|
||||||
|
@ -101,19 +92,20 @@ func (runtime *Runtime) goRoutineHandler() error {
|
||||||
} else {
|
} else {
|
||||||
log.Debug("We have restarted. Running the restart callback...")
|
log.Debug("We have restarted. Running the restart callback...")
|
||||||
runtime.OnCrashCallback(sock)
|
runtime.OnCrashCallback(sock)
|
||||||
log.Debug("Finished running the restart callback.")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.Debug("Clearing caches...")
|
||||||
|
runtime.cleanUpPendingCommandProcessingJobs()
|
||||||
|
runtime.messageBufferLock = sync.Mutex{}
|
||||||
} else {
|
} else {
|
||||||
log.Debug("We have not restarted.")
|
log.Debug("We have not restarted.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
log.Debugf("Setting up Hermes keepalive Goroutine")
|
log.Debug("Setting up Hermes keepalive Goroutine")
|
||||||
hasFailedBackendRunningCheckAlready := false
|
hasFailedBackendRunningCheckAlready := false
|
||||||
|
|
||||||
time.Sleep(time.Second * 1)
|
|
||||||
|
|
||||||
for {
|
for {
|
||||||
if !runtime.isRuntimeRunning {
|
if !runtime.isRuntimeRunning {
|
||||||
return
|
return
|
||||||
|
@ -125,21 +117,23 @@ func (runtime *Runtime) goRoutineHandler() error {
|
||||||
// To be safe here, we have to use the proper (yet annoying) facilities to prevent cross-talk, since we're in
|
// To be safe here, we have to use the proper (yet annoying) facilities to prevent cross-talk, since we're in
|
||||||
// a goroutine, and can't talk directly. This actually has benefits, as the OuterLoop should exit on its own, if we
|
// a goroutine, and can't talk directly. This actually has benefits, as the OuterLoop should exit on its own, if we
|
||||||
// encounter a critical error.
|
// encounter a critical error.
|
||||||
runtime.RuntimeCommands <- &commonbackend.BackendStatusRequest{
|
statusResponse, err := runtime.ProcessCommand(&commonbackend.BackendStatusRequest{
|
||||||
Type: "backendStatusRequest",
|
Type: "backendStatusRequest",
|
||||||
}
|
})
|
||||||
|
|
||||||
statusResponse := <-runtime.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend (in backend runtime keep alive): %s", err.Error())
|
||||||
switch responseMessage := statusResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend (in backend runtime keep alive): %s", responseMessage.Error())
|
|
||||||
log.Debugf("Attempting to close socket...")
|
log.Debugf("Attempting to close socket...")
|
||||||
err := sock.Close()
|
err := sock.Close()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Failed to close socket: %s", err.Error())
|
log.Debugf("Failed to close socket: %s", err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := statusResponse.(type) {
|
||||||
case *commonbackend.BackendStatusResponse:
|
case *commonbackend.BackendStatusResponse:
|
||||||
if !responseMessage.IsRunning {
|
if !responseMessage.IsRunning {
|
||||||
if hasFailedBackendRunningCheckAlready {
|
if hasFailedBackendRunningCheckAlready {
|
||||||
|
@ -162,118 +156,124 @@ func (runtime *Runtime) goRoutineHandler() error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(5)
|
time.Sleep(5 * time.Second)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
OuterLoop:
|
OuterLoop:
|
||||||
for {
|
for {
|
||||||
commandRaw := <-runtime.RuntimeCommands
|
for chanIndex, messageData := range runtime.messageBuffer {
|
||||||
|
if messageData == nil {
|
||||||
switch command := commandRaw.(type) {
|
continue
|
||||||
case *commonbackend.AddProxy:
|
|
||||||
err := handleCommand("addProxy", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
|
||||||
break OuterLoop
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
case *commonbackend.BackendStatusRequest:
|
|
||||||
err := handleCommand("backendStatusRequest", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
switch command := messageData.Message.(type) {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
case *commonbackend.AddProxy:
|
||||||
|
err := handleCommand("addProxy", command, sock, messageData.Channel)
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if err != nil {
|
||||||
break OuterLoop
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.BackendStatusRequest:
|
||||||
case *commonbackend.CheckClientParameters:
|
err := handleCommand("backendStatusRequest", command, sock, messageData.Channel)
|
||||||
err := handleCommand("checkClientParameters", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.CheckClientParameters:
|
||||||
case *commonbackend.CheckServerParameters:
|
err := handleCommand("checkClientParameters", command, sock, messageData.Channel)
|
||||||
err := handleCommand("checkServerParameters", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.CheckServerParameters:
|
||||||
case *commonbackend.ProxyConnectionsRequest:
|
err := handleCommand("checkServerParameters", command, sock, messageData.Channel)
|
||||||
err := handleCommand("proxyConnectionsRequest", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.ProxyConnectionsRequest:
|
||||||
case *commonbackend.ProxyInstanceRequest:
|
err := handleCommand("proxyConnectionsRequest", command, sock, messageData.Channel)
|
||||||
err := handleCommand("proxyInstanceRequest", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.ProxyInstanceRequest:
|
||||||
case *commonbackend.ProxyStatusRequest:
|
err := handleCommand("proxyInstanceRequest", command, sock, messageData.Channel)
|
||||||
err := handleCommand("proxyStatusRequest", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.ProxyStatusRequest:
|
||||||
case *commonbackend.RemoveProxy:
|
err := handleCommand("proxyStatusRequest", command, sock, messageData.Channel)
|
||||||
err := handleCommand("removeProxy", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.RemoveProxy:
|
||||||
case *commonbackend.Start:
|
err := handleCommand("removeProxy", command, sock, messageData.Channel)
|
||||||
err := handleCommand("start", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
case *commonbackend.Start:
|
||||||
case *commonbackend.Stop:
|
err := handleCommand("start", command, sock, messageData.Channel)
|
||||||
err := handleCommand("stop", command, sock, runtime.RuntimeCommands)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
if strings.HasPrefix(err.Error(), "failed to write message") {
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
break OuterLoop
|
break OuterLoop
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
case *commonbackend.Stop:
|
||||||
|
err := handleCommand("stop", command, sock, messageData.Channel)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Warnf("failed to handle command in backend runtime instance: %s", err.Error())
|
||||||
|
|
||||||
|
if strings.HasPrefix(err.Error(), "failed to write message") {
|
||||||
|
break OuterLoop
|
||||||
|
}
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Warnf("Recieved unknown command type from channel: %T", command)
|
||||||
|
messageData.Channel <- fmt.Errorf("unknown command recieved")
|
||||||
}
|
}
|
||||||
default:
|
|
||||||
log.Warnf("Recieved unknown command type from channel: %q", command)
|
runtime.messageBuffer[chanIndex] = nil
|
||||||
runtime.RuntimeCommands <- fmt.Errorf("unknown command recieved")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -330,7 +330,9 @@ func (runtime *Runtime) Start() error {
|
||||||
return fmt.Errorf("runtime already running")
|
return fmt.Errorf("runtime already running")
|
||||||
}
|
}
|
||||||
|
|
||||||
runtime.RuntimeCommands = make(chan interface{})
|
runtime.messageBuffer = make([]*messageForBuf, 10)
|
||||||
|
runtime.messageBufferLock = sync.Mutex{}
|
||||||
|
|
||||||
runtime.processRestartNotification = make(chan bool, 1)
|
runtime.processRestartNotification = make(chan bool, 1)
|
||||||
|
|
||||||
runtime.logger = &writeLogger{
|
runtime.logger = &writeLogger{
|
||||||
|
@ -379,6 +381,81 @@ func (runtime *Runtime) Stop() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (runtime *Runtime) ProcessCommand(command interface{}) (interface{}, error) {
|
||||||
|
schedulingAttempts := 0
|
||||||
|
var commandChannel chan interface{}
|
||||||
|
|
||||||
|
SchedulingLoop:
|
||||||
|
for {
|
||||||
|
if !runtime.isRuntimeRunning {
|
||||||
|
time.Sleep(10 * time.Millisecond)
|
||||||
|
}
|
||||||
|
|
||||||
|
if schedulingAttempts > 50 {
|
||||||
|
return nil, fmt.Errorf("failed to schedule message transmission after 50 tries (REPORT THIS ISSUE)")
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.messageBufferLock.Lock()
|
||||||
|
|
||||||
|
// Attempt to find spot in buffer to schedule message transmission
|
||||||
|
for i, message := range runtime.messageBuffer {
|
||||||
|
if message != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
commandChannel = make(chan interface{})
|
||||||
|
|
||||||
|
runtime.messageBuffer[i] = &messageForBuf{
|
||||||
|
Channel: commandChannel,
|
||||||
|
Message: command,
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.messageBufferLock.Unlock()
|
||||||
|
break SchedulingLoop
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.messageBufferLock.Unlock()
|
||||||
|
time.Sleep(100 * time.Millisecond)
|
||||||
|
|
||||||
|
schedulingAttempts++
|
||||||
|
}
|
||||||
|
|
||||||
|
// Fetch response and close Channel
|
||||||
|
response := <-commandChannel
|
||||||
|
close(commandChannel)
|
||||||
|
|
||||||
|
err, ok := response.(error)
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return response, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (runtime *Runtime) cleanUpPendingCommandProcessingJobs() {
|
||||||
|
for messageIndex, message := range runtime.messageBuffer {
|
||||||
|
if message == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
timeoutChannel := time.After(100 * time.Millisecond)
|
||||||
|
|
||||||
|
select {
|
||||||
|
case <-timeoutChannel:
|
||||||
|
log.Fatal("Message channel is likely running (timed out reading from it without an error)")
|
||||||
|
close(message.Channel)
|
||||||
|
case _, ok := <-message.Channel:
|
||||||
|
if ok {
|
||||||
|
log.Fatal("Message channel is running, but should be stopped (since message is NOT nil!)")
|
||||||
|
close(message.Channel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
runtime.messageBuffer[messageIndex] = nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func NewBackend(path string) *Runtime {
|
func NewBackend(path string) *Runtime {
|
||||||
return &Runtime{
|
return &Runtime{
|
||||||
ProcessPath: path,
|
ProcessPath: path,
|
||||||
|
|
|
@ -4,6 +4,9 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
|
|
||||||
|
"github.com/charmbracelet/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Backend struct {
|
type Backend struct {
|
||||||
|
@ -11,6 +14,11 @@ type Backend struct {
|
||||||
Path string `validate:"required"`
|
Path string `validate:"required"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type messageForBuf struct {
|
||||||
|
Channel chan interface{}
|
||||||
|
Message interface{}
|
||||||
|
}
|
||||||
|
|
||||||
type Runtime struct {
|
type Runtime struct {
|
||||||
isRuntimeRunning bool
|
isRuntimeRunning bool
|
||||||
logger *writeLogger
|
logger *writeLogger
|
||||||
|
@ -18,9 +26,11 @@ type Runtime struct {
|
||||||
currentListener net.Listener
|
currentListener net.Listener
|
||||||
processRestartNotification chan bool
|
processRestartNotification chan bool
|
||||||
|
|
||||||
ProcessPath string
|
messageBufferLock sync.Mutex
|
||||||
Logs []string
|
messageBuffer []*messageForBuf
|
||||||
RuntimeCommands chan interface{}
|
|
||||||
|
ProcessPath string
|
||||||
|
Logs []string
|
||||||
|
|
||||||
OnCrashCallback func(sock net.Conn)
|
OnCrashCallback func(sock net.Conn)
|
||||||
}
|
}
|
||||||
|
@ -31,6 +41,17 @@ type writeLogger struct {
|
||||||
|
|
||||||
func (writer writeLogger) Write(p []byte) (n int, err error) {
|
func (writer writeLogger) Write(p []byte) (n int, err error) {
|
||||||
logSplit := strings.Split(string(p), "\n")
|
logSplit := strings.Split(string(p), "\n")
|
||||||
|
|
||||||
|
if isDevelopmentMode {
|
||||||
|
for _, logLine := range logSplit {
|
||||||
|
if logLine == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Debug("spawned backend logs: " + logLine)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
writer.Runtime.Logs = append(writer.Runtime.Logs, logSplit...)
|
writer.Runtime.Logs = append(writer.Runtime.Logs, logSplit...)
|
||||||
|
|
||||||
return len(p), err
|
return len(p), err
|
||||||
|
|
|
@ -125,16 +125,13 @@ func CreateBackend(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.RuntimeCommands <- &commonbackend.CheckServerParameters{
|
backendParamCheckResponse, err := backend.ProcessCommand(&commonbackend.CheckServerParameters{
|
||||||
Type: "checkServerParameters",
|
Type: "checkServerParameters",
|
||||||
Arguments: backendParameters,
|
Arguments: backendParameters,
|
||||||
}
|
})
|
||||||
|
|
||||||
backendParamCheckResponse := <-backend.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend: %s", err.Error())
|
||||||
switch responseMessage := backendParamCheckResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend: %s", responseMessage.Error())
|
|
||||||
|
|
||||||
err = backend.Stop()
|
err = backend.Stop()
|
||||||
|
|
||||||
|
@ -147,6 +144,9 @@ func CreateBackend(c *gin.Context) {
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendParamCheckResponse.(type) {
|
||||||
case *commonbackend.CheckParametersResponse:
|
case *commonbackend.CheckParametersResponse:
|
||||||
if responseMessage.InResponseTo != "checkServerParameters" {
|
if responseMessage.InResponseTo != "checkServerParameters" {
|
||||||
log.Errorf("Got illegal response to CheckServerParameters: %s", responseMessage.InResponseTo)
|
log.Errorf("Got illegal response to CheckServerParameters: %s", responseMessage.InResponseTo)
|
||||||
|
@ -215,16 +215,13 @@ func CreateBackend(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.RuntimeCommands <- &commonbackend.Start{
|
backendStartResponse, err := backend.ProcessCommand(&commonbackend.Start{
|
||||||
Type: "start",
|
Type: "start",
|
||||||
Arguments: backendParameters,
|
Arguments: backendParameters,
|
||||||
}
|
})
|
||||||
|
|
||||||
backendStartResponse := <-backend.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend: %s", err.Error())
|
||||||
switch responseMessage := backendStartResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend: %s", responseMessage.Error())
|
|
||||||
|
|
||||||
err = backend.Stop()
|
err = backend.Stop()
|
||||||
|
|
||||||
|
@ -237,6 +234,9 @@ func CreateBackend(c *gin.Context) {
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendStartResponse.(type) {
|
||||||
case *commonbackend.BackendStatusResponse:
|
case *commonbackend.BackendStatusResponse:
|
||||||
if !responseMessage.IsRunning {
|
if !responseMessage.IsRunning {
|
||||||
err = backend.Stop()
|
err = backend.Stop()
|
||||||
|
|
|
@ -118,19 +118,21 @@ func GetConnections(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
backendRuntime.RuntimeCommands <- &commonbackend.ProxyConnectionsRequest{
|
backendResponse, err := backendRuntime.ProcessCommand(&commonbackend.ProxyConnectionsRequest{
|
||||||
Type: "proxyConnectionsRequest",
|
Type: "proxyConnectionsRequest",
|
||||||
}
|
})
|
||||||
|
|
||||||
backendResponse := <-backendRuntime.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend: %s", err.Error())
|
||||||
switch responseMessage := backendResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend: %s", responseMessage.Error())
|
|
||||||
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "Failed to get status response from backend",
|
"error": "Failed to get status response from backend",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendResponse.(type) {
|
||||||
case *commonbackend.ProxyConnectionsResponse:
|
case *commonbackend.ProxyConnectionsResponse:
|
||||||
sanitizedConnections := []*SanitizedConnection{}
|
sanitizedConnections := []*SanitizedConnection{}
|
||||||
|
|
||||||
|
|
|
@ -123,6 +123,8 @@ func CreateProxy(c *gin.Context) {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "Failed to add forward rule to database",
|
"error": "Failed to add forward rule to database",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
if autoStart {
|
if autoStart {
|
||||||
|
@ -139,25 +141,25 @@ func CreateProxy(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.RuntimeCommands <- &commonbackend.AddProxy{
|
backendResponse, err := backend.ProcessCommand(&commonbackend.AddProxy{
|
||||||
Type: "addProxy",
|
Type: "addProxy",
|
||||||
SourceIP: proxy.SourceIP,
|
SourceIP: proxy.SourceIP,
|
||||||
SourcePort: proxy.SourcePort,
|
SourcePort: proxy.SourcePort,
|
||||||
DestPort: proxy.DestinationPort,
|
DestPort: proxy.DestinationPort,
|
||||||
Protocol: proxy.Protocol,
|
Protocol: proxy.Protocol,
|
||||||
}
|
})
|
||||||
|
|
||||||
backendResponse := <-backend.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend #%d: %s", proxy.BackendID, err.Error())
|
||||||
switch responseMessage := backendResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend #%d: %s", proxy.BackendID, responseMessage.Error())
|
|
||||||
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "failed to get response from backend",
|
"error": "failed to get response from backend",
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendResponse.(type) {
|
||||||
case *commonbackend.ProxyStatusResponse:
|
case *commonbackend.ProxyStatusResponse:
|
||||||
if !responseMessage.IsActive {
|
if !responseMessage.IsActive {
|
||||||
log.Warnf("Failed to start proxy for backend #%d", proxy.BackendID)
|
log.Warnf("Failed to start proxy for backend #%d", proxy.BackendID)
|
||||||
|
|
|
@ -95,6 +95,8 @@ func LookupProxy(c *gin.Context) {
|
||||||
c.JSON(http.StatusBadRequest, gin.H{
|
c.JSON(http.StatusBadRequest, gin.H{
|
||||||
"error": "Protocol specified in body must either be 'tcp' or 'udp'",
|
"error": "Protocol specified in body must either be 'tcp' or 'udp'",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -110,25 +110,25 @@ func RemoveProxy(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.RuntimeCommands <- &commonbackend.RemoveProxy{
|
backendResponse, err := backend.ProcessCommand(&commonbackend.RemoveProxy{
|
||||||
Type: "removeProxy",
|
Type: "removeProxy",
|
||||||
SourceIP: proxy.SourceIP,
|
SourceIP: proxy.SourceIP,
|
||||||
SourcePort: proxy.SourcePort,
|
SourcePort: proxy.SourcePort,
|
||||||
DestPort: proxy.DestinationPort,
|
DestPort: proxy.DestinationPort,
|
||||||
Protocol: proxy.Protocol,
|
Protocol: proxy.Protocol,
|
||||||
}
|
})
|
||||||
|
|
||||||
backendResponse := <-backend.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend #%d: %s", proxy.BackendID, err.Error())
|
||||||
switch responseMessage := backendResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend #%d: %s", proxy.BackendID, responseMessage.Error())
|
|
||||||
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "Failed to get response from backend. Proxy was still successfully deleted",
|
"error": "Failed to get response from backend. Proxy was still successfully deleted",
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendResponse.(type) {
|
||||||
case *commonbackend.ProxyStatusResponse:
|
case *commonbackend.ProxyStatusResponse:
|
||||||
if responseMessage.IsActive {
|
if responseMessage.IsActive {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
|
|
@ -100,15 +100,13 @@ func StartProxy(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.RuntimeCommands <- &commonbackend.AddProxy{
|
backendResponse, err := backend.ProcessCommand(&commonbackend.AddProxy{
|
||||||
Type: "addProxy",
|
Type: "addProxy",
|
||||||
SourceIP: proxy.SourceIP,
|
SourceIP: proxy.SourceIP,
|
||||||
SourcePort: proxy.SourcePort,
|
SourcePort: proxy.SourcePort,
|
||||||
DestPort: proxy.DestinationPort,
|
DestPort: proxy.DestinationPort,
|
||||||
Protocol: proxy.Protocol,
|
Protocol: proxy.Protocol,
|
||||||
}
|
})
|
||||||
|
|
||||||
backendResponse := <-backend.RuntimeCommands
|
|
||||||
|
|
||||||
switch responseMessage := backendResponse.(type) {
|
switch responseMessage := backendResponse.(type) {
|
||||||
case error:
|
case error:
|
||||||
|
|
|
@ -100,25 +100,25 @@ func StopProxy(c *gin.Context) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
backend.RuntimeCommands <- &commonbackend.RemoveProxy{
|
backendResponse, err := backend.ProcessCommand(&commonbackend.RemoveProxy{
|
||||||
Type: "removeProxy",
|
Type: "removeProxy",
|
||||||
SourceIP: proxy.SourceIP,
|
SourceIP: proxy.SourceIP,
|
||||||
SourcePort: proxy.SourcePort,
|
SourcePort: proxy.SourcePort,
|
||||||
DestPort: proxy.DestinationPort,
|
DestPort: proxy.DestinationPort,
|
||||||
Protocol: proxy.Protocol,
|
Protocol: proxy.Protocol,
|
||||||
}
|
})
|
||||||
|
|
||||||
backendResponse := <-backend.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend #%d: %s", proxy.BackendID, err.Error())
|
||||||
switch responseMessage := backendResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend #%d: %s", proxy.BackendID, responseMessage.Error())
|
|
||||||
|
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
"error": "failed to get response from backend",
|
"error": "failed to get response from backend",
|
||||||
})
|
})
|
||||||
|
|
||||||
return
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendResponse.(type) {
|
||||||
case *commonbackend.ProxyStatusResponse:
|
case *commonbackend.ProxyStatusResponse:
|
||||||
if responseMessage.IsActive {
|
if responseMessage.IsActive {
|
||||||
c.JSON(http.StatusInternalServerError, gin.H{
|
c.JSON(http.StatusInternalServerError, gin.H{
|
||||||
|
|
|
@ -4,6 +4,7 @@ import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
@ -98,6 +99,96 @@ func apiEntrypoint(cCtx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
backendInstance := backendruntime.NewBackend(backendRuntimeFilePath)
|
backendInstance := backendruntime.NewBackend(backendRuntimeFilePath)
|
||||||
|
|
||||||
|
backendInstance.OnCrashCallback = func(conn net.Conn) {
|
||||||
|
backendParameters, err := base64.StdEncoding.DecodeString(backend.BackendParameters)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to decode backend parameters for backend #%d: %s", backend.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
marshalledStartCommand, err := commonbackend.Marshal("start", &commonbackend.Start{
|
||||||
|
Type: "start",
|
||||||
|
Arguments: backendParameters,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to marshal start command for backend #%d: %s", backend.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := conn.Write(marshalledStartCommand); err != nil {
|
||||||
|
log.Errorf("Failed to send start command for backend #%d: %s", backend.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
_, backendResponse, err := commonbackend.Unmarshal(conn)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to get start command response for backend #%d: %s", backend.ID, err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendResponse.(type) {
|
||||||
|
case *commonbackend.BackendStatusResponse:
|
||||||
|
if !responseMessage.IsRunning {
|
||||||
|
log.Errorf("Failed to start backend #%d: %s", backend.ID, responseMessage.Message)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Infof("Backend #%d has been reinitialized successfully", backend.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Warnf("Backend #%d has reinitialized! Starting up auto-starting proxies...", backend.ID)
|
||||||
|
|
||||||
|
autoStartProxies := []dbcore.Proxy{}
|
||||||
|
|
||||||
|
if err := dbcore.DB.Where("backend_id = ? AND auto_start = true", backend.ID).Find(&autoStartProxies).Error; err != nil {
|
||||||
|
log.Errorf("Failed to query proxies to autostart: %s", err.Error())
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, proxy := range autoStartProxies {
|
||||||
|
log.Infof("Starting up route #%d for backend #%d: %s", proxy.ID, backend.ID, proxy.Name)
|
||||||
|
|
||||||
|
marhalledCommand, err := commonbackend.Marshal("addProxy", &commonbackend.AddProxy{
|
||||||
|
Type: "addProxy",
|
||||||
|
SourceIP: proxy.SourceIP,
|
||||||
|
SourcePort: proxy.SourcePort,
|
||||||
|
DestPort: proxy.DestinationPort,
|
||||||
|
Protocol: proxy.Protocol,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to marshal proxy adding request for backend #%d and route #%d: %s", proxy.BackendID, proxy.ID, err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if _, err := conn.Write(marhalledCommand); err != nil {
|
||||||
|
log.Errorf("Failed to send proxy adding request for backend #%d and route #%d: %s", proxy.BackendID, proxy.ID, err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, backendResponse, err := commonbackend.Unmarshal(conn)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to get response for backend #%d and route #%d: %s", proxy.BackendID, proxy.ID, err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendResponse.(type) {
|
||||||
|
case *commonbackend.ProxyStatusResponse:
|
||||||
|
if !responseMessage.IsActive {
|
||||||
|
log.Warnf("Failed to start proxy for backend #%d and route #%d", proxy.BackendID, proxy.ID)
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
log.Errorf("Got illegal response type for backend #%d and proxy #%d: %T", proxy.BackendID, proxy.ID, responseMessage)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
err = backendInstance.Start()
|
err = backendInstance.Start()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -112,16 +203,13 @@ func apiEntrypoint(cCtx *cli.Context) error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
backendInstance.RuntimeCommands <- &commonbackend.Start{
|
backendStartResponse, err := backendInstance.ProcessCommand(&commonbackend.Start{
|
||||||
Type: "start",
|
Type: "start",
|
||||||
Arguments: backendParameters,
|
Arguments: backendParameters,
|
||||||
}
|
})
|
||||||
|
|
||||||
backendStartResponse := <-backendInstance.RuntimeCommands
|
if err != nil {
|
||||||
|
log.Warnf("Failed to get response for backend #%d: %s", backend.ID, err.Error())
|
||||||
switch responseMessage := backendStartResponse.(type) {
|
|
||||||
case error:
|
|
||||||
log.Warnf("Failed to get response for backend #%d: %s", backend.ID, responseMessage.Error())
|
|
||||||
|
|
||||||
err = backendInstance.Stop()
|
err = backendInstance.Stop()
|
||||||
|
|
||||||
|
@ -130,6 +218,9 @@ func apiEntrypoint(cCtx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
continue
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
switch responseMessage := backendStartResponse.(type) {
|
||||||
case *commonbackend.BackendStatusResponse:
|
case *commonbackend.BackendStatusResponse:
|
||||||
if !responseMessage.IsRunning {
|
if !responseMessage.IsRunning {
|
||||||
err = backendInstance.Stop()
|
err = backendInstance.Stop()
|
||||||
|
@ -165,20 +256,20 @@ func apiEntrypoint(cCtx *cli.Context) error {
|
||||||
for _, proxy := range autoStartProxies {
|
for _, proxy := range autoStartProxies {
|
||||||
log.Infof("Starting up route #%d for backend #%d: %s", proxy.ID, backend.ID, proxy.Name)
|
log.Infof("Starting up route #%d for backend #%d: %s", proxy.ID, backend.ID, proxy.Name)
|
||||||
|
|
||||||
backendInstance.RuntimeCommands <- &commonbackend.AddProxy{
|
backendResponse, err := backendInstance.ProcessCommand(&commonbackend.AddProxy{
|
||||||
Type: "addProxy",
|
Type: "addProxy",
|
||||||
SourceIP: proxy.SourceIP,
|
SourceIP: proxy.SourceIP,
|
||||||
SourcePort: proxy.SourcePort,
|
SourcePort: proxy.SourcePort,
|
||||||
DestPort: proxy.DestinationPort,
|
DestPort: proxy.DestinationPort,
|
||||||
Protocol: proxy.Protocol,
|
Protocol: proxy.Protocol,
|
||||||
|
})
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("Failed to get response for backend #%d and route #%d: %s", proxy.BackendID, proxy.ID, err.Error())
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
backendResponse := <-backendInstance.RuntimeCommands
|
|
||||||
|
|
||||||
switch responseMessage := backendResponse.(type) {
|
switch responseMessage := backendResponse.(type) {
|
||||||
case error:
|
|
||||||
log.Errorf("Failed to get response for backend #%d and route #%d: %s", proxy.BackendID, proxy.ID, responseMessage.Error())
|
|
||||||
continue
|
|
||||||
case *commonbackend.ProxyStatusResponse:
|
case *commonbackend.ProxyStatusResponse:
|
||||||
if !responseMessage.IsActive {
|
if !responseMessage.IsActive {
|
||||||
log.Warnf("Failed to start proxy for backend #%d and route #%d", proxy.BackendID, proxy.ID)
|
log.Warnf("Failed to start proxy for backend #%d and route #%d", proxy.BackendID, proxy.ID)
|
||||||
|
|
|
@ -72,6 +72,42 @@ func (helper *BackendApplicationHelper) Start() error {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
helper.socket.Write(responseMarshalled)
|
||||||
|
case "backendStatusRequest":
|
||||||
|
_, ok := commandRaw.(*commonbackend.BackendStatusRequest)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("failed to typecast")
|
||||||
|
}
|
||||||
|
|
||||||
|
ok, err := helper.Backend.GetBackendStatus()
|
||||||
|
|
||||||
|
var (
|
||||||
|
message string
|
||||||
|
statusCode int
|
||||||
|
)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
message = err.Error()
|
||||||
|
statusCode = commonbackend.StatusFailure
|
||||||
|
} else {
|
||||||
|
statusCode = commonbackend.StatusSuccess
|
||||||
|
}
|
||||||
|
|
||||||
|
response := &commonbackend.BackendStatusResponse{
|
||||||
|
Type: "backendStatusResponse",
|
||||||
|
IsRunning: ok,
|
||||||
|
StatusCode: statusCode,
|
||||||
|
Message: message,
|
||||||
|
}
|
||||||
|
|
||||||
|
responseMarshalled, err := commonbackend.Marshal(response.Type, response)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Error("failed to marshal response: %s", err.Error())
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
helper.socket.Write(responseMarshalled)
|
helper.socket.Write(responseMarshalled)
|
||||||
case "stop":
|
case "stop":
|
||||||
_, ok := commandRaw.(*commonbackend.Stop)
|
_, ok := commandRaw.(*commonbackend.Stop)
|
||||||
|
|
|
@ -5,6 +5,7 @@ import "git.terah.dev/imterah/hermes/backend/commonbackend"
|
||||||
type BackendInterface interface {
|
type BackendInterface interface {
|
||||||
StartBackend(arguments []byte) (bool, error)
|
StartBackend(arguments []byte) (bool, error)
|
||||||
StopBackend() (bool, error)
|
StopBackend() (bool, error)
|
||||||
|
GetBackendStatus() (bool, error)
|
||||||
StartProxy(command *commonbackend.AddProxy) (bool, error)
|
StartProxy(command *commonbackend.AddProxy) (bool, error)
|
||||||
StopProxy(command *commonbackend.RemoveProxy) (bool, error)
|
StopProxy(command *commonbackend.RemoveProxy) (bool, error)
|
||||||
GetAllClientConnections() []*commonbackend.ProxyClientConnection
|
GetAllClientConnections() []*commonbackend.ProxyClientConnection
|
||||||
|
|
|
@ -346,7 +346,7 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
|
||||||
return nil, fmt.Errorf("failed to typecast")
|
return nil, fmt.Errorf("failed to typecast")
|
||||||
}
|
}
|
||||||
|
|
||||||
statusRequestBytes := make([]byte, 2)
|
statusRequestBytes := make([]byte, 1)
|
||||||
statusRequestBytes[0] = BackendStatusRequestID
|
statusRequestBytes[0] = BackendStatusRequestID
|
||||||
|
|
||||||
return statusRequestBytes, nil
|
return statusRequestBytes, nil
|
||||||
|
|
|
@ -19,6 +19,10 @@ func (backend *DummyBackend) StopBackend() (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (backend *DummyBackend) GetBackendStatus() (bool, error) {
|
||||||
|
return true, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (backend *DummyBackend) StartProxy(command *commonbackend.AddProxy) (bool, error) {
|
func (backend *DummyBackend) StartProxy(command *commonbackend.AddProxy) (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -96,6 +96,10 @@ func (backend *SSHBackend) StopBackend() (bool, error) {
|
||||||
return true, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (backend *SSHBackend) GetBackendStatus() (bool, error) {
|
||||||
|
return backend.conn != nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (backend *SSHBackend) StartProxy(command *commonbackend.AddProxy) (bool, error) {
|
func (backend *SSHBackend) StartProxy(command *commonbackend.AddProxy) (bool, error) {
|
||||||
listenerObject := &SSHListener{
|
listenerObject := &SSHListener{
|
||||||
SourceIP: command.SourceIP,
|
SourceIP: command.SourceIP,
|
||||||
|
|
|
@ -12,8 +12,8 @@ post {
|
||||||
|
|
||||||
body:json {
|
body:json {
|
||||||
{
|
{
|
||||||
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiMSJdLCJleHAiOjE3MzUwNzY0MTEsIm5iZiI6MTczNDk5MDAxMSwiaWF0IjoxNzM0OTkwMDExfQ.N9TLraX4peHt7FKv8tPcHuEzL0K7T2IBEw3piQS_4OY",
|
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhdWQiOlsiMSJdLCJleHAiOjE3MzYyMzI2NjEsIm5iZiI6MTczNjE0NjI2MSwiaWF0IjoxNzM2MTQ2MjYxfQ.juoZ74xs-FBnbbT9Zlei1LmcNx7kTEfzymHlVbeMmtQ",
|
||||||
"name": "SSH",
|
"name": "SSH",
|
||||||
"id": 2
|
"id": 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue