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

Set classId & methodId for Close method #108

Merged
merged 10 commits into from
Dec 11, 2024
13 changes: 9 additions & 4 deletions libamqpprox/amqpprox_connector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,12 @@ void Connector::synthesizeCloseError(bool sendToIngressSide)

void Connector::synthesizeCustomCloseError(bool sendToIngressSide,
uint16_t code,
std::string_view text)
std::string_view text,
uint16_t classId,
uint16_t methodId)
{
synthesizeMessage(d_close, sendToIngressSide, code, text);
synthesizeMessage(
d_close, sendToIngressSide, code, text, classId, methodId);
}

Buffer Connector::outBuffer()
Expand Down Expand Up @@ -416,10 +419,12 @@ void Connector::sendResponse(const T &response, bool sendToIngressSide)
void Connector::synthesizeMessage(methods::Close &replyMethod,
bool sendToIngressSide,
uint64_t code,
std::string_view text)
std::string_view text,
uint16_t classId,
uint16_t methodId)
{
d_buffer = Buffer(); // forget inbound buffer
replyMethod.setReply(code, std::string(text));
replyMethod.setReply(code, std::string(text), classId, methodId);
sendResponse(replyMethod, sendToIngressSide);
}

Expand Down
10 changes: 8 additions & 2 deletions libamqpprox/amqpprox_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,9 @@ class Connector {
inline void synthesizeMessage(methods::Close &replyMethod,
bool sendToIngressSide,
uint64_t code,
std::string_view text);
std::string_view text,
uint16_t classId = 0,
uint16_t methodId = 0);

public:
Connector(SessionState *sessionState,
Expand Down Expand Up @@ -167,10 +169,14 @@ class Connector {
* for communicating with server
* \param code custom error code
* \param text custom error text
* \param classId custom class id
* \param methodId custom method id
*/
void synthesizeCustomCloseError(bool sendToIngressSide,
uint16_t code,
std::string_view text);
std::string_view text,
uint16_t classId = 0,
uint16_t methodId = 0);

/**
* \brief Synthesize AMQP protocol header buffer, which will eventually be
Expand Down
4 changes: 2 additions & 2 deletions libamqpprox/amqpprox_dnsresolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ struct PairHash {
class DNSResolver {
using TcpEndpoint = boost::asio::ip::tcp::endpoint;
using CacheType = std::unordered_map<std::pair<std::string, std::string>,
std::vector<TcpEndpoint>,
PairHash>;
std::vector<TcpEndpoint>,
PairHash>;

public:
using OverrideFunction =
Expand Down
2 changes: 1 addition & 1 deletion libamqpprox/amqpprox_hostnamemapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace amqpprox {
*/
class HostnameMapper {
public:
virtual ~HostnameMapper(){};
virtual ~HostnameMapper() {};

/**
* \brief prime the cache of hostnames with a list of endpoints
Expand Down
10 changes: 2 additions & 8 deletions libamqpprox/amqpprox_maybesecuresocketadaptor.h
Original file line number Diff line number Diff line change
Expand Up @@ -131,15 +131,9 @@ class MaybeSecureSocketAdaptor
src.d_dataRateTimer->cancel();
}

~MaybeSecureSocketAdaptor()
{
d_dataRateTimer->cancel();
}
~MaybeSecureSocketAdaptor() { d_dataRateTimer->cancel(); }

boost::asio::ip::tcp::socket &socket()
{
return d_socket->next_layer();
}
boost::asio::ip::tcp::socket &socket() { return d_socket->next_layer(); }

void setSecure(bool secure)
{
Expand Down
16 changes: 15 additions & 1 deletion libamqpprox/amqpprox_methods_close.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,24 @@ class Close {

const uint16_t methodId() const { return d_methodId; }

inline void setReply(uint16_t code, const std::string &text)
inline void setReply(uint16_t code,
const std::string &text,
uint16_t classId = 0,
uint16_t methodId = 0)
{
d_replyCode = code;
d_replyString = text;

// Close may be due to internal conditions or due to an exception
// during handling a specific method. When a close is due to an
// exception, the class and method id of the method which caused the
// exception is provided.
if (classId) {
d_classId = classId;
}
if (methodId) {
d_methodId = methodId;
}
}

/**
Expand Down
4 changes: 3 additions & 1 deletion libamqpprox/amqpprox_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,7 +627,9 @@ void Session::disconnectUnauthClient(const FieldTable &clientProperties,
d_connector.synthesizeCustomCloseError(
true,
Reply::Codes::access_refused,
reason.substr(0, sendSize));
reason.substr(0, sendSize),
methods::StartOk::classType(),
methods::StartOk::methodType());
sendSyntheticData();
}
}
Expand Down
4 changes: 2 additions & 2 deletions tests/amqpprox_farmstore.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ TEST(FarmStore, GettingMissingFarm)
{
FarmStore farmStore;

EXPECT_THROW({ farmStore.getFarmByName("nosuchfarm"); },
std::runtime_error);
EXPECT_THROW(
{ farmStore.getFarmByName("nosuchfarm"); }, std::runtime_error);
}

TEST(FarmStore, AddTwice)
Expand Down
4 changes: 2 additions & 2 deletions tests/amqpprox_maybesecuresocketadaptor.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SocketInterface {
virtual size_t read_some(const boost::asio::mutable_buffers_1 &buffer,
boost::system::error_code &error) = 0;

virtual ~SocketInterface(){};
virtual ~SocketInterface() {};
};

class MockSocket : public SocketInterface {
Expand Down Expand Up @@ -76,7 +76,7 @@ class MockSocket : public SocketInterface {

class TimerInterface {
public:
virtual ~TimerInterface(){};
virtual ~TimerInterface() {};
virtual void cancel() = 0;

virtual size_t
Expand Down
4 changes: 3 additions & 1 deletion tests/amqpprox_session.t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,9 @@ TEST_F(SessionTest,
std::shared_ptr<methods::Close> closeMethodPtr =
std::make_shared<methods::Close>();
closeMethodPtr->setReply(Reply::Codes::access_refused,
"Unauthorized test client");
"Unauthorized test client",
methods::StartOk::classType(),
methods::StartOk::methodType());
testSetupClientOpenWithProxyClose(4, closeMethodPtr);

std::shared_ptr<MaybeSecureSocketAdaptor<>> clientSocket =
Expand Down
Loading