Whisper Library
 All Classes Functions Variables Typedefs Enumerations Friends
whisper_library::TcpPacketGenerator Class Reference

Simulates a HTTP conversation based on tcp. More...

Public Member Functions

 TcpPacketGenerator (unsigned short port, function< void(GenericPacket)> send)
 Constructor. More...
 
bool receivePacket (TcpPacket packet)
 Has to be called when a packet arrives. More...
 
void sendConnect ()
 Sends a connect request (syn=1). More...
 
TcpPacket nextPacket ()
 Returns a valid tcp packet. More...
 
unsigned int status ()
 Returns the status code of the current connection state.
 
void setSend (function< void(GenericPacket)> send)
 

Static Public Attributes

static const unsigned int NO_CONNECTION = 0
 No connection established.
 
static const unsigned int RECEIVED_SYN = 1
 Connection request received by peer.
 
static const unsigned int ESTABLISHED = 2
 Handshake successful and connection established.
 

Private Member Functions

void send (TcpPacket packet)
 
void sendConnectResponse ()
 Acknowledges a connect request (syn=1, ack=1)
 
void sendAcknowledgeResponse ()
 Responses to a connect request acknowledgement (ack=1)
 
TcpPacket createPacket (bool syn, bool ack, std::string data)
 Creates a tcp packet with flags and data. More...
 

Private Attributes

unsigned short m_port
 source/destination port used for communication
 
unsigned long m_next_sequence
 sequence number used for sending of the next packet
 
unsigned long m_base_sequence
 highest sequence number that was acknowledge by the receiver
 
unsigned long m_next_peer_sequence
 next expected sequence number by peer
 
function< void(GenericPacket)> m_send
 pointer to a function that is used for sending packets over the network
 
unsigned int m_state
 stores the internal connection state code (see constants)
 
unsigned int m_timeout
 timeout in milliseconds used for resending of packets (not used yet)
 
bool m_server
 true if you are the server after a successful handshake
 

Detailed Description

Simulates a HTTP conversation based on tcp.

Creates valid tcp packets by increasing the sequence number and acknowledging incoming packets. Packet resending or re-ordering of incoming packets is not implemented.

Initiate a handshake by calling 'sendConnect'. If a connect request is received, a handshake is initiated as well.

Constructor & Destructor Documentation

whisper_library::TcpPacketGenerator::TcpPacketGenerator ( unsigned short  port,
function< void(GenericPacket)>  send 
)

Constructor.

Sends a connect request to peer.

Parameters
portSource and destination port used for creating the packets
sendPointer to a function to send packets over the network

Member Function Documentation

TcpPacket whisper_library::TcpPacketGenerator::createPacket ( bool  syn,
bool  ack,
std::string  data 
)
private

Creates a tcp packet with flags and data.

Parameters
synSets the synchronisation flag if true
ackSets the acknowledgement flag and number if true
datadata of the returned packet
Returns
valid tcp packet
TcpPacket whisper_library::TcpPacketGenerator::nextPacket ( )

Returns a valid tcp packet.

Creates a tcp data packet using m_next_sequence. The content is a http get request if you are sender or an http 404 response if you are server.

Returns
valid tcp data packet
bool whisper_library::TcpPacketGenerator::receivePacket ( TcpPacket  packet)

Has to be called when a packet arrives.

Interprets an incoming packet. Responds to connect requests and connect acknowledges. Data packets are forwarded to a covert channel using m_forward, afterwards an acknowledge is send.

Parameters
packetTcp packet that was received
void whisper_library::TcpPacketGenerator::sendConnect ( )

Sends a connect request (syn=1).

Use this at the start of a conversation to initiate a handshake