fixes
[oweals/gnunet.git] / src / dv / gnunet-service-dv.c
index 28362b82f378d0e44cac6a18d9d47b12b9c07183..844e44b6ffb4573962a6cdb5b9920bb3655c669b 100644 (file)
@@ -864,9 +864,16 @@ try_core_send (void *cls,
     return; /* Message send already in progress */
 
   if ((pending != NULL) && (coreAPI != NULL))
-    core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI, pending->importance, pending->timeout, &pending->recipient, pending->msg_size, &core_transmit_notify, NULL);
+    core_transmit_handle = GNUNET_CORE_notify_transmit_ready (coreAPI,
+                                                             GNUNET_YES,
+                                                             pending->importance,
+                                                             pending->timeout, 
+                                                             &pending->recipient,
+                                                             pending->msg_size,
+                                                             &core_transmit_notify, NULL);
 }
 
+
 /**
  * Function called to notify a client about the socket
  * being ready to queue more data.  "buf" will be
@@ -939,7 +946,7 @@ size_t core_transmit_notify (void *cls,
 
   GNUNET_SCHEDULER_add_now(&try_core_send, NULL);
   /*if (reply != NULL)
-    core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL);*/
+    core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES,  reply->importance, reply->timeout, &reply->recipient, reply->msg_size, &core_transmit_notify, NULL);*/
 
   return off;
 }
@@ -1347,8 +1354,7 @@ get_atsi_latency (const struct GNUNET_TRANSPORT_ATS_Information *atsi)
  * @param cls closure
  * @param peer peer which sent the message (immediate sender)
  * @param message the message
- * @param latency the latency of the connection we received the message from
- * @param distance the distance to the immediate peer
+ * @param atsi transport ATS information (latency, distance, etc.)
  */
 static int 
 handle_dv_data_message (void *cls,
@@ -1625,7 +1631,7 @@ neighbor_send_task (void *cls,
   p2p_dv_MESSAGE_NeighborInfo *message;
   struct PendingMessage *pending_message;
 
-  if (tc->reason == GNUNET_SCHEDULER_REASON_SHUTDOWN)
+  if ( (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN) != 0)
     {
 #if DEBUG_DV_GOSSIP
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -1705,7 +1711,7 @@ neighbor_send_task (void *cls,
 
       GNUNET_SCHEDULER_add_now(try_core_send, NULL);
       /*if (core_transmit_handle == NULL)
-        core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);*/
+        core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES,  default_dv_priority, GNUNET_TIME_relative_get_forever(), &to->identity, sizeof(p2p_dv_MESSAGE_NeighborInfo), &core_transmit_notify, NULL);*/
 
     }
 
@@ -2004,8 +2010,8 @@ distant_neighbor_free (struct DistantNeighbor *referee)
       GNUNET_CONTAINER_DLL_remove (referrer->referee_head,
                          referrer->referee_tail, referee);
     }
-  GNUNET_CONTAINER_heap_remove_node (neighbor_max_heap, referee->max_loc);
-  GNUNET_CONTAINER_heap_remove_node (neighbor_min_heap, referee->min_loc);
+  GNUNET_CONTAINER_heap_remove_node (referee->max_loc);
+  GNUNET_CONTAINER_heap_remove_node (referee->min_loc);
   GNUNET_CONTAINER_multihashmap_remove_all (extended_neighbors,
                                     &referee->identity.hashPubKey);
   GNUNET_free_non_null (referee->pkey);
@@ -2081,7 +2087,7 @@ static int schedule_disconnect_messages (void *cls,
 
   GNUNET_SCHEDULER_add_now(try_core_send, NULL);
   /*if (core_transmit_handle == NULL)
-    core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);*/
+    core_transmit_handle = GNUNET_CORE_notify_transmit_ready(coreAPI, GNUNET_YES, default_dv_priority, GNUNET_TIME_relative_get_forever(), &notify->identity, sizeof(p2p_dv_MESSAGE_Disconnect), &core_transmit_notify, NULL);*/
 
   return GNUNET_YES;
 }
@@ -2807,11 +2813,13 @@ add_all_direct_neighbors (void *cls,
  * @param cls closure
  * @param peer id of the peer, NULL for last call
  * @param hello hello message for the peer (can be NULL)
+ * @param err_msg NULL if successful, otherwise contains error message
  */
 static void
 process_peerinfo (void *cls,
                   const struct GNUNET_PeerIdentity *peer,
-                  const struct GNUNET_HELLO_Message *hello)
+                  const struct GNUNET_HELLO_Message *hello,
+                  const char *err_msg)
 {
   struct PeerIteratorContext *peerinfo_iterator = cls;
   struct DirectNeighbor *neighbor = peerinfo_iterator->neighbor;
@@ -2820,7 +2828,12 @@ process_peerinfo (void *cls,
   char *neighbor_pid;
 #endif
   int sent;
-
+  if (err_msg != NULL)
+  {
+         GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+                     _("Error in communication with PEERINFO service\n"));
+         /* return; */
+  }
   if (peer == NULL)
     {
       if (distant->pkey == NULL)
@@ -2897,6 +2910,10 @@ handle_core_connect (void *cls,
 #endif
   uint32_t distance;
 
+  /* Check for connect to self message */
+  if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+    return;
+
   distance = get_atsi_distance (atsi);
   if ((distance == DIRECT_NEIGHBOR_COST) &&
       (GNUNET_CONTAINER_multihashmap_get(direct_neighbors, &peer->hashPubKey) == NULL))
@@ -2969,6 +2986,10 @@ void handle_core_disconnect (void *cls,
               "%s: Receives core peer disconnect message!\n", "dv");
 #endif
 
+  /* Check for disconnect from self message */
+  if (0 == memcmp(&my_identity, peer, sizeof(struct GNUNET_PeerIdentity)))
+    return;
+
   neighbor =
     GNUNET_CONTAINER_multihashmap_get (direct_neighbors, &peer->hashPubKey);