Skip to content

Commit

Permalink
Disable checking of INVOCATION request IDs
Browse files Browse the repository at this point in the history
  • Loading branch information
ecorm committed May 26, 2023
1 parent 6b9d8e8 commit 7a2aa62
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
21 changes: 15 additions & 6 deletions cppwamp/include/cppwamp/internal/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -882,6 +882,11 @@ class ProcedureRegistry
WampErrc onProcedureInvocation(Invocation& inv,
const ProcedureRegistration& reg)
{
// Progressive calls not allowed on procedures not registered
// as streams.
if (inv.isProgress({}) || inv.resultsAreProgressive({}))
return WampErrc::optionNotAllowed;

auto requestId = inv.requestId();
auto registrationId = inv.registrationId();
auto emplaced = invocations_.emplace(requestId,
Expand All @@ -891,11 +896,6 @@ class ProcedureRegistry
if (!emplaced.second)
return WampErrc::protocolViolation;

// Progressive calls not allowed on procedures not registered
// as streams.
if (inv.isProgress({}) || inv.resultsAreProgressive({}))
return WampErrc::optionNotAllowed;

auto& invocationRec = emplaced.first->second;
invocationRec.closed = true;
postRpcRequest(reg.callSlot, inv, reg.registrationId);
Expand Down Expand Up @@ -1547,15 +1547,19 @@ class Client : public std::enable_shared_from_this<Client>, private PeerListener
auto reqId = inv.requestId();
auto regId = inv.registrationId();

// Crossbar uses the same INVOCATION request ID generator for
// all callee sessions.
// https://github.com/crossbario/crossbar/issues/2081
#ifdef CPPWAMP_STRICT_INVOCATION_ID_CHECKS
auto maxRequestId = inboundRequestIdWatermark_ + 1u;
if (reqId > maxRequestId)
{
return failProtocol("Router used non-sequential request ID "
"in INVOCATION message");
}

if (reqId == maxRequestId)
++inboundRequestIdWatermark_;
#endif

switch (registry_.onInvocation(std::move(inv)))
{
Expand Down Expand Up @@ -2337,7 +2341,10 @@ class Client : public std::enable_shared_from_this<Client>, private PeerListener
abandonPending(MiscErrc::abandoned);
readership_.clear();
registry_.clear();

#ifdef CPPWAMP_STRICT_INVOCATION_ID_CHECKS
inboundRequestIdWatermark_ = 0;
#endif
}

void sendUnsubscribe(SubscriptionId subId)
Expand Down Expand Up @@ -2474,7 +2481,9 @@ class Client : public std::enable_shared_from_this<Client>, private PeerListener
IncidentSlot incidentSlot_;
ChallengeSlot challengeSlot_;
Connecting::Ptr currentConnector_;
#ifdef CPPWAMP_STRICT_INVOCATION_ID_CHECKS
RequestId inboundRequestIdWatermark_ = 0;
#endif
bool isTerminating_ = false;

friend class ClientContext;
Expand Down
2 changes: 2 additions & 0 deletions test/clientprotocolerrors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ TEST_CASE( "WAMP protocol violation detection by client", "[WAMP][Advanced]" )
ioctx.restart();
}

#ifdef CPPWAMP_STRICT_INVOCATION_ID_CHECKS
{
INFO("Non-sequential INVOCATION request ID");

Expand Down Expand Up @@ -198,6 +199,7 @@ TEST_CASE( "WAMP protocol violation detection by client", "[WAMP][Advanced]" )
ioctx.run();
ioctx.restart();
}
#endif

{
INFO("Progressive invocation on RPC not registered as stream");
Expand Down

0 comments on commit 7a2aa62

Please sign in to comment.