diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-31 10:56:48 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-08-31 10:56:48 +0000 |
commit | 7efd3e4aa1f19f8af7f919991dc271dca1fa28be (patch) | |
tree | 82ddf7874f18a949962d298a29129ece95259abe /src/transport/plugin_transport_http_client.c | |
parent | a94a1861d123fe850d2ab5ae74cbb59b132a15ea (diff) | |
download | gnunet-7efd3e4aa1f19f8af7f919991dc271dca1fa28be.tar.gz gnunet-7efd3e4aa1f19f8af7f919991dc271dca1fa28be.zip |
cleanup for http_client
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 102 |
1 files changed, 81 insertions, 21 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index e2bc39f0e..f7fab9b3f 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -32,16 +32,12 @@ | |||
32 | #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done | 32 | #define LIBGNUNET_PLUGIN_TRANSPORT_DONE libgnunet_plugin_transport_http_client_done |
33 | #endif | 33 | #endif |
34 | 34 | ||
35 | 35 | #define VERBOSE_CURL GNUNET_NO | |
36 | #define VERBOSE_CURL GNUNET_YES | ||
37 | 36 | ||
38 | #include "platform.h" | 37 | #include "platform.h" |
39 | #include "gnunet_protocols.h" | 38 | #include "gnunet_protocols.h" |
40 | #include "gnunet_connection_lib.h" | 39 | #include "gnunet_common.h" |
41 | #include "gnunet_server_lib.h" | 40 | #include "gnunet_server_lib.h" |
42 | #include "gnunet_service_lib.h" | ||
43 | #include "gnunet_statistics_service.h" | ||
44 | #include "gnunet_transport_service.h" | ||
45 | #include "gnunet_transport_plugin.h" | 41 | #include "gnunet_transport_plugin.h" |
46 | #include "plugin_transport_http_common.h" | 42 | #include "plugin_transport_http_common.h" |
47 | #include <curl/curl.h> | 43 | #include <curl/curl.h> |
@@ -147,7 +143,7 @@ struct Session | |||
147 | /** | 143 | /** |
148 | * Was session given to transport service? | 144 | * Was session given to transport service? |
149 | */ | 145 | */ |
150 | int session_passed; | 146 | // int session_passed; |
151 | 147 | ||
152 | /** | 148 | /** |
153 | * Client send handle | 149 | * Client send handle |
@@ -191,6 +187,7 @@ struct Session | |||
191 | struct GNUNET_TIME_Absolute next_receive; | 187 | struct GNUNET_TIME_Absolute next_receive; |
192 | }; | 188 | }; |
193 | 189 | ||
190 | |||
194 | /** | 191 | /** |
195 | * Encapsulation of all of the state of the plugin. | 192 | * Encapsulation of all of the state of the plugin. |
196 | */ | 193 | */ |
@@ -259,29 +256,37 @@ struct HTTP_Client_Plugin | |||
259 | GNUNET_SCHEDULER_TaskIdentifier client_perform_task; | 256 | GNUNET_SCHEDULER_TaskIdentifier client_perform_task; |
260 | }; | 257 | }; |
261 | 258 | ||
259 | |||
262 | /** | 260 | /** |
263 | * Encapsulation of all of the state of the plugin. | 261 | * Encapsulation of all of the state of the plugin. |
264 | */ | 262 | */ |
265 | struct HTTP_Client_Plugin *p; | 263 | struct HTTP_Client_Plugin *p; |
266 | 264 | ||
265 | |||
267 | /** | 266 | /** |
268 | * Start session timeout | 267 | * Start session timeout for a session |
268 | * @param s the session | ||
269 | */ | 269 | */ |
270 | static void | 270 | static void |
271 | client_start_session_timeout (struct Session *s); | 271 | client_start_session_timeout (struct Session *s); |
272 | 272 | ||
273 | |||
273 | /** | 274 | /** |
274 | * Increment session timeout due to activity | 275 | * Increment session timeout due to activity for a session |
276 | * @param s the session | ||
275 | */ | 277 | */ |
276 | static void | 278 | static void |
277 | client_reschedule_session_timeout (struct Session *s); | 279 | client_reschedule_session_timeout (struct Session *s); |
278 | 280 | ||
281 | |||
279 | /** | 282 | /** |
280 | * Cancel timeout | 283 | * Cancel timeout for a session |
284 | * @param s the session | ||
281 | */ | 285 | */ |
282 | static void | 286 | static void |
283 | client_stop_session_timeout (struct Session *s); | 287 | client_stop_session_timeout (struct Session *s); |
284 | 288 | ||
289 | |||
285 | /** | 290 | /** |
286 | * Function setting up file descriptors and scheduling task to run | 291 | * Function setting up file descriptors and scheduling task to run |
287 | * | 292 | * |
@@ -293,7 +298,14 @@ static int | |||
293 | client_schedule (struct HTTP_Client_Plugin *plugin, int now); | 298 | client_schedule (struct HTTP_Client_Plugin *plugin, int now); |
294 | 299 | ||
295 | 300 | ||
296 | int | 301 | /** |
302 | * Does a session s exists? | ||
303 | * | ||
304 | * @param plugin the plugin | ||
305 | * @param s desired session | ||
306 | * @return GNUNET_YES or GNUNET_NO | ||
307 | */ | ||
308 | static int | ||
297 | client_exist_session (struct HTTP_Client_Plugin *plugin, struct Session *s) | 309 | client_exist_session (struct HTTP_Client_Plugin *plugin, struct Session *s) |
298 | { | 310 | { |
299 | struct Session * head; | 311 | struct Session * head; |
@@ -312,6 +324,7 @@ client_exist_session (struct HTTP_Client_Plugin *plugin, struct Session *s) | |||
312 | #if VERBOSE_CURL | 324 | #if VERBOSE_CURL |
313 | /** | 325 | /** |
314 | * Function to log curl debug messages with GNUNET_log | 326 | * Function to log curl debug messages with GNUNET_log |
327 | * | ||
315 | * @param curl handle | 328 | * @param curl handle |
316 | * @param type curl_infotype | 329 | * @param type curl_infotype |
317 | * @param data data | 330 | * @param data data |
@@ -361,6 +374,7 @@ client_log (CURL * curl, curl_infotype type, char *data, size_t size, void *cls) | |||
361 | } | 374 | } |
362 | #endif | 375 | #endif |
363 | 376 | ||
377 | |||
364 | /** | 378 | /** |
365 | * Function that can be used by the transport service to transmit | 379 | * Function that can be used by the transport service to transmit |
366 | * a message using the plugin. Note that in the case of a | 380 | * a message using the plugin. Note that in the case of a |
@@ -439,7 +453,12 @@ http_client_plugin_send (void *cls, | |||
439 | } | 453 | } |
440 | 454 | ||
441 | 455 | ||
442 | void | 456 | /** |
457 | * Delete session s | ||
458 | * | ||
459 | * @param s the session to delete | ||
460 | */ | ||
461 | static void | ||
443 | client_delete_session (struct Session *s) | 462 | client_delete_session (struct Session *s) |
444 | { | 463 | { |
445 | struct HTTP_Client_Plugin *plugin = s->plugin; | 464 | struct HTTP_Client_Plugin *plugin = s->plugin; |
@@ -605,6 +624,7 @@ http_client_plugin_disconnect (void *cls, const struct GNUNET_PeerIdentity *targ | |||
605 | 624 | ||
606 | } | 625 | } |
607 | 626 | ||
627 | |||
608 | static struct Session * | 628 | static struct Session * |
609 | client_lookup_session (struct HTTP_Client_Plugin *plugin, | 629 | client_lookup_session (struct HTTP_Client_Plugin *plugin, |
610 | const struct GNUNET_HELLO_Address *address) | 630 | const struct GNUNET_HELLO_Address *address) |
@@ -619,6 +639,7 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin, | |||
619 | return NULL; | 639 | return NULL; |
620 | } | 640 | } |
621 | 641 | ||
642 | |||
622 | /** | 643 | /** |
623 | * Callback method used with libcurl | 644 | * Callback method used with libcurl |
624 | * Method is called when libcurl needs to read data during sending | 645 | * Method is called when libcurl needs to read data during sending |
@@ -673,6 +694,12 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) | |||
673 | } | 694 | } |
674 | 695 | ||
675 | 696 | ||
697 | /** | ||
698 | * Wake up a curl handle which was suspended | ||
699 | * | ||
700 | * @param cls the session | ||
701 | * @param tc task context | ||
702 | */ | ||
676 | static void | 703 | static void |
677 | client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 704 | client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) |
678 | { | 705 | { |
@@ -693,7 +720,14 @@ client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
693 | } | 720 | } |
694 | 721 | ||
695 | 722 | ||
696 | 723 | /** | |
724 | * Callback for message stream tokenixer | ||
725 | * | ||
726 | * @param cls the session | ||
727 | * @param client not used | ||
728 | * @param message the message received | ||
729 | * @return always GNUNET_OK | ||
730 | */ | ||
697 | static int | 731 | static int |
698 | client_receive_mst_cb (void *cls, void *client, | 732 | client_receive_mst_cb (void *cls, void *client, |
699 | const struct GNUNET_MessageHeader *message) | 733 | const struct GNUNET_MessageHeader *message) |
@@ -783,6 +817,7 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) | |||
783 | 817 | ||
784 | } | 818 | } |
785 | 819 | ||
820 | |||
786 | /** | 821 | /** |
787 | * Task performing curl operations | 822 | * Task performing curl operations |
788 | * | 823 | * |
@@ -792,6 +827,7 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) | |||
792 | static void | 827 | static void |
793 | client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 828 | client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
794 | 829 | ||
830 | |||
795 | /** | 831 | /** |
796 | * Function setting up file descriptors and scheduling task to run | 832 | * Function setting up file descriptors and scheduling task to run |
797 | * | 833 | * |
@@ -861,7 +897,6 @@ client_schedule (struct HTTP_Client_Plugin *plugin, int now) | |||
861 | } | 897 | } |
862 | 898 | ||
863 | 899 | ||
864 | |||
865 | /** | 900 | /** |
866 | * Task performing curl operations | 901 | * Task performing curl operations |
867 | * | 902 | * |
@@ -1090,7 +1125,6 @@ http_client_plugin_get_session (void *cls, | |||
1090 | GNUNET_assert (address != NULL); | 1125 | GNUNET_assert (address != NULL); |
1091 | GNUNET_assert (address->address != NULL); | 1126 | GNUNET_assert (address->address != NULL); |
1092 | 1127 | ||
1093 | |||
1094 | /* find existing session */ | 1128 | /* find existing session */ |
1095 | s = client_lookup_session (plugin, address); | 1129 | s = client_lookup_session (plugin, address); |
1096 | if (s != NULL) | 1130 | if (s != NULL) |
@@ -1165,6 +1199,13 @@ http_client_plugin_get_session (void *cls, | |||
1165 | return s; | 1199 | return s; |
1166 | } | 1200 | } |
1167 | 1201 | ||
1202 | |||
1203 | /** | ||
1204 | * Setup http_client plugin | ||
1205 | * | ||
1206 | * @param plugin the plugin handle | ||
1207 | * @return GNUNET_OK on success, GNUNET_SYSERR on error | ||
1208 | */ | ||
1168 | static int | 1209 | static int |
1169 | client_start (struct HTTP_Client_Plugin *plugin) | 1210 | client_start (struct HTTP_Client_Plugin *plugin) |
1170 | { | 1211 | { |
@@ -1199,9 +1240,12 @@ client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc | |||
1199 | GNUNET_assert (GNUNET_OK == client_disconnect (s)); | 1240 | GNUNET_assert (GNUNET_OK == client_disconnect (s)); |
1200 | } | 1241 | } |
1201 | 1242 | ||
1243 | |||
1202 | /** | 1244 | /** |
1203 | * Start session timeout | 1245 | * Start session timeout for session s |
1204 | */ | 1246 | * |
1247 | * @param s the session | ||
1248 | */ | ||
1205 | static void | 1249 | static void |
1206 | client_start_session_timeout (struct Session *s) | 1250 | client_start_session_timeout (struct Session *s) |
1207 | { | 1251 | { |
@@ -1216,9 +1260,12 @@ client_start_session_timeout (struct Session *s) | |||
1216 | s, (unsigned long long) CLIENT_SESSION_TIMEOUT.rel_value); | 1260 | s, (unsigned long long) CLIENT_SESSION_TIMEOUT.rel_value); |
1217 | } | 1261 | } |
1218 | 1262 | ||
1263 | |||
1219 | /** | 1264 | /** |
1220 | * Increment session timeout due to activity | 1265 | * Increment session timeout due to activity for session s |
1221 | */ | 1266 | * |
1267 | * param s the session | ||
1268 | */ | ||
1222 | static void | 1269 | static void |
1223 | client_reschedule_session_timeout (struct Session *s) | 1270 | client_reschedule_session_timeout (struct Session *s) |
1224 | { | 1271 | { |
@@ -1235,9 +1282,12 @@ client_reschedule_session_timeout (struct Session *s) | |||
1235 | s, (unsigned long long) CLIENT_SESSION_TIMEOUT.rel_value); | 1282 | s, (unsigned long long) CLIENT_SESSION_TIMEOUT.rel_value); |
1236 | } | 1283 | } |
1237 | 1284 | ||
1285 | |||
1238 | /** | 1286 | /** |
1239 | * Cancel timeout | 1287 | * Cancel timeout due to activity for session s |
1240 | */ | 1288 | * |
1289 | * param s the session | ||
1290 | */ | ||
1241 | static void | 1291 | static void |
1242 | client_stop_session_timeout (struct Session *s) | 1292 | client_stop_session_timeout (struct Session *s) |
1243 | { | 1293 | { |
@@ -1273,8 +1323,12 @@ http_client_plugin_address_suggested (void *cls, const void *addr, size_t addrle | |||
1273 | return GNUNET_NO; | 1323 | return GNUNET_NO; |
1274 | } | 1324 | } |
1275 | 1325 | ||
1326 | |||
1276 | /** | 1327 | /** |
1277 | * Exit point from the plugin. | 1328 | * Exit point from the plugin. |
1329 | * | ||
1330 | * @param cls api as closure | ||
1331 | * @return NULL | ||
1278 | */ | 1332 | */ |
1279 | void * | 1333 | void * |
1280 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | 1334 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) |
@@ -1325,6 +1379,12 @@ LIBGNUNET_PLUGIN_TRANSPORT_DONE (void *cls) | |||
1325 | } | 1379 | } |
1326 | 1380 | ||
1327 | 1381 | ||
1382 | /** | ||
1383 | * Configure plugin | ||
1384 | * | ||
1385 | * @param plugin the plugin handle | ||
1386 | * @return GNUNET_OK on success, GNUNET_SYSERR on failure | ||
1387 | */ | ||
1328 | static int | 1388 | static int |
1329 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) | 1389 | client_configure_plugin (struct HTTP_Client_Plugin *plugin) |
1330 | { | 1390 | { |