pull/105/head
Apex Liu 2018-05-04 18:26:26 +08:00
parent 3eb59eb071
commit d78a1824c1
4 changed files with 33 additions and 34 deletions

View File

@ -15,6 +15,7 @@
#endif #endif
#define TPP_CMD_INIT 0x00000000 #define TPP_CMD_INIT 0x00000000
#define TPP_CMD_SET_RUNTIME_CFG 0x00000005
#define TPP_CMD_KILL_SESSIONS 0x00000006 #define TPP_CMD_KILL_SESSIONS 0x00000006
typedef struct TPP_CONNECT_INFO typedef struct TPP_CONNECT_INFO

View File

@ -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(); tpp_libs::iterator it = m_libs.begin();
for (; it != m_libs.end(); ++it) for (; it != m_libs.end(); ++it) {
{ (*it)->command(TPP_CMD_SET_RUNTIME_CFG, sp.c_str());
(*it)->command(TPP_CMD_KILL_SESSIONS, sessions.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());
} }
} }

View File

@ -53,7 +53,8 @@ public:
int count(void) { return m_libs.size(); } int count(void) { return m_libs.size(); }
void set_config(int noop_timeout); 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: private:
tpp_libs m_libs; tpp_libs m_libs;

View File

@ -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); _create_json_ret(buf, TPE_PARAM);
return; 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); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
Json::Value s = json_param["sessions"]; Json::Value s = json_param["sessions"];
int cnt = s.size(); int cnt = s.size();
for (int i = 0; i < cnt; ++i) for (int i = 0; i < cnt; ++i) {
{
if (!s[i].isString()) { if (!s[i].isString()) {
_create_json_ret(buf, TPE_PARAM); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
} }
EXLOGV("[core] kill %d sessions.\n", cnt); EXLOGV("[core] try to kill %d sessions.\n", cnt);
ex_astr sp = s.toStyledString();
ex_astr ss = s.toStyledString(); g_tpp_mgr.kill_sessions(sp);
g_tpp_mgr.kill_sessions(ss);
_create_json_ret(buf, TPE_OK); _create_json_ret(buf, TPE_OK);
} }
void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf) void TsHttpRpc::_rpc_func_enc(const Json::Value& json_param, ex_astr& buf)
{ {
// https://github.com/eomsoft/teleport/wiki/TELEPORT-CORE-JSON-RPC#enc // 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); _create_json_ret(buf, TPE_PARAM);
return; 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); _create_json_ret(buf, TPE_PARAM);
return; return;
} }
int noop_timeout = json_param["noop_timeout"].asUInt(); // int noop_timeout = json_param["noop_timeout"].asUInt();
if (noop_timeout == 0) // if (noop_timeout == 0) {
{ // _create_json_ret(buf, TPE_PARAM);
_create_json_ret(buf, TPE_PARAM); // return;
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] set run-time config.\n");
EXLOGV("[core] no-op timeout set to %d minutes.\n", noop_timeout); ex_astr sp = json_param.toStyledString();
g_tpp_mgr.set_config(noop_timeout * 60); // ÄÚ²¿°´Ãë¼Æ£¬Òò´ËÒª *60 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); _create_json_ret(buf, TPE_OK);
} }