diff options
author | Nathan S. Evans <evans@in.tum.de> | 2010-01-25 10:46:32 +0000 |
---|---|---|
committer | Nathan S. Evans <evans@in.tum.de> | 2010-01-25 10:46:32 +0000 |
commit | d227318a905599753d76848b9506bdf215ec1755 (patch) | |
tree | c82ab246123280ca113648a28974f407fc365090 /src | |
parent | cec1f698129682124b2f4831cef7354102f56e50 (diff) | |
download | gnunet-d227318a905599753d76848b9506bdf215ec1755.tar.gz gnunet-d227318a905599753d76848b9506bdf215ec1755.zip |
resolver for udp plugin, don't propagate welcomes in tcp
Diffstat (limited to 'src')
-rw-r--r-- | src/transport/plugin_transport_tcp.c | 32 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 84 |
2 files changed, 105 insertions, 11 deletions
diff --git a/src/transport/plugin_transport_tcp.c b/src/transport/plugin_transport_tcp.c index f33b48dad..3107e2792 100644 --- a/src/transport/plugin_transport_tcp.c +++ b/src/transport/plugin_transport_tcp.c | |||
@@ -52,7 +52,7 @@ | |||
52 | 52 | ||
53 | 53 | ||
54 | /** | 54 | /** |
55 | * Initial handshake message for a session. | 55 | * Initial handshake message for a session. |
56 | */ | 56 | */ |
57 | struct WelcomeMessage | 57 | struct WelcomeMessage |
58 | { | 58 | { |
@@ -334,7 +334,7 @@ create_session (struct Plugin *plugin, | |||
334 | ret->last_quota_update = GNUNET_TIME_absolute_get (); | 334 | ret->last_quota_update = GNUNET_TIME_absolute_get (); |
335 | ret->quota_in = plugin->env->default_quota_in; | 335 | ret->quota_in = plugin->env->default_quota_in; |
336 | ret->expecting_welcome = GNUNET_YES; | 336 | ret->expecting_welcome = GNUNET_YES; |
337 | ret->pending_messages = create_welcome (plugin); | 337 | ret->pending_messages = create_welcome (plugin); |
338 | return ret; | 338 | return ret; |
339 | } | 339 | } |
340 | 340 | ||
@@ -511,9 +511,9 @@ disconnect_session (struct Session *session) | |||
511 | "Notifying transport service about loss of data connection with `%4s'.\n", | 511 | "Notifying transport service about loss of data connection with `%4s'.\n", |
512 | GNUNET_i2s (&session->target)); | 512 | GNUNET_i2s (&session->target)); |
513 | #endif | 513 | #endif |
514 | /* Data session that actually went past the | 514 | /* Data session that actually went past the |
515 | initial handshake; transport service may | 515 | initial handshake; transport service may |
516 | know about this one, so we need to | 516 | know about this one, so we need to |
517 | notify transport service about disconnect */ | 517 | notify transport service about disconnect */ |
518 | session->plugin->env->receive (session->plugin->env->cls, | 518 | session->plugin->env->receive (session->plugin->env->cls, |
519 | &session->target, NULL, | 519 | &session->target, NULL, |
@@ -599,7 +599,7 @@ tcp_plugin_send (void *cls, | |||
599 | "tcp", | 599 | "tcp", |
600 | "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n", | 600 | "Asked to transmit to `%4s' without address and I have no existing connection (failing).\n", |
601 | GNUNET_i2s (target)); | 601 | GNUNET_i2s (target)); |
602 | #endif | 602 | #endif |
603 | return -1; | 603 | return -1; |
604 | } | 604 | } |
605 | if (session == NULL) | 605 | if (session == NULL) |
@@ -624,7 +624,7 @@ tcp_plugin_send (void *cls, | |||
624 | "Failed to create connection to `%4s' at `%s'\n", | 624 | "Failed to create connection to `%4s' at `%s'\n", |
625 | GNUNET_i2s (target), | 625 | GNUNET_i2s (target), |
626 | GNUNET_a2s (addr, addrlen)); | 626 | GNUNET_a2s (addr, addrlen)); |
627 | #endif | 627 | #endif |
628 | return -1; | 628 | return -1; |
629 | } | 629 | } |
630 | 630 | ||
@@ -663,7 +663,7 @@ tcp_plugin_send (void *cls, | |||
663 | } | 663 | } |
664 | else | 664 | else |
665 | { | 665 | { |
666 | /* FIXME: this could be done faster by keeping | 666 | /* FIXME: this could be done faster by keeping |
667 | track of the tail of the list... */ | 667 | track of the tail of the list... */ |
668 | while (NULL != pme->next) | 668 | while (NULL != pme->next) |
669 | pme = pme->next; | 669 | pme = pme->next; |
@@ -725,7 +725,7 @@ tcp_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *target) | |||
725 | session->client = NULL; | 725 | session->client = NULL; |
726 | } | 726 | } |
727 | /* rest of the clean-up of the session will be done as part of | 727 | /* rest of the clean-up of the session will be done as part of |
728 | disconnect_notify which should be triggered any time now | 728 | disconnect_notify which should be triggered any time now |
729 | (or which may be triggering this call in the first place) */ | 729 | (or which may be triggering this call in the first place) */ |
730 | } | 730 | } |
731 | } | 731 | } |
@@ -985,7 +985,7 @@ handle_tcp_welcome (void *cls, | |||
985 | GNUNET_SERVER_client_keep (client); | 985 | GNUNET_SERVER_client_keep (client); |
986 | session = create_session (plugin, | 986 | session = create_session (plugin, |
987 | &wm->clientIdentity, client); | 987 | &wm->clientIdentity, client); |
988 | if (GNUNET_OK == | 988 | if (GNUNET_OK == |
989 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) | 989 | GNUNET_SERVER_client_get_address (client, &vaddr, &alen)) |
990 | { | 990 | { |
991 | #if DEBUG_TCP | 991 | #if DEBUG_TCP |
@@ -1091,6 +1091,16 @@ handle_tcp_data (void *cls, | |||
1091 | 1091 | ||
1092 | msize = ntohs (message->size); | 1092 | msize = ntohs (message->size); |
1093 | session = find_session_by_client (plugin, client); | 1093 | session = find_session_by_client (plugin, client); |
1094 | |||
1095 | if (GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME == ntohs(message->type)) | ||
1096 | { | ||
1097 | #if DEBUG_TCP | ||
1098 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, | ||
1099 | "tcp", "Received a welcome, NOT sending to clients!\n"); | ||
1100 | #endif | ||
1101 | return; /* We don't want to propogate WELCOME messages up! */ | ||
1102 | } | ||
1103 | |||
1094 | if ( (NULL == session) || (GNUNET_NO != session->expecting_welcome)) | 1104 | if ( (NULL == session) || (GNUNET_NO != session->expecting_welcome)) |
1095 | { | 1105 | { |
1096 | GNUNET_break_op (0); | 1106 | GNUNET_break_op (0); |
@@ -1128,7 +1138,7 @@ handle_tcp_data (void *cls, | |||
1128 | * Handlers for the various TCP messages. | 1138 | * Handlers for the various TCP messages. |
1129 | */ | 1139 | */ |
1130 | static struct GNUNET_SERVER_MessageHandler my_handlers[] = { | 1140 | static struct GNUNET_SERVER_MessageHandler my_handlers[] = { |
1131 | {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, | 1141 | {&handle_tcp_welcome, NULL, GNUNET_MESSAGE_TYPE_TRANSPORT_TCP_WELCOME, |
1132 | sizeof (struct WelcomeMessage)}, | 1142 | sizeof (struct WelcomeMessage)}, |
1133 | {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0}, | 1143 | {&handle_tcp_data, NULL, GNUNET_MESSAGE_TYPE_ALL, 0}, |
1134 | {NULL, NULL, 0, 0} | 1144 | {NULL, NULL, 0, 0} |
@@ -1315,7 +1325,7 @@ libgnunet_plugin_transport_tcp_init (void *cls) | |||
1315 | aport); | 1325 | aport); |
1316 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, | 1326 | GNUNET_SERVER_disconnect_notify (plugin->server, &disconnect_notify, |
1317 | plugin); | 1327 | plugin); |
1318 | /* FIXME: do the two calls below periodically again and | 1328 | /* FIXME: do the two calls below periodically again and |
1319 | not just once (since the info we get might change...) */ | 1329 | not just once (since the info we get might change...) */ |
1320 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | 1330 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); |
1321 | plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, | 1331 | plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 4520a71f9..7697abdd3 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -53,6 +53,12 @@ | |||
53 | static struct GNUNET_RESOLVER_RequestHandle *hostname_dns; | 53 | static struct GNUNET_RESOLVER_RequestHandle *hostname_dns; |
54 | 54 | ||
55 | /** | 55 | /** |
56 | * How long until we give up on transmitting the welcome message? | ||
57 | */ | ||
58 | #define HOSTNAME_RESOLVE_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) | ||
59 | |||
60 | |||
61 | /** | ||
56 | * Message-Packet header. | 62 | * Message-Packet header. |
57 | */ | 63 | */ |
58 | struct UDPMessage | 64 | struct UDPMessage |
@@ -100,6 +106,11 @@ struct Plugin | |||
100 | struct GNUNET_SERVICE_Context *service; | 106 | struct GNUNET_SERVICE_Context *service; |
101 | 107 | ||
102 | /** | 108 | /** |
109 | * Handle for request of hostname resolution, non-NULL if pending. | ||
110 | */ | ||
111 | struct GNUNET_RESOLVER_RequestHandle *hostname_dns; | ||
112 | |||
113 | /** | ||
103 | * ID of task used to update our addresses when one expires. | 114 | * ID of task used to update our addresses when one expires. |
104 | */ | 115 | */ |
105 | GNUNET_SCHEDULER_TaskIdentifier address_update_task; | 116 | GNUNET_SCHEDULER_TaskIdentifier address_update_task; |
@@ -239,6 +250,69 @@ udp_plugin_send (void *cls, | |||
239 | } | 250 | } |
240 | 251 | ||
241 | 252 | ||
253 | /** | ||
254 | * Add the IP of our network interface to the list of | ||
255 | * our external IP addresses. | ||
256 | */ | ||
257 | static int | ||
258 | process_interfaces (void *cls, | ||
259 | const char *name, | ||
260 | int isDefault, | ||
261 | const struct sockaddr *addr, socklen_t addrlen) | ||
262 | { | ||
263 | struct Plugin *plugin = cls; | ||
264 | int af; | ||
265 | struct sockaddr_in *v4; | ||
266 | struct sockaddr_in6 *v6; | ||
267 | |||
268 | af = addr->sa_family; | ||
269 | if (af == AF_INET) | ||
270 | { | ||
271 | v4 = (struct sockaddr_in *) addr; | ||
272 | v4->sin_port = htons (plugin->adv_port); | ||
273 | } | ||
274 | else | ||
275 | { | ||
276 | GNUNET_assert (af == AF_INET6); | ||
277 | v6 = (struct sockaddr_in6 *) addr; | ||
278 | v6->sin6_port = htons (plugin->adv_port); | ||
279 | } | ||
280 | GNUNET_log_from (GNUNET_ERROR_TYPE_INFO | | ||
281 | GNUNET_ERROR_TYPE_BULK, | ||
282 | "udp", _("Found address `%s' (%s)\n"), | ||
283 | GNUNET_a2s (addr, addrlen), name); | ||
284 | plugin->env->notify_address (plugin->env->cls, | ||
285 | "udp", | ||
286 | addr, addrlen, GNUNET_TIME_UNIT_FOREVER_REL); | ||
287 | |||
288 | return GNUNET_OK; | ||
289 | } | ||
290 | |||
291 | |||
292 | /** | ||
293 | * Function called by the resolver for each address obtained from DNS | ||
294 | * for our own hostname. Add the addresses to the list of our | ||
295 | * external IP addresses. | ||
296 | * | ||
297 | * @param cls closure | ||
298 | * @param addr one of the addresses of the host, NULL for the last address | ||
299 | * @param addrlen length of the address | ||
300 | */ | ||
301 | static void | ||
302 | process_hostname_ips (void *cls, | ||
303 | const struct sockaddr *addr, socklen_t addrlen) | ||
304 | { | ||
305 | struct Plugin *plugin = cls; | ||
306 | |||
307 | if (addr == NULL) | ||
308 | { | ||
309 | plugin->hostname_dns = NULL; | ||
310 | return; | ||
311 | } | ||
312 | process_interfaces (plugin, "<hostname>", GNUNET_YES, addr, addrlen); | ||
313 | } | ||
314 | |||
315 | |||
242 | /* | 316 | /* |
243 | * @param cls the plugin handle | 317 | * @param cls the plugin handle |
244 | * @param tc the scheduling context (for rescheduling this function again) | 318 | * @param tc the scheduling context (for rescheduling this function again) |
@@ -667,6 +741,16 @@ libgnunet_plugin_transport_udp_init (void *cls) | |||
667 | 741 | ||
668 | plugin->service = service; | 742 | plugin->service = service; |
669 | 743 | ||
744 | /* FIXME: do the two calls below periodically again and | ||
745 | not just once (since the info we get might change...) */ | ||
746 | GNUNET_OS_network_interfaces_list (&process_interfaces, plugin); | ||
747 | plugin->hostname_dns = GNUNET_RESOLVER_hostname_resolve (env->sched, | ||
748 | env->cfg, | ||
749 | AF_UNSPEC, | ||
750 | HOSTNAME_RESOLVE_TIMEOUT, | ||
751 | &process_hostname_ips, | ||
752 | plugin); | ||
753 | |||
670 | udp_sock = udp_transport_server_start (plugin); | 754 | udp_sock = udp_transport_server_start (plugin); |
671 | 755 | ||
672 | GNUNET_assert (udp_sock != NULL); | 756 | GNUNET_assert (udp_sock != NULL); |