tcp

package
v0.0.0-...-baa17e1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2024 License: MIT Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Handler

type Handler struct {
	IdleTimeout time.Duration
	// contains filtered or unexported fields
}

Handler is the tcp protocol handler.

func NewHandler

func NewHandler(l zerolog.Logger, p Protocol, idle time.Duration) (h *Handler)

NewHandler creates a new tcp protocol handler.

func (*Handler) Handle

func (h *Handler) Handle(conn tcpserver.Connection)

Handle handles the tcp inbound connection. It parses the tcp payload and calls the protocol handler. If some useful Event is extracted from the packet, it will be sent to the listeners what previously was registered by calling RegisterEventSubscriber.

func (*Handler) RegisterEventSubscriber

func (h *Handler) RegisterEventSubscriber(sub event.Subscriber)

type Protocol

type Protocol interface {
	// Name returns the name of the protocol.
	Name() string
	// NewFrameSplitter returns instance of the split function for the protocol.
	NewFrameSplitter() common.FrameSplitter
	// Respond returns the Result as passed was processed.
	Respond(*internal.Session, []byte) (Result, error)
}

Protocol is the tcp protocol contract.

type Replayer

type Replayer struct {
	// contains filtered or unexported fields
}

Replayer is replayer previously recorded data of TCP protocols.

func NewReplayer

func NewReplayer(address string, proto Protocol, opts ...ReplayerOption) *Replayer

NewReplayer creates new instance of Replayer. Provide server address to where data will be sent and proto to send package by package with delay between. It is possible but not recommended to use proto by EOF to send whole file as one package.

func (*Replayer) Option

func (p *Replayer) Option(opts ...ReplayerOption)

Option sets the options specified.

func (*Replayer) Play

func (p *Replayer) Play(filename string) error

Play sends data from a file with given filename to a server. ToDo add ctx to break loop

type ReplayerOption

type ReplayerOption func(*Replayer)

func WithDelay

func WithDelay(milsecs int) ReplayerOption

func WithTimeouts

func WithTimeouts(to time.Duration) ReplayerOption

type Result

type Result struct {
	CloseSession   bool
	Response       []byte
	GenericAdapter gen.Adapter
}

Result is the result of handling bytes packet. It contains: CloseSession flag that signals that the session should be closed. In case like login message was failed. Response is the response bytes that shall be sent to the client. GenericAdapter that is used to get extracted and unified data from the packet.

type Server

type Server struct {
	Handler *Handler
	// contains filtered or unexported fields
}

Server is a TCP server for handling incoming device or retranslator connections.

func NewServer

func NewServer(l zerolog.Logger, address string, opts ...ServerOption) (server *Server, err error)

NewServer creates a new TCP server.

func (*Server) ListenAndServe

func (s *Server) ListenAndServe() error

ListenAndServe starts the TCP server.

func (*Server) Option

func (s *Server) Option(opts ...ServerOption)

Option sets the options specified.

func (*Server) RegisterHandler

func (s *Server) RegisterHandler(f tcpserver.RequestHandlerFunc)

RegisterHandler registers a handler for incoming device or retranslator connections.

func (*Server) SetProtocol

func (s *Server) SetProtocol(p Protocol)

SetProtocol sets the protocol for incoming device or retranslator connections.

type ServerOption

type ServerOption func(*Server)

func WithAllowThreadLocking

func WithAllowThreadLocking(locking bool) ServerOption

func WithLoops

func WithLoops(loops int) ServerOption

func WithSocketDeferAccept

func WithSocketDeferAccept(daccept bool) ServerOption

func WithSocketFastOpen

func WithSocketFastOpen(fopen bool) ServerOption

func WithSocketReusePort

func WithSocketReusePort(reuse bool) ServerOption

func WithTimeout

func WithTimeout(to time.Duration) ServerOption

WithTimeout sets the timeout for the server. Default is 10 minutes.

func WithWorkerpoolShards

func WithWorkerpoolShards(shards int) ServerOption

Jump to

Keyboard shortcuts

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