libsoratun

package
v0.0.0-...-fc9d9e6 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2023 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	UnifiedEndpointHostname = "100.127.69.42"
	UnifiedEndpointPort     = 80
)
View Source
const (
	SoracomNameServer1 = "100.127.0.53"
	SoracomNameServer2 = "100.127.1.53"
)

Variables

View Source
var Revision = "dev"

Functions

This section is empty.

Types

type ArcSession

type ArcSession struct {
	// ArcServerPeerPublicKey is WireGuard public key of the SORACOM Arc server.
	ArcServerPeerPublicKey Key `json:"arcServerPeerPublicKey"`
	// ArcServerEndpoint is a UDP endpoint of the SORACOM Arc server.
	ArcServerEndpoint *UDPAddr `json:"arcServerEndpoint"`
	// ArcAllowedIPs holds IP addresses allowed for routing from the SORACOM Arc server.
	ArcAllowedIPs []*IPNet `json:"arcAllowedIPs"`
	// ArcClientPeerPrivateKey holds private key from SORACOM Arc server.
	ArcClientPeerPrivateKey Key `json:"arcClientPeerPrivateKey,omitempty"`
	// ArcClientPeerIpAddress is an IP address for this client.
	ArcClientPeerIpAddress netip.Addr `json:"arcClientPeerIpAddress,omitempty"`
}

ArcSession holds SORACOM Arc configurations received from the server.

type Config

type Config struct {
	// PrivateKey is WireGuard private key.
	PrivateKey Key `json:"privateKey"`
	// ArcSession holds connection information provided from SORACOM Arc server.
	ArcSession *ArcSession `json:"arcSessionStatus,omitempty"`
	// LogLevel specifies logging level, verbose (2), error (1), or silent (0).
	LogLevel int `json:"logLevel"`
}

Config holds SORACOM Arc client configurations.

func NewConfig

func NewConfig(configJson []byte) (*Config, error)

NewConfig creates a new Config from a byte array of JSON.

func (*Config) String

func (c *Config) String() string

String returns string representation of Config. The private key is masked.

type IPNet

type IPNet net.IPNet

IPNet is an alias for net.IPNet.

func (*IPNet) UnmarshalText

func (n *IPNet) UnmarshalText(text []byte) error

UnmarshalText converts a byte array into IPNet. UnmarshalText returns error if invalid CIDR is provided.

type Key

type Key wgtypes.Key

Key is an alias for wgtypes.Key.

func (*Key) AsHexString

func (k *Key) AsHexString() string

AsHexString returns hexadecimal encoding of Key.

func (*Key) AsWgKey

func (k *Key) AsWgKey() *wgtypes.Key

AsWgKey converts Key back to wgtypes.Key.

func (*Key) UnmarshalText

func (k *Key) UnmarshalText(text []byte) error

UnmarshalText decodes a byte array of private key to the Key. If text is invalid WireGuard key, UnmarshalText returns an error.

type Params

type Params struct {
	// Method is an HTTP method of the request. Only GET or POST is supported.
	Method string
	// Path is a path of the request.
	Path string
	// Body is a body of the request.
	Body string
}

Params is a set of parameters for HTTP request.

type UDPAddr

type UDPAddr struct {
	IP          net.IP
	Port        int
	RawEndpoint []byte
}

UDPAddr represents the UDP address with keeping original endpoint.

func (UDPAddr) String

func (a UDPAddr) String() string

String returns string representation of UDPAddr for WireGuard configuration.

func (*UDPAddr) UnmarshalText

func (a *UDPAddr) UnmarshalText(text []byte) error

UnmarshalText converts a byte array into UDPAddr. UnmarshalText returns error if the format is invalid (not "ip" or "ip:port"), IP address specified is invalid, or the port is not a 16-bit unsigned integer.

type UnifiedEndpointHTTPClient

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

UnifiedEndpointHTTPClient is an HTTP client that can be used to communicate with SORACOM Unified Endpoint.

func NewUnifiedEndpointHTTPClient

func NewUnifiedEndpointHTTPClient(config Config) (*UnifiedEndpointHTTPClient, error)

NewUnifiedEndpointHTTPClient creates a new HTTP client specific for the SORACOM Unified Endpoint.

Args: - `config`: A Config object containing the configuration for the SORACOM Arc connection.

Returns: - `*UnifiedEndpointHTTPClient`: A pointer to the created UnifiedEndpointHTTPClient and an error object. If there's any error occurred during setting up the tunnel connection or parsing the endpoint URL, the error will be returned.

The created client uses the http.Transport with a custom DialContext for making HTTP requests. The User-Agent header for all requests made by this client is set to "libsoratun/0.0.1".

func (*UnifiedEndpointHTTPClient) DoRequest

func (c *UnifiedEndpointHTTPClient) DoRequest(req *http.Request) (*http.Response, error)

DoRequest sends an HTTP request and returns the response.

Args: - `req`: A pointer to the http.Request object to be sent.

Returns: - `*http.Response`: A pointer to the http.Response, and an error object.

func (*UnifiedEndpointHTTPClient) MakeRequest

func (c *UnifiedEndpointHTTPClient) MakeRequest(params *Params) (*http.Request, error)

MakeRequest creates a new HTTP request based on provided parameters.

Args: - `params`: A Params struct containing the parameters for the request.

  • `params.Method`: The HTTP method of the request. Only GET or POST is supported. Any extra spaces are trimmed.
  • `params.Path`: The path of the request. It cannot be empty, and any leading slashes are removed.
  • `params.Body`: The body of the request. It cannot be empty.

Returns: - `*http.Request`: A pointer to the created http.Request, and an error object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL