GoBroke/tunnelbroker/types.go

72 lines
4.0 KiB
Go
Raw Normal View History

2024-12-17 17:39:10 -05:00
package tunnelbroker
import (
`encoding/xml`
`net`
`net/netip`
`github.com/go-resty/resty/v2`
`r00t2.io/gobroke/conf`
)
/*
TunPrefix is derived from netip.Prefix.
Because even though -- EVEN THOUGH -- it has a TextMarshaler and TextUnmarshaler interface,
it fails to work properly because Golang.
https://github.com/jmoiron/sqlx/issues/957
*/
type TunPrefix netip.Prefix
2024-12-17 17:39:10 -05:00
2025-02-04 12:14:08 -05:00
// TunnelList is what's returned from the tunnelbroker.net API, regardless if a specific tunnel ID is specified or not.
2024-12-17 17:39:10 -05:00
type TunnelList struct {
2025-02-04 12:14:08 -05:00
XMLName xml.Name `json:"-" xml:"tunnels" yaml:"-"`
// Tunnels should only contain a single Tunnel if a (valid) tunnel ID was specified.
2024-12-17 17:39:10 -05:00
Tunnels []*Tunnel `json:"tunnels" xml:"tunnel" yaml:"Tunnels"`
}
2025-02-04 12:14:08 -05:00
// Tunnel is a single tunnel configuration as returned from the tunnelbroker.net API.
2024-12-17 17:39:10 -05:00
type Tunnel struct {
2025-02-04 12:14:08 -05:00
XMLName xml.Name `json:"-" xml:"tunnel" yaml:"-"`
// ID should correspond with a conf.Tunnel.ID.
ID uint `json:"id" xml:"id,attr" yaml:"ID" db:"tun_id"`
// Description is generally thought of more as a "friendly name" for the tunnel.
Description string `json:"desc" xml:"description" yaml:"Description" db:"desc"`
// ServerIPv4 is the "tunnel server"; the SIT client should use this as the server.
ServerIPv4 net.IP `json:"tgt_v4" xml:"serverv4" yaml:"IPv4 Tunnel Target" db:"server_v4"`
// ClientIPv4 is the *currently configured* "authorized client IP"; this should be the WAN-routable address of the client end of the SIT.
ClientIPv4 net.IP `json:"client_v4" xml:"clientv4" yaml:"Configured IPv4 Client Address" db:"current_client_v4"`
// ServerIPv6 is the gateway end that your SIT address (ClientIPv6) "peers" with.
ServerIPv6 net.IP `json:"server_v6" xml:"serverv6" yaml:"IPv6 Endpoint" db:"tunnel_server_v6"`
// ClientIPv6 is the address that should be assigned on your server's SIT interface.
ClientIPv6 net.IP `json:"client_v6" xml:"clientv6" yaml:"IPv6 Tunnel Client Address" db:"tunnel_client_v6"`
// Routed64 is the IPv6 prefix that gets routed to ClientIPv6. All tunnels have this.
Routed64 TunPrefix `json:"routed_64" xml:"routed64" yaml:"Routed /64" db:"prefix_64"`
// Routed48 may or may not be present, and only available after a certain level of HE certification has been completed and it has been allocated in the web UI.
Routed48 *TunPrefix `json:"routed_48,omitempty" xml:"routed48,omitempty" yaml:"Routed /48,omitempty" db:"prefix_48"`
// RDNS1 is the first RDNS you have specified for the tunnel, if any.
RDNS1 *string `json:"rdns_1,omitempty" xml:"rdns1,omitempty" yaml:"RDNS #1,omitempty" db:"rdns_1"`
// RDNS2 is the second RDNS you have specified for the tunnel, if any.
RDNS2 *string `json:"rdns_2,omitempty" xml:"rdns2,omitempty" yaml:"RDNS #2,omitempty" db:"rdns_2"`
// RDNS3 is the third RDNS you have specified for the tunnel, if any.
RDNS3 *string `json:"rdns_3,omitempty" xml:"rdns3,omitempty" yaml:"RDNS #3,omitempty" db:"rdns_3"`
// RDNS4 is the fourth RDNS you have specified for the tunnel, if any.
RDNS4 *string `json:"rdns_4,omitempty" xml:"rdns4,omitempty" yaml:"RDNS #4,omitempty" db:"rdns_4"`
// RDNS5 is the fifth RDNS you have specified for the tunnel, if any.
RDNS5 *string `json:"rdns_5,omitempty" xml:"rdns5,omitempty" yaml:"RDNS #5,omitempty" db:"rdns_5"`
// TunCfg is the tunnel as defined in the local configuration file associated with this Tunnel.
TunCfg *conf.Tunnel `json:"-" xml:"-" yaml:"-"`
client *resty.Client
2024-12-17 17:39:10 -05:00
}
2025-02-04 12:14:08 -05:00
// HTTPError is a handler for non-success HTTP(S) requests.
type HTTPError struct {
2025-02-04 12:14:08 -05:00
// Code is the status code as reported by the server.
Code int `json:"code" xml:"code,attr" yaml:"Status Code"`
// CodeStr is a more human-friendly string. It includes Code.
CodeStr string `json:"code_str" xml:"code_str,attr" yaml:"Status Code (Detailed)"`
// Message is any message sent from the server in the response's body, if any.
Message *string `json:"message,omitempty" xml:",chardata" yaml:"Error Message,omitempty"`
// Resp is the actual response received.
Resp *resty.Response `json:"-" xml:"-" yaml:"-"`
2024-12-17 17:39:10 -05:00
}