Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

network: fixes to public address support #5851

Merged
merged 6 commits into from Dec 7, 2023

Conversation

algorandskiy
Copy link
Contributor

@algorandskiy algorandskiy commented Dec 2, 2023

Summary

  1. requestTracker changes:
  • Remove http.Request.RemoteAddr overwriting in request tracker
  • Remove http.Request from request tracker
  • Add a new remoteAddresss() method that returns a most suitable address
  1. public addr changes:
  • no otherPublicAddr outside of requestTracker
  • new remoteAddresss() method provides most meaningful address for incoming requests

Rationale:
There is a chain http.Handler's in wsNetwork: request tracker and wsNetwork itself.
Tracked request is created/updated in the first ServeHTTP and used to save a pointer to http.Request object.
This request object is actually gets copied in mux.ServeHTTP that calls downstream wsNetwork's ServeHTTP making
the request non-usable in the main wsNetwork's ServeHTTP so removed.

otherPublicAddr is an address reported by a peer via our custom X-Algorand-Location header that the only
correct value for wsPeer.rootURL (host:port accepting connections) but cannot be trusted.
Unconditionally rewriting it with remoteAddr obtained from a tcp connection is too much and a new
remoteAddresss() method attempts to provide the most meaningful trusted value.

Fixes #5713

Test Plan

  1. Existing test must pass
  2. Added a new unit test
  3. Updated some connection dedup TestPeering tests since they relied on a buggy otherPublicAddr overwriting by remoteAddr.

Copy link

codecov bot commented Dec 2, 2023

Codecov Report

Attention: 10 lines in your changes are missing coverage. Please review.

Comparison is base (f48be99) 55.95% compared to head (793f8ca) 55.92%.
Report is 16 commits behind head on master.

Files Patch % Lines
network/requestTracker.go 73.68% 3 Missing and 2 partials ⚠️
network/wsNetwork.go 54.54% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5851      +/-   ##
==========================================
- Coverage   55.95%   55.92%   -0.03%     
==========================================
  Files         477      477              
  Lines       67346    67355       +9     
==========================================
- Hits        37683    37671      -12     
- Misses      27117    27131      +14     
- Partials     2546     2553       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@algorandskiy algorandskiy marked this pull request as draft December 4, 2023 15:23
1. requestTracker changes:
  - Remove http.Request.RemoteAddr overwriting in request tracker
  - Remove http.Request from request tracker
  - Add a new remoteAddresss() method that returns a most suitable address

2. public addr changes:
  - no otherPublicAddr outside of requestTracker
  - new remoteAddresss() method provides most meaningful address for incoming requests

Rationale:
There is a chain http.Handler's in wsNetwork: request tracker and wsNetwork itself.
Tracked request is created/updated in the first ServeHTTP and used to save a pointer to http.Request object.
This request object is actually gets copied in mux.ServeHTTP that calls downstream wsNetwork's ServeHTTP making
the request non-usable in the main wsNetwork's ServeHTTP so removed.

otherPublicAddr is an address reported by a peer via our custom X-Algorand-Location header that the only
correct value for wsPeer.rootURL (host:port accepting connections) but cannot be trusted.
Unconditionally rewriting it with remoteAddr obtained from a tcp connection is too much and a new
remoteAddresss() method attempts to provide the most meaningful trusted value.

Fixes algorand#5713
network/requestTracker.go Outdated Show resolved Hide resolved
network/requestTracker.go Outdated Show resolved Hide resolved
Co-authored-by: Gary <982483+gmalouf@users.noreply.github.com>
network/wsNetwork_test.go Outdated Show resolved Hide resolved
jasonpaulos
jasonpaulos previously approved these changes Dec 7, 2023
Copy link
Member

@jasonpaulos jasonpaulos left a comment

Choose a reason for hiding this comment

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

This seems better. Just putting in some minor corrections

network/requestTracker_test.go Outdated Show resolved Hide resolved
network/requestTracker.go Outdated Show resolved Hide resolved
Co-authored-by: Jason Paulos <jasonpaulos@users.noreply.github.com>
@algorandskiy algorandskiy merged commit 9229066 into algorand:master Dec 7, 2023
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect Remote Address in wsNetwork logs when algod behind proxy
3 participants