Documentation
¶
Index ¶
- Constants
- type Client
- func (c *Client) ClientRegister(ctx context.Context, req ClientRegisterRequest) (ClientRegisterResponse, error)
- func (c *Client) LaunchTunnel(ctx context.Context, cfg TunnelConfig) (*Tunnel, error)
- func (c *Client) Request(ctx context.Context, method, path string, body interface{}) (*http.Response, error)
- type ClientRegisterRequest
- type ClientRegisterResponse
- type Error
- type Key
- type Response
- type Tunnel
- type TunnelConfig
- type TunnelVersion
Constants ¶
const TunnelPort = 8090
TunnelPort is the port in the virtual wireguard network stack that the listener is listening on.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client provides HTTP methods for the tunneld API and a full wireguard tunnel client implementation.
func (*Client) ClientRegister ¶
func (c *Client) ClientRegister(ctx context.Context, req ClientRegisterRequest) (ClientRegisterResponse, error)
func (*Client) LaunchTunnel ¶
LaunchTunnel makes a request to the tunneld server to register the client's tunnel using the client's public key, then establishes a wireguard connection to the server and returns a *Tunnel. Connections can be accepted from tunnel.Listener.
type ClientRegisterRequest ¶
type ClientRegisterRequest struct { Version TunnelVersion `json:"version"` PublicKey device.NoisePublicKey `json:"public_key"` }
type ClientRegisterResponse ¶
type ClientRegisterResponse struct { Version TunnelVersion `json:"version"` ReregisterWait time.Duration `json:"reregister_wait"` // TunnelURLs contains a list of valid URLs that will be forwarded from the // server to this tunnel client once connected. The first URL is the // preferred URL, and the other URLs are provided for compatibility // purposes only. // // The order of the URLs changes based on the Version field in the request. TunnelURLs []string `json:"tunnel_urls"` ClientIP netip.Addr `json:"client_ip"` ServerEndpoint string `json:"server_endpoint"` ServerIP netip.Addr `json:"server_ip"` ServerPublicKey device.NoisePublicKey `json:"server_public_key"` WireguardMTU int `json:"wireguard_mtu"` }
type Error ¶
type Error struct { Response // contains filtered or unexported fields }
Error represents an unaccepted or invalid request to the API.
func (*Error) StatusCode ¶
type Key ¶
type Key struct {
// contains filtered or unexported fields
}
Key is a Wireguard private or public key.
func FromNoisePrivateKey ¶ added in v0.1.1
func FromNoisePrivateKey(k device.NoisePrivateKey) Key
FromNoisePrivateKey converts a device.NoisePrivateKey to a Key.
func FromNoisePublicKey ¶ added in v0.1.1
func FromNoisePublicKey(k device.NoisePublicKey) Key
FromNoisePublicKey converts a device.NoisePublicKey to a Key.
func GeneratePrivateKey ¶
GenerateWireguardPrivateKey generates a new wireguard private key using secure cryptography. The caller should store the key (using key.String()) in a safe place like the user's home directory, and use it in the future rather than generating a new key each time.
func ParsePrivateKey ¶
ParsePrivateKey parses a private key generated using key.String().
func ParsePublicKey ¶ added in v0.1.1
ParsePublicKey parses a public key generated using key.String().
func (Key) NoisePrivateKey ¶
func (k Key) NoisePrivateKey() (device.NoisePrivateKey, error)
NoisePrivateKey returns the device.NoisePrivateKey for the key. If the key is not a private key, an error is returned.
func (Key) NoisePublicKey ¶
func (k Key) NoisePublicKey() device.NoisePublicKey
NoisePublicKey returns the device.NoisePublicKey for the key. If the key is a private key, it is converted to a public key automatically.
type Tunnel ¶
type TunnelConfig ¶
type TunnelConfig struct { Log slog.Logger // Version denotes which version of the tunnel URL specification to use. // Undefined version is treated as the latest version. Version TunnelVersion // PrivateKey is the Wireguard private key. You can use GeneratePrivateKey // to generate a new key. It should be stored in a safe place for future // tunnel sessions, otherwise you will get a new hostname. PrivateKey Key }
type TunnelVersion ¶
type TunnelVersion int
TunnelVersion is the version of the tunnel URL specification.
const ( // TunnelVersion1 is the "old style" tunnel URL. Each hostname base is 32 // characters long and is base16 (hex) encoded. TunnelVersion1 TunnelVersion = 1 // TunnelVersion2 is the "new style" tunnel URL. Each hostname base is ~12 // characters long and is base32 encoded. TunnelVersion2 TunnelVersion = 2 TunnelVersionLatest = TunnelVersion2 )