Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 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
1a32f18
connmgr: Limit max connections per host.
davecgh May 21, 2026
8f9ff58
connmgr: Add max per-host conn tests.
davecgh May 21, 2026
a09f8f5
connmgr: Update README.md for per-host conn limits.
davecgh May 21, 2026
4d627a4
connmgr: Separate mock conn and addr test code.
davecgh May 23, 2026
b2b20c9
connmgr: Use more modern t.Cleanup in tests.
davecgh May 23, 2026
f776538
connmgr: Consistent naming in tests.
davecgh May 23, 2026
817edd6
connmgr: Use more modern t.Context in tests.
davecgh Jun 8, 2026
bd5bf25
connmgr: Only close once in double close tests.
davecgh May 26, 2026
1ce361d
connmgr: Cleaner dial timeout detection test.
davecgh May 26, 2026
0669e96
connmgr: Use synctest for max retry duration test.
davecgh May 24, 2026
5a8df14
connmgr: Add deterministic CSPRNG for tests.
davecgh May 24, 2026
6553231
connmgr: Implement exponential backoff with jitter.
davecgh May 24, 2026
6be73ed
connmgr: Update README.md for jitter.
davecgh May 25, 2026
ce4dd53
connmgr: Wait for all goroutines to finish.
davecgh May 27, 2026
4040caf
connmgr: Use addr generator in tests.
davecgh May 27, 2026
7faf0ea
connmgr: Use concrete addrmgr types in test.
davecgh May 27, 2026
e829674
connmgr: Use concrete addr type more often.
davecgh May 27, 2026
913f3d7
connmgr: Add outbound group support to tests.
davecgh May 27, 2026
07b51bb
connmgr: Limit auto outbounds per group.
davecgh May 27, 2026
d190342
connmgr: Add outbound group tests.
davecgh May 27, 2026
929aa0f
connmgr: Update README.md for outbound groups.
davecgh Jun 1, 2026
cfb50a7
ratelimit: Introduce new internal package.
davecgh Jun 1, 2026
eae7af1
ratelimit: Add allow and max duration tests.
davecgh Jun 1, 2026
09264c4
ratelimit: Add allow example.
davecgh Jun 1, 2026
ea7b0dc
ratelimit: Add README.md.
davecgh Jun 1, 2026
82ec86f
connmgr: Add inbound rate limiting.
davecgh Jun 1, 2026
e170d00
connmgr: Add rate limiting tests.
davecgh Jun 1, 2026
f895318
connmgr: Add inbound anti-flooding measures.
davecgh Jun 1, 2026
7b47062
connmgr: Add anti-flood tests.
davecgh Jun 1, 2026
392ca86
connmgr: Update README.md for inbound limiting.
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.24.0

require (
github.com/davecgh/go-spew v1.1.1
github.com/dchest/siphash v1.2.3
github.com/decred/base58 v1.0.6
github.com/decred/dcrd/addrmgr/v4 v4.0.0
github.com/decred/dcrd/bech32 v1.1.4
Expand Down Expand Up @@ -49,7 +50,6 @@ require (
decred.org/cspp/v2 v2.4.0 // indirect
github.com/agl/ed25519 v0.0.0-20170116200512-5312a6153412 // indirect
github.com/companyzero/sntrup4591761 v0.0.0-20220309191932-9e0f3af2f07a // indirect
github.com/dchest/siphash v1.2.3 // indirect
github.com/decred/dcrd/dcrec/edwards/v2 v2.0.4 // indirect
github.com/decred/dcrd/hdkeychain/v3 v3.1.3 // indirect
github.com/golang/snappy v0.0.4 // indirect
Expand Down
71 changes: 56 additions & 15 deletions internal/connmgr/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,67 @@ 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, preventing duplicates, and enforcing
multiple layers of connection limits and anti-abuse protections.

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
- Provides token bucket rate limiting on a per network group basis
- Anti-flood protection
- Detects floods based on allowed connection attempts
- Dynamically coarsens network group rate limiting during flooding
- Probabilistically drops connections when flooding is active via an S-curve
- Rate limits logging of dropped 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