api

package
v0.0.0-...-9adf2cc Latest Latest
Warning

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

Go to latest
Published: May 17, 2023 License: GPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Ping gatewayMsgType = iota
	NetworkJoin
	NetworkLeave
	DeviceUpdate

	Disconnect gatewayMsgType = -1
	Connect    gatewayMsgType = -2
)

Variables

View Source
var (
	ErrNotFound = httpError(404)
)

Functions

This section is empty.

Types

type API

type API struct {
	// Server is where the Pikonet Rendezvous server is hosted.
	// This must not change after the first call.
	Server string

	// Token is the Rendezvous token we receive after logging in.
	// This must be set, or will be set with a call to Login.
	//
	// Token must not change once set.
	Token string

	HTTP *http.Client
	// contains filtered or unexported fields
}

API handles API calls.

func (*API) Device

func (a *API) Device(ctx context.Context, id int64) (Device, error)

Device returns info for one specific device.

func (*API) Devices

func (a *API) Devices(ctx context.Context) ([]Device, error)

Devices returns a list of devices attached to your user.

func (*API) Endpoint

func (a *API) Endpoint(ep Endpoint) string

func (*API) Gateway

func (a *API) Gateway(ctx context.Context, c chan<- GatewayMsg, dev int64, port int)

func (*API) GatewaySend

func (a *API) GatewaySend(ctx context.Context, msg GatewayMsg) error

func (*API) JoinNetwork

func (a *API) JoinNetwork(ctx context.Context, dev, nw int64) error

JoinNetwork joins a device to a network.

func (*API) LeaveNetwork

func (a *API) LeaveNetwork(ctx context.Context, dev, nw int64) error

LeaveNetwork removes a device from a network.

func (*API) Login

func (a *API) Login(ctx context.Context, username, password string) error

Login attempts to login to the Rendezvous server.

Login automatically updates the token in the API struct. If error is nil, assume it is updated.

func (*API) Network

func (a *API) Network(ctx context.Context, id int64) (Network, error)

Network returns info for one specific network.

func (*API) Networks

func (a *API) Networks(ctx context.Context) ([]Network, error)

Network returns a list of networks attached to your user.

func (*API) NewDevice

func (a *API) NewDevice(ctx context.Context, name, key string) (Device, error)

NewDevice adds a new device to the user.

func (*API) NewNetwork

func (a *API) NewNetwork(ctx context.Context, name string) (Network, error)

NewNetwork adds a new network to the user.

func (*API) PunchDetails

func (a *API) PunchDetails(ctx context.Context) (PunchDetails, error)

PunchDetails fetches Pikopunch details from the rendezvous server.

type Device

type Device struct {
	ID    int64  `json:"id"`
	Owner int64  `json:"owner"`
	Name  string `json:"name"`

	// PublicKey is the WireGuard public key for this device.
	PublicKey string `json:"key"`

	// IP is the Pikonet IP, which likely means a random IP in the range
	// fd00::/32.
	// This IP is not routable by the Internet, and only by Pikonet nodes.
	IP string `json:"ip,omitempty"`

	Endpoint string `json:"endpoint,omitempty"`

	Networks []Network `json:"networks,omitempty"`

	PrivateKey string `json:"-"`
}

Device represents a device, its unique Pikonet IP, and its public key.

type Endpoint

type Endpoint string
const (
	EndpointAuth Endpoint = "/auth"

	EndpointListDevices  Endpoint = "/list/devices"
	EndpointListNetworks Endpoint = "/list/networks"

	EndpointNewDevice  Endpoint = "/new/device"
	EndpointNewNetwork Endpoint = "/new/network"

	EndpointNetworkInfo Endpoint = "/network/info"

	EndpointDeviceJoin  Endpoint = "/device/join"
	EndpointDeviceLeave Endpoint = "/device/leave"
	EndpointDeviceInfo  Endpoint = "/device/info"

	EndpointGateway Endpoint = "/gateway"
	EndpointPunch   Endpoint = "/punch"
)

type GatewayMsg

type GatewayMsg struct {
	Type gatewayMsgType

	Device  *Device  `json:"device,omitempty"`
	Network *Network `json:"network,omitempty"`
	Remove  bool

	Endpoint  string `json:"endpoint,omitempty"`
	DeviceID  int64  `json:"device_id,omitempty"`
	NetworkID int64  `json:"network_id,omitempty"`

	Delay time.Duration `json:"-"`
	Error error         `json:"-"`
}

type Network

type Network struct {
	ID    int64  `json:"id"`
	Owner int64  `json:"owner"`
	Name  string `json:"name"`

	Devices []Device `json:"devices"`
}

Network represents a network to which devices connect to

type PunchDetails

type PunchDetails struct {
	Endpoint  string `json:"endpoint"`
	IP        string `json:"ip"`
	PublicKey string `json:"public_key"`
}

type User

type User struct {
	ID       int64  `json:"id"`
	Username string `json:"username"`
	Email    string `json:"email"`
	Name     string `json:"name,omitempty"`
}

User represents a rendezvous user.

Jump to

Keyboard shortcuts

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