1
0

SupernodeHunter.h 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 SupernodeHunter_H
  16. #define SupernodeHunter_H
  17. #include "memory/Allocator.h"
  18. #include "util/log/Log.h"
  19. #include "util/events/EventBase.h"
  20. #include "subnode/AddrSet.h"
  21. #include "subnode/MsgCore.h"
  22. #include "subnode/ReachabilityCollector.h"
  23. #include "dht/Address.h"
  24. #include "net/SwitchPinger.h"
  25. #include "util/Linker.h"
  26. Linker_require("subnode/SupernodeHunter.c");
  27. struct SupernodeHunter;
  28. typedef void (* SupernodeHunter_Callback)(struct SupernodeHunter* sh,
  29. int64_t sendTime,
  30. int64_t snodeRecvTime);
  31. struct SupernodeHunter
  32. {
  33. // This will be set to:
  34. // 1 when a supernode is found and
  35. // 2 if the supernode is found AND it is one of the ones in the authorized list.
  36. // If it is in state 1 and there exist authorized snodes, it will keep on looking for anyone
  37. // who knows the way to one of the snodes in the authorized list.
  38. //
  39. // If you lose connection to your snode, you can use
  40. int snodeIsReachable;
  41. struct Address snodeAddr;
  42. SupernodeHunter_Callback onSnodeChange;
  43. SupernodeHunter_Callback onSnodeUnreachable;
  44. void* userData;
  45. };
  46. #define SupernodeHunter_addSnode_EXISTS -1
  47. int SupernodeHunter_addSnode(struct SupernodeHunter* snh, struct Address* snodeAddr);
  48. int SupernodeHunter_listSnodes(struct SupernodeHunter* snh,
  49. struct Address*** out,
  50. struct Allocator* alloc);
  51. #define SupernodeHunter_removeSnode_NONEXISTANT -1
  52. int SupernodeHunter_removeSnode(struct SupernodeHunter* snh, struct Address* toRemove);
  53. /**
  54. * The algorithm of this module is to ask each peer for a supernode using a findNode request.
  55. * If each peer comes up empty then each peer is sent a getPeers request and those nodes are
  56. * requested in turn.
  57. */
  58. struct SupernodeHunter* SupernodeHunter_new(struct Allocator* allocator,
  59. struct Log* log,
  60. struct EventBase* base,
  61. struct SwitchPinger* sp,
  62. struct AddrSet* peers,
  63. struct MsgCore* msgCore,
  64. struct Address* myAddress,
  65. struct ReachabilityCollector* rc);
  66. #endif