reliable udp
authorChristian Grothoff <christian@grothoff.org>
Thu, 14 Jul 2011 17:45:16 +0000 (17:45 +0000)
committerChristian Grothoff <christian@grothoff.org>
Thu, 14 Jul 2011 17:45:16 +0000 (17:45 +0000)
src/transport/Makefile.am
src/transport/plugin_transport_udp_new.c

index fce9f3296b5f028747649c3afc9ab0b3ac239ec4..1eb4b249c5ef1e14becfd39aebf350a59f053e21 100644 (file)
@@ -187,9 +187,10 @@ libgnunet_plugin_transport_wlan_la_LDFLAGS = \
   $(GN_PLUGIN_LDFLAGS)
 
 libgnunet_plugin_transport_udp_la_SOURCES = \
-  plugin_transport_udp.c
+  plugin_transport_udp_new.c
 libgnunet_plugin_transport_udp_la_LIBADD = \
   $(top_builddir)/src/hello/libgnunethello.la \
+  $(top_builddir)/src/fragmentation/libgnunetfragmentation.la \
   $(top_builddir)/src/statistics/libgnunetstatistics.la \
   $(top_builddir)/src/peerinfo/libgnunetpeerinfo.la \
   $(top_builddir)/src/nat/libgnunetnat.la \
index c5b14813b6f0d46f43a6a1b62f82232524511f77..4f57c6942f0af18d0aee22f1de68918503662814 100644 (file)
@@ -235,6 +235,11 @@ struct Plugin
    */
   struct GNUNET_SERVER_MessageStreamTokenizer *mst;
 
+  /**
+   * Bandwidth tracker to limit global UDP traffic.
+   */
+  struct GNUNET_BANDWIDTH_Tracker tracker;
+
   /**
    * Address we were told to bind to exclusively (IPv4).
    */
@@ -265,6 +270,11 @@ struct Plugin
    */
   struct GNUNET_NETWORK_Handle *sockv6;
 
+  /**
+   * expected delay for ACKs 
+   */
+  struct GNUNET_TIME_Relative last_expected_delay;
+
   /**
    * Port we listen on.
    */
@@ -314,7 +324,7 @@ udp_disconnect (void *cls, const struct GNUNET_PeerIdentity *target)
                 GNUNET_CONTAINER_multihashmap_remove (plugin->sessions,
                                                       &target->hashPubKey,
                                                       session));
-  (void) GNUNET_FRAGMENT_context_destroy (session->frag);
+  plugin->last_expected_delay = GNUNET_FRAGMENT_context_destroy (session->frag);
   session->cont (session->cont_cls, target, GNUNET_SYSERR);
   GNUNET_free (session);
 }
@@ -518,8 +528,8 @@ udp_plugin_send (void *cls,
                                                        GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY));
       peer_session->frag = GNUNET_FRAGMENT_context_create (plugin->env->stats,
                                                           UDP_MTU,
-                                                          NULL /* tracker; FIXME: add later to limit send rate... */,
-                                                          GNUNET_TIME_UNIT_SECONDS /* expected delay for ACKs */,
+                                                          &plugin->tracker,
+                                                          plugin->last_expected_delay,
                                                           &udp->header,
                                                           &send_fragment,
                                                           peer_session);
@@ -1313,6 +1323,7 @@ libgnunet_plugin_transport_udp_init (void *cls)
   socklen_t addrlens[2];
   socklen_t addrlen;
   unsigned int tries;
+  unsigned long long udp_max_bps;
 
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (env->cfg,
@@ -1320,6 +1331,12 @@ libgnunet_plugin_transport_udp_init (void *cls)
                                             "PORT",
                                             &port))
     port = 2086;
+  if (GNUNET_OK !=
+      GNUNET_CONFIGURATION_get_value_number (env->cfg,
+                                            "transport-udp",
+                                            "MAX_BPS",
+                                            &udp_max_bps))
+    udp_max_bps = 1024 * 1024 * 100; /* 100 MB/s == infinity for practical purposes */
   if (GNUNET_OK !=
       GNUNET_CONFIGURATION_get_value_number (env->cfg,
                                             "transport-udp",
@@ -1339,6 +1356,10 @@ libgnunet_plugin_transport_udp_init (void *cls)
   memset (&serverAddrv4, 0, sizeof (serverAddrv4));
 
   plugin = GNUNET_malloc (sizeof (struct Plugin));
+  GNUNET_BANDWIDTH_tracker_init (&plugin->tracker,
+                                GNUNET_BANDWIDTH_value_init ((uint32_t) udp_max_bps),
+                                30);
+  plugin->last_expected_delay = GNUNET_TIME_UNIT_SECONDS;
   plugin->port = port;
   plugin->aport = aport;
   plugin->env = env;