mirror of
https://github.com/mfontanini/libtins
synced 2026-01-23 02:35:57 +01:00
Add callbacks for stream termination events
This commit is contained in:
@@ -106,7 +106,7 @@ public:
|
||||
*/
|
||||
typedef std::function<void(Flow&,
|
||||
uint32_t,
|
||||
const payload_type&)> out_of_order_callback_type;
|
||||
const payload_type&)> flow_packet_callback_type;
|
||||
|
||||
/**
|
||||
* Construct a Flow from an IPv4 address
|
||||
@@ -146,7 +146,7 @@ public:
|
||||
*
|
||||
* \param callback The callback to be executed
|
||||
*/
|
||||
void out_of_order_callback(const out_of_order_callback_type& callback);
|
||||
void out_of_order_callback(const flow_packet_callback_type& callback);
|
||||
|
||||
/**
|
||||
* \brief Processes a packet.
|
||||
@@ -188,54 +188,59 @@ public:
|
||||
bool packet_belongs(const PDU& packet) const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the IPv4 destination address
|
||||
* \brief Retrieves the IPv4 destination address
|
||||
*
|
||||
* Note that it's only safe to execute this method if is_v6() == false
|
||||
*/
|
||||
IPv4Address dst_addr_v4() const;
|
||||
|
||||
/**
|
||||
* \brief Getter for the IPv6 destination address
|
||||
* \brief Retrieves the IPv6 destination address
|
||||
*
|
||||
* Note that it's only safe to execute this method if is_v6() == true
|
||||
*/
|
||||
IPv6Address dst_addr_v6() const;
|
||||
|
||||
/**
|
||||
* Getter for this flow's destination port
|
||||
* Retrieves this flow's destination port
|
||||
*/
|
||||
uint16_t dport() const;
|
||||
|
||||
/**
|
||||
* Getter for this flow's payload (const)
|
||||
* Retrieves this flow's payload (const)
|
||||
*/
|
||||
const payload_type& payload() const;
|
||||
|
||||
/**
|
||||
* Getter for this flow's destination port
|
||||
* Retrieves this flow's destination port
|
||||
*/
|
||||
payload_type& payload();
|
||||
|
||||
/**
|
||||
* Getter for this flow's state
|
||||
* Retrieves this flow's state
|
||||
*/
|
||||
State state() const;
|
||||
|
||||
/**
|
||||
* Getter for this flow's sequence number
|
||||
* Retrieves this flow's sequence number
|
||||
*/
|
||||
uint32_t sequence_number() const;
|
||||
|
||||
/**
|
||||
* Getter for this flow's buffered payload (const)
|
||||
* Retrieves this flow's buffered payload (const)
|
||||
*/
|
||||
const buffered_payload_type& buffered_payload() const;
|
||||
|
||||
/**
|
||||
* Getter for this flow's buffered payload
|
||||
* Retrieves this flow's buffered payload
|
||||
*/
|
||||
buffered_payload_type& buffered_payload();
|
||||
|
||||
/**
|
||||
* Retrieves this flow's total buffered bytes
|
||||
*/
|
||||
uint32_t total_buffered_bytes() const;
|
||||
|
||||
/**
|
||||
* Sets the state of this flow
|
||||
*
|
||||
@@ -277,14 +282,16 @@ private:
|
||||
void store_payload(uint32_t seq, payload_type payload);
|
||||
buffered_payload_type::iterator erase_iterator(buffered_payload_type::iterator iter);
|
||||
void update_state(const TCP& tcp);
|
||||
void initialize();
|
||||
|
||||
payload_type payload_;
|
||||
buffered_payload_type buffered_payload_;
|
||||
uint32_t seq_number_;
|
||||
uint32_t total_buffered_bytes_;
|
||||
std::array<uint8_t, 16> dest_address_;
|
||||
uint16_t dest_port_;
|
||||
data_available_callback_type on_data_callback_;
|
||||
out_of_order_callback_type on_out_of_order_callback_;
|
||||
flow_packet_callback_type on_out_of_order_callback_;
|
||||
State state_;
|
||||
int mss_;
|
||||
flags flags_;
|
||||
|
||||
@@ -85,13 +85,13 @@ public:
|
||||
typedef std::function<void(Stream&)> stream_callback_type;
|
||||
|
||||
/**
|
||||
* The type used for callbacks
|
||||
* The type used for packet-triggered callbacks
|
||||
*
|
||||
* /sa Flow::buffering_callback
|
||||
*/
|
||||
typedef std::function<void(Stream&,
|
||||
uint32_t,
|
||||
const payload_type&)> out_of_order_callback_type;
|
||||
const payload_type&)> stream_packet_callback_type;
|
||||
|
||||
/**
|
||||
* The type used to store hardware addresses
|
||||
@@ -279,7 +279,7 @@ public:
|
||||
* \sa Flow::buffering_callback
|
||||
* \param callback The callback to be set
|
||||
*/
|
||||
void client_out_of_order_callback(const out_of_order_callback_type& callback);
|
||||
void client_out_of_order_callback(const stream_packet_callback_type& callback);
|
||||
|
||||
/**
|
||||
* \brief Sets the callback to be executed when there's new buffered
|
||||
@@ -288,7 +288,7 @@ public:
|
||||
* \sa Flow::buffering_callback
|
||||
* \param callback The callback to be set
|
||||
*/
|
||||
void server_out_of_order_callback(const out_of_order_callback_type& callback);
|
||||
void server_out_of_order_callback(const stream_packet_callback_type& callback);
|
||||
|
||||
/**
|
||||
* \brief Indicates that the data packets sent by the client should be
|
||||
@@ -352,8 +352,8 @@ private:
|
||||
stream_callback_type on_stream_closed_;
|
||||
stream_callback_type on_client_data_callback_;
|
||||
stream_callback_type on_server_data_callback_;
|
||||
out_of_order_callback_type on_client_out_of_order_callback_;
|
||||
out_of_order_callback_type on_server_out_of_order_callback_;
|
||||
stream_packet_callback_type on_client_out_of_order_callback_;
|
||||
stream_packet_callback_type on_server_out_of_order_callback_;
|
||||
hwaddress_type client_hw_addr_;
|
||||
hwaddress_type server_hw_addr_;
|
||||
timestamp_type create_time_;
|
||||
|
||||
@@ -79,6 +79,21 @@ public:
|
||||
*/
|
||||
typedef Stream::stream_callback_type stream_callback_type;
|
||||
|
||||
/**
|
||||
* Enum to indicate the reason why a stream was terminated
|
||||
*/
|
||||
enum TerminationReason {
|
||||
TIMEOUT, ///< The stream was terminated due to a timeout
|
||||
BUFFERED_DATA ///< The stream was terminated because it had too much buffered data
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief The type used for stream termination callbacks
|
||||
*
|
||||
* \sa StreamFollower::stream_termination_callback
|
||||
*/
|
||||
typedef std::function<void(Stream&, TerminationReason)> stream_termination_callback_type;
|
||||
|
||||
/**
|
||||
* Default constructor
|
||||
*/
|
||||
@@ -116,6 +131,19 @@ public:
|
||||
*/
|
||||
void new_stream_callback(const stream_callback_type& callback);
|
||||
|
||||
/**
|
||||
* \brief Sets the stream termination callback
|
||||
*
|
||||
* A stream is terminated when either:
|
||||
*
|
||||
* * It contains too much buffered data.
|
||||
* * No packets have been seen for some time interval.
|
||||
*
|
||||
* \param callback The callback to be executed on stream termination
|
||||
* \sa StreamFollower::stream_keep_alive
|
||||
*/
|
||||
void stream_termination_callback(const stream_termination_callback_type& callback);
|
||||
|
||||
/**
|
||||
* \brief Sets the maximum time a stream will be followed without capturing
|
||||
* packets that belong to it.
|
||||
@@ -135,8 +163,8 @@ public:
|
||||
* \param server_addr The server's address
|
||||
* \param server_addr The server's port
|
||||
*/
|
||||
Stream& find_stream(IPv4Address client_addr, uint16_t client_port,
|
||||
IPv4Address server_addr, uint16_t server_port);
|
||||
Stream& find_stream(const IPv4Address& client_addr, uint16_t client_port,
|
||||
const IPv4Address& server_addr, uint16_t server_port);
|
||||
|
||||
/**
|
||||
* Finds the stream identified by the provided arguments.
|
||||
@@ -146,14 +174,14 @@ public:
|
||||
* \param server_addr The server's address
|
||||
* \param server_addr The server's port
|
||||
*/
|
||||
Stream& find_stream(IPv6Address client_addr, uint16_t client_port,
|
||||
IPv6Address server_addr, uint16_t server_port);
|
||||
Stream& find_stream(const IPv6Address& client_addr, uint16_t client_port,
|
||||
const IPv6Address& server_addr, uint16_t server_port);
|
||||
private:
|
||||
typedef std::array<uint8_t, 16> address_type;
|
||||
typedef Stream::timestamp_type timestamp_type;
|
||||
|
||||
static const size_t DEFAULT_MAX_BUFFERED_CHUNKS;
|
||||
static const timestamp_type DEFAULT_CLEANUP_INTERVAL;
|
||||
static const uint32_t DEFAULT_MAX_BUFFERED_BYTES;
|
||||
static const timestamp_type DEFAULT_KEEP_ALIVE;
|
||||
|
||||
struct stream_id {
|
||||
@@ -181,7 +209,9 @@ private:
|
||||
|
||||
streams_type streams_;
|
||||
stream_callback_type on_new_connection_;
|
||||
stream_termination_callback_type on_stream_termination_;
|
||||
size_t max_buffered_chunks_;
|
||||
uint32_t max_buffered_bytes_;
|
||||
timestamp_type last_cleanup_;
|
||||
timestamp_type stream_keep_alive_;
|
||||
bool attach_to_flows_;
|
||||
|
||||
Reference in New Issue
Block a user