protocols

package
v0.0.0-...-c8b15d8 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2018 License: MIT Imports: 11 Imported by: 15

Documentation

Index

Constants

View Source
const (
	CodeOK = iota
	CodeError
)
View Source
const (
	ErrorChanBuffer = 16
	SendTimeout     = 1 * time.Second
)
View Source
const (
	DefaultRetries = 3
)
View Source
const (
	DefaultTimeout = 1 * time.Second
)

Variables

View Source
var (
	DefaultTransport = TcpTransport()
)

Functions

func NewMiniProtocol

func NewMiniProtocol(fragment ProtocolFragment) *protocol

func NewMiniProtocolTransport

func NewMiniProtocolTransport(fragment ProtocolFragment, transport TransportProvider) *protocol

func NewProtocol

func NewProtocol(name string, fragments ...ProtocolFragment) (*protocol, error)

func NewProtocolTransport

func NewProtocolTransport(name string, transport TransportProvider, fragments ...ProtocolFragment) (*protocol, error)

func ParseServerFlags

func ParseServerFlags(default_ip string, default_port int) string

Types

type Addr

type Addr interface {
	net.Addr
	IP() net.IP
}

type CircuitBreaker

type CircuitBreaker interface {
	Client

	Error() error
	Online() bool
	AddCallback(callback FaultDetectorCallback, key interface{})
}

func NewCircuitBreaker

func NewCircuitBreaker(client Client, detector FaultDetector) (CircuitBreaker, error)

func NewCircuitBreakerOn

func NewCircuitBreakerOn(protocol Protocol, detector FaultDetector) (CircuitBreaker, error)

type Client

type Client interface {
	Close() error
	Closed() bool
	ResetConnection() // Will open new connection next time it's required

	SetServer(server_addr string) error
	Server() Addr
	SetTimeout(timeout time.Duration)
	Protocol() Protocol
	String() string

	SendPacket(packet *Packet) error
	Send(code Code, val interface{}) error
	SendRequest(code Code, val interface{}) (*Packet, error)
	SendRequestPacket(packet *Packet) (reply *Packet, err error)
	CheckReply(reply *Packet) error
	CheckError(reply *Packet, expectedCode Code) error
}

func NewClient

func NewClient(protocol Protocol) Client

func NewClientFor

func NewClientFor(server string, protocol Protocol) (Client, error)

func NewMiniClient

func NewMiniClient(fragment ProtocolFragment) Client

func NewMiniClientFor

func NewMiniClientFor(server_addr string, fragment ProtocolFragment) (Client, error)

type Code

type Code uint

type Conn

type Conn interface {
	Send(packet *Packet, timeout time.Duration) error
	UnreliableSend(packet *Packet) error
	Receive(timeout time.Duration) (*Packet, error)

	RemoteAddr() Addr
	LocalAddr() Addr
	Close() error
}

type Decoder

type Decoder func(decoder *gob.Decoder) (interface{}, error)

type DecoderMap

type DecoderMap map[Code]Decoder

type FaultDetector

type FaultDetector interface {
	Close() error
	Check()

	// Implemented by *FaultDetectorBase
	Error() error
	Online() bool
	ErrorDetected(err error)
	ObservedServer() Addr
	AddCallback(callback FaultDetectorCallback, key interface{})
}

type FaultDetectorBase

type FaultDetectorBase struct {
	Closed golib.StopChan
	// contains filtered or unexported fields
}

func NewFaultDetectorBase

func NewFaultDetectorBase(observedProtocol Protocol, server Addr) *FaultDetectorBase

func (*FaultDetectorBase) AddCallback

func (detector *FaultDetectorBase) AddCallback(callback FaultDetectorCallback, key interface{})

func (*FaultDetectorBase) Error

func (detector *FaultDetectorBase) Error() (err error)

func (*FaultDetectorBase) ErrorDetected

func (detector *FaultDetectorBase) ErrorDetected(err error)

func (*FaultDetectorBase) InvokeCallback

func (detector *FaultDetectorBase) InvokeCallback(wasOnline bool)

func (*FaultDetectorBase) LoopCheck

func (detector *FaultDetectorBase) LoopCheck(checker func(), timeout time.Duration)

func (*FaultDetectorBase) ObservedServer

func (detector *FaultDetectorBase) ObservedServer() Addr

func (*FaultDetectorBase) Online

func (detector *FaultDetectorBase) Online() bool

func (*FaultDetectorBase) PerformCheck

func (detector *FaultDetectorBase) PerformCheck(checker func() error)

type FaultDetectorCallback

type FaultDetectorCallback func(key interface{})

type Listener

type Listener interface {
	Accept() (Conn, error)
	LocalAddr() Addr
	Close() error
}

type MarshallingProvider

type MarshallingProvider interface {
	MarshalPacket(packet *Packet) ([]byte, error)
	UnmarshalPacket([]byte, Protocol) (*Packet, error)
}
var (
	Marshaller MarshallingProvider = gobMarshaller
)

type Packet

type Packet struct {
	Code       Code
	Val        interface{}
	SourceAddr Addr
}

func (*Packet) String

func (packet *Packet) String() string

type Plugin

type Plugin interface {
	Start(server *PluginServer)
	Stop() error

	// Create and fully initialize new session. The param data is passed from
	// plugin to plugin, enabling one plugin to modify the input data for the next plugin.
	// Modify param if necessary and copy values from it. Do not store it.
	NewSession(param SessionParameter) (PluginSessionHandler, error)
}

type PluginServer

type PluginServer struct {
	*Server

	SessionStartedCallback func(session *PluginSession)
	SessionStoppedCallback func(session *PluginSession)
	// contains filtered or unexported fields
}

func NewPluginServer

func NewPluginServer(server *Server) *PluginServer

func (*PluginServer) AddPlugin

func (server *PluginServer) AddPlugin(plugin Plugin)

func (*PluginServer) DeleteSession

func (server *PluginServer) DeleteSession(client string) error

func (*PluginServer) NewSession

func (server *PluginServer) NewSession(param SessionParameter) error

func (*PluginServer) StopServer

func (server *PluginServer) StopServer()

func (*PluginServer) StopSession

func (server *PluginServer) StopSession(client string) error

type PluginSession

type PluginSession struct {
	Base    *SessionBase
	Client  string // From the originating SessionParameter
	Server  *PluginServer
	Plugins []PluginSessionHandler
}

func (*PluginSession) Cleanup

func (session *PluginSession) Cleanup()

func (*PluginSession) Start

func (session *PluginSession) Start(base *SessionBase)

func (*PluginSession) Tasks

func (session *PluginSession) Tasks() (result []golib.Task)

type PluginSessionHandler

type PluginSessionHandler interface {
	Start(sendingSession PluginSessionHandler)
	Tasks() []golib.Task
	Cleanup() error
	String() string
}

type Protocol

type Protocol interface {
	Name() string
	CheckIncludesFragment(fragmentName string) error
	Transport() TransportProvider
	// contains filtered or unexported methods
}

type ProtocolFragment

type ProtocolFragment interface {
	Name() string
	Decoders() DecoderMap
}

type Server

type Server struct {
	Stopped bool
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr_string string, protocol Protocol) (*Server, error)

func (*Server) Errors

func (server *Server) Errors() <-chan error

func (*Server) LocalAddr

func (server *Server) LocalAddr() Addr

func (*Server) LogError

func (server *Server) LogError(err error)

func (*Server) Protocol

func (server *Server) Protocol() Protocol

func (*Server) RegisterHandlers

func (server *Server) RegisterHandlers(handlers ServerHandlerMap) error

func (*Server) RegisterStopHandler

func (server *Server) RegisterStopHandler(handler ServerStopper)

func (*Server) Reply

func (server *Server) Reply(code Code, value interface{}) *Packet

func (*Server) ReplyCheck

func (server *Server) ReplyCheck(err error) *Packet

func (*Server) ReplyError

func (server *Server) ReplyError(err error) *Packet

func (*Server) ReplyOK

func (server *Server) ReplyOK() *Packet

func (*Server) Start

func (server *Server) Start(wg *sync.WaitGroup) golib.StopChan

func (*Server) Stop

func (server *Server) Stop()

func (*Server) String

func (server *Server) String() string

type ServerHandlerMap

type ServerHandlerMap map[Code]ServerRequestHandler

type ServerProtocolFragment

type ServerProtocolFragment interface {
	ProtocolFragment
	ServerHandlers(server *Server) ServerHandlerMap
}

If a ProtocolFragment implements this, the returned handlers will be automatically added to a Server

type ServerRequestHandler

type ServerRequestHandler func(packet *Packet) (reply *Packet)

type ServerStopper

type ServerStopper func()

type Session

type Session interface {
	Start(base *SessionBase)
	Tasks() []golib.Task
	Cleanup()
}

type SessionBase

type SessionBase struct {
	Wg         *sync.WaitGroup
	Stopped    golib.StopChan
	CleanupErr error
	Session    Session
}

func (*SessionBase) Stop

func (base *SessionBase) Stop()

func (*SessionBase) StopAndFormatError

func (base *SessionBase) StopAndFormatError() error

type SessionParameter

type SessionParameter interface {
	// This string will be used as key in the sessions dictionary
	Client() string
}

type Sessions

type Sessions map[interface{}]*SessionBase

func (Sessions) DeleteSession

func (sessions Sessions) DeleteSession(key interface{}) error

func (Sessions) DeleteSessions

func (sessions Sessions) DeleteSessions() error

func (Sessions) Get

func (sessions Sessions) Get(key interface{}) Session

func (Sessions) ReKeySession

func (sessions Sessions) ReKeySession(oldKey, newKey interface{}) (*SessionBase, error)

func (Sessions) StartSession

func (sessions Sessions) StartSession(key interface{}, session Session)

func (Sessions) StopSession

func (sessions Sessions) StopSession(key interface{}) error

type TransportProvider

type TransportProvider interface {
	Resolve(addr string) (Addr, error)
	ResolveIP(ip string) (Addr, error)
	ResolveLocal(remote_addr string) (Addr, error)
	Listen(local Addr, protocol Protocol) (Listener, error)
	Dial(remote Addr, protocol Protocol) (Conn, error)
	String() string
}

func TcpTransport

func TcpTransport() TransportProvider

func UdpTransport

func UdpTransport() TransportProvider

func UdpTransportB

func UdpTransportB(bufferSize int) TransportProvider

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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