- simplify timing out of old hellos
[oweals/gnunet.git] / src / mesh / gnunet-service-mesh_peer.c
index 9a3623e7de4c0225d1e1b4e0bf3735e9e8f9f10e..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);
 }
 
@@ -1878,26 +1883,24 @@ GMP_get_tunnel (const struct MeshPeer *peer)
  * @param hello Hello message.
  */
 void
-GMP_set_hello (struct MeshPeer *peer, struct GNUNET_HELLO_Message *hello)
+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)
   {
-    peer->hello = hello;
+    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)
+  else
   {
-    GNUNET_free (peer->hello);
-    peer->hello = hello;
+    peer->hello = GNUNET_HELLO_merge (old, hello);
+    GNUNET_free (old);
   }
-  else
-    peer->hello = GNUNET_HELLO_merge (peer->hello, hello);
 }
 
 
@@ -1914,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)