diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-12-13 18:05:32 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-12-13 18:05:32 +0000 |
commit | f8013637fe0f9ec3b0d00fc81960321c56fc0f19 (patch) | |
tree | 05314e699e62b6d84dcbe5f88719997082a75c48 /src/transport/plugin_transport_http_client.c | |
parent | cb6a4b5cb451462ffdbc032ebb073a39b8aa8019 (diff) | |
download | gnunet-f8013637fe0f9ec3b0d00fc81960321c56fc0f19.tar.gz gnunet-f8013637fe0f9ec3b0d00fc81960321c56fc0f19.zip |
-doxygen, indentation, minor code cleanup
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 353 |
1 files changed, 151 insertions, 202 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index 772c2e1e7..c093a0312 100644 --- a/src/transport/plugin_transport_http_client.c +++ b/src/transport/plugin_transport_http_client.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of GNUnet | 2 | This file is part of GNUnet |
3 | (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009 Christian Grothoff (and other contributing authors) | 3 | (C) 2002-2013 Christian Grothoff (and other contributing authors) |
4 | 4 | ||
5 | GNUnet is free software; you can redistribute it and/or modify | 5 | GNUnet is free software; you can redistribute it and/or modify |
6 | it under the terms of the GNU General Public License as published | 6 | it under the terms of the GNU General Public License as published |
@@ -324,20 +324,6 @@ struct HTTP_Client_Plugin | |||
324 | 324 | ||
325 | 325 | ||
326 | /** | 326 | /** |
327 | * Encapsulation of all of the state of the plugin. | ||
328 | */ | ||
329 | struct HTTP_Client_Plugin *p; | ||
330 | |||
331 | |||
332 | /** | ||
333 | * Start session timeout for a session | ||
334 | * @param s the session | ||
335 | */ | ||
336 | static void | ||
337 | client_start_session_timeout (struct Session *s); | ||
338 | |||
339 | |||
340 | /** | ||
341 | * Increment session timeout due to activity for a session | 327 | * Increment session timeout due to activity for a session |
342 | * @param s the session | 328 | * @param s the session |
343 | */ | 329 | */ |
@@ -346,14 +332,6 @@ client_reschedule_session_timeout (struct Session *s); | |||
346 | 332 | ||
347 | 333 | ||
348 | /** | 334 | /** |
349 | * Cancel timeout for a session | ||
350 | * @param s the session | ||
351 | */ | ||
352 | static void | ||
353 | client_stop_session_timeout (struct Session *s); | ||
354 | |||
355 | |||
356 | /** | ||
357 | * Function setting up file descriptors and scheduling task to run | 335 | * Function setting up file descriptors and scheduling task to run |
358 | * | 336 | * |
359 | * @param plugin plugin as closure | 337 | * @param plugin plugin as closure |
@@ -368,7 +346,7 @@ client_schedule (struct HTTP_Client_Plugin *plugin, int now); | |||
368 | * Connect a HTTP put connection | 346 | * Connect a HTTP put connection |
369 | * | 347 | * |
370 | * @param s the session to connect | 348 | * @param s the session to connect |
371 | * @return GNUNET_SYSERR for hard failure, GNUNET_OK for success | 349 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for success |
372 | */ | 350 | */ |
373 | static int | 351 | static int |
374 | client_connect_put (struct Session *s); | 352 | client_connect_put (struct Session *s); |
@@ -379,21 +357,17 @@ client_connect_put (struct Session *s); | |||
379 | * | 357 | * |
380 | * @param plugin the plugin | 358 | * @param plugin the plugin |
381 | * @param s desired session | 359 | * @param s desired session |
382 | * @return GNUNET_YES or GNUNET_NO | 360 | * @return #GNUNET_YES or #GNUNET_NO |
383 | */ | 361 | */ |
384 | static int | 362 | static int |
385 | client_exist_session (struct HTTP_Client_Plugin *plugin, struct Session *s) | 363 | client_exist_session (struct HTTP_Client_Plugin *plugin, |
364 | struct Session *s) | ||
386 | { | 365 | { |
387 | struct Session * head; | 366 | struct Session * head; |
388 | 367 | ||
389 | GNUNET_assert (NULL != plugin); | ||
390 | GNUNET_assert (NULL != s); | ||
391 | |||
392 | for (head = plugin->head; head != NULL; head = head->next) | 368 | for (head = plugin->head; head != NULL; head = head->next) |
393 | { | ||
394 | if (head == s) | 369 | if (head == s) |
395 | return GNUNET_YES; | 370 | return GNUNET_YES; |
396 | } | ||
397 | return GNUNET_NO; | 371 | return GNUNET_NO; |
398 | } | 372 | } |
399 | 373 | ||
@@ -526,10 +500,11 @@ http_client_plugin_send (void *cls, | |||
526 | memcpy (msg->buf, msgbuf, msgbuf_size); | 500 | memcpy (msg->buf, msgbuf, msgbuf_size); |
527 | GNUNET_CONTAINER_DLL_insert_tail (s->msg_head, s->msg_tail, msg); | 501 | GNUNET_CONTAINER_DLL_insert_tail (s->msg_head, s->msg_tail, msg); |
528 | 502 | ||
529 | GNUNET_asprintf (&stat_txt, "# bytes currently in %s_client buffers", plugin->protocol); | 503 | GNUNET_asprintf (&stat_txt, |
504 | "# bytes currently in %s_client buffers", | ||
505 | plugin->protocol); | ||
530 | GNUNET_STATISTICS_update (plugin->env->stats, | 506 | GNUNET_STATISTICS_update (plugin->env->stats, |
531 | stat_txt, msgbuf_size, GNUNET_NO); | 507 | stat_txt, msgbuf_size, GNUNET_NO); |
532 | |||
533 | GNUNET_free (stat_txt); | 508 | GNUNET_free (stat_txt); |
534 | 509 | ||
535 | if (GNUNET_YES == s->put_tmp_disconnecting) | 510 | if (GNUNET_YES == s->put_tmp_disconnecting) |
@@ -585,8 +560,11 @@ client_delete_session (struct Session *s) | |||
585 | struct HTTP_Message *pos; | 560 | struct HTTP_Message *pos; |
586 | struct HTTP_Message *next; | 561 | struct HTTP_Message *next; |
587 | 562 | ||
588 | client_stop_session_timeout (s); | 563 | if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task) |
589 | 564 | { | |
565 | GNUNET_SCHEDULER_cancel (s->timeout_task); | ||
566 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
567 | } | ||
590 | if (GNUNET_SCHEDULER_NO_TASK != s->put_disconnect_task) | 568 | if (GNUNET_SCHEDULER_NO_TASK != s->put_disconnect_task) |
591 | { | 569 | { |
592 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); | 570 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); |
@@ -618,7 +596,6 @@ client_delete_session (struct Session *s) | |||
618 | } | 596 | } |
619 | 597 | ||
620 | 598 | ||
621 | |||
622 | /** | 599 | /** |
623 | * Disconnect a session | 600 | * Disconnect a session |
624 | * | 601 | * |
@@ -780,10 +757,13 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin, | |||
780 | return NULL; | 757 | return NULL; |
781 | } | 758 | } |
782 | 759 | ||
760 | |||
783 | static void | 761 | static void |
784 | client_put_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 762 | client_put_disconnect (void *cls, |
763 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
785 | { | 764 | { |
786 | struct Session *s = cls; | 765 | struct Session *s = cls; |
766 | |||
787 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; | 767 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; |
788 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 768 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
789 | "Session %p/connection %p: will be disconnected due to no activity\n", | 769 | "Session %p/connection %p: will be disconnected due to no activity\n", |
@@ -795,7 +775,6 @@ client_put_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
795 | } | 775 | } |
796 | 776 | ||
797 | 777 | ||
798 | |||
799 | /** | 778 | /** |
800 | * Callback method used with libcurl | 779 | * Callback method used with libcurl |
801 | * Method is called when libcurl needs to read data during sending | 780 | * Method is called when libcurl needs to read data during sending |
@@ -803,7 +782,7 @@ client_put_disconnect (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
803 | * @param stream pointer where to write data | 782 | * @param stream pointer where to write data |
804 | * @param size size of an individual element | 783 | * @param size size of an individual element |
805 | * @param nmemb count of elements that can be written to the buffer | 784 | * @param nmemb count of elements that can be written to the buffer |
806 | * @param cls source pointer, passed to the libcurl handle | 785 | * @param cls our `struct Session` |
807 | * @return bytes written to stream, returning 0 will terminate connection! | 786 | * @return bytes written to stream, returning 0 will terminate connection! |
808 | */ | 787 | */ |
809 | static size_t | 788 | static size_t |
@@ -881,11 +860,13 @@ client_send_cb (void *stream, size_t size, size_t nmemb, void *cls) | |||
881 | * @param tc task context | 860 | * @param tc task context |
882 | */ | 861 | */ |
883 | static void | 862 | static void |
884 | client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 863 | client_wake_up (void *cls, |
864 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
885 | { | 865 | { |
886 | struct Session *s = cls; | 866 | struct Session *s = cls; |
867 | struct HTTP_Client_Plugin *p = s->plugin; | ||
887 | 868 | ||
888 | if (GNUNET_YES != client_exist_session(p, s)) | 869 | if (GNUNET_YES != client_exist_session (p, s)) |
889 | { | 870 | { |
890 | GNUNET_break (0); | 871 | GNUNET_break (0); |
891 | return; | 872 | return; |
@@ -894,7 +875,9 @@ client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
894 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 875 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
895 | return; | 876 | return; |
896 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 877 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
897 | "Session %p/connection %p: Waking up GET handle\n", s, s->client_get); | 878 | "Session %p/connection %p: Waking up GET handle\n", |
879 | s, | ||
880 | s->client_get); | ||
898 | if (s->client_get != NULL) | 881 | if (s->client_get != NULL) |
899 | curl_easy_pause (s->client_get, CURLPAUSE_CONT); | 882 | curl_easy_pause (s->client_get, CURLPAUSE_CONT); |
900 | } | 883 | } |
@@ -906,7 +889,7 @@ client_wake_up (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
906 | * @param cls the session | 889 | * @param cls the session |
907 | * @param client not used | 890 | * @param client not used |
908 | * @param message the message received | 891 | * @param message the message received |
909 | * @return always GNUNET_OK | 892 | * @return always #GNUNET_OK |
910 | */ | 893 | */ |
911 | static int | 894 | static int |
912 | client_receive_mst_cb (void *cls, void *client, | 895 | client_receive_mst_cb (void *cls, void *client, |
@@ -918,12 +901,12 @@ client_receive_mst_cb (void *cls, void *client, | |||
918 | struct GNUNET_ATS_Information atsi; | 901 | struct GNUNET_ATS_Information atsi; |
919 | char *stat_txt; | 902 | char *stat_txt; |
920 | 903 | ||
921 | if (GNUNET_YES != client_exist_session(p, s)) | 904 | plugin = s->plugin; |
905 | if (GNUNET_YES != client_exist_session (plugin, s)) | ||
922 | { | 906 | { |
923 | GNUNET_break (0); | 907 | GNUNET_break (0); |
924 | return GNUNET_OK; | 908 | return GNUNET_OK; |
925 | } | 909 | } |
926 | plugin = s->plugin; | ||
927 | 910 | ||
928 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); | 911 | atsi.type = htonl (GNUNET_ATS_NETWORK_TYPE); |
929 | atsi.value = s->ats_address_network_type; | 912 | atsi.value = s->ats_address_network_type; |
@@ -1042,7 +1025,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
1042 | * | 1025 | * |
1043 | * @param plugin the plugin as closure | 1026 | * @param plugin the plugin as closure |
1044 | * @param now schedule task in 1ms, regardless of what curl may say | 1027 | * @param now schedule task in 1ms, regardless of what curl may say |
1045 | * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok | 1028 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok |
1046 | */ | 1029 | */ |
1047 | static int | 1030 | static int |
1048 | client_schedule (struct HTTP_Client_Plugin *plugin, int now) | 1031 | client_schedule (struct HTTP_Client_Plugin *plugin, int now) |
@@ -1239,7 +1222,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1239 | * Connect GET connection for a session | 1222 | * Connect GET connection for a session |
1240 | * | 1223 | * |
1241 | * @param s the session to connect | 1224 | * @param s the session to connect |
1242 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | 1225 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
1243 | */ | 1226 | */ |
1244 | static int | 1227 | static int |
1245 | client_connect_get (struct Session *s) | 1228 | client_connect_get (struct Session *s) |
@@ -1257,17 +1240,17 @@ client_connect_get (struct Session *s) | |||
1257 | #endif | 1240 | #endif |
1258 | #if BUILD_HTTPS | 1241 | #if BUILD_HTTPS |
1259 | curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); | 1242 | curl_easy_setopt (s->client_get, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
1260 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == | 1243 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == |
1261 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) | 1244 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
1262 | { | 1245 | { |
1263 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L); | 1246 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 1L); |
1264 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L); | 1247 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 2L); |
1265 | } | 1248 | } |
1266 | else | 1249 | else |
1267 | { | 1250 | { |
1268 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); | 1251 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYPEER, 0); |
1269 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); | 1252 | curl_easy_setopt (s->client_get, CURLOPT_SSL_VERIFYHOST, 0); |
1270 | } | 1253 | } |
1271 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); | 1254 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); |
1272 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); | 1255 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); |
1273 | #else | 1256 | #else |
@@ -1297,9 +1280,10 @@ client_connect_get (struct Session *s) | |||
1297 | mret = curl_multi_add_handle (s->plugin->curl_multi_handle, s->client_get); | 1280 | mret = curl_multi_add_handle (s->plugin->curl_multi_handle, s->client_get); |
1298 | if (mret != CURLM_OK) | 1281 | if (mret != CURLM_OK) |
1299 | { | 1282 | { |
1300 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, | 1283 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, |
1301 | "Session %p : Failed to add GET handle to multihandle: `%s'\n", | 1284 | "Session %p : Failed to add GET handle to multihandle: `%s'\n", |
1302 | s, curl_multi_strerror (mret)); | 1285 | s, |
1286 | curl_multi_strerror (mret)); | ||
1303 | curl_easy_cleanup (s->client_get); | 1287 | curl_easy_cleanup (s->client_get); |
1304 | s->client_get = NULL; | 1288 | s->client_get = NULL; |
1305 | s->get.s = NULL; | 1289 | s->get.s = NULL; |
@@ -1311,19 +1295,21 @@ client_connect_get (struct Session *s) | |||
1311 | return GNUNET_OK; | 1295 | return GNUNET_OK; |
1312 | } | 1296 | } |
1313 | 1297 | ||
1298 | |||
1314 | /** | 1299 | /** |
1315 | * Connect a HTTP put connection | 1300 | * Connect a HTTP put connection |
1316 | * | 1301 | * |
1317 | * @param s the session to connect | 1302 | * @param s the session to connect |
1318 | * @return GNUNET_SYSERR for hard failure, GNUNET_OK for ok | 1303 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok |
1319 | */ | 1304 | */ |
1320 | static int | 1305 | static int |
1321 | client_connect_put (struct Session *s) | 1306 | client_connect_put (struct Session *s) |
1322 | { | 1307 | { |
1323 | CURLMcode mret; | 1308 | CURLMcode mret; |
1309 | |||
1324 | /* create put connection */ | 1310 | /* create put connection */ |
1325 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, | 1311 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, s->plugin->name, |
1326 | "Session %p : Init PUT handle \n", s); | 1312 | "Session %p : Init PUT handle\n", s); |
1327 | s->client_put = curl_easy_init (); | 1313 | s->client_put = curl_easy_init (); |
1328 | s->put.s = s; | 1314 | s->put.s = s; |
1329 | s->put.easyhandle = s->client_put; | 1315 | s->put.easyhandle = s->client_put; |
@@ -1334,17 +1320,17 @@ client_connect_put (struct Session *s) | |||
1334 | #endif | 1320 | #endif |
1335 | #if BUILD_HTTPS | 1321 | #if BUILD_HTTPS |
1336 | curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); | 1322 | curl_easy_setopt (s->client_put, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1); |
1337 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == | 1323 | if (HTTP_OPTIONS_VERIFY_CERTIFICATE == |
1338 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) | 1324 | (ntohl (s->addr->options) & HTTP_OPTIONS_VERIFY_CERTIFICATE)) |
1339 | { | 1325 | { |
1340 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L); | 1326 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 1L); |
1341 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L); | 1327 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 2L); |
1342 | } | 1328 | } |
1343 | else | 1329 | else |
1344 | { | 1330 | { |
1345 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); | 1331 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYPEER, 0); |
1346 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); | 1332 | curl_easy_setopt (s->client_put, CURLOPT_SSL_VERIFYHOST, 0); |
1347 | } | 1333 | } |
1348 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); | 1334 | curl_easy_setopt (s->client_get, CURLOPT_PROTOCOLS, CURLPROTO_HTTPS); |
1349 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); | 1335 | curl_easy_setopt (s->client_get, CURLOPT_REDIR_PROTOCOLS, CURLPROTO_HTTPS); |
1350 | #else | 1336 | #else |
@@ -1372,9 +1358,10 @@ client_connect_put (struct Session *s) | |||
1372 | mret = curl_multi_add_handle (s->plugin->curl_multi_handle, s->client_put); | 1358 | mret = curl_multi_add_handle (s->plugin->curl_multi_handle, s->client_put); |
1373 | if (mret != CURLM_OK) | 1359 | if (mret != CURLM_OK) |
1374 | { | 1360 | { |
1375 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, | 1361 | GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, s->plugin->name, |
1376 | "Session %p : Failed to add PUT handle to multihandle: `%s'\n", | 1362 | "Session %p : Failed to add PUT handle to multihandle: `%s'\n", |
1377 | s, curl_multi_strerror (mret)); | 1363 | s, |
1364 | curl_multi_strerror (mret)); | ||
1378 | curl_easy_cleanup (s->client_put); | 1365 | curl_easy_cleanup (s->client_put); |
1379 | s->client_put = NULL; | 1366 | s->client_put = NULL; |
1380 | s->put.easyhandle = NULL; | 1367 | s->put.easyhandle = NULL; |
@@ -1391,7 +1378,7 @@ client_connect_put (struct Session *s) | |||
1391 | * Connect both PUT and GET connection for a session | 1378 | * Connect both PUT and GET connection for a session |
1392 | * | 1379 | * |
1393 | * @param s the session to connect | 1380 | * @param s the session to connect |
1394 | * @return GNUNET_OK on success, GNUNET_SYSERR otherwise | 1381 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
1395 | */ | 1382 | */ |
1396 | static int | 1383 | static int |
1397 | client_connect (struct Session *s) | 1384 | client_connect (struct Session *s) |
@@ -1401,9 +1388,12 @@ client_connect (struct Session *s) | |||
1401 | int res = GNUNET_OK; | 1388 | int res = GNUNET_OK; |
1402 | 1389 | ||
1403 | /* create url */ | 1390 | /* create url */ |
1404 | if (NULL == http_common_plugin_address_to_string (NULL, plugin->protocol, s->addr, s->addrlen)) | 1391 | if (NULL == http_common_plugin_address_to_string (NULL, |
1392 | plugin->protocol, | ||
1393 | s->addr, s->addrlen)) | ||
1405 | { | 1394 | { |
1406 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1395 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1396 | plugin->name, | ||
1407 | "Invalid address peer `%s'\n", | 1397 | "Invalid address peer `%s'\n", |
1408 | GNUNET_i2s (&s->target)); | 1398 | GNUNET_i2s (&s->target)); |
1409 | return GNUNET_SYSERR; | 1399 | return GNUNET_SYSERR; |
@@ -1423,20 +1413,21 @@ client_connect (struct Session *s) | |||
1423 | if ((GNUNET_SYSERR == client_connect_get (s)) || | 1413 | if ((GNUNET_SYSERR == client_connect_get (s)) || |
1424 | (GNUNET_SYSERR == client_connect_put (s))) | 1414 | (GNUNET_SYSERR == client_connect_put (s))) |
1425 | { | 1415 | { |
1426 | GNUNET_break (0); | 1416 | GNUNET_break (0); |
1427 | return GNUNET_SYSERR; | 1417 | return GNUNET_SYSERR; |
1428 | } | 1418 | } |
1429 | 1419 | ||
1430 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1420 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, |
1431 | "Session %p: connected with connections GET %p and PUT %p\n", | 1421 | plugin->name, |
1432 | s, s->client_get, s->client_put); | 1422 | "Session %p: connected with connections GET %p and PUT %p\n", |
1423 | s, s->client_get, s->client_put); | ||
1433 | 1424 | ||
1434 | /* Perform connect */ | 1425 | /* Perform connect */ |
1435 | plugin->cur_connections += 2; | 1426 | plugin->cur_connections += 2; |
1436 | GNUNET_STATISTICS_set (plugin->env->stats, | 1427 | GNUNET_STATISTICS_set (plugin->env->stats, |
1437 | HTTP_STAT_STR_CONNECTIONS, | 1428 | HTTP_STAT_STR_CONNECTIONS, |
1438 | plugin->cur_connections, | 1429 | plugin->cur_connections, |
1439 | GNUNET_NO); | 1430 | GNUNET_NO); |
1440 | 1431 | ||
1441 | /* Re-schedule since handles have changed */ | 1432 | /* Re-schedule since handles have changed */ |
1442 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) | 1433 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1452,22 +1443,46 @@ client_connect (struct Session *s) | |||
1452 | /** | 1443 | /** |
1453 | * Function obtain the network type for a session | 1444 | * Function obtain the network type for a session |
1454 | * | 1445 | * |
1455 | * @param cls closure ('struct Plugin*') | 1446 | * @param cls closure (`struct Plugin*`) |
1456 | * @param session the session | 1447 | * @param session the session |
1457 | * @return the network type in HBO or GNUNET_SYSERR | 1448 | * @return the network type |
1458 | */ | 1449 | */ |
1459 | static enum GNUNET_ATS_Network_Type | 1450 | static enum GNUNET_ATS_Network_Type |
1460 | http_client_get_network (void *cls, | 1451 | http_client_get_network (void *cls, |
1461 | struct Session *session) | 1452 | struct Session *session) |
1462 | { | 1453 | { |
1463 | GNUNET_assert (NULL != session); | ||
1464 | return ntohl (session->ats_address_network_type); | 1454 | return ntohl (session->ats_address_network_type); |
1465 | } | 1455 | } |
1466 | 1456 | ||
1467 | 1457 | ||
1468 | /** | 1458 | /** |
1469 | * Creates a new outbound session the transport service will use to send data to the | 1459 | * Session was idle, so disconnect it |
1470 | * peer | 1460 | * |
1461 | * @param cls the `struct Session` of the idle session | ||
1462 | * @param tc scheduler context | ||
1463 | */ | ||
1464 | static void | ||
1465 | client_session_timeout (void *cls, | ||
1466 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1467 | { | ||
1468 | struct Session *s = cls; | ||
1469 | |||
1470 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1471 | GNUNET_log (TIMEOUT_LOG, | ||
1472 | "Session %p was idle for %s, disconnecting\n", | ||
1473 | s, | ||
1474 | GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, | ||
1475 | GNUNET_YES)); | ||
1476 | |||
1477 | /* call session destroy function */ | ||
1478 | GNUNET_assert (GNUNET_OK == http_client_session_disconnect (s->plugin, | ||
1479 | s)); | ||
1480 | } | ||
1481 | |||
1482 | |||
1483 | /** | ||
1484 | * Creates a new outbound session the transport service will use to | ||
1485 | * send data to the peer | ||
1471 | * | 1486 | * |
1472 | * @param cls the plugin | 1487 | * @param cls the plugin |
1473 | * @param address the address | 1488 | * @param address the address |
@@ -1475,7 +1490,7 @@ http_client_get_network (void *cls, | |||
1475 | */ | 1490 | */ |
1476 | static struct Session * | 1491 | static struct Session * |
1477 | http_client_plugin_get_session (void *cls, | 1492 | http_client_plugin_get_session (void *cls, |
1478 | const struct GNUNET_HELLO_Address *address) | 1493 | const struct GNUNET_HELLO_Address *address) |
1479 | { | 1494 | { |
1480 | struct HTTP_Client_Plugin *plugin = cls; | 1495 | struct HTTP_Client_Plugin *plugin = cls; |
1481 | struct Session * s = NULL; | 1496 | struct Session * s = NULL; |
@@ -1484,8 +1499,6 @@ http_client_plugin_get_session (void *cls, | |||
1484 | size_t salen = 0; | 1499 | size_t salen = 0; |
1485 | int res; | 1500 | int res; |
1486 | 1501 | ||
1487 | GNUNET_assert (plugin != NULL); | ||
1488 | GNUNET_assert (address != NULL); | ||
1489 | GNUNET_assert (address->address != NULL); | 1502 | GNUNET_assert (address->address != NULL); |
1490 | 1503 | ||
1491 | /* find existing session */ | 1504 | /* find existing session */ |
@@ -1509,34 +1522,32 @@ http_client_plugin_get_session (void *cls, | |||
1509 | sa = http_common_socket_from_address (address->address, address->address_length, &res); | 1522 | sa = http_common_socket_from_address (address->address, address->address_length, &res); |
1510 | if (GNUNET_SYSERR == res) | 1523 | if (GNUNET_SYSERR == res) |
1511 | { | 1524 | { |
1512 | return NULL; | 1525 | return NULL; |
1513 | } | 1526 | } |
1514 | else if (GNUNET_YES == res) | 1527 | else if (GNUNET_YES == res) |
1515 | { | 1528 | { |
1516 | GNUNET_assert (NULL != sa); | 1529 | GNUNET_assert (NULL != sa); |
1517 | if (AF_INET == sa->sa_family) | 1530 | if (AF_INET == sa->sa_family) |
1518 | { | 1531 | { |
1519 | salen = sizeof (struct sockaddr_in); | 1532 | salen = sizeof (struct sockaddr_in); |
1520 | } | 1533 | } |
1521 | else if (AF_INET6 == sa->sa_family) | 1534 | else if (AF_INET6 == sa->sa_family) |
1522 | { | 1535 | { |
1523 | salen = sizeof (struct sockaddr_in6); | 1536 | salen = sizeof (struct sockaddr_in6); |
1524 | } | 1537 | } |
1525 | ats = plugin->env->get_address_type (plugin->env->cls, sa, salen); | 1538 | ats = plugin->env->get_address_type (plugin->env->cls, sa, salen); |
1526 | //fprintf (stderr, "Address %s is in %s\n", GNUNET_a2s (sa,salen), GNUNET_ATS_print_network_type(ntohl(ats.value))); | 1539 | //fprintf (stderr, "Address %s is in %s\n", GNUNET_a2s (sa,salen), GNUNET_ATS_print_network_type(ntohl(ats.value))); |
1527 | GNUNET_free (sa); | 1540 | GNUNET_free (sa); |
1528 | } | 1541 | } |
1529 | |||
1530 | else if (GNUNET_NO == res) | 1542 | else if (GNUNET_NO == res) |
1531 | { | 1543 | { |
1532 | /* Cannot convert to sockaddr -> is external hostname */ | 1544 | /* Cannot convert to sockaddr -> is external hostname */ |
1533 | ats.value = htonl (GNUNET_ATS_NET_WAN); | 1545 | ats.value = htonl (GNUNET_ATS_NET_WAN); |
1534 | } | 1546 | } |
1535 | 1547 | if (GNUNET_ATS_NET_UNSPECIFIED == ntohl (ats.value)) | |
1536 | if (GNUNET_ATS_NET_UNSPECIFIED == ntohl(ats.value)) | ||
1537 | { | 1548 | { |
1538 | GNUNET_break (0); | 1549 | GNUNET_break (0); |
1539 | return NULL; | 1550 | return NULL; |
1540 | } | 1551 | } |
1541 | 1552 | ||
1542 | s = GNUNET_new (struct Session); | 1553 | s = GNUNET_new (struct Session); |
@@ -1549,8 +1560,9 @@ http_client_plugin_get_session (void *cls, | |||
1549 | s->put_paused = GNUNET_NO; | 1560 | s->put_paused = GNUNET_NO; |
1550 | s->put_tmp_disconnecting = GNUNET_NO; | 1561 | s->put_tmp_disconnecting = GNUNET_NO; |
1551 | s->put_tmp_disconnected = GNUNET_NO; | 1562 | s->put_tmp_disconnected = GNUNET_NO; |
1552 | client_start_session_timeout (s); | 1563 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, |
1553 | 1564 | &client_session_timeout, | |
1565 | s); | ||
1554 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, | 1566 | GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, plugin->name, |
1555 | "Created new session %p for `%s' address `%s''\n", | 1567 | "Created new session %p for `%s' address `%s''\n", |
1556 | s, | 1568 | s, |
@@ -1596,48 +1608,6 @@ client_start (struct HTTP_Client_Plugin *plugin) | |||
1596 | return GNUNET_OK; | 1608 | return GNUNET_OK; |
1597 | } | 1609 | } |
1598 | 1610 | ||
1599 | /** | ||
1600 | * Session was idle, so disconnect it | ||
1601 | */ | ||
1602 | static void | ||
1603 | client_session_timeout (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1604 | { | ||
1605 | struct Session *s = cls; | ||
1606 | |||
1607 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1608 | GNUNET_log (TIMEOUT_LOG, | ||
1609 | "Session %p was idle for %s, disconnecting\n", | ||
1610 | s, | ||
1611 | GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, | ||
1612 | GNUNET_YES)); | ||
1613 | |||
1614 | /* call session destroy function */ | ||
1615 | GNUNET_assert (GNUNET_OK == http_client_session_disconnect (s->plugin, | ||
1616 | s)); | ||
1617 | } | ||
1618 | |||
1619 | |||
1620 | /** | ||
1621 | * Start session timeout for session s | ||
1622 | * | ||
1623 | * @param s the session | ||
1624 | */ | ||
1625 | static void | ||
1626 | client_start_session_timeout (struct Session *s) | ||
1627 | { | ||
1628 | |||
1629 | GNUNET_assert (NULL != s); | ||
1630 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK == s->timeout_task); | ||
1631 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, | ||
1632 | &client_session_timeout, | ||
1633 | s); | ||
1634 | GNUNET_log (TIMEOUT_LOG, | ||
1635 | "Timeout for session %p set to %s\n", | ||
1636 | s, | ||
1637 | GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, | ||
1638 | GNUNET_YES)); | ||
1639 | } | ||
1640 | |||
1641 | 1611 | ||
1642 | /** | 1612 | /** |
1643 | * Increment session timeout due to activity for session s | 1613 | * Increment session timeout due to activity for session s |
@@ -1647,38 +1617,16 @@ client_start_session_timeout (struct Session *s) | |||
1647 | static void | 1617 | static void |
1648 | client_reschedule_session_timeout (struct Session *s) | 1618 | client_reschedule_session_timeout (struct Session *s) |
1649 | { | 1619 | { |
1650 | 1620 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | |
1651 | GNUNET_assert (NULL != s); | 1621 | GNUNET_SCHEDULER_cancel (s->timeout_task); |
1652 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | 1622 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, |
1653 | 1623 | &client_session_timeout, | |
1654 | GNUNET_SCHEDULER_cancel (s->timeout_task); | 1624 | s); |
1655 | s->timeout_task = GNUNET_SCHEDULER_add_delayed (HTTP_CLIENT_SESSION_TIMEOUT, | 1625 | GNUNET_log (TIMEOUT_LOG, |
1656 | &client_session_timeout, | 1626 | "Timeout rescheduled for session %p set to %s\n", |
1657 | s); | 1627 | s, |
1658 | GNUNET_log (TIMEOUT_LOG, | 1628 | GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, |
1659 | "Timeout rescheduled for session %p set to %s\n", | 1629 | GNUNET_YES)); |
1660 | s, | ||
1661 | GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, | ||
1662 | GNUNET_YES)); | ||
1663 | } | ||
1664 | |||
1665 | |||
1666 | /** | ||
1667 | * Cancel timeout due to activity for session s | ||
1668 | * | ||
1669 | * param s the session | ||
1670 | */ | ||
1671 | static void | ||
1672 | client_stop_session_timeout (struct Session *s) | ||
1673 | { | ||
1674 | GNUNET_assert (NULL != s); | ||
1675 | |||
1676 | if (GNUNET_SCHEDULER_NO_TASK != s->timeout_task) | ||
1677 | { | ||
1678 | GNUNET_SCHEDULER_cancel (s->timeout_task); | ||
1679 | s->timeout_task = GNUNET_SCHEDULER_NO_TASK; | ||
1680 | GNUNET_log (TIMEOUT_LOG, "Timeout stopped for session %p\n", s); | ||
1681 | } | ||
1682 | } | 1630 | } |
1683 | 1631 | ||
1684 | 1632 | ||
@@ -1688,14 +1636,16 @@ client_stop_session_timeout (struct Session *s) | |||
1688 | * address. If so, consider adding it to the list | 1636 | * address. If so, consider adding it to the list |
1689 | * of addresses. | 1637 | * of addresses. |
1690 | * | 1638 | * |
1691 | * @param cls closure | 1639 | * @param cls closure with the `struct Plugin` |
1692 | * @param addr pointer to the address | 1640 | * @param addr pointer to the address |
1693 | * @param addrlen length of addr | 1641 | * @param addrlen length of @a addr |
1694 | * @return GNUNET_OK if this is a plausible address for this peer | 1642 | * @return #GNUNET_OK if this is a plausible address for this peer |
1695 | * and transport | 1643 | * and transport; always returns #GNUNET_NO (this is the client!) |
1696 | */ | 1644 | */ |
1697 | static int | 1645 | static int |
1698 | http_client_plugin_address_suggested (void *cls, const void *addr, size_t addrlen) | 1646 | http_client_plugin_address_suggested (void *cls, |
1647 | const void *addr, | ||
1648 | size_t addrlen) | ||
1699 | { | 1649 | { |
1700 | /* struct Plugin *plugin = cls; */ | 1650 | /* struct Plugin *plugin = cls; */ |
1701 | 1651 | ||
@@ -1817,7 +1767,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1817 | } | 1767 | } |
1818 | 1768 | ||
1819 | plugin = GNUNET_new (struct HTTP_Client_Plugin); | 1769 | plugin = GNUNET_new (struct HTTP_Client_Plugin); |
1820 | p = plugin; | ||
1821 | plugin->env = env; | 1770 | plugin->env = env; |
1822 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 1771 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
1823 | api->cls = plugin; | 1772 | api->cls = plugin; |
@@ -1843,15 +1792,15 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
1843 | 1792 | ||
1844 | if (GNUNET_SYSERR == client_configure_plugin (plugin)) | 1793 | if (GNUNET_SYSERR == client_configure_plugin (plugin)) |
1845 | { | 1794 | { |
1846 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); | 1795 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); |
1847 | return NULL; | 1796 | return NULL; |
1848 | } | 1797 | } |
1849 | 1798 | ||
1850 | /* Start client */ | 1799 | /* Start client */ |
1851 | if (GNUNET_SYSERR == client_start (plugin)) | 1800 | if (GNUNET_SYSERR == client_start (plugin)) |
1852 | { | 1801 | { |
1853 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); | 1802 | LIBGNUNET_PLUGIN_TRANSPORT_DONE (api); |
1854 | return NULL; | 1803 | return NULL; |
1855 | } | 1804 | } |
1856 | return api; | 1805 | return api; |
1857 | } | 1806 | } |