GNUnet  0.10.x
Data Structures | Macros | Functions
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, ...)   GNUNET_log_from(kind, "ats-connectivity-api", __VA_ARGS__)
 

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,
  ... 
)    GNUNET_log_from(kind, "ats-connectivity-api", __VA_ARGS__)

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.

References GNUNET_ATS_ConnectivityHandle::cfg, error_handler(), force_reconnect(), GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MESSAGE_TYPE_ATS_START, GNUNET_MQ_msg, GNUNET_MQ_send(), init, GNUNET_ATS_ConnectivityHandle::mq, ClientStartMessage::start_flag, START_FLAG_CONNECTION_SUGGESTION, GNUNET_ATS_ConnectivityHandle::sug_requests, and transmit_suggestion().

Referenced by GNUNET_ATS_connectivity_init(), and reconnect_task().

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  {
205  force_reconnect (ch);
206  return;
207  }
208  ev = GNUNET_MQ_msg (init,
211  GNUNET_MQ_send (ch->mq, ev);
212  if (NULL == ch->mq)
213  return;
216  ch);
217 }
#define GNUNET_MESSAGE_TYPE_ATS_START
Type of the 'struct ClientStartMessage' sent by clients to ATS to identify the type of the client...
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the ATS service.
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:901
uint32_t start_flag
NBO value of an enum StartFlag.
Definition: ats.h:80
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
struct GNUNET_CONTAINER_MultiPeerMap * sug_requests
Map with the identities of all the peers for which we would like to have address suggestions.
Message handler for a specific message type.
static int transmit_suggestion(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Transmit request for an address suggestion.
Connection suggestion handle.
Definition: ats.h:60
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
static char * init
Set to the name of a service to start.
Definition: gnunet-arm.c:69
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ to the ATS service.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
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:353
static void force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
Disconnect from ATS and then reconnect.
First message any client sends to ATS, used to self-identify (what type of client this is)...
Definition: ats.h:70
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.

References GNUNET_ATS_ConnectivitySuggestHandle::ch, reconnect(), and GNUNET_ATS_ConnectivityHandle::task.

Referenced by force_reconnect().

107 {
108  struct GNUNET_ATS_ConnectivityHandle *ch = cls;
109 
110  ch->task = NULL;
111  reconnect (ch);
112 }
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static void reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
Re-establish the connection to the ATS service.
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
Handle to the ATS subsystem for connectivity management.
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.

References GNUNET_ATS_ConnectivityHandle::backoff, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_TIME_STD_BACKOFF, GNUNET_ATS_ConnectivityHandle::mq, reconnect_task(), and GNUNET_ATS_ConnectivityHandle::task.

Referenced by error_handler(), and reconnect().

122 {
123  if (NULL != ch->mq)
124  {
125  GNUNET_MQ_destroy (ch->mq);
126  ch->mq = NULL;
127  }
131  ch);
132 }
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the ATS service.
static void reconnect_task(void *cls)
Re-establish the connection to the ATS service.
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
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:1246
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_TIME_Relative backoff
Reconnect backoff delay.
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.

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

Referenced by reconnect().

145 {
146  struct GNUNET_ATS_ConnectivityHandle *ch = cls;
147 
149  "ATS connection died (code %d), reconnecting\n",
150  (int) error);
151  force_reconnect (ch);
152 }
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
#define LOG(kind,...)
Handle to the ATS subsystem for connectivity management.
static void force_reconnect(struct GNUNET_ATS_ConnectivityHandle *ch)
Disconnect from ATS and then 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.

References GNUNET_ATS_ConnectivitySuggestHandle::ch, GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, m, GNUNET_ATS_ConnectivityHandle::mq, RequestAddressMessage::peer, peer, sh, GNUNET_ATS_ConnectivitySuggestHandle::strength, RequestAddressMessage::strength, and value.

Referenced by GNUNET_ATS_connectivity_suggest(), and reconnect().

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 }
Connectivity client to ATS service: we would like to have address suggestions for this peer...
Definition: ats.h:88
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the ATS service.
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
uint32_t strength
How "strong" is our need for an address for this peer?
Definition: ats.h:100
uint32_t strength
How urgent is the request.
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
static char * value
Value of the record to add/remove.
static struct SolverHandle * sh
Handle for ATS address suggestion requests.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_MESSAGE_TYPE_ATS_REQUEST_ADDRESS
Type of the 'struct RequestAddressMessage' sent by clients to ATS to request an address to help conne...
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:353
Handle to the ATS subsystem for connectivity management.
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
Definition: ats.h:105
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.

References GNUNET_free, GNUNET_OK, and value.

Referenced by GNUNET_ATS_connectivity_done().

253 {
255 
256  GNUNET_free (cur);
257  return GNUNET_OK;
258 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static char * value
Value of the record to add/remove.
Handle for ATS address suggestion requests.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: