GNUnet  0.11.x
Data Structures | Macros | Functions
transport_api2_core.c File Reference
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_arm_service.h"
#include "gnunet_hello_lib.h"
#include "gnunet_protocols.h"
#include "gnunet_transport_core_service.h"
#include "transport.h"
Include dependency graph for transport_api2_core.c:

Go to the source code of this file.

Data Structures

struct  Neighbour
 A connected controller which is not our child. More...
 
struct  GNUNET_TRANSPORT_CoreHandle
 Handle for the transport service (includes all of the state for the transport service). More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "transport-api-core", __VA_ARGS__)
 
#define STARTING_NEIGHBOURS_SIZE   16
 How large to start with for the hashmap of neighbours. More...
 
#define SEND_WINDOW_SIZE   4
 Window size. More...
 

Functions

static void disconnect_and_schedule_reconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
 Function that will schedule the job that will try to connect us again to the client. More...
 
static struct Neighbourneighbour_find (struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
 Get the neighbour list entry for the given peer. More...
 
static int neighbour_delete (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Iterator over hash map entries, for deleting state of a neighbour. More...
 
static void mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue. More...
 
static void notify_send_done (void *cls)
 A message from the handler's message queue to a neighbour was transmitted. More...
 
static void do_send (struct Neighbour *n)
 We have an envelope waiting for transmission at n, and our transmission window is positive. More...
 
static void mq_send_impl (struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
 Implement sending functionality of a message queue. More...
 
static void mq_destroy_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Handle destruction of a message queue. More...
 
static void mq_cancel_impl (struct GNUNET_MQ_Handle *mq, void *impl_state)
 Implementation function that cancels the currently sent message. More...
 
static void peer_mq_error_handler (void *cls, enum GNUNET_MQ_Error error)
 We had an error processing a message we forwarded from a peer to the CORE service. More...
 
static void handle_connect (void *cls, const struct ConnectInfoMessage *cim)
 Function we use for handling incoming connect messages. More...
 
static void handle_disconnect (void *cls, const struct DisconnectInfoMessage *dim)
 Function we use for handling incoming disconnect messages. More...
 
static void handle_send_ok (void *cls, const struct SendOkMessage *okm)
 Function we use for handling incoming send-ok messages. More...
 
static int check_recv (void *cls, const struct InboundMessage *im)
 Function we use for checking incoming "inbound" messages. More...
 
static void handle_recv (void *cls, const struct InboundMessage *im)
 Function we use for handling incoming messages. More...
 
static void reconnect (void *cls)
 Try again to connect to transport service. More...
 
static void disconnect (struct GNUNET_TRANSPORT_CoreHandle *h)
 Disconnect from the transport service. More...
 
struct GNUNET_MQ_HandleGNUNET_TRANSPORT_core_get_mq (struct GNUNET_TRANSPORT_CoreHandle *handle, const struct GNUNET_PeerIdentity *peer)
 Checks if a given peer is connected to us and get the message queue. More...
 

Macro Definition Documentation

◆ LOG

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

◆ STARTING_NEIGHBOURS_SIZE

#define STARTING_NEIGHBOURS_SIZE   16

How large to start with for the hashmap of neighbours.

Definition at line 40 of file transport_api2_core.c.

Referenced by GNUNET_TRANSPORT_core_get_mq().

◆ SEND_WINDOW_SIZE

#define SEND_WINDOW_SIZE   4

Window size.

How many messages to the same target do we pass to TRANSPORT without a SEND_OK in between? Small values limit thoughput, large values will increase latency.

FIXME-OPTIMIZE: find out what good values are experimentally, maybe set adaptively (i.e. to observed available bandwidth).

Definition at line 50 of file transport_api2_core.c.

Referenced by handle_connect().

Function Documentation

◆ disconnect_and_schedule_reconnect()

static void disconnect_and_schedule_reconnect ( struct GNUNET_TRANSPORT_CoreHandle h)
static

Function that will schedule the job that will try to connect us again to the client.

Parameters
htransport service to reconnect

Definition at line 645 of file transport_api2_core.c.

References disconnect(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, LOG, reconnect(), GNUNET_TRANSPORT_CoreHandle::reconnect_delay, and GNUNET_TRANSPORT_CoreHandle::reconnect_task.

Referenced by handle_connect(), handle_disconnect(), handle_recv(), handle_send_ok(), and mq_error_handler().

646 {
647  GNUNET_assert (NULL == h->reconnect_task);
648  disconnect (h);
650  "Scheduling task to reconnect to transport service in %s.\n",
652  h->reconnect_task =
655 }
static void reconnect(void *cls)
Try again to connect to transport service.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void disconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Disconnect from the transport service.
struct GNUNET_TIME_Relative reconnect_delay
Delay until we try to 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:1253
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
#define LOG(kind,...)
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
#define GNUNET_YES
Definition: gnunet_common.h:77
Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighbour_find()

static struct Neighbour* neighbour_find ( struct GNUNET_TRANSPORT_CoreHandle h,
const struct GNUNET_PeerIdentity peer 
)
static

Get the neighbour list entry for the given peer.

Parameters
hour context
peerpeer to look up
Returns
NULL if no such peer entry exists

Definition at line 189 of file transport_api2_core.c.

References GNUNET_CONTAINER_multipeermap_get(), and GNUNET_TRANSPORT_CoreHandle::neighbours.

Referenced by GNUNET_TRANSPORT_core_get_mq(), handle_connect(), handle_disconnect(), handle_recv(), and handle_send_ok().

191 {
193 }
struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map of the current connected neighbours of this peer.
void * GNUNET_CONTAINER_multipeermap_get(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key)
Given a key find a value in the map matching the key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ neighbour_delete()

static int neighbour_delete ( void *  cls,
const struct GNUNET_PeerIdentity key,
void *  value 
)
static

Iterator over hash map entries, for deleting state of a neighbour.

Parameters
clsthe struct GNUNET_TRANSPORT_CoreHandle *
keypeer identity
valuevalue in the hash map, the neighbour entry to delete
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 207 of file transport_api2_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, Neighbour::env, GNUNET_assert, GNUNET_CONTAINER_multipeermap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_MQ_destroy(), GNUNET_MQ_send_cancel(), GNUNET_YES, handle, Neighbour::handlers_cls, Neighbour::id, LOG, Neighbour::mq, GNUNET_TRANSPORT_CoreHandle::nd_cb, GNUNET_TRANSPORT_CoreHandle::neighbours, and value.

Referenced by disconnect(), and handle_disconnect().

208 {
210  struct Neighbour *n = value;
211 
213  "Dropping entry for neighbour `%s'.\n",
214  GNUNET_i2s (key));
215  if (NULL != handle->nd_cb)
216  handle->nd_cb (handle->cls, &n->id, n->handlers_cls);
217  if (NULL != n->env)
218  {
220  n->env = NULL;
221  }
222  GNUNET_MQ_destroy (n->mq);
223  GNUNET_assert (NULL == n->mq);
224  GNUNET_assert (
225  GNUNET_YES ==
227  GNUNET_free (n);
228  return GNUNET_YES;
229 }
A connected controller which is not our child.
void * cls
Closure for the callbacks.
void * handlers_cls
Closure for mq handlers.
GNUNET_TRANSPORT_NotifyDisconnect nd_cb
function to call on disconnect events
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
int GNUNET_CONTAINER_multipeermap_remove(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Remove the given key-value pair from the map.
struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map of the current connected neighbours of this peer.
static char * value
Value of the record to add/remove.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
#define LOG(kind,...)
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_MQ_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
Handle for the transport service (includes all of the state for the transport service).
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:916
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_error_handler()

static void mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

Generic error handler, called with the appropriate error code and the same closure specified at the creation of the message queue.

Not every message queue implementation supports an error handler.

Parameters
clsclosure with the struct GNUNET_TRANSPORT_CoreHandle *
errorerror code

Definition at line 242 of file transport_api2_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_ERROR_TYPE_DEBUG, Neighbour::h, and LOG.

Referenced by reconnect().

243 {
245 
247  "Error receiving from transport service, disconnecting temporarily.\n");
249 }
void * cls
Closure for the callbacks.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Function that will schedule the job that will try to connect us again to the client.
#define LOG(kind,...)
Handle for the transport service (includes all of the state for the transport service).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ notify_send_done()

static void notify_send_done ( void *  cls)
static

A message from the handler's message queue to a neighbour was transmitted.

Now trigger (possibly delayed) notification of the neighbour's message queue that we are done and thus ready for the next message. Note that the MQ being ready is independent of the send window, as we may queue many messages and simply not pass them to TRANSPORT if the send window is insufficient.

Parameters
clsthe struct Neighbour where the message was sent

Definition at line 263 of file transport_api2_core.c.

References Neighbour::awaiting_done, Neighbour::env, GNUNET_MQ_impl_send_continue(), GNUNET_NO, and Neighbour::mq.

Referenced by do_send().

264 {
265  struct Neighbour *n = cls;
266 
268  n->env = NULL;
270 }
A connected controller which is not our child.
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
#define GNUNET_NO
Definition: gnunet_common.h:78
int16_t awaiting_done
Used to indicate our status if env is non-NULL.
struct GNUNET_MQ_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:486
Here is the call graph for this function:
Here is the caller graph for this function:

◆ do_send()

static void do_send ( struct Neighbour n)
static

We have an envelope waiting for transmission at n, and our transmission window is positive.

Perform the transmission.

Parameters
nneighbour to perform transmission for

Definition at line 280 of file transport_api2_core.c.

References Neighbour::awaiting_done, Neighbour::env, GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_env_get_msg(), GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_YES, Neighbour::h, Neighbour::id, LOG, GNUNET_TRANSPORT_CoreHandle::mq, notify_send_done(), Neighbour::ready_window, and GNUNET_MessageHeader::type.

Referenced by handle_send_ok(), and mq_send_impl().

281 {
282  GNUNET_assert (0 < n->ready_window);
283  GNUNET_assert (NULL != n->env);
284  n->ready_window--;
287  GNUNET_MQ_send (n->h->mq, n->env);
289  "Passed message of type %u for neighbour `%s' to TRANSPORT.\n",
290  ntohs (GNUNET_MQ_env_get_msg (n->env)->type),
291  GNUNET_i2s (&n->id));
292 }
const struct GNUNET_MessageHeader * GNUNET_MQ_env_get_msg(const struct GNUNET_MQ_Envelope *env)
Obtain message contained in envelope.
Definition: mq.c:1080
struct GNUNET_TRANSPORT_CoreHandle * h
Overall transport handle.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MQ_Handle * mq
My client connection to the transport service.
static void notify_send_done(void *cls)
A message from the handler&#39;s message queue to a neighbour was transmitted.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
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:774
struct GNUNET_PeerIdentity id
Identity of this neighbour.
unsigned int ready_window
How many messages can we still send to this peer before we should throttle?
#define LOG(kind,...)
int16_t awaiting_done
Used to indicate our status if env is non-NULL.
#define GNUNET_YES
Definition: gnunet_common.h:77
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_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_send_impl()

static void mq_send_impl ( struct GNUNET_MQ_Handle mq,
const struct GNUNET_MessageHeader msg,
void *  impl_state 
)
static

Implement sending functionality of a message queue.

Called one message at a time. Should send the msg to the transport service and then notify the queue once we are ready for the next one.

Parameters
mqthe message queue
msgthe message to send
impl_statestate of the implementation

Definition at line 306 of file transport_api2_core.c.

References do_send(), Neighbour::env, Neighbour::env_size, GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MAX_MESSAGE_SIZE, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND, GNUNET_MQ_env_get_options(), GNUNET_MQ_get_current_envelope(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_msg_nested_mh, Neighbour::id, LOG, OutboundMessage::peer, OutboundMessage::priority, Neighbour::ready_window, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

Referenced by handle_connect().

309 {
310  struct Neighbour *n = impl_state;
311  struct OutboundMessage *obm;
312  uint16_t msize;
313 
314  msize = ntohs (msg->size);
315  if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof(*obm))
316  {
317  GNUNET_break (0);
319  return;
320  }
322  "CORE requested transmission of message of type %u to neighbour `%s'.\n",
323  ntohs (msg->type),
324  GNUNET_i2s (&n->id));
325 
326  GNUNET_assert (NULL == n->env);
327  n->env =
329  n->env_size = ntohs (msg->size);
330  {
331  struct GNUNET_MQ_Envelope *env;
332 
334  obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
335  }
336  obm->peer = n->id;
337  if (0 == n->ready_window)
338  {
340  "Flow control delays transmission to CORE until we see SEND_OK.\n");
341  return; /* can't send yet, need to wait for SEND_OK */
342  }
343  do_send (n);
344 }
A connected controller which is not our child.
uint32_t priority
An enum GNUNET_MQ_PriorityPreferences in NBO.
Definition: transport.h:294
#define GNUNET_MQ_msg_nested_mh(mvar, type, mh)
Allocate a GNUNET_MQ_Envelope, and append a payload message after the given message struct...
struct GNUNET_PeerIdentity peer
Which peer should receive the message?
Definition: transport.h:308
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#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_TRANSPORT_SEND
Request to TRANSPORT to transmit a message.
enum GNUNET_MQ_PriorityPreferences GNUNET_MQ_env_get_options(struct GNUNET_MQ_Envelope *env)
Get performance preferences set for this envelope.
Definition: mq.c:1020
uint16_t env_size
Size of the message in env.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
Message used to notify the transport service about a message to be transmitted to another peer...
Definition: transport.h:284
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
unsigned int ready_window
How many messages can we still send to this peer before we should throttle?
#define LOG(kind,...)
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
struct GNUNET_MQ_Envelope * GNUNET_MQ_get_current_envelope(struct GNUNET_MQ_Handle *mq)
Function to obtain the current envelope from within GNUNET_MQ_SendImpl implementations.
Definition: mq.c:974
struct GNUNET_MQ_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
void GNUNET_MQ_impl_send_continue(struct GNUNET_MQ_Handle *mq)
Call the send implementation for the next queued message, if any.
Definition: mq.c:486
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static void do_send(struct Neighbour *n)
We have an envelope waiting for transmission at n, and our transmission window is positive...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ mq_destroy_impl()

static void mq_destroy_impl ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Handle destruction of a message queue.

Implementations must not free mq, but should take care of impl_state.

Parameters
mqthe message queue to destroy
impl_statestate of the implementation

Definition at line 355 of file transport_api2_core.c.

References GNUNET_assert, and Neighbour::mq.

Referenced by handle_connect().

356 {
357  struct Neighbour *n = impl_state;
358 
359  GNUNET_assert (mq == n->mq);
360  n->mq = NULL;
361 }
A connected controller which is not our child.
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
Here is the caller graph for this function:

◆ mq_cancel_impl()

static void mq_cancel_impl ( struct GNUNET_MQ_Handle mq,
void *  impl_state 
)
static

Implementation function that cancels the currently sent message.

Should basically undo whatever mq_send_impl() did.

Parameters
mqmessage queue
impl_statestate specific to the implementation

Definition at line 372 of file transport_api2_core.c.

References Neighbour::awaiting_done, Neighbour::env, GNUNET_assert, GNUNET_MQ_send_cancel(), GNUNET_NO, GNUNET_YES, and Neighbour::ready_window.

Referenced by handle_connect().

373 {
374  struct Neighbour *n = impl_state;
375 
376  n->ready_window++;
377  if (GNUNET_YES == n->awaiting_done)
378  {
380  n->env = NULL;
382  }
383  else
384  {
385  GNUNET_assert (0 == n->ready_window);
386  n->env = NULL;
387  }
388 }
A connected controller which is not our child.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
unsigned int ready_window
How many messages can we still send to this peer before we should throttle?
int16_t awaiting_done
Used to indicate our status if env is non-NULL.
#define GNUNET_YES
Definition: gnunet_common.h:77
struct GNUNET_MQ_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
void GNUNET_MQ_send_cancel(struct GNUNET_MQ_Envelope *ev)
Cancel sending the message.
Definition: mq.c:916
Here is the call graph for this function:
Here is the caller graph for this function:

◆ peer_mq_error_handler()

static void peer_mq_error_handler ( void *  cls,
enum GNUNET_MQ_Error  error 
)
static

We had an error processing a message we forwarded from a peer to the CORE service.

We should just complain about it but otherwise continue processing.

Parameters
clsclosure
errorerror code

Definition at line 400 of file transport_api2_core.c.

References GNUNET_break_op.

Referenced by handle_connect().

401 {
402  /* struct Neighbour *n = cls; */
403 
404  GNUNET_break_op (0);
405 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Here is the caller graph for this function:

◆ handle_connect()

static void handle_connect ( void *  cls,
const struct ConnectInfoMessage cim 
)
static

Function we use for handling incoming connect messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_Handle *
cimmessage received

Definition at line 415 of file transport_api2_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_CONTAINER_multipeermap_put(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_queue_for_callbacks(), GNUNET_MQ_set_handlers_closure(), GNUNET_new, GNUNET_OK, Neighbour::h, GNUNET_TRANSPORT_CoreHandle::handlers, Neighbour::handlers_cls, ConnectInfoMessage::id, Neighbour::id, LOG, Neighbour::mq, mq_cancel_impl(), mq_destroy_impl(), mq_send_impl(), GNUNET_TRANSPORT_CoreHandle::nc_cb, neighbour_find(), GNUNET_TRANSPORT_CoreHandle::neighbours, peer_mq_error_handler(), Neighbour::ready_window, and SEND_WINDOW_SIZE.

416 {
418  struct Neighbour *n;
419 
421  "Receiving CONNECT message for `%s'\n",
422  GNUNET_i2s (&cim->id));
423  n = neighbour_find (h, &cim->id);
424  if (NULL != n)
425  {
426  GNUNET_break (0);
428  return;
429  }
430  n = GNUNET_new (struct Neighbour);
431  n->id = cim->id;
432  n->h = h;
436  h->neighbours,
437  &n->id,
438  n,
440 
444  n,
445  h->handlers,
447  n);
448  if (NULL != h->nc_cb)
449  {
450  n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq);
452  }
453 }
struct GNUNET_MQ_MessageHandler * handlers
Functions to call for received data (template for new message queues).
A connected controller which is not our child.
struct GNUNET_PeerIdentity id
Identity of the new neighbour.
Definition: transport.h:141
void * cls
Closure for the callbacks.
void * handlers_cls
Closure for mq handlers.
struct GNUNET_TRANSPORT_CoreHandle * h
Overall transport handle.
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
GNUNET_TRANSPORT_NotifyConnect nc_cb
function to call on connect events
static void mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
static void peer_mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
We had an error processing a message we forwarded from a peer to the CORE service.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map of the current connected neighbours of this peer.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
void GNUNET_MQ_set_handlers_closure(struct GNUNET_MQ_Handle *mq, void *handlers_cls)
Change the closure argument in all of the handlers of the mq.
Definition: mq.c:583
struct GNUNET_MQ_Handle * GNUNET_MQ_queue_for_callbacks(GNUNET_MQ_SendImpl send, GNUNET_MQ_DestroyImpl destroy, GNUNET_MQ_CancelImpl cancel, void *impl_state, const struct GNUNET_MQ_MessageHandler *handlers, GNUNET_MQ_ErrorHandler error_handler, void *cls)
Create a message queue for the specified handlers.
Definition: mq.c:552
struct GNUNET_PeerIdentity id
Identity of this neighbour.
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Function that will schedule the job that will try to connect us again to the client.
There must only be one value per key; storing a value should fail if a value under the same key alrea...
unsigned int ready_window
How many messages can we still send to this peer before we should throttle?
#define LOG(kind,...)
static void mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
int GNUNET_CONTAINER_multipeermap_put(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, void *value, enum GNUNET_CONTAINER_MultiHashMapOption opt)
Store a key-value pair in the map.
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
Handle for the transport service (includes all of the state for the transport service).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static void mq_send_impl(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *msg, void *impl_state)
Implement sending functionality of a message queue.
#define SEND_WINDOW_SIZE
Window size.
Here is the call graph for this function:

◆ handle_disconnect()

static void handle_disconnect ( void *  cls,
const struct DisconnectInfoMessage dim 
)
static

Function we use for handling incoming disconnect messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_CoreHandle *
dimmessage received

Definition at line 463 of file transport_api2_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_YES, Neighbour::h, LOG, neighbour_delete(), neighbour_find(), DisconnectInfoMessage::peer, and DisconnectInfoMessage::reserved.

464 {
466  struct Neighbour *n;
467 
468  GNUNET_break (ntohl (dim->reserved) == 0);
470  "Receiving DISCONNECT message for `%s'.\n",
471  GNUNET_i2s (&dim->peer));
472  n = neighbour_find (h, &dim->peer);
473  if (NULL == n)
474  {
475  GNUNET_break (0);
477  return;
478  }
479  GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n));
480 }
A connected controller which is not our child.
void * cls
Closure for the callbacks.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries, for deleting state of a neighbour.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
uint32_t reserved
Reserved, always zero.
Definition: transport.h:159
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Function that will schedule the job that will try to connect us again to the client.
#define LOG(kind,...)
struct GNUNET_PeerIdentity peer
Who got disconnected?
Definition: transport.h:164
#define GNUNET_YES
Definition: gnunet_common.h:77
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
Handle for the transport service (includes all of the state for the transport service).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:

◆ handle_send_ok()

static void handle_send_ok ( void *  cls,
const struct SendOkMessage okm 
)
static

Function we use for handling incoming send-ok messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_CoreHandle *
okmmessage received

Definition at line 490 of file transport_api2_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), do_send(), Neighbour::env, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), Neighbour::h, LOG, neighbour_find(), SendOkMessage::peer, and Neighbour::ready_window.

491 {
493  struct Neighbour *n;
494 
496  "Receiving SEND_OK message for transmission to %s\n",
497  GNUNET_i2s (&okm->peer));
498  n = neighbour_find (h, &okm->peer);
499  if (NULL == n)
500  {
501  /* We should never get a 'SEND_OK' for a peer that we are not
502  connected to */
503  GNUNET_break (0);
505  return;
506  }
507  n->ready_window++;
508  if ((NULL != n->env) && (1 == n->ready_window))
509  do_send (n);
510 }
A connected controller which is not our child.
void * cls
Closure for the callbacks.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Function that will schedule the job that will try to connect us again to the client.
unsigned int ready_window
How many messages can we still send to this peer before we should throttle?
#define LOG(kind,...)
struct GNUNET_PeerIdentity peer
Which peer can send more now?
Definition: transport.h:251
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
struct GNUNET_MQ_Envelope * env
Envelope with the message we are currently transmitting (or NULL).
Handle for the transport service (includes all of the state for the transport service).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
static void do_send(struct Neighbour *n)
We have an envelope waiting for transmission at n, and our transmission window is positive...
Here is the call graph for this function:

◆ check_recv()

static int check_recv ( void *  cls,
const struct InboundMessage im 
)
static

Function we use for checking incoming "inbound" messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_CoreHandle *
immessage received

Definition at line 520 of file transport_api2_core.c.

References GNUNET_break, GNUNET_OK, GNUNET_SYSERR, InboundMessage::header, size, and GNUNET_MessageHeader::size.

521 {
522  const struct GNUNET_MessageHeader *imm;
523  uint16_t size;
524 
525  size = ntohs (im->header.size) - sizeof(*im);
526  if (size < sizeof(struct GNUNET_MessageHeader))
527  {
528  GNUNET_break (0);
529  return GNUNET_SYSERR;
530  }
531  imm = (const struct GNUNET_MessageHeader *) &im[1];
532  if (ntohs (imm->size) != size)
533  {
534  GNUNET_break (0);
535  return GNUNET_SYSERR;
536  }
537  return GNUNET_OK;
538 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static unsigned int size
Size of the "table".
Definition: peer.c:67
Header for all communications.
struct GNUNET_MessageHeader header
Type will be GNUNET_MESSAGE_TYPE_TRANSPORT_RECV.
Definition: transport.h:203

◆ handle_recv()

static void handle_recv ( void *  cls,
const struct InboundMessage im 
)
static

Function we use for handling incoming messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_CoreHandle *
immessage received

Definition at line 548 of file transport_api2_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_MQ_inject_message(), Neighbour::h, LOG, Neighbour::mq, neighbour_find(), InboundMessage::peer, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

549 {
551  const struct GNUNET_MessageHeader *imm =
552  (const struct GNUNET_MessageHeader *) &im[1];
553  struct Neighbour *n;
554 
556  "Received message of type %u with %u bytes from `%s'.\n",
557  (unsigned int) ntohs (imm->type),
558  (unsigned int) ntohs (imm->size),
559  GNUNET_i2s (&im->peer));
560  n = neighbour_find (h, &im->peer);
561  if (NULL == n)
562  {
563  GNUNET_break (0);
565  return;
566  }
567  GNUNET_MQ_inject_message (n->mq, imm);
568 }
A connected controller which is not our child.
void * cls
Closure for the callbacks.
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
void GNUNET_MQ_inject_message(struct GNUNET_MQ_Handle *mq, const struct GNUNET_MessageHeader *mh)
Call the message message handler that was registered for the type of the given message in the given m...
Definition: mq.c:202
static void disconnect_and_schedule_reconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Function that will schedule the job that will try to connect us again to the client.
struct GNUNET_PeerIdentity peer
Which peer sent the message?
Definition: transport.h:208
#define LOG(kind,...)
Header for all communications.
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
Handle for the transport service (includes all of the state for the transport service).
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
Here is the call graph for this function:

◆ reconnect()

static void reconnect ( void *  cls)
static

Try again to connect to transport service.

Parameters
clsthe handle to the transport service

Definition at line 577 of file transport_api2_core.c.

References GNUNET_TRANSPORT_CoreHandle::cfg, GNUNET_TRANSPORT_CoreHandle::check_self, GNUNET_TRANSPORT_CoreHandle::cls, disconnect(), Neighbour::env, GNUNET_assert, GNUNET_CLIENT_connect(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT, GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT, GNUNET_MESSAGE_TYPE_TRANSPORT_RECV, GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK, GNUNET_MESSAGE_TYPE_TRANSPORT_START, GNUNET_MQ_handler_end, GNUNET_MQ_hd_fixed_size, GNUNET_MQ_hd_var_size, GNUNET_MQ_msg, GNUNET_MQ_send(), Neighbour::h, GNUNET_TRANSPORT_CoreHandle::handlers, LOG, GNUNET_TRANSPORT_CoreHandle::mq, mq_error_handler(), options, StartMessage::options, GNUNET_TRANSPORT_CoreHandle::reconnect_task, StartMessage::self, and GNUNET_TRANSPORT_CoreHandle::self.

Referenced by disconnect_and_schedule_reconnect(), and GNUNET_TRANSPORT_core_get_mq().

578 {
581  { GNUNET_MQ_hd_fixed_size (connect,
583  struct ConnectInfoMessage,
584  h),
587  struct DisconnectInfoMessage,
588  h),
589  GNUNET_MQ_hd_fixed_size (send_ok,
591  struct SendOkMessage,
592  h),
593  GNUNET_MQ_hd_var_size (recv,
595  struct InboundMessage,
596  h),
598  struct GNUNET_MQ_Envelope *env;
599  struct StartMessage *s;
600  uint32_t options;
601 
602  h->reconnect_task = NULL;
603  LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
604  GNUNET_assert (NULL == h->mq);
605  h->mq =
606  GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h);
607  if (NULL == h->mq)
608  return;
610  options = 0;
611  if (h->check_self)
612  options |= 1;
613  if (NULL != h->handlers)
614  options |= 2;
615  s->options = htonl (options);
616  s->self = h->self;
617  GNUNET_MQ_send (h->mq, env);
618 }
struct GNUNET_MQ_MessageHandler * handlers
Functions to call for received data (template for new message queues).
void * cls
Closure for the callbacks.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
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
const struct GNUNET_CONFIGURATION_Handle * cfg
My configuration.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_MQ_Handle * mq
My client connection to the transport service.
static void disconnect(struct GNUNET_TRANSPORT_CoreHandle *h)
Disconnect from the transport 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_PeerIdentity self
Identity we think we have.
Definition: transport.h:109
struct GNUNET_PeerIdentity self
Peer identity as assumed by this process, or all zeros.
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:99
#define GNUNET_MESSAGE_TYPE_TRANSPORT_CONNECT
Message from TRANSPORT notifying about a client that connected to us.
static struct GNUNET_CADET_MessageHandler handlers[]
Handlers, for diverse services.
#define GNUNET_MQ_hd_var_size(name, code, str, ctx)
uint32_t options
0: no options 1: The self field should be checked 2: this client is interested in payload traffic ...
Definition: transport.h:103
Message from the transport service to the library informing about neighbors.
Definition: transport.h:117
int check_self
Should we check that self matches what the service thinks? (if GNUNET_NO, then self is all zeros!)...
#define GNUNET_MESSAGE_TYPE_TRANSPORT_START
Message from the core saying that the transport server should start giving it messages.
Message handler for a specific message type.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_DISCONNECT
Message from TRANSPORT notifying about a client that disconnected from us.
Message from the transport service to the library asking to check if both processes agree about this ...
Definition: transport.h:91
Message from the transport service to the library informing about disconnects.
Definition: transport.h:149
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SEND_OK
Confirmation from TRANSPORT that message for transmission has been queued (and that the next message ...
#define LOG(kind,...)
Message used to notify the transport API that it can send another message to the transport service...
Definition: transport.h:216
#define GNUNET_MESSAGE_TYPE_TRANSPORT_RECV
Message from TRANSPORT notifying about a message that was received.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
Handle for the transport service (includes all of the state for the transport service).
#define GNUNET_MQ_handler_end()
End-marker for the handlers array.
Message used to notify the transport API about a message received from the network.
Definition: transport.h:198
static void mq_error_handler(void *cls, enum GNUNET_MQ_Error error)
Generic error handler, called with the appropriate error code and the same closure specified at the c...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect()

static void disconnect ( struct GNUNET_TRANSPORT_CoreHandle h)
static

Disconnect from the transport service.

Parameters
htransport service to reconnect

Definition at line 627 of file transport_api2_core.c.

References GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_MQ_destroy(), GNUNET_TRANSPORT_CoreHandle::mq, neighbour_delete(), and GNUNET_TRANSPORT_CoreHandle::neighbours.

Referenced by disconnect_and_schedule_reconnect(), GNUNET_TRANSPORT_core_get_mq(), and reconnect().

628 {
630  if (NULL != h->mq)
631  {
632  GNUNET_MQ_destroy (h->mq);
633  h->mq = NULL;
634  }
635 }
struct GNUNET_MQ_Handle * mq
My client connection to the transport service.
static int neighbour_delete(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Iterator over hash map entries, for deleting state of a neighbour.
struct GNUNET_CONTAINER_MultiPeerMap * neighbours
Hash map of the current connected neighbours of this peer.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
Here is the call graph for this function:
Here is the caller graph for this function: