tcp

package
v0.3.9 Latest Latest
Warning

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

Go to latest
Published: May 18, 2020 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTooManyConnections = errors.New("too many connections")

ErrTooManyConnections is returned the current number of connections exceeds the limit.

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(logger logrus.FieldLogger, pool ConnPool) *Client

func (*Client) Run

func (client *Client) Run(ctx context.Context, messages protocol.MessageReceiver)

type ConnPool added in v0.3.0

type ConnPool interface {
	Send(net.Addr, protocol.Message) error
}

A ConnPool maintains multiple connections to different remote peers and re-uses these connections when sending multiple message to the peer. If a connection to a peer does not exist when a message is sent, then it is established. When there are multiple Clients, they should all use a shared ConnPool, and therefore all implementations must be safe for concurrent use.

func NewConnPool added in v0.3.0

func NewConnPool(options ConnPoolOptions, logger logrus.FieldLogger, handshaker handshake.Handshaker) ConnPool

NewConnPool returns a ConnPool with no existing connections. It is safe for concurrent use.

type ConnPoolOptions added in v0.3.0

type ConnPoolOptions struct {
	Timeout        time.Duration // Timeout when dialing new connections.
	TimeToLive     time.Duration // Time-to-live for connections.
	MaxConnections int           // Max connections allowed.
}

ConnPoolOptions are used to parameterise the behaviour of a ConnPool.

type Server

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

func NewServer

func NewServer(options ServerOptions, logger logrus.FieldLogger, handshaker handshake.Handshaker) *Server

func (*Server) Run added in v0.2.3

func (server *Server) Run(ctx context.Context, messages protocol.MessageSender)

Run the server until the context is done. The server will continuously listen for new connections, spawning each one into a background goroutine so that it can be handled concurrently.

type ServerOptions

type ServerOptions struct {
	Host           string        // Host address
	Timeout        time.Duration // Timeout when establish a connection
	RateLimit      time.Duration // Minimum time interval before accepting connection from same peer.
	MaxConnections int           // Max connections allowed.
}

Jump to

Keyboard shortcuts

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