Documentation ¶
Index ¶
- Constants
- func LogLevel() string
- func SetLogLevel(level uint8)
- func SetLogger(l *log.Logger)
- type Callback
- type Config
- func (c *Config) Dump(path string) (err error)
- func (c *Config) GetLogLevel() uint8
- func (c *Config) GetName() (string, error)
- func (c *Config) GetPeer() (peers.Peer, error)
- func (c *Config) GetRemotes(actor Dispatcher) ([]*Remote, error)
- func (c *Config) GetTick() (tick time.Duration, err error)
- func (c *Config) GetUptime() (uptime time.Duration, err error)
- func (c *Config) Load(path string) (err error)
- func (c *Config) SetLogLevel()
- func (c *Config) SetSeed()
- type Dispatcher
- type Event
- type EventType
- type MessageCounts
- type Remote
- type Server
- func (s *Server) Close() error
- func (s *Server) Dispatch(e Event) error
- func (s *Server) DispatchError(err error, source interface{})
- func (s *Server) DispatchMessage(msg *pb.Envelope, source interface{}) error
- func (s *Server) Handle(e Event) error
- func (s *Server) Heartbeat()
- func (s *Server) Listen() error
- func (s *Server) Post(stream pb.LiveNet_PostServer) (err error)
- func (s *Server) Status()
Constants ¶
const ( DefaultTick = 500 * time.Millisecond DefaultLogLevel = LogCaution )
Default configuration values
const ( LogTrace uint8 = iota LogDebug LogInfo LogCaution LogStatus LogWarn LogSilent )
Levels for implementing the debug and trace message functionality.
const CautionThreshold = 50
CautionThreshold for issuing caution logs after accumulating cautions.
const PackageVersion = "0.2"
PackageVersion of LiveNet
Variables ¶
This section is empty.
Functions ¶
func LogLevel ¶
func LogLevel() string
LogLevel returns a string representation of the current level
func SetLogLevel ¶
func SetLogLevel(level uint8)
SetLogLevel modifies the log level for messages at runtime. Ensures that the highest level that can be set is the trace level.
Types ¶
type Config ¶
type Config struct { Name string `json:"name,omitempty"` // unique name of local replica (hostname by default) Seed int64 `json:"seed"` // random seed to initialize with Tick string `json:"tick"` // click tick rate for timing (parseable duration) Uptime string `json:"uptime,omitempty"` // run for a specified duration then shutdown LogLevel int `json:"log_level,omitempty"` // verbosity of logging, lower is more verbose Peers []peers.Peer `json:"peers"` // all hosts on the LiveNet }
Config implements a simple configuration object that can be loaded from a JSON file and defines the LiveNet network.
func (*Config) GetLogLevel ¶
GetLogLevel returns the uint8 parsed logging verbosity
func (*Config) GetRemotes ¶
func (c *Config) GetRemotes(actor Dispatcher) ([]*Remote, error)
GetRemotes returns all peer configurations for remote hosts on the network, excluding the local peer configuration.
func (*Config) GetUptime ¶
GetUptime returns the parsed duration from the uptime configuration. If no uptime is specified then a duration of 0 and no error is returned.
func (*Config) SetLogLevel ¶
func (c *Config) SetLogLevel()
SetLogLevel from the configuration if specified, e.g. > 0
type Dispatcher ¶
type Dispatcher interface { Dispatch(e Event) error DispatchMessage(msg *pb.Envelope, source interface{}) error DispatchError(err error, source interface{}) }
Dispatcher is an object that listens for events and handles them.
type Event ¶
type Event interface { Type() EventType Source() interface{} Value() interface{} }
Event represents actions that occur during consensus. Listeners can register callbacks with event handlers for specific event types.
type EventType ¶
type EventType uint16
EventType is an enumeration of the kind of events that can occur.
Event types represented in LiveNet
type MessageCounts ¶
type MessageCounts struct {
// contains filtered or unexported fields
}
MessageCounts is a simple data structure for keeping track of how many messages are sent, received, and dropped from a connection.
func (*MessageCounts) Drop ¶
func (c *MessageCounts) Drop()
Drop increments the dropped messages count
func (*MessageCounts) DropR ¶
func (c *MessageCounts) DropR() float64
DropR returns the ratio of dropped to sent messages
func (*MessageCounts) Recv ¶
func (c *MessageCounts) Recv()
Recv increments the received messages count
func (*MessageCounts) RecvR ¶
func (c *MessageCounts) RecvR() float64
RecvR returns the ratio of received to sent messages
func (*MessageCounts) String ¶
func (c *MessageCounts) String() string
type Remote ¶
Remote implements a streaming connection to a remote peer on the network.
type Server ¶
Server implements a LiveNet host that connects to all peers on the network via gRPC streams. It can send a variety of messages but primarily sends routine heartbeats to the other servers.
func New ¶
New is the entry point to the LiveNet service for a single machine, it instantiates a LiveNet sever for the specified network and configuration.
func (*Server) DispatchError ¶
DispatchError sends error messages that will stop the server and the event loop, returning an error and closing the process.
func (*Server) DispatchMessage ¶
DispatchMessage creates an event for the specified message type
func (*Server) Heartbeat ¶
func (s *Server) Heartbeat()
Heartbeat sends a routine liveness message to other peers.
func (*Server) Post ¶
func (s *Server) Post(stream pb.LiveNet_PostServer) (err error)
Post implements the LiveNet stream server, listening for stream connections from clients and remote hosts and dispatching each message as an event. Every message received on the stream is responded to before a new message event is dispatched on receive. This ensures that messages are ordered with respect to those that are sent from the client.
Post and Dispatch together also implements the simple multiplexer based on message type. Post sends events of the specified type, which gets handled by the specific event handler.