Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
c3130c7f
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
c3130c7f
编写于
3月 01, 2020
作者:
陶建辉(Jeff)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
optimize the authentication part
上级
ac893cff
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
20 addition
and
13 deletion
+20
-13
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+15
-9
src/rpc/test/rclient.c
src/rpc/test/rclient.c
+4
-3
src/rpc/test/rserver.c
src/rpc/test/rserver.c
+1
-1
未找到文件。
src/rpc/src/rpcMain.c
浏览文件 @
c3130c7f
...
@@ -94,6 +94,7 @@ typedef struct _RpcConn {
...
@@ -94,6 +94,7 @@ typedef struct _RpcConn {
char
encrypt
;
// encryption, 0:1
char
encrypt
;
// encryption, 0:1
char
secret
[
TSDB_KEY_LEN
];
// secret for the link
char
secret
[
TSDB_KEY_LEN
];
// secret for the link
char
ckey
[
TSDB_KEY_LEN
];
// ciphering key
char
ckey
[
TSDB_KEY_LEN
];
// ciphering key
char
secured
;
// if set to 1, no authentication
uint16_t
localPort
;
// for UDP only
uint16_t
localPort
;
// for UDP only
uint32_t
peerUid
;
// peer UID
uint32_t
peerUid
;
// peer UID
uint32_t
peerIp
;
// peer IP
uint32_t
peerIp
;
// peer IP
...
@@ -264,7 +265,7 @@ void *rpcOpen(SRpcInit *pInit) {
...
@@ -264,7 +265,7 @@ void *rpcOpen(SRpcInit *pInit) {
return
NULL
;
return
NULL
;
}
}
}
else
{
}
else
{
pRpc
->
pCache
=
rpcOpenConnCache
(
pRpc
->
sessions
,
rpcCloseConn
,
pRpc
->
tmrCtrl
,
tsShellActivityTimer
*
1000
);
pRpc
->
pCache
=
rpcOpenConnCache
(
pRpc
->
sessions
,
rpcCloseConn
,
pRpc
->
tmrCtrl
,
pRpc
->
idleTime
);
if
(
pRpc
->
pCache
==
NULL
)
{
if
(
pRpc
->
pCache
==
NULL
)
{
tError
(
"%s failed to init connection cache"
,
pRpc
->
label
);
tError
(
"%s failed to init connection cache"
,
pRpc
->
label
);
rpcClose
(
pRpc
);
rpcClose
(
pRpc
);
...
@@ -417,6 +418,7 @@ void rpcSendResponse(void *handle, int32_t code, void *pCont, int contLen) {
...
@@ -417,6 +418,7 @@ void rpcSendResponse(void *handle, int32_t code, void *pCont, int contLen) {
taosTmrStopA
(
&
pConn
->
pTimer
);
taosTmrStopA
(
&
pConn
->
pTimer
);
rpcSendMsgToPeer
(
pConn
,
msg
,
msgLen
);
rpcSendMsgToPeer
(
pConn
,
msg
,
msgLen
);
pConn
->
secured
=
1
;
// connection shall be secured
return
;
return
;
}
}
...
@@ -811,7 +813,8 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
...
@@ -811,7 +813,8 @@ static void *rpcProcessMsgFromPeer(SRecvInfo *pRecv) {
pRecv
->
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
,
pHead
->
port
);
pRecv
->
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
,
pHead
->
port
);
}
}
if
(
pConn
&&
pRpc
->
idleTime
)
{
if
(
pRpc
->
connType
==
TAOS_CONN_SERVER
&&
pConn
&&
pRpc
->
idleTime
)
{
// only for server, starts the idle timer. For client, it is started by cache mgmt
taosTmrReset
(
rpcProcessIdleTimer
,
pRpc
->
idleTime
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pIdleTimer
);
taosTmrReset
(
rpcProcessIdleTimer
,
pRpc
->
idleTime
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pIdleTimer
);
}
}
...
@@ -1023,8 +1026,8 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) {
...
@@ -1023,8 +1026,8 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) {
pConn
->
retry
++
;
pConn
->
retry
++
;
if
(
pConn
->
retry
<
4
)
{
if
(
pConn
->
retry
<
4
)
{
tTrace
(
"%s %p, re-send msg:%s to %s:%hu
retry:%
d"
,
pRpc
->
label
,
pConn
,
tTrace
(
"%s %p, re-send msg:%s to %s:%hud"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pConn
->
outType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
,
pConn
->
retry
);
taosMsg
[
pConn
->
outType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
);
rpcSendMsgToPeer
(
pConn
,
pConn
->
pReqMsg
,
pConn
->
reqMsgLen
);
rpcSendMsgToPeer
(
pConn
,
pConn
->
pReqMsg
,
pConn
->
reqMsgLen
);
taosTmrReset
(
rpcProcessRetryTimer
,
tsRpcTimer
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
taosTmrReset
(
rpcProcessRetryTimer
,
tsRpcTimer
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
}
else
{
}
else
{
...
@@ -1176,7 +1179,7 @@ static void rpcBuildAuthHead(void *pMsg, int msgLen, void *pAuth, void *pKey) {
...
@@ -1176,7 +1179,7 @@ static void rpcBuildAuthHead(void *pMsg, int msgLen, void *pAuth, void *pKey) {
static
int
rpcAddAuthPart
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
)
{
static
int
rpcAddAuthPart
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
)
{
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
if
(
pConn
->
spi
)
{
if
(
pConn
->
spi
&&
pConn
->
secured
==
0
)
{
// add auth part
// add auth part
pHead
->
spi
=
pConn
->
spi
;
pHead
->
spi
=
pConn
->
spi
;
SRpcDigest
*
pDigest
=
(
SRpcDigest
*
)(
msg
+
msgLen
);
SRpcDigest
*
pDigest
=
(
SRpcDigest
*
)(
msg
+
msgLen
);
...
@@ -1185,6 +1188,7 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen) {
...
@@ -1185,6 +1188,7 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen) {
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
rpcBuildAuthHead
(
pHead
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
);
rpcBuildAuthHead
(
pHead
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
);
}
else
{
}
else
{
pHead
->
spi
=
0
;
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
}
}
...
@@ -1194,9 +1198,10 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen) {
...
@@ -1194,9 +1198,10 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen) {
static
int
rpcCheckAuthentication
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
)
{
static
int
rpcCheckAuthentication
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
)
{
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
int
32_t
code
=
0
;
int
code
=
0
;
if
(
pConn
->
spi
==
0
)
{
if
((
pConn
->
secured
&&
pHead
->
spi
==
0
)
||
(
pHead
->
spi
==
0
&&
pConn
->
spi
==
0
)){
// secured link, or no authentication
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
->
msgLen
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
->
msgLen
);
return
0
;
return
0
;
}
}
...
@@ -1211,7 +1216,6 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
...
@@ -1211,7 +1216,6 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
}
}
code
=
0
;
code
=
0
;
if
(
pHead
->
spi
==
pConn
->
spi
)
{
if
(
pHead
->
spi
==
pConn
->
spi
)
{
// authentication
// authentication
SRpcDigest
*
pDigest
=
(
SRpcDigest
*
)((
char
*
)
pHead
+
msgLen
-
sizeof
(
SRpcDigest
));
SRpcDigest
*
pDigest
=
(
SRpcDigest
*
)((
char
*
)
pHead
+
msgLen
-
sizeof
(
SRpcDigest
));
...
@@ -1228,6 +1232,8 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
...
@@ -1228,6 +1232,8 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
code
=
TSDB_CODE_AUTH_FAILURE
;
code
=
TSDB_CODE_AUTH_FAILURE
;
}
else
{
}
else
{
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
->
msgLen
)
-
sizeof
(
SRpcDigest
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
->
msgLen
)
-
sizeof
(
SRpcDigest
);
if
(
!
rpcIsReq
(
pHead
->
msgType
)
)
pConn
->
secured
=
1
;
// link is secured for client
tTrace
(
"%s %p, message is authenticated"
,
pRpc
->
label
,
pConn
);
}
}
}
}
}
else
{
}
else
{
...
...
src/rpc/test/rclient.c
浏览文件 @
c3130c7f
...
@@ -106,11 +106,12 @@ int main(int argc, char *argv[]) {
...
@@ -106,11 +106,12 @@ int main(int argc, char *argv[]) {
rpcInit
.
cfp
=
processResponse
;
rpcInit
.
cfp
=
processResponse
;
rpcInit
.
ufp
=
processUpdateIpSet
;
rpcInit
.
ufp
=
processUpdateIpSet
;
rpcInit
.
sessions
=
100
;
rpcInit
.
sessions
=
100
;
rpcInit
.
idleTime
=
2
000
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1
000
;
rpcInit
.
user
=
"michael"
;
rpcInit
.
user
=
"michael"
;
rpcInit
.
secret
=
"mypassword"
;
rpcInit
.
secret
=
"mypassword"
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
ckey
=
"key"
;
rpcInit
.
spi
=
1
;
rpcInit
.
spi
=
1
;
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
i
<
argc
-
1
)
{
if
(
strcmp
(
argv
[
i
],
"-p"
)
==
0
&&
i
<
argc
-
1
)
{
...
@@ -159,8 +160,8 @@ int main(int argc, char *argv[]) {
...
@@ -159,8 +160,8 @@ int main(int argc, char *argv[]) {
}
}
}
}
rpcInit
.
connType
=
TAOS_CONN_CLIENT
;
taosInitLog
(
"client.log"
,
100000
,
10
);
taosInitLog
(
"client.log"
,
100000
,
10
);
tPrint
(
"rpcDebugFlag:%d"
,
rpcDebugFlag
);
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
if
(
pRpc
==
NULL
)
{
if
(
pRpc
==
NULL
)
{
...
@@ -200,7 +201,7 @@ int main(int argc, char *argv[]) {
...
@@ -200,7 +201,7 @@ int main(int argc, char *argv[]) {
tPrint
(
"it takes %.3f mseconds to send %d requests to server"
,
usedTime
,
numOfReqs
*
appThreads
);
tPrint
(
"it takes %.3f mseconds to send %d requests to server"
,
usedTime
,
numOfReqs
*
appThreads
);
tPrint
(
"Performance: %.3f requests per second, msgSize:%d bytes"
,
1000
.
0
*
numOfReqs
*
appThreads
/
usedTime
,
msgSize
);
tPrint
(
"Performance: %.3f requests per second, msgSize:%d bytes"
,
1000
.
0
*
numOfReqs
*
appThreads
/
usedTime
,
msgSize
);
taosCloseLog
();
taosCloseLog
ger
();
return
0
;
return
0
;
}
}
...
...
src/rpc/test/rserver.c
浏览文件 @
c3130c7f
...
@@ -110,7 +110,7 @@ int main(int argc, char *argv[]) {
...
@@ -110,7 +110,7 @@ int main(int argc, char *argv[]) {
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processRequestMsg
;
rpcInit
.
cfp
=
processRequestMsg
;
rpcInit
.
sessions
=
1000
;
rpcInit
.
sessions
=
1000
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
idleTime
=
tsShellActivityTimer
*
1500
;
rpcInit
.
afp
=
retrieveAuthInfo
;
rpcInit
.
afp
=
retrieveAuthInfo
;
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
for
(
int
i
=
1
;
i
<
argc
;
++
i
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录