rename config -> options

This commit is contained in:
luwenpeng
2024-03-08 14:51:21 +08:00
parent d0914483bb
commit 734f6a5135
32 changed files with 336 additions and 336 deletions

View File

@@ -27,7 +27,7 @@ struct session_manager
struct dupkt_filter *tcp_dupkt_filter;
struct eviction_filter *udp_eviction_filter;
struct session_manager_config config;
struct session_manager_options opts;
/***************************************************************
* session manager status
@@ -66,7 +66,7 @@ static inline void tcp_half_closed_timeout_cb(struct session *sess, void *arg);
static inline void tcp_time_wait_timeout_cb(struct session *sess, void *arg);
static inline void udp_data_timeout_cb(struct session *sess, void *arg);
static inline int session_manager_check_config(struct session_manager_config *config);
static inline int session_manager_check_options(struct session_manager_options *opts);
static inline uint64_t session_manager_alloc_session_id(void);
static inline int session_manager_update_tcp_filter(struct session_manager *mgr, struct session *sess, const struct packet *pkt, enum session_dir curr_dir);
@@ -181,123 +181,123 @@ static inline void udp_data_timeout_cb(struct session *sess, void *arg)
}
// return 0: success
// return -1: invalid config
static inline int session_manager_check_config(struct session_manager_config *config)
// return -1: invalid opts
static inline int session_manager_check_options(struct session_manager_options *opts)
{
if (config == NULL)
if (opts == NULL)
{
SESSION_LOG_ERROR("invalid config");
SESSION_LOG_ERROR("invalid opts");
return -1;
}
// max session number
if (config->max_tcp_session_num < 2)
if (opts->max_tcp_session_num < 2)
{
SESSION_LOG_ERROR("invalid max tcp session number");
return -1;
}
if (config->max_udp_session_num < 2)
if (opts->max_udp_session_num < 2)
{
SESSION_LOG_ERROR("invalid max udp session number");
return -1;
}
// session overload
if (config->tcp_overload_evict_old_sess != 0 && config->tcp_overload_evict_old_sess != 1)
if (opts->tcp_overload_evict_old_sess != 0 && opts->tcp_overload_evict_old_sess != 1)
{
SESSION_LOG_ERROR("invalid tcp overload evict old session, support range: 0-1");
return -1;
}
if (config->udp_overload_evict_old_sess != 0 && config->udp_overload_evict_old_sess != 1)
if (opts->udp_overload_evict_old_sess != 0 && opts->udp_overload_evict_old_sess != 1)
{
SESSION_LOG_ERROR("invalid udp overload evict old session, support range: 0-1");
return -1;
}
// TCP timeout config
if (config->tcp_timeout_init < 1 || config->tcp_timeout_init > 60)
// TCP timeout opts
if (opts->tcp_timeout_init < 1 || opts->tcp_timeout_init > 60)
{
SESSION_LOG_ERROR("invalid tcp timeout init, support range: 1-60");
return -1;
}
if (config->tcp_timeout_handshake < 1 || config->tcp_timeout_handshake > 60)
if (opts->tcp_timeout_handshake < 1 || opts->tcp_timeout_handshake > 60)
{
SESSION_LOG_ERROR("invalid tcp timeout handshake, support range: 1-60");
return -1;
}
if (config->tcp_timeout_data < 1 || config->tcp_timeout_data > 15999999)
if (opts->tcp_timeout_data < 1 || opts->tcp_timeout_data > 15999999)
{
SESSION_LOG_ERROR("invalid tcp timeout data, support range: 1-15,999,999");
return -1;
}
if (config->tcp_timeout_half_closed < 1 || config->tcp_timeout_half_closed > 604800)
if (opts->tcp_timeout_half_closed < 1 || opts->tcp_timeout_half_closed > 604800)
{
SESSION_LOG_ERROR("invalid tcp timeout half closed, support range: 1-604,800");
return -1;
}
if (config->tcp_timeout_time_wait < 1 || config->tcp_timeout_time_wait > 600)
if (opts->tcp_timeout_time_wait < 1 || opts->tcp_timeout_time_wait > 600)
{
SESSION_LOG_ERROR("invalid tcp timeout time wait, support range: 1-600");
return -1;
}
if (config->tcp_timeout_discard < 1 || config->tcp_timeout_discard > 15999999)
if (opts->tcp_timeout_discard < 1 || opts->tcp_timeout_discard > 15999999)
{
SESSION_LOG_ERROR("invalid tcp timeout discard, support range: 1-15,999,999");
return -1;
}
// UDP timeout config
if (config->udp_timeout_data < 1 || config->udp_timeout_data > 15999999)
// UDP timeout opts
if (opts->udp_timeout_data < 1 || opts->udp_timeout_data > 15999999)
{
SESSION_LOG_ERROR("invalid udp timeout data, support range: 1-15,999,999");
return -1;
}
// TCP duplicate packet filter config
if (config->tcp_dupkt_filter_enable != 0 && config->tcp_dupkt_filter_enable != 1)
// TCP duplicate packet filter opts
if (opts->tcp_dupkt_filter_enable != 0 && opts->tcp_dupkt_filter_enable != 1)
{
SESSION_LOG_ERROR("invalid tcp dupkt filter enable, support range: 0-1");
return -1;
}
if (config->tcp_dupkt_filter_enable)
if (opts->tcp_dupkt_filter_enable)
{
if (config->tcp_dupkt_filter_capacity == 0)
if (opts->tcp_dupkt_filter_capacity == 0)
{
SESSION_LOG_ERROR("invalid tcp dupkt filter capacity");
return -1;
}
if (config->tcp_dupkt_filter_timeout < 1 || config->tcp_dupkt_filter_timeout > 60)
if (opts->tcp_dupkt_filter_timeout < 1 || opts->tcp_dupkt_filter_timeout > 60)
{
SESSION_LOG_ERROR("invalid tcp dupkt filter timeout, support range: 1-60");
return -1;
}
if (config->tcp_dupkt_filter_error_rate < 0 || config->tcp_dupkt_filter_error_rate > 1)
if (opts->tcp_dupkt_filter_error_rate < 0 || opts->tcp_dupkt_filter_error_rate > 1)
{
SESSION_LOG_ERROR("invalid tcp dupkt filter error rate, support range: 0-1");
return -1;
}
}
// UDP eviction filter config
if (config->udp_eviction_filter_enable != 0 && config->udp_eviction_filter_enable != 1)
// UDP eviction filter opts
if (opts->udp_eviction_filter_enable != 0 && opts->udp_eviction_filter_enable != 1)
{
SESSION_LOG_ERROR("invalid udp eviction filter enable, support range: 0-1");
return -1;
}
if (config->udp_eviction_filter_enable)
if (opts->udp_eviction_filter_enable)
{
if (config->udp_eviction_filter_capacity == 0)
if (opts->udp_eviction_filter_capacity == 0)
{
SESSION_LOG_ERROR("invalid udp eviction filter capacity");
return -1;
}
if (config->udp_eviction_filter_timeout < 1 || config->udp_eviction_filter_timeout > 60)
if (opts->udp_eviction_filter_timeout < 1 || opts->udp_eviction_filter_timeout > 60)
{
SESSION_LOG_ERROR("invalid udp eviction filter timeout, support range: 1-60");
return -1;
}
if (config->udp_eviction_filter_error_rate < 0 || config->udp_eviction_filter_error_rate > 1)
if (opts->udp_eviction_filter_error_rate < 0 || opts->udp_eviction_filter_error_rate > 1)
{
SESSION_LOG_ERROR("invalid udp eviction filter error rate, support range: 0-1");
return -1;
@@ -633,13 +633,13 @@ static inline void session_manager_update_session_packet(struct session_manager
static inline void session_manager_update_udp_to_opening(struct session_manager *mgr, struct session *sess)
{
session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING);
session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->config.udp_timeout_data);
session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->opts.udp_timeout_data);
}
static inline void session_manager_update_udp_to_active(struct session_manager *mgr, struct session *sess)
{
session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE);
session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->config.udp_timeout_data);
session_manager_update_session_timer(mgr, sess, udp_data_timeout_cb, mgr->opts.udp_timeout_data);
}
static inline void session_manager_update_udp_to_closing(struct session_manager *mgr, struct session *sess)
@@ -655,18 +655,18 @@ static inline void session_manager_update_tcp_to_opening(struct session_manager
session_manager_update_session_state(mgr, sess, SESSION_STATE_OPENING);
if (opening_by_syn)
{
session_manager_update_session_timer(mgr, sess, tcp_init_timeout_cb, mgr->config.tcp_timeout_init);
session_manager_update_session_timer(mgr, sess, tcp_init_timeout_cb, mgr->opts.tcp_timeout_init);
}
else
{
session_manager_update_session_timer(mgr, sess, tcp_handshake_timeout_cb, mgr->config.tcp_timeout_handshake);
session_manager_update_session_timer(mgr, sess, tcp_handshake_timeout_cb, mgr->opts.tcp_timeout_handshake);
}
}
static inline void session_manager_update_tcp_to_active(struct session_manager *mgr, struct session *sess)
{
session_manager_update_session_state(mgr, sess, SESSION_STATE_ACTIVE);
session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->config.tcp_timeout_data);
session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->opts.tcp_timeout_data);
}
static inline void session_manager_update_tcp_to_closing(struct session_manager *mgr, struct session *sess, int enable_time_wait)
@@ -674,7 +674,7 @@ static inline void session_manager_update_tcp_to_closing(struct session_manager
session_manager_update_session_state(mgr, sess, SESSION_STATE_CLOSING);
if (enable_time_wait)
{
session_manager_update_session_timer(mgr, sess, tcp_time_wait_timeout_cb, mgr->config.tcp_timeout_time_wait);
session_manager_update_session_timer(mgr, sess, tcp_time_wait_timeout_cb, mgr->opts.tcp_timeout_time_wait);
}
else
{
@@ -724,7 +724,7 @@ static inline void session_manager_handle_tcp_on_opening(struct session_manager
SESSION_LOG_DEBUG("TCP %s FIN received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_FIN_RECVED ? "C2S" : "S2C"), session_get_id(sess));
// still opening, only update timeout
session_set_closing_reason(sess, (tcp_mod_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN);
session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->config.tcp_timeout_half_closed);
session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->opts.tcp_timeout_half_closed);
return;
}
@@ -732,7 +732,7 @@ static inline void session_manager_handle_tcp_on_opening(struct session_manager
{
SESSION_LOG_DEBUG("TCP %s ACK received, session %lu opening -> opening", (tcp_curr_state & TCP_C2S_ACK_RECVED ? "C2S" : "S2C"), session_get_id(sess));
// still opening, only update timeout
session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->config.tcp_timeout_data);
session_manager_update_session_timer(mgr, sess, tcp_data_timeout_cb, mgr->opts.tcp_timeout_data);
return;
}
@@ -783,7 +783,7 @@ static inline void session_manager_handle_tcp_on_active(struct session_manager *
SESSION_LOG_DEBUG("TCP %s FIN received, session %lu active -> active", (tcp_curr_state & TCP_C2S_FIN_RECVED) ? "C2S" : "S2C", session_get_id(sess));
// still active
session_set_closing_reason(sess, (tcp_curr_state & TCP_C2S_FIN_RECVED) ? CLOSING_BY_CLIENT_FIN : CLOSING_BY_SERVER_FIN);
session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->config.tcp_timeout_half_closed);
session_manager_update_session_timer(mgr, sess, tcp_half_closed_timeout_cb, mgr->opts.tcp_timeout_half_closed);
return;
}
@@ -815,9 +815,9 @@ static inline struct session *session_manager_new_tcp_session(struct session_man
return NULL;
}
if (mgr->tcp_sess_num >= mgr->config.max_tcp_session_num - 1)
if (mgr->tcp_sess_num >= mgr->opts.max_tcp_session_num - 1)
{
if (mgr->config.tcp_overload_evict_old_sess)
if (mgr->opts.tcp_overload_evict_old_sess)
{
struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->tcp_sess_table);
assert(evicted_sess);
@@ -826,7 +826,7 @@ static inline struct session *session_manager_new_tcp_session(struct session_man
}
else
{
if (mgr->tcp_sess_num >= mgr->config.max_tcp_session_num)
if (mgr->tcp_sess_num >= mgr->opts.max_tcp_session_num)
{
mgr->tcp_overload_evict_new_sess_num++;
return NULL;
@@ -866,9 +866,9 @@ static inline struct session *session_manager_new_udp_session(struct session_man
return NULL;
}
if (mgr->udp_sess_num >= mgr->config.max_udp_session_num - 1)
if (mgr->udp_sess_num >= mgr->opts.max_udp_session_num - 1)
{
if (mgr->config.udp_overload_evict_old_sess)
if (mgr->opts.udp_overload_evict_old_sess)
{
struct session *evicted_sess = session_table_find_least_recently_unused_session(mgr->udp_sess_table);
assert(evicted_sess);
@@ -877,7 +877,7 @@ static inline struct session *session_manager_new_udp_session(struct session_man
}
else
{
if (mgr->udp_sess_num >= mgr->config.max_udp_session_num)
if (mgr->udp_sess_num >= mgr->opts.max_udp_session_num)
{
mgr->udp_overload_evict_new_sess_num++;
return NULL;
@@ -1029,9 +1029,9 @@ static inline void session_manager_evicte_session(struct session_manager *mgr, s
* Public API
******************************************************************************/
struct session_manager *session_manager_new(struct session_manager_config *config)
struct session_manager *session_manager_new(struct session_manager_options *opts)
{
if (session_manager_check_config(config))
if (session_manager_check_options(opts))
{
return NULL;
}
@@ -1042,8 +1042,8 @@ struct session_manager *session_manager_new(struct session_manager_config *confi
return NULL;
}
memcpy(&mgr->config, config, sizeof(struct session_manager_config));
mgr->sess_pool = session_pool_new(mgr->config.max_tcp_session_num + mgr->config.max_udp_session_num);
memcpy(&mgr->opts, opts, sizeof(struct session_manager_options));
mgr->sess_pool = session_pool_new(mgr->opts.max_tcp_session_num + mgr->opts.max_udp_session_num);
if (mgr->sess_pool == NULL)
{
goto error;
@@ -1079,13 +1079,13 @@ struct session_manager *session_manager_new(struct session_manager_config *confi
goto error;
}
mgr->tcp_dupkt_filter = dupkt_filter_new(mgr->config.tcp_dupkt_filter_enable, mgr->config.tcp_dupkt_filter_capacity, mgr->config.tcp_dupkt_filter_error_rate, mgr->config.tcp_dupkt_filter_timeout);
mgr->tcp_dupkt_filter = dupkt_filter_new(mgr->opts.tcp_dupkt_filter_enable, mgr->opts.tcp_dupkt_filter_capacity, mgr->opts.tcp_dupkt_filter_error_rate, mgr->opts.tcp_dupkt_filter_timeout);
if (mgr->tcp_dupkt_filter == NULL)
{
goto error;
}
mgr->udp_eviction_filter = eviction_filter_new(mgr->config.udp_eviction_filter_enable, mgr->config.udp_eviction_filter_capacity, mgr->config.udp_eviction_filter_error_rate, mgr->config.udp_eviction_filter_timeout);
mgr->udp_eviction_filter = eviction_filter_new(mgr->opts.udp_eviction_filter_enable, mgr->opts.udp_eviction_filter_capacity, mgr->opts.udp_eviction_filter_error_rate, mgr->opts.udp_eviction_filter_timeout);
if (mgr->udp_eviction_filter == NULL)
{
goto error;