diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-11-08 23:20:42 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-11-08 23:20:42 +0000 |
commit | a983a0267109b1b6a8e16e476e2f2956a8771b94 (patch) | |
tree | 79bcae73cdb7b87b4f55d4396e79baea76ef53a6 /src/transport/gnunet-service-transport_hello.c | |
parent | a3f8ef5b89dc44fc3acfb8f081a502f3409e4224 (diff) | |
download | gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.tar.gz gnunet-a983a0267109b1b6a8e16e476e2f2956a8771b94.zip |
refactoring how we handle peer addresses in peerinfo/ats/transport/hello subsystems -- use a struct instead of 3--4 arguments
Diffstat (limited to 'src/transport/gnunet-service-transport_hello.c')
-rw-r--r-- | src/transport/gnunet-service-transport_hello.c | 55 |
1 files changed, 20 insertions, 35 deletions
diff --git a/src/transport/gnunet-service-transport_hello.c b/src/transport/gnunet-service-transport_hello.c index 45fdf0a26..8b38a673e 100644 --- a/src/transport/gnunet-service-transport_hello.c +++ b/src/transport/gnunet-service-transport_hello.c | |||
@@ -56,9 +56,9 @@ struct OwnAddressList | |||
56 | struct OwnAddressList *prev; | 56 | struct OwnAddressList *prev; |
57 | 57 | ||
58 | /** | 58 | /** |
59 | * Name of the plugin. | 59 | * The address. |
60 | */ | 60 | */ |
61 | char *plugin_name; | 61 | struct GNUNET_HELLO_Address *address; |
62 | 62 | ||
63 | /** | 63 | /** |
64 | * How long until the current signature expires? (ZERO if the | 64 | * How long until the current signature expires? (ZERO if the |
@@ -71,11 +71,6 @@ struct OwnAddressList | |||
71 | */ | 71 | */ |
72 | struct GNUNET_CRYPTO_RsaSignature pong_signature; | 72 | struct GNUNET_CRYPTO_RsaSignature pong_signature; |
73 | 73 | ||
74 | /** | ||
75 | * Length of addr. | ||
76 | */ | ||
77 | size_t addrlen; | ||
78 | |||
79 | }; | 74 | }; |
80 | 75 | ||
81 | 76 | ||
@@ -143,9 +138,8 @@ address_generator (void *cls, size_t max, void *buf) | |||
143 | if (NULL == gc->addr_pos) | 138 | if (NULL == gc->addr_pos) |
144 | return 0; | 139 | return 0; |
145 | ret = | 140 | ret = |
146 | GNUNET_HELLO_add_address (gc->addr_pos->plugin_name, gc->expiration, | 141 | GNUNET_HELLO_add_address (gc->addr_pos->address, gc->expiration, |
147 | &gc->addr_pos[1], gc->addr_pos->addrlen, buf, | 142 | buf, max); |
148 | max); | ||
149 | gc->addr_pos = gc->addr_pos->next; | 143 | gc->addr_pos = gc->addr_pos->next; |
150 | return ret; | 144 | return ret; |
151 | } | 145 | } |
@@ -253,14 +247,11 @@ GST_hello_get () | |||
253 | * Add or remove an address from this peer's HELLO message. | 247 | * Add or remove an address from this peer's HELLO message. |
254 | * | 248 | * |
255 | * @param addremove GNUNET_YES to add, GNUNET_NO to remove | 249 | * @param addremove GNUNET_YES to add, GNUNET_NO to remove |
256 | * @param plugin_name name of the plugin for which this is an address | 250 | * @param address address to add or remove |
257 | * @param plugin_address address in a plugin-specific format | ||
258 | * @param plugin_address_len number of bytes in plugin_address | ||
259 | */ | 251 | */ |
260 | void | 252 | void |
261 | GST_hello_modify_addresses (int addremove, const char *plugin_name, | 253 | GST_hello_modify_addresses (int addremove, |
262 | const void *plugin_address, | 254 | const struct GNUNET_HELLO_Address *address) |
263 | size_t plugin_address_len) | ||
264 | { | 255 | { |
265 | struct OwnAddressList *al; | 256 | struct OwnAddressList *al; |
266 | 257 | ||
@@ -269,18 +260,18 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, | |||
269 | (add_remove == | 260 | (add_remove == |
270 | GNUNET_YES) ? "Adding `%s':%s to the set of our addresses\n" : | 261 | GNUNET_YES) ? "Adding `%s':%s to the set of our addresses\n" : |
271 | "Removing `%s':%s from the set of our addresses\n", | 262 | "Removing `%s':%s from the set of our addresses\n", |
272 | GST_plugins_a2s (plugin_name, addr, addrlen), p->short_name); | 263 | GST_plugins_a2s (address), p->short_name); |
273 | #endif | 264 | #endif |
274 | GNUNET_assert (plugin_address != NULL); | 265 | GNUNET_assert (address != NULL); |
275 | if (GNUNET_NO == addremove) | 266 | if (GNUNET_NO == addremove) |
276 | { | 267 | { |
277 | for (al = oal_head; al != NULL; al = al->next) | 268 | for (al = oal_head; al != NULL; al = al->next) |
278 | if ((plugin_address_len == al->addrlen) && | 269 | if (0 == |
279 | (0 == strcmp (al->plugin_name, plugin_name)) && | 270 | GNUNET_HELLO_address_cmp (address, |
280 | (0 == memcmp (plugin_address, &al[1], plugin_address_len))) | 271 | al->address)) |
281 | { | 272 | { |
282 | GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al); | 273 | GNUNET_CONTAINER_DLL_remove (oal_head, oal_tail, al); |
283 | GNUNET_free (al->plugin_name); | 274 | GNUNET_HELLO_address_free (al->address); |
284 | GNUNET_free (al); | 275 | GNUNET_free (al); |
285 | refresh_hello (); | 276 | refresh_hello (); |
286 | return; | 277 | return; |
@@ -289,11 +280,9 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, | |||
289 | GNUNET_break (0); | 280 | GNUNET_break (0); |
290 | return; | 281 | return; |
291 | } | 282 | } |
292 | al = GNUNET_malloc (sizeof (struct OwnAddressList) + plugin_address_len); | 283 | al = GNUNET_malloc (sizeof (struct OwnAddressList)); |
293 | GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al); | 284 | GNUNET_CONTAINER_DLL_insert (oal_head, oal_tail, al); |
294 | al->plugin_name = GNUNET_strdup (plugin_name); | 285 | al->address = GNUNET_HELLO_address_copy (address); |
295 | al->addrlen = plugin_address_len; | ||
296 | memcpy (&al[1], plugin_address, plugin_address_len); | ||
297 | refresh_hello (); | 286 | refresh_hello (); |
298 | } | 287 | } |
299 | 288 | ||
@@ -301,9 +290,7 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, | |||
301 | /** | 290 | /** |
302 | * Test if a particular address is one of ours. | 291 | * Test if a particular address is one of ours. |
303 | * | 292 | * |
304 | * @param plugin_name name of the plugin for which this is an address | 293 | * @param address address to test |
305 | * @param plugin_address address in a plugin-specific format | ||
306 | * @param plugin_address_len number of bytes in plugin_address | ||
307 | * @param sig location where to cache PONG signatures for this address [set] | 294 | * @param sig location where to cache PONG signatures for this address [set] |
308 | * @param sig_expiration how long until the current 'sig' expires? | 295 | * @param sig_expiration how long until the current 'sig' expires? |
309 | * (ZERO if sig was never created) [set] | 296 | * (ZERO if sig was never created) [set] |
@@ -311,17 +298,15 @@ GST_hello_modify_addresses (int addremove, const char *plugin_name, | |||
311 | * GNUNET_NO if not | 298 | * GNUNET_NO if not |
312 | */ | 299 | */ |
313 | int | 300 | int |
314 | GST_hello_test_address (const char *plugin_name, const void *plugin_address, | 301 | GST_hello_test_address (const struct GNUNET_HELLO_Address *address, |
315 | size_t plugin_address_len, | ||
316 | struct GNUNET_CRYPTO_RsaSignature **sig, | 302 | struct GNUNET_CRYPTO_RsaSignature **sig, |
317 | struct GNUNET_TIME_Absolute **sig_expiration) | 303 | struct GNUNET_TIME_Absolute **sig_expiration) |
318 | { | 304 | { |
319 | struct OwnAddressList *al; | 305 | struct OwnAddressList *al; |
320 | 306 | ||
321 | for (al = oal_head; al != NULL; al = al->next) | 307 | for (al = oal_head; al != NULL; al = al->next) |
322 | if ((plugin_address_len == al->addrlen) && | 308 | if (0 == GNUNET_HELLO_address_cmp (address, |
323 | (0 == strcmp (al->plugin_name, plugin_name)) && | 309 | al->address)) |
324 | (0 == memcmp (plugin_address, &al[1], plugin_address_len))) | ||
325 | { | 310 | { |
326 | *sig = &al->pong_signature; | 311 | *sig = &al->pong_signature; |
327 | *sig_expiration = &al->pong_sig_expires; | 312 | *sig_expiration = &al->pong_sig_expires; |