ReachabilityCollector.h 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. void ReachabilityCollector_unreachable(struct ReachabilityCollector* rc, struct Address* nodeAddr);
  55. // NodeAddr->path should be 0 if the node is not reachable.
  56. void ReachabilityCollector_change(struct ReachabilityCollector* rc, struct Address* nodeAddr);
  57. void ReachabilityCollector_lagSample(
  58. struct ReachabilityCollector* rc, uint64_t label, uint32_t milliseconds);
  59. void ReachabilityCollector_updateBandwidthAndDrops(
  60. struct ReachabilityCollector* rc,
  61. uint64_t label,
  62. uint64_t sumOfPackets,
  63. uint64_t sumOfDrops,
  64. uint64_t sumOfKb);
  65. struct ReachabilityCollector* ReachabilityCollector_new(struct Allocator* allocator,
  66. struct MsgCore* msgCore,
  67. struct Log* log,
  68. struct EventBase* base,
  69. struct BoilerplateResponder* br,
  70. struct Address* myAddr,
  71. struct EncodingScheme* myScheme,
  72. struct SwitchPinger* sp);
  73. #endif