gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r33327 - gnunet/src/transport
Date: Mon, 19 May 2014 16:13:51 +0200

Author: wachs
Date: 2014-05-19 16:13:50 +0200 (Mon, 19 May 2014)
New Revision: 33327

Modified:
   gnunet/src/transport/gnunet-service-transport_clients.c
   gnunet/src/transport/gnunet-service-transport_neighbours.c
   gnunet/src/transport/gnunet-transport.c
   gnunet/src/transport/transport.h
   gnunet/src/transport/transport_api_address_to_string.c
Log:
new api


Modified: gnunet/src/transport/gnunet-service-transport_clients.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_clients.c     2014-05-19 
14:11:19 UTC (rev 33326)
+++ gnunet/src/transport/gnunet-service-transport_clients.c     2014-05-19 
14:13:50 UTC (rev 33327)
@@ -863,17 +863,39 @@
 transmit_address_to_client (void *cls, const char *buf)
 {
   struct AddressToStringContext *actx = cls;
+  struct AddressToStringResultMessage *atsm;
+  size_t len;
+
+  if (NULL != buf)
+  {
+    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);
+  }
+  else
+  {
+    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);
+    atsm->res = htonl (GNUNET_NO);
+    atsm->addr_len = htonl (0);
+  }
+
   if (NULL == buf)
   {
-    GNUNET_SERVER_transmit_context_append_data (actx->tc, NULL, 0,
-                                                
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+    /* Address could not be converted */
+    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);
     return;
   }
-  GNUNET_SERVER_transmit_context_append_data (actx->tc, buf, strlen (buf) + 1,
-                                              
GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+  GNUNET_SERVER_transmit_context_append_message (actx->tc, (const struct 
GNUNET_MessageHeader *) atsm);
 }
 
 
@@ -897,6 +919,7 @@
   uint16_t size;
   struct GNUNET_SERVER_TransmitContext *tc;
   struct AddressToStringContext *actx;
+  struct AddressToStringResultMessage atsm;
   struct GNUNET_TIME_Relative rtimeout;
   int32_t numeric;
 
@@ -929,8 +952,12 @@
   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;
   }

Modified: gnunet/src/transport/gnunet-service-transport_neighbours.c
===================================================================
--- gnunet/src/transport/gnunet-service-transport_neighbours.c  2014-05-19 
14:11:19 UTC (rev 33326)
+++ gnunet/src/transport/gnunet-service-transport_neighbours.c  2014-05-19 
14:13:50 UTC (rev 33327)
@@ -1229,10 +1229,11 @@
                              gettext_noop
                              ("# transmission failures for messages to other 
peers"),
                              1, GNUNET_NO);
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
-             "Sending message to `%s' of type %u was a %s\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+             "Sending message to `%s' of type %u with %u bytes was a %s\n",
              GNUNET_i2s (receiver),
               ntohs (((struct GNUNET_MessageHeader *) mq->message_buf)->type),
+              mq->message_buf_size,
               (success == GNUNET_OK) ? "success" : "FAILURE");
   if (NULL != mq->cont)
     mq->cont (mq->cont_cls, success, size_payload, physical);
@@ -1296,6 +1297,11 @@
     return;                     /* no more messages */
   GNUNET_CONTAINER_DLL_remove (n->messages_head, n->messages_tail, mq);
   n->is_active = mq;
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+      "Giving message with %u bytes to plugin session %p\n",
+      mq->message_buf_size, n->primary_address.session);
+
   (void) send_with_session (n,
                            mq->message_buf, mq->message_buf_size,
                            0 /* priority */, timeout, GNUNET_NO,
@@ -1635,10 +1641,11 @@
   mq->message_buf = (const char *) &mq[1];
   mq->message_buf_size = msg_size;
   mq->timeout = GNUNET_TIME_relative_to_absolute (timeout);
+
+  GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Enqueueing %u bytes to send to peer 
%s\n",
+      msg_size, GNUNET_i2s (target));
+
   GNUNET_CONTAINER_DLL_insert_tail (n->messages_head, n->messages_tail, mq);
-  if ( (NULL != n->is_active) ||
-       ( (NULL == n->primary_address.session) && (NULL == 
n->primary_address.address)) )
-    return;
   if (GNUNET_SCHEDULER_NO_TASK != n->task)
     GNUNET_SCHEDULER_cancel (n->task);
   n->task = GNUNET_SCHEDULER_add_now (&master_task, n);
@@ -2073,8 +2080,7 @@
   return GNUNET_OK;
 }
 
-static
-int
+static int
 free_notification_cb(void *cls, const struct GNUNET_PeerIdentity *key,
     void *value)
 {

Modified: gnunet/src/transport/gnunet-transport.c
===================================================================
--- gnunet/src/transport/gnunet-transport.c     2014-05-19 14:11:19 UTC (rev 
33326)
+++ gnunet/src/transport/gnunet-transport.c     2014-05-19 14:13:50 UTC (rev 
33327)
@@ -579,7 +579,7 @@
 
 
 static void
-process_validation_string (void *cls, const char *address)
+process_validation_string (void *cls, const char *address, int res)
 {
   struct ValidationResolutionContext *vc = cls;
   char *s_valid;
@@ -588,6 +588,13 @@
 
   if (address != NULL )
   {
+    if (GNUNET_SYSERR == res)
+    {
+      FPRINTF (stderr, "Failed to convert address for peer `%s' plugin `%s' 
length %lu to string \n",
+          GNUNET_i2s (&vc->id),
+          vc->addrcp->transport_name,
+          vc->addrcp->address_length);
+    }
     if (GNUNET_TIME_UNIT_ZERO_ABS.abs_value_us == vc->valid_until.abs_value_us)
       s_valid = GNUNET_strdup("never");
     else
@@ -605,7 +612,8 @@
 
     FPRINTF (stdout,
         _("Peer `%s' %s %s\n\t%s%s\n\t%s%s\n\t%s%s\n"),
-        GNUNET_i2s (&vc->id), address,
+        GNUNET_i2s (&vc->id),
+        (GNUNET_OK == res) ? address : "<invalid address>",
         (monitor_validation) ? GNUNET_TRANSPORT_vs2s (vc->state) : "",
         "Valid until    : ", s_valid,
         "Last validation: ",s_last,
@@ -618,9 +626,10 @@
   else
   {
     /* done */
+
     GNUNET_assert(address_resolutions > 0);
     address_resolutions--;
-    if (GNUNET_NO == vc->printed)
+    if ((GNUNET_SYSERR == res) && (GNUNET_NO == vc->printed))
     {
       if (numeric == GNUNET_NO)
       {
@@ -1066,7 +1075,7 @@
 
 
 static void
-process_peer_string (void *cls, const char *address)
+process_peer_string (void *cls, const char *address, int res)
 {
   struct PeerResolutionContext *rc = cls;
 

Modified: gnunet/src/transport/transport.h
===================================================================
--- gnunet/src/transport/transport.h    2014-05-19 14:11:19 UTC (rev 33326)
+++ gnunet/src/transport/transport.h    2014-05-19 14:13:50 UTC (rev 33327)
@@ -276,7 +276,33 @@
 
 };
 
+/**
+ * Message used to notify the transport API about an address to string
+ * conversion. Message is followed by the string with length strlen
+ */
+struct AddressToStringResultMessage
+{
 
+  /**
+   * Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
+   */
+  struct GNUNET_MessageHeader header;
+
+  /**
+   * GNUNET_OK if the conversion succeeded,
+   * GNUNET_SYSERR if it failed
+   */
+  uint32_t res GNUNET_PACKED;
+
+  /**
+   * Length of the following string
+   */
+  uint32_t addr_len GNUNET_PACKED;
+};
+
+
+
+
 /**
  * Message used to notify the transport service about a message
  * to be transmitted to another peer.  The actual message follows.

Modified: gnunet/src/transport/transport_api_address_to_string.c
===================================================================
--- gnunet/src/transport/transport_api_address_to_string.c      2014-05-19 
14:11:19 UTC (rev 33326)
+++ gnunet/src/transport/transport_api_address_to_string.c      2014-05-19 
14:13:50 UTC (rev 33327)
@@ -55,7 +55,7 @@
 /**
  * Function called with responses from the service.
  *
- * @param cls our 'struct GNUNET_TRANSPORT_AddressLookupContext*'
+ * @param cls our 'struct GNUNET_TRANSPORT_AddressToStringContext*'
  * @param msg NULL on timeout or error, otherwise presumably a
  *        message with the human-readable address
  */
@@ -63,41 +63,82 @@
 address_response_processor (void *cls, const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_TRANSPORT_AddressToStringContext *alucb = cls;
+  struct AddressToStringResultMessage *atsm;
   const char *address;
   uint16_t size;
+  uint32_t result;
+  uint32_t addr_len;
+  char *empty_str = "";
 
   if (msg == NULL)
   {
-    alucb->cb (alucb->cb_cls, NULL);
+    alucb->cb (alucb->cb_cls, NULL, GNUNET_OK);
     GNUNET_CLIENT_disconnect (alucb->client);
     GNUNET_free (alucb);
     return;
   }
   GNUNET_break (ntohs (msg->type) ==
                 GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_TO_STRING_REPLY);
+
   size = ntohs (msg->size);
-  if (size == sizeof (struct GNUNET_MessageHeader))
+  if (size < sizeof (struct AddressToStringResultMessage))
   {
-    /* done! */
-    alucb->cb (alucb->cb_cls, NULL);
+    alucb->cb (alucb->cb_cls, NULL, GNUNET_OK);
     GNUNET_CLIENT_disconnect (alucb->client);
     GNUNET_free (alucb);
     return;
   }
-  address = (const char *) &msg[1];
-  if (address[size - sizeof (struct GNUNET_MessageHeader) - 1] != '\0')
+  atsm = (struct AddressToStringResultMessage *) msg;
+
+  result = ntohl (atsm->res);
+  addr_len = ntohl (atsm->addr_len);
+
+  if (size == (sizeof (struct AddressToStringResultMessage)))
   {
+    /* done, success depends on result */
+    alucb->cb (alucb->cb_cls, NULL, result);
+    GNUNET_CLIENT_disconnect (alucb->client);
+    GNUNET_free (alucb);
+    return;
+  }
+
+  if (GNUNET_NO == result)
+  {
+    alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR);
+
+    /* expect more replies */
+    GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
+                           GNUNET_TIME_absolute_get_remaining 
(alucb->timeout));
+    return;
+  }
+
+
+  address = (const char *) &atsm[1];
+  if ( (addr_len > (size - (sizeof (struct AddressToStringResultMessage)))) ||
+       (address[addr_len -1] != '\0') )
+  {
     /* invalid reply */
     GNUNET_break (0);
-    alucb->cb (alucb->cb_cls, NULL);
+    alucb->cb (alucb->cb_cls, NULL, GNUNET_SYSERR);
     GNUNET_CLIENT_disconnect (alucb->client);
     GNUNET_free (alucb);
     return;
   }
+
+  result = GNUNET_NO;
+
   /* expect more replies */
   GNUNET_CLIENT_receive (alucb->client, &address_response_processor, alucb,
                          GNUNET_TIME_absolute_get_remaining (alucb->timeout));
-  alucb->cb (alucb->cb_cls, address);
+
+  if (GNUNET_NO == result)
+  {
+    alucb->cb (alucb->cb_cls, empty_str, GNUNET_SYSERR);
+  }
+  else
+  {
+    alucb->cb (alucb->cb_cls, address, GNUNET_OK);
+  }
 }
 
 




reply via email to

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