add rpc update interface
This commit is contained in:
parent
bc27d245b1
commit
147de26eec
|
@ -880,6 +880,11 @@ typedef struct SIpV4Range {
|
||||||
uint32_t mask;
|
uint32_t mask;
|
||||||
} SIpV4Range;
|
} SIpV4Range;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
int32_t num;
|
||||||
|
SIpV4Range pIpRange[];
|
||||||
|
} SIpWhiteList;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int8_t createType;
|
int8_t createType;
|
||||||
int8_t superUser; // denote if it is a super user or not
|
int8_t superUser; // denote if it is a super user or not
|
||||||
|
|
|
@ -63,11 +63,12 @@ static void dmConvertErrCode(tmsg_t msgType) {
|
||||||
terrno = TSDB_CODE_VND_STOPPED;
|
terrno = TSDB_CODE_VND_STOPPED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
static void dmUpdateRpcIpWhite(SRpcMsg *pRpc) {
|
static void dmUpdateRpcIpWhite(void *pTrans, SRpcMsg *pRpc) {
|
||||||
SUpdateIpWhite ipWhite;
|
SUpdateIpWhite *pIpWhite = taosMemoryCalloc(1, sizeof(SUpdateIpWhite));
|
||||||
tDeserializeSUpdateIpWhite(pRpc->pCont, pRpc->contLen, &ipWhite);
|
tDeserializeSUpdateIpWhite(pRpc->pCont, pRpc->contLen, pIpWhite);
|
||||||
|
|
||||||
tFreeSUpdateIpWhiteReq(&ipWhite);
|
// rpcSetIpWhite(pTrans, pIpWhite);
|
||||||
|
// tFreeSUpdateIpWhiteReq(&ipWhite);
|
||||||
}
|
}
|
||||||
static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
SDnodeTrans *pTrans = &pDnode->trans;
|
SDnodeTrans *pTrans = &pDnode->trans;
|
||||||
|
@ -103,7 +104,7 @@ static void dmProcessRpcMsg(SDnode *pDnode, SRpcMsg *pRpc, SEpSet *pEpSet) {
|
||||||
dmSetMnodeEpSet(&pDnode->data, pEpSet);
|
dmSetMnodeEpSet(&pDnode->data, pEpSet);
|
||||||
}
|
}
|
||||||
case TDMT_MND_RETRIEVE_IP_WHITE_RSP: {
|
case TDMT_MND_RETRIEVE_IP_WHITE_RSP: {
|
||||||
dmUpdateRpcIpWhite(pRpc);
|
dmUpdateRpcIpWhite(pTrans->serverRpc, pRpc);
|
||||||
} break;
|
} break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -275,10 +275,6 @@ typedef struct {
|
||||||
SAcctCfg cfg;
|
SAcctCfg cfg;
|
||||||
SAcctInfo info;
|
SAcctInfo info;
|
||||||
} SAcctObj;
|
} SAcctObj;
|
||||||
typedef struct {
|
|
||||||
int32_t num;
|
|
||||||
SIpV4Range pIpRange[];
|
|
||||||
} SIpWhiteList;
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
char user[TSDB_USER_LEN];
|
char user[TSDB_USER_LEN];
|
||||||
|
|
|
@ -138,7 +138,6 @@ int64_t ipWhiteMgtFillMsg(SUpdateIpWhite *pUpdate) {
|
||||||
size_t klen;
|
size_t klen;
|
||||||
char *key = taosHashGetKey(pIter, &klen);
|
char *key = taosHashGetKey(pIter, &klen);
|
||||||
if (list->num != 0) {
|
if (list->num != 0) {
|
||||||
taosHashIterate(ipWhiteMgt.pIpWhiteList, pIter);
|
|
||||||
memcpy(pUser->user, key, klen);
|
memcpy(pUser->user, key, klen);
|
||||||
|
|
||||||
pUser->numOfRange = list->num;
|
pUser->numOfRange = list->num;
|
||||||
|
@ -146,7 +145,7 @@ int64_t ipWhiteMgtFillMsg(SUpdateIpWhite *pUpdate) {
|
||||||
memcpy(pUser->pIpRanges, list->pIpRange, list->num * sizeof(SIpV4Range));
|
memcpy(pUser->pIpRanges, list->pIpRange, list->num * sizeof(SIpV4Range));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
taosHashIterate(ipWhiteMgt.pIpWhiteList, pIter);
|
pIter = taosHashIterate(ipWhiteMgt.pIpWhiteList, pIter);
|
||||||
}
|
}
|
||||||
pUpdate->numOfUser = i;
|
pUpdate->numOfUser = i;
|
||||||
|
|
||||||
|
@ -258,7 +257,7 @@ int32_t convertIpWhiteListToStr(SIpWhiteList *pList, char **buf) {
|
||||||
*buf = NULL;
|
*buf = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
*buf = taosMemoryCalloc(1, pList->num * (sizeof(SIpWhiteList) + 4) + 4);
|
*buf = taosMemoryCalloc(1, pList->num * 36);
|
||||||
ipRangeListToStr(pList->pIpRange, pList->num, *buf);
|
ipRangeListToStr(pList->pIpRange, pList->num, *buf);
|
||||||
return strlen(*buf);
|
return strlen(*buf);
|
||||||
}
|
}
|
||||||
|
@ -1006,7 +1005,8 @@ int32_t mndProcesSRetrieveIpWhiteReq(SRpcMsg *pReq) {
|
||||||
goto _OVER;
|
goto _OVER;
|
||||||
}
|
}
|
||||||
|
|
||||||
SUpdateIpWhite ipWhite;
|
SUpdateIpWhite ipWhite = {0};
|
||||||
|
ipWhiteMgtFillMsg(&ipWhite);
|
||||||
|
|
||||||
int32_t len = tSerializeSUpdateIpWhite(NULL, 0, &ipWhite);
|
int32_t len = tSerializeSUpdateIpWhite(NULL, 0, &ipWhite);
|
||||||
|
|
||||||
|
|
|
@ -305,11 +305,12 @@ void transUnrefCliHandle(void* handle);
|
||||||
int transReleaseCliHandle(void* handle);
|
int transReleaseCliHandle(void* handle);
|
||||||
int transReleaseSrvHandle(void* handle);
|
int transReleaseSrvHandle(void* handle);
|
||||||
|
|
||||||
int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransCtx* pCtx);
|
int transSendRequest(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransCtx* pCtx);
|
||||||
int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp);
|
int transSendRecv(void* shandle, const SEpSet* pEpSet, STransMsg* pMsg, STransMsg* pRsp);
|
||||||
int transSendResponse(const STransMsg* msg);
|
int transSendResponse(const STransMsg* msg);
|
||||||
int transRegisterMsg(const STransMsg* msg);
|
int transRegisterMsg(const STransMsg* msg);
|
||||||
int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn);
|
int transSetDefaultAddr(void* shandle, const char* ip, const char* fqdn);
|
||||||
|
void transSetIpWhiteList(void* shandle, void* arg, FilteFunc* func);
|
||||||
|
|
||||||
int transSockInfo2Str(struct sockaddr* sockname, char* dst);
|
int transSockInfo2Str(struct sockaddr* sockname, char* dst);
|
||||||
|
|
||||||
|
|
|
@ -178,12 +178,13 @@ void rpcUnrefHandle(void* handle, int8_t type) { (*taosUnRefHandle[type])(handle
|
||||||
int rpcRegisterBrokenLinkArg(SRpcMsg* msg) { return transRegisterMsg(msg); }
|
int rpcRegisterBrokenLinkArg(SRpcMsg* msg) { return transRegisterMsg(msg); }
|
||||||
int rpcReleaseHandle(void* handle, int8_t type) { return (*transReleaseHandle[type])(handle); }
|
int rpcReleaseHandle(void* handle, int8_t type) { return (*transReleaseHandle[type])(handle); }
|
||||||
|
|
||||||
|
// client only
|
||||||
int rpcSetDefaultAddr(void* thandle, const char* ip, const char* fqdn) {
|
int rpcSetDefaultAddr(void* thandle, const char* ip, const char* fqdn) {
|
||||||
// later
|
// later
|
||||||
return transSetDefaultAddr(thandle, ip, fqdn);
|
return transSetDefaultAddr(thandle, ip, fqdn);
|
||||||
}
|
}
|
||||||
|
// server only
|
||||||
void rpcSetIpWhite(void* thandl, void* arg) { return ; }
|
void rpcSetIpWhite(void* thandle, void* arg) { transSetIpWhiteList(thandle, arg, NULL); }
|
||||||
|
|
||||||
void* rpcAllocHandle() { return (void*)transAllocHandle(); }
|
void* rpcAllocHandle() { return (void*)transAllocHandle(); }
|
||||||
|
|
||||||
|
|
|
@ -71,8 +71,10 @@ typedef struct SSvrMsg {
|
||||||
} SSvrMsg;
|
} SSvrMsg;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int64_t ver;
|
int64_t ver;
|
||||||
SArray* list;
|
SIpWhiteList* pList;
|
||||||
|
// SArray* list;
|
||||||
|
|
||||||
} SWhiteUserList;
|
} SWhiteUserList;
|
||||||
typedef struct {
|
typedef struct {
|
||||||
SHashObj* pList;
|
SHashObj* pList;
|
||||||
|
@ -294,11 +296,11 @@ void uvWhiteListDestroy(SWhiteList* pWhite) {
|
||||||
void* pIter = taosHashIterate(pWhiteList, NULL);
|
void* pIter = taosHashIterate(pWhiteList, NULL);
|
||||||
while (pIter) {
|
while (pIter) {
|
||||||
SWhiteUserList* pList = *(SWhiteUserList**)pIter;
|
SWhiteUserList* pList = *(SWhiteUserList**)pIter;
|
||||||
for (int i = 0; i < taosArrayGetSize(pList->list); i++) {
|
// for (int i = 0; i < taosArrayGetSize(pList->list); i++) {
|
||||||
char* range = taosArrayGetP(pList->list, i);
|
// char* range = taosArrayGetP(pList->list, i);
|
||||||
taosMemoryFree(range);
|
// taosMemoryFree(range);
|
||||||
}
|
// }
|
||||||
taosArrayDestroy(pList->list);
|
// taosArrayDestroy(pList->list);
|
||||||
taosMemoryFree(pList);
|
taosMemoryFree(pList);
|
||||||
pIter = taosHashIterate(pWhiteList, pIter);
|
pIter = taosHashIterate(pWhiteList, pIter);
|
||||||
}
|
}
|
||||||
|
@ -311,15 +313,15 @@ void uvWhiteListAdd(SWhiteList* pWhite, char* user, char* ip) {
|
||||||
|
|
||||||
SWhiteUserList** ppList = taosHashGet(pWhiteList, user, strlen(user));
|
SWhiteUserList** ppList = taosHashGet(pWhiteList, user, strlen(user));
|
||||||
if (ppList == NULL || *ppList == NULL) {
|
if (ppList == NULL || *ppList == NULL) {
|
||||||
SWhiteUserList* pList = taosMemoryCalloc(1, sizeof(SWhiteUserList));
|
// SWhiteUserList* pList = taosMemoryCalloc(1, sizeof(SWhiteUserList));
|
||||||
pList->list = taosArrayInit(8, sizeof(void*));
|
// pList->list = taosArrayInit(8, sizeof(void*));
|
||||||
taosArrayPush(pList->list, &ip);
|
// taosArrayPush(pList->list, &ip);
|
||||||
pList->ver += 1;
|
// pList->ver += 1;
|
||||||
taosHashPut(pWhiteList, user, strlen(user), &pList, sizeof(void*));
|
// taosHashPut(pWhiteList, user, strlen(user), &pList, sizeof(void*));
|
||||||
} else {
|
} else {
|
||||||
SWhiteUserList* pList = *ppList;
|
// SWhiteUserList* pList = *ppList;
|
||||||
pList->ver += 1;
|
// pList->ver += 1;
|
||||||
taosArrayPush(pList->list, &ip);
|
// taosArrayPush(pList->list, &ip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,13 +341,13 @@ bool uvWhiteListFilte(SWhiteList* pWhite, char* user, uint32_t ip, int64_t ver)
|
||||||
SWhiteUserList* pList = *ppList;
|
SWhiteUserList* pList = *ppList;
|
||||||
if (pList->ver == ver) return true;
|
if (pList->ver == ver) return true;
|
||||||
|
|
||||||
for (int i = 0; i < taosArrayGetSize(pList->list); i++) {
|
// for (int i = 0; i < taosArrayGetSize(pList->list); i++) {
|
||||||
char* range = taosArrayGetP(pList->list, i);
|
// char* range = taosArrayGetP(pList->list, i);
|
||||||
if (uvCheckIp(range, ip)) {
|
// if (uvCheckIp(range, ip)) {
|
||||||
valid = true;
|
// valid = true;
|
||||||
break;
|
// break;
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
bool uvWhiteListCheckConn(SWhiteList* pWhite, SSvrConn* pConn) {
|
bool uvWhiteListCheckConn(SWhiteList* pWhite, SSvrConn* pConn) {
|
||||||
|
@ -1380,8 +1382,16 @@ void uvHandleRegister(SSvrMsg* msg, SWorkThrd* thrd) {
|
||||||
}
|
}
|
||||||
void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) {
|
void uvHandleUpdate(SSvrMsg* msg, SWorkThrd* thrd) {
|
||||||
// update white ip
|
// update white ip
|
||||||
bool ret = (msg->func)(msg->arg);
|
// bool ret = (msg->func)(msg->arg);
|
||||||
|
SUpdateIpWhite* updateReq = msg->arg;
|
||||||
|
for (int i = 0; i < updateReq->numOfUser; i++) {
|
||||||
|
SUpdateUserIpWhite* pUser = &updateReq->pUserIpWhite[i];
|
||||||
|
}
|
||||||
|
// uvWhiteListUpdate(thrd->pWhiteList, SHashObj *pTable);
|
||||||
|
|
||||||
|
tFreeSUpdateIpWhiteReq(updateReq);
|
||||||
|
|
||||||
|
taosMemoryFree(updateReq);
|
||||||
taosMemoryFree(msg);
|
taosMemoryFree(msg);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1564,17 +1574,19 @@ _return2:
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
void transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) {
|
void transSetIpWhiteList(void* thandle, void* arg, FilteFunc* func) {
|
||||||
|
STrans* pTransInst = (STrans*)transAcquireExHandle(transGetInstMgt(), (int64_t)thandle);
|
||||||
|
|
||||||
tInfo("update ip white list");
|
tInfo("update ip white list");
|
||||||
SServerObj* svrObj = thandle;
|
SServerObj* svrObj = pTransInst->tcphandle;
|
||||||
for (int i = 0; i < svrObj->numOfThreads; i++) {
|
for (int i = 0; i < svrObj->numOfThreads; i++) {
|
||||||
SWorkThrd* pThrd = svrObj->pThreadObj[i];
|
SWorkThrd* pThrd = svrObj->pThreadObj[i];
|
||||||
|
|
||||||
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
SSvrMsg* msg = taosMemoryCalloc(1, sizeof(SSvrMsg));
|
||||||
msg->type = Update;
|
msg->type = Update;
|
||||||
msg->arg = arg;
|
msg->arg = arg;
|
||||||
msg->func = *func;
|
|
||||||
transAsyncSend(pThrd->asyncPool, &msg->q);
|
transAsyncSend(pThrd->asyncPool, &msg->q);
|
||||||
}
|
}
|
||||||
|
transReleaseExHandle(transGetInstMgt(), (int64_t)thandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
int transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; }
|
int transGetConnInfo(void* thandle, STransHandleInfo* pConnInfo) { return -1; }
|
||||||
|
|
Loading…
Reference in New Issue