diff options
author | Christian Grothoff <christian@grothoff.org> | 2014-06-23 19:58:56 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2014-06-23 19:58:56 +0000 |
commit | b469a43110fd4c08e61530324fc0cec02fa7162b (patch) | |
tree | 1f1d5f72e71c3ef686f8bf732ba0aee8519f2063 /src/transport/plugin_transport_http_client.c | |
parent | f874eb3423cde2257d57c0f5d651297b303b3cff (diff) | |
download | gnunet-b469a43110fd4c08e61530324fc0cec02fa7162b.tar.gz gnunet-b469a43110fd4c08e61530324fc0cec02fa7162b.zip |
-add support for 'update_inbound_delay' to HTTP client, complete plugin monitoring implementation
Diffstat (limited to 'src/transport/plugin_transport_http_client.c')
-rw-r--r-- | src/transport/plugin_transport_http_client.c | 226 |
1 files changed, 148 insertions, 78 deletions
diff --git a/src/transport/plugin_transport_http_client.c b/src/transport/plugin_transport_http_client.c index d66d8c940..efcfcb1c3 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-2013 Christian Grothoff (and other contributing authors) | 3 | (C) 2002-2014 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 |
@@ -22,6 +22,7 @@ | |||
22 | * @file transport/plugin_transport_http_client.c | 22 | * @file transport/plugin_transport_http_client.c |
23 | * @brief HTTP/S client transport plugin | 23 | * @brief HTTP/S client transport plugin |
24 | * @author Matthias Wachs | 24 | * @author Matthias Wachs |
25 | * @author Christian Grothoff | ||
25 | */ | 26 | */ |
26 | 27 | ||
27 | #if BUILD_HTTPS | 28 | #if BUILD_HTTPS |
@@ -237,7 +238,7 @@ struct Session | |||
237 | uint32_t ats_address_network_type; | 238 | uint32_t ats_address_network_type; |
238 | 239 | ||
239 | /** | 240 | /** |
240 | * Is the client PUT handle currently paused | 241 | * Is the client PUT handle currently paused? |
241 | */ | 242 | */ |
242 | int put_paused; | 243 | int put_paused; |
243 | 244 | ||
@@ -394,9 +395,7 @@ notify_session_monitor (struct HTTP_Client_Plugin *plugin, | |||
394 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ | 395 | info.is_inbound = GNUNET_SYSERR; /* hard to say */ |
395 | info.num_msg_pending = session->msgs_in_queue; | 396 | info.num_msg_pending = session->msgs_in_queue; |
396 | info.num_bytes_pending = session->bytes_in_queue; | 397 | info.num_bytes_pending = session->bytes_in_queue; |
397 | /* info.receive_delay remains zero as this is not supported by UDP | 398 | info.receive_delay = session->next_receive; |
398 | (cannot selectively not receive from 'some' peer while continuing | ||
399 | to receive from others) */ | ||
400 | info.session_timeout = session->timeout; | 399 | info.session_timeout = session->timeout; |
401 | info.address = session->address; | 400 | info.address = session->address; |
402 | plugin->sic (plugin->sic_cls, | 401 | plugin->sic (plugin->sic_cls, |
@@ -406,11 +405,16 @@ notify_session_monitor (struct HTTP_Client_Plugin *plugin, | |||
406 | 405 | ||
407 | 406 | ||
408 | /** | 407 | /** |
409 | * Increment session timeout due to activity for a session | 408 | * Increment session timeout due to activity for session @a s. |
409 | * | ||
410 | * @param s the session | 410 | * @param s the session |
411 | */ | 411 | */ |
412 | static void | 412 | static void |
413 | client_reschedule_session_timeout (struct Session *s); | 413 | client_reschedule_session_timeout (struct Session *s) |
414 | { | ||
415 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | ||
416 | s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
417 | } | ||
414 | 418 | ||
415 | 419 | ||
416 | /** | 420 | /** |
@@ -564,7 +568,9 @@ http_client_plugin_send (void *cls, | |||
564 | GNUNET_STATISTICS_update (plugin->env->stats, | 568 | GNUNET_STATISTICS_update (plugin->env->stats, |
565 | stat_txt, msgbuf_size, GNUNET_NO); | 569 | stat_txt, msgbuf_size, GNUNET_NO); |
566 | GNUNET_free (stat_txt); | 570 | GNUNET_free (stat_txt); |
567 | 571 | notify_session_monitor (plugin, | |
572 | s, | ||
573 | GNUNET_TRANSPORT_SS_UP); | ||
568 | if (GNUNET_YES == s->put_tmp_disconnecting) | 574 | if (GNUNET_YES == s->put_tmp_disconnecting) |
569 | { | 575 | { |
570 | /* PUT connection is currently getting disconnected */ | 576 | /* PUT connection is currently getting disconnected */ |
@@ -597,12 +603,10 @@ http_client_plugin_send (void *cls, | |||
597 | s->put_tmp_disconnected = GNUNET_NO; | 603 | s->put_tmp_disconnected = GNUNET_NO; |
598 | GNUNET_break (s->client_put == NULL); | 604 | GNUNET_break (s->client_put == NULL); |
599 | if (GNUNET_SYSERR == client_connect_put (s)) | 605 | if (GNUNET_SYSERR == client_connect_put (s)) |
600 | { | ||
601 | return GNUNET_SYSERR; | 606 | return GNUNET_SYSERR; |
602 | } | ||
603 | } | 607 | } |
604 | 608 | client_schedule (s->plugin, | |
605 | client_schedule (s->plugin, GNUNET_YES); | 609 | GNUNET_YES); |
606 | return msgbuf_size; | 610 | return msgbuf_size; |
607 | } | 611 | } |
608 | 612 | ||
@@ -655,7 +659,11 @@ client_delete_session (struct Session *s) | |||
655 | s->overhead = 0; | 659 | s->overhead = 0; |
656 | GNUNET_free (pos); | 660 | GNUNET_free (pos); |
657 | } | 661 | } |
658 | 662 | GNUNET_assert (0 == s->msgs_in_queue); | |
663 | GNUNET_assert (0 == s->bytes_in_queue); | ||
664 | notify_session_monitor (plugin, | ||
665 | s, | ||
666 | GNUNET_TRANSPORT_SS_DOWN); | ||
659 | if (NULL != s->msg_tk) | 667 | if (NULL != s->msg_tk) |
660 | { | 668 | { |
661 | GNUNET_SERVER_mst_destroy (s->msg_tk); | 669 | GNUNET_SERVER_mst_destroy (s->msg_tk); |
@@ -675,8 +683,8 @@ client_delete_session (struct Session *s) | |||
675 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error | 683 | * @return #GNUNET_OK on success, #GNUNET_SYSERR on error |
676 | */ | 684 | */ |
677 | static int | 685 | static int |
678 | http_client_session_disconnect (void *cls, | 686 | http_client_plugin_session_disconnect (void *cls, |
679 | struct Session *s) | 687 | struct Session *s) |
680 | { | 688 | { |
681 | struct HTTP_Client_Plugin *plugin = cls; | 689 | struct HTTP_Client_Plugin *plugin = cls; |
682 | struct HTTP_Message *msg; | 690 | struct HTTP_Message *msg; |
@@ -688,7 +696,9 @@ http_client_session_disconnect (void *cls, | |||
688 | { | 696 | { |
689 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 697 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
690 | "Session %p/connection %p: disconnecting PUT connection to peer `%s'\n", | 698 | "Session %p/connection %p: disconnecting PUT connection to peer `%s'\n", |
691 | s, s->client_put, GNUNET_i2s (&s->target)); | 699 | s, |
700 | s->client_put, | ||
701 | GNUNET_i2s (&s->target)); | ||
692 | 702 | ||
693 | /* remove curl handle from multi handle */ | 703 | /* remove curl handle from multi handle */ |
694 | mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_put); | 704 | mret = curl_multi_remove_handle (plugin->curl_multi_handle, s->client_put); |
@@ -801,7 +811,7 @@ destroy_session_cb (void *cls, | |||
801 | struct HTTP_Client_Plugin *plugin = cls; | 811 | struct HTTP_Client_Plugin *plugin = cls; |
802 | struct Session *session = value; | 812 | struct Session *session = value; |
803 | 813 | ||
804 | http_client_session_disconnect (plugin, session); | 814 | http_client_plugin_session_disconnect (plugin, session); |
805 | return GNUNET_OK; | 815 | return GNUNET_OK; |
806 | } | 816 | } |
807 | 817 | ||
@@ -815,8 +825,8 @@ destroy_session_cb (void *cls, | |||
815 | * @param target peer from which to disconnect | 825 | * @param target peer from which to disconnect |
816 | */ | 826 | */ |
817 | static void | 827 | static void |
818 | http_client_peer_disconnect (void *cls, | 828 | http_client_plugin_peer_disconnect (void *cls, |
819 | const struct GNUNET_PeerIdentity *target) | 829 | const struct GNUNET_PeerIdentity *target) |
820 | { | 830 | { |
821 | struct HTTP_Client_Plugin *plugin = cls; | 831 | struct HTTP_Client_Plugin *plugin = cls; |
822 | 832 | ||
@@ -896,7 +906,12 @@ client_lookup_session (struct HTTP_Client_Plugin *plugin, | |||
896 | 906 | ||
897 | 907 | ||
898 | /** | 908 | /** |
899 | * FIXME. | 909 | * When we have nothing to transmit, we pause the HTTP PUT |
910 | * after a while (so that gnurl stops asking). This task | ||
911 | * is the delayed task that actually pauses the PUT. | ||
912 | * | ||
913 | * @param cls the `struct Session *` with the put | ||
914 | * @param tc scheduler context | ||
900 | */ | 915 | */ |
901 | static void | 916 | static void |
902 | client_put_disconnect (void *cls, | 917 | client_put_disconnect (void *cls, |
@@ -952,7 +967,9 @@ client_send_cb (void *stream, | |||
952 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 967 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
953 | "Session %p/connection %p: nothing to send, suspending\n", | 968 | "Session %p/connection %p: nothing to send, suspending\n", |
954 | s, s->client_put); | 969 | s, s->client_put); |
955 | s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, &client_put_disconnect, s); | 970 | s->put_disconnect_task = GNUNET_SCHEDULER_add_delayed (PUT_DISCONNECT_TIMEOUT, |
971 | &client_put_disconnect, | ||
972 | s); | ||
956 | s->put_paused = GNUNET_YES; | 973 | s->put_paused = GNUNET_YES; |
957 | return CURL_READFUNC_PAUSE; | 974 | return CURL_READFUNC_PAUSE; |
958 | } | 975 | } |
@@ -985,6 +1002,9 @@ client_send_cb (void *stream, | |||
985 | s->overhead = 0; | 1002 | s->overhead = 0; |
986 | GNUNET_free (msg); | 1003 | GNUNET_free (msg); |
987 | } | 1004 | } |
1005 | notify_session_monitor (plugin, | ||
1006 | s, | ||
1007 | GNUNET_TRANSPORT_SS_UP); | ||
988 | GNUNET_asprintf (&stat_txt, | 1008 | GNUNET_asprintf (&stat_txt, |
989 | "# bytes currently in %s_client buffers", | 1009 | "# bytes currently in %s_client buffers", |
990 | plugin->protocol); | 1010 | plugin->protocol); |
@@ -1024,10 +1044,19 @@ client_wake_up (void *cls, | |||
1024 | "Session %p/connection %p: Waking up GET handle\n", | 1044 | "Session %p/connection %p: Waking up GET handle\n", |
1025 | s, | 1045 | s, |
1026 | s->client_get); | 1046 | s->client_get); |
1027 | s->put_paused = GNUNET_NO; | 1047 | if (GNUNET_YES == s->put_paused) |
1048 | { | ||
1049 | /* PUT connection was paused, unpause */ | ||
1050 | GNUNET_assert (s->put_disconnect_task != GNUNET_SCHEDULER_NO_TASK); | ||
1051 | GNUNET_SCHEDULER_cancel (s->put_disconnect_task); | ||
1052 | s->put_disconnect_task = GNUNET_SCHEDULER_NO_TASK; | ||
1053 | s->put_paused = GNUNET_NO; | ||
1054 | if (NULL != s->client_put) | ||
1055 | curl_easy_pause (s->client_put, CURLPAUSE_CONT); | ||
1056 | } | ||
1028 | if (NULL != s->client_get) | 1057 | if (NULL != s->client_get) |
1029 | curl_easy_pause (s->client_get, CURLPAUSE_CONT); | 1058 | curl_easy_pause (s->client_get, |
1030 | 1059 | CURLPAUSE_CONT); | |
1031 | } | 1060 | } |
1032 | 1061 | ||
1033 | 1062 | ||
@@ -1055,7 +1084,10 @@ client_receive_mst_cb (void *cls, | |||
1055 | atsi.value = s->ats_address_network_type; | 1084 | atsi.value = s->ats_address_network_type; |
1056 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); | 1085 | GNUNET_break (s->ats_address_network_type != ntohl (GNUNET_ATS_NET_UNSPECIFIED)); |
1057 | 1086 | ||
1058 | delay = s->plugin->env->receive (plugin->env->cls, s->address, s, message); | 1087 | delay = s->plugin->env->receive (plugin->env->cls, |
1088 | s->address, | ||
1089 | s, | ||
1090 | message); | ||
1059 | plugin->env->update_address_metrics (plugin->env->cls, | 1091 | plugin->env->update_address_metrics (plugin->env->cls, |
1060 | s->address, s, | 1092 | s->address, s, |
1061 | &atsi, 1); | 1093 | &atsi, 1); |
@@ -1064,12 +1096,12 @@ client_receive_mst_cb (void *cls, | |||
1064 | "# bytes received via %s_client", | 1096 | "# bytes received via %s_client", |
1065 | plugin->protocol); | 1097 | plugin->protocol); |
1066 | GNUNET_STATISTICS_update (plugin->env->stats, | 1098 | GNUNET_STATISTICS_update (plugin->env->stats, |
1067 | stat_txt, ntohs(message->size), GNUNET_NO); | 1099 | stat_txt, |
1100 | ntohs (message->size), | ||
1101 | GNUNET_NO); | ||
1068 | GNUNET_free (stat_txt); | 1102 | GNUNET_free (stat_txt); |
1069 | 1103 | ||
1070 | s->next_receive = | 1104 | s->next_receive = GNUNET_TIME_relative_to_absolute (delay); |
1071 | GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), delay); | ||
1072 | |||
1073 | if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us) | 1105 | if (GNUNET_TIME_absolute_get ().abs_value_us < s->next_receive.abs_value_us) |
1074 | { | 1106 | { |
1075 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1107 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1117,7 +1149,10 @@ client_receive_put (void *stream, | |||
1117 | * @return bytes read from stream | 1149 | * @return bytes read from stream |
1118 | */ | 1150 | */ |
1119 | static size_t | 1151 | static size_t |
1120 | client_receive (void *stream, size_t size, size_t nmemb, void *cls) | 1152 | client_receive (void *stream, |
1153 | size_t size, | ||
1154 | size_t nmemb, | ||
1155 | void *cls) | ||
1121 | { | 1156 | { |
1122 | struct Session *s = cls; | 1157 | struct Session *s = cls; |
1123 | struct GNUNET_TIME_Absolute now; | 1158 | struct GNUNET_TIME_Absolute now; |
@@ -1131,11 +1166,13 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) | |||
1131 | if (now.abs_value_us < s->next_receive.abs_value_us) | 1166 | if (now.abs_value_us < s->next_receive.abs_value_us) |
1132 | { | 1167 | { |
1133 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); | 1168 | struct GNUNET_TIME_Absolute now = GNUNET_TIME_absolute_get (); |
1134 | struct GNUNET_TIME_Relative delta = | 1169 | struct GNUNET_TIME_Relative delta |
1135 | GNUNET_TIME_absolute_get_difference (now, s->next_receive); | 1170 | = GNUNET_TIME_absolute_get_difference (now, s->next_receive); |
1171 | |||
1136 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1172 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1137 | "Session %p / connection %p: No inbound bandwidth available! Next read was delayed for %s\n", | 1173 | "Session %p / connection %p: No inbound bandwidth available! Next read was delayed for %s\n", |
1138 | s, s->client_get, | 1174 | s, |
1175 | s->client_get, | ||
1139 | GNUNET_STRINGS_relative_time_to_string (delta, | 1176 | GNUNET_STRINGS_relative_time_to_string (delta, |
1140 | GNUNET_YES)); | 1177 | GNUNET_YES)); |
1141 | if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) | 1178 | if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) |
@@ -1143,13 +1180,21 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) | |||
1143 | GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); | 1180 | GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); |
1144 | s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; | 1181 | s->recv_wakeup_task = GNUNET_SCHEDULER_NO_TASK; |
1145 | } | 1182 | } |
1146 | s->recv_wakeup_task = | 1183 | s->recv_wakeup_task |
1147 | GNUNET_SCHEDULER_add_delayed (delta, &client_wake_up, s); | 1184 | = GNUNET_SCHEDULER_add_delayed (delta, |
1185 | &client_wake_up, | ||
1186 | s); | ||
1148 | return CURL_WRITEFUNC_PAUSE; | 1187 | return CURL_WRITEFUNC_PAUSE; |
1149 | } | 1188 | } |
1150 | if (NULL == s->msg_tk) | 1189 | if (NULL == s->msg_tk) |
1151 | s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, s); | 1190 | s->msg_tk = GNUNET_SERVER_mst_create (&client_receive_mst_cb, |
1152 | GNUNET_SERVER_mst_receive (s->msg_tk, s, stream, len, GNUNET_NO, GNUNET_NO); | 1191 | s); |
1192 | GNUNET_SERVER_mst_receive (s->msg_tk, | ||
1193 | s, | ||
1194 | stream, | ||
1195 | len, | ||
1196 | GNUNET_NO, | ||
1197 | GNUNET_NO); | ||
1153 | return len; | 1198 | return len; |
1154 | } | 1199 | } |
1155 | 1200 | ||
@@ -1161,7 +1206,8 @@ client_receive (void *stream, size_t size, size_t nmemb, void *cls) | |||
1161 | * @param tc gnunet scheduler task context | 1206 | * @param tc gnunet scheduler task context |
1162 | */ | 1207 | */ |
1163 | static void | 1208 | static void |
1164 | client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 1209 | client_run (void *cls, |
1210 | const struct GNUNET_SCHEDULER_TaskContext *tc); | ||
1165 | 1211 | ||
1166 | 1212 | ||
1167 | /** | 1213 | /** |
@@ -1172,7 +1218,8 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
1172 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok | 1218 | * @return #GNUNET_SYSERR for hard failure, #GNUNET_OK for ok |
1173 | */ | 1219 | */ |
1174 | static int | 1220 | static int |
1175 | client_schedule (struct HTTP_Client_Plugin *plugin, int now) | 1221 | client_schedule (struct HTTP_Client_Plugin *plugin, |
1222 | int now) | ||
1176 | { | 1223 | { |
1177 | fd_set rs; | 1224 | fd_set rs; |
1178 | fd_set ws; | 1225 | fd_set ws; |
@@ -1212,7 +1259,8 @@ client_schedule (struct HTTP_Client_Plugin *plugin, int now) | |||
1212 | 1259 | ||
1213 | if (mret != CURLM_OK) | 1260 | if (mret != CURLM_OK) |
1214 | { | 1261 | { |
1215 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"), | 1262 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
1263 | _("%s failed at %s:%d: `%s'\n"), | ||
1216 | "curl_multi_timeout", __FILE__, __LINE__, | 1264 | "curl_multi_timeout", __FILE__, __LINE__, |
1217 | curl_multi_strerror (mret)); | 1265 | curl_multi_strerror (mret)); |
1218 | return GNUNET_SYSERR; | 1266 | return GNUNET_SYSERR; |
@@ -1237,18 +1285,17 @@ client_schedule (struct HTTP_Client_Plugin *plugin, int now) | |||
1237 | * Task performing curl operations | 1285 | * Task performing curl operations |
1238 | * | 1286 | * |
1239 | * @param cls plugin as closure | 1287 | * @param cls plugin as closure |
1240 | * @param tc gnunet scheduler task context | 1288 | * @param tc scheduler task context |
1241 | */ | 1289 | */ |
1242 | static void | 1290 | static void |
1243 | client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | 1291 | client_run (void *cls, |
1292 | const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
1244 | { | 1293 | { |
1245 | struct HTTP_Client_Plugin *plugin = cls; | 1294 | struct HTTP_Client_Plugin *plugin = cls; |
1246 | int running; | 1295 | int running; |
1247 | long http_statuscode; | 1296 | long http_statuscode; |
1248 | CURLMcode mret; | 1297 | CURLMcode mret; |
1249 | 1298 | ||
1250 | GNUNET_assert (cls != NULL); | ||
1251 | |||
1252 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; | 1299 | plugin->client_perform_task = GNUNET_SCHEDULER_NO_TASK; |
1253 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) | 1300 | if (0 != (tc->reason & GNUNET_SCHEDULER_REASON_SHUTDOWN)) |
1254 | return; | 1301 | return; |
@@ -1267,7 +1314,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1267 | struct Session *s = NULL; | 1314 | struct Session *s = NULL; |
1268 | char *d = (char *) s; | 1315 | char *d = (char *) s; |
1269 | 1316 | ||
1270 | if (easy_h == NULL) | 1317 | if (NULL == easy_h) |
1271 | { | 1318 | { |
1272 | GNUNET_break (0); | 1319 | GNUNET_break (0); |
1273 | LOG (GNUNET_ERROR_TYPE_DEBUG, | 1320 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
@@ -1353,7 +1400,7 @@ client_run (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
1353 | /* Disconnect other transmission direction and tell transport */ | 1400 | /* Disconnect other transmission direction and tell transport */ |
1354 | s->get.easyhandle = NULL; | 1401 | s->get.easyhandle = NULL; |
1355 | s->get.s = NULL; | 1402 | s->get.s = NULL; |
1356 | http_client_session_disconnect (plugin, s); | 1403 | http_client_plugin_session_disconnect (plugin, s); |
1357 | } | 1404 | } |
1358 | } | 1405 | } |
1359 | } | 1406 | } |
@@ -1568,7 +1615,6 @@ client_connect_put (struct Session *s) | |||
1568 | static int | 1615 | static int |
1569 | client_connect (struct Session *s) | 1616 | client_connect (struct Session *s) |
1570 | { | 1617 | { |
1571 | |||
1572 | struct HTTP_Client_Plugin *plugin = s->plugin; | 1618 | struct HTTP_Client_Plugin *plugin = s->plugin; |
1573 | int res = GNUNET_OK; | 1619 | int res = GNUNET_OK; |
1574 | 1620 | ||
@@ -1584,8 +1630,9 @@ client_connect (struct Session *s) | |||
1584 | } | 1630 | } |
1585 | 1631 | ||
1586 | GNUNET_asprintf (&s->url, "%s/%s;%u", | 1632 | GNUNET_asprintf (&s->url, "%s/%s;%u", |
1587 | http_common_plugin_address_to_url (NULL, s->address->address, | 1633 | http_common_plugin_address_to_url (NULL, |
1588 | s->address->address_length), | 1634 | s->address->address, |
1635 | s->address->address_length), | ||
1589 | GNUNET_i2s_full (plugin->env->my_identity), | 1636 | GNUNET_i2s_full (plugin->env->my_identity), |
1590 | plugin->last_tag); | 1637 | plugin->last_tag); |
1591 | 1638 | ||
@@ -1613,7 +1660,6 @@ client_connect (struct Session *s) | |||
1613 | HTTP_STAT_STR_CONNECTIONS, | 1660 | HTTP_STAT_STR_CONNECTIONS, |
1614 | plugin->cur_connections, | 1661 | plugin->cur_connections, |
1615 | GNUNET_NO); | 1662 | GNUNET_NO); |
1616 | |||
1617 | /* Re-schedule since handles have changed */ | 1663 | /* Re-schedule since handles have changed */ |
1618 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) | 1664 | if (plugin->client_perform_task != GNUNET_SCHEDULER_NO_TASK) |
1619 | { | 1665 | { |
@@ -1633,8 +1679,8 @@ client_connect (struct Session *s) | |||
1633 | * @return the network type | 1679 | * @return the network type |
1634 | */ | 1680 | */ |
1635 | static enum GNUNET_ATS_Network_Type | 1681 | static enum GNUNET_ATS_Network_Type |
1636 | http_client_get_network (void *cls, | 1682 | http_client_plugin_get_network (void *cls, |
1637 | struct Session *session) | 1683 | struct Session *session) |
1638 | { | 1684 | { |
1639 | return ntohl (session->ats_address_network_type); | 1685 | return ntohl (session->ats_address_network_type); |
1640 | } | 1686 | } |
@@ -1673,7 +1719,7 @@ client_session_timeout (void *cls, | |||
1673 | GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, | 1719 | GNUNET_STRINGS_relative_time_to_string (HTTP_CLIENT_SESSION_TIMEOUT, |
1674 | GNUNET_YES)); | 1720 | GNUNET_YES)); |
1675 | GNUNET_assert (GNUNET_OK == | 1721 | GNUNET_assert (GNUNET_OK == |
1676 | http_client_session_disconnect (s->plugin, | 1722 | http_client_plugin_session_disconnect (s->plugin, |
1677 | s)); | 1723 | s)); |
1678 | } | 1724 | } |
1679 | 1725 | ||
@@ -1732,7 +1778,6 @@ http_client_plugin_get_session (void *cls, | |||
1732 | salen = sizeof (struct sockaddr_in6); | 1778 | salen = sizeof (struct sockaddr_in6); |
1733 | } | 1779 | } |
1734 | ats = plugin->env->get_address_type (plugin->env->cls, sa, salen); | 1780 | ats = plugin->env->get_address_type (plugin->env->cls, sa, salen); |
1735 | //fprintf (stderr, "Address %s is in %s\n", GNUNET_a2s (sa,salen), GNUNET_ATS_print_network_type(ntohl(ats.value))); | ||
1736 | GNUNET_free (sa); | 1781 | GNUNET_free (sa); |
1737 | } | 1782 | } |
1738 | else if (GNUNET_NO == res) | 1783 | else if (GNUNET_NO == res) |
@@ -1783,6 +1828,9 @@ http_client_plugin_get_session (void *cls, | |||
1783 | client_delete_session (s); | 1828 | client_delete_session (s); |
1784 | return NULL; | 1829 | return NULL; |
1785 | } | 1830 | } |
1831 | notify_session_monitor (plugin, | ||
1832 | s, | ||
1833 | GNUNET_TRANSPORT_SS_UP); /* or handshake? */ | ||
1786 | return s; | 1834 | return s; |
1787 | } | 1835 | } |
1788 | 1836 | ||
@@ -1811,19 +1859,6 @@ client_start (struct HTTP_Client_Plugin *plugin) | |||
1811 | 1859 | ||
1812 | 1860 | ||
1813 | /** | 1861 | /** |
1814 | * Increment session timeout due to activity for session @a s. | ||
1815 | * | ||
1816 | * @param s the session | ||
1817 | */ | ||
1818 | static void | ||
1819 | client_reschedule_session_timeout (struct Session *s) | ||
1820 | { | ||
1821 | GNUNET_assert (GNUNET_SCHEDULER_NO_TASK != s->timeout_task); | ||
1822 | s->timeout = GNUNET_TIME_relative_to_absolute (GNUNET_CONSTANTS_IDLE_CONNECTION_TIMEOUT); | ||
1823 | } | ||
1824 | |||
1825 | |||
1826 | /** | ||
1827 | * Another peer has suggested an address for this | 1862 | * Another peer has suggested an address for this |
1828 | * peer and transport plugin. Check that this could be a valid | 1863 | * peer and transport plugin. Check that this could be a valid |
1829 | * address. If so, consider adding it to the list | 1864 | * address. If so, consider adding it to the list |
@@ -1907,9 +1942,11 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) | |||
1907 | 1942 | ||
1908 | 1943 | ||
1909 | /* Optional parameters */ | 1944 | /* Optional parameters */ |
1910 | if (GNUNET_OK != GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, | 1945 | if (GNUNET_OK != |
1911 | plugin->name, | 1946 | GNUNET_CONFIGURATION_get_value_number (plugin->env->cfg, |
1912 | "MAX_CONNECTIONS", &max_connections)) | 1947 | plugin->name, |
1948 | "MAX_CONNECTIONS", | ||
1949 | &max_connections)) | ||
1913 | max_connections = 128; | 1950 | max_connections = 128; |
1914 | plugin->max_connections = max_connections; | 1951 | plugin->max_connections = max_connections; |
1915 | 1952 | ||
@@ -1990,14 +2027,15 @@ client_configure_plugin (struct HTTP_Client_Plugin *plugin) | |||
1990 | } | 2027 | } |
1991 | 2028 | ||
1992 | /* proxy http tunneling */ | 2029 | /* proxy http tunneling */ |
1993 | if (GNUNET_SYSERR == (plugin->proxy_use_httpproxytunnel = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, | 2030 | plugin->proxy_use_httpproxytunnel |
1994 | plugin->name, "PROXY_HTTP_TUNNELING"))) | 2031 | = GNUNET_CONFIGURATION_get_value_yesno (plugin->env->cfg, |
2032 | plugin->name, | ||
2033 | "PROXY_HTTP_TUNNELING"); | ||
2034 | if (GNUNET_SYSERR == plugin->proxy_use_httpproxytunnel) | ||
1995 | plugin->proxy_use_httpproxytunnel = GNUNET_NO; | 2035 | plugin->proxy_use_httpproxytunnel = GNUNET_NO; |
1996 | 2036 | ||
1997 | GNUNET_free_non_null (proxy_type); | 2037 | GNUNET_free_non_null (proxy_type); |
1998 | } | 2038 | } |
1999 | |||
2000 | |||
2001 | return GNUNET_OK; | 2039 | return GNUNET_OK; |
2002 | } | 2040 | } |
2003 | 2041 | ||
@@ -2046,6 +2084,38 @@ http_client_plugin_update_session_timeout (void *cls, | |||
2046 | 2084 | ||
2047 | 2085 | ||
2048 | /** | 2086 | /** |
2087 | * Function that will be called whenever the transport service wants to | ||
2088 | * notify the plugin that the inbound quota changed and that the plugin | ||
2089 | * should update it's delay for the next receive value | ||
2090 | * | ||
2091 | * @param cls closure | ||
2092 | * @param peer which peer was the session for | ||
2093 | * @param session which session is being updated | ||
2094 | * @param delay new delay to use for receiving | ||
2095 | */ | ||
2096 | static void | ||
2097 | http_client_plugin_update_inbound_delay (void *cls, | ||
2098 | const struct GNUNET_PeerIdentity *peer, | ||
2099 | struct Session *s, | ||
2100 | struct GNUNET_TIME_Relative delay) | ||
2101 | { | ||
2102 | s->next_receive = GNUNET_TIME_relative_to_absolute (delay); | ||
2103 | LOG (GNUNET_ERROR_TYPE_DEBUG, | ||
2104 | "New inbound delay %s\n", | ||
2105 | GNUNET_STRINGS_relative_time_to_string (delay, | ||
2106 | GNUNET_NO)); | ||
2107 | if (s->recv_wakeup_task != GNUNET_SCHEDULER_NO_TASK) | ||
2108 | { | ||
2109 | GNUNET_SCHEDULER_cancel (s->recv_wakeup_task); | ||
2110 | s->recv_wakeup_task | ||
2111 | = GNUNET_SCHEDULER_add_delayed (delay, | ||
2112 | &client_wake_up, | ||
2113 | s); | ||
2114 | } | ||
2115 | } | ||
2116 | |||
2117 | |||
2118 | /** | ||
2049 | * Return information about the given session to the | 2119 | * Return information about the given session to the |
2050 | * monitor callback. | 2120 | * monitor callback. |
2051 | * | 2121 | * |
@@ -2131,16 +2201,17 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
2131 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); | 2201 | api = GNUNET_new (struct GNUNET_TRANSPORT_PluginFunctions); |
2132 | api->cls = plugin; | 2202 | api->cls = plugin; |
2133 | api->send = &http_client_plugin_send; | 2203 | api->send = &http_client_plugin_send; |
2134 | api->disconnect_session = &http_client_session_disconnect; | 2204 | api->disconnect_session = &http_client_plugin_session_disconnect; |
2135 | api->query_keepalive_factor = &http_client_query_keepalive_factor; | 2205 | api->query_keepalive_factor = &http_client_query_keepalive_factor; |
2136 | api->disconnect_peer = &http_client_peer_disconnect; | 2206 | api->disconnect_peer = &http_client_plugin_peer_disconnect; |
2137 | api->check_address = &http_client_plugin_address_suggested; | 2207 | api->check_address = &http_client_plugin_address_suggested; |
2138 | api->get_session = &http_client_plugin_get_session; | 2208 | api->get_session = &http_client_plugin_get_session; |
2139 | api->address_to_string = &http_client_plugin_address_to_string; | 2209 | api->address_to_string = &http_client_plugin_address_to_string; |
2140 | api->string_to_address = &http_common_plugin_string_to_address; | 2210 | api->string_to_address = &http_common_plugin_string_to_address; |
2141 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; | 2211 | api->address_pretty_printer = &http_common_plugin_address_pretty_printer; |
2142 | api->get_network = &http_client_get_network; | 2212 | api->get_network = &http_client_plugin_get_network; |
2143 | api->update_session_timeout = &http_client_plugin_update_session_timeout; | 2213 | api->update_session_timeout = &http_client_plugin_update_session_timeout; |
2214 | api->update_inbound_delay = &http_client_plugin_update_inbound_delay; | ||
2144 | api->setup_monitor = &http_client_plugin_setup_monitor; | 2215 | api->setup_monitor = &http_client_plugin_setup_monitor; |
2145 | #if BUILD_HTTPS | 2216 | #if BUILD_HTTPS |
2146 | plugin->name = "transport-https_client"; | 2217 | plugin->name = "transport-https_client"; |
@@ -2150,7 +2221,6 @@ LIBGNUNET_PLUGIN_TRANSPORT_INIT (void *cls) | |||
2150 | plugin->protocol = "http"; | 2221 | plugin->protocol = "http"; |
2151 | #endif | 2222 | #endif |
2152 | plugin->last_tag = 1; | 2223 | plugin->last_tag = 1; |
2153 | plugin->options = 0; /* Setup options */ | ||
2154 | 2224 | ||
2155 | if (GNUNET_SYSERR == client_configure_plugin (plugin)) | 2225 | if (GNUNET_SYSERR == client_configure_plugin (plugin)) |
2156 | { | 2226 | { |