aboutsummaryrefslogtreecommitdiff
path: root/src/cadet/gnunet-service-cadet_peer.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cadet/gnunet-service-cadet_peer.c')
-rw-r--r--src/cadet/gnunet-service-cadet_peer.c42
1 files changed, 31 insertions, 11 deletions
diff --git a/src/cadet/gnunet-service-cadet_peer.c b/src/cadet/gnunet-service-cadet_peer.c
index 6d6288e8d..c46e968dc 100644
--- a/src/cadet/gnunet-service-cadet_peer.c
+++ b/src/cadet/gnunet-service-cadet_peer.c
@@ -33,7 +33,7 @@
33#include "platform.h" 33#include "platform.h"
34#include "gnunet_time_lib.h" 34#include "gnunet_time_lib.h"
35#include "gnunet_util_lib.h" 35#include "gnunet_util_lib.h"
36#include "gnunet_hello_lib.h" 36#include "gnunet_hello_uri_lib.h"
37#include "gnunet_signatures.h" 37#include "gnunet_signatures.h"
38#include "gnunet_transport_application_service.h" 38#include "gnunet_transport_application_service.h"
39#include "gnunet_ats_service.h" 39#include "gnunet_ats_service.h"
@@ -186,7 +186,7 @@ struct CadetPeer
186 /** 186 /**
187 * Hello message of the peer. 187 * Hello message of the peer.
188 */ 188 */
189 struct GNUNET_HELLO_Message *hello; 189 struct GNUNET_MessageHeader *hello;
190 190
191 /** 191 /**
192 * Handle to us offering the HELLO to the transport. 192 * Handle to us offering the HELLO to the transport.
@@ -491,12 +491,15 @@ consider_peer_destroy (struct CadetPeer *cp)
491 return; /* still relevant! */ 491 return; /* still relevant! */
492 if (NULL != cp->hello) 492 if (NULL != cp->hello)
493 { 493 {
494 struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (cp->hello);
495
494 /* relevant only until HELLO expires */ 496 /* relevant only until HELLO expires */
495 exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_get_last_expiration ( 497 exp = GNUNET_TIME_absolute_get_remaining (GNUNET_HELLO_builder_get_expiration_time (builder,
496 cp->hello)); 498 cp->hello));
497 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp, 499 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (exp,
498 &destroy_peer, 500 &destroy_peer,
499 cp); 501 cp);
502 GNUNET_HELLO_builder_free (builder);
500 return; 503 return;
501 } 504 }
502 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT, 505 cp->destroy_task = GNUNET_SCHEDULER_add_delayed (IDLE_PEER_TIMEOUT,
@@ -1307,26 +1310,43 @@ GCP_get_tunnel (struct CadetPeer *cp,
1307 1310
1308void 1311void
1309GCP_set_hello (struct CadetPeer *cp, 1312GCP_set_hello (struct CadetPeer *cp,
1310 const struct GNUNET_HELLO_Message *hello) 1313 const struct GNUNET_MessageHeader *hello)
1311{ 1314{
1312 struct GNUNET_HELLO_Message *mrg; 1315 struct GNUNET_HELLO_Message *mrg;
1313 struct GNUNET_BANDWIDTH_Value32NBO bw; 1316 struct GNUNET_BANDWIDTH_Value32NBO bw;
1317 uint16_t size = sizeof (hello);
1314 1318
1315 LOG (GNUNET_ERROR_TYPE_DEBUG, 1319 LOG (GNUNET_ERROR_TYPE_DEBUG,
1316 "Got %u byte HELLO for peer %s\n", 1320 "Got %u byte HELLO for peer %s\n",
1317 (unsigned int) GNUNET_HELLO_size (hello), 1321 (unsigned int) size,
1318 GCP_2s (cp)); 1322 GCP_2s (cp));
1319 if (NULL != cp->hello) 1323 if (NULL != cp->hello)
1320 { 1324 {
1321 mrg = GNUNET_HELLO_merge (hello, 1325 struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get ();
1322 cp->hello); 1326 struct GNUNET_HELLO_Builder *builder = GNUNET_HELLO_builder_from_msg (hello);
1323 GNUNET_free (cp->hello); 1327 struct GNUNET_HELLO_Builder *cp_builder = GNUNET_HELLO_builder_from_msg (cp->hello);
1324 cp->hello = mrg; 1328 struct GNUNET_TIME_Absolute new_hello_exp = GNUNET_HELLO_builder_get_expiration_time (builder,
1329 hello);
1330 struct GNUNET_TIME_Absolute old_hello_exp = GNUNET_HELLO_builder_get_expiration_time (cp_builder,
1331 cp->hello);
1332
1333 if (GNUNET_TIME_absolute_cmp (new_hello_exp, > , now) && GNUNET_TIME_absolute_cmp (new_hello_exp, > , old_hello_exp))
1334 {
1335 GNUNET_free (cp->hello);
1336 cp->hello = GNUNET_malloc (size);
1337 GNUNET_memcpy (cp->hello, hello, size);
1338 }
1339 else
1340 {
1341 return;
1342 }
1343 GNUNET_HELLO_builder_free (builder);
1344 GNUNET_HELLO_builder_free (cp_builder);
1325 } 1345 }
1326 else 1346 else
1327 { 1347 {
1328 cp->hello = GNUNET_memdup (hello, 1348 cp->hello = GNUNET_memdup (hello,
1329 GNUNET_HELLO_size (hello)); 1349 size);
1330 } 1350 }
1331 if (NULL != cp->ash) 1351 if (NULL != cp->ash)
1332 GNUNET_TRANSPORT_application_suggest_cancel (cp->ash); 1352 GNUNET_TRANSPORT_application_suggest_cancel (cp->ash);