-allow caller ID to differ from zone used for resolution
[oweals/gnunet.git] / src / transport / gnunet-service-transport_clients.c
index 653becf3940c8528ae17af1c6a0c4303931f65bd..b19a15bc735210043cf409c8db3902d27206a94f 100644 (file)
@@ -571,7 +571,7 @@ clients_handle_start (void *cls, struct GNUNET_SERVER_Client *client,
 
   tc = lookup_client (client);
 
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK,
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO | GNUNET_ERROR_TYPE_BULK,
               "Client %p sent START\n", tc);
   if (tc != NULL)
   {
@@ -766,11 +766,16 @@ try_connect_if_allowed (void *cls,
 {
   if (GNUNET_OK != result)
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Blacklist refuses connection attempt to peer `%s'\n",
+    GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                _("Blacklist refuses connection attempt to peer `%s'\n"),
                 GNUNET_i2s (peer));
     return;                     /* not allowed */
   }
+
+  GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+              _("Blacklist allows connection attempt to peer `%s'\n"),
+              GNUNET_i2s (peer));
+
   GST_neighbours_try_connect (peer);
 }
 
@@ -789,27 +794,59 @@ clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
   const struct TransportRequestConnectMessage *trcm =
       (const struct TransportRequestConnectMessage *) message;
 
-  GNUNET_STATISTICS_update (GST_stats,
-                            gettext_noop
-                            ("# REQUEST CONNECT messages received"), 1,
-                            GNUNET_NO);
+  if (GNUNET_YES == ntohl (trcm->connect))
+  {
+    GNUNET_STATISTICS_update (GST_stats,
+                              gettext_noop
+                              ("# REQUEST CONNECT messages received"), 1,
+                              GNUNET_NO);
 
-  if (0 == memcmp (&trcm->peer, &GST_my_identity,
-               sizeof (struct GNUNET_PeerIdentity)))
+    if (0 == memcmp (&trcm->peer, &GST_my_identity,
+                  sizeof (struct GNUNET_PeerIdentity)))
+    {
+      GNUNET_break_op (0);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Received a request connect message myself `%s'\n",
+                  GNUNET_i2s (&trcm->peer));
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  _("Received a request connect message for peer `%s'\n"),
+                  GNUNET_i2s (&trcm->peer));
+
+      (void) GST_blacklist_test_allowed (&trcm->peer, NULL, &try_connect_if_allowed,
+                                       NULL);
+    }
+  }
+  else if (GNUNET_NO == ntohl (trcm->connect))
   {
-    GNUNET_break_op (0);
-    GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
-                "Received a request connect message myself `%s'\n",
-                GNUNET_i2s (&trcm->peer));
+    GNUNET_STATISTICS_update (GST_stats,
+                              gettext_noop
+                              ("# REQUEST DISCONNECT messages received"), 1,
+                              GNUNET_NO);
+
+    if (0 == memcmp (&trcm->peer, &GST_my_identity,
+                  sizeof (struct GNUNET_PeerIdentity)))
+    {
+      GNUNET_break_op (0);
+      GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
+                  "Received a request disconnect message myself `%s'\n",
+                  GNUNET_i2s (&trcm->peer));
+    }
+    else
+    {
+      GNUNET_log (GNUNET_ERROR_TYPE_INFO,
+                  _("Received a request disconnect message for peer `%s'\n"),
+                  GNUNET_i2s (&trcm->peer));
+      (void) GST_neighbours_force_disconnect (&trcm->peer);
+    }
   }
   else
   {
-    GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-                "Received a request connect message for peer `%s'\n",
-                GNUNET_i2s (&trcm->peer));
-
-    (void) GST_blacklist_test_allowed (&trcm->peer, NULL, &try_connect_if_allowed,
-                                     NULL);
+    GNUNET_break_op (0);
+    GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
+    return;
   }
   GNUNET_SERVER_receive_done (client, GNUNET_OK);
 }
@@ -821,22 +858,62 @@ clients_handle_request_connect (void *cls, struct GNUNET_SERVER_Client *client,
  *
  * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*')
  * @param buf text to transmit
+ * @param res GNUNET_OK if conversion was successful, GNUNET_SYSERR on error
  */
 static void
-transmit_address_to_client (void *cls, const char *buf)
+transmit_address_to_client (void *cls, const char *buf, int res)
 {
   struct AddressToStringContext *actx = cls;
+  struct AddressToStringResultMessage *atsm;
+  size_t len;
+
   if (NULL == buf)
   {
-    GNUNET_SERVER_transmit_context_append_data (actx->tc, NULL, 0,
-                                                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
-    GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL);
-    GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
-    GNUNET_free (actx);
-    return;
+    GNUNET_assert ((res == GNUNET_OK) ||  (res == GNUNET_SYSERR));
+
+    len = sizeof (struct AddressToStringResultMessage);
+    atsm = GNUNET_malloc (len);
+    atsm->header.size = ntohs (len);
+    atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+
+    if (GNUNET_OK == res)
+    {
+      /* done, transmit */
+      atsm->res = htonl (GNUNET_YES);
+      atsm->addr_len = htonl (0);
+      GNUNET_SERVER_transmit_context_append_message (actx->tc,
+          (const struct GNUNET_MessageHeader *) atsm);
+
+      GNUNET_SERVER_transmit_context_run (actx->tc, GNUNET_TIME_UNIT_FOREVER_REL);
+      GNUNET_CONTAINER_DLL_remove (a2s_head, a2s_tail, actx);
+      GNUNET_free (actx);
+    }
+    if (GNUNET_SYSERR == res)
+    {
+      /* address conversion failed */
+
+      atsm->res = htonl (GNUNET_NO);
+      atsm->addr_len = htonl (0);
+      GNUNET_SERVER_transmit_context_append_message (actx->tc,
+          (const struct GNUNET_MessageHeader *) atsm);
+      GNUNET_free (atsm);
+    }
+  }
+  else
+  {
+    GNUNET_assert (res == GNUNET_OK);
+    /* succesful conversion, append*/
+    len = sizeof (struct AddressToStringResultMessage) + strlen (buf) + 1;
+    atsm = GNUNET_malloc (len);
+    atsm->header.size = ntohs (len);
+    atsm->header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+    atsm->res = htonl (GNUNET_YES);
+    atsm->addr_len = htonl (strlen (buf) + 1);
+    memcpy (&atsm[1], buf, strlen (buf) + 1);
+    GNUNET_SERVER_transmit_context_append_message (actx->tc,
+        (const struct GNUNET_MessageHeader *) atsm);
+    GNUNET_free (atsm);
   }
-  GNUNET_SERVER_transmit_context_append_data (actx->tc, buf, strlen (buf) + 1,
-                                              GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
 }
 
 
@@ -860,6 +937,7 @@ clients_handle_address_to_string (void *cls,
   uint16_t size;
   struct GNUNET_SERVER_TransmitContext *tc;
   struct AddressToStringContext *actx;
+  struct AddressToStringResultMessage atsm;
   struct GNUNET_TIME_Relative rtimeout;
   int32_t numeric;
 
@@ -892,8 +970,12 @@ clients_handle_address_to_string (void *cls,
   papi = GST_plugins_printer_find (plugin_name);
   if (NULL == papi)
   {
-    GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0,
-                                                GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+    atsm.header.size = ntohs (sizeof (struct AddressToStringResultMessage));
+    atsm.header.type = ntohs (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+    atsm.res = htonl (GNUNET_NO);
+    atsm.addr_len = htonl (0);
+    GNUNET_SERVER_transmit_context_append_message (tc,
+        (const struct GNUNET_MessageHeader *) &atsm);
     GNUNET_SERVER_transmit_context_run (tc, rtimeout);
     return;
   }