tunnel

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 28, 2019 License: Apache-2.0 Imports: 16 Imported by: 0

Documentation

Overview

Package tunnel implements websocket communication between the cloud server and edge clients.

Index

Constants

View Source
const (
	WriteTimeout = time.Second * 15
	ReadTimeout  = time.Second * 15
	IdleTimeout  = time.Second * 60
	StopTimeout  = time.Second * 15
)

Variables

View Source
var (
	ControllerSendChanBufferSize = 1000
)

Functions

This section is empty.

Types

type AfterConnectHook

type AfterConnectHook func(*config.ClusterRegistry)

AfterConnectHook is a function to handle wsclient connection event.

type AfterConnectToHook

type AfterConnectToHook func()

AfterConnectToHook is a function of edge tunnel to call after connection established.

type AfterDisconnectHook

type AfterDisconnectHook func()

AfterDisconnectHook is a function of edge tunnel to call after disconnect from parent.

type ClientCloseHandleFunc

type ClientCloseHandleFunc func(*config.ClusterRegistry)

ClientCloseHandleFunc is a function to handle wsclient close event.

type CloudBlackList

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

CloudBlackList records cloud address to blacklist.

Once disconnect from a parent, child use parent neighbor which out of blacklist to reconnect. If no parent neighbor available, get one from blacklist use FIFO for blacklist.

func (*CloudBlackList) Clear

func (c *CloudBlackList) Clear()

Clear all cloud address in the list.

func (*CloudBlackList) Find

func (c *CloudBlackList) Find(key string) bool

Find whether the address is in the list.

func (*CloudBlackList) Pop

func (c *CloudBlackList) Pop() string

Pop the front cloud address from list.

func (*CloudBlackList) Push

func (c *CloudBlackList) Push(addr string)

Push a cloud address to list.

type CloudTunnel

type CloudTunnel interface {
	// Start will start cloudtunnel.
	Start() error
	// Stop will shut down the server and close all websocket connection.
	Stop() error
	// Send sends binary message to the given wsclient.
	Send(clusterName string, msg []byte) error
	// Broadcast sends binary message to all connected wsclient.
	Broadcast(msg []byte)
	// SendToControllerManager sends msg to anyone of controller manager.
	SendToControllerManager([]byte) error
	// RegistRedirectFunc registers a func which calls before CheckNameValidFunc.
	RegistRedirectFunc(fn RedirectFunc)
	// RegistCheckNameValidFunc registers ClusterNameChecker.
	RegistCheckNameValidFunc(fn ClusterNameChecker)
	// RegistAfterConnectHook registers AfterConnectHook.
	RegistAfterConnectHook(fn AfterConnectHook)
	// RegistReturnMessageFunc registers TunnelReadMessageFunc.
	RegistReturnMessageFunc(fn TunnelReadMessageFunc)
	// RegistClientCloseHandler registers ClientCloseHandleFunc.
	RegistClientCloseHandler(fn ClientCloseHandleFunc)
	// RegistControllerManagerMsgHandler regists ControllerManagerMsgHandleFunc.
	RegistControllerManagerMsgHandler(fn ControllerManagerMsgHandleFunc)
}

CloudTunnel is interface for cloudtunnel.

func NewCloudTunnel

func NewCloudTunnel(address string) CloudTunnel

NewCloudTunnel returns a new cloudTunnel object.

type ClusterNameChecker

type ClusterNameChecker func(*config.ClusterRegistry) bool

ClusterNameChecker is a function to check cluster name.

type ControllerManagerMsgHandleFunc

type ControllerManagerMsgHandleFunc func(string, []byte) error

ControllerManagerMsgHandleFunc is a function handle msg from controller manager, string is remote address of the controller manager, and []byte is the msg.

type ControllerTunnel

type ControllerTunnel interface {
	// Start will start controllerTunnel.
	Start() error
	// Stop will close the connection of controllerTunnel.
	Stop() error
	// Send sends binary message to websocket connection.
	Send(msg []byte) error
	SendChan() chan clustermessage.ClusterMessage
	// Regist registers receive message handler.
	RegistReceiveMessageHandler(TunnelReadMessageFunc)
	RegistAfterConnectToHook(fn AfterConnectToHook)
}

ControllerTunnel is a iterface for controllerTunnel.

func NewControllerTunnel

func NewControllerTunnel(remoteAddr string) ControllerTunnel

NewControllerTunnel returns a new controllerTunnel object.

type EdgeTunnel

type EdgeTunnel interface {
	// Start will start edgeTunnel.
	Start() error
	// Stop will close the connection of edgeTunnel.
	Stop() error
	// Send sends binary message to websocket connection.
	Send(msg []byte) error
	// Regist registers receive message handler.
	RegistReceiveMessageHandler(TunnelReadMessageFunc)
	RegistAfterConnectToHook(fn AfterConnectToHook)
	RegistAfterDisconnectHook(fn AfterDisconnectHook)
}

EdgeTunnel is a iterface for edgeTunnel.

func NewEdgeTunnel

func NewEdgeTunnel(conf *config.ClusterControllerConfig) EdgeTunnel

NewEdgeTunnel returns a new edgeTunnel object.

type RedirectFunc

type RedirectFunc func() string

RedirectFunc is a function called before ClusterNameChecker, which returns a redirect server address.

type TunnelReadMessageFunc

type TunnelReadMessageFunc func(string, []byte) error

TunnelReadMessageFunc is a function to handle message from tunnel. this function takes 2 arguments, first mean client name(cluster name), the second is message data.

type WSClient

type WSClient struct {
	// Name defines uuid of the client.
	Name string
	// Conn defines websocket connection.
	Conn *websocket.Conn
	// contains filtered or unexported fields
}

WSClient is a websocket client.

func NewWSClient

func NewWSClient(name string, conn *websocket.Conn) *WSClient

NewWSClient returns a websocket client.

func (*WSClient) Close

func (c *WSClient) Close() error

Close closes websocket connection.

func (*WSClient) ReadMessage

func (c *WSClient) ReadMessage() ([]byte, error)

ReadMessage reads binary message from connection.

func (*WSClient) WriteMessage

func (c *WSClient) WriteMessage(msg []byte) error

WriteMessage writes binary message to connection.

Jump to

Keyboard shortcuts

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