What changed, and why it matters
This is a large maintenance update for btcd that upgrades Go and many dependencies, replaces some old external libraries with newer or in-house ones, and fixes several bugs in RPC, Tor proxy, and build processes. Most changes are not security fixes by themselves, but a few areas have clear defensive value: websocket authentication now has size limits and a timeout, websocket writes have a timeout, SOCKS/Tor proxy handling was rewritten, and peer inventory is now compared by value rather than by pointer. The commit does not describe itself as a security patch and no CVE is mentioned.
Review the new internal/socks package and the websocket authentication/timeout changes for correctness. Run the new tests, especially rpcwebsocket_test.go, rpcclient/infrastructure_test.go, and internal/socks/socks_test.go. Verify that dependency upgrades do not break downstream consumers. Consider whether the unauthenticated read limit and auth timeout should be configurable. No immediate emergency action is indicated, but operators should upgrade to benefit from the hardening and dependency updates.
Security signals we found
Unauthenticated websocket read limit added (64 KiB) to prevent large-message abuse before auth
Websocket authentication timeout added to drop unauthenticated clients
Websocket write timeout added to prevent slow/stalled clients from hanging server goroutines
Normal websocket close frames no longer logged as errors, reducing noise and improving disconnect handling
SOCKS/Tor proxy code rewritten in internal/socks with explicit Tor stream isolation and proxied address semantics
Peer known-inventory lookup changed from pointer identity to value equality, fixing duplicate inventory handling
Dependency bumps include golang.org/x/crypto and golang.org/x/net, which may include upstream security fixes
Windows service install now uses ErrorNormal for boot-time failure logging
Evidence from the diff
The commit bumps Go to 1.26.9/1.27.2, updates golang.org/x/crypto, golang.org/x/net, golang.org/x/sys, golang.org/x/time, dcrd dependencies, testify, goleveldb, and others. It replaces github.com/btcsuite/go-socks with a new internal/socks package wrapping golang.org/x/net/proxy, preserving Tor stream isolation and proxied address semantics. It replaces github.com/btcsuite/websocket with github.com/gorilla/websocket, and github.com/btcsuite/winsvc with golang.org/x/sys/windows/svc. It migrates decred/dcrd/lru to decred/dcrd/container/lru with typed generics. Notable behavior changes include: rpcwebsocket.go now limits unauthenticated websocket reads to 64 KiB, sets a 15-second authentication timeout, and sets a 5-minute write timeout; rpcclient now treats normal websocket close frames as non-errors and adds a handshake timeout; peer.go compares known inventory by value instead of pointer identity; config.go clarifies Tor isolation logic; and Windows service installation now sets ErrorNormal. Many new tests cover these behaviors.
Changed components
rpcwebsocket.gorpcclient/infrastructure.gointernal/sockspeer/peer.goconfig.goserver.goservice_windows.goDockerfile and CI workflowsgo.mod/go.sum across all modulesInspect captured patch +1848 / −309
### .github/workflows/Dockerfile
@@ -5,19 +5,20 @@
###########################
# Build binaries stage
###########################
-FROM --platform=$BUILDPLATFORM golang:1.26-alpine AS build
+FROM --platform=$BUILDPLATFORM golang:1.27.2-alpine3.24@sha256:85dc1069ac644ea3c527b177303a406eb3358192816cd7f9e5848eb658851673 AS build
ADD . /app
WORKDIR /app
# Arguments required to build binaries targetting the correct OS and CPU architectures
ARG TARGETOS TARGETARCH
-# Actually building the binaries
-RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go install -v . ./cmd/...
+# Build into a flat directory. When cross-compiling, go install would put the
+# binaries into a per-platform subdirectory such as /go/bin/linux_arm64.
+RUN GOOS=$TARGETOS GOARCH=$TARGETARCH go build -v -o /out/ . ./cmd/...
###########################
# Build docker image stage
###########################
-FROM alpine:3.15
-COPY --from=build /go/bin /bin
+FROM alpine:3.24
+COPY --from=build /out/ /bin/
# 8333 Mainnet Bitcoin peer-to-peer port
# 8334 Mainet RPC port
EXPOSE 8333 8334
### .github/workflows/dimagespub.yml
@@ -23,27 +23,27 @@ jobs:
steps:
- name: Checkout repository
- uses: actions/checkout@v4
+ uses: actions/checkout@v7
- name: Docker Setup Buildx
id: buildx
- uses: docker/setup-buildx-action@94ab11c41e45d028884a99163086648e898eed25
+ uses: docker/setup-buildx-action@f87e5991a6d7451dcb8d9637bfbc97413f497069 # v4.4.1
- name: Log in to the Container registry
- uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9
+ uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f # v4.6.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for Docker
id: meta
- uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38
+ uses: docker/metadata-action@dc802804100637a589fabce1cb79ff13a1411302 # v6.2.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
- name: Build and push Docker images
- uses: docker/build-push-action@ac9327eae2b366085ac7f6a2d02df8aa8ead720a
+ uses: docker/build-push-action@c3c9e263c25d99ce0380d002d59b67737d91b0dc # v7.4.0
with:
file: .github/workflows/Dockerfile
labels: ${{ steps.meta.outputs.labels }}
### .github/workflows/go-versions.yml
@@ -0,0 +1,20 @@
+name: Go version policy
+
+# Fails when a new Go release leaves the repo behind the Go version policy in
+# README.md, so the versions get bumped.
+on:
+ schedule:
+ # Every Monday at 06:00 UTC.
+ - cron: '0 6 * * 1'
+ workflow_dispatch:
+
+jobs:
+ check:
+ name: Check Go versions
+ runs-on: ubuntu-latest
+ steps:
+ - name: Check out source
+ uses: actions/checkout@v7
+
+ - name: Check Go versions
+ run: ./scripts/check_go_versions.sh
### .github/workflows/main.yml
@@ -6,20 +6,20 @@ env:
GOCACHE: /home/runner/work/go/pkg/build
GOPATH: /home/runner/work/go
GOBIN: /home/runner/work/go/bin
- GO_VERSION: 1.26.3
+ GO_VERSION: 1.27.2
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- name: Set up Go
- uses: actions/setup-go@v5
+ uses: actions/setup-go@v7
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out source
- uses: actions/checkout@v4
+ uses: actions/checkout@v7
- name: Build
run: make build
@@ -37,12 +37,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
- uses: actions/setup-go@v5
+ uses: actions/setup-go@v7
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out source
- uses: actions/checkout@v4
+ uses: actions/checkout@v7
- name: Test
run: make unit-cover
@@ -125,6 +125,15 @@ jobs:
format: 'golang'
parallel: true
+ - name: Send v2transport coverage
+ uses: coverallsapp/github-action@v2
+ continue-on-error: true
+ with:
+ file: v2transport/coverage.txt
+ flag-name: v2transport
+ format: 'golang'
+ parallel: true
+
- name: Notify coveralls all reports sent
uses: coverallsapp/github-action@v2
continue-on-error: true
@@ -136,12 +145,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
- uses: actions/setup-go@v5
+ uses: actions/setup-go@v7
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out source
- uses: actions/checkout@v4
+ uses: actions/checkout@v7
- name: Test
run: make unit-race
@@ -151,12 +160,63 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Set up Go
- uses: actions/setup-go@v5
+ uses: actions/setup-go@v7
+ with:
+ go-version: ${{ env.GO_VERSION }}
+
+ - name: Check out source
+ uses: actions/checkout@v7
+
+ - name: Test
+ run: make unit
+
+ # Builds and tests with the minimum Go version from go.mod, so code that
+ # needs a newer Go than go.mod promises fails here (see the Go version policy
+ # in README.md).
+ test-min-go:
+ name: Minimum Go version
+ runs-on: ubuntu-latest
+ env:
+ # Fail rather than switch to a newer Go if a go.mod asks for one.
+ GOTOOLCHAIN: local
+ steps:
+ - name: Check out source
+ uses: actions/checkout@v7
+
+ - name: Set up Go
+ uses: actions/setup-go@v7
+ with:
+ go-version-file: go.mod
+
+ - name: Build
+ run: make build
+
+ - name: Test
+ run: make unit
+
+ # The go.mod files require the published versions of the other modules in
+ # this repo. This job builds and tests all modules against each other's
+ # in-tree code instead, so a change to a sub-module is checked against the
+ # code that uses it before the sub-module is tagged.
+ test-workspace:
+ name: In-tree modules
+ runs-on: ubuntu-latest
+ steps:
+ - name: Set up Go
+ uses: actions/setup-go@v7
with:
go-version: ${{ env.GO_VERSION }}
- name: Check out source
- uses: actions/checkout@v4
+ uses: actions/checkout@v7
+
+ - name: Create workspace
+ run: |
+ find . -mindepth 2 -name go.mod -printf '%h\n' | sort |
+ xargs go work init .
+ # Even in a workspace, ./... from the root doesn't reach the nested
+ # modules. make unit tests each module from its own directory, which
+ # also builds all of their packages.
- name: Test
run: make unit
### Dockerfile
@@ -6,7 +6,7 @@
#
# You can use the following command to build an arm64v8 container:
#
-# docker build . -t yourregistry/btcd --build-arg ARCH=arm64v8
+# docker build . -t yourregistry/btcd --platform linux/arm64 --build-arg ARCH=arm64v8
#
# For more information how to use this docker image visit:
# https://github.com/btcsuite/btcd/tree/master/docs
@@ -19,9 +19,11 @@ ARG ARCH=amd64
# https://github.com/opencontainers/image-spec/blob/main/descriptor.md#digests
# https://cloud.google.com/architecture/using-container-images
# https://github.com/google/go-containerregistry/blob/main/cmd/crane/README.md
-# ➜ ~ crane digest golang:1.23.12-alpine3.21
-# sha256:4bb4be21ac98da06bc26437ee870c4973f8039f13e9a1a36971b4517632b0fc6
-FROM golang@sha256:4bb4be21ac98da06bc26437ee870c4973f8039f13e9a1a36971b4517632b0fc6 AS build-container
+# ➜ ~ crane digest golang:1.27.2-alpine3.24
+# sha256:85dc1069ac644ea3c527b177303a406eb3358192816cd7f9e5848eb658851673
+# Build on the host platform and cross-compile for ARCH, so no emulation is
+# needed for other architectures.
+FROM --platform=$BUILDPLATFORM golang@sha256:85dc1069ac644ea3c527b177303a406eb3358192816cd7f9e5848eb658851673 AS build-container
ARG ARCH
@@ -32,11 +34,11 @@ RUN set -ex \
&& if [ "${ARCH}" = "arm32v7" ]; then export GOARCH=arm; fi \
&& if [ "${ARCH}" = "arm64v8" ]; then export GOARCH=arm64; fi \
&& echo "Compiling for $GOARCH" \
- && go install -v . ./cmd/...
+ && go build -v -o /out/ . ./cmd/...
-FROM $ARCH/alpine:3.21
+FROM $ARCH/alpine:3.24
-COPY --from=build-container /go/bin /bin
+COPY --from=build-container /out/ /bin/
VOLUME ["/root/.btcd"]
### Makefile
@@ -13,8 +13,8 @@ endif
LINT_BIN := $(GO_BIN)/golangci-lint
GOIMPORTS_BIN := $(GO_BIN)/goimports
-LINT_COMMIT := v2.1.6
-GOIMPORTS_COMMIT := a24facf9e5586c95743d2f4ad15d148c7a8cf00b
+LINT_COMMIT := v2.14.0
+GOIMPORTS_COMMIT := v0.51.0
GOBUILD := go build -v
GOINSTALL := go install -v
@@ -104,6 +104,7 @@ unit:
cd txscript && $(GOTEST_DEV) ./... -test.timeout=20m
cd psbt && $(GOTEST_DEV) ./... -test.timeout=20m
cd wire && $(GOTEST_DEV) ./... -test.timeout=20m
+ cd v2transport && $(GOTEST_DEV) ./... -test.timeout=20m
#? unit-cover: Run unit coverage tests
unit-cover:
@@ -120,6 +121,7 @@ unit-cover:
cd txscript && $(GOTEST) $(COVER_FLAGS) ./... && sed -i.bak 's/v2\///g' coverage.txt
cd psbt && $(GOTEST) $(COVER_FLAGS) ./... && sed -i.bak 's/v2\///g' coverage.txt
cd wire && $(GOTEST) $(COVER_FLAGS) ./... && sed -i.bak 's/v2\///g' coverage.txt
+ cd v2transport && $(GOTEST) $(COVER_FLAGS) ./... && sed -i.bak 's/v2\///g' coverage.txt
#? unit-race: Run unit race tests
unit-race:
@@ -133,6 +135,7 @@ unit-race:
cd txscript && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
cd psbt && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
cd wire && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
+ cd v2transport && env CGO_ENABLED=1 GORACE="history_size=7 halt_on_errors=1" $(GOTEST) -race -test.timeout=20m ./...
# =========
# UTILITIES
@@ -161,6 +164,11 @@ tidy-module:
echo "Running 'go mod tidy' for all modules"
scripts/tidy_modules.sh
+#? check-go-versions: Check that Go versions follow the policy in README.md
+check-go-versions:
+ @$(call print, "Checking Go versions.")
+ scripts/check_go_versions.sh
+
.PHONY: all \
default \
build \
@@ -171,7 +179,8 @@ tidy-module:
fmt \
lint \
clean \
- tidy-module
+ tidy-module \
+ check-go-versions
#? help: Get more info on make commands
help: Makefile
### README.md
@@ -36,7 +36,23 @@ which are both under active development.
## Requirements
-[Go](http://golang.org) 1.25 or newer.
+[Go](http://golang.org) 1.26.9 or newer.
+
+### Go version policy
+
+btcd is built with the newest Go release and requires the previous one, which
+still receives point releases. Both are kept at the latest point release of
+their branch:
+
+- CI, the Docker images and release binaries are built with Go 1.27.2, the
+ `GO_VERSION` in `.github/workflows/main.yml`.
+- The `go` line in every `go.mod`, which sets the minimum Go version and the
+ language version, is Go 1.26.9.
+
+Both are bumped when Go publishes a point release, and both move up a branch
+when a new major version of Go is released. A weekly CI job checks this against
+the releases listed on go.dev; `make check-go-versions` runs the same check
+locally.
## Installation
### address/go.mod
@@ -1,20 +1,18 @@
module github.com/btcsuite/btcd/address/v2
-go 1.25
+go 1.26.9
require (
github.com/btcsuite/btcd/btcec/v2 v2.5.0
github.com/btcsuite/btcd/chaincfg/v2 v2.0.0
github.com/btcsuite/btcd/wire/v2 v2.0.0
- github.com/stretchr/testify v1.10.0
- golang.org/x/crypto v0.40.0
+ github.com/stretchr/testify v1.12.1
+ golang.org/x/crypto v0.57.0
)
require (
github.com/btcsuite/btcd/chainhash/v2 v2.0.0 // indirect
- github.com/davecgh/go-spew v1.1.1 // indirect
- github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
+ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 // indirect
+ go.yaml.in/yaml/v3 v3.0.5 // indirect
+ golang.org/x/sys v0.48.0 // indirect
)
### address/go.sum
@@ -8,17 +8,13 @@ github.com/btcsuite/btcd/wire/v2 v2.0.0 h1:mYSKzZZ0a1sK+aMhXzfDSVsSzRkWkU3x2U04T
github.com/btcsuite/btcd/wire/v2 v2.0.0/go.mod h1:bGxkPkk8IiDvUo1D96wE03llBIk7p2MdWYRyAQwLmqM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
-github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
+github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
+github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
+go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
+go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
### btcec/go.mod
@@ -1,16 +1,15 @@
module github.com/btcsuite/btcd/btcec/v2
-go 1.25
+go 1.26.9
require (
github.com/btcsuite/btcd/chainhash/v2 v2.0.0
github.com/davecgh/go-spew v1.1.1
- github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0
- github.com/stretchr/testify v1.8.0
+ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1
+ github.com/stretchr/testify v1.12.1
)
require (
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
+ go.yaml.in/yaml/v3 v3.0.5 // indirect
)
### btcec/go.sum
@@ -1,21 +1,12 @@
github.com/btcsuite/btcd/chainhash/v2 v2.0.0 h1:PMLlSloHJuEeB80XG9EjpXWNEKAZAMLl6YHZ6YsEuoA=
github.com/btcsuite/btcd/chainhash/v2 v2.0.0/go.mod h1:mKxcZ7oGTXE7IRV+sS9hP4EVBwc/SzfNR+52IsOP9j8=
-github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
-github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
-github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
-github.com/stretchr/testify v1.8.0 h1:pSgiaMZlXftHpm5L7V1+rVB+AZJydKsMxsQBIJw4PKk=
-github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
+github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
+github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
+go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
+go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
### btcutil/go.mod
@@ -1,6 +1,6 @@
module github.com/btcsuite/btcd/btcutil/v2
-go 1.25
+go 1.26.9
require (
github.com/aead/siphash v1.0.1
@@ -11,13 +11,13 @@ require (
github.com/btcsuite/btcd/txscript/v2 v2.0.0
github.com/btcsuite/btcd/wire/v2 v2.0.0
github.com/davecgh/go-spew v1.1.1
- github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0
+ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1
github.com/kkdai/bstream v1.0.0
)
require (
github.com/btcsuite/btclog v1.0.0 // indirect
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
- golang.org/x/crypto v0.40.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
+ golang.org/x/crypto v0.57.0 // indirect
+ golang.org/x/sys v0.48.0 // indirect
)
### btcutil/go.sum
@@ -18,17 +18,17 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
github.com/kkdai/bstream v1.0.0 h1:Se5gHwgp2VT2uHfDrkbbgbgEvV9cimLELwrPJctSjg8=
github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
### chaincfg/go.mod
@@ -1,17 +1,16 @@
module github.com/btcsuite/btcd/chaincfg/v2
-go 1.25
+go 1.26.9
require (
github.com/btcsuite/btcd/chainhash/v2 v2.0.0
github.com/btcsuite/btcd/wire/v2 v2.0.0
github.com/davecgh/go-spew v1.1.1
- github.com/stretchr/testify v1.10.0
+ github.com/stretchr/testify v1.12.1
)
require (
- github.com/pmezard/go-difflib v1.0.0 // indirect
- golang.org/x/crypto v0.40.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
+ go.yaml.in/yaml/v3 v3.0.5 // indirect
+ golang.org/x/crypto v0.57.0 // indirect
+ golang.org/x/sys v0.48.0 // indirect
)
### chaincfg/go.sum
@@ -4,15 +4,11 @@ github.com/btcsuite/btcd/wire/v2 v2.0.0 h1:mYSKzZZ0a1sK+aMhXzfDSVsSzRkWkU3x2U04T
github.com/btcsuite/btcd/wire/v2 v2.0.0/go.mod h1:bGxkPkk8IiDvUo1D96wE03llBIk7p2MdWYRyAQwLmqM=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
-github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
+github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
+go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
+go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
### chainhash/go.mod
@@ -1,3 +1,3 @@
module github.com/btcsuite/btcd/chainhash/v2
-go 1.25
+go 1.26.9
### cmd/btcctl/httpclient.go
@@ -12,7 +12,7 @@ import (
"os"
"github.com/btcsuite/btcd/btcjson"
- "github.com/btcsuite/go-socks/socks"
+ "github.com/btcsuite/btcd/internal/socks"
)
// newHTTPClient returns a new HTTP client that is configured according to the
### config.go
@@ -30,10 +30,10 @@ import (
"github.com/btcsuite/btcd/connmgr"
"github.com/btcsuite/btcd/database"
_ "github.com/btcsuite/btcd/database/ffldb"
+ "github.com/btcsuite/btcd/internal/socks"
"github.com/btcsuite/btcd/mempool"
"github.com/btcsuite/btcd/peer"
"github.com/btcsuite/btcd/wire/v2"
- "github.com/btcsuite/go-socks/socks"
flags "github.com/jessevdk/go-flags"
)
@@ -104,6 +104,13 @@ func validateMaxPeers(maxPeers int) error {
return nil
}
+// proxyTorIsolation returns whether connections through --proxy use Tor stream
+// isolation. When --onion is set too, --proxy isn't the Tor proxy and the
+// onion proxy is isolated instead.
+func proxyTorIsolation(torIsolation bool, onionProxy string) bool {
+ return torIsolation && onionProxy == ""
+}
+
// config defines the configuration options for btcd.
//
// See loadConfig for details on the configuration load process.
@@ -1079,11 +1086,12 @@ func loadConfig() (*config, []string, error) {
// Tor isolation flag means proxy credentials will be overridden
// unless there is also an onion proxy configured in which case
// that one will be overridden.
- torIsolation := false
- if cfg.TorIsolation && cfg.OnionProxy == "" &&
+ torIsolation := proxyTorIsolation(
+ cfg.TorIsolation, cfg.OnionProxy,
+ )
+ if torIsolation &&
(cfg.ProxyUser != "" || cfg.ProxyPass != "") {
- torIsolation = true
fmt.Fprintln(os.Stderr, "Tor isolation set -- "+
"overriding specified proxy user credentials")
}
### config_test.go
@@ -32,6 +32,36 @@ func TestValidateMaxPeers(t *testing.T) {
}
}
+// TestProxyTorIsolation checks when --torisolation applies to --proxy: always,
+// unless --onion is set too, in which case it applies to the onion proxy.
+func TestProxyTorIsolation(t *testing.T) {
+ tests := []struct {
+ name string
+ torIsolation bool
+ onionProxy string
+ want bool
+ }{
+ {name: "isolation", torIsolation: true, want: true},
+ {name: "no isolation"},
+ {
+ name: "bridge mode",
+ torIsolation: true,
+ onionProxy: "127.0.0.1:9050",
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ got := proxyTorIsolation(
+ test.torIsolation, test.onionProxy,
+ )
+ if got != test.want {
+ t.Fatalf("got %v, want %v", got, test.want)
+ }
+ })
+ }
+}
+
var (
rpcuserRegexp = regexp.MustCompile("(?m)^rpcuser=.+$")
rpcpassRegexp = regexp.MustCompile("(?m)^rpcpass=.+$")
### go.mod
@@ -1,6 +1,6 @@
module github.com/btcsuite/btcd
-go 1.25.0
+go 1.26.9
require (
github.com/btcsuite/btcd/address/v2 v2.0.0
@@ -12,32 +12,29 @@ require (
github.com/btcsuite/btcd/v2transport v1.1.0
github.com/btcsuite/btcd/wire/v2 v2.0.1
github.com/btcsuite/btclog v1.0.0
- github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd
- github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792
- github.com/btcsuite/winsvc v1.0.0
github.com/davecgh/go-spew v1.1.1
- github.com/decred/dcrd/lru v1.1.3
+ github.com/decred/dcrd/container/lru v1.0.0
github.com/gorilla/websocket v1.5.3
github.com/jessevdk/go-flags v1.6.1
github.com/jrick/logrotate v1.1.2
- github.com/stretchr/testify v1.10.0
- github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7
- golang.org/x/crypto v0.40.0
- golang.org/x/sys v0.35.0
- golang.org/x/time v0.15.0
- pgregory.net/rapid v1.2.0
+ github.com/stretchr/testify v1.12.1
+ github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d
+ golang.org/x/crypto v0.57.0
+ golang.org/x/net v0.60.0
+ golang.org/x/sys v0.48.0
+ golang.org/x/time v0.16.0
+ pgregory.net/rapid v1.3.0
)
require (
github.com/aead/siphash v1.0.1 // indirect
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
- github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
+ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 // indirect
github.com/golang/snappy v1.0.0 // indirect
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee // indirect
github.com/kkdai/bstream v1.0.0 // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
- github.com/stretchr/objx v0.5.2 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
+ github.com/stretchr/objx v0.5.3 // indirect
+ go.yaml.in/yaml/v3 v3.0.5 // indirect
)
// The retract statements below fixes an accidental push of the tags of a btcd
### go.sum
@@ -18,39 +18,44 @@ github.com/btcsuite/btcd/wire/v2 v2.0.1 h1:edmb35tvRyQpFp331L9PwZFccaTCOQwevSsU6
github.com/btcsuite/btcd/wire/v2 v2.0.1/go.mod h1:ENBpJL0JYUNlqvajhIFTOcWGNNumjCynDk4PL0OG58I=
github.com/btcsuite/btclog v1.0.0 h1:sEkpKJMmfGiyZjADwEIgB1NSwMyfdD1FB8v6+w1T0Ns=
github.com/btcsuite/btclog v1.0.0/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ=
-github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd h1:R/opQEbFEy9JGkIguV40SvRY1uliPX8ifOvi6ICsFCw=
-github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg=
-github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792 h1:R8vQdOQdZ9Y3SkEwmHoWBmX1DNXhXZqlTpq6s4tyJGc=
-github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY=
-github.com/btcsuite/winsvc v1.0.0 h1:J9B4L7e3oqhXOcm+2IuNApwzQec85lE+QaikUcCs+dk=
-github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs=
+github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
+github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=
+github.com/chzyer/test v0.0.0-20180213035817-a1ea475d72b1/go.mod h1:Q3SI9o4m/ZMnBNeIyt5eFwwo7qiLfzFZmjNmxjkiQlU=
+github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
+github.com/decred/dcrd/container/lru v1.0.0 h1:7foQymtbu18aQWYiY9RnNIeE+kvpiN+fiBQ3+viyJjI=
+github.com/decred/dcrd/container/lru v1.0.0/go.mod h1:vlPwj0l+IzAHhQSsbgQnJgO5Cte78+yI065V+Mc5PRQ=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
-github.com/decred/dcrd/lru v1.1.3 h1:w9EAbvGLyzm6jTjF83UKuqZEiUtJmvRhQDOCEIvSuE0=
-github.com/decred/dcrd/lru v1.1.3/go.mod h1:Tw0i0pJyiLEx/oZdHLe1Wdv/Y7EGzAX+sYftnmxBR4o=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
-github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
+github.com/fsnotify/fsnotify v1.5.4 h1:jRbGcIw6P2Meqdwuo0H1p6JVLbL5DHKAKlYndzMwVZI=
+github.com/fsnotify/fsnotify v1.5.4/go.mod h1:OVB6XrOHzAwXMpEM7uPOzcehqUV2UqJxmVXmkdnm1bU=
+github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8=
github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA=
github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs=
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
+github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
+github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/golang/snappy v1.0.0 h1:Oy607GVXHs7RtbggtPBnr2RmDArIsAefDwvrdWvRhGs=
github.com/golang/snappy v1.0.0/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
+github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38/go.mod h1:kpwsk12EmLew5upagYY7GY0pfYCcupk39gWOCRROcvE=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
+github.com/ianlancetaylor/demangle v0.0.0-20200824232613-28f6c0f3b639/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/jessevdk/go-flags v1.6.1 h1:Cvu5U8UGrLay1rZfv/zP7iLpSHGUZ/Ou68T0iX1bBK4=
github.com/jessevdk/go-flags v1.6.1/go.mod h1:Mk8T1hIAWpOiJiHa9rJASDK2UGWji0EuPGBnNLMooyc=
github.com/jrick/logrotate v1.1.2 h1:6ePk462NCX7TfKtNp5JJ7MbA2YIslkpfgP03TlTYMN0=
@@ -59,71 +64,105 @@ github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee h1:FPP9HDkBbPyni
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee/go.mod h1:N6sz6HwJAenJ6d+/xmSl0ikfV05ZrVGmjt1ryy/WOtE=
github.com/kkdai/bstream v1.0.0 h1:Se5gHwgp2VT2uHfDrkbbgbgEvV9cimLELwrPJctSjg8=
github.com/kkdai/bstream v1.0.0/go.mod h1:FDnDOHt5Yx4p3FaHcioFT0QjDOtgUpvjeZqAs+NVZZA=
-github.com/nxadm/tail v1.4.4 h1:DQuhQpB1tVlglWS2hLQ5OV6B5r8aGxSrPc5Qo6uTN78=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
+github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
+github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk=
-github.com/onsi/ginkgo v1.14.0 h1:2mOpI4JVVPBN+WQRa0WKH2eXR+Ey+uK4n7Zj0aYpIQA=
-github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY=
+github.com/onsi/ginkgo v1.16.4/go.mod h1:dX+/inL/fNMqNlz0e9LfyB9TswhZpCVdJM/Z6Vvnwo0=
+github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE=
+github.com/onsi/ginkgo v1.16.5/go.mod h1:+E8gABHa3K6zRBolWtd+ROzc/U5bkGt0FwiG042wbpU=
+github.com/onsi/ginkgo/v2 v2.1.3/go.mod h1:vw5CSIxN1JObi/U8gcbwft7ZxR2dgaR70JSE3/PpL4c=
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
-github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
+github.com/onsi/gomega v1.17.0/go.mod h1:HnhC7FXeEQY45zxNK3PPoIUhzk/80Xly9PcubAlGdZY=
+github.com/onsi/gomega v1.19.0 h1:4ieX6qQjPP/BfC3mpsAtIGGlxTWPeA3Inl/7DtXw1tw=
+github.com/onsi/gomega v1.19.0/go.mod h1:LY+I3pBVzYsTBU1AnDwOSxaYi9WoWiqgwooUqq9yPro=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY=
-github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA=
-github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
-github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7 h1:epCh84lMvA70Z7CTTCmYQn2CKbY8j86K7/FAIr141uY=
-github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
+github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
+github.com/stretchr/objx v0.5.3 h1:jmXUvGomnU1o3W/V5h2VEradbpJDwGrzugQQvL0POH4=
+github.com/stretchr/objx v0.5.3/go.mod h1:rDQraq+vQZU7Fde9LOZLr8Tax6zZvy4kuNKF+QYS+U0=
+github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
+github.com/stretchr/testify v1.7.2/go.mod h1:R6va5+xMeoiuVRoj+gSkQ7d3FALtqAAGI1FQKckRals=
+github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
+github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
+github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d h1:vfofYNRScrDdvS342BElfbETmL1Aiz3i2t0zfRj16Hs=
+github.com/syndtr/goleveldb v1.0.1-0.20220721030215-126854af5e6d/go.mod h1:RRCYJbIwD5jmqPI9XoAFR0OcDxqUctll6zUj/+B4S48=
+github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
+go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
+go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
+golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
-golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
-golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
-golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
+golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
+golang.org/x/net v0.0.0-20210428140749-89ef3d95e781/go.mod h1:OJAsFXCWl8Ukc7SiCT/9KSuxbyM7479/AVlXFRxuMCk=
+golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk=
+golang.org/x/net v0.0.0-20220607020251-c690dde0001d/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
+golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
+golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
+golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20191204072324-ce4227a45e2e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
+golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210112080510-489259a85091/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
+golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
+golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
+golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
-golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
-golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
-golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
-golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U=
-golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno=
+golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
+golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
+golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
+golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
+golang.org/x/time v0.16.0 h1:vMb6ptszcQMkcwiRTAuNNU50gom6++Q/6gY2hDM6VDE=
+golang.org/x/time v0.16.0/go.mod h1:rVKOqvZeKvrDKTQiAHJ7wmwP0RzleSphoEA9RcdLA0s=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
+golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
+golang.org/x/tools v0.0.0-20201224043029-2b0845dc783e/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
+golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
-golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
+golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8=
google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0=
google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM=
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
+google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
+google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ=
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
+gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
+gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
+gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
-pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk=
-pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04=
+pgregory.net/rapid v1.3.0 h1:vBvO0VSqti75J1jjYqpgPNBLKMd1+gxa9fYo7vk/Exc=
+pgregory.net/rapid v1.3.0/go.mod h1:dPlE4OBBxgXPqkP79flB6sJL1dx5azpI7HQ9MY9Z7uk=
### integration/p2a_test.go
@@ -197,4 +197,3 @@ func TestPayToAnchorSimple(t *testing.T) {
}
})
}
-
### internal/inbound/admission.go
@@ -9,7 +9,7 @@ import (
"sync/atomic"
"time"
- "github.com/decred/dcrd/lru"
+ "github.com/decred/dcrd/container/lru"
"golang.org/x/time/rate"
)
@@ -89,7 +89,7 @@ type Admission struct {
now func() time.Time
v2SourceMu sync.Mutex
- v2SourceLimiters lru.KVCache
+ v2SourceLimiters *lru.Map[netip.Prefix, *rate.Limiter]
v2SourceRate rate.Limit
v2SourceBurst int
@@ -158,9 +158,11 @@ func newAdmission(cfg admissionConfig) *Admission {
v2Limiter: rate.NewLimiter(cfg.v2Rate, cfg.v2Burst),
v2Slots: make(chan struct{}, cfg.v2Concurrency),
now: cfg.now,
- v2SourceLimiters: lru.NewKVCache(cfg.v2SourceCacheSize),
- v2SourceRate: cfg.v2SourceRate,
- v2SourceBurst: cfg.v2SourceBurst,
+ v2SourceLimiters: lru.NewMap[netip.Prefix, *rate.Limiter](
+ uint32(cfg.v2SourceCacheSize),
+ ),
+ v2SourceRate: cfg.v2SourceRate,
+ v2SourceBurst: cfg.v2SourceBurst,
sourceLog: rate.Sometimes{
First: 3,
Interval: 30 * time.Second,
@@ -388,14 +390,14 @@ func (a *Admission) reserveV2Source(
) (*rate.Reservation, bool) {
a.v2SourceMu.Lock()
- value, ok := a.v2SourceLimiters.Lookup(prefix)
+ limiter, ok := a.v2SourceLimiters.Get(prefix)
if !ok {
- value = rate.NewLimiter(a.v2SourceRate, a.v2SourceBurst)
- a.v2SourceLimiters.Add(prefix, value)
+ limiter = rate.NewLimiter(a.v2SourceRate, a.v2SourceBurst)
+ a.v2SourceLimiters.Put(prefix, limiter)
}
a.v2SourceMu.Unlock()
- return reserveImmediate(value.(*rate.Limiter), now)
+ return reserveImmediate(limiter, now)
}
// logV2Rejection records and occasionally logs a rejected v2 handshake.
### internal/socks/socks.go
@@ -0,0 +1,184 @@
+// Package socks dials connections through a SOCKS5 proxy such as Tor.
+//
+// It wraps golang.org/x/net/proxy and keeps the behavior btcd relied on from
+// github.com/btcsuite/go-socks:
+//
+// - A connection reports the requested destination as its remote address,
+// and the address the proxy bound for it as its local address, rather
+// than the addresses of the connection to the proxy.
+// - With Tor stream isolation, every connection authenticates with new
+// random credentials, so Tor puts it on a circuit of its own.
+// - Destinations are sent to the proxy unresolved, so the proxy resolves
+// hostnames, including onion addresses.
+package socks
+
+import (
+ "context"
+ "crypto/rand"
+ "encoding/hex"
+ "net"
+ "strconv"
+ "time"
+
+ "golang.org/x/net/proxy"
+)
+
+// Proxy dials connections through a SOCKS5 proxy.
+type Proxy struct {
+ // Addr is the host:port address of the proxy.
+ Addr string
+
+ // Username and Password are the credentials for the proxy, if it
+ // requires them. They are ignored when TorIsolation is set.
+ Username string
+ Password string
+
+ // TorIsolation makes every connection authenticate with new random
+ // credentials, which Tor uses to isolate it on a circuit of its own.
+ TorIsolation bool
+}
+
+// ProxiedAddr is the address of a connection made through a proxy. Host may
+// be a hostname, such as an onion address, since the proxy resolves it.
+type ProxiedAddr struct {
+ Net string
+ Host string
+ Port int
+}
+
+// Network returns the network of the address, such as "tcp".
+func (a *ProxiedAddr) Network() string {
+ return a.Net
+}
+
+// String returns the address in host:port form.
+func (a *ProxiedAddr) String() string {
+ return net.JoinHostPort(a.Host, strconv.Itoa(a.Port))
+}
+
+// Dial connects to addr through the proxy.
+func (p *Proxy) Dial(network, addr string) (net.Conn, error) {
+ return p.DialContext(context.Background(), network, addr)
+}
+
+// DialTimeout is like Dial, but gives up after timeout, which covers both
+// connecting to the proxy and the SOCKS handshake. A zero timeout means no
+// timeout.
+func (p *Proxy) DialTimeout(network, addr string,
+ timeout time.Duration) (net.Conn, error) {
+
+ ctx := context.Background()
+ if timeout > 0 {
+ var cancel context.CancelFunc
+ ctx, cancel = context.WithTimeout(ctx, timeout)
+ defer cancel()
+ }
+
+ return p.DialContext(ctx, network, addr)
+}
+
+// DialContext connects to addr through the proxy. The network is "tcp",
+// "tcp4", "tcp6" or "onion", which btcd uses for onion addresses. The context
+// covers both connecting to the proxy and the SOCKS handshake.
+func (p *Proxy) DialContext(ctx context.Context, network,
+ addr string) (net.Conn, error) {
+
+ host, portStr, err := net.SplitHostPort(addr)
+ if err != nil {
+ return nil, err
+ }
+ port, err := strconv.Atoi(portStr)
+ if err != nil {
+ return nil, err
+ }
+
+ auth, err := p.auth()
+ if err != nil {
+ return nil, err
+ }
+ dialer, err := proxy.SOCKS5("tcp", p.Addr, auth, proxy.Direct)
+ if err != nil {
+ return nil, err
+ }
+
+ // x/net doesn't know the "onion" network. The proxy connects to onion
+ // addresses over TCP like to any other host.
+ proxyNetwork := network
+ if network == "onion" {
+ proxyNetwork = "tcp"
+ }
+
+ // The SOCKS5 dialer implements DialContext, which, unlike its Dial,
+ // returns a connection that knows the address the proxy bound.
+ conn, err := dialer.(proxy.ContextDialer).DialContext(
+ ctx, proxyNetwork, addr,
+ )
+ if err != nil {
+ return nil, err
+ }
+
+ var boundAddr net.Addr
+ if c, ok := conn.(interface{ BoundAddr() net.Addr }); ok {
+ boundAddr = c.BoundAddr()
+ }
+
+ return &proxiedConn{
+ Conn: conn,
+ boundAddr: boundAddr,
+ remoteAddr: &ProxiedAddr{
+ Net: network,
+ Host: host,
+ Port: port,
+ },
+ }, nil
+}
+
+// auth returns the credentials to authenticate with the proxy, or nil to not
+// authenticate.
+func (p *Proxy) auth() (*proxy.Auth, error) {
+ if p.TorIsolation {
+ var b [16]byte
+ if _, err := rand.Read(b[:]); err != nil {
+ return nil, err
+ }
+
+ return &proxy.Auth{
+ User: hex.EncodeToString(b[:8]),
+ Password: hex.EncodeToString(b[8:]),
+ }, nil
+ }
+
+ // SOCKS5 username/password authentication needs a username.
+ if p.Username == "" {
+ return nil, nil
+ }
+
+ return &proxy.Auth{User: p.Username, Password: p.Password}, nil
+}
+
+// proxiedConn is a connection made through a proxy.
+type proxiedConn struct {
+ net.Conn
+
+ // boundAddr is the address the proxy bound for the connection, if it
+ // reported one.
+ boundAddr net.Addr
+
+ // remoteAddr is the requested destination.
+ remoteAddr *ProxiedAddr
+}
+
+// LocalAddr returns the address the proxy bound for the connection, or the
+// local address of the connection to the proxy if it didn't report one.
+func (c *proxiedConn) LocalAddr() net.Addr {
+ if c.boundAddr != nil {
+ return c.boundAddr
+ }
+
+ return c.Conn.LocalAddr()
+}
+
+// RemoteAddr returns the requested destination.
+func (c *proxiedConn) RemoteAddr() net.Addr {
+ return c.remoteAddr
+}
### internal/socks/socks_test.go
@@ -0,0 +1,326 @@
+package socks
+
+import (
+ "bytes"
+ "encoding/binary"
+ "io"
+ "net"
+ "strconv"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/stretchr/testify/require"
+)
+
+// testTimeout bounds how long a test waits for the test proxy.
+const testTimeout = 5 * time.Second
+
+// proxyRequest is what a client sent to the test proxy.
+type proxyRequest struct {
+ // user and pass are the credentials the client authenticated with, if
+ // any.
+ user, pass string
+
+ // addrType is the SOCKS address type of the destination.
+ addrType byte
+
+ // host and port are the requested destination.
+ host string
+ port int
+}
+
+// successReply is the reply of a SOCKS5 proxy that connected to the
+// destination and reports 0.0.0.0:0 as the bound address, as Tor does.
+var successReply = []byte{5, 0, 0, 1, 0, 0, 0, 0, 0, 0}
+
+// startProxy runs a minimal SOCKS5 proxy that sends reply to every connect
+// request, then keeps the connection open. It returns the proxy address and a
+// channel that receives each request.
+func startProxy(t *testing.T, reply []byte) (string, chan proxyRequest) {
+ t.Helper()
+
+ ln, err := net.Listen("tcp", "127.0.0.1:0")
+ require.NoError(t, err)
+ t.Cleanup(func() {
+ _ = ln.Close()
+ })
+
+ requests := make(chan proxyRequest, 10)
+ go func() {
+ for {
+ conn, err := ln.Accept()
+ if err != nil {
+ return
+ }
+ go func() {
+ defer conn.Close()
+
+ req, err := readRequest(conn)
+ if err != nil {
+ return
+ }
+ requests <- req
+ if _, err := conn.Write(reply); err != nil {
+ return
+ }
+ _, _ = io.Copy(io.Discard, conn)
+ }()
+ }
+ }()
+
+ return ln.Addr().String(), requests
+}
+
+// readRequest reads the method negotiation, the optional username/password
+// authentication and the connect request of a SOCKS5 client.
+func readRequest(conn net.Conn) (proxyRequest, error) {
+ var req proxyRequest
+
+ // Greeting: version, number of methods, methods.
+ header := make([]byte, 2)
+ if _, err := io.ReadFull(conn, header); err != nil {
+ return req, err
+ }
+ methods := make([]byte, header[1])
+ if _, err := io.ReadFull(conn, methods); err != nil {
+ return req, err
+ }
+
+ // Pick username/password authentication when offered.
+ if !bytes.Contains(methods, []byte{2}) {
+ if _, err := conn.Write([]byte{5, 0}); err != nil {
+ return req, err
+ }
+ } else {
+ if _, err := conn.Write([]byte{5, 2}); err != nil {
+ return req, err
+ }
+ user, pass, err := readCredentials(conn)
+ if err != nil {
+ return req, err
+ }
+ req.user, req.pass = user, pass
+ if _, err := conn.Write([]byte{1, 0}); err != nil {
+ return req, err
+ }
+ }
+
+ // Request: version, command, reserved, address type, address, port.
+ head := make([]byte, 4)
+ if _, err := io.ReadFull(conn, head); err != nil {
+ return req, err
+ }
+ req.addrType = head[3]
+
+ var addr []byte
+ switch req.addrType {
+ case 1:
+ addr = make([]byte, net.IPv4len)
+ case 4:
+ addr = make([]byte, net.IPv6len)
+ case 3:
+ length := make([]byte, 1)
+ if _, err := io.ReadFull(conn, length); err != nil {
+ return req, err
+ }
+ addr = make([]byte, length[0])
+ }
+ if _, err := io.ReadFull(conn, addr); err != nil {
+ return req, err
+ }
+ if req.addrType == 3 {
+ req.host = string(addr)
+ } else {
+ req.host = net.IP(addr).String()
+ }
+
+ port := make([]byte, 2)
+ if _, err := io.ReadFull(conn, port); err != nil {
+ return req, err
+ }
+ req.port = int(binary.BigEndian.Uint16(port))
+
+ return req, nil
+}
+
+// readCredentials reads a username/password authentication request.
+func readCredentials(conn net.Conn) (string, string, error) {
+ var b [1]byte
+ field := func() (string, error) {
+ if _, err := io.ReadFull(conn, b[:]); err != nil {
+ return "", err
+ }
+ value := make([]byte, b[0])
+ _, err := io.ReadFull(conn, value)
+
+ return string(value), err
+ }
+
+ // Version of the subnegotiation.
+ if _, err := io.ReadFull(conn, b[:]); err != nil {
+ return "", "", err
+ }
+ user, err := field()
+ if err != nil {
+ return "", "", err
+ }
+ pass, err := field()
+
+ return user, pass, err
+}
+
+// receive returns the next request the test proxy received.
+func receive(t *testing.T, requests chan proxyRequest) proxyRequest {
+ t.Helper()
+
+ select {
+ case req := <-requests:
+ return req
+
+ case <-time.After(testTimeout):
+ t.Fatal("the proxy received no request")
+ return proxyRequest{}
+ }
+}
+
+// dial dials addr through p and closes the connection when the test ends.
+func dial(t *testing.T, p *Proxy, addr string) net.Conn {
+ t.Helper()
+
+ conn, err := p.DialTimeout("tcp", addr, testTimeout)
+ require.NoError(t, err)
+ t.Cleanup(func() {
+ _ = conn.Close()
+ })
+
+ return conn
+}
+
+// TestDialAddresses checks that a connection reports the destination as its
+// remote address and the address bound by the proxy as its local address.
+func TestDialAddresses(t *testing.T) {
+ t.Parallel()
+
+ proxyAddr, requests := startProxy(t, successReply)
+ conn := dial(t, &Proxy{Addr: proxyAddr}, "1.2.3.4:8333")
+
+ req := receive(t, requests)
+ require.Equal(t, byte(1), req.addrType)
+ require.Equal(t, "1.2.3.4", req.host)
+ require.Equal(t, 8333, req.port)
+ require.Empty(t, req.user)
+
+ require.Equal(t, &ProxiedAddr{Net: "tcp", Host: "1.2.3.4", Port: 8333},
+ conn.RemoteAddr())
+ require.Equal(t, "0.0.0.0:0", conn.LocalAddr().String())
+}
+
+// TestDialHostname checks that a hostname is sent to the proxy unresolved and
+// reported as the remote address, also with the "onion" network, which btcd
+// uses to dial onion addresses.
+func TestDialHostname(t *testing.T) {
+ t.Parallel()
+
+ host := "vww6ybal4bd7szmgncyruucpgfkqahzddi37ktceo3ah7ngmcopnpyyd.onion"
+ addr := net.JoinHostPort(host, "8333")
+
+ for _, network := range []string{"tcp", "onion"} {
+ proxyAddr, requests := startProxy(t, successReply)
+ p := &Proxy{Addr: proxyAddr}
+ conn, err := p.DialTimeout(network, addr, testTimeout)
+ require.NoError(t, err, network)
+ t.Cleanup(func() {
+ _ = conn.Close()
+ })
+
+ req := receive(t, requests)
+ require.Equal(t, byte(3), req.addrType, network)
+ require.Equal(t, host, req.host, network)
+ want := &ProxiedAddr{Net: network, Host: host, Port: 8333}
+ require.Equal(t, want, conn.RemoteAddr())
+ }
+}
+
+// TestDialCredentials checks that the configured credentials are sent to the
+// proxy.
+func TestDialCredentials(t *testing.T) {
+ t.Parallel()
+
+ proxyAddr, requests := startProxy(t, successReply)
+ p := &Proxy{Addr: proxyAddr, Username: "user", Password: "pass"}
+ dial(t, p, "1.2.3.4:8333")
+
+ req := receive(t, requests)
+ require.Equal(t, "user", req.user)
+ require.Equal(t, "pass", req.pass)
+}
+
+// TestDialTorIsolation checks that with Tor stream isolation, every
+// connection uses new random credentials instead of the configured ones.
+func TestDialTorIsolation(t *testing.T) {
+ t.Parallel()
+
+ proxyAddr, requests := startProxy(t, successReply)
+ p := &Proxy{
+ Addr: proxyAddr,
+ Username: "user",
+ Password: "pass",
+ TorIsolation: true,
+ }
+
+ dial(t, p, "1.2.3.4:8333")
+ first := receive(t, requests)
+ dial(t, p, "1.2.3.4:8333")
+ second := receive(t, requests)
+
+ for _, req := range []proxyRequest{first, second} {
+ require.Len(t, req.user, 16)
+ require.Len(t, req.pass, 16)
+ require.NotEqual(t, "user", req.user)
+ }
+ require.NotEqual(t, first.user, second.user)
+ require.NotEqual(t, first.pass, second.pass)
+}
+
+// TestDialLongBoundHostname checks that a long hostname as the bound address
+// in the proxy's reply is handled. btcsuite/go-socks panicked on it.
+func TestDialLongBoundHostname(t *testing.T) {
+ t.Parallel()
+
+ name := strings.Repeat("a", 255)
+ reply := append([]byte{5, 0, 0, 3, byte(len(name))}, name...)
+ reply = append(reply, 0x20, 0x8d)
+
+ proxyAddr, _ := startProxy(t, reply)
+ conn := dial(t, &Proxy{Addr: proxyAddr}, "1.2.3.4:8333")
+
+ require.Equal(t, net.JoinHostPort(name, strconv.Itoa(8333)),
+ conn.LocalAddr().String())
+}
+
+// TestDialTimeout checks that the timeout covers the SOCKS handshake, so a
+// proxy that never answers can't hang the dial.
+func TestDialTimeout(t *testing.T) {
+ t.Parallel()
+
+ ln, err := net.Listen("tcp", "127.0.0.1:0")
+ require.NoError(t, err)
+ t.Cleanup(func() {
+ _ = ln.Close()
+ })
+ go func() {
+ conn, err := ln.Accept()
+ if err != nil {
+ return
+ }
+ defer conn.Close()
+ _, _ = io.Copy(io.Discard, conn)
+ }()
+
+ p := &Proxy{Addr: ln.Addr().String()}
+ start := time.Now()
+ _, err = p.DialTimeout("tcp", "1.2.3.4:8333", 100*time.Millisecond)
+ require.Error(t, err)
+ require.Less(t, time.Since(start), testTimeout)
+}
### mempool/mempooltest/mocks.go
@@ -1,11 +1,14 @@
-package mempool
+// Package mempooltest provides test helpers for code that uses the mempool
+// package.
+package mempooltest
import (
"time"
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/btcutil/v2"
"github.com/btcsuite/btcd/chainhash/v2"
+ "github.com/btcsuite/btcd/mempool"
"github.com/btcsuite/btcd/wire/v2"
"github.com/stretchr/testify/mock"
)
@@ -16,7 +19,7 @@ type MockTxMempool struct {
}
// Ensure the MockTxMempool implements the TxMemPool interface.
-var _ TxMempool = (*MockTxMempool)(nil)
+var _ mempool.TxMempool = (*MockTxMempool)(nil)
// LastUpdated returns the last time a transaction was added to or removed from
// the source pool.
@@ -26,9 +29,9 @@ func (m *MockTxMempool) LastUpdated() time.Time {
}
// TxDescs returns a slice of descriptors for all the transactions in the pool.
-func (m *MockTxMempool) TxDescs() []*TxDesc {
+func (m *MockTxMempool) TxDescs() []*mempool.TxDesc {
args := m.Called()
- return args.Get(0).([]*TxDesc)
+ return args.Get(0).([]*mempool.TxDesc)
}
// RawMempoolVerbose returns all the entries in the mempool as a fully
@@ -74,15 +77,15 @@ func (m *MockTxMempool) HaveTransaction(hash *chainhash.Hash) bool {
// such as rejecting duplicate transactions, ensuring transactions follow all
// rules, orphan transaction handling, and insertion into the memory pool.
func (m *MockTxMempool) ProcessTransaction(tx *btcutil.Tx, allowOrphan,
- rateLimit bool, tag Tag) ([]*TxDesc, error) {
+ rateLimit bool, tag mempool.Tag) ([]*mempool.TxDesc, error) {
args := m.Called(tx, allowOrphan, rateLimit, tag)
if args.Get(0) == nil {
return nil, args.Error(1)
}
- return args.Get(0).([]*TxDesc), args.Error(1)
+ return args.Get(0).([]*mempool.TxDesc), args.Error(1)
}
// RemoveTransaction removes the passed transaction from the mempool. When the
@@ -100,15 +103,15 @@ func (m *MockTxMempool) RemoveTransaction(tx *btcutil.Tx,
// transaction can be accepted to the mempool. If not, the specific error is
// returned and the caller needs to take actions based on it.
func (m *MockTxMempool) CheckMempoolAcceptance(
- tx *btcutil.Tx) (*MempoolAcceptResult, error) {
+ tx *btcutil.Tx) (*mempool.MempoolAcceptResult, error) {
args := m.Called(tx)
if args.Get(0) == nil {
return nil, args.Error(1)
}
- return args.Get(0).(*MempoolAcceptResult), args.Error(1)
+ return args.Get(0).(*mempool.MempoolAcceptResult), args.Error(1)
}
// CheckSpend checks whether the passed outpoint is already spent by a
### peer/inventory_test.go
@@ -0,0 +1,31 @@
+package peer
+
+import (
+ "testing"
+
+ "github.com/btcsuite/btcd/chainhash/v2"
+ "github.com/btcsuite/btcd/wire/v2"
+ "github.com/stretchr/testify/require"
+)
+
+// TestKnownInventoryByValue checks that known inventory is matched by its
+// type and hash rather than by pointer, so that inventory a peer announced is
+// known when it arrives again in another message.
+func TestKnownInventoryByValue(t *testing.T) {
+ p := NewInboundPeer(&Config{})
+
+ hash := chainhash.Hash{1}
+ p.AddKnownInventory(wire.NewInvVect(wire.InvTypeTx, &hash))
+
+ require.True(t, p.knowsInventory(
+ wire.NewInvVect(wire.InvTypeTx, &hash),
+ ))
+ require.False(t, p.knowsInventory(
+ wire.NewInvVect(wire.InvTypeBlock, &hash),
+ ))
+
+ other := chainhash.Hash{2}
+ require.False(t, p.knowsInventory(
+ wire.NewInvVect(wire.InvTypeTx, &other),
+ ))
+}
### peer/p2pdowngrader.go
@@ -1,7 +1,7 @@
package peer
import (
- "github.com/decred/dcrd/lru"
+ "github.com/decred/dcrd/container/lru"
)
const (
@@ -14,7 +14,7 @@ const (
// with the v1 P2P protocol on their next connection, typically after a v2
// handshake failure.
type P2PDowngrader struct {
- cache lru.Cache
+ cache *lru.Set[string]
}
// NewP2PDowngrader returns a new P2PDowngrader instance.
@@ -24,14 +24,14 @@ func NewP2PDowngrader(cacheSize uint) *P2PDowngrader {
cacheSize = defaultDowngradeCacheSize
}
return &P2PDowngrader{
- cache: lru.NewCache(cacheSize),
+ cache: lru.NewSet[string](uint32(cacheSize)),
}
}
// MarkForDowngrade flags an address so that the next outbound connection
// attempt to it will use the v1 P2P protocol.
func (pd *P2PDowngrader) MarkForDowngrade(addr string) {
- pd.cache.Add(addr)
+ pd.cache.Put(addr)
log.Debugf("P2PDowngrader: Marked %s for v1 downgrade", addr)
}
### peer/peer.go
@@ -22,11 +22,11 @@ import (
"github.com/btcsuite/btcd/blockchain"
"github.com/btcsuite/btcd/chaincfg/v2"
"github.com/btcsuite/btcd/chainhash/v2"
+ "github.com/btcsuite/btcd/internal/socks"
"github.com/btcsuite/btcd/v2transport"
"github.com/btcsuite/btcd/wire/v2"
- "github.com/btcsuite/go-socks/socks"
"github.com/davecgh/go-spew/spew"
- "github.com/decred/dcrd/lru"
+ "github.com/decred/dcrd/container/lru"
)
const (
@@ -85,7 +85,7 @@ var (
// sentNonces houses the unique nonces that are generated when pushing
// version messages that are used to detect self connections.
- sentNonces = lru.NewCache(50)
+ sentNonces = lru.NewSet[uint64](50)
)
// MessageListeners defines callback function pointers to invoke with message
@@ -478,7 +478,7 @@ type Peer struct {
wireEncoding wire.MessageEncoding
- knownInventory lru.Cache
+ knownInventory *lru.Set[wire.InvVect]
prevGetBlocksMtx sync.Mutex
prevGetBlocksBegin *chainhash.Hash
prevGetBlocksStop *chainhash.Hash
@@ -549,7 +549,16 @@ func (p *Peer) UpdateLastAnnouncedBlock(blkHash *chainhash.Hash) {
//
// This function is safe for concurrent access.
func (p *Peer) AddKnownInventory(invVect *wire.InvVect) {
- p.knownInventory.Add(invVect)
+ p.knownInventory.Put(*invVect)
+}
+
+// knowsInventory returns whether the peer is known to have the passed
+// inventory. Inventory is matched by value, since the same inventory arrives
+// in different messages.
+//
+// This function is safe for concurrent access.
+func (p *Peer) knowsInventory(invVect *wire.InvVect) bool {
+ return p.knownInventory.Contains(*invVect)
}
// StatsSnapshot returns a snapshot of the current peer flags and statistics.
@@ -1767,7 +1776,7 @@ out:
// Don't send inventory that became known after
// the initial check.
- if p.knownInventory.Contains(iv) {
+ if p.knowsInventory(iv) {
continue
}
@@ -1973,7 +1982,7 @@ func (p *Peer) QueueMessageWithEncoding(msg wire.Message, doneChan chan<- struct
func (p *Peer) QueueInventory(invVect *wire.InvVect) {
// Don't add the inventory to the send queue if the peer is already
// known to have it.
- if p.knownInventory.Contains(invVect) {
+ if p.knowsInventory(invVect) {
return
}
@@ -2189,7 +2198,7 @@ func (p *Peer) localVersionMsg() (*wire.MsgVersion, error) {
// detected. This is accomplished by adding it to a size-limited map of
// recently seen nonces.
nonce := uint64(rand.Int63())
- sentNonces.Add(nonce)
+ sentNonces.Put(nonce)
// Version message.
msg := wire.NewMsgVersion(ourNA, theirNA, nonce, blockNum)
@@ -2558,7 +2567,7 @@ func newPeerBase(origCfg *Config, inbound bool) *Peer {
p := Peer{
inbound: inbound,
wireEncoding: wire.BaseEncoding,
- knownInventory: lru.NewCache(maxKnownInventory),
+ knownInventory: lru.NewSet[wire.InvVect](maxKnownInventory),
stallControl: make(chan stallControlMsg, 1), // nonblocking sync
outputQueue: make(chan outMsg, outputBufferSize),
sendQueue: make(chan outMsg, 1), // nonblocking sync
### peer/peer_test.go
@@ -17,9 +17,9 @@ import (
"github.com/btcsuite/btcd/chaincfg/v2"
"github.com/btcsuite/btcd/chainhash/v2"
+ "github.com/btcsuite/btcd/internal/socks"
"github.com/btcsuite/btcd/peer"
"github.com/btcsuite/btcd/wire/v2"
- "github.com/btcsuite/go-socks/socks"
)
// testHandshakeAdmission adapts a function to the v2 handshake admission
### psbt/go.mod
@@ -1,6 +1,6 @@
module github.com/btcsuite/btcd/psbt/v2
-go 1.25
+go 1.26.9
require (
github.com/btcsuite/btcd/address/v2 v2.0.0
@@ -10,17 +10,16 @@ require (
github.com/btcsuite/btcd/txscript/v2 v2.0.0
github.com/btcsuite/btcd/wire/v2 v2.0.0
github.com/davecgh/go-spew v1.1.1
- github.com/stretchr/testify v1.10.0
+ github.com/stretchr/testify v1.12.1
)
require (
github.com/btcsuite/btcd/chaincfg/v2 v2.0.0 // indirect
github.com/btcsuite/btclog v1.0.0 // indirect
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
- github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
+ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 // indirect
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee // indirect
- github.com/pmezard/go-difflib v1.0.0 // indirect
- golang.org/x/crypto v0.40.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
+ go.yaml.in/yaml/v3 v3.0.5 // indirect
+ golang.org/x/crypto v0.57.0 // indirect
+ golang.org/x/sys v0.48.0 // indirect
)
### psbt/go.sum
@@ -18,19 +18,15 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee h1:FPP9HDkBbPyniu+u7FHZg+kKFX1WW0gxOGteJ0h3AJk=
github.com/kcalvinalvin/anet v0.0.0-20251112173137-d8ddc1f6dbee/go.mod h1:N6sz6HwJAenJ6d+/xmSl0ikfV05ZrVGmjt1ryy/WOtE=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
-github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
+github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
+go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
+go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
### release/README.md
@@ -96,6 +96,12 @@ This will then create a directory of the form `btcd-<TAG>` containing archives
of the release binaries for each supported operating system and architecture,
and a manifest file containing the hash of each archive.
+Release binaries are built with the same Go version as CI, the `GO_VERSION` in
+`.github/workflows/main.yml` (see the Go version policy in the
+[README](../README.md#go-version-policy)). `release.sh` refuses to run with any
+other version. If a different Go is installed, let the `go` command fetch the
+right one, for example `GOTOOLCHAIN=go1.27.2 ./release/release.sh <TAG>`.
+
### Pushing a release (for maintainers)
Now that the directory `btcd-<TAG>` is created, the manifest file needs to be
### release/release.sh
@@ -10,6 +10,17 @@
set -e
+# Release binaries must be built with the Go version CI uses (see the Go
+# version policy in README.md), otherwise they can't be reproduced.
+GO_VERSION=$(sed -n 's/^ *GO_VERSION: *//p' \
+ "$(git rev-parse --show-toplevel)/.github/workflows/main.yml")
+if [[ "$(go env GOVERSION)" != "go$GO_VERSION" ]]; then
+ echo "release.sh: found $(go env GOVERSION), but releases are built" \
+ "with go$GO_VERSION." >&2
+ echo "Run it as: GOTOOLCHAIN=go$GO_VERSION $0 $*" >&2
+ exit 1
+fi
+
# If no tag specified, use date + version otherwise use tag.
if [[ $1x = x ]]; then
DATE=`date +%Y%m%d`
### rpcclient/infrastructure.go
@@ -28,8 +28,8 @@ import (
"github.com/btcsuite/btcd/btcjson"
"github.com/btcsuite/btcd/chaincfg/v2"
- "github.com/btcsuite/go-socks/socks"
- "github.com/btcsuite/websocket"
+ "github.com/btcsuite/btcd/internal/socks"
+ "github.com/gorilla/websocket"
)
var (
@@ -464,10 +464,16 @@ func (c *Client) shouldLogReadError(err error) bool {
default:
}
- // No logging when the connection has been disconnected.
+ // No logging when the connection has been disconnected, including when
+ // the server closed it normally with a close frame.
if err == io.EOF {
return false
}
+ if websocket.IsCloseError(err, websocket.CloseNormalClosure,
+ websocket.CloseGoingAway) {
+
+ return false
+ }
if opErr, ok := err.(*net.OpError); ok && !opErr.Temporary() {
return false
}
@@ -1337,6 +1343,12 @@ type ConnConfig struct {
// Authorization header for RPC requests. Caller-provided Authorization
// values in ExtraHeaders are still sent.
DisableAuth bool
+
+ // netDialContext, if set, opens the network connection of a websocket
+ // instead of the default dialer. Tests use it to connect over in-memory
+ // pipes.
+ netDialContext func(ctx context.Context, network,
+ addr string) (net.Conn, error)
}
// getAuth returns the username and passphrase that will actually be used for
@@ -1464,7 +1476,13 @@ func dial(config *ConnConfig) (*websocket.Conn, error) {
// Create a websocket dialer that will be used to make the connection.
// It is modified by the proxy setting below as needed.
- dialer := websocket.Dialer{TLSClientConfig: tlsConfig}
+ // The handshake timeout keeps a server that stalls the handshake from
+ // hanging the dial.
+ dialer := websocket.Dialer{
+ NetDialContext: config.netDialContext,
+ TLSClientConfig: tlsConfig,
+ HandshakeTimeout: defaultHTTPTimeout,
+ }
// Setup the proxy if one is configured.
if config.Proxy != "" {
@@ -1473,7 +1491,7 @@ func dial(config *ConnConfig) (*websocket.Conn, error) {
Username: config.ProxyUser,
Password: config.ProxyPass,
}
- dialer.NetDial = proxy.Dial
+ dialer.NetDialContext = proxy.DialContext
}
// Configure generated basic access authorization. Caller-provided
### rpcclient/infrastructure_test.go
@@ -1,6 +1,7 @@
package rpcclient
import (
+ "bufio"
"context"
"errors"
"fmt"
@@ -10,8 +11,10 @@ import (
"strings"
"sync/atomic"
"testing"
+ "testing/synctest"
"time"
+ "github.com/gorilla/websocket"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -768,3 +771,121 @@ func TestHTTPURLWiring(t *testing.T) {
require.Equal(t, "http://localhost:8332", c.httpURL)
}
+
+// TestShouldLogReadError checks which websocket read errors are logged: a
+// normal close by the server or a shutdown of the client is not an error worth
+// logging, while a dropped connection or any other failure is.
+func TestShouldLogReadError(t *testing.T) {
+ t.Parallel()
+
+ tests := []struct {
+ name string
+ err error
+ want bool
+ }{
+ {
+ name: "EOF",
+ err: io.EOF,
+ want: false,
+ },
+ {
+ name: "normal close",
+ err: &websocket.CloseError{
+ Code: websocket.CloseNormalClosure,
+ },
+ want: false,
+ },
+ {
+ name: "going away",
+ err: &websocket.CloseError{
+ Code: websocket.CloseGoingAway,
+ },
+ want: false,
+ },
+ {
+ name: "connection dropped",
+ err: &websocket.CloseError{
+ Code: websocket.CloseAbnormalClosure,
+ Text: io.ErrUnexpectedEOF.Error(),
+ },
+ want: true,
+ },
+ {
+ name: "other error",
+ err: errors.New("read failed"),
+ want: true,
+ },
+ }
+
+ for _, test := range tests {
+ c := &Client{shutdown: make(chan struct{})}
+ require.Equal(t, test.want, c.shouldLogReadError(test.err),
+ test.name)
+
+ // Nothing is logged once the client is shutting down.
+ close(c.shutdown)
+ require.False(t, c.shouldLogReadError(test.err), test.name)
+ }
+}
+
+// dialStalledServer dials a websocket over an in-memory connection to a server
+// that runs serve on its end, and returns the dial error. It must be called in
+// a synctest bubble, where a dial that never returns makes the bubble deadlock
+// and fails the test.
+func dialStalledServer(t *testing.T, serve func(net.Conn)) error {
+ t.Helper()
+
+ server, client := net.Pipe()
+ go func() {
+ defer server.Close()
+
+ serve(server)
+ }()
+
+ _, err := dial(&ConnConfig{
+ Host: "127.0.0.1:8334",
+ Endpoint: "ws",
+ User: "user",
+ Pass: "pass",
+ DisableTLS: true,
+ netDialContext: func(context.Context, string, string) (net.Conn,
+ error) {
+
+ return client, nil
+ },
+ })
+
+ return err
+}
+
+// TestDialHandshakeTimeout checks that dialing a websocket gives up after the
+// timeout when the server never answers the opening handshake.
+func TestDialHandshakeTimeout(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ start := time.Now()
+ err := dialStalledServer(t, func(conn net.Conn) {
+ _, _ = io.Copy(io.Discard, conn)
+ })
+ require.Error(t, err)
+ require.Equal(t, defaultHTTPTimeout, time.Since(start))
+ })
+}
+
+// TestDialStalledErrorBody checks that a failed handshake still returns the
+// authentication error after the timeout when the body of the error response
+// never arrives.
+func TestDialStalledErrorBody(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ start := time.Now()
+ err := dialStalledServer(t, func(conn net.Conn) {
+ // Read the request, then promise a body that never
+ // arrives.
+ _, _ = http.ReadRequest(bufio.NewReader(conn))
+ _, _ = io.WriteString(conn, "HTTP/1.1 401 Unauthorized"+
+ "\r\nContent-Length: 2048\r\n\r\n")
+ _, _ = io.Copy(io.Discard, conn)
+ })
+ require.ErrorIs(t, err, ErrInvalidAuth)
+ require.Equal(t, defaultHTTPTimeout, time.Since(start))
+ })
+}
### rpcserver.go
@@ -41,7 +41,7 @@ import (
"github.com/btcsuite/btcd/peer"
"github.com/btcsuite/btcd/txscript/v2"
"github.com/btcsuite/btcd/wire/v2"
- "github.com/btcsuite/websocket"
+ "github.com/gorilla/websocket"
)
// API version constants
### rpcserver_test.go
@@ -12,6 +12,7 @@ import (
"github.com/btcsuite/btcd/chainhash/v2"
"github.com/btcsuite/btcd/database"
"github.com/btcsuite/btcd/mempool"
+ "github.com/btcsuite/btcd/mempool/mempooltest"
"github.com/btcsuite/btcd/wire/v2"
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"
@@ -171,7 +172,7 @@ func TestHandleGetBlockCopiesTransactionBytes(t *testing.T) {
func TestHandleSendRawTransactionRejectsTrailingBytes(t *testing.T) {
t.Parallel()
- mm := &mempool.MockTxMempool{}
+ mm := &mempooltest.MockTxMempool{}
mm.On(
"ProcessTransaction", mock.Anything, false, false, mempool.Tag(0),
).Return(nil, errors.New("mempool should not be reached")).Maybe()
@@ -286,7 +287,7 @@ func TestHandleTestMempoolAcceptMixedResults(t *testing.T) {
require := require.New(t)
// Create a mock mempool.
- mm := &mempool.MockTxMempool{}
+ mm := &mempooltest.MockTxMempool{}
// Create a testing server with the mock mempool.
s := &rpcServer{cfg: rpcserverConfig{
@@ -465,7 +466,7 @@ func TestHandleTestMempoolAcceptFees(t *testing.T) {
t.Parallel()
// Create a mock mempool.
- mm := &mempool.MockTxMempool{}
+ mm := &mempooltest.MockTxMempool{}
// Create a testing server with the mock mempool.
s := &rpcServer{cfg: rpcserverConfig{
@@ -592,7 +593,7 @@ func TestGetTxSpendingPrevOut(t *testing.T) {
require := require.New(t)
// Create a mock mempool.
- mm := &mempool.MockTxMempool{}
+ mm := &mempooltest.MockTxMempool{}
defer mm.AssertExpectations(t)
// Create a testing server with the mock mempool.
### rpcwebsocket.go
@@ -29,7 +29,7 @@ import (
"github.com/btcsuite/btcd/database"
"github.com/btcsuite/btcd/txscript/v2"
"github.com/btcsuite/btcd/wire/v2"
- "github.com/btcsuite/websocket"
+ "github.com/gorilla/websocket"
"golang.org/x/crypto/ripemd160"
)
@@ -40,6 +40,25 @@ const (
// handler since notifications have their own queuing mechanism
// independent of the send channel buffer.
websocketSendBufferSize = 50
+
+ // websocketReadLimitUnauthenticated is the maximum size of a message
+ // read from a websocket client that hasn't authenticated yet. It only
+ // has to fit an authenticate request. Authenticated clients have no
+ // limit, like HTTP POST requests, since some requests, such as a rescan
+ // for a large wallet, can be of any size.
+ websocketReadLimitUnauthenticated = 64 * 1024
+
+ // websocketAuthTimeout is how long a websocket client that didn't
+ // authenticate during the HTTP upgrade has to send the authenticate
+ // command before it is disconnected.
+ websocketAuthTimeout = time.Second * rpcAuthTimeoutSeconds
+
+ // websocketWriteTimeout is how long writing a single message to a
+ // websocket client may take before the client is disconnected. It's
+ // generous so that a slow link can still receive a large reply, such as
+ // a verbose getrawmempool result, while a client that stops reading is
+ // eventually dropped.
+ websocketWriteTimeout = 5 * time.Minute
)
type semaphore chan struct{}
@@ -1225,6 +1244,11 @@ type wsClient struct {
// false means its access is only to the limited set of RPC calls.
isAdmin bool
+ // authTimer disconnects a client that didn't authenticate during the
+ // HTTP upgrade unless it authenticates in time. It is nil for clients
+ // that were authenticated from the start.
+ authTimer *time.Timer
+
// sessionID is a random ID generated for each client when connected.
// These IDs may be queried by a client using the session RPC. A change
// to the session ID indicates that the client reconnected.
@@ -1257,6 +1281,13 @@ type wsClient struct {
wg sync.WaitGroup
}
+// isNormalWebsocketClose returns whether err is the error a websocket read
+// returns when the peer closes the connection normally with a close frame.
+func isNormalWebsocketClose(err error) bool {
+ return websocket.IsCloseError(err, websocket.CloseNormalClosure,
+ websocket.CloseGoingAway)
+}
+
// inHandler handles all incoming messages for the websocket connection. It
// must be run as a goroutine.
func (c *wsClient) inHandler() {
@@ -1273,7 +1304,7 @@ out:
_, msg, err := c.conn.ReadMessage()
if err != nil {
// Log the error if it's not due to disconnecting.
- if err != io.EOF {
+ if err != io.EOF && !isNormalWebsocketClose(err) {
rpcsLog.Errorf("Websocket receive error from "+
"%s: %v", c.addr, err)
}
@@ -1311,6 +1342,11 @@ out:
}
if req.Method == "" || req.Params == nil {
+ // Only process requests from authenticated clients
+ if !c.authenticated {
+ break out
+ }
+
jsonErr := &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "Invalid request: malformed",
@@ -1376,8 +1412,7 @@ out:
rpcsLog.Warnf("Auth failure.")
break out
}
- c.authenticated = true
- c.isAdmin = cmp == 1
+ c.markAuthenticated(cmp == 1)
// Marshal and send response.
reply, err = createMarshalledReply(cmd.jsonrpc, cmd.id, nil, nil)
@@ -1542,6 +1577,11 @@ out:
}
if req.Method == "" || req.Params == nil {
+ // Only process requests from authenticated clients
+ if !c.authenticated {
+ break out
+ }
+
jsonErr := &btcjson.RPCError{
Code: btcjson.ErrRPCInvalidRequest.Code,
Message: "Invalid request: malformed",
@@ -1614,8 +1654,7 @@ out:
break out
}
- c.authenticated = true
- c.isAdmin = cmp == 1
+ c.markAuthenticated(cmp == 1)
// Marshal and send response.
reply, err = createMarshalledReply(cmd.jsonrpc, cmd.id, nil, nil)
@@ -1712,11 +1751,28 @@ out:
}
// Ensure the connection is closed.
+ if c.authTimer != nil {
+ c.authTimer.Stop()
+ }
c.Disconnect()
c.wg.Done()
rpcsLog.Tracef("Websocket client input handler done for %s", c.addr)
}
+// markAuthenticated records that the client authenticated with the
+// authenticate command: it lifts the read limit for unauthenticated clients
+// and stops the authentication timer. It must only be called from inHandler.
+func (c *wsClient) markAuthenticated(isAdmin bool) {
+ c.authenticated = true
+ c.isAdmin = isAdmin
+
+ // A read limit of 0 is no limit, the default of a connection.
+ c.conn.SetReadLimit(0)
+ if c.authTimer != nil {
+ c.authTimer.Stop()
+ }
+}
+
// serviceRequest services a parsed RPC request by looking up and executing the
// appropriate RPC handler. The response is marshalled and sent to the
// websocket client.
@@ -1827,6 +1883,11 @@ out:
// closed.
select {
case r := <-c.sendChan:
+ // Setting the deadline only records it for the write
+ // below, so it can't fail.
+ _ = c.conn.SetWriteDeadline(
+ time.Now().Add(websocketWriteTimeout),
+ )
err := c.conn.WriteMessage(websocket.TextMessage, r.msg)
if err != nil {
c.Disconnect()
@@ -1928,6 +1989,14 @@ func (c *wsClient) Disconnect() {
func (c *wsClient) Start() {
rpcsLog.Tracef("Starting websocket client %s", c.addr)
+ // A client that didn't authenticate during the HTTP upgrade must send
+ // the authenticate command in time. The timer closes the connection,
+ // which also unblocks the client's goroutines if they are stuck
+ // writing to a client that doesn't read; a read deadline wouldn't.
+ if !c.authenticated {
+ c.authTimer = time.AfterFunc(websocketAuthTimeout, c.Disconnect)
+ }
+
// Start processing input and output.
c.wg.Add(3)
go c.inHandler()
@@ -1969,6 +2038,12 @@ func newWebsocketClient(server *rpcServer, conn *websocket.Conn,
sendChan: make(chan wsResponse, websocketSendBufferSize),
quit: make(chan struct{}),
}
+
+ // Until a client authenticates, it may only send small messages.
+ if !authenticated {
+ conn.SetReadLimit(websocketReadLimitUnauthenticated)
+ }
+
return client, nil
}
### rpcwebsocket_test.go
@@ -0,0 +1,461 @@
+package main
+
+import (
+ "bytes"
+ "context"
+ "crypto/sha256"
+ "encoding/base64"
+ "fmt"
+ "net"
+ "net/http"
+ "strings"
+ "sync"
+ "sync/atomic"
+ "testing"
+ "testing/synctest"
+ "time"
+
+ "github.com/gorilla/websocket"
+ "github.com/stretchr/testify/require"
+)
+
+const (
+ // testWSUser and testWSPass are the RPC credentials of the websocket
+ // test server.
+ testWSUser = "user"
+ testWSPass = "pass"
+)
+
+// testRPCLog collects what the RPC server logs during the tests. TestMain
+// installs it.
+var testRPCLog = &syncBuffer{}
+
+// lastTestClientPort numbers the in-memory connections of the websocket tests,
+// so that each gets its own client address and rpcLogFor tells their log
+// lines apart.
+var lastTestClientPort atomic.Int32
+
+// rpcLogFor returns the lines of testRPCLog about the client connected through
+// conn. The server logs clients by their address.
+func rpcLogFor(conn *websocket.Conn) string {
+ addr := conn.LocalAddr().String()
+
+ var lines []string
+ for _, line := range strings.Split(testRPCLog.String(), "\n") {
+ if strings.Contains(line, addr) {
+ lines = append(lines, line)
+ }
+ }
+
+ return strings.Join(lines, "\n")
+}
+
+// syncBuffer is a bytes.Buffer that is safe for concurrent use, so that
+// server goroutines can log into it while a test reads it.
+type syncBuffer struct {
+ mu sync.Mutex
+ buf bytes.Buffer
+}
+
+// Write appends p to the buffer.
+func (b *syncBuffer) Write(p []byte) (int, error) {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+
+ return b.buf.Write(p)
+}
+
+// String returns the contents of the buffer.
+func (b *syncBuffer) String() string {
+ b.mu.Lock()
+ defer b.mu.Unlock()
+
+ return b.buf.String()
+}
+
+// pipeListener is a net.Listener whose connections are in-memory pipes made by
+// its dial method. Unlike loopback connections, pipes let the websocket tests
+// run in a synctest bubble.
+type pipeListener struct {
+ conns chan net.Conn
+ closed chan struct{}
+ once sync.Once
+}
+
+// newPipeListener returns a listener for in-memory connections.
+func newPipeListener() *pipeListener {
+ return &pipeListener{
+ conns: make(chan net.Conn),
+ closed: make(chan struct{}),
+ }
+}
+
+// Accept returns the server end of the next connection made by dial.
+func (l *pipeListener) Accept() (net.Conn, error) {
+ select {
+ case conn := <-l.conns:
+ return conn, nil
+
+ case <-l.closed:
+ return nil, net.ErrClosed
+ }
+}
+
+// Close stops the listener.
+func (l *pipeListener) Close() error {
+ l.once.Do(func() {
+ close(l.closed)
+ })
+
+ return nil
+}
+
+// Addr returns the address of the listener.
+func (l *pipeListener) Addr() net.Addr {
+ return &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1)}
+}
+
+// dial connects to the listener through an in-memory pipe. Each connection
+// gets its own client address, which the server sees as the remote address.
+func (l *pipeListener) dial(ctx context.Context, _, _ string) (net.Conn,
+ error) {
+
+ port := 50000 + int(lastTestClientPort.Add(1))
+ addr := &net.TCPAddr{IP: net.IPv4(127, 0, 0, 1), Port: port}
+
+ server, client := net.Pipe()
+ select {
+ case l.conns <- &addrConn{Conn: server, remoteAddr: addr}:
+ return &addrConn{Conn: client, localAddr: addr}, nil
+
+ case <-l.closed:
+ _, _ = server.Close(), client.Close()
+ return nil, net.ErrClosed
+
+ case <-ctx.Done():
+ _, _ = server.Close(), client.Close()
+ return nil, ctx.Err()
+ }
+}
+
+// addrConn is a connection that reports the given local and remote addresses,
+// when set, instead of those of the underlying connection.
+type addrConn struct {
+ net.Conn
+
+ localAddr net.Addr
+ remoteAddr net.Addr
+}
+
+// LocalAddr returns the local address of the connection.
+func (c *addrConn) LocalAddr() net.Addr {
+ if c.localAddr != nil {
+ return c.localAddr
+ }
+
+ return c.Conn.LocalAddr()
+}
+
+// RemoteAddr returns the remote address of the connection.
+func (c *addrConn) RemoteAddr() net.Addr {
+ if c.remoteAddr != nil {
+ return c.remoteAddr
+ }
+
+ return c.Conn.RemoteAddr()
+}
+
+// testWebsocketServer serves the websocket endpoint of an RPC server that has
+// no chain behind it, which is enough to exercise authentication and request
+// parsing.
+type testWebsocketServer struct {
+ // listener makes the in-memory connections to the server.
+ listener *pipeListener
+
+ // done receives a value each time the server finishes handling a
+ // connection.
+ done chan struct{}
+}
+
+// newTestWebsocketServer starts a websocket test server. When authenticated
+// is set, clients are treated as having passed HTTP basic auth during the
+// upgrade; otherwise they have to send the authenticate command.
+//
+// It must be called in a synctest bubble, so the server runs on the bubble's
+// fake clock, and a server that never does what a test waits for makes the
+// bubble deadlock, which fails the test. The server swaps the global config,
+// so tests using it must not run in parallel.
+func newTestWebsocketServer(t *testing.T,
+ authenticated bool) *testWebsocketServer {
+
+ t.Helper()
+
+ oldCfg := cfg
+ cfg = &config{RPCMaxWebsockets: 10, RPCMaxConcurrentReqs: 10}
+ t.Cleanup(func() {
+ cfg = oldCfg
+ })
+
+ login := testWSUser + ":" + testWSPass
+ auth := "Basic " + base64.StdEncoding.EncodeToString([]byte(login))
+ s := &rpcServer{authsha: sha256.Sum256([]byte(auth))}
+ s.ntfnMgr = newWsNotificationManager(s)
+ s.ntfnMgr.Start()
+ t.Cleanup(func() {
+ s.ntfnMgr.Shutdown()
+ s.ntfnMgr.WaitForShutdown()
+ })
+
+ // Wait for all connections to be handled before the config is restored.
+ // Hijacked connections aren't tracked by the HTTP server.
+ var handlers sync.WaitGroup
+ t.Cleanup(handlers.Wait)
+
+ done := make(chan struct{}, 10)
+ srv := &http.Server{Handler: http.HandlerFunc(
+ func(w http.ResponseWriter, r *http.Request) {
+ handlers.Add(1)
+ defer handlers.Done()
+
+ ws, err := websocket.Upgrade(w, r, nil, 0, 0)
+ if err != nil {
+ return
+ }
+ s.WebsocketHandler(
+ ws, r.RemoteAddr, authenticated, true,
+ )
+ done <- struct{}{}
+ },
+ )}
+ listener := newPipeListener()
+ go func() {
+ _ = srv.Serve(listener)
+ }()
+ t.Cleanup(func() {
+ _ = srv.Close()
+ })
+
+ return &testWebsocketServer{
+ listener: listener,
+ done: done,
+ }
+}
+
+// dial connects a websocket client to the test server. The connection is
+// closed when the test ends.
+func (s *testWebsocketServer) dial(t *testing.T) *websocket.Conn {
+ t.Helper()
+
+ dialer := websocket.Dialer{NetDialContext: s.listener.dial}
+ conn, _, err := dialer.Dial("ws://btcd/ws", nil)
+ require.NoError(t, err)
+ t.Cleanup(func() {
+ _ = conn.Close()
+ })
+
+ return conn
+}
+
+// waitDone waits for the server to finish handling a connection.
+func (s *testWebsocketServer) waitDone() {
+ <-s.done
+}
+
+// TestWebsocketNormalCloseNotLogged checks that a client closing the
+// connection with a normal close frame isn't logged as a receive error.
+func TestWebsocketNormalCloseNotLogged(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ s := newTestWebsocketServer(t, true)
+ conn := s.dial(t)
+
+ msg := websocket.FormatCloseMessage(
+ websocket.CloseNormalClosure, "",
+ )
+ deadline := time.Now().Add(time.Second)
+ err := conn.WriteControl(websocket.CloseMessage, msg, deadline)
+ require.NoError(t, err)
+ s.waitDone()
+
+ log := rpcLogFor(conn)
+ require.Contains(t, log, "Disconnected websocket client")
+ require.NotContains(t, log, "Websocket receive error")
+ })
+}
+
+// authenticateRequest returns an authenticate command with the credentials of
+// the websocket test server.
+func authenticateRequest(jsonrpc string) string {
+ return fmt.Sprintf(`{"jsonrpc":%q,"id":1,"method":"authenticate",`+
+ `"params":[%q,%q]}`, jsonrpc, testWSUser, testWSPass)
+}
+
+// malformedRequest returns a request without a method whose ID is a string of
+// idSize bytes. The server answers it with an error that echoes the ID.
+func malformedRequest(idSize int) string {
+ return fmt.Sprintf(`{"jsonrpc":"1.0","id":"%s","params":[]}`,
+ strings.Repeat("a", idSize))
+}
+
+// send writes msg to conn as a text message.
+func send(t *testing.T, conn *websocket.Conn, msg string) {
+ t.Helper()
+
+ err := conn.WriteMessage(websocket.TextMessage, []byte(msg))
+ require.NoError(t, err)
+}
+
+// readReply reads the next message from conn.
+func readReply(t *testing.T, conn *websocket.Conn) string {
+ t.Helper()
+
+ _, msg, err := conn.ReadMessage()
+ require.NoError(t, err)
+
+ return string(msg)
+}
+
+// requireClosed checks that the server closes the connection without sending
+// anything.
+func requireClosed(t *testing.T, s *testWebsocketServer,
+ conn *websocket.Conn) {
+
+ t.Helper()
+
+ // Read before waiting for shutdown so a queued reply cannot be hidden
+ // by the authentication timeout closing the connection.
+ _, msg, err := conn.ReadMessage()
+ require.Error(t, err, "unexpected message %q", msg)
+
+ s.waitDone()
+}
+
+// TestWebsocketUnauthenticatedReadLimit checks that a client that hasn't
+// authenticated can't send a message bigger than the unauthenticated limit.
+func TestWebsocketUnauthenticatedReadLimit(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ s := newTestWebsocketServer(t, false)
+ conn := s.dial(t)
+
+ // The server stops reading once the message exceeds the limit
+ // and closes the connection, so sending it fails midway.
+ msg := malformedRequest(websocketReadLimitUnauthenticated)
+ _ = conn.WriteMessage(websocket.TextMessage, []byte(msg))
+ requireClosed(t, s, conn)
+ require.Contains(t, rpcLogFor(conn), "read limit exceeded")
+ })
+}
+
+// TestWebsocketUnauthenticatedMalformedRequest checks that a client that
+// hasn't authenticated is disconnected without a reply when it sends a
+// request without a method, so it can't make the server queue replies.
+func TestWebsocketUnauthenticatedMalformedRequest(t *testing.T) {
+ tests := []struct {
+ name string
+ msg string
+ }{
+ {
+ name: "single",
+ msg: `{"jsonrpc":"1.0","id":1}`,
+ },
+ {
+ name: "batch",
+ msg: `[{"jsonrpc":"2.0","id":1}]`,
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ s := newTestWebsocketServer(t, false)
+ conn := s.dial(t)
+
+ send(t, conn, test.msg)
+ requireClosed(t, s, conn)
+ })
+ })
+ }
+}
+
+// TestWebsocketAuthTimeout checks that a client that doesn't authenticate is
+// disconnected once the authentication timeout expires.
+func TestWebsocketAuthTimeout(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ s := newTestWebsocketServer(t, false)
+ conn := s.dial(t)
+
+ start := time.Now()
+ requireClosed(t, s, conn)
+ require.Equal(t, websocketAuthTimeout, time.Since(start))
+ })
+}
+
+// TestWebsocketAuthenticate checks that a client that authenticates with the
+// authenticate command, alone or in a batch, stays connected past the
+// authentication timeout and may then send messages bigger than the
+// unauthenticated limit.
+func TestWebsocketAuthenticate(t *testing.T) {
+ tests := []struct {
+ name string
+ msg string
+ }{
+ {
+ name: "single",
+ msg: authenticateRequest("1.0"),
+ },
+ {
+ name: "batch",
+ msg: "[" + authenticateRequest("2.0") + "]",
+ },
+ }
+
+ for _, test := range tests {
+ t.Run(test.name, func(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ s := newTestWebsocketServer(t, false)
+ conn := s.dial(t)
+
+ send(t, conn, test.msg)
+ reply := readReply(t, conn)
+ require.NotContains(t, reply, `"code"`)
+
+ time.Sleep(2 * websocketAuthTimeout)
+ send(t, conn, malformedRequest(1<<20))
+ reply = readReply(t, conn)
+ require.Contains(
+ t, reply, "Invalid request: malformed",
+ )
+ })
+ })
+ }
+}
+
+// TestWebsocketHTTPAuthenticated checks that a client that authenticated
+// during the HTTP upgrade has no authentication timeout and may send messages
+// bigger than the unauthenticated limit right away.
+func TestWebsocketHTTPAuthenticated(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ s := newTestWebsocketServer(t, true)
+ conn := s.dial(t)
+
+ time.Sleep(2 * websocketAuthTimeout)
+ send(t, conn, malformedRequest(1<<20))
+ reply := readReply(t, conn)
+ require.Contains(t, reply, "Invalid request: malformed")
+ })
+}
+
+// TestWebsocketWriteTimeout checks that an authenticated client that stops
+// reading is disconnected once a write to it times out.
+func TestWebsocketWriteTimeout(t *testing.T) {
+ synctest.Test(t, func(t *testing.T) {
+ s := newTestWebsocketServer(t, true)
+ conn := s.dial(t)
+
+ // The client never reads the reply, so writing it blocks until
+ // the write times out.
+ start := time.Now()
+ send(t, conn, malformedRequest(1))
+ s.waitDone()
+ require.Equal(t, websocketWriteTimeout, time.Since(start))
+ })
+}
### scripts/check_go_versions.sh
@@ -0,0 +1,107 @@
+#!/bin/bash
+
+# Checks that the repo follows the Go version policy in README.md: CI, the
+# Docker images and releases are built with the newest Go release, and every
+# go.mod requires the previous release, both at the latest point release of
+# their branch.
+
+set -e
+
+cd "$(git rev-parse --show-toplevel)"
+
+# go.dev lists the latest point release of each supported Go branch.
+RELEASES=$(curl -fsSL 'https://go.dev/dl/?mode=json' |
+ jq -r '.[] | select(.stable) | .version' | sed 's/^go//' | sort -rV)
+NEWEST=$(echo "$RELEASES" | sed -n 1p)
+PREVIOUS=$(echo "$RELEASES" | sed -n 2p)
+if [[ -z $NEWEST || -z $PREVIOUS ]]; then
+ echo "Could not read the supported Go releases from go.dev." >&2
+ exit 1
+fi
+
+STATUS=0
+fail() {
+ echo "$*" >&2
+ STATUS=1
+}
+
+# golang_image_version prints the Go version of the golang image with the given
+# digest, from the GOLANG_VERSION variable of its linux/amd64 image.
+golang_image_version() {
+ local registry=https://registry-1.docker.io/v2/library/golang
+ local accept="application/vnd.oci.image.index.v1+json,\
+application/vnd.docker.distribution.manifest.list.v2+json,\
+application/vnd.oci.image.manifest.v1+json,\
+application/vnd.docker.distribution.manifest.v2+json"
+ local token manifest amd64 config
+
+ token=$(curl -fsSL "https://auth.docker.io/token?\
+service=registry.docker.io&scope=repository:library/golang:pull" |
+ jq -r .token)
+ manifest=$(curl -fsSL -H "Authorization: Bearer $token" \
+ -H "Accept: $accept" "$registry/manifests/$1")
+
+ # A multi-platform image lists the manifest of each platform.
+ amd64=$(jq -r '.manifests[]? | select(.platform.os == "linux" and
+ .platform.architecture == "amd64") | .digest' <<< "$manifest")
+ if [[ -n $amd64 ]]; then
+ manifest=$(curl -fsSL -H "Authorization: Bearer $token" \
+ -H "Accept: $accept" "$registry/manifests/$amd64")
+ fi
+
+ config=$(jq -r .config.digest <<< "$manifest")
+ curl -fsSL -H "Authorization: Bearer $token" "$registry/blobs/$config" |
+ jq -r '.config.Env[] | select(startswith("GOLANG_VERSION=")) |
+ ltrimstr("GOLANG_VERSION=")'
+}
+
+for mod in $(git ls-files '*go.mod'); do
+ got=$(sed -n 's/^go //p' "$mod")
+ if [[ $got != "$PREVIOUS" ]]; then
+ fail "$mod: requires go $got, want go $PREVIOUS"
+ fi
+done
+
+got=$(sed -n 's/^ *GO_VERSION: *//p' .github/workflows/main.yml)
+if [[ $got != "$NEWEST" ]]; then
+ fail ".github/workflows/main.yml: GO_VERSION is $got, want $NEWEST"
+fi
+
+# Check the golang image each Dockerfile's FROM line actually uses, rather than
+# any text that mentions one: the root Dockerfile pins a bare digest.
+for dockerfile in Dockerfile .github/workflows/Dockerfile; do
+ images=$(sed -nE 's/^FROM (--platform=[^ ]+ )?(golang[^ ]*).*/\2/p' \
+ "$dockerfile")
+ if [[ -z $images ]]; then
+ fail "$dockerfile: no golang build stage found"
+ fi
+
+ for image in $images; do
+ # A version tag, as in golang:1.27.1-alpine3.24, has to match.
+ if [[ $image =~ ^golang:([^@]+) ]]; then
+ tag=${BASH_REMATCH[1]}
+ if [[ $tag != "$NEWEST" && $tag != "$NEWEST"-* ]]; then
+ fail "$dockerfile: built with golang:$tag, want $NEWEST"
+ fi
+ fi
+
+ # So does the Go version of the image a digest pins, since the
+ # digest is what Docker uses and a tag or a comment next to it can
+ # be updated without it.
+ if [[ $image =~ @(sha256:[0-9a-f]{64})$ ]]; then
+ got=$(golang_image_version "${BASH_REMATCH[1]}")
+ if [[ $got != "$NEWEST" ]]; then
+ fail "$dockerfile: the pinned golang image has Go" \
+ "$got, want $NEWEST"
+ fi
+ elif [[ ! $image =~ ^golang: ]]; then
+ fail "$dockerfile: $image pins no Go version"
+ fi
+ done
+done
+
+if [[ $STATUS -eq 0 ]]; then
+ echo "Go versions follow the policy: built with $NEWEST," \
+ "go.mod requires $PREVIOUS."
+fi
+exit $STATUS
### server.go
@@ -39,7 +39,7 @@ import (
"github.com/btcsuite/btcd/peer"
"github.com/btcsuite/btcd/txscript/v2"
"github.com/btcsuite/btcd/wire/v2"
- "github.com/decred/dcrd/lru"
+ "github.com/decred/dcrd/container/lru"
)
const (
@@ -342,7 +342,7 @@ type serverPeer struct {
isWhitelisted bool
filter *bloom.Filter
addressesMtx sync.RWMutex
- knownAddresses lru.Cache
+ knownAddresses *lru.Set[string]
banScore connmgr.DynamicBanScore
quit chan struct{}
@@ -376,7 +376,7 @@ func newServerPeer(s *server, isPersistent bool) *serverPeer {
server: s,
persistent: isPersistent,
filter: bloom.LoadFilter(nil),
- knownAddresses: lru.NewCache(5000),
+ knownAddresses: lru.NewSet[string](5000),
quit: make(chan struct{}),
verAckCh: make(chan struct{}),
txProcessed: make(chan struct{}, 1),
@@ -405,7 +405,7 @@ func (sp *serverPeer) newestBlock() (*chainhash.Hash, int32, error) {
func (sp *serverPeer) addKnownAddresses(addresses []*wire.NetAddressV2) {
sp.addressesMtx.Lock()
for _, na := range addresses {
- sp.knownAddresses.Add(addrmgr.NetAddressKey(na))
+ sp.knownAddresses.Put(addrmgr.NetAddressKey(na))
}
sp.addressesMtx.Unlock()
}
### server_test.go
@@ -1,6 +1,7 @@
package main
import (
+ "io"
"net"
"os"
"path/filepath"
@@ -10,7 +11,9 @@ import (
"github.com/btcsuite/btcd/chaincfg/v2"
"github.com/btcsuite/btcd/internal/inbound"
+ "github.com/btcsuite/btcd/internal/socks"
"github.com/btcsuite/btcd/peer"
+ "github.com/btcsuite/btclog"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
@@ -19,6 +22,14 @@ func TestMain(m *testing.M) {
// logRotator must be non-nil or any log write (e.g. from
// OnVerAck's double-call guard) panics via logWriter.Write.
initLogRotator(filepath.Join(os.TempDir(), "btcd-server-test.log"))
+
+ // Also send what the RPC server logs to testRPCLog for the websocket
+ // tests. This must happen before any test runs: server goroutines read
+ // rpcsLog without synchronization, even after their client shut down.
+ rpcsLog = btclog.NewBackend(
+ io.MultiWriter(logWriter{}, testRPCLog),
+ ).Logger("RPCS")
+
os.Exit(m.Run())
}
@@ -187,6 +198,31 @@ func TestInboundPeerReservation(t *testing.T) {
}
}
+// TestIsWhitelistedProxiedAddr checks that a peer reached through a proxy is
+// whitelisted by its own address rather than the proxy's, so whitelisting a
+// local Tor proxy's address doesn't whitelist every peer reached through it.
+// Connections made through the proxy report the peer as their remote address,
+// which is what outboundPeerConnected passes to isWhitelisted.
+func TestIsWhitelistedProxiedAddr(t *testing.T) {
+ originalCfg := cfg
+ t.Cleanup(func() {
+ cfg = originalCfg
+ })
+
+ _, loopback, err := net.ParseCIDR("127.0.0.0/8")
+ require.NoError(t, err)
+ _, peers, err := net.ParseCIDR("192.0.2.0/24")
+ require.NoError(t, err)
+
+ addr := &socks.ProxiedAddr{Net: "tcp", Host: "192.0.2.1", Port: 8333}
+
+ cfg = &config{whitelists: []*net.IPNet{loopback}}
+ require.False(t, isWhitelisted(addr))
+
+ cfg = &config{whitelists: []*net.IPNet{peers}}
+ require.True(t, isWhitelisted(addr))
+}
+
// TestInboundPeerAdmissionSourceLimits verifies that loopback and whitelisted
// peers retain the ordinary pending-handshake and V2 source limits.
func TestInboundPeerAdmissionSourceLimits(t *testing.T) {
### service_windows.go
@@ -10,9 +10,9 @@ import (
"path/filepath"
"time"
- "github.com/btcsuite/winsvc/eventlog"
- "github.com/btcsuite/winsvc/mgr"
- "github.com/btcsuite/winsvc/svc"
+ "golang.org/x/sys/windows/svc"
+ "golang.org/x/sys/windows/svc/eventlog"
+ "golang.org/x/sys/windows/svc/mgr"
)
const (
@@ -48,7 +48,7 @@ func logServiceStartOfDay(srvr *server) {
// updates and launching btcdMain.
type btcdService struct{}
-// Execute is the main entry point the winsvc package calls when receiving
+// Execute is the main entry point the svc package calls when receiving
// information from the Windows service control manager. It launches the
// long-running btcdMain (which is the real meat of btcd), handles service
// change requests, and notifies the service control manager of changes.
@@ -141,10 +141,12 @@ func installService() error {
return fmt.Errorf("service %s already exists", svcName)
}
- // Install the service.
+ // Install the service. The zero ErrorControl is ErrorIgnore, so set
+ // ErrorNormal to have Windows log a failure to start at boot.
service, err = serviceManager.CreateService(svcName, exePath, mgr.Config{
- DisplayName: svcDisplayName,
- Description: svcDesc,
+ DisplayName: svcDisplayName,
+ Description: svcDesc,
+ ErrorControl: mgr.ErrorNormal,
})
if err != nil {
return err
@@ -197,7 +199,7 @@ func startService() error {
}
defer service.Close()
- err = service.Start(os.Args)
+ err = service.Start(os.Args...)
if err != nil {
return fmt.Errorf("could not start service: %v", err)
}
### txscript/go.mod
@@ -1,6 +1,6 @@
module github.com/btcsuite/btcd/txscript/v2
-go 1.25
+go 1.26.9
require (
github.com/btcsuite/btcd/address/v2 v2.0.0
@@ -10,14 +10,14 @@ require (
github.com/btcsuite/btcd/wire/v2 v2.0.0
github.com/btcsuite/btclog v1.0.0
github.com/davecgh/go-spew v1.1.1
- github.com/stretchr/testify v1.10.0
- golang.org/x/crypto v0.40.0
+ github.com/stretchr/testify v1.12.1
+ golang.org/x/crypto v0.57.0
)
+require go.yaml.in/yaml/v3 v3.0.5 // indirect
+
require (
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
- github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0
- github.com/pmezard/go-difflib v1.0.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
+ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1
+ golang.org/x/sys v0.48.0 // indirect
)
### txscript/go.sum
@@ -14,17 +14,13 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/decred/dcrd/crypto/blake256 v1.1.0 h1:zPMNGQCm0g4QTY27fOCorQW7EryeQ/U0x++OzVrdms8=
github.com/decred/dcrd/crypto/blake256 v1.1.0/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
-github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
+github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
+github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
+go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
+go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
### txscript/standard_test.go
@@ -581,7 +581,7 @@ func TestCalcScriptInfo(t *testing.T) {
if *si != test.scriptInfo {
t.Errorf("%s: scriptinfo doesn't match expected. "+
- "got: %q expected %q", test.name, *si,
+ "got: %+v expected %+v", test.name, *si,
test.scriptInfo)
continue
}
### v2transport/go.mod
@@ -1,15 +1,15 @@
module github.com/btcsuite/btcd/v2transport
-go 1.25
+go 1.26.9
require (
- github.com/btcsuite/btcd/btcec/v2 v2.4.0
- github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f
- golang.org/x/crypto v0.25.0
+ github.com/btcsuite/btcd/btcec/v2 v2.5.0
+ github.com/btcsuite/btclog v1.0.0
+ golang.org/x/crypto v0.57.0
)
require (
- github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0 // indirect
- github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 // indirect
- golang.org/x/sys v0.22.0 // indirect
+ github.com/btcsuite/btcd/chainhash/v2 v2.0.0 // indirect
+ github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 // indirect
+ golang.org/x/sys v0.48.0 // indirect
)
### v2transport/go.sum
@@ -1,14 +1,14 @@
-github.com/btcsuite/btcd/btcec/v2 v2.4.0 h1:9JgnRkOL8J1UKuGlpJs7oL5tFRgrBgyM/uhwfS+cUiI=
-github.com/btcsuite/btcd/btcec/v2 v2.4.0/go.mod h1:64BXFSNzV1koQHPqljB4LaD6lZPQEQNZ38zMImajCRo=
-github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0 h1:yMIg99+4aBvqfl/HzJRKfxTX9rGfikoI9uvFzterhc8=
-github.com/btcsuite/btcd/chaincfg/chainhash v1.2.0/go.mod h1:Y72Ren9gfhlEvnwnT78BGcSNO2UMphTKLn9AorF+5rg=
-github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f h1:bAs4lUbRJpnnkd9VhRV3jjAVU7DJVjMaK+IsvSeZvFo=
-github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA=
+github.com/btcsuite/btcd/btcec/v2 v2.5.0 h1:KioMXOWa76b86sTZZOmbzv/ldaQCmB8KFAyn5PbB8E8=
+github.com/btcsuite/btcd/btcec/v2 v2.5.0/go.mod h1:+K/MYXcLBtHEQjRbjHuJChuybk4LCgjdjgRwil+e+Kk=
+github.com/btcsuite/btcd/chainhash/v2 v2.0.0 h1:PMLlSloHJuEeB80XG9EjpXWNEKAZAMLl6YHZ6YsEuoA=
+github.com/btcsuite/btcd/chainhash/v2 v2.0.0/go.mod h1:mKxcZ7oGTXE7IRV+sS9hP4EVBwc/SzfNR+52IsOP9j8=
+github.com/btcsuite/btclog v1.0.0 h1:sEkpKJMmfGiyZjADwEIgB1NSwMyfdD1FB8v6+w1T0Ns=
+github.com/btcsuite/btclog v1.0.0/go.mod h1:w7xnGOhwT3lmrS4H3b/D1XAXxvh+tbhUm8xeHN2y3TQ=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0 h1:NMZiJj8QnKe1LgsbDayM4UoHwbvwDRwnI3hwNaAHRnc=
-github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.0/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
-golang.org/x/crypto v0.25.0 h1:ypSNr+bnYL2YhwoMt2zPxHFmbAN1KZs/njMG3hxUp30=
-golang.org/x/crypto v0.25.0/go.mod h1:T+wALwcMOSE0kXgUAnPAHqTLW+XHgcELELW8VaDgm/M=
-golang.org/x/sys v0.22.0 h1:RI27ohtqKCnwULzJLqkv897zojh5/DwS/ENaMzUOaWI=
-golang.org/x/sys v0.22.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1 h1:5RVFMOWjMyRy8cARdy79nAmgYw3hK/4HUq48LQ6Wwqo=
+github.com/decred/dcrd/dcrec/secp256k1/v4 v4.4.1/go.mod h1:ZXNYxsqcloTdSy/rNShjYzMhyjf0LaoftYK0p+A3h40=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
### v2transport/handshake_test.go
@@ -61,12 +61,12 @@ func newBufferedReadWriterPair() (*bufferedReadWriter, *bufferedReadWriter) {
rightToLeft := make(chan []byte, 32)
return &bufferedReadWriter{
- recv: rightToLeft,
- send: leftToRight,
- }, &bufferedReadWriter{
- recv: leftToRight,
- send: rightToLeft,
- }
+ recv: rightToLeft,
+ send: leftToRight,
+ }, &bufferedReadWriter{
+ recv: leftToRight,
+ send: rightToLeft,
+ }
}
func (rw *bufferedReadWriter) Read(p []byte) (int, error) {
### wire/go.mod
@@ -1,17 +1,16 @@
module github.com/btcsuite/btcd/wire/v2
-go 1.25
+go 1.26.9
require (
github.com/btcsuite/btcd/chainhash/v2 v2.0.0
github.com/davecgh/go-spew v1.1.1
- github.com/stretchr/testify v1.10.0
- golang.org/x/crypto v0.40.0
+ github.com/stretchr/testify v1.12.1
+ golang.org/x/crypto v0.57.0
pgregory.net/rapid v1.3.0
)
require (
- github.com/pmezard/go-difflib v1.0.0 // indirect
- golang.org/x/sys v0.35.0 // indirect
- gopkg.in/yaml.v3 v3.0.1 // indirect
+ go.yaml.in/yaml/v3 v3.0.5 // indirect
+ golang.org/x/sys v0.48.0 // indirect
)
### wire/go.sum
@@ -2,17 +2,13 @@ github.com/btcsuite/btcd/chainhash/v2 v2.0.0 h1:PMLlSloHJuEeB80XG9EjpXWNEKAZAMLl
github.com/btcsuite/btcd/chainhash/v2 v2.0.0/go.mod h1:mKxcZ7oGTXE7IRV+sS9hP4EVBwc/SzfNR+52IsOP9j8=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
-github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
-github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
-github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA=
-github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
-golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
-golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
-golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
-golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
-gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
-gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
-gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
+github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE=
+github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg=
+go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
+go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
+golang.org/x/crypto v0.57.0 h1:3ZVCjf8Ggz7zneR/EHRVx68Ctf+2pmIMP2UFhh9cC6M=
+golang.org/x/crypto v0.57.0/go.mod h1:Fdz0i5U6CoizGwLda9DttjSk6qlZo25zYNtR+ycvuZA=
+golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
+golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
pgregory.net/rapid v1.3.0 h1:vBvO0VSqti75J1jjYqpgPNBLKMd1+gxa9fYo7vk/Exc=
pgregory.net/rapid v1.3.0/go.mod h1:dPlE4OBBxgXPqkP79flB6sJL1dx5azpI7HQ9MY9Z7uk=Why this scored 46/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.