fix RPS service: Provide closure for view insertion
[oweals/gnunet.git] / src / rps / gnunet-service-rps_view.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 it
6      under the terms of the GNU Affero General Public License as published
7      by the Free Software Foundation, either version 3 of the License,
8      or (at your 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      Affero General Public License for more details.
14     
15      You should have received a copy of the GNU Affero General Public License
16      along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /**
20  * @file rps/gnunet-service-rps_view.h
21  * @brief wrapper around the "local view"
22  * @author Julius Bünger
23  */
24 #include "gnunet_util_lib.h"
25 #include <inttypes.h>
26
27 struct View;
28
29 /**
30  * Create an empty view.
31  *
32  * @param len the maximum length for the view
33  * @return The newly created view
34  */
35 struct View *
36 View_create (unsigned int len);
37
38
39 /**
40  * Change length of view
41  *
42  * If size is decreased, peers with higher indices are removed.
43  *
44  * @param view The view that is changed
45  * @param len the (maximum) length for the view
46  */
47 void
48 View_change_len (struct View *view,
49                  unsigned int len);
50
51 /**
52  * Get the view as an array
53  *
54  * @return the view in array representation
55  */
56 const struct GNUNET_PeerIdentity *
57 View_get_as_array (const struct View *view);
58
59
60 /**
61  * Get the size of the view
62  *
63  * @param view The view of which the size should be returned
64  * @return current number of actually contained peers
65  */
66 unsigned int
67 View_size (const struct View *view);
68
69
70 /**
71  * Insert peer into the view
72  *
73  * @param view The view to put the peer into
74  * @param peer the peer to insert
75  *
76  * @return GNUNET_OK if peer was actually inserted
77  *         GNUNET_NO if peer was not inserted
78  */
79 int
80 View_put (struct View *view,
81           const struct GNUNET_PeerIdentity *peer);
82
83
84 /**
85  * Check whether view contains a peer
86  *
87  * @param view The which is checked for a peer
88  * @param peer the peer to check for
89  *
90  * @return GNUNET_OK if view contains peer
91  *         GNUNET_NO otherwise
92  */
93 int
94 View_contains_peer (const struct View *view,
95                     const struct GNUNET_PeerIdentity *peer);
96
97
98 /**
99  * Remove peer from view
100  *
101  * @param view The view of which to remove the peer
102  * @param peer the peer to remove
103  *
104  * @return GNUNET_OK if view contained peer and removed it successfully
105  *         GNUNET_NO if view does not contain peer
106  */
107 int
108 View_remove_peer (struct View *view,
109                   const struct GNUNET_PeerIdentity *peer);
110
111
112 /**
113  * Get a peer by index
114  *
115  * @param view the view of which to get the peer
116  * @param index the index of the peer to get
117  *
118  * @return peer to the corresponding index.
119  *         NULL if this index is not known
120  */
121 const struct GNUNET_PeerIdentity *
122 View_get_peer_by_index (const struct View *view,
123                         uint32_t index);
124
125
126 /**
127  * Clear the view
128  *
129  * @param view The view to clear
130  */
131 void
132 View_clear (struct View *view);
133
134
135 /**
136  * Destroy view.
137  *
138  * @param view the view to destroy
139  */
140 void
141 View_destroy (struct View *view);
142
143 /* end of gnunet-service-rps_view.h */