1
0

SearchRunner.h 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. /** The maximum number of requests to make before calling a search failed. */
  43. #define SearchRunner_DEFAULT_MAX_REQUESTS 8
  44. /** If the search found something, the maximum number of requests to make before call it done. */
  45. #define SearchRunner_DEFAULT_MAX_REQUESTS_IF_FOUND 8
  46. /**
  47. * Start a search.
  48. * The returned promise will have it's callback called for each result of the search and
  49. * then it will be called with 0 milliseconds lag and NULL response indicating the search is over.
  50. *
  51. * @param searchTarget the address to search for.
  52. * @param maxRequests the number of requests to make before terminating the search.
  53. * @param maxRequestsIfFound maximum number of requests if a find has been made.
  54. * @param runner the search runner
  55. * @param alloc an allocator for the search, free this to cancel the search
  56. */
  57. struct RouterModule_Promise* SearchRunner_search(uint8_t target[16],
  58. int maxRequests,
  59. int maxRequestsIfFound,
  60. struct SearchRunner* searchRunner,
  61. struct Allocator* allocator);
  62. /**
  63. * Show an active search.
  64. *
  65. * @param runner
  66. * @param number the search number
  67. * @param alloc the allocator to use for the output
  68. * @return an active search or null if number exceeds the index of the
  69. * highest numbered active search.
  70. */
  71. struct SearchRunner_SearchData* SearchRunner_showActiveSearch(struct SearchRunner* runner,
  72. int number,
  73. struct Allocator* alloc);
  74. struct SearchRunner* SearchRunner_new(struct NodeStore* nodeStore,
  75. struct Log* logger,
  76. struct EventBase* base,
  77. struct RouterModule* module,
  78. uint8_t myAddress[16],
  79. struct RumorMill* rumorMill,
  80. struct Allocator* alloc);
  81. #endif