clusterrouter

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: 7 Imported by: 0

Documentation

Overview

Package clusterrouter manages cluster route of subtree and neighbor.

Route information keeps my childs, neighbor and parent neighbor.

There are 2 ways to receive a route message:

1. cloud-tunnel: must be a child-connect/disconnect message.

Once get one, route should be updated, besides, notify all other childs, so they can update their neighbor.

2. edge-tunnel(EdgeToClusterChan): my neighbor or parent neighbor may changed.

If my parent neighbor changed, update my route, if my neighbor changed, notify my childs in addition.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func UpdateRouter

func UpdateRouter(msg *clustermessage.ClusterMessage, notifier RouterNotifier)

UpdateRouter updates router of current cluster and notify child.

Types

type ClusterRouter

type ClusterRouter struct {
	Childs         map[string]string // cluster name -> cluster tunnel listen address
	Neighbor       map[string]string // same as above
	ParentNeighbor map[string]string // same as above
	// contains filtered or unexported fields
}

ClusterRouter consists of all router info of a node.

func Router

func Router() *ClusterRouter

Router returns the default cluster router.

func (*ClusterRouter) AddChild

func (cr *ClusterRouter) AddChild(clusterName, listen string, notifier RouterNotifier) error

AddChild add a child named clusterName with listen addr, and call notifier if add successful.

func (*ClusterRouter) AddRoute

func (cr *ClusterRouter) AddRoute(to, port string) error

AddRoute add a route. to is cluster name of node in subtree, port is cluster name of a child which can reach to node.

func (*ClusterRouter) DelChild

func (cr *ClusterRouter) DelChild(clusterName string, notifier RouterNotifier)

DelChild delete a chiled named clusterName, and call notifier if delete successful.

func (*ClusterRouter) DelRoute

func (cr *ClusterRouter) DelRoute(to, port string)

DelRoute delete a route. to is cluster name of node in subtree, port is cluster name of a child which can reach to node.

func (*ClusterRouter) Deserialize

func (cr *ClusterRouter) Deserialize(b []byte) error

Deserialize deserializes a ClusterRouter so as to synchronize with neighbors.

func (*ClusterRouter) HasChild

func (cr *ClusterRouter) HasChild(clusterName string) bool

HasChild returns if the current node has a child named clusterName.

func (*ClusterRouter) HasRoute

func (cr *ClusterRouter) HasRoute(to, port string) bool

HasRoute returns if the current node has a route from "port" to "to".

func (*ClusterRouter) NeighborRouterMessage

func (cr *ClusterRouter) NeighborRouterMessage() *clustermessage.ClusterMessage

NeighborRouterMessage wrap router info to cluster message.

func (*ClusterRouter) ParentNeighbors

func (cr *ClusterRouter) ParentNeighbors() map[string]string

ParentNeighbors return neighbors of parent cluster. key is cluster name, and value is listen address of the cluster.

func (*ClusterRouter) PortsToSubtreeClusters

func (cr *ClusterRouter) PortsToSubtreeClusters(clusters *[]string) map[string][]string

PortsToSubtreeClusters get ports which can reach to clusters. return is a map whose key is cluster name of a port, value is subtree names of port.

func (*ClusterRouter) Serialize

func (cr *ClusterRouter) Serialize() ([]byte, error)

Serialize serializes a ClusterRouter so as to send to neighbors.

func (*ClusterRouter) SubTreeClusters

func (cr *ClusterRouter) SubTreeClusters() []string

SubTreeClusters return all cluster names under current cluster.

func (*ClusterRouter) SubTreeMessage

func (cr *ClusterRouter) SubTreeMessage() *clustermessage.ClusterMessage

SubTreeMessage wrap subtree router info to cluster message.

func (*ClusterRouter) SubTreeOfPort

func (cr *ClusterRouter) SubTreeOfPort(port string) []string

SubTreeOfPort return a slice of cluster names which is in the subtree under a certain port.

type RouterNotifier

type RouterNotifier func(*clustermessage.ClusterMessage, ...string)

RouterNotifier is a func to notify childs(...) of route info of current cluster.

type SubTreeRouter

type SubTreeRouter map[string]string

SubTreeRouter is a router which represents from a certain port to a certain node in subtree. The key is the cluster name of the node in subtree, and the value is the cluster name of the node directly connect to current node. A key-value pair means, in current node, you can reach to "key" from "value".

func SubtreeFromClusterController

func SubtreeFromClusterController(msg *clustermessage.ClusterMessage) SubTreeRouter

SubtreeFromClusterController get subtree router info from a cluster message.

func (*SubTreeRouter) Serialize

func (s *SubTreeRouter) Serialize() ([]byte, error)

Serialize serializes the SubTreeRouter so as to send to neighbors.

Jump to

Keyboard shortcuts

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