Documentation ¶
Overview ¶
Package network Copyright 2017 mitrakov. All right are reserved. Governed by the BSD license
Package network Copyright 2017 mitrakov. All right are reserved. Governed by the BSD license
Package network Copyright 2017 mitrakov. All right are reserved. Governed by the BSD license
Index ¶
- type IFloodDetector
- type IHandler
- type IProtocol
- type IServer
- type ISidHandler
- type Server
- func (server *Server) Close() *Error
- func (server *Server) Connect(port uint16) (*net.UDPConn, *Error)
- func (server *Server) GetRps() (result uint32)
- func (server *Server) Send(sid Sid, data []byte) *Error
- func (server *Server) SendAll(box *MailBox)
- func (server *Server) SetProtocol(protocol IProtocol)
- func (server *Server) SetSidHandler(handler ISidHandler)
- func (server *Server) Start()
- type SimpleDetector
- type SwUDP
- func (p *SwUDP) Close()
- func (p *SwUDP) ConnectionFailed(crcid uint)
- func (p *SwUDP) GetReceiversCount() uint
- func (p *SwUDP) GetSendersCount() uint
- func (p *SwUDP) OnReceived(data []byte, addr *net.UDPAddr) *Error
- func (p *SwUDP) OnReceiverConnected(crcid uint, addr *net.UDPAddr) *Error
- func (p *SwUDP) OnSenderConnected()
- func (p *SwUDP) Send(data []byte, crcid uint) *Error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type IFloodDetector ¶
type IFloodDetector interface {
// contains filtered or unexported methods
}
IFloodDetector is an interface to detect and ban suspicious addresses
func NewSimpleDetector ¶
func NewSimpleDetector() IFloodDetector
NewSimpleDetector creates a new instance of a SimpleDetector. Please don't create a SimpleDetector manually.
type IHandler ¶
type IHandler interface {
// contains filtered or unexported methods
}
IHandler is an interface for receivers of IProtocol
type IProtocol ¶
type IProtocol interface { Send(data []byte, crcid uint) *Error OnReceived(data []byte, addr *net.UDPAddr) *Error OnSenderConnected() OnReceiverConnected(crcid uint, addr *net.UDPAddr) *Error ConnectionFailed(crcid uint) GetSendersCount() uint GetReceiversCount() uint Close() }
IProtocol is an interface for network protocols that may be implemented over UDP
type IServer ¶
type IServer interface { Connect(port uint16) (*net.UDPConn, *Error) Start() Send(sid Sid, data []byte) *Error SendAll(box *MailBox) GetRps() uint32 SetSidHandler(handler ISidHandler) SetProtocol(protocol IProtocol) Close() *Error }
IServer is an interface to describe components that could send and receive messages
type ISidHandler ¶
ISidHandler is an interface to handle incoming messages
type Server ¶
Server is a component that could send and receive messages over a UDP socket. Both interface and implementation were placed in the same src intentionally! This component is independent.
func NewServer ¶
func NewServer(handler ISidHandler, protocol IProtocol) *Server
NewServer creates a new instance of Server. Please don't create a Server manually. "handler" - handler for incoming messages (may be NULL) "protocol" - an additional protocol over UDP (may be NULL)
func (*Server) Connect ¶
Connect tries to bind the Server to a given port. This method doesn't block the execution. Method throws error, if: 1) Cannot resolve UDPv4 address; 2) Cannot create a socket
func (*Server) Send ¶
Send transmits a message to the socket. Ensure the Connect() method is called before this. Method throws error, if: 1) SID not found; 2) Send message error. "sid" - client's Session ID "data" - message
func (*Server) SendAll ¶
func (server *Server) SendAll(box *MailBox)
SendAll sends all the messages, consolidated in a given MailBox
func (*Server) SetProtocol ¶
SetProtocol assigns a new transport protocol over UDP to handle the message delivery algorithms. May be NULL
func (*Server) SetSidHandler ¶
func (server *Server) SetSidHandler(handler ISidHandler)
SetSidHandler assigns a new message handler for the Server. May be NULL
type SimpleDetector ¶
SimpleDetector is a primitive misbehaviour detector (flood, DoS, etc.) This component is independent.
type SwUDP ¶
SwUDP is a "Simple Wrapper over UDP" protocol designed by @mitrakov to provide guaranteed delivery of messages. See SwUDP v1.2 specification for more details
func (*SwUDP) Close ¶
func (p *SwUDP) Close()
Close shuts SwUDP down and releases all seized resources
func (*SwUDP) ConnectionFailed ¶
ConnectionFailed is a callback on a connection failed event "crcid" - SwUDP CryptoRandom Connection ID
func (*SwUDP) GetReceiversCount ¶
GetReceiversCount returns current count of Receivers. This value might be inaccurate if some clients "fell off"
func (*SwUDP) GetSendersCount ¶
GetSendersCount returns current count of Senders. This value might be inaccurate if some clients "fell off"
func (*SwUDP) OnReceived ¶
OnReceived is a callback on a new message received "data" - message "addr" - UDP socket address
func (*SwUDP) OnReceiverConnected ¶
OnReceiverConnected is a callback on a new receiver connected event "crcid" - SwUDP CryptoRandom Connection ID "addr" - UDP socket address
func (*SwUDP) OnSenderConnected ¶
func (p *SwUDP) OnSenderConnected()
OnSenderConnected is a callback on a new sender connected event