GNUnet  0.11.x
gnunet-namestore-fcfsd.c
Go to the documentation of this file.
1 /*
2  This file is part of GNUnet.
3  Copyright (C) 2012-2014 GNUnet e.V.
4 
5  GNUnet is free software: you can redistribute it and/or modify it
6  under the terms of the GNU Affero General Public License as published
7  by the Free Software Foundation, either version 3 of the License,
8  or (at your option) any later version.
9 
10  GNUnet is distributed in the hope that it will be useful, but
11  WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  Affero General Public License for more details.
14 
15  You should have received a copy of the GNU Affero General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17 
18  SPDX-License-Identifier: AGPL3.0-or-later
19  */
33 #include "platform.h"
34 #include <microhttpd.h>
35 #include "gnunet_util_lib.h"
37 #include "gnunet_gnsrecord_lib.h"
39 #include "gnunet_mhd_compat.h"
40 
44 #define METHOD_ERROR \
45  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>Illegal request</title></head><body>Go away.</body></html>"
46 
50 #define MAIN_PAGE \
51  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>GNUnet FCFS Authority Name Registration Service</title></head><body><form action=\"S\" method=\"post\">What is your desired domain name? (at most 63 lowercase characters, no dots allowed.) <input type=\"text\" name=\"domain\" /> <p> What is your public key? (Copy from gnunet-setup.) <input type=\"text\" name=\"pkey\" /> <input type=\"submit\" value=\"Next\" /><br/><a href=./Zoneinfo> List of all registered names </a></body></html>"
52 
56 #define SUBMIT_PAGE \
57  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>%s</title></head><body>%s</body></html>"
58 
62 #define ZONEINFO_PAGE \
63  "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"><html lang=\"en\" xmlns=\"http://www.w3.org/1999/xhtml\"><html><head><title>FCFS Zoneinfo</title></head><body><h1> FCFS Zoneinfo </h1><table border=\"1\"><th>name</th><th>PKEY</th>%s</table></body></html>"
64 
65 #define FCFS_ZONEINFO_URL "/Zoneinfo"
66 
70 #define MIME_HTML "text/html"
71 
75 #define COOKIE_NAME "namestore-fcfsd"
76 
77 #define DEFAULT_ZONEINFO_BUFSIZE 2048
78 
82 enum Phase
83 {
87  RP_START = 0,
88 
93 
98 
103 
108 };
109 
110 
114 struct Request
115 {
119  // FIXME: struct Session *session;
120 
125  struct MHD_PostProcessor *pp;
126 
130  struct MHD_Connection *con;
135  const char *post_url;
136 
141 
151 
155  enum Phase phase;
156 
160  char domain_name[64];
161 
165  char public_key[128];
166 
168 };
169 
174 {
179 
183  char*zoneinfo;
184 
188  size_t buf_len;
189 
193  size_t write_offset;
194 };
195 
199 static struct MHD_Daemon *httpd;
200 
205 
210 
215 
220 
224 static struct MHD_Response *info_page;
225 
230 
235 
239 static unsigned long long port;
240 
244 static char *zone;
245 
246 
252 static void
253 do_httpd (void *cls);
254 
255 
259 static void
261 {
262  if (NULL != httpd_task)
263  {
264  GNUNET_SCHEDULER_cancel (httpd_task);
265  httpd_task = NULL;
266  }
267  httpd_task = GNUNET_SCHEDULER_add_now (&do_httpd, NULL);
268 }
269 
270 
274 static void
275 update_zoneinfo_page (void *cls);
276 
277 
281 static void
283 {
284  struct ZoneinfoRequest *zr = cls;
285 
286  zr->list_it = NULL;
287  GNUNET_free (zr->zoneinfo);
288  GNUNET_SCHEDULER_cancel (uzp_task);
290  NULL);
291 }
292 
293 
297 static void
299 {
300  struct ZoneinfoRequest *zr = cls;
301  struct MHD_Response *response;
302  char*full_page;
303 
304  zr->list_it = NULL;
305 
306  /* return static form */
307  GNUNET_asprintf (&full_page,
309  zr->zoneinfo);
310  response = MHD_create_response_from_buffer (strlen (full_page),
311  (void *) full_page,
312  MHD_RESPMEM_MUST_FREE);
313  MHD_add_response_header (response,
314  MHD_HTTP_HEADER_CONTENT_TYPE,
315  MIME_HTML);
316  MHD_destroy_response (info_page);
318  GNUNET_free (zr->zoneinfo);
319 }
320 
321 
332 static void
333 iterate_cb (void *cls,
334  const struct GNUNET_IDENTITY_PrivateKey *zone_key,
335  const char *name,
336  unsigned int rd_len,
337  const struct GNUNET_GNSRECORD_Data *rd)
338 {
339  struct ZoneinfoRequest *zr = cls;
340  size_t bytes_free;
341  char*pkey;
342  char*new_buf;
343 
344  (void) zone_key;
345  if (1 != rd_len)
346  {
348  1);
349  return;
350  }
351 
354  {
356  1);
357  return;
358  }
359 
360  bytes_free = zr->buf_len - zr->write_offset;
362  rd->data,
363  rd->data_size);
364  if (NULL == pkey)
365  {
366  GNUNET_break (0);
368  1);
369  return;
370  }
371  if (bytes_free < (strlen (name) + strlen (pkey) + 40))
372  {
373  new_buf = GNUNET_malloc (zr->buf_len * 2);
374  GNUNET_memcpy (new_buf, zr->zoneinfo, zr->write_offset);
375  GNUNET_free (zr->zoneinfo);
376  zr->zoneinfo = new_buf;
377  zr->buf_len *= 2;
378  }
379  sprintf (zr->zoneinfo + zr->write_offset,
380  "<tr><td>%s</td><td>%s</td></tr>",
381  name,
382  pkey);
383  zr->write_offset = strlen (zr->zoneinfo);
385  1);
386  GNUNET_free (pkey);
387 }
388 
389 
395 static int
396 serve_zoneinfo_page (struct MHD_Connection *connection)
397 {
398  return MHD_queue_response (connection,
399  MHD_HTTP_OK,
400  info_page);
401 }
402 
403 
407 static void
409 {
410  static struct ZoneinfoRequest zr;
411 
412  (void) cls;
415  NULL);
416  if (NULL != zr.list_it)
417  return;
420  zr.write_offset = 0;
424  &zr,
425  &iterate_cb,
426  &zr,
428  &zr);
429 }
430 
431 
438 static int
439 serve_main_page (struct MHD_Connection *connection)
440 {
441  int ret;
442  struct MHD_Response *response;
443 
444  /* return static form */
445  response = MHD_create_response_from_buffer (strlen (MAIN_PAGE),
446  (void *) MAIN_PAGE,
447  MHD_RESPMEM_PERSISTENT);
448  MHD_add_response_header (response,
449  MHD_HTTP_HEADER_CONTENT_TYPE,
450  MIME_HTML);
451  ret = MHD_queue_response (connection,
452  MHD_HTTP_OK,
453  response);
454  MHD_destroy_response (response);
455  return ret;
456 }
457 
458 
466 static int
467 fill_s_reply (const char *info,
468  struct Request *request,
469  struct MHD_Connection *connection)
470 {
471  int ret;
472  char *reply;
473  struct MHD_Response *response;
474 
475  (void) request;
476  GNUNET_asprintf (&reply,
477  SUBMIT_PAGE,
478  info,
479  info);
480  /* return static form */
481  response = MHD_create_response_from_buffer (strlen (reply),
482  (void *) reply,
483  MHD_RESPMEM_MUST_FREE);
484  MHD_add_response_header (response,
485  MHD_HTTP_HEADER_CONTENT_TYPE,
486  MIME_HTML);
487  ret = MHD_queue_response (connection,
488  MHD_HTTP_OK,
489  response);
490  MHD_destroy_response (response);
491  return ret;
492 }
493 
494 
514 static MHD_RESULT
515 post_iterator (void *cls,
516  enum MHD_ValueKind kind,
517  const char *key,
518  const char *filename,
519  const char *content_type,
520  const char *transfer_encoding,
521  const char *data,
522  uint64_t off,
523  size_t size)
524 {
525  struct Request *request = cls;
526 
527  (void) kind;
528  (void) filename;
529  (void) content_type;
530  (void) transfer_encoding;
531  if (0 == strcmp ("domain", key))
532  {
533  if (size + off >= sizeof(request->domain_name))
534  size = sizeof(request->domain_name) - off - 1;
535  GNUNET_memcpy (&request->domain_name[off],
536  data,
537  size);
538  request->domain_name[size + off] = '\0';
539  return MHD_YES;
540  }
541  if (0 == strcmp ("pkey", key))
542  {
543  if (size + off >= sizeof(request->public_key))
544  size = sizeof(request->public_key) - off - 1;
545  GNUNET_memcpy (&request->public_key[off],
546  data,
547  size);
548  request->public_key[size + off] = '\0';
549  return MHD_YES;
550  }
552  _ ("Unsupported form value `%s'\n"),
553  key);
554  return MHD_YES;
555 }
556 
557 
568 static void
569 put_continuation (void *cls,
570  int32_t success,
571  const char *emsg)
572 {
573  struct Request *request = cls;
574 
575  request->qe = NULL;
576  if (0 >= success)
577  {
579  _ ("Failed to create record for domain `%s': %s\n"),
580  request->domain_name,
581  emsg);
582  request->phase = RP_FAIL;
583  }
584  else
585  request->phase = RP_SUCCESS;
586  MHD_resume_connection (request->con);
587  run_httpd_now ();
588 }
589 
590 
594 static void
596 {
597  struct Request *request = cls;
598 
600  _ ("Error when mapping zone to name\n"));
601  request->phase = RP_FAIL;
602  MHD_resume_connection (request->con);
603  run_httpd_now ();
604 }
605 
606 
616 static void
617 zone_to_name_cb (void *cls,
618  const struct GNUNET_IDENTITY_PrivateKey *zone_key,
619  const char *name,
620  unsigned int rd_count,
621  const struct GNUNET_GNSRECORD_Data *rd)
622 {
623  struct Request *request = cls;
624  struct GNUNET_GNSRECORD_Data r;
625  char *rdata;
626 
627  (void) rd;
628  (void) zone_key;
629  request->qe = NULL;
630  if (0 != rd_count)
631  {
633  _ ("Found existing name `%s' for the given key\n"),
634  name);
635  request->phase = RP_FAIL;
636  MHD_resume_connection (request->con);
637  run_httpd_now ();
638  return;
639  }
641  &rdata,
642  &r.data_size,
643  &r.record_type))
644  {
646  _ ("Error creating record data.\n"));
647  request->phase = RP_FAIL;
648  MHD_resume_connection (request->con);
649  run_httpd_now ();
650  return;
651  }
652 
653  r.data = rdata;
654  r.expiration_time = UINT64_MAX;
656  request->qe = GNUNET_NAMESTORE_records_store (ns,
658  request->domain_name,
659  1, &r,
661  request);
662  GNUNET_free (rdata);
663 }
664 
665 
669 static void
670 lookup_it_error (void *cls)
671 {
672  struct Request *request = cls;
673 
674  MHD_resume_connection (request->con);
675  request->qe = NULL;
676  request->phase = RP_FAIL;
677  run_httpd_now ();
678 }
679 
680 
691 static void
693  const struct GNUNET_IDENTITY_PrivateKey *zonekey,
694  const char *label,
695  unsigned int rd_count,
696  const struct GNUNET_GNSRECORD_Data *rd)
697 {
698  struct Request *request = cls;
699 
700  (void) label;
701  (void) rd;
702  (void) zonekey;
703  if (0 == strcmp (label, request->domain_name))
704  {
705  GNUNET_break (0 != rd_count);
707  _ ("Found %u existing records for domain `%s'\n"),
708  rd_count,
709  request->domain_name);
710  request->phase = RP_FAIL;
711  }
713 }
714 
715 
716 static void
718 {
719  struct Request *request = cls;
720 
721  if (RP_FAIL == request->phase)
722  {
723  MHD_resume_connection (request->con);
724  run_httpd_now ();
725  return;
726  }
727  if (GNUNET_OK !=
729  &request->pub))
730  {
731  GNUNET_break (0);
732  request->phase = RP_FAIL;
733  MHD_resume_connection (request->con);
734  run_httpd_now ();
735  return;
736  }
737  request->qe = GNUNET_NAMESTORE_zone_to_name (ns,
739  &request->pub,
741  request,
743  request);
744 }
745 
746 
770 static MHD_RESULT
771 create_response (void *cls,
772  struct MHD_Connection *connection,
773  const char *url,
774  const char *method,
775  const char *version,
776  const char *upload_data,
777  size_t *upload_data_size,
778  void **ptr)
779 {
780  struct MHD_Response *response;
781  struct Request *request;
782  struct GNUNET_IDENTITY_PublicKey pub;
783  MHD_RESULT ret;
784 
785  (void) cls;
786  (void) version;
787  if ((0 == strcmp (method, MHD_HTTP_METHOD_GET)) ||
788  (0 == strcmp (method, MHD_HTTP_METHOD_HEAD)))
789  {
790  if (0 == strcmp (url, FCFS_ZONEINFO_URL))
791  ret = serve_zoneinfo_page (connection);
792  else
793  ret = serve_main_page (connection);
794  if (ret != MHD_YES)
796  _ ("Failed to create page for `%s'\n"),
797  url);
798  return ret;
799  }
800  if (0 == strcmp (method, MHD_HTTP_METHOD_POST))
801  {
802  request = *ptr;
803  if (NULL == request)
804  {
805  request = GNUNET_new (struct Request);
806  request->con = connection;
807  *ptr = request;
808  request->pp = MHD_create_post_processor (connection,
809  1024,
810  &post_iterator,
811  request);
812  if (NULL == request->pp)
813  {
815  _ ("Failed to setup post processor for `%s'\n"),
816  url);
817  return MHD_NO; /* internal error */
818  }
819  return MHD_YES;
820  }
821  if (NULL != request->pp)
822  {
823  /* evaluate POST data */
824  MHD_post_process (request->pp,
825  upload_data,
826  *upload_data_size);
827  if (0 != *upload_data_size)
828  {
829  *upload_data_size = 0;
830  return MHD_YES;
831  }
832  /* done with POST data, serve response */
833  MHD_destroy_post_processor (request->pp);
834  request->pp = NULL;
835  }
836  if (GNUNET_OK !=
838  &pub))
839  {
840  /* parse error */
841  return fill_s_reply ("Failed to parse given public key",
842  request, connection);
843  }
844  switch (request->phase)
845  {
846  case RP_START:
847  if (NULL != strchr (request->domain_name, (int) '.'))
848  {
850  _ ("Domain name must not contain `.'\n"));
851  request->phase = RP_FAIL;
852  return fill_s_reply ("Domain name must not contain `.', sorry.",
853  request,
854  connection);
855  }
856  if (NULL != strchr (request->domain_name, (int) '+'))
857  {
859  _ ("Domain name must not contain `+'\n"));
860  request->phase = RP_FAIL;
861  return fill_s_reply ("Domain name must not contain `+', sorry.",
862  request, connection);
863  }
864  request->phase = RP_LOOKUP;
865  MHD_suspend_connection (request->con);
866  request->lookup_it
870  request,
872  request,
874  request);
875  break;
876 
877  case RP_LOOKUP:
878  break;
879 
880  case RP_PUT:
881  break;
882 
883  case RP_FAIL:
884  return fill_s_reply ("Request failed, sorry.",
885  request, connection);
886 
887  case RP_SUCCESS:
888  return fill_s_reply ("Success.",
889  request, connection);
890 
891  default:
892  GNUNET_break (0);
893  return MHD_NO;
894  }
895  return MHD_YES; /* will have a reply later... */
896  }
897  /* unsupported HTTP method */
898  response = MHD_create_response_from_buffer (strlen (METHOD_ERROR),
899  (void *) METHOD_ERROR,
900  MHD_RESPMEM_PERSISTENT);
901  ret = MHD_queue_response (connection,
902  MHD_HTTP_NOT_ACCEPTABLE,
903  response);
904  MHD_destroy_response (response);
905  return ret;
906 }
907 
908 
918 static void
920  struct MHD_Connection *connection,
921  void **con_cls,
922  enum MHD_RequestTerminationCode toe)
923 {
924  struct Request *request = *con_cls;
925 
926  (void) cls;
927  (void) connection;
928  (void) toe;
929  if (NULL == request)
930  return;
931  if (NULL != request->pp)
932  MHD_destroy_post_processor (request->pp);
933  if (NULL != request->qe)
934  GNUNET_NAMESTORE_cancel (request->qe);
935  GNUNET_free (request);
936 }
937 
938 
939 #define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG
940 
941 
945 static void
947 {
948  fd_set rs;
949  fd_set ws;
950  fd_set es;
951  struct GNUNET_NETWORK_FDSet *wrs;
952  struct GNUNET_NETWORK_FDSet *wws;
953  struct GNUNET_NETWORK_FDSet *wes;
954  int max;
955  int haveto;
957  struct GNUNET_TIME_Relative tv;
958 
959  FD_ZERO (&rs);
960  FD_ZERO (&ws);
961  FD_ZERO (&es);
965  max = -1;
966  GNUNET_assert (MHD_YES ==
967  MHD_get_fdset (httpd,
968  &rs,
969  &ws,
970  &es,
971  &max));
972  haveto = MHD_get_timeout (httpd,
973  &timeout);
974  if (haveto == MHD_YES)
975  tv.rel_value_us = (uint64_t) timeout * 1000LL;
976  else
979  &rs,
980  max + 1);
982  &ws,
983  max + 1);
985  &es,
986  max + 1);
987  httpd_task =
989  tv,
990  wrs,
991  wws,
992  &do_httpd,
993  NULL);
997 }
998 
999 
1005 static void
1006 do_httpd (void *cls)
1007 {
1008  (void) cls;
1009  httpd_task = NULL;
1010  MHD_run (httpd);
1011  run_httpd ();
1012 }
1013 
1014 
1020 static void
1021 do_shutdown (void *cls)
1022 {
1023  (void) cls;
1024  if (NULL != httpd_task)
1025  {
1026  GNUNET_SCHEDULER_cancel (httpd_task);
1027  httpd_task = NULL;
1028  }
1029  if (NULL != uzp_task)
1030  {
1031  GNUNET_SCHEDULER_cancel (uzp_task);
1032  uzp_task = NULL;
1033  }
1034  if (NULL != ns)
1035  {
1037  ns = NULL;
1038  }
1039  if (NULL != httpd)
1040  {
1041  MHD_stop_daemon (httpd);
1042  httpd = NULL;
1043  }
1044  if (NULL != id_op)
1045  {
1046  GNUNET_IDENTITY_cancel (id_op);
1047  id_op = NULL;
1048  }
1049  if (NULL != identity)
1050  {
1051  GNUNET_IDENTITY_disconnect (identity);
1052  identity = NULL;
1053  }
1054 }
1055 
1056 
1075 static void
1076 identity_cb (void *cls,
1077  struct GNUNET_IDENTITY_Ego *ego,
1078  void **ctx,
1079  const char *name)
1080 {
1081  int options;
1082 
1083  (void) cls;
1084  (void) ctx;
1085  if (NULL == name)
1086  return;
1087  if (0 != strcmp (name,
1088  zone))
1089  return;
1090  if (NULL == ego)
1091  {
1093  _ ("No ego configured for `fcfsd` subsystem\n"));
1095  return;
1096  }
1098 
1099  options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
1100  do
1101  {
1102  httpd = MHD_start_daemon (options,
1103  (uint16_t) port,
1104  NULL, NULL,
1105  &create_response, NULL,
1106  MHD_OPTION_CONNECTION_LIMIT, (unsigned int) 128,
1107  MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned
1108  int) 1,
1109  MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int) 16,
1110  MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t) (4
1111  *
1112  1024),
1113  MHD_OPTION_NOTIFY_COMPLETED,
1115  MHD_OPTION_END);
1116  if (MHD_USE_DEBUG == options)
1117  break;
1118  options = MHD_USE_DEBUG;
1119  }
1120  while (NULL == httpd);
1121  if (NULL == httpd)
1122  {
1124  _ ("Failed to start HTTP server\n"));
1126  return;
1127  }
1128  run_httpd ();
1129 }
1130 
1131 
1140 static void
1141 run (void *cls,
1142  char *const *args,
1143  const char *cfgfile,
1144  const struct GNUNET_CONFIGURATION_Handle *cfg)
1145 {
1146  (void) cls;
1147  (void) args;
1148  (void) cfgfile;
1149  if (GNUNET_OK !=
1151  "fcfsd",
1152  "HTTPPORT",
1153  &port))
1154  {
1156  "fcfsd", "HTTPPORT");
1157  return;
1158  }
1159  ns = GNUNET_NAMESTORE_connect (cfg);
1160  if (NULL == ns)
1161  {
1163  _ ("Failed to connect to namestore\n"));
1164  return;
1165  }
1166  identity = GNUNET_IDENTITY_connect (cfg,
1167  &identity_cb,
1168  NULL);
1169  if (NULL == identity)
1170  {
1172  _ ("Failed to connect to identity\n"));
1173  return;
1174  }
1176  NULL);
1178  NULL);
1179 }
1180 
1181 
1189 int
1190 main (int argc,
1191  char *const *argv)
1192 {
1193  struct GNUNET_GETOPT_CommandLineOption options[] = {
1196  "zone",
1197  "EGO",
1198  gettext_noop (
1199  "name of the zone that is to be managed by FCFSD"),
1200  &zone)),
1202  };
1203  int ret;
1204 
1205  if (GNUNET_OK !=
1206  GNUNET_STRINGS_get_utf8_args (argc, argv,
1207  &argc, &argv))
1208  return 2;
1209 
1210  GNUNET_log_setup ("fcfsd",
1211  "WARNING",
1212  NULL);
1213  ret =
1214  (GNUNET_OK ==
1215  GNUNET_PROGRAM_run (argc,
1216  argv,
1217  "gnunet-namestore-fcfsd",
1218  _ (
1219  "GNU Name System First Come First Serve name registration service"),
1220  options,
1221  &run, NULL)) ? 0 : 1;
1222  GNUNET_free_nz ((void *) argv);
1223  // FIXME
1224  // GNUNET_CRYPTO_ecdsa_key_clear (&fcfs_zone_pkey);
1225  return ret;
1226 }
1227 
1228 
1229 /* end of gnunet-namestore-fcfsd.c */
struct GNUNET_IDENTITY_Handle * GNUNET_IDENTITY_connect(const struct GNUNET_CONFIGURATION_Handle *cfg, GNUNET_IDENTITY_Callback cb, void *cb_cls)
Connect to the identity service.
Definition: identity_api.c:610
struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator.
#define GNUNET_GNSRECORD_TYPE_PKEY
WARNING: This header is generated! In order to add GNS record types, you must register them in GANA...
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:904
static int fill_s_reply(const char *info, struct Request *request, struct MHD_Connection *connection)
Send the &#39;SUBMIT_PAGE&#39;.
Run with high priority (important requests).
#define SUBMIT_PAGE
Second page (/S)
static struct GNUNET_VPN_RedirectionRequest * request
Opaque redirection request handle.
Definition: gnunet-vpn.c:41
enum GNUNET_GenericReturnValue GNUNET_PROGRAM_run(int argc, char *const *argv, const char *binaryName, const char *binaryHelp, const struct GNUNET_GETOPT_CommandLineOption *options, GNUNET_PROGRAM_Main task, void *task_cls)
Run a standard GNUnet command startup sequence (initialize loggers and configuration, parse options).
Definition: program.c:363
struct GNUNET_NAMESTORE_ZoneIterator * lookup_it
Active lookup iterator TODO: deprecate or fix lookup by label and use above member.
static const struct GNUNET_CONFIGURATION_Handle * cfg
Configuration we are using.
Definition: gnunet-abd.c:36
uint64_t rel_value_us
The actual value.
static char * pkey
Public key of the zone to look in, in ASCII.
static struct GNUNET_IDENTITY_PrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
static void iterate_cb(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *name, unsigned int rd_len, const struct GNUNET_GNSRECORD_Data *rd)
Process a record that was stored in the namestore, adding the information to the HTML.
static void do_httpd(void *cls)
Task run whenever HTTP server operations are pending.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_shutdown(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run on shutdown, that is when a CTRL-C signal is received, or when GNUNET_SCHEDULER_shutdown() is being invoked.
Definition: scheduler.c:1331
static void put_continuation(void *cls, int32_t success, const char *emsg)
Continuation called to notify client about result of the operation.
#define GNUNET_TIME_UNIT_MINUTES
One minute.
int GNUNET_STRINGS_get_utf8_args(int argc, char *const *argv, int *u8argc, char *const **u8argv)
Returns utf-8 encoded arguments.
Definition: strings.c:1459
static struct GNUNET_SCHEDULER_Task * httpd_task
Main HTTP task.
char public_key[128]
Public key submitted via form.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
#define DEFAULT_ZONEINFO_BUFSIZE
Storing of the record.
A private key for an identity as per LSD0001.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
enum GNUNET_GenericReturnValue GNUNET_CONFIGURATION_get_value_number(const struct GNUNET_CONFIGURATION_Handle *cfg, const char *section, const char *option, unsigned long long *number)
Get a configuration value that should be a number.
size_t data_size
Number of bytes in data.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *pkey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd, GNUNET_NAMESTORE_ContinuationWithStatus cont, void *cont_cls)
Store an item in the namestore.
#define GNUNET_new(type)
Allocate a struct or union of the given type.
Definition of a command line option.
void GNUNET_NAMESTORE_zone_iterator_next(struct GNUNET_NAMESTORE_ZoneIterator *it, uint64_t limit)
Calls the record processor specified in GNUNET_NAMESTORE_zone_iteration_start for the next record...
static struct GNUNET_IDENTITY_Handle * identity
Connection to identity service.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:531
static void do_shutdown(void *cls)
Task run on shutdown.
#define GNUNET_break(cond)
Use this for internal assertion violations that are not fatal (can be handled) but should not occur...
struct MHD_Connection * con
MHD Connection.
static void identity_cb(void *cls, struct GNUNET_IDENTITY_Ego *ego, void **ctx, const char *name)
Method called to inform about the egos of this peer.
Handle for an operation with the identity service.
Definition: identity_api.c:39
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_OPTION_END
Definition: 002.c:13
static struct GNUNET_DNSSTUB_Context * ctx
Context for DNS resolution.
#define MAIN_PAGE
Front page.
void GNUNET_NETWORK_fdset_copy_native(struct GNUNET_NETWORK_FDSet *to, const fd_set *from, int nfds)
Copy a native fd set into the GNUnet representation.
Definition: network.c:1117
void GNUNET_NAMESTORE_cancel(struct GNUNET_NAMESTORE_QueueEntry *qe)
Cancel a namestore operation.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_string(char shortName, const char *name, const char *argumentHelp, const char *description, char **str)
Allow user to specify a string.
#define _(String)
GNU gettext support macro.
Definition: platform.h:178
#define METHOD_ERROR
Invalid method page.
#define max(x, y)
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1263
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
Zoneinfo request.
static void request_completed_callback(void *cls, struct MHD_Connection *connection, void **con_cls, enum MHD_RequestTerminationCode toe)
Callback called upon completion of a request.
Handle for a zone iterator operation.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_delayed(struct GNUNET_TIME_Relative delay, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay.
Definition: scheduler.c:1269
Handle for an ego.
Definition: identity.h:36
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1247
Phase
Phases a request goes through.
static struct MHD_Response * info_page
Zoneinfo page we currently use.
static struct GNUNET_TIME_Relative timeout
Desired timeout for the lookup (default is no timeout).
Definition: gnunet-abd.c:61
const void * data
Binary value stored in the DNS record.
void GNUNET_log_config_missing(enum GNUNET_ErrorType kind, const char *section, const char *option)
Log error message about missing configuration option.
static void update_zoneinfo_page(void *cls)
Create fresh version of zone information.
#define UNSIGNED_MHD_LONG_LONG
Connection to the NAMESTORE service.
Handle for the service.
Definition: identity_api.c:95
uint64_t expiration_time
Expiration time for the DNS record.
struct GNUNET_NAMESTORE_ZoneIterator * zi
Active iteration with the namestore.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_now(GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run as soon as possible.
Definition: scheduler.c:1296
collection of IO descriptors
static char * filename
char domain_name[64]
Domain name submitted via form.
struct GNUNET_SCHEDULER_Task * GNUNET_SCHEDULER_add_select(enum GNUNET_SCHEDULER_Priority prio, struct GNUNET_TIME_Relative delay, const struct GNUNET_NETWORK_FDSet *rs, const struct GNUNET_NETWORK_FDSet *ws, GNUNET_SCHEDULER_TaskCallback task, void *task_cls)
Schedule a new task to be run with a specified delay or when any of the specified file descriptor set...
Definition: scheduler.c:1841
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, const struct GNUNET_IDENTITY_PublicKey *value_zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls)
Look for an existing PKEY delegation record for a given public key.
#define GNUNET_TIME_UNIT_FOREVER_REL
Constant used to specify "forever".
Lookup to see if the domain name is taken.
struct GNUNET_GETOPT_CommandLineOption GNUNET_GETOPT_option_mandatory(struct GNUNET_GETOPT_CommandLineOption opt)
Make the given option mandatory.
void GNUNET_IDENTITY_disconnect(struct GNUNET_IDENTITY_Handle *h)
Disconnect from identity service.
Definition: identity_api.c:921
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static void lookup_it_finished(void *cls)
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_IDENTITY_PrivateKey *zone, GNUNET_SCHEDULER_TaskCallback error_cb, void *error_cb_cls, GNUNET_NAMESTORE_RecordMonitor proc, void *proc_cls, GNUNET_SCHEDULER_TaskCallback finish_cb, void *finish_cb_cls)
Starts a new zone iteration (used to periodically PUT all of our records into our DHT)...
static void run_httpd_now()
Schedule task to run MHD server now.
Start phase (parsing POST, checking).
const char * post_url
URL to serve in response to this POST (if this request was a &#39;POST&#39;)
static void lookup_it_processor(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zonekey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We got a block back from the namestore.
Send failure message.
int int GNUNET_asprintf(char **buf, const char *format,...) __attribute__((format(printf
Like asprintf, just portable.
enum GNUNET_GenericReturnValue GNUNET_IDENTITY_public_key_from_string(const char *str, struct GNUNET_IDENTITY_PublicKey *key)
Parses a (Base32) string representation of the public key.
#define ZONEINFO_PAGE
Fcfs zoneinfo page (/Zoneinfo)
#define GNUNET_free_nz(ptr)
Wrapper around free.
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:67
An QueueEntry used to store information for a pending NAMESTORE record operation. ...
Definition: namestore_api.c:53
struct GNUNET_NAMESTORE_Handle * GNUNET_NAMESTORE_connect(const struct GNUNET_CONFIGURATION_Handle *cfg)
Connect to the namestore service.
static void zone_iteration_error(void *cls)
Function called on error in zone iteration.
#define MHD_RESULT
Data type to use for functions return an "MHD result".
static void zone_to_name_cb(void *cls, const struct GNUNET_IDENTITY_PrivateKey *zone_key, const char *name, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
Test if a name mapping was found, if so, refuse.
static int serve_zoneinfo_page(struct MHD_Connection *connection)
Handler that returns FCFS zoneinfo page.
size_t buf_len
Buffer length.
static void zone_iteration_end(void *cls)
Function called once the zone iteration is done.
struct GNUNET_NAMESTORE_QueueEntry * qe
Active request with the namestore.
static struct GNUNET_SCHEDULER_Task * uzp_task
Task that runs update_zoneinfo_page peridicially.
Request we should make.
struct GNUNET_DNSSTUB_RequestSocket * rs
Socket used to make the request, NULL if not active.
static void lookup_it_error(void *cls)
We encountered an error in the name lookup.
static MHD_RESULT post_iterator(void *cls, enum MHD_ValueKind kind, const char *key, const char *filename, const char *content_type, const char *transfer_encoding, const char *data, uint64_t off, size_t size)
Iterator over key-value pairs where the value maybe made available in increments and/or may not be ze...
An identity key as per LSD0001.
uint32_t record_type
Type of the GNS/DNS record.
configuration data
Definition: configuration.c:84
const char * name
const struct GNUNET_IDENTITY_PrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:639
size_t write_offset
Buffer write offset.
struct GNUNET_IDENTITY_PublicKey pub
void * cls
Closure for cont or cb.
Definition: identity_api.c:88
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
#define GNUNET_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:134
static MHD_RESULT create_response(void *cls, struct MHD_Connection *connection, const char *url, const char *method, const char *version, const char *upload_data, size_t *upload_data_size, void **ptr)
Main MHD callback for handling requests.
static void run_httpd()
Schedule tasks to run MHD server.
const struct Zone * zone
Zone responsible for this request.
static struct MHD_Response * response
Our canonical response.
static struct MHD_Daemon * httpd
MHD daemon reference.
enum Phase phase
Current processing phase.
#define MIME_HTML
Mime type for HTML pages.
#define FCFS_ZONEINFO_URL
enum GNUNET_GNSRECORD_Flags flags
Flags for the record.
#define GNUNET_GNSRECORD_TYPE_EDKEY
Record type for EDKEY zone delegations.
int GNUNET_log_setup(const char *comp, const char *loglevel, const char *logfile)
Setup logging.
static int serve_main_page(struct MHD_Connection *connection)
Handler that returns a simple static HTTP page.
uint32_t data
The data value.
char * GNUNET_GNSRECORD_value_to_string(uint32_t type, const void *data, size_t data_size)
Convert the &#39;value&#39; of a record to a string.
Definition: gnsrecord.c:156
static void zone_to_name_error(void *cls)
Function called if we had an error in zone-to-name mapping.
#define GNUNET_malloc(size)
Wrapper around malloc.
static unsigned long long port
Port we use for the HTTP server.
#define GNUNET_free(ptr)
Wrapper around free.
Time for relative time used by GNUnet, in microseconds.
We&#39;re done with success.
struct MHD_PostProcessor * pp
Associated session.
static struct GNUNET_IDENTITY_Operation * id_op
Request for our ego.
#define gettext_noop(String)
Definition: gettext.h:69
enum GNUNET_GenericReturnValue GNUNET_GNSRECORD_data_from_identity(const struct GNUNET_IDENTITY_PublicKey *key, char **data, size_t *data_size, uint32_t *type)
Create record data and size from an identity key.
int main(int argc, char *const *argv)
The main function for the fcfs daemon.
void * GNUNET_SCHEDULER_cancel(struct GNUNET_SCHEDULER_Task *task)
Cancel the task with the specified identifier.
Definition: scheduler.c:972