}
}
-
/**
* @brief Checks if there is a sending channel and if it is needed
*
}
}
+/**
+ * @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.
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,
*/
};
+/**
+ * @brief Closure to #valid_peer_iterator
+ */
+struct PeersIteratorCls
+{
+ /**
+ * Iterator function
+ */
+ PeersIterator iterator;
+
+ /**
+ * Closure to iterator
+ */
+ void *cls;
+};
+
/**
* @brief Hashmap of valid peers.
*/
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.
*/
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
*
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.
*