new api
authorMatthias Wachs <wachs@net.in.tum.de>
Mon, 19 May 2014 14:13:50 +0000 (14:13 +0000)
committerMatthias Wachs <wachs@net.in.tum.de>
Mon, 19 May 2014 14:13:50 +0000 (14:13 +0000)
src/transport/gnunet-service-transport_clients.c
src/transport/gnunet-service-transport_neighbours.c
src/transport/gnunet-transport.c
src/transport/transport.h
src/transport/transport_api_address_to_string.c

index d9a750e2911e10f42bb0aab9838b32b662dc9637..1716441237a77f1234c057c35d19ea528586c4c2 100644 (file)
@@ -863,17 +863,39 @@ static void
 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 @@ 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;
 
@@ -929,8 +952,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;
   }
index d2dd2e752e3b5799ffe1b06135d91cdc04fd505c..7993bf2f4b182b037292feaa45813d5407731f23 100644 (file)
@@ -1229,10 +1229,11 @@ transmit_send_continuation (void *cls,
                              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 @@ try_transmission_to_peer (struct NeighbourMapEntry *n)
     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 @@ GST_neighbours_send (const struct GNUNET_PeerIdentity *target, const void *msg,
   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 @@ notification_cb(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
   return GNUNET_OK;
 }
 
-static
-int
+static int
 free_notification_cb(void *cls, const struct GNUNET_PeerIdentity *key,
     void *value)
 {
index 4487fc0e703c7f101b68749a2ee7573d9875b5fc..d4e16face8ef4a845d967af58f60e1ed99b3ea6a 100644 (file)
@@ -579,7 +579,7 @@ resolve_validation_address (const struct GNUNET_PeerIdentity *id,
 
 
 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 @@ process_validation_string (void *cls, const char *address)
 
   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 @@ process_validation_string (void *cls, const char *address)
 
     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 @@ process_validation_string (void *cls, const char *address)
   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 @@ print_info (const struct GNUNET_PeerIdentity *id,
 
 
 static void
-process_peer_string (void *cls, const char *address)
+process_peer_string (void *cls, const char *address, int res)
 {
   struct PeerResolutionContext *rc = cls;
 
index 7aa6c06a9e909eba38974ce970eba6f305b4e9cf..68c685c295e7c622469d45e32f7e81fc0cb290b8 100644 (file)
@@ -276,6 +276,32 @@ struct SendOkMessage
 
 };
 
+/**
+ * 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
index 0cf0111b3bd44bca0877fdb71f32b03da4d7748b..8a0db240fd1d0054bd66486a245811bc9421d324 100644 (file)
@@ -55,7 +55,7 @@ struct GNUNET_TRANSPORT_AddressToStringContext
 /**
  * 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 @@ static void
 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);
+  }
 }