#define TFE_STRING_MAX 2048 #define TFE_SYMBOL_MAX 64 enum tfe_session_proto { 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. }; 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. }; enum tfe_conn_status { CONN_STATUS_NONE, CONN_STATUS_ESTABLISHED, CONN_STATUS_CLOSED, }; /* single dst or src socket bufferevent descriptor */ struct tfe_conn { struct layer_addr addr; enum tfe_conn_status status; struct bufferevent *bev; } ; struct tfe_stream { struct tfe_conn upstream; struct tfe_conn downstream; void* application_pme; }; //Return 1 for identify as its traffic; //Return 0 for unknown traffic; typedef int proto_pend_cb_t(const struct tfe_stream* stream, struct evbuffer *data, void **pme); enum tfe_proto_action { PROTO_ATCION_FORWARD, PROTO_ACTION_DEFER, PROTO_ACTION_STEAL, PROTO_ACTION_PASSTHROUGH, PROTO_ACTION_CLOSE }; enum tfe_proto_action_opt { ACTION_OPT_DEFER_TIME_TV, //value is "struct timeval " which defines in , default: time defer is not enabled ACTION_OPT_DEFER_BYTES, //value is size_t, default: defer entire evbufer ACTION_OPT_FOWARD_BYTES, //value is size_t, default: forward entire evbufer ACTION_OPT_CLOSE_DIR //value is enum tfe_conn_dir, default: close both side. }; int tfe_proto_action_set_opt(const struct tfe_stream* stream,enum tfe_proto_action_opt type, void* value, size_t size); typedef tfe_proto_action proto_read_cb_t(const struct tfe_stream* stream, struct evbuffer *data, enum tfe_conn_dir dir, void **pme); typedef void proto_close_cb_t(const struct tfe_stream* stream, int ev, void **pme); //typedef int proto_onwrite_cb_t(struct tfe_stream*, struct evbuffer *data, void **pme); struct tfe_proto_module { char symbol[TFE_SYMBOL_MAX]; proto_pend_cb_t *on_pend; proto_read_cb_t *on_read; proto_close_cb_t *on_close; // proto_onwrite_cb_t *onwrite; }; int tfe_io_write(struct pxy_conn_desc* dest,int dir,struct evbuffer *data); int tfe_xxx_proto_init(struct tfe_proto_module*m);