common

package
v0.0.0-...-370eddc Latest Latest
Warning

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

Go to latest
Published: Jan 18, 2018 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PEER_INFO_REQUEST_CMD = iota
	PEER_INFO_RESPONSE_CMD
	SET_LEADER_CMD
	REPORT_PEER_CMD
	REMOVE_PEER_CMD
	LEADER_DISTANCE_REQUEST_CMD
	LEADER_DISTANCE_RESPONSE_CMD
	SYNC_PEERS_CMD
	PING_CMD
	PONG_CMD
	CHANG_ROBERTS_ID_CMD
	GET_REQUEST_CMD
	GET_RESPONSE_CMD
	SET_REQUEST_CMD
	SET_RESPONSE_CMD
	MAX_CMD
)

Variables

View Source
var NAMES = []string{}/* 201 elements not displayed */

Functions

func DispatchCommand

func DispatchCommand(handler CommandHandler, sender PeerAddr, cmd Command)

func GetInterfaceIPv4Addr

func GetInterfaceIPv4Addr(iface *net.Interface) (net.IP, error)

func GetInterfaceNames

func GetInterfaceNames() string

func GetTransmissionInfoString

func GetTransmissionInfoString(source, from, to, destination PeerAddr) string

func IsTimeoutError

func IsTimeoutError(err error) bool

func PickRandomName

func PickRandomName() string

Types

type ActionHandler

type ActionHandler interface {
	ActionSetValue(value int)
	ActionGetValue()
	ActionStartChRo()
	ActionLeave() bool
	ActionDisconnect()
	ActionSync()
	ActionReconnect()
	ActionReportPeer(addr PeerAddr)
}

type Command

type Command struct {
	Op          int
	Sarg        []string
	Iarg        []int
	Source      PeerAddr
	Destination PeerAddr
	From        PeerAddr
	Ttl         int
	Clock       LamportClock
}

func NewChangRobertIdCmd

func NewChangRobertIdCmd(id int) Command

func NewGetRequestCommand

func NewGetRequestCommand() Command

func NewGetResponseCommand

func NewGetResponseCommand(value int) Command

func NewLeaderDistanceRequestCommand

func NewLeaderDistanceRequestCommand() Command

func NewLeaderDistanceResponseCommand

func NewLeaderDistanceResponseCommand(distance int, direction int) Command

func NewPeerInfoRequestCommand

func NewPeerInfoRequestCommand(name string, leader PeerAddr) Command

func NewPeerInfoResponseCommand

func NewPeerInfoResponseCommand(name string) Command

func NewPingCmd

func NewPingCmd() Command

func NewPongCmd

func NewPongCmd() Command

func NewRemovePeerCommand

func NewRemovePeerCommand(peer PeerAddr, direction int) Command

func NewReportPeerCommand

func NewReportPeerCommand(peer PeerAddr) Command

func NewSetLeaderCommand

func NewSetLeaderCommand(leader PeerAddr, value int) Command

func NewSetRequestCommand

func NewSetRequestCommand(value int) Command

func NewSetResponseCommand

func NewSetResponseCommand() Command

func NewSyncPeersCmd

func NewSyncPeersCmd(peers map[PeerAddr]PeerInfo) Command

func (Command) String

func (cmd Command) String() string

type CommandHandler

type CommandHandler interface {
	NewPeer(sender PeerAddr, addr PeerAddr, name string, shouldReply bool)
	LeaderChanged(sender PeerAddr, leader PeerAddr, value int)

	PeerReported(reportedPeer PeerAddr)
	PeerRemoved(sender PeerAddr, reportedPeer PeerAddr, direction int)
	DistanceRequested(sender PeerAddr, source PeerAddr)
	DistanceReceived(sender PeerAddr, distance int, direction int)
	SyncPeers(sender PeerAddr, values []string)
	Ping(sender PeerAddr, source PeerAddr)
	Pong(sender PeerAddr, source PeerAddr)
	ChRoIdReceived(sender PeerAddr, id int)

	ValueGetRequested(sender PeerAddr, source PeerAddr)
	GotValue(sender PeerAddr, value int)
	ValueSetRequested(sender PeerAddr, source PeerAddr, value int)
	ValueSetConfirmed(sender PeerAddr)
}

type Context

type Context struct {
	Name           string
	ServerAddr     PeerAddr
	PeerId         int
	LinkedPeers    [2]PeerAddr
	Leader         PeerAddr
	LeaderDistance [2]int
	KnownPeers     map[PeerAddr]PeerInfo
	SendNumRetries int
	SendRetryPause time.Duration
	ChRoTimerDur   time.Duration

	StateSync        sync.Mutex
	Sync             sync.Mutex
	StartedChRoTimer int32
	Clock            LamportClock
	StopFlag         bool
	// contains filtered or unexported fields
}

func NewContext

func NewContext(name string, sendNumRetries int, sendRetryPause, chRoTimerDur time.Duration) *Context

func (*Context) AddNewPeer

func (ctx *Context) AddNewPeer(name string, addr PeerAddr)

func (*Context) CASState

func (ctx *Context) CASState(current, new State) bool

func (*Context) GetState

func (ctx *Context) GetState() State

func (*Context) RemovePeer

func (ctx *Context) RemovePeer(addr PeerAddr)

func (*Context) ResolvePeerName

func (ctx *Context) ResolvePeerName(addr PeerAddr) string

func (*Context) SetKnownPeers

func (ctx *Context) SetKnownPeers(peers map[PeerAddr]PeerInfo)

func (*Context) SetState

func (ctx *Context) SetState(new State)

func (*Context) UpdateLinkedPeers

func (ctx *Context) UpdateLinkedPeers()

type LamportClock

type LamportClock struct {
	Value uint64
}

func (LamportClock) String

func (l LamportClock) String() string

func (*LamportClock) SyncAfter

func (l *LamportClock) SyncAfter(remoteClock LamportClock, delta uint64)

type PeerAddr

type PeerAddr string

type PeerInfo

type PeerInfo struct {
	Addr PeerAddr
	Name string
}

type State

type State interface {
	CommandHandler
	ActionHandler
	Name() string
	Init()
}

type Tee

type Tee struct {
	OrigStdout *os.File
	OrigStderr *os.File
	Stdout     *os.File
	Stderr     *os.File
	TeeFile    *os.File
	// contains filtered or unexported fields
}

func NewTee

func NewTee(filename string) (*Tee, error)

func (*Tee) Close

func (t *Tee) Close()

func (*Tee) Sync

func (t *Tee) Sync()

Jump to

Keyboard shortcuts

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