{"id":19965534,"url":"https://github.com/tencent/libwxfreq","last_synced_at":"2025-09-02T10:37:03.840Z","repository":{"id":71777440,"uuid":"108090931","full_name":"Tencent/libwxfreq","owner":"Tencent","description":"libwxfreq is a generic high performance frequency limitation library","archived":false,"fork":false,"pushed_at":"2023-04-07T11:42:03.000Z","size":68,"stargazers_count":191,"open_issues_count":0,"forks_count":55,"subscribers_count":24,"default_branch":"master","last_synced_at":"2025-04-24T01:41:23.884Z","etag":null,"topics":["frequency"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tencent.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.TXT","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS"}},"created_at":"2017-10-24T07:17:48.000Z","updated_at":"2025-03-12T07:28:55.000Z","dependencies_parsed_at":"2024-01-13T16:25:06.194Z","dependency_job_id":"5d01ddc7-2dbd-451e-981b-33c8998eb279","html_url":"https://github.com/Tencent/libwxfreq","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/Tencent/libwxfreq","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2Flibwxfreq","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2Flibwxfreq/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2Flibwxfreq/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2Flibwxfreq/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tencent","download_url":"https://codeload.github.com/Tencent/libwxfreq/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tencent%2Flibwxfreq/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":273271980,"owners_count":25075971,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-09-02T02:00:09.530Z","response_time":77,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["frequency"],"created_at":"2024-11-13T02:29:24.757Z","updated_at":"2025-09-02T10:37:03.814Z","avatar_url":"https://github.com/Tencent.png","language":"C++","funding_links":[],"categories":[],"sub_categories":[],"readme":"# libwxfreq\n\n## 编译\n  1. 编译lib: make libwxfreq.a\n  2. 编译server: 依赖libevent库，所以要修改DIRLIBEVENT变量为libevent.a所在目录，并确定libevent相关头文件在头文件搜索路径中， 运行make\n\n## 安装\n  1. 修改makefile文件中的HEADERINSTALLDIR和LIBINSTALLDIR变量\n  2. make install\n\n## 单元测试\n  1. 以测试文件为目标make. 例如: make demo\n\n## 简介\n  libwxfreq是一个高性能频率限制库。通过简洁的几个接口便可以实现通用的可配置的频率\n限制功能。配合其他网络框架，便可以实现一个通用的高性能频率控制服务。\n\n## 特点：\n  1. 高度可配置。统计时长可配，规则可配。\n  2. 支持任意key类型。\n \n## 配置文件\n  1. 格式\n   \n   appid的元信息，指明apppid的统计时长。默认第一个统计时长是60s，第二个统计时  \n   时长是3600s， 第三个是86400s。可以手动修改任何一个统计时长为[0, 86400]  \n\n  [appid]\n  \n  5 = 30, 60, 90 // appid为5的统计时长分别是30s 60s 90s  \n  25 = 10, 60   // appid为25的统计时长分别是10s 60s 86400s  \n \n  频率规则， 用于说明某个appid的阈值， 拦截等级等  \n  [match_rule_name] // 规则名字，用户指明中了哪条规则  \n  match_appid = 5   // 匹配的appid                              \n  block_level = 1  // 拦截等级， 大于0  \n  rule_type = user // 规则对应的key类型  \n  item = min_interval \u003e= 4 // 具体的阈值表达式， 支持大于和等于\n  ```\n  min_interval 表示第一个统计时长的统计值，                  \n  mid_interval 表示第二个统计时长的统计值，                        \n  max_interval 表示第三个统计时长的统计值.\n  ```\n\n  2. 例子\n  ```\n  [appid]\n  100 = 30, 60, 90\n\n  [rule1]\n  match_appid = 100\n  item =  min_interval \u003e= 10\n  block_level = 1\n  rule_type = user\n\n  [rule2]\n  match_appid = 100\n  item =  mid_interval \u003e= 15 \n  block_level = 1\n  rule_type = user\n\n  [rule3]\n  match_appid = 100\n  item =  max_interval \u003e= 20\n  block_level = 1\n  rule_type = user\n\n  [rule4]\n  match_appid = 100\n  item =  min_interval \u003e= 100\n  block_level = 1\n  rule_type = ip \n\n  [rule5]\n  match_appid = 100\n  item =  mid_interval \u003e= 150\n  block_level = 1\n  rule_type = ip \n\n  [rule6]\n  match_appid = 100\n  item =  max_interval \u003e= 200 \n  block_level = 1\n  rule_type = ip \n  ```\n\n## API接口\n\n  设置规则配置文件\n  \u003e void SetRuleConfFile(const char *filename);\n\n  注册一个新的统计维度。type_name 指明类型名称， zero_init标志初始化时是否需要\n  初始化为0， key 是共享内存key，item_cnt 表示共享内存大小，最大能统计的item个\n  数。\n  \u003e int RegisterNewShmStat(const char* type_name, bool zero_init, key_t key,\n  \u003e                      unsigned int item_cnt);\n\n  系统初始化\n  \u003e bool InitFreq();\n\n  上报一次频率到系统中。type_name 是统计类型，说明key的含义。 key是主体标识，\n  appid 是业务标识， cnt 表示本次需要累加的次数。 例如，统计QQ号为3402393864的\n  用户在appid为5的服务上的频率，使用ReportAndCheck(\"user\", 3402393864, 5, 1);\n  同样统计ip为202.204.105.8访问appid的5的频率，使用ReportAndCheck( \"IP\", \n  3402393864, 5, 1); 因为202.204.105.8的整形表示也是3402393864。type_name指明了\n  key的含义。\n  \u003e struct BlockResult ReportAndCheck(const char* type_name, const char *key,\n  \u003e                                   const uint32_t appid, const uint32_t cnt);\n\n  只检查当前是否中频率\n  \u003e struct BlockResult OnlyCheck(const char* type_name, const char *key,\n  \u003e                             const uint32_t appid);\n\n  只上报，不检查\n  \u003e int OnlyReport(const char* type_name, const char *key, const uint32_t appid,\n  \u003e              const uint32_t cnt);\n\n  获取频率统计值, cnt为0获取当前统计值，不为零表示先累计再获取\n  \u003e struct FreqCache GetCache(const char* type_name, const char *key,\n  \u003e                          const uint32_t appid, const uint32_t cnt = 0);\n\n  加白操作，linger_time表示加白有效期\n  \u003e int AddWhite(const char* type_name, const char *key, const uint32_t appid,\n  \u003e            const uint32_t linger_time);\n\n  删除白名单\n  \u003e int DeleteWhite(const char* type_name, const char *key, const uint32_t appid);\n\n  手动加拦截\n  \u003e int AddBlock(const char* type_name, const char *key, const uint32_t appid,\n  \u003e            const uint32_t linger_time, const uint32_t block_level);\n\n  手动删除拦截\n  \u003e int DeleteBlock(const char* type_name, const char *key, const uint32_t appid);\n\n  设置写日志方法，默认写本地文件/tmp/libwxfreq.log\n  \u003e void SetLogFunc(LogFunction logfunc);\n\n  设置重启时恢复白名单/拦截方法，默认从本地文件/tmp/libwxfreq_db.$type_name读取\n  \u003e void SetLoadFunc(LoadFunc func);\n\n  设置白名单/加拦截数据持久化方法。默认写本地文件/tmp/libwxfreq_db.$type_name\n  \u003e void SetDumpFunc(DumpFunc func);\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftencent%2Flibwxfreq","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftencent%2Flibwxfreq","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftencent%2Flibwxfreq/lists"}