diff --git a/util/include/util/tc_consistent_hash.h b/util/include/util/tc_consistent_hash.h index 053adff..c4688f1 100644 --- a/util/include/util/tc_consistent_hash.h +++ b/util/include/util/tc_consistent_hash.h @@ -28,6 +28,7 @@ namespace tars /** * @file tc_consistent_hash.h * @brief 一致性hash算法类. + * @brief Consistency hash algorithm class. */ ///////////////////////////////////////////////// @@ -35,11 +36,13 @@ struct node_T { /** *节点hash值 + *node hash value */ unsigned int iHashCode; /** *节点下标 + *node subscript */ unsigned int iIndex; }; @@ -48,6 +51,7 @@ struct node_T /** * @brief 一致性hash算法类 + * @brief Consistency hash algorithm class. */ class TC_ConsistentHash { @@ -55,6 +59,7 @@ class TC_ConsistentHash /** * @brief 构造函数 + * @brief Constructor */ TC_ConsistentHash() { @@ -62,10 +67,14 @@ class TC_ConsistentHash /** * @brief 节点比较. + * @brief Node comparison. * * @param m1 node_T类型的对象,比较节点之一 + * @param m1 node_T type object, one of the compared nodes * @param m2 node_T类型的对象,比较节点之一 + * @param m2 node_T type object, one of the compared nodes * @return less or not 比较结果,less返回ture,否则返回false + * @return less or not. The result. If the result is 'less', returns true, else returns false. */ static bool less_hash(const node_T & m1, const node_T & m2) { @@ -74,10 +83,14 @@ class TC_ConsistentHash /** * @brief 增加节点. + * @brief the added node * * @param node 节点名称 + * @param node node name * @param index 节点的下标值 + * @param index the node subscript * @return 节点的hash值 + * @return node hash value */ unsigned addNode(const string & node, unsigned int index) { @@ -93,9 +106,12 @@ class TC_ConsistentHash /** * @brief 删除节点. + * @brief Delete the node. * * @param node 节点名称 + * @param node node name * @return 0 : 删除成功 -1 : 没有对应节点 + * @return 0 : delete successfully -1 : no corresponding nodes */ int removeNode(const string & node) { @@ -114,10 +130,14 @@ class TC_ConsistentHash /** * @brief 获取某key对应到的节点node的下标. + * @brief Get the node subscript which corresponds to a certain key. * * @param key key名称 + * @param key key name * @param iIndex 对应到的节点下标 + * @param iIndex the corresponding node subscript * @return 0:获取成功 -1:没有被添加的节点 + * @return 0:obtain successfully -1:no added nodes */ int getIndex(const string & key, unsigned int & iIndex) { @@ -156,9 +176,12 @@ class TC_ConsistentHash protected: /** * @brief 计算md5值的hash,分布范围在 0 -- 2^32-1. + * @brief Calculate the hash of the MD5 value, and the distribution range is 0--2^32-1. * * @param sMd5 md5值 + * @param sNd5 md5 value * @return hash值 + * @return hash value */ unsigned int hash_md5(const string & sMd5) { diff --git a/util/include/util/tc_consistent_hash_new.h b/util/include/util/tc_consistent_hash_new.h index 5ca9a6c..fb6eef1 100755 --- a/util/include/util/tc_consistent_hash_new.h +++ b/util/include/util/tc_consistent_hash_new.h @@ -34,6 +34,7 @@ enum TC_HashAlgorithmType /** * @brief hash 算法虚基类 + * @brief hash Algorithmic Virtual Base Class */ class TC_HashAlgorithm : public TC_HandleBase { @@ -50,6 +51,7 @@ typedef TC_AutoPtr TC_HashAlgorithmPtr; /** * @brief ketama hash 算法 + * @brief Ketama Hash Algorithm */ class TC_KetamaHashAlg : public TC_HashAlgorithm { @@ -60,6 +62,7 @@ public: /** * @brief 默认的 hash 算法 + * @brief Default Hash Algorithm */ class TC_DefaultHashAlg : public TC_HashAlgorithm { @@ -70,6 +73,7 @@ public: /** * @brief hash alg 工厂 + * @brief Hash Algorithm Factory */ class TC_HashAlgFactory { @@ -79,6 +83,7 @@ public: /** * @brief 一致性hash算法类 + * @brief Consistency Hash Algorithm Class */ class TC_ConsistentHashNew { @@ -88,76 +93,99 @@ public: { /** *节点hash值 + *node hash value */ int32_t iHashCode; /** *节点下标 + * node subscript */ unsigned int iIndex; }; /** * @brief 构造函数 + * @brief Constructor */ TC_ConsistentHashNew(); /** * @brief 构造函数 + * @brief Constructor */ TC_ConsistentHashNew(TC_HashAlgorithmType hashType); /** * @brief 排序 + * @brief Sort * * @param node 节点名称 + * @param node node name * @param index 节点的下标值 + * @param index node subscript value */ void sortNode(); /** * @brief 打印节点信息 + * @brief print node info * */ void printNode(); /** * @brief 增加节点. + * @brief add nodes * * @param node 节点名称 + * @param node node name * @param index 节点的下标值 + * @param index node subscript value * @param weight 节点的权重,默认为1 + * @param weight node weight, default value is 1 * @return 是否成功 + * @return whether it is successfull or not */ int addNode(const string & node, unsigned int index, int weight = 1); /** * @brief 获取某key对应到的节点node的下标. + * @brief Gets the subscript of the node to which a key corresponds. * * @param key key名称 + * @param key key name * @param iIndex 对应到的节点下标 + * @param iIndex the subscript of the node to which corresponds. * @return 0:获取成功 -1:没有被添加的节点 + * @return 0:obtain successfully -1:no nodes added */ int getIndex(const string & key, unsigned int & iIndex); /** * @brief 获取某hashcode对应到的节点node的下标. + * @brief Gets the subscript of the node to which a certain hashcode corresponds * * @param hashcode hashcode * @param iIndex 对应到的节点下标 + * @param iIndex the subscript of the node to which corresponds * @return 0:获取成功 -1:没有被添加的节点 + * @return 0:obtain successfully -1:no nodes added */ int getIndex(int32_t hashcode, unsigned int & iIndex); /** * @brief 获取当前hash列表的长度. + * @brief Get the length of the current hash list * * @return 长度值 + * @return length */ size_t size() { return _vHashList.size(); } /** * @brief 清空当前的hash列表. + * @brief Empty the current hash list. * */ void clear() { _vHashList.clear(); } diff --git a/util/include/util/tc_cron.h b/util/include/util/tc_cron.h index 580337f..b3a56db 100644 --- a/util/include/util/tc_cron.h +++ b/util/include/util/tc_cron.h @@ -43,10 +43,14 @@ public: public: /** * @brief 创建一个cron对象 + * @brief Create a cron object * @return cron 对象 + * @return cron object */ // 字段分别为 + // The fields are: // 通配符以及含义 + // Wildcards and their meanings: // * all values selects all values within a field // - range specify ranges // , comma specify additional values @@ -54,6 +58,7 @@ public: // DAYS = { "SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT" }; // MONTHS = { "NIL", "JAN", "FEB", "MAR", "APR", "MAY", "JUN", "JUL", "AUG", "SEP", "OCT", "NOV", "DEC" }; // 各类例子 + // Examples: // CRON Description // * * * * * * Every second // */5 * * * * * Every 5 seconds @@ -69,15 +74,21 @@ public: /** * @brief 获取cron对象的下一个时间点 + * @brief Get the next point in time for the cron object * @param cron 对象 + * @param cron object * @return 如果返回 INVALID_TIME,则是错误时间,否则返回正确的时间戳 + * @return If INVALID_TIME is returned, it is the wrong time. Otherwise the correct timestamp is returned. */ static std::time_t nextcron( const TC_Cron& cron, std::time_t timestamp); /** * @brief 获取cron对象的下一个时间点 + * @brief Get the next point in time for the cron object. * @param cron 对象 + * @param cron object * @return 如果返回 INVALID_TIME,则是错误时间,否则返回正确的时间戳 + * @return If INVALID_TIME is returned, it is the wrong time. Otherwise the correct timestamp is returned. */ static std::time_t nextcron(const TC_Cron& cron); @@ -117,18 +128,22 @@ public: protected: /** * @brief 判断是否包含字符 + * @brief Determine whether it includes characters. * @return true 包含;false 不包含 + * @return true include; false not include */ static bool contains(const std::string &text, char ch) ; /** * @brief 转换成crontab合法数字 + * @brief Convert to crontab legal number * @return cron_int */ static cron_int to_cron_int(const std::string& text); /** * @brief 时间格式转换函数 + * @brief Time format conversion function */ static std::time_t tm_to_time(std::tm& tmt); static std::tm* time_to_tm(std::time_t const* date, std::tm* const out); @@ -136,16 +151,19 @@ protected: protected: /** * @brief 替换周/月的字符为下标 + * @brief Replace week/month characters as Subscripts */ static std::string replaceOrdinals(std::string text, const std::vector & replacement); /** * @brief 获取时间范围,用于计算通配符 + * @brief Gets the time range for calculating wildcards. */ static std::pair makeRange(std::string field, cron_int minval, cron_int maxval); /** * @brief 设置crontab不同的位置标记 + * @brief Set different crontab location tags */ template static void setCronField(std::string value, std::bitset& target, cron_int minval, cron_int maxval); @@ -155,6 +173,7 @@ protected: /** * @brief 计算下一个时间戳 + * @brief Calculate the next timestamp */ template static size_t findNext(const std::bitset & target, std::tm& tmt, unsigned int minimum, unsigned int maximum, unsigned int value, @@ -164,6 +183,7 @@ protected: /** * @brief 位图控制函数 + * @brief Bitmap control function */ template static size_t nextSetbit(const std::bitset & target, size_t minimum, size_t maximum, size_t offset); diff --git a/util/include/util/tc_des.h b/util/include/util/tc_des.h index dbdd060..5950577 100644 --- a/util/include/util/tc_des.h +++ b/util/include/util/tc_des.h @@ -13,6 +13,7 @@ namespace tars /** * @file tc_des.h * @brief des加解密类(翻译至c代码) + * @brief DES encryption and decryption class (translated to C code) * * @author ruanshudong@qq.com */ @@ -21,6 +22,7 @@ namespace tars /** * @brief des异常. + * @brief des exception */ struct TC_DES_Exception : public TC_Exception { @@ -31,24 +33,34 @@ struct TC_DES_Exception : public TC_Exception /** * @brief des/3des加密解密源码, 不依赖任何库. + * @brief Use des/3des to encrypt and decrypt the source code, independent of any library. * * 在网上流行的d3des.h d3des.c修改完成. + * It is modified by the popular 'd3des.h' and 'd3des.c' on the web. * - * 对于des加密,8位密钥,不足8位的右补0x00,多余8位,只取左8位有效. + * 对于des加密,8位密钥,不足8位的右补0x00,多于8位,只取左8位有效. + * For des encryption, use 8-bit key. If it is less than 8 bits, right complete 0x00. If it is more than 8 bits, only the left 8 bits are valid. * * 加密内容8位补齐,补齐方式为:少1位补一个0x01,少2位补两个0x02,... + * The encrypted content follow 8-bit completion, the completion method is: less 1 bit to complete one 0x01, less 2 bits to complete two 0x02,... * * 本身已8位对齐的,后面补八个0x08. + * If itself is 8-bit aligned, complete eight '0x08' at the tail. * * 对于3des加解密,如下:只支持3des-ecb加密方式; + * For 3des encryption and decryption, only 3des-ecb encryption is supported; * * 24位密钥,不足24位的右补0x00,多余24位,只取左24位有效; + * For 24-bit key, if it is less than 24 bits, right complete 0x00. If it is more than 24 bits, only the left 24 bits are valid. * * 加密内容8位补齐,补齐方式为:少1位补一个0x01,少2位补两个0x02,... + * The encrypted content follow 8-bit completion, the completion method is: less 1 bit to complete one 0x01, less 2 bits to complete two 0x02,... * * 本身已8位对齐的,后面补八个0x08. + * If itself is 8-bit aligned, complete eight '0x08' at the tail. * * Key必须是null结束的字符串. + * The key must be a null-terminated string. * */ class TC_Des @@ -56,82 +68,117 @@ class TC_Des public: /** * @brief des加密. + * @brief des encryption * * @param key key, 8个字节 + * @param key key, 8 bits * @param sIn 输入buffer + * @param sIn input buffer * @param iInLen 输入buffer长度 + * @param iInLen input buffer length * @return string 加密后的内容 + * @return string, the encrypted content */ static string encrypt(const char *key, const char *sIn, size_t iInlen); /** * @brief des解密. + * @brief des decryption * * @param key key, 8个字节 + * @param key key, 8 bits * @param sIn 输入buffer + * @param sIn input buffer * @param iInlen 输入buffer长度 + * @param iInLen input buffer length * @return string 解码后的内容, 如果解密失败, 则为空 + * @return string, the decrypted content, if decryption failed, return null. */ static string decrypt(const char *key, const char *sIn, size_t iInlen); /** * @brief 3des加密. + * @brief 3des encryption * * @param key key, 24个字节 + * @param key key, 24 bits * @param sIn 输入buffer + * @param sIn input buffer * @param iInLen 输入buffer长度 + * @param iInLen input buffer length * @return string 加密后的内容 + * @return string, the encrypted content */ static string encrypt3(const char *key, const char *sIn, size_t iInlen); /** * @brief 3des解密. + * @brief 3des decryption * @param key key, 24个字节 + * @param key key, 24 bits * @param sIn 输入buffer + * @param sIn input buffer * @param iInlen 输入buffer长度 + * @param iInLen input buffer length * @return string解码后的内容, 如果解密失败, 则为空 + * @return string, the dcrypted content, if decryption failed, return null. */ static string decrypt3(const char *key, const char *sIn, size_t iInlen); /** * @brief 定义加密/解密 . + * @brief Define Encryption/Decryption */ enum { + /**Encryption*/ EN0 = 0, /**加密*/ + /**Decryption*/ DE1 = 1 /**解密*/ }; protected: /** * @brief 获取key. + * @brief Get key. * * @param key key值 + * @param key key value * @param mode 模式 :0代表加密, 1代表解密 + * @param mode mode : 0(encryption), 1(decryption) */ static void deskey(const char *key, short mode, uint32_t *k); /** * @brief des加密/解密. + * @brief DES Encryption/Decryption * * @param from 8个字节 + * @param from 8 bits * @param to 加密解密只有的8个字节 + * @param to encrypt and decrypt the only 8 bits. */ static void des(const char *from, char *to, uint32_t *KnL); /** * @brief 获取key. + * @brief Get key. * * @param key key值 + * @param key key value * @param mode 模式,0代表加密, 1代表解密 + * @param mode mode : 0(encryption), 1(decryption) */ static void des3key(const char *key, short mode, uint32_t *KnL, uint32_t *KnR, uint32_t *Kn3); /** * @brief 3des. + * @brief 3DES * * @param from 8个字节 + * @param from 8 bits * @param into 加密解密只有的8个字节 + * @param to encrypt and decrypt the only 8 bits. */ static void des3(const char *from, char *into, uint32_t *KnL, uint32_t *KnR, uint32_t *Kn3); diff --git a/util/include/util/tc_dyn_object.h b/util/include/util/tc_dyn_object.h index b1b6c6e..6a0096b 100644 --- a/util/include/util/tc_dyn_object.h +++ b/util/include/util/tc_dyn_object.h @@ -25,12 +25,14 @@ namespace tars /** * @file tc_dyn_object.h * @brief 动态生成类. + * @brief Dynamic Generation Class. */ ///////////////////////////////////////////////// /** * @brief 动态生成类 + * @brief Dynamic Generation Class. */ class TC_DYN_Object; struct TC_DYN_RuntimeClass;