Skip to content

Commit

Permalink
multistream max (#229)
Browse files Browse the repository at this point in the history
Signed-off-by: turuslan <[email protected]>
  • Loading branch information
turuslan authored Jan 12, 2024
1 parent e697206 commit aa51f77
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit aa51f77

Please sign in to comment.