GNUnet  0.20.0
transport_api2_communication.c File Reference

implementation of the gnunet_transport_communication_service.h API More...

Include dependency graph for transport_api2_communication.c:

Go to the source code of this file.

Data Structures

struct  FlowControl
 Information we track per packet to enable flow control. More...
 
struct  AckPending
 Information we track per message to tell the transport about success or failures. More...
 
struct  GNUNET_TRANSPORT_CommunicatorHandle
 Opaque handle to the transport service for communicators. More...
 
struct  GNUNET_TRANSPORT_QueueHandle
 Handle returned to identify the internal data structure the transport API has created to manage a message queue to a particular peer. More...
 
struct  GNUNET_TRANSPORT_AddressIdentifier
 Internal representation of an address a communicator is currently providing for the transport service. More...
 

Macros

#define DEFAULT_MAX_QUEUE_LENGTH   16
 How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file). More...
 

Functions

static void reconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
 (re)connect our communicator to the transport service More...
 
static void send_add_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
 Send message to the transport service about address ai being now available. More...
 
static void send_del_address (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
 Send message to the transport service about address ai being no longer available. More...
 
static void send_add_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
 Send message to the transport service about queue qh being now available. More...
 
static void send_update_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
 Send message to the transport service about queue qh updated. More...
 
static void send_del_queue (struct GNUNET_TRANSPORT_QueueHandle *qh)
 Send message to the transport service about queue qh being no longer available. More...
 
static void disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
 Disconnect from the transport service. More...
 
static void error_handler (void *cls, enum GNUNET_MQ_Error error)
 Function called on MQ errors. More...
 
static void handle_incoming_ack (void *cls, const struct GNUNET_TRANSPORT_IncomingMessageAck *incoming_ack)
 Transport service acknowledged a message we gave it (with flow control enabled). More...
 
static int check_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
 Transport service wants us to create a queue. More...
 
static void handle_create_queue (void *cls, const struct GNUNET_TRANSPORT_CreateQueue *cq)
 Transport service wants us to create a queue. More...
 
static int check_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
 Transport service wants us to send a message. More...
 
static void send_ack (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, int status, const struct GNUNET_PeerIdentity *receiver, uint64_t mid, uint32_t qid)
 Notify transport service about status of a message with mid sent to receiver. More...
 
static void send_ack_cb (void *cls)
 Message queue transmission by communicator was successful, notify transport service. More...
 
static void handle_send_msg (void *cls, const struct GNUNET_TRANSPORT_SendMessageTo *smt)
 Transport service wants us to send a message. More...
 
static int check_backchannel_incoming (void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
 Transport service gives us backchannel message. More...
 
static void handle_backchannel_incoming (void *cls, const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *bi)
 Transport service gives us backchannel message. More...
 
struct GNUNET_TRANSPORT_CommunicatorHandleGNUNET_TRANSPORT_communicator_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const char *config_section, const char *addr_prefix, enum GNUNET_TRANSPORT_CommunicatorCharacteristics cc, GNUNET_TRANSPORT_CommunicatorMqInit mq_init, void *mq_init_cls, GNUNET_TRANSPORT_CommunicatorNotify notify_cb, void *notify_cb_cls)
 Connect to the transport service. More...
 
void GNUNET_TRANSPORT_communicator_disconnect (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
 Disconnect from the transport service. More...
 
int GNUNET_TRANSPORT_communicator_receive (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *sender, const struct GNUNET_MessageHeader *msg, struct GNUNET_TIME_Relative expected_addr_validity, GNUNET_TRANSPORT_MessageCompletedCallback cb, void *cb_cls)
 Notify transport service that the communicator has received a message. More...
 
struct GNUNET_TRANSPORT_QueueHandleGNUNET_TRANSPORT_communicator_mq_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *peer, const char *address, uint32_t mtu, uint64_t q_len, uint32_t priority, enum GNUNET_NetworkType nt, enum GNUNET_TRANSPORT_ConnectionStatus cs, struct GNUNET_MQ_Handle *mq)
 Notify transport service that a MQ became available due to an "inbound" connection or because the communicator discovered the presence of another peer. More...
 
void GNUNET_TRANSPORT_communicator_mq_update (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_TRANSPORT_QueueHandle *u_qh, uint64_t q_len, uint32_t priority)
 Notify transport service that an MQ was updated. More...
 
void GNUNET_TRANSPORT_communicator_mq_del (struct GNUNET_TRANSPORT_QueueHandle *qh)
 Notify transport service that an MQ became unavailable due to a disconnect or timeout. More...
 
struct GNUNET_TRANSPORT_AddressIdentifierGNUNET_TRANSPORT_communicator_address_add (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const char *address, enum GNUNET_NetworkType nt, struct GNUNET_TIME_Relative expiration)
 Notify transport service about an address that this communicator provides for this peer. More...
 
void GNUNET_TRANSPORT_communicator_address_remove (struct GNUNET_TRANSPORT_AddressIdentifier *ai)
 Notify transport service about an address that this communicator no longer provides for this peer. More...
 
void GNUNET_TRANSPORT_communicator_address_remove_all (struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
 Notify transport service that this communicator no longer provides all its addresses for this peer. More...
 
void GNUNET_TRANSPORT_communicator_notify (struct GNUNET_TRANSPORT_CommunicatorHandle *ch, const struct GNUNET_PeerIdentity *pid, const char *comm, const struct GNUNET_MessageHeader *header)
 The communicator asks the transport service to route a message via a different path to another communicator service at another peer. More...
 

Detailed Description

implementation of the gnunet_transport_communication_service.h API

Author
Christian Grothoff

Definition in file transport_api2_communication.c.

Macro Definition Documentation

◆ DEFAULT_MAX_QUEUE_LENGTH

#define DEFAULT_MAX_QUEUE_LENGTH   16

How many messages do we keep at most in the queue to the transport service before we start to drop (default, can be changed via the configuration file).

Definition at line 39 of file transport_api2_communication.c.

Function Documentation

◆ reconnect()

static void reconnect ( struct GNUNET_TRANSPORT_CommunicatorHandle ch)
static

(re)connect our communicator to the transport service

Parameters
chhandle to reconnect

Definition at line 772 of file transport_api2_communication.c.

773 {
775  { GNUNET_MQ_hd_fixed_size (incoming_ack,
777  struct GNUNET_TRANSPORT_IncomingMessageAck,
778  ch),
779  GNUNET_MQ_hd_var_size (create_queue,
781  struct GNUNET_TRANSPORT_CreateQueue,
782  ch),
785  struct GNUNET_TRANSPORT_SendMessageTo,
786  ch),
788  backchannel_incoming,
790  struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming,
791  ch),
793  struct GNUNET_TRANSPORT_CommunicatorAvailableMessage *cam;
794  struct GNUNET_MQ_Envelope *env;
795 
796  ch->mq =
797  GNUNET_CLIENT_connect (ch->cfg, "transport", handlers, &error_handler, ch);
798  if (NULL == ch->mq)
799  return;
800  env = GNUNET_MQ_msg_extra (cam,
801  strlen (ch->addr_prefix) + 1,
803  cam->cc = htonl ((uint32_t) ch->cc);
804  memcpy (&cam[1], ch->addr_prefix, strlen (ch->addr_prefix) + 1);
805  GNUNET_MQ_send (ch->mq, env);
806  for (struct GNUNET_TRANSPORT_AddressIdentifier *ai = ch->ai_head; NULL != ai;
807  ai = ai->next)
809  for (struct GNUNET_TRANSPORT_QueueHandle *qh = ch->queue_head; NULL != qh;
810  qh = qh->next)
811  send_add_queue (qh);
812 }
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
static struct GNUNET_CADET_Channel * ch
Channel handle.
Definition: gnunet-cadet.c:117
static struct GNUNET_TRANSPORT_AddressIdentifier * ai
Handle to the operation that publishes our address.
static void send_msg(void *cls)
Function called to notify a client about the socket begin ready to queue more data.
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
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_handler_end()
End-marker for the handlers array.
#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:63
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
#define GNUNET_MQ_hd_fixed_size(name, code, str, ctx)
#define GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK
transport acknowledges processing an incoming message
#define GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR
Message sent to indicate to the transport which address prefix is supported by a communicator.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE
transport tells communicator it wants a queue
#define GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING
Transport signalling incoming backchannel message to a communicator.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG
transport tells communicator it wants to transmit
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.
Internal representation of an address a communicator is currently providing for the transport service...
struct GNUNET_TRANSPORT_AddressIdentifier * next
Kept in a DLL.
Handle returned to identify the internal data structure the transport API has created to manage a mes...
static void error_handler(void *cls, enum GNUNET_MQ_Error error)
Function called on MQ errors.
static void send_add_address(struct GNUNET_TRANSPORT_AddressIdentifier *ai)
Send message to the transport service about address ai being now available.
static void send_add_queue(struct GNUNET_TRANSPORT_QueueHandle *qh)
Send message to the transport service about queue qh being now available.

References ai, ch, env, error_handler(), GNUNET_CLIENT_connect(), GNUNET_MESSAGE_TYPE_TRANSPORT_COMMUNICATOR_BACKCHANNEL_INCOMING, GNUNET_MESSAGE_TYPE_TRANSPORT_INCOMING_MSG_ACK, GNUNET_MESSAGE_TYPE_TRANSPORT_NEW_COMMUNICATOR, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), handlers, GNUNET_CADET_Channel::mq, GNUNET_TRANSPORT_AddressIdentifier::next, send_add_address(), send_add_queue(), and send_msg().

Referenced by error_handler(), GNUNET_TRANSPORT_communicator_connect(), and handle_incoming_ack().

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

◆ send_add_address()

static void send_add_address ( struct GNUNET_TRANSPORT_AddressIdentifier ai)
static

Send message to the transport service about address ai being now available.

Parameters
aiaddress to add

Definition at line 361 of file transport_api2_communication.c.

362 {
363  struct GNUNET_MQ_Envelope *env;
364  struct GNUNET_TRANSPORT_AddAddressMessage *aam;
365 
366  if (NULL == ai->ch->mq)
367  return;
368  env = GNUNET_MQ_msg_extra (aam,
369  strlen (ai->address) + 1,
371  aam->expiration = GNUNET_TIME_relative_hton (ai->expiration);
372  aam->nt = htonl ((uint32_t) ai->nt);
373  memcpy (&aam[1], ai->address, strlen (ai->address) + 1);
374  GNUNET_MQ_send (ai->ch->mq, env);
375 }
#define GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS
inform transport to add an address of this peer
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:618
struct GNUNET_TIME_Relative expiration
When does the address expire? (Expected lifetime of the address.)
enum GNUNET_NetworkType nt
Network type for the address.
struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Transport handle where the address was added.
struct GNUNET_MQ_Handle * mq
Queue to talk to the transport service.

References GNUNET_TRANSPORT_AddressIdentifier::address, ai, GNUNET_TRANSPORT_AddressIdentifier::ch, env, GNUNET_TRANSPORT_AddressIdentifier::expiration, GNUNET_MESSAGE_TYPE_TRANSPORT_ADD_ADDRESS, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_TIME_relative_hton(), GNUNET_TRANSPORT_CommunicatorHandle::mq, and GNUNET_TRANSPORT_AddressIdentifier::nt.

Referenced by GNUNET_TRANSPORT_communicator_address_add(), and reconnect().

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

◆ send_del_address()

static void send_del_address ( struct GNUNET_TRANSPORT_AddressIdentifier ai)
static

Send message to the transport service about address ai being no longer available.

Parameters
aiaddress to delete

Definition at line 385 of file transport_api2_communication.c.

386 {
387  struct GNUNET_MQ_Envelope *env;
388  struct GNUNET_TRANSPORT_DelAddressMessage *dam;
389 
390  if (NULL == ai->ch->mq)
391  return;
393  dam->aid = htonl (ai->aid);
394  GNUNET_MQ_send (ai->ch->mq, env);
395 }
#define GNUNET_MQ_msg(mvar, type)
Allocate a GNUNET_MQ_Envelope.
Definition: gnunet_mq_lib.h:78
#define GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS
inform transport to delete an address of this peer
uint32_t aid
Internal UUID for the address used in communication with the transport service.

References ai, GNUNET_TRANSPORT_AddressIdentifier::aid, GNUNET_TRANSPORT_AddressIdentifier::ch, env, GNUNET_MESSAGE_TYPE_TRANSPORT_DEL_ADDRESS, GNUNET_MQ_msg, GNUNET_MQ_send(), and GNUNET_TRANSPORT_CommunicatorHandle::mq.

Referenced by GNUNET_TRANSPORT_communicator_address_remove().

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

◆ send_add_queue()

static void send_add_queue ( struct GNUNET_TRANSPORT_QueueHandle qh)
static

Send message to the transport service about queue qh being now available.

Parameters
qhqueue to add

Definition at line 405 of file transport_api2_communication.c.

406 {
407  struct GNUNET_MQ_Envelope *env;
408  struct GNUNET_TRANSPORT_AddQueueMessage *aqm;
409 
410  if (NULL == qh->ch->mq)
411  return;
413  "Sending `GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP` message\n");
414  env = GNUNET_MQ_msg_extra (aqm,
415  strlen (qh->address) + 1,
417  aqm->qid = htonl (qh->queue_id);
418  aqm->receiver = qh->peer;
419  aqm->nt = htonl ((uint32_t) qh->nt);
420  aqm->mtu = htonl (qh->mtu);
421  aqm->q_len = GNUNET_htonll (qh->q_len);
422  aqm->priority = htonl (qh->priority);
423  aqm->cs = htonl ((uint32_t) qh->cs);
424  memcpy (&aqm[1], qh->address, strlen (qh->address) + 1);
425  GNUNET_MQ_send (qh->ch->mq, env);
426 }
#define GNUNET_log(kind,...)
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:37
@ GNUNET_ERROR_TYPE_DEBUG
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP
inform transport that a queue was setup to talk to some peer
enum GNUNET_TRANSPORT_ConnectionStatus cs
Communication status of the queue.
uint32_t queue_id
ID for this queue when talking to the transport service.
uint32_t mtu
Maximum transmission unit for the queue.
char * address
Address used by the communication queue.
enum GNUNET_NetworkType nt
Network type of the communication queue.
struct GNUNET_PeerIdentity peer
Which peer we can communciate with.
struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Handle this queue belongs to.

References GNUNET_TRANSPORT_QueueHandle::address, GNUNET_TRANSPORT_QueueHandle::ch, GNUNET_TRANSPORT_QueueHandle::cs, env, GNUNET_ERROR_TYPE_DEBUG, GNUNET_htonll(), GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_SETUP, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_TRANSPORT_CommunicatorHandle::mq, GNUNET_TRANSPORT_QueueHandle::mtu, GNUNET_TRANSPORT_QueueHandle::nt, GNUNET_TRANSPORT_QueueHandle::peer, GNUNET_TRANSPORT_QueueHandle::priority, GNUNET_TRANSPORT_QueueHandle::q_len, and GNUNET_TRANSPORT_QueueHandle::queue_id.

Referenced by GNUNET_TRANSPORT_communicator_mq_add(), and reconnect().

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

◆ send_update_queue()

static void send_update_queue ( struct GNUNET_TRANSPORT_QueueHandle qh)
static

Send message to the transport service about queue qh updated.

Parameters
qhqueue to add

Definition at line 436 of file transport_api2_communication.c.

437 {
438  struct GNUNET_MQ_Envelope *env;
439  struct GNUNET_TRANSPORT_UpdateQueueMessage *uqm;
440 
441  if (NULL == qh->ch->mq)
442  return;
444  uqm->qid = htonl (qh->queue_id);
445  uqm->receiver = qh->peer;
446  uqm->nt = htonl ((uint32_t) qh->nt);
447  uqm->mtu = htonl (qh->mtu);
448  uqm->q_len = GNUNET_htonll (qh->q_len);
449  uqm->priority = htonl (qh->priority);
450  uqm->cs = htonl ((uint32_t) qh->cs);
451  GNUNET_MQ_send (qh->ch->mq, env);
452 }
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE
inform transport that a queue was updated

References GNUNET_TRANSPORT_QueueHandle::ch, GNUNET_TRANSPORT_QueueHandle::cs, env, GNUNET_htonll(), GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_UPDATE, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_TRANSPORT_CommunicatorHandle::mq, GNUNET_TRANSPORT_QueueHandle::mtu, GNUNET_TRANSPORT_QueueHandle::nt, GNUNET_TRANSPORT_QueueHandle::peer, GNUNET_TRANSPORT_QueueHandle::priority, GNUNET_TRANSPORT_QueueHandle::q_len, and GNUNET_TRANSPORT_QueueHandle::queue_id.

Referenced by GNUNET_TRANSPORT_communicator_mq_update().

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

◆ send_del_queue()

static void send_del_queue ( struct GNUNET_TRANSPORT_QueueHandle qh)
static

Send message to the transport service about queue qh being no longer available.

Parameters
qhqueue to delete

Definition at line 462 of file transport_api2_communication.c.

463 {
464  struct GNUNET_MQ_Envelope *env;
465  struct GNUNET_TRANSPORT_DelQueueMessage *dqm;
466 
467  if (NULL == qh->ch->mq)
468  return;
470  dqm->qid = htonl (qh->queue_id);
471  dqm->receiver = qh->peer;
472  GNUNET_MQ_send (qh->ch->mq, env);
473 }
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN
inform transport that a queue was torn down

References GNUNET_TRANSPORT_QueueHandle::ch, env, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_TEARDOWN, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_TRANSPORT_CommunicatorHandle::mq, GNUNET_TRANSPORT_QueueHandle::peer, and GNUNET_TRANSPORT_QueueHandle::queue_id.

Referenced by GNUNET_TRANSPORT_communicator_mq_del().

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

◆ disconnect()

static void disconnect ( struct GNUNET_TRANSPORT_CommunicatorHandle ch)
static

Disconnect from the transport service.

Purges all flow control entries as we will no longer receive the ACKs. Purges the ack pending entries as the transport will no longer expect the confirmations.

Parameters
chservice to disconnect from

Definition at line 485 of file transport_api2_communication.c.

486 {
487  struct FlowControl *fcn;
488  struct AckPending *apn;
489 
490  for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fcn)
491  {
492  fcn = fc->next;
493  GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
494  fc->cb (fc->cb_cls, GNUNET_SYSERR);
495  GNUNET_free (fc);
496  }
497  for (struct AckPending *ap = ch->ap_head; NULL != ap; ap = apn)
498  {
499  apn = ap->next;
500  GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
501  GNUNET_free (ap);
502  }
503  if (NULL == ch->mq)
504  return;
506  ch->mq = NULL;
507 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
@ GNUNET_SYSERR
#define GNUNET_free(ptr)
Wrapper around free.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:683
Information we track per message to tell the transport about success or failures.
struct AckPending * next
Kept in a DLL.
Information we track per packet to enable flow control.
struct FlowControl * next
Kept in a DLL.

References ch, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_MQ_destroy(), GNUNET_SYSERR, GNUNET_CADET_Channel::mq, FlowControl::next, and AckPending::next.

Referenced by error_handler(), GNUNET_TRANSPORT_communicator_disconnect(), and handle_incoming_ack().

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

Function called on MQ errors.

Definition at line 514 of file transport_api2_communication.c.

515 {
517 
519  "MQ failure %d, reconnecting to transport service.\n",
520  error);
521  disconnect (ch);
522  /* TODO: maybe do this with exponential backoff/delay */
523  reconnect (ch);
524 }
@ GNUNET_ERROR_TYPE_INFO
Opaque handle to the transport service for communicators.
static void reconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
(re)connect our communicator to the transport service
static void disconnect(struct GNUNET_TRANSPORT_CommunicatorHandle *ch)
Disconnect from the transport service.

References ch, disconnect(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, and reconnect().

Referenced by reconnect().

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

◆ handle_incoming_ack()

static void handle_incoming_ack ( void *  cls,
const struct GNUNET_TRANSPORT_IncomingMessageAck *  incoming_ack 
)
static

Transport service acknowledged a message we gave it (with flow control enabled).

Tell the communicator.

Parameters
clsour struct GNUNET_TRANSPORT_CommunicatorHandle *
incoming_ackthe ack

Definition at line 535 of file transport_api2_communication.c.

538 {
540 
541  for (struct FlowControl *fc = ch->fc_head; NULL != fc; fc = fc->next)
542  {
543  if ((fc->id == incoming_ack->fc_id) &&
544  (0 == memcmp (&fc->sender,
545  &incoming_ack->sender,
546  sizeof(struct GNUNET_PeerIdentity))))
547  {
549  "Done with message with flow control id %" PRIu64
550  " for sender %s from sender %s\n",
551  incoming_ack->fc_id,
552  GNUNET_i2s (&fc->sender),
553  GNUNET_i2s (&incoming_ack->sender));
554  GNUNET_CONTAINER_DLL_remove (ch->fc_head, ch->fc_tail, fc);
555  fc->cb (fc->cb_cls, GNUNET_OK);
556  GNUNET_free (fc);
557  return;
558  }
559  }
561  "Message with flow control id %" PRIu64
562  " from sender %s not found\n",
563  incoming_ack->fc_id,
564  GNUNET_i2s (&incoming_ack->sender));
565  GNUNET_break (0);
566  disconnect (ch);
567  /* TODO: maybe do this with exponential backoff/delay */
568  reconnect (ch);
569 }
@ GNUNET_OK
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur.
The identity of the host (wraps the signing key of the peer).

References ch, disconnect(), GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_log, GNUNET_OK, and reconnect().

Here is the call graph for this function:

◆ check_create_queue()

static int check_create_queue ( void *  cls,
const struct GNUNET_TRANSPORT_CreateQueue *  cq 
)
static

Transport service wants us to create a queue.

Check if cq is well-formed.

Parameters
clsour struct GNUNET_TRANSPORT_CommunicatorHandle *
cqthe queue creation request
Returns
GNUNET_OK if smt is well-formed

Definition at line 581 of file transport_api2_communication.c.

582 {
583  (void) cls;
585  return GNUNET_OK;
586 }
#define GNUNET_MQ_check_zero_termination(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...

References GNUNET_MQ_check_zero_termination, and GNUNET_OK.

◆ handle_create_queue()

static void handle_create_queue ( void *  cls,
const struct GNUNET_TRANSPORT_CreateQueue *  cq 
)
static

Transport service wants us to create a queue.

Tell the communicator.

Parameters
clsour struct GNUNET_TRANSPORT_CommunicatorHandle *
cqthe queue creation request

Definition at line 596 of file transport_api2_communication.c.

597 {
599  const char *addr = (const char *) &cq[1];
600  struct GNUNET_TRANSPORT_CreateQueueResponse *cqr;
601  struct GNUNET_MQ_Envelope *env;
602 
603  if (GNUNET_OK != ch->mq_init (ch->mq_init_cls, &cq->receiver, addr))
604  {
606  "Address `%s' invalid for this communicator\n",
607  addr);
609  }
610  else
611  {
613  }
614  cqr->request_id = cq->request_id;
615  GNUNET_MQ_send (ch->mq, env);
616 }
@ GNUNET_ERROR_TYPE_ERROR
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL
Response from communicator: address bogus, will not try to create queue.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK
Response from communicator: will try to create queue.

References ch, env, GNUNET_ERROR_TYPE_ERROR, GNUNET_log, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_FAIL, GNUNET_MESSAGE_TYPE_TRANSPORT_QUEUE_CREATE_OK, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_OK, and GNUNET_CADET_Channel::mq.

Here is the call graph for this function:

◆ check_send_msg()

static int check_send_msg ( void *  cls,
const struct GNUNET_TRANSPORT_SendMessageTo *  smt 
)
static

Transport service wants us to send a message.

Check if smt is well-formed.

Parameters
clsour struct GNUNET_TRANSPORT_CommunicatorHandle *
smtthe transmission request
Returns
GNUNET_OK if smt is well-formed

Definition at line 628 of file transport_api2_communication.c.

629 {
630  (void) cls;
632  return GNUNET_OK;
633 }
#define GNUNET_MQ_check_boxed_message(m)
Insert code for a "check_" function that verifies that a given variable-length message received over ...

References GNUNET_MQ_check_boxed_message, and GNUNET_OK.

◆ send_ack()

static void send_ack ( struct GNUNET_TRANSPORT_CommunicatorHandle ch,
int  status,
const struct GNUNET_PeerIdentity receiver,
uint64_t  mid,
uint32_t  qid 
)
static

Notify transport service about status of a message with mid sent to receiver.

Parameters
chhandle
statusGNUNET_OK on success, GNUNET_SYSERR on failure
receiverwhich peer was the receiver
midmessage that the ack is about

Definition at line 646 of file transport_api2_communication.c.

651 {
652  struct GNUNET_MQ_Envelope *env;
653  struct GNUNET_TRANSPORT_SendMessageToAck *ack;
654 
656  ack->status = htonl (status);
657  ack->mid = mid;
658  ack->qid = qid;
659  ack->receiver = *receiver;
660  GNUNET_MQ_send (ch->mq, env);
661 }
uint16_t status
See PRISM_STATUS_*-constants.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK
communicator tells transports that message was sent
void receiver(void *cls, const void *buf, size_t available, const struct sockaddr *addr, socklen_t addrlen, int errCode)
Callback to read from the SOCKS5 proxy.
Definition: socks.c:330

References ch, env, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_MSG_ACK, GNUNET_MQ_msg, GNUNET_MQ_send(), GNUNET_CADET_Channel::mq, receiver(), and status.

Referenced by handle_send_msg(), and send_ack_cb().

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

◆ send_ack_cb()

static void send_ack_cb ( void *  cls)
static

Message queue transmission by communicator was successful, notify transport service.

Parameters
clsan struct AckPending *

Definition at line 671 of file transport_api2_communication.c.

672 {
673  struct AckPending *ap = cls;
675 
676  GNUNET_CONTAINER_DLL_remove (ch->ap_head, ch->ap_tail, ap);
677  send_ack (ch, GNUNET_OK, &ap->receiver, ap->mid, ap->qid);
678  GNUNET_free (ap);
679 }
uint64_t mid
More-or-less unique ID for the message.
struct GNUNET_TRANSPORT_CommunicatorHandle * ch
Communicator this entry belongs to.
struct GNUNET_PeerIdentity receiver
Which peer is this about?
uint32_t qid
Queue ID of the queue which will be used for the message.
static void send_ack(struct GNUNET_TRANSPORT_CommunicatorHandle *ch, int status, const struct GNUNET_PeerIdentity *receiver, uint64_t mid, uint32_t qid)
Notify transport service about status of a message with mid sent to receiver.

References ch, AckPending::ch, GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_OK, AckPending::mid, AckPending::qid, AckPending::receiver, and send_ack().

Referenced by handle_send_msg().

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

◆ handle_send_msg()

static void handle_send_msg ( void *  cls,
const struct GNUNET_TRANSPORT_SendMessageTo *  smt 
)
static

Transport service wants us to send a message.

Tell the communicator.

Parameters
clsour struct GNUNET_TRANSPORT_CommunicatorHandle *
smtthe transmission request

Definition at line 689 of file transport_api2_communication.c.

690 {
692  const struct GNUNET_MessageHeader *mh;
693  struct GNUNET_MQ_Envelope *env;
694  struct AckPending *ap;
695  struct GNUNET_TRANSPORT_QueueHandle *qh;
696 
697  for (qh = ch->queue_head; NULL != qh; qh = qh->next)
698  if ((qh->queue_id == ntohl (smt->qid)) &&
699  (0 == memcmp (&qh->peer,
700  &smt->receiver,
701  sizeof(struct GNUNET_PeerIdentity))))
702  break;
703  if (NULL == qh)
704  {
705  /* queue is already gone, tell transport this one failed */
707  "Transmission failed, queue no longer exists.\n");
708  send_ack (ch, GNUNET_NO, &smt->receiver, smt->mid, smt->qid);
709  return;
710  }
711  ap = GNUNET_new (struct AckPending);
712  ap->ch = ch;
713  ap->receiver = smt->receiver;
714  ap->mid = smt->mid;
715  ap->qid = smt->qid;
716  GNUNET_CONTAINER_DLL_insert (ch->ap_head, ch->ap_tail, ap);
717  mh = (const struct GNUNET_MessageHeader *) &smt[1];
720  GNUNET_MQ_send (qh->mq, env);
721 }
static struct GNUNET_CADET_Handle * mh
Cadet handle.
Definition: gnunet-cadet.c:92
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
@ GNUNET_NO
#define GNUNET_new(type)
Allocate a struct or union of the given type.
void GNUNET_MQ_notify_sent(struct GNUNET_MQ_Envelope *ev, GNUNET_SCHEDULER_TaskCallback cb, void *cb_cls)
Call a callback once the envelope has been sent, that is, sending it can not be canceled anymore.
Definition: mq.c:638
struct GNUNET_MQ_Envelope * GNUNET_MQ_msg_copy(const struct GNUNET_MessageHeader *hdr)
Create a new envelope by copying an existing message.
Definition: mq.c:533
Header for all communications.
struct GNUNET_MQ_Handle * mq
The queue itself.
struct GNUNET_TRANSPORT_QueueHandle * next
Kept in a DLL.
static void send_ack_cb(void *cls)
Message queue transmission by communicator was successful, notify transport service.

References ch, AckPending::ch, env, GNUNET_CONTAINER_DLL_insert, GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MQ_msg_copy(), GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_new, GNUNET_NO, mh, AckPending::mid, GNUNET_TRANSPORT_QueueHandle::mq, GNUNET_TRANSPORT_QueueHandle::next, GNUNET_TRANSPORT_QueueHandle::peer, AckPending::qid, GNUNET_TRANSPORT_QueueHandle::queue_id, AckPending::receiver, send_ack(), and send_ack_cb().

Here is the call graph for this function:

◆ check_backchannel_incoming()

static int check_backchannel_incoming ( void *  cls,
const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *  bi 
)
static

Transport service gives us backchannel message.

Check if bi is well-formed.

Parameters
clsour struct GNUNET_TRANSPORT_CommunicatorHandle *
bithe backchannel message
Returns
GNUNET_OK if smt is well-formed

Definition at line 733 of file transport_api2_communication.c.

736 {
737  (void) cls;
739  return GNUNET_OK;
740 }

References GNUNET_MQ_check_boxed_message, and GNUNET_OK.

◆ handle_backchannel_incoming()

static void handle_backchannel_incoming ( void *  cls,
const struct GNUNET_TRANSPORT_CommunicatorBackchannelIncoming *  bi 
)
static

Transport service gives us backchannel message.

Handle it.

Parameters
clsour struct GNUNET_TRANSPORT_CommunicatorHandle *
bithe backchannel message

Definition at line 750 of file transport_api2_communication.c.

753 {
755  if (NULL != ch->notify_cb)
756  ch->notify_cb (ch->notify_cb_cls,
757  &bi->pid,
758  (const struct GNUNET_MessageHeader *) &bi[1]);
759  else
760  GNUNET_log (
762  _ ("Dropped backchanel message: handler not provided by communicator\n"));
763 }
#define _(String)
GNU gettext support macro.
Definition: platform.h:178

References _, ch, GNUNET_ERROR_TYPE_INFO, and GNUNET_log.