GNUnet  0.19.4
ats_api_connectivity.c File Reference

enable clients to ask ATS about establishing connections to peers More...

#include "platform.h"
#include "gnunet_ats_service.h"
#include "ats.h"
Include dependency graph for ats_api_connectivity.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_ATS_ConnectivitySuggestHandle
 Handle for ATS address suggestion requests. More...
 
struct  GNUNET_ATS_ConnectivityHandle
 Handle to the ATS subsystem for connectivity management. More...
 

Macros

#define LOG(kind, ...)
 

Functions

static void reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
 Re-establish the connection to the ATS service. More...
 
static void reconnect_task (void *cls)
 Re-establish the connection to the ATS service. More...
 
static void force_reconnect (struct GNUNET_ATS_ConnectivityHandle *ch)
 Disconnect from ATS and then reconnect. More...
 
static void error_handler (void *cls, enum GNUNET_MQ_Error error)
 We encountered an error handling the MQ to the ATS service. More...
 
static int transmit_suggestion (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Transmit request for an address suggestion. More...
 
struct GNUNET_ATS_ConnectivityHandleGNUNET_ATS_connectivity_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Initialize the ATS connectivity suggestion client handle. More...
 
static int free_sug_handle (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Function called to free all struct GNUNET_ATS_ConnectivitySuggestHandles in the map. More...
 
void GNUNET_ATS_connectivity_done (struct GNUNET_ATS_ConnectivityHandle *ch)
 Client is done with ATS connectivity management, release resources. More...
 
struct GNUNET_ATS_ConnectivitySuggestHandleGNUNET_ATS_connectivity_suggest (struct GNUNET_ATS_ConnectivityHandle *ch, const struct GNUNET_PeerIdentity *peer, uint32_t strength)
 We would like to receive address suggestions for a peer. More...
 
void GNUNET_ATS_connectivity_suggest_cancel (struct GNUNET_ATS_ConnectivitySuggestHandle *sh)
 We no longer care about being connected to a peer. More...
 

Detailed Description

enable clients to ask ATS about establishing connections to peers

Author
Christian Grothoff
Matthias Wachs

Definition in file ats_api_connectivity.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)
Value:
GNUNET_log_from (kind, "ats-connectivity-api", \
__VA_ARGS__)
#define GNUNET_log_from(kind, comp,...)

Definition at line 31 of file ats_api_connectivity.c.

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_ATS_ConnectivityHandle ch)
static

Re-establish the connection to the ATS service.

Parameters
chhandle to use to re-connect.

Definition at line 190 of file ats_api_connectivity.c.

191 {
192  static const struct GNUNET_MQ_MessageHandler handlers[] =
193  { { NULL, 0, 0 } };
194  struct GNUNET_MQ_Envelope *ev;
195  struct ClientStartMessage *init;
196 
197  GNUNET_assert (NULL == ch->mq);
198  ch->mq = GNUNET_CLIENT_connect (ch->cfg,
199  "ats",
200  handlers,
201  &error_handler,
202  ch);
203  if (NULL == ch->mq)
204  {
206  return;
207  }
208  ev = GNUNET_MQ_msg (init,
210  init->start_flag = htonl (START_FLAG_CONNECTION_SUGGESTION);
211  GNUNET_MQ_send (ch->mq, ev);
212  if (NULL == ch->mq)
213  return;
216  ch);
217 }
@ START_FLAG_CONNECTION_SUGGESTION
Connection suggestion handle.
Definition: ats.h:59
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ to the ATS service.
static int transmit_suggestion(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Transmit request for an address suggestion.
static void force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
Disconnect from ATS and then reconnect.
static char * init
Set to the name of a service to start.
Definition: gnunet-arm.c:74
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
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
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
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_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:77
#define GNUNET_MESSAGE_TYPE_ATS_START
Type of the 'struct ClientStartMessage' sent by clients to ATS to identify the type of the client.
First message any client sends to ATS, used to self-identify (what type of client this is).
Definition: ats.h:70
struct GNUNET_MQ_Handle * mq
Message Queue for the channel (which we are implementing).
Definition: cadet.h:142
Message handler for a specific message type.

References ch, error_handler(), force_reconnect(), GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MESSAGE_TYPE_ATS_START, GNUNET_MQ_msg, GNUNET_MQ_send(), handlers, init, GNUNET_CADET_Channel::mq, START_FLAG_CONNECTION_SUGGESTION, and transmit_suggestion().

Referenced by GNUNET_ATS_connectivity_init(), and reconnect_task().

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

◆ reconnect_task()

static void reconnect_task ( void *  cls)
static

Re-establish the connection to the ATS service.

Parameters
clshandle to use to re-connect.

Definition at line 106 of file ats_api_connectivity.c.

107 {
108  struct GNUNET_ATS_ConnectivityHandle *ch = cls;
109 
110  ch->task = NULL;
111  reconnect (ch);
112 }
static void reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
Re-establish the connection to the ATS service.
Handle to the ATS subsystem for connectivity management.

References ch, and reconnect().

Referenced by force_reconnect().

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

◆ force_reconnect()

static void force_reconnect ( struct GNUNET_ATS_ConnectivityHandle ch)
static

Disconnect from ATS and then reconnect.

Parameters
chour handle

Definition at line 121 of file ats_api_connectivity.c.

122 {
123  if (NULL != ch->mq)
124  {
126  ch->mq = NULL;
127  }
128  ch->backoff = GNUNET_TIME_STD_BACKOFF (ch->backoff);
129  ch->task = GNUNET_SCHEDULER_add_delayed (ch->backoff,
131  ch);
132 }
static void reconnect_task(void *cls)
Re-establish the connection to the ATS service.
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:1272
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...

References ch, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_CADET_Channel::mq, and reconnect_task().

Referenced by error_handler(), and reconnect().

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

We encountered an error handling the MQ to the ATS service.

Reconnect.

Parameters
clsthe struct GNUNET_ATS_ConnectivityHandle
errordetails about the error

Definition at line 143 of file ats_api_connectivity.c.

145 {
146  struct GNUNET_ATS_ConnectivityHandle *ch = cls;
147 
149  "ATS connection died (code %d), reconnecting\n",
150  (int) error);
152 }
#define LOG(kind,...)
@ GNUNET_ERROR_TYPE_DEBUG

References ch, force_reconnect(), GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by GNUNET_CLIENT_connect(), GNUNET_MQ_queue_for_callbacks(), and reconnect().

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

◆ transmit_suggestion()

static int transmit_suggestion ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Transmit request for an address suggestion.

Parameters
clsthe struct GNUNET_ATS_ConnectivityHandle
peerpeer to ask for an address suggestion for
valuethe struct GNUNET_ATS_SuggestHandle
Returns
GNUNET_OK (continue to iterate), GNUNET_SYSERR on failure (message queue no longer exists)

Definition at line 165 of file ats_api_connectivity.c.

168 {
169  struct GNUNET_ATS_ConnectivityHandle *ch = cls;
171  struct GNUNET_MQ_Envelope *ev;
172  struct RequestAddressMessage *m;
173 
174  if (NULL == ch->mq)
175  return GNUNET_SYSERR;
177  m->strength = htonl (sh->strength);
178  m->peer = *peer;
179  GNUNET_MQ_send (ch->mq, ev);
180  return GNUNET_OK;
181 }
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
static struct SolverHandle * sh
static char * value
Value of the record to add/remove.
@ GNUNET_OK
@ GNUNET_SYSERR
#define GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS
Type of the 'struct RequestAddressMessage' sent by clients to ATS to request an address to help conne...
Handle for ATS address suggestion requests.
Connectivity client to ATS service: we would like to have address suggestions for this peer.
Definition: ats.h:88
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.

References ch, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, m, GNUNET_CADET_Channel::mq, peer, sh, and value.

Referenced by GNUNET_ATS_connectivity_suggest(), and reconnect().

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

◆ free_sug_handle()

static int free_sug_handle ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Function called to free all struct GNUNET_ATS_ConnectivitySuggestHandles in the map.

Parameters
clsNULL
keythe key
valuethe value to free
Returns
GNUNET_OK (continue to iterate)

Definition at line 250 of file ats_api_connectivity.c.

253 {
255 
256  GNUNET_free (cur);
257  return GNUNET_OK;
258 }
#define GNUNET_free(ptr)
Wrapper around free.

References GNUNET_free, GNUNET_OK, and value.

Referenced by GNUNET_ATS_connectivity_done().

Here is the caller graph for this function: