enh(rpc):add auth
This commit is contained in:
parent
7e902a3ed4
commit
219c8dbf37
|
@ -54,12 +54,13 @@ typedef struct {
|
||||||
uint16_t clientPort;
|
uint16_t clientPort;
|
||||||
SRpcMsg rpcMsg;
|
SRpcMsg rpcMsg;
|
||||||
int32_t rspLen;
|
int32_t rspLen;
|
||||||
void *pRsp;
|
void * pRsp;
|
||||||
void *pNode;
|
void * pNode;
|
||||||
} SNodeMsg;
|
} SNodeMsg;
|
||||||
|
|
||||||
typedef void (*RpcCfp)(void *parent, SRpcMsg *, SEpSet *);
|
typedef void (*RpcCfp)(void *parent, SRpcMsg *, SEpSet *);
|
||||||
typedef int (*RpcAfp)(void *parent, char *tableId, char *spi, char *encrypt, char *secret, char *ckey);
|
typedef int (*RpcAfp)(void *parent, char *tableId, char *spi, char *encrypt, char *secret, char *ckey);
|
||||||
|
typedef int (*RpcRfp)(void *parent, SRpcMsg *, SEpSet *);
|
||||||
|
|
||||||
typedef struct SRpcInit {
|
typedef struct SRpcInit {
|
||||||
uint16_t localPort; // local port
|
uint16_t localPort; // local port
|
||||||
|
@ -80,22 +81,25 @@ typedef struct SRpcInit {
|
||||||
RpcCfp cfp;
|
RpcCfp cfp;
|
||||||
|
|
||||||
// call back to retrieve the client auth info, for server app only
|
// call back to retrieve the client auth info, for server app only
|
||||||
RpcAfp afp;;
|
RpcAfp afp;
|
||||||
|
|
||||||
|
// user defined retry func
|
||||||
|
RpcRfp rfp;
|
||||||
|
|
||||||
void *parent;
|
void *parent;
|
||||||
} SRpcInit;
|
} SRpcInit;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
void *val;
|
void *val;
|
||||||
int32_t (*clone)(void *src, void **dst);
|
int32_t (*clone)(void *src, void **dst);
|
||||||
void (*freeFunc)(const void *arg);
|
void (*freeFunc)(const void *arg);
|
||||||
} SRpcCtxVal;
|
} SRpcCtxVal;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
int32_t msgType;
|
int32_t msgType;
|
||||||
void *val;
|
void * val;
|
||||||
int32_t (*clone)(void *src, void **dst);
|
int32_t (*clone)(void *src, void **dst);
|
||||||
void (*freeFunc)(const void *arg);
|
void (*freeFunc)(const void *arg);
|
||||||
} SRpcBrokenlinkVal;
|
} SRpcBrokenlinkVal;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
|
|
@ -63,13 +63,14 @@ typedef struct {
|
||||||
|
|
||||||
void (*cfp)(void* parent, SRpcMsg*, SEpSet*);
|
void (*cfp)(void* parent, SRpcMsg*, SEpSet*);
|
||||||
int (*afp)(void* parent, char* user, char* spi, char* encrypt, char* secret, char* ckey);
|
int (*afp)(void* parent, char* user, char* spi, char* encrypt, char* secret, char* ckey);
|
||||||
|
int (*retry)(void* parent, SRpcMsg*, SEpSet*);
|
||||||
|
|
||||||
int32_t refCount;
|
int32_t refCount;
|
||||||
void* parent;
|
void* parent;
|
||||||
void* idPool; // handle to ID pool
|
void* idPool; // handle to ID pool
|
||||||
void* tmrCtrl; // handle to timer
|
void* tmrCtrl; // handle to timer
|
||||||
SHashObj* hash; // handle returned by hash utility
|
SHashObj* hash; // handle returned by hash utility
|
||||||
void* tcphandle; // returned handle from TCP initialization
|
void* tcphandle; // returned handle from TCP initialization
|
||||||
TdThreadMutex mutex;
|
TdThreadMutex mutex;
|
||||||
} SRpcInfo;
|
} SRpcInfo;
|
||||||
|
|
||||||
|
|
|
@ -39,6 +39,7 @@ void* rpcOpen(const SRpcInit* pInit) {
|
||||||
// register callback handle
|
// register callback handle
|
||||||
pRpc->cfp = pInit->cfp;
|
pRpc->cfp = pInit->cfp;
|
||||||
pRpc->afp = pInit->afp;
|
pRpc->afp = pInit->afp;
|
||||||
|
pRpc->retry = pInit->rfp;
|
||||||
|
|
||||||
if (pInit->connType == TAOS_CONN_SERVER) {
|
if (pInit->connType == TAOS_CONN_SERVER) {
|
||||||
pRpc->numOfThreads = pInit->numOfThreads > TSDB_MAX_RPC_THREADS ? TSDB_MAX_RPC_THREADS : pInit->numOfThreads;
|
pRpc->numOfThreads = pInit->numOfThreads > TSDB_MAX_RPC_THREADS ? TSDB_MAX_RPC_THREADS : pInit->numOfThreads;
|
||||||
|
|
|
@ -97,6 +97,8 @@ static void cliSendCb(uv_write_t* req, int status);
|
||||||
static void cliConnCb(uv_connect_t* req, int status);
|
static void cliConnCb(uv_connect_t* req, int status);
|
||||||
static void cliAsyncCb(uv_async_t* handle);
|
static void cliAsyncCb(uv_async_t* handle);
|
||||||
|
|
||||||
|
static void cliAppCb(SCliConn* pConn, STransMsg* pMsg);
|
||||||
|
|
||||||
static SCliConn* cliCreateConn(SCliThrdObj* thrd);
|
static SCliConn* cliCreateConn(SCliThrdObj* thrd);
|
||||||
static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/);
|
static void cliDestroyConn(SCliConn* pConn, bool clear /*clear tcp handle or not*/);
|
||||||
static void cliDestroy(uv_handle_t* handle);
|
static void cliDestroy(uv_handle_t* handle);
|
||||||
|
@ -311,7 +313,8 @@ void cliHandleResp(SCliConn* conn) {
|
||||||
|
|
||||||
if (pCtx == NULL || pCtx->pSem == NULL) {
|
if (pCtx == NULL || pCtx->pSem == NULL) {
|
||||||
tTrace("%s cli conn %p handle resp", pTransInst->label, conn);
|
tTrace("%s cli conn %p handle resp", pTransInst->label, conn);
|
||||||
(pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
cliAppCb(conn, &transMsg);
|
||||||
|
//(pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
||||||
} else {
|
} else {
|
||||||
tTrace("%s cli conn(sync) %p handle resp", pTransInst->label, conn);
|
tTrace("%s cli conn(sync) %p handle resp", pTransInst->label, conn);
|
||||||
memcpy((char*)pCtx->pRsp, (char*)&transMsg, sizeof(transMsg));
|
memcpy((char*)pCtx->pRsp, (char*)&transMsg, sizeof(transMsg));
|
||||||
|
@ -377,7 +380,8 @@ void cliHandleExcept(SCliConn* pConn) {
|
||||||
once = true;
|
once = true;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
(pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
cliAppCb(pConn, &transMsg);
|
||||||
|
//(pTransInst->cfp)(pTransInst->parent, &transMsg, NULL);
|
||||||
} else {
|
} else {
|
||||||
tTrace("%s cli conn(sync) %p handle except", pTransInst->label, pConn);
|
tTrace("%s cli conn(sync) %p handle except", pTransInst->label, pConn);
|
||||||
memcpy((char*)(pCtx->pRsp), (char*)(&transMsg), sizeof(transMsg));
|
memcpy((char*)(pCtx->pRsp), (char*)(&transMsg), sizeof(transMsg));
|
||||||
|
@ -877,6 +881,16 @@ int cliRBChoseIdx(STrans* pTransInst) {
|
||||||
}
|
}
|
||||||
return index % pTransInst->numOfThreads;
|
return index % pTransInst->numOfThreads;
|
||||||
}
|
}
|
||||||
|
void cliAppCb(SCliConn* pConn, STransMsg* transMsg) {
|
||||||
|
SCliThrdObj* pThrd = pConn->hostThrd;
|
||||||
|
STrans* pTransInst = pThrd->pTransInst;
|
||||||
|
|
||||||
|
if (transMsg->code == TSDB_CODE_RPC_REDIRECT && pTransInst->retry != NULL) {
|
||||||
|
// impl retry
|
||||||
|
} else {
|
||||||
|
(*pTransInst->cfp)(pTransInst->parent, transMsg, NULL);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void transCloseClient(void* arg) {
|
void transCloseClient(void* arg) {
|
||||||
SCliObj* cli = arg;
|
SCliObj* cli = arg;
|
||||||
|
|
Loading…
Reference in New Issue