FragmentProtoDisassembler.h 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. /**
  2. * @file FragmentProtoDisassembler.h
  3. * @author Ambroz Bizjak <ambrop7@gmail.com>
  4. *
  5. * @section LICENSE
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the author nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * @section DESCRIPTION
  30. *
  31. * Object which encodes packets into packets composed of chunks
  32. * according to FragmentProto.
  33. */
  34. #ifndef BADVPN_CLIENT_CCPROTODISASSEMBLER_H
  35. #define BADVPN_CLIENT_CCPROTODISASSEMBLER_H
  36. #include <stdint.h>
  37. #include <protocol/fragmentproto.h>
  38. #include <base/DebugObject.h>
  39. #include <system/BReactor.h>
  40. #include <system/BTime.h>
  41. #include <flow/PacketPassInterface.h>
  42. #include <flow/PacketRecvInterface.h>
  43. /**
  44. * Object which encodes packets into packets composed of chunks
  45. * according to FragmentProto.
  46. *
  47. * Input is with {@link PacketPassInterface}.
  48. * Output is with {@link PacketRecvInterface}.
  49. */
  50. typedef struct {
  51. BReactor *reactor;
  52. int output_mtu;
  53. int chunk_mtu;
  54. btime_t latency;
  55. PacketPassInterface input;
  56. PacketRecvInterface output;
  57. BTimer timer;
  58. int in_len;
  59. uint8_t *in;
  60. int in_used;
  61. uint8_t *out;
  62. int out_used;
  63. fragmentproto_frameid frame_id;
  64. DebugObject d_obj;
  65. } FragmentProtoDisassembler;
  66. /**
  67. * Initializes the object.
  68. *
  69. * @param o the object
  70. * @param reactor reactor we live in
  71. * @param input_mtu maximum input packet size. Must be >=0 and <=UINT16_MAX.
  72. * @param output_mtu maximum output packet size. Must be >sizeof(struct fragmentproto_chunk_header).
  73. * @param chunk_mtu maximum chunk size. Must be >0, or <0 for no explicit limit.
  74. * @param latency maximum time a pending output packet with some data can wait for more data
  75. * before being sent out. If nonnegative, a timer will be used. If negative,
  76. * packets will always be sent out immediately. If low latency is desired,
  77. * prefer setting this to zero rather than negative.
  78. */
  79. void FragmentProtoDisassembler_Init (FragmentProtoDisassembler *o, BReactor *reactor, int input_mtu, int output_mtu, int chunk_mtu, btime_t latency);
  80. /**
  81. * Frees the object.
  82. *
  83. * @param o the object
  84. */
  85. void FragmentProtoDisassembler_Free (FragmentProtoDisassembler *o);
  86. /**
  87. * Returns the input interface.
  88. *
  89. * @param o the object
  90. * @return input interface
  91. */
  92. PacketPassInterface * FragmentProtoDisassembler_GetInput (FragmentProtoDisassembler *o);
  93. /**
  94. * Returns the output interface.
  95. *
  96. * @param o the object
  97. * @return output interface
  98. */
  99. PacketRecvInterface * FragmentProtoDisassembler_GetOutput (FragmentProtoDisassembler *o);
  100. #endif