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

multistream max #229

Merged
merged 2 commits into from
Jan 12, 2024
Merged
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
4 changes: 4 additions & 0 deletions include/libp2p/basic/varint_prefix_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ namespace libp2p::basic {
return value_;
}

size_t size() const {
return got_bytes_;
}

/// Resets reader's state
void reset();

Expand Down
9 changes: 9 additions & 0 deletions src/protocol_muxer/multiselect/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
namespace libp2p::protocol_muxer::multiselect::detail {

constexpr size_t kMaxRecursionDepth = 3;
constexpr size_t kMaxLenBytes = 2;

size_t Parser::bytesNeeded() const {
size_t n = 0;
Expand Down Expand Up @@ -43,7 +44,15 @@ namespace libp2p::protocol_muxer::multiselect::detail {

if (expected_msg_size_ == 0) {
auto s = varint_reader_.consume(data);
if (varint_reader_.size() > kMaxLenBytes) {
state_ = kOverflow;
break;
}
if (s == VarintPrefixReader::kUnderflow) {
if (varint_reader_.size() == kMaxLenBytes) {
state_ = kOverflow;
break;
}
continue;
}
if (s != VarintPrefixReader::kReady) {
Expand Down
Loading