comparison libpurple/protocols/msn/directconn.h @ 30433:119bd7b072eb

Initial support for direct connections. Preliminary patch from ticket #247 by Gbor Szuromi. Still needs lots of testing and fixes. References #247. committer: Elliott Sales de Andrade <qulogic@pidgin.im>
author kukkerman@gmail.com
date Wed, 17 Mar 2010 03:45:07 +0000
parents 462cb893521b
children b1cda3f8fdc9
comparison
equal deleted inserted replaced
30001:bfaf039aed87 30433:119bd7b072eb
24 #ifndef MSN_DIRECTCONN_H 24 #ifndef MSN_DIRECTCONN_H
25 #define MSN_DIRECTCONN_H 25 #define MSN_DIRECTCONN_H
26 26
27 typedef struct _MsnDirectConn MsnDirectConn; 27 typedef struct _MsnDirectConn MsnDirectConn;
28 28
29 #include "network.h"
30 #include "proxy.h"
31 #include "circbuffer.h"
32
29 #include "msg.h" 33 #include "msg.h"
30 #include "slp.h" 34 #include "slp.h"
31 #include "slplink.h" 35 #include "slplink.h"
36 #include "slpmsg.h"
37
38 typedef enum
39 {
40 DC_STATE_CLOSED, /*< No socket opened yet */
41 DC_STATE_FOO, /*< Waiting for FOO message */
42 DC_STATE_HANDSHAKE, /*< Waiting for handshake message */
43 DC_STATE_HANDSHAKE_REPLY, /*< Waiting for handshake reply message */
44 DC_STATE_ESTABILISHED /*< Handshake complete */
45 } MsnDirectConnState;
46
47 typedef enum
48 {
49 DC_PROCESS_OK = 0,
50 DC_PROCESS_ERROR,
51 DC_PROCESS_FALLBACK,
52 DC_PROCESS_CLOSE
53
54 } MsnDirectConnProcessResult;
55
56 typedef struct _MsnDirectConnPacket MsnDirectConnPacket;
57
58 struct _MsnDirectConnPacket {
59 guint32 length;
60 guchar *data;
61
62 void (*sent_cb)(struct _MsnDirectConnPacket*);
63 MsnMessage *msg;
64 };
32 65
33 struct _MsnDirectConn 66 struct _MsnDirectConn
34 { 67 {
35 MsnSlpLink *slplink; 68 MsnDirectConnState state; /**< Direct connection status */
36 MsnSlpCall *initial_call; 69 MsnSlpLink *slplink; /**< The slplink using this direct connection */
70 MsnSlpCall *slpcall; /**< The slpcall which initiated the direct connection */
71 char *msg_body; /**< The body of message sent by send_connection_info_msg_cb */
72 MsnSlpMessage *prev_ack; /**< The saved SLP ACK message */
37 73
38 PurpleProxyConnectData *connect_data; 74 guchar nonce[16]; /**< The nonce used for direct connection handshake */
75 gchar nonce_hash[37]; /**< The hash of nonce */
39 76
40 gboolean acked; 77 PurpleNetworkListenData *listen_data; /**< The pending socket creation request */
78 PurpleProxyConnectData *connect_data; /**< The pending connection attempt */
79 int listenfd; /**< The socket we're listening for incoming connections */
80 guint listenfd_handle; /**< The timeout handle for incoming connection */
81 guint connect_timeout_handle; /**< The timeout handle for outgoing connection */
41 82
42 char *nonce; 83 int fd; /**< The direct connection socket */
84 guint recv_handle; /**< The incoming data callback handle */
85 guint send_handle; /**< The outgoing data callback handle */
43 86
44 int fd; 87 gchar *in_buffer; /**< The receive buffer */
88 int in_size; /**< The receive buffer size */
89 int in_pos; /**< The first free position in receive buffer */
90 GQueue *out_queue; /**< The outgoing packet queue */
91 int msg_pos; /**< The position of next byte to be sent in the actual packet */
45 92
46 int port; 93 MsnSlpHeader header; /**< SLP header for parsing / serializing */
47 int inpa; 94
95 /**< The callback used for sending information to the peer about the opened scoket */
96 void (*send_connection_info_msg_cb)(struct _MsnDirectConn*);
48 97
49 int c; 98 gchar *ext_ip; /**< Our external IP address */
99 int ext_port; /**< Our external port */
100
101 guint timeout_handle;
102 gboolean progress;
103
104 //int num_calls; /**< The number of slpcalls using this direct connection */
50 }; 105 };
51 106
52 MsnDirectConn *msn_directconn_new(MsnSlpLink *slplink); 107 #define DC_CONNECT_TIMEOUT 5
53 gboolean msn_directconn_connect(MsnDirectConn *directconn, 108 #define DC_TIMEOUT 60
54 const char *host, int port); 109
55 void msn_directconn_listen(MsnDirectConn *directconn); 110 /*
56 void msn_directconn_send_msg(MsnDirectConn *directconn, MsnMessage *msg); 111 * Queues an MSN message to be sent via direct connection.
57 void msn_directconn_parse_nonce(MsnDirectConn *directconn, const char *nonce); 112 */
58 void msn_directconn_destroy(MsnDirectConn *directconn); 113 void
59 void msn_directconn_send_handshake(MsnDirectConn *directconn); 114 msn_dc_enqueue_msg(MsnDirectConn *dc, MsnMessage *msg);
115
116 /*
117 * Creates initializes and returns a new MsnDirectConn structure.
118 */
119 MsnDirectConn*
120 msn_dc_new(MsnSlpCall *slplink);
121
122 /*
123 * Destroys an MsnDirectConn structure. Frees every buffer allocated earlier
124 * restores saved callbacks, etc.
125 */
126 void
127 msn_dc_destroy(MsnDirectConn *dc);
128
129 /*
130 * Increases the slpcall counter in DC. The direct connection remains open
131 * until all slpcalls using it are destroyed.
132 */
133 void
134 msn_dc_ref(MsnDirectConn *dc);
135
136 /*
137 * Decrease the slpcall counter in DC. The direct connection remains open
138 * until all slpcalls using it are destroyed.
139 */
140 void
141 msn_dc_unref(MsnDirectConn *dc);
142
143 /*
144 * Sends a direct connect INVITE message on the associated slplink
145 * with the corresponding connection type and information.
146 */
147 void
148 msn_dc_send_invite(MsnDirectConn *dc);
149
150 /*
151 * Sends a direct connect OK message as a response to an INVITE received earliaer
152 * on the corresponding slplink.
153 */
154 void
155 msn_dc_send_ok(MsnDirectConn *dc);
156
157 /*
158 * This callback will be called when we're successfully connected to
159 * the remote host.
160 */
161 void
162 msn_dc_connected_to_peer_cb(gpointer data, gint fd, const gchar *error_msg);
163
164 /*
165 * This callback will be called when we're unable to connect to
166 * the remote host in DC_CONNECT_TIMEOUT seconds.
167 */
168 gboolean
169 msn_dc_outgoing_connection_timeout_cb(gpointer data);
170
171 /*
172 * This callback will be called when the listening socket is successfully
173 * created and it's parameters (IP/port) are available.
174 */
175 void
176 msn_dc_listen_socket_created_cb(int listenfd, gpointer data);
60 177
61 #endif /* MSN_DIRECTCONN_H */ 178 #endif /* MSN_DIRECTCONN_H */