-
Notifications
You must be signed in to change notification settings - Fork 28
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
Support transport-level compression #256
Conversation
…and ntci::DatagramSocket
…ure build with zlib, zstd, and lz4 support
const bsl::uint32_t CompressionFrameHeader::k_MAGIC = 1380730184; | ||
#else | ||
const bsl::uint32_t CompressionFrameHeader::k_MAGIC = 1212501074; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment explaining where these magic number comes from.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They don't come from anywhere, that's why they are "magic". Magic numbers correspond to identifiable byte sequences used to help pluck out frame boundaries in hex dumps.
…b buffer has insufficient capacity
…lied during send operation
Many applications desire to either compress an entire data stream (or all datagrams), or compress the payload portion carried inside a higher-level message protocol. This PR acknowledges this not-usual requirement by providing an API mechanism to deflate/inflate a data stream, and formalizes the requirement that the entire transport is compressed by allowing a user to optionally apply a deflater to all outgoing data sent through an
ntci::StreamSocket
orntci::DatagramSocket
, and optionally apply an inflater to all incoming data received by anntci::StreamSocket
orntci::DatagramSocket
. Similar to how TLS is integrated, the user "sees" only the uncompressed data. The general idea is that, when a deflater is attached to a socket, all data given to "send" will be first, internally and automatically deflated before attempted to be copied to the socket send buffer/stored on the write queue. Similarly, all data copied from the socket receive buffer will be internally and automatically inflated before being staged in the read queue to be conditionally offered to the user for processing according to their receive criteria and read queue low watermark. Note that compression and encryption can be applied simultaneously; care is taken in the internal implementation to first deflate then encrypt when sending, but first decrypt then inflate when receiving.As an initial proposal, this PR acknowledges that there are several compression techniques popular when compressing network traffic. To start, this PR supports "zlib", "gzip", "lz4", and "zstd". These techniques are enumerated for ease-of-selection by the user, with a consistent API abstraction over the selected algorithm. For the implementation of these algorithms, this PR is delegates to industry-standard third party libraries to perform the actual compression and decompression. These third-party libraries must be explicitly enabled at build time. If the thirdparty library implementing a selected compression technique was not configured as a dependency at build time, the initialization of the compressor will fail at run-time with a detectable error. Alternatively, users may "plug in" their own compressors implemented however they wish.
To build with internal support for the enumerated compression algorithms, perform the build as:
This PR introduces the following new components:
This PR integrates automatic compression of a communication through socket by adding new methods to
ntci::StreamSocket
andntci::DatagramSocket
calledsetWriteDeflater
andsetReadInflater
. It is permitted to only apply compression in one direction (i.e. outgoing data is compressed but incoming data is not decompressed.) For example, see the usage ofd_sendDeflater_sp
inntcr::StreamSocket::send()
at ntcr_streamsocket.cpp:5472 andd_receiveInflater_sp
inntcr::StreamSocket::privateDequeueReceiveBuffer()
at ntcr_streamsocket.cpp:2922. But note we have many code paths both inntc{r,p}_streamsocket
andntc{r,p}_datagramsocket
that must handle possible deflation and inflation when there is no encryption, and when encryption is also simultaneously enabled.Compression support is tested in a new testing framework for the
ntcf
package. This testing machinery is not compiled into the library nor publically installed. Subsequent work will be performed to try to simply some the low-level tests inntcf_system
to be written in terms of this higher-level testing framework. Considerntcf_test*
to be long-term work in progress.