-
Notifications
You must be signed in to change notification settings - Fork 51
/
Copy pathConversationReconstructor.h
66 lines (54 loc) · 1.64 KB
/
ConversationReconstructor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#pragma once
#include <map>
#include <queue>
#include "net.h"
#include "Packet.h"
#include "Conversation.h"
#include "Config.h"
#include "IntervalKeeper.h"
namespace FeatureExtractor {
using namespace std;
/**
* Engine for identification and reconstruction of conversations from IP datagrams/packets
*/
class ConversationReconstructor
{
typedef map<FiveTuple, Conversation*> ConversationMap;
ConversationMap conv_map;
// Queue of reconstructed conversations prepared to output
queue<Conversation *>output_queue;
// Timeout values & timeout check interval
Config timeouts;
IntervalKeeper timeout_interval;
/**
* Removes timed out reassembly buffers - "drops incomplete datagrams"
*/
void check_timeouts(const Timestamp &now);
public:
ConversationReconstructor();
ConversationReconstructor(Config &timeouts);
~ConversationReconstructor();
/**
* Send next packet to conversation reconstruction engine
*/
void add_packet(const Packet *packet);
/**
* When no new packets, time can be reported to timeout old connections
*/
void report_time(const Timestamp &now);
/**
* Returns next reconstructed conversation from internal queue of finished conversation.
*
* Conversations are returned in order the ended (sorted by the timestamp
* of their last packet).
* If the queueis empty nullptr is returned.
* Caller must take care of deallocation of returned object.
*/
Conversation *get_next_conversation();
/**
* Places timeout on all active conversations
* Can be used to get unfinished conversations when no more traffic available
*/
void finish_all_conversations();
};
}