Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove TCPSocket hard-coding in SSLStream #29

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

quinnj
Copy link
Member

@quinnj quinnj commented Jul 13, 2023

No description provided.

@codecov-commenter
Copy link

codecov-commenter commented Jul 13, 2023

Codecov Report

Attention: Patch coverage is 65.00000% with 7 lines in your changes missing coverage. Please review.

Project coverage is 76.44%. Comparing base (3a20f19) to head (6aa00bd).
Report is 5 commits behind head on main.

Files Patch % Lines
src/ssl.jl 65.00% 7 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #29      +/-   ##
==========================================
- Coverage   76.80%   76.44%   -0.36%     
==========================================
  Files           2        2              
  Lines        1095     1104       +9     
==========================================
+ Hits          841      844       +3     
- Misses        254      260       +6     

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

@nickrobinson251
Copy link
Contributor

I think we should probably release this as a breaking change, or make it backwards compatible (e.g. keep SSLStream as a concrete type that is an alias for NewSSLStream{TCPSocket} (name TBD))

Otherwise dispatch will break, e.g. in cases like ::Vector{SSLStream}, and containers like that are no longer concretely typed which ofc has perf implications

@quinnj
Copy link
Member Author

quinnj commented Jul 15, 2023

Yeah, I was mulling over the best way to do this too. I hadn't thought of the alias idea, which is interesting. My initial thought was to do a breaking release, then a minor version release of HTTP where we bump up the minimum required to OpenSSL 2.0.

Do you think there are other advantages of doing the alias-non-breaking route?

@nickrobinson251
Copy link
Contributor

i think a breaking release is probably simplest -- there are only a couple packages depending directly on OpenSSL so a breaking release doesn't seem too disruptive

bio_set_read_retry(bio)
return Cint(0)
io = bio_get_data(bio)
if io isa TCPSocket
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe comment about why we have these identical branches (I assume it allows us to avoid a dynamic dispatch in the first branch?)

It makes me wonder how big the perf impact of the dynamic dispatch is if we are switching out TCPSocket (e.g. for an identical implementation that was just of type TCPSocket2)?

Comment on lines +390 to +395
mutable struct SSLStream{T} <: IO
ssl::SSL
ssl_context::SSLContext
rbio::BIO
wbio::BIO
io::TCPSocket
io::T
Copy link
Contributor

@Drvi Drvi Jul 17, 2023

Choose a reason for hiding this comment

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

Idea: If we parametrize BIO on the io type it was created with we can have more type stable code downstream and save ourselves some unrolling on the result of bio_get_data. Right now, we'd allocate a bunch for, e.g., a UDPSocket due to dynamic dispatch. The default case when we don't know the IO type for whatever reason can use Any or abstract IO.

I tried to prototype this idea but I hit a problem with how callbacks are used. To get any benefit from this new parametrization, we'd need to call the corresponding specialized method (obviously), but now we use a single method globally via BIOStreamCallbacks, e.g. @cfunction on_bio_stream_read Cint (BIO, Ptr{Cchar}, Cint) but we'd need

@cfunction on_bio_stream_read Cint (BIO{TCPSocket}, Ptr{Cchar}, Cint)
@cfunction on_bio_stream_read Cint (BIO{UDPSocket}, Ptr{Cchar}, Cint)
...

to be used by the BIOMethod object accordingly... which would also mean somehow correlating the type parameter with the BIOMethod and then maintaining keeping the @cfunctions around. I'm not too sure how to best approach that, so I'll just leave this here in case you have some better idea:) I think, instead of the current setup, where there is a single BIOMethod (BIO_STREAM_METHOD) we need an IdDict of them (or a generated function generating and caching them), one for each io type (similar to how we specialize connection pools in HTTP).

Copy link
Contributor

@grlap grlap Aug 7, 2023

Choose a reason for hiding this comment

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

I addressed this issue by having two specialized BIOMethods, one specialize for IO another for TCPStream.

#27

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.

5 participants