Skip to content

Conversation

@algorandskiy
Copy link
Contributor

@algorandskiy algorandskiy commented Sep 4, 2024

Summary

libp2phttp server rejects to run when no listen addresses can be determined and no ListenAddrs provided. After filtering out all non-routable and private addresses via address factory in host.Addrs(), our http server failed to start since host.Addrs() returned empty.
Fixed by handling this situation explicitly in MakeHTTPServer and providing 0.0.0.0 via ListenAddrs.

Note, if NetAddress is set to some specific address, all this new logic is not executed - http server will start on the NetAddress interface as before this change.

Test Plan

Added an explicit unit test for this NetAddress = ":0" case

@codecov
Copy link

codecov bot commented Sep 4, 2024

Codecov Report

Attention: Patch coverage is 0% with 6 lines in your changes missing coverage. Please review.

Project coverage is 56.18%. Comparing base (b1d81bc) to head (afa9785).
Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
network/p2p/http.go 0.00% 5 Missing ⚠️
network/p2p/p2p.go 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #6123      +/-   ##
==========================================
+ Coverage   56.14%   56.18%   +0.04%     
==========================================
  Files         494      494              
  Lines       69931    69936       +5     
==========================================
+ Hits        39266    39297      +31     
+ Misses      27987    27963      -24     
+ Partials     2678     2676       -2     

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

if len(streamHost.Addrs()) == 0 {
logging.Base().Debugf("MakeHTTPServer: no addresses for %s, asking to listen all interfaces", streamHost.ID())
httpServer.ListenAddrs = []multiaddr.Multiaddr{
multiaddr.StringCast("/ip4/0.0.0.0/tcp/0/http"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this /ip4/0.0.0.0/tcp/0/http mean it will pick a different port from libp2p or the same one?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not used from what I see in the source code, it gets a listener from basic_host but checks ListenAddrs for empty. But I agree, it is better to use the same port as basic_host, I'll followup in another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants