-
-
Notifications
You must be signed in to change notification settings - Fork 318
rework gateway compression #2000
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
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
c1aaf97
preliminary zlib and zstd bindings
akiraveliara 0c1ab7d
Merge branch 'master' into aki/compression
akiraveliara 88f961a
nuke the old PayloadDecompressor and add ways to configure compression
akiraveliara d2d0a48
the last remaining straws
akiraveliara d33e9cd
implement the decompressors
akiraveliara b0f73e0
use the pointer to access and check for prefixes
akiraveliara bde8b85
read the zlib suffix rather than headers
akiraveliara 791ffed
Merge branch 'master' into aki/compression
akiraveliara 93363f1
fill the throw helpers in
akiraveliara d676bb0
Merge branch 'master' into aki/compression
akiraveliara 1b82cd3
discord doesn't send the suffix.
akiraveliara ffd672d
cope with unterminated payloads in zlib
akiraveliara af2cf41
alias consistency
akiraveliara f51ee2d
remove superseded GatewayCompressionLevel
akiraveliara 3ea1463
remove GatewayCompressionLevel from DiscordConfiguration
akiraveliara 52e4c3f
minuscule fix for gateway identifys
akiraveliara 4e281ae
merge conflicts
akiraveliara 08b5e37
avoid doubly infinite looping over buffer processing
akiraveliara a07c5ea
managed fallback + default decompression selector
akiraveliara 2e9ae49
finish the managed backend
akiraveliara 3e7ac6d
log b64'ed compressed payloads temporarily
akiraveliara 07b3082
remove managed backend again
akiraveliara 1528afb
make zstd decompression work, hopefully
akiraveliara 79e95c4
make zlib work on top of ZLibStream, begrudgingly
akiraveliara 318fba3
make extension method naming consistent
akiraveliara 026f111
remove debugging code
akiraveliara 0e82e6d
make sure to reset the compression context if the connection changes
akiraveliara ab04ea0
change the loglevel of the message telling us the active decompressor
akiraveliara de69b83
add doc
akiraveliara d49d846
implement the finalizer vam wanted
akiraveliara 3d8fe83
fix a crash on shutdown
akiraveliara File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
DSharpPlus/Net/Gateway/Compression/IPayloadDecompressor.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| using System; | ||
|
|
||
| using CommunityToolkit.HighPerformance.Buffers; | ||
|
|
||
| namespace DSharpPlus.Net.Gateway.Compression; | ||
|
|
||
| /// <summary> | ||
| /// Contains functionality for decompressing inbound gateway payloads. | ||
| /// </summary> | ||
| public interface IPayloadDecompressor : IDisposable | ||
| { | ||
| /// <summary> | ||
| /// Gets the name of the decompressor. | ||
| /// </summary> | ||
| public string? Name { get; } | ||
|
|
||
| /// <summary> | ||
| /// Indicates whether the present compression format is connection-wide. | ||
| /// </summary> | ||
| public bool IsTransportCompression { get; } | ||
|
|
||
| /// <summary> | ||
| /// Attempts to decompress the provided payload. | ||
| /// </summary> | ||
| /// <param name="compressed">The raw, compressed data.</param> | ||
| /// <param name="decompressed">A buffer writer for writing decompressed data.</param> | ||
| /// <returns>A value indicating whether the operation was successful.</returns> | ||
| public bool TryDecompress(ReadOnlySpan<byte> compressed, ArrayPoolBufferWriter<byte> decompressed); | ||
|
|
||
| /// <summary> | ||
| /// Initializes the decompressor for a new connection. | ||
| /// </summary> | ||
| public void Initialize(); | ||
|
|
||
| /// <summary> | ||
| /// Frees and destroys all internal state when a connection has terminated. | ||
| /// </summary> | ||
| public void Reset(); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| using System; | ||
|
|
||
| using CommunityToolkit.HighPerformance; | ||
| using CommunityToolkit.HighPerformance.Buffers; | ||
|
|
||
| namespace DSharpPlus.Net.Gateway.Compression; | ||
|
|
||
| /// <summary> | ||
| /// Represents a decompressor that doesn't decompress at all. | ||
| /// </summary> | ||
| public sealed class NullDecompressor : IPayloadDecompressor | ||
| { | ||
| /// <inheritdoc/> | ||
| public string? Name => null; | ||
|
|
||
| // this decompressor *technically* applies transport-wide, and this simplifies composing the IDENTIFY payload. | ||
| /// <inheritdoc/> | ||
| public bool IsTransportCompression => true; | ||
|
|
||
| /// <inheritdoc/> | ||
| public bool TryDecompress(ReadOnlySpan<byte> compressed, ArrayPoolBufferWriter<byte> decompressed) | ||
| { | ||
| decompressed.Write(compressed); | ||
| return true; | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Dispose() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Reset() | ||
| { | ||
|
|
||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| public void Initialize() | ||
| { | ||
|
|
||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.