DPRelay.h 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /**
  2. * @file DPRelay.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. #ifndef BADVPN_CLIENT_DPRELAY_H
  30. #define BADVPN_CLIENT_DPRELAY_H
  31. #include <stdint.h>
  32. #include <limits.h>
  33. #include <protocol/scproto.h>
  34. #include <protocol/dataproto.h>
  35. #include <misc/debug.h>
  36. #include <structure/LinkedList1.h>
  37. #include <base/DebugObject.h>
  38. #include <flow/BufferWriter.h>
  39. #include <client/DataProto.h>
  40. struct DPRelay_flow;
  41. typedef struct {
  42. int frame_mtu;
  43. BufferWriter writer;
  44. DataProtoSource dp_source;
  45. struct DPRelay_flow *current_flow;
  46. DebugObject d_obj;
  47. DebugCounter d_ctr;
  48. } DPRelayRouter;
  49. typedef struct {
  50. DPRelayRouter *router;
  51. peerid_t source_id;
  52. LinkedList1 flows_list;
  53. DebugObject d_obj;
  54. } DPRelaySource;
  55. typedef struct {
  56. peerid_t dest_id;
  57. LinkedList1 flows_list;
  58. DataProtoSink *dp_sink;
  59. DebugObject d_obj;
  60. } DPRelaySink;
  61. struct DPRelay_flow {
  62. DPRelaySource *src;
  63. DPRelaySink *sink;
  64. DataProtoFlow dp_flow;
  65. LinkedList1Node src_list_node;
  66. LinkedList1Node sink_list_node;
  67. };
  68. int DPRelayRouter_Init (DPRelayRouter *o, int frame_mtu, BReactor *reactor) WARN_UNUSED;
  69. void DPRelayRouter_Free (DPRelayRouter *o);
  70. void DPRelayRouter_SubmitFrame (DPRelayRouter *o, DPRelaySource *src, DPRelaySink *sink, uint8_t *data, int data_len, int num_packets, int inactivity_time);
  71. void DPRelaySource_Init (DPRelaySource *o, DPRelayRouter *router, peerid_t source_id, BReactor *reactor);
  72. void DPRelaySource_Free (DPRelaySource *o);
  73. void DPRelaySink_Init (DPRelaySink *o, peerid_t dest_id);
  74. void DPRelaySink_Free (DPRelaySink *o);
  75. void DPRelaySink_Attach (DPRelaySink *o, DataProtoSink *dp_sink);
  76. void DPRelaySink_Detach (DPRelaySink *o);
  77. #endif