gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r37172 - gnunet/src/rps
Date: Sat, 14 May 2016 21:41:37 +0200

Author: ch3
Date: 2016-05-14 21:41:37 +0200 (Sat, 14 May 2016)
New Revision: 37172

Modified:
   gnunet/src/rps/gnunet-service-rps.c
   gnunet/src/rps/gnunet-service-rps_peers.c
   gnunet/src/rps/gnunet-service-rps_peers.h
Log:
rps: use stored peers at startup

Modified: gnunet/src/rps/gnunet-service-rps.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps.c 2016-05-14 17:29:48 UTC (rev 37171)
+++ gnunet/src/rps/gnunet-service-rps.c 2016-05-14 19:41:37 UTC (rev 37172)
@@ -698,7 +698,6 @@
   }
 }
 
-
 /**
  * @brief Checks if there is a sending channel and if it is needed
  *
@@ -2019,7 +2018,32 @@
   }
 }
 
+/**
+ * @brief Iterator function over stored, valid peers.
+ *
+ * We initialise the sampler with those.
+ *
+ * @param cls the closure
+ * @param peer the peer id
+ * @return #GNUNET_YES if we should continue to
+ *         iterate,
+ *         #GNUNET_NO if not.
+ */
+static int
+valid_peers_iterator (void *cls,
+                      const struct GNUNET_PeerIdentity *peer)
+{
+  if (NULL != peer)
+  {
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+         "Got stored, valid peer %s\n",
+         GNUNET_i2s (peer));
+    got_peer (peer);
+  }
+  return GNUNET_YES;
+}
 
+
 /**
  * Iterator over peers from peerinfo.
  *
@@ -2316,6 +2340,8 @@
   GNUNET_CADET_get_peers (cadet_handle, &init_peer_cb, NULL);
   // TODO send push/pull to each of those peers?
   // TODO read stored valid peers from last run
+  LOG (GNUNET_ERROR_TYPE_DEBUG, "Requesting stored valid peers\n");
+  Peers_get_valid_peers (valid_peers_iterator, NULL);
 
   peerinfo_notify_handle = GNUNET_PEERINFO_notify (cfg,
                                                    GNUNET_NO,

Modified: gnunet/src/rps/gnunet-service-rps_peers.c
===================================================================
--- gnunet/src/rps/gnunet-service-rps_peers.c   2016-05-14 17:29:48 UTC (rev 
37171)
+++ gnunet/src/rps/gnunet-service-rps_peers.c   2016-05-14 19:41:37 UTC (rev 
37172)
@@ -204,6 +204,22 @@
 };
 
 /**
+ * @brief Closure to #valid_peer_iterator
+ */
+struct PeersIteratorCls
+{
+  /**
+   * Iterator function
+   */
+  PeersIterator iterator;
+
+  /**
+   * Closure to iterator
+   */
+  void *cls;
+};
+
+/**
  * @brief Hashmap of valid peers.
  */
 static struct GNUNET_CONTAINER_MultiPeerMap *valid_peers;
@@ -919,9 +935,55 @@
   GNUNET_CONTAINER_multipeermap_destroy (valid_peers);
 }
 
-// TODO store valid peers
 
 /**
+ * Iterator over #valid_peers hash map entries.
+ *
+ * @param cls closure - unused
+ * @param peer current peer id
+ * @param value value in the hash map - unused
+ * @return #GNUNET_YES if we should continue to
+ *         iterate,
+ *         #GNUNET_NO if not.
+ */
+static int
+valid_peer_iterator (void *cls,
+                     const struct GNUNET_PeerIdentity *peer,
+                     void *value)
+{
+  struct PeersIteratorCls *it_cls = cls;
+
+  return it_cls->iterator (it_cls->cls,
+                           peer);
+}
+
+
+/**
+ * @brief Get all currently known, valid peer ids.
+ *
+ * @param it function to call on each peer id
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ *         #GNUNET_SYSERR if it aborted iteration
+ */
+int
+Peers_get_valid_peers (PeersIterator iterator,
+                       void *it_cls)
+{
+  struct PeersIteratorCls *cls;
+  int ret;
+
+  cls = GNUNET_new (struct PeersIteratorCls);
+  cls->iterator = iterator;
+  cls->cls = it_cls;
+  ret = GNUNET_CONTAINER_multipeermap_iterate (valid_peers,
+                                               valid_peer_iterator,
+                                               cls);
+  GNUNET_free (cls);
+  return ret;
+}
+
+/**
  * @brief Add peer to known peers.
  *
  * This function is called on new peer_ids from 'external' sources

Modified: gnunet/src/rps/gnunet-service-rps_peers.h
===================================================================
--- gnunet/src/rps/gnunet-service-rps_peers.h   2016-05-14 17:29:48 UTC (rev 
37171)
+++ gnunet/src/rps/gnunet-service-rps_peers.h   2016-05-14 19:41:37 UTC (rev 
37172)
@@ -100,6 +100,19 @@
 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
 
 /**
+ * @brief Iterator over valid peers.
+ *
+ * @param cls closure
+ * @param peer current public peer id
+ * @return #GNUNET_YES if we should continue to
+ *         iterate,
+ *         #GNUNET_NO if not.
+ */
+typedef int
+(*PeersIterator) (void *cls,
+                  const struct GNUNET_PeerIdentity *peer);
+
+/**
  * @brief Initialise storage of peers
  *
  * @param fn_valid_peers filename of the file used to store valid peer ids
@@ -117,7 +130,20 @@
 void
 Peers_terminate ();
 
+
 /**
+ * @brief Get all currently known, valid peer ids.
+ *
+ * @param it function to call on each peer id
+ * @param it_cls extra argument to @a it
+ * @return the number of key value pairs processed,
+ *         #GNUNET_SYSERR if it aborted iteration
+ */
+int
+Peers_get_valid_peers (PeersIterator iterator,
+                       void *it_cls);
+
+/**
  * @brief Add peer to known peers.
  *
  * This function is called on new peer_ids from 'external' sources




reply via email to

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