2 This file is part of GNUnet.
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.
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.
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.
22 * @file rps/gnunet-service-rps_peers.h
23 * @brief utilities for managing (information about) peers
24 * @author Julius Bünger
26 #include "gnunet_util_lib.h"
28 #include "gnunet_cadet_service.h"
32 * Different flags indicating the status of another peer.
37 * If we are waiting for a reply from that peer (sent a pull request).
39 Peers_PULL_REPLY_PENDING = 0x01,
41 /* IN_OTHER_GOSSIP_LIST = 0x02, unneeded? */
42 /* IN_OWN_SAMPLER_LIST = 0x04, unneeded? */
43 /* IN_OWN_GOSSIP_LIST = 0x08, unneeded? */
46 * We set this bit when we can be sure the other peer is/was live.
51 * We set this bit when we know the peer is online.
56 * We set this bit when we are going to destroy the channel to this peer.
57 * When cleanup_channel is called, we know that we wanted to destroy it.
58 * Otherwise the channel to the other peer was destroyed.
60 Peers_TO_DESTROY = 0x40,
64 * Keep track of the status of a channel.
66 * This is needed in order to know what to do with a channel when it's
69 enum Peers_ChannelFlags
72 * We destroyed the channel because the other peer established a second one.
74 Peers_CHANNEL_ESTABLISHED_TWICE = 0x1,
77 * The channel was removed because it was not needed any more. This should be
78 * the sending channel.
80 Peers_CHANNEL_CLEAN = 0x2,
84 * @brief The role of a channel. Sending or receiving.
86 enum Peers_ChannelRole
89 * Channel is used for sending
91 Peers_CHANNEL_ROLE_SENDING = 0x01,
94 * Channel is used for receiving
96 Peers_CHANNEL_ROLE_RECEIVING = 0x02,
100 * @brief Functions of this type can be used to be stored at a peer for later execution.
103 * @param peer peer to execute function on
105 typedef void (* PeerOp) (void *cls, const struct GNUNET_PeerIdentity *peer);
108 * @brief Initialise storage of peers
110 * @param cadet_h cadet handle
111 * @param own_id own peer identity
114 Peers_initialise (struct GNUNET_CADET_Handle *cadet_h,
115 const struct GNUNET_PeerIdentity *own_id);
118 * @brief Delete storage of peers that was created with #Peers_initialise ()
124 * @brief Add peer to known peers.
126 * This function is called on new peer_ids from 'external' sources
127 * (client seed, cadet get_peers(), ...)
129 * @param peer the new #GNUNET_PeerIdentity
131 * @return #GNUNET_YES if peer was inserted
132 * #GNUNET_NO if peer was already known
135 Peers_insert_peer (const struct GNUNET_PeerIdentity *peer);
138 * @brief Remove unecessary data
140 * If the other peer is not intending to send messages, we have messages pending
141 * to be sent to this peer and we are not waiting for a reply, remove the
142 * information about it (its #PeerContext).
144 * @param peer the peer to clean
145 * @return #GNUNET_YES if peer was removed
146 * #GNUNET_NO otherwise
149 Peers_clean_peer (const struct GNUNET_PeerIdentity *peer);
154 * @param peer the peer to clean
155 * @return #GNUNET_YES if peer was removed
156 * #GNUNET_NO otherwise
159 Peers_remove_peer (const struct GNUNET_PeerIdentity *peer);
162 * @brief set flags on a given peer.
164 * @param peer the peer to set flags on
165 * @param flags the flags
168 Peers_set_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
171 * @brief unset flags on a given peer.
173 * @param peer the peer to unset flags on
174 * @param flags the flags
177 Peers_unset_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
180 * @brief Check whether flags on a peer are set.
182 * @param peer the peer to check the flag of
183 * @param flags the flags to check
185 * @return #GNUNET_YES if all given flags are set
186 * ##GNUNET_NO otherwise
189 Peers_check_peer_flag (const struct GNUNET_PeerIdentity *peer, enum Peers_PeerFlags flags);
193 * @brief set flags on a given channel.
195 * @param channel the channel to set flags on
196 * @param flags the flags
199 Peers_set_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
202 * @brief unset flags on a given channel.
204 * @param channel the channel to unset flags on
205 * @param flags the flags
208 Peers_unset_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
211 * @brief Check whether flags on a channel are set.
213 * @param channel the channel to check the flag of
214 * @param flags the flags to check
216 * @return #GNUNET_YES if all given flags are set
217 * #GNUNET_NO otherwise
220 Peers_check_channel_flag (uint32_t *channel_flags, enum Peers_ChannelFlags flags);
223 * @brief Check whether we have information about the given peer.
225 * @param peer peer in question
227 * @return #GNUNET_YES if peer is known
228 * #GNUNET_NO if peer is not knwon
231 Peers_check_peer_known (const struct GNUNET_PeerIdentity *peer);
234 * @brief Indicate that we want to send to the other peer
236 * This establishes a sending channel
238 * @param peer the peer to establish channel to
241 Peers_indicate_sending_intention (const struct GNUNET_PeerIdentity *peer);
244 * @brief Check whether other peer has the intention to send/opened channel
247 * @param peer the peer in question
249 * @return #GNUNET_YES if peer has the intention to send
250 * #GNUNET_NO otherwise
253 Peers_check_peer_send_intention (const struct GNUNET_PeerIdentity *peer);
256 * Handle the channel a peer opens to us.
258 * @param cls The closure
259 * @param channel The channel the peer wants to establish
260 * @param initiator The peer's peer ID
261 * @param port The port the channel is being established over
262 * @param options Further options
264 * @return initial channel context for the channel
265 * (can be NULL -- that's not an error)
268 Peers_handle_inbound_channel (void *cls,
269 struct GNUNET_CADET_Channel *channel,
270 const struct GNUNET_PeerIdentity *initiator,
272 enum GNUNET_CADET_ChannelOption options);
275 * @brief Check whether a sending channel towards the given peer exists
277 * @param peer the peer to check for
279 * @return #GNUNET_YES if a sending channel towards that peer exists
280 * #GNUNET_NO otherwise
283 Peers_check_sending_channel_exists (const struct GNUNET_PeerIdentity *peer);
286 * @brief check whether the given channel is the sending channel of the given
289 * @param peer the peer in question
290 * @param channel the channel to check for
291 * @param role either #Peers_CHANNEL_ROLE_SENDING, or
292 * #Peers_CHANNEL_ROLE_RECEIVING
294 * @return #GNUNET_YES if the given chennel is the sending channel of the peer
295 * #GNUNET_NO otherwise
298 Peers_check_channel_role (const struct GNUNET_PeerIdentity *peer,
299 const struct GNUNET_CADET_Channel *channel,
300 enum Peers_ChannelRole role);
303 * @brief Destroy the send channel of a peer e.g. stop indicating a sending
304 * intention to another peer
306 * If there is also no channel to receive messages from that peer, remove it
309 * @peer the peer identity of the peer whose sending channel to destroy
310 * @return #GNUNET_YES if channel was destroyed
311 * #GNUNET_NO otherwise
314 Peers_destroy_sending_channel (const struct GNUNET_PeerIdentity *peer);
317 * This is called when a channel is destroyed.
319 * Removes peer completely from our knowledge if the send_channel was destroyed
320 * Otherwise simply delete the recv_channel
322 * @param cls The closure
323 * @param channel The channel being closed
324 * @param channel_ctx The context associated with this channel
327 Peers_cleanup_destroyed_channel (void *cls,
328 const struct GNUNET_CADET_Channel *channel,
332 * @brief Issue a check whether peer is live
334 * This tries to establish a channel to the given peer. Once the channel is
335 * established successfully, we know the peer is live.
337 * @param peer the peer to check liveliness
340 Peers_issue_peer_liveliness_check (const struct GNUNET_PeerIdentity *peer);
343 * @brief Send a message to another peer.
345 * Keeps track about pending messages so they can be properly removed when the
348 * @param peer receeiver of the message
349 * @param ev envelope of the message
350 * @param type type of the message
353 Peers_send_message (const struct GNUNET_PeerIdentity *peer,
354 struct GNUNET_MQ_Envelope *ev,
358 * @brief Schedule a operation on given peer
360 * Avoids scheduling an operation twice.
362 * @param peer the peer we want to schedule the operation for once it gets live
364 * @return #GNUNET_YES if the operation was scheduled
365 * #GNUNET_NO otherwise
368 Peers_schedule_operation (const struct GNUNET_PeerIdentity *peer,
369 const PeerOp peer_op);
371 /* end of gnunet-service-rps_peers.h */