libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Types | Public Member Functions | List of all members
Tins::TCPIP::StreamFollower Class Reference

Represents a class that follows TCP and reassembles streams. More...

#include <stream_follower.h>

Public Types

enum  TerminationReason { TIMEOUT, BUFFERED_DATA, SACKED_SEGMENTS }
 
typedef
Stream::stream_callback_type 
stream_callback_type
 
typedef StreamIdentifier stream_id
 
typedef std::function< void(Stream
&, TerminationReason)> 
stream_termination_callback_type
 The type used for stream termination callbacks. More...
 

Public Member Functions

 StreamFollower ()
 
void process_packet (PDU &packet)
 Processes a packet. More...
 
void process_packet (Packet &packet)
 Processes a packet. More...
 
void new_stream_callback (const stream_callback_type &callback)
 Sets the callback to be executed when a new stream is captured. More...
 
void stream_termination_callback (const stream_termination_callback_type &callback)
 Sets the stream termination callback. More...
 
template<typename Rep , typename Period >
void stream_keep_alive (const std::chrono::duration< Rep, Period > &keep_alive)
 Sets the maximum time a stream will be followed without capturing packets that belong to it. More...
 
Streamfind_stream (const IPv4Address &client_addr, uint16_t client_port, const IPv4Address &server_addr, uint16_t server_port)
 
Streamfind_stream (const IPv6Address &client_addr, uint16_t client_port, const IPv6Address &server_addr, uint16_t server_port)
 

Detailed Description

Represents a class that follows TCP and reassembles streams.

This class processes packets and whenever it detects a new connection being open, it starts tracking it. This will follow all data sent by each peer and make it available to the user in a simple way.

In order to use this class, just create an instance and set the new stream callback to some function that you want:

void on_new_stream(TCPStream& stream) {
// Do something with it.
// This is the perfect time to set the stream's client/server
// write callbacks so you are notified whenever there's new
// data on the stream
}
// Create it
StreamFollower follower;
// Set the callback
follower.new_stream_callback(&on_new_stream);

Member Typedef Documentation

The type used for callbacks

The type used to identify streams

The type used for stream termination callbacks.

See Also
StreamFollower::stream_termination_callback

Member Enumeration Documentation

Enum to indicate the reason why a stream was terminated

Enumerator
TIMEOUT 

The stream was terminated due to a timeout.

BUFFERED_DATA 

The stream was terminated because it had too much buffered data.

SACKED_SEGMENTS 

The stream was terminated because it had too many SACKed segments.

Constructor & Destructor Documentation

Tins::TCPIP::StreamFollower::StreamFollower ( )

Default constructor

Member Function Documentation

Stream & Tins::TCPIP::StreamFollower::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.

Parameters
client_addrThe client's address
client_portThe client's port
server_addrThe server's address
server_addrThe server's port
Stream & Tins::TCPIP::StreamFollower::find_stream ( const IPv6Address client_addr,
uint16_t  client_port,
const IPv6Address server_addr,
uint16_t  server_port 
)

Finds the stream identified by the provided arguments.

Parameters
client_addrThe client's address
client_portThe client's port
server_addrThe server's address
server_addrThe server's port
void Tins::TCPIP::StreamFollower::new_stream_callback ( const stream_callback_type callback)

Sets the callback to be executed when a new stream is captured.

Whenever a new stream is captured, the provided callback will be executed.

Parameters
callbackThe callback to be set
void Tins::TCPIP::StreamFollower::process_packet ( PDU packet)

Processes a packet.

This will detect if this packet belongs to an existing stream and process it, or if it belongs to a new one, in which case it starts tracking it.

Parameters
packetThe packet to be processed
void Tins::TCPIP::StreamFollower::process_packet ( Packet packet)

Processes a packet.

This will detect if this packet belongs to an existing stream and process it, or if it belongs to a new one, in which case it starts tracking it.

Parameters
packetThe packet to be processed
template<typename Rep , typename Period >
void Tins::TCPIP::StreamFollower::stream_keep_alive ( const std::chrono::duration< Rep, Period > &  keep_alive)
inline

Sets the maximum time a stream will be followed without capturing packets that belong to it.

Parameters
keep_aliveThe maximum time to keep unseen streams
void Tins::TCPIP::StreamFollower::stream_termination_callback ( const stream_termination_callback_type callback)

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.
Parameters
callbackThe callback to be executed on stream termination
See Also
StreamFollower::stream_keep_alive

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