gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r35267 - gnunet/src/rps


From: gnunet
Subject: [GNUnet-SVN] r35267 - gnunet/src/rps
Date: Sun, 15 Feb 2015 18:20:04 +0100

Author: ch3
Date: 2015-02-15 18:20:04 +0100 (Sun, 15 Feb 2015)
New Revision: 35267

Modified:
   gnunet/src/rps/gnunet-service-rps.c
   gnunet/src/rps/gnunet-service-rps_sampler.c
   gnunet/src/rps/gnunet-service-rps_sampler.h
Log:
- got rid of unneeded code

Modified: gnunet/src/rps/gnunet-service-rps.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps.c 2015-02-15 17:20:00 UTC (rev 35266)
+++ gnunet/src/rps/gnunet-service-rps.c 2015-02-15 17:20:04 UTC (rev 35267)
@@ -609,8 +609,8 @@
 {
   struct PeerContext *peer_ctx = (struct PeerContext *) cls;
 
-  if (NULL != buf ||
-      0 != size)
+  if (NULL != buf
+      && 0 != size)
     peer_is_live (peer_ctx);
 
   //if (NULL != peer_ctx->is_live_task)
@@ -1441,57 +1441,10 @@
 }
 
 
-/**
- * Open a connection to given peer and store channel and mq.
- */
-  void
-insertCB (void *cls, struct RPS_Sampler *sampler,
-          const struct GNUNET_PeerIdentity *id)
-{
-  // We open a channel to be notified when this peer goes down.
-  (void) get_channel (peer_map, id);
-}
-
-
-/**
- * Close the connection to given peer and delete channel and mq
- * if the peer is not anymore in the sampler.
- */
-  void
-removeCB (void *cls, struct RPS_Sampler *sampler,
-          const struct GNUNET_PeerIdentity *id)
-{
-  size_t s;
-  struct PeerContext *ctx;
-
-  s = RPS_sampler_count_id (sampler, id);
-  if ( 1 >= s )
-  {
-    if (GNUNET_YES == GNUNET_CONTAINER_multipeermap_contains (peer_map, id)
-        && 0 != GNUNET_CRYPTO_cmp_peer_identity (id, &own_identity))
-    {
-      ctx = GNUNET_CONTAINER_multipeermap_get (peer_map, id);
-      if (NULL != ctx->send_channel)
-      {
-        if (NULL != ctx->mq)
-        {
-          GNUNET_MQ_destroy (ctx->mq);
-          ctx->mq = NULL;
-        }
-        // may already be freed at shutdown of cadet
-        // maybe this fails at our own channel
-        GNUNET_CADET_channel_destroy (ctx->send_channel);
-        ctx->send_channel = NULL;
-      }
-      // TODO cleanup peer
-      //(void) GNUNET_CONTAINER_multipeermap_remove_all (peer_map, id);
-    }
-  }
-}
-
 static void
 rps_start (struct GNUNET_SERVER_Handle *server);
 
+
 /**
  * This is called from GNUNET_CADET_get_peers().
  *
@@ -1511,7 +1464,8 @@
   struct PeerContext *peer_ctx;
 
   server = (struct GNUNET_SERVER_Handle *) cls;
-  if (0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, peer))
+  if (NULL != peer
+      && 0 != GNUNET_CRYPTO_cmp_peer_identity (&own_identity, peer))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG,
         "Got peer %s (at %p) from CADET (gossip_list_size: %u)\n",
@@ -1890,12 +1844,8 @@
   half_round_interval = GNUNET_TIME_relative_multiply (round_interval, .5);
   max_round_interval = GNUNET_TIME_relative_add (round_interval, 
half_round_interval);
 
-  prot_sampler =   RPS_sampler_init (sampler_size_est_need, max_round_interval,
-      //insertCB, NULL, removeCB, NULL);
-      NULL, NULL, NULL, NULL);
-  client_sampler = RPS_sampler_init (sampler_size_est_need, max_round_interval,
-      //nsertCB, NULL, removeCB, NULL);
-      NULL, NULL, NULL, NULL);
+  prot_sampler =   RPS_sampler_init (sampler_size_est_need, 
max_round_interval);
+  client_sampler = RPS_sampler_init (sampler_size_est_need, 
max_round_interval);
 
   /* Initialise push and pull maps */
   push_list = NULL;

Modified: gnunet/src/rps/gnunet-service-rps_sampler.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler.c 2015-02-15 17:20:00 UTC (rev 
35266)
+++ gnunet/src/rps/gnunet-service-rps_sampler.c 2015-02-15 17:20:04 UTC (rev 
35267)
@@ -104,6 +104,7 @@
   uint32_t num_change;
 };
 
+
 /**
  * Sampler with its own array of SamplerElements
  */
@@ -126,26 +127,6 @@
    * Used in the context of RPS
    */
   struct GNUNET_TIME_Relative max_round_interval;
-
-  /**
-   * Callback to be called when a peer gets inserted into a sampler.
-   */
-  RPS_sampler_insert_cb insert_cb;
-
-  /**
-   * Closure to the insert_cb.
-   */
-  void *insert_cls;
-
-  /**
-   * Callback to be called when a peer gets inserted into a sampler.
-   */
-  RPS_sampler_remove_cb remove_cb;
-
-  /**
-   * Closure to the remove_cb.
-   */
-  void *remove_cls;
 };
 
 /**
@@ -344,15 +325,13 @@
 static void
 RPS_sampler_elem_next (struct RPS_SamplerElement *s_elem,
                        struct RPS_Sampler *sampler,
-                       const struct GNUNET_PeerIdentity *other,
-                       RPS_sampler_insert_cb insert_cb, void *insert_cls,
-                       RPS_sampler_remove_cb remove_cb, void *remove_cls)
+                       const struct GNUNET_PeerIdentity *other)
 {
   struct GNUNET_HashCode other_hash;
 
   s_elem->num_peers++;
 
-  if ( 0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id)) )
+  if (0 == GNUNET_CRYPTO_cmp_peer_identity (other, &(s_elem->peer_id)))
   {
     LOG (GNUNET_ERROR_TYPE_DEBUG, "         Got PeerID %s\n",
         GNUNET_i2s (other));
@@ -366,50 +345,31 @@
         sizeof(struct GNUNET_PeerIdentity),
         &other_hash);
 
-    if ( EMPTY == s_elem->is_empty )
+    if (EMPTY == s_elem->is_empty)
     {
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "Got PeerID %s; Simply accepting (was 
empty previously).\n",
-          GNUNET_i2s(other));
+      LOG (GNUNET_ERROR_TYPE_DEBUG,
+           "Got PeerID %s; Simply accepting (was empty previously).\n",
+           GNUNET_i2s(other));
       s_elem->peer_id = *other;
       s_elem->peer_id_hash = other_hash;
 
-      if (NULL != insert_cb)
-        insert_cb (insert_cls, sampler, &(s_elem->peer_id));
-
       s_elem->num_change++;
     }
-    else if ( 0 > GNUNET_CRYPTO_hash_cmp (&other_hash, &s_elem->peer_id_hash) )
+    else if (0 > GNUNET_CRYPTO_hash_cmp (&other_hash, &s_elem->peer_id_hash))
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG, "           Got PeerID %s\n",
           GNUNET_i2s (other));
       LOG (GNUNET_ERROR_TYPE_DEBUG, "Discarding old PeerID %s\n",
           GNUNET_i2s (&s_elem->peer_id));
 
-      if ( NULL != remove_cb )
-      {
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing old PeerID %s with the remove 
callback.\n",
-            GNUNET_i2s (&s_elem->peer_id));
-        remove_cb (remove_cls, sampler, &s_elem->peer_id);
-      }
-
-      s_elem->peer_id = *other;
-      s_elem->peer_id_hash = other_hash;
-
-      if ( NULL != insert_cb )
-      {
-        LOG (GNUNET_ERROR_TYPE_DEBUG, "Inserting new PeerID %s with the insert 
callback.\n",
-            GNUNET_i2s (&s_elem->peer_id));
-        insert_cb (insert_cls, sampler, &s_elem->peer_id);
-      }
-
       s_elem->num_change++;
     }
     else
     {
       LOG (GNUNET_ERROR_TYPE_DEBUG, "        Got PeerID %s\n",
-          GNUNET_i2s(other));
+          GNUNET_i2s (other));
       LOG (GNUNET_ERROR_TYPE_DEBUG, "Keeping old PeerID %s\n",
-          GNUNET_i2s(&s_elem->peer_id));
+          GNUNET_i2s (&s_elem->peer_id));
     }
   }
   s_elem->is_empty = NOT_EMPTY;
@@ -440,7 +400,6 @@
 {
   unsigned int old_size;
   uint32_t i;
-  struct RPS_SamplerElement **rem_list;
 
   // TODO check min and max size
 
@@ -449,10 +408,6 @@
   if (old_size > new_size)
   { /* Shrinking */
     /* Temporary store those to properly call the removeCB on those later */
-    rem_list = GNUNET_malloc ((old_size - new_size) * sizeof (struct 
RPS_SamplerElement *));
-    memcpy (rem_list,
-        &sampler->sampler_elements[new_size],
-        (old_size - new_size) * sizeof (struct RPS_SamplerElement *));
 
     LOG (GNUNET_ERROR_TYPE_DEBUG, "Shrinking sampler %d -> %d\n", old_size, 
new_size);
     GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, 
new_size);
@@ -460,14 +415,6 @@
         "sampler->sampler_elements now points to %p\n",
         sampler->sampler_elements);
 
-    for (i = 0 ; i < old_size - new_size ; i++)
-    {/* Remove unneeded rest */
-      LOG (GNUNET_ERROR_TYPE_DEBUG, "Removing %" PRIX32 ". sampler\n", i);
-      if (NULL != sampler->remove_cb)
-        sampler->remove_cb (sampler->remove_cls, sampler, 
&rem_list[i]->peer_id);
-      GNUNET_free (rem_list[i]);
-    }
-    GNUNET_free (rem_list);
   }
   else if (old_size < new_size)
   { /* Growing */
@@ -480,8 +427,6 @@
     for ( i = old_size ; i < new_size ; i++ )
     { /* Add new sampler elements */
       sampler->sampler_elements[i] = RPS_sampler_elem_create ();
-      if (NULL != sampler->insert_cb)
-        sampler->insert_cb (sampler->insert_cls, sampler, 
&sampler->sampler_elements[i]->peer_id);
       LOG (GNUNET_ERROR_TYPE_DEBUG,
           "Added %" PRIX32 ". sampler, now pointing to %p, contains %s\n",
           i, &sampler->sampler_elements[i], GNUNET_i2s 
(&sampler->sampler_elements[i]->peer_id));
@@ -539,9 +484,7 @@
  */
 struct RPS_Sampler *
 RPS_sampler_init (size_t init_size,
-    struct GNUNET_TIME_Relative max_round_interval,
-    RPS_sampler_insert_cb ins_cb, void *ins_cls,
-    RPS_sampler_remove_cb rem_cb, void *rem_cls)
+    struct GNUNET_TIME_Relative max_round_interval)
 {
   struct RPS_Sampler *sampler;
   //uint32_t i;
@@ -554,10 +497,6 @@
   sampler->sampler_size = 0;
   sampler->sampler_elements = NULL;
   sampler->max_round_interval = max_round_interval;
-  sampler->insert_cb = ins_cb;
-  sampler->insert_cls = ins_cls;
-  sampler->remove_cb = rem_cb;
-  sampler->remove_cls = rem_cls;
   //sampler->sampler_elements = GNUNET_new_array(init_size, struct 
GNUNET_PeerIdentity);
   //GNUNET_array_grow (sampler->sampler_elements, sampler->sampler_size, 
min_size);
   RPS_sampler_resize (sampler, init_size);
@@ -583,9 +522,8 @@
 
   for ( i = 0 ; i < sampler->sampler_size ; i++ )
     RPS_sampler_elem_next (sampler->sampler_elements[i],
-        sampler, id,
-        sampler->insert_cb, sampler->insert_cls,
-        sampler->remove_cb, sampler->remove_cls);
+                           sampler,
+                           id);
 }
 
 
@@ -705,7 +643,8 @@
     tmp_id = gpc->sampler->sampler_elements[client_get_index]->peer_id;
     RPS_sampler_elem_reinit (gpc->sampler->sampler_elements[client_get_index]);
     RPS_sampler_elem_next (gpc->sampler->sampler_elements[client_get_index],
-                           gpc->sampler, &tmp_id, NULL, NULL, NULL, NULL);
+                           gpc->sampler,
+                           &tmp_id);
 
     /* Cycle the #client_get_index one step further */
     if ( client_get_index == gpc->sampler->sampler_size - 1 )

Modified: gnunet/src/rps/gnunet-service-rps_sampler.h
===================================================================
--- gnunet/src/rps/gnunet-service-rps_sampler.h 2015-02-15 17:20:00 UTC (rev 
35266)
+++ gnunet/src/rps/gnunet-service-rps_sampler.h 2015-02-15 17:20:04 UTC (rev 
35267)
@@ -36,28 +36,6 @@
 
 
 /**
- * Callback that is called when a new PeerID is inserted into a sampler.
- *
- * @param cls the closure given alongside this function.
- * @param id the PeerID that is inserted
- */
-typedef void
-(*RPS_sampler_insert_cb) (void *cls,
-    struct RPS_Sampler *sampler,
-    const struct GNUNET_PeerIdentity *id);
-
-/**
- * Callback that is called when a new PeerID is removed from a sampler.
- *
- * @param cls the closure given alongside this function.
- * @param id the PeerID that is removed
- */
-typedef void
-(*RPS_sampler_remove_cb) (void *cls,
-    struct RPS_Sampler *sampler,
-    const struct GNUNET_PeerIdentity *id);
-
-/**
  * Callback that is called from _get_n_rand_peers() when the PeerIDs are ready.
  *
  * @param cls the closure given alongside this function.
@@ -104,9 +82,7 @@
  */
 struct RPS_Sampler *
 RPS_sampler_init (size_t init_size,
-    struct GNUNET_TIME_Relative max_round_interval,
-    RPS_sampler_insert_cb ins_cb, void *ins_cls,
-    RPS_sampler_remove_cb rem_cb, void *rem_cls);
+    struct GNUNET_TIME_Relative max_round_interval);
 
 
 /**




reply via email to

[Prev in Thread] Current Thread [Next in Thread]