api

package
v0.0.0-...-6dd53b5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	KeyRawRequest = PluginKeyType("_plugin_key_request")
)

Constants used in HTTP API

View Source
const (
	URIOpenTunnel = "/api/v1/tunnel"
)

API path group

Variables

This section is empty.

Functions

func ErrorWithCode

func ErrorWithCode(code message.StatusCode, err error) error

ErrorWithCode returns a error with the specified error message and code

Types

type Client

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

Client is used to access with the remote gateway

func NewClient

func NewClient(gateway, key string, tls bool) *Client

NewClient returns a new client instance which can be used to interact with the gateway.

func (*Client) OpenTunnel

func (c *Client) OpenTunnel(src, dst string) error

OpenTunnel request the server to open tunnel between the two peers. The source and destionation virtual network address need to be provided.

type Error

type Error struct {
	Code message.StatusCode
	Err  error
}

Error represent a dedicated error type, which contain the API status code

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface

type Notifier

type Notifier interface {
	OpenTunnel(src, dst *PeerInfo)
}

Notifier represents a notifier which is used to synchronize the peer information to the remote peer when any of the peer tries to establish a connection between the them.

type OpenTunnelRequest

type OpenTunnelRequest struct {
	Version     string `json:"version"`
	Algorithm   string `json:"algorithm"`
	Nonce       string `json:"nonce"`
	Cipher      string `json:"cipher"`
	Source      string `json:"source"`
	Destination string `json:"destination"`
}

OpenTunnelRequest represents the request when trying to open a tunnel

type OpenTunnelResponse

type OpenTunnelResponse struct {
	Encrypt string `json:"encrypt"`
}

OpenTunnelResponse represent the response of trying to open a tunnel

type PeerInfo

type PeerInfo struct {
	VirtAddress   string    `json:"virt_address"`
	UDPAddress    string    `json:"udp_address"`
	LastHeartbeat time.Time `json:"-"`
}

PeerInfo represents the peer of the Zetamesh system.

type PluginKeyType

type PluginKeyType string

PluginKeyType represents the unique type of plugin key

type Result

type Result struct {
	Code  message.StatusCode `json:"code"`
	Error string             `json:"error,omitempty"`
	Data  interface{}        `json:"data,omitempty"`
}

Result represent the common part of API response

type Server

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

Server represents the HTTP server which serves for current gateway.

func NewServer

func NewServer(notifier Notifier, key string) *Server

NewServer returns a new gateway server instance and the gateway server is used to handle the HTTP request and store the peer information.

func (*Server) Heartbeat

func (s *Server) Heartbeat(remote *net.UDPAddr, heartbeat *message.CtrlHeartbeat)

Heartbeat handles the peer heartbeat packet and update the peer information to the latest to keep it up to date.

func (*Server) OpenTunnel

func (s *Server) OpenTunnel(req *OpenTunnelRequest) (*OpenTunnelResponse, error)

OpenTunnel handles the `OpenTunnelRequest` POST request. It will validate the client information of `Version/Key` and notify the two endpoint if the peer validation successfully.

func (*Server) Peer

func (s *Server) Peer(virtAddr string) *PeerInfo

Peer returns the peers and nil will be returned if the peer corresponding to the virtual address is not found.

Jump to

Keyboard shortcuts

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