From 892766f15e00be973b788ec0686db940b910c9c5 Mon Sep 17 00:00:00 2001 From: Jason Carver Date: Thu, 12 Sep 2024 18:36:00 -0700 Subject: [PATCH] fix: stop byte-fiddling the utp connection ID Trust that the utp library returns the connection ID in its preferred format. Stop swapping to and from big-endian. I am still working out why this wasn't causing any problems up until the (still pending) RFC refactor. After the refactor, the connection IDs diverge on the outbound and inbound sides, which causes the utp transmission to fail. --- portalnet/src/overlay/protocol.rs | 1 - portalnet/src/overlay/service.rs | 8 +++----- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/portalnet/src/overlay/protocol.rs b/portalnet/src/overlay/protocol.rs index 074abb3c3..3958196ad 100644 --- a/portalnet/src/overlay/protocol.rs +++ b/portalnet/src/overlay/protocol.rs @@ -466,7 +466,6 @@ where Content::Enrs(_) => Ok((found_content, false)), // Init uTP stream if `connection_id` is received Content::ConnectionId(conn_id) => { - let conn_id = u16::from_be(conn_id); let content = self.init_find_content_stream(enr, conn_id).await?; match self.validate_content(&content_key, &content).await { Ok(_) => Ok((Content::Content(content), true)), diff --git a/portalnet/src/overlay/service.rs b/portalnet/src/overlay/service.rs index b14132047..1d7119c63 100644 --- a/portalnet/src/overlay/service.rs +++ b/portalnet/src/overlay/service.rs @@ -967,8 +967,7 @@ where drop(permit); }); - // Connection id is sent as BE because uTP header values are stored also as BE - Ok(Content::ConnectionId(cid_send.to_be())) + Ok(Content::ConnectionId(cid_send)) } } // If we don't have data to send back or can't obtain a permit, send the requester a @@ -1232,7 +1231,7 @@ where }); let accept = Accept { - connection_id: cid_send.to_be(), + connection_id: cid_send, content_keys: requested_keys, }; @@ -1457,7 +1456,7 @@ where } // Build a connection ID based on the response. - let conn_id = u16::from_be(response.connection_id); + let conn_id = response.connection_id; let cid = utp_rs::cid::ConnectionId { recv: conn_id, send: conn_id.wrapping_add(1), @@ -1676,7 +1675,6 @@ where Content::Enrs(_) => return Err(anyhow!("expected content, got ENRs")), // Init uTP stream if `connection_id` is received Content::ConnectionId(conn_id) => { - let conn_id = u16::from_be(conn_id); let cid = utp_rs::cid::ConnectionId { recv: conn_id, send: conn_id.wrapping_add(1),