Movatterモバイル変換


[0]ホーム

URL:


tunnelsdk

package
v0.1.12Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2023 License:MITImports:21Imported by:6

Details

Repository

github.com/coder/wgtunnel

Links

Documentation

Index

Constants

View Source
const TunnelPort = 8090

TunnelPort is the port in the virtual wireguard network stack that thelistener is listening on.

Variables

This section is empty.

Functions

This section is empty.

Types

typeClient

type Client struct {HTTPClient *http.ClientURL        *url.URL}

Client provides HTTP methods for the tunneld API and a full wireguard tunnelclient implementation.

funcNew

func New(serverURL *url.URL) *Client

New creates a tunneld client for the provided URL.

func (*Client)LaunchTunnel

func (c *Client) LaunchTunnel(ctxcontext.Context, cfgTunnelConfig) (*Tunnel,error)

LaunchTunnel makes a request to the tunneld server to register the client'stunnel using the client's public key, then establishes a wireguard connectionto the server and returns a *Tunnel. Connections can be accepted fromtunnel.Listener.

func (*Client)Request

func (c *Client) Request(ctxcontext.Context, method, pathstring, body interface{}) (*http.Response,error)

Request performs an HTTP request with the body provided. The caller isresponsible for closing the response body.

typeClientRegisterRequest

type ClientRegisterRequest struct {VersionTunnelVersion         `json:"version"`PublicKeydevice.NoisePublicKey `json:"public_key"`}

typeClientRegisterResponse

type ClientRegisterResponse struct {VersionTunnelVersion `json:"version"`ReregisterWaittime.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"`ClientIPnetip.Addr `json:"client_ip"`ServerEndpointstring                `json:"server_endpoint"`ServerIPnetip.Addr            `json:"server_ip"`ServerPublicKeydevice.NoisePublicKey `json:"server_public_key"`WireguardMTUint                   `json:"wireguard_mtu"`}

typeError

type Error struct {Response// contains filtered or unexported fields}

Error represents an unaccepted or invalid request to the API.

func (*Error)Error

func (e *Error) Error()string

func (*Error)Friendly

func (e *Error) Friendly()string

func (*Error)StatusCode

func (e *Error) StatusCode()int

typeKey

type Key struct {// contains filtered or unexported fields}

Key is a Wireguard private or public key.

funcFromNoisePrivateKeyadded inv0.1.1

func FromNoisePrivateKey(kdevice.NoisePrivateKey)Key

FromNoisePrivateKey converts a device.NoisePrivateKey to a Key.

funcFromNoisePublicKeyadded inv0.1.1

func FromNoisePublicKey(kdevice.NoisePublicKey)Key

FromNoisePublicKey converts a device.NoisePublicKey to a Key.

funcGeneratePrivateKey

func GeneratePrivateKey() (Key,error)

GenerateWireguardPrivateKey generates a new wireguard private key usingsecure cryptography. The caller should store the key (using key.String()) ina safe place like the user's home directory, and use it in the future ratherthan generating a new key each time.

funcParsePrivateKey

func ParsePrivateKey(keystring) (Key,error)

ParsePrivateKey parses a private key generated using key.String().

funcParsePublicKeyadded inv0.1.1

func ParsePublicKey(keystring) (Key,error)

ParsePublicKey parses a public key generated using key.String().

func (Key)Hashadded inv0.1.3

func (kKey) Hash()string

Hash returns the SHA512 hash of the key.

func (Key)HexString

func (kKey) HexString()string

HexString returns the hex string representation of the key.

func (Key)IsPrivate

func (kKey) IsPrivate()bool

IsPrivate returns true if the key is a private key.

func (Key)IsZero

func (kKey) IsZero()bool

IsZero returns true if the Key is the zero value.

func (Key)NoisePrivateKey

func (kKey) NoisePrivateKey() (device.NoisePrivateKey,error)

NoisePrivateKey returns the device.NoisePrivateKey for the key. If the key isnot a private key, an error is returned.

func (Key)NoisePublicKey

func (kKey) NoisePublicKey()device.NoisePublicKey

NoisePublicKey returns the device.NoisePublicKey for the key. If the key is aprivate key, it is converted to a public key automatically.

func (Key)PublicKey

func (kKey) PublicKey() (Key,error)

PublicKey returns the public key component of the Wireguard private key. Ifthe key is not a private key, an error is returned.

func (Key)String

func (kKey) String()string

String returns a base64 encoded string representation of the key.

typeResponse

type Response struct {Messagestring `json:"message"`Detailstring `json:"detail,omitempty"`}

typeTunnel

type Tunnel struct {URL       *url.URLOtherURLs []*url.URLListenernet.Listener// contains filtered or unexported fields}

func (*Tunnel)Close

func (t *Tunnel) Close()error

func (*Tunnel)Wait

func (t *Tunnel) Wait() <-chan struct{}

typeTunnelConfig

type TunnelConfig struct {Logslog.Logger// Version denotes which version of the tunnel URL specification to use.// Undefined version is treated as the latest version.VersionTunnelVersion// 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.PrivateKeyKey}

typeTunnelVersion

type TunnelVersionint

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.TunnelVersion1TunnelVersion = 1// TunnelVersion2 is the "new style" tunnel URL. Each hostname base is ~12// characters long and is base32 encoded.TunnelVersion2TunnelVersion = 2TunnelVersionLatest =TunnelVersion2)

Source Files

View all Source files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp