-dead code elimination
[oweals/gnunet.git] / src / core / gnunet-service-core_sessions.c
index 054ad97f4fe79ea886835ad78d1ee71c5176dec7..a77919bdedfe768ce576c941b41041736edf0f0d 100644 (file)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2009, 2010, 2011 Christian Grothoff (and other contributing authors)
+     (C) 2009-2013 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
  */
 #define TYPEMAP_FREQUENCY GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_MINUTES, 5)
 
+/**
+ * How often do we transmit our typemap on first attempt?
+ */
+#define TYPEMAP_FREQUENCY_FIRST GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
+
 
 /**
  * Message ready for encryption.  This struct is followed by the
@@ -114,13 +119,6 @@ struct Session
    */
   struct GSC_TypeMap *tmap;
 
-  /**
-   * At what time did we initially establish this session?
-   * (currently unused, should be integrated with ATS in the
-   * future...).
-   */
-  struct GNUNET_TIME_Absolute time_established;
-
   /**
    * Task to transmit corked messages with a delay.
    */
@@ -137,6 +135,12 @@ struct Session
    */
   int ready_to_transmit;
 
+  /**
+   * Is this the first time we're sending the typemap? If so,
+   * we want to send it a bit faster the second time.  0 if
+   * we are sending for the first time, 1 if not.
+   */
+  int first_typemap;
 };
 
 
@@ -226,10 +230,18 @@ transmit_typemap_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
   struct GNUNET_MessageHeader *hdr;
   struct GNUNET_TIME_Relative delay;
 
-  delay = TYPEMAP_FREQUENCY;
+  if (0 == session->first_typemap)
+  {
+    delay = TYPEMAP_FREQUENCY_FIRST;
+    session->first_typemap = 1;
+  }
+  else
+  {
+    delay = TYPEMAP_FREQUENCY;
+  }
   /* randomize a bit to avoid spont. sync */
-  delay.rel_value +=
-      GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000);
+  delay.rel_value_us +=
+      GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, 1000 * 1000);
   session->typemap_task =
       GNUNET_SCHEDULER_add_delayed (delay, &transmit_typemap_task, session);
   GNUNET_STATISTICS_update (GSC_stats,
@@ -259,7 +271,6 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
   session->tmap = GSC_TYPEMAP_create ();
   session->peer = *peer;
   session->kxinfo = kx;
-  session->time_established = GNUNET_TIME_absolute_get ();
   session->typemap_task =
       GNUNET_SCHEDULER_add_now (&transmit_typemap_task, session);
   GNUNET_assert (GNUNET_OK ==
@@ -283,7 +294,7 @@ GSC_SESSIONS_create (const struct GNUNET_PeerIdentity *peer,
  * @return GNUNET_OK (continue to iterate)
  */
 static int
-notify_client_about_session (void *cls, const GNUNET_HashCode * key,
+notify_client_about_session (void *cls, const struct GNUNET_HashCode * key,
                              void *value)
 {
   struct GSC_Client *client = cls;
@@ -398,7 +409,7 @@ discard_expired_requests (struct Session *session)
   {
     pos = nxt;
     nxt = pos->next;
-    if ((pos->deadline.abs_value < now.abs_value) &&
+    if ((pos->deadline.abs_value_us < now.abs_value_us) &&
         (GNUNET_YES != pos->was_solicited))
     {
       GNUNET_STATISTICS_update (GSC_stats,
@@ -490,7 +501,7 @@ try_transmission (struct Session *session)
   now = GNUNET_TIME_absolute_get ();
   if ((msize == 0) ||
       ((msize < GNUNET_CONSTANTS_MAX_ENCRYPTED_MESSAGE_SIZE / 2) &&
-       (min_deadline.abs_value > now.abs_value)))
+       (min_deadline.abs_value_us > now.abs_value_us)))
   {
     /* not enough ready yet, try to solicit more */
     solicit_messages (session);
@@ -549,7 +560,7 @@ try_transmission (struct Session *session)
  * @return always GNUNET_OK
  */
 static int
-do_send_message (void *cls, const GNUNET_HashCode * key, void *value)
+do_send_message (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   const struct GNUNET_MessageHeader *hdr = cls;
   struct Session *session = value;
@@ -642,7 +653,7 @@ GSC_SESSIONS_transmit (struct GSC_ClientActiveRequest *car,
  */
 #include "core.h"
 static int
-queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
+queue_connect_message (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct GNUNET_SERVER_TransmitContext *tc = cls;
   struct Session *session = value;
@@ -651,8 +662,6 @@ queue_connect_message (void *cls, const GNUNET_HashCode * key, void *value)
   /* FIXME: code duplication with clients... */
   cnm.header.size = htons (sizeof (struct ConnectNotifyMessage));
   cnm.header.type = htons (GNUNET_MESSAGE_TYPE_CORE_NOTIFY_CONNECT);
-  // FIXME: full ats...
-  cnm.ats_count = htonl (0);
   cnm.peer = session->peer;
   GNUNET_SERVER_transmit_context_append_message (tc, &cnm.header);
   return GNUNET_OK;
@@ -782,7 +791,7 @@ GSC_SESSIONS_add_to_typemap (const struct GNUNET_PeerIdentity *peer,
 void
 GSC_SESSIONS_init ()
 {
-  sessions = GNUNET_CONTAINER_multihashmap_create (128);
+  sessions = GNUNET_CONTAINER_multihashmap_create (128, GNUNET_NO);
 }
 
 
@@ -795,7 +804,7 @@ GSC_SESSIONS_init ()
  * @return GNUNET_OK (continue to iterate)
  */
 static int
-free_session_helper (void *cls, const GNUNET_HashCode * key, void *value)
+free_session_helper (void *cls, const struct GNUNET_HashCode * key, void *value)
 {
   struct Session *session = value;
 
@@ -810,9 +819,12 @@ free_session_helper (void *cls, const GNUNET_HashCode * key, void *value)
 void
 GSC_SESSIONS_done ()
 {
-  GNUNET_CONTAINER_multihashmap_iterate (sessions, &free_session_helper, NULL);
-  GNUNET_CONTAINER_multihashmap_destroy (sessions);
-  sessions = NULL;
+  if (NULL != sessions)
+  {
+    GNUNET_CONTAINER_multihashmap_iterate (sessions, &free_session_helper, NULL);
+    GNUNET_CONTAINER_multihashmap_destroy (sessions);
+    sessions = NULL;
+  }
 }
 
 /* end of gnunet-service-core_sessions.c */