Documentation
¶
Index ¶
- Constants
- type ConnectionClosedEvent
- type ConnectionManager
- func (c *ConnectionManager) AddConnection(conn *ouroboros.Connection, isInbound bool, peerAddr string)
- func (c *ConnectionManager) CreateOutboundConn(ctx context.Context, address string) (*ouroboros.Connection, error)
- func (c *ConnectionManager) GetConnectionById(connId ouroboros.ConnectionId) *ouroboros.Connection
- func (c *ConnectionManager) HandleConnectionRecycleRequestedEvent(evt event.Event)
- func (c *ConnectionManager) HasInboundPeerAddress(peerAddr string) bool
- func (c *ConnectionManager) IPConnCount(ipKey string) int
- func (c *ConnectionManager) InboundCount() int
- func (c *ConnectionManager) RemoveConnection(connId ouroboros.ConnectionId)
- func (c *ConnectionManager) Start(ctx context.Context) error
- func (c *ConnectionManager) Stop(ctx context.Context) error
- type ConnectionManagerConfig
- type ConnectionManagerConnClosedFunc
- type ConnectionRecycleRequestedEvent
- type InboundConnectionEvent
- type ListenerConfig
- type UnixConn
- type UnixConnAddr
Constants ¶
const ( InboundConnectionEventType = "connmanager.inbound_conn" ConnectionClosedEventType = "connmanager.conn_closed" ConnectionRecycleRequestedEventType = "connmanager.connection_recycle_requested" )
const DefaultMaxConnectionsPerIP = 5
DefaultMaxConnectionsPerIP is the default maximum number of concurrent connections allowed from a single IP address (or /64 prefix for IPv6).
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) HasInboundPeerAddress ¶ added in v0.27.1
func (c *ConnectionManager) HasInboundPeerAddress( peerAddr string, ) bool
HasInboundPeerAddress returns true if there is already an inbound connection from the same remote peer address as peerAddr.
This intentionally matches on the full remote address, not just the host. TCP collisions require the same 4-tuple, so a connection from the same host but a different source port must not suppress a valid outbound dial.
When OutboundSourcePort is set (listen-port reuse), an outbound connection to the same remote peer address may collide with an existing inbound connection if the peer also connected from its listening port. In that case the existing inbound connection should be treated as the reusable duplex connection, matching ouroboros-network's exact-address connection tracking.
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)
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 ListenerConfig ¶ added in v0.1.7
type UnixConn ¶ added in v0.4.0
UnixConn is a wrapper around net.UnixConn that provides a unique remote address
func (UnixConn) RemoteAddr ¶ added in v0.4.0
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