fixing blacklist ids for dv
[oweals/gnunet.git] / src / dv / dv_api.c
index ecc13941b15c2b360d37a7b1a7358bd66e448952..412ab47adaa2ff7d804f01205d8a99493bee1642 100644 (file)
@@ -63,7 +63,7 @@ struct GNUNET_DV_TransmitHandle
    * Closure for 'cb'.
    */
   void *cb_cls;
-  
+
   /**
    * The actual message (allocated at the end of this struct).
    */
@@ -78,7 +78,7 @@ struct GNUNET_DV_TransmitHandle
    * UID of our message, if any.
    */
   uint32_t uid;
-  
+
 };
 
 
@@ -107,7 +107,7 @@ struct GNUNET_DV_ServiceHandle
    * Closure for the callbacks.
    */
   void *cls;
-  
+
   /**
    * Function to call on connect events.
    */
@@ -143,7 +143,7 @@ struct GNUNET_DV_ServiceHandle
    * upon successful transmission.  The respective
    * transmissions have already been done.
    */
-  struct GNUNET_CONTAINER_MultiHashMap *send_callbacks;
+  struct GNUNET_CONTAINER_MultiPeerMap *send_callbacks;
 
   /**
    * Current unique ID
@@ -196,8 +196,8 @@ transmit_pending (void *cls, size_t size, void *buf)
     ret += tsize;
     if (NULL != th->cb)
     {
-      (void) GNUNET_CONTAINER_multihashmap_put (sh->send_callbacks,
-                                               &th->target.hashPubKey,
+      (void) GNUNET_CONTAINER_multipeermap_put (sh->send_callbacks,
+                                               &th->target,
                                                th,
                                                GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
     }
@@ -221,12 +221,12 @@ start_transmit (struct GNUNET_DV_ServiceHandle *sh)
   if (NULL != sh->th)
     return;
   if (NULL == sh->th_head)
-    return; 
+    return;
   sh->th =
     GNUNET_CLIENT_notify_transmit_ready (sh->client,
                                         ntohs (sh->th_head->msg->size),
                                         GNUNET_TIME_UNIT_FOREVER_REL,
-                                        GNUNET_NO, 
+                                        GNUNET_NO,
                                         &transmit_pending, sh);
 }
 
@@ -259,7 +259,7 @@ struct AckContext
  */
 static int
 process_ack (void *cls,
-            const struct GNUNET_HashCode *key,
+            const struct GNUNET_PeerIdentity *key,
             void *value)
 {
   struct AckContext *ctx = cls;
@@ -267,8 +267,11 @@ process_ack (void *cls,
 
   if (th->uid != ntohl (ctx->ack->uid))
     return GNUNET_OK;
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Matchedk ACK for message to peer %s\n",
+       GNUNET_i2s (key));
   GNUNET_assert (GNUNET_YES ==
-                GNUNET_CONTAINER_multihashmap_remove (ctx->sh->send_callbacks,
+                GNUNET_CONTAINER_multipeermap_remove (ctx->sh->send_callbacks,
                                                       key,
                                                       th));
   th->cb (th->cb_cls,
@@ -288,7 +291,7 @@ process_ack (void *cls,
  * @param msg the message that was received
  */
 static void
-handle_message_receipt (void *cls, 
+handle_message_receipt (void *cls,
                        const struct GNUNET_MessageHeader *msg)
 {
   struct GNUNET_DV_ServiceHandle *sh = cls;
@@ -299,13 +302,16 @@ handle_message_receipt (void *cls,
   const struct GNUNET_MessageHeader *payload;
   const struct GNUNET_DV_AckMessage *ack;
   struct AckContext ctx;
-  
+
   if (NULL == msg)
   {
     /* Connection closed */
     reconnect (sh);
     return;
   }
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Received message of type %u from DV service\n",
+       (unsigned int) msg->type);
   switch (ntohs (msg->type))
   {
   case GNUNET_MESSAGE_TYPE_DV_CONNECT:
@@ -374,8 +380,8 @@ handle_message_receipt (void *cls,
     ack = (const struct GNUNET_DV_AckMessage *) msg;
     ctx.ack = ack;
     ctx.sh = sh;
-    GNUNET_CONTAINER_multihashmap_get_multiple (sh->send_callbacks,
-                                               &ack->target.hashPubKey,
+    GNUNET_CONTAINER_multipeermap_get_multiple (sh->send_callbacks,
+                                               &ack->target,
                                                &process_ack,
                                                &ctx);
     break;
@@ -383,7 +389,7 @@ handle_message_receipt (void *cls,
     reconnect (sh);
     break;
   }
-  GNUNET_CLIENT_receive (sh->client, 
+  GNUNET_CLIENT_receive (sh->client,
                         &handle_message_receipt, sh,
                          GNUNET_TIME_UNIT_FOREVER_REL);
 }
@@ -396,7 +402,7 @@ handle_message_receipt (void *cls,
  * @param size number of bytes available in buf
  * @param buf where to copy the message
  * @return number of bytes written to buf
- */ 
+ */
 static size_t
 transmit_start (void *cls,
                size_t size,
@@ -435,14 +441,14 @@ transmit_start (void *cls,
  */
 static int
 cleanup_send_cb (void *cls,
-                const struct GNUNET_HashCode *key,
+                const struct GNUNET_PeerIdentity *key,
                 void *value)
 {
   struct GNUNET_DV_ServiceHandle *sh = cls;
   struct GNUNET_DV_TransmitHandle *th = value;
 
   GNUNET_assert (GNUNET_YES ==
-                GNUNET_CONTAINER_multihashmap_remove (sh->send_callbacks,
+                GNUNET_CONTAINER_multipeermap_remove (sh->send_callbacks,
                                                       key,
                                                       th));
   th->cb (th->cb_cls, GNUNET_SYSERR);
@@ -458,7 +464,7 @@ cleanup_send_cb (void *cls,
  */
 static void
 reconnect (struct GNUNET_DV_ServiceHandle *sh)
-{ 
+{
   if (NULL != sh->th)
   {
     GNUNET_CLIENT_notify_transmit_ready_cancel (sh->th);
@@ -469,9 +475,11 @@ reconnect (struct GNUNET_DV_ServiceHandle *sh)
     GNUNET_CLIENT_disconnect (sh->client);
     sh->client = NULL;
   }
-  GNUNET_CONTAINER_multihashmap_iterate (sh->send_callbacks,
+  GNUNET_CONTAINER_multipeermap_iterate (sh->send_callbacks,
                                         &cleanup_send_cb,
                                         sh);
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Connecting to DV service\n");
   sh->client = GNUNET_CLIENT_connect ("dv", sh->cfg);
   if (NULL == sh->client)
   {
@@ -508,14 +516,14 @@ GNUNET_DV_service_connect (const struct GNUNET_CONFIGURATION_Handle *cfg,
 {
   struct GNUNET_DV_ServiceHandle *sh;
 
-  sh = GNUNET_malloc (sizeof (struct GNUNET_DV_ServiceHandle));
+  sh = GNUNET_new (struct GNUNET_DV_ServiceHandle);
   sh->cfg = cfg;
   sh->cls = cls;
   sh->connect_cb = connect_cb;
   sh->distance_cb = distance_cb;
   sh->disconnect_cb = disconnect_cb;
   sh->message_cb = message_cb;
-  sh->send_callbacks = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_YES);
+  sh->send_callbacks = GNUNET_CONTAINER_multipeermap_create (128, GNUNET_YES);
   reconnect (sh);
   return sh;
 }
@@ -530,7 +538,7 @@ void
 GNUNET_DV_service_disconnect (struct GNUNET_DV_ServiceHandle *sh)
 {
   struct GNUNET_DV_TransmitHandle *pos;
-  
+
   if (NULL == sh)
     return;
   if (NULL != sh->th)
@@ -545,15 +553,15 @@ GNUNET_DV_service_disconnect (struct GNUNET_DV_ServiceHandle *sh)
                                 pos);
     GNUNET_free (pos);
   }
-  if (NULL != sh->client) 
+  if (NULL != sh->client)
   {
     GNUNET_CLIENT_disconnect (sh->client);
     sh->client = NULL;
   }
-  GNUNET_CONTAINER_multihashmap_iterate (sh->send_callbacks,
+  GNUNET_CONTAINER_multipeermap_iterate (sh->send_callbacks,
                                         &cleanup_send_cb,
                                         sh);
-  GNUNET_CONTAINER_multihashmap_destroy (sh->send_callbacks);
+  GNUNET_CONTAINER_multipeermap_destroy (sh->send_callbacks);
   GNUNET_free (sh);
 }
 
@@ -583,6 +591,12 @@ GNUNET_DV_send (struct GNUNET_DV_ServiceHandle *sh,
     GNUNET_break (0);
     return NULL;
   }
+  LOG (GNUNET_ERROR_TYPE_DEBUG,
+       "Asked to send %u bytes of type %u to %s\n",
+       (unsigned int) msg->size,
+       (unsigned int) msg->type,
+       GNUNET_i2s (target));
+
   th = GNUNET_malloc (sizeof (struct GNUNET_DV_TransmitHandle) +
                      sizeof (struct GNUNET_DV_SendMessage) +
                      ntohs (msg->size));
@@ -593,7 +607,7 @@ GNUNET_DV_send (struct GNUNET_DV_ServiceHandle *sh,
   th->msg = (const struct GNUNET_MessageHeader *) &th[1];
   sm = (struct GNUNET_DV_SendMessage *) &th[1];
   sm->header.type = htons (GNUNET_MESSAGE_TYPE_DV_SEND);
-  sm->header.size = htons (sizeof (struct GNUNET_DV_SendMessage) + 
+  sm->header.size = htons (sizeof (struct GNUNET_DV_SendMessage) +
                           ntohs (msg->size));
   if (0 == sh->uid_gen)
     sh->uid_gen = 1;
@@ -623,8 +637,8 @@ GNUNET_DV_send_cancel (struct GNUNET_DV_TransmitHandle *th)
   struct GNUNET_DV_ServiceHandle *sh = th->sh;
   int ret;
 
-  ret = GNUNET_CONTAINER_multihashmap_remove (sh->send_callbacks,
-                                             &th->target.hashPubKey,
+  ret = GNUNET_CONTAINER_multipeermap_remove (sh->send_callbacks,
+                                             &th->target,
                                              th);
   if (GNUNET_YES != ret)
     GNUNET_CONTAINER_DLL_remove (sh->th_head,