30 #ifndef TINS_TCP_IP_STREAM_H 31 #define TINS_TCP_IP_STREAM_H 33 #include <tins/config.h> 35 #ifdef TINS_HAVE_TCPIP 43 #include <tins/macros.h> 44 #include <tins/hw_address.h> 45 #include <tins/config.h> 46 #include <tins/tcp_ip/flow.h> 47 #ifdef TINS_HAVE_TCP_STREAM_CUSTOM_DATA 48 #include <boost/any.hpp> 73 class TINS_API Stream {
78 typedef Flow::payload_type payload_type;
83 typedef std::chrono::microseconds timestamp_type;
88 typedef std::function<void(Stream&)> stream_callback_type;
98 typedef std::function<void(Stream&,
100 const payload_type&)> stream_packet_callback_type;
105 typedef HWAddress<6> hwaddress_type;
114 Stream(PDU& initial_packet,
const timestamp_type& ts = timestamp_type());
125 void process_packet(PDU& packet,
const timestamp_type& ts);
135 void process_packet(PDU& packet);
145 const Flow& client_flow()
const;
155 const Flow& server_flow()
const;
163 bool is_finished()
const;
175 IPv4Address client_addr_v4()
const;
182 IPv6Address client_addr_v6()
const;
192 const hwaddress_type& client_hw_addr()
const;
202 const hwaddress_type& server_hw_addr()
const;
209 IPv4Address server_addr_v4()
const;
216 IPv6Address server_addr_v6()
const;
221 uint16_t client_port()
const;
226 uint16_t server_port()
const;
231 const payload_type& client_payload()
const;
236 payload_type& client_payload();
241 const payload_type& server_payload()
const;
246 payload_type& server_payload();
251 const timestamp_type& create_time()
const;
256 const timestamp_type& last_seen()
const;
263 void stream_closed_callback(
const stream_callback_type& callback);
271 void client_data_callback(
const stream_callback_type& callback);
279 void server_data_callback(
const stream_callback_type& callback);
288 void client_out_of_order_callback(
const stream_packet_callback_type& callback);
297 void server_out_of_order_callback(
const stream_packet_callback_type& callback);
305 void ignore_client_data();
313 void ignore_server_data();
321 void setup_flows_callbacks();
342 void auto_cleanup_payloads(
bool value);
350 void auto_cleanup_client_data(
bool value);
358 void auto_cleanup_server_data(
bool value);
365 void enable_ack_tracking();
370 bool ack_tracking_enabled()
const;
372 #ifdef TINS_HAVE_TCP_STREAM_CUSTOM_DATA 386 if (user_data_.empty()) {
389 return boost::any_cast<T&>(user_data_);
391 #endif // TINS_HAVE_TCP_STREAM_CUSTOM_DATA 396 bool is_partial_stream()
const;
417 void enable_recovery_mode(uint32_t recovery_window);
425 bool is_recovery_mode_enabled()
const;
427 static Flow extract_client_flow(
const PDU& packet);
428 static Flow extract_server_flow(
const PDU& packet);
430 void on_client_flow_data(
const Flow& flow);
431 void on_server_flow_data(
const Flow& flow);
432 void on_client_out_of_order(
const Flow& flow,
434 const payload_type& payload);
435 void on_server_out_of_order(
const Flow& flow,
437 const payload_type& payload);
438 static void client_recovery_mode_handler(Stream& stream, uint32_t sequence_number,
439 const payload_type& payload,
440 uint32_t recovery_sequence_number_end,
441 const stream_packet_callback_type& original_callback);
442 static void server_recovery_mode_handler(Stream& stream, uint32_t sequence_number,
443 const payload_type& payload,
444 uint32_t recovery_sequence_number_end,
445 const stream_packet_callback_type& original_callback);
446 static bool recovery_mode_handler(Flow& flow, uint32_t sequence_number,
447 uint32_t recovery_sequence_number_end);
451 stream_callback_type on_stream_closed_;
452 stream_callback_type on_client_data_callback_;
453 stream_callback_type on_server_data_callback_;
454 stream_packet_callback_type on_client_out_of_order_callback_;
455 stream_packet_callback_type on_server_out_of_order_callback_;
456 hwaddress_type client_hw_addr_;
457 hwaddress_type server_hw_addr_;
458 timestamp_type create_time_;
459 timestamp_type last_seen_;
460 bool auto_cleanup_client_;
461 bool auto_cleanup_server_;
462 bool is_partial_stream_;
463 unsigned directions_recovery_mode_enabled_;
465 #ifdef TINS_HAVE_TCP_STREAM_CUSTOM_DATA 466 boost::any user_data_;
467 #endif // TINS_HAVE_TCP_STREAM_CUSTOM_DATA 473 #endif // TINS_HAVE_TCPIP 475 #endif // TINS_TCP_IP_STREAM_H The Tins namespace.
Definition: address_range.h:38