network

package
v0.0.0-...-1af4f67 Latest Latest
Warning

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

Go to latest
Published: Dec 15, 2021 License: MIT Imports: 8 Imported by: 0

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

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

func NewSwUDP

func NewSwUDP(socket *net.UDPConn, handler IHandler) IProtocol

NewSwUDP creates a new instance of SwUDP protocol implementation. Please don't create an SwUDP manually. "socket" - standard UDP connection "handler" - listener for incoming messages

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

type ISidHandler interface {
	Handle(array []byte) (sid Sid, response []byte)
}

ISidHandler is an interface to handle incoming messages

type Server

type Server struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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) Close

func (server *Server) Close() *Error

Close shuts down the Server

func (*Server) Connect

func (server *Server) Connect(port uint16) (*net.UDPConn, *Error)

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) GetRps

func (server *Server) GetRps() (result uint32)

GetRps returns current "Requests per Second" value

func (*Server) Send

func (server *Server) Send(sid Sid, data []byte) *Error

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

func (server *Server) SetProtocol(protocol IProtocol)

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

func (*Server) Start

func (server *Server) Start()

Start gets the Server started. This method BLOCKS the execution. Ensure the Connect() method is called before this. Please note that all errors are handled inside the method (printed to log)

type SimpleDetector

type SimpleDetector struct {
	sync.Mutex
	// contains filtered or unexported fields
}

SimpleDetector is a primitive misbehaviour detector (flood, DoS, etc.) This component is independent.

type SwUDP

type SwUDP struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

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

func (p *SwUDP) ConnectionFailed(crcid uint)

ConnectionFailed is a callback on a connection failed event "crcid" - SwUDP CryptoRandom Connection ID

func (*SwUDP) GetReceiversCount

func (p *SwUDP) GetReceiversCount() uint

GetReceiversCount returns current count of Receivers. This value might be inaccurate if some clients "fell off"

func (*SwUDP) GetSendersCount

func (p *SwUDP) GetSendersCount() uint

GetSendersCount returns current count of Senders. This value might be inaccurate if some clients "fell off"

func (*SwUDP) OnReceived

func (p *SwUDP) OnReceived(data []byte, addr *net.UDPAddr) *Error

OnReceived is a callback on a new message received "data" - message "addr" - UDP socket address

func (*SwUDP) OnReceiverConnected

func (p *SwUDP) OnReceiverConnected(crcid uint, addr *net.UDPAddr) *Error

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

func (*SwUDP) Send

func (p *SwUDP) Send(data []byte, crcid uint) *Error

Send sends a message "data" - message "crcid" - SwUDP CryptoRandom Connection ID

Jump to

Keyboard shortcuts

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