SCOutmsgEncoder.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /**
  2. * @file SCOutmsgEncoder.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. #ifndef BADVPN_SCOUTMSGENCODER_H
  23. #define BADVPN_SCOUTMSGENCODER_H
  24. #include <protocol/scproto.h>
  25. #include <base/DebugObject.h>
  26. #include <flow/PacketRecvInterface.h>
  27. #define SCOUTMSG_OVERHEAD (sizeof(struct sc_header) + sizeof(struct sc_client_outmsg))
  28. /**
  29. * A {@link PacketRecvInterface} layer which encodes SCProto outgoing messages.
  30. */
  31. typedef struct {
  32. peerid_t peer_id;
  33. PacketRecvInterface *input;
  34. PacketRecvInterface output;
  35. uint8_t *output_packet;
  36. DebugObject d_obj;
  37. } SCOutmsgEncoder;
  38. /**
  39. * Initializes the object.
  40. *
  41. * @param o the object
  42. * @param peer_id destination peer for messages
  43. * @param input input interface. Its MTU muse be <= (INT_MAX - SCOUTMSG_OVERHEAD).
  44. * @param pg pending group we live in
  45. */
  46. void SCOutmsgEncoder_Init (SCOutmsgEncoder *o, peerid_t peer_id, PacketRecvInterface *input, BPendingGroup *pg);
  47. /**
  48. * Frees the object.
  49. *
  50. * @param o the object
  51. */
  52. void SCOutmsgEncoder_Free (SCOutmsgEncoder *o);
  53. /**
  54. * Returns the output interface.
  55. * The MTU of the interface will be (SCOUTMSG_OVERHEAD + input MTU).
  56. *
  57. * @param o the object
  58. * @return output interface
  59. */
  60. PacketRecvInterface * SCOutmsgEncoder_GetOutput (SCOutmsgEncoder *o);
  61. #endif