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

Fix compression enable flag and compression algorithm fetching #3705

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/ripple/overlay/impl/PeerImp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ PeerImp::PeerImp(
, request_(std::move(request))
, headers_(request_)
, compressionEnabled_(
headers_["X-Offer-Compression"] == "lz4" ? Compressed::On
: Compressed::Off)
headers_["X-Offer-Compression"] == "lz4" && app_.config().COMPRESSION
? Compressed::On
: Compressed::Off)
{
}

Expand Down
11 changes: 9 additions & 2 deletions src/ripple/overlay/impl/ProtocolMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ parseMessageHeader(
MessageHeader hdr;
auto iter = buffersBegin(bufs);

// Check valid header
// Check valid header compressed message:
// - 4 bits are the compression algorithm, 1st bit is always set to 1
// - 2 bits are always set to 0
// - 26 bits are the payload size
// - 32 bits are the uncompressed data size
if (*iter & 0x80)
{
hdr.header_size = headerBytesCompressed;
Expand All @@ -159,7 +163,7 @@ parseMessageHeader(
return boost::none;
}

hdr.algorithm = static_cast<compression::Algorithm>(*iter);
hdr.algorithm = static_cast<compression::Algorithm>(*iter & 0xF0);

if (hdr.algorithm != compression::Algorithm::LZ4)
{
Expand All @@ -184,6 +188,9 @@ parseMessageHeader(
return hdr;
}

// Check valid header uncompressed message:
// - 6 bits are set to 0
// - 26 bits are the payload size
if ((*iter & 0xFC) == 0)
{
hdr.header_size = headerBytes;
Expand Down