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

address suggestions and bandwidth allocation More...

#include "platform.h"
#include "gnunet_ats_transport_service.h"
#include "ats2.h"
Include dependency graph for ats_api2_transport.c:

Go to the source code of this file.

Data Structures

struct  GNUNET_ATS_SessionRecord
 Information we track per session, incoming or outgoing. More...
 
struct  GNUNET_ATS_TransportHandle
 Handle to the ATS subsystem for bandwidth/transport transport information. More...
 
struct  FindContext
 Closure for match_session_cb. More...
 

Macros

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

Functions

static void properties_hton (struct PropertiesNBO *nbo, const struct GNUNET_ATS_Properties *hbo)
 Convert ATS properties from host to network byte order. More...
 
static void reconnect (struct GNUNET_ATS_TransportHandle *ath)
 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_TransportHandle *ath)
 Disconnect from ATS and then reconnect. More...
 
static int check_ats_address_suggestion (void *cls, const struct AddressSuggestionMessage *m)
 Check format of address suggestion message from the service. More...
 
static void handle_ats_address_suggestion (void *cls, const struct AddressSuggestionMessage *m)
 We received an address suggestion message from the service. More...
 
static int match_session_cb (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Finds matching session record. More...
 
static struct GNUNET_ATS_SessionRecordfind_session (struct GNUNET_ATS_TransportHandle *ath, uint32_t session_id, const struct GNUNET_PeerIdentity *pid)
 Find session record for peer pid and session session_id. More...
 
static void handle_ats_session_allocation (void *cls, const struct SessionAllocationMessage *m)
 We received a session allocation message from the service. 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 void send_add_session_message (const struct GNUNET_ATS_SessionRecord *ar)
 Generate and transmit the struct SessionAddMessage for the given session record. More...
 
static int send_add_session_cb (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Send ATS information about the session record. More...
 
struct GNUNET_ATS_TransportHandleGNUNET_ATS_transport_init (const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_ATS_AllocationCallback alloc_cb, void *alloc_cb_cls, GNUNET_ATS_SuggestionCallback suggest_cb, void *suggest_cb_cls)
 Initialize the ATS subsystem. More...
 
static int free_record (void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
 Release memory associated with the session record. More...
 
void GNUNET_ATS_transport_done (struct GNUNET_ATS_TransportHandle *ath)
 Client is done with ATS transport, release resources. More...
 
struct GNUNET_ATS_SessionRecordGNUNET_ATS_session_add (struct GNUNET_ATS_TransportHandle *ath, const struct GNUNET_PeerIdentity *pid, const char *address, struct GNUNET_ATS_Session *session, const struct GNUNET_ATS_Properties *prop)
 We have a new session ATS should know. More...
 
void GNUNET_ATS_session_update (struct GNUNET_ATS_SessionRecord *ar, const struct GNUNET_ATS_Properties *prop)
 We have updated performance statistics for a given session. More...
 
void GNUNET_ATS_session_del (struct GNUNET_ATS_SessionRecord *ar)
 A session was destroyed, ATS should now schedule and allocate under the assumption that this ar is no longer in use. More...
 

Detailed Description

address suggestions and bandwidth allocation

Author
Christian Grothoff
Matthias Wachs

Definition in file ats_api2_transport.c.

Macro Definition Documentation

◆ LOG

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

Function Documentation

◆ properties_hton()

static void properties_hton ( struct PropertiesNBO nbo,
const struct GNUNET_ATS_Properties hbo 
)
static

Convert ATS properties from host to network byte order.

Parameters
nbo[OUT]value written
hbovalue read

Definition at line 140 of file ats_api2_transport.c.

References GNUNET_ATS_SessionRecord::ath, GNUNET_ATS_Properties::cc, PropertiesNBO::cc, PropertiesNBO::delay, GNUNET_ATS_Properties::delay, PropertiesNBO::distance, GNUNET_ATS_Properties::distance, GNUNET_TIME_relative_hton(), PropertiesNBO::goodput_in, GNUNET_ATS_Properties::goodput_in, PropertiesNBO::goodput_out, GNUNET_ATS_Properties::goodput_out, PropertiesNBO::mtu, GNUNET_ATS_Properties::mtu, PropertiesNBO::nt, GNUNET_ATS_Properties::nt, reconnect(), PropertiesNBO::utilization_in, GNUNET_ATS_Properties::utilization_in, PropertiesNBO::utilization_out, and GNUNET_ATS_Properties::utilization_out.

Referenced by GNUNET_ATS_session_update(), and send_add_session_message().

142 {
143  nbo->delay = GNUNET_TIME_relative_hton (hbo->delay);
144  nbo->goodput_out = htonl (hbo->goodput_out);
145  nbo->goodput_in = htonl (hbo->goodput_in);
146  nbo->utilization_out = htonl (hbo->utilization_out);
147  nbo->utilization_in = htonl (hbo->utilization_in);
148  nbo->distance = htonl (hbo->distance);
149  nbo->mtu = htonl (hbo->mtu);
150  nbo->nt = htonl ((uint32_t) hbo->nt);
151  nbo->cc = htonl ((uint32_t) hbo->cc);
152 }
uint32_t cc
What characteristics does this communicator have? A enum GNUNET_TRANSPORT_CommunicatorCharacteristics...
Definition: ats2.h:102
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
Definition: ats2.h:77
uint32_t goodput_out
Confirmed successful payload on this connection from this peer to the other peer. ...
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc
What characteristics does this communicator have?
uint32_t goodput_out
Confirmed successful payload on this connection from this peer to the other peer. ...
Definition: ats2.h:53
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
Definition: ats2.h:69
uint32_t mtu
MTU of the network layer, UINT32_MAX for no MTU (stream).
Definition: ats2.h:90
uint32_t distance
Distance on network layer (required for distance-vector routing) in hops.
Definition: ats2.h:83
struct GNUNET_TIME_Relative delay
Delay.
uint32_t goodput_in
Confirmed useful payload on this connection to this peer from the other peer.
uint32_t mtu
MTU of the network layer, UINT32_MAX for no MTU (stream).
uint32_t nt
Which network scope does the respective address belong to? A enum GNUNET_NetworkType nt in NBO...
Definition: ats2.h:96
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:623
enum GNUNET_NetworkType nt
Which network scope does the respective address belong to?
struct GNUNET_TIME_RelativeNBO delay
Delay.
Definition: ats2.h:45
uint32_t goodput_in
Confirmed useful payload on this connection to this peer from the other peer.
Definition: ats2.h:61
unsigned int distance
Distance on network layer (required for distance-vector routing) in hops.
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reconnect()

static void reconnect ( struct GNUNET_ATS_TransportHandle ath)
static

Re-establish the connection to the ATS service.

Parameters
shhandle to use to re-connect.
athhandle to use to re-connect.

Definition at line 434 of file ats_api2_transport.c.

References GNUNET_ATS_TransportHandle::cfg, error_handler(), force_reconnect(), GNUNET_assert, GNUNET_break, GNUNET_CLIENT_connect(), GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION, GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION, GNUNET_MESSAGE_TYPE_ATS_START, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), init, GNUNET_ATS_TransportHandle::mq, GNUNET_ATS_TransportHandle::records, and send_add_session_cb().

Referenced by GNUNET_ATS_transport_init(), properties_hton(), and reconnect_task().

435 {
437  GNUNET_MQ_hd_var_size (ats_address_suggestion,
440  ath),
441  GNUNET_MQ_hd_fixed_size (ats_session_allocation,
444  ath),
446  };
447  struct GNUNET_MQ_Envelope *ev;
448  struct GNUNET_MessageHeader *init;
449 
450  GNUNET_assert (NULL == ath->mq);
451  ath->mq = GNUNET_CLIENT_connect (ath->cfg,
452  "ats",
453  handlers,
454  &error_handler,
455  ath);
456  if (NULL == ath->mq)
457  {
458  GNUNET_break (0);
459  force_reconnect (ath);
460  return;
461  }
462  ev = GNUNET_MQ_msg (init,
464  GNUNET_MQ_send (ath->mq,
465  ev);
466  if (NULL == ath->mq)
467  return;
470  ath);
471 }
#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 * 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:1058
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_MESSAGE_TYPE_ATS_ADDRESS_SUGGESTION
Type of the 'struct AddressSuggestionMessage' sent by ATS to clients to suggest switching to a differ...
static void force_reconnect(struct GNUNET_ATS_TransportHandle *ath)
Disconnect from ATS and then reconnect.
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
We encountered an error handling the MQ to the ATS service.
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:67
struct GNUNET_CONTAINER_MultiPeerMap * records
Hash map mapping PIDs to session records.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_ALLOCATION
Type of the 'struct SessionAllocationMessage' send by ATS to the transport to tell it about resources...
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
ATS Service allocates resources to an session identified by the given session_id for the given peer w...
Definition: ats2.h:231
const struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Message handler for a specific message type.
static char * init
Set to the name of a service to start.
Definition: gnunet-arm.c:74
static int send_add_session_cb(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Send ATS information about the session record.
ATS Service suggests to the transport service to use the address identified by the given session_id f...
Definition: ats.h:244
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
Header for all communications.
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
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
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 170 of file ats_api2_transport.c.

References reconnect(), and GNUNET_ATS_TransportHandle::task.

Referenced by force_reconnect().

171 {
172  struct GNUNET_ATS_TransportHandle *ath = cls;
173 
174  ath->task = NULL;
175  reconnect (ath);
176 }
static void reconnect(struct GNUNET_ATS_TransportHandle *ath)
Re-establish the connection to the ATS service.
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
Handle to the ATS subsystem for bandwidth/transport transport information.
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_TransportHandle ath)
static

Disconnect from ATS and then reconnect.

Parameters
athour handle

Definition at line 185 of file ats_api2_transport.c.

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

Referenced by error_handler(), and reconnect().

186 {
187  if (NULL != ath->mq)
188  {
189  GNUNET_MQ_destroy (ath->mq);
190  ath->mq = NULL;
191  }
192  /* FIXME: do we tell transport service about disconnect events? CON:
193  initially ATS will have a really screwed picture of the world and
194  the rapid change would be bad. PRO: if we don't, ATS and
195  transport may disagree about the allocation for a while...
196  For now: lazy: do nothing. */
200  ath);
201 }
static void reconnect_task(void *cls)
Re-establish the connection to the ATS service.
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:1253
struct GNUNET_SCHEDULER_Task * task
Task to trigger reconnect.
#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.
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:

◆ check_ats_address_suggestion()

static int check_ats_address_suggestion ( void *  cls,
const struct AddressSuggestionMessage m 
)
static

Check format of address suggestion message from the service.

Parameters
clsthe struct GNUNET_ATS_TransportHandle
mmessage received

Definition at line 211 of file ats_api2_transport.c.

References GNUNET_MQ_check_zero_termination, and GNUNET_SYSERR.

213 {
214  (void) cls;
216  return GNUNET_SYSERR;
217 }
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76

◆ handle_ats_address_suggestion()

static void handle_ats_address_suggestion ( void *  cls,
const struct AddressSuggestionMessage m 
)
static

We received an address suggestion message from the service.

Parameters
clsthe struct GNUNET_ATS_TransportHandle
mmessage received

Definition at line 227 of file ats_api2_transport.c.

References GNUNET_ATS_SessionRecord::address, AddressSuggestionMessage::peer, GNUNET_ATS_TransportHandle::suggest_cb, and GNUNET_ATS_TransportHandle::suggest_cb_cls.

229 {
230  struct GNUNET_ATS_TransportHandle *ath = cls;
231  const char *address = (const char *) &m[1];
232 
233  ath->suggest_cb (ath->suggest_cb_cls,
234  &m->peer,
235  address);
236 }
void * suggest_cb_cls
Closure for suggest_cb.
GNUNET_ATS_SuggestionCallback suggest_cb
Callback to invoke on suggestions.
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but may enable client to find the session faster and/or check consistency).
Definition: ats.h:262
static char * address
GNS address for this phone.
Handle to the ATS subsystem for bandwidth/transport transport information.

◆ match_session_cb()

static int match_session_cb ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Finds matching session record.

Parameters
clsa struct FindContext
pidpeer identity (unused)
valuea struct GNUNET_ATS_SessionRecord
Returns
GNUNET_NO if match found, GNUNET_YES to continue searching

Definition at line 265 of file ats_api2_transport.c.

References GNUNET_NO, GNUNET_YES, FindContext::session_id, GNUNET_ATS_SessionRecord::slot, FindContext::sr, and value.

Referenced by find_session().

268 {
269  struct FindContext *fc = cls;
270  struct GNUNET_ATS_SessionRecord *sr = value;
271 
272  (void) pid;
273  if (fc->session_id == sr->slot)
274  {
275  fc->sr = sr;
276  return GNUNET_NO;
277  }
278  return GNUNET_YES;
279 }
struct GNUNET_ATS_SessionRecord * sr
Where to store the result.
#define GNUNET_NO
Definition: gnunet_common.h:78
Closure for match_session_cb.
Information we track per session, incoming or outgoing.
uint32_t slot
Unique ID to identify this session at this pid in IPC messages.
static char * value
Value of the record to add/remove.
uint32_t session_id
Key to look for.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the caller graph for this function:

◆ find_session()

static struct GNUNET_ATS_SessionRecord* find_session ( struct GNUNET_ATS_TransportHandle ath,
uint32_t  session_id,
const struct GNUNET_PeerIdentity pid 
)
static

Find session record for peer pid and session session_id.

Parameters
athtransport handle to search
session_idsession ID to match
pidpeer to search under
Returns
NULL if no such record exists

Definition at line 292 of file ats_api2_transport.c.

References GNUNET_CONTAINER_multipeermap_get_multiple(), match_session_cb(), GNUNET_ATS_TransportHandle::records, session_id, FindContext::session_id, and FindContext::sr.

Referenced by GNUNET_ATS_session_add(), and handle_ats_session_allocation().

295 {
296  struct FindContext fc = {
298  .sr = NULL
299  };
300 
302  pid,
304  &fc);
305  return fc.sr;
306 }
static int match_session_cb(void *cls, const struct GNUNET_PeerIdentity *pid, void *value)
Finds matching session record.
struct GNUNET_ATS_SessionRecord * sr
Where to store the result.
struct GNUNET_CONTAINER_MultiPeerMap * records
Hash map mapping PIDs to session records.
static struct GNUNET_HashCode session_id
Closure for match_session_cb.
uint32_t session_id
Key to look for.
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ handle_ats_session_allocation()

static void handle_ats_session_allocation ( void *  cls,
const struct SessionAllocationMessage m 
)
static

We received a session allocation message from the service.

Parameters
clsthe struct GNUNET_ATS_TransportHandle
mmessage received

Definition at line 316 of file ats_api2_transport.c.

References GNUNET_ATS_SessionRecord::address, GNUNET_ATS_TransportHandle::alloc_cb, GNUNET_ATS_TransportHandle::alloc_cb_cls, GNUNET_ATS_TransportHandle::backoff, SessionAllocationMessage::bandwidth_in, SessionAllocationMessage::bandwidth_out, find_session(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_TIME_UNIT_ZERO, LOG, SessionAllocationMessage::peer, GNUNET_ATS_SessionRecord::pid, GNUNET_ATS_SessionRecord::session, session_id, and SessionAllocationMessage::session_id.

318 {
319  struct GNUNET_ATS_TransportHandle *ath = cls;
320  struct GNUNET_ATS_SessionRecord *ar;
321  uint32_t session_id;
322 
323  session_id = ntohl (m->session_id);
324  ar = find_session (ath,
325  session_id,
326  &m->peer);
327  if (NULL == ar)
328  {
329  /* this can (rarely) happen if ATS changes an sessiones allocation
330  just when the transport service deleted it */
332  "Allocation ignored, session unknown\n");
333  return;
334  }
337  "ATS allocates bandwidth for peer `%s' using address %s\n",
338  GNUNET_i2s (&ar->pid),
339  ar->address);
340  ath->alloc_cb (ath->alloc_cb_cls,
341  ar->session,
342  m->bandwidth_out,
343  m->bandwidth_in);
344 }
void * alloc_cb_cls
Closure for alloc_cb.
struct GNUNET_PeerIdentity peer
Which peer is this about? (Technically redundant, as the session_id should be sufficient, but may enable client to find the session faster and/or check consistency).
Definition: ats2.h:249
struct GNUNET_PeerIdentity pid
Identity of the peer reached at address.
GNUNET_ATS_AllocationCallback alloc_cb
Callback to invoke on allocations.
static struct GNUNET_HashCode session_id
Information we track per session, incoming or outgoing.
static struct GNUNET_ATS_SessionRecord * find_session(struct GNUNET_ATS_TransportHandle *ath, uint32_t session_id, const struct GNUNET_PeerIdentity *pid)
Find session record for peer pid and session session_id.
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out
How much bandwidth we are allowed for sending.
Definition: ats2.h:254
uint32_t session_id
Internal number this client uses to refer to the session this suggestion is about.
Definition: ats2.h:242
struct GNUNET_ATS_Session * session
Session handle, NULL if inbound-only (also implies we cannot actually control inbound traffic via tra...
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
const char * address
Address data.
#define GNUNET_log(kind,...)
#define LOG(kind,...)
struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in
How much bandwidth we are allowed for receiving.
Definition: ats2.h:259
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_TIME_Relative backoff
Reconnect backoff delay.
Handle to the ATS subsystem for bandwidth/transport transport information.
Here is the call 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_TransportHandle
errordetails about the error

Definition at line 355 of file ats_api2_transport.c.

References force_reconnect(), GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by reconnect().

357 {
358  struct GNUNET_ATS_TransportHandle *ath = cls;
359 
361  "ATS connection died (code %d), reconnecting\n",
362  (int) error);
363  force_reconnect (ath);
364 }
static void force_reconnect(struct GNUNET_ATS_TransportHandle *ath)
Disconnect from ATS and then reconnect.
#define LOG(kind,...)
Handle to the ATS subsystem for bandwidth/transport transport information.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ send_add_session_message()

static void send_add_session_message ( const struct GNUNET_ATS_SessionRecord ar)
static

Generate and transmit the struct SessionAddMessage for the given session record.

Parameters
arthe session to inform the ATS service about

Definition at line 374 of file ats_api2_transport.c.

References GNUNET_ATS_SessionRecord::address, GNUNET_ATS_SessionRecord::ath, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_memcpy, GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD, GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), LOG, m, GNUNET_ATS_TransportHandle::mq, SessionAddMessage::peer, GNUNET_ATS_SessionRecord::pid, GNUNET_ATS_SessionRecord::properties, SessionAddMessage::properties, properties_hton(), GNUNET_ATS_SessionRecord::session, SessionAddMessage::session_id, and GNUNET_ATS_SessionRecord::slot.

Referenced by GNUNET_ATS_session_add(), and send_add_session_cb().

375 {
376  struct GNUNET_ATS_TransportHandle *ath = ar->ath;
377  struct GNUNET_MQ_Envelope *ev;
378  struct SessionAddMessage *m;
379  size_t alen;
380 
381  if (NULL == ath->mq)
382  return; /* disconnected, skip for now */
383  alen = strlen (ar->address) + 1;
384  ev = GNUNET_MQ_msg_extra (m,
385  alen,
386  (NULL == ar->session)
389  m->peer = ar->pid;
390  m->session_id = htonl (ar->slot);
392  &ar->properties);
393  GNUNET_memcpy (&m[1],
394  ar->address,
395  alen);
396 
398  "Adding address `%s' for peer `%s'\n",
399  ar->address,
400  GNUNET_i2s (&ar->pid));
401  GNUNET_MQ_send (ath->mq,
402  ev);
403 }
struct GNUNET_PeerIdentity pid
Identity of the peer reached at address.
uint32_t session_id
Internal number this client will henceforth use to refer to this session.
Definition: ats2.h:152
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static void properties_hton(struct PropertiesNBO *nbo, const struct GNUNET_ATS_Properties *hbo)
Convert ATS properties from host to network byte order.
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD_INBOUND_ONLY
Type of the 'struct SessionAddMessage' send by transport clients to ATS to inform ATS about a session...
Transport client to ATS service: here is another session you can use.
Definition: ats2.h:140
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:104
uint32_t slot
Unique ID to identify this session at this pid in IPC messages.
#define GNUNET_MQ_msg_extra(mvar, esize, type)
Allocate an envelope, with extra space allocated after the space needed by the message struct...
Definition: gnunet_mq_lib.h:52
struct GNUNET_ATS_TransportHandle * ath
Transport handle this session record belongs to.
struct GNUNET_ATS_Session * session
Session handle, NULL if inbound-only (also implies we cannot actually control inbound traffic via tra...
struct GNUNET_PeerIdentity peer
Identity of the peer that this session is for.
Definition: ats2.h:157
const char * address
Address data.
struct GNUNET_ATS_Properties properties
Performance data about the session.
#define LOG(kind,...)
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
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Handle to the ATS subsystem for bandwidth/transport transport information.
struct PropertiesNBO properties
Performance properties of the session.
Definition: ats2.h:162
#define GNUNET_MESSAGE_TYPE_ATS_SESSION_ADD
Type of the 'struct SessionAddMessage' send by transport clients to ATS to ask ATS to allocate resour...
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:

◆ send_add_session_cb()

static int send_add_session_cb ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Send ATS information about the session record.

Parameters
clsour struct GNUNET_ATS_TransportHandle *, unused
pidunused
valuethe struct GNUNET_ATS_SessionRecord * to add
Returns
GNUNET_OK

Definition at line 415 of file ats_api2_transport.c.

References GNUNET_OK, send_add_session_message(), and value.

Referenced by reconnect().

418 {
419  struct GNUNET_ATS_SessionRecord *ar = value;
420 
421  (void) cls;
422  (void) pid;
424  return GNUNET_OK;
425 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Information we track per session, incoming or outgoing.
static char * value
Value of the record to add/remove.
static void send_add_session_message(const struct GNUNET_ATS_SessionRecord *ar)
Generate and transmit the struct SessionAddMessage for the given session record.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_record()

static int free_record ( void *  cls,
const struct GNUNET_PeerIdentity pid,
void *  value 
)
static

Release memory associated with the session record.

Parameters
clsNULL
pidunused
valuea struct GNUNET_ATS_SessionRecord
Returns
GNUNET_OK

Definition at line 515 of file ats_api2_transport.c.

References GNUNET_free, GNUNET_OK, and value.

Referenced by GNUNET_ATS_transport_done().

518 {
519  struct GNUNET_ATS_SessionRecord *ar = value;
520 
521  (void) cls;
522  (void) pid;
523  GNUNET_free (ar);
524  return GNUNET_OK;
525 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
Information we track per session, incoming or outgoing.
static char * value
Value of the record to add/remove.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the caller graph for this function: