Whisper Library
|
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 | |
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.
whisper_library::TcpPacketGenerator::TcpPacketGenerator | ( | unsigned short | port, |
function< void(GenericPacket)> | send | ||
) |
Constructor.
Sends a connect request to peer.
port | Source and destination port used for creating the packets |
send | Pointer to a function to send packets over the network |
|
private |
Creates a tcp packet with flags and data.
syn | Sets the synchronisation flag if true |
ack | Sets the acknowledgement flag and number if true |
data | data of the returned 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.
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.
packet | Tcp 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