PacketPassInactivityMonitor.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /**
  2. * @file PacketPassInactivityMonitor.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * This file is part of BadVPN.
  8. *
  9. * BadVPN is free software: you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2
  11. * as published by the Free Software Foundation.
  12. *
  13. * BadVPN is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. *
  22. * @section DESCRIPTION
  23. *
  24. * A {@link PacketPassInterface} layer for detecting inactivity.
  25. */
  26. #ifndef BADVPN_FLOW_PACKETPASSINACTIVITYMONITOR_H
  27. #define BADVPN_FLOW_PACKETPASSINACTIVITYMONITOR_H
  28. #include <misc/dead.h>
  29. #include <system/DebugObject.h>
  30. #include <system/BReactor.h>
  31. #include <flow/PacketPassInterface.h>
  32. /**
  33. * Handler function invoked when inactivity is detected.
  34. * It is guaranteed that the interfaces are in not sending state.
  35. *
  36. * @param user value given to {@link PacketPassInactivityMonitor_Init}
  37. */
  38. typedef void (*PacketPassInactivityMonitor_handler) (void *user);
  39. /**
  40. * A {@link PacketPassInterface} layer for detecting inactivity.
  41. * It reports inactivity to a user provided handler function.
  42. *
  43. * The object behaves like that:
  44. * ("timer set" means started with the given timeout whether if was running or not,
  45. * "timer unset" means stopped if it was running)
  46. * - There is a timer.
  47. * - The timer is set when the object is initialized.
  48. * - When the input calls Send, the call is passed on to the output.
  49. * If the output accepted the packet, the timer is set. If the output
  50. * blocked the packet, the timer is unset.
  51. * - When the output calls Done, the timer is set, and the call is
  52. * passed on to the input.
  53. * - When the input calls Cancel, the timer is set, and the call is
  54. * passed on to the output.
  55. * - When the timer expires, the timer is set, ant the user's handler
  56. * function is invoked.
  57. */
  58. typedef struct {
  59. DebugObject d_obj;
  60. dead_t dead;
  61. PacketPassInterface *output;
  62. BReactor *reactor;
  63. PacketPassInactivityMonitor_handler handler;
  64. void *user;
  65. PacketPassInterface input;
  66. BTimer timer;
  67. int send_called;
  68. } PacketPassInactivityMonitor;
  69. /**
  70. * Initializes the object.
  71. * See {@link PacketPassInactivityMonitor} for details.
  72. *
  73. * @param o the object
  74. * @param output output interface
  75. * @param reactor reactor we live in
  76. * @param interval timer interval is milliseconds. Must be >0.
  77. * @param handler handler function for reporting inactivity
  78. * @param user value passed to handler functions
  79. */
  80. void PacketPassInactivityMonitor_Init (PacketPassInactivityMonitor *o, PacketPassInterface *output, BReactor *reactor, btime_t interval, PacketPassInactivityMonitor_handler handler, void *user);
  81. /**
  82. * Frees the object.
  83. *
  84. * @param o the object
  85. */
  86. void PacketPassInactivityMonitor_Free (PacketPassInactivityMonitor *o);
  87. /**
  88. * Returns the input interface.
  89. * The MTU of the interface will be the same as of the output interface.
  90. * The interface supports cancel functionality if the output interface supports it.
  91. *
  92. * @param o the object
  93. * @return input interface
  94. */
  95. PacketPassInterface * PacketPassInactivityMonitor_GetInput (PacketPassInactivityMonitor *o);
  96. #endif