Documentation ¶
Overview ¶
Package tunnel implements websocket communication between the cloud server and edge clients.
Index ¶
- Constants
- Variables
- type AfterConnectHook
- type AfterConnectToHook
- type AfterDisconnectHook
- type ClientCloseHandleFunc
- type CloudBlackList
- type CloudTunnel
- type ClusterNameChecker
- type ControllerManagerMsgHandleFunc
- type ControllerTunnel
- type EdgeTunnel
- type RedirectFunc
- type TunnelReadMessageFunc
- type WSClient
Constants ¶
Variables ¶
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 ¶
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 ¶
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 ¶
NewWSClient returns a websocket client.
func (*WSClient) ReadMessage ¶
ReadMessage reads binary message from connection.
func (*WSClient) WriteMessage ¶
WriteMessage writes binary message to connection.