Skip to content

Commit

Permalink
Test SEND_MORE and fix log statement that causes error with SEND_MORE
Browse files Browse the repository at this point in the history
  • Loading branch information
bboston7 committed Aug 2, 2024
1 parent f04f0c1 commit f1111b9
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
11 changes: 4 additions & 7 deletions src/overlay/FlowControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ FlowControl::maybeReleaseCapacity(StellarMessage const& msg)
releaseAssert(threadIsMain());
std::lock_guard<std::mutex> guard(mFlowControlMutex);

if (msg.type() == SEND_MORE || msg.type() == SEND_MORE_EXTENDED)
if (msg.type() == SEND_MORE_EXTENDED)
{
if (mNoOutboundCapacity)
{
Expand Down Expand Up @@ -283,8 +283,8 @@ FlowControl::canRead() const
uint32_t
FlowControl::getNumMessages(StellarMessage const& msg)
{
return msg.type() == SEND_MORE ? msg.sendMoreMessage().numMessages
: msg.sendMoreExtendedMessage().numMessages;
releaseAssert(msg.type() == SEND_MORE_EXTENDED);
return msg.sendMoreExtendedMessage().numMessages;
}

bool
Expand All @@ -294,10 +294,7 @@ FlowControl::isSendMoreValid(StellarMessage const& msg,
releaseAssert(threadIsMain());
std::lock_guard<std::mutex> guard(mFlowControlMutex);

bool sendMoreExtendedType = msg.type() == SEND_MORE_EXTENDED;
bool sendMoreType = msg.type() == SEND_MORE;

if (!sendMoreExtendedType && !sendMoreType)
if (msg.type() != SEND_MORE_EXTENDED)
{
errorMsg =
fmt::format("unexpected message type {}",
Expand Down
2 changes: 1 addition & 1 deletion src/overlay/FlowControlCapacity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void
FlowControlMessageCapacity::releaseOutboundCapacity(StellarMessage const& msg)
{
ZoneScoped;
releaseAssert(msg.type() == SEND_MORE || msg.type() == SEND_MORE_EXTENDED);
releaseAssert(msg.type() == SEND_MORE_EXTENDED);
auto numMessages = FlowControl::getNumMessages(msg);
if (!hasOutboundCapacity(msg) && numMessages != 0)
{
Expand Down
9 changes: 9 additions & 0 deletions src/overlay/test/OverlayTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,15 @@ TEST_CASE("loopback peer flow control activation", "[overlay][flowcontrol]")
conn.getAcceptor()->sendSendMore(0, 0);
dropReason = "invalid message SEND_MORE_EXTENDED";
}
SECTION("invalid message type")
{
// Manually construct a SEND_MORE message and send it
auto m = std::make_shared<StellarMessage>();
m->type(SEND_MORE);
m->sendMoreMessage().numMessages = 1;
conn.getAcceptor()->sendAuthenticatedMessageForTesting(m);
dropReason = "unexpected message type SEND_MORE";
}
testutil::crankSome(clock);
REQUIRE(!conn.getInitiator()->isConnectedForTesting());
REQUIRE(!conn.getAcceptor()->isConnectedForTesting());
Expand Down

0 comments on commit f1111b9

Please sign in to comment.