chore: Rename structs to be more clear.

This commit is contained in:
greysoh 2024-12-02 16:38:41 -05:00
parent 0b6e40a944
commit b30d8150f3
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
9 changed files with 136 additions and 126 deletions

View file

@ -17,6 +17,9 @@ type BackendApplicationHelper struct {
}
func (helper *BackendApplicationHelper) Start() error {
log.Debug("BackendApplicationHelper is starting")
log.Debug("Currently waiting for Unix socket connection...")
var err error
helper.socket, err = net.Dial("unix", helper.SocketPath)
@ -24,6 +27,8 @@ func (helper *BackendApplicationHelper) Start() error {
return err
}
log.Debug("Sucessfully connected")
for {
commandType, commandRaw, err := commonbackend.Unmarshal(helper.socket)
@ -34,7 +39,7 @@ func (helper *BackendApplicationHelper) Start() error {
switch commandType {
case "start":
// TODO: implement response logic
command, ok := commandRaw.(*commonbackend.StartCommand)
command, ok := commandRaw.(*commonbackend.Start)
if !ok {
return fmt.Errorf("failed to typecast")
@ -44,33 +49,33 @@ func (helper *BackendApplicationHelper) Start() error {
_, _ = helper.Backend.StartBackend(command.Arguments)
case "stop":
// TODO: implement response logic
_, ok := commandRaw.(*commonbackend.StopCommand)
_, ok := commandRaw.(*commonbackend.Stop)
if !ok {
return fmt.Errorf("failed to typecast")
}
_, _ = helper.Backend.StopBackend()
case "addConnection":
case "addProxy":
// TODO: implement response logic
command, ok := commandRaw.(*commonbackend.AddConnectionCommand)
command, ok := commandRaw.(*commonbackend.AddProxy)
if !ok {
return fmt.Errorf("failed to typecast")
}
_, _ = helper.Backend.StartProxy(command)
case "removeConnection":
case "removeProxy":
// TODO: implement response logic
command, ok := commandRaw.(*commonbackend.RemoveConnectionCommand)
command, ok := commandRaw.(*commonbackend.RemoveProxy)
if !ok {
return fmt.Errorf("failed to typecast")
}
_, _ = helper.Backend.StopProxy(command)
case "getAllConnections":
_, ok := commandRaw.(*commonbackend.AddConnectionCommand)
case "proxyConnectionsRequest":
_, ok := commandRaw.(*commonbackend.ProxyConnectionsRequest)
if !ok {
return fmt.Errorf("failed to typecast")
@ -78,8 +83,8 @@ func (helper *BackendApplicationHelper) Start() error {
connections := helper.Backend.GetAllClientConnections()
serverParams := &commonbackend.ConnectionsResponse{
Type: "connectionsResponse",
serverParams := &commonbackend.ProxyConnectionsResponse{
Type: "proxyConnectionsResponse",
Connections: connections,
}

View file

@ -5,9 +5,9 @@ import "git.greysoh.dev/imterah/nextnet/commonbackend"
type BackendInterface interface {
StartBackend(arguments []byte) (bool, error)
StopBackend() (bool, error)
StartProxy(command *commonbackend.AddConnectionCommand) (bool, error)
StopProxy(command *commonbackend.RemoveConnectionCommand) (bool, error)
GetAllClientConnections() []*commonbackend.ClientConnection
StartProxy(command *commonbackend.AddProxy) (bool, error)
StopProxy(command *commonbackend.RemoveProxy) (bool, error)
GetAllClientConnections() []*commonbackend.ProxyClientConnection
CheckParametersForConnections(clientParameters *commonbackend.CheckClientParameters) *commonbackend.CheckParametersResponse
CheckParametersForBackend(arguments []byte) *commonbackend.CheckParametersResponse
}

View file

@ -3,25 +3,25 @@ package commonbackend
// TODO (imterah): Rename AddConnectionCommand/RemoveConnectionCommand to AddProxyCommand/RemoveProxyCommand
// and their associated function calls
type StartCommand struct {
type Start struct {
Type string // Will be 'start' always
Arguments []byte
}
type StopCommand struct {
type Stop struct {
Type string // Will be 'stop' always
}
type AddConnectionCommand struct {
Type string // Will be 'addConnection' always
type AddProxy struct {
Type string // Will be 'addProxy' always
SourceIP string
SourcePort uint16
DestPort uint16
Protocol string // Will be either 'tcp' or 'udp'
}
type RemoveConnectionCommand struct {
Type string // Will be 'removeConnection' always
type RemoveProxy struct {
Type string // Will be 'removeProxy' always
SourceIP string
SourcePort uint16
DestPort uint16
@ -45,25 +45,25 @@ type ProxyStatusResponse struct {
IsActive bool
}
type ProxyConnection struct {
type ProxyInstance struct {
SourceIP string
SourcePort uint16
DestPort uint16
Protocol string // Will be either 'tcp' or 'udp'
}
type ProxyConnectionResponse struct {
Type string // Will be 'proxyConnectionResponse' always
Proxies []*ProxyConnection // List of connections
type ProxyInstanceResponse struct {
Type string // Will be 'proxyConnectionResponse' always
Proxies []*ProxyInstance // List of connections
}
type ProxyConnectionRequest struct {
type ProxyInstanceRequest struct {
Type string // Will be 'proxyConnectionRequest' always
}
type BackendStatusResponse struct {
Type string // Will be 'backendStatusResponse' always
IsRunning bool // Can be either for 'start' or 'stop'
IsRunning bool // True if running, false if not running
StatusCode int // Either the 'Success' or 'Failure' constant
Message string // String message from the client (ex. failed to dial TCP)
}
@ -72,11 +72,12 @@ type BackendStatusRequest struct {
Type string // Will be 'backendStatusRequest' always
}
type GetAllConnectionsRequest struct {
Type string // Will be 'getAllConnectionsRequest' always
type ProxyConnectionsRequest struct {
Type string // Will be 'proxyConnectionsRequest' always
}
type ClientConnection struct {
// Client's connection to a specific proxy
type ProxyClientConnection struct {
SourceIP string
SourcePort uint16
DestPort uint16
@ -84,9 +85,9 @@ type ClientConnection struct {
ClientPort uint16
}
type ConnectionsResponse struct {
Type string // Will be 'connectionsResponse' always
Connections []*ClientConnection // List of connections
type ProxyConnectionsResponse struct {
Type string // Will be 'proxyConnectionsResponse' always
Connections []*ProxyClientConnection // List of connections
}
type CheckClientParameters struct {
@ -111,22 +112,21 @@ type CheckParametersResponse struct {
}
const (
StartCommandID = iota
StopCommandID
AddConnectionCommandID
RemoveConnectionCommandID
ClientConnectionID
GetAllConnectionsID
StartID = iota
StopID
AddProxyID
RemoveProxyID
ProxyConnectionsResponseID
CheckClientParametersID
CheckServerParametersID
CheckParametersResponseID
GetAllConnectionsRequestID
ProxyConnectionsRequestID
BackendStatusResponseID
BackendStatusRequestID
ProxyStatusRequestID
ProxyStatusResponseID
ProxyConnectionResponseID
ProxyConnectionRequestID
ProxyInstanceResponseID
ProxyInstanceRequestID
)
const (

View file

@ -6,7 +6,7 @@ import (
"net"
)
func marshalIndividualConnectionStruct(conn *ClientConnection) []byte {
func marshalIndividualConnectionStruct(conn *ProxyClientConnection) []byte {
sourceIPOriginal := net.ParseIP(conn.SourceIP)
clientIPOriginal := net.ParseIP(conn.ClientIP)
@ -47,7 +47,7 @@ func marshalIndividualConnectionStruct(conn *ClientConnection) []byte {
return connectionBlock
}
func marshalIndividualProxyStruct(conn *ProxyConnection) ([]byte, error) {
func marshalIndividualProxyStruct(conn *ProxyInstance) ([]byte, error) {
sourceIPOriginal := net.ParseIP(conn.SourceIP)
var sourceIPVer uint8
@ -87,28 +87,28 @@ func marshalIndividualProxyStruct(conn *ProxyConnection) ([]byte, error) {
func Marshal(commandType string, command interface{}) ([]byte, error) {
switch commandType {
case "start":
startCommand, ok := command.(*StartCommand)
startCommand, ok := command.(*Start)
if !ok {
return nil, fmt.Errorf("failed to typecast")
}
startCommandBytes := make([]byte, 1+2+len(startCommand.Arguments))
startCommandBytes[0] = StartCommandID
startCommandBytes[0] = StartID
binary.BigEndian.PutUint16(startCommandBytes[1:3], uint16(len(startCommand.Arguments)))
copy(startCommandBytes[3:], startCommand.Arguments)
return startCommandBytes, nil
case "stop":
_, ok := command.(*StopCommand)
_, ok := command.(*Stop)
if !ok {
return nil, fmt.Errorf("failed to typecast")
}
return []byte{StopCommandID}, nil
case "addConnection":
addConnectionCommand, ok := command.(*AddConnectionCommand)
return []byte{StopID}, nil
case "addProxy":
addConnectionCommand, ok := command.(*AddProxy)
if !ok {
return nil, fmt.Errorf("failed to typecast")
@ -129,7 +129,7 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
addConnectionBytes := make([]byte, 1+1+len(ipBytes)+2+2+1)
addConnectionBytes[0] = AddConnectionCommandID
addConnectionBytes[0] = AddProxyID
addConnectionBytes[1] = ipVer
copy(addConnectionBytes[2:2+len(ipBytes)], ipBytes)
@ -150,8 +150,8 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
addConnectionBytes[6+len(ipBytes)] = protocol
return addConnectionBytes, nil
case "removeConnection":
removeConnectionCommand, ok := command.(*RemoveConnectionCommand)
case "removeProxy":
removeConnectionCommand, ok := command.(*RemoveProxy)
if !ok {
return nil, fmt.Errorf("failed to typecast")
@ -172,7 +172,7 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
removeConnectionBytes := make([]byte, 1+1+len(ipBytes)+2+2+1)
removeConnectionBytes[0] = RemoveConnectionCommandID
removeConnectionBytes[0] = RemoveProxyID
removeConnectionBytes[1] = ipVer
copy(removeConnectionBytes[2:2+len(ipBytes)], ipBytes)
binary.BigEndian.PutUint16(removeConnectionBytes[2+len(ipBytes):4+len(ipBytes)], removeConnectionCommand.SourcePort)
@ -191,8 +191,8 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
removeConnectionBytes[6+len(ipBytes)] = protocol
return removeConnectionBytes, nil
case "connectionsResponse":
allConnectionsCommand, ok := command.(*ConnectionsResponse)
case "proxyConnectionsResponse":
allConnectionsCommand, ok := command.(*ProxyConnectionsResponse)
if !ok {
return nil, fmt.Errorf("failed to typecast")
@ -207,7 +207,7 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
}
connectionCommandArray := make([]byte, totalSize+1)
connectionCommandArray[0] = GetAllConnectionsID
connectionCommandArray[0] = ProxyConnectionsResponseID
currentPosition := 1
@ -442,8 +442,8 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
proxyStatusResponseBytes[7+len(ipBytes)] = isActive
return proxyStatusResponseBytes, nil
case "proxyConnectionResponse":
proxyConectionResponse, ok := command.(*ProxyConnectionResponse)
case "proxyInstanceResponse":
proxyConectionResponse, ok := command.(*ProxyInstanceResponse)
if !ok {
return nil, fmt.Errorf("failed to typecast")
@ -464,7 +464,7 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
}
connectionCommandArray := make([]byte, totalSize+1)
connectionCommandArray[0] = ProxyConnectionResponseID
connectionCommandArray[0] = ProxyInstanceResponseID
currentPosition := 1
@ -476,23 +476,23 @@ func Marshal(commandType string, command interface{}) ([]byte, error) {
connectionCommandArray[totalSize] = '\n'
return connectionCommandArray, nil
case "proxyConnectionRequest":
_, ok := command.(*ProxyConnectionRequest)
case "proxyInstanceRequest":
_, ok := command.(*ProxyInstanceRequest)
if !ok {
return nil, fmt.Errorf("failed to typecast")
}
return []byte{ProxyConnectionRequestID}, nil
case "getAllConnectionsRequest":
_, ok := command.(*GetAllConnectionsRequest)
return []byte{ProxyInstanceRequestID}, nil
case "proxyConnectionsRequest":
_, ok := command.(*ProxyConnectionsRequest)
if !ok {
return nil, fmt.Errorf("failed to typecast")
}
return []byte{GetAllConnectionsRequestID}, nil
return []byte{ProxyConnectionsRequestID}, nil
}
return nil, fmt.Errorf("couldn't match command")
return nil, fmt.Errorf("couldn't match command name")
}

View file

@ -10,7 +10,7 @@ import (
var logLevel = os.Getenv("NEXTNET_LOG_LEVEL")
func TestStartCommandMarshalSupport(t *testing.T) {
commandInput := &StartCommand{
commandInput := &Start{
Type: "start",
Arguments: []byte("Hello from automated testing"),
}
@ -37,7 +37,7 @@ func TestStartCommandMarshalSupport(t *testing.T) {
log.Print("command type does not match up!")
}
commandUnmarshalled, ok := commandUnmarshalledRaw.(*StartCommand)
commandUnmarshalled, ok := commandUnmarshalledRaw.(*Start)
if !ok {
t.Fatal("failed typecast")
@ -54,7 +54,7 @@ func TestStartCommandMarshalSupport(t *testing.T) {
}
func TestStopCommandMarshalSupport(t *testing.T) {
commandInput := &StopCommand{
commandInput := &Stop{
Type: "stop",
}
@ -80,7 +80,7 @@ func TestStopCommandMarshalSupport(t *testing.T) {
log.Print("command type does not match up!")
}
commandUnmarshalled, ok := commandUnmarshalledRaw.(*StopCommand)
commandUnmarshalled, ok := commandUnmarshalledRaw.(*Stop)
if !ok {
t.Fatal("failed typecast")
@ -93,8 +93,8 @@ func TestStopCommandMarshalSupport(t *testing.T) {
}
func TestAddConnectionCommandMarshalSupport(t *testing.T) {
commandInput := &AddConnectionCommand{
Type: "addConnection",
commandInput := &AddProxy{
Type: "addProxy",
SourceIP: "192.168.0.139",
SourcePort: 19132,
DestPort: 19132,
@ -123,7 +123,7 @@ func TestAddConnectionCommandMarshalSupport(t *testing.T) {
log.Print("command type does not match up!")
}
commandUnmarshalled, ok := commandUnmarshalledRaw.(*AddConnectionCommand)
commandUnmarshalled, ok := commandUnmarshalledRaw.(*AddProxy)
if !ok {
t.Fatal("failed typecast")
@ -156,8 +156,8 @@ func TestAddConnectionCommandMarshalSupport(t *testing.T) {
}
func TestRemoveConnectionCommandMarshalSupport(t *testing.T) {
commandInput := &RemoveConnectionCommand{
Type: "removeConnection",
commandInput := &RemoveProxy{
Type: "removeProxy",
SourceIP: "192.168.0.139",
SourcePort: 19132,
DestPort: 19132,
@ -186,7 +186,7 @@ func TestRemoveConnectionCommandMarshalSupport(t *testing.T) {
log.Print("command type does not match up!")
}
commandUnmarshalled, ok := commandUnmarshalledRaw.(*RemoveConnectionCommand)
commandUnmarshalled, ok := commandUnmarshalledRaw.(*RemoveProxy)
if !ok {
t.Fatal("failed typecast")
@ -219,9 +219,9 @@ func TestRemoveConnectionCommandMarshalSupport(t *testing.T) {
}
func TestGetAllConnectionsCommandMarshalSupport(t *testing.T) {
commandInput := &ConnectionsResponse{
Type: "connectionsResponse",
Connections: []*ClientConnection{
commandInput := &ProxyConnectionsResponse{
Type: "proxyConnectionsResponse",
Connections: []*ProxyClientConnection{
{
SourceIP: "127.0.0.1",
SourcePort: 19132,
@ -268,7 +268,7 @@ func TestGetAllConnectionsCommandMarshalSupport(t *testing.T) {
log.Print("command type does not match up!")
}
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ConnectionsResponse)
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionsResponse)
if !ok {
t.Fatal("failed typecast")
@ -702,8 +702,8 @@ func TestProxyStatusResponseMarshalSupport(t *testing.T) {
}
func TestProxyConnectionRequestMarshalSupport(t *testing.T) {
commandInput := &ProxyConnectionRequest{
Type: "proxyConnectionRequest",
commandInput := &ProxyInstanceRequest{
Type: "proxyInstanceRequest",
}
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
@ -728,7 +728,7 @@ func TestProxyConnectionRequestMarshalSupport(t *testing.T) {
log.Print("command type does not match up!")
}
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionRequest)
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyInstanceRequest)
if !ok {
t.Fatal("failed typecast")
@ -741,9 +741,9 @@ func TestProxyConnectionRequestMarshalSupport(t *testing.T) {
}
func TestProxyConnectionResponseMarshalSupport(t *testing.T) {
commandInput := &ProxyConnectionResponse{
Type: "proxyConnectionResponse",
Proxies: []*ProxyConnection{
commandInput := &ProxyInstanceResponse{
Type: "proxyInstanceResponse",
Proxies: []*ProxyInstance{
{
SourceIP: "192.168.0.168",
SourcePort: 25565,
@ -787,7 +787,7 @@ func TestProxyConnectionResponseMarshalSupport(t *testing.T) {
log.Print("command type does not match up!")
}
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionResponse)
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyInstanceResponse)
if !ok {
t.Fatal("failed typecast")

View file

@ -7,7 +7,7 @@ import (
"net"
)
func unmarshalIndividualConnectionStruct(conn io.Reader) (*ClientConnection, error) {
func unmarshalIndividualConnectionStruct(conn io.Reader) (*ProxyClientConnection, error) {
serverIPVersion := make([]byte, 1)
if _, err := conn.Read(serverIPVersion); err != nil {
@ -70,7 +70,7 @@ func unmarshalIndividualConnectionStruct(conn io.Reader) (*ClientConnection, err
return nil, fmt.Errorf("couldn't read source port")
}
return &ClientConnection{
return &ProxyClientConnection{
SourceIP: serverIP.String(),
SourcePort: binary.BigEndian.Uint16(sourcePort),
DestPort: binary.BigEndian.Uint16(destinationPort),
@ -79,7 +79,7 @@ func unmarshalIndividualConnectionStruct(conn io.Reader) (*ClientConnection, err
}, nil
}
func unmarshalIndividualProxyStruct(conn io.Reader) (*ProxyConnection, error) {
func unmarshalIndividualProxyStruct(conn io.Reader) (*ProxyInstance, error) {
ipVersion := make([]byte, 1)
if _, err := conn.Read(ipVersion); err != nil {
@ -130,7 +130,7 @@ func unmarshalIndividualProxyStruct(conn io.Reader) (*ProxyConnection, error) {
return nil, fmt.Errorf("invalid protocol")
}
return &ProxyConnection{
return &ProxyInstance{
SourceIP: ip.String(),
SourcePort: binary.BigEndian.Uint16(sourcePort),
DestPort: binary.BigEndian.Uint16(destPort),
@ -146,7 +146,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
}
switch commandType[0] {
case StartCommandID:
case StartID:
argumentsLength := make([]byte, 2)
if _, err := conn.Read(argumentsLength); err != nil {
@ -159,15 +159,15 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
return "", nil, fmt.Errorf("couldn't read arguments")
}
return "start", &StartCommand{
return "start", &Start{
Type: "start",
Arguments: arguments,
}, nil
case StopCommandID:
return "stop", &StopCommand{
case StopID:
return "stop", &Stop{
Type: "stop",
}, nil
case AddConnectionCommandID:
case AddProxyID:
ipVersion := make([]byte, 1)
if _, err := conn.Read(ipVersion); err != nil {
@ -218,14 +218,14 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
return "", nil, fmt.Errorf("invalid protocol")
}
return "addConnection", &AddConnectionCommand{
Type: "addConnection",
return "addProxy", &AddProxy{
Type: "addProxy",
SourceIP: ip.String(),
SourcePort: binary.BigEndian.Uint16(sourcePort),
DestPort: binary.BigEndian.Uint16(destPort),
Protocol: protocol,
}, nil
case RemoveConnectionCommandID:
case RemoveProxyID:
ipVersion := make([]byte, 1)
if _, err := conn.Read(ipVersion); err != nil {
@ -276,15 +276,15 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
return "", nil, fmt.Errorf("invalid protocol")
}
return "removeConnection", &RemoveConnectionCommand{
Type: "removeConnection",
return "removeProxy", &RemoveProxy{
Type: "removeProxy",
SourceIP: ip.String(),
SourcePort: binary.BigEndian.Uint16(sourcePort),
DestPort: binary.BigEndian.Uint16(destPort),
Protocol: protocol,
}, nil
case GetAllConnectionsID:
connections := []*ClientConnection{}
case ProxyConnectionsResponseID:
connections := []*ProxyClientConnection{}
delimiter := make([]byte, 1)
var errorReturn error
@ -313,8 +313,8 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
}
}
return "connectionsResponse", &ConnectionsResponse{
Type: "connectionsResponse",
return "proxyConnectionsResponse", &ProxyConnectionsResponse{
Type: "proxyConnectionsResponse",
Connections: connections,
}, errorReturn
case CheckClientParametersID:
@ -605,12 +605,12 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
Protocol: protocol,
IsActive: isActive[0] == 1,
}, nil
case ProxyConnectionRequestID:
return "proxyConnectionRequest", &ProxyConnectionRequest{
Type: "proxyConnectionRequest",
case ProxyInstanceRequestID:
return "proxyInstanceRequest", &ProxyInstanceRequest{
Type: "proxyInstanceRequest",
}, nil
case ProxyConnectionResponseID:
proxies := []*ProxyConnection{}
case ProxyInstanceResponseID:
proxies := []*ProxyInstance{}
delimiter := make([]byte, 1)
var errorReturn error
@ -639,15 +639,15 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
}
}
return "proxyConnectionResponse", &ProxyConnectionResponse{
Type: "proxyConnectionResponse",
return "proxyInstanceResponse", &ProxyInstanceResponse{
Type: "proxyInstanceResponse",
Proxies: proxies,
}, errorReturn
case GetAllConnectionsRequestID:
return "getAllConnectionsRequest", &GetAllConnectionsRequest{
Type: "getAllConnectionsRequest",
case ProxyConnectionsRequestID:
return "proxyConnectionsRequest", &ProxyConnectionsRequest{
Type: "proxyConnectionsRequest",
}, nil
}
return "", nil, fmt.Errorf("couldn't match command")
return "", nil, fmt.Errorf("couldn't match command ID")
}

View file

@ -19,16 +19,16 @@ func (backend *DummyBackend) StopBackend() (bool, error) {
return true, nil
}
func (backend *DummyBackend) StartProxy(command *commonbackend.AddConnectionCommand) (bool, error) {
func (backend *DummyBackend) StartProxy(command *commonbackend.AddProxy) (bool, error) {
return true, nil
}
func (backend *DummyBackend) StopProxy(command *commonbackend.RemoveConnectionCommand) (bool, error) {
func (backend *DummyBackend) StopProxy(command *commonbackend.RemoveProxy) (bool, error) {
return true, nil
}
func (backend *DummyBackend) GetAllClientConnections() []*commonbackend.ClientConnection {
return []*commonbackend.ClientConnection{}
func (backend *DummyBackend) GetAllClientConnections() []*commonbackend.ProxyClientConnection {
return []*commonbackend.ProxyClientConnection{}
}
func (backend *DummyBackend) CheckParametersForConnections(clientParameters *commonbackend.CheckClientParameters) *commonbackend.CheckParametersResponse {

View file

@ -19,6 +19,10 @@ func (writer WriteLogger) Write(p []byte) (n int, err error) {
logSplit := strings.Split(string(p), "\n")
for _, line := range logSplit {
if line == "" {
continue
}
if writer.UseError {
log.Errorf("application: %s", line)
} else {

View file

@ -26,7 +26,7 @@ type SSHListener struct {
type SSHBackend struct {
config SSHBackendData
conn *ssh.Client
clients []*commonbackend.ClientConnection
clients []*commonbackend.ProxyClientConnection
proxies []*SSHListener
arrayPropMutex sync.Mutex
}
@ -40,6 +40,7 @@ type SSHBackendData struct {
}
func (backend *SSHBackend) StartBackend(bytes []byte) (bool, error) {
log.Info("SSHBackend is initializing...")
var backendData SSHBackendData
err := json.Unmarshal(bytes, &backendData)
@ -77,6 +78,7 @@ func (backend *SSHBackend) StartBackend(bytes []byte) (bool, error) {
backend.conn = conn
log.Info("SSHBackend has initialized successfully.")
return true, nil
}
@ -90,7 +92,7 @@ func (backend *SSHBackend) StopBackend() (bool, error) {
return true, nil
}
func (backend *SSHBackend) StartProxy(command *commonbackend.AddConnectionCommand) (bool, error) {
func (backend *SSHBackend) StartProxy(command *commonbackend.AddProxy) (bool, error) {
listenerObject := &SSHListener{
SourceIP: command.SourceIP,
SourcePort: command.SourcePort,
@ -131,7 +133,7 @@ func (backend *SSHBackend) StartProxy(command *commonbackend.AddConnectionComman
continue
}
sourceConn, err := net.Dial("tcp", command.SourceIP+":"+string(command.SourcePort))
sourceConn, err := net.Dial("tcp", fmt.Sprintf("%s:%d", command.SourceIP, command.SourcePort))
if err != nil {
log.Warnf("failed to dial source connection: %s", err.Error())
@ -146,7 +148,7 @@ func (backend *SSHBackend) StartProxy(command *commonbackend.AddConnectionComman
continue
}
advertisedConn := &commonbackend.ClientConnection{
advertisedConn := &commonbackend.ProxyClientConnection{
SourceIP: command.SourceIP,
SourcePort: command.SourcePort,
DestPort: command.DestPort,
@ -241,7 +243,7 @@ func (backend *SSHBackend) StartProxy(command *commonbackend.AddConnectionComman
return true, nil
}
func (backend *SSHBackend) StopProxy(command *commonbackend.RemoveConnectionCommand) (bool, error) {
func (backend *SSHBackend) StopProxy(command *commonbackend.RemoveProxy) (bool, error) {
defer backend.arrayPropMutex.Unlock()
backend.arrayPropMutex.Lock()
@ -270,7 +272,7 @@ func (backend *SSHBackend) StopProxy(command *commonbackend.RemoveConnectionComm
return false, fmt.Errorf("could not find the proxy")
}
func (backend *SSHBackend) GetAllClientConnections() []*commonbackend.ClientConnection {
func (backend *SSHBackend) GetAllClientConnections() []*commonbackend.ProxyClientConnection {
defer backend.arrayPropMutex.Unlock()
backend.arrayPropMutex.Lock()
@ -306,7 +308,6 @@ func (backend *SSHBackend) CheckParametersForBackend(arguments []byte) *commonba
}
func main() {
// When using logging, you should use charmbracelet/log, because that's what everything else uses in this ecosystem of a project. - imterah
logLevel := os.Getenv("NEXTNET_LOG_LEVEL")
if logLevel != "" {