GNUnet  0.10.x
Data Structures | Macros | Functions
ats_api2_application.c File Reference

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

#include "platform.h"
#include "gnunet_ats_application_service.h"
#include "ats2.h"
Include dependency graph for ats_api2_application.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_ATS_ApplicationSuggestHandle
 Handle for ATS address suggestion requests. More...
 
struct  GNUNET_ATS_ApplicationHandle
 Handle to the ATS subsystem for application management. More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from(kind, "ats-application-api", __VA_ARGS__)
 

Functions

static void reconnect (struct GNUNET_ATS_ApplicationHandle *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_ApplicationHandle *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_ApplicationHandleGNUNET_ATS_application_init (const struct GNUNET_CONFIGURATION_Handle *cfg)
 Initialize the ATS application 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_ApplicationSuggestHandles in the map. More...
 
void GNUNET_ATS_application_done (struct GNUNET_ATS_ApplicationHandle *ch)
 Client is done with ATS application management, release resources. More...
 
struct GNUNET_ATS_ApplicationSuggestHandleGNUNET_ATS_application_suggest (struct GNUNET_ATS_ApplicationHandle *ch, const struct GNUNET_PeerIdentity *peer, enum GNUNET_MQ_PreferenceKind pk, struct GNUNET_BANDWIDTH_Value32NBO bw)
 We would like to receive address suggestions for a peer. More...
 
void GNUNET_ATS_application_suggest_cancel (struct GNUNET_ATS_ApplicationSuggestHandle *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_api2_application.c.

Macro Definition Documentation

◆ LOG

#define LOG (   kind,
  ... 
)    GNUNET_log_from(kind, "ats-application-api", __VA_ARGS__)

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_ATS_ApplicationHandle ch)
static

Re-establish the connection to the ATS service.

Parameters
chhandle to use to re-connect.

Definition at line 197 of file ats_api2_application.c.

References GNUNET_ATS_ApplicationHandle::cfg, error_handler(), force_reconnect(), GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ATS_ApplicationHandle::mq, GNUNET_ATS_ApplicationHandle::sug_requests, and transmit_suggestion().

Referenced by GNUNET_ATS_application_init(), iopen(), and reconnect_task().

198 {
199  static const struct GNUNET_MQ_MessageHandler handlers[] = {
200  { NULL, 0, 0 }
201  };
202 
203  GNUNET_assert (NULL == ch->mq);
204  ch->mq = GNUNET_CLIENT_connect (ch->cfg,
205  "ats",
206  handlers,
207  &error_handler,
208  ch);
209  if (NULL == ch->mq)
210  {
211  force_reconnect (ch);
212  return;
213  }
216  ch);
217 }
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ 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
static int transmit_suggestion(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Transmit request for an address suggestion.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void force_reconnect(struct GNUNET_ATS_ApplicationHandle *ch)
Disconnect from ATS and then reconnect.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
Message handler for a specific message type.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_CONTAINER_MultiPeerMap * sug_requests
Map with the identities of all the peers for which we would like to have address suggestions.
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the ATS service.
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 111 of file ats_api2_application.c.

References GNUNET_ATS_ApplicationSuggestHandle::ch, reconnect(), and GNUNET_ATS_ApplicationHandle::task.

Referenced by force_reconnect().

112 {
113  struct GNUNET_ATS_ApplicationHandle *ch = cls;
114 
115  ch->task = NULL;
116  reconnect (ch);
117 }
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static void reconnect(struct GNUNET_ATS_ApplicationHandle *ch)
Re-establish the connection to the ATS service.
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
Handle to the ATS subsystem for application 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_ApplicationHandle ch)
static

Disconnect from ATS and then reconnect.

Parameters
chour handle

Definition at line 126 of file ats_api2_application.c.

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

Referenced by error_handler(), and reconnect().

127 {
128  if (NULL != ch->mq)
129  {
130  GNUNET_MQ_destroy (ch->mq);
131  ch->mq = NULL;
132  }
136  ch);
137 }
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
static void reconnect_task(void *cls)
Re-establish the connection to the ATS service.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
struct GNUNET_TIME_Relative backoff
Reconnect backoff delay.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the ATS service.
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_ApplicationHandle
errordetails about the error

Definition at line 148 of file ats_api2_application.c.

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

Referenced by GNUNET_MQ_queue_for_callbacks(), and reconnect().

150 {
151  struct GNUNET_ATS_ApplicationHandle *ch = cls;
152 
154  "ATS connection died (code %d), reconnecting\n",
155  (int) error);
156  force_reconnect (ch);
157 }
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
#define LOG(kind,...)
static void force_reconnect(struct GNUNET_ATS_ApplicationHandle *ch)
Disconnect from ATS and then reconnect.
Handle to the ATS subsystem for application management.
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_ApplicationHandle
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 170 of file ats_api2_application.c.

References GNUNET_ATS_ApplicationSuggestHandle::bw, ExpressPreferenceMessage::bw, GNUNET_ATS_ApplicationSuggestHandle::ch, GNUNET_MESSAGE_TYPE_ATS_SUGGEST, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, GNUNET_SYSERR, m, GNUNET_ATS_ApplicationHandle::mq, peer, ExpressPreferenceMessage::peer, GNUNET_ATS_ApplicationSuggestHandle::pk, ExpressPreferenceMessage::pk, sh, and value.

Referenced by GNUNET_ATS_application_suggest(), and reconnect().

173 {
174  struct GNUNET_ATS_ApplicationHandle *ch = cls;
176  struct GNUNET_MQ_Envelope *ev;
177  struct ExpressPreferenceMessage *m;
178 
179  if (NULL == ch->mq)
180  return GNUNET_SYSERR;
181  ev = GNUNET_MQ_msg (m,
183  m->pk = htonl ((uint32_t) sh->pk);
184  m->bw = sh->bw;
185  m->peer = *peer;
186  GNUNET_MQ_send (ch->mq, ev);
187  return GNUNET_OK;
188 }
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
#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 pk
What type of performance preference does the client have? A enum GNUNET_MQ_PreferenceKind in NBO...
Definition: ats2.h:125
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 to the ATS subsystem for application management.
struct GNUNET_TESTBED_Peer * peer
The peer associated with this model.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_MESSAGE_TYPE_ATS_SUGGEST
Type of the 'struct ExpressPreferenceMessage' send by clients to ATS to establish bandwidth preferenc...
enum GNUNET_MQ_PreferenceKind pk
What preference is being expressed?
Handle for ATS address suggestion requests.
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
struct GNUNET_MQ_Handle * mq
Message queue for sending requests to the ATS service.
struct GNUNET_BANDWIDTH_Value32NBO bw
How much bandwidth in bytes/second does the application expect?
Definition: ats2.h:135
Application client to ATS service: we would like to have address suggestions for this peer...
Definition: ats2.h:112
struct GNUNET_PeerIdentity peer
Peer to get address suggestions for.
Definition: ats2.h:130
struct GNUNET_BANDWIDTH_Value32NBO bw
How much bandwidth does the client expect?
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_ApplicationSuggestHandles in the map.

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

Definition at line 250 of file ats_api2_application.c.

References GNUNET_free, GNUNET_OK, and value.

Referenced by GNUNET_ATS_application_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: