Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
colorEagleStdio
dataproxy
提交
1dbe5740
dataproxy
项目概览
colorEagleStdio
/
dataproxy
通知
9
Star
6
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
dataproxy
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1dbe5740
编写于
12月 02, 2016
作者:
丁劲犇
😸
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
DNS查找
上级
fa0329aa
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
54 addition
and
19 deletion
+54
-19
proxyobject.cpp
proxyobject.cpp
+52
-18
proxyobject.h
proxyobject.h
+2
-1
未找到文件。
proxyobject.cpp
浏览文件 @
1dbe5740
...
...
@@ -63,10 +63,19 @@ void ProxyObject::initEngine()
else
engine
->
AddListeningAddress
(
keyPrefix
,
QHostAddress
::
Any
,
nInnerPort
,
false
);
m_para_OuterAddress
[
nInnerPort
]
=
strOuterAddress
;
QHostInfo
info
=
QHostInfo
::
fromName
(
strOuterAddress
);
QList
<
QHostAddress
>
lstaddr
=
info
.
addresses
();
if
(
lstaddr
.
size
())
{
QString
outerIP
=
lstaddr
.
first
().
toString
();
stout
<<
strOuterAddress
<<
" IP ="
<<
outerIP
<<
"
\n
"
;
m_para_IPLocalPort
[
outerIP
]
=
nInnerPort
;
m_para_OuterAddress
[
nInnerPort
]
=
outerIP
;
}
//m_para_OuterAddress[nInnerPort] = strOuterAddress;
m_para_OuterPort
[
nInnerPort
]
=
nOuterPort
;
}
engine
->
AddClientTransThreads
(
2
,
false
);
engine
->
AddClientTransThreads
(
4
,
false
);
}
//The socket error message
...
...
@@ -85,10 +94,10 @@ void ProxyObject::slot_NewClientConnected(QObject * clientHandle)
QString
pn
=
sock
->
peerName
();
if
(
pn
.
length
())
{
if
(
m_
Ourter
IPLocalPort
.
contains
(
pn
))
if
(
m_
para_
IPLocalPort
.
contains
(
pn
))
{
qDebug
()
<<
"Outer side "
<<
pn
<<
":"
<<
sock
->
peerPort
()
<<
",Local Port="
<<
sock
->
localPort
()
<<
" Connected"
;
int
nLocalPort
=
m_
Ourter
IPLocalPort
[
pn
];
int
nLocalPort
=
m_
para_
IPLocalPort
[
pn
];
if
(
m_pendingInners
[
nLocalPort
].
size
())
{
QObject
*
innerClient
=
m_pendingInners
[
nLocalPort
].
first
();
...
...
@@ -134,20 +143,7 @@ void ProxyObject::slot_NewClientConnected(QObject * clientHandle)
{
qDebug
()
<<
"Inner side "
<<
sock
->
peerAddress
().
toString
()
<<
":"
<<
sock
->
peerPort
()
<<
",Local Port="
<<
sock
->
localPort
()
<<
" Connected"
;
m_pendingInners
[
localPort
].
push_back
(
clientHandle
);
QHostInfo
info
=
QHostInfo
::
fromName
(
m_para_OuterAddress
[
localPort
]);
QList
<
QHostAddress
>
lstaddr
=
info
.
addresses
();
if
(
lstaddr
.
size
())
{
QString
outerIP
=
lstaddr
.
first
().
toString
();
m_OurterIPLocalPort
[
outerIP
]
=
localPort
;
engine
->
connectTo
(
QHostAddress
(
outerIP
),
m_para_OuterPort
[
localPort
],
false
);
}
else
{
qWarning
()
<<
"Address Not found in DNS."
;
engine
->
KickClients
(
clientHandle
);
}
engine
->
connectTo
(
QHostAddress
(
m_para_OuterAddress
[
localPort
]),
m_para_OuterPort
[
localPort
],
false
);
}
else
{
...
...
@@ -165,6 +161,8 @@ void ProxyObject::slot_ClientDisconnected(QObject * clientHandle)
penging_data
.
remove
(
clientHandle
);
m_hash_Inner2Outer
.
remove
(
clientHandle
);
m_hash_Outer2Inner
.
remove
(
clientHandle
);
foreach
(
int
k
,
m_pendingInners
.
keys
())
m_pendingInners
[
k
].
removeAll
(
clientHandle
);
}
//some data arrival
...
...
@@ -188,6 +186,7 @@ void ProxyObject::timerEvent(QTimerEvent *event)
{
if
(
event
->
timerId
()
==
m_nTimerRefresh
)
{
static
int
counter
=
0
;
fprintf
(
stdout
,
"Send %.2lf MB(%.2lfkbps) Rev %.2lf MB (%.2lfkbps)
\r
"
,
g_bytesRecieved
/
1024.0
/
1024.0
,
g_secRecieved
/
1024.0
*
8
,
...
...
@@ -197,5 +196,40 @@ void ProxyObject::timerEvent(QTimerEvent *event)
g_secRecieved
=
0
;
g_secSent
=
0
;
if
(
++
counter
%
3600
==
0
)
{
killTimer
(
m_nTimerRefresh
);
m_nTimerRefresh
=
-
1
;
QTextStream
stout
(
stdout
,
QIODevice
::
WriteOnly
);
QString
inidfile
=
QCoreApplication
::
applicationFilePath
()
+
".ini"
;
QSettings
settings
(
inidfile
,
QSettings
::
IniFormat
);
int
nPorts
=
settings
.
value
(
"PROXY/Ports"
,
0
).
toInt
();
for
(
int
i
=
0
;
i
<
nPorts
;
++
i
)
{
QString
keyPrefix
=
QString
().
sprintf
(
"PORT%d"
,
i
);
QString
sk
=
keyPrefix
+
"/InnerPort"
;
int
nInnerPort
=
settings
.
value
(
sk
,
0
).
toInt
();
sk
=
keyPrefix
+
"/OuterPort"
;
int
nOuterPort
=
settings
.
value
(
sk
,
0
).
toInt
();
sk
=
keyPrefix
+
"/OuterAddress"
;
QString
strOuterAddress
=
settings
.
value
(
sk
,
""
).
toString
();
QHostInfo
info
=
QHostInfo
::
fromName
(
strOuterAddress
);
QList
<
QHostAddress
>
lstaddr
=
info
.
addresses
();
if
(
lstaddr
.
size
())
{
QString
outerIP
=
lstaddr
.
first
().
toString
();
m_para_IPLocalPort
[
outerIP
]
=
nInnerPort
;
m_para_OuterAddress
[
nInnerPort
]
=
outerIP
;
stout
<<
strOuterAddress
<<
" IP ="
<<
outerIP
<<
"
\n
"
;
}
//m_para_OuterAddress[nInnerPort] = strOuterAddress;
m_para_OuterPort
[
nInnerPort
]
=
nOuterPort
;
}
m_nTimerRefresh
=
startTimer
(
1000
);
}
}
}
proxyobject.h
浏览文件 @
1dbe5740
...
...
@@ -19,6 +19,8 @@ private:
//Ports
QMap
<
int
,
int
>
m_para_OuterPort
;
QMap
<
int
,
QString
>
m_para_OuterAddress
;
QMap
<
QString
,
int
>
m_para_IPLocalPort
;
private:
int
m_nTimerRefresh
=
-
1
;
ZPNetwork
::
zp_net_Engine
*
engine
;
...
...
@@ -26,7 +28,6 @@ private:
QHash
<
QObject
*
,
QObject
*>
m_hash_Inner2Outer
;
QHash
<
QObject
*
,
QObject
*>
m_hash_Outer2Inner
;
QHash
<
QObject
*
,
QList
<
QByteArray
>
>
penging_data
;
QMap
<
QString
,
int
>
m_OurterIPLocalPort
;
public
slots
:
void
slot_Message
(
QObject
*
pSource
,
QString
);
//The socket error message
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录