Skip to content

Commit

Permalink
Merge pull request #3540 from marta-lokhova/peer_version_checks
Browse files Browse the repository at this point in the history
Drop peers that do not respect pull mode settings

Reviewed-by: MonsieurNicolas
  • Loading branch information
latobarita authored Sep 19, 2022
2 parents 585c8e9 + 97c00e1 commit f49b173
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/overlay/Peer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,8 @@ Peer::recvMessage(StellarMessage const& stellarMsg)

char const* cat = nullptr;
Scheduler::ActionType type = Scheduler::ActionType::NORMAL_ACTION;
switch (stellarMsg.type())
auto msgType = stellarMsg.type();
switch (msgType)
{
// group messages used during handshake, process those synchronously
case HELLO:
Expand Down Expand Up @@ -877,9 +878,23 @@ Peer::recvMessage(StellarMessage const& stellarMsg)

// high volume flooding
case TRANSACTION:
case FLOOD_ADVERT:
case FLOOD_DEMAND:
{
if (!mPullModeEnabled &&
(msgType == FLOOD_ADVERT || msgType == FLOOD_DEMAND))
{
drop(fmt::format("Peer sent {}, but pull mode is disabled",
xdr::xdr_traits<MessageType>::enum_name(msgType)),
Peer::DropDirection::WE_DROPPED_REMOTE,
Peer::DropMode::IGNORE_WRITE_QUEUE);
return;
}

cat = "TX";
type = Scheduler::ActionType::DROPPABLE_ACTION;
break;
}

// consensus, inbound
case GET_TX_SET:
Expand Down
23 changes: 23 additions & 0 deletions src/overlay/test/OverlayTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2125,6 +2125,29 @@ TEST_CASE("pull mode enable only if both request", "[overlay][pullmode]")
REQUIRE(conn->getAcceptor()->isAuthenticated());
REQUIRE(conn->getInitiator()->isPullModeEnabled() == false);
REQUIRE(conn->getAcceptor()->isPullModeEnabled() == false);

SECTION("peer does not follow the protocol")
{
StellarMessage adv, emptyMsg;
adv.type(FLOOD_ADVERT);
adv.floodAdvert().txHashes.push_back(xdrSha256(emptyMsg));
conn->getInitiator()->sendMessage(
std::make_shared<StellarMessage>(adv));
testutil::crankSome(clock);

if (node1 && node2)
{
REQUIRE(conn->getInitiator()->isAuthenticated());
REQUIRE(conn->getAcceptor()->isAuthenticated());
}
else
{
REQUIRE(!conn->getInitiator()->isConnected());
REQUIRE(!conn->getAcceptor()->isConnected());
REQUIRE(conn->getAcceptor()->getDropReason() ==
"Peer sent FLOOD_ADVERT, but pull mode is disabled");
}
}
};
SECTION("acceptor disabled pull mode")
{
Expand Down

0 comments on commit f49b173

Please sign in to comment.