tcp

package
v0.4.0-3 Latest Latest
Warning

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

Go to latest
Published: Jun 10, 2020 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// DefaultClientTimeToLive is set to 1 hour. If no dial attempt succeeds, or
	// no messages are attempted to be sent, within one hour, then the
	// connection is killed and all pending messages will be lost.
	DefaultClientTimeToLive = time.Hour
	// DefaultClientMaxCapacity is set to 4096.
	DefaultClientMaxCapacity = 4096
)
View Source
var (
	DefaultServerTimeout    = 10 * time.Second
	DefaultServerTimeToLive = 24 * time.Hour
	DefaultServerMaxConns   = 256
	DefaultServerHost       = "0.0.0.0"
	DefaultServerPort       = uint16(18514)
	DefaultRateLimit        = rate.Limit(1.0)
	DefaultRateLimitBurst   = DefaultServerMaxConns
)

Functions

This section is empty.

Types

type Client

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

func NewClient

func NewClient(opts ClientOptions, handshaker handshake.Handshaker, listener wire.Listener) *Client

func (*Client) Close added in v0.4.0

func (client *Client) Close(addr string)

Close all connections being maintained by the Client to this address. Other connections will be kept alive.

func (*Client) CloseAll added in v0.4.0

func (client *Client) CloseAll()

CloseAll connections being maintained by the Client.

func (*Client) Options added in v0.4.0

func (client *Client) Options() ClientOptions

Options returns the Options used to configure the Client. Changing the Options returned by the method will have no affect on the behaviour of the Client.

func (*Client) Send added in v0.4.0

func (client *Client) Send(ctx context.Context, addr string, msg wire.Message) error

Send a message to an address. If no connection exists between the Client and the address, then one will be established. If a connection already exists, it will be re-used. If the message cannot be sent before the context is done, then an error will be returned.

type ClientOptions

type ClientOptions struct {
	// Logger for all information/debugging/error output.
	Logger logrus.FieldLogger
	// TimeToLive for connections. Connections with no non-malicious activity
	// after the TimeToLive duration will be killed. Setting the TimeToLive, and
	// carefully choosing which addresses to send messages to, is the primary
	// mechanism for ensuring that the Client does not consume too many
	// resources on maintaining connections (there is no explicit maximum number
	// of connections). This is also the amount of time that we will wait while
	// attempting to dial connections.
	TimeToLive time.Duration
	// MaxCapacity of messages that can be bufferred while waiting to write
	// messages to a channel.
	MaxCapacity int
}

ClientOptions are used to parameterize the behaviour of the Client.

func DefaultClientOptions added in v0.4.0

func DefaultClientOptions() ClientOptions

DefaultClientOptions return the default ClientOptions.

func (ClientOptions) WithLogger added in v0.4.0

func (opts ClientOptions) WithLogger(logger logrus.FieldLogger) ClientOptions

func (ClientOptions) WithMaxCapacity added in v0.4.0

func (opts ClientOptions) WithMaxCapacity(capacity int) ClientOptions

func (ClientOptions) WithTimeToLive added in v0.4.0

func (opts ClientOptions) WithTimeToLive(ttl time.Duration) ClientOptions

type Server

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

func NewServer

func NewServer(opts ServerOptions, handshaker handshake.Handshaker, listener wire.Listener) *Server

func (*Server) Listen

func (server *Server) Listen(ctx context.Context) error

Listen for incoming connections until the context is done. The Server will accept spawn a background goroutine for every accepted connection, but will not accept more connections than its configured maximum.

func (*Server) Options added in v0.4.0

func (server *Server) Options() ServerOptions

Options returns the Options used to configure the Server. Changing the Options returned by the method will have no affect on the behaviour of the Server.

type ServerOptions

type ServerOptions struct {
	Logger         logrus.FieldLogger
	Timeout        time.Duration
	TimeToLive     time.Duration
	MaxConns       int
	Host           string
	Port           uint16
	RateLimit      rate.Limit
	RateLimitBurst int
}

func DefaultServerOptions added in v0.3.0

func DefaultServerOptions() ServerOptions

func (ServerOptions) WithHost added in v0.4.0

func (opts ServerOptions) WithHost(host string) ServerOptions

WithHost sets the host address that will be used for listening.

func (ServerOptions) WithLogger added in v0.4.0

func (opts ServerOptions) WithLogger(logger logrus.FieldLogger) ServerOptions

WithLogger sets the logger.

func (ServerOptions) WithPort added in v0.4.0

func (opts ServerOptions) WithPort(port uint16) ServerOptions

WithPort sets the port that will be used for listening.

Jump to

Keyboard shortcuts

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