FragmentProtoDisassembler.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /**
  2. * @file FragmentProtoDisassembler.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. * Object which encodes packets into packets composed of chunks
  25. * according to FragmentProto.
  26. */
  27. #ifndef BADVPN_FLOW_CCPROTODISASSEMBLER_H
  28. #define BADVPN_FLOW_CCPROTODISASSEMBLER_H
  29. #include <stdint.h>
  30. #include <protocol/fragmentproto.h>
  31. #include <misc/dead.h>
  32. #include <system/DebugObject.h>
  33. #include <system/BReactor.h>
  34. #include <system/BTime.h>
  35. #include <flow/PacketPassInterface.h>
  36. #include <flow/PacketRecvInterface.h>
  37. /**
  38. * Object which encodes packets into packets composed of chunks
  39. * according to FragmentProto.
  40. *
  41. * Input is with {@link PacketPassInterface}.
  42. * Output is with {@link PacketRecvInterface}.
  43. */
  44. typedef struct {
  45. DebugObject d_obj;
  46. dead_t dead;
  47. BReactor *reactor;
  48. int input_mtu;
  49. int output_mtu;
  50. int chunk_mtu;
  51. btime_t latency;
  52. PacketPassInterface input;
  53. PacketRecvInterface output;
  54. BTimer timer;
  55. int in_len;
  56. uint8_t *in;
  57. int in_used;
  58. uint8_t *out;
  59. int out_used;
  60. fragmentproto_frameid frame_id;
  61. int doing_send;
  62. int doing_recv;
  63. } FragmentProtoDisassembler;
  64. /**
  65. * Initializes the object.
  66. *
  67. * @param o the object
  68. * @param reactor reactor we live in
  69. * @param input_mtu maximum input packet size. Must be >=0 and <2^16
  70. * @param output_mtu maximum output packet size. Must be >sizeof(struct fragmentproto_chunk_header).
  71. * @param chunk_mtu maximum chunk size. Must be >0, or <0 for no explicit limit.
  72. * @param latency maximum time a pending output packet with some data can wait for more data
  73. * before being sent out. If nonnegative, a timer will be used. If negative,
  74. * packets will always be sent out immediately. If low latency is desired,
  75. * prefer setting this to zero rather than negative.
  76. */
  77. void FragmentProtoDisassembler_Init (FragmentProtoDisassembler *o, BReactor *reactor, int input_mtu, int output_mtu, int chunk_mtu, btime_t latency);
  78. /**
  79. * Frees the object.
  80. *
  81. * @param o the object
  82. */
  83. void FragmentProtoDisassembler_Free (FragmentProtoDisassembler *o);
  84. /**
  85. * Returns the input interface.
  86. *
  87. * @param o the object
  88. * @return input interface
  89. */
  90. PacketPassInterface * FragmentProtoDisassembler_GetInput (FragmentProtoDisassembler *o);
  91. /**
  92. * Returns the output interface.
  93. *
  94. * @param o the object
  95. * @return output interface
  96. */
  97. PacketRecvInterface * FragmentProtoDisassembler_GetOutput (FragmentProtoDisassembler *o);
  98. #endif