From 17da64628a0a1aaade90346830f8490b16df74c2 Mon Sep 17 00:00:00 2001 From: bhartnett <51288821+bhartnett@users.noreply.github.com> Date: Fri, 6 Dec 2024 23:53:15 +0800 Subject: [PATCH] Fluffy: Fix broken portal hive tests (#2917) Fix bug in portal stream where connection id was not correctly generated when handling requests from peers. --- fluffy/network/wire/portal_stream.nim | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/fluffy/network/wire/portal_stream.nim b/fluffy/network/wire/portal_stream.nim index 3a0f8b137..06affad99 100644 --- a/fluffy/network/wire/portal_stream.nim +++ b/fluffy/network/wire/portal_stream.nim @@ -190,7 +190,8 @@ proc addContentOffer*( var id = ConnectionId.fromBytesBE(connectionId) # Generate a new id if already existing to avoid using a duplicate - if stream.contentOffers.contains(id): + # or if we happen to get an id of zero from the generator + if id == 0 or stream.contentOffers.contains(id): stream.rng[].generate(connectionId) id = ConnectionId.fromBytesBE(connectionId) @@ -212,12 +213,14 @@ proc addContentRequest*( # TODO: Should we check if `NodeId` & `connectionId` combo already exists? # What happens if we get duplicates? var connectionId: Bytes2 + stream.rng[].generate(connectionId) # uTP protocol uses BE for all values in the header, incl. connection id. var id = ConnectionId.fromBytesBE(connectionId) # Generate a new id if already existing to avoid using a duplicate - if stream.contentRequests.contains(id): + # or if we happen to get an id of zero from the generator + if id == 0 or stream.contentRequests.contains(id): stream.rng[].generate(connectionId) id = ConnectionId.fromBytesBE(connectionId)