gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r35021 - gnunet/src/rps


From: gnunet
Subject: [GNUnet-SVN] r35021 - gnunet/src/rps
Date: Tue, 27 Jan 2015 17:09:08 +0100

Author: ch3
Date: 2015-01-27 17:09:07 +0100 (Tue, 27 Jan 2015)
New Revision: 35021

Modified:
   gnunet/src/rps/rps_api.c
Log:
fixed _seed() funktion

Modified: gnunet/src/rps/rps_api.c
===================================================================
--- gnunet/src/rps/rps_api.c    2015-01-27 15:04:09 UTC (rev 35020)
+++ gnunet/src/rps/rps_api.c    2015-01-27 16:09:07 UTC (rev 35021)
@@ -217,6 +217,7 @@
   return rh;
 }
 
+
 /**
  * Seed rps service with peerIDs.
  *
@@ -229,33 +230,40 @@
                      const struct GNUNET_PeerIdentity * ids)
 {
   uint32_t size_needed;
-  uint32_t tmp_num_peers;
+  uint32_t num_peers_max;
+  const struct GNUNET_PeerIdentity *tmp_peer_pointer;
   struct GNUNET_MQ_Envelope *ev;
   struct GNUNET_RPS_CS_SeedMessage *msg;
 
+  /* The actual size the message occupies */
   size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
-                n * sizeof (struct GNUNET_PeerIdentity);
+    n * sizeof (struct GNUNET_PeerIdentity);
+  /* The number of peers that fits in one message together with
+   * the respective header */
+  num_peers_max = (GNUNET_SERVER_MAX_MESSAGE_SIZE -
+      sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
+    sizeof (struct GNUNET_PeerIdentity);
+  tmp_peer_pointer = ids;
 
   while (GNUNET_SERVER_MAX_MESSAGE_SIZE < size_needed)
   {
-    tmp_num_peers = (GNUNET_SERVER_MAX_MESSAGE_SIZE -
-        sizeof (struct GNUNET_RPS_CS_SeedMessage)) /
-      sizeof (struct GNUNET_PeerIdentity);
-    n -= tmp_num_peers;
+    ev = GNUNET_MQ_msg_extra (msg, num_peers_max * sizeof (struct 
GNUNET_PeerIdentity),
+        GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
+    msg->num_peers = ntohl (num_peers_max);
+    memcpy (&msg[1], tmp_peer_pointer, num_peers_max * sizeof (struct 
GNUNET_PeerIdentity));
+    GNUNET_MQ_send (h->mq, ev);
+
+    n -= num_peers_max;
     size_needed = sizeof (struct GNUNET_RPS_CS_SeedMessage) +
                   n * sizeof (struct GNUNET_PeerIdentity);
-
-    ev = GNUNET_MQ_msg_extra (msg, tmp_num_peers * sizeof (struct 
GNUNET_PeerIdentity),
-        GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
-    msg->num_peers = GNUNET_htonll (tmp_num_peers);
-    memcpy (&msg[1], ids, tmp_num_peers * sizeof (struct GNUNET_PeerIdentity));
-    GNUNET_MQ_send (h->mq, ev);
+    /* Set pointer to beginning of next block of num_peers_max peers */
+    tmp_peer_pointer = &ids[num_peers_max];
   }
 
   ev = GNUNET_MQ_msg_extra (msg, n * sizeof (struct GNUNET_PeerIdentity),
                             GNUNET_MESSAGE_TYPE_RPS_CS_SEED);
   msg->num_peers = GNUNET_htonll (n);
-  memcpy (&msg[1], ids, n * sizeof (struct GNUNET_PeerIdentity));
+  memcpy (&msg[1], tmp_peer_pointer, n * sizeof (struct GNUNET_PeerIdentity));
   GNUNET_MQ_send (h->mq, ev);
 }
 




reply via email to

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