Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions addrmgr/netaddress.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,18 @@ func (netAddr *NetAddress) Key() string {
return net.JoinHostPort(netAddr.ipString(), portString)
}

// Network returns the name of the network. It is always tcp.
//
// This is part of the [net.Addr] implementation.
func (netAddr *NetAddress) Network() string {
return "tcp"
}

// String returns a human-readable string for the network address. This is
// equivalent to calling Key, but is provided so the type can be used as a
// fmt.Stringer.
//
// This is part of the [net.Addr] implementation.
func (netAddr *NetAddress) String() string {
return netAddr.Key()
}
Expand Down
58 changes: 40 additions & 18 deletions internal/connmgr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,48 @@ connmgr
[![ISC License](https://img.shields.io/badge/license-ISC-blue.svg)](http://copyfree.org)
[![Doc](https://img.shields.io/badge/doc-reference-blue.svg)](https://pkg.go.dev/github.com/decred/dcrd/internal/connmgr)

Package connmgr implements a generic Decred network connection manager.

## Overview

This package handles all the general connection concerns such as maintaining a
set number of outbound connections, sourcing peers, banning, limiting max
connections, tor lookup, etc.

The package provides a generic connection manager which is able to accept
connection requests from a source or a set of given addresses, dial them and
notify the caller on connections. The main intended use is to initialize a pool
of active connections and maintain them to remain connected to the P2P network.

In addition the connection manager provides the following utilities:

- Notifications on connections or disconnections
- Handle failures and retry new addresses from the source
- Connect only to specified addresses
- Permanent connections with increasing backoff retry timers
- Disconnect or Remove an established connection
Package `connmgr` provides a flexible and robust context-aware connection
manager for inbound, outbound, and persistent network connections with retry
logic.

In short, it handles all general connection concerns such as accepting inbound
connections, automatically maintaining a set number of outbound connections,
maintaining persistent connections, and limiting max connections.

The design has a strong emphasis on reliability, readability, and efficiency
while also aiming to provide an ergonomic API.

The following is a brief overview of the key features:

- Full context support
- Inbound listening
- Accepts inbound connections on provided `Listeners`
- Uses connection shedding for rejected inbound connections
- Automatic outbound maintenance
- Maintains up to `TargetOutbound` normal outbound connections via a provided
address source (`GetNewAddress`)
- Persistent connections
- Maintains up to `MaxPersistent` addresses that are automatically retried
with exponential backoff on disconnect
- Manual connections
- Supports manual connection establishment via `Connect`
- Custom connection wrapping via `Conn`
- Connection types for differentiated handling
- Automatic cleanup on connection close
- Concrete parsed address access
- Manual disconnection and removal
- Ability to disconnect / remove established, pending, and persistent
connections via `Disconnect` and `Remove`
- Duplicate address prevention
- Rejects duplicate connections to and from the same address (host:port)
- Notification callbacks
- Provides callbacks for connection establishment and disconnects
- Graceful network outage handling
- Automatic connection attempts are throttled during network outages

A full suite of tests is provided to help ensure proper functionality.

## License

Expand Down
Loading