gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r21241 - in gnunet/src: . include peerinfo peerinfo-tool tr


From: gnunet
Subject: [GNUnet-SVN] r21241 - in gnunet/src: . include peerinfo peerinfo-tool transport
Date: Thu, 3 May 2012 13:27:14 +0200

Author: grothoff
Date: 2012-05-03 13:27:14 +0200 (Thu, 03 May 2012)
New Revision: 21241

Modified:
   gnunet/src/Makefile.am
   gnunet/src/include/gnunet_peerinfo_service.h
   gnunet/src/peerinfo-tool/gnunet-peerinfo.c
   gnunet/src/peerinfo/peerinfo_api.c
   gnunet/src/transport/gnunet-service-transport_hello.c
   gnunet/src/transport/gnunet-service-transport_validation.c
Log:
-enable lm building

Modified: gnunet/src/Makefile.am
===================================================================
--- gnunet/src/Makefile.am      2012-05-03 11:25:57 UTC (rev 21240)
+++ gnunet/src/Makefile.am      2012-05-03 11:27:14 UTC (rev 21241)
@@ -28,6 +28,7 @@
   block \
   statistics \
   arm \
+  lockmanager \
   peerinfo \
   $(MYSQL_DIR) \
   $(POSTGRES_DIR) \

Modified: gnunet/src/include/gnunet_peerinfo_service.h
===================================================================
--- gnunet/src/include/gnunet_peerinfo_service.h        2012-05-03 11:25:57 UTC 
(rev 21240)
+++ gnunet/src/include/gnunet_peerinfo_service.h        2012-05-03 11:27:14 UTC 
(rev 21241)
@@ -58,7 +58,6 @@
 GNUNET_PEERINFO_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
 
 
-
 /**
  * Disconnect from the peerinfo service.  Note that all iterators must
  * have completed or have been cancelled by the time this function is
@@ -73,6 +72,22 @@
 
 
 /**
+ * Continuation called with a status result.
+ * 
+ * @param cls closure
+ * @param emsg error message, NULL on success
+ */
+typedef void (*GNUNET_PEERINFO_Continuation)(void *cls,
+                                            const char *emsg);
+
+
+/**
+ * Opaque handle to cancel 'add' operation.
+ */
+struct GNUNET_PEERINFO_AddContext;
+
+
+/**
  * Add a host to the persistent list.  This method operates in
  * semi-reliable mode: if the transmission is not completed by
  * the time 'GNUNET_PEERINFO_disconnect' is called, it will be
@@ -82,13 +97,32 @@
  *
  * @param h handle to the peerinfo service
  * @param hello the verified (!) HELLO message
+ * @param cont continuation to call when done, NULL is allowed
+ * @param cont_cls closure for 'cont'
+ * @return handle to cancel add operation; all pending
+ *         'add' operations will be cancelled automatically
+ *        on disconnect, so it is not necessary to keep this
+ *        handle (unless 'cont' is NULL and at some point
+ *        calling 'cont' must be prevented)
  */
-void
+struct GNUNET_PEERINFO_AddContext *
 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
-                          const struct GNUNET_HELLO_Message *hello);
+                          const struct GNUNET_HELLO_Message *hello,
+                         GNUNET_PEERINFO_Continuation cont,
+                         void *cont_cls);
 
 
 /**
+ * Cancel pending 'add' operation.  Must only be called before
+ * either 'cont' or 'GNUNET_PEERINFO_disconnect' are invoked.
+ *
+ * @param ac handle for the add operation to cancel
+ */
+void
+GNUNET_PEERINFO_add_peer_cancel (struct GNUNET_PEERINFO_AddContext *ac);
+
+
+/**
  * Type of an iterator over the hosts.  Note that each
  * host will be called with each available protocol.
  *

Modified: gnunet/src/peerinfo/peerinfo_api.c
===================================================================
--- gnunet/src/peerinfo/peerinfo_api.c  2012-05-03 11:25:57 UTC (rev 21240)
+++ gnunet/src/peerinfo/peerinfo_api.c  2012-05-03 11:27:14 UTC (rev 21241)
@@ -33,35 +33,28 @@
 
 #define LOG(kind,...) GNUNET_log_from (kind, "peerinfo-api",__VA_ARGS__)
 
-/**
- * Function to call after transmission has succeeded.
- *
- * @param cls closure
- * @param success GNUNET_OK if transmission worked, GNUNET_SYSERR on error
- */
-typedef void (*TransmissionContinuation) (void *cls, int success);
 
-
 /**
- * Entry in the transmission queue to PEERINFO service.
+ * Entry in the transmission queue to PEERINFO service.  We use
+ * the same structure for queueing 'iteration' requests and
+ * actual 'add' messages.
  */
-struct TransmissionQueueEntry
+struct GNUNET_PEERINFO_AddContext
 {
   /**
    * This is a linked list.
    */
-  struct TransmissionQueueEntry *next;
+  struct GNUNET_PEERINFO_AddContext *next;
 
   /**
    * This is a linked list.
    */
-  struct TransmissionQueueEntry *prev;
+  struct GNUNET_PEERINFO_AddContext *prev;
 
   /**
-   * Function to call after request has been transmitted, or NULL (in which
-   * case we must consider sending the next entry immediately).
+   * Function to call after request has been transmitted, or NULL.
    */
-  TransmissionContinuation cont;
+  GNUNET_PEERINFO_Continuation cont;
 
   /**
    * Closure for 'cont'.
@@ -110,7 +103,7 @@
   /**
    * Our entry in the transmission queue.
    */
-  struct TransmissionQueueEntry *tqe;
+  struct GNUNET_PEERINFO_AddContext *ac;
 
   /**
    * Task responsible for timeout.
@@ -147,12 +140,12 @@
   /**
    * Head of transmission queue.
    */
-  struct TransmissionQueueEntry *tq_head;
+  struct GNUNET_PEERINFO_AddContext *ac_head;
 
   /**
    * Tail of transmission queue.
    */
-  struct TransmissionQueueEntry *tq_tail;
+  struct GNUNET_PEERINFO_AddContext *ac_tail;
 
   /**
    * Handle for the current transmission request, or NULL if none is pending.
@@ -214,7 +207,7 @@
 void
 GNUNET_PEERINFO_disconnect (struct GNUNET_PEERINFO_Handle *h)
 {
-  struct TransmissionQueueEntry *tqe;
+  struct GNUNET_PEERINFO_AddContext *ac;
   struct GNUNET_PEERINFO_IteratorContext *ic;
 
   while (NULL != (ic = h->ic_head))
@@ -223,12 +216,12 @@
     ic->in_receive = GNUNET_NO;
     GNUNET_PEERINFO_iterate_cancel (ic);
   }
-  while (NULL != (tqe = h->tq_head))
+  while (NULL != (ac = h->ac_head))
   {
-    GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe);
-    if (tqe->cont != NULL)
-      tqe->cont (tqe->cont_cls, GNUNET_SYSERR);
-    GNUNET_free (tqe);
+    GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
+    if (NULL != ac->cont)
+      ac->cont (ac->cont_cls, _("aborted due to explicit disconnect request"));
+    GNUNET_free (ac);
   }
   if (NULL != h->th)
   {
@@ -333,25 +326,25 @@
 do_transmit (void *cls, size_t size, void *buf)
 {
   struct GNUNET_PEERINFO_Handle *h = cls;
-  struct TransmissionQueueEntry *tqe = h->tq_head;
+  struct GNUNET_PEERINFO_AddContext *ac = h->ac_head;
   size_t ret;
 
   h->th = NULL;
-  if (NULL == tqe)
+  if (NULL == ac)
     return 0; /* request was cancelled in the meantime */
   if (NULL == buf)
   {
     /* peerinfo service died */
     LOG (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
          "Failed to transmit message to `%s' service.\n", "PEERINFO");
-    GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe);
+    GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
     reconnect (h);
-    if (NULL != tqe->cont)
-      tqe->cont (tqe->cont_cls, GNUNET_SYSERR);
-    GNUNET_free (tqe);
+    if (NULL != ac->cont)
+      ac->cont (ac->cont_cls, _("failed to transmit request (service down?)"));
+    GNUNET_free (ac);
     return 0;
   }
-  ret = tqe->size;
+  ret = ac->size;
   if (size < ret)
   {
     /* change in head of queue (i.e. cancel + add), try again */
@@ -360,13 +353,12 @@
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Transmitting request of size %u to `%s' service.\n", ret, "PEERINFO");
-  memcpy (buf, &tqe[1], ret);
-  GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, tqe);
-  if (NULL != tqe->cont)
-    tqe->cont (tqe->cont_cls, GNUNET_OK);
-  else
-    trigger_transmit (h);
-  GNUNET_free (tqe);
+  memcpy (buf, &ac[1], ret);
+  GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ac);
+  trigger_transmit (h);
+  if (NULL != ac->cont)
+    ac->cont (ac->cont_cls, NULL);
+  GNUNET_free (ac);
   return ret;
 }
 
@@ -380,9 +372,9 @@
 static void
 trigger_transmit (struct GNUNET_PEERINFO_Handle *h)
 {
-  struct TransmissionQueueEntry *tqe;
+  struct GNUNET_PEERINFO_AddContext *ac;
 
-  if (NULL == (tqe = h->tq_head))
+  if (NULL == (ac = h->ac_head))
     return; /* no requests queued */
   if (NULL != h->th)
     return; /* request already pending */
@@ -395,7 +387,7 @@
     return;
   }
   h->th =
-    GNUNET_CLIENT_notify_transmit_ready (h->client, tqe->size,
+    GNUNET_CLIENT_notify_transmit_ready (h->client, ac->size,
                                         GNUNET_TIME_UNIT_FOREVER_REL,
                                         GNUNET_YES,
                                         &do_transmit, h);
@@ -413,23 +405,28 @@
  * @param h handle to the peerinfo service
  * @param hello the verified (!) HELLO message
  */
-void
+struct GNUNET_PEERINFO_AddContext *
 GNUNET_PEERINFO_add_peer (struct GNUNET_PEERINFO_Handle *h,
-                          const struct GNUNET_HELLO_Message *hello)
+                          const struct GNUNET_HELLO_Message *hello,
+                         GNUNET_PEERINFO_Continuation cont,
+                         void *cont_cls)
 {
   uint16_t hs = GNUNET_HELLO_size (hello);
-  struct TransmissionQueueEntry *tqe;
+  struct GNUNET_PEERINFO_AddContext *ac;
   struct GNUNET_PeerIdentity peer;
 
   GNUNET_assert (GNUNET_OK == GNUNET_HELLO_get_id (hello, &peer));
   LOG (GNUNET_ERROR_TYPE_DEBUG,
        "Adding peer `%s' to PEERINFO database (%u bytes of `%s')\n",
        GNUNET_i2s (&peer), hs, "HELLO");
-  tqe = GNUNET_malloc (sizeof (struct TransmissionQueueEntry) + hs);
-  tqe->size = hs;
-  memcpy (&tqe[1], hello, hs);
-  GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe);
+  ac = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) + hs);
+  ac->size = hs;
+  ac->cont = cont;
+  ac->cont_cls = cont_cls;
+  memcpy (&ac[1], hello, hs);
+  GNUNET_CONTAINER_DLL_insert_after (h->ac_head, h->ac_tail, h->ac_tail, ac);
   trigger_transmit (h);
+  return ac;
 }
 
 
@@ -528,26 +525,25 @@
  * the results (or handle transmission error).
  *
  * @param cls the 'struct GNUNET_PEERINFO_IteratorContext'
- * @param transmit_success GNUNET_OK if transmission worked
+ * @param emsg error message, NULL if transmission worked
  */
 static void
-iterator_start_receive (void *cls, int transmit_success)
+iterator_start_receive (void *cls, const char *emsg)
 {
   struct GNUNET_PEERINFO_IteratorContext *ic = cls;
   struct GNUNET_PEERINFO_Handle *h = ic->h;
   GNUNET_PEERINFO_Processor cb;
   void *cb_cls;
 
-  ic->tqe = NULL;
-  if (GNUNET_OK != transmit_success)
+  ic->ac = NULL;
+  if (NULL != emsg)
   {
     cb = ic->callback;
     cb_cls = ic->callback_cls;
     GNUNET_PEERINFO_iterate_cancel (ic);
     reconnect (h);
     if (NULL != cb)
-      cb (cb_cls, NULL, NULL,
-         _("Failed to transmit iteration request to `PEERINFO' service"));
+      cb (cb_cls, NULL, NULL, emsg);
     return;
   }
   LOG (GNUNET_ERROR_TYPE_DEBUG, "Waiting for response from `%s' service.\n",
@@ -607,17 +603,17 @@
   struct GNUNET_MessageHeader *lapm;
   struct ListPeerMessage *lpm;
   struct GNUNET_PEERINFO_IteratorContext *ic;
-  struct TransmissionQueueEntry *tqe;
+  struct GNUNET_PEERINFO_AddContext *ac;
 
   if (NULL == peer)
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Requesting list of peers from PEERINFO service\n");
-    tqe =
-        GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
+    ac =
+        GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) +
                        sizeof (struct GNUNET_MessageHeader));
-    tqe->size = sizeof (struct GNUNET_MessageHeader);
-    lapm = (struct GNUNET_MessageHeader *) &tqe[1];
+    ac->size = sizeof (struct GNUNET_MessageHeader);
+    lapm = (struct GNUNET_MessageHeader *) &ac[1];
     lapm->size = htons (sizeof (struct GNUNET_MessageHeader));
     lapm->type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET_ALL);
   }
@@ -626,26 +622,26 @@
     LOG (GNUNET_ERROR_TYPE_DEBUG,
          "Requesting information on peer `%4s' from PEERINFO service\n",
          GNUNET_i2s (peer));
-    tqe =
-        GNUNET_malloc (sizeof (struct TransmissionQueueEntry) +
+    ac =
+        GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_AddContext) +
                        sizeof (struct ListPeerMessage));
-    tqe->size = sizeof (struct ListPeerMessage);
-    lpm = (struct ListPeerMessage *) &tqe[1];
+    ac->size = sizeof (struct ListPeerMessage);
+    lpm = (struct ListPeerMessage *) &ac[1];
     lpm->header.size = htons (sizeof (struct ListPeerMessage));
     lpm->header.type = htons (GNUNET_MESSAGE_TYPE_PEERINFO_GET);
     memcpy (&lpm->peer, peer, sizeof (struct GNUNET_PeerIdentity));
   }
   ic = GNUNET_malloc (sizeof (struct GNUNET_PEERINFO_IteratorContext));
   ic->h = h;
-  ic->tqe = tqe;
+  ic->ac = ac;
   ic->callback = callback;
   ic->callback_cls = callback_cls;
   ic->timeout = GNUNET_TIME_relative_to_absolute (timeout);
   ic->timeout_task =
       GNUNET_SCHEDULER_add_delayed (timeout, &signal_timeout, ic);
-  tqe->cont = &iterator_start_receive;
-  tqe->cont_cls = ic;
-  GNUNET_CONTAINER_DLL_insert_after (h->tq_head, h->tq_tail, h->tq_tail, tqe);
+  ac->cont = &iterator_start_receive;
+  ac->cont_cls = ic;
+  GNUNET_CONTAINER_DLL_insert_after (h->ac_head, h->ac_tail, h->ac_tail, ac);
   GNUNET_CONTAINER_DLL_insert (h->ic_head,
                               h->ic_tail,
                               ic);
@@ -676,10 +672,10 @@
   ic->callback = NULL;
   if (GNUNET_YES == ic->in_receive)
     return;                     /* need to finish processing */
-  if (NULL != ic->tqe)
+  if (NULL != ic->ac)
   {
-    GNUNET_CONTAINER_DLL_remove (h->tq_head, h->tq_tail, ic->tqe);
-    GNUNET_free (ic->tqe);
+    GNUNET_CONTAINER_DLL_remove (h->ac_head, h->ac_tail, ic->ac);
+    GNUNET_free (ic->ac);
   }
   GNUNET_free (ic);
 }

Modified: gnunet/src/peerinfo-tool/gnunet-peerinfo.c
===================================================================
--- gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2012-05-03 11:25:57 UTC (rev 
21240)
+++ gnunet/src/peerinfo-tool/gnunet-peerinfo.c  2012-05-03 11:27:14 UTC (rev 
21241)
@@ -699,7 +699,7 @@
   {
     /* WARNING: this adds the address from URI WITHOUT verification! */
     if (GNUNET_OK == ctx.ret)
-      GNUNET_PEERINFO_add_peer (peerinfo, hello);
+      GNUNET_PEERINFO_add_peer (peerinfo, hello, NULL, NULL);
     GNUNET_free (hello);
   }
 

Modified: gnunet/src/transport/gnunet-service-transport_hello.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_hello.c       2012-05-03 
11:25:57 UTC (rev 21240)
+++ gnunet/src/transport/gnunet-service-transport_hello.c       2012-05-03 
11:27:14 UTC (rev 21241)
@@ -177,7 +177,7 @@
                             GNUNET_NO);
   if (NULL != hello_cb)
     hello_cb (hello_cb_cls, GST_hello_get ());
-  GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello);
+  GNUNET_PEERINFO_add_peer (GST_peerinfo, our_hello, NULL, NULL);
   hello_task =
       GNUNET_SCHEDULER_add_delayed (HELLO_REFRESH_PERIOD, &refresh_hello_task,
                                     NULL);

Modified: gnunet/src/transport/gnunet-service-transport_validation.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_validation.c  2012-05-03 
11:25:57 UTC (rev 21240)
+++ gnunet/src/transport/gnunet-service-transport_validation.c  2012-05-03 
11:27:14 UTC (rev 21241)
@@ -1104,7 +1104,7 @@
   /* build HELLO to store in PEERINFO */
   ve->copied = GNUNET_NO;
   hello = GNUNET_HELLO_create (&ve->public_key, &add_valid_peer_address, ve);
-  GNUNET_PEERINFO_add_peer (GST_peerinfo, hello);
+  GNUNET_PEERINFO_add_peer (GST_peerinfo, hello, NULL, NULL);
   GNUNET_free (hello);
 }
 
@@ -1135,7 +1135,7 @@
     return;
   /* Add peer identity without addresses to peerinfo service */
   h = GNUNET_HELLO_create (&vac.public_key, NULL, NULL);
-  GNUNET_PEERINFO_add_peer (GST_peerinfo, h);
+  GNUNET_PEERINFO_add_peer (GST_peerinfo, h, NULL, NULL);
 #if VERBOSE_VALIDATION
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
               _("Adding `%s' without addresses for peer `%s'\n"), "HELLO",




reply via email to

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