-simplify logic
[oweals/gnunet.git] / src / transport / plugin_transport_udp.h
index 3770b3b70584392b361e85b3429130f9bdbb52ad..e1ff5e9cf339d233b1e6108036ed07e117d698d0 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet
-     (C) 2010-2014 Christian Grothoff (and other contributing authors)
+     Copyright (C) 2010-2014 Christian Grothoff (and other contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -102,6 +102,23 @@ struct IPv6UdpAddress
 };
 GNUNET_NETWORK_STRUCT_END
 
+/**
+ * Either an IPv4 or IPv6 UDP address.  Note that without a "length",
+ * one cannot tell which one of the two types this address represents.
+ */
+union UdpAddress
+{
+  /**
+   * IPv4 case.
+   */
+  struct IPv4UdpAddress v4;
+
+  /**
+   * IPv6 case.
+   */
+  struct IPv6UdpAddress v6;
+};
+
 
 /**
  * UDP Message-Packet header (after defragmentation).
@@ -155,12 +172,12 @@ struct Plugin
   /**
    * ID of select task for IPv4
    */
-  GNUNET_SCHEDULER_TaskIdentifier select_task;
+  struct GNUNET_SCHEDULER_Task *select_task;
 
   /**
    * ID of select task for IPv6
    */
-  GNUNET_SCHEDULER_TaskIdentifier select_task_v6;
+  struct GNUNET_SCHEDULER_Task *select_task_v6;
 
   /**
    * Tokenizer for inbound messages.
@@ -218,14 +235,9 @@ struct Plugin
   struct GNUNET_NETWORK_Handle *sockv6;
 
   /**
-   * Tokenizer for inbound IPv6 messages.
-   */
-  struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv6_mst;
-
-  /**
-   * Tokenizer for inbound IPv4 messages.
+   * Tokenizer for inbound messages.
    */
-  struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_ipv4_mst;
+  struct GNUNET_SERVER_MessageStreamTokenizer *broadcast_mst;
 
   /**
    * Head of DLL of broadcast addresses
@@ -336,20 +348,37 @@ struct Plugin
 
 
 const char *
-udp_address_to_string (void *cls, const void *addr, size_t addrlen);
+udp_address_to_string (void *cls,
+                       const void *addr,
+                       size_t addrlen);
+
 
+/**
+ * We received a broadcast message.  Process it and all subsequent
+ * messages in the same packet.
+ *
+ * @param plugin the UDP plugin
+ * @param buf the buffer with the message(s)
+ * @param size number of bytes in @a buf
+ * @param udp_addr address of the sender
+ * @param udp_addr_len number of bytes in @a udp_addr
+ * @param network_type network type of the sender's address
+ */
 void
 udp_broadcast_receive (struct Plugin *plugin,
-                       const char * buf,
+                       const char *buf,
                        ssize_t size,
-                       const struct sockaddr *addr,
-                       size_t addrlen);
+                       const union UdpAddress *udp_addr,
+                       size_t udp_addr_len,
+                       enum GNUNET_ATS_Network_Type network_type);
+
 
 void
 setup_broadcast (struct Plugin *plugin,
                  struct sockaddr_in6 *server_addrv6,
                  struct sockaddr_in *server_addrv4);
 
+
 void
 stop_broadcast (struct Plugin *plugin);