提交 07e6caa3 编写于 作者: S slguan

shell can connect to server

上级 d43c0ab2
......@@ -371,6 +371,8 @@ typedef struct _sstream {
struct _sstream *prev, *next;
} SSqlStream;
int32_t tscInitRpc(const char *user, const char *secret);
// tscSql API
int tsParseSql(SSqlObj *pSql, bool multiVnodeInsertion);
......
......@@ -166,8 +166,6 @@ void tscProcessActivityTimer(void *handle, void *tmrId) {
if (tscShouldFreeHeatBeat(pObj->pHb)) {
tscTrace("%p free HB object and release connection", pObj);
//taosCloseRpcConn(pObj->pHb->thandle);
tscFreeSqlObj(pObj->pHb);
tscCloseTscObj(pObj);
return;
......
......@@ -36,11 +36,6 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
taos_init();
if (pTscMgmtConn == NULL || pVnodeConn == NULL) {
globalCode = TSDB_CODE_APP_ERROR;
return NULL;
}
if (user == NULL) {
globalCode = TSDB_CODE_INVALID_ACCT;
return NULL;
......@@ -63,6 +58,11 @@ TAOS *taos_connect_imp(const char *ip, const char *user, const char *pass, const
}
}
if (tscInitRpc(user, pass) != 0) {
globalCode = TSDB_CODE_NETWORK_UNAVAIL;
return NULL;
}
if (ip && ip[0]) {
tscMgmtIpList.index = 0;
tscMgmtIpList.port = tsMgmtShellPort;
......
......@@ -45,6 +45,7 @@ int tsInsertHeadSize;
extern int tscEmbedded;
int tscNumOfThreads;
static pthread_once_t tscinit = PTHREAD_ONCE_INIT;
static pthread_mutex_t tscMutex;
extern int tsTscEnableRecordSql;
extern int tsNumOfLogLines;
......@@ -56,11 +57,64 @@ void tscCheckDiskUsage(void *para, void *unused) {
taosTmrReset(tscCheckDiskUsage, 1000, NULL, tscTmr, &tscCheckDiskUsageTmr);
}
int32_t tscInitRpc(const char *user, const char *secret) {
SRpcInit rpcInit;
char secretEncrypt[32] = {0};
taosEncryptPass((uint8_t *)secret, strlen(secret), secretEncrypt);
pthread_mutex_lock(&tscMutex);
if (pVnodeConn == NULL) {
memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsLocalIp;
rpcInit.localPort = 0;
rpcInit.label = "TSC-vnode";
rpcInit.numOfThreads = tscNumOfThreads;
rpcInit.cfp = tscProcessMsgFromServer;
rpcInit.sessions = tsMaxVnodeConnections;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.user = user;
rpcInit.ckey = "key";
rpcInit.secret = secretEncrypt;
pVnodeConn = rpcOpen(&rpcInit);
if (pVnodeConn == NULL) {
tscError("failed to init connection to vnode");
pthread_mutex_unlock(&tscMutex);
return -1;
}
}
if (pTscMgmtConn == NULL) {
memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = tsLocalIp;
rpcInit.localPort = 0;
rpcInit.label = "TSC-mgmt";
rpcInit.numOfThreads = 1;
rpcInit.cfp = tscProcessMsgFromServer;
rpcInit.sessions = tsMaxMgmtConnections;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.idleTime = 2000;
rpcInit.user = "root";
rpcInit.ckey = "key";
rpcInit.secret = secretEncrypt;
pTscMgmtConn = rpcOpen(&rpcInit);
if (pTscMgmtConn == NULL) {
tscError("failed to init connection to mgmt");
pthread_mutex_unlock(&tscMutex);
return -1;
}
}
pthread_mutex_unlock(&tscMutex);
return 0;
}
void taos_init_imp() {
char temp[128];
struct stat dirstat;
SRpcInit rpcInit;
pthread_mutex_init(&tscMutex, NULL);
srand(taosGetTimestampSec());
deltaToUtcInitOnce();
......@@ -124,42 +178,6 @@ void taos_init_imp() {
return;
}
memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = "0.0.0.0";//tsLocalIp;
rpcInit.localPort = 0;
rpcInit.label = "TSC-vnode";
rpcInit.numOfThreads = tscNumOfThreads;
rpcInit.cfp = tscProcessMsgFromServer;
rpcInit.sessions = tsMaxVnodeConnections;
rpcInit.connType = TAOS_CONN_CLIENT;
pVnodeConn = rpcOpen(&rpcInit);
if (pVnodeConn == NULL) {
tscError("failed to init connection to vnode");
return;
}
memset(&rpcInit, 0, sizeof(rpcInit));
rpcInit.localIp = "0.0.0.0";//tsLocalIp;
rpcInit.localPort = 0;
rpcInit.label = "TSC-mgmt";
rpcInit.numOfThreads = 1;
rpcInit.cfp = tscProcessMsgFromServer;
rpcInit.sessions = tsMaxMgmtConnections;
rpcInit.connType = TAOS_CONN_CLIENT;
rpcInit.idleTime = 2000;
rpcInit.user = "root";
rpcInit.ckey = "key";
char secret[32] = {0};
taosEncryptPass((uint8_t *)"taosdata", strlen("taosdata"), secret);
rpcInit.secret = secret;
pTscMgmtConn = rpcOpen(&rpcInit);
if (pTscMgmtConn == NULL) {
tscError("failed to init connection to mgmt");
return;
}
tscTmr = taosTmrInit(tsMaxMgmtConnections * 2, 200, 60000, "TSC");
if(0 == tscEmbedded){
taosTmrReset(tscCheckDiskUsage, 10, NULL, tscTmr, &tscCheckDiskUsageTmr);
......
......@@ -800,6 +800,8 @@ void source_file(TAOS *con, char *fptr) {
}
void shellGetGrantInfo(void *con) {
return;
char sql[] = "show grants";
int code = taos_query(con, sql);
......
......@@ -81,11 +81,7 @@ struct arguments args = {
*/
int main(int argc, char* argv[]) {
/*setlocale(LC_ALL, "en_US.UTF-8"); */
//
void *taos = taos_connect(NULL, "root", "taosdata", NULL, 0);
printf("ok\n");
//
if (!checkVersion()) {
exit(EXIT_FAILURE);
}
......
......@@ -1230,20 +1230,18 @@ int32_t mgmtProcessHeartBeatMsg(void *pCont, int32_t contLen, void *ahandle) {
}
int32_t mgmtRetriveUserAuthInfo(char *user, char *spi, char *encrypt, char *secret, char *ckey) {
*spi = 0;
*encrypt = 0;
*ckey = 0;
SUserObj *pUser = mgmtGetUser(user);
if (pUser == NULL) {
*spi = 0;
*encrypt = 0;
*ckey = 0;
*secret = 0;
return TSDB_CODE_INVALID_USER;
} else {
memcpy(secret, pUser->pass, TSDB_KEY_LEN);
return TSDB_CODE_SUCCESS;
}
*spi = 0;
*encrypt = 0;
*ckey = 0;
memcpy(secret, pUser->pass, TSDB_KEY_LEN);
return TSDB_CODE_SUCCESS;
}
static int32_t mgmtProcessConnectMsg(void *pCont, int32_t contLen, void *thandle) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册