connmanager

package
v0.26.0 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2026 License: Apache-2.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	InboundConnectionEventType          = "connmanager.inbound_conn"
	ConnectionClosedEventType           = "connmanager.conn_closed"
	ConnectionRecycleRequestedEventType = "connmanager.connection_recycle_requested"
)
View Source
const DefaultMaxConnectionsPerIP = 5

DefaultMaxConnectionsPerIP is the default maximum number of concurrent connections allowed from a single IP address (or /64 prefix for IPv6).

View Source
const (

	// DefaultMaxInboundConnections is the default maximum number of
	// simultaneous inbound connections accepted by the connection manager.
	// This prevents resource exhaustion from malicious or accidental
	// connection floods.
	DefaultMaxInboundConnections = 100
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ConnectionClosedEvent added in v0.2.0

type ConnectionClosedEvent struct {
	ConnectionId ouroboros.ConnectionId
	Error        error
}

type ConnectionManager

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

func NewConnectionManager

func NewConnectionManager(cfg ConnectionManagerConfig) *ConnectionManager

func (*ConnectionManager) AddConnection

func (c *ConnectionManager) AddConnection(
	conn *ouroboros.Connection,
	isInbound bool,
	peerAddr string,
)

func (*ConnectionManager) CreateOutboundConn added in v0.2.0

func (c *ConnectionManager) CreateOutboundConn(
	ctx context.Context,
	address string,
) (*ouroboros.Connection, error)

func (*ConnectionManager) GetConnectionById

func (c *ConnectionManager) GetConnectionById(
	connId ouroboros.ConnectionId,
) *ouroboros.Connection

func (*ConnectionManager) HandleConnectionRecycleRequestedEvent added in v0.22.0

func (c *ConnectionManager) HandleConnectionRecycleRequestedEvent(
	evt event.Event,
)

HandleConnectionRecycleRequestedEvent closes a connection when a recycle request event is received.

func (*ConnectionManager) HasInboundFromHost added in v0.22.0

func (c *ConnectionManager) HasInboundFromHost(
	peerAddr string,
) bool

HasInboundFromHost returns true if there is already an inbound connection from the same host (IP) as peerAddr, regardless of port or DiffusionMode. When OutboundSourcePort is set (listen port reuse), an outbound connection to the same host would create an identical TCP 4-tuple and fail with EADDRINUSE. The existing inbound connection serves as the bidirectional link between the two nodes.

func (*ConnectionManager) IPConnCount added in v0.22.0

func (c *ConnectionManager) IPConnCount(ipKey string) int

ipConnCount returns the current connection count for an IP key. Exported for testing only.

func (*ConnectionManager) InboundCount added in v0.22.0

func (c *ConnectionManager) InboundCount() int

InboundCount returns the current number of inbound connections.

func (*ConnectionManager) RemoveConnection

func (c *ConnectionManager) RemoveConnection(connId ouroboros.ConnectionId)

func (*ConnectionManager) Start added in v0.1.7

func (c *ConnectionManager) Start(ctx context.Context) error

func (*ConnectionManager) Stop added in v0.18.0

func (c *ConnectionManager) Stop(ctx context.Context) error

type ConnectionManagerConfig

type ConnectionManagerConfig struct {
	PromRegistry       prometheus.Registerer
	Logger             *slog.Logger
	EventBus           *event.EventBus
	ConnClosedFunc     ConnectionManagerConnClosedFunc
	Listeners          []ListenerConfig
	OutboundConnOpts   []ouroboros.ConnectionOptionFunc
	OutboundSourcePort uint
	MaxInboundConns    int // 0 means use DefaultMaxInboundConnections
	// MaxConnectionsPerIP limits the number of concurrent inbound
	// connections from the same IP address. IPv6 addresses are grouped
	// by /64 prefix. A value of 0 means use DefaultMaxConnectionsPerIP.
	MaxConnectionsPerIP int
}

type ConnectionManagerConnClosedFunc

type ConnectionManagerConnClosedFunc func(ouroboros.ConnectionId, error)

ConnectionManagerConnClosedFunc is a function that takes a connection ID and an optional error

type ConnectionRecycleRequestedEvent added in v0.22.0

type ConnectionRecycleRequestedEvent struct {
	ConnectionId ouroboros.ConnectionId
	ConnKey      string
	Reason       string
}

ConnectionRecycleRequestedEvent requests that a specific connection be recycled.

type InboundConnectionEvent added in v0.1.7

type InboundConnectionEvent struct {
	ConnectionId ouroboros.ConnectionId
	LocalAddr    net.Addr
	RemoteAddr   net.Addr
	IsNtC        bool // true for node-to-client (local) connections
}

type ListenerConfig added in v0.1.7

type ListenerConfig struct {
	Listener       net.Listener
	ListenNetwork  string
	ListenAddress  string
	ConnectionOpts []ouroboros.ConnectionOptionFunc
	UseNtC         bool
	ReuseAddress   bool
}

type UnixConn added in v0.4.0

type UnixConn struct {
	*net.UnixConn
	// contains filtered or unexported fields
}

UnixConn is a wrapper around net.UnixConn that provides a unique remote address

func NewUnixConn added in v0.4.0

func NewUnixConn(conn net.Conn) (*UnixConn, error)

func (UnixConn) RemoteAddr added in v0.4.0

func (u UnixConn) RemoteAddr() net.Addr

type UnixConnAddr added in v0.4.0

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

func (UnixConnAddr) Network added in v0.4.0

func (UnixConnAddr) Network() string

func (UnixConnAddr) String added in v0.4.0

func (u UnixConnAddr) String() string

Jump to

Keyboard shortcuts

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