aboutsummaryrefslogtreecommitdiff
path: root/src/gns
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2018-03-08 15:50:18 +0100
committerChristian Grothoff <christian@grothoff.org>2018-03-08 15:50:18 +0100
commit310d0f559656343c4fd849fa517a054c31b24a4e (patch)
tree7c4d3c9a1adc9e1163a4f603e2b72cb744b877e9 /src/gns
parent0fa813ec6c9083a9b689181daccdf1d8a0228ca7 (diff)
downloadgnunet-310d0f559656343c4fd849fa517a054c31b24a4e.tar.gz
gnunet-310d0f559656343c4fd849fa517a054c31b24a4e.zip
misc fixes to gnunet-gns-proxy, in particular avoiding MHD-busy waiting
Diffstat (limited to 'src/gns')
-rw-r--r--src/gns/gns_tld_api.c12
-rw-r--r--src/gns/gnunet-gns-proxy.c298
-rw-r--r--src/gns/gnunet-gns.c7
-rw-r--r--src/gns/plugin_rest_gns.c25
4 files changed, 252 insertions, 90 deletions
diff --git a/src/gns/gns_tld_api.c b/src/gns/gns_tld_api.c
index c78afa572..293e37140 100644
--- a/src/gns/gns_tld_api.c
+++ b/src/gns/gns_tld_api.c
@@ -57,9 +57,9 @@ struct GNUNET_GNS_LookupWithTldRequest
57 57
58 /** 58 /**
59 * Domain name we are resolving. 59 * Domain name we are resolving.
60 */ 60 */
61 char *name; 61 char *name;
62 62
63 /** 63 /**
64 * @e lookup_proc closure 64 * @e lookup_proc closure
65 */ 65 */
@@ -82,7 +82,7 @@ struct GNUNET_GNS_LookupWithTldRequest
82 82
83 /** 83 /**
84 * Lookup options. 84 * Lookup options.
85 */ 85 */
86 enum GNUNET_GNS_LocalOptions options; 86 enum GNUNET_GNS_LocalOptions options;
87}; 87};
88 88
@@ -144,7 +144,7 @@ process_lookup_result (void *cls,
144{ 144{
145 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls; 145 struct GNUNET_GNS_LookupWithTldRequest *ltr = cls;
146 146
147 ltr->lr = NULL; 147 ltr->lr = NULL;
148 ltr->lookup_proc (ltr->lookup_proc_cls, 148 ltr->lookup_proc (ltr->lookup_proc_cls,
149 GNUNET_YES, 149 GNUNET_YES,
150 rd_count, 150 rd_count,
@@ -291,10 +291,12 @@ GNUNET_GNS_lookup_with_tld (struct GNUNET_GNS_Handle *handle,
291 /* Final case: TLD matches one of our egos */ 291 /* Final case: TLD matches one of our egos */
292 eat_tld (ltr->name); 292 eat_tld (ltr->name);
293 293
294 /* if the name is of the form 'label.gnu', never go to the DHT */ 294 /* if the name is of the form 'label' (and not 'label.SUBDOMAIN'), never go to the DHT */
295 if (NULL == strchr (ltr->name, 295 if (NULL == strchr (ltr->name,
296 (unsigned char) '.')) 296 (unsigned char) '.'))
297 ltr->options = GNUNET_GNS_LO_NO_DHT; 297 ltr->options = GNUNET_GNS_LO_NO_DHT;
298 else
299 ltr->options = GNUNET_GNS_LO_LOCAL_MASTER;
298 ltr->id_op = GNUNET_IDENTITY_ego_lookup (ltr->gns_handle->cfg, 300 ltr->id_op = GNUNET_IDENTITY_ego_lookup (ltr->gns_handle->cfg,
299 tld, 301 tld,
300 &identity_zone_cb, 302 &identity_zone_cb,
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 83518fcd7..ce06ccebe 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -485,17 +485,17 @@ struct Socks5Request
485 /** 485 /**
486 * Client socket read task 486 * Client socket read task
487 */ 487 */
488 struct GNUNET_SCHEDULER_Task * rtask; 488 struct GNUNET_SCHEDULER_Task *rtask;
489 489
490 /** 490 /**
491 * Client socket write task 491 * Client socket write task
492 */ 492 */
493 struct GNUNET_SCHEDULER_Task * wtask; 493 struct GNUNET_SCHEDULER_Task *wtask;
494 494
495 /** 495 /**
496 * Timeout task 496 * Timeout task
497 */ 497 */
498 struct GNUNET_SCHEDULER_Task * timeout_task; 498 struct GNUNET_SCHEDULER_Task *timeout_task;
499 499
500 /** 500 /**
501 * Read buffer 501 * Read buffer
@@ -518,6 +518,11 @@ struct Socks5Request
518 struct MhdHttpList *hd; 518 struct MhdHttpList *hd;
519 519
520 /** 520 /**
521 * MHD connection for this request.
522 */
523 struct MHD_Connection *con;
524
525 /**
521 * MHD response object for this request. 526 * MHD response object for this request.
522 */ 527 */
523 struct MHD_Response *response; 528 struct MHD_Response *response;
@@ -611,6 +616,16 @@ struct Socks5Request
611 * SSL Certificate status 616 * SSL Certificate status
612 */ 617 */
613 int ssl_checked; 618 int ssl_checked;
619
620 /**
621 * Was the hostname resolved via GNS?
622 */
623 int is_gns;
624
625 /**
626 * Did we suspend MHD processing?
627 */
628 int suspended;
614}; 629};
615 630
616 631
@@ -731,10 +746,16 @@ cleanup_s5r (struct Socks5Request *s5r)
731 { 746 {
732 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 747 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
733 "Cleaning up cURL handle\n"); 748 "Cleaning up cURL handle\n");
734 curl_multi_remove_handle (curl_multi, s5r->curl); 749 curl_multi_remove_handle (curl_multi,
750 s5r->curl);
735 curl_easy_cleanup (s5r->curl); 751 curl_easy_cleanup (s5r->curl);
736 s5r->curl = NULL; 752 s5r->curl = NULL;
737 } 753 }
754 if (s5r->suspended)
755 {
756 s5r->suspended = GNUNET_NO;
757 MHD_resume_connection (s5r->con);
758 }
738 curl_slist_free_all (s5r->headers); 759 curl_slist_free_all (s5r->headers);
739 if (NULL != s5r->hosts) 760 if (NULL != s5r->hosts)
740 { 761 {
@@ -774,6 +795,7 @@ cleanup_s5r (struct Socks5Request *s5r)
774static void 795static void
775curl_download_prepare (); 796curl_download_prepare ();
776 797
798
777/** 799/**
778 * Callback for MHD response generation. This function is called from 800 * Callback for MHD response generation. This function is called from
779 * MHD whenever MHD expects to get data back. Copies data from the 801 * MHD whenever MHD expects to get data back. Copies data from the
@@ -813,9 +835,16 @@ mhd_content_cb (void *cls,
813 "Pausing MHD download, no data available\n"); 835 "Pausing MHD download, no data available\n");
814 if (NULL != s5r->curl) 836 if (NULL != s5r->curl)
815 { 837 {
838 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
839 "Continuing CURL interaction\n");
816 curl_easy_pause (s5r->curl, CURLPAUSE_CONT); 840 curl_easy_pause (s5r->curl, CURLPAUSE_CONT);
817 curl_download_prepare (); 841 curl_download_prepare ();
818 } 842 }
843 if (GNUNET_NO == s5r->suspended)
844 {
845 MHD_suspend_connection (s5r->con);
846 s5r->suspended = GNUNET_YES;
847 }
819 return 0; /* more data later */ 848 return 0; /* more data later */
820 } 849 }
821 if ( (0 == bytes_to_copy) && 850 if ( (0 == bytes_to_copy) &&
@@ -826,14 +855,23 @@ mhd_content_cb (void *cls,
826 return MHD_CONTENT_READER_END_OF_STREAM; 855 return MHD_CONTENT_READER_END_OF_STREAM;
827 } 856 }
828 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 857 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
829 "Writing %lu/%lu bytes\n", bytes_to_copy, s5r->io_len); 858 "Writing %lu/%lu bytes\n",
830 GNUNET_memcpy (buf, s5r->io_buf, bytes_to_copy); 859 bytes_to_copy,
860 s5r->io_len);
861 GNUNET_memcpy (buf,
862 s5r->io_buf,
863 bytes_to_copy);
831 memmove (s5r->io_buf, 864 memmove (s5r->io_buf,
832 &s5r->io_buf[bytes_to_copy], 865 &s5r->io_buf[bytes_to_copy],
833 s5r->io_len - bytes_to_copy); 866 s5r->io_len - bytes_to_copy);
834 s5r->io_len -= bytes_to_copy; 867 s5r->io_len -= bytes_to_copy;
835 if (NULL != s5r->curl) 868 if (NULL != s5r->curl)
836 curl_easy_pause (s5r->curl, CURLPAUSE_CONT); 869 {
870 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
871 "Continuing CURL interaction\n");
872 curl_easy_pause (s5r->curl,
873 CURLPAUSE_CONT);
874 }
837 return bytes_to_copy; 875 return bytes_to_copy;
838} 876}
839 877
@@ -1028,12 +1066,14 @@ curl_check_hdr (void *buffer,
1028 int domain_matched; 1066 int domain_matched;
1029 char *tok; 1067 char *tok;
1030 1068
1069 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1070 "Receiving HTTP response header from CURL\n");
1031 /* first, check SSL certificate */ 1071 /* first, check SSL certificate */
1032 if ((GNUNET_YES != s5r->ssl_checked) && 1072 if ( (GNUNET_YES != s5r->ssl_checked) &&
1033 (HTTPS_PORT == s5r->port)) 1073 (HTTPS_PORT == s5r->port))
1034 { 1074 {
1035 if (GNUNET_OK != check_ssl_certificate (s5r)) 1075 if (GNUNET_OK != check_ssl_certificate (s5r))
1036 return 0; 1076 return 0;
1037 } 1077 }
1038 1078
1039 ndup = GNUNET_strndup (buffer, bytes); 1079 ndup = GNUNET_strndup (buffer, bytes);
@@ -1181,8 +1221,11 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r)
1181 CURLINFO_CONTENT_LENGTH_DOWNLOAD, 1221 CURLINFO_CONTENT_LENGTH_DOWNLOAD,
1182 &content_length)); 1222 &content_length));
1183 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1223 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1184 "Creating MHD response with code %d and size %d\n", 1224 "Creating MHD response with code %d and size %d for %s%s\n",
1185 (int) resp_code, (int) content_length); 1225 (int) resp_code,
1226 (int) content_length,
1227 s5r->domain,
1228 s5r->url);
1186 s5r->response_code = resp_code; 1229 s5r->response_code = resp_code;
1187 s5r->response = MHD_create_response_from_callback ((-1 == content_length) ? MHD_SIZE_UNKNOWN : content_length, 1230 s5r->response = MHD_create_response_from_callback ((-1 == content_length) ? MHD_SIZE_UNKNOWN : content_length,
1188 IO_BUFFERSIZE, 1231 IO_BUFFERSIZE,
@@ -1221,6 +1264,8 @@ create_mhd_response_from_s5r (struct Socks5Request *s5r)
1221 MHD_add_response_header (s5r->response, 1264 MHD_add_response_header (s5r->response,
1222 MHD_HTTP_HEADER_CONNECTION, 1265 MHD_HTTP_HEADER_CONNECTION,
1223 "close"));*/ 1266 "close"));*/
1267 MHD_resume_connection (s5r->con);
1268 s5r->suspended = GNUNET_NO;
1224 return GNUNET_OK; 1269 return GNUNET_OK;
1225} 1270}
1226 1271
@@ -1244,7 +1289,8 @@ curl_download_cb (void *ptr,
1244 size_t total = size * nmemb; 1289 size_t total = size * nmemb;
1245 1290
1246 if (NULL == s5r->response) 1291 if (NULL == s5r->response)
1247 GNUNET_assert (GNUNET_OK == create_mhd_response_from_s5r (s5r)); 1292 GNUNET_assert (GNUNET_OK ==
1293 create_mhd_response_from_s5r (s5r));
1248 1294
1249 if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) || 1295 if ( (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) ||
1250 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) ) 1296 (SOCKS5_SOCKET_UPLOAD_DONE == s5r->state) )
@@ -1253,20 +1299,35 @@ curl_download_cb (void *ptr,
1253 start the download, the IO buffer is still full 1299 start the download, the IO buffer is still full
1254 with upload data. */ 1300 with upload data. */
1255 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1301 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1256 "Pausing CURL download, waiting for UPLOAD to finish\n"); 1302 "Pausing CURL download `%s%s', waiting for UPLOAD to finish\n",
1303 s5r->domain,
1304 s5r->url);
1257 return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */ 1305 return CURL_WRITEFUNC_PAUSE; /* not yet ready for data download */
1258 } 1306 }
1259 if (sizeof (s5r->io_buf) - s5r->io_len < total) 1307 if (sizeof (s5r->io_buf) - s5r->io_len < total)
1260 { 1308 {
1261 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1309 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1262 "Pausing CURL download, not enough space %lu %lu %lu\n", sizeof (s5r->io_buf), 1310 "Pausing CURL `%s%s' download, not enough space %lu %lu %lu\n",
1263 s5r->io_len, total); 1311 s5r->domain,
1312 s5r->url,
1313 sizeof (s5r->io_buf),
1314 s5r->io_len,
1315 total);
1264 return CURL_WRITEFUNC_PAUSE; /* not enough space */ 1316 return CURL_WRITEFUNC_PAUSE; /* not enough space */
1265 } 1317 }
1266 GNUNET_memcpy (&s5r->io_buf[s5r->io_len], 1318 GNUNET_memcpy (&s5r->io_buf[s5r->io_len],
1267 ptr, 1319 ptr,
1268 total); 1320 total);
1269 s5r->io_len += total; 1321 s5r->io_len += total;
1322 if (GNUNET_YES == s5r->suspended)
1323 {
1324 MHD_resume_connection (s5r->con);
1325 s5r->suspended = GNUNET_NO;
1326 }
1327 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1328 "Received %llu bytes of payload via cURL from %s\n",
1329 (unsigned long long) total,
1330 s5r->domain);
1270 if (s5r->io_len == total) 1331 if (s5r->io_len == total)
1271 run_mhd_now (s5r->hd); 1332 run_mhd_now (s5r->hd);
1272 return total; 1333 return total;
@@ -1297,7 +1358,9 @@ curl_upload_cb (void *buf,
1297 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) ) 1358 (SOCKS5_SOCKET_UPLOAD_DONE != s5r->state) )
1298 { 1359 {
1299 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1360 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1300 "Pausing CURL UPLOAD, need more data\n"); 1361 "Pausing CURL UPLOAD %s%s, need more data\n",
1362 s5r->domain,
1363 s5r->url);
1301 return CURL_READFUNC_PAUSE; 1364 return CURL_READFUNC_PAUSE;
1302 } 1365 }
1303 if ( (0 == s5r->io_len) && 1366 if ( (0 == s5r->io_len) &&
@@ -1305,7 +1368,9 @@ curl_upload_cb (void *buf,
1305 { 1368 {
1306 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 1369 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1307 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1370 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1308 "Completed CURL UPLOAD\n"); 1371 "Completed CURL UPLOAD %s%s\n",
1372 s5r->domain,
1373 s5r->url);
1309 return 0; /* upload finished, can now download */ 1374 return 0; /* upload finished, can now download */
1310 } 1375 }
1311 if ( (SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) && 1376 if ( (SOCKS5_SOCKET_UPLOAD_STARTED != s5r->state) &&
@@ -1356,6 +1421,8 @@ curl_download_prepare ()
1356 long to; 1421 long to;
1357 struct GNUNET_TIME_Relative rtime; 1422 struct GNUNET_TIME_Relative rtime;
1358 1423
1424 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1425 "Scheduling CURL interaction\n");
1359 if (NULL != curl_download_task) 1426 if (NULL != curl_download_task)
1360 { 1427 {
1361 GNUNET_SCHEDULER_cancel (curl_download_task); 1428 GNUNET_SCHEDULER_cancel (curl_download_task);
@@ -1365,7 +1432,11 @@ curl_download_prepare ()
1365 FD_ZERO (&rs); 1432 FD_ZERO (&rs);
1366 FD_ZERO (&ws); 1433 FD_ZERO (&ws);
1367 FD_ZERO (&es); 1434 FD_ZERO (&es);
1368 if (CURLM_OK != (mret = curl_multi_fdset (curl_multi, &rs, &ws, &es, &max))) 1435 if (CURLM_OK != (mret = curl_multi_fdset (curl_multi,
1436 &rs,
1437 &ws,
1438 &es,
1439 &max)))
1369 { 1440 {
1370 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1441 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1371 "%s failed at %s:%d: `%s'\n", 1442 "%s failed at %s:%d: `%s'\n",
@@ -1388,7 +1459,8 @@ curl_download_prepare ()
1388 curl_download_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT, 1459 curl_download_task = GNUNET_SCHEDULER_add_select (GNUNET_SCHEDULER_PRIORITY_DEFAULT,
1389 rtime, 1460 rtime,
1390 grs, gws, 1461 grs, gws,
1391 &curl_task_download, curl_multi); 1462 &curl_task_download,
1463 curl_multi);
1392 GNUNET_NETWORK_fdset_destroy (gws); 1464 GNUNET_NETWORK_fdset_destroy (gws);
1393 GNUNET_NETWORK_fdset_destroy (grs); 1465 GNUNET_NETWORK_fdset_destroy (grs);
1394 } 1466 }
@@ -1416,11 +1488,15 @@ curl_task_download (void *cls)
1416 struct Socks5Request *s5r; 1488 struct Socks5Request *s5r;
1417 1489
1418 curl_download_task = NULL; 1490 curl_download_task = NULL;
1491 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1492 "Running CURL interaction\n");
1419 do 1493 do
1420 { 1494 {
1421 running = 0; 1495 running = 0;
1422 mret = curl_multi_perform (curl_multi, &running); 1496 mret = curl_multi_perform (curl_multi,
1423 while (NULL != (msg = curl_multi_info_read (curl_multi, &msgnum))) 1497 &running);
1498 while (NULL != (msg = curl_multi_info_read (curl_multi,
1499 &msgnum)))
1424 { 1500 {
1425 GNUNET_break (CURLE_OK == 1501 GNUNET_break (CURLE_OK ==
1426 curl_easy_getinfo (msg->easy_handle, 1502 curl_easy_getinfo (msg->easy_handle,
@@ -1443,15 +1519,22 @@ curl_task_download (void *cls)
1443 case CURLE_OK: 1519 case CURLE_OK:
1444 case CURLE_GOT_NOTHING: 1520 case CURLE_GOT_NOTHING:
1445 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1521 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1446 "CURL download completed.\n"); 1522 "CURL download %s%s completed.\n",
1523 s5r->domain,
1524 s5r->url);
1447 if (NULL == s5r->response) 1525 if (NULL == s5r->response)
1448 GNUNET_assert (GNUNET_OK == create_mhd_response_from_s5r (s5r)); 1526 {
1527 GNUNET_assert (GNUNET_OK ==
1528 create_mhd_response_from_s5r (s5r));
1529 }
1449 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; 1530 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE;
1450 run_mhd_now (s5r->hd); 1531 run_mhd_now (s5r->hd);
1451 break; 1532 break;
1452 default: 1533 default:
1453 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 1534 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
1454 "Download curl failed: %s\n", 1535 "Download curl %s%s failed: %s\n",
1536 s5r->domain,
1537 s5r->url,
1455 curl_easy_strerror (msg->data.result)); 1538 curl_easy_strerror (msg->data.result));
1456 /* FIXME: indicate error somehow? close MHD connection badly as well? */ 1539 /* FIXME: indicate error somehow? close MHD connection badly as well? */
1457 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE; 1540 s5r->state = SOCKS5_SOCKET_DOWNLOAD_DONE;
@@ -1481,6 +1564,11 @@ curl_task_download (void *cls)
1481 { 1564 {
1482 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1565 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1483 "Suspending cURL multi loop, no more events pending\n"); 1566 "Suspending cURL multi loop, no more events pending\n");
1567 if (NULL != curl_download_task)
1568 {
1569 GNUNET_SCHEDULER_cancel (curl_download_task);
1570 curl_download_task = NULL;
1571 }
1484 return; /* nothing more in progress */ 1572 return; /* nothing more in progress */
1485 } 1573 }
1486 curl_download_prepare (); 1574 curl_download_prepare ();
@@ -1568,7 +1656,6 @@ create_response (void *cls,
1568{ 1656{
1569 struct Socks5Request *s5r = *con_cls; 1657 struct Socks5Request *s5r = *con_cls;
1570 char *curlurl; 1658 char *curlurl;
1571 char *curl_hosts;
1572 char ipstring[INET6_ADDRSTRLEN]; 1659 char ipstring[INET6_ADDRSTRLEN];
1573 char ipaddr[INET6_ADDRSTRLEN + 2]; 1660 char ipaddr[INET6_ADDRSTRLEN + 2];
1574 const struct sockaddr *sa; 1661 const struct sockaddr *sa;
@@ -1582,13 +1669,16 @@ create_response (void *cls,
1582 GNUNET_break (0); 1669 GNUNET_break (0);
1583 return MHD_NO; 1670 return MHD_NO;
1584 } 1671 }
1672 s5r->con = con;
1585 //Fresh connection. 1673 //Fresh connection.
1586 if (SOCKS5_SOCKET_WITH_MHD == s5r->state) 1674 if (SOCKS5_SOCKET_WITH_MHD == s5r->state)
1587 { 1675 {
1588 /* first time here, initialize curl handle */ 1676 /* first time here, initialize curl handle */
1589 sa = (const struct sockaddr *) &s5r->destination_address; 1677 if (s5r->is_gns)
1590 switch (sa->sa_family)
1591 { 1678 {
1679 sa = (const struct sockaddr *) &s5r->destination_address;
1680 switch (sa->sa_family)
1681 {
1592 case AF_INET: 1682 case AF_INET:
1593 s4 = (const struct sockaddr_in *) &s5r->destination_address; 1683 s4 = (const struct sockaddr_in *) &s5r->destination_address;
1594 if (NULL == inet_ntop (AF_INET, 1684 if (NULL == inet_ntop (AF_INET,
@@ -1624,6 +1714,11 @@ create_response (void *cls,
1624 default: 1714 default:
1625 GNUNET_break (0); 1715 GNUNET_break (0);
1626 return MHD_NO; 1716 return MHD_NO;
1717 }
1718 }
1719 else
1720 {
1721 port = s5r->port;
1627 } 1722 }
1628 if (NULL == s5r->curl) 1723 if (NULL == s5r->curl)
1629 s5r->curl = curl_easy_init (); 1724 s5r->curl = curl_easy_init ();
@@ -1634,7 +1729,10 @@ create_response (void *cls,
1634 curl_easy_setopt (s5r->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr); 1729 curl_easy_setopt (s5r->curl, CURLOPT_HEADERFUNCTION, &curl_check_hdr);
1635 curl_easy_setopt (s5r->curl, CURLOPT_HEADERDATA, s5r); 1730 curl_easy_setopt (s5r->curl, CURLOPT_HEADERDATA, s5r);
1636 curl_easy_setopt (s5r->curl, CURLOPT_FOLLOWLOCATION, 0); 1731 curl_easy_setopt (s5r->curl, CURLOPT_FOLLOWLOCATION, 0);
1637 curl_easy_setopt (s5r->curl, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); 1732 if (s5r->is_gns)
1733 curl_easy_setopt (s5r->curl,
1734 CURLOPT_IPRESOLVE,
1735 CURL_IPRESOLVE_V4);
1638 curl_easy_setopt (s5r->curl, CURLOPT_CONNECTTIMEOUT, 600L); 1736 curl_easy_setopt (s5r->curl, CURLOPT_CONNECTTIMEOUT, 600L);
1639 curl_easy_setopt (s5r->curl, CURLOPT_TIMEOUT, 600L); 1737 curl_easy_setopt (s5r->curl, CURLOPT_TIMEOUT, 600L);
1640 curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); 1738 curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L);
@@ -1642,7 +1740,7 @@ create_response (void *cls,
1642 curl_easy_setopt (s5r->curl, CURLOPT_HTTP_TRANSFER_DECODING, 0); 1740 curl_easy_setopt (s5r->curl, CURLOPT_HTTP_TRANSFER_DECODING, 0);
1643 curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L); 1741 curl_easy_setopt (s5r->curl, CURLOPT_NOSIGNAL, 1L);
1644 curl_easy_setopt (s5r->curl, CURLOPT_PRIVATE, s5r); 1742 curl_easy_setopt (s5r->curl, CURLOPT_PRIVATE, s5r);
1645 curl_easy_setopt (s5r->curl, CURLOPT_VERBOSE, 0); 1743 curl_easy_setopt (s5r->curl, CURLOPT_VERBOSE, 0L);
1646 /** 1744 /**
1647 * Pre-populate cache to resolve Hostname. 1745 * Pre-populate cache to resolve Hostname.
1648 * This is necessary as the DNS name in the CURLOPT_URL is used 1746 * This is necessary as the DNS name in the CURLOPT_URL is used
@@ -1650,32 +1748,55 @@ create_response (void *cls,
1650 */ 1748 */
1651 if (NULL != s5r->leho) 1749 if (NULL != s5r->leho)
1652 { 1750 {
1751 char *curl_hosts;
1752
1653 GNUNET_asprintf (&curl_hosts, 1753 GNUNET_asprintf (&curl_hosts,
1654 "%s:%d:%s", 1754 "%s:%d:%s",
1655 s5r->leho, 1755 s5r->leho,
1656 port, 1756 port,
1657 ipaddr); 1757 ipaddr);
1658 s5r->hosts = curl_slist_append(NULL, curl_hosts); 1758 s5r->hosts = curl_slist_append (NULL,
1659 curl_easy_setopt(s5r->curl, CURLOPT_RESOLVE, s5r->hosts); 1759 curl_hosts);
1760 curl_easy_setopt (s5r->curl,
1761 CURLOPT_RESOLVE,
1762 s5r->hosts);
1660 GNUNET_free (curl_hosts); 1763 GNUNET_free (curl_hosts);
1661 } 1764 }
1662 GNUNET_asprintf (&curlurl, 1765 if (s5r->is_gns)
1663 (HTTPS_PORT != s5r->port) 1766 {
1664 ? "http://%s:%d%s" 1767 GNUNET_asprintf (&curlurl,
1665 : "https://%s:%d%s", 1768 (HTTPS_PORT != s5r->port)
1666 (NULL != s5r->leho) 1769 ? "http://%s:%d%s"
1667 ? s5r->leho 1770 : "https://%s:%d%s",
1668 : ipaddr, 1771 (NULL != s5r->leho)
1669 port, 1772 ? s5r->leho
1670 s5r->url); 1773 : ipaddr,
1774 port,
1775 s5r->url);
1776 }
1777 else
1778 {
1779 GNUNET_asprintf (&curlurl,
1780 (HTTPS_PORT != s5r->port)
1781 ? "http://%s:%d%s"
1782 : "https://%s:%d%s",
1783 s5r->domain,
1784 port,
1785 s5r->url);
1786 }
1671 curl_easy_setopt (s5r->curl, 1787 curl_easy_setopt (s5r->curl,
1672 CURLOPT_URL, 1788 CURLOPT_URL,
1673 curlurl); 1789 curlurl);
1790 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1791 "Launching %s CURL interaction, fetching `%s'\n",
1792 (s5r->is_gns) ? "GNS" : "DNS",
1793 curlurl);
1674 GNUNET_free (curlurl); 1794 GNUNET_free (curlurl);
1675 if (0 == strcasecmp (meth, MHD_HTTP_METHOD_PUT)) 1795 if (0 == strcasecmp (meth,
1796 MHD_HTTP_METHOD_PUT))
1676 { 1797 {
1677 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; 1798 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
1678 curl_easy_setopt (s5r->curl, CURLOPT_UPLOAD, 1); 1799 curl_easy_setopt (s5r->curl, CURLOPT_UPLOAD, 1L);
1679 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); 1800 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb);
1680 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); 1801 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r);
1681 curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb); 1802 curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb);
@@ -1685,7 +1806,7 @@ create_response (void *cls,
1685 { 1806 {
1686 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED; 1807 s5r->state = SOCKS5_SOCKET_UPLOAD_STARTED;
1687 curl_easy_setopt (s5r->curl, CURLOPT_POST, 1L); 1808 curl_easy_setopt (s5r->curl, CURLOPT_POST, 1L);
1688 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); 1809 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb);
1689 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); 1810 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r);
1690 curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb); 1811 curl_easy_setopt (s5r->curl, CURLOPT_READFUNCTION, &curl_upload_cb);
1691 curl_easy_setopt (s5r->curl, CURLOPT_READDATA, s5r); 1812 curl_easy_setopt (s5r->curl, CURLOPT_READDATA, s5r);
@@ -1693,7 +1814,7 @@ create_response (void *cls,
1693 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_HEAD)) 1814 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_HEAD))
1694 { 1815 {
1695 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 1816 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1696 curl_easy_setopt (s5r->curl, CURLOPT_NOBODY, 1); 1817 curl_easy_setopt (s5r->curl, CURLOPT_NOBODY, 1L);
1697 } 1818 }
1698 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_OPTIONS)) 1819 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_OPTIONS))
1699 { 1820 {
@@ -1703,7 +1824,7 @@ create_response (void *cls,
1703 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_GET)) 1824 else if (0 == strcasecmp (meth, MHD_HTTP_METHOD_GET))
1704 { 1825 {
1705 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED; 1826 s5r->state = SOCKS5_SOCKET_DOWNLOAD_STARTED;
1706 curl_easy_setopt (s5r->curl, CURLOPT_HTTPGET, 1); 1827 curl_easy_setopt (s5r->curl, CURLOPT_HTTPGET, 1L);
1707 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb); 1828 curl_easy_setopt (s5r->curl, CURLOPT_WRITEFUNCTION, &curl_download_cb);
1708 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r); 1829 curl_easy_setopt (s5r->curl, CURLOPT_WRITEDATA, s5r);
1709 } 1830 }
@@ -1746,7 +1867,9 @@ create_response (void *cls,
1746 curl_easy_setopt (s5r->curl, CURLOPT_USE_SSL, CURLUSESSL_NONE); 1867 curl_easy_setopt (s5r->curl, CURLOPT_USE_SSL, CURLUSESSL_NONE);
1747 } 1868 }
1748 1869
1749 if (CURLM_OK != curl_multi_add_handle (curl_multi, s5r->curl)) 1870 if (CURLM_OK !=
1871 curl_multi_add_handle (curl_multi,
1872 s5r->curl))
1750 { 1873 {
1751 GNUNET_break (0); 1874 GNUNET_break (0);
1752 curl_easy_cleanup (s5r->curl); 1875 curl_easy_cleanup (s5r->curl);
@@ -1755,8 +1878,11 @@ create_response (void *cls,
1755 } 1878 }
1756 MHD_get_connection_values (con, 1879 MHD_get_connection_values (con,
1757 MHD_HEADER_KIND, 1880 MHD_HEADER_KIND,
1758 &con_val_iter, s5r); 1881 &con_val_iter,
1759 curl_easy_setopt (s5r->curl, CURLOPT_HTTPHEADER, s5r->headers); 1882 s5r);
1883 curl_easy_setopt (s5r->curl,
1884 CURLOPT_HTTPHEADER,
1885 s5r->headers);
1760 curl_download_prepare (); 1886 curl_download_prepare ();
1761 return MHD_YES; 1887 return MHD_YES;
1762 } 1888 }
@@ -1764,7 +1890,6 @@ create_response (void *cls,
1764 /* continuing to process request */ 1890 /* continuing to process request */
1765 if (0 != *upload_data_size) 1891 if (0 != *upload_data_size)
1766 { 1892 {
1767
1768 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1893 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1769 "Processing %u bytes UPLOAD\n", 1894 "Processing %u bytes UPLOAD\n",
1770 (unsigned int) *upload_data_size); 1895 (unsigned int) *upload_data_size);
@@ -1782,7 +1907,8 @@ create_response (void *cls,
1782 s5r->io_len += left; 1907 s5r->io_len += left;
1783 *upload_data_size -= left; 1908 *upload_data_size -= left;
1784 GNUNET_assert (NULL != s5r->curl); 1909 GNUNET_assert (NULL != s5r->curl);
1785 curl_easy_pause (s5r->curl, CURLPAUSE_CONT); 1910 curl_easy_pause (s5r->curl,
1911 CURLPAUSE_CONT);
1786 return MHD_YES; 1912 return MHD_YES;
1787 } 1913 }
1788 if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state) 1914 if (SOCKS5_SOCKET_UPLOAD_STARTED == s5r->state)
@@ -1792,9 +1918,19 @@ create_response (void *cls,
1792 s5r->state = SOCKS5_SOCKET_UPLOAD_DONE; 1918 s5r->state = SOCKS5_SOCKET_UPLOAD_DONE;
1793 } 1919 }
1794 if (NULL == s5r->response) 1920 if (NULL == s5r->response)
1921 {
1922 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1923 "Waiting for HTTP response for %s%s...\n",
1924 s5r->domain,
1925 s5r->url);
1926 MHD_suspend_connection (con);
1927 s5r->suspended = GNUNET_YES;
1795 return MHD_YES; 1928 return MHD_YES;
1929 }
1796 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1930 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1797 "Queueing response with MHD\n"); 1931 "Queueing response for %s%s with MHD\n",
1932 s5r->domain,
1933 s5r->url);
1798 run_mhd_now (s5r->hd); 1934 run_mhd_now (s5r->hd);
1799 return MHD_queue_response (con, 1935 return MHD_queue_response (con,
1800 s5r->response_code, 1936 s5r->response_code,
@@ -1821,7 +1957,6 @@ mhd_completed_cb (void *cls,
1821 enum MHD_RequestTerminationCode toe) 1957 enum MHD_RequestTerminationCode toe)
1822{ 1958{
1823 struct Socks5Request *s5r = *con_cls; 1959 struct Socks5Request *s5r = *con_cls;
1824 struct HttpResponseHeader *header;
1825 1960
1826 if (NULL == s5r) 1961 if (NULL == s5r)
1827 return; 1962 return;
@@ -1832,19 +1967,23 @@ mhd_completed_cb (void *cls,
1832 if (NULL != s5r->curl) 1967 if (NULL != s5r->curl)
1833 { 1968 {
1834 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1969 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1835 "Resetting cURL handle\n"); 1970 "Removing cURL handle (MHD interaction complete)\n");
1836 curl_multi_remove_handle (curl_multi, s5r->curl); 1971 curl_multi_remove_handle (curl_multi,
1972 s5r->curl);
1837 curl_slist_free_all (s5r->headers); 1973 curl_slist_free_all (s5r->headers);
1838 s5r->headers = NULL; 1974 s5r->headers = NULL;
1839 curl_easy_reset (s5r->curl); 1975 curl_easy_reset (s5r->curl);
1840 s5r->rbuf_len = 0; 1976 s5r->rbuf_len = 0;
1841 s5r->wbuf_len = 0; 1977 s5r->wbuf_len = 0;
1842 s5r->io_len = 0; 1978 s5r->io_len = 0;
1979 curl_download_prepare ();
1843 } 1980 }
1844 if ( (NULL != s5r->response) && 1981 if ( (NULL != s5r->response) &&
1845 (curl_failure_response != s5r->response) ) 1982 (curl_failure_response != s5r->response) )
1846 MHD_destroy_response (s5r->response); 1983 MHD_destroy_response (s5r->response);
1847 for (header = s5r->header_head; header != NULL; header = s5r->header_head) 1984 for (struct HttpResponseHeader *header = s5r->header_head;
1985 NULL != header;
1986 header = s5r->header_head)
1848 { 1987 {
1849 GNUNET_CONTAINER_DLL_remove (s5r->header_head, 1988 GNUNET_CONTAINER_DLL_remove (s5r->header_head,
1850 s5r->header_tail, 1989 s5r->header_tail,
@@ -1853,7 +1992,9 @@ mhd_completed_cb (void *cls,
1853 GNUNET_free (header->value); 1992 GNUNET_free (header->value);
1854 GNUNET_free (header); 1993 GNUNET_free (header);
1855 } 1994 }
1856 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Finished request for %s\n", s5r->url); 1995 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1996 "Finished request for %s\n",
1997 s5r->url);
1857 GNUNET_free (s5r->url); 1998 GNUNET_free (s5r->url);
1858 s5r->state = SOCKS5_SOCKET_WITH_MHD; 1999 s5r->state = SOCKS5_SOCKET_WITH_MHD;
1859 s5r->url = NULL; 2000 s5r->url = NULL;
@@ -2043,12 +2184,18 @@ schedule_httpd (struct MhdHttpList *hd)
2043 FD_ZERO (&ws); 2184 FD_ZERO (&ws);
2044 FD_ZERO (&es); 2185 FD_ZERO (&es);
2045 max = -1; 2186 max = -1;
2046 if (MHD_YES != MHD_get_fdset (hd->daemon, &rs, &ws, &es, &max)) 2187 if (MHD_YES !=
2188 MHD_get_fdset (hd->daemon,
2189 &rs,
2190 &ws,
2191 &es,
2192 &max))
2047 { 2193 {
2048 kill_httpd (hd); 2194 kill_httpd (hd);
2049 return; 2195 return;
2050 } 2196 }
2051 haveto = MHD_get_timeout (hd->daemon, &timeout); 2197 haveto = MHD_get_timeout (hd->daemon,
2198 &timeout);
2052 if (MHD_YES == haveto) 2199 if (MHD_YES == haveto)
2053 tv.rel_value_us = (uint64_t) timeout * 1000LL; 2200 tv.rel_value_us = (uint64_t) timeout * 1000LL;
2054 else 2201 else
@@ -2146,7 +2293,10 @@ load_file (const char* filename,
2146 return NULL; 2293 return NULL;
2147 *size = (unsigned int) fsize; 2294 *size = (unsigned int) fsize;
2148 buffer = GNUNET_malloc (*size); 2295 buffer = GNUNET_malloc (*size);
2149 if (fsize != GNUNET_DISK_fn_read (filename, buffer, (size_t) fsize)) 2296 if (fsize !=
2297 GNUNET_DISK_fn_read (filename,
2298 buffer,
2299 (size_t) fsize))
2150 { 2300 {
2151 GNUNET_free (buffer); 2301 GNUNET_free (buffer);
2152 return NULL; 2302 return NULL;
@@ -2317,7 +2467,7 @@ lookup_ssl_httpd (const char* domain)
2317 hd->is_ssl = GNUNET_YES; 2467 hd->is_ssl = GNUNET_YES;
2318 hd->domain = GNUNET_strdup (domain); 2468 hd->domain = GNUNET_strdup (domain);
2319 hd->proxy_cert = pgc; 2469 hd->proxy_cert = pgc;
2320 hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_NO_LISTEN_SOCKET, 2470 hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_SSL | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME,
2321 0, 2471 0,
2322 NULL, NULL, 2472 NULL, NULL,
2323 &create_response, hd, 2473 &create_response, hd,
@@ -2546,6 +2696,7 @@ signal_socks_success (struct Socks5Request *s5r)
2546 * Process GNS results for target domain. 2696 * Process GNS results for target domain.
2547 * 2697 *
2548 * @param cls the `struct Socks5Request *` 2698 * @param cls the `struct Socks5Request *`
2699 * @param tld #GNUNET_YES if this was a GNS TLD.
2549 * @param rd_count number of records returned 2700 * @param rd_count number of records returned
2550 * @param rd record data 2701 * @param rd record data
2551 */ 2702 */
@@ -2556,13 +2707,13 @@ handle_gns_result (void *cls,
2556 const struct GNUNET_GNSRECORD_Data *rd) 2707 const struct GNUNET_GNSRECORD_Data *rd)
2557{ 2708{
2558 struct Socks5Request *s5r = cls; 2709 struct Socks5Request *s5r = cls;
2559 uint32_t i;
2560 const struct GNUNET_GNSRECORD_Data *r; 2710 const struct GNUNET_GNSRECORD_Data *r;
2561 int got_ip; 2711 int got_ip;
2562 2712
2563 s5r->gns_lookup = NULL; 2713 s5r->gns_lookup = NULL;
2714 s5r->is_gns = tld;
2564 got_ip = GNUNET_NO; 2715 got_ip = GNUNET_NO;
2565 for (i=0;i<rd_count;i++) 2716 for (uint32_t i=0;i<rd_count;i++)
2566 { 2717 {
2567 r = &rd[i]; 2718 r = &rd[i];
2568 switch (r->record_type) 2719 switch (r->record_type)
@@ -2655,7 +2806,8 @@ handle_gns_result (void *cls,
2655 break; 2806 break;
2656 } 2807 }
2657 } 2808 }
2658 if (GNUNET_YES != got_ip) 2809 if ( (GNUNET_YES != got_ip) &&
2810 (GNUNET_YES == tld) )
2659 { 2811 {
2660 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 2812 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2661 "Name resolution failed to yield useful IP address.\n"); 2813 "Name resolution failed to yield useful IP address.\n");
@@ -2844,7 +2996,8 @@ do_s5r_read (void *cls)
2844 return; /* need more data */ 2996 return; /* need more data */
2845 dom_name = (const char *) &dom_len[1]; 2997 dom_name = (const char *) &dom_len[1];
2846 port = (const uint16_t*) &dom_name[*dom_len]; 2998 port = (const uint16_t*) &dom_name[*dom_len];
2847 s5r->domain = GNUNET_strndup (dom_name, *dom_len); 2999 s5r->domain = GNUNET_strndup (dom_name,
3000 *dom_len);
2848 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 3001 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
2849 "Requested connection is to %s:%d\n", 3002 "Requested connection is to %s:%d\n",
2850 s5r->domain, 3003 s5r->domain,
@@ -2957,6 +3110,17 @@ do_shutdown (void *cls)
2957{ 3110{
2958 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 3111 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
2959 "Shutting down...\n"); 3112 "Shutting down...\n");
3113 /* MHD requires resuming before destroying the daemons */
3114 for (struct Socks5Request *s5r = s5r_head;
3115 NULL != s5r;
3116 s5r = s5r->next)
3117 {
3118 if (s5r->suspended)
3119 {
3120 s5r->suspended = GNUNET_NO;
3121 MHD_resume_connection (s5r->con);
3122 }
3123 }
2960 while (NULL != mhd_httpd_head) 3124 while (NULL != mhd_httpd_head)
2961 kill_httpd (mhd_httpd_head); 3125 kill_httpd (mhd_httpd_head);
2962 while (NULL != s5r_head) 3126 while (NULL != s5r_head)
@@ -3222,7 +3386,7 @@ run (void *cls,
3222 3386
3223 /* start MHD daemon for HTTP */ 3387 /* start MHD daemon for HTTP */
3224 hd = GNUNET_new (struct MhdHttpList); 3388 hd = GNUNET_new (struct MhdHttpList);
3225 hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET, 3389 hd->daemon = MHD_start_daemon (MHD_USE_DEBUG | MHD_USE_NO_LISTEN_SOCKET | MHD_ALLOW_SUSPEND_RESUME,
3226 0, 3390 0,
3227 NULL, NULL, 3391 NULL, NULL,
3228 &create_response, hd, 3392 &create_response, hd,
diff --git a/src/gns/gnunet-gns.c b/src/gns/gnunet-gns.c
index 771a7dcc8..34f6e2c82 100644
--- a/src/gns/gnunet-gns.c
+++ b/src/gns/gnunet-gns.c
@@ -50,11 +50,6 @@ static char *lookup_name;
50static char *lookup_type; 50static char *lookup_type;
51 51
52/** 52/**
53 * Set to GNUNET_GNS_LO_LOCAL_MASTER if we are looking up in the master zone.
54 */
55static enum GNUNET_GNS_LocalOptions local_options;
56
57/**
58 * raw output 53 * raw output
59 */ 54 */
60static int raw; 55static int raw;
@@ -207,7 +202,7 @@ run (void *cls,
207 lr = GNUNET_GNS_lookup_with_tld (gns, 202 lr = GNUNET_GNS_lookup_with_tld (gns,
208 lookup_name, 203 lookup_name,
209 rtype, 204 rtype,
210 local_options, 205 GNUNET_GNS_LO_DEFAULT,
211 &process_lookup_result, 206 &process_lookup_result,
212 lookup_name); 207 lookup_name);
213 if (NULL == lr) 208 if (NULL == lr)
diff --git a/src/gns/plugin_rest_gns.c b/src/gns/plugin_rest_gns.c
index b7775e4ea..1d215b6a4 100644
--- a/src/gns/plugin_rest_gns.c
+++ b/src/gns/plugin_rest_gns.c
@@ -423,7 +423,8 @@ identity_master_cb (void *cls,
423 GNUNET_SCHEDULER_add_now (&do_error, handle); 423 GNUNET_SCHEDULER_add_now (&do_error, handle);
424 return; 424 return;
425 } 425 }
426 GNUNET_IDENTITY_ego_get_public_key (ego, &handle->pkey); 426 GNUNET_IDENTITY_ego_get_public_key (ego,
427 &handle->pkey);
427 /* main name is our own master zone, do no look for that in the DHT */ 428 /* main name is our own master zone, do no look for that in the DHT */
428 handle->options = GNUNET_GNS_LO_LOCAL_MASTER; 429 handle->options = GNUNET_GNS_LO_LOCAL_MASTER;
429 /* if the name is of the form 'label.gnu', never go to the DHT */ 430 /* if the name is of the form 'label.gnu', never go to the DHT */
@@ -465,6 +466,7 @@ parse_url (const char *url, struct LookupHandle *handle)
465 return GNUNET_OK; 466 return GNUNET_OK;
466} 467}
467 468
469
468static void 470static void
469get_gns_cont (struct GNUNET_REST_RequestHandle *conndata_handle, 471get_gns_cont (struct GNUNET_REST_RequestHandle *conndata_handle,
470 const char* url, 472 const char* url,
@@ -610,14 +612,19 @@ options_cont (struct GNUNET_REST_RequestHandle *con_handle,
610 * @param data body of the HTTP request (optional) 612 * @param data body of the HTTP request (optional)
611 * @param data_size length of the body 613 * @param data_size length of the body
612 * @param proc callback function for the result 614 * @param proc callback function for the result
613 * @param proc_cls closure for callback function 615 * @param proc_cls closure for @a proc
614 * @return GNUNET_OK if request accepted 616 * @return #GNUNET_OK if request accepted
615 */ 617 */
616static void 618static void
617rest_gns_process_request(struct GNUNET_REST_RequestHandle *conndata_handle, 619rest_gns_process_request (struct GNUNET_REST_RequestHandle *conndata_handle,
618 GNUNET_REST_ResultProcessor proc, 620 GNUNET_REST_ResultProcessor proc,
619 void *proc_cls) 621 void *proc_cls)
620{ 622{
623 static const struct GNUNET_REST_RequestHandler handlers[] = {
624 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
625 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
626 GNUNET_REST_HANDLER_END
627 };
621 struct LookupHandle *handle = GNUNET_new (struct LookupHandle); 628 struct LookupHandle *handle = GNUNET_new (struct LookupHandle);
622 struct GNUNET_REST_RequestHandlerError err; 629 struct GNUNET_REST_RequestHandlerError err;
623 630
@@ -626,12 +633,6 @@ rest_gns_process_request(struct GNUNET_REST_RequestHandle *conndata_handle,
626 handle->proc = proc; 633 handle->proc = proc;
627 handle->rest_handle = conndata_handle; 634 handle->rest_handle = conndata_handle;
628 635
629 static const struct GNUNET_REST_RequestHandler handlers[] = {
630 {MHD_HTTP_METHOD_GET, GNUNET_REST_API_NS_GNS, &get_gns_cont},
631 {MHD_HTTP_METHOD_OPTIONS, GNUNET_REST_API_NS_GNS, &options_cont},
632 GNUNET_REST_HANDLER_END
633 };
634
635 if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle, 636 if (GNUNET_NO == GNUNET_JSONAPI_handle_request (conndata_handle,
636 handlers, 637 handlers,
637 &err, 638 &err,