Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
ba72317f
提交
ba72317f
authored
10月 31, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
feature: reverse debug tunnel
上级
7eab710a
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
68 行增加
和
59 行删除
+68
-59
evdaemon.cpp
opencv-motion-detect/evdaemon.cpp
+7
-2
reverse_tun.hpp
opencv-motion-detect/reverse_tun.hpp
+61
-57
没有找到文件。
opencv-motion-detect/evdaemon.cpp
浏览文件 @
ba72317f
...
@@ -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
;
...
...
opencv-motion-detect/reverse_tun.hpp
浏览文件 @
ba72317f
...
@@ -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,75 +210,79 @@ int createReverseTun(string host, int port, string user, string _password, threa
...
@@ -211,75 +210,79 @@ 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
)
{
FD_ZERO
(
&
fds
);
if
(
hasError
)
{
FD_SET
(
forwardsock
,
&
fds
);
break
;
tv
.
tv_sec
=
0
;
}
tv
.
tv_usec
=
100000
;
FD_ZERO
(
&
fds
);
rc
=
select
(
forwardsock
+
1
,
&
fds
,
nullptr
,
nullptr
,
&
tv
);
FD_SET
(
forwardsock
,
&
fds
);
if
(
-
1
==
rc
)
{
tv
.
tv_sec
=
0
;
spdlog
::
error
(
"tun failed to select"
);
tv
.
tv_usec
=
100000
;
rc
=
select
(
forwardsock
+
1
,
&
fds
,
nullptr
,
nullptr
,
&
tv
);
if
(
-
1
==
rc
)
{
spdlog
::
error
(
"tun failed to select"
);
break
;
}
if
(
rc
&&
FD_ISSET
(
forwardsock
,
&
fds
))
{
len
=
recv
(
forwardsock
,
buf
,
sizeof
(
buf
),
0
);
if
(
len
<
0
)
{
spdlog
::
error
(
"tun failed to read"
);
break
;
break
;
}
}
else
if
(
0
==
len
)
{
if
(
rc
&&
FD_ISSET
(
forwardsock
,
&
fds
))
{
spdlog
::
info
(
"tun the local server at {}:{} disconnected!
\n
"
,
len
=
recv
(
forwardsock
,
buf
,
sizeof
(
buf
),
0
);
local_destip
,
local_destport
);
if
(
len
<
0
)
{
break
;
spdlog
::
error
(
"tun failed to read"
);
}
break
;
wr
=
0
;
}
do
{
else
if
(
0
==
len
)
{
i
=
libssh2_channel_write
(
channel
,
buf
,
len
);
spdlog
::
info
(
"tun the local server at {}:{} disconnected!
\n
"
,
if
(
i
<
0
)
{
local_destip
,
local_destport
);
spdlog
::
error
(
"tun failed to libssh2_channel_write: {}"
,
i
);
hasError
=
true
;
break
;
break
;
}
}
wr
=
0
;
wr
+=
i
;
do
{
i
=
libssh2_channel_write
(
channel
,
buf
,
len
);
if
(
i
<
0
)
{
spdlog
::
error
(
"tun failed to libssh2_channel_write: {}"
,
i
);
hasError
=
true
;
break
;
}
wr
+=
i
;
}
while
(
i
>
0
&&
wr
<
len
);
}
}
while
(
i
>
0
&&
wr
<
len
);
}
while
(
1
)
{
while
(
1
)
{
len
=
libssh2_channel_read
(
channel
,
buf
,
sizeof
(
buf
));
len
=
libssh2_channel_read
(
channel
,
buf
,
sizeof
(
buf
));
if
(
LIBSSH2_ERROR_EAGAIN
==
len
)
if
(
LIBSSH2_ERROR_EAGAIN
==
len
)
break
;
break
;
else
if
(
len
<
0
)
{
else
if
(
len
<
0
)
{
spdlog
::
error
(
"tun failed libssh2_channel_read: {}"
,
(
int
)
len
);
spdlog
::
error
(
"tun failed libssh2_channel_read: {}"
,
(
int
)
len
);
hasError
=
true
;
break
;
}
wr
=
0
;
while
(
wr
<
len
)
{
i
=
send
(
forwardsock
,
buf
+
wr
,
len
-
wr
,
0
);
if
(
i
<=
0
)
{
spdlog
::
error
(
"tun failed to reverse write"
);
hasError
=
true
;
hasError
=
true
;
break
;
break
;
}
}
wr
=
0
;
wr
+=
i
;
while
(
wr
<
len
)
{
}
i
=
send
(
forwardsock
,
buf
+
wr
,
len
-
wr
,
0
);
if
(
i
<=
0
)
{
spdlog
::
error
(
"tun failed to reverse write"
);
hasError
=
true
;
break
;
}
wr
+=
i
;
}
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
);
break
;
hasError
=
true
;
}
break
;
}
}
}
}
}
closeFun
();
closeFun
();
});
return
remote_listenport
;
return
0
;
//
remote_listenport;
}
}
#endif
#endif
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论