Skip to content

Conversation

@martinconic
Copy link
Contributor

@martinconic martinconic commented Aug 11, 2025

Checklist

  • I have read the coding guide.
  • My change requires a documentation update, and I have done it.
  • I have added tests to cover my changes.
  • I have filled out the description and linked the related issues.

Description

This pull request introduces an AutoTLS implementation for the Bee node. The primary motivation for this feature is to support the In-Browser project, which requires secure communication channels for clients.

Modern web browsers strictly enforce secure contexts, meaning they can only connect to endpoints using secure protocols like HTTPS or Secure WebSockets (wss://). AutoTLS automates the process of obtaining, managing, and renewing valid TLS certificates from a Certificate Authority (like Let's Encrypt).

By implementing AutoTLS, Bee nodes can now accept wss:// connections directly, enabling browsers to interact with the Bee network securely and seamlessly.

Implementation Details
The implementation is based on the approach outlined in the official libp2p blog post on AutoTLS and follows the patterns from the go-libp2p AutoTLS example.

Testing & Validation
The functionality was manually tested by running a Bee node (built with the flag above) and attempting to connect to it using wscat over a secure websocket.

Test Command:
wscat --no-check -c wss://<node-public-ip>.<peer-id>.libp2p.direct:5500

Result:
A successful connection was established, and the node responded with the multistream header, confirming the wss listener is active and secured with a valid TLS certificate:

Connected (press CTRL+C to quit)
< /multistream/1.0.0

Related Issue (Optional)

#5171

@martinconic martinconic marked this pull request as ready for review August 14, 2025 06:46
@bcsorvasi bcsorvasi added this to the v2.7.0 milestone Oct 7, 2025
@bcsorvasi bcsorvasi linked an issue Oct 7, 2025 that may be closed by this pull request
@gacevicljubisa gacevicljubisa changed the title AutoTLS implementation feat(p2p): add AutoTLS support for secure WebSocket connections Jan 2, 2026
func parseAddress(addr string) (*parsedAddress, error) {
host, port, err := net.SplitHostPort(addr)
if err != nil {
return nil, fmt.Errorf("address: %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

The error message "address: ..." is generic. Consider adding the actual address to the error for debugging.

Copy link
Member

Choose a reason for hiding this comment

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

Good point. I have updated the error.

for _, underlay := range multiUnderlay {
// ping each underlay address, pick first available
start = time.Now()
if _, err := s.streamer.Ping(ctx, underlay); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intentional to remove ping check before adding the peer ?

Copy link
Member

Choose a reason for hiding this comment

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

Yes, the ping in hive is not needed as the peer may not be available right away, but most importantly the removal of this Ping also cause much more stable topology when running integration tests on testnet clusters.

pkg/hive/hive.go Outdated
if err := s.addressBook.Put(bzzAddress.Overlay, bzzAddress); err != nil {
s.metrics.StorePeerErr.Inc()
s.logger.Warning("skipping peer in response", "peer_address", p.String(), "error", err)
return
Copy link
Contributor

@akrem-chabchoub akrem-chabchoub Jan 7, 2026

Choose a reason for hiding this comment

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

Why the log is mentionning warning / skip and there is a return ?

Copy link
Member

Choose a reason for hiding this comment

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

Good catch, I have change return to continue to try other addresses and I've updated the log message to be more clear.

Limit: libp2prate.Limit{RPS: 10.0, Burst: 40},
},
},
GracePeriod: 10 * time.Second,
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe extracting these numbers into separate variables, with a small comment explaining the rationale behind them ?

Copy link
Member

Choose a reason for hiding this comment

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

I have added some comments. If you still think that extracting variables instead having here literals, I will make them, but it appeared to me that such indirection made this part of the code less readable, in this particular case.

}

// If we skipped all addresses due to self-connection, return an error
if skippedSelf && info != nil && info.ID == s.host.ID() {
Copy link
Contributor

Choose a reason for hiding this comment

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

If skippedSelf is true, info.ID == s.host.ID() will be true also, I was wondering whether both checks are needed here?

Copy link
Member

Choose a reason for hiding this comment

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

Correct, I have remove the unnecessary checks.

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.

AutoTLS support

7 participants