Fix compression enable flag and compression algorithm fetching #3705
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.
High Level Overview of Change
Fixes compressionEnabled_ flag in the inbound peer.
Fixes compression algorithm fetching on protocol message receive.
Context of Change
Both issues are introduced in 1.6.0.
First fix adds configuration compression flag check when setting compressionEnabled_ in the PeerImp constructor.
Previously the compressionEnabled_ of the inbound peer was set to true if the connected peer supported compression even though the node didn't support the compression.
Second fix adds 0xF0 mask when fetching the compression algorithm from a received message. Previously the compression algorithm used the whole byte. Since the algorithm occupies high four bits, when a payload size is large then the low four bits could be set resulting in an invalid algorithm.
Type of Change
Test Plan
Added log messages to PeerImp::PeerImp() to verify the compressionEnabled_ flag for different compression configurations. Added log messages to PeerImp::onMessageBegin() to output received message compressed flag and peer's remote address.