KeepaliveIO.h 2.4 KB

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