address printing for dv plugin, doxygen comment
authorNathan S. Evans <evans@in.tum.de>
Mon, 3 May 2010 09:58:34 +0000 (09:58 +0000)
committerNathan S. Evans <evans@in.tum.de>
Mon, 3 May 2010 09:58:34 +0000 (09:58 +0000)
src/dv/dv_api.c
src/dv/plugin_transport_dv.c

index 29b6dcca336449724f220261220fcc27a79f5c0b..28bd0dcac9a5875b3707e8e72e04a47b44ec1b50 100644 (file)
@@ -433,6 +433,8 @@ void handle_message_receipt (void *cls,
  * @param timeout how long can this message be delayed (pass through to core)
  * @param addr the address of this peer (internally known to DV)
  * @param addrlen the length of the peer address
+ * @param cont continuation to call once the message has been sent (or failed)
+ * @param cont_cls closure for continuation
  *
  */
 int GNUNET_DV_send (struct GNUNET_DV_Handle *dv_handle,
index 83a89abba7872a2a4702dff94f9870dc32a8fa77..6932ce34b1fe2c159fb4c54afd10518a6837c055 100644 (file)
@@ -310,7 +310,47 @@ dv_plugin_address_pretty_printer (void *cls,
   asc (asc_cls, NULL);
 }
 
+/**
+ * Convert the DV address to a pretty string.
+ *
+ * @param cls closure
+ * @param addr the (hopefully) DV address
+ * @param addrlen the length of the address
+ *
+ * @return string representing the DV address
+ */
+static const char *address_to_string (void *cls,
+                                       const void *addr,
+                                       size_t addrlen)
+{
+  static char return_buffer[2 * 4 + 2]; // Two four character peer identity prefixes a ':' and '\0'
+
+  struct GNUNET_CRYPTO_HashAsciiEncoded peer_hash;
+  struct GNUNET_CRYPTO_HashAsciiEncoded via_hash;
+  struct GNUNET_PeerIdentity *peer;
+  struct GNUNET_PeerIdentity *via;
+  char *addr_buf = (char *)addr;
+
+  if (addrlen == (2 * sizeof(struct GNUNET_PeerIdentity)))
+    {
+      peer = (struct GNUNET_PeerIdentity *)addr_buf;
+      via = (struct GNUNET_PeerIdentity *)&addr_buf[sizeof(struct GNUNET_PeerIdentity)];
+
+      GNUNET_CRYPTO_hash_to_enc (&peer->hashPubKey, &peer_hash);
+      peer_hash.encoding[4] = '\0';
+      GNUNET_CRYPTO_hash_to_enc (&via->hashPubKey, &via_hash);
+      via_hash.encoding[4] = '\0';
+      GNUNET_snprintf (return_buffer,
+                       sizeof (return_buffer),
+                       "%s:%s",
+                       &peer_hash,
+                       &via_hash);
+    }
+  else
+    return NULL;
 
+  return return_buffer;
+}
 
 /**
  * Another peer has suggested an address for this
@@ -368,6 +408,7 @@ libgnunet_plugin_transport_dv_init (void *cls)
   api->disconnect = &dv_plugin_disconnect;
   api->address_pretty_printer = &dv_plugin_address_pretty_printer;
   api->check_address = &dv_plugin_address_suggested;
+  api->address_to_string = &address_to_string;
   return api;
 }