提交 ba72317f authored 作者: blu's avatar blu

feature: reverse debug tunnel

上级 7eab710a
...@@ -547,8 +547,13 @@ private: ...@@ -547,8 +547,13 @@ private:
return -1; return -1;
} }
thread th; thread th;
auto port = createReverseTun(tunCfg["host"], tunCfg["port"], tunCfg["user"], tunCfg["password"], th); string host = tunCfg["host"], user = tunCfg["user"], password = tunCfg["password"];
spdlog::info("evdaemon {} created reverse tun to {}:{}", devSn, tunCfg["host"].get<string>(), port); int port = tunCfg["port"];
th = thread([host, port, user, password](){
createReverseTun(host, port, user, password);
});
spdlog::info("evdaemon {} created reverse tun to {}:{}", devSn, tunCfg["host"].get<string>(), tunCfg["port"].get<int>());
th.detach(); th.detach();
return ret; return ret;
......
...@@ -35,7 +35,7 @@ enum { ...@@ -35,7 +35,7 @@ enum {
}; };
int createReverseTun(string host, int port, string user, string _password, thread &thWorker) int createReverseTun(string host, int port, string user, string _password)
{ {
int remote_listenport = -1; int remote_listenport = -1;
const char *server_ip = host.c_str(); const char *server_ip = host.c_str();
...@@ -56,7 +56,6 @@ int createReverseTun(string host, int port, string user, string _password, threa ...@@ -56,7 +56,6 @@ int createReverseTun(string host, int port, string user, string _password, threa
fd_set fds; fd_set fds;
struct timeval tv; struct timeval tv;
ssize_t len, wr; ssize_t len, wr;
char buf[10240]; // 10K
string msg = "Fingerprint: "; string msg = "Fingerprint: ";
int sock = -1, forwardsock = -1; int sock = -1, forwardsock = -1;
...@@ -211,9 +210,12 @@ int createReverseTun(string host, int port, string user, string _password, threa ...@@ -211,9 +210,12 @@ int createReverseTun(string host, int port, string user, string _password, threa
/* Must use non-blocking IO hereafter due to the current libssh2 API */ /* Must use non-blocking IO hereafter due to the current libssh2 API */
libssh2_session_set_blocking(session, 0); libssh2_session_set_blocking(session, 0);
thWorker = thread([&]() {
bool hasError = false; bool hasError = false;
char buf[10240]; // 10K
while(1) { while(1) {
if(hasError) {
break;
}
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(forwardsock, &fds); FD_SET(forwardsock, &fds);
tv.tv_sec = 0; tv.tv_sec = 0;
...@@ -269,17 +271,18 @@ int createReverseTun(string host, int port, string user, string _password, threa ...@@ -269,17 +271,18 @@ int createReverseTun(string host, int port, string user, string _password, threa
} }
if(libssh2_channel_eof(channel)) { if(libssh2_channel_eof(channel)) {
spdlog::error("tun the remote client at {}:{} disconnected!", spdlog::info("tun the remote client at {}:{} disconnected!",
remote_listenhost, remote_listenport); remote_listenhost, remote_listenport);
hasError = true;
break; break;
} }
} }
} }
closeFun(); closeFun();
});
return remote_listenport;
return 0;//remote_listenport;
} }
#endif #endif
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论