GNUnet 0.21.2
cadet_api_list_peers.c
Go to the documentation of this file.
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2011, 2017, 2019 GNUnet e.V.
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 SPDX-License-Identifier: AGPL3.0-or-later
19 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "gnunet_constants.h"
30#include "cadet.h"
31#include "cadet_protocol.h"
32
33
38{
43
48
53
58
63
68};
69
70
77static void
80{
81 struct GNUNET_CADET_PeersLister *pl = cls;
83
84 ple.peer = info->destination;
85 ple.have_tunnel = (int) ntohs (info->tunnel);
86 ple.n_paths = (unsigned int) ntohs (info->paths);
87 ple.best_path_length = (unsigned int) ntohl (info->best_path_length);
88 pl->peers_cb (pl->peers_cb_cls,
89 &ple);
90}
91
92
99static void
101 const struct GNUNET_MessageHeader *msg)
102{
103 struct GNUNET_CADET_PeersLister *pl = cls;
104
105 (void) msg;
106
107 pl->peers_cb (pl->peers_cb_cls,
108 NULL);
110}
111
112
118static void
119reconnect (void *cls);
120
121
128static void
129error_handler (void *cls,
130 enum GNUNET_MQ_Error error)
131{
132 struct GNUNET_CADET_PeersLister *pl = cls;
133
134 GNUNET_MQ_destroy (pl->mq);
135 pl->mq = NULL;
139 &reconnect,
140 pl);
141}
142
143
149static void
150reconnect (void *cls)
151{
152 struct GNUNET_CADET_PeersLister *pl = cls;
157 pl),
158 GNUNET_MQ_hd_fixed_size (get_peers_end,
161 pl),
163 };
165 struct GNUNET_MQ_Envelope *env;
166
167 pl->reconnect_task = NULL;
168 pl->mq = GNUNET_CLIENT_connect (pl->cfg,
169 "cadet",
170 handlers,
172 pl);
173 if (NULL == pl->mq)
174 return;
177 GNUNET_MQ_send (pl->mq,
178 env);
179}
180
181
194 GNUNET_CADET_PeersCB callback,
195 void *callback_cls)
196{
197 struct GNUNET_CADET_PeersLister *pl;
198
199 if (NULL == callback)
200 {
201 GNUNET_break (0);
202 return NULL;
203 }
205 pl->peers_cb = callback;
206 pl->peers_cb_cls = callback_cls;
207 pl->cfg = cfg;
208 reconnect (pl);
209 if (NULL == pl->mq)
210 {
211 GNUNET_free (pl);
212 return NULL;
213 }
214 return pl;
215}
216
217
224void *
226{
227 void *ret = pl->peers_cb_cls;
228
229 if (NULL != pl->mq)
230 GNUNET_MQ_destroy (pl->mq);
231 if (NULL != pl->reconnect_task)
233 GNUNET_free (pl);
234 return ret;
235}
236
237
238/* end of cadet_api_list_peers.c */
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void handle_get_peers(void *cls, const struct GNUNET_CADET_LocalInfoPeers *info)
Process a local reply about info on all tunnels, pass info to the user.
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on connection trouble.
static void reconnect(void *cls)
Reconnect to the service and try again.
static void handle_get_peers_end(void *cls, const struct GNUNET_MessageHeader *msg)
Process a end of list reply about info on all peers.
P2P messages used by CADET.
static int ret
Final status code.
Definition: gnunet-arm.c:94
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:109
static void get_peers(void *cls)
Call CADET's meta API, get all peers known to a peer.
Definition: gnunet-cadet.c:584
#define info
CADET service; establish channels to distant peers.
void(* GNUNET_CADET_PeersCB)(void *cls, const struct GNUNET_CADET_PeerListEntry *ple)
Method called to retrieve information about all peers in CADET, called once per peer.
struct GNUNET_CADET_PeersLister * GNUNET_CADET_list_peers(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_CADET_PeersCB callback, void *callback_cls)
Request information about peers known to the running cadet service.
void * GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl)
Cancel a peer info request.
struct GNUNET_MQ_Handle * GNUNET_CLIENT_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *service_name, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *error_handler_cls)
Create a message queue to connect to a GNUnet service.
Definition: client.c:1057
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#define GNUNET_free(ptr)
Wrapper around free.
GNUNET_MQ_Error
Error codes for the queue.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:304
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS
Request local information about all peers known to the service.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS
Local information about all peers known to the service.
#define GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END
End of local information about all peers known to the service.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:981
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1278
struct GNUNET_TIME_Relative GNUNET_TIME_randomized_backoff(struct GNUNET_TIME_Relative rt, struct GNUNET_TIME_Relative threshold)
Randomized exponential back-off, starting at 1 ms and going up by a factor of 2+r,...
Definition: time.c:830
#define GNUNET_TIME_UNIT_MINUTES
One minute.
Message to inform the client about one of the peers in the service.
Definition: cadet.h:424
Information we return per peer.
unsigned int best_path_length
Length of the shortest path (0 = unknown, 1 = ourselves, 2 = direct neighbour).
unsigned int n_paths
Number of disjoint known paths to peer.
struct GNUNET_PeerIdentity peer
Which peer is the information about?
int have_tunnel
Do we have a tunnel to this peer?
void * peers_cb_cls
Info callback closure for info_cb.
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
GNUNET_CADET_PeersCB peers_cb
Monitor callback.
struct GNUNET_TIME_Relative backoff
Backoff for reconnect attempts.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Handle to a message queue.
Definition: mq.c:87
Message handler for a specific message type.
Header for all communications.
Entry in list of pending tasks.
Definition: scheduler.c:136
Time for relative time used by GNUnet, in microseconds.