GNUnet 0.21.1
cadet_api_list_peers.c File Reference

cadet api: client implementation of cadet service More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_cadet_service.h"
#include "cadet.h"
#include "cadet_protocol.h"
Include dependency graph for cadet_api_list_peers.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_CADET_PeersLister
 Operation handle. More...
 

Functions

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. More...
 
static void handle_get_peers_end (void *cls, const struct GNUNET_MessageHeader *msg)
 Process a end of list reply about info on all peers. More...
 
static void reconnect (void *cls)
 Reconnect to the service and try again. More...
 
static void error_handler (void *cls, enum GNUNET_MQ_Error error)
 Function called on connection trouble. More...
 
struct GNUNET_CADET_PeersListerGNUNET_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. More...
 
void * GNUNET_CADET_list_peers_cancel (struct GNUNET_CADET_PeersLister *pl)
 Cancel a peer info request. More...
 

Detailed Description

cadet api: client implementation of cadet service

Author
Bartlomiej Polot
Christian Grothoff

Definition in file cadet_api_list_peers.c.

Function Documentation

◆ handle_get_peers()

static void handle_get_peers ( void *  cls,
const struct GNUNET_CADET_LocalInfoPeers info 
)
static

Process a local reply about info on all tunnels, pass info to the user.

Parameters
clsa struct GNUNET_CADET_PeersLister
infoMessage itself.

Definition at line 78 of file cadet_api_list_peers.c.

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}
#define info
Information we return per peer.
struct GNUNET_PeerIdentity peer
Which peer is the information about?
void * peers_cb_cls
Info callback closure for info_cb.
GNUNET_CADET_PeersCB peers_cb
Monitor callback.

References GNUNET_CADET_PeerListEntry::best_path_length, GNUNET_CADET_PeerListEntry::have_tunnel, info, consensus-simulation::int, GNUNET_CADET_PeerListEntry::n_paths, GNUNET_CADET_PeerListEntry::peer, GNUNET_CADET_PeersLister::peers_cb, and GNUNET_CADET_PeersLister::peers_cb_cls.

◆ handle_get_peers_end()

static void handle_get_peers_end ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Process a end of list reply about info on all peers.

Parameters
clsa struct GNUNET_CADET_PeersLister
msgMessage itself.

Definition at line 100 of file cadet_api_list_peers.c.

102{
103 struct GNUNET_CADET_PeersLister *pl = cls;
104
105 (void) msg;
106
107 pl->peers_cb (pl->peers_cb_cls,
108 NULL);
110}
struct GNUNET_MessageHeader * msg
Definition: 005.c:2
void * GNUNET_CADET_list_peers_cancel(struct GNUNET_CADET_PeersLister *pl)
Cancel a peer info request.

References GNUNET_CADET_list_peers_cancel(), msg, GNUNET_CADET_PeersLister::peers_cb, and GNUNET_CADET_PeersLister::peers_cb_cls.

Here is the call graph for this function:

◆ reconnect()

static void reconnect ( void *  cls)
static

Reconnect to the service and try again.

Parameters
clsa struct GNUNET_CADET_PeersLister operation

Definition at line 150 of file cadet_api_list_peers.c.

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}
struct GNUNET_MQ_MessageHandlers handlers[]
Definition: 003.c:1
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on connection trouble.
static void get_peers(void *cls)
Call CADET's meta API, get all peers known to a peer.
Definition: gnunet-cadet.c:584
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
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)
#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.
Message to inform the client about one of the peers in the service.
Definition: cadet.h:424
struct GNUNET_MQ_Handle * mq
Message queue to talk to CADET service.
struct GNUNET_SCHEDULER_Task * reconnect_task
Task to reconnect.
const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we use.
Message handler for a specific message type.
Header for all communications.

References GNUNET_CADET_PeersLister::cfg, env, error_handler(), get_peers(), GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS, GNUNET_MESSAGE_TYPE_CADET_LOCAL_INFO_PEERS_END, GNUNET_MESSAGE_TYPE_CADET_LOCAL_REQUEST_INFO_PEERS, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_msg, GNUNET_MQ_send(), handlers, GNUNET_CADET_PeersLister::mq, msg, and GNUNET_CADET_PeersLister::reconnect_task.

Referenced by error_handler(), and GNUNET_CADET_list_peers().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ error_handler()

static void error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Function called on connection trouble.

Reconnects.

Parameters
clsa struct GNUNET_CADET_PeersLister
errorerror code from MQ

Definition at line 129 of file cadet_api_list_peers.c.

131{
132 struct GNUNET_CADET_PeersLister *pl = cls;
133
134 GNUNET_MQ_destroy (pl->mq);
135 pl->mq = NULL;
139 &reconnect,
140 pl);
141}
static void reconnect(void *cls)
Reconnect to the service and try again.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
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.
struct GNUNET_TIME_Relative backoff
Backoff for reconnect attempts.

References GNUNET_CADET_PeersLister::backoff, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_randomized_backoff(), GNUNET_TIME_UNIT_MINUTES, GNUNET_CADET_PeersLister::mq, reconnect(), and GNUNET_CADET_PeersLister::reconnect_task.

Referenced by reconnect().

Here is the call graph for this function:
Here is the caller graph for this function: