-allow caller ID to differ from zone used for resolution
[oweals/gnunet.git] / src / core / gnunet-service-core_kx.c
index 4ab902fbe985a7428599319f27148fe452b8d380..4bf1b79259b6a55601db6d2bd62a545f07b253b2 100644 (file)
@@ -289,6 +289,11 @@ struct GSC_KeyExchangeInfo
    */
   struct GNUNET_TIME_Absolute timeout;
 
+  /**
+   * What was the last timeout we informed our monitors about?
+   */
+  struct GNUNET_TIME_Absolute last_notify_timeout;
+
   /**
    * At what frequency are we currently re-trying SET_KEY messages?
    */
@@ -419,6 +424,7 @@ monitor_notify_all (struct GSC_KeyExchangeInfo *kx)
   GNUNET_SERVER_notification_context_broadcast (nc,
                                                 &msg.header,
                                                 GNUNET_NO);
+  kx->last_notify_timeout = kx->timeout;
 }
 
 
@@ -431,7 +437,8 @@ monitor_notify_all (struct GSC_KeyExchangeInfo *kx)
  */
 static void
 derive_auth_key (struct GNUNET_CRYPTO_AuthKey *akey,
-                 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey, uint32_t seed)
+                 const struct GNUNET_CRYPTO_SymmetricSessionKey *skey,
+                 uint32_t seed)
 {
   static const char ctx[] = "authentication key";
 
@@ -821,13 +828,15 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
         (GNUNET_CORE_KX_STATE_REKEY_SENT == kx->status) ) &&
        (end_t.abs_value_us <= kx->foreign_key_expires.abs_value_us) )
   {
-    GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# old ephemeral keys ignored"),
+    GNUNET_STATISTICS_update (GSC_stats,
+                              gettext_noop ("# old ephemeral keys ignored"),
                              1, GNUNET_NO);
     return;
   }
   start_t = GNUNET_TIME_absolute_ntoh (m->creation_time);
 
-  GNUNET_STATISTICS_update (GSC_stats, gettext_noop ("# ephemeral keys received"),
+  GNUNET_STATISTICS_update (GSC_stats,
+                            gettext_noop ("# ephemeral keys received"),
                             1, GNUNET_NO);
 
   GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -884,11 +893,17 @@ GSC_KX_handle_ephemeral_key (struct GSC_KeyExchangeInfo *kx,
     break;
   case GNUNET_CORE_KX_STATE_KEY_SENT:
     /* fine, need to send our key after updating our status, see below */
+    GSC_SESSIONS_reinit (&kx->peer);
     break;
   case GNUNET_CORE_KX_STATE_KEY_RECEIVED:
+    /* other peer already got our key, but typemap did go down */
+    GSC_SESSIONS_reinit (&kx->peer);
+    break;
   case GNUNET_CORE_KX_STATE_UP:
+    /* other peer already got our key, typemap NOT down */
+    break;
   case GNUNET_CORE_KX_STATE_REKEY_SENT:
-    /* other peer already got our key */
+    /* other peer already got our key, typemap NOT down */
     break;
   default:
     GNUNET_break (0);
@@ -1077,9 +1092,19 @@ send_keep_alive (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
 static void
 update_timeout (struct GSC_KeyExchangeInfo *kx)
 {
+  struct GNUNET_TIME_Relative delta;
+
   kx->timeout =
       GNUNET_TIME_relative_to_absolute
       (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT);
+  delta = GNUNET_TIME_absolute_get_difference (kx->last_notify_timeout,
+                                               kx->timeout);
+  if (delta.rel_value_us > 5LL * 1000LL * 1000LL)
+  {
+    /* we only notify monitors about timeout changes if those
+       are bigger than the threshold (5s) */
+    monitor_notify_all (kx);
+  }
   if (kx->keep_alive_task != GNUNET_SCHEDULER_NO_TASK)
     GNUNET_SCHEDULER_cancel (kx->keep_alive_task);
   kx->keep_alive_task =
@@ -1167,7 +1192,8 @@ GSC_KX_handle_pong (struct GSC_KeyExchangeInfo *kx,
                 "PONG", GNUNET_i2s (&t.target), (unsigned int) t.challenge);
     return;
   }
-  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received PONG from `%s'\n",
+  GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+              "Received PONG from `%s'\n",
               GNUNET_i2s (&kx->peer));
   /* no need to resend key any longer */
   if (GNUNET_SCHEDULER_NO_TASK != kx->retry_set_key_task)
@@ -1508,6 +1534,9 @@ deliver_message (void *cls,
   case GNUNET_MESSAGE_TYPE_CORE_COMPRESSED_TYPE_MAP:
     GSC_SESSIONS_set_typemap (dmc->peer, m);
     return GNUNET_OK;
+  case GNUNET_MESSAGE_TYPE_CORE_CONFIRM_TYPE_MAP:
+    GSC_SESSIONS_confirm_typemap (dmc->peer, m);
+    return GNUNET_OK;
   default:
     GSC_CLIENTS_deliver_message (dmc->peer, m,
                                  ntohs (m->size),
@@ -1683,6 +1712,7 @@ GSC_KX_handle_client_monitor_peers (void *cls,
   struct MonitorNotifyMessage done_msg;
   struct GSC_KeyExchangeInfo *kx;
 
+  GNUNET_SERVER_receive_done (client, GNUNET_OK);
   GNUNET_SERVER_notification_context_add (nc,
                                           client);
   for (kx = kx_head; NULL != kx; kx = kx->next)