aboutsummaryrefslogtreecommitdiff
path: root/src/core/gnunet-service-core_typemap.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2014-04-23 11:04:53 +0000
committerChristian Grothoff <christian@grothoff.org>2014-04-23 11:04:53 +0000
commita19683a4b76e10843c4e75db928bac5750c6430a (patch)
tree7aeff0c4d49b5f3750c569216e77912016fd5a81 /src/core/gnunet-service-core_typemap.c
parent21bac846638fbbbe2b03672295d4f14fc3ceb839 (diff)
downloadgnunet-a19683a4b76e10843c4e75db928bac5750c6430a.tar.gz
gnunet-a19683a4b76e10843c4e75db928bac5750c6430a.zip
fix #3348: send typemap confirmation messages, perform faster typemap retransmissions for unconfirmed typemaps, restart retransmissions on reconnect
Diffstat (limited to 'src/core/gnunet-service-core_typemap.c')
-rw-r--r--src/core/gnunet-service-core_typemap.c67
1 files changed, 65 insertions, 2 deletions
diff --git a/src/core/gnunet-service-core_typemap.c b/src/core/gnunet-service-core_typemap.c
index 8d9fcbec7..13f5309fb 100644
--- a/src/core/gnunet-service-core_typemap.c
+++ b/src/core/gnunet-service-core_typemap.c
@@ -1,6 +1,6 @@
1/* 1/*
2 This file is part of GNUnet. 2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors) 3 (C) 2011-2014 Christian Grothoff (and other contributing authors)
4 4
5 GNUnet is free software; you can redistribute it and/or modify 5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published 6 it under the terms of the GNU General Public License as published
@@ -51,6 +51,63 @@ static struct GSC_TypeMap my_type_map;
51 */ 51 */
52static uint8_t map_counters[UINT16_MAX + 1]; 52static uint8_t map_counters[UINT16_MAX + 1];
53 53
54/**
55 * Current hash of our (uncompressed) type map.
56 * Lazily computed when needed.
57 */
58static struct GNUNET_HashCode my_tm_hash;
59
60/**
61 * Is #my_tm_hash() current with respect to our type map?
62 */
63static int hash_current;
64
65
66/**
67 * Our type map changed, recompute its hash.
68 */
69static void
70rehash_typemap ()
71{
72 hash_current = GNUNET_NO;
73}
74
75
76/**
77 * Hash the contents of a type map.
78 *
79 * @param tm map to hash
80 * @param hc where to store the hash code
81 */
82void
83GSC_TYPEMAP_hash (const struct GSC_TypeMap *tm,
84 struct GNUNET_HashCode *hc)
85{
86 GNUNET_CRYPTO_hash (tm,
87 sizeof (struct GSC_TypeMap),
88 hc);
89}
90
91
92/**
93 * Check if the given hash matches our current type map.
94 *
95 * @param hc hash code to check if it matches our type map
96 * @return #GNUNET_YES if the hash matches, #GNUNET_NO if not
97 */
98int
99GSC_TYPEMAP_check_hash (const struct GNUNET_HashCode *hc)
100{
101 if (GNUNET_NO == hash_current)
102 {
103 GSC_TYPEMAP_hash (&my_type_map,
104 &my_tm_hash);
105 hash_current = GNUNET_YES;
106 }
107 return (0 == memcmp (hc, &my_tm_hash, sizeof (struct GNUNET_HashCode)))
108 ? GNUNET_YES : GNUNET_NO;
109}
110
54 111
55/** 112/**
56 * Compute a type map message for this peer. 113 * Compute a type map message for this peer.
@@ -152,7 +209,7 @@ broadcast_my_type_map ()
152 GNUNET_STATISTICS_update (GSC_stats, 209 GNUNET_STATISTICS_update (GSC_stats,
153 gettext_noop ("# updates to my type map"), 1, 210 gettext_noop ("# updates to my type map"), 1,
154 GNUNET_NO); 211 GNUNET_NO);
155 GSC_SESSIONS_broadcast (hdr); 212 GSC_SESSIONS_broadcast_typemap (hdr);
156 GNUNET_free (hdr); 213 GNUNET_free (hdr);
157} 214}
158 215
@@ -180,7 +237,10 @@ GSC_TYPEMAP_add (const uint16_t *types,
180 } 237 }
181 } 238 }
182 if (GNUNET_YES == changed) 239 if (GNUNET_YES == changed)
240 {
241 rehash_typemap ();
183 broadcast_my_type_map (); 242 broadcast_my_type_map ();
243 }
184} 244}
185 245
186 246
@@ -207,7 +267,10 @@ GSC_TYPEMAP_remove (const uint16_t *types,
207 } 267 }
208 } 268 }
209 if (GNUNET_YES == changed) 269 if (GNUNET_YES == changed)
270 {
271 rehash_typemap ();
210 broadcast_my_type_map (); 272 broadcast_my_type_map ();
273 }
211} 274}
212 275
213 276