chore: Adds more Go support.
This commit is contained in:
parent
42d88a90c4
commit
0575ec97a5
3 changed files with 76 additions and 21 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,2 @@
|
|||
*.go
|
||||
*.capnp.go
|
||||
*.rs
|
||||
|
|
40
data.capnp
40
data.capnp
|
@ -14,6 +14,11 @@ enum StatusCode {
|
|||
failure @1;
|
||||
}
|
||||
|
||||
enum InResponseTo {
|
||||
checkClientParameters @0;
|
||||
checkServerParameters @1;
|
||||
}
|
||||
|
||||
struct Start {
|
||||
arguments @0 :Data;
|
||||
}
|
||||
|
@ -49,17 +54,17 @@ struct ProxyStatusResponse {
|
|||
isActive @4 :Bool;
|
||||
}
|
||||
|
||||
struct ProxyInstance {
|
||||
sourceIP @0 :Text;
|
||||
sourcePort @1 :UInt16;
|
||||
destPort @2 :UInt16;
|
||||
protocol @3 :Protocol;
|
||||
}
|
||||
|
||||
struct ProxyInstanceRequest {}
|
||||
|
||||
struct ProxyInstanceResponse {
|
||||
proxies @0 :List(ProxyInstance);
|
||||
|
||||
struct ProxyInstance {
|
||||
sourceIP @0 :Text;
|
||||
sourcePort @1 :UInt16;
|
||||
destPort @2 :UInt16;
|
||||
protocol @3 :Protocol;
|
||||
}
|
||||
}
|
||||
|
||||
struct BackendStatusRequest {}
|
||||
|
@ -70,18 +75,18 @@ struct BackendStatusResponse {
|
|||
message @2 :Text;
|
||||
}
|
||||
|
||||
struct Connection {
|
||||
sourceIP @0 :Data;
|
||||
sourcePort @1 :UInt16;
|
||||
destPort @2 :UInt16;
|
||||
clientIP @3 :Data;
|
||||
clientPort @4 :UInt16;
|
||||
}
|
||||
|
||||
struct ProxyConnectionsRequest {}
|
||||
|
||||
struct ProxyConnectionsResponse {
|
||||
connections @0 :List(Connection);
|
||||
|
||||
struct Connection {
|
||||
sourceIP @0 :Data;
|
||||
sourcePort @1 :UInt16;
|
||||
destPort @2 :UInt16;
|
||||
clientIP @3 :Data;
|
||||
clientPort @4 :UInt16;
|
||||
}
|
||||
}
|
||||
|
||||
struct CheckClientParameters {
|
||||
|
@ -99,9 +104,4 @@ struct CheckParametersResponse {
|
|||
inResponseTo @0 :InResponseTo;
|
||||
isValid @1 :Bool;
|
||||
message @2 :Text;
|
||||
|
||||
enum InResponseTo {
|
||||
checkClientParameters @0;
|
||||
checkServerParameters @1;
|
||||
}
|
||||
}
|
||||
|
|
55
iptool.go
Normal file
55
iptool.go
Normal 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")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue