From 64caae83fd386d377abd3760bbedaaea5e929f95 Mon Sep 17 00:00:00 2001 From: shenglian zhou Date: Fri, 8 Sep 2023 19:04:14 +0800 Subject: [PATCH] enhance: add hb whitelist version and notify taosadapter --- include/client/taos.h | 1 + include/common/tmsg.h | 2 ++ source/client/inc/clientInt.h | 7 +++++++ source/client/src/clientHb.c | 13 +++++++++++++ source/client/src/clientMsgHandler.c | 1 + source/common/src/tmsg.c | 13 ++++++++++++- source/dnode/mnode/impl/src/mndPrivilege.c | 2 ++ source/dnode/mnode/impl/src/mndProfile.c | 1 + 8 files changed, 39 insertions(+), 1 deletion(-) diff --git a/include/client/taos.h b/include/client/taos.h index 5b7946c9ad..dfa6ff43ec 100644 --- a/include/client/taos.h +++ b/include/client/taos.h @@ -125,6 +125,7 @@ typedef enum { typedef enum { TAOS_NOTIFY_PASSVER = 0, + TAOS_NOTIFY_WHITELIST_VER = 1 } TAOS_NOTIFY_TYPE; #define RET_MSG_LENGTH 1024 diff --git a/include/common/tmsg.h b/include/common/tmsg.h index 44c0b41784..ff3d07ae13 100644 --- a/include/common/tmsg.h +++ b/include/common/tmsg.h @@ -849,6 +849,7 @@ typedef struct { int32_t authVer; char sVer[TSDB_VERSION_LEN]; char sDetailVer[128]; + int64_t whiteListVer; } SConnectRsp; int32_t tSerializeSConnectRsp(void* buf, int32_t bufLen, SConnectRsp* pRsp); @@ -965,6 +966,7 @@ typedef struct { SHashObj* readTbs; SHashObj* writeTbs; SHashObj* useDbs; + int64_t whiteListVer; } SGetUserAuthRsp; int32_t tSerializeSGetUserAuthRsp(void* buf, int32_t bufLen, SGetUserAuthRsp* pRsp); diff --git a/source/client/inc/clientInt.h b/source/client/inc/clientInt.h index aa7caaaba3..9448634c5b 100644 --- a/source/client/inc/clientInt.h +++ b/source/client/inc/clientInt.h @@ -135,6 +135,12 @@ typedef struct { __taos_notify_fn_t fp; } SPassInfo; +typedef struct { + int64_t ver; + void* param; + __taos_notify_fn_t fp; +} SWhiteListInfo; + typedef struct STscObj { char user[TSDB_USER_LEN]; char pass[TSDB_PASSWORD_LEN]; @@ -152,6 +158,7 @@ typedef struct STscObj { SAppInstInfo* pAppInfo; SHashObj* pRequests; SPassInfo passInfo; + SWhiteListInfo whiteListInfo; } STscObj; typedef struct STscDbg { diff --git a/source/client/src/clientHb.c b/source/client/src/clientHb.c index 54e3a6ee48..e64f0d779c 100644 --- a/source/client/src/clientHb.c +++ b/source/client/src/clientHb.c @@ -116,6 +116,19 @@ static int32_t hbUpdateUserAuthInfo(SAppHbMgr *pAppHbMgr, SUserAuthBatchRsp *bat atomic_load_32(&passInfo->ver), pTscObj->id); } } + + if (pTscObj->whiteListInfo.fp) { + SWhiteListInfo *whiteListInfo = &pTscObj->whiteListInfo; + int64_t oldVer = atomic_load_64(&whiteListInfo->ver); + if (oldVer < pRsp->whiteListVer) { + atomic_store_64(&whiteListInfo->ver, pRsp->whiteListVer); + if (whiteListInfo->fp) { + (*whiteListInfo->fp)(whiteListInfo->param, &pRsp->whiteListVer, TAOS_NOTIFY_WHITELIST_VER); + } + tscDebug("update whitelist version of user %s from %"PRId64" to %"PRId64", tscRid:%" PRIi64, pRsp->user, oldVer, + atomic_load_64(&whiteListInfo->ver), pTscObj->id); + } + } releaseTscObj(pReq->connKey.tscRid); } } diff --git a/source/client/src/clientMsgHandler.c b/source/client/src/clientMsgHandler.c index 9f9809b227..8027a61b8f 100644 --- a/source/client/src/clientMsgHandler.c +++ b/source/client/src/clientMsgHandler.c @@ -139,6 +139,7 @@ int32_t processConnectRsp(void* param, SDataBuf* pMsg, int32_t code) { pTscObj->connType = connectRsp.connType; pTscObj->passInfo.ver = connectRsp.passVer; pTscObj->authVer = connectRsp.authVer; + pTscObj->whiteListInfo.ver = connectRsp.whiteListVer; hbRegisterConn(pTscObj->pAppInfo->pAppHbMgr, pTscObj->id, connectRsp.clusterId, connectRsp.connType); diff --git a/source/common/src/tmsg.c b/source/common/src/tmsg.c index 4d58335944..06a088a8ec 100644 --- a/source/common/src/tmsg.c +++ b/source/common/src/tmsg.c @@ -1730,7 +1730,7 @@ int32_t tSerializeSGetUserAuthRspImpl(SEncoder *pEncoder, SGetUserAuthRsp *pRsp) // since 3.0.7.0 if (tEncodeI32(pEncoder, pRsp->passVer) < 0) return -1; - + if (tEncodeI64(pEncoder, pRsp->whiteListVer) < 0) return -1; return 0; } @@ -1862,6 +1862,11 @@ int32_t tDeserializeSGetUserAuthRspImpl(SDecoder *pDecoder, SGetUserAuthRsp *pRs } else { pRsp->passVer = 0; } + if (!tDecodeIsEnd(pDecoder)) { + if (tDecodeI64(pDecoder, &pRsp->whiteListVer) < 0) goto _err; + } else { + pRsp->whiteListVer = 0; + } } return 0; _err: @@ -4366,6 +4371,7 @@ int32_t tSerializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) { if (tEncodeCStr(&encoder, pRsp->sDetailVer) < 0) return -1; if (tEncodeI32(&encoder, pRsp->passVer) < 0) return -1; if (tEncodeI32(&encoder, pRsp->authVer) < 0) return -1; + if (tEncodeI64(&encoder, pRsp->whiteListVer) < 0) return -1; tEndEncode(&encoder); int32_t tlen = encoder.pos; @@ -4402,6 +4408,11 @@ int32_t tDeserializeSConnectRsp(void *buf, int32_t bufLen, SConnectRsp *pRsp) { pRsp->authVer = 0; } + if (!tDecodeIsEnd(&decoder)) { + if (tDecodeI64(&decoder, &pRsp->whiteListVer) < 0) return -1; + } else { + pRsp->whiteListVer = 0; + } tEndDecode(&decoder); tDecoderClear(&decoder); diff --git a/source/dnode/mnode/impl/src/mndPrivilege.c b/source/dnode/mnode/impl/src/mndPrivilege.c index e5cc1fde5e..25b59f4a9a 100644 --- a/source/dnode/mnode/impl/src/mndPrivilege.c +++ b/source/dnode/mnode/impl/src/mndPrivilege.c @@ -40,6 +40,8 @@ int32_t mndSetUserAuthRsp(SMnode *pMnode, SUserObj *pUser, SGetUserAuthRsp *pRsp pRsp->sysInfo = pUser->sysInfo; pRsp->version = pUser->authVersion; pRsp->passVer = pUser->passVersion; + pRsp->whiteListVer = mndGetIpWhiteVer(pMnode); + //TODO: mndSetUserAuthRsp in enterprise version return 0; } diff --git a/source/dnode/mnode/impl/src/mndProfile.c b/source/dnode/mnode/impl/src/mndProfile.c index 9847024bee..0a3e6c616a 100644 --- a/source/dnode/mnode/impl/src/mndProfile.c +++ b/source/dnode/mnode/impl/src/mndProfile.c @@ -290,6 +290,7 @@ _CONNECT: connectRsp.svrTimestamp = taosGetTimestampSec(); connectRsp.passVer = pUser->passVersion; connectRsp.authVer = pUser->authVersion; + connectRsp.whiteListVer = mndGetIpWhiteVer(pMnode); strcpy(connectRsp.sVer, version); snprintf(connectRsp.sDetailVer, sizeof(connectRsp.sDetailVer), "ver:%s\nbuild:%s\ngitinfo:%s", version, buildinfo,