Janitor.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. */
  15. #ifndef Janitor_H
  16. #define Janitor_H
  17. #ifdef SUBNODE
  18. #error "this file should not be included in subnode"
  19. #endif
  20. #include "crypto/random/Random.h"
  21. #include "dht/Address.h"
  22. #include "dht/dhtcore/RouterModule.h"
  23. #include "dht/dhtcore/SearchRunner.h"
  24. #include "dht/dhtcore/NodeStore.h"
  25. #include "dht/dhtcore/RumorMill.h"
  26. #include "memory/Allocator.h"
  27. #include "util/events/EventBase.h"
  28. #include "util/log/Log.h"
  29. #include "util/Linker.h"
  30. Linker_require("dht/dhtcore/Janitor.c")
  31. #include <stdint.h>
  32. struct Janitor
  33. {
  34. /**
  35. * Externally accessible RumorMill.
  36. * Used for direct peers and search results that are closer than the responder.
  37. */
  38. struct RumorMill* externalMill;
  39. /**
  40. * High priority RumorMill.
  41. * Used to discover new links to nodes we already know about.
  42. */
  43. struct RumorMill* linkMill;
  44. /**
  45. * Low priority RumorMill.
  46. * Used to discover new nodes.
  47. */
  48. struct RumorMill* nodeMill;
  49. /** Just used to keep track of nodes that we need to check on for DHT health. */
  50. struct RumorMill* dhtMill;
  51. /** Used for splitting links which are longer than 1 hop. */
  52. struct RumorMill* splitMill;
  53. /**
  54. * The number of milliseconds after a path has been (successfully) pinged which it will
  55. * not be pinged again.
  56. */
  57. #define Janitor_BLACKLIST_PATH_FOR_MILLISECONDS_DEFAULT 30000
  58. int64_t blacklistPathForMilliseconds;
  59. /** The number of milliseconds between attempting local maintenance searches. */
  60. #define Janitor_LOCAL_MAINTENANCE_MILLISECONDS_DEFAULT 1000
  61. uint64_t localMaintainenceMilliseconds;
  62. /**
  63. * The number of milliseconds to pass between global maintainence searches.
  64. * These are searches for random targets which are used to discover new nodes.
  65. */
  66. #define Janitor_GLOBAL_MAINTENANCE_MILLISECONDS_DEFAULT 30000
  67. uint64_t globalMaintainenceMilliseconds;
  68. };
  69. struct Janitor* Janitor_new(struct RouterModule* routerModule,
  70. struct NodeStore* nodeStore,
  71. struct SearchRunner* searchRunner,
  72. struct RumorMill* rumorMill,
  73. struct Log* logger,
  74. struct Allocator* alloc,
  75. struct EventBase* eventBase,
  76. struct Random* rand);
  77. #endif