Documentation ¶
Index ¶
Constants ¶
const (
KeyRawRequest = PluginKeyType("_plugin_key_request")
)
Constants used in HTTP API
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 ¶
NewClient returns a new client instance which can be used to interact with the gateway.
func (*Client) OpenTunnel ¶
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
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 ¶
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.