curl-fuzzer C++ reference
Loading...
Searching...
No Matches
proto_fuzzer::MqttMockServer Class Reference

Services curl's single-connection binary MQTT exchange. More...

#include <mqtt_mock_server.h>

Inheritance diagram for proto_fuzzer::MqttMockServer:
proto_fuzzer::MockServerBase proto_fuzzer::IncomingDataObserver proto_fuzzer::MqttsMockServer

Public Member Functions

 MqttMockServer (curl::fuzzer::proto::MqttProbeMode mode=curl::fuzzer::proto::MQTT_PROBE_DEFAULT)
 Begin without a borrowed protobuf or open socketpair.
 ~MqttMockServer () override
 Release the server-owned socketpair half after curl has returned its client descriptor.
void ObserveState () override
 Retain protocol outcomes in coverage and introspector builds.
const std::string & packet_transcript () const
const std::string & published_topic () const
const std::string & published_payload () const
std::size_t packet_count () const
std::size_t connect_count () const
std::size_t publish_count () const
std::size_t subscribe_count () const
std::size_t qos1_publish_count () const
std::size_t active_pollset_probe_count () const
 Report how many requested zero-timeout multi-poll probes ran during the most recent drive.
Public Member Functions inherited from proto_fuzzer::MockServerBase
virtual ~MockServerBase ()
 Out-of-line destructor so MockConnection can stay forward-declared in the base header (its complete type is only needed where unique_ptr is instantiated for destruction).
virtual void Install (CURL *easy)
 Install the common OPENSOCKETFUNCTION / OPENSOCKETDATA / SOCKOPTFUNCTION callbacks on 'easy'.
virtual void ConfigureRequestData (ScenarioRequestData *request_data)
 Bind protocol-specific work to the request-data callbacks after their per-scenario state has been constructed.
CURLcode DriveScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Run 'scenario' to completion on 'easy': allocate a multi, attach 'easy', delegate protocol-specific work to RunLoop, consume its completion message, and clean up.
virtual CURLcode DriveEasyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario, bool use_events=false)
 Run through the public easy entrypoint when a protocol mock can preload all peer work before curl takes control.
virtual ConnectOnlyRunStats DriveConnectOnlyScenario (CURL *easy, const curl::fuzzer::proto::Scenario &scenario)
 Establish a CONNECT_ONLY transport, then perform bounded direct I/O.
void SetMultiObserver (MultiObserver observer)
 Register an observer invoked with the live multi handle after 'easy' is attached and before the drive loop starts.
MockConnection * connection ()

Protected Member Functions

virtual std::unique_ptr< MockConnection > CreateConnection ()
 Create the default plaintext transport for the MQTT packet exchange.
curl_socket_t HandleOpenSocket (curlsocktype purpose=CURLSOCKTYPE_IPCXN, struct curl_sockaddr *address=nullptr) override
 Create the single MQTT socketpair and queue the scenario's first server bytes.
void RunLoop (CURLM *multi, CURL *easy, const curl::fuzzer::proto::Scenario &scenario) override
 Alternate curl transitions with immediate peer service until the transfer completes or deterministic idle/operation caps win.
void ObserveIncomingData (const unsigned char *data, std::size_t size) override
 Append decoded application bytes to the pending parser buffer.
Protected Member Functions inherited from proto_fuzzer::MockServerBase
 MockServerBase (MultiDrivePolicy drive_policy=MultiDrivePolicy::kPerform)
 Construct an empty base instance with a fixed multi-drive policy.
virtual void HandleDetachedMulti (CurlMultiPtr multi)
 Dispose of or retain the multi after its easy handle has been removed.
virtual SocketSetupDisposition GetSocketSetupDisposition (curl_socket_t curlfd, curlsocktype purpose) const
 Describe the socket returned by HandleOpenSocket without issuing native descriptor queries.
MultiSocketDriver * multi_socket_driver ()
 Expose the callback state installed for the current socket-action drive.
std::size_t additional_handle_cleanup_count () const
void ResumeResponseIfRequested (CURL *easy)
 Resume receive-side callback output at one bounded drive boundary when the dedicated API plan requested it.
void ApplyPendingBackpressure ()
 Apply the BackpressureConfig cached by DriveScenario to the new connection_.

Additional Inherited Members

Public Types inherited from proto_fuzzer::MockServerBase
using MultiObserver = std::function<void(CURLM*)>
 Callback type used to publish the driving multi handle to observers.
Static Protected Member Functions inherited from proto_fuzzer::MockServerBase
static int WaitOnMultiFdset (CURLM *multi, CURLMcode *rc)
 Wait on curl's fdset with a short timeout.
static void ProbeMultiPollset (CURLM *multi)
 Ask curl to construct and inspect its connection-filter pollset without waiting.
static bool MultiPollsetWantsWrite (CURLM *multi, curl_socket_t socket)
 Inspect one socket's current writable interest through curl's public multi fdset API.
static bool UsesTimedDrive (const curl::fuzzer::proto::Scenario &scenario)
 Treat a non-default BackpressureConfig as an explicit request for the slower, timed drive policy.
Protected Attributes inherited from proto_fuzzer::MockServerBase
std::unique_ptr< MockConnection > connection_
 The per-scenario MockConnection, lazily created by HandleOpenSocket().
int pending_recv_buf_bytes_
 Cached SO_RCVBUF/SO_SNDBUF setting in bytes.
std::size_t pending_drain_limit_
 Cached per-call DrainIncoming byte budget.
MultiSocketDriver * multi_socket_driver_
 Non-owning pointer into DriveScenario's stack.
std::size_t additional_handle_cleanup_count_
 Number of application-created handles, excluding the caller's parent, successfully removed from the current multi and cleaned up.
bool resume_response_
 True only for an API-plan multi drive with its one-shot write callback.
MultiObserver multi_observer_
 Observer receiving the live multi handle at the start of a drive.
Static Protected Attributes inherited from proto_fuzzer::MockServerBase
static constexpr int kMaxDriveIterations = 512
 Hard operation budget for one scenario.
static constexpr int kMaxIdleIterations = 8
 Consecutive no-progress budget for ordinary scenarios.
static constexpr int kMaxTimedIdleIterations = 256
 Explicit backpressure scenarios get a larger idle budget and may use the short timed wait above.

Detailed Description

Services curl's single-connection binary MQTT exchange.

MQTT has no line grammar: every packet starts with a one-byte fixed header (message type plus flags) followed by a 1-4 byte base-128 remaining-length field. This peer therefore treats Scenario.connection as opaque server bytes rather than a command/reply script:

  • initial_response is queued as soon as curl opens the socket and is expected to contain a CONNACK (20 02 00 00).
  • The peer reads and reassembles complete client packets from the same socket, using the fixed header and remaining length to find boundaries.
  • CONNECT needs no synthetic reply because the CONNACK was preloaded.
  • SUBSCRIBE receives a synthesized SUBACK that echoes its packet id. After that acknowledgement the peer releases the bounded on_readable chunks one at a time as server-initiated packets (for example PUBLISH followed by a server DISCONNECT).
  • PUBLISH is recorded as the fuzz-controlled topic and payload. A QoS 1 PUBLISH receives the matching PUBACK, even though the current curl revision always emits QoS 0.
  • PINGREQ receives PINGRESP. A client DISCONNECT only ends the packet stream; the peer still half-closes during cleanup.

All work remains in-process and non-waiting, so malformed packet headers terminate by the operation budget or a half-close instead of a timeout.

Subclasses replace the transport through CreateConnection(). The implicit- TLS MQTTS peer uses that hook to wrap the identical packet exchange in a verified OpenSSL connection; incoming bytes are observed after transport decoding so the parser does not depend on the carrier.

Definition at line 57 of file mqtt_mock_server.h.

Constructor & Destructor Documentation

◆ MqttMockServer()

proto_fuzzer::MqttMockServer::MqttMockServer ( curl::fuzzer::proto::MqttProbeMode mode = curl::fuzzer::proto::MQTT_PROBE_DEFAULT)
explicit

Begin without a borrowed protobuf or open socketpair.

RunLoop borrows a Scenario only for the synchronous DriveScenario call in which socket callbacks can run.

Parameters
modeClosed harness-owned probe shape to apply before the transfer.

Definition at line 48 of file mqtt_mock_server.cc.

◆ ~MqttMockServer()

proto_fuzzer::MqttMockServer::~MqttMockServer ( )
overridedefault

Release the server-owned socketpair half after curl has returned its client descriptor.

The out-of-line destructor keeps MockConnection's complete type local to this translation unit.

Member Function Documentation

◆ active_pollset_probe_count()

std::size_t proto_fuzzer::MqttMockServer::active_pollset_probe_count ( ) const

Report how many requested zero-timeout multi-poll probes ran during the most recent drive.

RunLoop increments this only after a successful perform turn while curl still owns an active transfer and the MQTT socket is open.

Returns
Number of active, connected pollset probes in the previous drive.

Definition at line 96 of file mqtt_mock_server.cc.

◆ connect_count()

std::size_t proto_fuzzer::MqttMockServer::connect_count ( ) const
Returns
Number of CONNECT packets observed.

Definition at line 81 of file mqtt_mock_server.cc.

◆ CreateConnection()

std::unique_ptr< MockConnection > proto_fuzzer::MqttMockServer::CreateConnection ( )
protectedvirtual

Create the default plaintext transport for the MQTT packet exchange.

The MQTTS subclass overrides this factory while retaining the binary parser.

Returns
A new socketpair-backed connection.

Reimplemented in proto_fuzzer::MqttsMockServer.

Definition at line 143 of file mqtt_mock_server.cc.

◆ HandleOpenSocket()

curl_socket_t proto_fuzzer::MqttMockServer::HandleOpenSocket ( curlsocktype purpose = CURLSOCKTYPE_IPCXN,
struct curl_sockaddr * address = nullptr )
overrideprotectedvirtual

Create the single MQTT socketpair and queue the scenario's first server bytes.

curl sends CONNECT immediately, so a normal scenario preloads the CONNACK here; an empty or malformed greeting remains a reachable error path.

Parameters
purposeSocket role requested by curl.
addressUnused stream destination metadata required by the callback signature.
Returns
Client descriptor for the MQTT channel, or CURL_SOCKET_BAD.

Implements proto_fuzzer::MockServerBase.

Definition at line 164 of file mqtt_mock_server.cc.

◆ ObserveIncomingData()

void proto_fuzzer::MqttMockServer::ObserveIncomingData ( const unsigned char * data,
std::size_t size )
overrideprotectedvirtual

Append decoded application bytes to the pending parser buffer.

The outer service loop drains this buffer after every transport call, so it remains bounded by the scenario's packet budget.

Parameters
dataFirst decoded byte.
sizeNumber of bytes available at data.

Implements proto_fuzzer::IncomingDataObserver.

Definition at line 150 of file mqtt_mock_server.cc.

◆ packet_count()

std::size_t proto_fuzzer::MqttMockServer::packet_count ( ) const
Returns
Number of complete client packets observed in the most recent drive.

Definition at line 78 of file mqtt_mock_server.cc.

◆ packet_transcript()

const std::string & proto_fuzzer::MqttMockServer::packet_transcript ( ) const
Returns
A prefix of complete client packets from the most recent drive.

Definition at line 69 of file mqtt_mock_server.cc.

◆ publish_count()

std::size_t proto_fuzzer::MqttMockServer::publish_count ( ) const
Returns
Number of PUBLISH packets observed.

Definition at line 84 of file mqtt_mock_server.cc.

◆ published_payload()

const std::string & proto_fuzzer::MqttMockServer::published_payload ( ) const
Returns
A prefix of the first PUBLISH packet's application payload.

Definition at line 75 of file mqtt_mock_server.cc.

◆ published_topic()

const std::string & proto_fuzzer::MqttMockServer::published_topic ( ) const
Returns
A prefix of the first PUBLISH packet's topic.

Definition at line 72 of file mqtt_mock_server.cc.

◆ qos1_publish_count()

std::size_t proto_fuzzer::MqttMockServer::qos1_publish_count ( ) const
Returns
Number of PUBLISH packets that requested QoS 1.

Definition at line 90 of file mqtt_mock_server.cc.

◆ RunLoop()

void proto_fuzzer::MqttMockServer::RunLoop ( CURLM * multi,
CURL * easy,
const curl::fuzzer::proto::Scenario & scenario )
overrideprotectedvirtual

Alternate curl transitions with immediate peer service until the transfer completes or deterministic idle/operation caps win.

No select(), poll(), or sleep is needed: the CONNACK is preloaded, synthesized acknowledgements are written from the same thread, and scripted server packets are released one per turn so curl consumes the preceding acknowledgement first.

Parameters
multiMulti handle containing easy.
easyEasy handle already installed on this mock.
scenarioConnection script to borrow.

Implements proto_fuzzer::MockServerBase.

Definition at line 463 of file mqtt_mock_server.cc.

◆ subscribe_count()

std::size_t proto_fuzzer::MqttMockServer::subscribe_count ( ) const
Returns
Number of SUBSCRIBE packets observed.

Definition at line 87 of file mqtt_mock_server.cc.


The documentation for this class was generated from the following files: