doxy
[oweals/gnunet.git] / src / dv / plugin_transport_dv.c
index 2803e347e9ad187a944f78ffa1aaef85d2c186e0..3a8bafcefee8dcb7fb4bb819827b516b783e2669 100644 (file)
@@ -37,7 +37,7 @@
 #include "gnunet_transport_plugin.h"
 #include "dv.h"
 
-#define DEBUG_TEMPLATE GNUNET_NO
+#define DEBUG_TEMPLATE GNUNET_EXTRA_LOGGING
 
 /**
  * Encapsulation of all of the state of the plugin.
@@ -145,11 +145,8 @@ struct Plugin
  * Handler for messages received from the DV service.
  */
 void
-handle_dv_message_received (void *cls,
-                            struct GNUNET_PeerIdentity *sender,
-                            char *msg,
-                            size_t msg_len,
-                            uint32_t distance,
+handle_dv_message_received (void *cls, struct GNUNET_PeerIdentity *sender,
+                            char *msg, size_t msg_len, uint32_t distance,
                             char *sender_address, size_t sender_address_len)
 {
   struct Plugin *plugin = cls;
@@ -158,26 +155,34 @@ handle_dv_message_received (void *cls,
   char *my_id;
 
   my_id = GNUNET_strdup (GNUNET_i2s (plugin->env->my_identity));
-  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG,
-                   "plugin_transport_dv",
+  GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "plugin_transport_dv",
                    _("%s Received message from %s of type %d, distance %u!\n"),
                    my_id, GNUNET_i2s (sender),
                    ntohs (((struct GNUNET_MessageHeader *) msg)->type),
                    distance);
+  if (sender_address_len == (2 * sizeof (struct GNUNET_PeerIdentity)))
+  {
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "plugin_transport_dv",
+                     "Parsed sender address: %s:%s\n",
+                     GNUNET_i2s ((struct GNUNET_PeerIdentity *) sender_address),
+                     GNUNET_h2s (&
+                                 ((struct GNUNET_PeerIdentity *)
+                                  &sender_address[sizeof
+                                                  (struct
+                                                   GNUNET_PeerIdentity)])->hashPubKey));
+  }
+
   GNUNET_free_non_null (my_id);
 #endif
-  struct GNUNET_TRANSPORT_ATS_Information ats[2];
+  struct GNUNET_ATS_Information ats[1];
 
-  ats[0].type = htonl (GNUNET_TRANSPORT_ATS_QUALITY_NET_DISTANCE);
+  ats[0].type = htonl (GNUNET_ATS_QUALITY_NET_DISTANCE);
   ats[0].value = htonl (distance);
-  ats[1].type = htonl (GNUNET_TRANSPORT_ATS_ARRAY_TERMINATOR);
-  ats[1].value = htonl (0);
 
-  plugin->env->receive (plugin->env->cls,
-                        sender,
+  plugin->env->receive (plugin->env->cls, sender,
                         (struct GNUNET_MessageHeader *) msg,
-                        (const struct GNUNET_TRANSPORT_ATS_Information *) &ats,
-                        2, NULL, sender_address, sender_address_len);
+                        (const struct GNUNET_ATS_Information *) &ats, 1, NULL,
+                        sender_address, sender_address_len);
 
 }
 
@@ -192,18 +197,11 @@ handle_dv_message_received (void *cls,
  * a message using the plugin.
  *
  * @param cls closure
- * @param target who should receive this message
+ * @param session the session used
  * @param priority how important is the message
  * @param msgbuf the message to transmit
  * @param msgbuf_size number of bytes in 'msgbuf'
  * @param timeout when should we time out
- * @param session the session used
- * @param addr the address to use (can be NULL if the plugin
- *                is "on its own" (i.e. re-use existing TCP connection))
- * @param addrlen length of the address in bytes
- * @param force_address GNUNET_YES if the plugin MUST use the given address,
- *                otherwise the plugin may use other addresses or
- *                existing connections (if available)
  * @param cont continuation to call once the message has
  *        been transmitted (or if the transport is ready
  *        for the next transmission call; or if the
@@ -214,26 +212,21 @@ handle_dv_message_received (void *cls,
  *         and does NOT mean that the message was not transmitted (DV)
  */
 static ssize_t
-dv_plugin_send (void *cls,
-                const struct GNUNET_PeerIdentity *target,
-                const char *msgbuf,
-                size_t msgbuf_size,
-                unsigned int priority,
-                struct GNUNET_TIME_Relative timeout,
-                struct Session *session,
-                const void *addr,
-                size_t addrlen,
-                int force_address,
+dv_plugin_send (void *cls, 
+               struct Session *session,
+                const char *msgbuf, size_t msgbuf_size, unsigned int priority,
+                struct GNUNET_TIME_Relative timeout, 
                 GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
 {
-  int ret = 0;
+  int ret = -1;
+#if 0
   struct Plugin *plugin = cls;
 
-  ret = GNUNET_DV_send (plugin->dv_handle,
-                        target,
-                        msgbuf,
-                        msgbuf_size,
-                        priority, timeout, addr, addrlen, cont, cont_cls);
+  ret =
+      GNUNET_DV_send (plugin->dv_handle, &session->sender, 
+                     msgbuf, msgbuf_size, priority,
+                      timeout, addr, addrlen, cont, cont_cls);
+#endif
   return ret;
 }
 
@@ -270,14 +263,11 @@ dv_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
  * @param asc_cls closure for asc
  */
 static void
-dv_plugin_address_pretty_printer (void *cls,
-                                  const char *type,
-                                  const void *addr,
-                                  size_t addrlen,
-                                  int numeric,
+dv_plugin_address_pretty_printer (void *cls, const char *type, const void *addr,
+                                  size_t addrlen, int numeric,
                                   struct GNUNET_TIME_Relative timeout,
-                                  GNUNET_TRANSPORT_AddressStringCallback
-                                  asc, void *asc_cls)
+                                  GNUNET_TRANSPORT_AddressStringCallback asc,
+                                  void *asc_cls)
 {
   char *dest_peer;
   char *via_peer;
@@ -337,8 +327,8 @@ address_to_string (void *cls, const void *addr, size_t addrlen)
     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);
+    GNUNET_snprintf (return_buffer, sizeof (return_buffer), "%s:%s", &peer_hash,
+                     &via_hash);
   }
   else
     return NULL;
@@ -383,10 +373,29 @@ dv_plugin_check_address (void *cls, const void *addr, size_t addrlen)
     }
     return GNUNET_SYSERR;
   }
+
   return GNUNET_OK;
 }
 
 
+
+/**
+ * Create a new session to transmit data to the target
+ * This session will used to send data to this peer and the plugin will
+ * notify us by calling the env->session_end function
+ *
+ * @param cls the plugin
+ * @param address the address
+ * @return the session if the address is valid, NULL otherwise
+ */
+static struct Session * 
+dv_get_session (void *cls,
+               const struct GNUNET_HELLO_Address *address)
+{
+  return NULL;
+}
+
+
 /**
  * Entry point for the plugin.
  */
@@ -416,6 +425,7 @@ libgnunet_plugin_transport_dv_init (void *cls)
   api->address_pretty_printer = &dv_plugin_address_pretty_printer;
   api->check_address = &dv_plugin_check_address;
   api->address_to_string = &address_to_string;
+  api->get_session = dv_get_session;
   return api;
 }
 
@@ -437,4 +447,4 @@ libgnunet_plugin_transport_dv_done (void *cls)
   return NULL;
 }
 
-/* end of plugin_transport_template.c */
+/* end of plugin_transport_dv.c */