pull/105/head
ApexLiu 2017-10-31 01:09:09 +08:00
parent 65f2d1ceae
commit 2d0ce5da20
5 changed files with 32 additions and 18 deletions

View File

@ -609,7 +609,7 @@ void TsHttpRpc::_rpc_func_run_client(const ex_astr& func_args, ex_astr& buf)
// SSH
//==============================================
if (pro_sub == TP_PROTOCOL_SUB_TYPE_SSH)
if (pro_sub == TP_PROTOCOL_TYPE_SSH_SHELL)
{
char szCmd[1024] = {0};
ex_strformat(szCmd, 1023, "ssh %s@%s -p %d", sid.c_str(), teleport_ip.c_str(), teleport_port);

View File

@ -85,7 +85,6 @@ bool tpp_session_begin(const TPP_CONNECT_INFO* info, int* db_id)
sinfo.conn_port = info->conn_port;
sinfo.protocol_type = info->protocol_type;
sinfo.protocol_sub_type = info->protocol_sub_type;
//sinfo.protocol_flag = info->protocol_flag;
sinfo.auth_type = info->auth_type;
return ts_web_rpc_session_begin(sinfo, *db_id);

View File

@ -8,6 +8,9 @@
typedef struct TS_CONNECT_INFO
{
// TODO:
//TPP_CONNECT_INFO conn;
ex_astr sid;
// 与此连接信息相关的三个要素的ID
@ -36,7 +39,7 @@ typedef struct TS_CONNECT_INFO
ex_u64 ticket_start;// 此连接信息的创建时间(用于超时未使用就销毁的功能)
}TS_CONNECT_INFO;
typedef std::map<ex_astr, TS_CONNECT_INFO*> ts_connections;
typedef std::map<ex_astr, TS_CONNECT_INFO*> ts_connections; // sid -> TS_CONNECT_INFO
class TsSessionManager : public ExThreadBase
{
@ -44,8 +47,21 @@ public:
TsSessionManager();
~TsSessionManager();
// generate a sid for connection info.
bool request_session(ex_astr& sid, TS_CONNECT_INFO* info);
// +ref for connection-info.
bool session_connect(const ex_astr& sid, TPP_CONNECT_INFO** info);
// free connection-info created by session_connect().
bool free_connect_info(TPP_CONNECT_INFO* info);
// -ref for connecton-info, and release it when ref is 0.
bool session_end(const ex_astr& sid);
// TODO:
void timer();
// 根据sid得到session信息
bool get_connect_info(const ex_astr& sid, TS_CONNECT_INFO& info);

View File

@ -25,7 +25,7 @@ SshProxy::~SshProxy()
m_sftp_sessions.clear();
}
bool SshProxy::init(void)
bool SshProxy::init()
{
m_host_ip = g_ssh_env.bind_ip;
m_host_port = g_ssh_env.bind_port;
@ -69,9 +69,8 @@ bool SshProxy::init(void)
return true;
}
void SshProxy::timer(void) {
void SshProxy::timer() {
// be called per one second.
// EXLOGV("[ssh] on-timer.\n");
m_timer_counter++;
if(m_timer_counter < 5)
return;
@ -86,14 +85,14 @@ void SshProxy::timer(void) {
}
}
void SshProxy::_thread_loop(void)
void SshProxy::_thread_loop()
{
EXLOGV("[ssh] TeleportServer-SSH ready on %s:%d\n", m_host_ip.c_str(), m_host_port);
_run();
EXLOGV("[ssh] main-loop end.\n");
}
void SshProxy::_set_stop_flag(void)
void SshProxy::_set_stop_flag()
{
m_stop_flag = true;
@ -108,8 +107,8 @@ void SshProxy::_set_stop_flag(void)
ssh_options_set(_session, SSH_OPTIONS_HOST, host_ip.c_str());
ssh_options_set(_session, SSH_OPTIONS_PORT, &m_host_port);
int _timeout_us = 100000;
ssh_options_set(_session, SSH_OPTIONS_TIMEOUT_USEC, &_timeout_us);
int _timeout_us = 10;
ssh_options_set(_session, SSH_OPTIONS_TIMEOUT, &_timeout_us);
ssh_connect(_session);
ssh_free(_session);
}
@ -117,7 +116,7 @@ void SshProxy::_set_stop_flag(void)
m_thread_mgr.stop_all();
}
void SshProxy::_run(void)
void SshProxy::_run()
{
for (;;)
{
@ -172,7 +171,7 @@ void SshProxy::_run(void)
m_thread_mgr.stop_all();
}
void SshProxy::_dump_sftp_sessions(void)
void SshProxy::_dump_sftp_sessions()
{
ts_sftp_sessions::iterator it = m_sftp_sessions.begin();
for (; it != m_sftp_sessions.end(); ++it)

View File

@ -25,8 +25,8 @@ public:
SshProxy();
~SshProxy();
bool init(void);
void timer(void);
bool init();
void timer();
void add_sftp_session_info(
const ex_astr& sid,
@ -42,13 +42,13 @@ public:
void session_finished(SshSession* sess);
protected:
void _thread_loop(void);
void _set_stop_flag(void);
void _thread_loop();
void _set_stop_flag();
void _run(void);
void _run();
private:
void _dump_sftp_sessions(void);
void _dump_sftp_sessions();
private:
ssh_bind m_bind;