gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r33089 - gnunet/src/transport


From: gnunet
Subject: [GNUnet-SVN] r33089 - gnunet/src/transport
Date: Wed, 16 Apr 2014 11:10:58 +0200

Author: grothoff
Date: 2014-04-16 11:10:58 +0200 (Wed, 16 Apr 2014)
New Revision: 33089

Modified:
   gnunet/src/transport/gnunet-transport.c
   gnunet/src/transport/transport_api_monitoring.c
Log:
-signal monitor disconnect via callback

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2014-04-16 08:50:19 UTC (rev 
33088)
+++ gnunet/src/transport/gnunet-transport.c     2014-04-16 09:10:58 UTC (rev 
33089)
@@ -310,18 +310,21 @@
 };
 
 
- int destroy_it (void *cls,
-    const struct GNUNET_PeerIdentity *key,
-    void *value)
+static int
+destroy_it (void *cls,
+            const struct GNUNET_PeerIdentity *key,
+            void *value)
 {
-   struct MonitoredPeer *m = value;
-   GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove 
(monitored_peers,
-       key, value));
-   GNUNET_free_non_null (m->address);
-   GNUNET_free (value);
-   return GNUNET_OK;
+  struct MonitoredPeer *m = value;
+
+  GNUNET_assert (GNUNET_OK == GNUNET_CONTAINER_multipeermap_remove 
(monitored_peers,
+                                                                    key, 
value));
+  GNUNET_free_non_null (m->address);
+  GNUNET_free (value);
+  return GNUNET_OK;
 }
 
+
 /**
  * Task run in monitor mode when the user presses CTRL-C to abort.
  * Stops monitoring activity.
@@ -567,12 +570,14 @@
 
 static void
 resolve_validation_address (const struct GNUNET_PeerIdentity *id,
-    const struct GNUNET_HELLO_Address *address, int numeric,
-    struct GNUNET_TIME_Absolute last_validation,
-    struct GNUNET_TIME_Absolute valid_until,
-    struct GNUNET_TIME_Absolute next_validation,
-    enum GNUNET_TRANSPORT_ValidationState state);
+                            const struct GNUNET_HELLO_Address *address,
+                            int numeric,
+                            struct GNUNET_TIME_Absolute last_validation,
+                            struct GNUNET_TIME_Absolute valid_until,
+                            struct GNUNET_TIME_Absolute next_validation,
+                            enum GNUNET_TRANSPORT_ValidationState state);
 
+
 static void
 process_validation_string (void *cls, const char *address)
 {
@@ -685,13 +690,14 @@
 }
 
 
-void process_validation_cb (void *cls,
-    const struct GNUNET_PeerIdentity *peer,
-    const struct GNUNET_HELLO_Address *address,
-    struct GNUNET_TIME_Absolute last_validation,
-    struct GNUNET_TIME_Absolute valid_until,
-    struct GNUNET_TIME_Absolute next_validation,
-    enum GNUNET_TRANSPORT_ValidationState state)
+static void
+process_validation_cb (void *cls,
+                       const struct GNUNET_PeerIdentity *peer,
+                       const struct GNUNET_HELLO_Address *address,
+                       struct GNUNET_TIME_Absolute last_validation,
+                       struct GNUNET_TIME_Absolute valid_until,
+                       struct GNUNET_TIME_Absolute next_validation,
+                       enum GNUNET_TRANSPORT_ValidationState state)
 {
   if ((NULL == peer) && (NULL == address))
   {
@@ -716,6 +722,7 @@
      valid_until, next_validation, state);
 }
 
+
 static void
 run_nat_test ()
 {
@@ -736,6 +743,7 @@
   head->tsk = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &fail_timeout, head);
 }
 
+
 /**
  * Test our plugin's configuration (NAT traversal, etc.).
  *
@@ -1009,16 +1017,21 @@
   }
 }
 
+
 static void
 resolve_peer_address (const struct GNUNET_PeerIdentity *id,
-    const struct GNUNET_HELLO_Address *address, int numeric,
-    enum GNUNET_TRANSPORT_PeerState state,
-    struct GNUNET_TIME_Absolute state_timeout);
+                      const struct GNUNET_HELLO_Address *address,
+                      int numeric,
+                      enum GNUNET_TRANSPORT_PeerState state,
+                      struct GNUNET_TIME_Absolute state_timeout);
 
+
 static void
-print_info (const struct GNUNET_PeerIdentity *id, const char *transport,
-    const char *addr, enum GNUNET_TRANSPORT_PeerState state,
-    struct GNUNET_TIME_Absolute state_timeout)
+print_info (const struct GNUNET_PeerIdentity *id,
+            const char *transport,
+            const char *addr,
+            enum GNUNET_TRANSPORT_PeerState state,
+            struct GNUNET_TIME_Absolute state_timeout)
 {
 
   if ( ((GNUNET_YES == iterate_connections) && (GNUNET_YES == iterate_all)) ||
@@ -1039,6 +1052,7 @@
   }
 }
 
+
 static void
 process_peer_string (void *cls, const char *address)
 {
@@ -1090,11 +1104,13 @@
   }
 }
 
+
 static void
 resolve_peer_address (const struct GNUNET_PeerIdentity *id,
-    const struct GNUNET_HELLO_Address *address, int numeric,
-    enum GNUNET_TRANSPORT_PeerState state,
-    struct GNUNET_TIME_Absolute state_timeout)
+                      const struct GNUNET_HELLO_Address *address,
+                      int numeric,
+                      enum GNUNET_TRANSPORT_PeerState state,
+                      struct GNUNET_TIME_Absolute state_timeout)
 {
   struct PeerResolutionContext *rc;
 
@@ -1114,6 +1130,7 @@
       RESOLUTION_TIMEOUT, &process_peer_string, rc);
 }
 
+
 /**
  * Function called with information about a peers during a one shot iteration
  *
@@ -1126,13 +1143,20 @@
  *
  */
 static void
-process_peer_iteration_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
-    const struct GNUNET_HELLO_Address *address,
-    enum GNUNET_TRANSPORT_PeerState state,
-    struct GNUNET_TIME_Absolute state_timeout)
+process_peer_iteration_cb (void *cls,
+                           const struct GNUNET_PeerIdentity *peer,
+                           const struct GNUNET_HELLO_Address *address,
+                           enum GNUNET_TRANSPORT_PeerState state,
+                           struct GNUNET_TIME_Absolute state_timeout)
 {
-  if (peer == NULL )
+  if (NULL == peer)
   {
+    if (monitor_connections)
+    {
+      FPRINTF (stdout,
+               _("Monitor disconnected from transport service. 
Reconnecting.\n"));
+      return;
+    }
     /* done */
     address_resolution_in_progress = GNUNET_NO;
     pic = NULL;
@@ -1150,8 +1174,9 @@
   op_timeout = GNUNET_SCHEDULER_add_delayed (OP_TIMEOUT, &operation_timeout,
       NULL );
 
-  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, "Received address for peer `%s': %s\n",
-      GNUNET_i2s (peer), address->transport_name);
+  GNUNET_log(GNUNET_ERROR_TYPE_DEBUG,
+             "Received address for peer `%s': %s\n",
+             GNUNET_i2s (peer), address->transport_name);
 
   if (NULL != address)
     resolve_peer_address (peer, address, numeric, state, state_timeout);

Modified: gnunet/src/transport/transport_api_monitoring.c
===================================================================
--- gnunet/src/transport/transport_api_monitoring.c     2014-04-16 08:50:19 UTC 
(rev 33088)
+++ gnunet/src/transport/transport_api_monitoring.c     2014-04-16 09:10:58 UTC 
(rev 33089)
@@ -375,6 +375,10 @@
   GNUNET_assert (GNUNET_NO == val_ctx->one_shot);
   GNUNET_CLIENT_disconnect (val_ctx->client);
   val_ctx->client = NULL;
+  /* notify clients about (re)connect */
+  val_ctx->cb (val_ctx->cb_cls, NULL, NULL,
+               GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TIME_UNIT_ZERO_ABS,
+               GNUNET_TIME_UNIT_ZERO_ABS, GNUNET_TRANSPORT_VS_TIMEOUT);
   val_ctx->backoff = GNUNET_TIME_STD_BACKOFF (val_ctx->backoff);
   val_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (val_ctx->backoff,
                                                           &do_val_connect,
@@ -384,7 +388,7 @@
 /**
  * Function called with responses from the service.
  *
- * @param cls our 'struct GNUNET_TRANSPORT_PeerMonitoringContext*'
+ * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
  * @param msg NULL on timeout or error, otherwise presumably a
  *        message with the human-readable address
  */
@@ -400,7 +404,7 @@
   size_t tlen;
   size_t alen;
 
-  if (msg == NULL)
+  if (NULL == msg)
   {
     if (val_ctx->one_shot)
     {
@@ -530,15 +534,17 @@
     GNUNET_HELLO_address_free (address);
   }
   /* expect more replies */
-  GNUNET_CLIENT_receive (val_ctx->client, &val_response_processor,
-      val_ctx, GNUNET_TIME_absolute_get_remaining (val_ctx->timeout));
+  GNUNET_CLIENT_receive (val_ctx->client,
+                         &val_response_processor,
+                         val_ctx,
+                         GNUNET_TIME_absolute_get_remaining 
(val_ctx->timeout));
 }
 
 
 /**
  * Function called with responses from the service.
  *
- * @param cls our 'struct GNUNET_TRANSPORT_PeerMonitoringContext*'
+ * @param cls our `struct GNUNET_TRANSPORT_PeerMonitoringContext *`
  * @param msg NULL on timeout or error, otherwise presumably a
  *        message with the human-readable address
  */
@@ -577,6 +583,7 @@
     /* Done! */
     if (pal_ctx->one_shot)
     {
+      /* iteration finished */
       pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
           GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
       GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
@@ -594,6 +601,7 @@
     GNUNET_break (0);
     if (pal_ctx->one_shot)
     {
+      /* iteration finished (with error) */
       pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
           GNUNET_TRANSPORT_PS_NOT_CONNECTED, GNUNET_TIME_UNIT_ZERO_ABS);
       GNUNET_TRANSPORT_monitor_peers_cancel (pal_ctx);
@@ -697,19 +705,19 @@
  * @param cfg configuration to use
  * @param peer a specific peer identity to obtain information for,
  *      NULL for all peers
- * @param one_shot GNUNET_YES to return the current state and then end (with 
NULL+NULL),
- *                 GNUNET_NO to monitor peers continuously
+ * @param one_shot #GNUNET_YES to return the current state and then end (with 
NULL+NULL),
+ *                 #GNUNET_NO to monitor peers continuously
  * @param timeout how long is the lookup allowed to take at most
  * @param peer_callback function to call with the results
- * @param peer_callback_cls closure for peer_address_callback
+ * @param peer_callback_cls closure for @a peer_address_callback
  */
 struct GNUNET_TRANSPORT_PeerMonitoringContext *
 GNUNET_TRANSPORT_monitor_peers (const struct GNUNET_CONFIGURATION_Handle *cfg,
-    const struct GNUNET_PeerIdentity *peer,
-    int one_shot,
-    struct GNUNET_TIME_Relative timeout,
-    GNUNET_TRANSPORT_PeerIterateCallback peer_callback,
-    void *peer_callback_cls)
+                                const struct GNUNET_PeerIdentity *peer,
+                                int one_shot,
+                                struct GNUNET_TIME_Relative timeout,
+                                GNUNET_TRANSPORT_PeerIterateCallback 
peer_callback,
+                                void *peer_callback_cls)
 {
   struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx;
   struct GNUNET_CLIENT_Connection *client;




reply via email to

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