refactor
This commit is contained in:
parent
0a4556984c
commit
a1b7444a48
|
@ -337,7 +337,6 @@ int32_t updateEncryptKey(char *key) {
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: dmchen parse key from code
|
||||
if (!(machineId = tGetMachineId())) {
|
||||
terrno = TSDB_CODE_OUT_OF_MEMORY;
|
||||
goto _OVER;
|
||||
|
@ -436,33 +435,31 @@ int32_t getEncryptKey(){
|
|||
}
|
||||
|
||||
char *encryptKey = NULL;
|
||||
//TODO: dmchen parse key from code
|
||||
if(checkAndGetCryptKey(content, machineId, &encryptKey) != 0){
|
||||
goto _OVER;
|
||||
}
|
||||
strncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN);
|
||||
|
||||
taosMemoryFreeClear(encryptKey);
|
||||
|
||||
//TODO: dmchen checksum
|
||||
tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
|
||||
|
||||
taosMemoryFreeClear(content);
|
||||
|
||||
if(tsEncryptKey[0] == '\0'){
|
||||
if(encryptKey[0] == '\0'){
|
||||
terrno = TSDB_CODE_DNODE_INVALID_ENCRYPTKEY;
|
||||
dError("failed to read key since %s", terrstr());
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
if(compareCheckCode(checkFile, tsEncryptKey) != 0){
|
||||
if(compareCheckCode(checkFile, encryptKey) != 0){
|
||||
goto _OVER;
|
||||
}
|
||||
|
||||
strncpy(tsEncryptKey, encryptKey, ENCRYPT_KEY_LEN);
|
||||
taosMemoryFreeClear(encryptKey);
|
||||
tsEncryptionKeyChksum = taosCalcChecksum(0, tsEncryptKey, ENCRYPT_KEY_LEN);
|
||||
tsEncryptionKeyStat = ENCRYPT_KEY_STAT_LOADED;
|
||||
|
||||
code = 0;
|
||||
_OVER:
|
||||
if (content != NULL) taosMemoryFree(content);
|
||||
if (encryptKey != NULL) taosMemoryFree(encryptKey);
|
||||
if (code != 0) {
|
||||
if (terrno == 0) terrno = TAOS_SYSTEM_ERROR(errno);
|
||||
dError("failed to get encrypt key since %s", terrstr());
|
||||
|
|
|
@ -273,8 +273,7 @@ struct STsdbCfg {
|
|||
int32_t keepTimeOffset; // just for save config, use STsdbKeepCfg in STsdb instead
|
||||
SRetention retentions[TSDB_RETENTION_MAX];
|
||||
int32_t encryptAlgorithm;
|
||||
//TODO dmchen len
|
||||
char encryptKey[17];
|
||||
char encryptKey[ENCRYPT_KEY_LEN + 1];
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
|
|
|
@ -154,8 +154,7 @@ static FORCE_INLINE int64_t walScanLogGetLastVer(SWal* pWal, int32_t fileIdx) {
|
|||
|
||||
// validate body
|
||||
int32_t cryptedBodyLen = logContent->head.bodyLen;
|
||||
//TODO: dmchen enum
|
||||
if(pWal->cfg.encryptAlgorithm == 1){
|
||||
if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
|
||||
cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen);
|
||||
}
|
||||
recordLen = walCkHeadSz + cryptedBodyLen;
|
||||
|
@ -627,8 +626,7 @@ int walCheckAndRepairIdxFile(SWal* pWal, int32_t fileIdx) {
|
|||
|
||||
int32_t plainBodyLen = ckHead.head.bodyLen;
|
||||
int32_t cryptedBodyLen = plainBodyLen;
|
||||
//TODO: dmchen enum
|
||||
if(pWal->cfg.encryptAlgorithm == 1){
|
||||
if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
|
||||
cryptedBodyLen = ENCRYPTED_LEN(cryptedBodyLen);
|
||||
}
|
||||
idxEntry.offset += sizeof(SWalCkHead) + cryptedBodyLen;
|
||||
|
|
|
@ -528,8 +528,7 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
|
|||
char* newBody = NULL;
|
||||
char* newBodyEncrypted = NULL;
|
||||
|
||||
//TODO: dmchen enum
|
||||
if(pWal->cfg.encryptAlgorithm == 1){
|
||||
if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
|
||||
cyptedBodyLen = ENCRYPTED_LEN(cyptedBodyLen);
|
||||
char* newBody = taosMemoryMalloc(cyptedBodyLen);
|
||||
if(newBody == NULL){
|
||||
|
@ -571,16 +570,14 @@ static FORCE_INLINE int32_t walWriteImpl(SWal *pWal, int64_t index, tmsg_t msgTy
|
|||
wError("vgId:%d, file:%" PRId64 ".log, failed to write since %s", pWal->cfg.vgId, walGetLastFileFirstVer(pWal),
|
||||
strerror(errno));
|
||||
code = -1;
|
||||
//TODO: dmchen enum
|
||||
if(pWal->cfg.encryptAlgorithm == 1){
|
||||
if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
|
||||
taosMemoryFree(newBody);
|
||||
taosMemoryFree(newBodyEncrypted);
|
||||
}
|
||||
goto END;
|
||||
}
|
||||
|
||||
//TODO: dmchen enum
|
||||
if(pWal->cfg.encryptAlgorithm == 1){
|
||||
if(pWal->cfg.encryptAlgorithm == DND_CA_SM4){
|
||||
taosMemoryFree(newBody);
|
||||
taosMemoryFree(newBodyEncrypted);
|
||||
wInfo("vgId:%d, free newBody newBodyEncrypted %s",
|
||||
|
|
Loading…
Reference in New Issue