reduce loop counters to more practical levels
[oweals/gnunet.git] / src / include / gnunet_rps_service.h
1 /*
2       This file is part of GNUnet
3       Copyright (C)
4
5       GNUnet is free software; you can redistribute it and/or modify
6       it under the terms of the GNU General Public License as published
7       by the Free Software Foundation; either version 3, or (at your
8       option) any later version.
9
10       GNUnet is distributed in the hope that it will be useful, but
11       WITHOUT ANY WARRANTY; without even the implied warranty of
12       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13       General Public License for more details.
14
15       You should have received a copy of the GNU General Public License
16       along with GNUnet; see the file COPYING.  If not, write to the
17       Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18       Boston, MA 02110-1301, USA.
19  */
20
21 /**
22  * @author Julius Bünger
23  *
24  * @file
25  * API to the rps service
26  *
27  * @defgroup rps  RPS service
28  * Random Peer Sampling
29  * @{
30  */
31 #ifndef GNUNET_RPS_SERVICE_H
32 #define GNUNET_RPS_SERVICE_H
33
34 #ifdef __cplusplus
35 extern "C"
36 {
37 #if 0                           /* keep Emacsens' auto-indent happy */
38 }
39 #endif
40 #endif
41
42 /**
43  * Version of the rps API.
44  */
45 #define GNUNET_RPS_VERSION 0x00000000
46
47 /**
48  * Handle for the random peer sampling service
49  */
50 struct GNUNET_RPS_Handle;
51
52 /**
53  * Handle for one request to the rps service
54  */
55 struct GNUNET_RPS_Request_Handle;
56
57 /**
58  * Callback called when requested random peers are available.
59  *
60  * @param cls the closure given with the request
61  * @param num_peers the number of peers returned
62  * @param peers array with num_peers PeerIDs
63  */
64 typedef void (* GNUNET_RPS_NotifyReadyCB) (void *cls,
65     uint64_t num_peers,
66     const struct GNUNET_PeerIdentity *peers);
67
68 /**
69  * Callback called when view was updated
70  *
71  * @param num_peers the number of peers returned
72  * @param peers array with num_peers PeerIDs
73  */
74 typedef void (* GNUNET_RPS_ViewUpdateCB) (void *cls,
75     uint64_t num_peers,
76     const struct GNUNET_PeerIdentity *peers);
77
78 /**
79  * Connect to the rps service
80  *
81  * @param cfg configuration to use
82  * @return handle to the rps service
83  */
84   struct GNUNET_RPS_Handle *
85 GNUNET_RPS_connect (const struct GNUNET_CONFIGURATION_Handle *cfg);
86
87 /**
88  * Request n random peers.
89  *
90  * This does exacly the same as GNUNET_RPS_request_peers_single_call
91  * but needs a GNUNET_RPS_Handle.
92  * This exists only for other parts of GNUnet that expect having to
93  * (dis)connect from/to a service.
94  *
95  * @param h handle to the rps service
96  * @param n number of random peers to return
97  * @param ready_cb the callback to be called when the peers are available
98  * @param cls a closure that will be given to the callback
99  * @return handle to this request
100  */
101   struct GNUNET_RPS_Request_Handle *
102 GNUNET_RPS_request_peers (struct GNUNET_RPS_Handle *h, uint32_t n,
103                           GNUNET_RPS_NotifyReadyCB ready_cb,
104                           void *cls);
105
106 /**
107  * Seed rps service with peerIDs.
108  *
109  * @param h handle to the rps service
110  * @param n number of peers to seed
111  * @param ids the ids of the peers seeded
112  */
113   void
114 GNUNET_RPS_seed_ids (struct GNUNET_RPS_Handle *h, uint32_t n,
115                      const struct GNUNET_PeerIdentity * ids);
116
117 /**
118  * Cancle an issued request.
119  *
120  * @param rh handle of the pending request to be canceled
121  */
122   void
123 GNUNET_RPS_request_cancel (struct GNUNET_RPS_Request_Handle *rh);
124
125
126 #ifdef ENABLE_MALICIOUS
127 /**
128  * Turn RPS service to act malicious.
129  *
130  * @param h handle to the rps service
131  * @param type which type of malicious peer to turn to.
132  *             0 Don't act malicious at all
133  *             1 Try to maximise representation
134  *             2 Try to partition the network
135  *               (isolate one peer from the rest)
136  * @param n number of @a ids
137  * @param ids the ids of the malicious peers
138  *            if @type is 2 the last id is the id of the
139  *            peer to be isolated from the rest
140  */
141   void
142 GNUNET_RPS_act_malicious (struct GNUNET_RPS_Handle *h,
143                           uint32_t type,
144                           uint32_t num_peers,
145                           const struct GNUNET_PeerIdentity *ids,
146                           const struct GNUNET_PeerIdentity *target_peer);
147 #endif /* ENABLE_MALICIOUS */
148
149 /* Get internals for debugging/profiling purposes */
150
151 /**
152  * Request updates of view
153  *
154  * @param rps_handle handle to the rps service
155  * @param num_req_peers number of peers we want to receive
156  *        (0 for infinite updates)
157  * @param cls a closure that will be given to the callback
158  * @param ready_cb the callback called when the peers are available
159  */
160 void
161 GNUNET_RPS_view_request (struct GNUNET_RPS_Handle *rps_handle,
162                          uint32_t num_updates,
163                          GNUNET_RPS_ViewUpdateCB view_update_cb,
164                          void *cls);
165
166 /**
167  * Disconnect from the rps service
168  *
169  * @param h the handle to the rps service
170  */
171   void
172 GNUNET_RPS_disconnect (struct GNUNET_RPS_Handle *h);
173
174
175 #if 0                           /* keep Emacsens' auto-indent happy */
176 {
177 #endif
178 #ifdef __cplusplus
179 }
180 #endif
181
182 #endif
183
184 /** @} */  /* end of group */