Skip to content

0.2 pu gtest support #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,7 @@ DerivedData
# http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control
#
# Pods/

## googletest
test/acceltcp_unittest
gtest*
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ cmake_minimum_required(VERSION 2.6.2)
include_directories(/usr/local/include /usr/include)
link_directories(/usr/local/lib /usr/lib)

set(acceltcp_srcs acceltcp.c evsock.c http_handler.c http_parser.c)
set(acceltcp_srcs acceltcp_main.c acceltcp.c evsock.c http_handler.c http_parser.c)
add_executable(acceltcp ${acceltcp_srcs})
target_link_libraries(acceltcp ev)
target_link_libraries(acceltcp ssl)
target_link_libraries(acceltcp crypto)

add_subdirectory(gtest-1.7.0)
add_subdirectory(test)
183 changes: 19 additions & 164 deletions acceltcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,159 +23,10 @@
* THE SOFTWARE.
*/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <signal.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <arpa/inet.h>
#include <netinet/tcp.h>
#include <openssl/crypto.h>
#include <openssl/ssl.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <ev.h>
#include "evsock.h"
#include "http_handler.h"
#include "acceltcp.h"

#define APP_NAME "acceltcp"
#define APP_DESCRIPTION "ACCELerate TCP proxy"
#define APP_VERSION "0.2"
#define APP_AUTHOR "Masaya YAMAMOTO <[email protected]>"

#define DEFAULT_SSL_CERITIFICATE_FILE "server.crt"
#define DEFAULT_SSL_PRIVATEKEY_FILE "server.key"

#ifndef SOL_TCP
#define SOL_TCP IPPROTO_TCP
#endif

#define ACCELTCP_TCP_KEEPIDLE 90
#define ACCELTCP_TCP_KEEPINTVL 30
#define ACCELTCP_TCP_KEEPCNT 6

#define ACCELTCP_HDR_MAGIC 0xacce1381
#define ACCELTCP_HDR_FLG_SYN 0x0100
#define ACCELTCP_HDR_FLG_FIN 0x0200
#define ACCELTCP_HDR_FLG_RST 0x0300

#define DEBUG(fmt, ...) \
do { \
if (config.debug) { \
fprintf(stderr, fmt, ## __VA_ARGS__); \
} \
} while (0);

#define STRSAFEPRINT(x) ((x) ? (x) : "")

#ifndef MIN
#define MIN(x, y) ((x) < (y) ? (x) : (y))
#endif
#ifndef MAX
#define MAX(x, y) ((x) > (y) ? (x) : (y))
#endif

#define BACKLOG 1024

struct hdr {
uint32_t ___;
uint32_t xid;
uint16_t flg;
uint16_t len;
};

#define HDR_LEN (sizeof(struct hdr))

struct config_tunnel {
int ipv4only;
int ipv6only;
int http;
char *http_host;
int server;
int ssl_accept;
char *ssl_certificate;
char *ssl_privatekey;
int ssl_connect;
int rbuf;
int sbuf;
int connection_num;
char *self_addr;
char *self_port;
char *peer_addr;
char *peer_port;
struct config_tunnel *next;
};

struct config {
int debug;
int quiet;
int verbose;
struct config_tunnel *tunnels;
};

struct ssock {
struct evsock sock;
struct tunnel *tunnel;
struct ssock *next;
};

struct econn {
struct evsock sock;
struct {
http_parser parser;
struct http_handler_env env;
} http;
struct tunnel *tunnel;
struct session *session;
struct econn *next;
};

struct pconn {
int ready;
struct evsock sock;
struct tunnel *tunnel;
struct session *session;
struct pconn *next;
};

struct session {
uint32_t xid;
struct {
int closed;
struct buffer buf;
size_t bytes;
} e2p;
struct {
int closed;
struct buffer buf;
size_t bytes;
} p2e;
struct econn *econn;
struct pconn *pconn;
};

struct tunnel {
int id;
struct {
SSL_CTX *server_ctx;
SSL_CTX *client_ctx;
} ssl;
struct config_tunnel *config;
struct ssock *ssocks;
struct pconn *pconns;
struct tunnel *next;
};

static struct config config;
static struct tunnel *tunnels;
struct config config;
struct tunnel *tunnels;

void
hexdump (FILE *fp, void *data, size_t size) {
Expand Down Expand Up @@ -800,7 +651,7 @@ pconn_pre_accept_cb (struct evsock *sock) {
return &p->sock;
}

static void
void
usage (void) {
printf("usage: %s [options] -- [tunnel_options] tunnel\n", APP_NAME);
printf(" Options:\n");
Expand Down Expand Up @@ -882,7 +733,7 @@ strisdigit (const char *s) {
return 1;
}

static int
int
option_parse_tunnel (char *s, struct config_tunnel *c) {
char *p, *t[4];
size_t n;
Expand Down Expand Up @@ -921,7 +772,7 @@ option_parse_tunnel (char *s, struct config_tunnel *c) {
return 0;
}

static int
int
option_parse (int argc, char *argv[], struct config *config) {
int opt;
struct config_tunnel *c;
Expand Down Expand Up @@ -956,8 +807,8 @@ option_parse (int argc, char *argv[], struct config *config) {
config->debug = 1;
break;
case 'h':
usage();
exit(EXIT_SUCCESS);
usage();
return -2;
case 'q':
config->quiet = 1;
break;
Expand All @@ -966,7 +817,7 @@ option_parse (int argc, char *argv[], struct config *config) {
break;
case 'V':
version();
exit(EXIT_SUCCESS);
return -2;
default:
return -1;
}
Expand Down Expand Up @@ -1342,7 +1193,7 @@ tunnel_setup_pconns (struct ev_loop *loop, struct tunnel *tunnel) {
return count;
}

static struct tunnel *
struct tunnel *
tunnel_setup (struct ev_loop *loop, struct config_tunnel *c) {
struct tunnel *tunnel;
int ret;
Expand Down Expand Up @@ -1418,18 +1269,18 @@ print_pconn_status (void) {
}
}

static void
void
timeout_cb (struct ev_loop *loop, struct ev_timer *w, int revents) {
print_pconn_status();
}

static void
void
signal_cb (struct ev_loop *loop, struct ev_signal *w, int revents) {
print_pconn_status();
}

int
main (int argc, char *argv[]) {
acceltcp (int argc, char *argv[]) {
struct sigaction sig;
struct ev_loop *loop;
struct ev_signal signal_w;
Expand All @@ -1443,8 +1294,12 @@ main (int argc, char *argv[]) {
sigemptyset(&sig.sa_mask);
sig.sa_flags= 0;
sigaction(SIGPIPE, &sig, NULL);
if (option_parse(argc, argv, &config) == -1) {
usage();
int option_parse_status = option_parse(argc, argv, &config);
if (option_parse_status != 0) {
if (option_parse_status == -2) {
return EXIT_SUCCESS;
}
usage();
return -1;
}
if (config.debug) {
Expand Down
Loading