-allow caller ID to differ from zone used for resolution
[oweals/gnunet.git] / src / transport / transport_api_monitoring.c
index af59881516dfb40fe38cd1a31d563403859a0542..31f3d4f90eec2d7187b8ca186e1fe064dfe59b98 100644 (file)
@@ -153,18 +153,13 @@ GNUNET_TRANSPORT_is_connected (enum GNUNET_TRANSPORT_PeerState state)
   {
   case GNUNET_TRANSPORT_PS_NOT_CONNECTED:
   case GNUNET_TRANSPORT_PS_INIT_ATS:
-  case GNUNET_TRANSPORT_PS_INIT_BLACKLIST:
   case GNUNET_TRANSPORT_PS_CONNECT_SENT:
-  case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST_INBOUND:
   case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
-  case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST:
   case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
     return GNUNET_NO;
   case GNUNET_TRANSPORT_PS_CONNECTED:
   case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
-  case GNUNET_TRANSPORT_PS_RECONNECT_BLACKLIST:
   case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
-  case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_BLACKLIST:
   case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
     return GNUNET_YES;
   case GNUNET_TRANSPORT_PS_DISCONNECT:
@@ -195,28 +190,18 @@ GNUNET_TRANSPORT_ps2s (enum GNUNET_TRANSPORT_PeerState state)
     return "S_NOT_CONNECTED";
   case GNUNET_TRANSPORT_PS_INIT_ATS:
     return "S_INIT_ATS";
-  case GNUNET_TRANSPORT_PS_INIT_BLACKLIST:
-    return "S_INIT_BLACKLIST";
   case GNUNET_TRANSPORT_PS_CONNECT_SENT:
     return "S_CONNECT_SENT";
-  case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST_INBOUND:
-    return "S_CONNECT_RECV_BLACKLIST_INBOUND";
   case GNUNET_TRANSPORT_PS_CONNECT_RECV_ATS:
     return "S_CONNECT_RECV_ATS";
-  case GNUNET_TRANSPORT_PS_CONNECT_RECV_BLACKLIST:
-    return "S_CONNECT_RECV_BLACKLIST";
   case GNUNET_TRANSPORT_PS_CONNECT_RECV_ACK:
     return "S_CONNECT_RECV_ACK";
   case GNUNET_TRANSPORT_PS_CONNECTED:
     return "S_CONNECTED";
   case GNUNET_TRANSPORT_PS_RECONNECT_ATS:
     return "S_RECONNECT_ATS";
-  case GNUNET_TRANSPORT_PS_RECONNECT_BLACKLIST:
-    return "S_RECONNECT_BLACKLIST";
   case GNUNET_TRANSPORT_PS_RECONNECT_SENT:
     return "S_RECONNECT_SENT";
-  case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_BLACKLIST:
-    return "S_CONNECTED_SWITCHING_BLACKLIST";
   case GNUNET_TRANSPORT_PS_CONNECTED_SWITCHING_CONNECT_SENT:
     return "S_CONNECTED_SWITCHING_CONNECT_SENT";
   case GNUNET_TRANSPORT_PS_DISCONNECT:
@@ -241,7 +226,7 @@ GNUNET_TRANSPORT_vs2s (enum GNUNET_TRANSPORT_ValidationState state)
   switch (state)
   {
   case GNUNET_TRANSPORT_VS_NONE:
-    return "NEW";
+    return "NONE";
   case GNUNET_TRANSPORT_VS_NEW:
     return "NEW";
   case GNUNET_TRANSPORT_VS_REMOVE:
@@ -304,7 +289,7 @@ send_peer_mon_request (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
 /**
  * Send our subscription request to the service.
  *
- * @param pal_ctx our context
+ * @param val_ctx our context
  */
 static void
 send_val_mon_request (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
@@ -354,6 +339,9 @@ reconnect_peer_ctx (struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx)
   GNUNET_assert (GNUNET_NO == pal_ctx->one_shot);
   GNUNET_CLIENT_disconnect (pal_ctx->client);
   pal_ctx->client = NULL;
+  pal_ctx->cb (pal_ctx->cb_cls, NULL, NULL,
+               GNUNET_TRANSPORT_PS_NOT_CONNECTED,
+               GNUNET_TIME_UNIT_ZERO_ABS);
   pal_ctx->backoff = GNUNET_TIME_STD_BACKOFF (pal_ctx->backoff);
   pal_ctx->reconnect_task = GNUNET_SCHEDULER_add_delayed (pal_ctx->backoff,
                                                          &do_peer_connect,
@@ -382,7 +370,7 @@ do_val_connect (void *cls,
 /**
  * Cut the existing connection and reconnect.
  *
- * @param pal_ctx our context
+ * @param val_ctx our context
  */
 static void
 reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
@@ -390,21 +378,27 @@ reconnect_val_ctx (struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx)
   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,
                                                           val_ctx);
 }
 
+
 /**
  * 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
  */
 static void
-val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
+val_response_processor (void *cls,
+                        const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_TRANSPORT_ValidationMonitoringContext *val_ctx = cls;
   struct ValidationIterateResponseMessage *vr_msg;
@@ -415,7 +409,7 @@ val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
   size_t tlen;
   size_t alen;
 
-  if (msg == NULL)
+  if (NULL == msg)
   {
     if (val_ctx->one_shot)
     {
@@ -545,20 +539,23 @@ val_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
     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
  */
 static void
-peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
+peer_response_processor (void *cls,
+                         const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_TRANSPORT_PeerMonitoringContext *pal_ctx = cls;
   struct PeerIterateResponseMessage *pir_msg;
@@ -569,7 +566,7 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
   size_t alen;
   size_t tlen;
 
-  if (msg == NULL)
+  if (NULL == msg)
   {
     if (pal_ctx->one_shot)
     {
@@ -592,6 +589,7 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
     /* 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);
@@ -609,6 +607,7 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
     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);
@@ -712,19 +711,19 @@ peer_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
  * @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;