Documentation
¶
Index ¶
- Variables
- type Client
- type ClientOptions
- func (opts ClientOptions) WithLogger(logger *zap.Logger) ClientOptions
- func (opts ClientOptions) WithMaxCapacity(capacity int) ClientOptions
- func (opts ClientOptions) WithMaxConnections(maxConnections int) ClientOptions
- func (opts ClientOptions) WithMaxDialAttempts(dialAttempts int) ClientOptions
- func (opts ClientOptions) WithTimeToLive(ttl time.Duration) ClientOptions
- type Server
- type ServerConnPool
- func (pool *ServerConnPool) AddToRemoteAddress(ip string, conn net.Conn) uint64
- func (pool *ServerConnPool) AddToRemoteSignatory(signatory id.Signatory, conn net.Conn) uint64
- func (pool *ServerConnPool) RemoveFromRemoteAddress(ip string, tok uint64)
- func (pool *ServerConnPool) RemoveFromRemoteSignatory(signatory id.Signatory, tok uint64)
- func (pool *ServerConnPool) Signal()
- func (pool *ServerConnPool) Wait()
- type ServerOptions
- func (opts ServerOptions) WithBandwidthLimit(bandwidthLimit rate.Limit) ServerOptions
- func (opts ServerOptions) WithBandwidthLimitBurst(bandwidthLimitBurst int) ServerOptions
- func (opts ServerOptions) WithHost(host string) ServerOptions
- func (opts ServerOptions) WithLogger(logger *zap.Logger) ServerOptions
- func (opts ServerOptions) WithMaxConns(maxConns int) ServerOptions
- func (opts ServerOptions) WithPort(port uint16) ServerOptions
- func (opts ServerOptions) WithPreventDuplicateConns(preventDuplicateConns bool) ServerOptions
- func (opts ServerOptions) WithRateLimit(rateLimit rate.Limit) ServerOptions
- func (opts ServerOptions) WithRateLimitBurst(rateLimitBurst int) ServerOptions
- func (opts ServerOptions) WithTimeToLive(timeToLive time.Duration) ServerOptions
- func (opts ServerOptions) WithTimeout(timeout time.Duration) ServerOptions
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultClientTimeToLive is set to 10 minutes. If no messages are // attempted to be sent within this time, then the connection is killed and // all pending messages will be lost. DefaultClientTimeToLive = 10 * time.Minute // DefaultClientTimeToDial is set to 15 seconds. If a single dial attempt // takes longer than this duration, it will be dropped (and a new attempt // may begin). DefaultClientTimeToDial = 15 * time.Second // DefaultClientMaxDialAttempts is set to 5. If the first 5 dial attempts // fail, the connection will be dropped. DefaultClientMaxDialAttempts = 5 // DefaultClientMaxCapacity is set to 4096. DefaultClientMaxCapacity = 4096 // DefaultClientMaxConnections is set to 128. DefaultClientMaxConnections = 128 )
var ( DefaultServerTimeout = 10 * time.Second DefaultServerTimeToLive = 24 * time.Hour DefaultServerMaxConns = 5000 DefaultServerHost = "0.0.0.0" DefaultServerPort = uint16(18514) DefaultConnRateLimit = rate.Limit(10000) DefaultConnRateLimitBurst = 10000 DefaultBandwidthLimit = rate.Limit(500 * 1024 * 1024) // 4 MB DefaultBandwidthLimitBurst = 500 * 1024 * 1024 // 32 MB DefaultPreventDuplicateConns = true )
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
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.
type ClientOptions ¶
type ClientOptions struct { // Logger for all information/debugging/error output. Logger *zap.Logger // TimeToLive for connections. Connections with no 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 // TimeToDial for establishing new connections. After this duration has // passed, the dial attempt will be dropped. A new dial attempt will usually // be started, assuming that the client has not been attempting dials for // longer than the TimeToLive. TimeToDial time.Duration // MaxDialAttempts when establishing new connections. MaxDialAttempts int // MaxCapacity of messages that can be bufferred while waiting to write // messages to a channel. MaxCapacity int // MaxConnections is the maximum number of outbound connections that the // Client will have open. New connection attempts will error. MaxConnections 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 *zap.Logger) ClientOptions
func (ClientOptions) WithMaxCapacity ¶ added in v0.4.0
func (opts ClientOptions) WithMaxCapacity(capacity int) ClientOptions
func (ClientOptions) WithMaxConnections ¶
func (opts ClientOptions) WithMaxConnections(maxConnections int) ClientOptions
func (ClientOptions) WithMaxDialAttempts ¶
func (opts ClientOptions) WithMaxDialAttempts(dialAttempts 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 ¶
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 ServerConnPool ¶
type ServerConnPool struct {
// contains filtered or unexported fields
}
A ServerConnPool is used to manage connections from the perspective of a server. Its primary responsibility is ensuring that every IP address and every cryptographic identity only has one active connection, where new connections will replace old connections.
func NewServerConnPool ¶
func NewServerConnPool(maxConns int64, preventDuplicateConns bool) ServerConnPool
NewServerConnPool returns an empty connection pool. Because this pool exists to prevent duplicate connections, and connections do not persist across reboots, the pool does not need to be persisted across reboots. In other words, this method is sufficient to construct a new connection pool.
func (*ServerConnPool) AddToRemoteAddress ¶
func (pool *ServerConnPool) AddToRemoteAddress(ip string, conn net.Conn) uint64
AddToRemoteAddress will add a connection and associate it with an IP address. Any previous connection associated with this IP address will be closed (and error caused by the closure will be ignored). This method returns a token that can be used to explicitly remove the connection.
func (*ServerConnPool) AddToRemoteSignatory ¶
AddToRemoteSignatory will add a connection and associate it with a signatory. Any previous connection associated with this signatory will be closed (any error caused by the closure will be ignored). This method returns a token that can be used to explicitly remove the connection.
func (*ServerConnPool) RemoveFromRemoteAddress ¶
func (pool *ServerConnPool) RemoveFromRemoteAddress(ip string, tok uint64)
RemoveFromRemoteAddress removes an IP address from the map, unless the provided token is no longer the most recent token, and closes any associated connection (any error caused by the closure will be ignored).
func (*ServerConnPool) RemoveFromRemoteSignatory ¶
func (pool *ServerConnPool) RemoveFromRemoteSignatory(signatory id.Signatory, tok uint64)
RemoveFromRemoteSignatory removes a signatory from the map, unless the provided token is no longer the most recent token, and closes any associated connection (any error caused by the closure will be ignored).
func (*ServerConnPool) Signal ¶
func (pool *ServerConnPool) Signal()
Signal that an existing connection has been closed.
func (*ServerConnPool) Wait ¶
func (pool *ServerConnPool) Wait()
Wait until the there are available connections. If the maximum number of connections have already been established, then this method will block until one of the existing connections is closed.
type ServerOptions ¶
type ServerOptions struct { Logger *zap.Logger Timeout time.Duration TimeToLive time.Duration MaxConns int Host string Port uint16 RateLimit rate.Limit RateLimitBurst int BandwidthLimit rate.Limit BandwidthLimitBurst int PreventDuplicateConns bool }
func DefaultServerOptions ¶ added in v0.3.0
func DefaultServerOptions() ServerOptions
func (ServerOptions) WithBandwidthLimit ¶
func (opts ServerOptions) WithBandwidthLimit(bandwidthLimit rate.Limit) ServerOptions
func (ServerOptions) WithBandwidthLimitBurst ¶
func (opts ServerOptions) WithBandwidthLimitBurst(bandwidthLimitBurst int) 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 *zap.Logger) ServerOptions
WithLogger sets the logger that will be used by the server.
func (ServerOptions) WithMaxConns ¶
func (opts ServerOptions) WithMaxConns(maxConns int) ServerOptions
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.
func (ServerOptions) WithPreventDuplicateConns ¶
func (opts ServerOptions) WithPreventDuplicateConns(preventDuplicateConns bool) ServerOptions
func (ServerOptions) WithRateLimit ¶
func (opts ServerOptions) WithRateLimit(rateLimit rate.Limit) ServerOptions
func (ServerOptions) WithRateLimitBurst ¶
func (opts ServerOptions) WithRateLimitBurst(rateLimitBurst int) ServerOptions
func (ServerOptions) WithTimeToLive ¶
func (opts ServerOptions) WithTimeToLive(timeToLive time.Duration) ServerOptions
func (ServerOptions) WithTimeout ¶
func (opts ServerOptions) WithTimeout(timeout time.Duration) ServerOptions