typelevel / fs2

Compositional, streaming I/O library for Scala
https://fs2.io
Other
2.36k stars 597 forks source link

API to directly open TLS connections, instead of upgrading an existing socket #3138

Open armanbilge opened 1 year ago

armanbilge commented 1 year ago

Background: currently to get a TLSSocket, you first create a non-encrypted Socket, then upgrade it via TLSContext to get a TLSSocket. This proposal is for new TLSContext APIs to directly create client/server TLSSockets.

Motivation:

I'm not aware of any motivation to do this on the JVM, at least with the JDK. Probably a hypothetical Netty-based TLSContext could take advantage of this.

Questions:

  1. Could e.g. Ember and Skunk take advantage of such an API, instead of manually upgrading?
  2. Alternatively, could we make these optimizations within the upgrade mechanism, without exposing a new API? Seems hard, since in theory the user could continue doing things with the raw Socket even after upgrading it. If we assume that won't happen, then maybe it can work.
armanbilge commented 10 months ago

On Native, s2n-tls is capable of interfacing directly with the underlying socket's file descriptor. This should have higher performance

There is a significant caveat to this: s2n-tls does not (and cannot without redesign) use io_uring for dispatching the reads/writes. So it might not have higher performance compared to our io_uring-powered sockets.

There's still a chance for kTLS to be compatible with io_uring, depending on the implementation strategy taken.