GNUnet  0.10.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 
43 #define METHOD_ERROR "<!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>"
44 
48 #define MAIN_PAGE "<!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>"
49 
53 #define SUBMIT_PAGE "<!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>"
54 
58 #define ZONEINFO_PAGE "<!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>"
59 
60 #define FCFS_ZONEINFO_URL "/Zoneinfo"
61 
65 #define MIME_HTML "text/html"
66 
70 #define COOKIE_NAME "namestore-fcfsd"
71 
72 #define DEFAULT_ZONEINFO_BUFSIZE 2048
73 
77 enum Phase {
81  RP_START = 0,
82 
87 
92 
97 
102 };
103 
104 
108 struct Request {
112  // FIXME: struct Session *session;
113 
118  struct MHD_PostProcessor *pp;
119 
123  struct MHD_Connection *con;
128  const char *post_url;
129 
134 
144 
148  enum Phase phase;
149 
153  char domain_name[64];
154 
158  char public_key[128];
159 
161 };
162 
171 
175  char* zoneinfo;
176 
180  size_t buf_len;
181 
185  size_t write_offset;
186 };
187 
191 static struct MHD_Daemon *httpd;
192 
197 
202 
207 
212 
216 static struct MHD_Response *info_page;
217 
222 
227 
231 static unsigned long long port;
232 
236 static char *zone;
237 
238 
244 static void
245 do_httpd(void *cls);
246 
247 
251 static void
253 {
254  if (NULL != httpd_task)
255  {
256  GNUNET_SCHEDULER_cancel(httpd_task);
257  httpd_task = NULL;
258  }
259  httpd_task = GNUNET_SCHEDULER_add_now(&do_httpd, NULL);
260 }
261 
262 
266 static void
268 
269 
273 static void
275 {
276  struct ZoneinfoRequest *zr = cls;
277 
278  zr->list_it = NULL;
279  GNUNET_free(zr->zoneinfo);
280  GNUNET_SCHEDULER_cancel(uzp_task);
282  NULL);
283 }
284 
285 
289 static void
291 {
292  struct ZoneinfoRequest *zr = cls;
293  struct MHD_Response *response;
294  char* full_page;
295 
296  zr->list_it = NULL;
297 
298  /* return static form */
299  GNUNET_asprintf(&full_page,
301  zr->zoneinfo,
302  zr->zoneinfo);
303  response = MHD_create_response_from_buffer(strlen(full_page),
304  (void *)full_page,
305  MHD_RESPMEM_MUST_FREE);
306  MHD_add_response_header(response,
307  MHD_HTTP_HEADER_CONTENT_TYPE,
308  MIME_HTML);
309  MHD_destroy_response(info_page);
311  GNUNET_free(zr->zoneinfo);
312 }
313 
314 
325 static void
326 iterate_cb(void *cls,
327  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
328  const char *name,
329  unsigned int rd_len,
330  const struct GNUNET_GNSRECORD_Data *rd)
331 {
332  struct ZoneinfoRequest *zr = cls;
333  size_t bytes_free;
334  char* pkey;
335  char* new_buf;
336 
337  (void)zone_key;
338  if (1 != rd_len)
339  {
341  1);
342  return;
343  }
344 
346  {
348  1);
349  return;
350  }
351 
352  bytes_free = zr->buf_len - zr->write_offset;
354  rd->data,
355  rd->data_size);
356  if (NULL == pkey)
357  {
358  GNUNET_break(0);
360  1);
361  return;
362  }
363  if (bytes_free < (strlen(name) + strlen(pkey) + 40))
364  {
365  new_buf = GNUNET_malloc(zr->buf_len * 2);
366  GNUNET_memcpy(new_buf, zr->zoneinfo, zr->write_offset);
367  GNUNET_free(zr->zoneinfo);
368  zr->zoneinfo = new_buf;
369  zr->buf_len *= 2;
370  }
371  sprintf(zr->zoneinfo + zr->write_offset,
372  "<tr><td>%s</td><td>%s</td></tr>",
373  name,
374  pkey);
375  zr->write_offset = strlen(zr->zoneinfo);
377  1);
378  GNUNET_free(pkey);
379 }
380 
381 
387 static int
388 serve_zoneinfo_page(struct MHD_Connection *connection)
389 {
390  return MHD_queue_response(connection,
391  MHD_HTTP_OK,
392  info_page);
393 }
394 
395 
399 static void
401 {
402  static struct ZoneinfoRequest zr;
403 
404  (void)cls;
407  NULL);
408  if (NULL != zr.list_it)
409  return;
412  zr.write_offset = 0;
416  &zr,
417  &iterate_cb,
418  &zr,
420  &zr);
421 }
422 
423 
430 static int
431 serve_main_page(struct MHD_Connection *connection)
432 {
433  int ret;
434  struct MHD_Response *response;
435 
436  /* return static form */
437  response = MHD_create_response_from_buffer(strlen(MAIN_PAGE),
438  (void *)MAIN_PAGE,
439  MHD_RESPMEM_PERSISTENT);
440  MHD_add_response_header(response,
441  MHD_HTTP_HEADER_CONTENT_TYPE,
442  MIME_HTML);
443  ret = MHD_queue_response(connection,
444  MHD_HTTP_OK,
445  response);
446  MHD_destroy_response(response);
447  return ret;
448 }
449 
450 
458 static int
459 fill_s_reply(const char *info,
460  struct Request *request,
461  struct MHD_Connection *connection)
462 {
463  int ret;
464  char *reply;
465  struct MHD_Response *response;
466 
467  (void)request;
468  GNUNET_asprintf(&reply,
469  SUBMIT_PAGE,
470  info,
471  info);
472  /* return static form */
473  response = MHD_create_response_from_buffer(strlen(reply),
474  (void *)reply,
475  MHD_RESPMEM_MUST_FREE);
476  MHD_add_response_header(response,
477  MHD_HTTP_HEADER_CONTENT_TYPE,
478  MIME_HTML);
479  ret = MHD_queue_response(connection,
480  MHD_HTTP_OK,
481  response);
482  MHD_destroy_response(response);
483  return ret;
484 }
485 
486 
506 static int
507 post_iterator(void *cls,
508  enum MHD_ValueKind kind,
509  const char *key,
510  const char *filename,
511  const char *content_type,
512  const char *transfer_encoding,
513  const char *data,
514  uint64_t off,
515  size_t size)
516 {
517  struct Request *request = cls;
518 
519  (void)kind;
520  (void)filename;
521  (void)content_type;
522  (void)transfer_encoding;
523  if (0 == strcmp("domain", key))
524  {
525  if (size + off >= sizeof(request->domain_name))
526  size = sizeof(request->domain_name) - off - 1;
527  GNUNET_memcpy(&request->domain_name[off],
528  data,
529  size);
530  request->domain_name[size + off] = '\0';
531  return MHD_YES;
532  }
533  if (0 == strcmp("pkey", key))
534  {
535  if (size + off >= sizeof(request->public_key))
536  size = sizeof(request->public_key) - off - 1;
537  GNUNET_memcpy(&request->public_key[off],
538  data,
539  size);
540  request->public_key[size + off] = '\0';
541  return MHD_YES;
542  }
544  _("Unsupported form value `%s'\n"),
545  key);
546  return MHD_YES;
547 }
548 
549 
560 static void
562  int32_t success,
563  const char *emsg)
564 {
565  struct Request *request = cls;
566 
567  request->qe = NULL;
568  if (0 >= success)
569  {
571  _("Failed to create record for domain `%s': %s\n"),
572  request->domain_name,
573  emsg);
574  request->phase = RP_FAIL;
575  }
576  else
577  request->phase = RP_SUCCESS;
578  MHD_resume_connection(request->con);
579  run_httpd_now();
580 }
581 
582 
586 static void
588 {
589  struct Request *request = cls;
590 
592  _("Error when mapping zone to name\n"));
593  request->phase = RP_FAIL;
594  MHD_resume_connection(request->con);
595  run_httpd_now();
596 }
597 
598 
608 static void
609 zone_to_name_cb(void *cls,
610  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone_key,
611  const char *name,
612  unsigned int rd_count,
613  const struct GNUNET_GNSRECORD_Data *rd)
614 {
615  struct Request *request = cls;
616  struct GNUNET_GNSRECORD_Data r;
617 
618  (void)rd;
619  (void)zone_key;
620  request->qe = NULL;
621  if (0 != rd_count)
622  {
624  _("Found existing name `%s' for the given key\n"),
625  name);
626  request->phase = RP_FAIL;
627  MHD_resume_connection(request->con);
628  run_httpd_now();
629  return;
630  }
631  r.data = &request->pub;
632  r.data_size = sizeof(request->pub);
633  r.expiration_time = UINT64_MAX;
636  request->qe = GNUNET_NAMESTORE_records_store(ns,
638  request->domain_name,
639  1, &r,
641  request);
642 }
643 
644 
648 static void
649 lookup_it_error(void *cls)
650 {
651  struct Request *request = cls;
652 
653  MHD_resume_connection(request->con);
654  request->qe = NULL;
655  request->phase = RP_FAIL;
656  run_httpd_now();
657 }
658 
659 
670 static void
672  const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey,
673  const char *label,
674  unsigned int rd_count,
675  const struct GNUNET_GNSRECORD_Data *rd)
676 {
677  struct Request *request = cls;
678 
679  (void)label;
680  (void)rd;
681  (void)zonekey;
682  if (0 == strcmp(label, request->domain_name))
683  {
684  GNUNET_break(0 != rd_count);
686  _("Found %u existing records for domain `%s'\n"),
687  rd_count,
688  request->domain_name);
689  request->phase = RP_FAIL;
690  }
692 }
693 
694 static void
696 {
697  struct Request *request = cls;
698 
699  if (RP_FAIL == request->phase)
700  {
701  MHD_resume_connection(request->con);
702  run_httpd_now();
703  return;
704  }
705  if (GNUNET_OK !=
707  strlen(request->public_key),
708  &request->pub))
709  {
710  GNUNET_break(0);
711  request->phase = RP_FAIL;
712  MHD_resume_connection(request->con);
713  run_httpd_now();
714  return;
715  }
716  request->qe = GNUNET_NAMESTORE_zone_to_name(ns,
718  &request->pub,
720  request,
722  request);
723 }
724 
748 static int
749 create_response(void *cls,
750  struct MHD_Connection *connection,
751  const char *url,
752  const char *method,
753  const char *version,
754  const char *upload_data,
755  size_t *upload_data_size,
756  void **ptr)
757 {
758  struct MHD_Response *response;
759  struct Request *request;
760  struct GNUNET_CRYPTO_EcdsaPublicKey pub;
761  int ret;
762 
763  (void)cls;
764  (void)version;
765  if ((0 == strcmp(method, MHD_HTTP_METHOD_GET)) ||
766  (0 == strcmp(method, MHD_HTTP_METHOD_HEAD)))
767  {
768  if (0 == strcmp(url, FCFS_ZONEINFO_URL))
769  ret = serve_zoneinfo_page(connection);
770  else
771  ret = serve_main_page(connection);
772  if (ret != MHD_YES)
774  _("Failed to create page for `%s'\n"),
775  url);
776  return ret;
777  }
778  if (0 == strcmp(method, MHD_HTTP_METHOD_POST))
779  {
780  request = *ptr;
781  if (NULL == request)
782  {
783  request = GNUNET_new(struct Request);
784  request->con = connection;
785  *ptr = request;
786  request->pp = MHD_create_post_processor(connection,
787  1024,
788  &post_iterator,
789  request);
790  if (NULL == request->pp)
791  {
793  _("Failed to setup post processor for `%s'\n"),
794  url);
795  return MHD_NO; /* internal error */
796  }
797  return MHD_YES;
798  }
799  if (NULL != request->pp)
800  {
801  /* evaluate POST data */
802  MHD_post_process(request->pp,
803  upload_data,
804  *upload_data_size);
805  if (0 != *upload_data_size)
806  {
807  *upload_data_size = 0;
808  return MHD_YES;
809  }
810  /* done with POST data, serve response */
811  MHD_destroy_post_processor(request->pp);
812  request->pp = NULL;
813  }
814  if (GNUNET_OK !=
816  strlen(request->public_key),
817  &pub))
818  {
819  /* parse error */
820  return fill_s_reply("Failed to parse given public key",
821  request, connection);
822  }
823  switch (request->phase)
824  {
825  case RP_START:
826  if (NULL != strchr(request->domain_name, (int)'.'))
827  {
829  _("Domain name must not contain `.'\n"));
830  request->phase = RP_FAIL;
831  return fill_s_reply("Domain name must not contain `.', sorry.",
832  request,
833  connection);
834  }
835  if (NULL != strchr(request->domain_name, (int)'+'))
836  {
838  _("Domain name must not contain `+'\n"));
839  request->phase = RP_FAIL;
840  return fill_s_reply("Domain name must not contain `+', sorry.",
841  request, connection);
842  }
843  request->phase = RP_LOOKUP;
844  MHD_suspend_connection(request->con);
845  request->lookup_it
849  request,
851  request,
853  request);
854  break;
855 
856  case RP_LOOKUP:
857  break;
858 
859  case RP_PUT:
860  break;
861 
862  case RP_FAIL:
863  return fill_s_reply("Request failed, sorry.",
864  request, connection);
865 
866  case RP_SUCCESS:
867  return fill_s_reply("Success.",
868  request, connection);
869 
870  default:
871  GNUNET_break(0);
872  return MHD_NO;
873  }
874  return MHD_YES; /* will have a reply later... */
875  }
876  /* unsupported HTTP method */
877  response = MHD_create_response_from_buffer(strlen(METHOD_ERROR),
878  (void *)METHOD_ERROR,
879  MHD_RESPMEM_PERSISTENT);
880  ret = MHD_queue_response(connection,
881  MHD_HTTP_NOT_ACCEPTABLE,
882  response);
883  MHD_destroy_response(response);
884  return ret;
885 }
886 
887 
897 static void
899  struct MHD_Connection *connection,
900  void **con_cls,
901  enum MHD_RequestTerminationCode toe)
902 {
903  struct Request *request = *con_cls;
904 
905  (void)cls;
906  (void)connection;
907  (void)toe;
908  if (NULL == request)
909  return;
910  if (NULL != request->pp)
911  MHD_destroy_post_processor(request->pp);
912  if (NULL != request->qe)
913  GNUNET_NAMESTORE_cancel(request->qe);
914  GNUNET_free(request);
915 }
916 
917 
918 #define UNSIGNED_MHD_LONG_LONG unsigned MHD_LONG_LONG
919 
920 
924 static void
926 {
927  fd_set rs;
928  fd_set ws;
929  fd_set es;
930  struct GNUNET_NETWORK_FDSet *wrs;
931  struct GNUNET_NETWORK_FDSet *wws;
932  struct GNUNET_NETWORK_FDSet *wes;
933  int max;
934  int haveto;
936  struct GNUNET_TIME_Relative tv;
937 
938  FD_ZERO(&rs);
939  FD_ZERO(&ws);
940  FD_ZERO(&es);
944  max = -1;
945  GNUNET_assert(MHD_YES ==
946  MHD_get_fdset(httpd,
947  &rs,
948  &ws,
949  &es,
950  &max));
951  haveto = MHD_get_timeout(httpd,
952  &timeout);
953  if (haveto == MHD_YES)
954  tv.rel_value_us = (uint64_t)timeout * 1000LL;
955  else
958  &rs,
959  max + 1);
961  &ws,
962  max + 1);
964  &es,
965  max + 1);
966  httpd_task =
968  tv,
969  wrs,
970  wws,
971  &do_httpd,
972  NULL);
976 }
977 
978 
984 static void
985 do_httpd(void *cls)
986 {
987  (void)cls;
988  httpd_task = NULL;
989  MHD_run(httpd);
990  run_httpd();
991 }
992 
993 
999 static void
1000 do_shutdown(void *cls)
1001 {
1002  (void)cls;
1003  if (NULL != httpd_task)
1004  {
1005  GNUNET_SCHEDULER_cancel(httpd_task);
1006  httpd_task = NULL;
1007  }
1008  if (NULL != uzp_task)
1009  {
1010  GNUNET_SCHEDULER_cancel(uzp_task);
1011  uzp_task = NULL;
1012  }
1013  if (NULL != ns)
1014  {
1016  ns = NULL;
1017  }
1018  if (NULL != httpd)
1019  {
1020  MHD_stop_daemon(httpd);
1021  httpd = NULL;
1022  }
1023  if (NULL != id_op)
1024  {
1025  GNUNET_IDENTITY_cancel(id_op);
1026  id_op = NULL;
1027  }
1028  if (NULL != identity)
1029  {
1030  GNUNET_IDENTITY_disconnect(identity);
1031  identity = NULL;
1032  }
1033 }
1034 
1035 
1055 static void
1056 identity_cb(void *cls,
1057  struct GNUNET_IDENTITY_Ego *ego,
1058  void **ctx,
1059  const char *name)
1060 {
1061  int options;
1062 
1063  (void)cls;
1064  (void)ctx;
1065  if (NULL == name)
1066  return;
1067  if (0 != strcmp(name,
1068  zone))
1069  return;
1070  if (NULL == ego)
1071  {
1073  _("No ego configured for `fcfsd` subsystem\n"));
1075  return;
1076  }
1078 
1079  options = MHD_USE_DUAL_STACK | MHD_USE_DEBUG | MHD_ALLOW_SUSPEND_RESUME;
1080  do
1081  {
1082  httpd = MHD_start_daemon(options,
1083  (uint16_t)port,
1084  NULL, NULL,
1085  &create_response, NULL,
1086  MHD_OPTION_CONNECTION_LIMIT, (unsigned int)128,
1087  MHD_OPTION_PER_IP_CONNECTION_LIMIT, (unsigned int)1,
1088  MHD_OPTION_CONNECTION_TIMEOUT, (unsigned int)16,
1089  MHD_OPTION_CONNECTION_MEMORY_LIMIT, (size_t)(4 * 1024),
1090  MHD_OPTION_NOTIFY_COMPLETED, &request_completed_callback, NULL,
1091  MHD_OPTION_END);
1092  if (MHD_USE_DEBUG == options)
1093  break;
1094  options = MHD_USE_DEBUG;
1095  }
1096  while (NULL == httpd);
1097  if (NULL == httpd)
1098  {
1100  _("Failed to start HTTP server\n"));
1102  return;
1103  }
1104  run_httpd();
1105 }
1106 
1107 
1116 static void
1117 run(void *cls,
1118  char *const *args,
1119  const char *cfgfile,
1120  const struct GNUNET_CONFIGURATION_Handle *cfg)
1121 {
1122  (void)cls;
1123  (void)args;
1124  (void)cfgfile;
1125  if (GNUNET_OK !=
1127  "fcfsd",
1128  "HTTPPORT",
1129  &port))
1130  {
1132  "fcfsd", "HTTPPORT");
1133  return;
1134  }
1135  ns = GNUNET_NAMESTORE_connect(cfg);
1136  if (NULL == ns)
1137  {
1139  _("Failed to connect to namestore\n"));
1140  return;
1141  }
1142  identity = GNUNET_IDENTITY_connect(cfg,
1143  &identity_cb,
1144  NULL);
1145  if (NULL == identity)
1146  {
1148  _("Failed to connect to identity\n"));
1149  return;
1150  }
1152  NULL);
1154  NULL);
1155 }
1156 
1157 
1165 int
1166 main(int argc,
1167  char *const *argv)
1168 {
1169  struct GNUNET_GETOPT_CommandLineOption options[] = {
1172  "zone",
1173  "EGO",
1174  gettext_noop("name of the zone that is to be managed by FCFSD"),
1175  &zone)),
1177  };
1178  int ret;
1179 
1180  if (GNUNET_OK !=
1181  GNUNET_STRINGS_get_utf8_args(argc, argv,
1182  &argc, &argv))
1183  return 2;
1184 
1185  GNUNET_log_setup("fcfsd",
1186  "WARNING",
1187  NULL);
1188  ret =
1189  (GNUNET_OK ==
1190  GNUNET_PROGRAM_run(argc,
1191  argv,
1192  "gnunet-namestore-fcfsd",
1193  _("GNU Name System First Come First Serve name registration service"),
1194  options,
1195  &run, NULL)) ? 0 : 1;
1196  GNUNET_free((void*)argv);
1198  return ret;
1199 }
1200 
1201 /* 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:525
struct GNUNET_NAMESTORE_ZoneIterator * list_it
List iterator.
void GNUNET_IDENTITY_cancel(struct GNUNET_IDENTITY_Operation *op)
Cancel an identity operation.
Definition: identity_api.c:816
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
struct GNUNET_NAMESTORE_ZoneIterator * lookup_it
Active lookup iterator TODO: deprecate or fix lookup by label and use above member.
int 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.
uint64_t rel_value_us
The actual value.
static char * pkey
Public key of the zone to look in, in ASCII.
struct GNUNET_GETOPT_CommandLineOption options[]
Definition: 002.c:5
void GNUNET_CRYPTO_ecdsa_key_clear(struct GNUNET_CRYPTO_EcdsaPrivateKey *pk)
Clear memory that was used to store a private key.
Definition: crypto_ecc.c:585
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:1284
struct GNUNET_NAMESTORE_ZoneIterator * GNUNET_NAMESTORE_zone_iteration_start(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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 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:1439
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.
const struct GNUNET_CRYPTO_EcdsaPrivateKey * GNUNET_IDENTITY_ego_get_private_key(const struct GNUNET_IDENTITY_Ego *ego)
Obtain the ECC key associated with a ego.
Definition: identity_api.c:553
#define DEFAULT_ZONEINFO_BUFSIZE
Storing of the record.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
size_t data_size
Number of bytes in data.
#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...
Private ECC key encoded for transmission.
static struct GNUNET_IDENTITY_Handle * identity
Connection to identity service.
void GNUNET_SCHEDULER_shutdown(void)
Request the shutdown of a scheduler.
Definition: scheduler.c:517
static int ret
Final status code.
Definition: gnunet-arm.c:89
static void iterate_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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_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:1108
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.
static int 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.
#define _(String)
GNU gettext support macro.
Definition: platform.h:181
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_records_store(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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 METHOD_ERROR
Invalid method page.
void GNUNET_NETWORK_fdset_destroy(struct GNUNET_NETWORK_FDSet *fds)
Releases the associated memory of an fd set.
Definition: network.c:1254
void GNUNET_NAMESTORE_disconnect(struct GNUNET_NAMESTORE_Handle *h)
Disconnect from the namestore service (and free associated resources).
Zoneinfo request.
int GNUNET_asprintf(char **buf, const char *format,...)
Like asprintf, just portable.
static struct GNUNET_CRYPTO_EcdsaPrivateKey fcfs_zone_pkey
Private key for the fcfsd zone.
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:1237
Handle for an ego.
Definition: identity.h:237
struct GNUNET_NETWORK_FDSet * GNUNET_NETWORK_fdset_create(void)
Creates an fd set.
Definition: network.c:1238
Phase
Phases a request goes through.
static struct MHD_Response * info_page
Zoneinfo page we currently use.
static struct GNUNET_TIME_Relative timeout
User defined timestamp for completing operations.
Definition: gnunet-arm.c:114
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 lookup_it_processor(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zonekey, const char *label, unsigned int rd_count, const struct GNUNET_GNSRECORD_Data *rd)
We got a block back from the namestore.
static void update_zoneinfo_page(void *cls)
Create fresh version of zone information.
#define GNUNET_GNSRECORD_TYPE_PKEY
Record type for GNS zone transfer ("PKEY").
static void zone_to_name_cb(void *cls, const struct GNUNET_CRYPTO_EcdsaPrivateKey *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.
#define UNSIGNED_MHD_LONG_LONG
Connection to the NAMESTORE service.
Handle for the service.
Definition: identity_api.c:94
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:1264
collection of IO descriptors
static char * filename
char domain_name[64]
Domain name submitted via form.
struct GNUNET_CRYPTO_EcdsaPublicKey pub
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:1784
#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:835
static struct GNUNET_NAMESTORE_Handle * ns
Handle to the namestore.
static void lookup_it_finished(void *cls)
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;)
Send failure message.
static struct GNUNET_CONFIGURATION_Handle * cfg
Our configuration.
Definition: gnunet-arm.c:104
#define ZONEINFO_PAGE
Fcfs zoneinfo page (/Zoneinfo)
struct GNUNET_HashCode key
The key used in the DHT.
static unsigned int size
Size of the "table".
Definition: peer.c:66
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.
const char * name
static void zone_iteration_error(void *cls)
Function called on error in zone iteration.
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.
int GNUNET_CRYPTO_ecdsa_public_key_from_string(const char *enc, size_t enclen, struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Convert a string representing a public key to a public key.
Definition: crypto_ecc.c:468
uint32_t record_type
Type of the GNS/DNS record.
configuration data
Definition: configuration.c:83
size_t write_offset
Buffer write offset.
Public ECC key (always for Curve25519) encoded in a format suitable for network transmission and ECDS...
void * cls
Closure for cont or cb.
Definition: identity_api.c:87
static void run(void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg)
Main function that will be run.
struct GNUNET_NAMESTORE_QueueEntry * GNUNET_NAMESTORE_zone_to_name(struct GNUNET_NAMESTORE_Handle *h, const struct GNUNET_CRYPTO_EcdsaPrivateKey *zone, const struct GNUNET_CRYPTO_EcdsaPublicKey *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_log(kind,...)
Entry in list of pending tasks.
Definition: scheduler.c:131
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 deamon reference.
int 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:367
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.
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:142
static int 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...
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
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:956