SearchRunner.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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 <http://www.gnu.org/licenses/>.
  14. */
  15. #ifndef SearchRunner_H
  16. #define SearchRunner_H
  17. #include "dht/dhtcore/RouterModule.h"
  18. #include "dht/dhtcore/NodeStore.h"
  19. #include "dht/dhtcore/RumorMill.h"
  20. #include "util/log/Log.h"
  21. #include "util/events/EventBase.h"
  22. #include "util/Bits.h"
  23. #include "memory/Allocator.h"
  24. #include "util/Linker.h"
  25. Linker_require("dht/dhtcore/SearchRunner.c")
  26. struct SearchRunner_SearchData
  27. {
  28. /** What we're searching for */
  29. uint8_t target[16];
  30. /** Who we last asked about it. */
  31. struct Address lastNodeAsked;
  32. /** How many people we have asked. */
  33. int totalRequests;
  34. /** Number of searches which are currently active. */
  35. int activeSearches;
  36. };
  37. struct SearchRunner
  38. {
  39. int unused;
  40. };
  41. #define SearchRunner_DEFAULT_MAX_CONCURRENT_SEARCHES 30
  42. /**
  43. * Start a search.
  44. * The returned promise will have it's callback called for each result of the search and
  45. * then it will be called with 0 milliseconds lag and NULL response indicating the search is over.
  46. *
  47. * @param searchTarget the address to search for.
  48. * @param runner the search runner
  49. * @param alloc an allocator for the search, free this to cancel the search
  50. */
  51. struct RouterModule_Promise* SearchRunner_search(uint8_t searchTarget[16],
  52. struct SearchRunner* runner,
  53. struct Allocator* alloc);
  54. /**
  55. * Show an active search.
  56. *
  57. * @param runner
  58. * @param number the search number
  59. * @param alloc the allocator to use for the output
  60. * @return an active search or null if number exceeds the index of the
  61. * highest numbered active search.
  62. */
  63. struct SearchRunner_SearchData* SearchRunner_showActiveSearch(struct SearchRunner* runner,
  64. int number,
  65. struct Allocator* alloc);
  66. struct SearchRunner* SearchRunner_new(struct NodeStore* nodeStore,
  67. struct Log* logger,
  68. struct EventBase* base,
  69. struct RouterModule* module,
  70. uint8_t myAddress[16],
  71. struct RumorMill* rumorMill,
  72. struct Allocator* alloc);
  73. #endif