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 138 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().

140 {
142  nbo->goodput_out = htonl(hbo->goodput_out);
143  nbo->goodput_in = htonl(hbo->goodput_in);
144  nbo->utilization_out = htonl(hbo->utilization_out);
145  nbo->utilization_in = htonl(hbo->utilization_in);
146  nbo->distance = htonl(hbo->distance);
147  nbo->mtu = htonl(hbo->mtu);
148  nbo->nt = htonl((uint32_t)hbo->nt);
149  nbo->cc = htonl((uint32_t)hbo->cc);
150 }
uint32_t cc
What characteristics does this communicator have? A enum GNUNET_TRANSPORT_CommunicatorCharacteristics...
Definition: ats2.h:101
uint32_t utilization_in
Actual traffic on this connection from the other peer to this peer.
Definition: ats2.h:76
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:52
uint32_t utilization_out
Actual traffic on this connection from this peer to the other peer.
Definition: ats2.h:68
uint32_t mtu
MTU of the network layer, UINT32_MAX for no MTU (stream).
Definition: ats2.h:89
uint32_t distance
Distance on network layer (required for distance-vector routing) in hops.
Definition: ats2.h:82
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:95
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:44
uint32_t goodput_in
Confirmed useful payload on this connection to this peer from the other peer.
Definition: ats2.h:60
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 431 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().

432 {
434  GNUNET_MQ_hd_var_size(ats_address_suggestion,
437  ath),
438  GNUNET_MQ_hd_fixed_size(ats_session_allocation,
441  ath),
443  };
444  struct GNUNET_MQ_Envelope *ev;
445  struct GNUNET_MessageHeader *init;
446 
447  GNUNET_assert(NULL == ath->mq);
448  ath->mq = GNUNET_CLIENT_connect(ath->cfg,
449  "ats",
450  handlers,
451  &error_handler,
452  ath);
453  if (NULL == ath->mq)
454  {
455  GNUNET_break(0);
456  force_reconnect(ath);
457  return;
458  }
459  ev = GNUNET_MQ_msg(init,
461  GNUNET_MQ_send(ath->mq,
462  ev);
463  if (NULL == ath->mq)
464  return;
467  ath);
468 }
#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:900
#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:226
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:69
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:237
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:351
#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 168 of file ats_api2_transport.c.

References reconnect(), and GNUNET_ATS_TransportHandle::task.

Referenced by force_reconnect().

169 {
170  struct GNUNET_ATS_TransportHandle *ath = cls;
171 
172  ath->task = NULL;
173  reconnect(ath);
174 }
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 183 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().

184 {
185  if (NULL != ath->mq)
186  {
187  GNUNET_MQ_destroy(ath->mq);
188  ath->mq = NULL;
189  }
190  /* FIXME: do we tell transport service about disconnect events? CON:
191  initially ATS will have a really screwed picture of the world and
192  the rapid change would be bad. PRO: if we don't, ATS and
193  transport may disagree about the allocation for a while...
194  For now: lazy: do nothing. */
198  ath);
199 }
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:1237
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:821
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 209 of file ats_api2_transport.c.

References GNUNET_MQ_check_zero_termination, and GNUNET_SYSERR.

211 {
212  (void)cls;
214  return GNUNET_SYSERR;
215 }
#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 225 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.

227 {
228  struct GNUNET_ATS_TransportHandle *ath = cls;
229  const char *address = (const char *)&m[1];
230 
231  ath->suggest_cb(ath->suggest_cb_cls,
232  &m->peer,
233  address);
234 }
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:254
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 262 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().

265 {
266  struct FindContext *fc = cls;
267  struct GNUNET_ATS_SessionRecord *sr = value;
268 
269  (void)pid;
270  if (fc->session_id == sr->slot)
271  {
272  fc->sr = sr;
273  return GNUNET_NO;
274  }
275  return GNUNET_YES;
276 }
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 289 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().

292 {
293  struct FindContext fc = {
295  .sr = NULL
296  };
297 
299  pid,
301  &fc);
302  return fc.sr;
303 }
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 313 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.

315 {
316  struct GNUNET_ATS_TransportHandle *ath = cls;
317  struct GNUNET_ATS_SessionRecord *ar;
318  uint32_t session_id;
319 
320  session_id = ntohl(m->session_id);
321  ar = find_session(ath,
322  session_id,
323  &m->peer);
324  if (NULL == ar)
325  {
326  /* this can (rarely) happen if ATS changes an sessiones allocation
327  just when the transport service deleted it */
329  "Allocation ignored, session unknown\n");
330  return;
331  }
334  "ATS allocates bandwidth for peer `%s' using address %s\n",
335  GNUNET_i2s(&ar->pid),
336  ar->address);
337  ath->alloc_cb(ath->alloc_cb_cls,
338  ar->session,
339  m->bandwidth_out,
340  m->bandwidth_in);
341 }
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:243
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:248
uint32_t session_id
Internal number this client uses to refer to the session this suggestion is about.
Definition: ats2.h:236
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:253
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 352 of file ats_api2_transport.c.

References force_reconnect(), GNUNET_ERROR_TYPE_DEBUG, and LOG.

Referenced by reconnect().

354 {
355  struct GNUNET_ATS_TransportHandle *ath = cls;
356 
358  "ATS connection died (code %d), reconnecting\n",
359  (int)error);
360  force_reconnect(ath);
361 }
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 371 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().

372 {
373  struct GNUNET_ATS_TransportHandle *ath = ar->ath;
374  struct GNUNET_MQ_Envelope *ev;
375  struct SessionAddMessage *m;
376  size_t alen;
377 
378  if (NULL == ath->mq)
379  return; /* disconnected, skip for now */
380  alen = strlen(ar->address) + 1;
381  ev = GNUNET_MQ_msg_extra(m,
382  alen,
383  (NULL == ar->session)
386  m->peer = ar->pid;
387  m->session_id = htonl(ar->slot);
389  &ar->properties);
390  GNUNET_memcpy(&m[1],
391  ar->address,
392  alen);
393 
395  "Adding address `%s' for peer `%s'\n",
396  ar->address,
397  GNUNET_i2s(&ar->pid));
398  GNUNET_MQ_send(ath->mq,
399  ev);
400 }
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:149
#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:138
static struct GNUNET_ARM_MonitorHandle * m
Monitor connection with ARM.
Definition: gnunet-arm.c:99
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:154
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:351
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:159
#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 412 of file ats_api2_transport.c.

References GNUNET_OK, send_add_session_message(), and value.

Referenced by reconnect().

415 {
416  struct GNUNET_ATS_SessionRecord *ar = value;
417 
418  (void)cls;
419  (void)pid;
421  return GNUNET_OK;
422 }
#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 512 of file ats_api2_transport.c.

References GNUNET_free, GNUNET_OK, and value.

Referenced by GNUNET_ATS_transport_done().

515 {
516  struct GNUNET_ATS_SessionRecord *ar = value;
517 
518  (void)cls;
519  (void)pid;
520  GNUNET_free(ar);
521  return GNUNET_OK;
522 }
#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: