GNUnet  0.11.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
 Session handle for connections. 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 59 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 68 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 387 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 515 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().

518 {
519  struct GNUNET_TRANSPORT_SessionInfo info;
520 
521  if (NULL == plugin->sic)
522  return;
523  if (GNUNET_YES == session->in_destroy)
524  return; /* already destroyed, just RC>0 left-over actions */
525  memset (&info, 0, sizeof(info));
526  info.state = state;
527  info.is_inbound = GNUNET_SYSERR; /* hard to say */
528  info.num_msg_pending = session->msgs_in_queue;
529  info.num_bytes_pending = session->bytes_in_queue;
530  /* info.receive_delay remains zero as this is not supported by UDP
531  (cannot selectively not receive from 'some' peer while continuing
532  to receive from others) */
533  info.session_timeout = session->timeout;
534  info.address = session->address;
535  plugin->sic (plugin->sic_cls, session, &info);
536 }
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:76
#define GNUNET_YES
Definition: gnunet_common.h:77
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 548 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().

551 {
552  struct Plugin *plugin = cls;
553  struct GNUNET_ATS_Session *session = value;
554 
557  return GNUNET_OK;
558 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
static char * value
Value of the record to add/remove.
Session handle for connections.
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 char * plugin
Solver plugin name as string.
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 574 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().

577 {
578  struct Plugin *plugin = cls;
579 
580  plugin->sic = sic;
581  plugin->sic_cls = sic_cls;
582  if (NULL != sic)
583  {
586  plugin);
587  /* signal end of first iteration */
588  sic (sic_cls, NULL, NULL);
589  }
590 }
GNUNET_TRANSPORT_SessionInfoCallback sic
Function to call about session status changes.
static char * plugin
Solver plugin name as string.
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 602 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().

603 {
604  if (NULL != s->address)
605  {
607  s->address = NULL;
608  }
609  if (NULL != s->frag_ctx)
610  {
612  GNUNET_free (s->frag_ctx);
613  s->frag_ctx = NULL;
614  }
615  if (NULL != s->mst)
616  {
617  GNUNET_MST_destroy (s->mst);
618  s->mst = NULL;
619  }
620  GNUNET_free (s);
621 }
struct GNUNET_HELLO_Address * address
Address.
void GNUNET_MST_destroy(struct GNUNET_MessageStreamTokenizer *mst)
Destroys a tokenizer.
Definition: mst.c:411
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 633 of file plugin_transport_udp.c.

Referenced by libgnunet_plugin_transport_udp_init().

634 {
635  return 15;
636 }
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 647 of file plugin_transport_udp.c.

References GNUNET_ATS_Session::scope.

Referenced by libgnunet_plugin_transport_udp_init().

648 {
649  return session->scope;
650 }
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 661 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().

663 {
664  struct Plugin *plugin = cls;
665  size_t addrlen;
666  struct sockaddr_in a4;
667  struct sockaddr_in6 a6;
668  const struct IPv4UdpAddress *u4;
669  const struct IPv6UdpAddress *u6;
670  const void *sb;
671  size_t sbs;
672 
673  addrlen = address->address_length;
674  if (addrlen == sizeof(struct IPv6UdpAddress))
675  {
676  GNUNET_assert (NULL != address->address); /* make static analysis happy */
677  u6 = address->address;
678  memset (&a6, 0, sizeof(a6));
679 #if HAVE_SOCKADDR_IN_SIN_LEN
680  a6.sin6_len = sizeof(a6);
681 #endif
682  a6.sin6_family = AF_INET6;
683  a6.sin6_port = u6->u6_port;
684  GNUNET_memcpy (&a6.sin6_addr, &u6->ipv6_addr, sizeof(struct in6_addr));
685  sb = &a6;
686  sbs = sizeof(a6);
687  }
688  else if (addrlen == sizeof(struct IPv4UdpAddress))
689  {
690  GNUNET_assert (NULL != address->address); /* make static analysis happy */
691  u4 = address->address;
692  memset (&a4, 0, sizeof(a4));
693 #if HAVE_SOCKADDR_IN_SIN_LEN
694  a4.sin_len = sizeof(a4);
695 #endif
696  a4.sin_family = AF_INET;
697  a4.sin_port = u4->u4_port;
698  a4.sin_addr.s_addr = u4->ipv4_addr;
699  sb = &a4;
700  sbs = sizeof(a4);
701  }
702  else
703  {
704  GNUNET_break (0);
705  return GNUNET_NT_UNSPECIFIED;
706  }
707  return plugin->env->get_address_type (plugin->env->cls, sb, sbs);
708 }
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.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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...
Network format for IPv4 addresses.
uint32_t ipv4_addr
IPv4 address, in network byte order.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static char * plugin
Solver plugin name as string.
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 3320 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 schedule_select_v4(), and udp_plugin_get_network_for_address().

3321 {
3322  struct Plugin *plugin = cls;
3323  const struct GNUNET_SCHEDULER_TaskContext *tc;
3324 
3325  plugin->select_task_v4 = NULL;
3326  if (NULL == plugin->sockv4)
3327  return;
3329  if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3330  (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv4)))
3331  udp_select_read (plugin, plugin->sockv4);
3332  udp_select_send (plugin, plugin->sockv4);
3333  schedule_select_v4 (plugin);
3334 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
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:418
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.
struct GNUNET_SCHEDULER_Task * select_task_v4
ID of select task for IPv4.
static char * plugin
Solver plugin name as string.
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:1029
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 3345 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 schedule_select_v6(), and udp_plugin_get_network_for_address().

3346 {
3347  struct Plugin *plugin = cls;
3348  const struct GNUNET_SCHEDULER_TaskContext *tc;
3349 
3350  plugin->select_task_v6 = NULL;
3351  if (NULL == plugin->sockv6)
3352  return;
3354  if ((0 != (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY)) &&
3355  (GNUNET_NETWORK_fdset_isset (tc->read_ready, plugin->sockv6)))
3356  udp_select_read (plugin, plugin->sockv6);
3357 
3358  udp_select_send (plugin, plugin->sockv6);
3359  schedule_select_v6 (plugin);
3360 }
const struct GNUNET_SCHEDULER_TaskContext * GNUNET_SCHEDULER_get_task_context(void)
Obtain the reasoning why the current task was started.
Definition: scheduler.c:747
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:418
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 char * plugin
Solver plugin name as string.
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:1029
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 741 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, UDP_MessageWrapper::transmission_time, and udp_plugin_select_v4().

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

742 {
743  struct GNUNET_TIME_Relative min_delay;
745  struct UDP_MessageWrapper *udpw;
746  struct UDP_MessageWrapper *min_udpw;
747 
748  if ((GNUNET_YES == plugin->enable_ipv4) && (NULL != plugin->sockv4))
749  {
750  /* Find a message ready to send:
751  * Flow delay from other peer is expired or not set (0) */
752  min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
753  min_udpw = NULL;
754  for (udpw = plugin->ipv4_queue_head; NULL != udpw; udpw = udpw->next)
755  {
757  if (delay.rel_value_us < min_delay.rel_value_us)
758  {
759  min_delay = delay;
760  min_udpw = udpw;
761  }
762  }
763  if (NULL != plugin->select_task_v4)
765  if (NULL != min_udpw)
766  {
767  if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
768  {
770  "Calculated flow delay for UDPv4 at %s for %s\n",
772  GNUNET_YES),
773  GNUNET_i2s (&min_udpw->session->target));
774  }
775  else
776  {
778  "Calculated flow delay for UDPv4 at %s for %s\n",
780  GNUNET_YES),
781  GNUNET_i2s (&min_udpw->session->target));
782  }
783  }
784  plugin->select_task_v4 =
786  plugin->sockv4,
788  plugin);
789  }
790 }
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:687
#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:77
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:1486
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:966
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 799 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, UDP_MessageWrapper::transmission_time, and udp_plugin_select_v6().

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

800 {
801  struct GNUNET_TIME_Relative min_delay;
803  struct UDP_MessageWrapper *udpw;
804  struct UDP_MessageWrapper *min_udpw;
805 
806  if ((GNUNET_YES == plugin->enable_ipv6) && (NULL != plugin->sockv6))
807  {
808  min_delay = GNUNET_TIME_UNIT_FOREVER_REL;
809  min_udpw = NULL;
810  for (udpw = plugin->ipv6_queue_head; NULL != udpw; udpw = udpw->next)
811  {
813  if (delay.rel_value_us < min_delay.rel_value_us)
814  {
815  min_delay = delay;
816  min_udpw = udpw;
817  }
818  }
819  if (NULL != plugin->select_task_v6)
821  if (NULL != min_udpw)
822  {
823  if (min_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
824  {
826  "Calculated flow delay for UDPv6 at %s for %s\n",
828  GNUNET_YES),
829  GNUNET_i2s (&min_udpw->session->target));
830  }
831  else
832  {
834  "Calculated flow delay for UDPv6 at %s for %s\n",
836  GNUNET_YES),
837  GNUNET_i2s (&min_udpw->session->target));
838  }
839  }
840  plugin->select_task_v6 =
842  plugin->sockv6,
844  plugin);
845  }
846 }
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:687
#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:77
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:1486
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:966
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 864 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().

865 {
866  static char rbuf[INET6_ADDRSTRLEN + 10];
867  char buf[INET6_ADDRSTRLEN];
868  const void *sb;
869  struct in_addr a4;
870  struct in6_addr a6;
871  const struct IPv4UdpAddress *t4;
872  const struct IPv6UdpAddress *t6;
873  int af;
874  uint16_t port;
875  uint32_t options;
876 
877  if (NULL == addr)
878  {
879  GNUNET_break_op (0);
880  return NULL;
881  }
882 
883  if (addrlen == sizeof(struct IPv6UdpAddress))
884  {
885  t6 = addr;
886  af = AF_INET6;
887  options = ntohl (t6->options);
888  port = ntohs (t6->u6_port);
889  a6 = t6->ipv6_addr;
890  sb = &a6;
891  }
892  else if (addrlen == sizeof(struct IPv4UdpAddress))
893  {
894  t4 = addr;
895  af = AF_INET;
896  options = ntohl (t4->options);
897  port = ntohs (t4->u4_port);
898  a4.s_addr = t4->ipv4_addr;
899  sb = &a4;
900  }
901  else
902  {
903  GNUNET_break_op (0);
904  return NULL;
905  }
906  inet_ntop (af, sb, buf, INET6_ADDRSTRLEN);
907  GNUNET_snprintf (rbuf,
908  sizeof(rbuf),
909  (af == AF_INET6) ? "%s.%u.[%s]:%u" : "%s.%u.%s:%u",
910  PLUGIN_NAME,
911  options,
912  buf,
913  port);
914  return rbuf;
915 }
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:81
#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 930 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().

935 {
936  struct sockaddr_storage socket_address;
937  char *address;
938  char *plugin;
939  char *optionstr;
940  uint32_t options;
941 
942  /* Format tcp.options.address:port */
943  address = NULL;
944  plugin = NULL;
945  optionstr = NULL;
946 
947  if ((NULL == addr) || (0 == addrlen))
948  {
949  GNUNET_break (0);
950  return GNUNET_SYSERR;
951  }
952  if ('\0' != addr[addrlen - 1])
953  {
954  GNUNET_break (0);
955  return GNUNET_SYSERR;
956  }
957  if (strlen (addr) != addrlen - 1)
958  {
959  GNUNET_break (0);
960  return GNUNET_SYSERR;
961  }
962  plugin = GNUNET_strdup (addr);
963  optionstr = strchr (plugin, '.');
964  if (NULL == optionstr)
965  {
966  GNUNET_break (0);
967  GNUNET_free (plugin);
968  return GNUNET_SYSERR;
969  }
970  optionstr[0] = '\0';
971  optionstr++;
972  options = atol (optionstr);
973  address = strchr (optionstr, '.');
974  if (NULL == address)
975  {
976  GNUNET_break (0);
977  GNUNET_free (plugin);
978  return GNUNET_SYSERR;
979  }
980  address[0] = '\0';
981  address++;
982 
983  if (GNUNET_OK !=
984  GNUNET_STRINGS_to_address_ip (address, strlen (address), &socket_address))
985  {
986  GNUNET_break (0);
987  GNUNET_free (plugin);
988  return GNUNET_SYSERR;
989  }
990  GNUNET_free (plugin);
991 
992  switch (socket_address.ss_family)
993  {
994  case AF_INET: {
995  struct IPv4UdpAddress *u4;
996  const struct sockaddr_in *in4 =
997  (const struct sockaddr_in *) &socket_address;
998 
999  u4 = GNUNET_new (struct IPv4UdpAddress);
1000  u4->options = htonl (options);
1001  u4->ipv4_addr = in4->sin_addr.s_addr;
1002  u4->u4_port = in4->sin_port;
1003  *buf = u4;
1004  *added = sizeof(struct IPv4UdpAddress);
1005  return GNUNET_OK;
1006  }
1007 
1008  case AF_INET6: {
1009  struct IPv6UdpAddress *u6;
1010  const struct sockaddr_in6 *in6 =
1011  (const struct sockaddr_in6 *) &socket_address;
1012 
1013  u6 = GNUNET_new (struct IPv6UdpAddress);
1014  u6->options = htonl (options);
1015  u6->ipv6_addr = in6->sin6_addr;
1016  u6->u6_port = in6->sin6_port;
1017  *buf = u6;
1018  *added = sizeof(struct IPv6UdpAddress);
1019  return GNUNET_OK;
1020  }
1021 
1022  default:
1023  GNUNET_break (0);
1024  return GNUNET_SYSERR;
1025  }
1026 }
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:75
#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...
Network format for IPv4 addresses.
uint32_t ipv4_addr
IPv4 address, in network byte order.
static char buf[2048]
static char * plugin
Solver plugin name as string.
uint32_t options
Optional options and flags for this address.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:1326
#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 1036 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().

1037 {
1038  struct PrettyPrinterContext *ppc = cls;
1039  struct Plugin *plugin = ppc->plugin;
1040  char *ret;
1041 
1042  if (NULL == hostname)
1043  {
1044  /* Final call, done */
1046  plugin->ppc_dll_tail,
1047  ppc);
1048  ppc->resolver_handle = NULL;
1049  ppc->asc (ppc->asc_cls, NULL, GNUNET_OK);
1050  GNUNET_free (ppc);
1051  return;
1052  }
1053  if (GNUNET_YES == ppc->ipv6)
1054  GNUNET_asprintf (&ret,
1055  "%s.%u.[%s]:%d",
1056  PLUGIN_NAME,
1057  ppc->options,
1058  hostname,
1059  ppc->port);
1060  else
1061  GNUNET_asprintf (&ret,
1062  "%s.%u.%s:%d",
1063  PLUGIN_NAME,
1064  ppc->options,
1065  hostname,
1066  ppc->port);
1067  ppc->asc (ppc->asc_cls, ret, GNUNET_OK);
1068  GNUNET_free (ret);
1069 }
#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.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
void * asc_cls
Clsoure for asc.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static char * plugin
Solver plugin name as string.
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:77
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 1087 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().

1095 {
1096  struct Plugin *plugin = cls;
1097  struct PrettyPrinterContext *ppc;
1098  const struct sockaddr *sb;
1099  size_t sbs;
1100  struct sockaddr_in a4;
1101  struct sockaddr_in6 a6;
1102  const struct IPv4UdpAddress *u4;
1103  const struct IPv6UdpAddress *u6;
1104  uint16_t port;
1105  uint32_t options;
1106 
1107  if (addrlen == sizeof(struct IPv6UdpAddress))
1108  {
1109  u6 = addr;
1110  memset (&a6, 0, sizeof(a6));
1111  a6.sin6_family = AF_INET6;
1112 #if HAVE_SOCKADDR_IN_SIN_LEN
1113  a6.sin6_len = sizeof(a6);
1114 #endif
1115  a6.sin6_port = u6->u6_port;
1116  a6.sin6_addr = u6->ipv6_addr;
1117  port = ntohs (u6->u6_port);
1118  options = ntohl (u6->options);
1119  sb = (const struct sockaddr *) &a6;
1120  sbs = sizeof(a6);
1121  }
1122  else if (addrlen == sizeof(struct IPv4UdpAddress))
1123  {
1124  u4 = addr;
1125  memset (&a4, 0, sizeof(a4));
1126  a4.sin_family = AF_INET;
1127 #if HAVE_SOCKADDR_IN_SIN_LEN
1128  a4.sin_len = sizeof(a4);
1129 #endif
1130  a4.sin_port = u4->u4_port;
1131  a4.sin_addr.s_addr = u4->ipv4_addr;
1132  port = ntohs (u4->u4_port);
1133  options = ntohl (u4->options);
1134  sb = (const struct sockaddr *) &a4;
1135  sbs = sizeof(a4);
1136  }
1137  else
1138  {
1139  /* invalid address */
1140  GNUNET_break_op (0);
1141  asc (asc_cls, NULL, GNUNET_SYSERR);
1142  asc (asc_cls, NULL, GNUNET_OK);
1143  return;
1144  }
1145  ppc = GNUNET_new (struct PrettyPrinterContext);
1146  ppc->plugin = plugin;
1147  ppc->asc = asc;
1148  ppc->asc_cls = asc_cls;
1149  ppc->port = port;
1150  ppc->options = options;
1151  if (addrlen == sizeof(struct IPv6UdpAddress))
1152  ppc->ipv6 = GNUNET_YES;
1153  else
1154  ppc->ipv6 = GNUNET_NO;
1155  GNUNET_CONTAINER_DLL_insert (plugin->ppc_dll_head, plugin->ppc_dll_tail, ppc);
1157  sbs,
1158  ! numeric,
1159  timeout,
1160  &append_port,
1161  ppc);
1162 }
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:78
static int numeric
Option -n.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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.
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 char * plugin
Solver plugin name as string.
uint32_t options
Optional options and flags for this address.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
static uint16_t port
Port number.
Definition: gnunet-bcd.c:81
Handle for a plugin.
Definition: block.c:37
uint32_t options
Address options.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 1175 of file plugin_transport_udp.c.

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

Referenced by udp_plugin_check_address().

1176 {
1177  if ((plugin->port == in_port) || (plugin->aport == in_port))
1178  return GNUNET_OK;
1179  return GNUNET_SYSERR;
1180 }
uint16_t aport
Port we advertise on.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 1199 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().

1200 {
1201  struct Plugin *plugin = cls;
1202  const struct IPv4UdpAddress *v4;
1203  const struct IPv6UdpAddress *v6;
1204 
1205  if (sizeof(struct IPv4UdpAddress) == addrlen)
1206  {
1207  struct sockaddr_in s4;
1208 
1209  v4 = (const struct IPv4UdpAddress *) addr;
1210  if (GNUNET_OK != check_port (plugin, ntohs (v4->u4_port)))
1211  return GNUNET_SYSERR;
1212  memset (&s4, 0, sizeof(s4));
1213  s4.sin_family = AF_INET;
1214 #if HAVE_SOCKADDR_IN_SIN_LEN
1215  s4.sin_len = sizeof(s4);
1216 #endif
1217  s4.sin_port = v4->u4_port;
1218  s4.sin_addr.s_addr = v4->ipv4_addr;
1219 
1220  if (GNUNET_OK !=
1221  GNUNET_NAT_test_address (plugin->nat, &s4, sizeof(struct sockaddr_in)))
1222  return GNUNET_SYSERR;
1223  }
1224  else if (sizeof(struct IPv6UdpAddress) == addrlen)
1225  {
1226  struct sockaddr_in6 s6;
1227 
1228  v6 = (const struct IPv6UdpAddress *) addr;
1229  if (IN6_IS_ADDR_LINKLOCAL (&v6->ipv6_addr))
1230  return GNUNET_OK; /* plausible, if unlikely... */
1231  memset (&s6, 0, sizeof(s6));
1232  s6.sin6_family = AF_INET6;
1233 #if HAVE_SOCKADDR_IN_SIN_LEN
1234  s6.sin6_len = sizeof(s6);
1235 #endif
1236  s6.sin6_port = v6->u6_port;
1237  s6.sin6_addr = v6->ipv6_addr;
1238 
1239  if (GNUNET_OK != GNUNET_NAT_test_address (plugin->nat,
1240  &s6,
1241  sizeof(struct sockaddr_in6)))
1242  return GNUNET_SYSERR;
1243  }
1244  else
1245  {
1246  GNUNET_break_op (0);
1247  return GNUNET_SYSERR;
1248  }
1249  return GNUNET_OK;
1250 }
struct GNUNET_NAT_Handle * nat
NAT handle & address management.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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:625
Network format for IPv4 addresses.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
static char * plugin
Solver plugin name as string.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 1266 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().

1272 {
1273  struct Plugin *plugin = cls;
1274  struct GNUNET_HELLO_Address *address;
1275  struct IPv4UdpAddress u4;
1276  struct IPv6UdpAddress u6;
1277  void *arg;
1278  size_t args;
1279 
1280  (void) app_ctx;
1282  (GNUNET_YES == add_remove) ? "NAT notification to add address `%s'\n"
1283  : "NAT notification to remove address `%s'\n",
1284  GNUNET_a2s (addr, addrlen));
1285  /* convert 'address' to our internal format */
1286  switch (addr->sa_family)
1287  {
1288  case AF_INET: {
1289  const struct sockaddr_in *i4;
1290 
1291  GNUNET_assert (sizeof(struct sockaddr_in) == addrlen);
1292  i4 = (const struct sockaddr_in *) addr;
1293  if (0 == ntohs (i4->sin_port))
1294  return; /* Port = 0 means unmapped, ignore these for UDP. */
1295  memset (&u4, 0, sizeof(u4));
1296  u4.options = htonl (plugin->myoptions);
1297  u4.ipv4_addr = i4->sin_addr.s_addr;
1298  u4.u4_port = i4->sin_port;
1299  arg = &u4;
1300  args = sizeof(struct IPv4UdpAddress);
1301  break;
1302  }
1303 
1304  case AF_INET6: {
1305  const struct sockaddr_in6 *i6;
1306 
1307  GNUNET_assert (sizeof(struct sockaddr_in6) == addrlen);
1308  i6 = (const struct sockaddr_in6 *) addr;
1309  if (0 == ntohs (i6->sin6_port))
1310  return; /* Port = 0 means unmapped, ignore these for UDP. */
1311  memset (&u6, 0, sizeof(u6));
1312  u6.options = htonl (plugin->myoptions);
1313  u6.ipv6_addr = i6->sin6_addr;
1314  u6.u6_port = i6->sin6_port;
1315  arg = &u6;
1316  args = sizeof(struct IPv6UdpAddress);
1317  break;
1318  }
1319 
1320  default:
1321  GNUNET_break (0);
1322  return;
1323  }
1324  /* modify our published address list */
1325  /* TODO: use 'ac' here in the future... */
1326  address = GNUNET_HELLO_address_allocate (plugin->env->my_identity,
1327  PLUGIN_NAME,
1328  arg,
1329  args,
1331  plugin->env->notify_address (plugin->env->cls, add_remove, address);
1332  GNUNET_HELLO_address_free (address);
1333 }
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...
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)...
static char * plugin
Solver plugin name as string.
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:77
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 1365 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().

1366 {
1367  struct GNUNET_ATS_SessionCompareContext *cctx = cls;
1368  struct GNUNET_ATS_Session *s = value;
1369 
1370  if (0 == GNUNET_HELLO_address_cmp (s->address, cctx->address))
1371  {
1373  cctx->res = s;
1374  return GNUNET_NO;
1375  }
1376  return GNUNET_OK;
1377 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
Session handle for connections.
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 1390 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().

1392 {
1393  struct Plugin *plugin = cls;
1394  const struct IPv6UdpAddress *udp_a6;
1395  const struct IPv4UdpAddress *udp_a4;
1397 
1398  if (NULL == address->address)
1399  {
1400  GNUNET_break (0);
1401  return NULL;
1402  }
1403  if (sizeof(struct IPv4UdpAddress) == address->address_length)
1404  {
1405  if (NULL == plugin->sockv4)
1406  return NULL;
1407  udp_a4 = (const struct IPv4UdpAddress *) address->address;
1408  if (0 == udp_a4->u4_port)
1409  {
1410  GNUNET_break (0);
1411  return NULL;
1412  }
1413  }
1414  else if (sizeof(struct IPv6UdpAddress) == address->address_length)
1415  {
1416  if (NULL == plugin->sockv6)
1417  return NULL;
1418  udp_a6 = (const struct IPv6UdpAddress *) address->address;
1419  if (0 == udp_a6->u6_port)
1420  {
1421  GNUNET_break (0);
1422  return NULL;
1423  }
1424  }
1425  else
1426  {
1427  GNUNET_break (0);
1428  return NULL;
1429  }
1430 
1431  /* check if session already exists */
1432  cctx.address = address;
1433  cctx.res = NULL;
1435  "Looking for existing session for peer `%s' with address `%s'\n",
1436  GNUNET_i2s (&address->peer),
1437  udp_address_to_string (plugin,
1438  address->address,
1439  address->address_length));
1441  &address->peer,
1442  &session_cmp_it,
1443  &cctx);
1444  if (NULL == cctx.res)
1445  return NULL;
1446  LOG (GNUNET_ERROR_TYPE_DEBUG, "Found existing session %p\n", cctx.res);
1447  return cctx.res;
1448 }
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...
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.
static char * plugin
Solver plugin name as string.
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 1460 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().

1461 {
1462  if (GNUNET_YES == s->in_destroy)
1463  return;
1464  GNUNET_assert (NULL != s->timeout_task);
1466 }
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:246
#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:77
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 1479 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().

1482 {
1483  struct Plugin *plugin = cls;
1484 
1485  if (GNUNET_YES !=
1487  peer,
1488  session))
1489  {
1490  GNUNET_break (0);
1491  return;
1492  }
1493  /* Reschedule session timeout */
1494  reschedule_session_timeout (session);
1495 }
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
static char * plugin
Solver plugin name as string.
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:77
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 1509 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().

1510 {
1511  struct GNUNET_ATS_Session *session = udpw->session;
1512 
1513  if (plugin->bytes_in_buffer < udpw->msg_size)
1514  {
1515  GNUNET_break (0);
1516  }
1517  else
1518  {
1519  GNUNET_STATISTICS_update (plugin->env->stats,
1520  "# UDP, total bytes in send buffers",
1521  -(long long) udpw->msg_size,
1522  GNUNET_NO);
1523  plugin->bytes_in_buffer -= udpw->msg_size;
1524  }
1525  GNUNET_STATISTICS_update (plugin->env->stats,
1526  "# UDP, total messages in send buffers",
1527  -1,
1528  GNUNET_NO);
1529  if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1530  {
1532  plugin->ipv4_queue_tail,
1533  udpw);
1534  }
1535  else if (sizeof(struct IPv6UdpAddress) ==
1536  udpw->session->address->address_length)
1537  {
1539  plugin->ipv6_queue_tail,
1540  udpw);
1541  }
1542  else
1543  {
1544  GNUNET_break (0);
1545  return;
1546  }
1547  GNUNET_assert (session->msgs_in_queue > 0);
1548  session->msgs_in_queue--;
1549  GNUNET_assert (session->bytes_in_queue >= udpw->msg_size);
1550  session->bytes_in_queue -= udpw->msg_size;
1551 }
#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:78
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.
Session handle for connections.
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 1561 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().

1562 {
1563  struct GNUNET_ATS_Session *session = udpw->session;
1564 
1565  if (GNUNET_YES == session->in_destroy)
1566  {
1567  GNUNET_break (0);
1568  GNUNET_free (udpw);
1569  return;
1570  }
1571  if (plugin->bytes_in_buffer > INT64_MAX - udpw->msg_size)
1572  {
1573  GNUNET_break (0);
1574  }
1575  else
1576  {
1577  GNUNET_STATISTICS_update (plugin->env->stats,
1578  "# UDP, total bytes in send buffers",
1579  udpw->msg_size,
1580  GNUNET_NO);
1581  plugin->bytes_in_buffer += udpw->msg_size;
1582  }
1583  GNUNET_STATISTICS_update (plugin->env->stats,
1584  "# UDP, total messages in send buffers",
1585  1,
1586  GNUNET_NO);
1587  if (sizeof(struct IPv4UdpAddress) == udpw->session->address->address_length)
1588  {
1590  plugin->ipv4_queue_tail,
1591  udpw);
1592  }
1593  else if (sizeof(struct IPv6UdpAddress) ==
1594  udpw->session->address->address_length)
1595  {
1597  plugin->ipv6_queue_tail,
1598  udpw);
1599  }
1600  else
1601  {
1602  GNUNET_break (0);
1603  udpw->cont (udpw->cont_cls,
1604  &session->target,
1605  GNUNET_SYSERR,
1606  udpw->msg_size,
1607  0);
1608  GNUNET_free (udpw);
1609  return;
1610  }
1611  session->msgs_in_queue++;
1612  session->bytes_in_queue += udpw->msg_size;
1613 }
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:78
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.
Session handle for connections.
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:76
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:77
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 1627 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().

1628 {
1629  struct Plugin *plugin = frag_ctx->plugin;
1630  struct GNUNET_ATS_Session *s = frag_ctx->session;
1631  struct UDP_MessageWrapper *udpw;
1632  struct UDP_MessageWrapper *tmp;
1633  size_t overhead;
1634  struct GNUNET_TIME_Relative delay;
1635 
1637  "%p: Fragmented message removed with result %s\n",
1638  frag_ctx,
1639  (result == GNUNET_SYSERR) ? "FAIL" : "SUCCESS");
1640  /* Call continuation for fragmented message */
1641  if (frag_ctx->on_wire_size >= frag_ctx->payload_size)
1642  overhead = frag_ctx->on_wire_size - frag_ctx->payload_size;
1643  else
1644  overhead = frag_ctx->on_wire_size;
1647  {
1649  "Fragmented message acknowledged after %s (expected at %s)\n",
1652  }
1653  else
1654  {
1656  "Fragmented message acknowledged after %s (expected at %s)\n",
1659  }
1660 
1661  if (NULL != frag_ctx->cont)
1662  frag_ctx->cont (frag_ctx->cont_cls,
1663  &s->target,
1664  result,
1665  s->frag_ctx->payload_size,
1666  frag_ctx->on_wire_size);
1667  GNUNET_STATISTICS_update (plugin->env->stats,
1668  "# UDP, fragmented messages active",
1669  -1,
1670  GNUNET_NO);
1671 
1672  if (GNUNET_OK == result)
1673  {
1674  GNUNET_STATISTICS_update (plugin->env->stats,
1675  "# UDP, fragmented msgs, messages, sent, success",
1676  1,
1677  GNUNET_NO);
1678  GNUNET_STATISTICS_update (plugin->env->stats,
1679  "# UDP, fragmented msgs, bytes payload, sent, success",
1680  s->frag_ctx->payload_size,
1681  GNUNET_NO);
1683  plugin->env->stats,
1684  "# UDP, fragmented msgs, bytes overhead, sent, success",
1685  overhead,
1686  GNUNET_NO);
1687  GNUNET_STATISTICS_update (plugin->env->stats,
1688  "# UDP, total, bytes overhead, sent",
1689  overhead,
1690  GNUNET_NO);
1691  GNUNET_STATISTICS_update (plugin->env->stats,
1692  "# UDP, total, bytes payload, sent",
1693  s->frag_ctx->payload_size,
1694  GNUNET_NO);
1695  }
1696  else
1697  {
1698  GNUNET_STATISTICS_update (plugin->env->stats,
1699  "# UDP, fragmented msgs, messages, sent, failure",
1700  1,
1701  GNUNET_NO);
1702  GNUNET_STATISTICS_update (plugin->env->stats,
1703  "# UDP, fragmented msgs, bytes payload, sent, failure",
1704  s->frag_ctx->payload_size,
1705  GNUNET_NO);
1706  GNUNET_STATISTICS_update (plugin->env->stats,
1707  "# UDP, fragmented msgs, bytes payload, sent, failure",
1708  overhead,
1709  GNUNET_NO);
1710  GNUNET_STATISTICS_update (plugin->env->stats,
1711  "# UDP, fragmented msgs, bytes payload, sent, failure",
1712  overhead,
1713  GNUNET_NO);
1714  }
1715 
1716  /* Remove remaining fragments from queue, no need to transmit those
1717  any longer. */
1718  if (s->address->address_length == sizeof(struct IPv6UdpAddress))
1719  {
1720  udpw = plugin->ipv6_queue_head;
1721  while (NULL != udpw)
1722  {
1723  tmp = udpw->next;
1724  if ((udpw->frag_ctx != NULL) && (udpw->frag_ctx == frag_ctx))
1725  {
1726  dequeue (plugin, udpw);
1727  GNUNET_free (udpw);
1728  }
1729  udpw = tmp;
1730  }
1731  }
1732  if (s->address->address_length == sizeof(struct IPv4UdpAddress))
1733  {
1734  udpw = plugin->ipv4_queue_head;
1735  while (NULL != udpw)
1736  {
1737  tmp = udpw->next;
1738  if ((NULL != udpw->frag_ctx) && (udpw->frag_ctx == frag_ctx))
1739  {
1740  dequeue (plugin, udpw);
1741  GNUNET_free (udpw);
1742  }
1743  udpw = tmp;
1744  }
1745  }
1750  s->frag_ctx = NULL;
1751  GNUNET_free (frag_ctx);
1752 }
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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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.
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.
Session handle for connections.
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:687
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.
static char * plugin
Solver plugin name as string.
Network format for IPv6 addresses.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:375
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_YES
Definition: gnunet_common.h:77
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:742
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 1764 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().

1765 {
1766  struct Plugin *plugin = cls;
1767 
1768  GNUNET_assert (NULL != udpw->frag_ctx);
1769  if (GNUNET_OK == result)
1770  {
1772  "Fragment of message with %u bytes transmitted to %s\n",
1773  (unsigned int) udpw->payload_size,
1774  GNUNET_i2s (&udpw->session->target));
1776  GNUNET_STATISTICS_update (plugin->env->stats,
1777  "# UDP, fragmented msgs, fragments, sent, success",
1778  1,
1779  GNUNET_NO);
1781  plugin->env->stats,
1782  "# UDP, fragmented msgs, fragments bytes, sent, success",
1783  udpw->msg_size,
1784  GNUNET_NO);
1785  }
1786  else
1787  {
1789  "Failed to transmit fragment of message with %u bytes to %s\n",
1790  (unsigned int) udpw->payload_size,
1791  GNUNET_i2s (&udpw->session->target));
1793  GNUNET_STATISTICS_update (plugin->env->stats,
1794  "# UDP, fragmented msgs, fragments, sent, failure",
1795  1,
1796  GNUNET_NO);
1798  plugin->env->stats,
1799  "# UDP, fragmented msgs, fragments bytes, sent, failure",
1800  udpw->msg_size,
1801  GNUNET_NO);
1802  }
1803 }
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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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 ...
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static int result
Global testing status.
static char * plugin
Solver plugin name as string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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 1816 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().

1817 {
1818  struct UDP_FragmentationContext *frag_ctx = cls;
1819  struct Plugin *plugin = frag_ctx->plugin;
1820  struct UDP_MessageWrapper *udpw;
1821  struct GNUNET_ATS_Session *session = frag_ctx->session;
1822  size_t msg_len = ntohs (msg->size);
1823 
1824  LOG (GNUNET_ERROR_TYPE_DEBUG, "Enqueuing fragment with %u bytes\n", msg_len);
1825  udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msg_len);
1826  udpw->session = session;
1827  udpw->msg_buf = (char *) &udpw[1];
1828  udpw->msg_size = msg_len;
1829  udpw->payload_size = msg_len; /* FIXME: minus fragment overhead */
1830  udpw->timeout = frag_ctx->timeout;
1831  udpw->start_time = frag_ctx->start_time;
1832  udpw->transmission_time = frag_ctx->next_frag_time;
1833  frag_ctx->next_frag_time =
1835  frag_ctx->flow_delay_from_other_peer);
1836  udpw->frag_ctx = frag_ctx;
1837  udpw->qc = &qc_fragment_sent;
1838  udpw->qc_cls = plugin;
1839  GNUNET_memcpy (udpw->msg_buf, msg, msg_len);
1840  enqueue (plugin, udpw);
1841  if (session->address->address_length == sizeof(struct IPv4UdpAddress))
1842  schedule_select_v4 (plugin);
1843  else
1844  schedule_select_v6 (plugin);
1845 }
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...
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
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:395
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.
Context to send fragmented messages.
Network format for IPv4 addresses.
Session handle for connections.
struct GNUNET_ATS_Session * session
The session this fragmentation context belongs to.
Information we track for each message in the queue.
static char * plugin
Solver plugin name as string.
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 1857 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().

1858 {
1859  struct Plugin *plugin = cls;
1860  size_t overhead;
1861  struct GNUNET_TIME_Relative delay;
1862 
1863  if (udpw->msg_size >= udpw->payload_size)
1864  overhead = udpw->msg_size - udpw->payload_size;
1865  else
1866  overhead = udpw->msg_size;
1867 
1868  if (NULL != udpw->cont)
1869  {
1872  {
1874  "Message sent via UDP with delay of %s\n",
1876  }
1877  else
1878  {
1880  "Message sent via UDP with delay of %s\n",
1882  }
1883  udpw->cont (udpw->cont_cls,
1884  &udpw->session->target,
1885  result,
1886  udpw->payload_size,
1887  overhead);
1888  }
1889  if (GNUNET_OK == result)
1890  {
1891  GNUNET_STATISTICS_update (plugin->env->stats,
1892  "# UDP, unfragmented msgs, messages, sent, success",
1893  1,
1894  GNUNET_NO);
1896  plugin->env->stats,
1897  "# UDP, unfragmented msgs, bytes payload, sent, success",
1898  udpw->payload_size,
1899  GNUNET_NO);
1901  plugin->env->stats,
1902  "# UDP, unfragmented msgs, bytes overhead, sent, success",
1903  overhead,
1904  GNUNET_NO);
1905  GNUNET_STATISTICS_update (plugin->env->stats,
1906  "# UDP, total, bytes overhead, sent",
1907  overhead,
1908  GNUNET_NO);
1909  GNUNET_STATISTICS_update (plugin->env->stats,
1910  "# UDP, total, bytes payload, sent",
1911  udpw->payload_size,
1912  GNUNET_NO);
1913  }
1914  else
1915  {
1916  GNUNET_STATISTICS_update (plugin->env->stats,
1917  "# UDP, unfragmented msgs, messages, sent, failure",
1918  1,
1919  GNUNET_NO);
1921  plugin->env->stats,
1922  "# UDP, unfragmented msgs, bytes payload, sent, failure",
1923  udpw->payload_size,
1924  GNUNET_NO);
1926  plugin->env->stats,
1927  "# UDP, unfragmented msgs, bytes overhead, sent, failure",
1928  overhead,
1929  GNUNET_NO);
1930  }
1931 }
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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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 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:687
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 char * plugin
Solver plugin name as string.
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:375
struct GNUNET_PeerIdentity target
To whom are we talking to.
#define GNUNET_YES
Definition: gnunet_common.h:77
#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 1962 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().

1970 {
1971  struct Plugin *plugin = cls;
1972  size_t udpmlen = msgbuf_size + sizeof(struct UDPMessage);
1973  struct UDP_FragmentationContext *frag_ctx;
1974  struct UDP_MessageWrapper *udpw;
1975  struct UDPMessage *udp;
1976  char mbuf[udpmlen] GNUNET_ALIGN;
1977  struct GNUNET_TIME_Relative latency;
1978 
1979  if ((sizeof(struct IPv6UdpAddress) == s->address->address_length) &&
1980  (NULL == plugin->sockv6))
1981  return GNUNET_SYSERR;
1982  if ((sizeof(struct IPv4UdpAddress) == s->address->address_length) &&
1983  (NULL == plugin->sockv4))
1984  return GNUNET_SYSERR;
1985  if (udpmlen >= GNUNET_MAX_MESSAGE_SIZE)
1986  {
1987  GNUNET_break (0);
1988  return GNUNET_SYSERR;
1989  }
1990  if (GNUNET_YES !=
1992  &s->target,
1993  s))
1994  {
1995  GNUNET_break (0);
1996  return GNUNET_SYSERR;
1997  }
1999  "UDP transmits %u-byte message to `%s' using address `%s'\n",
2000  udpmlen,
2001  GNUNET_i2s (&s->target),
2002  udp_address_to_string (plugin,
2003  s->address->address,
2004  s->address->address_length));
2005 
2006  udp = (struct UDPMessage *) mbuf;
2007  udp->header.size = htons (udpmlen);
2009  udp->reserved = htonl (0);
2010  udp->sender = *plugin->env->my_identity;
2011 
2012  /* We do not update the session time out here! Otherwise this
2013  * session will not timeout since we send keep alive before session
2014  * can timeout.
2015  *
2016  * For UDP we update session timeout only on receive, this will
2017  * cover keep alives, since remote peer will reply with keep alive
2018  * responses!
2019  */if (udpmlen <= UDP_MTU)
2020  {
2021  /* unfragmented message */
2022  udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + udpmlen);
2023  udpw->session = s;
2024  udpw->msg_buf = (char *) &udpw[1];
2025  udpw->msg_size = udpmlen; /* message size with UDP overhead */
2026  udpw->payload_size = msgbuf_size; /* message size without UDP overhead */
2030  s->last_transmit_time =
2033  udpw->cont = cont;
2034  udpw->cont_cls = cont_cls;
2035  udpw->frag_ctx = NULL;
2036  udpw->qc = &qc_message_sent;
2037  udpw->qc_cls = plugin;
2038  GNUNET_memcpy (udpw->msg_buf, udp, sizeof(struct UDPMessage));
2039  GNUNET_memcpy (&udpw->msg_buf[sizeof(struct UDPMessage)],
2040  msgbuf,
2041  msgbuf_size);
2042  enqueue (plugin, udpw);
2043  GNUNET_STATISTICS_update (plugin->env->stats,
2044  "# UDP, unfragmented messages queued total",
2045  1,
2046  GNUNET_NO);
2047  GNUNET_STATISTICS_update (plugin->env->stats,
2048  "# UDP, unfragmented bytes payload queued total",
2049  msgbuf_size,
2050  GNUNET_NO);
2051  if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2052  schedule_select_v4 (plugin);
2053  else
2054  schedule_select_v6 (plugin);
2055  }
2056  else
2057  {
2058  /* fragmented message */
2059  if (NULL != s->frag_ctx)
2060  return GNUNET_SYSERR;
2061  GNUNET_memcpy (&udp[1], msgbuf, msgbuf_size);
2062  frag_ctx = GNUNET_new (struct UDP_FragmentationContext);
2063  frag_ctx->plugin = plugin;
2064  frag_ctx->session = s;
2065  frag_ctx->cont = cont;
2066  frag_ctx->cont_cls = cont_cls;
2067  frag_ctx->start_time = GNUNET_TIME_absolute_get ();
2068  frag_ctx->next_frag_time = s->last_transmit_time;
2069  frag_ctx->flow_delay_from_other_peer =
2071  1 + (msgbuf_size / UDP_MTU));
2072  frag_ctx->timeout = GNUNET_TIME_relative_to_absolute (to);
2073  frag_ctx->payload_size =
2074  msgbuf_size; /* unfragmented message size without UDP overhead */
2075  frag_ctx->on_wire_size = 0; /* bytes with UDP and fragmentation overhead */
2076  frag_ctx->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
2077  UDP_MTU,
2078  &plugin->tracker,
2081  &udp->header,
2083  frag_ctx);
2084  s->frag_ctx = frag_ctx;
2085  s->last_transmit_time = frag_ctx->next_frag_time;
2087  if (latency.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2089  "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2091  GNUNET_i2s (&s->target),
2092  (unsigned int) s->msgs_in_queue);
2093  else
2095  "Enqueued fragments will take %s for transmission to %s (queue size: %u)\n",
2097  GNUNET_i2s (&s->target),
2098  (unsigned int) s->msgs_in_queue);
2099 
2100  GNUNET_STATISTICS_update (plugin->env->stats,
2101  "# UDP, fragmented messages active",
2102  1,
2103  GNUNET_NO);
2104  GNUNET_STATISTICS_update (plugin->env->stats,
2105  "# UDP, fragmented messages, total",
2106  1,
2107  GNUNET_NO);
2108  GNUNET_STATISTICS_update (plugin->env->stats,
2109  "# UDP, fragmented bytes (payload)",
2110  frag_ctx->payload_size,
2111  GNUNET_NO);
2112  }
2114  return udpmlen;
2115 }
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:246
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_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#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:78
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:395
#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...
uint16_t type
The type of the message (GNUNET_MESSAGE_TYPE_XXXX), in big-endian format.
Context to send fragmented messages.
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:687
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.
static char * plugin
Solver plugin name as string.
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:76
#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:527
#define GNUNET_YES
Definition: gnunet_common.h:77
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 2159 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().

2163 {
2164  struct FindReceiveContext *frc = cls;
2165  struct DefragContext *e = element;
2166 
2167  if ((frc->udp_addr_len == e->udp_addr_len) &&
2168  (0 == memcmp (frc->udp_addr, e->udp_addr, frc->udp_addr_len)))
2169  {
2170  frc->rc = e;
2171  return GNUNET_NO;
2172  }
2173  return GNUNET_YES;
2174 }
const union UdpAddress * udp_addr
Address to find.
static struct Experiment * e
#define GNUNET_NO
Definition: gnunet_common.h:78
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:77
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 2186 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().

2187 {
2188  struct Plugin *plugin = cls;
2189  struct UDP_MessageWrapper *udpw;
2190  struct UDP_MessageWrapper *next;
2191  struct FindReceiveContext frc;
2192 
2195  "Session %p to peer `%s' at address %s ended\n",
2196  s,
2197  GNUNET_i2s (&s->target),
2198  udp_address_to_string (plugin,
2199  s->address->address,
2200  s->address->address_length));
2201  if (NULL != s->timeout_task)
2202  {
2204  s->timeout_task = NULL;
2205  }
2206  if (NULL != s->frag_ctx)
2207  {
2208  /* Remove fragmented message due to disconnect */
2210  }
2211  GNUNET_assert (
2212  GNUNET_YES ==
2214  frc.rc = NULL;
2215  frc.udp_addr = s->address->address;
2216  frc.udp_addr_len = s->address->address_length;
2217  /* Lookup existing receive context for this address */
2218  if (NULL != plugin->defrag_ctxs)
2219  {
2222  &frc);
2223  if (NULL != frc.rc)
2224  {
2225  struct DefragContext *d_ctx = frc.rc;
2226 
2229  GNUNET_free (d_ctx);
2230  }
2231  }
2232  s->in_destroy = GNUNET_YES;
2233  next = plugin->ipv4_queue_head;
2234  while (NULL != (udpw = next))
2235  {
2236  next = udpw->next;
2237  if (udpw->session == s)
2238  {
2239  dequeue (plugin, udpw);
2240  udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
2241  GNUNET_free (udpw);
2242  }
2243  }
2244  next = plugin->ipv6_queue_head;
2245  while (NULL != (udpw = next))
2246  {
2247  next = udpw->next;
2248  if (udpw->session == s)
2249  {
2250  dequeue (plugin, udpw);
2251  udpw->qc (udpw->qc_cls, udpw, GNUNET_SYSERR);
2252  GNUNET_free (udpw);
2253  }
2254  }
2255  if ((NULL != s->frag_ctx) && (NULL != s->frag_ctx->cont))
2256  {
2257  /* The 'frag_ctx' itself will be freed in #free_session() a bit
2258  later, as it might be in use right now */
2260  "Calling continuation for fragemented message to `%s' with result SYSERR\n",
2261  GNUNET_i2s (&s->target));
2262  s->frag_ctx->cont (s->frag_ctx->cont_cls,
2263  &s->target,
2264  GNUNET_SYSERR,
2265  s->frag_ctx->payload_size,
2266  s->frag_ctx->on_wire_size);
2267  }
2269  plugin->env->session_end (plugin->env->cls, s->address, s);
2270  GNUNET_STATISTICS_set (plugin->env->stats,
2271  "# UDP sessions active",
2273  GNUNET_NO);
2274  if (0 == s->rc)
2275  free_session (s);
2276  return GNUNET_OK;
2277 }
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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_HELLO_Address * address
Address.
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().
static char * plugin
Solver plugin name as string.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
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:77
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:966
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 2289 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().

2293 {
2294  const struct GNUNET_MessageHeader *ack;
2295  const struct UDP_ACK_Message *udp_ack;
2296  struct GNUNET_HELLO_Address *address;
2297  struct GNUNET_ATS_Session *s;
2298  struct GNUNET_TIME_Relative flow_delay;
2299 
2300  /* check message format */
2301  if (ntohs (msg->size) <
2302  sizeof(struct UDP_ACK_Message) + sizeof(struct GNUNET_MessageHeader))
2303  {
2304  GNUNET_break_op (0);
2305  return;
2306  }
2307  udp_ack = (const struct UDP_ACK_Message *) msg;
2308  ack = (const struct GNUNET_MessageHeader *) &udp_ack[1];
2309  if (ntohs (ack->size) != ntohs (msg->size) - sizeof(struct UDP_ACK_Message))
2310  {
2311  GNUNET_break_op (0);
2312  return;
2313  }
2314 
2315  /* Locate session */
2316  address = GNUNET_HELLO_address_allocate (&udp_ack->sender,
2317  PLUGIN_NAME,
2318  udp_addr,
2319  udp_addr_len,
2321  s = udp_plugin_lookup_session (plugin, address);
2322  if (NULL == s)
2323  {
2325  "UDP session of address %s for ACK not found\n",
2326  udp_address_to_string (plugin,
2327  address->address,
2328  address->address_length));
2329  GNUNET_HELLO_address_free (address);
2330  return;
2331  }
2332  if (NULL == s->frag_ctx)
2333  {
2335  "Fragmentation context of address %s for ACK (%s) not found\n",
2336  udp_address_to_string (plugin,
2337  address->address,
2338  address->address_length),
2340  GNUNET_HELLO_address_free (address);
2341  return;
2342  }
2343  GNUNET_HELLO_address_free (address);
2344 
2345  /* evaluate flow delay: how long should we wait between messages? */
2346  if (UINT32_MAX == ntohl (udp_ack->delay))
2347  {
2348  /* Other peer asked for us to terminate the session */
2350  "Asked to disconnect UDP session of %s\n",
2351  GNUNET_i2s (&udp_ack->sender));
2352  udp_disconnect_session (plugin, s);
2353  return;
2354  }
2355  flow_delay.rel_value_us = (uint64_t) ntohl (udp_ack->delay);
2356  if (flow_delay.rel_value_us > GNUNET_CONSTANTS_LATENCY_WARN.rel_value_us)
2358  "We received a sending delay of %s for %s\n",
2360  GNUNET_i2s (&udp_ack->sender));
2361  else
2363  "We received a sending delay of %s for %s\n",
2365  GNUNET_i2s (&udp_ack->sender));
2366  /* Flow delay is for the reassembled packet, however, our delay
2367  is per packet, so we need to adjust: */
2368  s->flow_delay_from_other_peer = flow_delay;
2369 
2370  /* Handle ACK */
2372  {
2374  "UDP processes %u-byte acknowledgement from `%s' at `%s'\n",
2375  (unsigned int) ntohs (msg->size),
2376  GNUNET_i2s (&udp_ack->sender),
2377  udp_address_to_string (plugin, udp_addr, udp_addr_len));
2378  /* Expect more ACKs to arrive */
2379  return;
2380  }
2381 
2382  /* Remove fragmented message after successful sending */
2384  "Message from %s at %s full ACK'ed\n",
2385  GNUNET_i2s (&udp_ack->sender),
2386  udp_address_to_string (plugin, udp_addr, udp_addr_len));
2388 }
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:75
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.
Session handle for connections.
#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:687
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:77
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 2400 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().

2402 {
2403  struct GNUNET_ATS_Session *session = cls;
2404  struct Plugin *plugin = session->plugin;
2405 
2406  if (GNUNET_YES == session->in_destroy)
2407  return GNUNET_OK;
2408  reschedule_session_timeout (session);
2409  session->flow_delay_for_other_peer =
2410  plugin->env->receive (plugin->env->cls, session->address, session, hdr);
2411  return GNUNET_OK;
2412 }
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:75
struct GNUNET_HELLO_Address * address
Address.
Session handle for connections.
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 ...
static char * plugin
Solver plugin name as string.
Handle for a plugin.
Definition: block.c:37
void * cls
Closure to use for callbacks.
#define GNUNET_YES
Definition: gnunet_common.h:77
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 2424 of file plugin_transport_udp.c.

References GNUNET_OK, plugin, and udp_disconnect_session().

Referenced by libgnunet_plugin_transport_udp_done(), and udp_disconnect().

2427 {
2428  struct Plugin *plugin = cls;
2429 
2430  udp_disconnect_session (plugin, value);
2431  return GNUNET_OK;
2432 }
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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...
static char * plugin
Solver plugin name as string.
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 2444 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().

2445 {
2446  struct Plugin *plugin = cls;
2447 
2449  "Disconnecting from peer `%s'\n",
2450  GNUNET_i2s (target));
2452  target,
2454  plugin);
2455 }
static char * plugin
Solver plugin name as string.
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 2464 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().

2465 {
2466  struct GNUNET_ATS_Session *s = cls;
2467  struct Plugin *plugin = s->plugin;
2468  struct GNUNET_TIME_Relative left;
2469 
2470  s->timeout_task = NULL;
2472  if (left.rel_value_us > 0)
2473  {
2474  /* not actually our turn yet, but let's at least update
2475  the monitor, it may think we're about to die ... */
2478  return;
2479  }
2481  "Session %p was idle for %s, disconnecting\n",
2482  s,
2484  GNUNET_YES));
2485  /* call session destroy function */
2486  udp_disconnect_session (plugin, s);
2487 }
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?
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
Session handle for connections.
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
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...
static char * plugin
Solver plugin name as string.
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:77
#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 2502 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().

2505 {
2506  struct Plugin *plugin = cls;
2507  struct GNUNET_ATS_Session *s;
2508 
2509  s = GNUNET_new (struct GNUNET_ATS_Session);
2511  s->plugin = plugin;
2512  s->address = GNUNET_HELLO_address_copy (address);
2513  s->target = address->peer;
2521  s->timeout_task =
2523  s->scope = network_type;
2524 
2526  "Creating new session %p for peer `%s' address `%s'\n",
2527  s,
2528  GNUNET_i2s (&address->peer),
2529  udp_address_to_string (plugin,
2530  address->address,
2531  address->address_length));
2533  plugin->sessions,
2534  &s->target,
2535  s,
2537  GNUNET_STATISTICS_set (plugin->env->stats,
2538  "# UDP sessions active",
2540  GNUNET_NO);
2542  return s;
2543 }
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:246
#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:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
#define GNUNET_new(type)
Allocate a struct or union of the given type.
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?
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1253
struct GNUNET_TIME_Relative flow_delay_from_other_peer
Desired delay for transmissions we received from other peer.
Session handle for connections.
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:85
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:442
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.
static char * plugin
Solver plugin name as string.
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 2555 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().

2556 {
2557  struct Plugin *plugin = cls;
2558  struct GNUNET_ATS_Session *s;
2559  enum GNUNET_NetworkType network_type = GNUNET_NT_UNSPECIFIED;
2560  const struct IPv4UdpAddress *udp_v4;
2561  const struct IPv6UdpAddress *udp_v6;
2562 
2563  if (NULL == address)
2564  {
2565  GNUNET_break (0);
2566  return NULL;
2567  }
2568  if ((address->address_length != sizeof(struct IPv4UdpAddress)) &&
2569  (address->address_length != sizeof(struct IPv6UdpAddress)))
2570  {
2571  GNUNET_break_op (0);
2572  return NULL;
2573  }
2574  if (NULL != (s = udp_plugin_lookup_session (cls, address)))
2575  return s;
2576 
2577  /* need to create new session */
2578  if (sizeof(struct IPv4UdpAddress) == address->address_length)
2579  {
2580  struct sockaddr_in v4;
2581 
2582  udp_v4 = (const struct IPv4UdpAddress *) address->address;
2583  memset (&v4, '\0', sizeof(v4));
2584  v4.sin_family = AF_INET;
2585 #if HAVE_SOCKADDR_IN_SIN_LEN
2586  v4.sin_len = sizeof(struct sockaddr_in);
2587 #endif
2588  v4.sin_port = udp_v4->u4_port;
2589  v4.sin_addr.s_addr = udp_v4->ipv4_addr;
2590  network_type = plugin->env->get_address_type (plugin->env->cls,
2591  (const struct sockaddr *) &v4,
2592  sizeof(v4));
2593  }
2594  if (sizeof(struct IPv6UdpAddress) == address->address_length)
2595  {
2596  struct sockaddr_in6 v6;
2597 
2598  udp_v6 = (const struct IPv6UdpAddress *) address->address;
2599  memset (&v6, '\0', sizeof(v6));
2600  v6.sin6_family = AF_INET6;
2601 #if HAVE_SOCKADDR_IN_SIN_LEN
2602  v6.sin6_len = sizeof(struct sockaddr_in6);
2603 #endif
2604  v6.sin6_port = udp_v6->u6_port;
2605  v6.sin6_addr = udp_v6->ipv6_addr;
2606  network_type = plugin->env->get_address_type (plugin->env->cls,
2607  (const struct sockaddr *) &v6,
2608  sizeof(v6));
2609  }
2610  GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2611  return udp_plugin_create_session (cls, address, network_type);
2612 }
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...
Network format for IPv4 addresses.
Session handle for connections.
#define GNUNET_break_op(cond)
Use this for assertion violations caused by other peers (i.e.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static char * plugin
Solver plugin name as string.
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 2625 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().

2630 {
2631  struct GNUNET_ATS_Session *s;
2632  struct GNUNET_HELLO_Address *address;
2633 
2634  GNUNET_break (GNUNET_NT_UNSPECIFIED != network_type);
2635  if (0 != ntohl (msg->reserved))
2636  {
2637  GNUNET_break_op (0);
2638  return;
2639  }
2640  if (ntohs (msg->header.size) <
2641  sizeof(struct GNUNET_MessageHeader) + sizeof(struct UDPMessage))
2642  {
2643  GNUNET_break_op (0);
2644  return;
2645  }
2646 
2647  address = GNUNET_HELLO_address_allocate (&msg->sender,
2648  PLUGIN_NAME,
2649  udp_addr,
2650  udp_addr_len,
2652  if (NULL == (s = udp_plugin_lookup_session (plugin, address)))
2653  {
2654  s = udp_plugin_create_session (plugin, address, network_type);
2655  plugin->env->session_start (plugin->env->cls, address, s, s->scope);
2657  }
2658  GNUNET_free (address);
2659 
2660  s->rc++;
2662  (const char *) &msg[1],
2663  ntohs (msg->header.size) - sizeof(struct UDPMessage),
2664  GNUNET_YES,
2665  GNUNET_NO);
2666  s->rc--;
2667  if ((0 == s->rc) && (GNUNET_YES == s->in_destroy))
2668  free_session (s);
2669 }
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:78
uint16_t size
The length of the struct (in bytes, including the length field itself), in big-endian format...
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
Session handle for connections.
#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:114
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:77
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 2679 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().

2680 {
2681  struct DefragContext *dc = cls;
2682  const struct UDPMessage *um;
2683 
2684  if (ntohs (msg->type) != GNUNET_MESSAGE_TYPE_TRANSPORT_UDP_MESSAGE)
2685  {
2686  GNUNET_break_op (0);
2687  return;
2688  }
2689  if (ntohs (msg->size) < sizeof(struct UDPMessage))
2690  {
2691  GNUNET_break_op (0);
2692  return;
2693  }
2694  um = (const struct UDPMessage *) msg;
2695  dc->sender = um->sender;
2696  dc->have_sender = GNUNET_YES;
2698  um,
2699  dc->udp_addr,
2700  dc->udp_addr_len,
2701  dc->network_type);
2702 }
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:77
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 2715 of file plugin_transport_udp.c.

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

Referenced by ack_proc().

2716 {
2717  struct Plugin *plugin = cls;
2718 
2719  if (GNUNET_OK == result)
2720  {
2721  GNUNET_STATISTICS_update (plugin->env->stats,
2722  "# UDP, ACK messages sent",
2723  1,
2724  GNUNET_NO);
2725  }
2726  else
2727  {
2728  GNUNET_STATISTICS_update (plugin->env->stats,
2729  "# UDP, ACK transmissions failed",
2730  1,
2731  GNUNET_NO);
2732  }
2733 }
#define GNUNET_NO
Definition: gnunet_common.h:78
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
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 GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
static int result
Global testing status.
static char * plugin
Solver plugin name as string.
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 2744 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().

2745 {
2746  struct DefragContext *rc = cls;
2747  struct Plugin *plugin = rc->plugin;
2748  size_t msize = sizeof(struct UDP_ACK_Message) + ntohs (msg->size);
2749  struct UDP_ACK_Message *udp_ack;
2750  uint32_t delay;
2751  struct UDP_MessageWrapper *udpw;
2752  struct GNUNET_ATS_Session *s;
2753  struct GNUNET_HELLO_Address *address;
2754 
2755  if (GNUNET_NO == rc->have_sender)
2756  {
2757  /* tried to defragment but never succeeded, hence will not ACK */
2758  /* This can happen if we just lost msgs */
2759  GNUNET_STATISTICS_update (plugin->env->stats,
2760  "# UDP, fragments discarded without ACK",
2761  1,
2762  GNUNET_NO);
2763  return;
2764  }
2765  address = GNUNET_HELLO_address_allocate (&rc->sender,
2766  PLUGIN_NAME,
2767  rc->udp_addr,
2768  rc->udp_addr_len,
2770  s = udp_plugin_lookup_session (plugin, address);
2771  GNUNET_HELLO_address_free (address);
2772  if (NULL == s)
2773  {
2775  "Trying to transmit ACK to peer `%s' but no session found!\n",
2776  udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len));
2779  GNUNET_free (rc);
2780  GNUNET_STATISTICS_update (plugin->env->stats,
2781  "# UDP, ACK transmissions failed",
2782  1,
2783  GNUNET_NO);
2784  return;
2785  }
2786  if (GNUNET_TIME_UNIT_FOREVER_REL.rel_value_us ==
2788  delay = UINT32_MAX;
2789  else if (s->flow_delay_for_other_peer.rel_value_us < UINT32_MAX)
2791  else
2792  delay = UINT32_MAX - 1; /* largest value we can communicate */
2794  "Sending ACK to `%s' including delay of %s\n",
2795  udp_address_to_string (plugin, rc->udp_addr, rc->udp_addr_len),
2797  GNUNET_YES));
2798  udpw = GNUNET_malloc (sizeof(struct UDP_MessageWrapper) + msize);
2799  udpw->msg_size = msize;
2800  udpw->payload_size = 0;
2801  udpw->session = s;
2804  udpw->msg_buf = (char *) &udpw[1];
2805  udpw->qc = &ack_message_sent;
2806  udpw->qc_cls = plugin;
2807  udp_ack = (struct UDP_ACK_Message *) udpw->msg_buf;
2808  udp_ack->header.size = htons ((uint16_t) msize);
2810  udp_ack->delay = htonl (delay);
2811  udp_ack->sender = *plugin->env->my_identity;
2812  GNUNET_memcpy (&udp_ack[1], msg, ntohs (msg->size));
2813  enqueue (plugin, udpw);
2815  if (s->address->address_length == sizeof(struct IPv4UdpAddress))
2816  schedule_select_v4 (plugin);
2817  else
2818  schedule_select_v6 (plugin);
2819 }
size_t address_length
Number of bytes in address.
size_t payload_size
Payload size of original message.
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
uint64_t rel_value_us
The actual value.
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_Relative flow_delay_for_other_peer
Desired delay for next sending we send to other peer.
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_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_NO
Definition: gnunet_common.h:78
static void ack_message_sent(void *cls, struct UDP_MessageWrapper *udpw, int result)
We finished sending an acknowledgement.
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...
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 GNUNET_TIME_UNIT_FOREVER_ABS
Constant used to specify "forever".
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.
void GNUNET_DEFRAGMENT_context_destroy(struct GNUNET_DEFRAGMENT_Context *dc)
Destroy the given defragmentation context.
Network format for IPv4 addresses.
Session handle for connections.
struct GNUNET_DATACACHE_PluginEnvironment * env
Our execution environment.
int have_sender
Has the sender field been initialized yet?
const char * GNUNET_STRINGS_relative_time_to_string(struct GNUNET_TIME_Relative delta, int do_round)
Give relative time in human-readable fancy format.
Definition: strings.c:687
struct GNUNET_DEFRAGMENT_Context * defrag
Defragmentation context.
struct GNUNET_MessageHeader header
Message header.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
size_t udp_addr_len
Length of udp_addr.
struct GNUNET_PeerIdentity sender
What is the identity of the sender.
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.
Information we track for each message in the queue.
static char * plugin
Solver plugin name as string.
struct GNUNET_TIME_Absolute GNUNET_TIME_absolute_get(vo