1 #ifndef HELLOBYEPROTO_CPP 2 #define HELLOBYEPROTO_CPP 23 template <
class Identifier,
class Packet>
25 this->serverCookie = rand() % 10;
28 template <
class Identifier,
class Packet>
39 char clientStr[] =
"CLIENT HELLO:";
40 if (memcmp(udp->
getPayload(), clientStr,
sizeof(clientStr) - 1) != 0) {
41 std::cout <<
"HelloByeServerHello::fun() clientStr didn't match" << std::endl;
42 funIface.
transition(HelloByeServer::Terminate);
49 reinterpret_cast<uint8_t *
>(udp->
getPayload())[
sizeof(clientStr) - 1];
50 this->clientCookie =
static_cast<int>(cookieChar) - 48;
54 std::stringstream sstream;
55 sstream <<
"SERVER HELLO:" << this->serverCookie << std::endl;
56 std::string serverHelloStr = sstream.str();
57 memcpy(udp->
getPayload(), serverHelloStr.c_str(), serverHelloStr.length());
63 uint32_t tmp = ipv4->
dstIP;
85 template <
class Identifier,
class Packet>
88 : clientCookie(in->clientCookie), serverCookie(in->serverCookie) {}
90 template <
class Identifier,
class Packet>
101 char clientStr[] =
"CLIENT BYE:";
102 if (memcmp(udp->
getPayload(), clientStr,
sizeof(clientStr) - 1) != 0) {
103 std::cout <<
"HelloByeServerBye::fun() clientStr didn't match" << std::endl;
110 reinterpret_cast<uint8_t *
>(udp->
getPayload())[
sizeof(clientStr) - 1];
111 int recvCookie =
static_cast<int>(cookieChar) - 48;
113 if (recvCookie != this->serverCookie) {
114 std::cout <<
"HelloByeServerBye::fun() Client sent over wrong cookie" << std::endl;
121 std::stringstream sstream;
122 sstream <<
"SERVER BYE:" << this->clientCookie << std::endl;
123 std::string serverByeStr = sstream.str();
124 memcpy(udp->
getPayload(), serverByeStr.c_str(), serverByeStr.length());
129 uint32_t tmp = ipv4->
dstIP;
151 template <
class Identifier,
class Packet>
153 uint32_t dstIp, uint16_t srcPort)
154 : dstIp(dstIp), srcPort(srcPort) {
155 this->clientCookie = rand() % 10;
158 template <
class Identifier,
class Packet>
164 memset(pkt->getData(), 0, pkt->getDataLen());
187 std::stringstream sstream;
188 sstream <<
"CLIENT HELLO:" << this->clientCookie << std::endl;
189 std::string clientHelloStr = sstream.str();
190 memcpy(udp->
getPayload(), clientHelloStr.c_str(), clientHelloStr.length());
192 ether->ethertype = htons(0x0800);
210 template <
class Identifier,
class Packet>
213 : clientCookie(in->clientCookie) {}
215 template <
class Identifier,
class Packet>
226 char serverStr[] =
"SERVER HELLO:";
227 if (memcmp(udp->
getPayload(), serverStr,
sizeof(serverStr) - 1) != 0) {
228 std::cout <<
"HelloByeClientBye::fun() serverStr didn't match" << std::endl;
235 reinterpret_cast<uint8_t *
>(udp->
getPayload())[
sizeof(serverStr) - 1];
236 this->serverCookie =
static_cast<int>(cookieChar) - 48;
240 std::stringstream sstream;
241 sstream <<
"CLIENT BYE:" << this->serverCookie << std::endl;
242 std::string clientByeStr = sstream.str();
246 memcpy(udp->
getPayload(), clientByeStr.c_str(), clientByeStr.length());
251 uint32_t tmp = ipv4->
dstIP;
273 template <
class Identifier,
class Packet>
276 : clientCookie(in->clientCookie), serverCookie(in->serverCookie) {}
278 template <
class Identifier,
class Packet>
289 char serverStr[] =
"SERVER BYE:";
290 if (memcmp(udp->
getPayload(), serverStr,
sizeof(serverStr) - 1) != 0) {
291 std::cout <<
"HelloByeClientRecvBye::fun() serverStr didn't match" << std::endl;
298 reinterpret_cast<uint8_t *
>(udp->
getPayload())[
sizeof(serverStr) - 1];
299 int recvCookie =
static_cast<int>(cookieChar) - 48;
301 if (recvCookie != this->clientCookie) {
302 std::cout <<
"HelloByeClientRecvBye::fun() Server sent over wrong cookie"
static constexpr StateID Terminate
Main interface for the needs of a state function.
HelloByeServerBye(const HelloByeServerHello< Identifier, Packet > *in)
HelloByeClientRecvBye(const HelloByeClientBye< Identifier, Packet > *in)
static constexpr StateID Bye
static HelloByeClientConfig * getInstance()
static constexpr StateID RecvBye
HelloByeClientHello(uint32_t dstIp, uint16_t srcPort)
PROD_INLINE void fun(typename SM::State &state, Packet *pkt, typename SM::FunIface &funIface)
void freePkt()
Free the packet after the batch is processed, do not send it.
PROD_INLINE void fun(typename SM::State &state, Packet *pkt, typename SM::FunIface &funIface)
PROD_INLINE void fun(typename SM::State &state, Packet *pkt, typename SM::FunIface &funIface)
PROD_INLINE void fun(typename SM::State &state, Packet *pkt, typename SM::FunIface &funIface)
PROD_INLINE void fun(typename SM::State &state, Packet *pkt, typename SM::FunIface &funIface)
static constexpr StateID Terminate
Represents one connection.
HelloByeClientBye(const HelloByeClientHello< Identifier, Packet > *in)
void transition(StateID newState)
Transition to another state.