-getting rid of silly, stupid, useless, often wrong DEFAULTCONFIG setting
[oweals/gnunet.git] / src / ats / ats_api_scheduling.c
index 398c8b2d0f5570f4598b490859eb6d32eb592608..db71d1e1e95a3fafb69e4838e670d3240b609900 100644 (file)
@@ -346,6 +346,22 @@ find_session (struct GNUNET_ATS_SchedulingHandle *sh, uint32_t session_id,
     sh->reconnect = GNUNET_YES;
     return NULL;
   }
+  /* This check exploits the fact that first field of a session object
+   * is peer identity.
+   */
+  if (0 !=
+      memcmp (peer, sh->session_array[session_id].session,
+              sizeof (struct GNUNET_PeerIdentity)))
+  {
+    GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "ats-scheduling-api",
+              "Session %p belongs to peer `%s'\n",
+              sh->session_array[session_id].session, GNUNET_i2s_full ((struct GNUNET_PeerIdentity *)sh->session_array[session_id].session));
+/*
+    GNUNET_break (0);
+    sh->reconnect = GNUNET_YES;
+    return NULL;
+*/
+  }
   return sh->session_array[session_id].session;
 }
 
@@ -1049,7 +1065,7 @@ GNUNET_ATS_suggest_address_cancel (struct GNUNET_ATS_SchedulingHandle *sh,
  *
  * @param sh handle
  * @param address the address
- * @param session session handle (if available)
+ * @param session session handle, can be NULL
  * @param ats performance data for the address
  * @param ats_count number of performance records in 'ats'
  * @return GNUNET_OK on success, GNUNET_SYSERR on error
@@ -1075,11 +1091,6 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
     GNUNET_break (0);
     return GNUNET_SYSERR;
   }
-  if ((address == NULL) && (session == NULL))
-  {
-    GNUNET_break (0);
-    return GNUNET_SYSERR;
-  }
 
   namelen =
       (address->transport_name ==
@@ -1134,7 +1145,8 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
   memcpy (am, ats, ats_count * sizeof (struct GNUNET_ATS_Information));
   pm = (char *) &am[ats_count];
   memcpy (pm, address->address, address->address_length);
-  memcpy (&pm[address->address_length], address->transport_name, namelen);
+  if (NULL != address->transport_name)
+       memcpy (&pm[address->address_length], address->transport_name, namelen);
   GNUNET_CONTAINER_DLL_insert_tail (sh->pending_head, sh->pending_tail, p);
   do_transmit (sh);
   return GNUNET_OK;
@@ -1152,7 +1164,7 @@ GNUNET_ATS_address_add (struct GNUNET_ATS_SchedulingHandle *sh,
  *
  * @param sh handle
  * @param address the address
- * @param session session handle (if available)
+ * @param session session handle, can be NULL
  * @param ats performance data for the address
  * @param ats_count number of performance records in 'ats'
  */
@@ -1176,11 +1188,6 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
     GNUNET_break (0);
     return;
   }
-  if ((address == NULL) && (session == NULL))
-  {
-    GNUNET_break (0);
-    return;
-  }
 
   namelen =
       (address->transport_name ==
@@ -1247,7 +1254,7 @@ GNUNET_ATS_address_update (struct GNUNET_ATS_SchedulingHandle *sh,
  *
  * @param sh handle
  * @param address the address
- * @param session session handle
+ * @param session session handle, can be NULL
  * @param in_use GNUNET_YES if this address is now used, GNUNET_NO
  * if address is not used any more
  */
@@ -1327,7 +1334,7 @@ GNUNET_ATS_address_in_use (struct GNUNET_ATS_SchedulingHandle *sh,
  *
  * @param sh handle
  * @param address the address
- * @param session session handle that is no longer valid
+ * @param session session handle that is no longer valid, can be NULL
  */
 void
 GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
@@ -1341,6 +1348,12 @@ GNUNET_ATS_address_destroyed (struct GNUNET_ATS_SchedulingHandle *sh,
   size_t msize;
   uint32_t s = 0;
 
+  if (address == NULL)
+  {
+    GNUNET_break (0);
+    return;
+  }
+
   GNUNET_assert (address->transport_name != NULL);
   namelen = strlen (address->transport_name) + 1;
   GNUNET_assert (namelen > 1);