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.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.c')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 11a8e23ae..542eb743e 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -25,6 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_hello_lib.h" | ||
28 | #include "gnunet_statistics_service.h" | 29 | #include "gnunet_statistics_service.h" |
29 | #include "gnunet_transport_service.h" | 30 | #include "gnunet_transport_service.h" |
30 | #include "gnunet_peerinfo_service.h" | 31 | #include "gnunet_peerinfo_service.h" |
@@ -83,15 +84,13 @@ struct GNUNET_ATS_SchedulingHandle *GST_ats; | |||
83 | * @param target a connected neighbour | 84 | * @param target a connected neighbour |
84 | * @param ats performance information (unused) | 85 | * @param ats performance information (unused) |
85 | * @param ats_count number of records in ats (unused) | 86 | * @param ats_count number of records in ats (unused) |
86 | * @param transport plugin | 87 | * @param address the address |
87 | * @param addr address | ||
88 | * @param addrlen address length | ||
89 | */ | 88 | */ |
90 | static void | 89 | static void |
91 | transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, | 90 | transmit_our_hello (void *cls, const struct GNUNET_PeerIdentity *target, |
92 | const struct GNUNET_ATS_Information *ats, | 91 | const struct GNUNET_ATS_Information *ats, |
93 | uint32_t ats_count, const char *transport, const void *addr, | 92 | uint32_t ats_count, |
94 | size_t addrlen) | 93 | const struct GNUNET_HELLO_Address *address) |
95 | { | 94 | { |
96 | const struct GNUNET_MessageHeader *hello = cls; | 95 | const struct GNUNET_MessageHeader *hello = cls; |
97 | 96 | ||
@@ -200,7 +199,8 @@ process_payload (const struct GNUNET_PeerIdentity *peer, | |||
200 | * (plugins that do not support this, can ignore the return value) | 199 | * (plugins that do not support this, can ignore the return value) |
201 | */ | 200 | */ |
202 | static struct GNUNET_TIME_Relative | 201 | static struct GNUNET_TIME_Relative |
203 | plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | 202 | plugin_env_receive_callback (void *cls, |
203 | const struct GNUNET_PeerIdentity *peer, | ||
204 | const struct GNUNET_MessageHeader *message, | 204 | const struct GNUNET_MessageHeader *message, |
205 | const struct GNUNET_ATS_Information *ats, | 205 | const struct GNUNET_ATS_Information *ats, |
206 | uint32_t ats_count, struct Session *session, | 206 | uint32_t ats_count, struct Session *session, |
@@ -209,8 +209,13 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
209 | { | 209 | { |
210 | const char *plugin_name = cls; | 210 | const char *plugin_name = cls; |
211 | struct GNUNET_TIME_Relative ret; | 211 | struct GNUNET_TIME_Relative ret; |
212 | struct GNUNET_HELLO_Address address; | ||
212 | uint16_t type; | 213 | uint16_t type; |
213 | 214 | ||
215 | address.peer = *peer; | ||
216 | address.address = sender_address; | ||
217 | address.address_length = sender_address_len; | ||
218 | address.transport_name = plugin_name; | ||
214 | ret = GNUNET_TIME_UNIT_ZERO; | 219 | ret = GNUNET_TIME_UNIT_ZERO; |
215 | if (NULL == message) | 220 | if (NULL == message) |
216 | goto end; | 221 | goto end; |
@@ -229,37 +234,29 @@ plugin_env_receive_callback (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
229 | #if DEBUG_TRANSPORT | 234 | #if DEBUG_TRANSPORT |
230 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 235 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
231 | "Processing `%s' from `%s'\n", "PING", | 236 | "Processing `%s' from `%s'\n", "PING", |
232 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, | 237 | (sender_address != NULL) ? GST_plugins_a2s (&address) |
233 | sender_address, | ||
234 | sender_address_len) | ||
235 | : "<inbound>"); | 238 | : "<inbound>"); |
236 | #endif | 239 | #endif |
237 | GST_validation_handle_ping (peer, message, plugin_name, session, | 240 | GST_validation_handle_ping (peer, message, &address, session); |
238 | sender_address, sender_address_len); | ||
239 | break; | 241 | break; |
240 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: | 242 | case GNUNET_MESSAGE_TYPE_TRANSPORT_PONG: |
241 | #if DEBUG_TRANSPORT | 243 | #if DEBUG_TRANSPORT |
242 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, | 244 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG | GNUNET_ERROR_TYPE_BULK, |
243 | "Processing `%s' from `%s'\n", "PONG", | 245 | "Processing `%s' from `%s'\n", "PONG", |
244 | (sender_address != NULL) ? GST_plugins_a2s (plugin_name, | 246 | (sender_address != NULL) ? GST_plugins_a2s (&address) |
245 | sender_address, | ||
246 | sender_address_len) | ||
247 | : "<inbound>"); | 247 | : "<inbound>"); |
248 | #endif | 248 | #endif |
249 | GST_validation_handle_pong (peer, message); | 249 | GST_validation_handle_pong (peer, message); |
250 | break; | 250 | break; |
251 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: | 251 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT: |
252 | GST_neighbours_handle_connect (message, peer, plugin_name, sender_address, | 252 | GST_neighbours_handle_connect (message, peer, &address, session, ats, ats_count); |
253 | sender_address_len, session, ats, ats_count); | ||
254 | break; | 253 | break; |
255 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: | 254 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_CONNECT_ACK: |
256 | GST_neighbours_handle_connect_ack (message, peer, plugin_name, | 255 | GST_neighbours_handle_connect_ack (message, peer, &address, |
257 | sender_address, sender_address_len, | ||
258 | session, ats, ats_count); | 256 | session, ats, ats_count); |
259 | break; | 257 | break; |
260 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: | 258 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_ACK: |
261 | GST_neighbours_handle_ack (message, peer, plugin_name, sender_address, | 259 | GST_neighbours_handle_ack (message, peer, &address, session, ats, ats_count); |
262 | sender_address_len, session, ats, ats_count); | ||
263 | break; | 260 | break; |
264 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: | 261 | case GNUNET_MESSAGE_TYPE_TRANSPORT_SESSION_DISCONNECT: |
265 | GST_neighbours_handle_disconnect_message (peer, message); | 262 | GST_neighbours_handle_disconnect_message (peer, message); |
@@ -276,8 +273,7 @@ end: | |||
276 | #if 1 | 273 | #if 1 |
277 | /* FIXME: this should not be needed, and not sure it's good to have it, but without | 274 | /* FIXME: this should not be needed, and not sure it's good to have it, but without |
278 | * this connections seem to go extra-slow */ | 275 | * this connections seem to go extra-slow */ |
279 | GNUNET_ATS_address_update (GST_ats, peer, plugin_name, sender_address, | 276 | GNUNET_ATS_address_update (GST_ats, &address, session, ats, ats_count); |
280 | sender_address_len, session, ats, ats_count); | ||
281 | #endif | 277 | #endif |
282 | #if DEBUG_TRANSPORT | 278 | #if DEBUG_TRANSPORT |
283 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 279 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -304,8 +300,13 @@ plugin_env_address_change_notification (void *cls, int add_remove, | |||
304 | const void *addr, size_t addrlen) | 300 | const void *addr, size_t addrlen) |
305 | { | 301 | { |
306 | const char *plugin_name = cls; | 302 | const char *plugin_name = cls; |
303 | struct GNUNET_HELLO_Address address; | ||
307 | 304 | ||
308 | GST_hello_modify_addresses (add_remove, plugin_name, addr, addrlen); | 305 | address.peer = GST_my_identity; |
306 | address.transport_name = plugin_name; | ||
307 | address.address = addr; | ||
308 | address.address_length = addrlen; | ||
309 | GST_hello_modify_addresses (add_remove, &address); | ||
309 | } | 310 | } |
310 | 311 | ||
311 | 312 | ||
@@ -326,6 +327,8 @@ static void | |||
326 | plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | 327 | plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, |
327 | struct Session *session) | 328 | struct Session *session) |
328 | { | 329 | { |
330 | struct GNUNET_HELLO_Address address; | ||
331 | |||
329 | #if DEBUG_TRANSPORT | 332 | #if DEBUG_TRANSPORT |
330 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", | 333 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Session %X to peer `%s' ended \n", |
331 | session, GNUNET_i2s (peer)); | 334 | session, GNUNET_i2s (peer)); |
@@ -335,7 +338,11 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
335 | "transport-ats", | 338 | "transport-ats", |
336 | "Telling ATS to destroy session %p from peer %s\n", | 339 | "Telling ATS to destroy session %p from peer %s\n", |
337 | session, GNUNET_i2s (peer)); | 340 | session, GNUNET_i2s (peer)); |
338 | GNUNET_ATS_address_destroyed (GST_ats, peer, NULL, NULL, 0, session); | 341 | address.peer = *peer; |
342 | address.address = NULL; | ||
343 | address.address_length = 0; | ||
344 | address.transport_name = cls; | ||
345 | GNUNET_ATS_address_destroyed (GST_ats, &address, session); | ||
339 | GST_neighbours_session_terminated (peer, session); | 346 | GST_neighbours_session_terminated (peer, session); |
340 | } | 347 | } |
341 | 348 | ||
@@ -348,18 +355,15 @@ plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
348 | * actually happened. | 355 | * actually happened. |
349 | * | 356 | * |
350 | * @param cls closure | 357 | * @param cls closure |
351 | * @param peer identity of the peer | 358 | * @param address address to use (for peer given in address) |
352 | * @param plugin_name name of the transport plugin, NULL to disconnect | ||
353 | * @param session session to use (if available) | 359 | * @param session session to use (if available) |
354 | * @param plugin_addr address to use (if available) | ||
355 | * @param plugin_addr_len number of bytes in addr | ||
356 | * @param bandwidth_out assigned outbound bandwidth for the connection, 0 to disconnect from peer | 360 | * @param bandwidth_out assigned outbound bandwidth for the connection, 0 to disconnect from peer |
357 | * @param bandwidth_in assigned inbound bandwidth for the connection, 0 to disconnect from peer | 361 | * @param bandwidth_in assigned inbound bandwidth for the connection, 0 to disconnect from peer |
358 | */ | 362 | */ |
359 | static void | 363 | static void |
360 | ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, | 364 | ats_request_address_change (void *cls, |
361 | const char *plugin_name, const void *plugin_addr, | 365 | const struct GNUNET_HELLO_Address *address, |
362 | size_t plugin_addr_len, struct Session *session, | 366 | struct Session *session, |
363 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | 367 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, |
364 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | 368 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, |
365 | const struct GNUNET_ATS_Information *ats, | 369 | const struct GNUNET_ATS_Information *ats, |
@@ -374,14 +378,14 @@ ats_request_address_change (void *cls, const struct GNUNET_PeerIdentity *peer, | |||
374 | #if DEBUG_TRANSPORT | 378 | #if DEBUG_TRANSPORT |
375 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 379 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
376 | "ATS tells me to disconnect from peer `%s'\n", | 380 | "ATS tells me to disconnect from peer `%s'\n", |
377 | GNUNET_i2s (peer)); | 381 | GNUNET_i2s (&address->peer)); |
378 | #endif | 382 | #endif |
379 | GST_neighbours_force_disconnect (peer); | 383 | GST_neighbours_force_disconnect (&address->peer); |
380 | return; | 384 | return; |
381 | } | 385 | } |
382 | /* will never return GNUNET_YES since connection is to be established */ | 386 | /* will never return GNUNET_YES since connection is to be established */ |
383 | GST_neighbours_switch_to_address_3way (peer, plugin_name, plugin_addr, | 387 | GST_neighbours_switch_to_address_3way (&address->peer, |
384 | plugin_addr_len, session, ats, | 388 | address, session, ats, |
385 | ats_count, bandwidth_in, | 389 | ats_count, bandwidth_in, |
386 | bandwidth_out); | 390 | bandwidth_out); |
387 | } | 391 | } |