change the uid in RPC head to linkUid, hide user name once it is authenticated
This commit is contained in:
parent
c3130c7f44
commit
5049b99bf6
|
@ -48,7 +48,7 @@ typedef struct {
|
|||
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 linkUid; // for unique connection ID assigned by client
|
||||
uint32_t sourceId; // source ID, an index for connection list
|
||||
uint32_t destId; // destination ID, an index for connection list
|
||||
uint32_t destIp; // destination IP address, for NAT scenario
|
||||
|
|
|
@ -96,7 +96,7 @@ typedef struct _RpcConn {
|
|||
char ckey[TSDB_KEY_LEN]; // ciphering key
|
||||
char secured; // if set to 1, no authentication
|
||||
uint16_t localPort; // for UDP only
|
||||
uint32_t peerUid; // peer UID
|
||||
uint32_t linkUid; // connection unique ID assigned by client
|
||||
uint32_t peerIp; // peer IP
|
||||
uint32_t destIp; // server destination IP to handle NAT
|
||||
uint16_t peerPort; // peer port
|
||||
|
@ -400,10 +400,9 @@ void rpcSendResponse(void *handle, int32_t code, void *pCont, int contLen) {
|
|||
pHead->tranId = pConn->inTranId;
|
||||
pHead->sourceId = pConn->ownId;
|
||||
pHead->destId = pConn->peerId;
|
||||
pHead->uid = 0;
|
||||
pHead->linkUid = pConn->linkUid;
|
||||
pHead->port = htons(pConn->localPort);
|
||||
pHead->code = htonl(code);
|
||||
memcpy(pHead->user, pConn->user, tListLen(pHead->user));
|
||||
|
||||
// set pConn parameters
|
||||
pConn->inType = 0;
|
||||
|
@ -499,7 +498,7 @@ static void rpcCloseConn(void *thandle) {
|
|||
|
||||
if ( pRpc->connType == TAOS_CONN_SERVER) {
|
||||
char hashstr[40] = {0};
|
||||
sprintf(hashstr, "%x:%x:%x:%d", pConn->peerIp, pConn->peerUid, pConn->peerId, pConn->connType);
|
||||
sprintf(hashstr, "%x:%x:%x:%d", pConn->peerIp, pConn->linkUid, pConn->peerId, pConn->connType);
|
||||
taosDeleteStrHash(pRpc->hash, hashstr);
|
||||
rpcFreeMsg(pConn->pRspMsg); // it may have a response msg saved, but not request msg
|
||||
pConn->pRspMsg = NULL;
|
||||
|
@ -535,6 +534,7 @@ static SRpcConn *rpcAllocateClientConn(SRpcInfo *pRpc) {
|
|||
pConn->sid = sid;
|
||||
pConn->tranId = (uint16_t)(rand() & 0xFFFF);
|
||||
pConn->ownId = htonl(pConn->sid);
|
||||
pConn->linkUid = (uint32_t)((int64_t)pConn + (int64_t)getpid());
|
||||
pConn->spi = pRpc->spi;
|
||||
pConn->encrypt = pRpc->encrypt;
|
||||
if (pConn->spi) memcpy(pConn->secret, pRpc->secret, TSDB_KEY_LEN);
|
||||
|
@ -548,7 +548,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
|
|||
char hashstr[40] = {0};
|
||||
SRpcHead *pHead = (SRpcHead *)pRecv->msg;
|
||||
|
||||
sprintf(hashstr, "%x:%x:%x:%d", pRecv->ip, pHead->uid, pHead->sourceId, pRecv->connType);
|
||||
sprintf(hashstr, "%x:%x:%x:%d", pRecv->ip, pHead->linkUid, pHead->sourceId, pRecv->connType);
|
||||
|
||||
// check if it is already allocated
|
||||
SRpcConn **ppConn = (SRpcConn **)(taosGetStrHashData(pRpc->hash, hashstr));
|
||||
|
@ -567,6 +567,7 @@ static SRpcConn *rpcAllocateServerConn(SRpcInfo *pRpc, SRecvInfo *pRecv) {
|
|||
pConn->sid = sid;
|
||||
pConn->tranId = (uint16_t)(rand() & 0xFFFF);
|
||||
pConn->ownId = htonl(pConn->sid);
|
||||
pConn->linkUid = pHead->linkUid;
|
||||
if (pRpc->afp && (*pRpc->afp)(pConn->user, &pConn->spi, &pConn->encrypt, pConn->secret, pConn->ckey) < 0) {
|
||||
tWarn("%s %p, user not there", pRpc->label, pConn);
|
||||
taosFreeId(pRpc->idPool, sid); // sid shall be released
|
||||
|
@ -601,8 +602,8 @@ static SRpcConn *rpcGetConnObj(SRpcInfo *pRpc, int sid, SRecvInfo *pRecv) {
|
|||
}
|
||||
|
||||
if (pConn) {
|
||||
if (memcmp(pConn->user, pHead->user, tListLen(pConn->user)) != 0) {
|
||||
tTrace("%s %p, user:%s is not matched, received:%s", pRpc->label, pConn, pConn->user, pHead->user);
|
||||
if (pConn->linkUid != pHead->linkUid) {
|
||||
tTrace("%s %p, linkUid:0x%x not matched, received:0x%x", pRpc->label, pConn, pConn->linkUid, pHead->linkUid);
|
||||
terrno = TSDB_CODE_MISMATCHED_METER_ID;
|
||||
pConn = NULL;
|
||||
}
|
||||
|
@ -748,7 +749,6 @@ static SRpcConn *rpcProcessMsgHead(SRpcInfo *pRpc, SRecvInfo *pRecv) {
|
|||
|
||||
if (pRecv->port) pConn->peerPort = pRecv->port;
|
||||
if (pHead->port) pConn->peerPort = htons(pHead->port);
|
||||
if (pHead->uid) pConn->peerUid = pHead->uid;
|
||||
|
||||
terrno = rpcCheckAuthentication(pConn, (char *)pHead, pRecv->msgLen);
|
||||
|
||||
|
@ -881,7 +881,7 @@ static void rpcSendQuickRsp(SRpcConn *pConn, int32_t code) {
|
|||
pHead->tranId = pConn->inTranId;
|
||||
pHead->sourceId = pConn->ownId;
|
||||
pHead->destId = pConn->peerId;
|
||||
pHead->uid = 0;
|
||||
pHead->linkUid = pConn->linkUid;
|
||||
memcpy(pHead->user, pConn->user, tListLen(pHead->user));
|
||||
pHead->code = htonl(code);
|
||||
|
||||
|
@ -905,7 +905,7 @@ static void rpcSendErrorMsgToPeer(SRecvInfo *pRecv, int32_t code) {
|
|||
pReplyHead->tranId = pRecvHead->tranId;
|
||||
pReplyHead->sourceId = pRecvHead->destId;
|
||||
pReplyHead->destId = pRecvHead->sourceId;
|
||||
memcpy(pReplyHead->user, pRecvHead->user, tListLen(pReplyHead->user));
|
||||
pReplyHead->linkUid = pRecvHead->linkUid;
|
||||
|
||||
pReplyHead->code = htonl(code);
|
||||
msgLen = sizeof(SRpcHead);
|
||||
|
@ -951,8 +951,8 @@ static void rpcSendReqToServer(SRpcInfo *pRpc, SRpcReqContext *pContext) {
|
|||
pHead->destId = pConn->peerId;
|
||||
pHead->destIp = pConn->destIp;
|
||||
pHead->port = 0;
|
||||
pHead->uid = (uint32_t)((int64_t)pConn + (int64_t)getpid());
|
||||
memcpy(pHead->user, pConn->user, tListLen(pHead->user));
|
||||
pHead->linkUid = pConn->linkUid;
|
||||
if (!pConn->secured) memcpy(pHead->user, pConn->user, tListLen(pHead->user));
|
||||
|
||||
// set the connection parameters
|
||||
pConn->outType = msgType;
|
||||
|
|
Loading…
Reference in New Issue