ReachabilityCollector.h 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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 "net/SwitchPinger.h"
  21. #include "subnode/MsgCore.h"
  22. #include "subnode/LinkState.h"
  23. #include "util/Linker.h"
  24. Linker_require("subnode/ReachabilityCollector.c")
  25. struct ReachabilityCollector_PeerInfo
  26. {
  27. // Address of the peer from us
  28. struct Address addr;
  29. // Their path to us
  30. uint64_t pathThemToUs;
  31. // True when we are not sure about the connection to this peer
  32. // so we will be sending queries to it. Does not mean we're waiting
  33. // for a response from them.
  34. bool isQuerying;
  35. struct LinkState linkState;
  36. // This is set by ReachabilityAnnouncer when it announces a set of data
  37. // so that the same data won't be announced twice.
  38. uint32_t lastAnnouncedSamples;
  39. };
  40. struct ReachabilityCollector;
  41. // pi == NULL -> peer dropped
  42. typedef void (* ReachabilityCollector_OnChange)(struct ReachabilityCollector* rc,
  43. struct Address* addr,
  44. struct ReachabilityCollector_PeerInfo* pi);
  45. struct ReachabilityCollector
  46. {
  47. ReachabilityCollector_OnChange onChange;
  48. void* userData;
  49. };
  50. struct ReachabilityCollector_PeerInfo*
  51. ReachabilityCollector_piForLabel(struct ReachabilityCollector* rc, uint64_t label);
  52. struct ReachabilityCollector_PeerInfo*
  53. ReachabilityCollector_getPeerInfo(struct ReachabilityCollector* rc, int peerNum);
  54. int ReachabilityCollector_peerCount(struct ReachabilityCollector* rc);
  55. void ReachabilityCollector_unreachable(struct ReachabilityCollector* rc, struct Address* nodeAddr);
  56. // NodeAddr->path should be 0 if the node is not reachable.
  57. void ReachabilityCollector_change(struct ReachabilityCollector* rc, struct Address* nodeAddr);
  58. void ReachabilityCollector_lagSample(
  59. struct ReachabilityCollector* rc, uint64_t label, uint32_t milliseconds);
  60. void ReachabilityCollector_updateBandwidthAndDrops(
  61. struct ReachabilityCollector* rc,
  62. uint64_t label,
  63. uint64_t sumOfPackets,
  64. uint64_t sumOfDrops,
  65. uint64_t sumOfKb);
  66. struct ReachabilityCollector* ReachabilityCollector_new(struct Allocator* allocator,
  67. struct MsgCore* msgCore,
  68. struct Log* log,
  69. struct EventBase* base,
  70. struct BoilerplateResponder* br,
  71. struct Address* myAddr,
  72. struct EncodingScheme* myScheme,
  73. struct SwitchPinger* sp);
  74. #endif