|
4 | 4 | * modify it under the terms of the GNU General Public License as *
|
5 | 5 | * published by the Free Software Foundation; either version 2 of *
|
6 | 6 | * the License, or (at your option) any later version. *
|
7 |
| - * * |
8 |
| - * This program is distributed in the hope that it will be useful, * |
9 |
| - * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
10 |
| - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
11 |
| - * GNU General Public License for more details. * |
12 |
| - * * |
13 |
| - * You should have received a copy of the GNU General Public License* |
14 |
| - * along with this program; if not, contact: * |
15 |
| - * * |
16 |
| - * Free Software Foundation Voice: +1-617-542-5942 * |
17 |
| - * 59 Temple Place - Suite 330 Fax: +1-617-542-2652 * |
18 |
| - * Boston, MA 02111-1307, USA [email protected] * |
19 |
| - * * |
20 | 7 | \********************************************************************/
|
21 | 8 |
|
22 |
| -/** @file control.h |
23 |
| - @brief control related |
24 |
| - @author Copyright (C) 2016 Dengfeng Liu <[email protected]> |
25 |
| -*/ |
| 9 | +/** |
| 10 | + * @file control.h |
| 11 | + * @brief Main control interface for FRP (Fast Reverse Proxy) client |
| 12 | + * @author Dengfeng Liu <[email protected]> |
| 13 | + * @copyright Copyright (C) 2016 Dengfeng Liu |
| 14 | + * |
| 15 | + * This file contains the core control structures and functions |
| 16 | + * for managing FRP client connections and communications. |
| 17 | + */ |
26 | 18 |
|
27 |
| -#ifndef _CONTROL_H_ |
28 |
| -#define _CONTROL_H_ |
| 19 | +#ifndef CONTROL_H_ |
| 20 | +#define CONTROL_H_ |
29 | 21 |
|
30 |
| -#include "uthash.h" |
31 | 22 | #include "msg.h"
|
| 23 | +#include "uthash.h" |
32 | 24 |
|
33 |
| -struct proxy_client; |
34 |
| -struct bufferevent; |
35 |
| -struct event_base; |
36 |
| -enum msg_type; |
37 |
| - |
| 25 | +/** |
| 26 | + * @brief Main control structure for FRP client |
| 27 | + */ |
38 | 28 | struct control {
|
39 |
| - struct event_base *connect_base; //main netevent |
40 |
| - struct evdns_base *dnsbase; |
41 |
| - struct bufferevent *connect_bev; //main io evet buf |
42 |
| - struct event *ticker_ping; //heartbeat timer |
43 |
| - |
44 |
| - struct event *tcp_mux_ping_event; |
45 |
| - uint32_t tcp_mux_ping_id; |
46 |
| - struct tmux_stream stream; |
| 29 | + struct event_base *connect_base; /* Main event base */ |
| 30 | + struct evdns_base *dnsbase; /* DNS resolver base */ |
| 31 | + struct bufferevent *connect_bev; /* Main I/O event buffer */ |
| 32 | + struct event *ticker_ping; /* Heartbeat timer */ |
| 33 | + struct event *tcp_mux_ping_event; /* TCP multiplexing ping event */ |
| 34 | + uint32_t tcp_mux_ping_id; /* TCP multiplexing ping ID */ |
| 35 | + struct tmux_stream stream; /* Multiplexing stream */ |
47 | 36 | };
|
48 | 37 |
|
49 |
| -void connect_eventcb(struct bufferevent *bev, short events, void *ptr); |
50 |
| - |
51 |
| -void init_main_control(); |
| 38 | +/* Control lifecycle functions */ |
| 39 | +void init_main_control(void); |
| 40 | +void run_control(void); |
| 41 | +struct control *get_main_control(void); |
| 42 | +void close_main_control(void); |
52 | 43 |
|
53 |
| -void run_control(); |
54 |
| - |
55 |
| -struct control *get_main_control(); |
56 |
| - |
57 |
| -void close_main_control(); |
| 44 | +/* Server connection functions */ |
| 45 | +struct bufferevent *connect_server(struct event_base *base, const char *name, |
| 46 | + const int port); |
| 47 | +struct bufferevent *connect_udp_server(struct event_base *base); |
| 48 | +void connect_eventcb(struct bufferevent *bev, short events, void *ptr); |
58 | 49 |
|
| 50 | +/* Server communication functions */ |
59 | 51 | void start_login_frp_server(struct event_base *base);
|
60 |
| - |
61 | 52 | void send_login_frp_server(struct bufferevent *bev);
|
| 53 | +void login(void); |
| 54 | +void send_new_proxy(struct proxy_service *ps); |
62 | 55 |
|
63 |
| -void login(); |
| 56 | +/* Message handling functions */ |
| 57 | +void send_msg_frp_server(struct bufferevent *bev, const enum msg_type type, |
| 58 | + const char *msg, const size_t msg_len, |
| 59 | + struct tmux_stream *stream); |
64 | 60 |
|
65 |
| -void send_msg_frp_server(struct bufferevent *bev, |
66 |
| - const enum msg_type type, |
67 |
| - const char *msg, |
68 |
| - const size_t msg_len, |
69 |
| - struct tmux_stream *stream); |
| 61 | +void send_msg_frp_server(struct bufferevent *bev, const enum msg_type type, |
| 62 | + const char *msg, const size_t msg_len, |
| 63 | + struct tmux_stream *stream); |
70 | 64 |
|
71 |
| -void send_enc_msg_frp_server(struct bufferevent *bev, |
72 |
| - const enum msg_type type, |
73 |
| - const char *msg, |
74 |
| - const size_t msg_len, |
75 |
| - struct tmux_stream *stream); |
| 65 | +void send_enc_msg_frp_server(struct bufferevent *bev, const enum msg_type type, |
| 66 | + const char *msg, const size_t msg_len, |
| 67 | + struct tmux_stream *stream); |
76 | 68 |
|
77 | 69 | void control_process(struct proxy_client *client);
|
78 | 70 |
|
79 | 71 | void send_new_proxy(struct proxy_service *ps);
|
80 | 72 |
|
81 |
| -struct bufferevent *connect_server(struct event_base *base, const char *name, const int port); |
| 73 | +struct bufferevent *connect_server(struct event_base *base, const char *name, |
| 74 | + const int port); |
82 | 75 |
|
83 | 76 | struct bufferevent *connect_udp_server(struct event_base *base);
|
84 | 77 |
|
|
0 commit comments