]> git.seodisparate.com - UDPConnection/commitdiff
Some fixes
authorStephen Seo <seo.disparate@gmail.com>
Wed, 28 Aug 2019 06:54:18 +0000 (15:54 +0900)
committerStephen Seo <seo.disparate@gmail.com>
Wed, 28 Aug 2019 06:54:18 +0000 (15:54 +0900)
Fix id of sent packet stored in network byte order instead of native
order.

Fix failing to send packet not stopping storing sent packet data.

cpp_impl/src/UDPC_Defines.hpp
cpp_impl/src/UDPConnection.cpp

index 0325b1ec500c726bbcb99dc1ab32d427f8b5ab1a..40e53e651eb141f489146ffc239caa31d64970c6 100644 (file)
@@ -145,9 +145,9 @@ struct Context {
     struct sockaddr_in socketInfo;
 
     std::chrono::steady_clock::time_point lastUpdated;
-    // ipv4 address and port to ConnectionData
+    // ipv4 address and port (as ConnectionIdentifier) to ConnectionData
     std::unordered_map<ConnectionIdentifier, ConnectionData, ConnectionIdentifier::Hasher> conMap;
-    // id to ipv4 address
+    // id to ipv4 address and port (as ConnectionIdentifier)
     std::unordered_map<uint32_t, ConnectionIdentifier> idMap;
 
     std::default_random_engine rng_engine;
index a082498fc6c822a13984660be8a87c46495e886e..15104a839028bc054f4fc84d18d1acd8809ffef6 100644 (file)
@@ -78,8 +78,11 @@ UDPC::ConnectionData::ConnectionData()
 void UDPC::ConnectionData::cleanupSentPkts() {
     uint32_t id;
     while(sentPkts.size() > UDPC_SENT_PKTS_MAX_SIZE) {
-        id = ntohl(*((uint32_t*)(sentPkts.front().data + 8)));
-        sentInfoMap.erase(id);
+        id = *((uint32_t*)(sentPkts.front().data + 8));
+        auto iter = sentInfoMap.find(id);
+        assert(iter != sentInfoMap.end()
+                && "Sent packet must have correspoding entry in sentInfoMap");
+        sentInfoMap.erase(iter);
         sentPkts.pop_front();
     }
 }
@@ -367,6 +370,7 @@ void UDPC_update(void *ctx) {
                     sizeof(struct sockaddr_in));
                 if(sentBytes != 20) {
                     // TODO log fail of sending connection-initiate-packet
+                    continue;
                 }
             } else {
                 // is server, initiate connection to client
@@ -396,6 +400,7 @@ void UDPC_update(void *ctx) {
                     sizeof(struct sockaddr_in));
                 if(sentBytes != 20) {
                     // TODO log fail send init connection packet as server
+                    continue;
                 }
             }
             continue;
@@ -432,6 +437,7 @@ void UDPC_update(void *ctx) {
                 sizeof(struct sockaddr_in));
             if(sentBytes != 20) {
                 // TODO log fail send heartbeat packet
+                continue;
             }
 
             UDPC_PacketInfo pInfo{{0}, 0, 0, 0, 0, 0, 0};
@@ -439,7 +445,7 @@ void UDPC_update(void *ctx) {
             pInfo.receiver = iter->first.getAddr();
             pInfo.senderPort = c->socketInfo.sin_port;
             pInfo.receiverPort = iter->second.port;
-            *((uint32_t*)(pInfo.data + 8)) = htonl(iter->second.lseq - 1);
+            *((uint32_t*)(pInfo.data + 8)) = iter->second.lseq - 1;
 
             iter->second.sentPkts.push_back(std::move(pInfo));
             iter->second.cleanupSentPkts();
@@ -485,6 +491,7 @@ void UDPC_update(void *ctx) {
                 sizeof(struct sockaddr_in));
             if(sentBytes != 20 + pInfo.dataSize) {
                 // TODO log fail send packet
+                continue;
             }
 
             if((pInfo.flags & 0x4) == 0) {
@@ -509,7 +516,7 @@ void UDPC_update(void *ctx) {
                 sentPInfo.receiver = iter->first.getAddr();
                 sentPInfo.senderPort = c->socketInfo.sin_port;
                 sentPInfo.receiverPort = iter->second.port;
-                *((uint32_t*)(sentPInfo.data + 8)) = htonl(iter->second.lseq - 1);
+                *((uint32_t*)(sentPInfo.data + 8)) = iter->second.lseq - 1;
 
                 iter->second.sentPkts.push_back(std::move(pInfo));
                 iter->second.cleanupSentPkts();