PacketProtoFlow.h 2.2 KB

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