gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r21359 - in gnunet/src: core dns include util


From: gnunet
Subject: [GNUnet-SVN] r21359 - in gnunet/src: core dns include util
Date: Tue, 8 May 2012 21:17:03 +0200

Author: grothoff
Date: 2012-05-08 21:17:03 +0200 (Tue, 08 May 2012)
New Revision: 21359

Modified:
   gnunet/src/core/gnunet-service-core_kx.c
   gnunet/src/dns/gnunet-service-dns.c
   gnunet/src/include/gnunet_helper_lib.h
   gnunet/src/util/helper.c
Log:
-allow helper send to be cancelled

Modified: gnunet/src/core/gnunet-service-core_kx.c
===================================================================
--- gnunet/src/core/gnunet-service-core_kx.c    2012-05-08 19:16:55 UTC (rev 
21358)
+++ gnunet/src/core/gnunet-service-core_kx.c    2012-05-08 19:17:03 UTC (rev 
21359)
@@ -41,7 +41,7 @@
 /**
  * Set to GNUNET_YES to perform some slightly expensive internal invariant 
checks.
  */
-#define EXTRA_CHECKS GNUNET_NO
+#define EXTRA_CHECKS GNUNET_YES
 
 /**
  * How long do we wait for SET_KEY confirmation initially?
@@ -877,6 +877,12 @@
       (GNUNET_OK != GNUNET_CRYPTO_aes_check_session_key (&k)))
   {
     /* failed to decrypt !? */
+    GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+               "Invalid key %x decrypted by %s from message %u (origin: %s)\n",
+               (unsigned int) GNUNET_CRYPTO_crc32_n (&k, sizeof (struct 
GNUNET_CRYPTO_AesSessionKey)),
+               GNUNET_i2s (&GSC_my_identity),
+               (unsigned int) GNUNET_CRYPTO_crc32_n (&m->encrypted_key, sizeof 
(struct GNUNET_CRYPTO_RsaEncryptedData)),
+               GNUNET_h2s (&kx->peer.hashPubKey));
     GNUNET_break_op (0);
     return;
   }
@@ -1058,6 +1064,13 @@
                                                     
GNUNET_CRYPTO_AesSessionKey),
                                             kx->public_key,
                                             &skm->encrypted_key));
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+             "Encrypting key %x for %s resulting in message %u (origin: %s)\n",
+             (unsigned int) GNUNET_CRYPTO_crc32_n (&kx->encrypt_key, sizeof 
(struct GNUNET_CRYPTO_AesSessionKey)),
+             GNUNET_i2s (&kx->peer),
+             (unsigned int) GNUNET_CRYPTO_crc32_n (&skm->encrypted_key, sizeof 
(struct GNUNET_CRYPTO_RsaEncryptedData)),
+             GNUNET_h2s (&GSC_my_identity.hashPubKey));
+
   GNUNET_assert (GNUNET_OK ==
                  GNUNET_CRYPTO_rsa_sign (my_private_key, &skm->purpose,
                                          &skm->signature));

Modified: gnunet/src/dns/gnunet-service-dns.c
===================================================================
--- gnunet/src/dns/gnunet-service-dns.c 2012-05-08 19:16:55 UTC (rev 21358)
+++ gnunet/src/dns/gnunet-service-dns.c 2012-05-08 19:17:03 UTC (rev 21359)
@@ -631,10 +631,10 @@
     }
     /* final checks & sending */
     GNUNET_assert (off == reply_len);
-    GNUNET_HELPER_send (hijacker,
-                       hdr,
-                       GNUNET_YES,
-                       NULL, NULL);
+    (void) GNUNET_HELPER_send (hijacker,
+                              hdr,
+                              GNUNET_YES,
+                              NULL, NULL);
     GNUNET_STATISTICS_update (stats,
                              gettext_noop ("# DNS requests answered via TUN 
interface"),
                              1, GNUNET_NO);

Modified: gnunet/src/include/gnunet_helper_lib.h
===================================================================
--- gnunet/src/include/gnunet_helper_lib.h      2012-05-08 19:16:55 UTC (rev 
21358)
+++ gnunet/src/include/gnunet_helper_lib.h      2012-05-08 19:17:03 UTC (rev 
21359)
@@ -75,6 +75,12 @@
 
 
 /**
+ * Handle to cancel 'send'
+ */
+struct GNUNET_HELPER_SendHandle;
+
+
+/**
  * Send an message to the helper.
  *
  * @param h helper to send message to
@@ -82,10 +88,11 @@
  * @param can_drop can the message be dropped if there is already one in the 
queue?
  * @param cont continuation to run once the message is out
  * @param cont_cls closure for 'cont'
- * @return GNUNET_YES if the message will be sent
- *         GNUNET_NO if the message was dropped
+ * @return NULL if the message was dropped, 
+ *         otherwise handle to cancel *cont* (actual transmission may
+ *         not be abortable)
  */
-int
+struct GNUNET_HELPER_SendHandle *
 GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, 
                    const struct GNUNET_MessageHeader *msg,
                    int can_drop,
@@ -93,4 +100,14 @@
                    void *cont_cls);
 
 
+/**
+ * Cancel a 'send' operation.  If possible, transmitting the
+ * message is also aborted, but at least 'cont' won't be
+ * called.
+ *
+ * @param sh operation to cancel
+ */
+void
+GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh);
+
 #endif /* end of include guard: GNUNET_HELPER_LIB_H */

Modified: gnunet/src/util/helper.c
===================================================================
--- gnunet/src/util/helper.c    2012-05-08 19:16:55 UTC (rev 21358)
+++ gnunet/src/util/helper.c    2012-05-08 19:17:03 UTC (rev 21359)
@@ -31,25 +31,30 @@
 /**
  * Entry in the queue of messages we need to transmit to the helper.
  */
-struct HelperMessageQueueEntry
+struct GNUNET_HELPER_SendHandle
 {
 
   /**
    * This is an entry in a DLL.
    */
-  struct HelperMessageQueueEntry *next;
+  struct GNUNET_HELPER_SendHandle *next;
 
   /**
    * This is an entry in a DLL.
    */
-  struct HelperMessageQueueEntry *prev;
+  struct GNUNET_HELPER_SendHandle *prev;
 
   /**
    * Message to transmit (allocated at the end of this struct)
    */
   const struct GNUNET_MessageHeader *msg;
-  
+ 
   /**
+   * The handle to a helper process.
+   */
+  struct GNUNET_HELPER_Handle *h;
+ 
+  /**
    * Function to call upon completion.
    */
   GNUNET_HELPER_Continuation cont;
@@ -106,12 +111,12 @@
   /**
    * First message queued for transmission to helper.
    */
-  struct HelperMessageQueueEntry *mq_head;
+  struct GNUNET_HELPER_SendHandle *sh_head;
 
   /**
    * Last message queued for transmission to helper.
    */
-  struct HelperMessageQueueEntry *mq_tail;
+  struct GNUNET_HELPER_SendHandle *sh_tail;
 
   /**
    * Binary to run.
@@ -148,7 +153,7 @@
 static void
 stop_helper (struct GNUNET_HELPER_Handle *h)
 {
-  struct HelperMessageQueueEntry *qe;
+  struct GNUNET_HELPER_SendHandle *sh;
 
   if (NULL != h->helper_proc)
   {
@@ -184,14 +189,14 @@
     h->helper_out = NULL;
     h->fh_from_helper = NULL;
   }
-  while (NULL != (qe = h->mq_head))
+  while (NULL != (sh = h->sh_head))
   {
-    GNUNET_CONTAINER_DLL_remove (h->mq_head,
-                                h->mq_tail,
-                                qe);
-    if (NULL != qe->cont)
-      qe->cont (qe->cont_cls, GNUNET_NO);
-    GNUNET_free (qe);
+    GNUNET_CONTAINER_DLL_remove (h->sh_head,
+                                h->sh_tail,
+                                sh);
+    if (NULL != sh->cont)
+      sh->cont (sh->cont_cls, GNUNET_NO);
+    GNUNET_free (sh);
   }
   /* purge MST buffer */
   (void) GNUNET_SERVER_mst_receive (h->mst, NULL, NULL, 0, GNUNET_YES, 
GNUNET_NO);
@@ -380,17 +385,17 @@
 void
 GNUNET_HELPER_stop (struct GNUNET_HELPER_Handle *h)
 {
-  struct HelperMessageQueueEntry *qe;
+  struct GNUNET_HELPER_SendHandle *sh;
 
   /* signal pending writes that we were stopped */
-  while (NULL != (qe = h->mq_head))
+  while (NULL != (sh = h->sh_head))
   {
-    GNUNET_CONTAINER_DLL_remove (h->mq_head,
-                                h->mq_tail,
-                                qe);
-    if (NULL != qe->cont)
-      qe->cont (qe->cont_cls, GNUNET_SYSERR);
-    GNUNET_free (qe);
+    GNUNET_CONTAINER_DLL_remove (h->sh_head,
+                                h->sh_tail,
+                                sh);
+    if (NULL != sh->cont)
+      sh->cont (sh->cont_cls, GNUNET_SYSERR);
+    GNUNET_free (sh);
   }
   stop_helper (h);
   GNUNET_SERVER_mst_destroy (h->mst);
@@ -409,7 +414,7 @@
             const struct GNUNET_SCHEDULER_TaskContext *tc)
 {
   struct GNUNET_HELPER_Handle *h = cls;
-  struct HelperMessageQueueEntry *qe;
+  struct GNUNET_HELPER_SendHandle *sh;
   const char *buf;
   ssize_t t;
 
@@ -421,10 +426,10 @@
                                                    h->fh_to_helper, 
&helper_write, h);
     return;
   }  
-  if (NULL == (qe = h->mq_head))
+  if (NULL == (sh = h->sh_head))
     return; /* how did this happen? */
-  buf = (const char*) qe->msg;
-  t = GNUNET_DISK_file_write (h->fh_to_helper, &buf[qe->wpos], ntohs 
(qe->msg->size) - qe->wpos);
+  buf = (const char*) sh->msg;
+  t = GNUNET_DISK_file_write (h->fh_to_helper, &buf[sh->wpos], ntohs 
(sh->msg->size) - sh->wpos);
   if (t <= 0)
   {
     /* On write-error, restart the helper */
@@ -439,17 +444,17 @@
                                    &restart_task, h);
     return;
   }
-  qe->wpos += t;
-  if (qe->wpos == ntohs (qe->msg->size))
+  sh->wpos += t;
+  if (sh->wpos == ntohs (sh->msg->size))
   {
-    GNUNET_CONTAINER_DLL_remove (h->mq_head,
-                                h->mq_tail,
-                                qe);
-    if (NULL != qe->cont)
-      qe->cont (qe->cont_cls, GNUNET_YES);
-    GNUNET_free (qe);
+    GNUNET_CONTAINER_DLL_remove (h->sh_head,
+                                h->sh_tail,
+                                sh);
+    if (NULL != sh->cont)
+      sh->cont (sh->cont_cls, GNUNET_YES);
+    GNUNET_free (sh);
   }
-  if (NULL != h->mq_head)
+  if (NULL != h->sh_head)
     h->write_task = GNUNET_SCHEDULER_add_write_file 
(GNUNET_TIME_UNIT_FOREVER_REL,
                                                     h->fh_to_helper, 
                                                     &helper_write, 
@@ -466,41 +471,69 @@
  * @param cont continuation to run once the message is out (PREREQ_DONE on 
succees, CANCEL
  *             if the helper process died, NULL during GNUNET_HELPER_stop).
  * @param cont_cls closure for 'cont'
- * @return GNUNET_YES if the message will be sent
- *         GNUNET_NO if the message was dropped
+ * @return NULL if the message was dropped, 
+ *         otherwise handle to cancel *cont* (actual transmission may
+ *         not be abortable)
  */
-int
+struct GNUNET_HELPER_SendHandle *
 GNUNET_HELPER_send (struct GNUNET_HELPER_Handle *h, 
                    const struct GNUNET_MessageHeader *msg,
                    int can_drop,
                    GNUNET_HELPER_Continuation cont,
                    void *cont_cls)
 {
-  struct HelperMessageQueueEntry *qe;
+  struct GNUNET_HELPER_SendHandle *sh;
   uint16_t mlen;
 
   if (NULL == h->fh_to_helper)
-    return GNUNET_NO;
+    return NULL;
   if ( (GNUNET_YES == can_drop) &&
-       (h->mq_head != NULL) )
-    return GNUNET_NO;
+       (NULL != h->sh_head) )
+    return NULL;
   mlen = ntohs (msg->size);
-  qe = GNUNET_malloc (sizeof (struct HelperMessageQueueEntry) + mlen);
-  qe->msg = (const struct GNUNET_MessageHeader*) &qe[1];
-  memcpy (&qe[1], msg, mlen);
-  qe->cont = cont;
-  qe->cont_cls = cont_cls;
-  GNUNET_CONTAINER_DLL_insert_tail (h->mq_head,
-                                   h->mq_tail,
-                                   qe);
+  sh = GNUNET_malloc (sizeof (struct GNUNET_HELPER_SendHandle) + mlen);
+  sh->msg = (const struct GNUNET_MessageHeader*) &sh[1];
+  memcpy (&sh[1], msg, mlen);
+  sh->h = h;
+  sh->cont = cont;
+  sh->cont_cls = cont_cls;
+  GNUNET_CONTAINER_DLL_insert_tail (h->sh_head,
+                                   h->sh_tail,
+                                   sh);
   if (GNUNET_SCHEDULER_NO_TASK == h->write_task)
     h->write_task = GNUNET_SCHEDULER_add_write_file 
(GNUNET_TIME_UNIT_FOREVER_REL,
                                                     h->fh_to_helper, 
                                                     &helper_write, 
                                                     h);
     
-  return GNUNET_YES;
+  return sh;
 }
 
+/**
+ * Cancel a 'send' operation.  If possible, transmitting the
+ * message is also aborted, but at least 'cont' won't be
+ * called.
+ *
+ * @param sh operation to cancel
+ */
+void
+GNUNET_HELPER_send_cancel (struct GNUNET_HELPER_SendHandle *sh)
+{
+  struct GNUNET_HELPER_Handle *h = sh->h;
 
+  sh->cont = NULL;
+  sh->cont_cls = NULL;
+  if (0 == sh->wpos)
+  {
+    GNUNET_CONTAINER_DLL_remove (h->sh_head, h->sh_tail, sh);
+    if (NULL == h->sh_head)
+    {
+      GNUNET_SCHEDULER_cancel (h->write_task);
+      h->write_task = GNUNET_SCHEDULER_NO_TASK;
+    }
+    GNUNET_free (sh);
+  }
+}
+
+
 /* end of helper.c */




reply via email to

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