KeepaliveIO.h 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * @file KeepaliveIO.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 sending keep-alive packets.
  25. */
  26. #ifndef BADVPN_FLOW_KEEPALIVEIO
  27. #define BADVPN_FLOW_KEEPALIVEIO
  28. #include <misc/dead.h>
  29. #include <misc/debug.h>
  30. #include <system/DebugObject.h>
  31. #include <system/BReactor.h>
  32. #include <flow/PacketPassInterface.h>
  33. #include <flow/PacketRecvInterface.h>
  34. #include <flow/PacketPassPriorityQueue.h>
  35. #include <flow/SinglePacketBuffer.h>
  36. #include <flow/PacketRecvBlocker.h>
  37. #include <flow/PacketPassInactivityMonitor.h>
  38. /**
  39. * A {@link PacketPassInterface} layer for sending keep-alive packets.
  40. */
  41. typedef struct {
  42. DebugObject d_obj;
  43. dead_t dead;
  44. BReactor *reactor;
  45. PacketPassInactivityMonitor kasender;
  46. PacketPassPriorityQueue queue;
  47. PacketPassPriorityQueueFlow user_qflow;
  48. PacketPassPriorityQueueFlow ka_qflow;
  49. SinglePacketBuffer ka_buffer;
  50. PacketRecvBlocker ka_blocker;
  51. } KeepaliveIO;
  52. /**
  53. * Initializes the object.
  54. *
  55. * @param o the object
  56. * @param reactor reactor we live in
  57. * @param output output interface
  58. * @param keepalive_input keepalive input interface. Its MTU must be <= MTU of output.
  59. * @param keepalive_interval_ms keepalive interval in milliseconds. Must be >0.
  60. * @return 1 on success, 0 on failure
  61. */
  62. int KeepaliveIO_Init (KeepaliveIO *o, BReactor *reactor, PacketPassInterface *output, PacketRecvInterface *keepalive_input, btime_t keepalive_interval_ms) WARN_UNUSED;
  63. /**
  64. * Frees the object.
  65. *
  66. * @param o the object
  67. */
  68. void KeepaliveIO_Free (KeepaliveIO *o);
  69. /**
  70. * Returns the input interface.
  71. *
  72. * @param o the object
  73. * @return input interface
  74. */
  75. PacketPassInterface * KeepaliveIO_GetInput (KeepaliveIO *o);
  76. #endif