Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
taosdata
TDengine
提交
a2629a02
T
TDengine
项目概览
taosdata
/
TDengine
1 年多 前同步成功
通知
1185
Star
22016
Fork
4786
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
1
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
TDengine
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
1
Issue
1
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
提交
a2629a02
编写于
2月 20, 2020
作者:
陶建辉(Jeff)
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix some bugs, rename files in rpc module
上级
789246a4
变更
16
隐藏空白更改
内联
并排
Showing
16 changed file
with
207 addition
and
224 deletion
+207
-224
src/inc/taosmsg.h
src/inc/taosmsg.h
+0
-31
src/inc/trpc.h
src/inc/trpc.h
+1
-1
src/rpc/inc/rpcCache.h
src/rpc/inc/rpcCache.h
+3
-3
src/rpc/inc/rpcClient.h
src/rpc/inc/rpcClient.h
+2
-2
src/rpc/inc/rpcHaship.h
src/rpc/inc/rpcHaship.h
+5
-5
src/rpc/inc/rpcHead.h
src/rpc/inc/rpcHead.h
+61
-0
src/rpc/inc/rpcServer.h
src/rpc/inc/rpcServer.h
+2
-2
src/rpc/inc/rpcUdp.h
src/rpc/inc/rpcUdp.h
+9
-9
src/rpc/src/rpcCache.c
src/rpc/src/rpcCache.c
+1
-1
src/rpc/src/rpcClient.c
src/rpc/src/rpcClient.c
+5
-4
src/rpc/src/rpcHaship.c
src/rpc/src/rpcHaship.c
+9
-9
src/rpc/src/rpcMain.c
src/rpc/src/rpcMain.c
+27
-58
src/rpc/src/rpcServer.c
src/rpc/src/rpcServer.c
+5
-5
src/rpc/src/rpcUdp.c
src/rpc/src/rpcUdp.c
+77
-42
src/rpc/src/tmsghdr.c
src/rpc/src/tmsghdr.c
+0
-52
src/util/src/tstring.c
src/util/src/tstring.c
+0
-0
未找到文件。
src/inc/taosmsg.h
浏览文件 @
a2629a02
...
...
@@ -199,37 +199,6 @@ typedef struct {
uint32_t
ip
[
TSDB_MAX_MGMT_IPS
];
}
SMgmtIpList
;
typedef
struct
{
char
version
:
4
;
char
comp
:
4
;
char
tcp
:
2
;
char
spi
:
3
;
char
encrypt
:
3
;
uint16_t
tranId
;
uint32_t
uid
;
// for unique ID inside a client
uint32_t
sourceId
;
// internal part
uint32_t
destId
;
uint32_t
destIp
;
char
meterId
[
TSDB_UNI_LEN
];
uint16_t
port
;
// for UDP only
char
empty
[
1
];
uint8_t
msgType
;
int32_t
msgLen
;
uint8_t
content
[
0
];
}
STaosHeader
;
typedef
struct
{
uint32_t
timeStamp
;
uint8_t
auth
[
TSDB_AUTH_LEN
];
}
STaosDigest
;
typedef
struct
{
unsigned
char
code
;
char
more
[];
}
STaosRsp
,
SMsgReply
;
typedef
struct
{
uint32_t
customerId
;
uint32_t
osId
;
...
...
src/inc/trpc.h
浏览文件 @
a2629a02
...
...
@@ -68,7 +68,7 @@ typedef struct {
void
(
*
ufp
)(
void
*
ahandle
,
SRpcIpSet
ipSet
);
// call back to retrieve the client auth info
int
(
*
afp
)(
char
*
meterId
,
char
*
spi
,
char
*
encrypt
,
uint8_t
*
secret
,
uint8_t
*
ckey
);
int
(
*
afp
)(
char
*
meterId
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
}
SRpcInit
;
void
*
rpcOpen
(
SRpcInit
*
pRpc
);
...
...
src/rpc/inc/
tconnc
ache.h
→
src/rpc/inc/
rpcC
ache.h
浏览文件 @
a2629a02
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_
CONN
_CACHE_H
#define TDENGINE_
CONN
_CACHE_H
#ifndef TDENGINE_
RPC
_CACHE_H
#define TDENGINE_
RPC
_CACHE_H
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -29,4 +29,4 @@ void *rpcGetConnFromCache(void *handle, uint32_t ip, uint16_t port, char *user);
}
#endif
#endif // TDENGINE_
CONN
_CACHE_H
#endif // TDENGINE_
RPC
_CACHE_H
src/rpc/inc/
ttcpc
lient.h
→
src/rpc/inc/
rpcC
lient.h
浏览文件 @
a2629a02
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _
taos_tcp
_client_header_
#define _
taos_tcp
_client_header_
#ifndef _
rpc
_client_header_
#define _
rpc
_client_header_
#ifdef __cplusplus
extern
"C"
{
...
...
src/rpc/inc/
th
aship.h
→
src/rpc/inc/
rpcH
aship.h
浏览文件 @
a2629a02
...
...
@@ -20,11 +20,11 @@
extern
"C"
{
#endif
void
*
taos
OpenIpHash
(
int
maxSessions
);
void
taos
CloseIpHash
(
void
*
handle
);
void
*
taos
AddIpHash
(
void
*
handle
,
void
*
pData
,
uint32_t
ip
,
uint16_t
port
);
void
taos
DeleteIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
);
void
*
taos
GetIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
);
void
*
rpc
OpenIpHash
(
int
maxSessions
);
void
rpc
CloseIpHash
(
void
*
handle
);
void
*
rpc
AddIpHash
(
void
*
handle
,
void
*
pData
,
uint32_t
ip
,
uint16_t
port
);
void
rpc
DeleteIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
);
void
*
rpc
GetIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
);
#ifdef __cplusplus
}
...
...
src/rpc/inc/rpcHead.h
0 → 100644
浏览文件 @
a2629a02
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef TDENGINE_RPCHEAD_H
#define TDENGINE_RPCHEAD_H
#ifdef __cplusplus
extern
"C"
{
#endif
#pragma pack(push, 1)
typedef
struct
{
char
version
:
4
;
// RPC version
char
comp
:
4
;
// compression algorithm, 0:no compression 1:lz4
char
tcp
:
2
;
// tcp flag
char
spi
:
3
;
// security parameter index
char
encrypt
:
3
;
// encrypt algorithm, 0: no encryption
uint16_t
tranId
;
// transcation ID
uint32_t
uid
;
// for unique ID inside a client
uint32_t
sourceId
;
// source ID, an index for connection list
uint32_t
destId
;
// destination ID, an index for connection list
char
meterId
[
TSDB_UNI_LEN
];
uint16_t
port
;
// for UDP only, port may be changed
char
empty
[
1
];
// reserved
uint8_t
msgType
;
// message type
int32_t
msgLen
;
// message length including the header iteslf
int32_t
code
;
uint8_t
content
[
0
];
// message body starts from here
}
SRpcHead
;
typedef
struct
{
int32_t
reserved
;
int32_t
contLen
;
}
SRpcComp
;
typedef
struct
{
uint32_t
timeStamp
;
uint8_t
auth
[
TSDB_AUTH_LEN
];
}
SRpcDigest
;
#pragma pack(pop)
#ifdef __cplusplus
}
#endif
#endif // TDENGINE_RPCHEAD_H
src/rpc/inc/
ttcps
erver.h
→
src/rpc/inc/
rpcS
erver.h
浏览文件 @
a2629a02
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _
taos_tcp
_server_header_
#define _
taos_tcp
_server_header_
#ifndef _
rpc
_server_header_
#define _
rpc
_server_header_
#ifdef __cplusplus
extern
"C"
{
...
...
src/rpc/inc/
tu
dp.h
→
src/rpc/inc/
rpcU
dp.h
浏览文件 @
a2629a02
...
...
@@ -13,8 +13,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _
taos
_udp_header_
#define _
taos
_udp_header_
#ifndef _
rpc
_udp_header_
#define _
rpc
_udp_header_
#ifdef __cplusplus
extern
"C"
{
...
...
@@ -24,15 +24,15 @@ extern "C" {
void
*
taosInitUdpServer
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
,
void
*
fp
,
void
*
shandle
);
void
*
taosInitUdpClient
(
char
*
ip
,
uint16_t
port
,
char
*
label
,
int
,
void
*
fp
,
void
*
shandle
);
void
taosCleanUpUdpConnection
(
void
*
handle
);
int
taosSendUdpData
(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
dataLen
,
void
*
chandle
);
void
taosCleanUpUdpConnection
(
void
*
handle
);
int
taosSendUdpData
(
uint32_t
ip
,
uint16_t
port
,
char
*
data
,
int
dataLen
,
void
*
chandle
);
void
*
taosOpenUdpConnection
(
void
*
shandle
,
void
*
thandle
,
char
*
ip
,
uint16_t
port
);
void
taosFreeMsgHdr
(
void
*
hdr
);
int
taosMsgHdrSize
(
void
*
hdr
);
void
taosSendMsgHdr
(
void
*
hdr
,
int
fd
);
void
taosInitMsgHdr
(
void
**
hdr
,
void
*
dest
,
int
maxPkts
);
void
taosSetMsgHdrData
(
void
*
hdr
,
char
*
data
,
int
dataLen
);
void
taosFreeMsgHdr
(
void
*
hdr
);
int
taosMsgHdrSize
(
void
*
hdr
);
void
taosSendMsgHdr
(
void
*
hdr
,
int
fd
);
void
taosInitMsgHdr
(
void
**
hdr
,
void
*
dest
,
int
maxPkts
);
void
taosSetMsgHdrData
(
void
*
hdr
,
char
*
data
,
int
dataLen
);
#ifdef __cplusplus
}
...
...
src/rpc/src/
tconnc
ache.c
→
src/rpc/src/
rpcC
ache.c
浏览文件 @
a2629a02
...
...
@@ -21,7 +21,7 @@
#include "ttime.h"
#include "ttimer.h"
#include "tutil.h"
#include "
tconnc
ache.h"
#include "
rpcC
ache.h"
typedef
struct
_c_hash_t
{
uint32_t
ip
;
...
...
src/rpc/src/
ttcpc
lient.c
→
src/rpc/src/
rpcC
lient.c
浏览文件 @
a2629a02
...
...
@@ -17,8 +17,9 @@
#include "taosmsg.h"
#include "tlog.h"
#include "tsocket.h"
#include "ttcpclient.h"
#include "tutil.h"
#include "rpcClient.h"
#include "rpcHead.h"
#ifndef EPOLLWAKEUP
#define EPOLLWAKEUP (1u << 29)
...
...
@@ -152,15 +153,15 @@ static void *taosReadTcpData(void *param) {
continue
;
}
int
headLen
=
taosReadMsg
(
pFdObj
->
fd
,
buffer
,
sizeof
(
S
TaosHeader
));
if
(
headLen
!=
sizeof
(
S
TaosHeader
))
{
int
headLen
=
taosReadMsg
(
pFdObj
->
fd
,
buffer
,
sizeof
(
S
RpcHead
));
if
(
headLen
!=
sizeof
(
S
RpcHead
))
{
tError
(
"%s read error, headLen:%d"
,
pTcp
->
label
,
headLen
);
tfree
(
buffer
);
taosCleanUpTcpFdObj
(
pFdObj
);
continue
;
}
int
dataLen
=
(
int32_t
)
htonl
((
uint32_t
)((
S
TaosHeader
*
)
buffer
)
->
msgLen
);
int
dataLen
=
(
int32_t
)
htonl
((
uint32_t
)((
S
RpcHead
*
)
buffer
)
->
msgLen
);
if
(
dataLen
>
1024
)
{
void
*
b
=
realloc
(
buffer
,
(
size_t
)
dataLen
);
if
(
NULL
==
b
)
{
...
...
src/rpc/src/
th
aship.c
→
src/rpc/src/
rpcH
aship.c
浏览文件 @
a2629a02
...
...
@@ -32,7 +32,7 @@ typedef struct {
int
maxSessions
;
}
SHashObj
;
int
taos
HashIp
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
)
{
int
rpc
HashIp
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
)
{
SHashObj
*
pObj
=
(
SHashObj
*
)
handle
;
int
hash
=
0
;
...
...
@@ -45,7 +45,7 @@ int taosHashIp(void *handle, uint32_t ip, uint16_t port) {
return
hash
;
}
void
*
taos
AddIpHash
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
)
{
void
*
rpc
AddIpHash
(
void
*
handle
,
void
*
data
,
uint32_t
ip
,
uint16_t
port
)
{
int
hash
;
SIpHash
*
pNode
;
SHashObj
*
pObj
;
...
...
@@ -53,7 +53,7 @@ void *taosAddIpHash(void *handle, void *data, uint32_t ip, uint16_t port) {
pObj
=
(
SHashObj
*
)
handle
;
if
(
pObj
==
NULL
||
pObj
->
maxSessions
==
0
)
return
NULL
;
hash
=
taos
HashIp
(
pObj
,
ip
,
port
);
hash
=
rpc
HashIp
(
pObj
,
ip
,
port
);
pNode
=
(
SIpHash
*
)
taosMemPoolMalloc
(
pObj
->
ipHashMemPool
);
pNode
->
ip
=
ip
;
pNode
->
port
=
port
;
...
...
@@ -68,7 +68,7 @@ void *taosAddIpHash(void *handle, void *data, uint32_t ip, uint16_t port) {
return
pObj
;
}
void
taos
DeleteIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
)
{
void
rpc
DeleteIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
)
{
int
hash
;
SIpHash
*
pNode
;
SHashObj
*
pObj
;
...
...
@@ -76,7 +76,7 @@ void taosDeleteIpHash(void *handle, uint32_t ip, uint16_t port) {
pObj
=
(
SHashObj
*
)
handle
;
if
(
pObj
==
NULL
||
pObj
->
maxSessions
==
0
)
return
;
hash
=
taos
HashIp
(
pObj
,
ip
,
port
);
hash
=
rpc
HashIp
(
pObj
,
ip
,
port
);
pNode
=
pObj
->
ipHashList
[
hash
];
while
(
pNode
)
{
...
...
@@ -100,7 +100,7 @@ void taosDeleteIpHash(void *handle, uint32_t ip, uint16_t port) {
}
}
void
*
taos
GetIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
)
{
void
*
rpc
GetIpHash
(
void
*
handle
,
uint32_t
ip
,
uint16_t
port
)
{
int
hash
;
SIpHash
*
pNode
;
SHashObj
*
pObj
;
...
...
@@ -108,7 +108,7 @@ void *taosGetIpHash(void *handle, uint32_t ip, uint16_t port) {
pObj
=
(
SHashObj
*
)
handle
;
if
(
pObj
==
NULL
||
pObj
->
maxSessions
==
0
)
return
NULL
;
hash
=
taos
HashIp
(
pObj
,
ip
,
port
);
hash
=
rpc
HashIp
(
pObj
,
ip
,
port
);
pNode
=
pObj
->
ipHashList
[
hash
];
while
(
pNode
)
{
...
...
@@ -124,7 +124,7 @@ void *taosGetIpHash(void *handle, uint32_t ip, uint16_t port) {
return
NULL
;
}
void
*
taos
OpenIpHash
(
int
maxSessions
)
{
void
*
rpc
OpenIpHash
(
int
maxSessions
)
{
SIpHash
**
ipHashList
;
mpool_h
ipHashMemPool
;
SHashObj
*
pObj
;
...
...
@@ -152,7 +152,7 @@ void *taosOpenIpHash(int maxSessions) {
return
pObj
;
}
void
taos
CloseIpHash
(
void
*
handle
)
{
void
rpc
CloseIpHash
(
void
*
handle
)
{
SHashObj
*
pObj
;
pObj
=
(
SHashObj
*
)
handle
;
...
...
src/rpc/src/
trpc
.c
→
src/rpc/src/
rpcMain
.c
浏览文件 @
a2629a02
...
...
@@ -14,23 +14,24 @@
*/
#include "os.h"
#include "shash.h"
#include "taosmsg.h"
#include "tidpool.h"
#include "tlog.h"
#include "tmd5.h"
#include "tmempool.h"
#include "tsocket.h"
#include "ttcpclient.h"
#include "ttcpserver.h"
#include "ttime.h"
#include "ttimer.h"
#include "tudp.h"
#include "tutil.h"
#include "lz4.h"
#include "tconncache.h"
#include "trpc.h"
#include "taoserror.h"
#include "tsocket.h"
#include "shash.h"
#include "taosmsg.h"
#include "rpcUdp.h"
#include "rpcCache.h"
#include "rpcClient.h"
#include "rpcServer.h"
#include "rpcHead.h"
#include "trpc.h"
#define RPC_MSG_OVERHEAD (sizeof(SRpcReqContext) + sizeof(SRpcHead) + sizeof(SRpcDigest))
#define rpcHeadFromCont(cont) ((SRpcHead *) (cont - sizeof(SRpcHead)))
...
...
@@ -51,11 +52,11 @@ typedef struct {
char
meterId
[
TSDB_UNI_LEN
];
// meter ID
char
spi
;
// security parameter index
char
encrypt
;
// encrypt algorithm
uint8_t
secret
[
TSDB_KEY_LEN
];
// secret for the link
uint8_t
ckey
[
TSDB_KEY_LEN
];
// ciphering key
char
secret
[
TSDB_KEY_LEN
];
// secret for the link
char
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
);
int
(
*
afp
)(
char
*
meterId
,
char
*
spi
,
char
*
encrypt
,
char
*
secret
,
char
*
ckey
);
void
(
*
ufp
)(
void
*
ahandle
,
SRpcIpSet
ipSet
);
void
*
idPool
;
// handle to ID pool
...
...
@@ -88,8 +89,8 @@ typedef struct _RpcConn {
char
meterId
[
TSDB_UNI_LEN
];
// user ID for the link
char
spi
;
// security parameter index
char
encrypt
;
// encryption, 0:1
uint8_t
secret
[
TSDB_KEY_LEN
];
// secret for the link
uint8_t
ckey
[
TSDB_KEY_LEN
];
// ciphering key
char
secret
[
TSDB_KEY_LEN
];
// secret for the link
char
ckey
[
TSDB_KEY_LEN
];
// ciphering key
uint16_t
localPort
;
// for UDP only
uint32_t
peerUid
;
// peer UID
uint32_t
peerIp
;
// peer IP
...
...
@@ -114,39 +115,6 @@ 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
char
tcp
:
2
;
// tcp flag
char
spi
:
3
;
// security parameter index
char
encrypt
:
3
;
// encrypt algorithm, 0: no encryption
uint16_t
tranId
;
// transcation ID
uint32_t
uid
;
// for unique ID inside a client
uint32_t
sourceId
;
// source ID, an index for connection list
uint32_t
destId
;
// destination ID, an index for connection list
char
meterId
[
TSDB_UNI_LEN
];
uint16_t
port
;
// for UDP only, port may be changed
char
empty
[
1
];
// reserved
uint8_t
msgType
;
// message type
int32_t
msgLen
;
// message length including the header iteslf
int32_t
code
;
uint8_t
content
[
0
];
// message body starts from here
}
SRpcHead
;
typedef
struct
{
int32_t
reserved
;
int32_t
contLen
;
}
SRpcComp
;
typedef
struct
{
uint32_t
timeStamp
;
uint8_t
auth
[
TSDB_AUTH_LEN
];
}
SRpcDigest
;
#pragma pack(pop)
int
tsRpcProgressTime
=
10
;
// milliseocnds
// not configurable
...
...
@@ -196,7 +164,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, char *meterId, char *hash
static
SRpcConn
*
rpcGetConnObj
(
SRpcInfo
*
pRpc
,
int
sid
,
char
*
meterId
,
char
*
hashstr
);
static
void
rpcSendReqToServer
(
SRpcInfo
*
pRpc
,
SRpcReqContext
*
pContext
);
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
char
code
);
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
int32_t
code
);
static
void
rpcSendErrorMsgToPeer
(
SRpcInfo
*
pRpc
,
char
*
pMsg
,
int32_t
code
,
uint32_t
ip
,
uint16_t
port
,
void
*
chandle
);
static
void
rpcSendMsgToPeer
(
SRpcConn
*
pConn
,
void
*
data
,
int
dataLen
);
...
...
@@ -509,10 +477,11 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) {
}
static
SRpcConn
*
rpcAllocateServerConn
(
SRpcInfo
*
pRpc
,
char
*
meterId
,
char
*
hashstr
)
{
SRpcConn
*
pConn
;
SRpcConn
*
pConn
=
NULL
;
// check if it is already allocated
pConn
=
*
(
SRpcConn
**
)(
taosGetStrHashData
(
pRpc
->
hash
,
hashstr
));
SRpcConn
**
ppConn
=
(
SRpcConn
**
)(
taosGetStrHashData
(
pRpc
->
hash
,
hashstr
));
if
(
ppConn
)
pConn
=
*
ppConn
;
if
(
pConn
)
return
pConn
;
int
sid
=
taosAllocateId
(
pRpc
->
idPool
);
...
...
@@ -537,7 +506,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, char *meterId, char *hash
if
(
pConn
)
{
taosAddStrHash
(
pRpc
->
hash
,
hashstr
,
(
char
*
)
&
pConn
);
tTrace
(
"%s pConn:%p, rpc connection is allocated, sid:%d id:%s"
,
pRpc
->
label
,
pConn
,
sid
);
tTrace
(
"%s pConn:%p, rpc connection is allocated, sid:%d id:%s"
,
pRpc
->
label
,
pConn
,
sid
,
pConn
->
meterId
);
}
return
pConn
;
...
...
@@ -660,7 +629,7 @@ static int rpcProcessRspHead(SRpcConn *pConn, SRpcHead *pHead) {
return
TSDB_CODE_SUCCESS
;
}
static
int
rpcProcessHead
(
SRpcInfo
*
pRpc
,
SRpcConn
**
ppConn
,
void
*
data
,
int
dataLen
,
uint32_t
ip
)
{
static
int
32_t
rpcProcessHead
(
SRpcInfo
*
pRpc
,
SRpcConn
**
ppConn
,
void
*
data
,
int
dataLen
,
uint32_t
ip
)
{
int32_t
sid
,
code
=
0
;
SRpcConn
*
pConn
=
NULL
;
char
hashstr
[
40
]
=
{
0
};
...
...
@@ -724,7 +693,7 @@ static void *rpcProcessMsgFromPeer(void *data, int dataLen, uint32_t ip, uint16_
SRpcHead
*
pHead
=
(
SRpcHead
*
)
data
;
SRpcInfo
*
pRpc
=
(
SRpcInfo
*
)
shandle
;
SRpcConn
*
pConn
=
NULL
;
uint8
_t
code
=
0
;
int32
_t
code
=
0
;
tDump
(
data
,
dataLen
);
...
...
@@ -750,7 +719,7 @@ static void *rpcProcessMsgFromPeer(void *data, int dataLen, uint32_t ip, uint16_
pthread_mutex_unlock
(
&
pRpc
->
mutex
);
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"
,
tTrace
(
"%s pConn:%p, %s received from 0x%x:%hu, parse code:%
x
len:%d source:0x%08x dest:0x%08x tranId:%d"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
],
ip
,
port
,
code
,
dataLen
,
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
}
...
...
@@ -763,7 +732,7 @@ static void *rpcProcessMsgFromPeer(void *data, int dataLen, uint32_t ip, uint16_
if
(
code
!=
0
)
{
// parsing error
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
->
msgType
+
1
],
code
);
tTrace
(
"%s pConn:%p, %s is sent with error code:%
x
"
,
pRpc
->
label
,
pConn
,
taosMsg
[
pHead
->
msgType
+
1
],
code
);
}
}
else
{
// parsing OK
rpcProcessIncomingMsg
(
pConn
,
pHead
);
...
...
@@ -804,7 +773,7 @@ static void rpcProcessIncomingMsg(SRpcConn *pConn, SRpcHead *pHead) {
}
}
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
char
code
)
{
static
void
rpcSendQuickRsp
(
SRpcConn
*
pConn
,
int32_t
code
)
{
char
msg
[
RPC_MSG_OVERHEAD
];
SRpcHead
*
pHead
;
...
...
@@ -1131,7 +1100,7 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen) {
pDigest
->
timeStamp
=
htonl
(
taosGetTimestampSec
());
msgLen
+=
sizeof
(
SRpcDigest
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
rpcBuildAuthHead
((
uint8_t
*
)
pHead
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
);
rpcBuildAuthHead
((
uint8_t
*
)
pHead
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
(
uint8_t
*
)
pConn
->
secret
);
}
else
{
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
}
...
...
@@ -1142,7 +1111,7 @@ static int rpcAddAuthPart(SRpcConn *pConn, char *msg, int msgLen) {
static
int
rpcCheckAuthentication
(
SRpcConn
*
pConn
,
char
*
msg
,
int
msgLen
)
{
SRpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
SRpcInfo
*
pRpc
=
pConn
->
pRpc
;
int
code
=
0
;
int
32_t
code
=
0
;
if
(
pConn
->
spi
==
0
)
return
0
;
...
...
@@ -1158,7 +1127,7 @@ 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
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
pConn
->
secret
)
<
0
)
{
if
(
rpcAuthenticateMsg
((
uint8_t
*
)
pHead
,
msgLen
-
TSDB_AUTH_LEN
,
pDigest
->
auth
,
(
uint8_t
*
)
pConn
->
secret
)
<
0
)
{
tError
(
"%s pConn:%p, authentication failed, msg discarded"
,
pRpc
->
label
,
pConn
);
code
=
TSDB_CODE_AUTH_FAILURE
;
}
else
{
...
...
src/rpc/src/
ttcps
erver.c
→
src/rpc/src/
rpcS
erver.c
浏览文件 @
a2629a02
...
...
@@ -14,12 +14,12 @@
*/
#include "os.h"
#include "taosmsg.h"
#include "tlog.h"
#include "tlog.h"
#include "tsocket.h"
#include "ttcpserver.h"
#include "tutil.h"
#include "rpcServer.h"
#include "rpcHead.h"
#define TAOS_IPv4ADDR_LEN 16
#ifndef EPOLLWAKEUP
...
...
@@ -184,16 +184,16 @@ static void taosProcessTcpData(void *param) {
}
void
*
buffer
=
malloc
(
1024
);
int
headLen
=
taosReadMsg
(
pFdObj
->
fd
,
buffer
,
sizeof
(
S
TaosHeader
));
int
headLen
=
taosReadMsg
(
pFdObj
->
fd
,
buffer
,
sizeof
(
S
RpcHead
));
if
(
headLen
!=
sizeof
(
S
TaosHeader
))
{
if
(
headLen
!=
sizeof
(
S
RpcHead
))
{
tError
(
"%s read error, headLen:%d, errno:%d"
,
pThreadObj
->
label
,
headLen
,
errno
);
taosCleanUpFdObj
(
pFdObj
);
tfree
(
buffer
);
continue
;
}
int
dataLen
=
(
int32_t
)
htonl
((
uint32_t
)((
S
TaosHeader
*
)
buffer
)
->
msgLen
);
int
dataLen
=
(
int32_t
)
htonl
((
uint32_t
)((
S
RpcHead
*
)
buffer
)
->
msgLen
);
if
(
dataLen
>
1024
)
buffer
=
realloc
(
buffer
,
(
size_t
)
dataLen
);
int
leftLen
=
dataLen
-
headLen
;
...
...
src/rpc/src/
tu
dp.c
→
src/rpc/src/
rpcU
dp.c
浏览文件 @
a2629a02
...
...
@@ -14,15 +14,15 @@
*/
#include "os.h"
#include "taosmsg.h"
#include "thash.h"
#include "thaship.h"
#include "tlog.h"
#include "tsocket.h"
#include "tsystem.h"
#include "ttimer.h"
#include "tudp.h"
#include "tutil.h"
#include "thash.h"
#include "rpcHaship.h"
#include "rpcUdp.h"
#include "rpcHead.h"
#define RPC_MAX_UDP_CONNS 256
#define RPC_MAX_UDP_PKTS 1000
...
...
@@ -104,6 +104,41 @@ typedef struct {
uint64_t
hash
;
}
SHandleViaTcp
;
void
taosFreeMsgHdr
(
void
*
hdr
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
free
(
msgHdr
->
msg_iov
);
}
int
taosMsgHdrSize
(
void
*
hdr
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
return
(
int
)
msgHdr
->
msg_iovlen
;
}
void
taosSendMsgHdr
(
void
*
hdr
,
int
fd
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
sendmsg
(
fd
,
msgHdr
,
0
);
msgHdr
->
msg_iovlen
=
0
;
}
void
taosInitMsgHdr
(
void
**
hdr
,
void
*
dest
,
int
maxPkts
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
malloc
(
sizeof
(
struct
msghdr
));
memset
(
msgHdr
,
0
,
sizeof
(
struct
msghdr
));
*
hdr
=
msgHdr
;
struct
sockaddr_in
*
destAdd
=
(
struct
sockaddr_in
*
)
dest
;
msgHdr
->
msg_name
=
destAdd
;
msgHdr
->
msg_namelen
=
sizeof
(
struct
sockaddr_in
);
int
size
=
(
int
)
sizeof
(
struct
iovec
)
*
maxPkts
;
msgHdr
->
msg_iov
=
(
struct
iovec
*
)
malloc
((
size_t
)
size
);
memset
(
msgHdr
->
msg_iov
,
0
,
(
size_t
)
size
);
}
void
taosSetMsgHdrData
(
void
*
hdr
,
char
*
data
,
int
dataLen
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
msgHdr
->
msg_iov
[
msgHdr
->
msg_iovlen
].
iov_base
=
data
;
msgHdr
->
msg_iov
[
msgHdr
->
msg_iovlen
].
iov_len
=
(
size_t
)
dataLen
;
msgHdr
->
msg_iovlen
++
;
}
bool
taosCheckHandleViaTcpValid
(
SHandleViaTcp
*
handleViaTcp
)
{
return
handleViaTcp
->
hash
==
taosHashUInt64
(
handleViaTcp
->
handle
);
}
...
...
@@ -134,8 +169,8 @@ void taosProcessMonitorTimer(void *param, void *tmrId) {
}
void
*
taosReadTcpData
(
void
*
argv
)
{
SMonitor
*
pMonitor
=
(
SMonitor
*
)
argv
;
S
TaosHeader
*
pHead
=
(
STaosHeader
*
)
pMonitor
->
data
;
SMonitor
*
pMonitor
=
(
SMonitor
*
)
argv
;
S
RpcHead
*
pHead
=
(
SRpcHead
*
)
pMonitor
->
data
;
SPacketInfo
*
pInfo
=
(
SPacketInfo
*
)
pHead
->
content
;
SUdpConnSet
*
pSet
=
pMonitor
->
pSet
;
int
retLen
,
fd
;
...
...
@@ -189,7 +224,7 @@ void *taosReadTcpData(void *argv) {
return
NULL
;
}
int
taosReceivePacketViaTcp
(
uint32_t
ip
,
S
TaosHeader
*
pHead
,
SUdpConn
*
pConn
)
{
int
taosReceivePacketViaTcp
(
uint32_t
ip
,
S
RpcHead
*
pHead
,
SUdpConn
*
pConn
)
{
SUdpConnSet
*
pSet
=
pConn
->
pSet
;
SPacketInfo
*
pInfo
=
(
SPacketInfo
*
)
pHead
->
content
;
int
code
=
0
;
...
...
@@ -200,7 +235,7 @@ int taosReceivePacketViaTcp(uint32_t ip, STaosHeader *pHead, SUdpConn *pConn) {
pHead
->
sourceId
,
pHead
->
destId
,
pHead
->
tranId
);
SMonitor
*
pMonitor
=
(
SMonitor
*
)
calloc
(
1
,
sizeof
(
SMonitor
));
pMonitor
->
dataLen
=
sizeof
(
S
TaosHeader
)
+
sizeof
(
SPacketInfo
);
pMonitor
->
dataLen
=
sizeof
(
S
RpcHead
)
+
sizeof
(
SPacketInfo
);
memcpy
(
pMonitor
->
data
,
pHead
,
(
size_t
)
pMonitor
->
dataLen
);
pMonitor
->
pSet
=
pSet
;
pMonitor
->
ip
=
ip
;
...
...
@@ -225,7 +260,7 @@ void *taosRecvUdpData(void *param) {
unsigned
int
addLen
,
dataLen
;
SUdpConn
*
pConn
=
(
SUdpConn
*
)
param
;
uint16_t
port
;
int
minSize
=
sizeof
(
S
TaosHeader
);
int
minSize
=
sizeof
(
S
RpcHead
);
memset
(
&
sourceAdd
,
0
,
sizeof
(
sourceAdd
));
addLen
=
sizeof
(
sourceAdd
);
...
...
@@ -237,7 +272,7 @@ void *taosRecvUdpData(void *param) {
tTrace
(
"%s msg is recv from 0x%x:%hu len:%d"
,
pConn
->
label
,
sourceAdd
.
sin_addr
.
s_addr
,
ntohs
(
sourceAdd
.
sin_port
),
dataLen
);
if
(
dataLen
<
sizeof
(
S
TaosHeader
))
{
if
(
dataLen
<
sizeof
(
S
RpcHead
))
{
tError
(
"%s recvfrom failed, reason:%s
\n
"
,
pConn
->
label
,
strerror
(
errno
));
continue
;
}
...
...
@@ -250,7 +285,7 @@ void *taosRecvUdpData(void *param) {
char
*
msg
=
pConn
->
buffer
;
while
(
processedLen
<
(
int
)
dataLen
)
{
leftLen
=
dataLen
-
processedLen
;
S
TaosHeader
*
pHead
=
(
STaosHeader
*
)
msg
;
S
RpcHead
*
pHead
=
(
SRpcHead
*
)
msg
;
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
->
msgLen
);
if
(
leftLen
<
minSize
||
msgLen
>
leftLen
||
msgLen
<
minSize
)
{
tError
(
"%s msg is messed up, dataLen:%d processedLen:%d count:%d msgLen:%d"
,
pConn
->
label
,
dataLen
,
...
...
@@ -259,7 +294,7 @@ void *taosRecvUdpData(void *param) {
}
if
(
pHead
->
tcp
==
1
)
{
taosReceivePacketViaTcp
(
sourceAdd
.
sin_addr
.
s_addr
,
(
S
TaosHeader
*
)
msg
,
pConn
);
taosReceivePacketViaTcp
(
sourceAdd
.
sin_addr
.
s_addr
,
(
S
RpcHead
*
)
msg
,
pConn
);
}
else
{
char
*
data
=
malloc
((
size_t
)
msgLen
);
memcpy
(
data
,
msg
,
(
size_t
)
msgLen
);
...
...
@@ -282,7 +317,7 @@ void *taosTransferDataViaTcp(void *argv) {
int
connFd
=
pTransfer
->
fd
;
int
msgLen
,
retLen
,
leftLen
;
uint64_t
handle
;
S
TaosHeader
*
pHeader
=
NULL
,
head
;
S
RpcHead
*
pHead
=
NULL
,
head
;
SUdpConnSet
*
pSet
=
pTransfer
->
pSet
;
SHandleViaTcp
handleViaTcp
;
...
...
@@ -308,8 +343,8 @@ void *taosTransferDataViaTcp(void *argv) {
if
(
handle
==
0
)
{
// receive a packet from client
tTrace
(
"%s data will be received via TCP from 0x%x:%hu"
,
pSet
->
label
,
pTransfer
->
ip
,
pTransfer
->
port
);
retLen
=
taosReadMsg
(
connFd
,
&
head
,
sizeof
(
S
TaosHeader
));
if
(
retLen
!=
(
int
)
sizeof
(
S
TaosHeader
))
{
retLen
=
taosReadMsg
(
connFd
,
&
head
,
sizeof
(
S
RpcHead
));
if
(
retLen
!=
(
int
)
sizeof
(
S
RpcHead
))
{
tError
(
"%s failed to read msg header, retLen:%d"
,
pSet
->
label
,
retLen
);
}
else
{
SMonitor
*
pMonitor
=
(
SMonitor
*
)
calloc
(
1
,
sizeof
(
SMonitor
));
...
...
@@ -319,10 +354,10 @@ void *taosTransferDataViaTcp(void *argv) {
free
(
pTransfer
);
return
NULL
;
}
pMonitor
->
dataLen
=
sizeof
(
S
TaosHeader
);
pMonitor
->
dataLen
=
sizeof
(
S
RpcHead
);
memcpy
(
pMonitor
->
data
,
&
head
,
(
size_t
)
pMonitor
->
dataLen
);
((
S
TaosHeader
*
)
pMonitor
->
data
)
->
msgLen
=
(
int32_t
)
htonl
(
sizeof
(
STaosHeader
));
((
S
TaosHeader
*
)
pMonitor
->
data
)
->
tcp
=
1
;
((
S
RpcHead
*
)
pMonitor
->
data
)
->
msgLen
=
(
int32_t
)
htonl
(
sizeof
(
SRpcHead
));
((
S
RpcHead
*
)
pMonitor
->
data
)
->
tcp
=
1
;
pMonitor
->
ip
=
pTransfer
->
ip
;
pMonitor
->
port
=
head
.
port
;
pMonitor
->
pSet
=
pSet
;
...
...
@@ -337,8 +372,8 @@ void *taosTransferDataViaTcp(void *argv) {
return
NULL
;
}
leftLen
=
msgLen
-
(
int
)
sizeof
(
S
TaosHeader
);
retLen
=
taosReadMsg
(
connFd
,
buffer
+
sizeof
(
S
TaosHeader
),
leftLen
);
leftLen
=
msgLen
-
(
int
)
sizeof
(
S
RpcHead
);
retLen
=
taosReadMsg
(
connFd
,
buffer
+
sizeof
(
S
RpcHead
),
leftLen
);
pMonitor
->
pSet
=
NULL
;
if
(
retLen
!=
leftLen
)
{
...
...
@@ -349,7 +384,7 @@ void *taosTransferDataViaTcp(void *argv) {
pTransfer
->
port
,
msgLen
);
pSet
->
index
=
(
pSet
->
index
+
1
)
%
pSet
->
threads
;
SUdpConn
*
pConn
=
pSet
->
udpConn
+
pSet
->
index
;
memcpy
(
buffer
,
&
head
,
sizeof
(
S
TaosHeader
));
memcpy
(
buffer
,
&
head
,
sizeof
(
S
RpcHead
));
(
*
pSet
->
fp
)(
buffer
,
msgLen
,
pTransfer
->
ip
,
head
.
port
,
pSet
->
shandle
,
NULL
,
pConn
);
}
...
...
@@ -358,11 +393,11 @@ void *taosTransferDataViaTcp(void *argv) {
}
else
{
// send a packet to client
tTrace
(
"%s send packet to client via TCP, handle:0x%x"
,
pSet
->
label
,
handle
);
pHead
er
=
(
STaosHeader
*
)
handle
;
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
er
->
msgLen
);
pHead
=
(
SRpcHead
*
)
handle
;
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
pHead
->
msgLen
);
if
(
pHead
er
->
tcp
!=
0
||
msgLen
<
1024
)
{
tError
(
"%s invalid handle:%p, connection shall be closed"
,
pSet
->
label
,
pHead
er
);
if
(
pHead
->
tcp
!=
0
||
msgLen
<
1024
)
{
tError
(
"%s invalid handle:%p, connection shall be closed"
,
pSet
->
label
,
pHead
);
}
else
{
SMonitor
*
pMonitor
=
(
SMonitor
*
)
calloc
(
1
,
sizeof
(
SMonitor
));
if
(
NULL
==
pMonitor
)
{
...
...
@@ -371,12 +406,12 @@ void *taosTransferDataViaTcp(void *argv) {
free
(
pTransfer
);
return
NULL
;
}
pMonitor
->
dataLen
=
sizeof
(
S
TaosHeader
);
pMonitor
->
dataLen
=
sizeof
(
S
RpcHead
);
memcpy
(
pMonitor
->
data
,
(
void
*
)
handle
,
(
size_t
)
pMonitor
->
dataLen
);
S
TaosHeader
*
pThead
=
(
STaosHeader
*
)
pMonitor
->
data
;
S
RpcHead
*
pThead
=
(
SRpcHead
*
)
pMonitor
->
data
;
pThead
->
tcp
=
1
;
pThead
->
msgType
=
(
char
)(
pHead
er
->
msgType
-
1
);
pThead
->
msgLen
=
(
int32_t
)
htonl
(
sizeof
(
S
TaosHeader
));
pThead
->
msgType
=
(
char
)(
pHead
->
msgType
-
1
);
pThead
->
msgLen
=
(
int32_t
)
htonl
(
sizeof
(
S
RpcHead
));
uint32_t
id
=
pThead
->
sourceId
;
pThead
->
sourceId
=
pThead
->
destId
;
pThead
->
destId
=
id
;
pMonitor
->
ip
=
pTransfer
->
ip
;
pMonitor
->
port
=
pTransfer
->
port
;
...
...
@@ -522,7 +557,7 @@ void *taosInitUdpConnection(char *ip, uint16_t port, char *label, int threads, v
pConn
->
pSet
=
pSet
;
pConn
->
signature
=
pConn
;
if
(
tsUdpDelay
)
{
pConn
->
hash
=
taos
OpenIpHash
(
RPC_MAX_UDP_CONNS
);
pConn
->
hash
=
rpc
OpenIpHash
(
RPC_MAX_UDP_CONNS
);
pthread_mutex_init
(
&
pConn
->
mutex
,
NULL
);
pConn
->
tmrCtrl
=
pSet
->
tmrCtrl
;
}
...
...
@@ -575,7 +610,7 @@ void taosCleanUpUdpConnection(void *handle) {
pthread_cancel
(
pConn
->
thread
);
taosCloseSocket
(
pConn
->
fd
);
if
(
pConn
->
hash
)
{
taos
CloseIpHash
(
pConn
->
hash
);
rpc
CloseIpHash
(
pConn
->
hash
);
pthread_mutex_destroy
(
&
pConn
->
mutex
);
}
}
...
...
@@ -608,7 +643,7 @@ void *taosOpenUdpConnection(void *shandle, void *thandle, char *ip, uint16_t por
void
taosRemoveUdpBuf
(
SUdpBuf
*
pBuf
)
{
taosTmrStopA
(
&
pBuf
->
timer
);
taos
DeleteIpHash
(
pBuf
->
pConn
->
hash
,
pBuf
->
ip
,
pBuf
->
port
);
rpc
DeleteIpHash
(
pBuf
->
pConn
->
hash
,
pBuf
->
ip
,
pBuf
->
port
);
// tTrace("%s UDP buffer to:0x%lld:%d is removed", pBuf->pConn->label,
// pBuf->ip, pBuf->port);
...
...
@@ -671,13 +706,13 @@ int taosSendPacketViaTcp(uint32_t ip, uint16_t port, char *data, int dataLen, vo
int
code
=
-
1
,
retLen
,
msgLen
;
char
ipstr
[
64
];
char
buffer
[
128
];
S
TaosHeader
*
pHead
;
S
RpcHead
*
pHead
;
if
(
pSet
->
server
)
{
// send from server
pHead
=
(
S
TaosHeader
*
)
buffer
;
memcpy
(
pHead
,
data
,
sizeof
(
S
TaosHeader
));
pHead
=
(
S
RpcHead
*
)
buffer
;
memcpy
(
pHead
,
data
,
sizeof
(
S
RpcHead
));
pHead
->
tcp
=
1
;
SPacketInfo
*
pInfo
=
(
SPacketInfo
*
)
pHead
->
content
;
...
...
@@ -685,7 +720,7 @@ int taosSendPacketViaTcp(uint32_t ip, uint16_t port, char *data, int dataLen, vo
pInfo
->
port
=
pSet
->
port
;
pInfo
->
msgLen
=
pHead
->
msgLen
;
msgLen
=
sizeof
(
S
TaosHeader
)
+
sizeof
(
SPacketInfo
);
msgLen
=
sizeof
(
S
RpcHead
)
+
sizeof
(
SPacketInfo
);
pHead
->
msgLen
=
(
int32_t
)
htonl
((
uint32_t
)
msgLen
);
code
=
taosSendUdpData
(
ip
,
port
,
buffer
,
msgLen
,
chandle
);
tTrace
(
"%s data from server will be sent via TCP:%hu, msgType:%d, length:%d, handle:0x%x"
,
pSet
->
label
,
pInfo
->
port
,
...
...
@@ -696,16 +731,16 @@ int taosSendPacketViaTcp(uint32_t ip, uint16_t port, char *data, int dataLen, vo
tTrace
(
"%s data will be sent via TCP from client"
,
pSet
->
label
);
// send a UDP header first to set up the connection
pHead
=
(
S
TaosHeader
*
)
buffer
;
memcpy
(
pHead
,
data
,
sizeof
(
S
TaosHeader
));
pHead
=
(
S
RpcHead
*
)
buffer
;
memcpy
(
pHead
,
data
,
sizeof
(
S
RpcHead
));
pHead
->
tcp
=
2
;
msgLen
=
sizeof
(
S
TaosHeader
);
msgLen
=
sizeof
(
S
RpcHead
);
pHead
->
msgLen
=
(
int32_t
)
htonl
(
msgLen
);
code
=
taosSendUdpData
(
ip
,
port
,
buffer
,
msgLen
,
chandle
);
//pHead = (S
TaosHeader
*)data;
//pHead = (S
RpcHead
*)data;
tinet_ntoa
(
ipstr
,
ip
);
int
fd
=
taosOpenTcpClientSocket
(
ipstr
,
pConn
->
port
,
tsLocalIp
);
...
...
@@ -762,10 +797,10 @@ int taosSendUdpData(uint32_t ip, uint16_t port, char *data, int dataLen, void *c
pthread_mutex_lock
(
&
pConn
->
mutex
);
pBuf
=
(
SUdpBuf
*
)
taos
GetIpHash
(
pConn
->
hash
,
ip
,
port
);
pBuf
=
(
SUdpBuf
*
)
rpc
GetIpHash
(
pConn
->
hash
,
ip
,
port
);
if
(
pBuf
==
NULL
)
{
pBuf
=
taosCreateUdpBuf
(
pConn
,
ip
,
port
);
taos
AddIpHash
(
pConn
->
hash
,
pBuf
,
ip
,
port
);
rpc
AddIpHash
(
pConn
->
hash
,
pBuf
,
ip
,
port
);
}
if
((
pBuf
->
totalLen
+
dataLen
>
RPC_MAX_UDP_SIZE
)
||
(
taosMsgHdrSize
(
pBuf
->
msgHdr
)
>=
RPC_MAX_UDP_PKTS
))
{
...
...
src/rpc/src/tmsghdr.c
已删除
100644 → 0
浏览文件 @
789246a4
/*
* Copyright (c) 2019 TAOS Data, Inc. <jhtao@taosdata.com>
*
* This program is free software: you can use, redistribute, and/or modify
* it under the terms of the GNU Affero General Public License, version 3
* or later ("AGPL"), as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "os.h"
void
taosFreeMsgHdr
(
void
*
hdr
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
free
(
msgHdr
->
msg_iov
);
}
int
taosMsgHdrSize
(
void
*
hdr
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
return
(
int
)
msgHdr
->
msg_iovlen
;
}
void
taosSendMsgHdr
(
void
*
hdr
,
int
fd
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
sendmsg
(
fd
,
msgHdr
,
0
);
msgHdr
->
msg_iovlen
=
0
;
}
void
taosInitMsgHdr
(
void
**
hdr
,
void
*
dest
,
int
maxPkts
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
malloc
(
sizeof
(
struct
msghdr
));
memset
(
msgHdr
,
0
,
sizeof
(
struct
msghdr
));
*
hdr
=
msgHdr
;
struct
sockaddr_in
*
destAdd
=
(
struct
sockaddr_in
*
)
dest
;
msgHdr
->
msg_name
=
destAdd
;
msgHdr
->
msg_namelen
=
sizeof
(
struct
sockaddr_in
);
int
size
=
(
int
)
sizeof
(
struct
iovec
)
*
maxPkts
;
msgHdr
->
msg_iov
=
(
struct
iovec
*
)
malloc
((
size_t
)
size
);
memset
(
msgHdr
->
msg_iov
,
0
,
(
size_t
)
size
);
}
void
taosSetMsgHdrData
(
void
*
hdr
,
char
*
data
,
int
dataLen
)
{
struct
msghdr
*
msgHdr
=
(
struct
msghdr
*
)
hdr
;
msgHdr
->
msg_iov
[
msgHdr
->
msg_iovlen
].
iov_base
=
data
;
msgHdr
->
msg_iov
[
msgHdr
->
msg_iovlen
].
iov_len
=
(
size_t
)
dataLen
;
msgHdr
->
msg_iovlen
++
;
}
src/
rpc
/src/tstring.c
→
src/
util
/src/tstring.c
浏览文件 @
a2629a02
文件已移动
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录