Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
a1dcaea
connmgr: Add context-aware semaphore.
davecgh May 17, 2026
704eb85
connmgr: Add semaphore tests.
davecgh May 17, 2026
7db9f9e
connmgr: Overhaul to use wrapped conns plus ctx.
davecgh May 17, 2026
9ad909d
connmgr: Make max retry duration a field.
davecgh May 20, 2026
61122e4
connmgr: Correct shutdown failed conns test.
davecgh May 24, 2026
1ef516b
connmgr: Add double close tests.
davecgh May 17, 2026
a3f4690
connmgr: Add duplicate conn rejection tests.
davecgh May 17, 2026
9e6fe37
connmgr: Add max persistent conns test.
davecgh May 17, 2026
354adde
connmgr: Add disconnect by id tests.
davecgh May 17, 2026
bd5aaf2
connmgr: Add remove by id tests.
davecgh May 17, 2026
3b78fbb
connmgr: Update README.md.
davecgh May 17, 2026
1cc2fa7
connmgr: Add internal state test assertions.
davecgh May 23, 2026
76bf202
connmgr: Support whitelisting.
davecgh May 18, 2026
78e734f
connmgr: Add whitelist detection tests.
davecgh May 21, 2026
b2f6007
server: Integrate connmgr whitelisting.
davecgh May 18, 2026
dc4cd88
connmgr: Update README.md for whitelist support.
davecgh May 21, 2026
26ea64f
connmgr: Add try acquire support to semaphore.
davecgh May 19, 2026
0b85a38
connmgr: Add semaphore try acquire tests.
davecgh May 19, 2026
6f13d36
connmgr: Limit total overall normal connections.
davecgh May 19, 2026
9b30eee
connmgr: Add total max normal conns tests.
davecgh May 19, 2026
aedda39
connmgr: Update README.md for total conn limits.
davecgh May 21, 2026
c7fe6c9
connmgr: Limit max connections per host.
davecgh May 21, 2026
8036544
connmgr: Add max per-host conn tests.
davecgh May 21, 2026
a295a18
connmgr: Update README.md for per-host conn limits.
davecgh May 21, 2026
9cf1f5b
connmgr: Separate mock conn and addr test code.
davecgh May 23, 2026
b883470
connmgr: Use more modern t.Cleanup in tests.
davecgh May 23, 2026
f1d87b8
connmgr: Consistent naming in tests.
davecgh May 23, 2026
70003a1
connmgr: Only close once in double close tests.
davecgh May 26, 2026
acd90f5
connmgr: Cleaner dial timeout detection test.
davecgh May 26, 2026
ab0af2a
connmgr: Use synctest for max retry duration test.
davecgh May 24, 2026
5749dba
connmgr: Add deterministic CSPRNG for tests.
davecgh May 24, 2026
3752a4f
connmgr: Implement exponential backoff with jitter.
davecgh May 24, 2026
74c2dab
connmgr: Update README.md for jitter.
davecgh May 25, 2026
049ed41
connmgr: Wait for all goroutines to finish.
davecgh May 27, 2026
807597b
connmgr: Use addr generator in tests.
davecgh May 27, 2026
f7343e4
connmgr: Use concrete addrmgr types in test.
davecgh May 27, 2026
0c54169
connmgr: Use concrete addr type more often.
davecgh May 27, 2026
b8356ca
connmgr: Add outbound group support to tests.
davecgh May 27, 2026
4d7dff2
connmgr: Limit auto outbounds per group.
davecgh May 27, 2026
e88fe13
connmgr: Add outbound group tests.
davecgh May 27, 2026
8ba39ea
connmgr: Update README.md for outbound groups.
davecgh Jun 1, 2026
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
64 changes: 49 additions & 15 deletions internal/connmgr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,60 @@ 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.
Package `connmgr` provides a flexible and robust context-aware connection
manager for inbound, outbound, and persistent network connections with retry
logic.

It handles all general connection lifecycle concerns such as accepting inbound
connections, automatically maintaining a set number of outbound connections,
maintaining persistent connections, enforcing limits, and preventing duplicates.

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

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.
The following is a brief overview of the key features:

In addition the connection manager provides the following utilities:
- 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`)
- Strongly prefers connections to different network segments
- Incorporates intelligent address selection
- Skips addresses in already-connected outbound groups
- Skips recently attempted addresses unless no suitable addresses are found
after enough retries
- Prefers default peer-to-peer port addresses (configurable via `DefaultPort`)
- Persistent connections
- Maintains up to `MaxPersistent` addresses that are automatically retried
with exponential backoff and jitter on disconnect
- Manual connections
- Supports manual connection establishment via `Connect`
- Connection limits
- Limits total normal (non-persistent) connections to `MaxNormalConns`
- Limits per-host connections to `MaxConnsPerHost` with exemptions for
whitelisted and loopback addresses
- Duplicate address prevention
- Rejects duplicate connections to and from the same address (host:port)
- Whitelist support
- CIDR-based whitelists that allow bypassing certain limits and restrictions
- Rich managed connections 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`
- Notification callbacks
- Provides callbacks for connection establishment and disconnects
- Graceful network outage handling
- Automatic connection attempts are throttled during network outages
- Clear and actionable programatically-detectable errors

- 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
A full suite of tests is provided to help ensure proper functionality.

## License

Expand Down
Loading