Skip to content

Conversation

@cloorc
Copy link

@cloorc cloorc commented Dec 2, 2025

  • Add UseProxy field to p2p.Config and corresponding --use-proxy CLI flag.
  • Implement proxy-aware tcpDialer (uses golang.org/x/net/proxy and attempts context-aware DialContext when supported).
  • Wire UseProxy through Server to the dialer so peer dials can go via SOCKS5 proxy defined by ALL_PROXY/all_proxy.
  • Minor debug start.sh for running geth with --use-proxy.

This will fix #33345

Copilot AI review requested due to automatic review settings December 2, 2025 10:27
@cloorc cloorc requested review from fjl and zsfelfoldi as code owners December 2, 2025 10:27
Copilot finished reviewing on behalf of cloorc December 2, 2025 10:29
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds optional SOCKS5 proxy support for outbound peer connections in geth's p2p networking layer. When enabled via the --use-proxy CLI flag, peer dials are routed through a SOCKS5 proxy specified by the ALL_PROXY or all_proxy environment variables. This feature is useful for running nodes behind network restrictions or for privacy-enhanced operations.

Key changes:

  • Adds UseProxy configuration field to control proxy usage
  • Implements proxy-aware dialing in tcpDialer with context support
  • Provides CLI flag --use-proxy for user control

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
p2p/config.go Adds UseProxy boolean field to enable proxy support in p2p configuration
p2p/dial.go Implements proxy dialing logic using golang.org/x/net/proxy with context-aware fallback
p2p/server.go Passes UseProxy config value to tcpDialer during dial scheduler setup
cmd/utils/flags.go Defines --use-proxy CLI flag and wires it to p2p configuration
cmd/geth/main.go Registers the UseProxyFlag with the geth command

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +85 to +87
} else {
log.Warn("Proxy dialer does not support context, falling back to direct", "addr", addr.String())
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When the proxy dialer doesn't support DialContext, the code logs a warning and falls back to direct connection without actually using the non-context-aware proxy dialer. This fallback behavior is inconsistent with the user's intention to use a proxy. Consider either returning an error when UseProxy is true but the proxy doesn't support context, or actually calling the non-context-aware Dial method (though this would lose context cancellation support). The current implementation silently ignores the proxy requirement.

Copilot uses AI. Check for mistakes.
Comment on lines +81 to +88
if t.useProxy {
log.Debug("Dialing peer via proxy", "direct", proxyDialer == proxy.Direct, "addr", addr.String())
if v, ok := proxyDialer.(dialerWithContext); ok {
return v.DialContext(ctx, "tcp", addr.String())
} else {
log.Warn("Proxy dialer does not support context, falling back to direct", "addr", addr.String())
}
}
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new proxy dialing functionality lacks test coverage. The codebase has comprehensive tests for the dialing logic in dial_test.go, but there are no tests verifying the proxy behavior. Consider adding tests to cover: (1) successful proxy connections when useProxy is true, (2) fallback to direct connection when proxy dialer doesn't support context, (3) behavior when proxy environment variables are not set, and (4) interaction with the existing dial scheduler.

Copilot uses AI. Check for mistakes.
DialContext(ctx context.Context, network, address string) (net.Conn, error)
}

var proxyDialer = proxy.FromEnvironment()
Copy link

Copilot AI Dec 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The global variable proxyDialer is initialized once at package level and accessed by all tcpDialer instances. This could lead to a race condition if the environment variable changes at runtime or if different instances need different proxy configurations. Consider making proxyDialer a field of tcpDialer that is initialized when the dialer is created, or use sync.Once to ensure thread-safe initialization if shared state is intended.

Copilot uses AI. Check for mistakes.
- Add `UseProxy` field to `p2p.Config` and corresponding `--use-proxy` CLI flag.
- Implement proxy-aware `tcpDialer` (uses `golang.org/x/net/proxy` and attempts context-aware DialContext when supported).
- Wire `UseProxy` through `Server` to the dialer so peer dials can go via SOCKS5 proxy defined by `ALL_PROXY`/`all_proxy`.
- Minor debug `start.sh` for running geth with `--use-proxy`.

Signed-off-by: cloorc <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add proxy support for p2p connections

1 participant