- simplify timing out of old hellos
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_peer.c
index 3eeea68ddf011c4d42fb579dc280eb20e1588861..569eda84bccce534e62d4b54ae234842bc1472e2 100644 (file)
@@ -1321,6 +1321,11 @@ GMP_shutdown (void)
     GNUNET_CORE_disconnect (core_handle);
     core_handle = NULL;
   }
+  if (transport_handle != NULL)
+  {
+    GNUNET_TRANSPORT_disconnect (transport_handle);
+    transport_handle = NULL;
+  }
   GNUNET_PEER_change_rc (myid, -1);
 }
 
@@ -1880,32 +1885,19 @@ GMP_get_tunnel (const struct MeshPeer *peer)
 void
 GMP_set_hello (struct MeshPeer *peer, const struct GNUNET_HELLO_Message *hello)
 {
-  struct GNUNET_TIME_Absolute expiration;
-  struct GNUNET_TIME_Relative remaining;
+  struct GNUNET_HELLO_Message *old;
   size_t size;
 
-  if (NULL == peer->hello)
+  old = GMP_get_hello (peer);
+  if (NULL == old)
   {
     size = GNUNET_HELLO_size (hello);
     peer->hello = GNUNET_malloc (size);
     memcpy (peer->hello, hello, size);
     return;
   }
-
-  expiration = GNUNET_HELLO_get_last_expiration (peer->hello);
-  remaining = GNUNET_TIME_absolute_get_remaining (expiration);
-  if (0 == remaining.rel_value_us)
-  {
-    GNUNET_free (peer->hello);
-    size = GNUNET_HELLO_size (hello);
-    peer->hello = GNUNET_malloc (size);
-    memcpy (peer->hello, hello, size);
-  }
   else
   {
-    struct GNUNET_HELLO_Message *old;
-
-    old = peer->hello;
     peer->hello = GNUNET_HELLO_merge (old, hello);
     GNUNET_free (old);
   }
@@ -1925,6 +1917,9 @@ GMP_get_hello (struct MeshPeer *peer)
   struct GNUNET_TIME_Absolute expiration;
   struct GNUNET_TIME_Relative remaining;
 
+  if (NULL == peer->hello)
+    return NULL;
+
   expiration = GNUNET_HELLO_get_last_expiration (peer->hello);
   remaining = GNUNET_TIME_absolute_get_remaining (expiration);
   if (0 == remaining.rel_value_us)