gnunet-service-cadet.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. /*
  2. This file is part of GNUnet.
  3. (C) 2001-2013 Christian Grothoff (and other contributing authors)
  4. GNUnet is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published
  6. by the Free Software Foundation; either version 3, or (at your
  7. option) any later version.
  8. GNUnet is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNUnet; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  15. Boston, MA 02111-1307, USA.
  16. */
  17. /**
  18. * @file cadet/gnunet-service-cadet.c
  19. * @brief GNUnet CADET service with encryption
  20. * @author Bartlomiej Polot
  21. *
  22. * FIXME in progress:
  23. * - rekey - reliability interaction
  24. * - channel retransmit timing
  25. *
  26. * TODO:
  27. * - relay corking down to core
  28. * - set ttl relative to path length
  29. * TODO END
  30. *
  31. * Dictionary:
  32. * - peer: other cadet instance. If there is direct connection it's a neighbor.
  33. * - tunnel: encrypted connection to a peer, neighbor or not.
  34. * - channel: connection between two clients, on the same or different peers.
  35. * have properties like reliability.
  36. * - path: series of directly connected peer from one peer to another.
  37. * - connection: path which is being used in a tunnel.
  38. */
  39. #include "platform.h"
  40. #include "gnunet_util_lib.h"
  41. #include "cadet.h"
  42. #include "gnunet_statistics_service.h"
  43. #include "gnunet-service-cadet_local.h"
  44. #include "gnunet-service-cadet_channel.h"
  45. #include "gnunet-service-cadet_connection.h"
  46. #include "gnunet-service-cadet_tunnel.h"
  47. #include "gnunet-service-cadet_dht.h"
  48. #include "gnunet-service-cadet_peer.h"
  49. #include "gnunet-service-cadet_hello.h"
  50. /******************************************************************************/
  51. /*********************** GLOBAL VARIABLES ****************************/
  52. /******************************************************************************/
  53. /****************************** Global variables ******************************/
  54. /**
  55. * Handle to the statistics service.
  56. */
  57. struct GNUNET_STATISTICS_Handle *stats;
  58. /**
  59. * Local peer own ID (memory efficient handle).
  60. */
  61. GNUNET_PEER_Id myid;
  62. /**
  63. * Local peer own ID (full value).
  64. */
  65. struct GNUNET_PeerIdentity my_full_id;
  66. /**
  67. * Signal that shutdown is happening: prevent recover measures.
  68. */
  69. int shutting_down;
  70. /*************************** Static global variables **************************/
  71. /**
  72. * Own private key.
  73. */
  74. static struct GNUNET_CRYPTO_EddsaPrivateKey *my_private_key;
  75. /******************************************************************************/
  76. /************************ MAIN FUNCTIONS ****************************/
  77. /******************************************************************************/
  78. /**
  79. * Task run during shutdown.
  80. *
  81. * @param cls unused
  82. * @param tc unused
  83. */
  84. static void
  85. shutdown_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
  86. {
  87. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shutting down\n");
  88. shutting_down = GNUNET_YES;
  89. GML_shutdown ();
  90. GCH_shutdown ();
  91. GCC_shutdown ();
  92. GCT_shutdown ();
  93. GCD_shutdown ();
  94. GCP_shutdown ();
  95. GNUNET_STATISTICS_destroy (stats, GNUNET_NO);
  96. stats = NULL;
  97. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "shut down\n");
  98. }
  99. /**
  100. * Process cadet requests.
  101. *
  102. * @param cls closure
  103. * @param server the initialized server
  104. * @param c configuration to use
  105. */
  106. static void
  107. run (void *cls, struct GNUNET_SERVER_Handle *server,
  108. const struct GNUNET_CONFIGURATION_Handle *c)
  109. {
  110. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "starting to run\n");
  111. stats = GNUNET_STATISTICS_create ("cadet", c);
  112. /* Scheduled the task to clean up when shutdown is called */
  113. GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &shutdown_task,
  114. NULL);
  115. GNUNET_log (GNUNET_ERROR_TYPE_INFO, "reading key\n");
  116. my_private_key = GNUNET_CRYPTO_eddsa_key_create_from_configuration (c);
  117. GNUNET_assert (NULL != my_private_key);
  118. GNUNET_CRYPTO_eddsa_key_get_public (my_private_key, &my_full_id.public_key);
  119. myid = GNUNET_PEER_intern (&my_full_id);
  120. GNUNET_log (GNUNET_ERROR_TYPE_INFO,
  121. "STARTING SERVICE (CADET) for peer [%s]\n",
  122. GNUNET_i2s (&my_full_id));
  123. GML_init (server); /* Local clients */
  124. GCH_init (c); /* Hellos */
  125. GCC_init (c); /* Connections */
  126. GCP_init (c); /* Peers */
  127. GCD_init (c); /* DHT */
  128. GCT_init (c, my_private_key); /* Tunnels */
  129. GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Cadet service running\n");
  130. }
  131. /**
  132. * The main function for the cadet service.
  133. *
  134. * @param argc number of arguments from the command line
  135. * @param argv command line arguments
  136. * @return 0 ok, 1 on error
  137. */
  138. int
  139. main (int argc, char *const *argv)
  140. {
  141. int ret;
  142. int r;
  143. shutting_down = GNUNET_NO;
  144. r = GNUNET_SERVICE_run (argc, argv, "cadet", GNUNET_SERVICE_OPTION_NONE, &run,
  145. NULL);
  146. GNUNET_free (my_private_key);
  147. ret = (GNUNET_OK == r) ? 0 : 1;
  148. return ret;
  149. }