From 27e3ee8f1d5483e30a1ebf86e9a40a88c3aeed8d Mon Sep 17 00:00:00 2001 From: yihaoDeng Date: Thu, 7 Sep 2023 21:10:05 +0800 Subject: [PATCH] add rpc update interface --- source/dnode/mnode/impl/inc/mndDnode.h | 2 ++ source/dnode/mnode/impl/inc/mndUser.h | 2 ++ source/dnode/mnode/impl/src/mndDnode.c | 32 ++++++++++++++++++++++++++ source/dnode/mnode/impl/src/mndUser.c | 1 + source/libs/transport/src/transSvr.c | 2 +- 5 files changed, 38 insertions(+), 1 deletion(-) diff --git a/source/dnode/mnode/impl/inc/mndDnode.h b/source/dnode/mnode/impl/inc/mndDnode.h index 83c2277612..e1e5c11ec3 100644 --- a/source/dnode/mnode/impl/inc/mndDnode.h +++ b/source/dnode/mnode/impl/inc/mndDnode.h @@ -31,6 +31,8 @@ int32_t mndGetDnodeSize(SMnode *pMnode); bool mndIsDnodeOnline(SDnodeObj *pDnode, int64_t curMs); void mndGetDnodeData(SMnode *pMnode, SArray *pDnodeInfo); +SIpWhiteList *mndCreateIpWhiteFromDnode(SMnode *pMnode); + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/inc/mndUser.h b/source/dnode/mnode/impl/inc/mndUser.h index e9847f439d..ea0bb4082b 100644 --- a/source/dnode/mnode/impl/inc/mndUser.h +++ b/source/dnode/mnode/impl/inc/mndUser.h @@ -42,6 +42,8 @@ int32_t mndUserDupObj(SUserObj *pUser, SUserObj *pNew); void mndUserFreeObj(SUserObj *pUser); int64_t mndGetIpWhiteVer(SMnode *pMnode); + + #ifdef __cplusplus } #endif diff --git a/source/dnode/mnode/impl/src/mndDnode.c b/source/dnode/mnode/impl/src/mndDnode.c index 0e50dadfb3..3d8330d2c3 100644 --- a/source/dnode/mnode/impl/src/mndDnode.c +++ b/source/dnode/mnode/impl/src/mndDnode.c @@ -820,6 +820,38 @@ _OVER: return code; } +SIpWhiteList *mndCreateIpWhiteFromDnode(SMnode *pMnode) { + SDnodeObj *pObj = NULL; + void *pIter = NULL; + SSdb *pSdb = pMnode->pSdb; + SArray *fqdns = taosArrayInit(4, sizeof(void *)); + while (1) { + pIter = sdbFetch(pSdb, SDB_DNODE, pIter, (void **)&pObj); + if (pIter == NULL) break; + + char *fqdn = taosStrdup(pObj->fqdn); + taosArrayPush(fqdns, &fqdn); + sdbRelease(pSdb, pObj); + } + int32_t sz = taosArrayGetSize(fqdns); + SIpWhiteList *list = NULL; + if (sz != 0) { + list = taosMemoryCalloc(1, sizeof(SIpWhiteList) + sz * sizeof(SIpV4Range)); + for (int i = 0; i < sz; i++) { + char *e = taosArrayGetP(fqdns, i); + taosMemoryFree(e); + int32_t ip = taosGetFqdn(e); + + SIpV4Range *pRange = &list->pIpRange[0]; + pRange->ip = ip; + pRange->mask = 0; + } + } + + taosArrayDestroy(fqdns); + return list; +} + static int32_t mndProcessShowVariablesReq(SRpcMsg *pReq) { SShowVariablesRsp rsp = {0}; int32_t code = -1; diff --git a/source/dnode/mnode/impl/src/mndUser.c b/source/dnode/mnode/impl/src/mndUser.c index 5bf218574c..3f7c8634c2 100644 --- a/source/dnode/mnode/impl/src/mndUser.c +++ b/source/dnode/mnode/impl/src/mndUser.c @@ -240,6 +240,7 @@ SHashObj *mndFetchAllIpWhite(SMnode *pMnode) { SSdb *pSdb = pMnode->pSdb; void *pIter = NULL; SHashObj *pIpWhiteTab = taosHashInit(8, taosGetDefaultHashFunction(TSDB_DATA_TYPE_BINARY), 1, HASH_ENTRY_LOCK); + while (1) { SUserObj *pUser = NULL; pIter = sdbFetch(pSdb, SDB_USER, pIter, (void **)&pUser); diff --git a/source/libs/transport/src/transSvr.c b/source/libs/transport/src/transSvr.c index a44bea25bf..f44f9203dc 100644 --- a/source/libs/transport/src/transSvr.c +++ b/source/libs/transport/src/transSvr.c @@ -354,7 +354,7 @@ bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver) return valid; } bool uvWhiteListCheckConn(SWhiteList* pWhite, SSvrConn* pConn) { - if (pWhite->ver == pConn->whiteListVer) return true; + if (pWhite->ver == pConn->whiteListVer || strncmp(pConn->user, "_dnd", strlen("_dnd")) == 0) return true; return uvWhiteListFilte(pWhite, pConn->user, pConn->clientIp, pConn->whiteListVer); }