chore: Adds more Go support.

This commit is contained in:
Tera << 8 2025-01-12 11:36:43 -05:00
parent 42d88a90c4
commit 0575ec97a5
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
3 changed files with 76 additions and 21 deletions

2
.gitignore vendored
View file

@ -1,2 +1,2 @@
*.go *.capnp.go
*.rs *.rs

View file

@ -14,6 +14,11 @@ enum StatusCode {
failure @1; failure @1;
} }
enum InResponseTo {
checkClientParameters @0;
checkServerParameters @1;
}
struct Start { struct Start {
arguments @0 :Data; arguments @0 :Data;
} }
@ -49,17 +54,17 @@ struct ProxyStatusResponse {
isActive @4 :Bool; isActive @4 :Bool;
} }
struct ProxyInstance {
sourceIP @0 :Text;
sourcePort @1 :UInt16;
destPort @2 :UInt16;
protocol @3 :Protocol;
}
struct ProxyInstanceRequest {} struct ProxyInstanceRequest {}
struct ProxyInstanceResponse { struct ProxyInstanceResponse {
proxies @0 :List(ProxyInstance); proxies @0 :List(ProxyInstance);
struct ProxyInstance {
sourceIP @0 :Text;
sourcePort @1 :UInt16;
destPort @2 :UInt16;
protocol @3 :Protocol;
}
} }
struct BackendStatusRequest {} struct BackendStatusRequest {}
@ -70,18 +75,18 @@ struct BackendStatusResponse {
message @2 :Text; message @2 :Text;
} }
struct Connection {
sourceIP @0 :Data;
sourcePort @1 :UInt16;
destPort @2 :UInt16;
clientIP @3 :Data;
clientPort @4 :UInt16;
}
struct ProxyConnectionsRequest {} struct ProxyConnectionsRequest {}
struct ProxyConnectionsResponse { struct ProxyConnectionsResponse {
connections @0 :List(Connection); connections @0 :List(Connection);
struct Connection {
sourceIP @0 :Data;
sourcePort @1 :UInt16;
destPort @2 :UInt16;
clientIP @3 :Data;
clientPort @4 :UInt16;
}
} }
struct CheckClientParameters { struct CheckClientParameters {
@ -99,9 +104,4 @@ struct CheckParametersResponse {
inResponseTo @0 :InResponseTo; inResponseTo @0 :InResponseTo;
isValid @1 :Bool; isValid @1 :Bool;
message @2 :Text; message @2 :Text;
enum InResponseTo {
checkClientParameters @0;
checkServerParameters @1;
}
} }

55
iptool.go Normal file
View file

@ -0,0 +1,55 @@
package commonbackend
import (
"fmt"
"net"
)
func IPStringToIPBytes(ip string) ([]byte, error) {
sourceIP := net.ParseIP(ip)
ipBytes := sourceIP.To4()
if ipBytes == nil {
ipBytes = sourceIP.To16()
if ipBytes == nil {
return nil, fmt.Errorf("invalid IP address recieved")
}
}
return ipBytes, nil
}
func IPBytesToIPSafe(ip []byte) (net.IP, error) {
sourceIP := net.IP(ip)
ipBytes := sourceIP.To4()
if ipBytes != nil {
return ipBytes, nil
}
ipBytes = sourceIP.To16()
if ipBytes != nil {
return ipBytes, nil
}
return nil, fmt.Errorf("invalid IP address recieved")
}
func IPBytesToString(ip []byte) (string, error) {
sourceIP := net.IP(ip)
ipBytes := sourceIP.To4()
if ipBytes != nil {
return ipBytes.String(), nil
}
ipBytes = sourceIP.To16()
if ipBytes != nil {
return ipBytes.String(), nil
}
return "", fmt.Errorf("invalid IP address recieved")
}