This file is part of GNUnet.
Copyright (C)
- GNUnet is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published
- by the Free Software Foundation; either version 3, or (at your
- option) any later version.
+ GNUnet is free software: you can redistribute it and/or modify it
+ under the terms of the GNU Affero General Public License as published
+ by the Free Software Foundation, either version 3 of the License,
+ or (at your option) any later version.
GNUnet is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ Affero General Public License for more details.
+
+ 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/>.
- You should have received a copy of the GNU General Public License
- along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 59 Temple Place - Suite 330,
- Boston, MA 02111-1307, USA.
+ SPDX-License-Identifier: AGPL3.0-or-later
*/
/**
#ifndef RPS_SAMPLER_H
#define RPS_SAMPLER_H
#include <inttypes.h>
+#include "rps-sampler_common.h"
/**
*/
struct RPS_Sampler;
-
-/**
- * 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.
- * @param ids the PeerIDs that were returned
- * to be freed
+ * A handle to cancel a request.
*/
- typedef void
-(*RPS_sampler_n_rand_peers_ready_cb) (void *cls,
- struct GNUNET_PeerIdentity *ids, uint32_t num_peers);
+struct RPS_SamplerRequestHandle;
/**
* Initialise a tuple of samplers.
*
* @param init_size the size the sampler is initialised with
- * @param id with which all newly created sampler elements are initialised
- * @param ins_cb the callback that will be called on every PeerID that is
- * newly inserted into a sampler element
- * @param ins_cls the closure given to #ins_cb
- * @param rem_cb the callback that will be called on every PeerID that is
- * removed from a sampler element
- * @param rem_cls the closure given to #rem_cb
+ * @param max_round_interval maximum time a round takes
* @return a handle to a sampler that consists of sampler elements.
*/
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);
/**
- * A fuction to update every sampler in the given list
+ * Update every sampler element of this sampler with given peer
*
* @param sampler the sampler to update.
* @param id the PeerID that is put in the sampler
*
* Used to get rid of a PeerID.
*
+ * FIXME: This should also consider currently pending requests
+ * (Pending requests already collect peerids. As long as not all
+ * requested IDs have been collected, they are kept.
+ * Ideally, the @p id should be removed from all pending requests. This
+ * seems quite complicated.)
+ *
* @param sampler the sampler to reinitialise a sampler in.
* @param id the id of the samplers to update.
*/
* #GNUNET_NO if used internally
* @param num_peers the number of peers requested
*/
- void
+struct RPS_SamplerRequestHandle *
RPS_sampler_get_n_rand_peers (struct RPS_Sampler *sampler,
+ uint32_t num_peers,
RPS_sampler_n_rand_peers_ready_cb cb,
- void *cls, uint32_t num_peers, int for_client);
+ void *cls);
+
+/**
+ * Cancle a request issued through #RPS_sampler_n_rand_peers_ready_cb.
+ *
+ * @param req_handle the handle to the request
+ */
+void
+RPS_sampler_request_cancel (struct RPS_SamplerRequestHandle *req_handle);
/**