Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
54cd817f
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看板
提交
54cd817f
编写于
2月 19, 2020
作者:
陶建辉(Jeff)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix many bugs
上级
e9470f0a
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
306 addition
and
291 deletion
+306
-291
src/rpc/inc/tconncache.h
src/rpc/inc/tconncache.h
+4
-4
src/rpc/src/tconncache.c
src/rpc/src/tconncache.c
+87
-87
src/rpc/src/trpc.c
src/rpc/src/trpc.c
+198
-194
src/rpc/test/rclient.c
src/rpc/test/rclient.c
+9
-3
src/rpc/test/rserver.c
src/rpc/test/rserver.c
+7
-2
src/util/src/tglobalcfg.c
src/util/src/tglobalcfg.c
+1
-1
未找到文件。
src/rpc/inc/tconncache.h
浏览文件 @
54cd817f
...
...
@@ -20,10 +20,10 @@
extern
"C"
{
#endif
void
*
taos
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
);
void
taos
CloseConnCache
(
void
*
handle
);
void
taos
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
void
*
taos
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
void
*
rpc
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
);
void
rpc
CloseConnCache
(
void
*
handle
);
void
rpc
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
void
*
rpc
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
);
#ifdef __cplusplus
}
...
...
src/rpc/src/tconncache.c
浏览文件 @
54cd817f
...
...
@@ -40,13 +40,13 @@ typedef struct {
int
*
count
;
int64_t
keepTimer
;
pthread_mutex_t
mutex
;
void
(
*
cleanFp
)(
void
*
);
void
*
tmrCtrl
;
void
*
pTimer
;
void
(
*
cleanFp
)(
void
*
);
void
*
tmrCtrl
;
void
*
pTimer
;
}
SConnCache
;
int
taos
HashConn
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
SConnCache
*
p
Obj
=
(
SConnCache
*
)
handle
;
int
rpc
HashConn
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
SConnCache
*
p
Cache
=
(
SConnCache
*
)
handle
;
int
hash
=
0
;
// size_t user_len = strlen(user);
...
...
@@ -58,109 +58,109 @@ int taosHashConn(void *handle, uint32_t ip, uint16_t port, char *user) {
user
++
;
}
hash
=
hash
%
p
Obj
->
maxSessions
;
hash
=
hash
%
p
Cache
->
maxSessions
;
return
hash
;
}
void
taosRemoveExpiredNodes
(
SConnCache
*
pObj
,
SConnHash
*
pNode
,
int
hash
,
uint64_t
time
)
{
if
(
time
<
pObj
->
keepTimer
+
pNode
->
time
)
return
;
void
rpcRemoveExpiredNodes
(
SConnCache
*
pCache
,
SConnHash
*
pNode
,
int
hash
,
uint64_t
time
)
{
if
(
pNode
==
NULL
||
(
time
<
pCache
->
keepTimer
+
pNode
->
time
)
)
return
;
SConnHash
*
pPrev
=
pNode
->
prev
,
*
pNext
;
while
(
pNode
)
{
(
*
p
Obj
->
cleanFp
)(
pNode
->
data
);
(
*
p
Cache
->
cleanFp
)(
pNode
->
data
);
pNext
=
pNode
->
next
;
p
Obj
->
total
--
;
p
Obj
->
count
[
hash
]
--
;
t
sc
Trace
(
"%p ip:0x%x:%hu:%d:%p removed, connections in cache:%d"
,
pNode
->
data
,
pNode
->
ip
,
pNode
->
port
,
hash
,
pNode
,
p
Obj
->
count
[
hash
]);
taosMemPoolFree
(
p
Obj
->
connHashMemPool
,
(
char
*
)
pNode
);
p
Cache
->
total
--
;
p
Cache
->
count
[
hash
]
--
;
tTrace
(
"%p ip:0x%x:%hu:%d:%p removed, connections in cache:%d"
,
pNode
->
data
,
pNode
->
ip
,
pNode
->
port
,
hash
,
pNode
,
p
Cache
->
count
[
hash
]);
taosMemPoolFree
(
p
Cache
->
connHashMemPool
,
(
char
*
)
pNode
);
pNode
=
pNext
;
}
if
(
pPrev
)
pPrev
->
next
=
NULL
;
else
p
Obj
->
connHashList
[
hash
]
=
NULL
;
p
Cache
->
connHashList
[
hash
]
=
NULL
;
}
void
taos
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
void
rpc
AddConnIntoCache
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
int
hash
;
SConnHash
*
pNode
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
uint64_t
time
=
taosGetTimestampMs
();
p
Obj
=
(
SConnCache
*
)
handle
;
assert
(
p
Obj
);
p
Cache
=
(
SConnCache
*
)
handle
;
assert
(
p
Cache
);
assert
(
data
);
hash
=
taosHashConn
(
pObj
,
ip
,
port
,
user
);
pNode
=
(
SConnHash
*
)
taosMemPoolMalloc
(
p
Obj
->
connHashMemPool
);
hash
=
rpcHashConn
(
pCache
,
ip
,
port
,
user
);
pNode
=
(
SConnHash
*
)
taosMemPoolMalloc
(
p
Cache
->
connHashMemPool
);
pNode
->
ip
=
ip
;
pNode
->
port
=
port
;
pNode
->
data
=
data
;
pNode
->
prev
=
NULL
;
pNode
->
time
=
time
;
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
pNode
->
next
=
p
Obj
->
connHashList
[
hash
];
if
(
p
Obj
->
connHashList
[
hash
]
!=
NULL
)
(
pObj
->
connHashList
[
hash
])
->
prev
=
pNode
;
p
Obj
->
connHashList
[
hash
]
=
pNode
;
pNode
->
next
=
p
Cache
->
connHashList
[
hash
];
if
(
p
Cache
->
connHashList
[
hash
]
!=
NULL
)
(
pCache
->
connHashList
[
hash
])
->
prev
=
pNode
;
p
Cache
->
connHashList
[
hash
]
=
pNode
;
p
Obj
->
total
++
;
p
Obj
->
count
[
hash
]
++
;
taosRemoveExpiredNodes
(
pObj
,
pNode
->
next
,
hash
,
time
);
p
Cache
->
total
++
;
p
Cache
->
count
[
hash
]
++
;
rpcRemoveExpiredNodes
(
pCache
,
pNode
->
next
,
hash
,
time
);
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
t
scTrace
(
"%p ip:0x%x:%hu:%d:%p added, connections in cache:%d"
,
data
,
ip
,
port
,
hash
,
pNode
,
pObj
->
count
[
hash
]);
t
Trace
(
"%p ip:0x%x:%hu:%d:%p added, connections in cache:%d"
,
data
,
ip
,
port
,
hash
,
pNode
,
pCache
->
count
[
hash
]);
return
;
}
void
taos
CleanConnCache
(
void
*
handle
,
void
*
tmrId
)
{
void
rpc
CleanConnCache
(
void
*
handle
,
void
*
tmrId
)
{
int
hash
;
SConnHash
*
pNode
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
p
Obj
=
(
SConnCache
*
)
handle
;
if
(
p
Obj
==
NULL
||
pObj
->
maxSessions
==
0
)
return
;
if
(
p
Obj
->
pTimer
!=
tmrId
)
return
;
p
Cache
=
(
SConnCache
*
)
handle
;
if
(
p
Cache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
if
(
p
Cache
->
pTimer
!=
tmrId
)
return
;
uint64_t
time
=
taosGetTimestampMs
();
for
(
hash
=
0
;
hash
<
p
Obj
->
maxSessions
;
++
hash
)
{
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
pNode
=
p
Obj
->
connHashList
[
hash
];
taosRemoveExpiredNodes
(
pObj
,
pNode
,
hash
,
time
);
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
for
(
hash
=
0
;
hash
<
p
Cache
->
maxSessions
;
++
hash
)
{
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
pNode
=
p
Cache
->
connHashList
[
hash
];
rpcRemoveExpiredNodes
(
pCache
,
pNode
,
hash
,
time
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
}
// t
scTrace("timer, total connections in cache:%d", pObj
->total);
taosTmrReset
(
taosCleanConnCache
,
pObj
->
keepTimer
*
2
,
pObj
,
pObj
->
tmrCtrl
,
&
pObj
->
pTimer
);
// t
Trace("timer, total connections in cache:%d", pCache
->total);
taosTmrReset
(
rpcCleanConnCache
,
pCache
->
keepTimer
*
2
,
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
}
void
*
taos
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
void
*
rpc
GetConnFromCache
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
,
char
*
user
)
{
int
hash
;
SConnHash
*
pNode
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
void
*
pData
=
NULL
;
p
Obj
=
(
SConnCache
*
)
handle
;
assert
(
p
Obj
);
p
Cache
=
(
SConnCache
*
)
handle
;
assert
(
p
Cache
);
uint64_t
time
=
taosGetTimestampMs
();
hash
=
taosHashConn
(
pObj
,
ip
,
port
,
user
);
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
hash
=
rpcHashConn
(
pCache
,
ip
,
port
,
user
);
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
pNode
=
p
Obj
->
connHashList
[
hash
];
pNode
=
p
Cache
->
connHashList
[
hash
];
while
(
pNode
)
{
if
(
time
>=
p
Obj
->
keepTimer
+
pNode
->
time
)
{
taosRemoveExpiredNodes
(
pObj
,
pNode
,
hash
,
time
);
if
(
time
>=
p
Cache
->
keepTimer
+
pNode
->
time
)
{
rpcRemoveExpiredNodes
(
pCache
,
pNode
,
hash
,
time
);
pNode
=
NULL
;
break
;
}
...
...
@@ -171,12 +171,12 @@ void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user)
}
if
(
pNode
)
{
taosRemoveExpiredNodes
(
pObj
,
pNode
->
next
,
hash
,
time
);
rpcRemoveExpiredNodes
(
pCache
,
pNode
->
next
,
hash
,
time
);
if
(
pNode
->
prev
)
{
pNode
->
prev
->
next
=
pNode
->
next
;
}
else
{
p
Obj
->
connHashList
[
hash
]
=
pNode
->
next
;
p
Cache
->
connHashList
[
hash
]
=
pNode
->
next
;
}
if
(
pNode
->
next
)
{
...
...
@@ -184,24 +184,24 @@ void *taosGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user)
}
pData
=
pNode
->
data
;
taosMemPoolFree
(
p
Obj
->
connHashMemPool
,
(
char
*
)
pNode
);
p
Obj
->
total
--
;
p
Obj
->
count
[
hash
]
--
;
taosMemPoolFree
(
p
Cache
->
connHashMemPool
,
(
char
*
)
pNode
);
p
Cache
->
total
--
;
p
Cache
->
count
[
hash
]
--
;
}
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
if
(
pData
)
{
t
scTrace
(
"%p ip:0x%x:%hu:%d:%p retrieved, connections in cache:%d"
,
pData
,
ip
,
port
,
hash
,
pNode
,
pObj
->
count
[
hash
]);
t
Trace
(
"%p ip:0x%x:%hu:%d:%p retrieved, connections in cache:%d"
,
pData
,
ip
,
port
,
hash
,
pNode
,
pCache
->
count
[
hash
]);
}
return
pData
;
}
void
*
taos
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
)
{
void
*
rpc
OpenConnCache
(
int
maxSessions
,
void
(
*
cleanFp
)(
void
*
),
void
*
tmrCtrl
,
int64_t
keepTimer
)
{
SConnHash
**
connHashList
;
mpool_h
connHashMemPool
;
SConnCache
*
p
Obj
;
SConnCache
*
p
Cache
;
connHashMemPool
=
taosMemPoolInit
(
maxSessions
,
sizeof
(
SConnHash
));
if
(
connHashMemPool
==
0
)
return
NULL
;
...
...
@@ -212,48 +212,48 @@ void *taosOpenConnCache(int maxSessions, void (*cleanFp)(void *), void *tmrCtrl,
return
NULL
;
}
p
Obj
=
malloc
(
sizeof
(
SConnCache
));
if
(
p
Obj
==
NULL
)
{
p
Cache
=
malloc
(
sizeof
(
SConnCache
));
if
(
p
Cache
==
NULL
)
{
taosMemPoolCleanUp
(
connHashMemPool
);
free
(
connHashList
);
return
NULL
;
}
memset
(
p
Obj
,
0
,
sizeof
(
SConnCache
));
memset
(
p
Cache
,
0
,
sizeof
(
SConnCache
));
p
Obj
->
count
=
calloc
(
sizeof
(
int
),
maxSessions
);
p
Obj
->
total
=
0
;
p
Obj
->
keepTimer
=
keepTimer
;
p
Obj
->
maxSessions
=
maxSessions
;
p
Obj
->
connHashMemPool
=
connHashMemPool
;
p
Obj
->
connHashList
=
connHashList
;
p
Obj
->
cleanFp
=
cleanFp
;
p
Obj
->
tmrCtrl
=
tmrCtrl
;
taosTmrReset
(
taosCleanConnCache
,
pObj
->
keepTimer
*
2
,
pObj
,
pObj
->
tmrCtrl
,
&
pObj
->
pTimer
);
p
Cache
->
count
=
calloc
(
sizeof
(
int
),
maxSessions
);
p
Cache
->
total
=
0
;
p
Cache
->
keepTimer
=
keepTimer
;
p
Cache
->
maxSessions
=
maxSessions
;
p
Cache
->
connHashMemPool
=
connHashMemPool
;
p
Cache
->
connHashList
=
connHashList
;
p
Cache
->
cleanFp
=
cleanFp
;
p
Cache
->
tmrCtrl
=
tmrCtrl
;
taosTmrReset
(
rpcCleanConnCache
,
pCache
->
keepTimer
*
2
,
pCache
,
pCache
->
tmrCtrl
,
&
pCache
->
pTimer
);
pthread_mutex_init
(
&
p
Obj
->
mutex
,
NULL
);
pthread_mutex_init
(
&
p
Cache
->
mutex
,
NULL
);
return
p
Obj
;
return
p
Cache
;
}
void
taos
CloseConnCache
(
void
*
handle
)
{
SConnCache
*
p
Obj
;
void
rpc
CloseConnCache
(
void
*
handle
)
{
SConnCache
*
p
Cache
;
p
Obj
=
(
SConnCache
*
)
handle
;
if
(
p
Obj
==
NULL
||
pObj
->
maxSessions
==
0
)
return
;
p
Cache
=
(
SConnCache
*
)
handle
;
if
(
p
Cache
==
NULL
||
pCache
->
maxSessions
==
0
)
return
;
pthread_mutex_lock
(
&
p
Obj
->
mutex
);
pthread_mutex_lock
(
&
p
Cache
->
mutex
);
taosTmrStopA
(
&
(
p
Obj
->
pTimer
));
taosTmrStopA
(
&
(
p
Cache
->
pTimer
));
if
(
p
Obj
->
connHashMemPool
)
taosMemPoolCleanUp
(
pObj
->
connHashMemPool
);
if
(
p
Cache
->
connHashMemPool
)
taosMemPoolCleanUp
(
pCache
->
connHashMemPool
);
tfree
(
p
Obj
->
connHashList
);
tfree
(
p
Obj
->
count
)
tfree
(
p
Cache
->
connHashList
);
tfree
(
p
Cache
->
count
)
pthread_mutex_unlock
(
&
p
Obj
->
mutex
);
pthread_mutex_unlock
(
&
p
Cache
->
mutex
);
pthread_mutex_destroy
(
&
p
Obj
->
mutex
);
pthread_mutex_destroy
(
&
p
Cache
->
mutex
);
memset
(
p
Obj
,
0
,
sizeof
(
SConnCache
));
free
(
p
Obj
);
memset
(
p
Cache
,
0
,
sizeof
(
SConnCache
));
free
(
p
Cache
);
}
src/rpc/src/trpc.c
浏览文件 @
54cd817f
...
...
@@ -32,11 +32,11 @@
#include "trpc.h"
#include "taoserror.h"
#define RPC_MSG_OVERHEAD (sizeof(SRpcReqContext) + sizeof(SRpcHead
er
) + sizeof(SRpcDigest))
#define rpcHead
erFromCont(cont) ((SRpcHeader *) (cont - sizeof(SRpcHeader
)))
#define rpcContFromHead
er(msg) (msg + sizeof(SRpcHeader
))
#define rpcMsgLenFromCont(contLen) (contLen + sizeof(SRpcHead
er
))
#define rpcContLenFromMsg(msgLen) (msgLen - sizeof(SRpcHead
er
))
#define RPC_MSG_OVERHEAD (sizeof(SRpcReqContext) + sizeof(SRpcHead) + sizeof(SRpcDigest))
#define rpcHead
FromCont(cont) ((SRpcHead *) (cont - sizeof(SRpcHead
)))
#define rpcContFromHead
(msg) (msg + sizeof(SRpcHead
))
#define rpcMsgLenFromCont(contLen) (contLen + sizeof(SRpcHead))
#define rpcContLenFromMsg(msgLen) (msgLen - sizeof(SRpcHead))
#define rpcIsReq(type) (type & 1U)
typedef
struct
{
...
...
@@ -48,11 +48,11 @@ typedef struct {
int
connType
;
char
label
[
12
];
char
*
meterId
;
// meter ID
char
meterId
[
TSDB_UNI_LEN
];
// meter ID
char
spi
;
// security parameter index
char
encrypt
;
// encrypt algorithm
char
*
secret
;
// key for authentication
char
*
ckey
;
// ciphering key
uint8_t
secret
[
TSDB_KEY_LEN
];
// secret for the link
uint8_t
ckey
[
TSDB_KEY_LEN
];
// ciphering key
void
(
*
cfp
)(
char
type
,
void
*
pCont
,
int
contLen
,
void
*
ahandle
,
int32_t
code
);
int
(
*
afp
)(
char
*
meterId
,
char
*
spi
,
char
*
encrypt
,
uint8_t
*
secret
,
uint8_t
*
ckey
);
...
...
@@ -78,7 +78,7 @@ typedef struct {
int16_t
numOfTry
;
// number of try for different servers
int8_t
oldIndex
;
// server IP index passed by app
int8_t
redirect
;
// flag to indicate redirect
char
msg
[
0
];
// RpcHead
er
starts from here
char
msg
[
0
];
// RpcHead starts from here
}
SRpcReqContext
;
typedef
struct
_RpcConn
{
...
...
@@ -114,6 +114,8 @@ typedef struct _RpcConn {
SRpcReqContext
*
pContext
;
// request context
}
SRpcConn
;
#pragma pack(push, 1)
typedef
struct
{
char
version
:
4
;
// RPC version
char
comp
:
4
;
// compression algorithm, 0:no compression 1:lz4
...
...
@@ -131,7 +133,7 @@ typedef struct {
int32_t
msgLen
;
// message length including the header iteslf
int32_t
code
;
uint8_t
content
[
0
];
// message body starts from here
}
SRpcHead
er
;
}
SRpcHead
;
typedef
struct
{
int32_t
reserved
;
...
...
@@ -143,6 +145,8 @@ typedef struct {
uint8_t
auth
[
TSDB_AUTH_LEN
];
}
SRpcDigest
;
#pragma pack(pop)
int
tsRpcProgressTime
=
10
;
// milliseocnds
// not configurable
...
...
@@ -197,7 +201,7 @@ static void rpcSendErrorMsgToPeer(SRpcInfo *pRpc, char *pMsg, int32_t code, uin
static
void
rpcSendMsgToPeer
(
SRpcConn
*
pConn
,
void
*
data
,
int
dataLen
);
static
void
*
rpcProcessMsgFromPeer
(
void
*
data
,
int
dataLen
,
uint32_t
ip
,
uint16_t
port
,
void
*
shandle
,
void
*
chandle
);
static
void
rpcProcessIncomingMsg
(
SRpcConn
*
pConn
,
SRpcHead
er
*
pHeader
);
static
void
rpcProcessIncomingMsg
(
SRpcConn
*
pConn
,
SRpcHead
*
pHead
);
static
void
rpcProcessConnError
(
void
*
param
,
void
*
id
);
static
void
rpcProcessRetryTimer
(
void
*
,
void
*
);
static
void
rpcProcessIdleTimer
(
void
*
param
,
void
*
tmrId
);
...
...
@@ -205,7 +209,7 @@ static void rpcProcessProgressTimer(void *param, void *tmrId);
static
void
rpcFreeOutMsg
(
void
*
msg
);
static
int32_t
rpcCompressRpcMsg
(
char
*
pCont
,
int32_t
contLen
);
static
SRpcHead
er
*
rpcDecompressRpcMsg
(
SRpcHeader
*
pHeader
);
static
SRpcHead
*
rpcDecompressRpcMsg
(
SRpcHead
*
pHead
);
static
int
rpcAddAuthPart
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
);
static
int
rpcCheckAuthentication
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
);
...
...
@@ -218,7 +222,7 @@ void *rpcOpen(SRpcInit *pInit) {
pRpc
=
(
SRpcInfo
*
)
calloc
(
1
,
sizeof
(
SRpcInfo
));
if
(
pRpc
==
NULL
)
return
NULL
;
strcpy
(
pRpc
->
label
,
pInit
->
label
);
if
(
pInit
->
label
)
strcpy
(
pRpc
->
label
,
pInit
->
label
);
pRpc
->
connType
=
pInit
->
connType
;
pRpc
->
idleTime
=
pInit
->
idleTime
;
pRpc
->
numOfThreads
=
pInit
->
numOfThreads
;
...
...
@@ -226,14 +230,14 @@ void *rpcOpen(SRpcInit *pInit) {
pRpc
->
numOfThreads
=
TSDB_MAX_RPC_THREADS
;
}
strcpy
(
pRpc
->
localIp
,
pInit
->
localIp
);
if
(
pInit
->
localIp
)
strcpy
(
pRpc
->
localIp
,
pInit
->
localIp
);
pRpc
->
localPort
=
pInit
->
localPort
;
pRpc
->
afp
=
pInit
->
afp
;
pRpc
->
sessions
=
pInit
->
sessions
;
strcpy
(
pRpc
->
meterId
,
pInit
->
meterId
);
if
(
pInit
->
meterId
)
strcpy
(
pRpc
->
meterId
,
pInit
->
meterId
);
if
(
pInit
->
secret
)
strcpy
(
pRpc
->
secret
,
pInit
->
secret
);
if
(
pInit
->
ckey
)
strcpy
(
pRpc
->
ckey
,
pInit
->
ckey
);
pRpc
->
spi
=
pInit
->
spi
;
strcpy
(
pRpc
->
secret
,
pInit
->
secret
);
strcpy
(
pRpc
->
ckey
,
pInit
->
ckey
);
pRpc
->
ufp
=
pInit
->
ufp
;
pRpc
->
cfp
=
pInit
->
cfp
;
pRpc
->
afp
=
pInit
->
afp
;
...
...
@@ -275,7 +279,7 @@ void *rpcOpen(SRpcInit *pInit) {
return
NULL
;
}
pRpc
->
pCache
=
taos
OpenConnCache
(
pRpc
->
sessions
,
rpcCloseConn
,
pRpc
->
tmrCtrl
,
tsShellActivityTimer
*
1000
);
pRpc
->
pCache
=
rpc
OpenConnCache
(
pRpc
->
sessions
,
rpcCloseConn
,
pRpc
->
tmrCtrl
,
tsShellActivityTimer
*
1000
);
if
(
pRpc
->
pCache
==
NULL
)
{
tError
(
"%s failed to init connection cache"
,
pRpc
->
label
);
rpcClose
(
pRpc
);
...
...
@@ -303,7 +307,7 @@ void rpcClose(void *param) {
taosCleanUpStrHash
(
pRpc
->
hash
);
taosTmrCleanUp
(
pRpc
->
tmrCtrl
);
taosIdPoolCleanUp
(
pRpc
->
idPool
);
taos
CloseConnCache
(
pRpc
->
pCache
);
rpc
CloseConnCache
(
pRpc
->
pCache
);
tfree
(
pRpc
->
connList
);
pthread_mutex_destroy
(
&
pRpc
->
mutex
);
...
...
@@ -320,11 +324,11 @@ void *rpcMallocCont(int size) {
return
NULL
;
}
return
pMsg
+
sizeof
(
SRpcReqContext
)
+
sizeof
(
SRpcHead
er
);
return
pMsg
+
sizeof
(
SRpcReqContext
)
+
sizeof
(
SRpcHead
);
}
void
rpcFreeCont
(
void
*
cont
)
{
char
*
msg
=
((
char
*
)
cont
)
-
sizeof
(
SRpcHead
er
);
char
*
msg
=
((
char
*
)
cont
)
-
sizeof
(
SRpcHead
);
free
(
msg
);
}
...
...
@@ -333,7 +337,7 @@ void rpcSendRequest(void *shandle, SRpcIpSet ipSet, char type, void *pCont, int
SRpcReqContext
*
pContext
;
contLen
=
rpcCompressRpcMsg
(
pCont
,
contLen
);
pContext
=
(
SRpcReqContext
*
)
(
pCont
-
sizeof
(
SRpcHead
er
)
-
sizeof
(
SRpcReqContext
));
pContext
=
(
SRpcReqContext
*
)
(
pCont
-
sizeof
(
SRpcHead
)
-
sizeof
(
SRpcReqContext
));
pContext
->
ahandle
=
ahandle
;
pContext
->
pRpc
=
(
SRpcInfo
*
)
shandle
;
pContext
->
ipSet
=
ipSet
;
...
...
@@ -348,11 +352,11 @@ void rpcSendRequest(void *shandle, SRpcIpSet ipSet, char type, void *pCont, int
}
void
rpcSendResponse
(
void
*
handle
,
int32_t
code
,
void
*
pCont
,
int
contLen
)
{
int
msgLen
=
0
;
SRpcConn
*
pConn
=
(
SRpcConn
*
)
handle
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
SRpcHead
er
*
pHeader
=
rpcHeader
FromCont
(
pCont
);
char
*
msg
=
(
char
*
)
pHeader
;
int
msgLen
=
0
;
SRpcConn
*
pConn
=
(
SRpcConn
*
)
handle
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
SRpcHead
*
pHead
=
rpcHead
FromCont
(
pCont
);
char
*
msg
=
(
char
*
)
pHead
;
if
(
pCont
==
NULL
)
{
pCont
=
rpcMallocCont
(
0
);
...
...
@@ -371,17 +375,17 @@ void rpcSendResponse(void *handle, int32_t code, void *pCont, int contLen) {
}
// set msg header
pHead
er
->
version
=
1
;
pHead
er
->
msgType
=
pConn
->
inType
+
1
;
pHead
er
->
spi
=
0
;
pHead
er
->
tcp
=
0
;
pHead
er
->
encrypt
=
0
;
pHead
er
->
tranId
=
pConn
->
inTranId
;
pHead
er
->
sourceId
=
pConn
->
ownId
;
pHead
er
->
destId
=
pConn
->
peerId
;
pHead
er
->
uid
=
0
;
pHead
er
->
code
=
htonl
(
code
);
memcpy
(
pHead
er
->
meterId
,
pConn
->
meterId
,
tListLen
(
pHeader
->
meterId
));
pHead
->
version
=
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
spi
=
0
;
pHead
->
tcp
=
0
;
pHead
->
encrypt
=
0
;
pHead
->
tranId
=
pConn
->
inTranId
;
pHead
->
sourceId
=
pConn
->
ownId
;
pHead
->
destId
=
pConn
->
peerId
;
pHead
->
uid
=
0
;
pHead
->
code
=
htonl
(
code
);
memcpy
(
pHead
->
meterId
,
pConn
->
meterId
,
tListLen
(
pHead
->
meterId
));
// set pConn parameters
pConn
->
inType
=
0
;
...
...
@@ -390,7 +394,7 @@ void rpcSendResponse(void *handle, int32_t code, void *pCont, int contLen) {
rpcFreeOutMsg
(
pConn
->
pRspMsg
);
pConn
->
pRspMsg
=
msg
;
pConn
->
rspMsgLen
=
msgLen
;
if
(
pHead
er
->
content
[
0
]
==
TSDB_CODE_ACTION_IN_PROGRESS
)
pConn
->
inTranId
--
;
if
(
pHead
->
content
[
0
]
==
TSDB_CODE_ACTION_IN_PROGRESS
)
pConn
->
inTranId
--
;
pthread_mutex_unlock
(
&
pRpc
->
mutex
);
...
...
@@ -487,7 +491,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) {
tError
(
"%s maximum number of sessions:%d is reached"
,
pRpc
->
label
,
pRpc
->
sessions
);
terrno
=
TSDB_CODE_MAX_SESSIONS
;
}
else
{
tTrace
(
"%s sid:%d, ID allocated, used:%d
, old id:%d
"
,
pRpc
->
label
,
sid
,
taosIdPoolNumOfUsed
(
pRpc
->
idPool
));
tTrace
(
"%s sid:%d, ID allocated, used:%d"
,
pRpc
->
label
,
sid
,
taosIdPoolNumOfUsed
(
pRpc
->
idPool
));
pConn
=
pRpc
->
connList
+
sid
;
memset
(
pConn
,
0
,
sizeof
(
SRpcConn
));
...
...
@@ -562,7 +566,7 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, char *meterId, char *has
SRpcConn
*
rpcSetConnToServer
(
SRpcInfo
*
pRpc
,
SRpcIpSet
ipSet
)
{
SRpcConn
*
pConn
;
pConn
=
taos
GetConnFromCache
(
pRpc
->
pCache
,
ipSet
.
ip
[
ipSet
.
index
],
ipSet
.
port
,
pRpc
->
meterId
);
pConn
=
rpc
GetConnFromCache
(
pRpc
->
pCache
,
ipSet
.
ip
[
ipSet
.
index
],
ipSet
.
port
,
pRpc
->
meterId
);
if
(
pConn
==
NULL
)
{
char
ipstr
[
20
]
=
{
0
};
tinet_ntoa
(
ipstr
,
ipSet
.
ip
[
ipSet
.
index
]);
...
...
@@ -572,29 +576,29 @@ SRpcConn *rpcSetConnToServer(SRpcInfo *pRpc, SRpcIpSet ipSet) {
return
pConn
;
}
static
int
rpcProcessReqHead
er
(
SRpcConn
*
pConn
,
SRpcHeader
*
pHeader
)
{
static
int
rpcProcessReqHead
(
SRpcConn
*
pConn
,
SRpcHead
*
pHead
)
{
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
if
(
pConn
->
peerId
==
0
)
{
pConn
->
peerId
=
pHead
er
->
sourceId
;
pConn
->
peerId
=
pHead
->
sourceId
;
}
else
{
if
(
pConn
->
peerId
!=
pHead
er
->
sourceId
)
{
if
(
pConn
->
peerId
!=
pHead
->
sourceId
)
{
tTrace
(
"%s pConn:%p, source Id is changed, old:0x%08x new:0x%08x"
,
pRpc
->
label
,
pConn
,
pConn
->
peerId
,
pHead
er
->
sourceId
);
pConn
->
peerId
,
pHead
->
sourceId
);
return
TSDB_CODE_INVALID_VALUE
;
}
}
if
(
pConn
->
inTranId
==
pHead
er
->
tranId
)
{
if
(
pConn
->
inType
==
pHead
er
->
msgType
)
{
tTrace
(
"%s pConn:%p, %s is retransmitted"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
er
->
msgType
]);
if
(
pConn
->
inTranId
==
pHead
->
tranId
)
{
if
(
pConn
->
inType
==
pHead
->
msgType
)
{
tTrace
(
"%s pConn:%p, %s is retransmitted"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
]);
rpcSendQuickRsp
(
pConn
,
TSDB_CODE_ACTION_IN_PROGRESS
);
}
else
if
(
pConn
->
inType
==
0
)
{
tTrace
(
"%s pConn:%p, %s is already processed, tranId:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
er
->
msgType
],
pConn
->
inTranId
);
taosMsg
[
pHead
->
msgType
],
pConn
->
inTranId
);
rpcSendMsgToPeer
(
pConn
,
pConn
->
pRspMsg
,
pConn
->
rspMsgLen
);
// resend the response
}
else
{
tTrace
(
"%s pConn:%p, mismatched message %s and tranId"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
er
->
msgType
]);
tTrace
(
"%s pConn:%p, mismatched message %s and tranId"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
]);
}
// do not reply any message
...
...
@@ -603,40 +607,40 @@ static int rpcProcessReqHeader(SRpcConn *pConn, SRpcHeader *pHeader) {
if
(
pConn
->
inType
!=
0
)
{
tTrace
(
"%s pConn:%p, last session is not finished, inTranId:%d tranId:%d"
,
pRpc
->
label
,
pConn
,
pConn
->
inTranId
,
pHead
er
->
tranId
);
pConn
->
inTranId
,
pHead
->
tranId
);
return
TSDB_CODE_LAST_SESSION_NOT_FINISHED
;
}
pConn
->
inTranId
=
pHead
er
->
tranId
;
pConn
->
inType
=
pHead
er
->
msgType
;
pConn
->
inTranId
=
pHead
->
tranId
;
pConn
->
inType
=
pHead
->
msgType
;
return
0
;
}
static
int
rpcProcessRspHead
er
(
SRpcConn
*
pConn
,
SRpcHeader
*
pHeader
)
{
static
int
rpcProcessRspHead
(
SRpcConn
*
pConn
,
SRpcHead
*
pHead
)
{
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
pConn
->
peerId
=
pHead
er
->
sourceId
;
pConn
->
peerId
=
pHead
->
sourceId
;
if
(
pConn
->
outType
==
0
||
pConn
->
pContext
==
NULL
)
{
return
TSDB_CODE_UNEXPECTED_RESPONSE
;
}
if
(
pHead
er
->
tranId
!=
pConn
->
outTranId
)
{
if
(
pHead
->
tranId
!=
pConn
->
outTranId
)
{
return
TSDB_CODE_INVALID_TRAN_ID
;
}
if
(
pHead
er
->
msgType
!=
pConn
->
outType
+
1
)
{
if
(
pHead
->
msgType
!=
pConn
->
outType
+
1
)
{
return
TSDB_CODE_INVALID_RESPONSE_TYPE
;
}
if
(
*
pHead
er
->
content
==
TSDB_CODE_NOT_READY
)
{
if
(
*
pHead
->
content
==
TSDB_CODE_NOT_READY
)
{
return
TSDB_CODE_ALREADY_PROCESSED
;
}
taosTmrStopA
(
&
pConn
->
pTimer
);
pConn
->
retry
=
0
;
if
(
*
pHead
er
->
content
==
TSDB_CODE_ACTION_IN_PROGRESS
||
pHeader
->
tcp
)
{
if
(
*
pHead
->
content
==
TSDB_CODE_ACTION_IN_PROGRESS
||
pHead
->
tcp
)
{
if
(
pConn
->
tretry
<=
tsRpcMaxRetry
)
{
pConn
->
tretry
++
;
tTrace
(
"%s pConn:%p, peer is still processing the transaction"
,
pRpc
->
label
,
pConn
);
...
...
@@ -644,7 +648,7 @@ static int rpcProcessRspHeader(SRpcConn *pConn, SRpcHeader *pHeader) {
return
TSDB_CODE_ALREADY_PROCESSED
;
}
else
{
// peer still in processing, give up
*
pHead
er
->
content
=
TSDB_CODE_TOO_SLOW
;
*
pHead
->
content
=
TSDB_CODE_TOO_SLOW
;
}
}
...
...
@@ -656,77 +660,77 @@ static int rpcProcessRspHeader(SRpcConn *pConn, SRpcHeader *pHeader) {
return
TSDB_CODE_SUCCESS
;
}
static
int
rpcProcessHead
er
(
SRpcInfo
*
pRpc
,
SRpcConn
**
ppConn
,
void
*
data
,
int
dataLen
,
uint32_t
ip
)
{
static
int
rpcProcessHead
(
SRpcInfo
*
pRpc
,
SRpcConn
**
ppConn
,
void
*
data
,
int
dataLen
,
uint32_t
ip
)
{
int32_t
sid
,
code
=
0
;
SRpcConn
*
pConn
=
NULL
;
char
hashstr
[
40
]
=
{
0
};
*
ppConn
=
NULL
;
SRpcHead
er
*
pHeader
=
(
SRpcHeader
*
)
data
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
data
;
sid
=
htonl
(
pHead
er
->
destId
);
pHead
er
->
code
=
htonl
(
pHeader
->
code
);
pHead
er
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHeader
->
msgLen
);
sid
=
htonl
(
pHead
->
destId
);
pHead
->
code
=
htonl
(
pHead
->
code
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
->
msgLen
);
if
(
pHead
er
->
msgType
>=
TSDB_MSG_TYPE_MAX
||
pHeader
->
msgType
<=
0
)
{
tTrace
(
"%s sid:%d, invalid message type:%d"
,
pRpc
->
label
,
sid
,
pHead
er
->
msgType
);
if
(
pHead
->
msgType
>=
TSDB_MSG_TYPE_MAX
||
pHead
->
msgType
<=
0
)
{
tTrace
(
"%s sid:%d, invalid message type:%d"
,
pRpc
->
label
,
sid
,
pHead
->
msgType
);
return
TSDB_CODE_INVALID_MSG_TYPE
;
}
if
(
dataLen
!=
pHead
er
->
msgLen
)
{
if
(
dataLen
!=
pHead
->
msgLen
)
{
tTrace
(
"%s sid:%d, %s has invalid length, dataLen:%d, msgLen:%d"
,
pRpc
->
label
,
sid
,
taosMsg
[
pHead
er
->
msgType
],
dataLen
,
pHeader
->
msgLen
);
taosMsg
[
pHead
->
msgType
],
dataLen
,
pHead
->
msgLen
);
return
TSDB_CODE_INVALID_MSG_LEN
;
}
if
(
sid
<
0
||
sid
>=
pRpc
->
sessions
)
{
tTrace
(
"%s sid:%d, sid is out of range, max sid:%d, %s discarded"
,
pRpc
->
label
,
sid
,
pRpc
->
sessions
,
taosMsg
[
pHead
er
->
msgType
]);
pRpc
->
sessions
,
taosMsg
[
pHead
->
msgType
]);
return
TSDB_CODE_INVALID_SESSION_ID
;
}
if
(
sid
==
0
)
sprintf
(
hashstr
,
"%x:%x:%x"
,
ip
,
pHead
er
->
uid
,
pHeader
->
sourceId
);
pConn
=
rpcGetConnObj
(
pRpc
,
sid
,
pHead
er
->
meterId
,
hashstr
);
if
(
sid
==
0
)
sprintf
(
hashstr
,
"%x:%x:%x"
,
ip
,
pHead
->
uid
,
pHead
->
sourceId
);
pConn
=
rpcGetConnObj
(
pRpc
,
sid
,
pHead
->
meterId
,
hashstr
);
if
(
pConn
==
NULL
)
return
terrno
;
*
ppConn
=
pConn
;
sid
=
pConn
->
sid
;
if
(
pHead
er
->
uid
)
pConn
->
peerUid
=
pHeader
->
uid
;
if
(
pHead
->
uid
)
pConn
->
peerUid
=
pHead
->
uid
;
if
(
pHead
er
->
tcp
)
{
if
(
pHead
->
tcp
)
{
tTrace
(
"%s pConn:%p, content will be transfered via TCP"
,
pRpc
->
label
,
pConn
);
if
(
pConn
->
outType
)
taosTmrReset
(
rpcProcessRetryTimer
,
tsRpcTimer
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
return
TSDB_CODE_ALREADY_PROCESSED
;
}
code
=
rpcCheckAuthentication
(
pConn
,
(
char
*
)
pHead
er
,
dataLen
);
code
=
rpcCheckAuthentication
(
pConn
,
(
char
*
)
pHead
,
dataLen
);
if
(
code
!=
0
)
return
code
;
if
(
pHead
er
->
msgType
!=
TSDB_MSG_TYPE_REG
&&
pHeader
->
encrypt
)
{
if
(
pHead
->
msgType
!=
TSDB_MSG_TYPE_REG
&&
pHead
->
encrypt
)
{
// decrypt here
}
if
(
rpcIsReq
(
pHead
er
->
msgType
)
)
{
code
=
rpcProcessReqHead
er
(
pConn
,
pHeader
);
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
code
=
rpcProcessReqHead
(
pConn
,
pHead
);
}
else
{
code
=
rpcProcessRspHead
er
(
pConn
,
pHeader
);
code
=
rpcProcessRspHead
(
pConn
,
pHead
);
}
return
code
;
}
static
void
*
rpcProcessMsgFromPeer
(
void
*
data
,
int
dataLen
,
uint32_t
ip
,
uint16_t
port
,
void
*
shandle
,
void
*
chandle
)
{
SRpcHead
er
*
pHeader
=
(
SRpcHeader
*
)
data
;
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
shandle
;
SRpcConn
*
pConn
=
NULL
;
uint8_t
code
=
0
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
data
;
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
shandle
;
SRpcConn
*
pConn
=
NULL
;
uint8_t
code
=
0
;
tDump
(
data
,
dataLen
);
pthread_mutex_lock
(
&
pRpc
->
mutex
);
code
=
rpcProcessHead
er
(
pRpc
,
&
pConn
,
data
,
dataLen
,
ip
);
code
=
rpcProcessHead
(
pRpc
,
&
pConn
,
data
,
dataLen
,
ip
);
if
(
pConn
)
{
// update connection info
...
...
@@ -739,16 +743,16 @@ static void *rpcProcessMsgFromPeer(void *data, int dataLen, uint32_t ip, uint16_
}
if
(
port
)
pConn
->
peerPort
=
port
;
if
(
pHead
er
->
port
)
// port maybe changed by the peer
pConn
->
peerPort
=
pHead
er
->
port
;
if
(
pHead
->
port
)
// port maybe changed by the peer
pConn
->
peerPort
=
pHead
->
port
;
}
pthread_mutex_unlock
(
&
pRpc
->
mutex
);
if
(
pHead
er
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
{
if
(
pHead
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
{
tTrace
(
"%s pConn:%p, %s received from 0x%x:%hu, parse code:%u len:%d source:0x%08x dest:0x%08x tranId:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
er
->
msgType
],
ip
,
port
,
code
,
dataLen
,
pHead
er
->
sourceId
,
pHeader
->
destId
,
pHeader
->
tranId
);
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
ip
,
port
,
code
,
dataLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
if
(
pConn
&&
pRpc
->
idleTime
)
{
...
...
@@ -757,12 +761,12 @@ static void *rpcProcessMsgFromPeer(void *data, int dataLen, uint32_t ip, uint16_
if
(
code
!=
TSDB_CODE_ALREADY_PROCESSED
)
{
if
(
code
!=
0
)
{
// parsing error
if
(
rpcIsReq
(
pHead
er
->
msgType
)
)
{
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
rpcSendErrorMsgToPeer
(
pRpc
,
data
,
code
,
ip
,
port
,
chandle
);
tTrace
(
"%s pConn:%p, %s is sent with error code:%u"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
er
->
msgType
+
1
],
code
);
tTrace
(
"%s pConn:%p, %s is sent with error code:%u"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
+
1
],
code
);
}
}
else
{
// parsing OK
rpcProcessIncomingMsg
(
pConn
,
pHead
er
);
rpcProcessIncomingMsg
(
pConn
,
pHead
);
}
}
...
...
@@ -770,100 +774,100 @@ static void *rpcProcessMsgFromPeer(void *data, int dataLen, uint32_t ip, uint16_
return
pConn
;
}
static
void
rpcProcessIncomingMsg
(
SRpcConn
*
pConn
,
SRpcHead
er
*
pHeader
)
{
static
void
rpcProcessIncomingMsg
(
SRpcConn
*
pConn
,
SRpcHead
*
pHead
)
{
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
pHead
er
=
rpcDecompressRpcMsg
(
pHeader
);
int
contLen
=
rpcContLenFromMsg
(
pHead
er
->
msgLen
);
uint8_t
*
pCont
=
pHead
er
->
content
;
pHead
=
rpcDecompressRpcMsg
(
pHead
);
int
contLen
=
rpcContLenFromMsg
(
pHead
->
msgLen
);
uint8_t
*
pCont
=
pHead
->
content
;
if
(
rpcIsReq
(
pHead
er
->
msgType
)
)
{
if
(
rpcIsReq
(
pHead
->
msgType
)
)
{
taosTmrReset
(
rpcProcessProgressTimer
,
tsRpcTimer
/
2
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
(
*
(
pRpc
->
cfp
))(
pHead
er
->
msgType
,
pCont
,
contLen
,
pConn
,
0
);
(
*
(
pRpc
->
cfp
))(
pHead
->
msgType
,
pCont
,
contLen
,
pConn
,
0
);
}
else
{
// it's a response
int32_t
code
=
pHead
er
->
code
;
int32_t
code
=
pHead
->
code
;
SRpcReqContext
*
pContext
=
pConn
->
pContext
;
pConn
->
pContext
=
NULL
;
taos
AddConnIntoCache
(
pRpc
->
pCache
,
pConn
,
pConn
->
peerIp
,
pConn
->
peerPort
,
pConn
->
meterId
);
rpc
AddConnIntoCache
(
pRpc
->
pCache
,
pConn
,
pConn
->
peerIp
,
pConn
->
peerPort
,
pConn
->
meterId
);
if
(
code
==
TSDB_CODE_REDIRECT
)
{
pContext
->
redirect
=
1
;
pContext
->
numOfTry
=
0
;
memcpy
(
&
pContext
->
ipSet
,
pHead
er
->
content
,
sizeof
(
pContext
->
ipSet
));
memcpy
(
&
pContext
->
ipSet
,
pHead
->
content
,
sizeof
(
pContext
->
ipSet
));
rpcSendReqToServer
(
pRpc
,
pContext
);
}
else
{
rpcFreeOutMsg
(
rpcHead
er
FromCont
(
pContext
->
pCont
));
// free the request msg
rpcFreeOutMsg
(
rpcHeadFromCont
(
pContext
->
pCont
));
// free the request msg
if
(
pContext
->
ipSet
.
index
!=
pContext
->
oldIndex
||
pContext
->
redirect
)
(
*
pRpc
->
ufp
)(
pContext
->
ahandle
,
pContext
->
ipSet
);
(
*
pRpc
->
cfp
)(
pHead
er
->
msgType
,
pCont
,
contLen
,
pContext
->
ahandle
,
pContext
->
ipSet
.
index
);
(
*
pRpc
->
cfp
)(
pHead
->
msgType
,
pCont
,
contLen
,
pContext
->
ahandle
,
pContext
->
ipSet
.
index
);
}
}
}
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
char
code
)
{
char
msg
[
RPC_MSG_OVERHEAD
];
SRpcHead
er
*
pHeader
;
char
msg
[
RPC_MSG_OVERHEAD
];
SRpcHead
*
pHead
;
// set msg header
memset
(
msg
,
0
,
sizeof
(
SRpcHead
er
));
pHead
er
=
(
SRpcHeader
*
)
msg
;
pHead
er
->
version
=
1
;
pHead
er
->
msgType
=
pConn
->
inType
+
1
;
pHead
er
->
spi
=
0
;
pHead
er
->
tcp
=
0
;
pHead
er
->
encrypt
=
0
;
pHead
er
->
tranId
=
pConn
->
inTranId
;
pHead
er
->
sourceId
=
pConn
->
ownId
;
pHead
er
->
destId
=
pConn
->
peerId
;
pHead
er
->
uid
=
0
;
memcpy
(
pHead
er
->
meterId
,
pConn
->
meterId
,
tListLen
(
pHeader
->
meterId
));
pHead
er
->
code
=
htonl
(
code
);
memset
(
msg
,
0
,
sizeof
(
SRpcHead
));
pHead
=
(
SRpcHead
*
)
msg
;
pHead
->
version
=
1
;
pHead
->
msgType
=
pConn
->
inType
+
1
;
pHead
->
spi
=
0
;
pHead
->
tcp
=
0
;
pHead
->
encrypt
=
0
;
pHead
->
tranId
=
pConn
->
inTranId
;
pHead
->
sourceId
=
pConn
->
ownId
;
pHead
->
destId
=
pConn
->
peerId
;
pHead
->
uid
=
0
;
memcpy
(
pHead
->
meterId
,
pConn
->
meterId
,
tListLen
(
pHead
->
meterId
));
pHead
->
code
=
htonl
(
code
);
rpcSendMsgToPeer
(
pConn
,
msg
,
0
);
}
static
void
rpcSendErrorMsgToPeer
(
SRpcInfo
*
pRpc
,
char
*
pMsg
,
int32_t
code
,
uint32_t
ip
,
uint16_t
port
,
void
*
chandle
)
{
SRpcHead
er
*
pRecvHeader
,
*
pReplyHeader
;
char
msg
[
sizeof
(
SRpcHeader
)
+
sizeof
(
SRpcDigest
)
+
sizeof
(
uint32_t
)
];
SRpcHead
*
pRecvHead
,
*
pReplyHead
;
char
msg
[
sizeof
(
SRpcHead
)
+
sizeof
(
SRpcDigest
)
+
sizeof
(
uint32_t
)
];
uint32_t
timeStamp
;
int
msgLen
;
pRecvHead
er
=
(
SRpcHeader
*
)
pMsg
;
pReplyHead
er
=
(
SRpcHeader
*
)
msg
;
pRecvHead
=
(
SRpcHead
*
)
pMsg
;
pReplyHead
=
(
SRpcHead
*
)
msg
;
memset
(
msg
,
0
,
sizeof
(
SRpcHead
er
));
pReplyHead
er
->
version
=
pRecvHeader
->
version
;
pReplyHead
er
->
msgType
=
(
char
)(
pRecvHeader
->
msgType
+
1
);
pReplyHead
er
->
tcp
=
0
;
pReplyHead
er
->
spi
=
0
;
pReplyHead
er
->
encrypt
=
0
;
pReplyHead
er
->
tranId
=
pRecvHeader
->
tranId
;
pReplyHead
er
->
sourceId
=
0
;
pReplyHead
er
->
destId
=
pRecvHeader
->
sourceId
;
memcpy
(
pReplyHead
er
->
meterId
,
pRecvHeader
->
meterId
,
tListLen
(
pReplyHeader
->
meterId
));
memset
(
msg
,
0
,
sizeof
(
SRpcHead
));
pReplyHead
->
version
=
pRecvHead
->
version
;
pReplyHead
->
msgType
=
(
char
)(
pRecvHead
->
msgType
+
1
);
pReplyHead
->
tcp
=
0
;
pReplyHead
->
spi
=
0
;
pReplyHead
->
encrypt
=
0
;
pReplyHead
->
tranId
=
pRecvHead
->
tranId
;
pReplyHead
->
sourceId
=
0
;
pReplyHead
->
destId
=
pRecvHead
->
sourceId
;
memcpy
(
pReplyHead
->
meterId
,
pRecvHead
->
meterId
,
tListLen
(
pReplyHead
->
meterId
));
pReplyHead
er
->
code
=
htonl
(
code
);
msgLen
=
sizeof
(
SRpcHead
er
);
pReplyHead
->
code
=
htonl
(
code
);
msgLen
=
sizeof
(
SRpcHead
);
if
(
code
==
TSDB_CODE_INVALID_TIME_STAMP
)
{
// include a time stamp if client's time is not synchronized well
uint8_t
*
pContent
=
pReplyHead
er
->
content
;
uint8_t
*
pContent
=
pReplyHead
->
content
;
timeStamp
=
taosGetTimestampSec
();
memcpy
(
pContent
,
&
timeStamp
,
sizeof
(
timeStamp
));
msgLen
+=
sizeof
(
timeStamp
);
}
pReplyHead
er
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
pReplyHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
(
*
taosSendData
[
pRpc
->
connType
])(
ip
,
port
,
msg
,
msgLen
,
chandle
);
return
;
}
static
void
rpcSendReqToServer
(
SRpcInfo
*
pRpc
,
SRpcReqContext
*
pContext
)
{
SRpcHead
er
*
pHeader
=
rpcHeader
FromCont
(
pContext
->
pCont
);
char
*
msg
=
(
char
*
)
pHeader
;
int
msgLen
=
rpcMsgLenFromCont
(
pContext
->
contLen
);
char
msgType
=
pContext
->
msgType
;
SRpcHead
*
pHead
=
rpcHead
FromCont
(
pContext
->
pCont
);
char
*
msg
=
(
char
*
)
pHead
;
int
msgLen
=
rpcMsgLenFromCont
(
pContext
->
contLen
);
char
msgType
=
pContext
->
msgType
;
pContext
->
numOfTry
++
;
SRpcConn
*
pConn
=
rpcSetConnToServer
(
pRpc
,
pContext
->
ipSet
);
...
...
@@ -876,22 +880,22 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
pthread_mutex_lock
(
&
pRpc
->
mutex
);
// set the message header
pHead
er
->
version
=
1
;
pHead
er
->
msgType
=
msgType
;
pHead
er
->
tcp
=
0
;
pHead
er
->
encrypt
=
0
;
pHead
->
version
=
1
;
pHead
->
msgType
=
msgType
;
pHead
->
tcp
=
0
;
pHead
->
encrypt
=
0
;
pConn
->
tranId
++
;
if
(
pConn
->
tranId
==
0
)
pConn
->
tranId
++
;
pHead
er
->
tranId
=
pConn
->
tranId
;
pHead
er
->
sourceId
=
pConn
->
ownId
;
pHead
er
->
destId
=
pConn
->
peerId
;
pHead
er
->
port
=
0
;
pHead
er
->
uid
=
(
uint32_t
)((
int64_t
)
pConn
+
(
int64_t
)
getpid
());
memcpy
(
pHead
er
->
meterId
,
pConn
->
meterId
,
tListLen
(
pHeader
->
meterId
));
pHead
->
tranId
=
pConn
->
tranId
;
pHead
->
sourceId
=
pConn
->
ownId
;
pHead
->
destId
=
pConn
->
peerId
;
pHead
->
port
=
0
;
pHead
->
uid
=
(
uint32_t
)((
int64_t
)
pConn
+
(
int64_t
)
getpid
());
memcpy
(
pHead
->
meterId
,
pConn
->
meterId
,
tListLen
(
pHead
->
meterId
));
// set the connection parameters
pConn
->
outType
=
msgType
;
pConn
->
outTranId
=
pHead
er
->
tranId
;
pConn
->
outTranId
=
pHead
->
tranId
;
pConn
->
pReqMsg
=
msg
;
pConn
->
reqMsgLen
=
msgLen
;
pConn
->
pContext
=
pContext
;
...
...
@@ -903,25 +907,25 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
}
static
void
rpcSendMsgToPeer
(
SRpcConn
*
pConn
,
void
*
msg
,
int
msgLen
)
{
int
writtenLen
=
0
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
SRpcHead
er
*
pHeader
=
(
SRpcHeader
*
)
msg
;
int
writtenLen
=
0
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
msgLen
=
rpcAddAuthPart
(
pConn
,
msg
,
msgLen
);
if
(
rpcIsReq
(
pHead
er
->
msgType
))
{
if
(
pHead
er
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
if
(
rpcIsReq
(
pHead
->
msgType
))
{
if
(
pHead
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
tTrace
(
"%s pConn:%p, %s is sent to %s:%hu, len:%d source:0x%08x dest:0x%08x tranId:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
er
->
msgType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
,
msgLen
,
pHead
er
->
sourceId
,
pHeader
->
destId
,
pHeader
->
tranId
);
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
,
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
else
{
if
(
pHead
er
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
if
(
pHead
->
msgType
<
TSDB_MSG_TYPE_HEARTBEAT
||
(
rpcDebugFlag
&
16
))
tTrace
(
"%s pConn:%p, %s is sent to %s:%hu, code:%u len:%d source:0x%08x dest:0x%08x tranId:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
er
->
msgType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
,
(
uint8_t
)
pHead
er
->
content
[
0
],
msgLen
,
pHeader
->
sourceId
,
pHeader
->
destId
,
pHeader
->
tranId
);
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
,
(
uint8_t
)
pHead
->
content
[
0
],
msgLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
writtenLen
=
(
*
taosSendData
[
pRpc
->
connType
])(
pConn
->
peerIp
,
pConn
->
peerPort
,
(
char
*
)
pHead
er
,
msgLen
,
pConn
->
chandle
);
writtenLen
=
(
*
taosSendData
[
pRpc
->
connType
])(
pConn
->
peerIp
,
pConn
->
peerPort
,
(
char
*
)
pHead
,
msgLen
,
pConn
->
chandle
);
if
(
writtenLen
!=
msgLen
)
{
tError
(
"%s pConn:%p, failed to send, dataLen:%d writtenLen:%d, reason:%s"
,
pRpc
->
label
,
pConn
,
...
...
@@ -936,7 +940,7 @@ static void rpcProcessConnError(void *param, void *id) {
SRpcInfo
*
pRpc
=
pContext
->
pRpc
;
if
(
pContext
->
numOfTry
>=
pContext
->
ipSet
.
numOfIps
)
{
rpcFreeOutMsg
(
rpcHead
er
FromCont
(
pContext
->
pCont
));
// free the request msg
rpcFreeOutMsg
(
rpcHeadFromCont
(
pContext
->
pCont
));
// free the request msg
(
*
(
pRpc
->
cfp
))(
pContext
->
msgType
+
1
,
NULL
,
0
,
pContext
->
ahandle
,
pContext
->
code
);
}
else
{
// move to next IP
...
...
@@ -959,7 +963,7 @@ static void rpcProcessRetryTimer(void *param, void *tmrId) {
pConn
->
retry
++
;
if
(
pConn
->
retry
<
4
)
{
tTrace
(
"%s pConn:%p, re-send msg:%s to %s:%hu"
,
pRpc
->
label
,
tTrace
(
"%s pConn:%p, re-send msg:%s to %s:%hu"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pConn
->
outType
],
pConn
->
peerIpstr
,
pConn
->
peerPort
);
rpcSendMsgToPeer
(
pConn
,
pConn
->
pReqMsg
,
pConn
->
reqMsgLen
);
taosTmrReset
(
rpcProcessRetryTimer
,
tsRpcTimer
<<
pConn
->
retry
,
pConn
,
pRpc
->
tmrCtrl
,
&
pConn
->
pTimer
);
...
...
@@ -1018,9 +1022,9 @@ static void rpcFreeOutMsg(void *msg) {
}
static
int32_t
rpcCompressRpcMsg
(
char
*
pCont
,
int32_t
contLen
)
{
SRpcHead
er
*
pHeader
=
rpcHeader
FromCont
(
pCont
);
int32_t
finalLen
=
0
;
int
overhead
=
sizeof
(
SRpcComp
);
SRpcHead
*
pHead
=
rpcHead
FromCont
(
pCont
);
int32_t
finalLen
=
0
;
int
overhead
=
sizeof
(
SRpcComp
);
if
(
!
NEEDTO_COMPRESSS_MSG
(
contLen
))
{
return
contLen
;
...
...
@@ -1044,7 +1048,7 @@ static int32_t rpcCompressRpcMsg(char* pCont, int32_t contLen) {
pComp
->
contLen
=
htonl
(
contLen
);
memcpy
(
pCont
+
overhead
,
buf
,
compLen
);
pHead
er
->
comp
=
1
;
pHead
->
comp
=
1
;
tTrace
(
"compress rpc msg, before:%d, after:%d"
,
contLen
,
compLen
);
finalLen
=
compLen
+
overhead
;
...
...
@@ -1056,13 +1060,13 @@ static int32_t rpcCompressRpcMsg(char* pCont, int32_t contLen) {
return
finalLen
;
}
static
SRpcHead
er
*
rpcDecompressRpcMsg
(
SRpcHeader
*
pHeader
)
{
static
SRpcHead
*
rpcDecompressRpcMsg
(
SRpcHead
*
pHead
)
{
int
overhead
=
sizeof
(
SRpcComp
);
SRpcHead
er
*
pNewHeader
=
NULL
;
uint8_t
*
pCont
=
pHead
er
->
content
;
SRpcComp
*
pComp
=
(
SRpcComp
*
)
pHead
er
->
content
;
SRpcHead
*
pNewHead
=
NULL
;
uint8_t
*
pCont
=
pHead
->
content
;
SRpcComp
*
pComp
=
(
SRpcComp
*
)
pHead
->
content
;
if
(
pHead
er
->
comp
)
{
if
(
pHead
->
comp
)
{
// decompress the content
assert
(
pComp
->
reserved
==
0
);
int
contLen
=
htonl
(
pComp
->
contLen
);
...
...
@@ -1071,21 +1075,21 @@ static SRpcHeader *rpcDecompressRpcMsg(SRpcHeader *pHeader) {
char
*
buf
=
rpcMallocCont
(
contLen
);
if
(
buf
)
{
pNewHead
er
=
rpcHeader
FromCont
(
buf
);
int
compLen
=
rpcContLenFromMsg
(
pHead
er
->
msgLen
)
-
overhead
;
pNewHead
=
rpcHead
FromCont
(
buf
);
int
compLen
=
rpcContLenFromMsg
(
pHead
->
msgLen
)
-
overhead
;
int32_t
originalLen
=
LZ4_decompress_safe
((
const
char
*
)(
pCont
+
overhead
),
buf
,
compLen
,
contLen
);
assert
(
originalLen
==
contLen
);
memcpy
(
pNewHead
er
,
pHeader
,
sizeof
(
SRpcHeader
));
pNewHead
er
->
msgLen
=
rpcMsgLenFromCont
(
originalLen
);
free
(
pHead
er
);
// free the compressed message buffer
pHead
er
=
pNewHeader
;
memcpy
(
pNewHead
,
pHead
,
sizeof
(
SRpcHead
));
pNewHead
->
msgLen
=
rpcMsgLenFromCont
(
originalLen
);
free
(
pHead
);
// free the compressed message buffer
pHead
=
pNewHead
;
}
else
{
tError
(
"failed to allocate memory to decompress msg, contLen:%d, reason:%s"
,
contLen
,
strerror
(
errno
));
}
}
return
pHead
er
;
return
pHead
;
}
static
int
rpcAuthenticateMsg
(
uint8_t
*
pMsg
,
int
msgLen
,
uint8_t
*
pAuth
,
uint8_t
*
pKey
)
{
...
...
@@ -1103,7 +1107,7 @@ static int rpcAuthenticateMsg(uint8_t *pMsg, int msgLen, uint8_t *pAuth, uint8_t
return
ret
;
}
static
int
rpcBuildAuthHead
er
(
uint8_t
*
pMsg
,
int
msgLen
,
uint8_t
*
pAuth
,
uint8_t
*
pKey
)
{
static
int
rpcBuildAuthHead
(
uint8_t
*
pMsg
,
int
msgLen
,
uint8_t
*
pAuth
,
uint8_t
*
pKey
)
{
MD5_CTX
context
;
MD5Init
(
&
context
);
...
...
@@ -1118,33 +1122,33 @@ static int rpcBuildAuthHeader(uint8_t *pMsg, int msgLen, uint8_t *pAuth, uint8_t
}
static
int
rpcAddAuthPart
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
)
{
SRpcHead
er
*
pHeader
=
(
SRpcHeader
*
)
msg
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
if
(
pConn
->
spi
)
{
// add auth part
pHead
er
->
spi
=
pConn
->
spi
;
pHead
->
spi
=
pConn
->
spi
;
SRpcDigest
*
pDigest
=
(
SRpcDigest
*
)(
msg
+
msgLen
);
pDigest
->
timeStamp
=
htonl
(
taosGetTimestampSec
());
msgLen
+=
sizeof
(
SRpcDigest
);
pHead
er
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
rpcBuildAuthHead
er
((
uint8_t
*
)
pHeader
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
rpcBuildAuthHead
((
uint8_t
*
)
pHead
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
);
}
else
{
pHead
er
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
}
return
msgLen
;
}
static
int
rpcCheckAuthentication
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
)
{
SRpcHead
er
*
pHeader
=
(
SRpcHeader
*
)
msg
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
int
code
=
0
;
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
int
code
=
0
;
if
(
pConn
->
spi
==
0
)
return
0
;
if
(
pHead
er
->
spi
==
pConn
->
spi
)
{
if
(
pHead
->
spi
==
pConn
->
spi
)
{
// authentication
SRpcDigest
*
pDigest
=
(
SRpcDigest
*
)((
char
*
)
pHead
er
+
msgLen
-
sizeof
(
SRpcDigest
));
SRpcDigest
*
pDigest
=
(
SRpcDigest
*
)((
char
*
)
pHead
+
msgLen
-
sizeof
(
SRpcDigest
));
int32_t
delta
;
delta
=
(
int32_t
)
htonl
(
pDigest
->
timeStamp
);
...
...
@@ -1154,16 +1158,16 @@ static int rpcCheckAuthentication(SRpcConn *pConn, char *msg, int msgLen) {
delta
,
htonl
(
pDigest
->
timeStamp
));
code
=
TSDB_CODE_INVALID_TIME_STAMP
;
}
else
{
if
(
rpcAuthenticateMsg
((
uint8_t
*
)
pHead
er
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
)
<
0
)
{
if
(
rpcAuthenticateMsg
((
uint8_t
*
)
pHead
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
)
<
0
)
{
tError
(
"%s pConn:%p, authentication failed, msg discarded"
,
pRpc
->
label
,
pConn
);
code
=
TSDB_CODE_AUTH_FAILURE
;
}
else
{
pHead
er
->
msgLen
-=
sizeof
(
SRpcDigest
);
pHead
->
msgLen
-=
sizeof
(
SRpcDigest
);
}
}
}
else
{
// if it is request or response with code 0, msg shall be discarded
if
(
rpcIsReq
(
pHead
er
->
msgType
)
||
(
pHeader
->
content
[
0
]
==
0
))
{
if
(
rpcIsReq
(
pHead
->
msgType
)
||
(
pHead
->
content
[
0
]
==
0
))
{
tTrace
(
"%s pConn:%p, auth spi not matched, msg discarded"
,
pRpc
->
label
,
pConn
);
code
=
TSDB_CODE_AUTH_FAILURE
;
}
...
...
src/rpc/test/rclient.c
浏览文件 @
54cd817f
...
...
@@ -24,18 +24,23 @@ void processMsg(char type, void *pCont, int contLen, void *ahandle, int32_t code
}
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
taosInitLog
(
"client.log"
,
100000
,
10
);
dPrint
(
"unit test for rpc module"
);
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localIp
=
"0.0.0.0"
;
rpcInit
.
localPort
=
700
0
;
rpcInit
.
label
=
"
unittest
"
;
rpcInit
.
localPort
=
0
;
rpcInit
.
label
=
"
APP
"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
sessions
=
1000
;
rpcInit
.
connType
=
TAOS_CONN_UDPC
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
meterId
=
"jefftao"
;
rpcInit
.
secret
=
"password"
;
rpcInit
.
ckey
=
"key"
;
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
if
(
pRpc
==
NULL
)
{
...
...
@@ -46,6 +51,7 @@ int32_t main(int32_t argc, char *argv[]) {
SRpcIpSet
ipSet
;
ipSet
.
numOfIps
=
2
;
ipSet
.
index
=
0
;
ipSet
.
port
=
7000
;
ipSet
.
ip
[
0
]
=
inet_addr
(
"127.0.0.1"
);
ipSet
.
ip
[
1
]
=
inet_addr
(
"192.168.0.1"
);
...
...
src/rpc/test/rserver.c
浏览文件 @
54cd817f
...
...
@@ -27,18 +27,23 @@ void processMsg(char type, void *pCont, int contLen, void *ahandle, int32_t code
}
int32_t
main
(
int32_t
argc
,
char
*
argv
[])
{
taosInitLog
(
"server.log"
,
100000
,
10
);
dPrint
(
"unit test for rpc module"
);
SRpcInit
rpcInit
;
memset
(
&
rpcInit
,
0
,
sizeof
(
rpcInit
));
rpcInit
.
localIp
=
"0.0.0.0"
;
rpcInit
.
localPort
=
7000
;
rpcInit
.
label
=
"
unittest
"
;
rpcInit
.
label
=
"
APP
"
;
rpcInit
.
numOfThreads
=
1
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
cfp
=
processMsg
;
rpcInit
.
sessions
=
1000
;
rpcInit
.
connType
=
TAOS_CONN_UDPS
;
rpcInit
.
idleTime
=
2000
;
rpcInit
.
meterId
=
"jefftao"
;
rpcInit
.
secret
=
"password"
;
rpcInit
.
ckey
=
"key"
;
void
*
pRpc
=
rpcOpen
(
&
rpcInit
);
if
(
pRpc
==
NULL
)
{
...
...
src/util/src/tglobalcfg.c
浏览文件 @
54cd817f
...
...
@@ -209,7 +209,7 @@ char tsLocale[TSDB_LOCALE_LEN] = {0};
char
tsCharset
[
TSDB_LOCALE_LEN
]
=
{
0
};
// default encode string
int
tsNumOfLogLines
=
10000000
;
uint32_t
rpcDebugFlag
=
13
1
;
uint32_t
rpcDebugFlag
=
13
5
;
uint32_t
ddebugFlag
=
131
;
uint32_t
mdebugFlag
=
135
;
uint32_t
sdbDebugFlag
=
135
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录