aboutsummaryrefslogtreecommitdiff
path: root/src/transport/gnunet-service-transport_hello.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2015-10-05 15:28:21 +0000
committerChristian Grothoff <christian@grothoff.org>2015-10-05 15:28:21 +0000
commitef76e090bf279f25038c03eec4eac96bbfbe952e (patch)
tree9e70dd991daefef65cd85dbcdc4bc4d19b7fedb0 /src/transport/gnunet-service-transport_hello.c
parent8c85bda93a8ece52f02af7f20fb797ad6ac79337 (diff)
downloadgnunet-ef76e090bf279f25038c03eec4eac96bbfbe952e.tar.gz
gnunet-ef76e090bf279f25038c03eec4eac96bbfbe952e.zip
fix #3986
Diffstat (limited to 'src/transport/gnunet-service-transport_hello.c')
-rw-r--r--src/transport/gnunet-service-transport_hello.c65
1 files changed, 45 insertions, 20 deletions
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c
index 4607902a2..f1a16f112 100644
--- a/src/transport/gnunet-service-transport_hello.c
+++ b/src/transport/gnunet-service-transport_hello.c
@@ -76,6 +76,13 @@ struct OwnAddressList
76 */ 76 */
77 struct GNUNET_CRYPTO_EddsaSignature pong_signature; 77 struct GNUNET_CRYPTO_EddsaSignature pong_signature;
78 78
79 /**
80 * How often has this address been added/removed? Used as
81 * some plugins may learn the same external address from
82 * multiple origins.
83 */
84 unsigned int rc;
85
79}; 86};
80 87
81 88
@@ -133,7 +140,7 @@ struct GeneratorContext
133 140
134 141
135/** 142/**
136 * Add an address from the 'OwnAddressList' to the buffer. 143 * Add an address from the `struct OwnAddressList` to the buffer.
137 * 144 *
138 * @param cls the `struct GeneratorContext` 145 * @param cls the `struct GeneratorContext`
139 * @param max maximum number of bytes left 146 * @param max maximum number of bytes left
@@ -151,8 +158,10 @@ address_generator (void *cls,
151 158
152 if (NULL == gc->addr_pos) 159 if (NULL == gc->addr_pos)
153 return GNUNET_SYSERR; /* Done */ 160 return GNUNET_SYSERR; /* Done */
154 ret = GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, buf, 161 ret = GNUNET_HELLO_add_address (gc->addr_pos->address,
155 max); 162 gc->expiration,
163 buf,
164 max);
156 gc->addr_pos = gc->addr_pos->next; 165 gc->addr_pos = gc->addr_pos->next;
157 return ret; 166 return ret;
158} 167}
@@ -267,7 +276,7 @@ GST_hello_stop ()
267const struct GNUNET_MessageHeader * 276const struct GNUNET_MessageHeader *
268GST_hello_get () 277GST_hello_get ()
269{ 278{
270 return (struct GNUNET_MessageHeader *) our_hello; 279 return (const struct GNUNET_MessageHeader *) our_hello;
271} 280}
272 281
273 282
@@ -284,28 +293,44 @@ GST_hello_modify_addresses (int addremove,
284 struct OwnAddressList *al; 293 struct OwnAddressList *al;
285 294
286 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 295 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
287 (addremove == 296 (GNUNET_YES == addremove)
288 GNUNET_YES) ? "Adding `%s' to the set of our addresses\n" : 297 ? "Adding `%s' to the set of our addresses\n"
289 "Removing `%s' from the set of our addresses\n", 298 : "Removing `%s' from the set of our addresses\n",
290 GST_plugins_a2s (address)); 299 GST_plugins_a2s (address));
291 GNUNET_assert (address != NULL); 300 GNUNET_assert (NULL != address);
301 for (al = oal_head; al != NULL; al = al->next)
302 if (0 == GNUNET_HELLO_address_cmp (address, al->address))
303 break;
292 if (GNUNET_NO == addremove) 304 if (GNUNET_NO == addremove)
293 { 305 {
294 for (al = oal_head; al != NULL; al = al->next) 306 if (NULL == al)
295 if (0 == GNUNET_HELLO_address_cmp (address, al->address)) 307 {
296 { 308 /* address to be removed not found!? */
297 GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al); 309 GNUNET_break (0);
298 GNUNET_HELLO_address_free (al->address); 310 return;
299 GNUNET_free (al); 311 }
300 refresh_hello (); 312 al->rc--;
301 return; 313 if (0 != al->rc)
302 } 314 return; /* RC not yet zero */
303 /* address to be removed not found!? */ 315 GNUNET_CONTAINER_DLL_remove (oal_head,
304 GNUNET_break (0); 316 oal_tail,
317 al);
318 GNUNET_HELLO_address_free (al->address);
319 GNUNET_free (al);
320 refresh_hello ();
321 return;
322 }
323 if (NULL != al)
324 {
325 /* address added twice or more */
326 al->rc++;
305 return; 327 return;
306 } 328 }
307 al = GNUNET_new (struct OwnAddressList); 329 al = GNUNET_new (struct OwnAddressList);
308 GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al); 330 al->rc = 1;
331 GNUNET_CONTAINER_DLL_insert (oal_head,
332 oal_tail,
333 al);
309 al->address = GNUNET_HELLO_address_copy (address); 334 al->address = GNUNET_HELLO_address_copy (address);
310 refresh_hello (); 335 refresh_hello ();
311} 336}