Skip to content

Commit 8667a8a

Browse files
committed
feat(p2p): allow inbound-only peers without underlay addresses
Relax the non-empty underlay validation in bzz.ParseAddress/MarshalJSON so browser/wasm and strict-NAT peers that cannot be dialed back can still handshake and use protocols over existing connections. Guard the Connect addressbook.Put so such peers are not stored for reconnection (v2.8 already guards handleIncoming and the reacher). Port of pr-5326; peer registry rename already landed upstream via #5337. Note: this is a deliberate protocol relaxation vs upstream v2.8.
1 parent c05a4b2 commit 8667a8a

2 files changed

Lines changed: 9 additions & 8 deletions

File tree

pkg/bzz/address.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,10 +114,10 @@ func ParseAddress(underlay, overlay, signature, nonce []byte, timestamp int64, n
114114
return nil, fmt.Errorf("deserialize underlays: %w: %w", ErrInvalidAddress, err)
115115
}
116116

117-
if len(multiUnderlays) == 0 {
118-
// no underlays sent
119-
return nil, ErrInvalidAddress
120-
}
117+
// Empty underlays are allowed for inbound-only peers (e.g. browsers/wasm,
118+
// strict NAT) that cannot be dialed back. These peers can still use protocols
119+
// over existing connections but won't participate in Kademlia topology or hive
120+
// gossip (see the addressbook/reacher guards in pkg/p2p/libp2p).
121121

122122
ethAddress, err := crypto.NewEthereumAddress(*recoveredPK)
123123
if err != nil {
@@ -198,9 +198,7 @@ func AreUnderlaysEqual(a, b []ma.Multiaddr) bool {
198198
}
199199

200200
func (a *Address) MarshalJSON() ([]byte, error) {
201-
if len(a.Underlays) == 0 {
202-
return nil, fmt.Errorf("no underlays for %s", a.Overlay)
203-
}
201+
// Empty underlays are allowed for inbound-only peers that cannot be dialed back.
204202

205203
chequebook := ""
206204
if a.ChequebookAddress != (common.Address{}) {

pkg/p2p/libp2p/libp2p.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -803,7 +803,10 @@ func (s *Service) Connect(ctx context.Context, addrs []ma.Multiaddr) (address *b
803803
return nil, p2p.ErrPeerNotFound
804804
}
805805

806-
if i.FullNode {
806+
// Only persist peers with underlays to the addressbook. Inbound-only peers
807+
// (empty underlays, e.g. browsers/wasm) cannot be dialed back, so there is no
808+
// point storing them for reconnection.
809+
if i.FullNode && len(i.BzzAddress.Underlays) > 0 {
807810
if err := s.putHandshakeAddress(i.BzzAddress); err != nil {
808811
_ = s.Disconnect(overlay, "failed storing peer in addressbook")
809812
return nil, fmt.Errorf("storing bzz address: %w", err)

0 commit comments

Comments
 (0)