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

Represents an unidirectional TCP flow between 2 endpoints. More...

#include <flow.h>

Public Types

enum  State {
  UNKNOWN, SYN_SENT, ESTABLISHED, FIN_SENT,
  RST_SENT
}
 Enum that indicates the state of this flow. More...
 
typedef std::vector< uint8_t > payload_type
 
typedef std::map< uint32_t,
payload_type
buffered_payload_type
 
typedef std::function< void(Flow &)> data_available_callback_type
 
typedef std::function< void(Flow
&, uint32_t, const
payload_type &)> 
flow_packet_callback_type
 The type used to store the callback called when data is buffered. More...
 

Public Member Functions

 Flow (const IPv4Address &dst_address, uint16_t dst_port, uint32_t sequence_number)
 
 Flow (const IPv6Address &dst_address, uint16_t dst_port, uint32_t sequence_number)
 
void data_callback (const data_available_callback_type &callback)
 Sets the callback that will be executed when data is readable. More...
 
void out_of_order_callback (const flow_packet_callback_type &callback)
 Sets the callback that will be executed when out of order data arrives. More...
 
void process_packet (PDU &pdu)
 Processes a packet. More...
 
bool is_v6 () const
 
bool is_finished () const
 Indicates whether this flow is finished. More...
 
bool packet_belongs (const PDU &packet) const
 Indicates whether a packet belongs to this flow. More...
 
IPv4Address dst_addr_v4 () const
 Retrieves the IPv4 destination address. More...
 
IPv6Address dst_addr_v6 () const
 Retrieves the IPv6 destination address. More...
 
uint16_t dport () const
 
const payload_typepayload () const
 
payload_typepayload ()
 
State state () const
 
uint32_t sequence_number () const
 
const buffered_payload_typebuffered_payload () const
 
buffered_payload_typebuffered_payload ()
 
uint32_t total_buffered_bytes () const
 
void state (State new_state)
 
void ignore_data_packets ()
 Sets whether this flow should ignore data packets. More...
 
int mss () const
 Returns the MSS for this Flow. More...
 
bool sack_permitted () const
 Indicates whether this Flow supports selective acknowledgements.
 
void enable_ack_tracking ()
 Enables tracking of ACK numbers. More...
 
bool ack_tracking_enabled () const
 Indicates whether ACK number tracking is enabled.
 
const AckTrackerack_tracker () const
 
AckTrackerack_tracker ()
 

Detailed Description

Represents an unidirectional TCP flow between 2 endpoints.

This class will keep the state for all the traffic sent by one of the peers in a TCP connection. This contains the sequence number, payload ready to be read and buffered payload, along with some other properties of the flow.

A TCP stream (see class Stream) is made out of 2 Flows, so you should probably have a look at that class first.

You shouldn't normally need to interact with this class. Stream already provides proxys to most of its Flow's attributes.

Member Typedef Documentation

The type used to store the buffered payload

The type used to store the callback called when new data is available

typedef std::function<void(Flow&, uint32_t, const payload_type&)> Tins::TCPIP::Flow::flow_packet_callback_type

The type used to store the callback called when data is buffered.

The arguments are the flow, the sequence number and payload that will be buffered.

typedef std::vector<uint8_t> Tins::TCPIP::Flow::payload_type

The type used to store the payload

Member Enumeration Documentation

Enum that indicates the state of this flow.

Note that although similar, this is not mapped to a TCP state-machine state. This is mostly used internally to know which packets the flow is expecting and to know when it's done sending data.

Constructor & Destructor Documentation

Tins::TCPIP::Flow::Flow ( const IPv4Address dst_address,
uint16_t  dst_port,
uint32_t  sequence_number 
)

Construct a Flow from an IPv4 address

Parameters
dst_addressThis flow's destination address
dst_portThis flow's destination port
sequence_numberThe initial sequence number to be used
Tins::TCPIP::Flow::Flow ( const IPv6Address dst_address,
uint16_t  dst_port,
uint32_t  sequence_number 
)

Construct a Flow from an IPv6 address

Parameters
dst_addressThis flow's destination address
dst_portThis flow's destination port
sequence_numberThe initial sequence number to be used

Member Function Documentation

const AckTracker& Tins::TCPIP::Flow::ack_tracker ( ) const

Retrieves the ACK tracker for this Flow (const)

AckTracker& Tins::TCPIP::Flow::ack_tracker ( )

Retrieves the ACK tracker for this Flow

const Flow::buffered_payload_type & Tins::TCPIP::Flow::buffered_payload ( ) const

Retrieves this flow's buffered payload (const)

Flow::buffered_payload_type & Tins::TCPIP::Flow::buffered_payload ( )

Retrieves this flow's buffered payload

void Tins::TCPIP::Flow::data_callback ( const data_available_callback_type callback)

Sets the callback that will be executed when data is readable.

Whenever this flow has readable data, this callback will be executed. By readable, this means that there's non-out-of-order data captured.

Parameters
callbackThe callback to be executed
uint16_t Tins::TCPIP::Flow::dport ( ) const

Retrieves this flow's destination port

IPv4Address Tins::TCPIP::Flow::dst_addr_v4 ( ) const

Retrieves the IPv4 destination address.

Note that it's only safe to execute this method if is_v6() == false

IPv6Address Tins::TCPIP::Flow::dst_addr_v6 ( ) const

Retrieves the IPv6 destination address.

Note that it's only safe to execute this method if is_v6() == true

void Tins::TCPIP::Flow::enable_ack_tracking ( )

Enables tracking of ACK numbers.

This requires having the boost.icl library. If the library is not installed or ACK tracking was disabled when compiling the library, then this method will throw an exception.

void Tins::TCPIP::Flow::ignore_data_packets ( )

Sets whether this flow should ignore data packets.

If the data packets are ignored then the flow will just be followed to keep track of its state.

bool Tins::TCPIP::Flow::is_finished ( ) const

Indicates whether this flow is finished.

A finished is considered to be finished if either it sent a packet with the FIN or RST flags on.

bool Tins::TCPIP::Flow::is_v6 ( ) const

Indicates whether this flow uses IPv6 addresses

int Tins::TCPIP::Flow::mss ( ) const

Returns the MSS for this Flow.

If the MSS option wasn't provided by the peer, -1 is returned

void Tins::TCPIP::Flow::out_of_order_callback ( const flow_packet_callback_type callback)

Sets the callback that will be executed when out of order data arrives.

Whenever this flow receives out-of-order data, this callback will be executed.

Parameters
callbackThe callback to be executed
bool Tins::TCPIP::Flow::packet_belongs ( const PDU packet) const

Indicates whether a packet belongs to this flow.

Since Flow represents a unidirectional stream, this will only check the destination endpoint and not the source one.

Parameters
packetThe packet to be checked
const Flow::payload_type & Tins::TCPIP::Flow::payload ( ) const

Retrieves this flow's payload (const)

Flow::payload_type & Tins::TCPIP::Flow::payload ( )

Retrieves this flow's destination port

void Tins::TCPIP::Flow::process_packet ( PDU pdu)

Processes a packet.

If this packet contains data and starts or overlaps with the current sequence number, then the data will be appended to this flow's payload and the data_callback will be executed.

If this packet contains out-of-order data, it will be buffered and the buffering_callback will be executed.

Parameters
pduThe packet to be processed
See Also
Flow::data_callback
Flow::buffering_callback
uint32_t Tins::TCPIP::Flow::sequence_number ( ) const

Retrieves this flow's sequence number

Flow::State Tins::TCPIP::Flow::state ( ) const

Retrieves this flow's state

void Tins::TCPIP::Flow::state ( State  new_state)

Sets the state of this flow

Parameters
new_stateThe new state of this flow
uint32_t Tins::TCPIP::Flow::total_buffered_bytes ( ) const

Retrieves this flow's total buffered bytes


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