diff options
author | Christian Grothoff <christian@grothoff.org> | 2011-08-05 08:37:59 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2011-08-05 08:37:59 +0000 |
commit | 6d99e0c26d6cb6dc6e00f21b9a75327f30886f4f (patch) | |
tree | 542a78aa7f59ffd9208f517b14d49e3afeb03061 /src/transport | |
parent | 3b289fa38ecb8b298efb43f3745c216092129fdc (diff) | |
download | gnunet-6d99e0c26d6cb6dc6e00f21b9a75327f30886f4f.tar.gz gnunet-6d99e0c26d6cb6dc6e00f21b9a75327f30886f4f.zip |
use relative timeouts over network
Diffstat (limited to 'src/transport')
-rw-r--r-- | src/transport/gnunet-service-transport.c | 6 | ||||
-rw-r--r-- | src/transport/gnunet-service-transport_clients.c | 81 | ||||
-rw-r--r-- | src/transport/transport.h | 6 | ||||
-rw-r--r-- | src/transport/transport_api_address_lookup.c | 6 |
4 files changed, 89 insertions, 10 deletions
diff --git a/src/transport/gnunet-service-transport.c b/src/transport/gnunet-service-transport.c index 269d21f63..6fd17e72d 100644 --- a/src/transport/gnunet-service-transport.c +++ b/src/transport/gnunet-service-transport.c | |||
@@ -5870,6 +5870,8 @@ transmit_address_to_client (void *cls, const char *address) | |||
5870 | } | 5870 | } |
5871 | else | 5871 | else |
5872 | { | 5872 | { |
5873 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
5874 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
5873 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); | 5875 | GNUNET_SERVER_transmit_context_run (tc, GNUNET_TIME_UNIT_FOREVER_REL); |
5874 | } | 5876 | } |
5875 | } | 5877 | } |
@@ -5893,7 +5895,6 @@ handle_address_lookup (void *cls, | |||
5893 | const char *address; | 5895 | const char *address; |
5894 | uint16_t size; | 5896 | uint16_t size; |
5895 | struct GNUNET_SERVER_TransmitContext *tc; | 5897 | struct GNUNET_SERVER_TransmitContext *tc; |
5896 | struct GNUNET_TIME_Absolute timeout; | ||
5897 | struct GNUNET_TIME_Relative rtimeout; | 5898 | struct GNUNET_TIME_Relative rtimeout; |
5898 | int32_t numeric; | 5899 | int32_t numeric; |
5899 | 5900 | ||
@@ -5921,8 +5922,7 @@ handle_address_lookup (void *cls, | |||
5921 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | 5922 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); |
5922 | return; | 5923 | return; |
5923 | } | 5924 | } |
5924 | timeout = GNUNET_TIME_absolute_ntoh (alum->timeout); | 5925 | rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); |
5925 | rtimeout = GNUNET_TIME_absolute_get_remaining (timeout); | ||
5926 | numeric = ntohl (alum->numeric_only); | 5926 | numeric = ntohl (alum->numeric_only); |
5927 | lsPlugin = find_transport (nameTransport); | 5927 | lsPlugin = find_transport (nameTransport); |
5928 | if (NULL == lsPlugin) | 5928 | if (NULL == lsPlugin) |
diff --git a/src/transport/gnunet-service-transport_clients.c b/src/transport/gnunet-service-transport_clients.c index 2e345a9c0..1cf3d0959 100644 --- a/src/transport/gnunet-service-transport_clients.c +++ b/src/transport/gnunet-service-transport_clients.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include "gnunet-service-transport_clients.h" | 27 | #include "gnunet-service-transport_clients.h" |
28 | #include "gnunet-service-transport_hello.h" | 28 | #include "gnunet-service-transport_hello.h" |
29 | #include "gnunet-service-transport_neighbours.h" | 29 | #include "gnunet-service-transport_neighbours.h" |
30 | #include "gnunet-service-transport_plugins.h" | ||
30 | #include "gnunet-service-transport.h" | 31 | #include "gnunet-service-transport.h" |
31 | #include "transport.h" | 32 | #include "transport.h" |
32 | 33 | ||
@@ -473,6 +474,33 @@ GST_clients_handle_set_quota (void *cls, | |||
473 | 474 | ||
474 | 475 | ||
475 | /** | 476 | /** |
477 | * Take the given address and append it to the set of results sent back to | ||
478 | * the client. | ||
479 | * | ||
480 | * @param cls the transmission context used ('struct GNUNET_SERVER_TransmitContext*') | ||
481 | * @param address the resolved name, NULL to indicate the last response | ||
482 | */ | ||
483 | static void | ||
484 | transmit_address_to_client (void *cls, | ||
485 | const char *address) | ||
486 | { | ||
487 | struct GNUNET_SERVER_TransmitContext *tc = cls; | ||
488 | |||
489 | if (NULL == address) | ||
490 | { | ||
491 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
492 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
493 | GNUNET_SERVER_transmit_context_run (tc, | ||
494 | GNUNET_TIME_UNIT_FOREVER_REL); | ||
495 | return; | ||
496 | } | ||
497 | GNUNET_SERVER_transmit_context_append_data (tc, | ||
498 | address, strlen (address) + 1, | ||
499 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
500 | } | ||
501 | |||
502 | |||
503 | /** | ||
476 | * Client asked to resolve an address. Process the request. | 504 | * Client asked to resolve an address. Process the request. |
477 | * | 505 | * |
478 | * @param cls unused | 506 | * @param cls unused |
@@ -484,6 +512,59 @@ GST_clients_handle_address_lookup (void *cls, | |||
484 | struct GNUNET_SERVER_Client *client, | 512 | struct GNUNET_SERVER_Client *client, |
485 | const struct GNUNET_MessageHeader *message) | 513 | const struct GNUNET_MessageHeader *message) |
486 | { | 514 | { |
515 | const struct AddressLookupMessage *alum; | ||
516 | struct GNUNET_TRANSPORT_PluginFunctions *papi; | ||
517 | const char *plugin_name; | ||
518 | const char *address; | ||
519 | uint32_t address_len; | ||
520 | uint16_t size; | ||
521 | struct GNUNET_SERVER_TransmitContext *tc; | ||
522 | struct GNUNET_TIME_Relative rtimeout; | ||
523 | int32_t numeric; | ||
524 | |||
525 | size = ntohs (message->size); | ||
526 | if (size < sizeof (struct AddressLookupMessage)) | ||
527 | { | ||
528 | GNUNET_break (0); | ||
529 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
530 | return; | ||
531 | } | ||
532 | alum = (const struct AddressLookupMessage *) message; | ||
533 | address_len = ntohl (alum->addrlen); | ||
534 | if (size <= sizeof (struct AddressLookupMessage) + address_len) | ||
535 | { | ||
536 | GNUNET_break (0); | ||
537 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
538 | return; | ||
539 | } | ||
540 | address = (const char *) &alum[1]; | ||
541 | plugin_name = (const char *) &address[address_len]; | ||
542 | if (plugin_name | ||
543 | [size - sizeof (struct AddressLookupMessage) - address_len - 1] != '\0') | ||
544 | { | ||
545 | GNUNET_break (0); | ||
546 | GNUNET_SERVER_receive_done (client, GNUNET_SYSERR); | ||
547 | return; | ||
548 | } | ||
549 | rtimeout = GNUNET_TIME_relative_ntoh (alum->timeout); | ||
550 | numeric = ntohl (alum->numeric_only); | ||
551 | papi = GST_plugins_find (plugin_name); | ||
552 | if (NULL == papi) | ||
553 | { | ||
554 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
555 | GNUNET_SERVER_transmit_context_append_data (tc, NULL, 0, | ||
556 | GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_REPLY); | ||
557 | GNUNET_SERVER_transmit_context_run (tc, rtimeout); | ||
558 | return; | ||
559 | } | ||
560 | GNUNET_SERVER_disable_receive_done_warning (client); | ||
561 | tc = GNUNET_SERVER_transmit_context_create (client); | ||
562 | papi->address_pretty_printer (papi->cls, | ||
563 | plugin_name, | ||
564 | address, address_len, | ||
565 | numeric, | ||
566 | rtimeout, | ||
567 | &transmit_address_to_client, tc); | ||
487 | } | 568 | } |
488 | 569 | ||
489 | 570 | ||
diff --git a/src/transport/transport.h b/src/transport/transport.h index 1c6aaa2a9..5384e7395 100644 --- a/src/transport/transport.h +++ b/src/transport/transport.h | |||
@@ -165,8 +165,8 @@ struct TransportRequestConnectMessage | |||
165 | }; | 165 | }; |
166 | 166 | ||
167 | /** | 167 | /** |
168 | * Message used to set a particular bandwidth quota. Send TO the | 168 | * Message used to set a particular bandwidth quota. Sent TO the |
169 | * service to set an incoming quota, send FROM the service to update | 169 | * service to set an incoming quota, sent FROM the service to update |
170 | * an outgoing quota. | 170 | * an outgoing quota. |
171 | */ | 171 | */ |
172 | struct QuotaSetMessage | 172 | struct QuotaSetMessage |
@@ -311,7 +311,7 @@ struct AddressLookupMessage | |||
311 | /** | 311 | /** |
312 | * timeout to give up. | 312 | * timeout to give up. |
313 | */ | 313 | */ |
314 | struct GNUNET_TIME_AbsoluteNBO timeout; | 314 | struct GNUNET_TIME_RelativeNBO timeout; |
315 | 315 | ||
316 | /** | 316 | /** |
317 | * Length of the (binary) address in bytes, in big-endian. | 317 | * Length of the (binary) address in bytes, in big-endian. |
diff --git a/src/transport/transport_api_address_lookup.c b/src/transport/transport_api_address_lookup.c index c6244c28f..619e60a43 100644 --- a/src/transport/transport_api_address_lookup.c +++ b/src/transport/transport_api_address_lookup.c | |||
@@ -131,7 +131,6 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
131 | size_t slen; | 131 | size_t slen; |
132 | size_t len; | 132 | size_t len; |
133 | struct AddressLookupMessage *msg; | 133 | struct AddressLookupMessage *msg; |
134 | struct GNUNET_TIME_Absolute abs_timeout; | ||
135 | struct AddressLookupCtx *aluCB; | 134 | struct AddressLookupCtx *aluCB; |
136 | struct GNUNET_CLIENT_Connection *client; | 135 | struct GNUNET_CLIENT_Connection *client; |
137 | char *addrbuf; | 136 | char *addrbuf; |
@@ -150,12 +149,11 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
150 | aluc (aluc_cls, NULL); | 149 | aluc (aluc_cls, NULL); |
151 | return; | 150 | return; |
152 | } | 151 | } |
153 | abs_timeout = GNUNET_TIME_relative_to_absolute (timeout); | ||
154 | msg = GNUNET_malloc (len); | 152 | msg = GNUNET_malloc (len); |
155 | msg->header.size = htons (len); | 153 | msg->header.size = htons (len); |
156 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); | 154 | msg->header.type = htons (GNUNET_MESSAGE_TYPE_TRANSPORT_ADDRESS_LOOKUP); |
157 | msg->numeric_only = htonl (numeric); | 155 | msg->numeric_only = htonl (numeric); |
158 | msg->timeout = GNUNET_TIME_absolute_hton (abs_timeout); | 156 | msg->timeout = GNUNET_TIME_relative_hton (timeout); |
159 | msg->addrlen = htonl (addressLen); | 157 | msg->addrlen = htonl (addressLen); |
160 | addrbuf = (char *) &msg[1]; | 158 | addrbuf = (char *) &msg[1]; |
161 | memcpy (addrbuf, address, addressLen); | 159 | memcpy (addrbuf, address, addressLen); |
@@ -163,7 +161,7 @@ GNUNET_TRANSPORT_address_lookup (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
163 | aluCB = GNUNET_malloc (sizeof (struct AddressLookupCtx)); | 161 | aluCB = GNUNET_malloc (sizeof (struct AddressLookupCtx)); |
164 | aluCB->cb = aluc; | 162 | aluCB->cb = aluc; |
165 | aluCB->cb_cls = aluc_cls; | 163 | aluCB->cb_cls = aluc_cls; |
166 | aluCB->timeout = abs_timeout; | 164 | aluCB->timeout = GNUNET_TIME_relative_to_absolute (timeout); |
167 | aluCB->client = client; | 165 | aluCB->client = client; |
168 | GNUNET_assert (GNUNET_OK == | 166 | GNUNET_assert (GNUNET_OK == |
169 | GNUNET_CLIENT_transmit_and_get_response (client, | 167 | GNUNET_CLIENT_transmit_and_get_response (client, |