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

library to access the transport service for message exchange More...

#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_service.h"
#include "transport.h"
Include dependency graph for transport_api_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 UNREADY_WARN_TIME   GNUNET_TIME_UNIT_MINUTES
 If we could not send any payload to a peer for this amount of time, we print a warning. More...
 
#define STARTING_NEIGHBOURS_SIZE   16
 How large to start with for the hashmap of neighbours. 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 void notify_excess_cb (void *cls)
 Function called by the bandwidth tracker if we have excess bandwidth. 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 int check_hello (void *cls, const struct GNUNET_MessageHeader *msg)
 Function we use for checking incoming HELLO messages. More...
 
static void handle_hello (void *cls, const struct GNUNET_MessageHeader *msg)
 Function we use for handling incoming HELLO messages. More...
 
static void notify_send_done_fin (void *cls)
 A message from the handler's message queue to a neighbour was transmitted. More...
 
static void notify_send_done (void *cls)
 A message from the handler's message queue to a neighbour was transmitted. 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 outbound_bw_tracker_update (void *cls)
 The outbound quota has changed in a way that may require us to reset the timeout. 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 handle_set_quota (void *cls, const struct QuotaSetMessage *qm)
 Function we use for handling incoming set quota messages. More...
 
static void reconnect (void *cls)
 Try again to connect to 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...
 
struct GNUNET_TRANSPORT_CoreHandleGNUNET_TRANSPORT_core_connect (const struct GNUNET_CONFIGURATION_Handle *cfg, const struct GNUNET_PeerIdentity *self, const struct GNUNET_MQ_MessageHandler *handlers, void *cls, GNUNET_TRANSPORT_NotifyConnect nc, GNUNET_TRANSPORT_NotifyDisconnect nd, GNUNET_TRANSPORT_NotifyExcessBandwidth neb)
 Connect to the transport service. More...
 
void GNUNET_TRANSPORT_core_disconnect (struct GNUNET_TRANSPORT_CoreHandle *handle)
 Disconnect from the transport service. More...
 

Detailed Description

library to access the transport service for message exchange

Author
Christian Grothoff

Definition in file transport_api_core.c.

Macro Definition Documentation

◆ LOG

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

◆ UNREADY_WARN_TIME

#define UNREADY_WARN_TIME   GNUNET_TIME_UNIT_MINUTES

If we could not send any payload to a peer for this amount of time, we print a warning.

Definition at line 41 of file transport_api_core.c.

◆ STARTING_NEIGHBOURS_SIZE

#define STARTING_NEIGHBOURS_SIZE   16

How large to start with for the hashmap of neighbours.

Definition at line 46 of file transport_api_core.c.

Referenced by GNUNET_TRANSPORT_core_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 805 of file transport_api_core.c.

References GNUNET_assert, GNUNET_CONTAINER_multipeermap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_MQ_destroy(), GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_STD_BACKOFF, GNUNET_YES, LOG, GNUNET_TRANSPORT_CoreHandle::mq, neighbour_delete(), GNUNET_TRANSPORT_CoreHandle::neighbours, reconnect(), GNUNET_TRANSPORT_CoreHandle::reconnect_delay, and GNUNET_TRANSPORT_CoreHandle::reconnect_task.

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

806 {
807  GNUNET_assert (NULL == h->reconnect_task);
808  /* Forget about all neighbours that we used to be connected to */
810  if (NULL != h->mq)
811  {
812  GNUNET_MQ_destroy (h->mq);
813  h->mq = NULL;
814  }
816  "Scheduling task to reconnect to transport service in %s.\n",
818  h->reconnect_task =
821 }
#define LOG(kind,...)
#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 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.
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:1246
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:727
static void reconnect(void *cls)
Try again to connect to transport service.
#define GNUNET_TIME_STD_BACKOFF(r)
Perform our standard exponential back-off calculation, starting at 1 ms and then going by a factor of...
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
struct GNUNET_SCHEDULER_Task * reconnect_task
ID of the task trying to reconnect to the service.
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:80
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 217 of file transport_api_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(), handle_send_ok(), and handle_set_quota().

219 {
221 }
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:

◆ notify_excess_cb()

static void notify_excess_cb ( void *  cls)
static

Function called by the bandwidth tracker if we have excess bandwidth.

Parameters
clsthe struct Neighbour that has excess bandwidth

Definition at line 231 of file transport_api_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), Neighbour::h, Neighbour::handlers_cls, Neighbour::id, LOG, and GNUNET_TRANSPORT_CoreHandle::neb_cb.

Referenced by handle_connect().

232 {
233  struct Neighbour *n = cls;
234  struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
235 
237  "Notifying CORE that more bandwidth is available for %s\n",
238  GNUNET_i2s (&n->id));
239 
240  if (NULL != h->neb_cb)
241  h->neb_cb (h->cls, &n->id, n->handlers_cls);
242 }
A connected controller which is not our child.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
void * handlers_cls
Closure for mq handlers.
struct GNUNET_TRANSPORT_CoreHandle * h
Overall transport handle.
GNUNET_TRANSPORT_NotifyExcessBandwidth neb_cb
function to call on excess bandwidth events
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
struct GNUNET_PeerIdentity id
Identity of this neighbour.
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:
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 256 of file transport_api_core.c.

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

Referenced by disconnect_and_schedule_reconnect(), and handle_disconnect().

257 {
259  struct Neighbour *n = value;
260 
262  "Dropping entry for neighbour `%s'.\n",
263  GNUNET_i2s (key));
265  if (NULL != handle->nd_cb)
266  handle->nd_cb (handle->cls, &n->id, n->handlers_cls);
267  if (NULL != n->timeout_task)
268  {
270  n->timeout_task = NULL;
271  }
272  if (NULL != n->env)
273  {
275  n->env = NULL;
276  }
277  GNUNET_MQ_destroy (n->mq);
278  GNUNET_assert (NULL == n->mq);
279  GNUNET_assert (
280  GNUNET_YES ==
282  GNUNET_free (n);
283  return GNUNET_YES;
284 }
A connected controller which is not our child.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
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.
struct GNUNET_SCHEDULER_Task * timeout_task
Task to trigger MQ when we have enough bandwidth for the next transmission.
static struct GNUNET_DNS_Handle * handle
Handle to transport service.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
struct GNUNET_BANDWIDTH_Tracker out_tracker
Outbound bandwidh tracker.
void GNUNET_BANDWIDTH_tracker_notification_stop(struct GNUNET_BANDWIDTH_Tracker *av)
Stop notifying about tracker updates and excess notifications.
Definition: bandwidth.c:325
void GNUNET_MQ_destroy(struct GNUNET_MQ_Handle *mq)
Destroy the message queue.
Definition: mq.c:824
#define GNUNET_YES
Definition: gnunet_common.h:80
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.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
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 297 of file transport_api_core.c.

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

Referenced by reconnect().

298 {
300 
302  "Error receiving from transport service (%d), disconnecting temporarily.\n",
303  error);
305 }
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.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
static struct GNUNET_ARM_Handle * h
Connection with ARM.
Definition: gnunet-arm.c:94
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:

◆ check_hello()

static int check_hello ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Function we use for checking incoming HELLO messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_CoreHandle *
msgmessage received
Returns
GNUNET_OK if message is well-formed

Definition at line 316 of file transport_api_core.c.

References GNUNET_break, GNUNET_HELLO_get_id(), GNUNET_OK, and GNUNET_SYSERR.

317 {
318  struct GNUNET_PeerIdentity me;
319 
320  if (GNUNET_OK !=
321  GNUNET_HELLO_get_id ((const struct GNUNET_HELLO_Message *) msg, &me))
322  {
323  GNUNET_break (0);
324  return GNUNET_SYSERR;
325  }
326  return GNUNET_OK;
327 }
int GNUNET_HELLO_get_id(const struct GNUNET_HELLO_Message *hello, struct GNUNET_PeerIdentity *peer)
Get the peer identity from a HELLO message.
Definition: hello.c:668
static GNUNET_NETWORK_STRUCT_END struct GNUNET_PeerIdentity me
Our own peer identity.
A HELLO message is used to exchange information about transports with other peers.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:79
The identity of the host (wraps the signing key of the peer).
Here is the call graph for this function:

◆ handle_hello()

static void handle_hello ( void *  cls,
const struct GNUNET_MessageHeader msg 
)
static

Function we use for handling incoming HELLO messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_CoreHandle *
msgmessage received

Definition at line 337 of file transport_api_core.c.

338 {
339  /* we do not care => FIXME: signal in options to NEVER send HELLOs! */
340 }

◆ notify_send_done_fin()

static void notify_send_done_fin ( 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.

Parameters
clsthe struct Neighbour where the message was sent

Definition at line 352 of file transport_api_core.c.

References GNUNET_MQ_impl_send_continue(), GNUNET_YES, Neighbour::is_ready, Neighbour::mq, and Neighbour::timeout_task.

Referenced by notify_send_done().

353 {
354  struct Neighbour *n = cls;
355 
356  n->timeout_task = NULL;
357  n->is_ready = GNUNET_YES;
359 }
A connected controller which is not our child.
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
struct GNUNET_SCHEDULER_Task * timeout_task
Task to trigger MQ when we have enough bandwidth for the next transmission.
int is_ready
Is this peer currently ready to receive a message?
#define GNUNET_YES
Definition: gnunet_common.h:80
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:

◆ 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.

Parameters
clsthe struct Neighbour where the message was sent

Definition at line 371 of file transport_api_core.c.

References Neighbour::env, Neighbour::env_size, GNUNET_BANDWIDTH_tracker_consume(), GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_MQ_impl_send_continue(), GNUNET_MQ_impl_send_in_flight(), GNUNET_SCHEDULER_add_delayed(), GNUNET_YES, Neighbour::is_ready, Neighbour::mq, notify_send_done_fin(), Neighbour::out_tracker, GNUNET_TIME_Relative::rel_value_us, Neighbour::timeout_task, and Neighbour::traffic_overhead.

Referenced by mq_send_impl(), and outbound_bw_tracker_update().

372 {
373  struct Neighbour *n = cls;
375 
376  n->timeout_task = NULL;
377  if (NULL != n->env)
378  {
380  n->env_size + n->traffic_overhead);
381  n->env = NULL;
382  n->traffic_overhead = 0;
383  }
385  if (0 == delay.rel_value_us)
386  {
387  n->is_ready = GNUNET_YES;
389  return;
390  }
392  /* cannot send even a small message without violating
393  quota, wait a before allowing MQ to send next message */
394  n->timeout_task =
396 }
A connected controller which is not our child.
int GNUNET_BANDWIDTH_tracker_consume(struct GNUNET_BANDWIDTH_Tracker *av, ssize_t size)
Notify the tracker that a certain number of bytes of bandwidth have been consumed.
Definition: bandwidth.c:402
uint64_t rel_value_us
The actual value.
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
static void notify_send_done_fin(void *cls)
A message from the handler's message queue to a neighbour was transmitted.
uint16_t env_size
Size of the message in env.
void GNUNET_MQ_impl_send_in_flight(struct GNUNET_MQ_Handle *mq)
Call the send notification for the current message, but do not try to send the next message until #gn...
Definition: mq.c:519
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GNUNET_SCHEDULER_Task * timeout_task
Task to trigger MQ when we have enough bandwidth for the next transmission.
struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_tracker_get_delay(struct GNUNET_BANDWIDTH_Tracker *av, size_t size)
Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the g...
Definition: bandwidth.c:458
int is_ready
Is this peer currently ready to receive a message?
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
unsigned long long traffic_overhead
Sending consumed more bytes on wire than payload was announced This overhead is added to the delay of...
struct GNUNET_BANDWIDTH_Tracker out_tracker
Outbound bandwidh tracker.
#define GNUNET_YES
Definition: gnunet_common.h:80
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
Time for relative time used by GNUnet, in microseconds.
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 410 of file transport_api_core.c.

References 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, GNUNET_MQ_notify_sent(), GNUNET_MQ_send(), GNUNET_NO, GNUNET_TIME_relative_hton(), GNUNET_TIME_UNIT_MINUTES, GNUNET_YES, Neighbour::h, Neighbour::id, Neighbour::is_ready, LOG, GNUNET_TRANSPORT_CoreHandle::mq, notify_send_done(), OutboundMessage::peer, OutboundMessage::priority, GNUNET_MessageHeader::size, OutboundMessage::timeout, Neighbour::timeout_task, and GNUNET_MessageHeader::type.

Referenced by handle_connect().

413 {
414  struct Neighbour *n = impl_state;
415  struct GNUNET_TRANSPORT_CoreHandle *h = n->h;
416  struct OutboundMessage *obm;
417  uint16_t msize;
418 
420  msize = ntohs (msg->size);
421  if (msize >= GNUNET_MAX_MESSAGE_SIZE - sizeof (*obm))
422  {
423  GNUNET_break (0);
425  return;
426  }
427  GNUNET_assert (NULL == n->env);
428  n->env =
430  {
431  struct GNUNET_MQ_Envelope *env;
432 
434  obm->priority = htonl ((uint32_t) GNUNET_MQ_env_get_options (env));
435  }
437  GNUNET_TIME_UNIT_MINUTES); /* FIXME: to be removed */
438  obm->peer = n->id;
439  GNUNET_assert (NULL == n->timeout_task);
440  n->is_ready = GNUNET_NO;
441  n->env_size = ntohs (msg->size);
443  GNUNET_MQ_send (h->mq, n->env);
445  "Queued message of type %u for neighbour `%s'.\n",
446  ntohs (msg->type),
447  GNUNET_i2s (&n->id));
448 }
A connected controller which is not our child.
#define LOG(kind,...)
uint32_t priority
An enum GNUNET_MQ_PriorityPreferences in NBO.
Definition: transport.h:307
#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_TRANSPORT_CoreHandle * h
Overall transport handle.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
struct GNUNET_PeerIdentity peer
Which peer should receive the message?
Definition: transport.h:321
#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.
#define GNUNET_NO
Definition: gnunet_common.h:81
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:94
#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.
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_SCHEDULER_Task * timeout_task
Task to trigger MQ when we have enough bandwidth for the next transmission.
struct GNUNET_TIME_RelativeNBO timeout
Allowed delay.
Definition: transport.h:315
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:296
struct GNUNET_TIME_RelativeNBO GNUNET_TIME_relative_hton(struct GNUNET_TIME_Relative a)
Convert relative time to network byte order.
Definition: time.c:622
struct GNUNET_MQ_Envelope * env
Definition: 005.c:1
int is_ready
Is this peer currently ready to receive a message?
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
static void notify_send_done(void *cls)
A message from the handler's message queue to a neighbour was transmitted.
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
#define GNUNET_YES
Definition: gnunet_common.h:80
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).
Handle for the transport service (includes all of the state for the transport service).
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).
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 459 of file transport_api_core.c.

References GNUNET_assert, and Neighbour::mq.

Referenced by handle_connect().

460 {
461  struct Neighbour *n = impl_state;
462 
463  GNUNET_assert (mq == n->mq);
464  n->mq = NULL;
465 }
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 476 of file transport_api_core.c.

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

Referenced by handle_connect().

477 {
478  struct Neighbour *n = impl_state;
479 
481  if (NULL != n->env)
482  {
484  n->env = NULL;
485  }
486 
487  n->is_ready = GNUNET_YES;
488 }
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:81
int is_ready
Is this peer currently ready to receive a message?
#define GNUNET_YES
Definition: gnunet_common.h:80
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 500 of file transport_api_core.c.

References GNUNET_break_op.

Referenced by handle_connect().

501 {
502  /* struct Neighbour *n = cls; */
503 
504  GNUNET_break_op (0);
505 }
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Here is the caller graph for this function:

◆ outbound_bw_tracker_update()

static void outbound_bw_tracker_update ( void *  cls)
static

The outbound quota has changed in a way that may require us to reset the timeout.

Update the timeout.

Parameters
clsthe struct Neighbour for which the timeout changed

Definition at line 515 of file transport_api_core.c.

References GNUNET_BANDWIDTH_tracker_get_delay(), GNUNET_SCHEDULER_add_delayed(), GNUNET_SCHEDULER_cancel(), notify_send_done(), Neighbour::out_tracker, and Neighbour::timeout_task.

Referenced by handle_connect().

516 {
517  struct Neighbour *n = cls;
519 
520  if (NULL == n->timeout_task)
521  return;
525 }
A connected controller which is not our child.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1246
struct GNUNET_SCHEDULER_Task * timeout_task
Task to trigger MQ when we have enough bandwidth for the next transmission.
struct GNUNET_TIME_Relative GNUNET_BANDWIDTH_tracker_get_delay(struct GNUNET_BANDWIDTH_Tracker *av, size_t size)
Compute how long we should wait until consuming size bytes of bandwidth in order to stay within the g...
Definition: bandwidth.c:458
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_BANDWIDTH_Tracker out_tracker
Outbound bandwidh tracker.
static void notify_send_done(void *cls)
A message from the handler's message queue to a neighbour was transmitted.
Time for relative time used by GNUnet, in microseconds.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:965
Here is the call graph for this function:
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 535 of file transport_api_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_assert, GNUNET_BANDWIDTH_tracker_init2(), GNUNET_BANDWIDTH_tracker_update_quota(), GNUNET_break, GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT, 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, GNUNET_YES, Neighbour::h, GNUNET_TRANSPORT_CoreHandle::handlers, Neighbour::handlers_cls, ConnectInfoMessage::id, Neighbour::id, Neighbour::is_ready, LOG, MAX_BANDWIDTH_CARRY_S, Neighbour::mq, mq_cancel_impl(), mq_destroy_impl(), mq_send_impl(), GNUNET_TRANSPORT_CoreHandle::nc_cb, neighbour_find(), GNUNET_TRANSPORT_CoreHandle::neighbours, notify_excess_cb(), Neighbour::out_tracker, outbound_bw_tracker_update(), peer_mq_error_handler(), ConnectInfoMessage::quota_out, Neighbour::traffic_overhead, and GNUNET_BANDWIDTH_Value32NBO::value__.

536 {
538  struct Neighbour *n;
539 
541  "Receiving CONNECT message for `%s' with quota %u\n",
542  GNUNET_i2s (&cim->id),
543  ntohl (cim->quota_out.value__));
544  n = neighbour_find (h, &cim->id);
545  if (NULL != n)
546  {
547  GNUNET_break (0); /* FIXME: this assertion seems to fail sometimes!? */
549  return;
550  }
551  n = GNUNET_new (struct Neighbour);
552  n->id = cim->id;
553  n->h = h;
554  n->is_ready = GNUNET_YES;
555  n->traffic_overhead = 0;
558  n,
562  n);
565  h->neighbours,
566  &n->id,
567  n,
569 
574  n,
575  h->handlers,
577  n);
578  if (NULL != h->nc_cb)
579  {
580  n->handlers_cls = h->nc_cb (h->cls, &n->id, n->mq);
582  }
583 }
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:145
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.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
void * handlers_cls
Closure for mq handlers.
struct GNUNET_TRANSPORT_CoreHandle * h
Overall transport handle.
void GNUNET_BANDWIDTH_tracker_update_quota(struct GNUNET_BANDWIDTH_Tracker *av, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit)
Update quota of bandwidth tracker.
Definition: bandwidth.c:526
struct GNUNET_MQ_Handle * mq
Active message queue for the peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_BANDWIDTH_Value32NBO quota_out
Current outbound quota for this peer.
Definition: transport.h:139
static void notify_excess_cb(void *cls)
Function called by the bandwidth tracker if we have excess bandwidth.
GNUNET_TRANSPORT_NotifyConnect nc_cb
function to call on connect events
#define GNUNET_CONSTANTS_DEFAULT_BW_IN_OUT
Bandwidth (in/out) to assume initially (before either peer has communicated any particular preference...
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_new(type)
Allocate a struct or union of the given type.
#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:94
uint32_t value__
The actual value (bytes per second).
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
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.
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
static void mq_cancel_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Implementation function that cancels the currently sent message.
struct GNUNET_PeerIdentity id
Identity of this neighbour.
void GNUNET_BANDWIDTH_tracker_init2(struct GNUNET_BANDWIDTH_Tracker *av, GNUNET_BANDWIDTH_TrackerUpdateCallback update_cb, void *update_cb_cls, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit, uint32_t max_carry_s, GNUNET_BANDWIDTH_ExcessNotificationCallback excess_cb, void *excess_cb_cls)
Initialize bandwidth tracker.
Definition: bandwidth.c:259
#define MAX_BANDWIDTH_CARRY_S
Number of seconds that available bandwidth carries over (can accumulate).
There must only be one value per key; storing a value should fail if a value under the same key alrea...
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
int is_ready
Is this peer currently ready to receive a message?
unsigned long long traffic_overhead
Sending consumed more bytes on wire than payload was announced This overhead is added to the delay of...
struct GNUNET_BANDWIDTH_Tracker out_tracker
Outbound bandwidh tracker.
static void mq_destroy_impl(struct GNUNET_MQ_Handle *mq, void *impl_state)
Handle destruction of a message queue.
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.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void outbound_bw_tracker_update(void *cls)
The outbound quota has changed in a way that may require us to reset the timeout. ...
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.
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_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 593 of file transport_api_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.

594 {
596  struct Neighbour *n;
597 
598  GNUNET_break (ntohl (dim->reserved) == 0);
600  "Receiving DISCONNECT message for `%s'.\n",
601  GNUNET_i2s (&dim->peer));
602  n = neighbour_find (h, &dim->peer);
603  if (NULL == n)
604  {
605  GNUNET_break (0);
607  return;
608  }
609  GNUNET_assert (GNUNET_YES == neighbour_delete (h, &dim->peer, n));
610 }
A connected controller which is not our child.
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.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
#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:94
uint32_t reserved
Reserved, always zero.
Definition: transport.h:164
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_PeerIdentity peer
Who got disconnected?
Definition: transport.h:169
#define GNUNET_YES
Definition: gnunet_common.h:80
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 620 of file transport_api_core.c.

References SendOkMessage::bytes_msg, SendOkMessage::bytes_physical, GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), GNUNET_OK, Neighbour::h, LOG, neighbour_find(), SendOkMessage::peer, SendOkMessage::success, and Neighbour::traffic_overhead.

621 {
623  struct Neighbour *n;
624  uint32_t bytes_msg;
625  uint32_t bytes_physical;
626 
627  bytes_msg = ntohl (okm->bytes_msg);
628  bytes_physical = ntohl (okm->bytes_physical);
630  "Receiving SEND_OK message, transmission to %s %s.\n",
631  GNUNET_i2s (&okm->peer),
632  ntohl (okm->success) == GNUNET_OK ? "succeeded" : "failed");
633  n = neighbour_find (h, &okm->peer);
634  if (NULL == n)
635  {
636  /* We should never get a 'SEND_OK' for a peer that we are not
637  connected to */
638  GNUNET_break (0);
640  return;
641  }
642  if (bytes_physical > bytes_msg)
643  {
645  "Overhead for %u byte message was %u\n",
646  bytes_msg,
647  bytes_physical - bytes_msg);
648  n->traffic_overhead += bytes_physical - bytes_msg;
649  }
650 }
A connected controller which is not our child.
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.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#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:94
uint16_t success
GNUNET_OK if the transmission succeeded, GNUNET_SYSERR if it failed (i.e.
Definition: transport.h:244
uint32_t bytes_physical
Size of message sent over wire.
Definition: transport.h:255
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
uint16_t bytes_msg
Size of message sent.
Definition: transport.h:249
unsigned long long traffic_overhead
Sending consumed more bytes on wire than payload was announced This overhead is added to the delay of...
struct GNUNET_PeerIdentity peer
Which peer can send more now?
Definition: transport.h:262
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:

◆ 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 660 of file transport_api_core.c.

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

661 {
662  const struct GNUNET_MessageHeader *imm;
663  uint16_t size;
664 
665  size = ntohs (im->header.size) - sizeof (*im);
666  if (size < sizeof (struct GNUNET_MessageHeader))
667  {
668  GNUNET_break (0);
669  return GNUNET_SYSERR;
670  }
671  imm = (const struct GNUNET_MessageHeader *) &im[1];
672  if (ntohs (imm->size) != size)
673  {
674  GNUNET_break (0);
675  return GNUNET_SYSERR;
676  }
677  return GNUNET_OK;
678 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
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:79
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:210

◆ 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 688 of file transport_api_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_TRANSPORT_CoreHandle::rom_pending, GNUNET_MessageHeader::size, and GNUNET_MessageHeader::type.

689 {
691  const struct GNUNET_MessageHeader *imm =
692  (const struct GNUNET_MessageHeader *) &im[1];
693  struct Neighbour *n;
694 
696  "Received message of type %u with %u bytes from `%s'.\n",
697  (unsigned int) ntohs (imm->type),
698  (unsigned int) ntohs (imm->size),
699  GNUNET_i2s (&im->peer));
700  n = neighbour_find (h, &im->peer);
701  if (NULL == n)
702  {
703  GNUNET_break (0);
705  return;
706  }
707  h->rom_pending++;
708  GNUNET_MQ_inject_message (n->mq, imm);
709 }
A connected controller which is not our child.
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.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
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:94
unsigned int rom_pending
Internal counter to check how many more receive OK messages this CORE service is allowed to send in t...
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
struct GNUNET_PeerIdentity peer
Which peer sent the message?
Definition: transport.h:215
static struct Neighbour * neighbour_find(struct GNUNET_TRANSPORT_CoreHandle *h, const struct GNUNET_PeerIdentity *peer)
Get the neighbour list entry for the given peer.
Header for all communications.
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_set_quota()

static void handle_set_quota ( void *  cls,
const struct QuotaSetMessage qm 
)
static

Function we use for handling incoming set quota messages.

Parameters
clsclosure, a struct GNUNET_TRANSPORT_CoreHandle *
msgmessage received

Definition at line 719 of file transport_api_core.c.

References GNUNET_TRANSPORT_CoreHandle::cls, disconnect_and_schedule_reconnect(), GNUNET_BANDWIDTH_tracker_update_quota(), GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), Neighbour::h, LOG, neighbour_find(), Neighbour::out_tracker, QuotaSetMessage::peer, QuotaSetMessage::quota, and GNUNET_BANDWIDTH_Value32NBO::value__.

720 {
722  struct Neighbour *n;
723 
725  "Receiving SET_QUOTA message for `%s' with quota %u\n",
726  GNUNET_i2s (&qm->peer),
727  ntohl (qm->quota.value__));
728  n = neighbour_find (h, &qm->peer);
729  if (NULL == n)
730  {
731  GNUNET_break (
732  0); /* FIXME: julius reports this assertion fails sometimes? */
734  return;
735  }
737 }
A connected controller which is not our child.
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.
void * cls
Closure for the callbacks.
#define LOG(kind,...)
void GNUNET_BANDWIDTH_tracker_update_quota(struct GNUNET_BANDWIDTH_Tracker *av, struct GNUNET_BANDWIDTH_Value32NBO bytes_per_second_limit)
Update quota of bandwidth tracker.
Definition: bandwidth.c:526
#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:94
uint32_t value__
The actual value (bytes per second).
struct GNUNET_PeerIdentity peer
About which peer are we talking here?
Definition: transport.h:196
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_BANDWIDTH_Tracker out_tracker
Outbound bandwidh tracker.
struct GNUNET_BANDWIDTH_Value32NBO quota
Quota.
Definition: transport.h:191
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 746 of file transport_api_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_HELLO, 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_SET_QUOTA, 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_connect().

747 {
750  {GNUNET_MQ_hd_var_size (hello,
752  struct GNUNET_MessageHeader,
753  h),
754  GNUNET_MQ_hd_fixed_size (connect,
756  struct ConnectInfoMessage,
757  h),
760  struct DisconnectInfoMessage,
761  h),
762  GNUNET_MQ_hd_fixed_size (send_ok,
764  struct SendOkMessage,
765  h),
766  GNUNET_MQ_hd_var_size (recv,
768  struct InboundMessage,
769  h),
770  GNUNET_MQ_hd_fixed_size (set_quota,
772  struct QuotaSetMessage,
773  h),
775  struct GNUNET_MQ_Envelope *env;
776  struct StartMessage *s;
777  uint32_t options;
778 
779  h->reconnect_task = NULL;
780  LOG (GNUNET_ERROR_TYPE_DEBUG, "Connecting to transport service.\n");
781  GNUNET_assert (NULL == h->mq);
782  h->mq =
783  GNUNET_CLIENT_connect (h->cfg, "transport", handlers, &mq_error_handler, h);
784  if (NULL == h->mq)
785  return;
787  options = 0;
788  if (h->check_self)
789  options |= 1;
790  if (NULL != h->handlers)
791  options |= 2;
792  s->options = htonl (options);
793  s->self = h->self;
794  GNUNET_MQ_send (h->mq, env);
795 }
struct GNUNET_MQ_MessageHandler * handlers
Functions to call for received data (template for new message queues).
void * cls
Closure for the callbacks.
#define LOG(kind,...)
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:901
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.
#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:110
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...
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:94
#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:104
static void disconnect(struct GNUNET_PEERSTORE_Handle *h)
Disconnect from the peerstore service.
Message from the transport service to the library informing about neighbors.
Definition: transport.h:118
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 used to set a particular bandwidth quota.
Definition: transport.h:180
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:153
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 ...
Message used to notify the transport API that it can send another message to the transport service...
Definition: transport.h:223
#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.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_SET_QUOTA
Message telling transport to limit its receive rate.
Header for all communications.
void GNUNET_MQ_send(struct GNUNET_MQ_Handle *mq, struct GNUNET_MQ_Envelope *ev)
Send a message with the given message queue.
Definition: mq.c:353
#define GNUNET_MESSAGE_TYPE_HELLO
HELLO message with friend only flag used for communicating peer addresses.
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:204
Here is the call graph for this function:
Here is the caller graph for this function: