Skip to content

[2/3] implement the caller-side managed buffers API (take 2) - #1583

Merged
ctz merged 15 commits into
rustls:mainfrom
japaric:rfc1420-impl-take2
Dec 19, 2023
Merged

ctz merged 15 commits into
rustls:mainfrom
japaric:rfc1420-impl-take2

Conversation

@japaric

@japaric japaric commented Nov 10, 2023 •

Copy link
Copy Markdown
Contributor

supersedes #1578 but I'm not closing that one just yet because this one is still WIP

I took a different approach and tried to first move the buffers out from CommonState into ConnectionCommon to implement ConnectionCommon on top of UnbufferedConnectionCommon ; that turned out to be a non-trivial exercise. Then I tried the same "unbuffering" exercise with MessageDeframer and that turned out to be relatively straightforward. That's when I realized that as a more incremental step we can implement UnbufferedConnectionCommon on top of the current, buffered CommonState while still achieving the goal of not depending on IO traits or anything else from the std crate. So that's what this PR does (I haven't finished moving the server and early data stuff over from #1578 )

I did some renaming while copying over bits from #1578

@codecov

codecov Bot commented Nov 10, 2023 •

Copy link
Copy Markdown

Codecov Report

Attention: 69 lines in your changes are missing coverage. Please review.

Comparison is base (902c8e0) 95.90% compared to head (cfbcb5c) 95.60%.

Files Patch % Lines
rustls/src/conn/unbuffered.rs 80.55% 49 Missing ⚠️
rustls/src/client/client_conn.rs 79.62% 11 Missing ⚠️
rustls/src/common_state.rs 94.33% 6 Missing ⚠️
rustls/src/server/server_conn.rs 87.50% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1583      +/-   ##
==========================================
- Coverage   95.90%   95.60%   -0.30%     
==========================================
  Files          78       79       +1     
  Lines       16211    16662     +451     
==========================================
+ Hits        15547    15930     +383     
- Misses        664      732      +68     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@japaric
japaric marked this pull request as ready for review November 13, 2023 14:47
@japaric
japaric force-pushed the rfc1420-impl-take2 branch 4 times, most recently from ca6f70d to b02bc61 Compare November 13, 2023 17:54
@japaric

japaric commented Nov 13, 2023 •

Copy link
Copy Markdown
Contributor Author

I think the only thing missing here is implementing buffer size checking but that depends on #1579 . I'll implement that locally and push it when #1579 gets merged I already pushed that commit. I'll remove the #1579 cherry-pick after that has been merged

I'll resume looking into implementing *Connection on top of Unbuffered*Connection. One thing I noticed there is that it may make sense to let UnbufferedConnection deref to CommonState but some of its methods related to internal buffers (like wants_read, wants_write, set_buffer_limit) should move from CommonState to ConnectionCommon. Either that, or we add a subset of CommonState methods to UnbufferedConnection (internally they would delegate to CommonState); that would let us provide better API docs on methods like is_handshaking (which talks about Connection::process_new_packets and it's not applicable to UnbufferedConnection).

@japaric japaric mentioned this pull request Nov 14, 2023
1 task done

@djc djc left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just looked at the first commit for now.

Comment thread rustls/src/msgs/deframer.rs Resolved
Comment thread rustls/src/msgs/deframer.rs Resolved
Comment thread rustls/src/msgs/deframer.rs Outdated
}

#[derive(Default)]
struct MessageDeframerBuffer {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This feels a little verbose. Just DeframerBuffer should do?

@ctz ctz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Up to and including "early data support".

Comment thread rustls/tests/unbuffered.rs Resolved
Comment thread rustls/src/client/client_conn.rs Resolved
Comment thread rustls/src/conn/unbuffered.rs Resolved
Comment thread rustls/src/conn/unbuffered.rs Resolved
Comment thread examples/src/bin/unbuffered-client.rs Resolved
Comment thread rustls/src/conn/unbuffered.rs Resolved
Comment thread rustls/src/record_layer.rs Resolved
Comment thread rustls/src/conn/unbuffered.rs Resolved
@japaric

japaric commented Nov 16, 2023

Copy link
Copy Markdown
Contributor Author

docs and module org wise, what do you think about exporting / exposing all the UnbufferedConnection-related types under a public unbuffered module that includes module-level docs with an overview of the API and perhaps a doctest example?

@djc

djc commented Nov 16, 2023

Copy link
Copy Markdown
Member

I'll suggest we trim this PR down to only the deframer buffer commits in order to make it more digestible?

@japaric

japaric commented Nov 17, 2023

Copy link
Copy Markdown
Contributor Author

I'll suggest we trim this PR down to only the deframer buffer commits in order to make it more digestible?

separated the deframer commits into #1595

@japaric
japaric force-pushed the rfc1420-impl-take2 branch 3 times, most recently from d3ddb1a to 3e8103f Compare November 24, 2023 15:16
@japaric

japaric commented Nov 24, 2023

Copy link
Copy Markdown
Contributor Author

rebased to fix a merge conflict. I also have fleshed out more the API docs

@japaric japaric changed the title implement the caller-side managed buffers API (take 2) [2/3] implement the caller-side managed buffers API (take 2) Dec 1, 2023
@pvdrz
pvdrz force-pushed the rfc1420-impl-take2 branch from bbc0830 to 620e11e Compare December 1, 2023 22:50
@pvdrz

pvdrz commented Dec 1, 2023

Copy link
Copy Markdown
Contributor

rebased to fix merge conflicts

Comment thread rustls/tests/unbuffered.rs Resolved
Comment thread examples/src/lib.rs Resolved
@pvdrz
pvdrz force-pushed the rfc1420-impl-take2 branch 2 times, most recently from f526a4a to 334d6f4 Compare December 4, 2023 21:30
@pvdrz

pvdrz commented Dec 4, 2023

Copy link
Copy Markdown
Contributor

I rebased this on top of #1595, resolved the conflicts with main and addressed @ctz comments.

@pvdrz
pvdrz force-pushed the rfc1420-impl-take2 branch from af5e3e6 to 4996f62 Compare December 15, 2023 19:46
@pvdrz
pvdrz requested a review from cpu December 15, 2023 19:46
@pvdrz

pvdrz commented Dec 15, 2023

Copy link
Copy Markdown
Contributor

@cpu not sure why I can't comment but #1583 (comment) these functions have been renamed already.

@cpu

cpu commented Dec 15, 2023 •

Copy link
Copy Markdown
Member

@cpu not sure why I can't comment but #1583 (comment) these functions have been renamed already.

Sorry, GitHub has really mangled the interleaving of my review comments with the older ones 😭

@pvdrz
pvdrz force-pushed the rfc1420-impl-take2 branch from 4996f62 to 5a55d44 Compare December 18, 2023 15:27
@pvdrz

pvdrz commented Dec 18, 2023

Copy link
Copy Markdown
Contributor

@ctz, @cpu, @djc is there anything else to be done here?

@pvdrz
pvdrz force-pushed the rfc1420-impl-take2 branch from 5a55d44 to cfbcb5c Compare December 18, 2023 16:55
ctz added 4 commits December 18, 2023 11:56
This allows people to use `unwrap_err`, etc.
This a) returns an error, and b) sends an alert.  But unfortunately
(a) doesn't include accounting for the processed bytes.
This sticks the error from `process_tls_records()` inside
`UnbufferedStatus`.  That means the `discard` field is still
available, but continues to require handling the error to learn
the `state` field's underlying value.

TODO: the example code is made to unwrap errors in this PR.
They need reorganising so the discard processing happens before
error handling.
@ctz
ctz added this pull request to the merge queue Dec 19, 2023
Merged via the queue into rustls:main with commit 74fb489 Dec 19, 2023
@tshepang

Copy link
Copy Markdown

epic!

@tshepang
tshepang deleted the rfc1420-impl-take2 branch December 19, 2023 09:43
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.

7 participants