PacketProtoFlow.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. * @file PacketProtoFlow.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. * Buffer which encodes packets with PacketProto, with {@link BufferWriter}
  25. * input and {@link PacketPassInterface} output.
  26. */
  27. #ifndef BADVPN_FLOW_PACKETPROTOFLOW_H
  28. #define BADVPN_FLOW_PACKETPROTOFLOW_H
  29. #include <misc/debug.h>
  30. #include <system/DebugObject.h>
  31. #include <flow/BufferWriter.h>
  32. #include <flow/PacketProtoEncoder.h>
  33. #include <flow/PacketBuffer.h>
  34. /**
  35. * Buffer which encodes packets with PacketProto, with {@link BufferWriter}
  36. * input and {@link PacketPassInterface} output.
  37. */
  38. typedef struct {
  39. BufferWriter ainput;
  40. PacketProtoEncoder encoder;
  41. PacketBuffer buffer;
  42. DebugObject d_obj;
  43. } PacketProtoFlow;
  44. /**
  45. * Initializes the object.
  46. *
  47. * @param o the object
  48. * @param input_mtu maximum input packet size. Must be >=0 and <=PACKETPROTO_MAXPAYLOAD.
  49. * @param num_packets minimum number of packets the buffer should hold. Must be >0.
  50. * @param output output interface. Its MTU must be >=PACKETPROTO_ENCLEN(input_mtu).
  51. * @param pg pending group
  52. * @return 1 on success, 0 on failure
  53. */
  54. int PacketProtoFlow_Init (PacketProtoFlow *o, int input_mtu, int num_packets, PacketPassInterface *output, BPendingGroup *pg) WARN_UNUSED;
  55. /**
  56. * Frees the object.
  57. *
  58. * @param o the object
  59. */
  60. void PacketProtoFlow_Free (PacketProtoFlow *o);
  61. /**
  62. * Returns the input interface.
  63. *
  64. * @param o the object
  65. * @return input interface
  66. */
  67. BufferWriter * PacketProtoFlow_GetInput (PacketProtoFlow *o);
  68. #endif