chore: Strip unneeded components from code.
This commit is contained in:
parent
62cc8b39ad
commit
cf90ddb104
19 changed files with 228 additions and 762 deletions
|
@ -1,57 +1,47 @@
|
|||
package datacommands
|
||||
|
||||
type ProxyStatusRequest struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
}
|
||||
|
||||
type ProxyStatusResponse struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
IsActive bool
|
||||
}
|
||||
|
||||
type RemoveProxy struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
}
|
||||
|
||||
type ProxyInstanceResponse struct {
|
||||
Type string
|
||||
Proxies []uint16
|
||||
}
|
||||
|
||||
type ProxyConnectionsRequest struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
}
|
||||
|
||||
type ProxyConnectionsResponse struct {
|
||||
Type string
|
||||
Connections []uint16
|
||||
}
|
||||
|
||||
type TCPConnectionOpened struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
ConnectionID uint16
|
||||
}
|
||||
|
||||
type TCPConnectionClosed struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
ConnectionID uint16
|
||||
}
|
||||
|
||||
type TCPProxyData struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
ConnectionID uint16
|
||||
DataLength uint16
|
||||
}
|
||||
|
||||
type UDPProxyData struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
ClientIP string
|
||||
ClientPort uint16
|
||||
|
@ -59,12 +49,10 @@ type UDPProxyData struct {
|
|||
}
|
||||
|
||||
type ProxyInformationRequest struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
}
|
||||
|
||||
type ProxyInformationResponse struct {
|
||||
Type string
|
||||
Exists bool
|
||||
SourceIP string
|
||||
SourcePort uint16
|
||||
|
@ -73,13 +61,11 @@ type ProxyInformationResponse struct {
|
|||
}
|
||||
|
||||
type ProxyConnectionInformationRequest struct {
|
||||
Type string
|
||||
ProxyID uint16
|
||||
ConnectionID uint16
|
||||
}
|
||||
|
||||
type ProxyConnectionInformationResponse struct {
|
||||
Type string
|
||||
Exists bool
|
||||
ClientIP string
|
||||
ClientPort uint16
|
||||
|
|
|
@ -16,7 +16,7 @@ const (
|
|||
)
|
||||
|
||||
// Marshal takes a command (pointer to one of our structs) and converts it to a byte slice.
|
||||
func Marshal(_ string, command interface{}) ([]byte, error) {
|
||||
func Marshal(command interface{}) ([]byte, error) {
|
||||
switch cmd := command.(type) {
|
||||
// ProxyStatusRequest: 1 byte for the command ID + 2 bytes for the ProxyID.
|
||||
case *ProxyStatusRequest:
|
||||
|
|
|
@ -11,11 +11,10 @@ var logLevel = os.Getenv("HERMES_LOG_LEVEL")
|
|||
|
||||
func TestProxyStatusRequest(t *testing.T) {
|
||||
commandInput := &ProxyStatusRequest{
|
||||
Type: "proxyStatusRequest",
|
||||
ProxyID: 19132,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -26,28 +25,18 @@ func TestProxyStatusRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyStatusRequest)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -56,12 +45,11 @@ func TestProxyStatusRequest(t *testing.T) {
|
|||
|
||||
func TestProxyStatusResponse(t *testing.T) {
|
||||
commandInput := &ProxyStatusResponse{
|
||||
Type: "proxyStatusResponse",
|
||||
ProxyID: 19132,
|
||||
IsActive: true,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -72,28 +60,18 @@ func TestProxyStatusResponse(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyStatusResponse)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -107,11 +85,10 @@ func TestProxyStatusResponse(t *testing.T) {
|
|||
|
||||
func TestRemoveProxy(t *testing.T) {
|
||||
commandInput := &RemoveProxy{
|
||||
Type: "removeProxy",
|
||||
ProxyID: 19132,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -122,28 +99,18 @@ func TestRemoveProxy(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*RemoveProxy)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -152,11 +119,10 @@ func TestRemoveProxy(t *testing.T) {
|
|||
|
||||
func TestProxyConnectionsRequest(t *testing.T) {
|
||||
commandInput := &ProxyConnectionsRequest{
|
||||
Type: "proxyConnectionsRequest",
|
||||
ProxyID: 19132,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -167,28 +133,18 @@ func TestProxyConnectionsRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionsRequest)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -197,11 +153,10 @@ func TestProxyConnectionsRequest(t *testing.T) {
|
|||
|
||||
func TestProxyConnectionsResponse(t *testing.T) {
|
||||
commandInput := &ProxyConnectionsResponse{
|
||||
Type: "proxyConnectionsResponse",
|
||||
Connections: []uint16{12831, 9455, 64219, 12, 32},
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -212,28 +167,18 @@ func TestProxyConnectionsResponse(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionsResponse)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
for connectionIndex, originalConnection := range commandInput.Connections {
|
||||
remoteConnection := commandUnmarshalled.Connections[connectionIndex]
|
||||
|
||||
|
@ -246,11 +191,10 @@ func TestProxyConnectionsResponse(t *testing.T) {
|
|||
|
||||
func TestProxyInstanceResponse(t *testing.T) {
|
||||
commandInput := &ProxyInstanceResponse{
|
||||
Type: "proxyInstanceResponse",
|
||||
Proxies: []uint16{12831, 9455, 64219, 12, 32},
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -261,28 +205,18 @@ func TestProxyInstanceResponse(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyInstanceResponse)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
for proxyIndex, originalProxy := range commandInput.Proxies {
|
||||
remoteProxy := commandUnmarshalled.Proxies[proxyIndex]
|
||||
|
||||
|
@ -295,12 +229,11 @@ func TestProxyInstanceResponse(t *testing.T) {
|
|||
|
||||
func TestTCPConnectionOpened(t *testing.T) {
|
||||
commandInput := &TCPConnectionOpened{
|
||||
Type: "tcpConnectionOpened",
|
||||
ProxyID: 19132,
|
||||
ConnectionID: 25565,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -311,28 +244,18 @@ func TestTCPConnectionOpened(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*TCPConnectionOpened)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -346,12 +269,11 @@ func TestTCPConnectionOpened(t *testing.T) {
|
|||
|
||||
func TestTCPConnectionClosed(t *testing.T) {
|
||||
commandInput := &TCPConnectionClosed{
|
||||
Type: "tcpConnectionClosed",
|
||||
ProxyID: 19132,
|
||||
ConnectionID: 25565,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -362,28 +284,18 @@ func TestTCPConnectionClosed(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*TCPConnectionClosed)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -397,13 +309,12 @@ func TestTCPConnectionClosed(t *testing.T) {
|
|||
|
||||
func TestTCPProxyData(t *testing.T) {
|
||||
commandInput := &TCPProxyData{
|
||||
Type: "tcpProxyData",
|
||||
ProxyID: 19132,
|
||||
ConnectionID: 25565,
|
||||
DataLength: 1234,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -414,28 +325,18 @@ func TestTCPProxyData(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*TCPProxyData)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -454,14 +355,13 @@ func TestTCPProxyData(t *testing.T) {
|
|||
|
||||
func TestUDPProxyData(t *testing.T) {
|
||||
commandInput := &UDPProxyData{
|
||||
Type: "udpProxyData",
|
||||
ProxyID: 19132,
|
||||
ClientIP: "68.51.23.54",
|
||||
ClientPort: 28173,
|
||||
DataLength: 1234,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -472,28 +372,18 @@ func TestUDPProxyData(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*UDPProxyData)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -517,11 +407,10 @@ func TestUDPProxyData(t *testing.T) {
|
|||
|
||||
func TestProxyInformationRequest(t *testing.T) {
|
||||
commandInput := &ProxyInformationRequest{
|
||||
Type: "proxyInformationRequest",
|
||||
ProxyID: 19132,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -532,28 +421,18 @@ func TestProxyInformationRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyInformationRequest)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -562,7 +441,6 @@ func TestProxyInformationRequest(t *testing.T) {
|
|||
|
||||
func TestProxyInformationResponseExists(t *testing.T) {
|
||||
commandInput := &ProxyInformationResponse{
|
||||
Type: "proxyInformationResponse",
|
||||
Exists: true,
|
||||
SourceIP: "192.168.0.139",
|
||||
SourcePort: 19132,
|
||||
|
@ -570,7 +448,7 @@ func TestProxyInformationResponseExists(t *testing.T) {
|
|||
Protocol: "tcp",
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
|
@ -581,28 +459,18 @@ func TestProxyInformationResponseExists(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyInformationResponse)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.Exists != commandUnmarshalled.Exists {
|
||||
t.Fail()
|
||||
log.Printf("Exists's are not equal (orig: '%t', unmsh: '%t')", commandInput.Exists, commandUnmarshalled.Exists)
|
||||
|
@ -631,11 +499,10 @@ func TestProxyInformationResponseExists(t *testing.T) {
|
|||
|
||||
func TestProxyInformationResponseNoExist(t *testing.T) {
|
||||
commandInput := &ProxyInformationResponse{
|
||||
Type: "proxyInformationResponse",
|
||||
Exists: false,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
|
@ -646,28 +513,18 @@ func TestProxyInformationResponseNoExist(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyInformationResponse)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.Exists != commandUnmarshalled.Exists {
|
||||
t.Fail()
|
||||
log.Printf("Exists's are not equal (orig: '%t', unmsh: '%t')", commandInput.Exists, commandUnmarshalled.Exists)
|
||||
|
@ -676,12 +533,11 @@ func TestProxyInformationResponseNoExist(t *testing.T) {
|
|||
|
||||
func TestProxyConnectionInformationRequest(t *testing.T) {
|
||||
commandInput := &ProxyConnectionInformationRequest{
|
||||
Type: "proxyConnectionInformationRequest",
|
||||
ProxyID: 19132,
|
||||
ConnectionID: 25565,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if logLevel == "debug" {
|
||||
log.Printf("Generated array contents: %v", commandMarshalled)
|
||||
|
@ -692,28 +548,18 @@ func TestProxyConnectionInformationRequest(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionInformationRequest)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.ProxyID != commandUnmarshalled.ProxyID {
|
||||
t.Fail()
|
||||
log.Printf("ProxyID's are not equal (orig: '%d', unmsh: '%d')", commandInput.ProxyID, commandUnmarshalled.ProxyID)
|
||||
|
@ -727,13 +573,12 @@ func TestProxyConnectionInformationRequest(t *testing.T) {
|
|||
|
||||
func TestProxyConnectionInformationResponseExists(t *testing.T) {
|
||||
commandInput := &ProxyConnectionInformationResponse{
|
||||
Type: "proxyConnectionInformationResponse",
|
||||
Exists: true,
|
||||
ClientIP: "192.168.0.139",
|
||||
ClientPort: 19132,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
|
@ -744,28 +589,18 @@ func TestProxyConnectionInformationResponseExists(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionInformationResponse)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.Exists != commandUnmarshalled.Exists {
|
||||
t.Fail()
|
||||
log.Printf("Exists's are not equal (orig: '%t', unmsh: '%t')", commandInput.Exists, commandUnmarshalled.Exists)
|
||||
|
@ -784,11 +619,10 @@ func TestProxyConnectionInformationResponseExists(t *testing.T) {
|
|||
|
||||
func TestProxyConnectionInformationResponseNoExists(t *testing.T) {
|
||||
commandInput := &ProxyConnectionInformationResponse{
|
||||
Type: "proxyConnectionInformationResponse",
|
||||
Exists: false,
|
||||
}
|
||||
|
||||
commandMarshalled, err := Marshal(commandInput.Type, commandInput)
|
||||
commandMarshalled, err := Marshal(commandInput)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
|
@ -799,28 +633,18 @@ func TestProxyConnectionInformationResponseNoExists(t *testing.T) {
|
|||
}
|
||||
|
||||
buf := bytes.NewBuffer(commandMarshalled)
|
||||
commandType, commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
commandUnmarshalledRaw, err := Unmarshal(buf)
|
||||
|
||||
if err != nil {
|
||||
t.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if commandType != commandInput.Type {
|
||||
t.Fail()
|
||||
log.Print("command type does not match up!")
|
||||
}
|
||||
|
||||
commandUnmarshalled, ok := commandUnmarshalledRaw.(*ProxyConnectionInformationResponse)
|
||||
|
||||
if !ok {
|
||||
t.Fatal("failed typecast")
|
||||
}
|
||||
|
||||
if commandInput.Type != commandUnmarshalled.Type {
|
||||
t.Fail()
|
||||
log.Printf("Types are not equal (orig: %s, unmsh: %s)", commandInput.Type, commandUnmarshalled.Type)
|
||||
}
|
||||
|
||||
if commandInput.Exists != commandUnmarshalled.Exists {
|
||||
t.Fail()
|
||||
log.Printf("Exists's are not equal (orig: '%t', unmsh: '%t')", commandInput.Exists, commandUnmarshalled.Exists)
|
||||
|
|
|
@ -9,11 +9,12 @@ import (
|
|||
|
||||
// Unmarshal reads from the provided connection and returns
|
||||
// the message type (as a string), the unmarshalled struct, or an error.
|
||||
func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
||||
func Unmarshal(conn io.Reader) (interface{}, error) {
|
||||
// Every command starts with a 1-byte command ID.
|
||||
header := make([]byte, 1)
|
||||
|
||||
if _, err := io.ReadFull(conn, header); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read command ID: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read command ID: %w", err)
|
||||
}
|
||||
|
||||
cmdID := header[0]
|
||||
|
@ -23,13 +24,12 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyStatusRequest ProxyID: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyStatusRequest ProxyID: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf)
|
||||
|
||||
return "proxyStatusRequest", &ProxyStatusRequest{
|
||||
Type: "proxyStatusRequest",
|
||||
return &ProxyStatusRequest{
|
||||
ProxyID: proxyID,
|
||||
}, nil
|
||||
|
||||
|
@ -38,20 +38,19 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyStatusResponse ProxyID: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyStatusResponse ProxyID: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf)
|
||||
boolBuf := make([]byte, 1)
|
||||
|
||||
if _, err := io.ReadFull(conn, boolBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyStatusResponse IsActive: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyStatusResponse IsActive: %w", err)
|
||||
}
|
||||
|
||||
isActive := boolBuf[0] != 0
|
||||
|
||||
return "proxyStatusResponse", &ProxyStatusResponse{
|
||||
Type: "proxyStatusResponse",
|
||||
return &ProxyStatusResponse{
|
||||
ProxyID: proxyID,
|
||||
IsActive: isActive,
|
||||
}, nil
|
||||
|
@ -61,13 +60,12 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read RemoveProxy ProxyID: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read RemoveProxy ProxyID: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf)
|
||||
|
||||
return "removeProxy", &RemoveProxy{
|
||||
Type: "removeProxy",
|
||||
return &RemoveProxy{
|
||||
ProxyID: proxyID,
|
||||
}, nil
|
||||
|
||||
|
@ -76,13 +74,12 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionsRequest ProxyID: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionsRequest ProxyID: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf)
|
||||
|
||||
return "proxyConnectionsRequest", &ProxyConnectionsRequest{
|
||||
Type: "proxyConnectionsRequest",
|
||||
return &ProxyConnectionsRequest{
|
||||
ProxyID: proxyID,
|
||||
}, nil
|
||||
|
||||
|
@ -91,7 +88,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionsResponse length: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionsResponse length: %w", err)
|
||||
}
|
||||
|
||||
length := binary.BigEndian.Uint16(buf)
|
||||
|
@ -108,8 +105,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
connections[connectionIndex] = binary.BigEndian.Uint16(buf)
|
||||
}
|
||||
|
||||
return "proxyConnectionsResponse", &ProxyConnectionsResponse{
|
||||
Type: "proxyConnectionsResponse",
|
||||
return &ProxyConnectionsResponse{
|
||||
Connections: connections,
|
||||
}, failedDuringReading
|
||||
|
||||
|
@ -118,7 +114,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionsResponse length: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionsResponse length: %w", err)
|
||||
}
|
||||
|
||||
length := binary.BigEndian.Uint16(buf)
|
||||
|
@ -135,8 +131,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
proxies[connectionIndex] = binary.BigEndian.Uint16(buf)
|
||||
}
|
||||
|
||||
return "proxyInstanceResponse", &ProxyInstanceResponse{
|
||||
Type: "proxyInstanceResponse",
|
||||
return &ProxyInstanceResponse{
|
||||
Proxies: proxies,
|
||||
}, failedDuringReading
|
||||
|
||||
|
@ -145,14 +140,13 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2+2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read TCPConnectionOpened fields: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read TCPConnectionOpened fields: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf[0:2])
|
||||
connectionID := binary.BigEndian.Uint16(buf[2:4])
|
||||
|
||||
return "tcpConnectionOpened", &TCPConnectionOpened{
|
||||
Type: "tcpConnectionOpened",
|
||||
return &TCPConnectionOpened{
|
||||
ProxyID: proxyID,
|
||||
ConnectionID: connectionID,
|
||||
}, nil
|
||||
|
@ -162,14 +156,13 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2+2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read TCPConnectionClosed fields: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read TCPConnectionClosed fields: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf[0:2])
|
||||
connectionID := binary.BigEndian.Uint16(buf[2:4])
|
||||
|
||||
return "tcpConnectionClosed", &TCPConnectionClosed{
|
||||
Type: "tcpConnectionClosed",
|
||||
return &TCPConnectionClosed{
|
||||
ProxyID: proxyID,
|
||||
ConnectionID: connectionID,
|
||||
}, nil
|
||||
|
@ -179,15 +172,14 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2+2+2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read TCPProxyData fields: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read TCPProxyData fields: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf[0:2])
|
||||
connectionID := binary.BigEndian.Uint16(buf[2:4])
|
||||
dataLength := binary.BigEndian.Uint16(buf[4:6])
|
||||
|
||||
return "tcpProxyData", &TCPProxyData{
|
||||
Type: "tcpProxyData",
|
||||
return &TCPProxyData{
|
||||
ProxyID: proxyID,
|
||||
ConnectionID: connectionID,
|
||||
DataLength: dataLength,
|
||||
|
@ -201,7 +193,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read UDPProxyData ProxyID/ConnectionID: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read UDPProxyData ProxyID/ConnectionID: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf)
|
||||
|
@ -210,7 +202,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
ipVerBuf := make([]byte, 1)
|
||||
|
||||
if _, err := io.ReadFull(conn, ipVerBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read UDPProxyData IP version: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read UDPProxyData IP version: %w", err)
|
||||
}
|
||||
|
||||
var ipSize int
|
||||
|
@ -220,13 +212,13 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
} else if ipVerBuf[0] == 6 {
|
||||
ipSize = IPv6Size
|
||||
} else {
|
||||
return "", nil, fmt.Errorf("invalid IP version received: %v", ipVerBuf[0])
|
||||
return nil, fmt.Errorf("invalid IP version received: %v", ipVerBuf[0])
|
||||
}
|
||||
|
||||
// Read the IP bytes.
|
||||
ipBytes := make([]byte, ipSize)
|
||||
if _, err := io.ReadFull(conn, ipBytes); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read UDPProxyData IP bytes: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read UDPProxyData IP bytes: %w", err)
|
||||
}
|
||||
clientIP := net.IP(ipBytes).String()
|
||||
|
||||
|
@ -234,7 +226,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
portBuf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, portBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read UDPProxyData ClientPort: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read UDPProxyData ClientPort: %w", err)
|
||||
}
|
||||
|
||||
clientPort := binary.BigEndian.Uint16(portBuf)
|
||||
|
@ -243,13 +235,12 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
dataLengthBuf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, dataLengthBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read UDPProxyData DataLength: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read UDPProxyData DataLength: %w", err)
|
||||
}
|
||||
|
||||
dataLength := binary.BigEndian.Uint16(dataLengthBuf)
|
||||
|
||||
return "udpProxyData", &UDPProxyData{
|
||||
Type: "udpProxyData",
|
||||
return &UDPProxyData{
|
||||
ProxyID: proxyID,
|
||||
ClientIP: clientIP,
|
||||
ClientPort: clientPort,
|
||||
|
@ -261,13 +252,12 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyInformationRequest ProxyID: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyInformationRequest ProxyID: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf)
|
||||
|
||||
return "proxyInformationRequest", &ProxyInformationRequest{
|
||||
Type: "proxyInformationRequest",
|
||||
return &ProxyInformationRequest{
|
||||
ProxyID: proxyID,
|
||||
}, nil
|
||||
|
||||
|
@ -279,14 +269,13 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
boolBuf := make([]byte, 1)
|
||||
|
||||
if _, err := io.ReadFull(conn, boolBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyInformationResponse Exists flag: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyInformationResponse Exists flag: %w", err)
|
||||
}
|
||||
|
||||
exists := boolBuf[0] != 0
|
||||
|
||||
if !exists {
|
||||
return "proxyInformationResponse", &ProxyInformationResponse{
|
||||
Type: "proxyInformationResponse",
|
||||
return &ProxyInformationResponse{
|
||||
Exists: exists,
|
||||
}, nil
|
||||
}
|
||||
|
@ -295,7 +284,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
ipVerBuf := make([]byte, 1)
|
||||
|
||||
if _, err := io.ReadFull(conn, ipVerBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyInformationResponse IP version: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyInformationResponse IP version: %w", err)
|
||||
}
|
||||
|
||||
var ipSize int
|
||||
|
@ -305,14 +294,14 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
} else if ipVerBuf[0] == 6 {
|
||||
ipSize = IPv6Size
|
||||
} else {
|
||||
return "", nil, fmt.Errorf("invalid IP version in ProxyInformationResponse: %v", ipVerBuf[0])
|
||||
return nil, fmt.Errorf("invalid IP version in ProxyInformationResponse: %v", ipVerBuf[0])
|
||||
}
|
||||
|
||||
// Read the source IP bytes.
|
||||
ipBytes := make([]byte, ipSize)
|
||||
|
||||
if _, err := io.ReadFull(conn, ipBytes); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyInformationResponse IP bytes: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyInformationResponse IP bytes: %w", err)
|
||||
}
|
||||
|
||||
sourceIP := net.IP(ipBytes).String()
|
||||
|
@ -321,7 +310,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
portsBuf := make([]byte, 2+2)
|
||||
|
||||
if _, err := io.ReadFull(conn, portsBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyInformationResponse ports: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyInformationResponse ports: %w", err)
|
||||
}
|
||||
|
||||
sourcePort := binary.BigEndian.Uint16(portsBuf[0:2])
|
||||
|
@ -331,19 +320,20 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
protoBuf := make([]byte, 1)
|
||||
|
||||
if _, err := io.ReadFull(conn, protoBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyInformationResponse protocol: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyInformationResponse protocol: %w", err)
|
||||
}
|
||||
|
||||
var protocol string
|
||||
|
||||
if protoBuf[0] == TCP {
|
||||
protocol = "tcp"
|
||||
} else if protoBuf[0] == UDP {
|
||||
protocol = "udp"
|
||||
} else {
|
||||
return "", nil, fmt.Errorf("invalid protocol value in ProxyInformationResponse: %d", protoBuf[0])
|
||||
return nil, fmt.Errorf("invalid protocol value in ProxyInformationResponse: %d", protoBuf[0])
|
||||
}
|
||||
|
||||
return "proxyInformationResponse", &ProxyInformationResponse{
|
||||
Type: "proxyInformationResponse",
|
||||
return &ProxyInformationResponse{
|
||||
Exists: exists,
|
||||
SourceIP: sourceIP,
|
||||
SourcePort: sourcePort,
|
||||
|
@ -356,14 +346,13 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
buf := make([]byte, 2+2)
|
||||
|
||||
if _, err := io.ReadFull(conn, buf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionInformationRequest fields: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionInformationRequest fields: %w", err)
|
||||
}
|
||||
|
||||
proxyID := binary.BigEndian.Uint16(buf[0:2])
|
||||
connectionID := binary.BigEndian.Uint16(buf[2:4])
|
||||
|
||||
return "proxyConnectionInformationRequest", &ProxyConnectionInformationRequest{
|
||||
Type: "proxyConnectionInformationRequest",
|
||||
return &ProxyConnectionInformationRequest{
|
||||
ProxyID: proxyID,
|
||||
ConnectionID: connectionID,
|
||||
}, nil
|
||||
|
@ -374,14 +363,13 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
// Read Exists flag.
|
||||
boolBuf := make([]byte, 1)
|
||||
if _, err := io.ReadFull(conn, boolBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse Exists flag: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse Exists flag: %w", err)
|
||||
}
|
||||
|
||||
exists := boolBuf[0] != 0
|
||||
|
||||
if !exists {
|
||||
return "proxyConnectionInformationResponse", &ProxyConnectionInformationResponse{
|
||||
Type: "proxyConnectionInformationResponse",
|
||||
return &ProxyConnectionInformationResponse{
|
||||
Exists: exists,
|
||||
}, nil
|
||||
}
|
||||
|
@ -390,11 +378,11 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
ipVerBuf := make([]byte, 1)
|
||||
|
||||
if _, err := io.ReadFull(conn, ipVerBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse IP version: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse IP version: %w", err)
|
||||
}
|
||||
|
||||
if ipVerBuf[0] != 4 && ipVerBuf[0] != 6 {
|
||||
return "", nil, fmt.Errorf("invalid IP version in ProxyConnectionInformationResponse: %v", ipVerBuf[0])
|
||||
return nil, fmt.Errorf("invalid IP version in ProxyConnectionInformationResponse: %v", ipVerBuf[0])
|
||||
}
|
||||
|
||||
var ipSize int
|
||||
|
@ -409,7 +397,7 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
ipBytes := make([]byte, ipSize)
|
||||
|
||||
if _, err := io.ReadFull(conn, ipBytes); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse IP bytes: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse IP bytes: %w", err)
|
||||
}
|
||||
|
||||
clientIP := net.IP(ipBytes).String()
|
||||
|
@ -418,18 +406,17 @@ func Unmarshal(conn io.Reader) (string, interface{}, error) {
|
|||
portBuf := make([]byte, 2)
|
||||
|
||||
if _, err := io.ReadFull(conn, portBuf); err != nil {
|
||||
return "", nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse ClientPort: %w", err)
|
||||
return nil, fmt.Errorf("couldn't read ProxyConnectionInformationResponse ClientPort: %w", err)
|
||||
}
|
||||
|
||||
clientPort := binary.BigEndian.Uint16(portBuf)
|
||||
|
||||
return "proxyConnectionInformationResponse", &ProxyConnectionInformationResponse{
|
||||
Type: "proxyConnectionInformationResponse",
|
||||
return &ProxyConnectionInformationResponse{
|
||||
Exists: exists,
|
||||
ClientIP: clientIP,
|
||||
ClientPort: clientPort,
|
||||
}, nil
|
||||
default:
|
||||
return "", nil, fmt.Errorf("unknown command id: %v", cmdID)
|
||||
return nil, fmt.Errorf("unknown command id: %v", cmdID)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,7 +36,7 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
log.Debug("Sucessfully connected")
|
||||
|
||||
for {
|
||||
_, commandRaw, err := datacommands.Unmarshal(helper.socket)
|
||||
commandRaw, err := datacommands.Unmarshal(helper.socket)
|
||||
|
||||
if err != nil && err.Error() != "couldn't match command ID" {
|
||||
return err
|
||||
|
@ -47,11 +47,10 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
connections := helper.Backend.GetAllClientConnections(command.ProxyID)
|
||||
|
||||
serverParams := &datacommands.ProxyConnectionsResponse{
|
||||
Type: "proxyConnectionsResponse",
|
||||
Connections: connections,
|
||||
}
|
||||
|
||||
byteData, err := datacommands.Marshal(serverParams.Type, serverParams)
|
||||
byteData, err := datacommands.Marshal(serverParams)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -73,12 +72,11 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
}
|
||||
|
||||
response := &datacommands.ProxyStatusResponse{
|
||||
Type: "proxyStatusResponse",
|
||||
ProxyID: command.ProxyID,
|
||||
IsActive: hasAnyFailed,
|
||||
}
|
||||
|
||||
responseMarshalled, err := commonbackend.Marshal(response.Type, response)
|
||||
responseMarshalled, err := datacommands.Marshal(response)
|
||||
|
||||
if err != nil {
|
||||
log.Error("failed to marshal response: %s", err.Error())
|
||||
|
@ -87,7 +85,7 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
|
||||
helper.socket.Write(responseMarshalled)
|
||||
default:
|
||||
_, commandRaw, err := commonbackend.Unmarshal(helper.socket)
|
||||
commandRaw, err := commonbackend.Unmarshal(helper.socket)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -110,13 +108,12 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
}
|
||||
|
||||
response := &commonbackend.BackendStatusResponse{
|
||||
Type: "backendStatusResponse",
|
||||
IsRunning: ok,
|
||||
StatusCode: statusCode,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
responseMarshalled, err := commonbackend.Marshal(response.Type, response)
|
||||
responseMarshalled, err := commonbackend.Marshal(response)
|
||||
|
||||
if err != nil {
|
||||
log.Error("failed to marshal response: %s", err.Error())
|
||||
|
@ -140,13 +137,12 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
}
|
||||
|
||||
response := &commonbackend.BackendStatusResponse{
|
||||
Type: "backendStatusResponse",
|
||||
IsRunning: !ok,
|
||||
StatusCode: statusCode,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
responseMarshalled, err := commonbackend.Marshal(response.Type, response)
|
||||
responseMarshalled, err := commonbackend.Marshal(response)
|
||||
|
||||
if err != nil {
|
||||
log.Error("failed to marshal response: %s", err.Error())
|
||||
|
@ -170,13 +166,12 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
}
|
||||
|
||||
response := &commonbackend.BackendStatusResponse{
|
||||
Type: "backendStatusResponse",
|
||||
IsRunning: ok,
|
||||
StatusCode: statusCode,
|
||||
Message: message,
|
||||
}
|
||||
|
||||
responseMarshalled, err := commonbackend.Marshal(response.Type, response)
|
||||
responseMarshalled, err := commonbackend.Marshal(response)
|
||||
|
||||
if err != nil {
|
||||
log.Error("failed to marshal response: %s", err.Error())
|
||||
|
@ -197,12 +192,11 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
}
|
||||
|
||||
response := &datacommands.ProxyStatusResponse{
|
||||
Type: "proxyStatusResponse",
|
||||
ProxyID: id,
|
||||
IsActive: !hasAnyFailed,
|
||||
}
|
||||
|
||||
responseMarshalled, err := commonbackend.Marshal(response.Type, response)
|
||||
responseMarshalled, err := datacommands.Marshal(response)
|
||||
|
||||
if err != nil {
|
||||
log.Error("failed to marshal response: %s", err.Error())
|
||||
|
@ -212,10 +206,9 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
helper.socket.Write(responseMarshalled)
|
||||
case *commonbackend.CheckClientParameters:
|
||||
resp := helper.Backend.CheckParametersForConnections(command)
|
||||
resp.Type = "checkParametersResponse"
|
||||
resp.InResponseTo = "checkClientParameters"
|
||||
|
||||
byteData, err := commonbackend.Marshal(resp.Type, resp)
|
||||
byteData, err := commonbackend.Marshal(resp)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -226,10 +219,9 @@ func (helper *BackendApplicationHelper) Start() error {
|
|||
}
|
||||
case *commonbackend.CheckServerParameters:
|
||||
resp := helper.Backend.CheckParametersForBackend(command.Arguments)
|
||||
resp.Type = "checkParametersResponse"
|
||||
resp.InResponseTo = "checkServerParameters"
|
||||
|
||||
byteData, err := commonbackend.Marshal(resp.Type, resp)
|
||||
byteData, err := commonbackend.Marshal(resp)
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue