aboutsummaryrefslogtreecommitdiff
path: root/src/transport/test_plugin_transport_http.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
committerChristian Grothoff <christian@grothoff.org>2011-08-15 21:54:06 +0000
commit5746309cb4be2073d550ad7a6885e918631dbc38 (patch)
tree89455bc4aadf977816b38df13f990372cd81d71a /src/transport/test_plugin_transport_http.c
parent6fd3e715cae09fa6e657c96f1c6f9711ee51f42f (diff)
downloadgnunet-5746309cb4be2073d550ad7a6885e918631dbc38.tar.gz
gnunet-5746309cb4be2073d550ad7a6885e918631dbc38.zip
indentation
Diffstat (limited to 'src/transport/test_plugin_transport_http.c')
-rw-r--r--src/transport/test_plugin_transport_http.c160
1 files changed, 64 insertions, 96 deletions
diff --git a/src/transport/test_plugin_transport_http.c b/src/transport/test_plugin_transport_http.c
index 921f9ec32..f59edfb26 100644
--- a/src/transport/test_plugin_transport_http.c
+++ b/src/transport/test_plugin_transport_http.c
@@ -399,8 +399,8 @@ shutdown_clean ()
399 399
400 /* Evaluate results */ 400 /* Evaluate results */
401 fail = 0; 401 fail = 0;
402 if ((fail_notify_address == GNUNET_YES) || 402 if ((fail_notify_address == GNUNET_YES) || (fail_pretty_printer == GNUNET_YES)
403 (fail_pretty_printer == GNUNET_YES) || (fail_addr_to_str == GNUNET_YES)) 403 || (fail_addr_to_str == GNUNET_YES))
404 { 404 {
405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 405 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
406 "Phase 0: Test plugin functions failed\n"); 406 "Phase 0: Test plugin functions failed\n");
@@ -530,15 +530,14 @@ static void run_connection_tests (int phase, void *cls);
530static struct GNUNET_TIME_Relative 530static struct GNUNET_TIME_Relative
531receive (void *cls, const struct GNUNET_PeerIdentity *peer, 531receive (void *cls, const struct GNUNET_PeerIdentity *peer,
532 const struct GNUNET_MessageHeader *message, 532 const struct GNUNET_MessageHeader *message,
533 const struct GNUNET_TRANSPORT_ATS_Information *ats, 533 const struct GNUNET_TRANSPORT_ATS_Information *ats, uint32_t ats_count,
534 uint32_t ats_count, 534 struct Session *session, const char *sender_address,
535 struct Session *session, 535 uint16_t sender_address_len)
536 const char *sender_address, uint16_t sender_address_len)
537{ 536{
538 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 537 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
539 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n", 538 "Testcase recieved new message from peer `%s' with type %u and length %u, session %X\n",
540 GNUNET_i2s (peer), 539 GNUNET_i2s (peer), ntohs (message->type), ntohs (message->size),
541 ntohs (message->type), ntohs (message->size), session); 540 session);
542 541
543 if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20)) 542 if ((ntohs (message->type) >= 10) && (ntohs (message->type) < 20))
544 { 543 {
@@ -689,9 +688,8 @@ send_execute (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
689 688
690 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 689 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
691 _("curl failed for `%s' at %s:%d: `%s'\n"), 690 _("curl failed for `%s' at %s:%d: `%s'\n"),
692 "curl_multi_perform", 691 "curl_multi_perform", __FILE__, __LINE__,
693 __FILE__, 692 curl_easy_strerror (msg->data.result));
694 __LINE__, curl_easy_strerror (msg->data.result));
695 /* sending msg failed */ 693 /* sending msg failed */
696 curl_easy_cleanup (curl_handle); 694 curl_easy_cleanup (curl_handle);
697 curl_handle = NULL; 695 curl_handle = NULL;
@@ -792,8 +790,7 @@ send_prepare (struct HTTP_Transfer *result)
792 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max); 790 mret = curl_multi_fdset (multi_handle, &rs, &ws, &es, &max);
793 if (mret != CURLM_OK) 791 if (mret != CURLM_OK)
794 { 792 {
795 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 793 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
796 _("%s failed at %s:%d: `%s'\n"),
797 "curl_multi_fdset", __FILE__, __LINE__, 794 "curl_multi_fdset", __FILE__, __LINE__,
798 curl_multi_strerror (mret)); 795 curl_multi_strerror (mret));
799 return -1; 796 return -1;
@@ -801,8 +798,7 @@ send_prepare (struct HTTP_Transfer *result)
801 mret = curl_multi_timeout (multi_handle, &to); 798 mret = curl_multi_timeout (multi_handle, &to);
802 if (mret != CURLM_OK) 799 if (mret != CURLM_OK)
803 { 800 {
804 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 801 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("%s failed at %s:%d: `%s'\n"),
805 _("%s failed at %s:%d: `%s'\n"),
806 "curl_multi_timeout", __FILE__, __LINE__, 802 "curl_multi_timeout", __FILE__, __LINE__,
807 curl_multi_strerror (mret)); 803 curl_multi_strerror (mret));
808 return -1; 804 return -1;
@@ -918,13 +914,12 @@ notify_address (void *cls, int add_remove, const void *addr, size_t addrlen)
918} 914}
919 915
920static void 916static void
921plugin_env_session_end (void *cls, 917plugin_env_session_end (void *cls, const struct GNUNET_PeerIdentity *peer,
922 const struct GNUNET_PeerIdentity *peer,
923 struct Session *session) 918 struct Session *session)
924{ 919{
925 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 920 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
926 "Pluging tells me: session %X to peer `%s' ended\n", 921 "Pluging tells me: session %X to peer `%s' ended\n", session,
927 session, GNUNET_i2s (peer)); 922 GNUNET_i2s (peer));
928} 923}
929 924
930 925
@@ -967,8 +962,8 @@ pretty_printer_cb (void *cls, const char *address)
967{ 962{
968 if (NULL == address) 963 if (NULL == address)
969 return; 964 return;
970 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 965 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Plugin returned pretty address: `%s'\n",
971 "Plugin returned pretty address: `%s'\n", address); 966 address);
972 fail_pretty_printer_count++; 967 fail_pretty_printer_count++;
973} 968}
974 969
@@ -999,8 +994,8 @@ run_connection_tests (int phase, void *cls)
999 /* Connecting to peer without identification */ 994 /* Connecting to peer without identification */
1000 const char *ident = ""; 995 const char *ident = "";
1001 996
1002 GNUNET_asprintf (&host_str, 997 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1003 "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident); 998 ident);
1004 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 999 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1005 _("Connecting to peer without any peer identification.\n")); 1000 _("Connecting to peer without any peer identification.\n"));
1006 test_no_ident.test_executed = GNUNET_YES; 1001 test_no_ident.test_executed = GNUNET_YES;
@@ -1013,8 +1008,8 @@ run_connection_tests (int phase, void *cls)
1013 const char *ident = "AAAAAAAAAA"; 1008 const char *ident = "AAAAAAAAAA";
1014 1009
1015 /* Connecting to peer with too short identification */ 1010 /* Connecting to peer with too short identification */
1016 GNUNET_asprintf (&host_str, 1011 GNUNET_asprintf (&host_str, "%s://%s/%s", PROTOCOL_PREFIX, test_addr,
1017 "%s://%s/%s", PROTOCOL_PREFIX, test_addr, ident); 1012 ident);
1018 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1013 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1019 _ 1014 _
1020 ("Connecting to peer with too short peer identification.\n")); 1015 ("Connecting to peer with too short peer identification.\n"));
@@ -1044,9 +1039,8 @@ run_connection_tests (int phase, void *cls)
1044 struct GNUNET_CRYPTO_HashAsciiEncoded ident; 1039 struct GNUNET_CRYPTO_HashAsciiEncoded ident;
1045 1040
1046 GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident); 1041 GNUNET_CRYPTO_hash_to_enc (&my_identity.hashPubKey, &ident);
1047 GNUNET_asprintf (&host_str, 1042 GNUNET_asprintf (&host_str, "%s://%s/%s%s", PROTOCOL_PREFIX, test_addr,
1048 "%s://%s/%s%s", 1043 (char *) &ident, ";0");
1049 PROTOCOL_PREFIX, test_addr, (char *) &ident, ";0");
1050 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1044 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1051 _("Connecting to peer with valid peer identification.\n")); 1045 _("Connecting to peer with valid peer identification.\n"));
1052 test_valid_ident.test_executed = GNUNET_YES; 1046 test_valid_ident.test_executed = GNUNET_YES;
@@ -1083,8 +1077,8 @@ run_connection_tests (int phase, void *cls)
1083 INET_ADDRSTRLEN); 1077 INET_ADDRSTRLEN);
1084 port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port); 1078 port = ntohs (((struct IPv4HttpAddress *) tmp_addr->addr)->u_port);
1085 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1079 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1086 "Sending message to addres no. %u: `%s':%u\n", 1080 "Sending message to addres no. %u: `%s':%u\n", count,
1087 count, address, port); 1081 address, port);
1088 } 1082 }
1089 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress))) 1083 if (tmp_addr->addrlen == (sizeof (struct IPv6HttpAddress)))
1090 { 1084 {
@@ -1092,19 +1086,15 @@ run_connection_tests (int phase, void *cls)
1092 INET6_ADDRSTRLEN); 1086 INET6_ADDRSTRLEN);
1093 port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port); 1087 port = ntohs (((struct IPv6HttpAddress *) tmp_addr->addr)->u6_port);
1094 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1088 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1095 "Sending message to addres no. %u: `%s':%u\n", 1089 "Sending message to addres no. %u: `%s':%u\n", count,
1096 count, address, port); 1090 address, port);
1097 } 1091 }
1098 msg.type = htons (type); 1092 msg.type = htons (type);
1099 memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader)); 1093 memcpy (tmp, &msg, sizeof (struct GNUNET_MessageHeader));
1100 api->send (api->cls, 1094 api->send (api->cls, &my_identity, tmp,
1101 &my_identity, 1095 sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
1102 tmp, sizeof (struct GNUNET_MessageHeader), 1096 tmp_addr->addr, tmp_addr->addrlen, GNUNET_YES, &task_send_cont,
1103 0, TIMEOUT, 1097 &fail_msgs_transmited_to_local_addrs);
1104 NULL,
1105 tmp_addr->addr, tmp_addr->addrlen,
1106 GNUNET_YES,
1107 &task_send_cont, &fail_msgs_transmited_to_local_addrs);
1108 tmp_addr = tmp_addr->next; 1098 tmp_addr = tmp_addr->next;
1109 count++; 1099 count++;
1110 type++; 1100 type++;
@@ -1123,26 +1113,19 @@ run_connection_tests (int phase, void *cls)
1123 size = sizeof (struct GNUNET_MessageHeader); 1113 size = sizeof (struct GNUNET_MessageHeader);
1124 msg->size = htons (size); 1114 msg->size = htons (size);
1125 msg->type = htons (20); 1115 msg->type = htons (20);
1126 api->send (api->cls, 1116 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1127 &my_identity, 1117 NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1128 (const char *) msg, size,
1129 0, TIMEOUT, NULL, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1130 1118
1131 msg->type = htons (21); 1119 msg->type = htons (21);
1132 api->send (api->cls, 1120 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1133 &my_identity, 1121 NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1134 (const char *) msg, size,
1135 0, TIMEOUT, NULL, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1136 1122
1137 /* answer on session */ 1123 /* answer on session */
1138 size = sizeof (struct GNUNET_MessageHeader); 1124 size = sizeof (struct GNUNET_MessageHeader);
1139 msg->size = htons (size); 1125 msg->size = htons (size);
1140 msg->type = htons (22); 1126 msg->type = htons (22);
1141 api->send (api->cls, 1127 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1142 &my_identity, 1128 session, NULL, 0, GNUNET_SYSERR, &task_send_cont, NULL);
1143 (const char *) msg, size,
1144 0, TIMEOUT, session, NULL, 0, GNUNET_SYSERR,
1145 &task_send_cont, NULL);
1146 GNUNET_free (msg); 1129 GNUNET_free (msg);
1147 1130
1148 /* answer on session with big message not fitting in mhd send buffer */ 1131 /* answer on session with big message not fitting in mhd send buffer */
@@ -1150,10 +1133,8 @@ run_connection_tests (int phase, void *cls)
1150 msg = GNUNET_malloc (size); 1133 msg = GNUNET_malloc (size);
1151 msg->size = htons (size); 1134 msg->size = htons (size);
1152 msg->type = htons (23); 1135 msg->type = htons (23);
1153 api->send (api->cls, 1136 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1154 &my_identity, 1137 session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1155 (const char *) msg, size,
1156 0, TIMEOUT, session, NULL, 0, GNUNET_NO, &task_send_cont, NULL);
1157 GNUNET_free (msg); 1138 GNUNET_free (msg);
1158 return; 1139 return;
1159 } 1140 }
@@ -1178,12 +1159,10 @@ run_connection_tests (int phase, void *cls)
1178 1159
1179 msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader)); 1160 msg2->size = htons (2 * sizeof (struct GNUNET_MessageHeader));
1180 msg2->type = htons (31); 1161 msg2->type = htons (31);
1181 api->send (api->cls, 1162 api->send (api->cls, &my_identity, (const char *) msg,
1182 &my_identity, 1163 4 * sizeof (struct GNUNET_MessageHeader), 0, TIMEOUT, NULL,
1183 (const char *) msg, 4 * sizeof (struct GNUNET_MessageHeader), 1164 addr_head->addr, addr_head->addrlen, GNUNET_NO, &task_send_cont,
1184 0, TIMEOUT, NULL, 1165 &fail_multiple_msgs_in_transmission);
1185 addr_head->addr, addr_head->addrlen,
1186 GNUNET_NO, &task_send_cont, &fail_multiple_msgs_in_transmission);
1187 GNUNET_free (msg); 1166 GNUNET_free (msg);
1188 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */ 1167 /* send a message with size GNUNET_SERVER_MAX_MESSAGE_SIZE-1 */
1189 1168
@@ -1191,12 +1170,9 @@ run_connection_tests (int phase, void *cls)
1191 msg = GNUNET_malloc (size); 1170 msg = GNUNET_malloc (size);
1192 msg->size = htons (size); 1171 msg->size = htons (size);
1193 msg->type = htons (32); 1172 msg->type = htons (32);
1194 api->send (api->cls, 1173 api->send (api->cls, &my_identity, (const char *) msg, size, 0, TIMEOUT,
1195 &my_identity, 1174 NULL, addr_head->addr, addr_head->addrlen, GNUNET_NO,
1196 (const char *) msg, size, 1175 &task_send_cont, &fail_msg_transmited_max_size);
1197 0, TIMEOUT, NULL,
1198 addr_head->addr, addr_head->addrlen,
1199 GNUNET_NO, &task_send_cont, &fail_msg_transmited_max_size);
1200 GNUNET_free (msg); 1176 GNUNET_free (msg);
1201 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n"); 1177 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "No more tests to run\n");
1202 } 1178 }
@@ -1210,9 +1186,8 @@ run_connection_tests (int phase, void *cls)
1210 * @param c configuration to use 1186 * @param c configuration to use
1211 */ 1187 */
1212static void 1188static void
1213run (void *cls, 1189run (void *cls, char *const *args, const char *cfgfile,
1214 char *const *args, 1190 const struct GNUNET_CONFIGURATION_Handle *c)
1215 const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *c)
1216{ 1191{
1217 char *libname; 1192 char *libname;
1218 1193
@@ -1244,14 +1219,11 @@ run (void *cls,
1244 &servicehome); 1219 &servicehome);
1245 1220
1246 if ((GNUNET_OK != 1221 if ((GNUNET_OK !=
1247 GNUNET_CONFIGURATION_get_value_number (c, 1222 GNUNET_CONFIGURATION_get_value_number (c, "TRANSPORT", "NEIGHBOUR_LIMIT",
1248 "TRANSPORT",
1249 "NEIGHBOUR_LIMIT",
1250 &tneigh)) || 1223 &tneigh)) ||
1251 (GNUNET_OK != 1224 (GNUNET_OK !=
1252 GNUNET_CONFIGURATION_get_value_filename (c, 1225 GNUNET_CONFIGURATION_get_value_filename (c, "GNUNETD", "HOSTKEY",
1253 "GNUNETD", 1226 &keyfile)))
1254 "HOSTKEY", &keyfile)))
1255 { 1227 {
1256 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1228 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1257 _ 1229 _
@@ -1262,14 +1234,11 @@ run (void *cls,
1262 } 1234 }
1263 1235
1264 if ((GNUNET_OK != 1236 if ((GNUNET_OK !=
1265 GNUNET_CONFIGURATION_get_value_number (cfg, 1237 GNUNET_CONFIGURATION_get_value_number (cfg, "transport-http", "PORT",
1266 "transport-http", 1238 &port)) || (port > 65535) ||
1267 "PORT", 1239 (port == 0))
1268 &port)) ||
1269 (port > 65535) || (port == 0))
1270 { 1240 {
1271 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, 1241 GNUNET_log_from (GNUNET_ERROR_TYPE_ERROR, "http",
1272 "http",
1273 _ 1242 _
1274 ("Require valid port number for transport plugin `%s' in configuration!\n"), 1243 ("Require valid port number for transport plugin `%s' in configuration!\n"),
1275 "transport-http"); 1244 "transport-http");
@@ -1297,8 +1266,8 @@ run (void *cls,
1297 /* load plugins... */ 1266 /* load plugins... */
1298 setup_plugin_environment (); 1267 setup_plugin_environment ();
1299 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http"); 1268 GNUNET_asprintf (&libname, "libgnunet_plugin_transport_http");
1300 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 1269 GNUNET_log (GNUNET_ERROR_TYPE_INFO, _("Loading HTTP transport plugin `%s'\n"),
1301 _("Loading HTTP transport plugin `%s'\n"), libname); 1270 libname);
1302 api = GNUNET_PLUGIN_load (libname, &env); 1271 api = GNUNET_PLUGIN_load (libname, &env);
1303 GNUNET_free (libname); 1272 GNUNET_free (libname);
1304 if (api == NULL) 1273 if (api == NULL)
@@ -1322,9 +1291,9 @@ run (void *cls,
1322 cur = addr_head; 1291 cur = addr_head;
1323 while (cur != NULL) 1292 while (cur != NULL)
1324 { 1293 {
1325 api->address_pretty_printer (api->cls, "http", 1294 api->address_pretty_printer (api->cls, "http", cur->addr, cur->addrlen,
1326 cur->addr, cur->addrlen, GNUNET_NO, 1295 GNUNET_NO, TEST_TIMEOUT, &pretty_printer_cb,
1327 TEST_TIMEOUT, &pretty_printer_cb, NULL); 1296 NULL);
1328 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen); 1297 addr_str = api->address_to_string (api->cls, cur->addr, cur->addrlen);
1329 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen); 1298 suggest_res = api->check_address (api->cls, cur->addr, cur->addrlen);
1330 1299
@@ -1444,12 +1413,11 @@ main (int argc, char *const *argv)
1444 GNUNET_DISK_directory_remove (servicehome); 1413 GNUNET_DISK_directory_remove (servicehome);
1445 GNUNET_CONFIGURATION_destroy (cfg); 1414 GNUNET_CONFIGURATION_destroy (cfg);
1446 1415
1447 ret = (GNUNET_OK == 1416 ret =
1448 GNUNET_PROGRAM_run (5, 1417 (GNUNET_OK ==
1449 argv_prog, 1418 GNUNET_PROGRAM_run (5, argv_prog, "test_gnunet_transport_plugin_http",
1450 "test_gnunet_transport_plugin_http", 1419 "testcase", options, &run,
1451 "testcase", options, &run, 1420 NULL)) ? GNUNET_NO : GNUNET_YES;
1452 NULL)) ? GNUNET_NO : GNUNET_YES;
1453 1421
1454 if (servicehome != NULL) 1422 if (servicehome != NULL)
1455 { 1423 {