gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r1307 - GNUnet/src/server


From: grothoff
Subject: [GNUnet-SVN] r1307 - GNUnet/src/server
Date: Thu, 7 Jul 2005 06:45:54 -0700 (PDT)

Author: grothoff
Date: 2005-07-07 06:45:51 -0700 (Thu, 07 Jul 2005)
New Revision: 1307

Modified:
   GNUnet/src/server/connection.c
Log:
bugfix

Modified: GNUnet/src/server/connection.c
===================================================================
--- GNUnet/src/server/connection.c      2005-07-07 13:23:52 UTC (rev 1306)
+++ GNUnet/src/server/connection.c      2005-07-07 13:45:51 UTC (rev 1307)
@@ -1088,6 +1088,38 @@
   p2pHdr->bandwidth
     = htonl(be->idealized_limit);
   p = sizeof(P2P_Message);
+
+  /* first, trigger callbacks on selected entries */
+  for (i=0;i<be->sendBufferSize;i++) {
+    SendEntry * entry = be->sendBuffer[i];
+    if ( (entry->knapsackSolution == YES) &&
+        (entry->callback != NULL) ) {
+      if (OK == entry->callback(&plaintextMsg[p],
+                               entry->closure,
+                               entry->len)) {
+       entry->callback = NULL;
+       entry->closure = MALLOC(entry->len);
+       memcpy(entry->closure,
+              &plaintextMsg[p],
+              entry->len);
+      } else {
+       /* should not happen if everything went well,
+          add random padding instead */
+       p2p_HEADER * part;
+       
+       part = (p2p_HEADER *) &plaintextMsg[p];
+       part->size
+         = htons(entry->len);
+       part->type
+         = htons(p2p_PROTO_NOISE);
+       for (i=p+sizeof(p2p_HEADER);i<entry->len+p;i++)
+         plaintextMsg[p] = (char) rand();
+       entry->callback = NULL;
+       entry->closure = NULL;
+      }
+    }
+  }
+
   perm = permute(be->sendBufferSize);
   /* change permutation such that SE_FLAGS
      are obeyed */
@@ -1118,35 +1150,10 @@
   for (i=0;i<be->sendBufferSize;i++) {
     SendEntry * entry = be->sendBuffer[perm[i]];
     if (entry->knapsackSolution == YES) {
-      if (entry->callback == NULL) {
-       memcpy(&plaintextMsg[p],
-              entry->closure,
-              entry->len);
-      } else { 
-       if (OK == entry->callback(&plaintextMsg[p],
-                                 entry->closure,
-                                 entry->len)) {
-         entry->callback = NULL;
-         entry->closure = MALLOC(entry->len);
-         memcpy(entry->closure,
-                &plaintextMsg[p],
-                entry->len);
-       } else {
-         /* should not happen if everything went well,
-            add random padding instead */
-         p2p_HEADER * part;
-         
-         part = (p2p_HEADER *) &plaintextMsg[p];
-         part->size
-           = htons(entry->len);
-         part->type
-           = htons(p2p_PROTO_NOISE);
-         for (i=p+sizeof(p2p_HEADER);i<entry->len+p;i++)
-           plaintextMsg[p] = (char) rand();
-         entry->callback = NULL;
-         entry->closure = NULL;
-       }
-      }
+      GNUNET_ASSERT(entry->callback == NULL);
+      memcpy(&plaintextMsg[p],
+            entry->closure,
+            entry->len);
       p += entry->len;
     } else {
       int msgCap;





reply via email to

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