Documentation ¶
Overview ¶
TODO Add heartbeat mechanism
This file contains structs and functions for the nodes.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Connection ¶
type Connection struct { Conn *net.TCPConn // The connection Data interface{} // The remote node's extra data }
Resembles a connection between two nodes.
func (Connection) Write ¶
func (c Connection) Write(msg Message) error
Write a message to the connection
type ErrorMessage ¶
type ErrorMessage struct {
Err error
}
A message containing only errors
func (ErrorMessage) Msg ¶
func (m ErrorMessage) Msg() interface{}
func (ErrorMessage) Type ¶
func (m ErrorMessage) Type() string
type GreetingMessage ¶
type GreetingMessage struct { Id int Data interface{} }
The message a node sends to the node it's newly connected to with its id to make authentication easier
func (GreetingMessage) Msg ¶
func (m GreetingMessage) Msg() interface{}
func (GreetingMessage) Type ¶
func (m GreetingMessage) Type() string
type IntroduceMessage ¶
type IntroduceMessage struct { Addr string Data interface{} }
The message a new node sends to the master with its information
func (IntroduceMessage) Msg ¶
func (m IntroduceMessage) Msg() interface{}
func (IntroduceMessage) Type ¶
func (m IntroduceMessage) Type() string
type Message ¶
type Message interface { Type() string Msg() interface{} }
The Message interface, this is supposed to be customized (for example Msg is encoded in gob).
type NewNodeMessage ¶
type NewNodeMessage struct { Id int // The Id Addr string // The address to connect to Data interface{} // The new node's data }
The message the master sends when all nodes when a new node joins
func (NewNodeMessage) Msg ¶
func (m NewNodeMessage) Msg() interface{}
func (NewNodeMessage) Type ¶
func (m NewNodeMessage) Type() string
type Node ¶
type Node struct { Addr string // Incoming connections address Ready bool // Whether is node is ready for connections Id int // This node's ID NextId int // Next client's id Message chan Message // The channel to forward messages to Nodes *sync.Map // A map that maps other node ids to their connections. Data interface{} // Allows the node to have extra information attached to it }
The node is the general data type in go-cluster, it resembles a node in the cluster
func CreateCluster ¶
Creates a new master node This new node will introduce other nodes to each other.
func JoinCluster ¶
Creates a new node and connects to the master
type ReadyMessage ¶
The message the master sends to a newly connected node with its id
func (ReadyMessage) Msg ¶
func (m ReadyMessage) Msg() interface{}
func (ReadyMessage) Type ¶
func (m ReadyMessage) Type() string