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

Implementation of the UDP transport protocol. More...

#include "platform.h"
#include "plugin_transport_udp.h"
#include "gnunet_hello_lib.h"
#include "gnunet_util_lib.h"
#include "gnunet_fragmentation_lib.h"
#include "gnunet_nat_service.h"
#include "gnunet_protocols.h"
#include "gnunet_resolver_service.h"
#include "gnunet_signatures.h"
#include "gnunet_constants.h"
#include "gnunet_statistics_service.h"
#include "gnunet_transport_service.h"
#include "gnunet_transport_plugin.h"
#include "transport.h"
Include dependency graph for plugin_transport_udp.c:

Go to the source code of this file.

Data Structures

struct  UDPMessage
 UDP Message-Packet header (after defragmentation). More...
 
struct  PrettyPrinterContext
 Closure for append_port(). More...
 
struct  GNUNET_ATS_Session
 Information about ongoing sessions of the transport client. More...
 
struct  DefragContext
 Data structure to track defragmentation contexts based on the source of the UDP traffic. More...
 
struct  UDP_FragmentationContext
 Context to send fragmented messages. More...
 
struct  UDP_MessageWrapper
 Information we track for each message in the queue. More...
 
struct  UDP_ACK_Message
 UDP ACK Message-Packet header. More...
 
struct  GNUNET_ATS_SessionCompareContext
 Closure for session_cmp_it(). More...
 
struct  FindReceiveContext
 Closure for find_receive_context(). More...
 

Macros

#define LOG(kind, ...)   GNUNET_log_from (kind, "transport-udp", __VA_ARGS__)
 
#define UDP_SESSION_TIME_OUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)
 After how much inactivity should a UDP session time out? More...
 
#define UDP_MAX_MESSAGES_IN_DEFRAG   3
 Number of messages we can defragment in parallel. More...
 
#define UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG   128
 We keep a defragmentation queue per sender address. More...
 

Typedefs

typedef void(* QueueContinuation) (void *cls, struct UDP_MessageWrapper *udpw, int result)
 Function called when a message is removed from the transmission queue. More...
 

Functions

static GNUNET_NETWORK_STRUCT_END void notify_session_monitor (struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
 If a session monitor is attached, notify it about the new session state. More...
 
static int send_session_info_iter (void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
 Return information about the given session to the monitor callback. More...
 
static void udp_plugin_setup_monitor (void *cls, GNUNET_TRANSPORT_SessionInfoCallback sic, void *sic_cls)
 Begin monitoring sessions of a plugin. More...
 
static void free_session (struct GNUNET_ATS_Session *s)
 Function to free last resources associated with a session. More...
 
static unsigned int udp_query_keepalive_factor (void *cls)
 Function that is called to get the keepalive factor. More...
 
static enum GNUNET_NetworkType udp_plugin_get_network (void *cls, struct GNUNET_ATS_Session *session)
 Function obtain the network type for a session. More...
 
static enum GNUNET_NetworkType udp_plugin_get_network_for_address (void *cls, const struct GNUNET_HELLO_Address *address)
 Function obtain the network type for an address. More...
 
static void udp_plugin_select_v4 (void *cls)
 We have been notified that our readset has something to read. More...
 
static void udp_plugin_select_v6 (void *cls)
 We have been notified that our readset has something to read. More...
 
static void schedule_select_v4 (struct Plugin *plugin)
 (re)schedule IPv4-select tasks for this plugin. More...
 
static void schedule_select_v6 (struct Plugin *plugin)
 (re)schedule IPv6-select tasks for this plugin. More...
 
const char * udp_address_to_string (void *cls, const void *addr, size_t addrlen)
 Function called for a quick conversion of the binary address to a numeric address. More...
 
static int udp_string_to_address (void *cls, const char *addr, uint16_t addrlen, void **buf, size_t *added)
 Function called to convert a string address to a binary address. More...
 
static void append_port (void *cls, const char *hostname)
 Append our port and forward the result. More...
 
static void udp_plugin_address_pretty_printer (void *cls, const char *type, const void *addr, size_t addrlen, int numeric, struct GNUNET_TIME_Relative timeout, GNUNET_TRANSPORT_AddressStringCallback asc, void *asc_cls)
 Convert the transports address to a nice, human-readable format. More...
 
static int check_port (const struct Plugin *plugin, uint16_t in_port)
 Check if the given port is plausible (must be either our listen port or our advertised port). More...
 
static int udp_plugin_check_address (void *cls, const void *addr, size_t addrlen)
 Function that will be called to check if a binary address for this plugin is well-formed and corresponds to an address for THIS peer (as per our configuration). More...
 
static void udp_nat_port_map_callback (void *cls, void **app_ctx, int add_remove, enum GNUNET_NAT_AddressClass ac, const struct sockaddr *addr, socklen_t addrlen)
 Our external IP address/port mapping has changed. More...
 
static int session_cmp_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Find a session with a matching address. More...
 
static struct GNUNET_ATS_Sessionudp_plugin_lookup_session (void *cls, const struct GNUNET_HELLO_Address *address)
 Locate an existing session the transport service is using to send data to another peer. More...
 
static void reschedule_session_timeout (struct GNUNET_ATS_Session *s)
 Increment session timeout due to activity. More...
 
static void udp_plugin_update_session_timeout (void *cls, const struct GNUNET_PeerIdentity *peer, struct GNUNET_ATS_Session *session)
 Function that will be called whenever the transport service wants to notify the plugin that a session is still active and in use and therefore the session timeout for this session has to be updated. More...
 
static void dequeue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
 Remove the given message from the transmission queue and update all applicable statistics. More...
 
static void enqueue (struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
 Enqueue a message for transmission and update statistics. More...
 
static void fragmented_message_done (struct UDP_FragmentationContext *frag_ctx, int result)
 We have completed our (attempt) to transmit a message that had to be fragmented – either because we got an ACK saying that all fragments were received, or because of timeout / disconnect. More...
 
static void qc_fragment_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
 We are finished with a fragment in the message queue. More...
 
static void enqueue_fragment (void *cls, const struct GNUNET_MessageHeader *msg)
 Function that is called with messages created by the fragmentation module. More...
 
static void qc_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
 We are finished with a message from the message queue. More...
 
static ssize_t udp_plugin_send (void *cls, struct GNUNET_ATS_Session *s, const char *msgbuf, size_t msgbuf_size, unsigned int priority, struct GNUNET_TIME_Relative to, GNUNET_TRANSPORT_TransmitContinuation cont, void *cont_cls)
 Function that can be used by the transport service to transmit a message using the plugin. More...
 
static int find_receive_context (void *cls, struct GNUNET_CONTAINER_HeapNode *node, void *element, GNUNET_CONTAINER_HeapCostType cost)
 Scan the heap for a receive context with the given address. More...
 
static int udp_disconnect_session (void *cls, struct GNUNET_ATS_Session *s)
 Functions with this signature are called whenever we need to close a session due to a disconnect or failure to establish a connection. More...
 
static void read_process_ack (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, const union UdpAddress *udp_addr, socklen_t udp_addr_len)
 Handle a GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK message. More...
 
static int process_inbound_tokenized_messages (void *cls, const struct GNUNET_MessageHeader *hdr)
 Message tokenizer has broken up an incomming message. More...
 
static int disconnect_and_free_it (void *cls, const struct GNUNET_PeerIdentity *key, void *value)
 Destroy a session, plugin is being unloaded. More...
 
static void udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
 Disconnect from a remote node. More...
 
static void session_timeout (void *cls)
 Session was idle, so disconnect it. More...
 
static struct GNUNET_ATS_Sessionudp_plugin_create_session (void *cls, const struct GNUNET_HELLO_Address *address, enum GNUNET_NetworkType network_type)
 Allocate a new session for the given endpoint address. More...
 
static struct GNUNET_ATS_Sessionudp_plugin_get_session (void *cls, const struct GNUNET_HELLO_Address *address)
 Creates a new outbound session the transport service will use to send data to the peer. More...
 
static void process_udp_message (struct Plugin *plugin, const struct UDPMessage *msg, const union UdpAddress *udp_addr, size_t udp_addr_len, enum GNUNET_NetworkType network_type)
 We've received a UDP Message. More...
 
static void fragment_msg_proc (void *cls, const struct GNUNET_MessageHeader *msg)
 Process a defragmented message. More...
 
static void ack_message_sent (void *cls, struct UDP_MessageWrapper *udpw, int result)
 We finished sending an acknowledgement. More...
 
static void ack_proc (void *cls, uint32_t id, const struct GNUNET_MessageHeader *msg)
 Transmit an acknowledgement. More...
 
static void read_process_fragment (struct Plugin *plugin, const struct GNUNET_MessageHeader *msg, const union UdpAddress *udp_addr, size_t udp_addr_len, enum GNUNET_NetworkType network_type)
 We received a fragment, process it. More...
 
static void udp_select_read (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
 Read and process a message from the given socket. More...
 
static struct UDP_MessageWrapperremove_timeout_messages_and_select (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
 Removes messages from the transmission queue that have timed out, and then selects a message that should be transmitted next. More...
 
static void analyze_send_error (struct Plugin *plugin, const struct sockaddr *sa, socklen_t slen, int error)
 We failed to transmit a message via UDP. More...
 
static void udp_select_send (struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
 It is time to try to transmit a UDP message. More...
 
static unsigned int setup_sockets (struct Plugin *plugin, const struct sockaddr_in6 *bind_v6, const struct sockaddr_in *bind_v4)
 Setup the UDP sockets (for IPv4 and IPv6) for the plugin. More...
 
void * libgnunet_plugin_transport_udp_init (void *cls)
 The exported method. More...
 
static int heap_cleanup_iterator (void *cls, struct GNUNET_CONTAINER_HeapNode *node, void *element, GNUNET_CONTAINER_HeapCostType cost)
 Function called on each entry in the defragmentation heap to clean it up. More...
 
void * libgnunet_plugin_transport_udp_done (void *cls)
 The exported method. More...
 

Detailed Description

Implementation of the UDP transport protocol.

Author
Christian Grothoff
Nathan Evans
Matthias Wachs

Definition in file plugin_transport_udp.c.

Macro Definition Documentation

◆ LOG

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

◆ UDP_SESSION_TIME_OUT

#define UDP_SESSION_TIME_OUT   GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 60)

After how much inactivity should a UDP session time out?

Definition at line 48 of file plugin_transport_udp.c.

Referenced by reschedule_session_timeout(), session_timeout(), and udp_plugin_create_session().

◆ UDP_MAX_MESSAGES_IN_DEFRAG

#define UDP_MAX_MESSAGES_IN_DEFRAG   3

Number of messages we can defragment in parallel.

We only really defragment 1 message at a time, but if messages get re-ordered, we may want to keep knowledge about the previous message to avoid discarding the current message in favor of a single fragment of a previous message. 3 should be good since we don't expect massive message reorderings with UDP.

Definition at line 58 of file plugin_transport_udp.c.

Referenced by read_process_fragment().

◆ UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG

#define UDP_MAX_SENDER_ADDRESSES_WITH_DEFRAG   128

We keep a defragmentation queue per sender address.

How many sender addresses do we support at the same time? Memory consumption is roughly a factor of 32k * UDP_MAX_MESSAGES_IN_DEFRAG times this value. (So 128 corresponds to 12 MB and should suffice for connecting to roughly 128 peers via UDP).

Definition at line 67 of file plugin_transport_udp.c.

Referenced by read_process_fragment().

Typedef Documentation

◆ QueueContinuation

typedef void(* QueueContinuation) (void *cls, struct UDP_MessageWrapper *udpw, int result)

Function called when a message is removed from the transmission queue.

Parameters
clsclosure
udpwmessage wrapper finished
resultGNUNET_OK on success (message was sent) GNUNET_SYSERR if the target disconnected or we had a timeout or other trouble sending

Definition at line 392 of file plugin_transport_udp.c.

Function Documentation

◆ notify_session_monitor()

static GNUNET_NETWORK_STRUCT_END void notify_session_monitor ( struct Plugin plugin,
struct GNUNET_ATS_Session session,
enum GNUNET_TRANSPORT_SessionState  state 
)
static

If a session monitor is attached, notify it about the new session state.

Parameters
pluginour plugin
sessionsession that changed state
statenew state of the session

Definition at line 522 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, GNUNET_TRANSPORT_SessionInfo::address, GNUNET_ATS_Session::bytes_in_queue, GNUNET_SYSERR, GNUNET_YES, GNUNET_ATS_Session::in_destroy, GNUNET_TRANSPORT_SessionInfo::is_inbound, GNUNET_ATS_Session::msgs_in_queue, GNUNET_TRANSPORT_SessionInfo::num_bytes_pending, GNUNET_TRANSPORT_SessionInfo::num_msg_pending, GNUNET_TRANSPORT_SessionInfo::session_timeout, Plugin::sic, Plugin::sic_cls, state, GNUNET_TRANSPORT_SessionInfo::state, and GNUNET_ATS_Session::timeout.

Referenced by ack_proc(), fragmented_message_done(), process_udp_message(), remove_timeout_messages_and_select(), send_session_info_iter(), session_timeout(), udp_disconnect_session(), udp_plugin_create_session(), udp_plugin_send(), and udp_select_send().

525 {
526  struct GNUNET_TRANSPORT_SessionInfo info;
527 
528  if (NULL == plugin->sic)
529  return;
530  if (GNUNET_YES == session->in_destroy)
531  return; /* already destroyed, just RC>0 left-over actions */
532  memset (&info,
533  0,
534  sizeof (info));
535  info.state = state;
536  info.is_inbound = GNUNET_SYSERR; /* hard to say */
537  info.num_msg_pending = session->msgs_in_queue;
538  info.num_bytes_pending = session->bytes_in_queue;
539  /* info.receive_delay remains zero as this is not supported by UDP
540  (cannot selectively not receive from 'some' peer while continuing
541  to receive from others) */
542  info.session_timeout = session->timeout;
543  info.address = session->address;
544  plugin->sic (plugin->sic_cls,
545  session,
546  &info);
547 }
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
struct GNUNET_HELLO_Address * address
Address.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
Information about a plugin's session.
enum State state
current state of profiling
int in_destroy
Is this session about to be destroyed (sometimes we cannot destroy a session immediately as below us ...
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_YES
Definition: gnunet_common.h:80
void * sic_cls
Closure for sic.
Here is the caller graph for this function:

◆ send_session_info_iter()

static int send_session_info_iter ( void *  cls,
const struct GNUNET_PeerIdentity peer,
void *  value 
)
static

Return information about the given session to the monitor callback.

Parameters
clsthe struct Plugin with the monitor callback (sic)
peerpeer we send information about
valueour struct GNUNET_ATS_Session to send information about
Returns
GNUNET_OK (continue to iterate)

Definition at line 559 of file plugin_transport_udp.c.

References GNUNET_OK, GNUNET_TRANSPORT_SS_INIT, GNUNET_TRANSPORT_SS_UP, notify_session_monitor(), plugin, and value.

Referenced by udp_plugin_setup_monitor().

562 {
563  struct Plugin *plugin = cls;
564  struct GNUNET_ATS_Session *session = value;
565 
566  notify_session_monitor (plugin,
567  session,
569  notify_session_monitor (plugin,
570  session,
572  return GNUNET_OK;
573 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
static GNUNET_NETWORK_STRUCT_END void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
Handle for a plugin.
Definition: block.c:37
The session was created (first call for each session object).
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_plugin_setup_monitor()

static void udp_plugin_setup_monitor ( void *  cls,
GNUNET_TRANSPORT_SessionInfoCallback  sic,
void *  sic_cls 
)
static

Begin monitoring sessions of a plugin.

There can only be one active monitor per plugin (i.e. if there are multiple monitors, the transport service needs to multiplex the generated events over all of them).

Parameters
clsclosure of the plugin
siccallback to invoke, NULL to disable monitor; plugin will being by iterating over all active sessions immediately and then enter monitor mode
sic_clsclosure for sic

Definition at line 589 of file plugin_transport_udp.c.

References GNUNET_CONTAINER_multipeermap_iterate(), plugin, send_session_info_iter(), Plugin::sessions, Plugin::sic, and Plugin::sic_cls.

Referenced by libgnunet_plugin_transport_udp_init().

592 {
593  struct Plugin *plugin = cls;
594 
595  plugin->sic = sic;
596  plugin->sic_cls = sic_cls;
597  if (NULL != sic)
598  {
601  plugin);
602  /* signal end of first iteration */
603  sic (sic_cls,
604  NULL,
605  NULL);
606  }
607 }
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_CONTAINER_multipeermap_iterate(struct GNUNET_CONTAINER_MultiPeerMap *map, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
static int send_session_info_iter(void *cls, const struct GNUNET_PeerIdentity *peer, void *value)
Return information about the given session to the monitor callback.
void * sic_cls
Closure for sic.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ free_session()

static void free_session ( struct GNUNET_ATS_Session s)
static

Function to free last resources associated with a session.

Parameters
ssession to free

Definition at line 619 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, UDP_FragmentationContext::frag, GNUNET_ATS_Session::frag_ctx, GNUNET_FRAGMENT_context_destroy(), GNUNET_free, GNUNET_HELLO_address_free, GNUNET_MST_destroy(), and GNUNET_ATS_Session::mst.

Referenced by process_udp_message(), and udp_disconnect_session().

620 {
621  if (NULL != s->address)
622  {
624  s->address = NULL;
625  }
626  if (NULL != s->frag_ctx)
627  {
629  NULL,
630  NULL);
631  GNUNET_free (s->frag_ctx);
632  s->frag_ctx = NULL;
633  }
634  if (NULL != s->mst)
635  {
636  GNUNET_MST_destroy (s->mst);
637  s->mst = NULL;
638  }
639  GNUNET_free (s);
640 }
struct GNUNET_HELLO_Address * address
Address.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:413
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer for inbound messages.
struct UDP_FragmentationContext * frag_ctx
Context for dealing with fragments.
void GNUNET_FRAGMENT_context_destroy(struct GNUNET_FRAGMENT_Context *fc, struct GNUNET_TIME_Relative *msg_delay, struct GNUNET_TIME_Relative *ack_delay)
Destroy the given fragmentation context (stop calling 'proc', free resources).
struct GNUNET_FRAGMENT_Context * frag
Handle for fragmentation.
#define GNUNET_HELLO_address_free(addr)
Free an address.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_query_keepalive_factor()

static unsigned int udp_query_keepalive_factor ( void *  cls)
static

Function that is called to get the keepalive factor.

GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT is divided by this number to calculate the interval between keepalive packets.

Parameters
clsclosure with the struct Plugin
Returns
keepalive factor

Definition at line 652 of file plugin_transport_udp.c.

Referenced by libgnunet_plugin_transport_udp_init().

653 {
654  return 15;
655 }
Here is the caller graph for this function:

◆ udp_plugin_get_network()

static enum GNUNET_NetworkType udp_plugin_get_network ( void *  cls,
struct GNUNET_ATS_Session session 
)
static

Function obtain the network type for a session.

Parameters
clsclosure (struct Plugin *)
sessionthe session
Returns
the network type

Definition at line 666 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::scope.

Referenced by libgnunet_plugin_transport_udp_init().

668 {
669  return session->scope;
670 }
enum GNUNET_NetworkType scope
ATS network type.
Here is the caller graph for this function:

◆ udp_plugin_get_network_for_address()

static enum GNUNET_NetworkType udp_plugin_get_network_for_address ( void *  cls,
const struct GNUNET_HELLO_Address address 
)
static

Function obtain the network type for an address.

Parameters
clsclosure (struct Plugin *)
addressthe address
Returns
the network type

Definition at line 681 of file plugin_transport_udp.c.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_assert, GNUNET_break, GNUNET_memcpy, GNUNET_NT_UNSPECIFIED, IPv4UdpAddress::ipv4_addr, IPv6UdpAddress::ipv6_addr, plugin, IPv4UdpAddress::u4_port, IPv6UdpAddress::u6_port, udp_plugin_select_v4(), and udp_plugin_select_v6().

Referenced by libgnunet_plugin_transport_udp_init().

683 {
684  struct Plugin *plugin = cls;
685  size_t addrlen;
686  struct sockaddr_in a4;
687  struct sockaddr_in6 a6;
688  const struct IPv4UdpAddress *u4;
689  const struct IPv6UdpAddress *u6;
690  const void *sb;
691  size_t sbs;
692 
693  addrlen = address->address_length;
694  if (addrlen == sizeof(struct IPv6UdpAddress))
695  {
696  GNUNET_assert (NULL != address->address); /* make static analysis happy */
697  u6 = address->address;
698  memset (&a6, 0, sizeof(a6));
699 #if HAVE_SOCKADDR_IN_SIN_LEN
700  a6.sin6_len = sizeof (a6);
701 #endif
702  a6.sin6_family = AF_INET6;
703  a6.sin6_port = u6->u6_port;
704  GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
705  sb = &a6;
706  sbs = sizeof(a6);
707  }
708  else if (addrlen == sizeof(struct IPv4UdpAddress))
709  {
710  GNUNET_assert (NULL != address->address); /* make static analysis happy */
711  u4 = address->address;
712  memset (&a4, 0, sizeof(a4));
713 #if HAVE_SOCKADDR_IN_SIN_LEN
714  a4.sin_len = sizeof (a4);
715 #endif
716  a4.sin_family = AF_INET;
717  a4.sin_port = u4->u4_port;
718  a4.sin_addr.s_addr = u4->ipv4_addr;
719  sb = &a4;
720  sbs = sizeof(a4);
721  }
722  else
723  {
724  GNUNET_break (0);
725  return GNUNET_NT_UNSPECIFIED;
726  }
727  return plugin->env->get_address_type (plugin->env->cls,
728  sb,
729  sbs);
730 }
size_t address_length
Number of bytes in address.
const void * address
Binary representation of the address (plugin-specific).
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint16_t u4_port
Port number, in network byte order.
struct in6_addr ipv6_addr
IPv6 address.
uint16_t u6_port
Port number, in network byte order.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
#define GNUNET_memcpy(dst, src, n)
Network format for IPv4 addresses.
uint32_t ipv4_addr
IPv4 address, in network byte order.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
Network format for IPv6 addresses.
Handle for a plugin.
Definition: block.c:37
void * cls
Closure to use for callbacks.
Category of last resort.
Definition: gnunet_nt_lib.h:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_plugin_select_v4()

static void udp_plugin_select_v4 ( void *  cls)
static

We have been notified that our readset has something to read.

We don't know which socket needs to be read, so we have to check each one Then reschedule this function to be called again once more is available.

Parameters
clsthe plugin handle

Definition at line 3542 of file plugin_transport_udp.c.

References GNUNET_NETWORK_fdset_isset(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, plugin, GNUNET_SCHEDULER_TaskContext::read_ready, GNUNET_SCHEDULER_TaskContext::reason, schedule_select_v4(), Plugin::select_task_v4, Plugin::sockv4, tc, udp_select_read(), and udp_select_send().

Referenced by udp_plugin_get_network_for_address().

3543 {
3544  struct Plugin *plugin = cls;
3545  const struct GNUNET_SCHEDULER_TaskContext *tc;
3546 
3547  plugin->select_task_v4 = NULL;
3548  if (NULL == plugin->sockv4)
3549  return;
3551  if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3553  plugin->sockv4)))
3554  udp_select_read (plugin,
3555  plugin->sockv4);
3556  udp_select_send (plugin,
3557  plugin->sockv4);
3558  schedule_select_v4 (plugin);
3559 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:746
The reading socket is ready.
Context information passed to each scheduler task.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:417
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_SCHEDULER_Task * select_task_v4
ID of select task for IPv4.
static void schedule_select_v4(struct Plugin *plugin)
(re)schedule IPv4-select tasks for this plugin.
Handle for a plugin.
Definition: block.c:37
static void udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
It is time to try to transmit a UDP message.
static void udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
Read and process a message from the given socket.
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
Definition: network.c:1181
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_plugin_select_v6()

static void udp_plugin_select_v6 ( void *  cls)
static

We have been notified that our readset has something to read.

We don't know which socket needs to be read, so we have to check each one Then reschedule this function to be called again once more is available.

Parameters
clsthe plugin handle

Definition at line 3570 of file plugin_transport_udp.c.

References GNUNET_NETWORK_fdset_isset(), GNUNET_SCHEDULER_get_task_context(), GNUNET_SCHEDULER_REASON_READ_READY, plugin, GNUNET_SCHEDULER_TaskContext::read_ready, GNUNET_SCHEDULER_TaskContext::reason, schedule_select_v6(), Plugin::select_task_v6, Plugin::sockv6, tc, udp_select_read(), and udp_select_send().

Referenced by udp_plugin_get_network_for_address().

3571 {
3572  struct Plugin *plugin = cls;
3573  const struct GNUNET_SCHEDULER_TaskContext *tc;
3574 
3575  plugin->select_task_v6 = NULL;
3576  if (NULL == plugin->sockv6)
3577  return;
3579  if ( (0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3581  plugin->sockv6)) )
3582  udp_select_read (plugin,
3583  plugin->sockv6);
3584 
3585  udp_select_send (plugin,
3586  plugin->sockv6);
3587  schedule_select_v6 (plugin);
3588 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:746
The reading socket is ready.
Context information passed to each scheduler task.
static struct GNUNET_SCHEDULER_TaskContext tc
Task context of the current task.
Definition: scheduler.c:417
const struct GNUNET_NETWORK_FDSet * read_ready
Set of file descriptors ready for reading; note that additional bits may be set that were not in the ...
enum GNUNET_SCHEDULER_Reason reason
Reason why the task is run now.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_SCHEDULER_Task * select_task_v6
ID of select task for IPv6.
static void schedule_select_v6(struct Plugin *plugin)
(re)schedule IPv6-select tasks for this plugin.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
static void udp_select_send(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *sock)
It is time to try to transmit a UDP message.
static void udp_select_read(struct Plugin *plugin, struct GNUNET_NETWORK_Handle *rsock)
Read and process a message from the given socket.
int GNUNET_NETWORK_fdset_isset(const struct GNUNET_NETWORK_FDSet *fds, const struct GNUNET_NETWORK_Handle *desc)
Check whether a socket is part of the fd set.
Definition: network.c:1181
Here is the call graph for this function:
Here is the caller graph for this function:

◆ schedule_select_v4()

static void schedule_select_v4 ( struct Plugin plugin)
static

(re)schedule IPv4-select tasks for this plugin.

Parameters
pluginplugin to reschedule

Definition at line 763 of file plugin_transport_udp.c.

References delay, Plugin::enable_ipv4, GNUNET_CONSTANTS_LATENCY_WARN, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, Plugin::ipv4_queue_head, UDP_MessageWrapper::next, GNUNET_TIME_Relative::rel_value_us, Plugin::select_task_v4, UDP_MessageWrapper::session, Plugin::sockv4, GNUNET_ATS_Session::target, and UDP_MessageWrapper::transmission_time.

Referenced by ack_proc(), enqueue_fragment(), setup_sockets(), udp_plugin_select_v4(), and udp_plugin_send().

764 {
765  struct GNUNET_TIME_Relative min_delay;
767  struct UDP_MessageWrapper *udpw;
768  struct UDP_MessageWrapper *min_udpw;
769 
770  if ( (GNUNET_YES == plugin->enable_ipv4) &&
771  (NULL != plugin->sockv4) )
772  {
773  /* Find a message ready to send:
774  * Flow delay from other peer is expired or not set (0) */
775  min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
776  min_udpw = NULL;
777  for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next)
778  {
780  if (delay.rel_value_us < min_delay.rel_value_us)
781  {
782  min_delay = delay;
783  min_udpw = udpw;
784  }
785  }
786  if (NULL != plugin->select_task_v4)
788  if (NULL != min_udpw)
789  {
790  if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
791  {
793  "Calculated flow delay for UDPv4 at %s for %s\n",
795  GNUNET_YES),
796  GNUNET_i2s (&min_udpw->session->target));
797  }
798  else
799  {
801  "Calculated flow delay for UDPv4 at %s for %s\n",
803  GNUNET_YES),
804  GNUNET_i2s (&min_udpw->session->target));
805  }
806  }
807  plugin->select_task_v4
808  = GNUNET_SCHEDULER_add_read_net (min_delay,
809  plugin->sockv4,
811  plugin);
812  }
813 }
uint64_t rel_value_us
The actual value.
struct GNUNET_ATS_Session * session
Session this message belongs to.
int enable_ipv4
Is IPv4 enabled: GNUNET_YES or GNUNET_NO.
struct GNUNET_TIME_Absolute transmission_time
Desired transmission time for this message, based on the flow limiting information we got from the ot...
#define GNUNET_CONSTANTS_LATENCY_WARN
After what amount of latency for a message do we print a warning?
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
struct UDP_MessageWrapper * next
DLL of messages, next element.
struct GNUNET_SCHEDULER_Task * select_task_v4
ID of select task for IPv4.
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
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Information we track for each message in the queue.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static void udp_plugin_select_v4(void *cls)
We have been notified that our readset has something to read.
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1478
struct UDP_MessageWrapper * ipv4_queue_head
Head of messages in IPv4 queue.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
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:

◆ schedule_select_v6()

static void schedule_select_v6 ( struct Plugin plugin)
static

(re)schedule IPv6-select tasks for this plugin.

Parameters
pluginplugin to reschedule

Definition at line 822 of file plugin_transport_udp.c.

References delay, Plugin::enable_ipv6, GNUNET_CONSTANTS_LATENCY_WARN, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_i2s(), GNUNET_log, GNUNET_SCHEDULER_add_read_net(), GNUNET_SCHEDULER_cancel(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_YES, Plugin::ipv6_queue_head, UDP_MessageWrapper::next, GNUNET_TIME_Relative::rel_value_us, Plugin::select_task_v6, UDP_MessageWrapper::session, Plugin::sockv6, GNUNET_ATS_Session::target, and UDP_MessageWrapper::transmission_time.

Referenced by ack_proc(), enqueue_fragment(), setup_sockets(), udp_plugin_select_v6(), and udp_plugin_send().

823 {
824  struct GNUNET_TIME_Relative min_delay;
826  struct UDP_MessageWrapper *udpw;
827  struct UDP_MessageWrapper *min_udpw;
828 
829  if ( (GNUNET_YES == plugin->enable_ipv6) &&
830  (NULL != plugin->sockv6) )
831  {
832  min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
833  min_udpw = NULL;
834  for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next)
835  {
837  if (delay.rel_value_us < min_delay.rel_value_us)
838  {
839  min_delay = delay;
840  min_udpw = udpw;
841  }
842  }
843  if (NULL != plugin->select_task_v6)
845  if (NULL != min_udpw)
846  {
847  if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
848  {
850  "Calculated flow delay for UDPv6 at %s for %s\n",
852  GNUNET_YES),
853  GNUNET_i2s (&min_udpw->session->target));
854  }
855  else
856  {
858  "Calculated flow delay for UDPv6 at %s for %s\n",
860  GNUNET_YES),
861  GNUNET_i2s (&min_udpw->session->target));
862  }
863  }
864  plugin->select_task_v6
865  = GNUNET_SCHEDULER_add_read_net (min_delay,
866  plugin->sockv6,
868  plugin);
869  }
870 }
struct UDP_MessageWrapper * ipv6_queue_head
Head of messages in IPv6 queue.
uint64_t rel_value_us
The actual value.
struct GNUNET_ATS_Session * session
Session this message belongs to.
static void udp_plugin_select_v6(void *cls)
We have been notified that our readset has something to read.
struct GNUNET_TIME_Absolute transmission_time
Desired transmission time for this message, based on the flow limiting information we got from the ot...
#define GNUNET_CONSTANTS_LATENCY_WARN
After what amount of latency for a message do we print a warning?
struct UDP_MessageWrapper * next
DLL of messages, next element.
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
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Information we track for each message in the queue.
struct GNUNET_SCHEDULER_Task * select_task_v6
ID of select task for IPv6.
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_log(kind,...)
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_read_net(struct GNUNET_TIME_Relative delay, struct GNUNET_NETWORK_Handle *rfd, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when the specified file descriptor is ready f...
Definition: scheduler.c:1478
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
int enable_ipv6
Is IPv6 enabled: GNUNET_YES or GNUNET_NO.
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:

◆ udp_address_to_string()

const char* udp_address_to_string ( void *  cls,
const void *  addr,
size_t  addrlen 
)

Function called for a quick conversion of the binary address to a numeric address.

Note that the caller must not free the address and that the next call to this function is allowed to override the address again.

Parameters
clsclosure
addrbinary address (a union UdpAddress)
addrlenlength of the addr
Returns
string representing the same address

Definition at line 888 of file plugin_transport_udp.c.

References buf, GNUNET_break_op, GNUNET_snprintf(), IPv4UdpAddress::ipv4_addr, IPv6UdpAddress::ipv6_addr, options, IPv4UdpAddress::options, IPv6UdpAddress::options, PLUGIN_NAME, port, t4, t6, IPv4UdpAddress::u4_port, and IPv6UdpAddress::u6_port.

Referenced by ack_proc(), broadcast_mst_cb(), libgnunet_plugin_transport_udp_init(), read_process_ack(), read_process_fragment(), udp_disconnect_session(), udp_plugin_create_session(), udp_plugin_lookup_session(), and udp_plugin_send().

891 {
892  static char rbuf[INET6_ADDRSTRLEN + 10];
893  char buf[INET6_ADDRSTRLEN];
894  const void *sb;
895  struct in_addr a4;
896  struct in6_addr a6;
897  const struct IPv4UdpAddress *t4;
898  const struct IPv6UdpAddress *t6;
899  int af;
900  uint16_t port;
901  uint32_t options;
902 
903  if (NULL == addr)
904  {
905  GNUNET_break_op (0);
906  return NULL;
907  }
908 
909  if (addrlen == sizeof(struct IPv6UdpAddress))
910  {
911  t6 = addr;
912  af = AF_INET6;
913  options = ntohl (t6->options);
914  port = ntohs (t6->u6_port);
915  a6 = t6->ipv6_addr;
916  sb = &a6;
917  }
918  else if (addrlen == sizeof(struct IPv4UdpAddress))
919  {
920  t4 = addr;
921  af = AF_INET;
922  options = ntohl (t4->options);
923  port = ntohs (t4->u4_port);
924  a4.s_addr = t4->ipv4_addr;
925  sb = &a4;
926  }
927  else
928  {
929  GNUNET_break_op (0);
930  return NULL;
931  }
932  inet_ntop (af,
933  sb,
934  buf,
935  INET6_ADDRSTRLEN);
936  GNUNET_snprintf (rbuf,
937  sizeof(rbuf),
938  (af == AF_INET6)
939  ? "%s.%u.[%s]:%u"
940  : "%s.%u.%s:%u",
941  PLUGIN_NAME,
942  options,
943  buf,
944  port);
945  return rbuf;
946 }
uint32_t options
Optional options and flags for this address.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
int GNUNET_snprintf(char *buf, size_t size, const char *format,...)
Like snprintf, just aborts if the buffer is of insufficient size.
uint16_t u4_port
Port number, in network byte order.
struct in6_addr ipv6_addr
IPv6 address.
uint16_t u6_port
Port number, in network byte order.
Network format for IPv4 addresses.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint32_t ipv4_addr
IPv4 address, in network byte order.
static struct GNUNET_SCHEDULER_Task * t4
Task for IPv4 socket.
static char buf[2048]
uint32_t options
Optional options and flags for this address.
Network format for IPv6 addresses.
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
#define PLUGIN_NAME
static struct GNUNET_SCHEDULER_Task * t6
Task for IPv6 socket.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_string_to_address()

static int udp_string_to_address ( void *  cls,
const char *  addr,
uint16_t  addrlen,
void **  buf,
size_t *  added 
)
static

Function called to convert a string address to a binary address.

Parameters
clsclosure (struct Plugin *)
addrstring address
addrlenlength of the address
buflocation to store the buffer
addedlocation to store the number of bytes in the buffer. If the function returns GNUNET_SYSERR, its contents are undefined.
Returns
GNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 961 of file plugin_transport_udp.c.

References address, GNUNET_break, GNUNET_free, GNUNET_new, GNUNET_OK, GNUNET_strdup, GNUNET_STRINGS_to_address_ip(), GNUNET_SYSERR, IPv4UdpAddress::ipv4_addr, IPv6UdpAddress::ipv6_addr, options, IPv4UdpAddress::options, IPv6UdpAddress::options, plugin, IPv4UdpAddress::u4_port, and IPv6UdpAddress::u6_port.

Referenced by libgnunet_plugin_transport_udp_init().

966 {
967  struct sockaddr_storage socket_address;
968  char *address;
969  char *plugin;
970  char *optionstr;
971  uint32_t options;
972 
973  /* Format tcp.options.address:port */
974  address = NULL;
975  plugin = NULL;
976  optionstr = NULL;
977 
978  if ((NULL == addr) || (0 == addrlen))
979  {
980  GNUNET_break (0);
981  return GNUNET_SYSERR;
982  }
983  if ('\0' != addr[addrlen - 1])
984  {
985  GNUNET_break (0);
986  return GNUNET_SYSERR;
987  }
988  if (strlen (addr) != addrlen - 1)
989  {
990  GNUNET_break (0);
991  return GNUNET_SYSERR;
992  }
993  plugin = GNUNET_strdup (addr);
994  optionstr = strchr (plugin, '.');
995  if (NULL == optionstr)
996  {
997  GNUNET_break (0);
998  GNUNET_free (plugin);
999  return GNUNET_SYSERR;
1000  }
1001  optionstr[0] = '\0';
1002  optionstr++;
1003  options = atol (optionstr);
1004  address = strchr (optionstr, '.');
1005  if (NULL == address)
1006  {
1007  GNUNET_break (0);
1008  GNUNET_free (plugin);
1009  return GNUNET_SYSERR;
1010  }
1011  address[0] = '\0';
1012  address++;
1013 
1014  if (GNUNET_OK !=
1016  strlen (address),
1017  &socket_address))
1018  {
1019  GNUNET_break (0);
1020  GNUNET_free (plugin);
1021  return GNUNET_SYSERR;
1022  }
1023  GNUNET_free(plugin);
1024 
1025  switch (socket_address.ss_family)
1026  {
1027  case AF_INET:
1028  {
1029  struct IPv4UdpAddress *u4;
1030  const struct sockaddr_in *in4 = (const struct sockaddr_in *) &socket_address;
1031 
1032  u4 = GNUNET_new (struct IPv4UdpAddress);
1033  u4->options = htonl (options);
1034  u4->ipv4_addr = in4->sin_addr.s_addr;
1035  u4->u4_port = in4->sin_port;
1036  *buf = u4;
1037  *added = sizeof (struct IPv4UdpAddress);
1038  return GNUNET_OK;
1039  }
1040  case AF_INET6:
1041  {
1042  struct IPv6UdpAddress *u6;
1043  const struct sockaddr_in6 *in6 = (const struct sockaddr_in6 *) &socket_address;
1044 
1045  u6 = GNUNET_new (struct IPv6UdpAddress);
1046  u6->options = htonl (options);
1047  u6->ipv6_addr = in6->sin6_addr;
1048  u6->u6_port = in6->sin6_port;
1049  *buf = u6;
1050  *added = sizeof (struct IPv6UdpAddress);
1051  return GNUNET_OK;
1052  }
1053  default:
1054  GNUNET_break (0);
1055  return GNUNET_SYSERR;
1056  }
1057 }
uint32_t options
Optional options and flags for this address.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
uint16_t u4_port
Port number, in network byte order.
struct in6_addr ipv6_addr
IPv6 address.
#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.
uint16_t u6_port
Port number, in network byte order.
#define GNUNET_strdup(a)
Wrapper around GNUNET_xstrdup_.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Network format for IPv4 addresses.
uint32_t ipv4_addr
IPv4 address, in network byte order.
static char buf[2048]
uint32_t options
Optional options and flags for this address.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static char * address
GNS address for this phone.
int GNUNET_STRINGS_to_address_ip(const char *addr, uint16_t addrlen, struct sockaddr_storage *r_buf)
Tries to convert addr string to an IP (v4 or v6) address.
Definition: strings.c:1409
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ append_port()

static void append_port ( void *  cls,
const char *  hostname 
)
static

Append our port and forward the result.

Parameters
clsa struct PrettyPrinterContext *
hostnameresult from DNS resolver

Definition at line 1067 of file plugin_transport_udp.c.

References PrettyPrinterContext::asc, PrettyPrinterContext::asc_cls, GNUNET_asprintf(), GNUNET_CONTAINER_DLL_remove, GNUNET_free, GNUNET_OK, GNUNET_YES, PrettyPrinterContext::ipv6, PrettyPrinterContext::options, plugin, PrettyPrinterContext::plugin, PLUGIN_NAME, PrettyPrinterContext::port, Plugin::ppc_dll_head, Plugin::ppc_dll_tail, PrettyPrinterContext::resolver_handle, and ret.

Referenced by udp_plugin_address_pretty_printer().

1069 {
1070  struct PrettyPrinterContext *ppc = cls;
1071  struct Plugin *plugin = ppc->plugin;
1072  char *ret;
1073 
1074  if (NULL == hostname)
1075  {
1076  /* Final call, done */
1078  plugin->ppc_dll_tail,
1079  ppc);
1080  ppc->resolver_handle = NULL;
1081  ppc->asc (ppc->asc_cls,
1082  NULL,
1083  GNUNET_OK);
1084  GNUNET_free (ppc);
1085  return;
1086  }
1087  if (GNUNET_YES == ppc->ipv6)
1088  GNUNET_asprintf (&ret,
1089  "%s.%u.[%s]:%d",
1090  PLUGIN_NAME,
1091  ppc->options,
1092  hostname,
1093  ppc->port);
1094  else
1095  GNUNET_asprintf (&ret,
1096  "%s.%u.%s:%d",
1097  PLUGIN_NAME,
1098  ppc->options,
1099  hostname,
1100  ppc->port);
1101  ppc->asc (ppc->asc_cls,
1102  ret,
1103  GNUNET_OK);
1104  GNUNET_free (ret);
1105 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
GNUNET_TRANSPORT_AddressStringCallback asc
Function to call with the result.
struct PrettyPrinterContext * ppc_dll_tail
Running pretty printers: tail.
struct GNUNET_RESOLVER_RequestHandle * resolver_handle
Resolver handle.
Closure for append_port().
uint16_t port
Port to add after the IP address.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void * asc_cls
Clsoure for asc.
static int ret
Final status code.
Definition: gnunet-arm.c:89
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * hostname
Our hostname; we give this to all the peers we start.
Handle for a plugin.
Definition: block.c:37
uint32_t options
Address options.
#define PLUGIN_NAME
#define GNUNET_YES
Definition: gnunet_common.h:80
struct PrettyPrinterContext * ppc_dll_head
Running pretty printers: head.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_plugin_address_pretty_printer()

static void udp_plugin_address_pretty_printer ( void *  cls,
const char *  type,
const void *  addr,
size_t  addrlen,
int  numeric,
struct GNUNET_TIME_Relative  timeout,
GNUNET_TRANSPORT_AddressStringCallback  asc,
void *  asc_cls 
)
static

Convert the transports address to a nice, human-readable format.

Parameters
clsclosure with the struct Plugin *
typename of the transport that generated the address
addrone of the addresses of the host, NULL for the last address the specific address format depends on the transport; a union UdpAddress
addrlenlength of the address
numericshould (IP) addresses be displayed in numeric form?
timeoutafter how long should we give up?
ascfunction to call on each string
asc_clsclosure for asc

Definition at line 1123 of file plugin_transport_udp.c.

References append_port(), PrettyPrinterContext::asc, PrettyPrinterContext::asc_cls, GNUNET_break_op, GNUNET_CONTAINER_DLL_insert, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_RESOLVER_hostname_get(), GNUNET_SYSERR, GNUNET_YES, IPv4UdpAddress::ipv4_addr, PrettyPrinterContext::ipv6, IPv6UdpAddress::ipv6_addr, options, IPv4UdpAddress::options, IPv6UdpAddress::options, PrettyPrinterContext::options, plugin, PrettyPrinterContext::plugin, port, PrettyPrinterContext::port, Plugin::ppc_dll_head, Plugin::ppc_dll_tail, PrettyPrinterContext::resolver_handle, IPv4UdpAddress::u4_port, and IPv6UdpAddress::u6_port.

Referenced by libgnunet_plugin_transport_udp_init().

1131 {
1132  struct Plugin *plugin = cls;
1133  struct PrettyPrinterContext *ppc;
1134  const struct sockaddr *sb;
1135  size_t sbs;
1136  struct sockaddr_in a4;
1137  struct sockaddr_in6 a6;
1138  const struct IPv4UdpAddress *u4;
1139  const struct IPv6UdpAddress *u6;
1140  uint16_t port;
1141  uint32_t options;
1142 
1143  if (addrlen == sizeof(struct IPv6UdpAddress))
1144  {
1145  u6 = addr;
1146  memset (&a6,
1147  0,
1148  sizeof (a6));
1149  a6.sin6_family = AF_INET6;
1150 #if HAVE_SOCKADDR_IN_SIN_LEN
1151  a6.sin6_len = sizeof (a6);
1152 #endif
1153  a6.sin6_port = u6->u6_port;
1154  a6.sin6_addr = u6->ipv6_addr;
1155  port = ntohs (u6->u6_port);
1156  options = ntohl (u6->options);
1157  sb = (const struct sockaddr *) &a6;
1158  sbs = sizeof (a6);
1159  }
1160  else if (addrlen == sizeof (struct IPv4UdpAddress))
1161  {
1162  u4 = addr;
1163  memset (&a4,
1164  0,
1165  sizeof(a4));
1166  a4.sin_family = AF_INET;
1167 #if HAVE_SOCKADDR_IN_SIN_LEN
1168  a4.sin_len = sizeof (a4);
1169 #endif
1170  a4.sin_port = u4->u4_port;
1171  a4.sin_addr.s_addr = u4->ipv4_addr;
1172  port = ntohs (u4->u4_port);
1173  options = ntohl (u4->options);
1174  sb = (const struct sockaddr *) &a4;
1175  sbs = sizeof(a4);
1176  }
1177  else
1178  {
1179  /* invalid address */
1180  GNUNET_break_op (0);
1181  asc (asc_cls,
1182  NULL,
1183  GNUNET_SYSERR);
1184  asc (asc_cls,
1185  NULL,
1186  GNUNET_OK);
1187  return;
1188  }
1189  ppc = GNUNET_new (struct PrettyPrinterContext);
1190  ppc->plugin = plugin;
1191  ppc->asc = asc;
1192  ppc->asc_cls = asc_cls;
1193  ppc->port = port;
1194  ppc->options = options;
1195  if (addrlen == sizeof (struct IPv6UdpAddress))
1196  ppc->ipv6 = GNUNET_YES;
1197  else
1198  ppc->ipv6 = GNUNET_NO;
1200  plugin->ppc_dll_tail,
1201  ppc);
1202  ppc->resolver_handle
1204  sbs,
1205  ! numeric,
1206  timeout,
1207  &append_port,
1208  ppc);
1209 }
uint32_t options
Optional options and flags for this address.
GNUNET_TRANSPORT_AddressStringCallback asc
Function to call with the result.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
struct PrettyPrinterContext * ppc_dll_tail
Running pretty printers: tail.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
struct GNUNET_RESOLVER_RequestHandle * resolver_handle
Resolver handle.
uint16_t u4_port
Port number, in network byte order.
Closure for append_port().
uint16_t port
Port to add after the IP address.
struct in6_addr ipv6_addr
IPv6 address.
#define GNUNET_NO
Definition: gnunet_common.h:81
static int numeric
Option -n.
#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.
struct GNUNET_RESOLVER_RequestHandle * GNUNET_RESOLVER_hostname_get(const struct sockaddr *sa, socklen_t salen, int do_resolve, struct GNUNET_TIME_Relative timeout, GNUNET_RESOLVER_HostnameCallback callback, void *cls)
Perform a reverse DNS lookup.
void * asc_cls
Clsoure for asc.
uint16_t u6_port
Port number, in network byte order.
static void append_port(void *cls, const char *hostname)
Append our port and forward the result.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Network format for IPv4 addresses.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
uint32_t ipv4_addr
IPv4 address, in network byte order.
uint32_t options
Optional options and flags for this address.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static uint16_t port
Port number.
Definition: gnunet-bcd.c:79
Handle for a plugin.
Definition: block.c:37
uint32_t options
Address options.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct PrettyPrinterContext * ppc_dll_head
Running pretty printers: head.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ check_port()

static int check_port ( const struct Plugin plugin,
uint16_t  in_port 
)
static

Check if the given port is plausible (must be either our listen port or our advertised port).

If it is neither, we return GNUNET_SYSERR.

Parameters
pluginglobal variables
in_portport number to check
Returns
GNUNET_OK if port is either our open or advertised port

Definition at line 1222 of file plugin_transport_udp.c.

References Plugin::aport, GNUNET_OK, GNUNET_SYSERR, and Plugin::port.

Referenced by udp_plugin_check_address().

1224 {
1225  if ( (plugin->port == in_port) ||
1226  (plugin->aport == in_port) )
1227  return GNUNET_OK;
1228  return GNUNET_SYSERR;
1229 }
uint16_t aport
Port we advertise on.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
uint16_t port
Port used.
Here is the caller graph for this function:

◆ udp_plugin_check_address()

static int udp_plugin_check_address ( void *  cls,
const void *  addr,
size_t  addrlen 
)
static

Function that will be called to check if a binary address for this plugin is well-formed and corresponds to an address for THIS peer (as per our configuration).

Naturally, if absolutely necessary, plugins can be a bit conservative in their answer, but in general plugins should make sure that the address does not redirect traffic to a 3rd party that might try to man-in-the-middle our traffic.

Parameters
clsclosure, should be our handle to the Plugin
addrpointer to a union UdpAddress
addrlenlength of addr
Returns
GNUNET_OK if this is a plausible address for this peer and transport, GNUNET_SYSERR if not

Definition at line 1248 of file plugin_transport_udp.c.

References check_port(), GNUNET_break_op, GNUNET_NAT_test_address(), GNUNET_OK, GNUNET_SYSERR, Plugin::nat, and plugin.

Referenced by libgnunet_plugin_transport_udp_init().

1251 {
1252  struct Plugin *plugin = cls;
1253  const struct IPv4UdpAddress *v4;
1254  const struct IPv6UdpAddress *v6;
1255 
1256  if (sizeof(struct IPv4UdpAddress) == addrlen)
1257  {
1258  struct sockaddr_in s4;
1259 
1260  v4 = (const struct IPv4UdpAddress *) addr;
1261  if (GNUNET_OK != check_port (plugin,
1262  ntohs (v4->u4_port)))
1263  return GNUNET_SYSERR;
1264  memset (&s4, 0, sizeof (s4));
1265  s4.sin_family = AF_INET;
1266 #if HAVE_SOCKADDR_IN_SIN_LEN
1267  s4.sin_len = sizeof (s4);
1268 #endif
1269  s4.sin_port = v4->u4_port;
1270  s4.sin_addr.s_addr = v4->ipv4_addr;
1271 
1272  if (GNUNET_OK !=
1273  GNUNET_NAT_test_address (plugin->nat,
1274  &s4,
1275  sizeof (struct sockaddr_in)))
1276  return GNUNET_SYSERR;
1277  }
1278  else if (sizeof(struct IPv6UdpAddress) == addrlen)
1279  {
1280  struct sockaddr_in6 s6;
1281 
1282  v6 = (const struct IPv6UdpAddress *) addr;
1283  if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1284  return GNUNET_OK; /* plausible, if unlikely... */
1285  memset (&s6, 0, sizeof (s6));
1286  s6.sin6_family = AF_INET6;
1287 #if HAVE_SOCKADDR_IN_SIN_LEN
1288  s6.sin6_len = sizeof (s6);
1289 #endif
1290  s6.sin6_port = v6->u6_port;
1291  s6.sin6_addr = v6->ipv6_addr;
1292 
1293  if (GNUNET_OK !=
1294  GNUNET_NAT_test_address (plugin->nat,
1295  &s6,
1296  sizeof(struct sockaddr_in6)))
1297  return GNUNET_SYSERR;
1298  }
1299  else
1300  {
1301  GNUNET_break_op (0);
1302  return GNUNET_SYSERR;
1303  }
1304  return GNUNET_OK;
1305 }
struct GNUNET_NAT_Handle * nat
NAT handle & address management.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
int GNUNET_NAT_test_address(struct GNUNET_NAT_Handle *nh, const void *addr, socklen_t addrlen)
Test if the given address is (currently) a plausible IP address for this peer.
Definition: nat_api.c:623
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Network format for IPv4 addresses.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Handle for a plugin.
Definition: block.c:37
static int check_port(const struct Plugin *plugin, uint16_t in_port)
Check if the given port is plausible (must be either our listen port or our advertised port)...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_nat_port_map_callback()

static void udp_nat_port_map_callback ( void *  cls,
void **  app_ctx,
int  add_remove,
enum GNUNET_NAT_AddressClass  ac,
const struct sockaddr *  addr,
socklen_t  addrlen 
)
static

Our external IP address/port mapping has changed.

Parameters
clsclosure, the struct Plugin
app_ctx[in,out]location where the app can store stuff on add and retrieve it on remove
add_removeGNUNET_YES to mean the new public IP address, GNUNET_NO to mean the previous (now invalid) one
acaddress class the address belongs to
addreither the previous or the new public IP address
addrlenactual length of the addr

Definition at line 1321 of file plugin_transport_udp.c.

References address, find_typedefs::arg, gnunet-chk::args, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_a2s(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_YES, IPv4UdpAddress::ipv4_addr, IPv6UdpAddress::ipv6_addr, LOG, Plugin::myoptions, IPv4UdpAddress::options, IPv6UdpAddress::options, plugin, PLUGIN_NAME, IPv4UdpAddress::u4_port, and IPv6UdpAddress::u6_port.

Referenced by setup_sockets().

1327 {
1328  struct Plugin *plugin = cls;
1329  struct GNUNET_HELLO_Address *address;
1330  struct IPv4UdpAddress u4;
1331  struct IPv6UdpAddress u6;
1332  void *arg;
1333  size_t args;
1334 
1335  (void) app_ctx;
1337  (GNUNET_YES == add_remove)
1338  ? "NAT notification to add address `%s'\n"
1339  : "NAT notification to remove address `%s'\n",
1340  GNUNET_a2s (addr,
1341  addrlen));
1342  /* convert 'address' to our internal format */
1343  switch (addr->sa_family)
1344  {
1345  case AF_INET:
1346  {
1347  const struct sockaddr_in *i4;
1348 
1349  GNUNET_assert (sizeof(struct sockaddr_in) == addrlen);
1350  i4 = (const struct sockaddr_in *) addr;
1351  if (0 == ntohs (i4->sin_port))
1352  return; /* Port = 0 means unmapped, ignore these for UDP. */
1353  memset (&u4,
1354  0,
1355  sizeof(u4));
1356  u4.options = htonl (plugin->myoptions);
1357  u4.ipv4_addr = i4->sin_addr.s_addr;
1358  u4.u4_port = i4->sin_port;
1359  arg = &u4;
1360  args = sizeof (struct IPv4UdpAddress);
1361  break;
1362  }
1363  case AF_INET6:
1364  {
1365  const struct sockaddr_in6 *i6;
1366 
1367  GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen);
1368  i6 = (const struct sockaddr_in6 *) addr;
1369  if (0 == ntohs (i6->sin6_port))
1370  return; /* Port = 0 means unmapped, ignore these for UDP. */
1371  memset (&u6,
1372  0,
1373  sizeof(u6));
1374  u6.options = htonl (plugin->myoptions);
1375  u6.ipv6_addr = i6->sin6_addr;
1376  u6.u6_port = i6->sin6_port;
1377  arg = &u6;
1378  args = sizeof (struct IPv6UdpAddress);
1379  break;
1380  }
1381  default:
1382  GNUNET_break (0);
1383  return;
1384  }
1385  /* modify our published address list */
1386  /* TODO: use 'ac' here in the future... */
1387  address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1388  PLUGIN_NAME,
1389  arg,
1390  args,
1392  plugin->env->notify_address (plugin->env->cls,
1393  add_remove,
1394  address);
1395  GNUNET_HELLO_address_free (address);
1396 }
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Network format for IPv4 addresses.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
const char * GNUNET_a2s(const struct sockaddr *addr, socklen_t addrlen)
Convert a "struct sockaddr*" (IPv4 or IPv6 address) to a string (for printing debug messages)...
Network format for IPv6 addresses.
No additional information.
Handle for a plugin.
Definition: block.c:37
#define PLUGIN_NAME
An address for communicating with a peer.
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:80
uint32_t myoptions
Address options.
static char * address
GNS address for this phone.
#define LOG(kind,...)
#define GNUNET_HELLO_address_free(addr)
Free an address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_cmp_it()

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

Find a session with a matching address.

Parameters
clsthe struct GNUNET_ATS_SessionCompareContext *
keypeer identity (unused)
valuethe struct GNUNET_ATS_Session *
Returns
GNUNET_NO if we found the session, GNUNET_OK if not

Definition at line 1428 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, GNUNET_ATS_SessionCompareContext::address, GNUNET_assert, GNUNET_HELLO_address_cmp(), GNUNET_NO, GNUNET_OK, GNUNET_ATS_Session::in_destroy, GNUNET_ATS_SessionCompareContext::res, and value.

Referenced by udp_plugin_lookup_session().

1431 {
1432  struct GNUNET_ATS_SessionCompareContext *cctx = cls;
1433  struct GNUNET_ATS_Session *s = value;
1434 
1435  if (0 == GNUNET_HELLO_address_cmp (s->address,
1436  cctx->address))
1437  {
1439  cctx->res = s;
1440  return GNUNET_NO;
1441  }
1442  return GNUNET_OK;
1443 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
int GNUNET_HELLO_address_cmp(const struct GNUNET_HELLO_Address *a1, const struct GNUNET_HELLO_Address *a2)
Compare two addresses.
Definition: address.c:130
static char * value
Value of the record to add/remove.
Information about ongoing sessions of the transport client.
Closure for session_cmp_it().
int in_destroy
Is this session about to be destroyed (sometimes we cannot destroy a session immediately as below us ...
const struct GNUNET_HELLO_Address * address
Address we are looking for.
struct GNUNET_ATS_Session * res
Set to session matching the address.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_plugin_lookup_session()

static struct GNUNET_ATS_Session* udp_plugin_lookup_session ( void *  cls,
const struct GNUNET_HELLO_Address address 
)
static

Locate an existing session the transport service is using to send data to another peer.

Performs some basic sanity checks on the address and then tries to locate a matching session.

Parameters
clsthe plugin
addressthe address we should locate the session by
Returns
the session if it exists, or NULL if it is not found

Definition at line 1456 of file plugin_transport_udp.c.

References GNUNET_HELLO_Address::address, address, GNUNET_ATS_SessionCompareContext::address, GNUNET_HELLO_Address::address_length, GNUNET_break, GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_SessionCompareContext::res, session_cmp_it(), Plugin::sessions, Plugin::sockv4, Plugin::sockv6, IPv4UdpAddress::u4_port, IPv6UdpAddress::u6_port, and udp_address_to_string().

Referenced by ack_proc(), process_udp_message(), read_process_ack(), and udp_plugin_get_session().

1458 {
1459  struct Plugin *plugin = cls;
1460  const struct IPv6UdpAddress *udp_a6;
1461  const struct IPv4UdpAddress *udp_a4;
1463 
1464  if (NULL == address->address)
1465  {
1466  GNUNET_break (0);
1467  return NULL;
1468  }
1469  if (sizeof(struct IPv4UdpAddress) == address->address_length)
1470  {
1471  if (NULL == plugin->sockv4)
1472  return NULL;
1473  udp_a4 = (const struct IPv4UdpAddress *) address->address;
1474  if (0 == udp_a4->u4_port)
1475  {
1476  GNUNET_break (0);
1477  return NULL;
1478  }
1479  }
1480  else if (sizeof(struct IPv6UdpAddress) == address->address_length)
1481  {
1482  if (NULL == plugin->sockv6)
1483  return NULL;
1484  udp_a6 = (const struct IPv6UdpAddress *) address->address;
1485  if (0 == udp_a6->u6_port)
1486  {
1487  GNUNET_break (0);
1488  return NULL;
1489  }
1490  }
1491  else
1492  {
1493  GNUNET_break (0);
1494  return NULL;
1495  }
1496 
1497  /* check if session already exists */
1498  cctx.address = address;
1499  cctx.res = NULL;
1501  "Looking for existing session for peer `%s' with address `%s'\n",
1502  GNUNET_i2s (&address->peer),
1503  udp_address_to_string (plugin,
1504  address->address,
1505  address->address_length));
1507  &address->peer,
1508  &session_cmp_it,
1509  &cctx);
1510  if (NULL == cctx.res)
1511  return NULL;
1513  "Found existing session %p\n",
1514  cctx.res);
1515  return cctx.res;
1516 }
size_t address_length
Number of bytes in address.
const void * address
Binary representation of the address (plugin-specific).
uint16_t u4_port
Port number, in network byte order.
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
uint16_t u6_port
Port number, in network byte order.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Network format for IPv4 addresses.
Closure for session_cmp_it().
static int session_cmp_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Find a session with a matching address.
Network format for IPv6 addresses.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
Handle for a plugin.
Definition: block.c:37
const char * udp_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define LOG(kind,...)
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ reschedule_session_timeout()

static void reschedule_session_timeout ( struct GNUNET_ATS_Session s)
static

Increment session timeout due to activity.

Parameters
ssession to reschedule timeout activity for

Definition at line 1528 of file plugin_transport_udp.c.

References GNUNET_assert, GNUNET_TIME_relative_to_absolute(), GNUNET_YES, GNUNET_ATS_Session::in_destroy, GNUNET_ATS_Session::timeout, GNUNET_ATS_Session::timeout_task, and UDP_SESSION_TIME_OUT.

Referenced by process_inbound_tokenized_messages(), and udp_plugin_update_session_timeout().

1529 {
1530  if (GNUNET_YES == s->in_destroy)
1531  return;
1532  GNUNET_assert (NULL != s->timeout_task);
1534 }
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define UDP_SESSION_TIME_OUT
After how much inactivity should a UDP session time out?
int in_destroy
Is this session about to be destroyed (sometimes we cannot destroy a session immediately as below us ...
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_plugin_update_session_timeout()

static void udp_plugin_update_session_timeout ( void *  cls,
const struct GNUNET_PeerIdentity peer,
struct GNUNET_ATS_Session session 
)
static

Function that will be called whenever the transport service wants to notify the plugin that a session is still active and in use and therefore the session timeout for this session has to be updated.

Parameters
clsclosure with the struct Plugin
peerwhich peer was the session for
sessionwhich session is being updated

Definition at line 1548 of file plugin_transport_udp.c.

References GNUNET_break, GNUNET_CONTAINER_multipeermap_contains_value(), GNUNET_YES, plugin, reschedule_session_timeout(), and Plugin::sessions.

Referenced by libgnunet_plugin_transport_udp_init().

1551 {
1552  struct Plugin *plugin = cls;
1553 
1554  if (GNUNET_YES !=
1556  peer,
1557  session))
1558  {
1559  GNUNET_break (0);
1560  return;
1561  }
1562  /* Reschedule session timeout */
1563  reschedule_session_timeout (session);
1564 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
int GNUNET_CONTAINER_multipeermap_contains_value(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Check if the map contains the given value under the given key.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
#define GNUNET_YES
Definition: gnunet_common.h:80
static void reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ dequeue()

static void dequeue ( struct Plugin plugin,
struct UDP_MessageWrapper udpw 
)
static

Remove the given message from the transmission queue and update all applicable statistics.

Parameters
pluginthe UDP plugin
udpwmessage wrapper to dequeue

Definition at line 1578 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, Plugin::bytes_in_buffer, GNUNET_ATS_Session::bytes_in_queue, Plugin::env, GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_remove, GNUNET_NO, GNUNET_STATISTICS_update(), Plugin::ipv4_queue_head, Plugin::ipv4_queue_tail, Plugin::ipv6_queue_head, Plugin::ipv6_queue_tail, UDP_MessageWrapper::msg_size, GNUNET_ATS_Session::msgs_in_queue, and UDP_MessageWrapper::session.

Referenced by fragmented_message_done(), libgnunet_plugin_transport_udp_done(), remove_timeout_messages_and_select(), udp_disconnect_session(), and udp_select_send().

1580 {
1581  struct GNUNET_ATS_Session *session = udpw->session;
1582 
1583  if (plugin->bytes_in_buffer < udpw->msg_size)
1584  {
1585  GNUNET_break (0);
1586  }
1587  else
1588  {
1589  GNUNET_STATISTICS_update (plugin->env->stats,
1590  "# UDP, total bytes in send buffers",
1591  - (long long) udpw->msg_size,
1592  GNUNET_NO);
1593  plugin->bytes_in_buffer -= udpw->msg_size;
1594  }
1595  GNUNET_STATISTICS_update (plugin->env->stats,
1596  "# UDP, total messages in send buffers",
1597  -1,
1598  GNUNET_NO);
1599  if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1600  {
1602  plugin->ipv4_queue_tail,
1603  udpw);
1604  }
1605  else if (sizeof(struct IPv6UdpAddress) == udpw->session->address->address_length)
1606  {
1608  plugin->ipv6_queue_tail,
1609  udpw);
1610  }
1611  else
1612  {
1613  GNUNET_break (0);
1614  return;
1615  }
1616  GNUNET_assert (session->msgs_in_queue > 0);
1617  session->msgs_in_queue--;
1618  GNUNET_assert (session->bytes_in_queue >= udpw->msg_size);
1619  session->bytes_in_queue -= udpw->msg_size;
1620 }
#define GNUNET_CONTAINER_DLL_remove(head, tail, element)
Remove an element from a DLL.
size_t address_length
Number of bytes in address.
struct UDP_MessageWrapper * ipv6_queue_head
Head of messages in IPv6 queue.
struct GNUNET_ATS_Session * session
Session this message belongs to.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:81
int64_t bytes_in_buffer
Bytes currently in buffer.
struct GNUNET_HELLO_Address * address
Address.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Network format for IPv4 addresses.
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
Network format for IPv6 addresses.
struct UDP_MessageWrapper * ipv4_queue_tail
Tail of messages in IPv4 queue.
struct UDP_MessageWrapper * ipv6_queue_tail
Tail of messages in IPv6 queue.
struct UDP_MessageWrapper * ipv4_queue_head
Head of messages in IPv4 queue.
size_t msg_size
Size of UDP message to send, including UDP-specific overhead.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enqueue()

static void enqueue ( struct Plugin plugin,
struct UDP_MessageWrapper udpw 
)
static

Enqueue a message for transmission and update statistics.

Parameters
pluginthe UDP plugin
udpwmessage wrapper to queue

Definition at line 1630 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, Plugin::bytes_in_buffer, GNUNET_ATS_Session::bytes_in_queue, UDP_MessageWrapper::cont, UDP_MessageWrapper::cont_cls, Plugin::env, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_free, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_SYSERR, GNUNET_YES, GNUNET_ATS_Session::in_destroy, Plugin::ipv4_queue_head, Plugin::ipv4_queue_tail, Plugin::ipv6_queue_head, Plugin::ipv6_queue_tail, UDP_MessageWrapper::msg_size, GNUNET_ATS_Session::msgs_in_queue, UDP_MessageWrapper::session, and GNUNET_ATS_Session::target.

Referenced by ack_proc(), enqueue_fragment(), and udp_plugin_send().

1632 {
1633  struct GNUNET_ATS_Session *session = udpw->session;
1634 
1635  if (GNUNET_YES == session->in_destroy)
1636  {
1637  GNUNET_break (0);
1638  GNUNET_free (udpw);
1639  return;
1640  }
1641  if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size)
1642  {
1643  GNUNET_break (0);
1644  }
1645  else
1646  {
1647  GNUNET_STATISTICS_update (plugin->env->stats,
1648  "# UDP, total bytes in send buffers",
1649  udpw->msg_size,
1650  GNUNET_NO);
1651  plugin->bytes_in_buffer += udpw->msg_size;
1652  }
1653  GNUNET_STATISTICS_update (plugin->env->stats,
1654  "# UDP, total messages in send buffers",
1655  1,
1656  GNUNET_NO);
1657  if (sizeof (struct IPv4UdpAddress) == udpw->session->address->address_length)
1658  {
1660  plugin->ipv4_queue_tail,
1661  udpw);
1662  }
1663  else if (sizeof (struct IPv6UdpAddress) == udpw->session->address->address_length)
1664  {
1666  plugin->ipv6_queue_tail,
1667  udpw);
1668  }
1669  else
1670  {
1671  GNUNET_break (0);
1672  udpw->cont (udpw->cont_cls,
1673  &session->target,
1674  GNUNET_SYSERR,
1675  udpw->msg_size,
1676  0);
1677  GNUNET_free (udpw);
1678  return;
1679  }
1680  session->msgs_in_queue++;
1681  session->bytes_in_queue += udpw->msg_size;
1682 }
size_t address_length
Number of bytes in address.
struct UDP_MessageWrapper * ipv6_queue_head
Head of messages in IPv6 queue.
struct GNUNET_ATS_Session * session
Session this message belongs to.
#define GNUNET_CONTAINER_DLL_insert(head, tail, element)
Insert an element at the head of a DLL.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
#define GNUNET_NO
Definition: gnunet_common.h:81
int64_t bytes_in_buffer
Bytes currently in buffer.
struct GNUNET_HELLO_Address * address
Address.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
unsigned long long bytes_in_queue
Number of bytes waiting for transmission to this peer.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Network format for IPv4 addresses.
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
int in_destroy
Is this session about to be destroyed (sometimes we cannot destroy a session immediately as below us ...
GNUNET_TRANSPORT_TransmitContinuation cont
External continuation to call upon completion of the transmission, NULL if this queue entry is not fo...
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
struct UDP_MessageWrapper * ipv4_queue_tail
Tail of messages in IPv4 queue.
struct UDP_MessageWrapper * ipv6_queue_tail
Tail of messages in IPv6 queue.
void * cont_cls
Closure for cont.
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct UDP_MessageWrapper * ipv4_queue_head
Head of messages in IPv4 queue.
size_t msg_size
Size of UDP message to send, including UDP-specific overhead.
#define GNUNET_free(ptr)
Wrapper around free.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fragmented_message_done()

static void fragmented_message_done ( struct UDP_FragmentationContext frag_ctx,
int  result 
)
static

We have completed our (attempt) to transmit a message that had to be fragmented – either because we got an ACK saying that all fragments were received, or because of timeout / disconnect.

Clean up our state.

Parameters
frag_ctxfragmentation context to clean up
resultGNUNET_OK if we succeeded (got ACK), GNUNET_SYSERR if the transmission failed

Definition at line 1696 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, UDP_FragmentationContext::cont, UDP_FragmentationContext::cont_cls, dequeue(), Plugin::env, UDP_FragmentationContext::frag, GNUNET_ATS_Session::frag_ctx, UDP_MessageWrapper::frag_ctx, GNUNET_CONSTANTS_LATENCY_WARN, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_FRAGMENT_context_destroy(), GNUNET_free, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_STRINGS_absolute_time_to_string(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_get_duration(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, Plugin::ipv4_queue_head, Plugin::ipv6_queue_head, GNUNET_ATS_Session::last_expected_ack_delay, GNUNET_ATS_Session::last_expected_msg_delay, LOG, UDP_MessageWrapper::next, UDP_FragmentationContext::next_frag_time, notify_session_monitor(), UDP_FragmentationContext::on_wire_size, UDP_FragmentationContext::payload_size, plugin, UDP_FragmentationContext::plugin, GNUNET_ATS_Session::plugin, GNUNET_TIME_Relative::rel_value_us, UDP_FragmentationContext::session, UDP_FragmentationContext::start_time, and GNUNET_ATS_Session::target.

Referenced by qc_fragment_sent(), read_process_ack(), and udp_disconnect_session().

1698 {
1699  struct Plugin *plugin = frag_ctx->plugin;
1700  struct GNUNET_ATS_Session *s = frag_ctx->session;
1701  struct UDP_MessageWrapper *udpw;
1702  struct UDP_MessageWrapper *tmp;
1703  size_t overhead;
1704  struct GNUNET_TIME_Relative delay;
1705 
1707  "%p: Fragmented message removed with result %s\n",
1708  frag_ctx,
1709  (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS");
1710  /* Call continuation for fragmented message */
1711  if (frag_ctx->on_wire_size >= frag_ctx->payload_size)
1712  overhead = frag_ctx->on_wire_size - frag_ctx->payload_size;
1713  else
1714  overhead = frag_ctx->on_wire_size;
1717  {
1719  "Fragmented message acknowledged after %s (expected at %s)\n",
1721  GNUNET_YES),
1723  }
1724  else
1725  {
1727  "Fragmented message acknowledged after %s (expected at %s)\n",
1729  GNUNET_YES),
1731  }
1732 
1733  if (NULL != frag_ctx->cont)
1734  frag_ctx->cont (frag_ctx->cont_cls,
1735  &s->target,
1736  result,
1737  s->frag_ctx->payload_size,
1738  frag_ctx->on_wire_size);
1739  GNUNET_STATISTICS_update (plugin->env->stats,
1740  "# UDP, fragmented messages active",
1741  -1,
1742  GNUNET_NO);
1743 
1744  if (GNUNET_OK == result)
1745  {
1746  GNUNET_STATISTICS_update (plugin->env->stats,
1747  "# UDP, fragmented msgs, messages, sent, success",
1748  1,
1749  GNUNET_NO);
1750  GNUNET_STATISTICS_update (plugin->env->stats,
1751  "# UDP, fragmented msgs, bytes payload, sent, success",
1752  s->frag_ctx->payload_size,
1753  GNUNET_NO);
1754  GNUNET_STATISTICS_update (plugin->env->stats,
1755  "# UDP, fragmented msgs, bytes overhead, sent, success",
1756  overhead,
1757  GNUNET_NO);
1758  GNUNET_STATISTICS_update (plugin->env->stats,
1759  "# UDP, total, bytes overhead, sent",
1760  overhead,
1761  GNUNET_NO);
1762  GNUNET_STATISTICS_update (plugin->env->stats,
1763  "# UDP, total, bytes payload, sent",
1764  s->frag_ctx->payload_size,
1765  GNUNET_NO);
1766  }
1767  else
1768  {
1769  GNUNET_STATISTICS_update (plugin->env->stats,
1770  "# UDP, fragmented msgs, messages, sent, failure",
1771  1,
1772  GNUNET_NO);
1773  GNUNET_STATISTICS_update (plugin->env->stats,
1774  "# UDP, fragmented msgs, bytes payload, sent, failure",
1775  s->frag_ctx->payload_size,
1776  GNUNET_NO);
1777  GNUNET_STATISTICS_update (plugin->env->stats,
1778  "# UDP, fragmented msgs, bytes payload, sent, failure",
1779  overhead,
1780  GNUNET_NO);
1781  GNUNET_STATISTICS_update (plugin->env->stats,
1782  "# UDP, fragmented msgs, bytes payload, sent, failure",
1783  overhead,
1784  GNUNET_NO);
1785  }
1786 
1787  /* Remove remaining fragments from queue, no need to transmit those
1788  any longer. */
1789  if (s->address->address_length == sizeof(struct IPv6UdpAddress))
1790  {
1791  udpw = plugin->ipv6_queue_head;
1792  while (NULL != udpw)
1793  {
1794  tmp = udpw->next;
1795  if ( (udpw->frag_ctx != NULL) &&
1796  (udpw->frag_ctx == frag_ctx) )
1797  {
1798  dequeue (plugin,
1799  udpw);
1800  GNUNET_free (udpw);
1801  }
1802  udpw = tmp;
1803  }
1804  }
1805  if (s->address->address_length == sizeof(struct IPv4UdpAddress))
1806  {
1807  udpw = plugin->ipv4_queue_head;
1808  while (NULL != udpw)
1809  {
1810  tmp = udpw->next;
1811  if ( (NULL != udpw->frag_ctx) &&
1812  (udpw->frag_ctx == frag_ctx) )
1813  {
1814  dequeue (plugin,
1815  udpw);
1816  GNUNET_free (udpw);
1817  }
1818  udpw = tmp;
1819  }
1820  }
1822  s,
1827  s->frag_ctx = NULL;
1828  GNUNET_free (frag_ctx);
1829 }
size_t address_length
Number of bytes in address.
size_t payload_size
Payload size of original unfragmented message.
struct UDP_MessageWrapper * ipv6_queue_head
Head of messages in IPv6 queue.
uint64_t rel_value_us
The actual value.
struct Plugin * plugin
Pointer to the global plugin struct.
struct Plugin * plugin
The plugin.
#define GNUNET_CONSTANTS_LATENCY_WARN
After what amount of latency for a message do we print a warning?
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TIME_Relative last_expected_ack_delay
expected delay for ACKs
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct UDP_FragmentationContext * frag_ctx
Fragmentation context.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct UDP_MessageWrapper * next
DLL of messages, next element.
size_t on_wire_size
Bytes used to send all fragments on wire including UDP overhead.
Network format for IPv4 addresses.
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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 int result
Global testing status.
static GNUNET_NETWORK_STRUCT_END void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
void * cont_cls
Closure for cont.
struct GNUNET_ATS_Session * session
The session this fragmentation context belongs to.
Information we track for each message in the queue.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
static void dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
Remove the given message from the transmission queue and update all applicable statistics.
struct GNUNET_TIME_Absolute start_time
Start time.
This is just an update about the session, the state did not change.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TIME_Relative last_expected_msg_delay
desired delay between UDP messages
const char * GNUNET_STRINGS_absolute_time_to_string(struct GNUNET_TIME_Absolute t)
Like asctime, except for GNUnet time.
Definition: strings.c:792
struct UDP_MessageWrapper * ipv4_queue_head
Head of messages in IPv4 queue.
GNUNET_TRANSPORT_TransmitContinuation cont
Function to call upon completion of the transmission.
struct UDP_FragmentationContext * frag_ctx
Context for dealing with fragments.
void GNUNET_FRAGMENT_context_destroy(struct GNUNET_FRAGMENT_Context *fc, struct GNUNET_TIME_Relative *msg_delay, struct GNUNET_TIME_Relative *ack_delay)
Destroy the given fragmentation context (stop calling &#39;proc&#39;, free resources).
#define LOG(kind,...)
struct GNUNET_FRAGMENT_Context * frag
Handle for fragmentation.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TIME_Absolute next_frag_time
Transmission time for the next fragment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ qc_fragment_sent()

static void qc_fragment_sent ( void *  cls,
struct UDP_MessageWrapper udpw,
int  result 
)
static

We are finished with a fragment in the message queue.

Notify the continuation and update statistics.

Parameters
clsthe struct Plugin *
udpwthe queue entry
resultGNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 1841 of file plugin_transport_udp.c.

References Plugin::env, UDP_FragmentationContext::frag, UDP_MessageWrapper::frag_ctx, fragmented_message_done(), GNUNET_assert, GNUNET_ERROR_TYPE_DEBUG, GNUNET_FRAGMENT_context_transmission_done(), GNUNET_i2s(), GNUNET_log, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_SYSERR, UDP_MessageWrapper::msg_size, UDP_MessageWrapper::payload_size, plugin, UDP_MessageWrapper::session, and GNUNET_ATS_Session::target.

Referenced by enqueue_fragment().

1844 {
1845  struct Plugin *plugin = cls;
1846 
1847  GNUNET_assert (NULL != udpw->frag_ctx);
1848  if (GNUNET_OK == result)
1849  {
1851  "Fragment of message with %u bytes transmitted to %s\n",
1852  (unsigned int) udpw->payload_size,
1853  GNUNET_i2s (&udpw->session->target));
1855  GNUNET_STATISTICS_update (plugin->env->stats,
1856  "# UDP, fragmented msgs, fragments, sent, success",
1857  1,
1858  GNUNET_NO);
1859  GNUNET_STATISTICS_update (plugin->env->stats,
1860  "# UDP, fragmented msgs, fragments bytes, sent, success",
1861  udpw->msg_size,
1862  GNUNET_NO);
1863  }
1864  else
1865  {
1867  "Failed to transmit fragment of message with %u bytes to %s\n",
1868  (unsigned int) udpw->payload_size,
1869  GNUNET_i2s (&udpw->session->target));
1871  GNUNET_SYSERR);
1872  GNUNET_STATISTICS_update (plugin->env->stats,
1873  "# UDP, fragmented msgs, fragments, sent, failure",
1874  1,
1875  GNUNET_NO);
1876  GNUNET_STATISTICS_update (plugin->env->stats,
1877  "# UDP, fragmented msgs, fragments bytes, sent, failure",
1878  udpw->msg_size,
1879  GNUNET_NO);
1880  }
1881 }
size_t payload_size
Payload size of original message.
struct GNUNET_ATS_Session * session
Session this message belongs to.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result)
We have completed our (attempt) to transmit a message that had to be fragmented – either because we ...
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
struct UDP_FragmentationContext * frag_ctx
Fragmentation context.
void GNUNET_FRAGMENT_context_transmission_done(struct GNUNET_FRAGMENT_Context *fc)
Continuation to call from the &#39;proc&#39; function after the fragment has been transmitted (and hence the ...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static int result
Global testing status.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_log(kind,...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
struct GNUNET_FRAGMENT_Context * frag
Handle for fragmentation.
size_t msg_size
Size of UDP message to send, including UDP-specific overhead.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ enqueue_fragment()

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

Function that is called with messages created by the fragmentation module.

In the case of the proc callback of the GNUNET_FRAGMENT_context_create() function, this function must eventually call GNUNET_FRAGMENT_context_transmission_done().

Parameters
clsclosure, the struct UDP_FragmentationContext
msgthe message that was created

Definition at line 1894 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, enqueue(), UDP_FragmentationContext::flow_delay_from_other_peer, GNUNET_ATS_Session::frag_ctx, UDP_MessageWrapper::frag_ctx, GNUNET_ERROR_TYPE_DEBUG, GNUNET_malloc, GNUNET_memcpy, GNUNET_TIME_absolute_add(), LOG, UDP_MessageWrapper::msg_buf, UDP_MessageWrapper::msg_size, UDP_FragmentationContext::next_frag_time, UDP_MessageWrapper::payload_size, plugin, UDP_FragmentationContext::plugin, UDP_MessageWrapper::qc, UDP_MessageWrapper::qc_cls, qc_fragment_sent(), schedule_select_v4(), schedule_select_v6(), UDP_FragmentationContext::session, UDP_MessageWrapper::session, GNUNET_MessageHeader::size, UDP_FragmentationContext::start_time, UDP_MessageWrapper::start_time, UDP_FragmentationContext::timeout, UDP_MessageWrapper::timeout, and UDP_MessageWrapper::transmission_time.

Referenced by udp_plugin_send().

1896 {
1897  struct UDP_FragmentationContext *frag_ctx = cls;
1898  struct Plugin *plugin = frag_ctx->plugin;
1899  struct UDP_MessageWrapper *udpw;
1900  struct GNUNET_ATS_Session *session = frag_ctx->session;
1901  size_t msg_len = ntohs (msg->size);
1902 
1904  "Enqueuing fragment with %u bytes\n",
1905  msg_len);
1906  udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msg_len);
1907  udpw->session = session;
1908  udpw->msg_buf = (char *) &udpw[1];
1909  udpw->msg_size = msg_len;
1910  udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */
1911  udpw->timeout = frag_ctx->timeout;
1912  udpw->start_time = frag_ctx->start_time;
1913  udpw->transmission_time = frag_ctx->next_frag_time;
1914  frag_ctx->next_frag_time
1916  frag_ctx->flow_delay_from_other_peer);
1917  udpw->frag_ctx = frag_ctx;
1918  udpw->qc = &qc_fragment_sent;
1919  udpw->qc_cls = plugin;
1920  GNUNET_memcpy (udpw->msg_buf,
1921  msg,
1922  msg_len);
1923  enqueue (plugin,
1924  udpw);
1925  if (session->address->address_length == sizeof (struct IPv4UdpAddress))
1926  schedule_select_v4 (plugin);
1927  else
1928  schedule_select_v6 (plugin);
1929 }
size_t address_length
Number of bytes in address.
size_t payload_size
Payload size of original message.
struct GNUNET_ATS_Session * session
Session this message belongs to.
static void enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
Enqueue a message for transmission and update statistics.
struct GNUNET_TIME_Absolute timeout
Message timeout.
struct Plugin * plugin
The plugin.
struct GNUNET_TIME_Absolute transmission_time
Desired transmission time for this message, based on the flow limiting information we got from the ot...
struct GNUNET_TIME_Relative flow_delay_from_other_peer
Desired delay for transmissions we received from other peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:393
struct GNUNET_HELLO_Address * address
Address.
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct UDP_FragmentationContext * frag_ctx
Fragmentation context.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Context to send fragmented messages.
#define GNUNET_memcpy(dst, src, n)
Network format for IPv4 addresses.
Information about ongoing sessions of the transport client.
struct GNUNET_ATS_Session * session
The session this fragmentation context belongs to.
Information we track for each message in the queue.
static void schedule_select_v6(struct Plugin *plugin)
(re)schedule IPv6-select tasks for this plugin.
static void schedule_select_v4(struct Plugin *plugin)
(re)schedule IPv4-select tasks for this plugin.
struct GNUNET_TIME_Absolute start_time
Message enqueue time.
struct GNUNET_TIME_Absolute start_time
Start time.
char * msg_buf
Message with msg_size bytes including UDP-specific overhead.
Handle for a plugin.
Definition: block.c:37
void * qc_cls
Closure for qc.
QueueContinuation qc
Function to call once the message wrapper is being removed from the queue (with success or failure)...
static void qc_fragment_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
We are finished with a fragment in the message queue.
struct UDP_FragmentationContext * frag_ctx
Context for dealing with fragments.
#define LOG(kind,...)
size_t msg_size
Size of UDP message to send, including UDP-specific overhead.
#define GNUNET_malloc(size)
Wrapper around malloc.
struct GNUNET_TIME_Absolute timeout
Message timeout.
struct GNUNET_TIME_Absolute next_frag_time
Transmission time for the next fragment.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ qc_message_sent()

static void qc_message_sent ( void *  cls,
struct UDP_MessageWrapper udpw,
int  result 
)
static

We are finished with a message from the message queue.

Notify the continuation and update statistics.

Parameters
clsthe struct Plugin *
udpwthe queue entry
resultGNUNET_OK on success, GNUNET_SYSERR on failure

Definition at line 1941 of file plugin_transport_udp.c.

References UDP_MessageWrapper::cont, UDP_MessageWrapper::cont_cls, Plugin::env, GNUNET_CONSTANTS_LATENCY_WARN, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_duration(), GNUNET_YES, LOG, UDP_MessageWrapper::msg_size, UDP_MessageWrapper::payload_size, plugin, GNUNET_TIME_Relative::rel_value_us, UDP_MessageWrapper::session, UDP_MessageWrapper::start_time, and GNUNET_ATS_Session::target.

Referenced by udp_plugin_send().

1944 {
1945  struct Plugin *plugin = cls;
1946  size_t overhead;
1947  struct GNUNET_TIME_Relative delay;
1948 
1949  if (udpw->msg_size >= udpw->payload_size)
1950  overhead = udpw->msg_size - udpw->payload_size;
1951  else
1952  overhead = udpw->msg_size;
1953 
1954  if (NULL != udpw->cont)
1955  {
1958  {
1960  "Message sent via UDP with delay of %s\n",
1962  GNUNET_YES));
1963  }
1964  else
1965  {
1967  "Message sent via UDP with delay of %s\n",
1969  GNUNET_YES));
1970  }
1971  udpw->cont (udpw->cont_cls,
1972  &udpw->session->target,
1973  result,
1974  udpw->payload_size,
1975  overhead);
1976  }
1977  if (GNUNET_OK == result)
1978  {
1979  GNUNET_STATISTICS_update (plugin->env->stats,
1980  "# UDP, unfragmented msgs, messages, sent, success",
1981  1,
1982  GNUNET_NO);
1983  GNUNET_STATISTICS_update (plugin->env->stats,
1984  "# UDP, unfragmented msgs, bytes payload, sent, success",
1985  udpw->payload_size,
1986  GNUNET_NO);
1987  GNUNET_STATISTICS_update (plugin->env->stats,
1988  "# UDP, unfragmented msgs, bytes overhead, sent, success",
1989  overhead,
1990  GNUNET_NO);
1991  GNUNET_STATISTICS_update (plugin->env->stats,
1992  "# UDP, total, bytes overhead, sent",
1993  overhead,
1994  GNUNET_NO);
1995  GNUNET_STATISTICS_update (plugin->env->stats,
1996  "# UDP, total, bytes payload, sent",
1997  udpw->payload_size,
1998  GNUNET_NO);
1999  }
2000  else
2001  {
2002  GNUNET_STATISTICS_update (plugin->env->stats,
2003  "# UDP, unfragmented msgs, messages, sent, failure",
2004  1,
2005  GNUNET_NO);
2006  GNUNET_STATISTICS_update (plugin->env->stats,
2007  "# UDP, unfragmented msgs, bytes payload, sent, failure",
2008  udpw->payload_size,
2009  GNUNET_NO);
2010  GNUNET_STATISTICS_update (plugin->env->stats,
2011  "# UDP, unfragmented msgs, bytes overhead, sent, failure",
2012  overhead,
2013  GNUNET_NO);
2014  }
2015 }
size_t payload_size
Payload size of original message.
uint64_t rel_value_us
The actual value.
struct GNUNET_ATS_Session * session
Session this message belongs to.
#define GNUNET_CONSTANTS_LATENCY_WARN
After what amount of latency for a message do we print a warning?
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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 int result
Global testing status.
GNUNET_TRANSPORT_TransmitContinuation cont
External continuation to call upon completion of the transmission, NULL if this queue entry is not fo...
static struct GNUNET_TIME_Relative delay
When should dkg communication start?
struct GNUNET_TIME_Absolute start_time
Message enqueue time.
Handle for a plugin.
Definition: block.c:37
void * cont_cls
Closure for cont.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_duration(struct GNUNET_TIME_Absolute whence)
Get the duration of an operation as the difference of the current time and the given start time "henc...
Definition: time.c:373
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
size_t msg_size
Size of UDP message to send, including UDP-specific overhead.
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:

◆ udp_plugin_send()

static ssize_t udp_plugin_send ( void *  cls,
struct GNUNET_ATS_Session s,
const char *  msgbuf,
size_t  msgbuf_size,
unsigned int  priority,
struct GNUNET_TIME_Relative  to,
GNUNET_TRANSPORT_TransmitContinuation  cont,
void *  cont_cls 
)
static

Function that can be used by the transport service to transmit a message using the plugin.

Note that in the case of a peer disconnecting, the continuation MUST be called prior to the disconnect notification itself. This function will be called with this peer's HELLO message to initiate a fresh connection to another peer.

Parameters
clsclosure
swhich session must be used
msgbufthe message to transmit
msgbuf_sizenumber of bytes in msgbuf
priorityhow important is the message (most plugins will ignore message priority and just FIFO)
tohow long to wait at most for the transmission (does not require plugins to discard the message after the timeout, just advisory for the desired delay; most plugins will ignore this as well)
contcontinuation to call once the message has been transmitted (or if the transport is ready for the next transmission call; or if the peer disconnected...); can be NULL
cont_clsclosure for cont
Returns
number of bytes used (on the physical network, with overheads); -1 on hard errors (i.e. address invalid); 0 is a legal value and does NOT mean that the message was not transmitted (DV)

Definition at line 2046 of file plugin_transport_udp.c.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, UDP_FragmentationContext::cont, UDP_MessageWrapper::cont, UDP_FragmentationContext::cont_cls, UDP_MessageWrapper::cont_cls, enqueue(), enqueue_fragment(), Plugin::env, GNUNET_ATS_Session::flow_delay_from_other_peer, UDP_FragmentationContext::flow_delay_from_other_peer, UDP_FragmentationContext::frag, GNUNET_ATS_Session::frag_ctx, UDP_MessageWrapper::frag_ctx, GNUNET_ALIGN, GNUNET_break, GNUNET_CONSTANTS_LATENCY_WARN, GNUNET_CONTAINER_multipeermap_contains_value(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_WARNING, GNUNET_FRAGMENT_context_create(), GNUNET_i2s(), GNUNET_malloc, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE, GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_SYSERR, GNUNET_TIME_absolute_add(), GNUNET_TIME_absolute_get(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TIME_relative_divide(), GNUNET_TIME_relative_to_absolute(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, UDPMessage::header, GNUNET_ATS_Session::last_expected_ack_delay, GNUNET_ATS_Session::last_expected_msg_delay, GNUNET_ATS_Session::last_transmit_time, LOG, UDP_MessageWrapper::msg_buf, UDP_MessageWrapper::msg_size, GNUNET_ATS_Session::msgs_in_queue, UDP_FragmentationContext::next_frag_time, notify_session_monitor(), UDP_FragmentationContext::on_wire_size, UDP_FragmentationContext::payload_size, UDP_MessageWrapper::payload_size, plugin, UDP_FragmentationContext::plugin, GNUNET_ATS_Session::plugin, UDP_MessageWrapper::qc, UDP_MessageWrapper::qc_cls, qc_message_sent(), GNUNET_TIME_Relative::rel_value_us, UDPMessage::reserved, schedule_select_v4(), schedule_select_v6(), UDPMessage::sender, UDP_FragmentationContext::session, UDP_MessageWrapper::session, Plugin::sessions, GNUNET_MessageHeader::size, Plugin::sockv4, Plugin::sockv6, UDP_FragmentationContext::start_time, UDP_MessageWrapper::start_time, GNUNET_ATS_Session::target, UDP_FragmentationContext::timeout, UDP_MessageWrapper::timeout, Plugin::tracker, UDP_MessageWrapper::transmission_time, GNUNET_MessageHeader::type, udp, udp_address_to_string(), and UDP_MTU.

Referenced by libgnunet_plugin_transport_udp_init().

2054 {
2055  struct Plugin *plugin = cls;
2056  size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage);
2057  struct UDP_FragmentationContext *frag_ctx;
2058  struct UDP_MessageWrapper *udpw;
2059  struct UDPMessage *udp;
2060  char mbuf[udpmlen] GNUNET_ALIGN;
2061  struct GNUNET_TIME_Relative latency;
2062 
2063  if ( (sizeof(struct IPv6UdpAddress) == s->address->address_length) &&
2064  (NULL == plugin->sockv6) )
2065  return GNUNET_SYSERR;
2066  if ( (sizeof(struct IPv4UdpAddress) == s->address->address_length) &&
2067  (NULL == plugin->sockv4) )
2068  return GNUNET_SYSERR;
2069  if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
2070  {
2071  GNUNET_break (0);
2072  return GNUNET_SYSERR;
2073  }
2074  if (GNUNET_YES !=
2076  &s->target,
2077  s))
2078  {
2079  GNUNET_break (0);
2080  return GNUNET_SYSERR;
2081  }
2083  "UDP transmits %u-byte message to `%s' using address `%s'\n",
2084  udpmlen,
2085  GNUNET_i2s (&s->target),
2086  udp_address_to_string (plugin,
2087  s->address->address,
2088  s->address->address_length));
2089 
2090  udp = (struct UDPMessage *) mbuf;
2091  udp->header.size = htons (udpmlen);
2093  udp->reserved = htonl (0);
2094  udp->sender = *plugin->env->my_identity;
2095 
2096  /* We do not update the session time out here! Otherwise this
2097  * session will not timeout since we send keep alive before session
2098  * can timeout.
2099  *
2100  * For UDP we update session timeout only on receive, this will
2101  * cover keep alives, since remote peer will reply with keep alive
2102  * responses!
2103  */
2104  if (udpmlen <= UDP_MTU)
2105  {
2106  /* unfragmented message */
2107  udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + udpmlen);
2108  udpw->session = s;
2109  udpw->msg_buf = (char *) &udpw[1];
2110  udpw->msg_size = udpmlen; /* message size with UDP overhead */
2111  udpw->payload_size = msgbuf_size; /* message size without UDP overhead */
2118  udpw->cont = cont;
2119  udpw->cont_cls = cont_cls;
2120  udpw->frag_ctx = NULL;
2121  udpw->qc = &qc_message_sent;
2122  udpw->qc_cls = plugin;
2123  GNUNET_memcpy (udpw->msg_buf,
2124  udp,
2125  sizeof (struct UDPMessage));
2126  GNUNET_memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)],
2127  msgbuf,
2128  msgbuf_size);
2129  enqueue (plugin,
2130  udpw);
2131  GNUNET_STATISTICS_update (plugin->env->stats,
2132  "# UDP, unfragmented messages queued total",
2133  1,
2134  GNUNET_NO);
2135  GNUNET_STATISTICS_update (plugin->env->stats,
2136  "# UDP, unfragmented bytes payload queued total",
2137  msgbuf_size,
2138  GNUNET_NO);
2139  if (s->address->address_length == sizeof (struct IPv4UdpAddress))
2140  schedule_select_v4 (plugin);
2141  else
2142  schedule_select_v6 (plugin);
2143  }
2144  else
2145  {
2146  /* fragmented message */
2147  if (NULL != s->frag_ctx)
2148  return GNUNET_SYSERR;
2149  GNUNET_memcpy (&udp[1],
2150  msgbuf,
2151  msgbuf_size);
2152  frag_ctx = GNUNET_new (struct UDP_FragmentationContext);
2153  frag_ctx->plugin = plugin;
2154  frag_ctx->session = s;
2155  frag_ctx->cont = cont;
2156  frag_ctx->cont_cls = cont_cls;
2157  frag_ctx->start_time = GNUNET_TIME_absolute_get ();
2158  frag_ctx->next_frag_time = s->last_transmit_time;
2159  frag_ctx->flow_delay_from_other_peer
2161  1 + (msgbuf_size /
2162  UDP_MTU));
2163  frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to);
2164  frag_ctx->payload_size = msgbuf_size; /* unfragmented message size without UDP overhead */
2165  frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
2166  frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
2167  UDP_MTU,
2168  &plugin->tracker,
2171  &udp->header,
2173  frag_ctx);
2174  s->frag_ctx = frag_ctx;
2175  s->last_transmit_time = frag_ctx->next_frag_time;
2177  if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2179  "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2181  GNUNET_YES),
2182  GNUNET_i2s (&s->target),
2183  (unsigned int) s->msgs_in_queue);
2184  else
2186  "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2188  GNUNET_YES),
2189  GNUNET_i2s (&s->target),
2190  (unsigned int) s->msgs_in_queue);
2191 
2192  GNUNET_STATISTICS_update (plugin->env->stats,
2193  "# UDP, fragmented messages active",
2194  1,
2195  GNUNET_NO);
2196  GNUNET_STATISTICS_update (plugin->env->stats,
2197  "# UDP, fragmented messages, total",
2198  1,
2199  GNUNET_NO);
2200  GNUNET_STATISTICS_update (plugin->env->stats,
2201  "# UDP, fragmented bytes (payload)",
2202  frag_ctx->payload_size,
2203  GNUNET_NO);
2204  }
2206  s,
2208  return udpmlen;
2209 }
size_t address_length
Number of bytes in address.
struct GNUNET_TIME_Absolute last_transmit_time
What time did we last transmit?
size_t payload_size
Payload size of original message.
static int udp
Option -u: UDP requested.
Definition: gnunet-vpn.c:76
size_t payload_size
Payload size of original unfragmented message.
const void * address
Binary representation of the address (plugin-specific).
struct GNUNET_ATS_Session * session
Session this message belongs to.
static void enqueue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
Enqueue a message for transmission and update statistics.
unsigned int msgs_in_queue
Number of messages waiting for transmission to this peer.
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_TIME_Absolute timeout
Message timeout.
struct Plugin * plugin
The plugin.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
struct GNUNET_MessageHeader header
Message header.
UDP Message-Packet header (after defragmentation).
struct GNUNET_TIME_Absolute transmission_time
Desired transmission time for this message, based on the flow limiting information we got from the ot...
uint32_t reserved
Always zero for now.
static void qc_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
We are finished with a message from the message queue.
struct GNUNET_FRAGMENT_Context * GNUNET_FRAGMENT_context_create(struct GNUNET_STATISTICS_Handle *stats, uint16_t mtu, struct GNUNET_BANDWIDTH_Tracker *tracker, struct GNUNET_TIME_Relative msg_delay, struct GNUNET_TIME_Relative ack_delay, const struct GNUNET_MessageHeader *msg, GNUNET_FRAGMENT_MessageProcessor proc, void *proc_cls)
Create a fragmentation context for the given message.
#define GNUNET_CONSTANTS_LATENCY_WARN
After what amount of latency for a message do we print a warning?
static void enqueue_fragment(void *cls, const struct GNUNET_MessageHeader *msg)
Function that is called with messages created by the fragmentation module.
#define GNUNET_NO
Definition: gnunet_common.h:81
struct GNUNET_TIME_Relative flow_delay_from_other_peer
Desired delay for transmissions we received from other peer.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_add(struct GNUNET_TIME_Absolute start, struct GNUNET_TIME_Relative duration)
Add a given relative duration to the given start time.
Definition: time.c:393
#define GNUNET_new(type)
Allocate a struct or union of the given type.
struct GNUNET_HELLO_Address * address
Address.
struct GNUNET_TIME_Relative last_expected_ack_delay
expected delay for ACKs
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
struct GNUNET_NETWORK_Handle * sockv4
The read socket for IPv4.
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
#define UDP_MTU
MTU for fragmentation subsystem.
struct UDP_FragmentationContext * frag_ctx
Fragmentation context.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Context to send fragmented messages.
#define GNUNET_memcpy(dst, src, n)
struct GNUNET_TIME_Relative flow_delay_from_other_peer
Desired delay for transmissions we received from other peer.
size_t on_wire_size
Bytes used to send all fragments on wire including UDP overhead.
Network format for IPv4 addresses.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE
Normal UDP message type.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
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 GNUNET_NETWORK_STRUCT_END void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
GNUNET_TRANSPORT_TransmitContinuation cont
External continuation to call upon completion of the transmission, NULL if this queue entry is not fo...
void * cont_cls
Closure for cont.
struct GNUNET_ATS_Session * session
The session this fragmentation context belongs to.
Information we track for each message in the queue.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
static void schedule_select_v6(struct Plugin *plugin)
(re)schedule IPv6-select tasks for this plugin.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
#define GNUNET_MAX_MESSAGE_SIZE
Largest supported message (to be precise, one byte more than the largest possible message...
static void schedule_select_v4(struct Plugin *plugin)
(re)schedule IPv4-select tasks for this plugin.
struct GNUNET_TIME_Absolute start_time
Message enqueue time.
struct GNUNET_TIME_Absolute start_time
Start time.
This is just an update about the session, the state did not change.
char * msg_buf
Message with msg_size bytes including UDP-specific overhead.
int GNUNET_CONTAINER_multipeermap_contains_value(const struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, const void *value)
Check if the map contains the given value under the given key.
#define GNUNET_ALIGN
gcc-ism to force alignment; we use this to align char-arrays that may then be cast to &#39;struct&#39;s...
Handle for a plugin.
Definition: block.c:37
void * cont_cls
Closure for cont.
void * qc_cls
Closure for qc.
struct GNUNET_PeerIdentity target
To whom are we talking to.
const char * udp_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
struct GNUNET_NETWORK_Handle * sockv6
The read socket for IPv6.
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
struct GNUNET_TIME_Relative GNUNET_TIME_relative_divide(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Divide relative time by a given factor.
Definition: time.c:525
#define GNUNET_YES
Definition: gnunet_common.h:80
struct GNUNET_TIME_Relative last_expected_msg_delay
desired delay between UDP messages
QueueContinuation qc
Function to call once the message wrapper is being removed from the queue (with success or failure)...
struct GNUNET_BANDWIDTH_Tracker tracker
Bandwidth tracker to limit global UDP traffic.
GNUNET_TRANSPORT_TransmitContinuation cont
Function to call upon completion of the transmission.
struct UDP_FragmentationContext * frag_ctx
Context for dealing with fragments.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define LOG(kind,...)
struct GNUNET_FRAGMENT_Context * frag
Handle for fragmentation.
size_t msg_size
Size of UDP message to send, including UDP-specific overhead.
#define GNUNET_malloc(size)
Wrapper around malloc.
Time for relative time used by GNUnet, in microseconds.
struct GNUNET_TIME_Absolute timeout
Message timeout.
struct GNUNET_TIME_Absolute next_frag_time
Transmission time for the next fragment.
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_receive_context()

static int find_receive_context ( void *  cls,
struct GNUNET_CONTAINER_HeapNode node,
void *  element,
GNUNET_CONTAINER_HeapCostType  cost 
)
static

Scan the heap for a receive context with the given address.

Parameters
clsthe struct FindReceiveContext
nodeinternal node of the heap
elementvalue stored at the node (a struct ReceiveContext)
costcost associated with the node
Returns
GNUNET_YES if we should continue to iterate, GNUNET_NO if not.

Definition at line 2254 of file plugin_transport_udp.c.

References e, GNUNET_NO, GNUNET_YES, FindReceiveContext::rc, DefragContext::udp_addr, FindReceiveContext::udp_addr, DefragContext::udp_addr_len, and FindReceiveContext::udp_addr_len.

Referenced by read_process_fragment(), and udp_disconnect_session().

2258 {
2259  struct FindReceiveContext *frc = cls;
2260  struct DefragContext *e = element;
2261 
2262  if ( (frc->udp_addr_len == e->udp_addr_len) &&
2263  (0 == memcmp (frc->udp_addr,
2264  e->udp_addr,
2265  frc->udp_addr_len)) )
2266  {
2267  frc->rc = e;
2268  return GNUNET_NO;
2269  }
2270  return GNUNET_YES;
2271 }
const union UdpAddress * udp_addr
Address to find.
static struct Experiment * e
#define GNUNET_NO
Definition: gnunet_common.h:81
const union UdpAddress * udp_addr
Source address this receive context is for (allocated at the end of the struct).
size_t udp_addr_len
Length of udp_addr.
Closure for find_receive_context().
struct DefragContext * rc
Where to store the result.
Data structure to track defragmentation contexts based on the source of the UDP traffic.
size_t udp_addr_len
Number of bytes in udp_addr.
#define GNUNET_YES
Definition: gnunet_common.h:80
Here is the caller graph for this function:

◆ udp_disconnect_session()

static int udp_disconnect_session ( void *  cls,
struct GNUNET_ATS_Session s 
)
static

Functions with this signature are called whenever we need to close a session due to a disconnect or failure to establish a connection.

Parameters
clsclosure with the struct Plugin
ssession to close down
Returns
GNUNET_OK on success

Definition at line 2283 of file plugin_transport_udp.c.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, GNUNET_DATACACHE_PluginEnvironment::cls, UDP_FragmentationContext::cont, UDP_FragmentationContext::cont_cls, DefragContext::defrag, Plugin::defrag_ctxs, dequeue(), Plugin::env, find_receive_context(), GNUNET_ATS_Session::frag_ctx, fragmented_message_done(), free_session(), GNUNET_assert, GNUNET_CONTAINER_heap_iterate(), GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multipeermap_remove(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_DEFRAGMENT_context_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_i2s(), GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_cancel(), GNUNET_STATISTICS_set(), GNUNET_SYSERR, GNUNET_TRANSPORT_SS_DONE, GNUNET_YES, DefragContext::hnode, GNUNET_ATS_Session::in_destroy, Plugin::ipv4_queue_head, Plugin::ipv6_queue_head, LOG, UDP_MessageWrapper::next, notify_session_monitor(), UDP_FragmentationContext::on_wire_size, UDP_FragmentationContext::payload_size, plugin, GNUNET_ATS_Session::plugin, UDP_MessageWrapper::qc, UDP_MessageWrapper::qc_cls, GNUNET_ATS_Session::rc, FindReceiveContext::rc, UDP_MessageWrapper::session, Plugin::sessions, GNUNET_ATS_Session::target, GNUNET_ATS_Session::timeout_task, FindReceiveContext::udp_addr, FindReceiveContext::udp_addr_len, and udp_address_to_string().

Referenced by disconnect_and_free_it(), libgnunet_plugin_transport_udp_init(), read_process_ack(), and session_timeout().

2285 {
2286  struct Plugin *plugin = cls;
2287  struct UDP_MessageWrapper *udpw;
2288  struct UDP_MessageWrapper *next;
2289  struct FindReceiveContext frc;
2290 
2293  "Session %p to peer `%s' at address %s ended\n",
2294  s,
2295  GNUNET_i2s (&s->target),
2296  udp_address_to_string (plugin,
2297  s->address->address,
2298  s->address->address_length));
2299  if (NULL != s->timeout_task)
2300  {
2302  s->timeout_task = NULL;
2303  }
2304  if (NULL != s->frag_ctx)
2305  {
2306  /* Remove fragmented message due to disconnect */
2308  GNUNET_SYSERR);
2309  }
2312  &s->target,
2313  s));
2314  frc.rc = NULL;
2315  frc.udp_addr = s->address->address;
2316  frc.udp_addr_len = s->address->address_length;
2317  /* Lookup existing receive context for this address */
2318  if (NULL != plugin->defrag_ctxs)
2319  {
2322  &frc);
2323  if (NULL != frc.rc)
2324  {
2325  struct DefragContext *d_ctx = frc.rc;
2326 
2329  GNUNET_free (d_ctx);
2330  }
2331  }
2332  s->in_destroy = GNUNET_YES;
2333  next = plugin->ipv4_queue_head;
2334  while (NULL != (udpw = next))
2335  {
2336  next = udpw->next;
2337  if (udpw->session == s)
2338  {
2339  dequeue (plugin,
2340  udpw);
2341  udpw->qc (udpw->qc_cls,
2342  udpw,
2343  GNUNET_SYSERR);
2344  GNUNET_free (udpw);
2345  }
2346  }
2347  next = plugin->ipv6_queue_head;
2348  while (NULL != (udpw = next))
2349  {
2350  next = udpw->next;
2351  if (udpw->session == s)
2352  {
2353  dequeue (plugin,
2354  udpw);
2355  udpw->qc (udpw->qc_cls,
2356  udpw,
2357  GNUNET_SYSERR);
2358  GNUNET_free (udpw);
2359  }
2360  }
2361  if ( (NULL != s->frag_ctx) &&
2362  (NULL != s->frag_ctx->cont) )
2363  {
2364  /* The 'frag_ctx' itself will be freed in #free_session() a bit
2365  later, as it might be in use right now */
2367  "Calling continuation for fragemented message to `%s' with result SYSERR\n",
2368  GNUNET_i2s (&s->target));
2369  s->frag_ctx->cont (s->frag_ctx->cont_cls,
2370  &s->target,
2371  GNUNET_SYSERR,
2372  s->frag_ctx->payload_size,
2373  s->frag_ctx->on_wire_size);
2374  }
2376  s,
2378  plugin->env->session_end (plugin->env->cls,
2379  s->address,
2380  s);
2381  GNUNET_STATISTICS_set (plugin->env->stats,
2382  "# UDP sessions active",
2384  GNUNET_NO);
2385  if (0 == s->rc)
2386  free_session (s);
2387  return GNUNET_OK;
2388 }
size_t address_length
Number of bytes in address.
Session is being torn down and about to disappear.
size_t payload_size
Payload size of original unfragmented message.
struct UDP_MessageWrapper * ipv6_queue_head
Head of messages in IPv6 queue.
unsigned int rc
Reference counter to indicate that this session is currently being used and must not be destroyed; se...
const void * address
Binary representation of the address (plugin-specific).
struct GNUNET_ATS_Session * session
Session this message belongs to.
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
static void free_session(struct GNUNET_ATS_Session *s)
Function to free last resources associated with a session.
struct Plugin * plugin
Pointer to the global plugin struct.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static void fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result)
We have completed our (attempt) to transmit a message that had to be fragmented – either because we ...
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.
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct UDP_MessageWrapper * next
DLL of messages, next element.
void GNUNET_DEFRAGMENT_context_destroy(struct GNUNET_DEFRAGMENT_Context *dc)
Destroy the given defragmentation context.
size_t on_wire_size
Bytes used to send all fragments on wire including UDP overhead.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_DEFRAGMENT_Context * defrag
Defragmentation context.
int in_destroy
Is this session about to be destroyed (sometimes we cannot destroy a session immediately as below us ...
static GNUNET_NETWORK_STRUCT_END void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
void * cont_cls
Closure for cont.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
Information we track for each message in the queue.
Closure for find_receive_context().
#define GNUNET_SYSERR
Definition: gnunet_common.h:79
Data structure to track defragmentation contexts based on the source of the UDP traffic.
static void dequeue(struct Plugin *plugin, struct UDP_MessageWrapper *udpw)
Remove the given message from the transmission queue and update all applicable statistics.
struct GNUNET_CONTAINER_HeapNode * hnode
Node in the defrag heap.
static int find_receive_context(void *cls, struct GNUNET_CONTAINER_HeapNode *node, void *element, GNUNET_CONTAINER_HeapCostType cost)
Scan the heap for a receive context with the given address.
Handle for a plugin.
Definition: block.c:37
void * qc_cls
Closure for qc.
struct GNUNET_PeerIdentity target
To whom are we talking to.
const char * udp_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
void * cls
Closure to use for callbacks.
struct GNUNET_CONTAINER_Heap * defrag_ctxs
Heap with all of our defragmentation activities.
#define GNUNET_YES
Definition: gnunet_common.h:80
QueueContinuation qc
Function to call once the message wrapper is being removed from the queue (with success or failure)...
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
struct UDP_MessageWrapper * ipv4_queue_head
Head of messages in IPv4 queue.
void GNUNET_CONTAINER_heap_iterate(const struct GNUNET_CONTAINER_Heap *heap, GNUNET_CONTAINER_HeapIterator iterator, void *iterator_cls)
Iterate over all entries in the heap.
GNUNET_TRANSPORT_TransmitContinuation cont
Function to call upon completion of the transmission.
struct UDP_FragmentationContext * frag_ctx
Context for dealing with fragments.
void * GNUNET_CONTAINER_heap_remove_node(struct GNUNET_CONTAINER_HeapNode *node)
Removes a node from the heap.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define LOG(kind,...)
#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:

◆ read_process_ack()

static void read_process_ack ( struct Plugin plugin,
const struct GNUNET_MessageHeader msg,
const union UdpAddress udp_addr,
socklen_t  udp_addr_len 
)
static

Handle a GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK message.

Parameters
pluginthe UDP plugin
msgthe (presumed) UDP ACK message
udp_addrsender address
udp_addr_lennumber of bytes in udp_addr

Definition at line 2400 of file plugin_transport_udp.c.

References GNUNET_HELLO_Address::address, address, GNUNET_HELLO_Address::address_length, UDP_ACK_Message::delay, GNUNET_ATS_Session::flow_delay_from_other_peer, UDP_FragmentationContext::frag, GNUNET_ATS_Session::frag_ctx, fragmented_message_done(), GNUNET_break_op, GNUNET_CONSTANTS_LATENCY_WARN, GNUNET_ERROR_TYPE_BULK, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_FRAGMENT_print_ack(), GNUNET_FRAGMENT_process_ack(), GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_i2s(), GNUNET_OK, GNUNET_STRINGS_relative_time_to_string(), GNUNET_YES, LOG, PLUGIN_NAME, GNUNET_TIME_Relative::rel_value_us, UDP_ACK_Message::sender, GNUNET_MessageHeader::size, udp_address_to_string(), udp_disconnect_session(), and udp_plugin_lookup_session().

Referenced by udp_select_read().

2404 {
2405  const struct GNUNET_MessageHeader *ack;
2406  const struct UDP_ACK_Message *udp_ack;
2407  struct GNUNET_HELLO_Address *address;
2408  struct GNUNET_ATS_Session *s;
2409  struct GNUNET_TIME_Relative flow_delay;
2410 
2411  /* check message format */
2412  if (ntohs (msg->size)
2413  < sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader))
2414  {
2415  GNUNET_break_op (0);
2416  return;
2417  }
2418  udp_ack = (const struct UDP_ACK_Message *) msg;
2419  ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
2420  if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message))
2421  {
2422  GNUNET_break_op(0);
2423  return;
2424  }
2425 
2426  /* Locate session */
2427  address = GNUNET_HELLO_address_allocate (&udp_ack->sender,
2428  PLUGIN_NAME,
2429  udp_addr,
2430  udp_addr_len,
2432  s = udp_plugin_lookup_session (plugin,
2433  address);
2434  if (NULL == s)
2435  {
2437  "UDP session of address %s for ACK not found\n",
2438  udp_address_to_string (plugin,
2439  address->address,
2440  address->address_length));
2441  GNUNET_HELLO_address_free (address);
2442  return;
2443  }
2444  if (NULL == s->frag_ctx)
2445  {
2447  "Fragmentation context of address %s for ACK (%s) not found\n",
2448  udp_address_to_string (plugin,
2449  address->address,
2450  address->address_length),
2452  GNUNET_HELLO_address_free (address);
2453  return;
2454  }
2455  GNUNET_HELLO_address_free (address);
2456 
2457  /* evaluate flow delay: how long should we wait between messages? */
2458  if (UINT32_MAX == ntohl (udp_ack->delay))
2459  {
2460  /* Other peer asked for us to terminate the session */
2462  "Asked to disconnect UDP session of %s\n",
2463  GNUNET_i2s (&udp_ack->sender));
2464  udp_disconnect_session (plugin,
2465  s);
2466  return;
2467  }
2468  flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay);
2469  if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2471  "We received a sending delay of %s for %s\n",
2473  GNUNET_YES),
2474  GNUNET_i2s (&udp_ack->sender));
2475  else
2477  "We received a sending delay of %s for %s\n",
2479  GNUNET_YES),
2480  GNUNET_i2s (&udp_ack->sender));
2481  /* Flow delay is for the reassembled packet, however, our delay
2482  is per packet, so we need to adjust: */
2483  s->flow_delay_from_other_peer = flow_delay;
2484 
2485  /* Handle ACK */
2486  if (GNUNET_OK !=
2488  ack))
2489  {
2491  "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
2492  (unsigned int) ntohs (msg->size),
2493  GNUNET_i2s (&udp_ack->sender),
2494  udp_address_to_string (plugin,
2495  udp_addr,
2496  udp_addr_len));
2497  /* Expect more ACKs to arrive */
2498  return;
2499  }
2500 
2501  /* Remove fragmented message after successful sending */
2503  "Message from %s at %s full ACK'ed\n",
2504  GNUNET_i2s (&udp_ack->sender),
2505  udp_address_to_string (plugin,
2506  udp_addr,
2507  udp_addr_len));
2509  GNUNET_OK);
2510 }
size_t address_length
Number of bytes in address.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
const void * address
Binary representation of the address (plugin-specific).
static struct GNUNET_ATS_Session * udp_plugin_lookup_session(void *cls, const struct GNUNET_HELLO_Address *address)
Locate an existing session the transport service is using to send data to another peer...
#define GNUNET_CONSTANTS_LATENCY_WARN
After what amount of latency for a message do we print a warning?
static void fragmented_message_done(struct UDP_FragmentationContext *frag_ctx, int result)
We have completed our (attempt) to transmit a message that had to be fragmented – either because we ...
#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...
const char * GNUNET_FRAGMENT_print_ack(const struct GNUNET_MessageHeader *ack)
Convert an ACK message to a printable format suitable for logging.
struct GNUNET_TIME_Relative flow_delay_from_other_peer
Desired delay for transmissions we received from other peer.
Information about ongoing sessions of the transport client.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
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
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
static int udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s)
Functions with this signature are called whenever we need to close a session due to a disconnect or f...
int GNUNET_FRAGMENT_process_ack(struct GNUNET_FRAGMENT_Context *fc, const struct GNUNET_MessageHeader *msg)
Process an acknowledgement message we got from the other side (to control re-transmits).
uint32_t delay
Desired delay for flow control, in us (in NBO).
No additional information.
#define PLUGIN_NAME
An address for communicating with a peer.
const char * udp_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
UDP ACK Message-Packet header.
struct UDP_FragmentationContext * frag_ctx
Context for dealing with fragments.
static char * address
GNS address for this phone.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define LOG(kind,...)
struct GNUNET_FRAGMENT_Context * frag
Handle for fragmentation.
#define GNUNET_HELLO_address_free(addr)
Free an address.
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:

◆ process_inbound_tokenized_messages()

static int process_inbound_tokenized_messages ( void *  cls,
const struct GNUNET_MessageHeader hdr 
)
static

Message tokenizer has broken up an incomming message.

Pass it on to the service.

Parameters
clsthe struct GNUNET_ATS_Session *
hdrthe actual message
Returns
GNUNET_OK (always)

Definition at line 2522 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::address, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_ATS_Session::flow_delay_for_other_peer, GNUNET_OK, GNUNET_YES, GNUNET_ATS_Session::in_destroy, plugin, GNUNET_ATS_Session::plugin, and reschedule_session_timeout().

Referenced by udp_plugin_create_session().

2524 {
2525  struct GNUNET_ATS_Session *session = cls;
2526  struct Plugin *plugin = session->plugin;
2527 
2528  if (GNUNET_YES == session->in_destroy)
2529  return GNUNET_OK;
2530  reschedule_session_timeout (session);
2531  session->flow_delay_for_other_peer
2532  = plugin->env->receive (plugin->env->cls,
2533  session->address,
2534  session,
2535  hdr);
2536  return GNUNET_OK;
2537 }
struct GNUNET_TIME_Relative flow_delay_for_other_peer
Desired delay for next sending we send to other peer.
struct Plugin * plugin
Pointer to the global plugin struct.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
struct GNUNET_HELLO_Address * address
Address.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
int in_destroy
Is this session about to be destroyed (sometimes we cannot destroy a session immediately as below us ...
Handle for a plugin.
Definition: block.c:37
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:80
static void reschedule_session_timeout(struct GNUNET_ATS_Session *s)
Increment session timeout due to activity.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ disconnect_and_free_it()

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

Destroy a session, plugin is being unloaded.

Parameters
clsthe struct Plugin
keyhash of public key of target peer
valuea struct PeerSession * to clean up
Returns
GNUNET_OK (continue to iterate)

Definition at line 2549 of file plugin_transport_udp.c.

References GNUNET_OK, plugin, and udp_disconnect_session().

Referenced by libgnunet_plugin_transport_udp_done(), and udp_disconnect().

2552 {
2553  struct Plugin *plugin = cls;
2554 
2555  udp_disconnect_session (plugin,
2556  value);
2557  return GNUNET_OK;
2558 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static char * value
Value of the record to add/remove.
static int udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s)
Functions with this signature are called whenever we need to close a session due to a disconnect or f...
Handle for a plugin.
Definition: block.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_disconnect()

static void udp_disconnect ( void *  cls,
const struct GNUNET_PeerIdentity target 
)
static

Disconnect from a remote node.

Clean up session if we have one for this peer.

Parameters
clsclosure for this call (should be handle to Plugin)
targetthe peeridentity of the peer to disconnect
Returns
GNUNET_OK on success, GNUNET_SYSERR if the operation failed

Definition at line 2570 of file plugin_transport_udp.c.

References disconnect_and_free_it(), GNUNET_CONTAINER_multipeermap_get_multiple(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_i2s(), LOG, plugin, and Plugin::sessions.

Referenced by libgnunet_plugin_transport_udp_init().

2572 {
2573  struct Plugin *plugin = cls;
2574 
2576  "Disconnecting from peer `%s'\n",
2577  GNUNET_i2s (target));
2579  target,
2581  plugin);
2582 }
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
static int disconnect_and_free_it(void *cls, const struct GNUNET_PeerIdentity *key, void *value)
Destroy a session, plugin is being unloaded.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define LOG(kind,...)
int GNUNET_CONTAINER_multipeermap_get_multiple(struct GNUNET_CONTAINER_MultiPeerMap *map, const struct GNUNET_PeerIdentity *key, GNUNET_CONTAINER_PeerMapIterator it, void *it_cls)
Iterate over all entries in the map that match a particular key.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ session_timeout()

static void session_timeout ( void *  cls)
static

Session was idle, so disconnect it.

Parameters
clsthe struct GNUNET_ATS_Session to time out

Definition at line 2591 of file plugin_transport_udp.c.

References GNUNET_ERROR_TYPE_DEBUG, GNUNET_SCHEDULER_add_delayed(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get_remaining(), GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, LOG, notify_session_monitor(), plugin, GNUNET_ATS_Session::plugin, GNUNET_TIME_Relative::rel_value_us, GNUNET_ATS_Session::timeout, GNUNET_ATS_Session::timeout_task, udp_disconnect_session(), and UDP_SESSION_TIME_OUT.

Referenced by udp_plugin_create_session().

2592 {
2593  struct GNUNET_ATS_Session *s = cls;
2594  struct Plugin *plugin = s->plugin;
2595  struct GNUNET_TIME_Relative left;
2596 
2597  s->timeout_task = NULL;
2599  if (left.rel_value_us > 0)
2600  {
2601  /* not actually our turn yet, but let's at least update
2602  the monitor, it may think we're about to die ... */
2604  s,
2607  &session_timeout,
2608  s);
2609  return;
2610  }
2612  "Session %p was idle for %s, disconnecting\n",
2613  s,
2615  GNUNET_YES));
2616  /* call session destroy function */
2617  udp_disconnect_session (plugin,
2618  s);
2619 }
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define UDP_SESSION_TIME_OUT
After how much inactivity should a UDP session time out?
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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
Information about ongoing sessions of the transport client.
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 GNUNET_NETWORK_STRUCT_END void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
static int udp_disconnect_session(void *cls, struct GNUNET_ATS_Session *s)
Functions with this signature are called whenever we need to close a session due to a disconnect or f...
This is just an update about the session, the state did not change.
static void session_timeout(void *cls)
Session was idle, so disconnect it.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_TIME_Relative GNUNET_TIME_absolute_get_remaining(struct GNUNET_TIME_Absolute future)
Given a timestamp in the future, how much time remains until then?
Definition: time.c:331
#define GNUNET_YES
Definition: gnunet_common.h:80
#define LOG(kind,...)
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:

◆ udp_plugin_create_session()

static struct GNUNET_ATS_Session* udp_plugin_create_session ( void *  cls,
const struct GNUNET_HELLO_Address address,
enum GNUNET_NetworkType  network_type 
)
static

Allocate a new session for the given endpoint address.

Note that this function does not inform the service of the new session, this is the responsibility of the caller (if needed).

Parameters
clsthe struct Plugin
addressaddress of the other peer to use
network_typenetwork type the address belongs to
Returns
NULL on error, otherwise session handle

Definition at line 2634 of file plugin_transport_udp.c.

References GNUNET_HELLO_Address::address, GNUNET_ATS_Session::address, GNUNET_HELLO_Address::address_length, Plugin::env, GNUNET_ATS_Session::flow_delay_for_other_peer, GNUNET_ATS_Session::flow_delay_from_other_peer, GNUNET_assert, GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_CONTAINER_multipeermap_put(), GNUNET_CONTAINER_multipeermap_size(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELLO_address_copy(), GNUNET_i2s(), GNUNET_MST_create(), GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SCHEDULER_add_delayed(), GNUNET_STATISTICS_set(), GNUNET_TIME_absolute_get(), GNUNET_TIME_relative_multiply(), GNUNET_TIME_relative_to_absolute(), GNUNET_TIME_UNIT_MILLISECONDS, GNUNET_TIME_UNIT_ZERO, GNUNET_TRANSPORT_SS_INIT, GNUNET_ATS_Session::last_expected_ack_delay, GNUNET_ATS_Session::last_expected_msg_delay, GNUNET_ATS_Session::last_transmit_time, LOG, GNUNET_ATS_Session::mst, notify_session_monitor(), GNUNET_HELLO_Address::peer, plugin, GNUNET_ATS_Session::plugin, process_inbound_tokenized_messages(), GNUNET_ATS_Session::scope, session_timeout(), Plugin::sessions, GNUNET_ATS_Session::target, GNUNET_ATS_Session::timeout, GNUNET_ATS_Session::timeout_task, udp_address_to_string(), and UDP_SESSION_TIME_OUT.

Referenced by process_udp_message(), and udp_plugin_get_session().

2637 {
2638  struct Plugin *plugin = cls;
2639  struct GNUNET_ATS_Session *s;
2640 
2641  s = GNUNET_new (struct GNUNET_ATS_Session);
2643  s);
2644  s->plugin = plugin;
2645  s->address = GNUNET_HELLO_address_copy (address);
2646  s->target = address->peer;
2649  250);
2655  &session_timeout,
2656  s);
2657  s->scope = network_type;
2658 
2660  "Creating new session %p for peer `%s' address `%s'\n",
2661  s,
2662  GNUNET_i2s (&address->peer),
2663  udp_address_to_string (plugin,
2664  address->address,
2665  address->address_length));
2668  &s->target,
2669  s,
2671  GNUNET_STATISTICS_set (plugin->env->stats,
2672  "# UDP sessions active",
2674  GNUNET_NO);
2675  notify_session_monitor (plugin,
2676  s,
2678  return s;
2679 }
size_t address_length
Number of bytes in address.
struct GNUNET_TIME_Absolute last_transmit_time
What time did we last transmit?
const void * address
Binary representation of the address (plugin-specific).
struct GNUNET_SCHEDULER_Task * timeout_task
Session timeout task.
struct GNUNET_TIME_Relative flow_delay_for_other_peer
Desired delay for next sending we send to other peer.
struct Plugin * plugin
Pointer to the global plugin struct.
struct GNUNET_TIME_Absolute GNUNET_TIME_relative_to_absolute(struct GNUNET_TIME_Relative rel)
Convert relative time to an absolute time in the future.
Definition: time.c:245
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
struct GNUNET_TIME_Absolute timeout
When does this session time out.
#define GNUNET_NO
Definition: gnunet_common.h:81
#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.
struct GNUNET_HELLO_Address * address
Address.
static int process_inbound_tokenized_messages(void *cls, const struct GNUNET_MessageHeader *hdr)
Message tokenizer has broken up an incomming message.
struct GNUNET_TIME_Relative last_expected_ack_delay
expected delay for ACKs
#define UDP_SESSION_TIME_OUT
After how much inactivity should a UDP session time out?
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
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_TIME_Relative flow_delay_from_other_peer
Desired delay for transmissions we received from other peer.
Information about ongoing sessions of the transport client.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
struct GNUNET_MessageStreamTokenizer * GNUNET_MST_create(GNUNET_MessageTokenizerCallback cb, void *cb_cls)
Create a message stream tokenizer.
Definition: mst.c:87
struct GNUNET_TIME_Relative GNUNET_TIME_relative_multiply(struct GNUNET_TIME_Relative rel, unsigned long long factor)
Multiply relative time by a given factor.
Definition: time.c:439
static GNUNET_NETWORK_STRUCT_END void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
void GNUNET_STATISTICS_set(struct GNUNET_STATISTICS_Handle *handle, const char *name, uint64_t value, int make_persistent)
Set statistic value for the peer.
#define GNUNET_TIME_UNIT_MILLISECONDS
One millisecond.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(void)
Get the current time.
Definition: time.c:118
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer for inbound messages.
enum GNUNET_NetworkType scope
ATS network type.
struct GNUNET_PeerIdentity peer
For which peer is this an address?
#define GNUNET_TIME_UNIT_ZERO
Relative time zero.
Allow multiple values with the same key.
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 void session_timeout(void *cls)
Session was idle, so disconnect it.
Handle for a plugin.
Definition: block.c:37
struct GNUNET_PeerIdentity target
To whom are we talking to.
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_copy(const struct GNUNET_HELLO_Address *address)
Copy an address struct.
Definition: address.c:109
const char * udp_address_to_string(void *cls, const void *addr, size_t addrlen)
Function called for a quick conversion of the binary address to a numeric address.
The session was created (first call for each session object).
struct GNUNET_ATS_Session * sessions
List of open sessions (or peer map, or...)
struct GNUNET_TIME_Relative last_expected_msg_delay
desired delay between UDP messages
unsigned int GNUNET_CONTAINER_multipeermap_size(const struct GNUNET_CONTAINER_MultiPeerMap *map)
Get the number of key-value pairs in the map.
const char * GNUNET_i2s(const struct GNUNET_PeerIdentity *pid)
Convert a peer identity to a string (for printing debug messages).
#define LOG(kind,...)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ udp_plugin_get_session()

static struct GNUNET_ATS_Session* udp_plugin_get_session ( void *  cls,
const struct GNUNET_HELLO_Address address 
)
static

Creates a new outbound session the transport service will use to send data to the peer.

Parameters
clsthe struct Plugin *
addressthe address
Returns
the session or NULL of max connections exceeded

Definition at line 2691 of file plugin_transport_udp.c.

References GNUNET_HELLO_Address::address, GNUNET_HELLO_Address::address_length, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, GNUNET_break, GNUNET_break_op, GNUNET_NT_UNSPECIFIED, plugin, udp_plugin_create_session(), and udp_plugin_lookup_session().

Referenced by libgnunet_plugin_transport_udp_init().

2693 {
2694  struct Plugin *plugin = cls;
2695  struct GNUNET_ATS_Session *s;
2696  enum GNUNET_NetworkType network_type = GNUNET_NT_UNSPECIFIED;
2697  const struct IPv4UdpAddress *udp_v4;
2698  const struct IPv6UdpAddress *udp_v6;
2699 
2700  if (NULL == address)
2701  {
2702  GNUNET_break (0);
2703  return NULL;
2704  }
2705  if ( (address->address_length != sizeof(struct IPv4UdpAddress)) &&
2706  (address->address_length != sizeof(struct IPv6UdpAddress)) )
2707  {
2708  GNUNET_break_op (0);
2709  return NULL;
2710  }
2711  if (NULL != (s = udp_plugin_lookup_session (cls,
2712  address)))
2713  return s;
2714 
2715  /* need to create new session */
2716  if (sizeof (struct IPv4UdpAddress) == address->address_length)
2717  {
2718  struct sockaddr_in v4;
2719 
2720  udp_v4 = (const struct IPv4UdpAddress *) address->address;
2721  memset (&v4, '\0', sizeof (v4));
2722  v4.sin_family = AF_INET;
2723 #if HAVE_SOCKADDR_IN_SIN_LEN
2724  v4.sin_len = sizeof (struct sockaddr_in);
2725 #endif
2726  v4.sin_port = udp_v4->u4_port;
2727  v4.sin_addr.s_addr = udp_v4->ipv4_addr;
2728  network_type = plugin->env->get_address_type (plugin->env->cls,
2729  (const struct sockaddr *) &v4,
2730  sizeof (v4));
2731  }
2732  if (sizeof (struct IPv6UdpAddress) == address->address_length)
2733  {
2734  struct sockaddr_in6 v6;
2735 
2736  udp_v6 = (const struct IPv6UdpAddress *) address->address;
2737  memset (&v6, '\0', sizeof (v6));
2738  v6.sin6_family = AF_INET6;
2739 #if HAVE_SOCKADDR_IN_SIN_LEN
2740  v6.sin6_len = sizeof (struct sockaddr_in6);
2741 #endif
2742  v6.sin6_port = udp_v6->u6_port;
2743  v6.sin6_addr = udp_v6->ipv6_addr;
2744  network_type = plugin->env->get_address_type (plugin->env->cls,
2745  (const struct sockaddr *) &v6,
2746  sizeof (v6));
2747  }
2748  GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2749  return udp_plugin_create_session (cls,
2750  address,
2751  network_type);
2752 }
size_t address_length
Number of bytes in address.
const void * address
Binary representation of the address (plugin-specific).
static struct GNUNET_ATS_Session * udp_plugin_lookup_session(void *cls, const struct GNUNET_HELLO_Address *address)
Locate an existing session the transport service is using to send data to another peer...
GNUNET_NetworkType
Types of networks (with separate quotas) we support.
Definition: gnunet_nt_lib.h:35
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
Network format for IPv4 addresses.
Information about ongoing sessions of the transport client.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
Network format for IPv6 addresses.
static struct GNUNET_ATS_Session * udp_plugin_create_session(void *cls, const struct GNUNET_HELLO_Address *address, enum GNUNET_NetworkType network_type)
Allocate a new session for the given endpoint address.
Handle for a plugin.
Definition: block.c:37
void * cls
Closure to use for callbacks.
Category of last resort.
Definition: gnunet_nt_lib.h:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ process_udp_message()

static void process_udp_message ( struct Plugin plugin,
const struct UDPMessage msg,
const union UdpAddress udp_addr,
size_t  udp_addr_len,
enum GNUNET_NetworkType  network_type 
)
static

We've received a UDP Message.

Process it (pass contents to main service).

Parameters
pluginplugin context
msgthe message
udp_addrsender address
udp_addr_lennumber of bytes in udp_addr
network_typenetwork type the address belongs to

Definition at line 2765 of file plugin_transport_udp.c.

References address, GNUNET_DATACACHE_PluginEnvironment::cls, Plugin::env, free_session(), GNUNET_break, GNUNET_break_op, GNUNET_free, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_MST_from_buffer(), GNUNET_NO, GNUNET_NT_UNSPECIFIED, GNUNET_TRANSPORT_SS_UP, GNUNET_YES, UDPMessage::header, GNUNET_ATS_Session::in_destroy, GNUNET_ATS_Session::mst, notify_session_monitor(), PLUGIN_NAME, GNUNET_ATS_Session::rc, UDPMessage::reserved, GNUNET_ATS_Session::scope, UDPMessage::sender, GNUNET_MessageHeader::size, udp_plugin_create_session(), and udp_plugin_lookup_session().

Referenced by fragment_msg_proc(), and udp_select_read().

2770 {
2771  struct GNUNET_ATS_Session *s;
2772  struct GNUNET_HELLO_Address *address;
2773 
2774  GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2775  if (0 != ntohl (msg->reserved))
2776  {
2777  GNUNET_break_op(0);
2778  return;
2779  }
2780  if (ntohs (msg->header.size)
2781  < sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage))
2782  {
2783  GNUNET_break_op(0);
2784  return;
2785  }
2786 
2787  address = GNUNET_HELLO_address_allocate (&msg->sender,
2788  PLUGIN_NAME,
2789  udp_addr,
2790  udp_addr_len,
2792  if (NULL ==
2793  (s = udp_plugin_lookup_session (plugin,
2794  address)))
2795  {
2796  s = udp_plugin_create_session (plugin,
2797  address,
2798  network_type);
2799  plugin->env->session_start (plugin->env->cls,
2800  address,
2801  s,
2802  s->scope);
2803  notify_session_monitor (plugin,
2804  s,
2806  }
2807  GNUNET_free (address);
2808 
2809  s->rc++;
2811  (const char *) &msg[1],
2812  ntohs (msg->header.size) - sizeof(struct UDPMessage),
2813  GNUNET_YES,
2814  GNUNET_NO);
2815  s->rc--;
2816  if ( (0 == s->rc) &&
2817  (GNUNET_YES == s->in_destroy) )
2818  free_session (s);
2819 }
unsigned int rc
Reference counter to indicate that this session is currently being used and must not be destroyed; se...
struct GNUNET_HELLO_Address * GNUNET_HELLO_address_allocate(const struct GNUNET_PeerIdentity *peer, const char *transport_name, const void *address, size_t address_length, enum GNUNET_HELLO_AddressInfo local_info)
Allocate an address struct.
Definition: address.c:73
static void free_session(struct GNUNET_ATS_Session *s)
Function to free last resources associated with a session.
static struct GNUNET_ATS_Session * udp_plugin_lookup_session(void *cls, const struct GNUNET_HELLO_Address *address)
Locate an existing session the transport service is using to send data to another peer...
struct GNUNET_MessageHeader header
Message header.
UDP Message-Packet header (after defragmentation).
uint32_t reserved
Always zero for now.
#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...
Information about ongoing sessions of the transport client.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
int GNUNET_MST_from_buffer(struct GNUNET_MessageStreamTokenizer *mst, const char *buf, size_t size, int purge, int one_shot)
Add incoming data to the receive buffer and call the callback for all complete messages.
Definition: mst.c:116
int in_destroy
Is this session about to be destroyed (sometimes we cannot destroy a session immediately as below us ...
static GNUNET_NETWORK_STRUCT_END void notify_session_monitor(struct Plugin *plugin, struct GNUNET_ATS_Session *session, enum GNUNET_TRANSPORT_SessionState state)
If a session monitor is attached, notify it about the new session state.
struct GNUNET_MessageStreamTokenizer * mst
Tokenizer for inbound messages.
enum GNUNET_NetworkType scope
ATS network type.
static struct GNUNET_ATS_Session * udp_plugin_create_session(void *cls, const struct GNUNET_HELLO_Address *address, enum GNUNET_NetworkType network_type)
Allocate a new session for the given endpoint address.
No additional information.
#define PLUGIN_NAME
An address for communicating with a peer.
void * cls
Closure to use for callbacks.
Header for all communications.
#define GNUNET_YES
Definition: gnunet_common.h:80
static char * address
GNS address for this phone.
#define GNUNET_free(ptr)
Wrapper around free.
Category of last resort.
Definition: gnunet_nt_lib.h:40
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ fragment_msg_proc()

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

Process a defragmented message.

Parameters
clsthe struct DefragContext *
msgthe message

Definition at line 2829 of file plugin_transport_udp.c.

References dc, GNUNET_break_op, GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE, GNUNET_YES, DefragContext::have_sender, DefragContext::network_type, DefragContext::plugin, process_udp_message(), UDPMessage::sender, DefragContext::sender, GNUNET_MessageHeader::size, GNUNET_MessageHeader::type, DefragContext::udp_addr, and DefragContext::udp_addr_len.

Referenced by read_process_fragment().

2831 {
2832  struct DefragContext *dc = cls;
2833  const struct UDPMessage *um;
2834 
2835  if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
2836  {
2837  GNUNET_break_op (0);
2838  return;
2839  }
2840  if (ntohs (msg->size) < sizeof(struct UDPMessage))
2841  {
2842  GNUNET_break_op (0);
2843  return;
2844  }
2845  um = (const struct UDPMessage *) msg;
2846  dc->sender = um->sender;
2847  dc->have_sender = GNUNET_YES;
2849  um,
2850  dc->udp_addr,
2851  dc->udp_addr_len,
2852  dc->network_type);
2853 }
UDP Message-Packet header (after defragmentation).
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
const union UdpAddress * udp_addr
Source address this receive context is for (allocated at the end of the struct).
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
enum GNUNET_NetworkType network_type
Network type the address belongs to.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
#define GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE
Normal UDP message type.
int have_sender
Has the sender field been initialized yet?
size_t udp_addr_len
Length of udp_addr.
Data structure to track defragmentation contexts based on the source of the UDP traffic.
static void process_udp_message(struct Plugin *plugin, const struct UDPMessage *msg, const union UdpAddress *udp_addr, size_t udp_addr_len, enum GNUNET_NetworkType network_type)
We&#39;ve received a UDP Message.
#define GNUNET_YES
Definition: gnunet_common.h:80
struct Plugin * plugin
Reference to master plugin struct.
static struct GNUNET_FS_DownloadContext * dc
struct GNUNET_PeerIdentity sender
Who&#39;s message(s) are we defragmenting here? Only initialized once we succeeded and have_sender is set...
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ack_message_sent()

static void ack_message_sent ( void *  cls,
struct UDP_MessageWrapper udpw,
int  result 
)
static

We finished sending an acknowledgement.

Update statistics.

Parameters
clsthe struct Plugin
udpwmessage queue entry of the ACK
resultGNUNET_OK if the transmission worked, GNUNET_SYSERR if we failed to send the ACK

Definition at line 2866 of file plugin_transport_udp.c.

References Plugin::env, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), and plugin.

Referenced by ack_proc().

2869 {
2870  struct Plugin *plugin = cls;
2871 
2872  if (GNUNET_OK == result)
2873  {
2874  GNUNET_STATISTICS_update (plugin->env->stats,
2875  "# UDP, ACK messages sent",
2876  1,
2877  GNUNET_NO);
2878  }
2879  else
2880  {
2881  GNUNET_STATISTICS_update (plugin->env->stats,
2882  "# UDP, ACK transmissions failed",
2883  1,
2884  GNUNET_NO);
2885  }
2886 }
#define GNUNET_NO
Definition: gnunet_common.h:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:78
void GNUNET_STATISTICS_update(struct GNUNET_STATISTICS_Handle *handle, const char *name, int64_t delta, int make_persistent)
Set statistic value for the peer.
static struct GNUNET_ATS_SolverFunctions * plugin
Our solver.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static int result
Global testing status.
Handle for a plugin.
Definition: block.c:37
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ack_proc()

static void ack_proc ( void *  cls,
uint32_t  id,
const struct GNUNET_MessageHeader msg 
)
static

Transmit an acknowledgement.

Parameters
clsthe struct DefragContext *
idmessage ID (unused)
msgack to transmit

Definition at line 2897 of file plugin_transport_udp.c.

References ack_message_sent(), GNUNET_ATS_Session::address, address, GNUNET_HELLO_Address::address_length, DefragContext::defrag, delay, UDP_ACK_Message::delay, enqueue(), Plugin::env, GNUNET_ATS_Session::flow_delay_for_other_peer, GNUNET_CONTAINER_heap_remove_node(), GNUNET_DEFRAGMENT_context_destroy(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_free, GNUNET_HELLO_address_allocate(), GNUNET_HELLO_address_free, GNUNET_HELLO_ADDRESS_INFO_NONE, GNUNET_malloc, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_ACK, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_STRINGS_relative_time_to_string(), GNUNET_TIME_absolute_get(), GNUNET_TIME_UNIT_FOREVER_ABS, GNUNET_TIME_UNIT_FOREVER_REL, GNUNET_TRANSPORT_SS_UPDATE, GNUNET_YES, DefragContext::have_sender, UDP_ACK_Message::header, DefragContext::hnode, LOG, UDP_MessageWrapper::msg_buf, UDP_MessageWrapper::msg_size, notify_session_monitor(), UDP_MessageWrapper::payload_size, plugin, DefragContext::plugin, PLUGIN_NAME, UDP_MessageWrapper::qc, UDP_MessageWrapper::qc_cls, GNUNET_TIME_Relative::rel_value_us, schedule_select_v4(), schedule_select_v6(), DefragContext::sender, UDP_ACK_Message::sender, UDP_MessageWrapper::session, GNUNET_MessageHeader::size, UDP_MessageWrapper::start_time, UDP_MessageWrapper::timeout, GNUNET_MessageHeader::type, DefragContext::udp_addr, DefragContext::udp_addr_len, udp_address_to_string(), and udp_plugin_lookup_session().

Referenced by read_process_fragment().

2900 {
2901  struct DefragContext *rc = cls;
2902  struct Plugin *plugin = rc->plugin;
2903  size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size);
2904  struct UDP_ACK_Message *udp_ack;
2905  uint32_t delay;
2906  struct UDP_MessageWrapper *udpw;
2907  struct GNUNET_ATS_Session *s;
2908  struct GNUNET_HELLO_Address *address;
2909 
2910  if (GNUNET_NO == rc->have_sender)
2911  {
2912  /* tried to defragment but never succeeded, hence will not ACK */
2913  /* This can happen if we just lost msgs */
2914  GNUNET_STATISTICS_update (plugin->env->stats,
2915  "# UDP, fragments discarded without ACK",
2916  1,
2917  GNUNET_NO);
2918  return;
2919  }
2920  address = GNUNET_HELLO_address_allocate (&rc->sender,
2921  PLUGIN_NAME,
2922  rc->udp_addr,
2923  rc->udp_addr_len,
2925  s = udp_plugin_lookup_session (plugin,
2926  address);
2927  GNUNET_HELLO_address_free (address);
2928  if (NULL == s)
2929  {
2931  "Trying to transmit ACK to peer `%s' but no session found!\n",
2932  udp_address_to_string (plugin,
2933  rc->udp_addr,
2934  rc->udp_addr_len));
2937  GNUNET_free (rc);
2938  GNUNET_STATISTICS_update (plugin->env->stats,
2939  "# UDP, ACK transmissions failed",
2940  1,
2941  GNUNET_NO);
2942  return;
2943  }
2944  if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us ==
2946  delay = UINT32_MAX;
2947  else if (s->flow_delay_for_other_peer.rel_value_us < UINT32_MAX)
2949  else
2950  delay = UINT32_MAX - 1; /* largest value we can communicate */
2952  "Sending ACK to `%s' including delay of %s\n",
2953  udp_address_to_string (plugin,
2954  rc->udp_addr,
2955  rc->udp_addr_len),
2957  GNUNET_YES));
2958  udpw = GNUNET_malloc (sizeof (struct UDP_MessageWrapper) + msize);
2959  udpw->msg_size = msize;
2960  udpw->payload_size = 0;
2961  udpw->session = s;
2964  udpw->msg_buf = (char *) &udpw[1];
2965  udpw->qc = &ack_message_sent;
2966  udpw->qc_cls = plugin;
2967  udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf;
2968  udp_ack->header.size = htons ((uint16_t) msize);
2970  udp_ack->delay = htonl (delay);
2971  udp_ack->sender = *plugin->env->my_identity;
2972  GNUNET_memcpy (&udp_ack[1],
2973  msg,
2974  ntohs (msg->size));
2975  enqueue (plugin,
2976  udpw);
2977  notify_session_monitor (plugin,
2978  s,
2980  if (s->address->address_length == sizeof (struct IPv4UdpAddress))
2981  schedule_select_v4 (plugin);
2982  else
2983  schedule_select_v6 (plugin);
2984 }
size_t address_length
Number of bytes in address.
size_t payload_size
Payload size of original message.