Skip to content

Commit

Permalink
fix: stop byte-fiddling the utp connection ID
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
carver committed Sep 13, 2024
1 parent 5cb1abf commit 892766f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
1 change: 0 additions & 1 deletion portalnet/src/overlay/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down
8 changes: 3 additions & 5 deletions portalnet/src/overlay/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1232,7 +1231,7 @@ where
});

let accept = Accept {
connection_id: cid_send.to_be(),
connection_id: cid_send,
content_keys: requested_keys,
};

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down

0 comments on commit 892766f

Please sign in to comment.