From d78a1824c19eba4c4f409659729cf5778ff23b78 Mon Sep 17 00:00:00 2001 From: Apex Liu Date: Fri, 4 May 2018 18:26:26 +0800 Subject: [PATCH] . --- server/tp_core/common/protocol_interface.h | 1 + server/tp_core/core/tp_tpp_mgr.cpp | 14 +++++-- server/tp_core/core/tp_tpp_mgr.h | 3 +- server/tp_core/core/ts_http_rpc.cpp | 49 +++++++++------------- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/server/tp_core/common/protocol_interface.h b/server/tp_core/common/protocol_interface.h index eb95e21..5ba08da 100644 --- a/server/tp_core/common/protocol_interface.h +++ b/server/tp_core/common/protocol_interface.h @@ -15,6 +15,7 @@ #endif #define TPP_CMD_INIT 0x00000000 +#define TPP_CMD_SET_RUNTIME_CFG 0x00000005 #define TPP_CMD_KILL_SESSIONS 0x00000006 typedef struct TPP_CONNECT_INFO diff --git a/server/tp_core/core/tp_tpp_mgr.cpp b/server/tp_core/core/tp_tpp_mgr.cpp index 27ac29f..5f0d747 100644 --- a/server/tp_core/core/tp_tpp_mgr.cpp +++ b/server/tp_core/core/tp_tpp_mgr.cpp @@ -121,11 +121,17 @@ void TppManager::set_config(int noop_timeout) { } } -void TppManager::kill_sessions(const ex_astr& sessions) { +void TppManager::set_runtime_config(const ex_astr& sp) { tpp_libs::iterator it = m_libs.begin(); - for (; it != m_libs.end(); ++it) - { - (*it)->command(TPP_CMD_KILL_SESSIONS, sessions.c_str()); + for (; it != m_libs.end(); ++it) { + (*it)->command(TPP_CMD_SET_RUNTIME_CFG, sp.c_str()); + } +} + +void TppManager::kill_sessions(const ex_astr& sp) { + tpp_libs::iterator it = m_libs.begin(); + for (; it != m_libs.end(); ++it) { + (*it)->command(TPP_CMD_KILL_SESSIONS, sp.c_str()); } } diff --git a/server/tp_core/core/tp_tpp_mgr.h b/server/tp_core/core/tp_tpp_mgr.h index cec6d47..b625a72 100644 --- a/server/tp_core/core/tp_tpp_mgr.h +++ b/server/tp_core/core/tp_tpp_mgr.h @@ -53,7 +53,8 @@ public: int count(void) { return m_libs.size(); } void set_config(int noop_timeout); - void kill_sessions(const ex_astr& sessions); + void set_runtime_config(const ex_astr& sp); + void kill_sessions(const ex_astr& sp); private: tpp_libs m_libs; diff --git a/server/tp_core/core/ts_http_rpc.cpp b/server/tp_core/core/ts_http_rpc.cpp index c5d1f4b..d7d23b5 100644 --- a/server/tp_core/core/ts_http_rpc.cpp +++ b/server/tp_core/core/ts_http_rpc.cpp @@ -388,38 +388,32 @@ void TsHttpRpc::_rpc_func_kill_sessions(const Json::Value& json_param, ex_astr& } */ - if (json_param.isArray()) - { + if (json_param.isArray()) { _create_json_ret(buf, TPE_PARAM); return; } - if (json_param["sessions"].isNull() || !json_param["sessions"].isArray()) - { + if (json_param["sessions"].isNull() || !json_param["sessions"].isArray()) { _create_json_ret(buf, TPE_PARAM); return; } Json::Value s = json_param["sessions"]; int cnt = s.size(); - for (int i = 0; i < cnt; ++i) - { + for (int i = 0; i < cnt; ++i) { if (!s[i].isString()) { _create_json_ret(buf, TPE_PARAM); return; } } - EXLOGV("[core] kill %d sessions.\n", cnt); - - ex_astr ss = s.toStyledString(); - - g_tpp_mgr.kill_sessions(ss); + EXLOGV("[core] try to kill %d sessions.\n", cnt); + ex_astr sp = s.toStyledString(); + g_tpp_mgr.kill_sessions(sp); _create_json_ret(buf, TPE_OK); } - void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf) { // https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#enc @@ -474,33 +468,30 @@ void TsHttpRpc::_rpc_func_set_config(const Json::Value& json_param, ex_astr& buf } */ - if (json_param.isArray()) - { + if (json_param.isArray()) { _create_json_ret(buf, TPE_PARAM); return; } - if (json_param["noop_timeout"].isNull() || !json_param["noop_timeout"].isUInt()) - { + if (json_param["noop_timeout"].isNull() || !json_param["noop_timeout"].isUInt()) { _create_json_ret(buf, TPE_PARAM); return; } - int noop_timeout = json_param["noop_timeout"].asUInt(); - if (noop_timeout == 0) - { - _create_json_ret(buf, TPE_PARAM); - return; - } +// int noop_timeout = json_param["noop_timeout"].asUInt(); +// if (noop_timeout == 0) { +// _create_json_ret(buf, TPE_PARAM); +// return; +// } +// +// //static TppManager g_tpp_mgr; +// EXLOGV("[core] no-op timeout set to %d minutes.\n", noop_timeout); +// g_tpp_mgr.set_config(noop_timeout * 60); // 内部按秒计,因此要 *60 - //static TppManager g_tpp_mgr; - EXLOGV("[core] no-op timeout set to %d minutes.\n", noop_timeout); - g_tpp_mgr.set_config(noop_timeout * 60); // 内部按秒计,因此要 *60 + EXLOGV("[core] set run-time config.\n"); + ex_astr sp = json_param.toStyledString(); + g_tpp_mgr.set_runtime_config(sp); - -// Json::Value jr_data; -// jr_data["c"] = cipher_text; -// _create_json_ret(buf, TPE_OK, jr_data); _create_json_ret(buf, TPE_OK); }