ReachabilityCollector.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 ReachabilityCollector_H
  16. #define ReachabilityCollector_H
  17. #include "subnode/BoilerplateResponder.h"
  18. #include "dht/Address.h"
  19. #include "memory/Allocator.h"
  20. #include "subnode/MsgCore.h"
  21. #include "subnode/LinkState.h"
  22. #include "util/Linker.h"
  23. Linker_require("subnode/ReachabilityCollector.c");
  24. struct ReachabilityCollector_PeerInfo
  25. {
  26. // Address of the peer from us
  27. struct Address addr;
  28. // Their path to us
  29. uint64_t pathThemToUs;
  30. bool querying;
  31. struct LinkState linkState;
  32. };
  33. struct ReachabilityCollector;
  34. // pi == NULL -> peer dropped
  35. typedef void (* ReachabilityCollector_OnChange)(struct ReachabilityCollector* rc,
  36. uint8_t ipv6[16],
  37. struct ReachabilityCollector_PeerInfo* pi);
  38. struct ReachabilityCollector
  39. {
  40. ReachabilityCollector_OnChange onChange;
  41. void* userData;
  42. };
  43. struct ReachabilityCollector_PeerInfo*
  44. ReachabilityCollector_getPeerInfo(struct ReachabilityCollector* rc, int peerNum);
  45. // NodeAddr->path should be 0 if the node is not reachable.
  46. void ReachabilityCollector_change(struct ReachabilityCollector* rc, struct Address* nodeAddr);
  47. void ReachabilityCollector_lagSample(
  48. struct ReachabilityCollector* rc, uint64_t label, uint32_t milliseconds);
  49. void ReachabilityCollector_updateBandwidthAndDrops(
  50. struct ReachabilityCollector* rc,
  51. uint64_t label,
  52. uint32_t sumOfPackets,
  53. uint32_t sumOfDrops,
  54. uint32_t sumOfKb);
  55. struct ReachabilityCollector* ReachabilityCollector_new(struct Allocator* allocator,
  56. struct MsgCore* mc,
  57. struct Log* log,
  58. struct EventBase* base,
  59. struct BoilerplateResponder* br,
  60. struct Address* myAddr,
  61. struct EncodingScheme* myScheme);
  62. #endif