BadVPN – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /**
2 * @file PeerChat.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  
30 #ifndef BADVPN_PEERCHAT_H
31 #define BADVPN_PEERCHAT_H
32  
33 #include <nss/cert.h>
34 #include <nss/keyhi.h>
35  
36 #include <protocol/packetproto.h>
37 #include <protocol/scproto.h>
38 #include <misc/debug.h>
39 #include <misc/debugerror.h>
40 #include <base/DebugObject.h>
41 #include <base/BPending.h>
42 #include <base/BLog.h>
43 #include <flow/SinglePacketSender.h>
44 #include <flow/PacketProtoEncoder.h>
45 #include <flow/PacketCopier.h>
46 #include <flow/StreamPacketSender.h>
47 #include <flow/PacketStreamSender.h>
48 #include <flow/SinglePacketBuffer.h>
49 #include <flow/PacketProtoDecoder.h>
50 #include <flow/PacketBuffer.h>
51 #include <flow/BufferWriter.h>
52 #include <nspr_support/BSSLConnection.h>
53 #include <client/SCOutmsgEncoder.h>
54 #include <client/SimpleStreamBuffer.h>
55  
56 #define PEERCHAT_SSL_NONE 0
57 #define PEERCHAT_SSL_CLIENT 1
58 #define PEERCHAT_SSL_SERVER 2
59  
60 #define PEERCHAT_SSL_RECV_BUF_SIZE 4096
61 #define PEERCHAT_SEND_BUF_SIZE 200
62  
63 //#define PEERCHAT_SIMULATE_ERROR 40
64  
65 typedef void (*PeerChat_handler_error) (void *user);
66 typedef void (*PeerChat_handler_message) (void *user, uint8_t *data, int data_len);
67  
68 typedef struct {
69 int ssl_mode;
70 CERTCertificate *ssl_cert;
71 SECKEYPrivateKey *ssl_key;
72 uint8_t *ssl_peer_cert;
73 int ssl_peer_cert_len;
74 void *user;
75 BLog_logfunc logfunc;
76 PeerChat_handler_error handler_error;
77 PeerChat_handler_message handler_message;
78  
79 // transport
80 PacketProtoEncoder pp_encoder;
81 SCOutmsgEncoder sc_encoder;
82 PacketCopier copier;
83 BPending recv_job;
84 uint8_t *recv_data;
85 int recv_data_len;
86  
87 // SSL transport
88 StreamPacketSender ssl_sp_sender;
89 SimpleStreamBuffer ssl_recv_buf;
90  
91 // SSL connection
92 PRFileDesc ssl_bottom_prfd;
93 PRFileDesc *ssl_prfd;
94 BSSLConnection ssl_con;
95  
96 // SSL higher layer
97 PacketStreamSender ssl_ps_sender;
98 SinglePacketBuffer ssl_buffer;
99 PacketProtoEncoder ssl_encoder;
100 PacketCopier ssl_copier;
101 PacketProtoDecoder ssl_recv_decoder;
102 PacketPassInterface ssl_recv_if;
103  
104 // higher layer send buffer
105 PacketBuffer send_buf;
106 BufferWriter send_writer;
107  
108 DebugError d_err;
109 DebugObject d_obj;
110 } PeerChat;
111  
112 int PeerChat_Init (PeerChat *o, peerid_t peer_id, int ssl_mode, int ssl_flags, CERTCertificate *ssl_cert, SECKEYPrivateKey *ssl_key,
113 uint8_t *ssl_peer_cert, int ssl_peer_cert_len, BPendingGroup *pg, BThreadWorkDispatcher *twd, void *user,
114 BLog_logfunc logfunc,
115 PeerChat_handler_error handler_error,
116 PeerChat_handler_message handler_message) WARN_UNUSED;
117 void PeerChat_Free (PeerChat *o);
118 PacketRecvInterface * PeerChat_GetSendOutput (PeerChat *o);
119 void PeerChat_InputReceived (PeerChat *o, uint8_t *data, int data_len);
120 int PeerChat_StartMessage (PeerChat *o, uint8_t **data) WARN_UNUSED;
121 void PeerChat_EndMessage (PeerChat *o, int data_len);
122  
123 #endif