REST: nothing triggers rest
[oweals/gnunet.git] / src / ats / plugin_ats2_simple.c
index 6faf8ad7ca3ed428eff1fb24c34b8caa9d7ac3ee..35a256f32bb5e8f1bff002a7cf6c46ae1f11cbd4 100644 (file)
@@ -14,6 +14,8 @@
 
  You should have received a copy of the GNU Affero General Public License
  along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+     SPDX-License-Identifier: AGPL3.0-or-later
  */
 /**
  * @file ats/plugin_ats2_simple.c
@@ -490,15 +492,14 @@ watch_cb (void *cls,
   struct GNUNET_TIME_Absolute expiration;
   struct Hello *hello;
 
-  if (0 != memcmp (&p->pid,
-                   &record->peer,
-                   sizeof (struct GNUNET_PeerIdentity)))
+  if (0 != GNUNET_memcmp (&p->pid,
+                   &record->peer))
   {
     GNUNET_break (0);
     return;
   }
   if (0 != strcmp (record->key,
-                   GNUNET_HELLO_PEERSTORE_KEY))
+                   GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY))
   {
     GNUNET_break (0);
     return;
@@ -588,7 +589,7 @@ peer_add (struct SimpleHandle *h,
   p->wc = GNUNET_PEERSTORE_watch (h->ps,
                                   "transport",
                                   &p->pid,
-                                  GNUNET_HELLO_PEERSTORE_KEY,
+                                  GNUNET_PEERSTORE_TRANSPORT_URLADDRESS_KEY,
                                   &watch_cb,
                                   p);
   GNUNET_assert (GNUNET_YES ==
@@ -753,6 +754,8 @@ update_counters (void *cls,
   struct GNUNET_ATS_SessionHandle *best[GNUNET_MQ_PREFERENCE_COUNT];
 
   (void) pid;
+  if (NULL == peer->sh_head)
+    return GNUNET_YES; /* no available session, cannot allocate bandwidth */
   memset (best,
           0,
           sizeof (best));
@@ -821,12 +824,15 @@ update_counters (void *cls,
   }
   /* for first round, assign target bandwidth simply to sum of
      requested bandwidth */
-  for (enum GNUNET_MQ_PreferenceKind pk = 0;
+  for (enum GNUNET_MQ_PreferenceKind pk = 1 /* skip GNUNET_MQ_PREFERENCE_NONE */;
        pk < GNUNET_MQ_PREFERENCE_COUNT;
        pk++)
   {
-    enum GNUNET_NetworkType nt = best[pk]->data->prop.nt;
+    const struct GNUNET_ATS_SessionData *data = best[pk]->data;
+    enum GNUNET_NetworkType nt;
 
+    GNUNET_assert (NULL != data);
+    nt = data->prop.nt;
     best[pk]->target_out = GNUNET_MIN (peer->bw_by_pk[pk],
                                        MIN_BANDWIDTH_PER_SESSION);
     c->bw_out_by_nt[nt] += (uint64_t) (best[pk]->target_out - MIN_BANDWIDTH_PER_SESSION);
@@ -970,6 +976,7 @@ simple_session_add (void *cls,
   struct GNUNET_ATS_SessionHandle *sh;
 
   /* setup session handle */
+  GNUNET_assert (NULL != data);
   if (NULL == address)
     alen = 0;
   else
@@ -1005,7 +1012,7 @@ simple_session_add (void *cls,
     sh->hello = hello;
   }
   update (h);
-  return NULL;
+  return sh;
 }
 
 
@@ -1024,6 +1031,7 @@ simple_session_update (void *cls,
 {
   struct SimpleHandle *h = cls;
 
+  GNUNET_assert (NULL != data);
   sh->data = data; /* this statement should not really do anything... */
   update (h);
 }