PeerChat.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * @file PeerChat.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_PEERCHAT_H
  23. #define BADVPN_PEERCHAT_H
  24. #include <cert.h>
  25. #include <keyhi.h>
  26. #include <protocol/packetproto.h>
  27. #include <protocol/scproto.h>
  28. #include <misc/debug.h>
  29. #include <misc/debugerror.h>
  30. #include <base/DebugObject.h>
  31. #include <base/BPending.h>
  32. #include <flow/SinglePacketSender.h>
  33. #include <flow/PacketProtoEncoder.h>
  34. #include <flow/PacketCopier.h>
  35. #include <flow/StreamPacketSender.h>
  36. #include <flow/PacketStreamSender.h>
  37. #include <flow/SinglePacketBuffer.h>
  38. #include <flow/PacketProtoDecoder.h>
  39. #include <nspr_support/BSSLConnection.h>
  40. #include <client/SCOutmsgEncoder.h>
  41. #include <client/SimpleStreamBuffer.h>
  42. #define PEERCHAT_SSL_NONE 0
  43. #define PEERCHAT_SSL_CLIENT 1
  44. #define PEERCHAT_SSL_SERVER 2
  45. #define PEERCHAT_SSL_RECV_BUF_SIZE 4096
  46. //#define PEERCHAT_SIMULATE_ERROR 40
  47. typedef void (*PeerChat_handler_error) (void *user);
  48. typedef void (*PeerChat_handler_message) (void *user, uint8_t *data, int data_len);
  49. typedef struct {
  50. int ssl_mode;
  51. CERTCertificate *ssl_cert;
  52. SECKEYPrivateKey *ssl_key;
  53. uint8_t *ssl_peer_cert;
  54. int ssl_peer_cert_len;
  55. void *user;
  56. PeerChat_handler_error handler_error;
  57. PeerChat_handler_message handler_message;
  58. // common
  59. PacketProtoEncoder pp_encoder;
  60. SCOutmsgEncoder sc_encoder;
  61. PacketCopier copier;
  62. BPending recv_job;
  63. uint8_t *recv_data;
  64. int recv_data_len;
  65. // SSL transport
  66. StreamPacketSender ssl_sp_sender;
  67. SimpleStreamBuffer ssl_recv_buf;
  68. // SSL connection
  69. PRFileDesc ssl_bottom_prfd;
  70. PRFileDesc *ssl_prfd;
  71. BSSLConnection ssl_con;
  72. // SSL higher layer
  73. PacketStreamSender ssl_ps_sender;
  74. SinglePacketBuffer ssl_buffer;
  75. PacketProtoEncoder ssl_encoder;
  76. PacketCopier ssl_copier;
  77. PacketProtoDecoder ssl_recv_decoder;
  78. PacketPassInterface ssl_recv_if;
  79. DebugError d_err;
  80. DebugObject d_obj;
  81. } PeerChat;
  82. int PeerChat_Init (PeerChat *o, peerid_t peer_id, int ssl_mode, CERTCertificate *ssl_cert, SECKEYPrivateKey *ssl_key,
  83. uint8_t *ssl_peer_cert, int ssl_peer_cert_len, BPendingGroup *pg, void *user,
  84. PeerChat_handler_error handler_error,
  85. PeerChat_handler_message handler_message) WARN_UNUSED;
  86. void PeerChat_Free (PeerChat *o);
  87. PacketPassInterface * PeerChat_GetSendInput (PeerChat *o);
  88. PacketRecvInterface * PeerChat_GetSendOutput (PeerChat *o);
  89. void PeerChat_InputReceived (PeerChat *o, uint8_t *data, int data_len);
  90. #endif