Skip to content

fix: refactor proxy header logic into ConnectionStream#157

Open
junderw wants to merge 1 commit into
mempoolfrom
junderw/add-electrum-ip-detection
Open

fix: refactor proxy header logic into ConnectionStream#157
junderw wants to merge 1 commit into
mempoolfrom
junderw/add-electrum-ip-detection

Conversation

@junderw

@junderw junderw commented Jun 29, 2026

Copy link
Copy Markdown
Member
  1. Large refactor. Moved the Proxy parse logic into ConnectionStream (the wrapper around TcpStream or UnixStream)
  2. Should make it easier to nab the proxy IP without blocking, before we start logging stuff.

NGINX sends the Proxy header as soon as the client finishes the TCP connection regardless of whether the client sends anything yet... so this should work out fine.

Client                    NGINX                     Origin
  |                         |                        |
  |---- TCP SYN ----------->|                        |
  |<--- SYN/ACK ------------|                        |
  |---- ACK --------------->|                        |
  |                         |---- TCP SYN ---------->|
  |                         |<--- SYN/ACK -----------|
  |                         |---- ACK -------------->|
  |                         |---- PROXY header ----->|
  |                         |     (immediately)      |
  |                         |                        |
  |                         |                        |
  |                         |                        |
  |---- First payload ----->|---- First payload ---->|

Copilot AI left a comment

Copy link
Copy Markdown

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 refactors PROXY-protocol (HAProxy) header parsing so it lives inside ConnectionStream, enabling early/non-blocking resolution of the proxied client address for logging and per-client connection limiting.

Changes:

  • Introduces ConnectionStream buffering (leftover) and one-shot PROXY probing (resolve_proxy) to strip headers before request parsing.
  • Updates connection lifecycle/logging to use an eagerly resolved client identifier.
  • Simplifies the request reader by removing the prior pre-read/Cursor chaining logic.

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

Comment thread src/electrum/server.rs
Comment thread src/electrum/server.rs
Comment thread src/electrum/server.rs Outdated
@junderw junderw force-pushed the junderw/add-electrum-ip-detection branch from 00df937 to 82bf715 Compare June 29, 2026 13:22
@junderw junderw requested a review from Copilot June 29, 2026 13:23

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 4 comments.

Comment thread src/electrum/server.rs Outdated
Comment thread src/electrum/server.rs
Comment thread src/electrum/server.rs
Comment thread src/electrum/server.rs
@junderw junderw force-pushed the junderw/add-electrum-ip-detection branch from 82bf715 to ae924b2 Compare June 29, 2026 14:43
@junderw junderw requested a review from Copilot June 29, 2026 14:44

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread src/electrum/server.rs
@junderw junderw force-pushed the junderw/add-electrum-ip-detection branch from 351266a to d351a40 Compare June 29, 2026 14:58
@junderw junderw requested a review from Copilot June 29, 2026 14:58

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread src/electrum/server.rs Outdated
Comment thread src/electrum/server.rs Outdated
@junderw junderw force-pushed the junderw/add-electrum-ip-detection branch from d351a40 to 8c6f855 Compare June 29, 2026 15:23
@junderw junderw requested a review from Copilot June 29, 2026 15:24

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/electrum/server.rs
Comment thread src/electrum/server.rs
Comment thread src/electrum/server.rs
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.

3 participants