gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[gnunet] 02/05: transport (quic): parse msgs before passing to core


From: gnunet
Subject: [gnunet] 02/05: transport (quic): parse msgs before passing to core
Date: Thu, 27 Jul 2023 03:43:59 +0200

This is an automated email from the git hooks/post-receive script.

marshall pushed a commit to branch master
in repository gnunet.

commit 1470f8232a5e3e787725a5b0dad62bccf7e722ef
Author: marshall <stmr@umich.edu>
AuthorDate: Wed Jul 26 15:28:46 2023 -0400

    transport (quic): parse msgs before passing to core
---
 src/transport/gnunet-communicator-quic.c | 41 ++++++++++++++++++++++++++------
 1 file changed, 34 insertions(+), 7 deletions(-)

diff --git a/src/transport/gnunet-communicator-quic.c 
b/src/transport/gnunet-communicator-quic.c
index e2fd970bf..b31d86cf7 100644
--- a/src/transport/gnunet-communicator-quic.c
+++ b/src/transport/gnunet-communicator-quic.c
@@ -254,18 +254,38 @@ recv_from_streams (struct PeerAddress *peer)
       buf_ptr += sizeof(struct GNUNET_PeerIdentity);
       recv_len -= sizeof(struct GNUNET_PeerIdentity);
     }
-
-    if (recv_len < sizeof(struct GNUNET_MessageHeader))
+    /**
+     * Parse messages to pass to communicator
+    */
+    while (recv_len >= sizeof(struct GNUNET_MessageHeader))
+    {
+      hdr = (struct GNUNET_MessageHeader *) buf_ptr;
+      if (ntohs (hdr->size) > recv_len)
+      {
+        GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+                    "message size stated is greater than length of recvd 
data!\n");
+        return;
+      }
+      GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "passing %zd bytes to core\n",
+                  recv_len);
+      GNUNET_TRANSPORT_communicator_receive (ch, &peer->target, hdr,
+                                             ADDRESS_VALIDITY_PERIOD, NULL,
+                                             NULL);
+      recv_len -= ntohs (hdr->size);
+      buf_ptr += ntohs (hdr->size);
+    }
+    /**
+     * Check for leftover bytes
+    */
+    if (0 != recv_len)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   "message recv len of %zd less than length of message 
header\n",
                   recv_len);
     }
-    hdr = (struct GNUNET_MessageHeader *) buf_ptr;
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "passing %zd bytes to core\n",
-                recv_len);
-    GNUNET_TRANSPORT_communicator_receive (ch, &peer->target, hdr,
-                                           ADDRESS_VALIDITY_PERIOD, NULL, 
NULL);
+    /**
+     * fin
+    */
     if (fin)
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -966,6 +986,10 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity 
*peer_id, const
   path = &address[strlen (COMMUNICATOR_ADDRESS_PREFIX "-")];
   in = udp_address_to_sockaddr (path, &in_len);
 
+  /**
+   * TODO: Check for existing peer (i.e. if we received a message from this 
address before)
+  */
+
   peer = GNUNET_new (struct PeerAddress);
   peer->address = in;
   peer->address_len = in_len;
@@ -1040,6 +1064,9 @@ mq_init (void *cls, const struct GNUNET_PeerIdentity 
*peer_id, const
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                 "tried to add duplicate address into address map\n");
+    peer_destroy (peer);
+    GNUNET_free (local_addr);
+    return GNUNET_SYSERR;
   }
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new peer to the addr map\n");
   setup_peer_mq (peer);

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]