server

package
v0.0.0-...-7aac46a Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2023 License: MIT Imports: 18 Imported by: 0

README

server

Documentation

Overview

Server contains bunch of interfaces and functionalities for serving connections compatible with Protox. It has APIs for interacting with the underlaying subsystems.

Index

Constants

View Source
const (
	ProtoUNIXSO byte = iota
	// Protox over TCP
	ProtoTCP
	// Protox over TLS
	ProtoTLS
	// Protox over SSL
	ProtoSSL
)

Constants for server transport types (UNIX, TCP, SSL/TLS, .... )

View Source
const (
	CLConnected cstflg = iota
	CLDisconnected
	CLSent
	CLRecv
	CLReject
	CLFault
)

Variables

View Source
var (
	SRVShutdownError  error = errors.New("server: cannot shutdown due to incompatible state.")
	SRVGeneralError   error = errors.New("server: %s")
	SRVInvalidAddr    error = errors.New("server: invalid address.")
	SRVInvalidMode    error = errors.New("server: invalid serving mode.")
	SRVMissingOptions error = errors.New("server: options are missing.")
	SRVTLSInvalidCA   error = errors.New("server: invalid caFile.")
)

Server error messages

View Source
var (
	DefaultHeartbeat int = 1
)

Defaults

Functions

This section is empty.

Types

type ClientDelegate

type ClientDelegate func(string, string, string) protobase.ClientInterface

ClientDelegate is a signature for `ClientInterface` delegation.

type ConnectionDelegate

type ConnectionDelegate func(net.Conn) protobase.ProtoConnection

ConnectionDelegate is a signature for `ProtoConnection` delegation.

type SConnType

type SConnType byte

SConnTyp is server client type ( CLIENT, RESOURCE, ROUTER, MONITOR, .... )

const (
	// Client
	STCLIENT SConnType = iota
	// Manager
	STMANAGER
	// Router
	STROUTER
	// Resource provider
	STRESOURCE
	// Monitor and statics collector
	STMONITOR
)

Constants for server client types

type Server

type Server struct {
	sync.RWMutex
	protobase.ServerInterface

	Clients map[net.Conn]protobase.ProtoConnection

	Authenticator protobase.AuthInterface
	Store         protobase.MessageStorage
	Router        protobase.RouterInterface
	State         *serverState

	StatusChan chan uint32

	Status uint32
	// contains filtered or unexported fields
}

Server is a main implementation of `protocol.ServerInterface`.

func NewServer

func NewServer() (s *Server)

NewServer creates a new server instance. It is the entry point for using underlaying subsystems. Most of the subsystems can be customized by providing a handler function or delegating.

func NewServerWithConfigs

func NewServerWithConfigs(opts ServerConfigs) (s *Server, err error)

NewServerWithConfigs creates a new server instance using options given as `opts` argument and returns a pointer to it. It returns an error in case of invalid options or unsucces.

func (*Server) GetErrChan

func (s *Server) GetErrChan() <-chan struct{}

GetErrChan returns a channel to the caller. It sends a packet when server gets into a fatal error.

func (*Server) GetStatus

func (s *Server) GetStatus() uint32

GetStatus atomically loads current state of the `Server`.

func (*Server) GetStatusChan

func (s *Server) GetStatusChan() <-chan uint32

GetStatusChan returns a channel containing the server status. It is used for reterieving initial status.

func (*Server) NotifyConnected

func (s *Server) NotifyConnected(prc protobase.ProtoConnection)

NotifyConnected is a delegate routine. It gets called whenever a new client successfully passes `Genesis` stage and authorization levels. This function is directly called by a compatible `protocol.ProtoConnection` structure and only after that the corresponsing function on a compatible `client.ClientInterface` will be called. Subsequently, a `client.ClientInterface` struct can drop the connection after.

func (*Server) NotifyDisconnected

func (s *Server) NotifyDisconnected(prc protobase.ProtoConnection)

NotifyDisconnected notifies the server that the connection to a client is either lost or broken.

func (*Server) NotifyPublish

func (s *Server) NotifyPublish(prc protobase.ProtoConnection, msg protobase.MsgInterface)

NotifyPublish sends messages from publishers to subscribers. A compatible `client.ClientInterface` structure is responsible to call this function and may decide not to if messages must be dropped. Note: this uses the new implementation and is under development.

func (*Server) NotifyQueue

func (s *Server) NotifyQueue(prc protobase.ProtoConnection, msg protobase.MsgInterface)

func (*Server) NotifyReject

func (s *Server) NotifyReject(prc protobase.ProtoConnection)

NotifyRejected notifies the server that the connection is rejected ( invalid creds, ban , ..... ).

func (*Server) NotifySubscribe

func (s *Server) NotifySubscribe(prc protobase.ProtoConnection, msg protobase.MsgInterface)

NotifySubscribe is a delegate routine that registers client subscriptions. It is only accessible above `Genesis` stage. Calling this method is theresponsibility of `client.ClientInterface` and consequently - implementor may decide to drop new subscriptions by not calling this function.

Note: this is the new implementation and is under development.

func (*Server) Redeliver

func (s *Server) Redeliver(prc protobase.ProtoConnection)

func (*Server) RegisterClient

func (s *Server) RegisterClient(prc protobase.ProtoConnection)

RegisterClient adds the client to internal data structures is called when the client is fully authorized and passes `Genesis` stage.

func (*Server) Serve

func (s *Server) Serve() (err error)

func (*Server) ServeTCP

func (s *Server) ServeTCP(address string) (err error)

ServeTCP is the main listening loop. It is responsible for accepting incoming TCP connections from clients.

func (*Server) ServeWS

func (s *Server) ServeWS(address string) (err error)

ServeWS is the main listening loop for serving protocol connections over WebSockets. Notice - this is experimental.

func (*Server) SetAuthenticator

func (s *Server) SetAuthenticator(authenticator protobase.AuthInterface)

SetAuthenticator sets the delegate to use the provided handler. It should be called prior to running the server and listening for new connections.

func (*Server) SetClientHandler

func (s *Server) SetClientHandler(fn func(string, string, string) protobase.ClientInterface)

SetClientHandler sets the delegate to a function with a signature of `func(string, string, string) protocol.ClientInterface`. It gets called only after the connection is fully authorized and passed `Genesis` stage.

func (*Server) SetConnectionHandler

func (s *Server) SetConnectionHandler(fn ConnectionDelegate)

SetConnectionHandler creates a connection of type `protocol.ProtoConnection` which handles all low-level protocol logics.

func (*Server) SetHeartBeat

func (s *Server) SetHeartBeat(heartbeat int)

SetHeartBeat sets the maximum tolerable time ( heartbeat ) in which not receiving packets from a client does not cause connection termination.

func (*Server) SetLogger

func (s *Server) SetLogger(l protobase.LoggingInterface)

SetLogger is a method that implements `prtobase.ILoggable`.

func (*Server) SetMessageHandler

func (s *Server) SetMessageHandler(fn ServerHandlerFunc)

SetMessageHandler is a callback to server whenever a new package is received and parsed in the protocol layer.

func (*Server) SetMessageStore

func (s *Server) SetMessageStore(store protobase.MessageStorage)

SetMessageStore sets the internal storage delegate to a `protobase.MessageStorage` compatible struct.

func (*Server) SetPermissionDelegate

func (s *Server) SetPermissionDelegate(pd func(protobase.AuthInterface, ...string) bool)

SetPermissionDelegate sets the delegate for a subsystem that checks right accesses and permissions.

func (*Server) SetStatus

func (s *Server) SetStatus(status uint32) uint32

SetStatus sets the internal status to the new argument status and returns its old value, atomically.

func (*Server) Setup

func (s *Server) Setup()

Setup is for prechecks before running the server. It must crash ( or recover ) to indicate fatal problems early on.

func (*Server) Shutdown

func (s *Server) Shutdown() (<-chan struct{}, error)

Shutdown is a graceful shutdown method which returns a channel. It can be polled if server fails to shuts down.

func (*Server) SigHandler

func (s *Server) SigHandler()

type ServerConfigs

type ServerConfigs struct {
	Config interface{}
	Addr   string
	Mode   byte
	Type   byte
	// TRate is the cycle interval in milliseconds
	// for performing status check.
	TRate int
}

ServerConfigs is a struct for configuring the server.

type ServerHandlerFunc

type ServerHandlerFunc func(net.Conn) protobase.ClientInterface

ServerHandlerFunc is the signature for `ClientInterface` delegation.

type ServerType

type ServerType byte
const (
	// Protox over original protocol
	ProtoOrigin ServerType = iota
	// Protox over HTTP
	ProtoHTTP
	// Protox over HTTPS
	ProtoHTTPS
	// Protox over WS
	ProtoWS
	// Protox over MQTT
	ProtoMQTT
	// Protox over RP
	ProtoRP
)

Constants for server service types (Protox over : HTTP/S, MQTT, WS, REDIS PROTOCOL, .... )

type TCPOptions

type TCPOptions struct {
}

TCPOptions contains necessarry information required by TCP server.

type TLSOptions

type TLSOptions struct {
	Curves           []tls.CurveID
	Ciphers          []uint16
	Cert             string
	Key              string
	Ca               string
	HandshakeTimeout int
	ShouldVerify     bool
}

TLSOptions contains neccessary information required by TLS server.

type UNIXSOptions

type UNIXSOptions struct {
}

UNIXSOPtions contains necessary information required by unix socket server.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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