Documentation ¶
Index ¶
Constants ¶
const (
PayloadMessageType messageType = iota
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // NodeName of this node. This must be unique in the cluster. // If it is not set, set it to the host name of the running machine. NodeName string // BroadcastTimeout is the amount of time to wait for a broadcast message to be sent // to the cluster. If this is not set, a timeout of 5 seconds will be set. BroadcastTimeout time.Duration // MemberlistConfig is the memberlist configuration that P2P will // use to do the underlying membership management and gossip. MemberlistConfig *memberlist.Config // MessageBuffer is used to control how many messages are buffered.This is // used to prevent messages that have already been received from being redelivered. // The buffer must be large enough to handle all recent messages. MessageBuffer int // HandleFunc is a hook function used by the client to process messages and // must not be blocked. HandleFunc func([]byte) error // LogOutput is the location to write logs to. If this is not set, // logs will go to stderr. LogOutput io.Writer // Logger is a custom logger which you provide. If Logger is set, it will use // this for the internal logger. If Logger is not set, it will fall back to the // behavior for using LogOutput. You cannot specify both LogOutput and Logger // at the same time. Logger *log.Logger }
Config is the configuration for creating a P2P-Node instance.
func DefaultConfig ¶
func DefaultConfig() Config
DefaultConfig provides a default p2p node configuration
type LamportClock ¶
type LamportClock struct {
// contains filtered or unexported fields
}
LamportClock is a thread safe implementation of a lamport clock. It uses efficient atomic operations for all of its functions, falling back to a heavy lock only if there are enough CAS failures.
func (*LamportClock) Increment ¶
func (l *LamportClock) Increment() LamportTime
Increment is used to increment and return the value of the lamport clock
func (*LamportClock) Time ¶
func (l *LamportClock) Time() LamportTime
Time is used to return the current value of the lamport clock
func (*LamportClock) Witness ¶
func (l *LamportClock) Witness(v LamportTime)
Witness is called to update our local clock if necessary after witnessing a clock value received from another process
type Node ¶
type Node struct { Config *Config HandleFunc func([]byte) error // contains filtered or unexported fields }
func (*Node) Join ¶
Join joins an existing P2P cluster. Returns the number of nodes successfully contacted. The returned error will be non-nil only in the case that no nodes could be contacted.
func (*Node) Members ¶
func (n *Node) Members() []nodeState
Members returns the status information of all members
func (*Node) RegisterHandleFunc ¶
func (*Node) SendMessage ¶
SendMessage is a method that needs to be called by the client to send messages. messageType is used to distinguish message types