整理目录结构,调整框架部分实现,初步编译通过。
This commit is contained in:
@@ -1,20 +1,25 @@
|
||||
|
||||
enum e_future_error
|
||||
{
|
||||
FUTURE_ERROR_CANCEL,
|
||||
FUTURE_ERROR_EXCEPTION,
|
||||
FUTURE_ERROR_TIMEOUT
|
||||
FUTURE_ERROR_CANCEL,
|
||||
FUTURE_ERROR_EXCEPTION,
|
||||
FUTURE_ERROR_TIMEOUT
|
||||
};
|
||||
|
||||
struct promise;
|
||||
struct future;
|
||||
typedef void (*future_success_cb)(void * result, void * user);
|
||||
typedef void (*future_failed_cb)(enum e_future_error err, const char * what, void * user);
|
||||
typedef void (*promise_ctx_destroy_cb)(struct promise* p);
|
||||
|
||||
struct future* future_create(future_success_cb * cb_success, future_failed_cb * cb_failed, void * user);
|
||||
|
||||
struct future* promise_to_future(struct promise* p);
|
||||
struct promise* future_to_promise(struct future* f);
|
||||
|
||||
typedef void (future_success_cb)(void * result, void * user);
|
||||
typedef void (future_failed_cb)(enum e_future_error err, const char * what, void * user);
|
||||
typedef void (promise_ctx_destroy_cb)(struct promise * p);
|
||||
|
||||
struct future * future_create(future_success_cb * cb_success, future_failed_cb * cb_failed, void * user);
|
||||
struct future * promise_to_future(struct promise * p);
|
||||
struct promise * future_to_promise(struct future * f);
|
||||
|
||||
void future_destroy(struct future * f);
|
||||
void promise_failed(struct promise * p, enum e_future_error error, const char * what);
|
||||
void promise_success(struct promise * p, void * result);
|
||||
void promise_set_ctx(struct promise * p, void * ctx, promise_ctx_destroy_cb * cb);
|
||||
void * promise_get_ctx(struct promise * p);
|
||||
void * promise_dettach_ctx(struct promise * p);
|
||||
|
||||
@@ -1,25 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <tfe_types.h>
|
||||
|
||||
#define TFE_STRING_MAX 2048
|
||||
#define TFE_SYMBOL_MAX 64
|
||||
|
||||
#define TFE_STRING_MAX 2048
|
||||
#define TFE_SYMBOL_MAX 64
|
||||
enum tfe_session_proto
|
||||
{
|
||||
SESSION_PROTO_PLAIN=0,
|
||||
SESSION_PROTO_PLAIN = 0,
|
||||
SESSION_PROTO_SSL,
|
||||
SESSION_PROTO_QUIC,
|
||||
SESSION_PROTO_SPDY
|
||||
};
|
||||
|
||||
enum tfe_app_proto
|
||||
{
|
||||
APP_PROTO_HTTP1,
|
||||
APP_PROTO_HTTP2,
|
||||
APP_PROTO_WS, //websocket
|
||||
APP_PROTO_QUIC //QUIC is a protocol that cross session layer and application layer.
|
||||
APP_PROTO_WS, //websocket
|
||||
APP_PROTO_QUIC //QUIC is a protocol that cross session layer and application layer.
|
||||
};
|
||||
|
||||
enum tfe_conn_dir
|
||||
{
|
||||
CONN_DIR_DOWNSTREAM=0, //From client to proxy, aka client-side.
|
||||
CONN_DIR_UPSTREAM //From proxy to server, aka server-side.
|
||||
CONN_DIR_DOWNSTREAM = 0, //From client to proxy, aka client-side.
|
||||
CONN_DIR_UPSTREAM //From proxy to server, aka server-side.
|
||||
};
|
||||
|
||||
enum tfe_conn_status
|
||||
{
|
||||
CONN_STATUS_NONE,
|
||||
@@ -32,78 +41,79 @@ struct tfe_conn
|
||||
{
|
||||
struct layer_addr addr;
|
||||
enum tfe_conn_status status;
|
||||
struct bufferevent *bev;
|
||||
} ;
|
||||
struct bufferevent * bev;
|
||||
};
|
||||
|
||||
struct tfe_stream
|
||||
{
|
||||
|
||||
struct tfe_conn upstream;
|
||||
struct tfe_conn upstream;
|
||||
struct tfe_conn downstream;
|
||||
};
|
||||
|
||||
|
||||
enum tfe_stream_action
|
||||
{
|
||||
ACTION_FORWARD_DATA,
|
||||
ACTION_DEFER_DATA,
|
||||
ACTION_DROP_DATA
|
||||
};
|
||||
|
||||
enum tfe_stream_action_opt
|
||||
{
|
||||
ACTION_OPT_FOWARD_BYTES, //value is size_t, default: forward entire data
|
||||
ACTION_OPT_DEFER_TIME_TV, //value is "struct timeval " which defines in <time.h>, default: time defer is not enabled
|
||||
ACTION_OPT_DEFER_BYTES, //value is size_t, default: defer entire data
|
||||
ACTION_OPT_DROP_BYTES //value is size_t, default: drop entire data
|
||||
ACTION_OPT_FOWARD_BYTES, //value is size_t, default: forward entire data
|
||||
ACTION_OPT_DEFER_TIME_TV, //value is "struct timeval " which defines in <time.h>, default: time defer is not enabled
|
||||
ACTION_OPT_DEFER_BYTES, //value is size_t, default: defer entire data
|
||||
ACTION_OPT_DROP_BYTES //value is size_t, default: drop entire data
|
||||
};
|
||||
|
||||
enum tfe_stream_close_reason
|
||||
{
|
||||
REASON_PASSIVE_CLOSED,
|
||||
REASON_ACTIVE_CLOSED,
|
||||
REASON_ERROR
|
||||
};
|
||||
int tfe_stream_action_set_opt(const struct tfe_stream* stream,enum tfe_stream_action_opt type, void* value, size_t size);
|
||||
|
||||
int tfe_stream_action_set_opt(const struct tfe_stream * stream, enum tfe_stream_action_opt type,
|
||||
void * value, size_t size);
|
||||
/*
|
||||
@return 0 if successful, or -1 if an error occurred
|
||||
*/
|
||||
int tfe_stream_write(const struct tfe_stream * stream, enum tfe_conn_dir dir, const unsigned char * data, size_t len);
|
||||
|
||||
int tfe_stream_write(const struct tfe_stream* stream, enum tfe_conn_dir dir, const unsigned char *data, size_t len);
|
||||
|
||||
struct tfe_stream_write_ctx{};
|
||||
struct tfe_stream_write_ctx;
|
||||
//following tfe_stream_write_xx functions are NOT thread safe, MUST be called in the stream process thread.
|
||||
struct tfe_stream_write_ctx* tfe_stream_write_frag_start(const struct tfe_stream* stream, enum tfe_conn_dir dir);
|
||||
struct tfe_stream_write_ctx * tfe_stream_write_frag_start(const struct tfe_stream * stream, enum tfe_conn_dir dir);
|
||||
/*
|
||||
@return 0 if successful, or -1 if an error occurred
|
||||
*/
|
||||
int tfe_stream_write_frag(struct tfe_stream_write_ctx* w_ctx,const unsigned char *data, size_t size);
|
||||
void tfe_stream_write_frag_end(struct tfe_stream_write_ctx* w_ctx);
|
||||
int tfe_stream_write_frag(struct tfe_stream_write_ctx * w_ctx, const unsigned char * data, size_t size);
|
||||
void tfe_stream_write_frag_end(struct tfe_stream_write_ctx * w_ctx);
|
||||
|
||||
//Return 1 for identify as its traffic;
|
||||
//Return 0 for unknown traffic;
|
||||
typedef tfe_stream_action stream_open_cb_t(const struct tfe_stream* stream, unsigned int thread_id, enum tfe_conn_dir dir, const unsigned char *data, size_t len, void **pme);
|
||||
typedef tfe_stream_action stream_data_cb_t(const struct tfe_stream* stream, unsigned int thread_id, enum tfe_conn_dir dir, const unsigned char *data, size_t len, void **pme);
|
||||
typedef void stream_close_cb_t(const struct tfe_stream* stream, unsigned int thread_id, enum tfe_stream_close_reason reason, void **pme);
|
||||
typedef tfe_stream_action stream_open_cb_t(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme);
|
||||
|
||||
void tfe_stream_detach(const struct tfe_stream* stream);
|
||||
int tfe_stream_preempt(const struct tfe_stream* stream);
|
||||
typedef tfe_stream_action stream_data_cb_t(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_conn_dir dir, const unsigned char * data, size_t len, void ** pme);
|
||||
|
||||
typedef void stream_close_cb_t(const struct tfe_stream * stream, unsigned int thread_id,
|
||||
enum tfe_stream_close_reason reason, void ** pme);
|
||||
|
||||
void tfe_stream_detach(const struct tfe_stream * stream);
|
||||
int tfe_stream_preempt(const struct tfe_stream * stream);
|
||||
struct promise * tfe_stream_suspend(const struct tfe_stream * stream);
|
||||
void tfe_stream_resume(struct promisc * promisc);
|
||||
|
||||
int stream_shutdown(const struct tfe_stream* stream);//close both sides of the stream.
|
||||
int stream_shutdown_dir(const struct tfe_stream* stream, enum tfe_conn_dir dir);
|
||||
//typedef int proto_onwrite_cb_t(struct tfe_stream*, struct evbuffer *data, void **pme);
|
||||
//close both sides of the stream.
|
||||
int stream_shutdown(const struct tfe_stream * stream);
|
||||
int stream_shutdown_dir(const struct tfe_stream * stream, enum tfe_conn_dir dir);
|
||||
|
||||
struct tfe_plugin
|
||||
{
|
||||
char symbol[TFE_SYMBOL_MAX];
|
||||
enum tfe_app_proto proto;
|
||||
stream_open_cb_t* on_open;
|
||||
stream_data_cb_t* on_data;
|
||||
stream_close_cb_t* on_close;
|
||||
// proto_onwrite_cb_t *onwrite;
|
||||
|
||||
stream_open_cb_t * on_open;
|
||||
stream_data_cb_t * on_data;
|
||||
stream_close_cb_t * on_close;
|
||||
};
|
||||
int tfe_io_write(struct pxy_conn_desc* dest,int dir,struct evbuffer *data);
|
||||
|
||||
int tfe_xxx_proto_init(struct tfe_plugin*m);
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
#include <netinet/in.h> //defines struct in_addr
|
||||
|
||||
#define __TFE_STRING_MAX 2048
|
||||
#define MAX_FILENAME_SIZE 256
|
||||
|
||||
/* network-order */
|
||||
struct stream_tuple4_v4{
|
||||
struct in_addr saddr; /* network order */
|
||||
@@ -25,15 +24,12 @@ struct stream_tuple4_v6
|
||||
in_port_t dest; /* network order */
|
||||
};
|
||||
|
||||
|
||||
|
||||
#define GRE_TAG_LEN (4)
|
||||
struct layer_addr_gre
|
||||
{
|
||||
uint16_t gre_id;
|
||||
};
|
||||
|
||||
|
||||
#define VLAN_ID_MASK (0x0FFF)
|
||||
#define VLAN_TAG_LEN (4)
|
||||
struct layer_addr_vlan
|
||||
@@ -140,4 +136,3 @@ struct layer_addr
|
||||
};
|
||||
uint8_t addrlen; /* 地址结构长度 */
|
||||
};
|
||||
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
//#define ALLOC(t,n) (t *)calloc(sizeof(t),(n))
|
||||
|
||||
/* Allocates an array of objects using malloc() */
|
||||
#define ALLOC(type, number) \
|
||||
((type *)calloc(sizeof(type), number))
|
||||
|
||||
#define log_err_printf(fmt, args...) \
|
||||
fprintf(stderr, "file %s, line %d, " fmt, \
|
||||
__FILE__, __LINE__, ##args)
|
||||
#define log_dbg_printf(fmt, args...) \
|
||||
fprintf(stdout, "file %s, line %d, " fmt, \
|
||||
__FILE__, __LINE__, ##args)
|
||||
#define likely(expr) __builtin_expect((expr), 1)
|
||||
#define unlikely(expr) __builtin_expect((expr), 0)
|
||||
|
||||
int addr_sock2layer(struct sockaddr * sock_addr, int sockaddrlen, struct layer_addr* layer_addr);
|
||||
int addr_layer2sock(struct layer_addr* layer_addr,struct sockaddr * sock_addr);
|
||||
char* tfe_strdup(const char* s);
|
||||
|
||||
|
||||
17
common/include/tfe_utils.h
Normal file
17
common/include/tfe_utils.h
Normal file
@@ -0,0 +1,17 @@
|
||||
//#define ALLOC(t,n) (t *)calloc(sizeof(t),(n))
|
||||
|
||||
/* Allocates an array of objects using malloc() */
|
||||
#define ALLOC(type, number) \
|
||||
((type *)calloc(sizeof(type), number))
|
||||
|
||||
#define likely(expr) __builtin_expect((expr), 1)
|
||||
#define unlikely(expr) __builtin_expect((expr), 0)
|
||||
|
||||
int addr_sock_to_layer(struct sockaddr * sock_addr, int sockaddrlen, struct layer_addr * layer_addr);
|
||||
int addr_layer_to_sock(struct layer_addr * layer_addr, struct sockaddr * sock_addr);
|
||||
char* tfe_strdup(const char* s);
|
||||
|
||||
|
||||
#define TFE_LOG_ERROR
|
||||
#define TFE_LOG_INFO
|
||||
#define TFE_LOG_DEBUG
|
||||
Reference in New Issue
Block a user