{"action":"created","comment":{"url":"https://api.github.com/repos/gogapp/gatekeeper/pulls/comments/204227405","pull_request_review_id":139274870,"id":204227405,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDIwNDIyNzQwNQ==","diff_hunk":"@@ -0,0 +1,795 @@\n+/*\n+ * Gatekeeper - DoS protection system.\n+ * Copyright (C) 2016 Digirati LTDA.\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License as published by\n+ * the Free Software Foundation, either version 3 of the License, or\n+ * (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ */\n+\n+\n+/*\n+ * This Implementation is similar to the stream summary data structure decribed\n+ * in the research paper on space saving algorithm by Ahmed Metwally,\n+ * Divyakant Agrawal and Amr El Abbadi.\n+ */\n+\n+/* \n+ * TODO #1 : Add a Tree based data structure such as AVL Tree or\n+ * Van Emde Boas Tree to support sublinear bucket update operation.\n+ */\n+\n+/* TODO #2 : Test the written code for correctness */\n+\n+#include <time.h>\n+\n+#include \"space_saving.h\"\n+\n+/* Set up the parameters of a counter bucket */\n+static int\n+setup_bucket_params(unsigned int socket_id, int bkt_size, int bkt_id,\n+\t\tint ip_ver, struct rte_hash_parameters *bkt_hash_params)\n+{\n+\tint ret;\n+\n+\tint key_len = ip_ver == ETHER_TYPE_IPv4 ?\n+\t\t\tsizeof(struct in_addr) : sizeof(struct in6_addr);\n+\n+\tbkt_hash_params->name = NULL;\n+\tbkt_hash_params->entries = bkt_size;\n+\tbkt_hash_params->key_len = key_len;\n+\tbkt_hash_params->hash_func = DEFAULT_HASH_FUNC;\n+\tbkt_hash_params->hash_func_init_val = 0;\n+\tbkt_hash_params->reserved = 0;\n+\n+\tchar bkt_name[64];\n+\tret = snprintf(bkt_name, sizeof(bkt_name), \"Bucket_number_%d_%d\",\n+\t\t\tip_ver, bkt_id);\n+\tRTE_VERIFY(ret > 0 && ret < (int)sizeof(bkt_name));\n+\n+\tbkt_hash_params->name = bkt_name;\n+\tbkt_hash_params->socket_id = socket_id;\n+\n+\treturn ret;\n+}\n+\n+/* Create a counter bucket */\n+static int\n+create_bucket(struct gatekeeper_if *iface, struct gk_config *gk_conf,\n+\t\tint bkt_id)\n+{\n+\tint ret;\n+\tunsigned int socket_id;\n+\tstruct rte_hash_parameters bkt_hash_params;\n+\tstruct counter_bucket *ct_bkt =\n+\t\t(struct counter_bucket *)malloc(sizeof(struct counter_bucket));\n+\n+\tsocket_id = rte_lcore_to_socket_id(gk_conf->lcores[0]);\n+\n+\t/*\n+\t * TODO : How to determine max_size of a bucket ?\n+\t * Currently it has been set to \"10000\" but final values has to be\n+\t * updated after testing.\n+\t */\n+\n+\tif(ipv4_if_configured(iface)) {\n+\t\tret = setup_bucket_params(socket_id, bkt_id, ETHER_TYPE_IPv4,\n+\t\t\t\t\t\t10000, &bkt_hash_params);\n+\t\tif(ret < 0) {\n+\t\t\tRTE_LOG(ERR, HASH, \"The bucket parameters \"\n+\t\t\t\t\"can't be set\\n\");\n+\t\t\tret = -1;\n+\t\t}\n+\n+\t\tct_bkt->bkt.bkt_ip4 = rte_hash_create(&bkt_hash_params);\n+\t\tif(ct_bkt->bkt.bkt_ip4 == NULL) {\n+\t\t\tRTE_LOG(ERR, HASH, \"Bucket number %d could not be \"\n+\t\t\t\t\"created!\\n\",bkt_id);\n+\t\t\tret = -1;\n+\t\t}\n+\t}\n+\n+\tif(ipv6_if_configured(iface)) {\n+\t\tret = setup_bucket_params(socket_id, bkt_id, ETHER_TYPE_IPv6,\n+\t\t\t\t\t\t10000, &bkt_hash_params);\n+\t\tif(ret < 0) {\n+\t\t\tRTE_LOG(ERR, HASH, \"The bucket parameters \"\n+\t\t\t\t\"can't be set\\n\");\n+\t\t\tret = -1;\n+\t\t}\n+\n+\t\tct_bkt->bkt.bkt_ip6 = rte_hash_create(&bkt_hash_params);\n+\t\tif(ct_bkt->bkt.bkt_ip6 == NULL) {\n+\t\t\tRTE_LOG(ERR, HASH, \"Bucket number %d could not be \"\n+\t\t\t\t\"created!\\n\",bkt_id);\n+\t\t\tret = -1;\n+\t\t}\n+\t}\n+\treturn ret;\n+}\n+\n+/* Retuns a pointer to a counter bucket */\n+static int\n+get_bucket(int bkt_id, int proto, struct counter_bucket *ct_bkt)","path":"lib/space_saving.c","position":122,"original_position":122,"commit_id":"5b985ee6c951adcd61e610d6056a068f606cc4b9","original_commit_id":"5b985ee6c951adcd61e610d6056a068f606cc4b9","user":{"login":"mengxiang0811","id":4590679,"node_id":"MDQ6VXNlcjQ1OTA2Nzk=","avatar_url":"https://avatars1.githubusercontent.com/u/4590679?v=4","gravatar_id":"","url":"https://api.github.com/users/mengxiang0811","html_url":"https://github.com/mengxiang0811","followers_url":"https://api.github.com/users/mengxiang0811/followers","following_url":"https://api.github.com/users/mengxiang0811/following{/other_user}","gists_url":"https://api.github.com/users/mengxiang0811/gists{/gist_id}","starred_url":"https://api.github.com/users/mengxiang0811/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mengxiang0811/subscriptions","organizations_url":"https://api.github.com/users/mengxiang0811/orgs","repos_url":"https://api.github.com/users/mengxiang0811/repos","events_url":"https://api.github.com/users/mengxiang0811/events{/privacy}","received_events_url":"https://api.github.com/users/mengxiang0811/received_events","type":"User","site_admin":false},"body":"16 bits are enough for ``proto``.","created_at":"2018-07-22T04:09:32Z","updated_at":"2018-07-22T04:19:34Z","html_url":"https://github.com/gogapp/gatekeeper/pull/1#discussion_r204227405","pull_request_url":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1","author_association":"COLLABORATOR","_links":{"self":{"href":"https://api.github.com/repos/gogapp/gatekeeper/pulls/comments/204227405"},"html":{"href":"https://github.com/gogapp/gatekeeper/pull/1#discussion_r204227405"},"pull_request":{"href":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1","id":195592297,"node_id":"MDExOlB1bGxSZXF1ZXN0MTk1NTkyMjk3","html_url":"https://github.com/gogapp/gatekeeper/pull/1","diff_url":"https://github.com/gogapp/gatekeeper/pull/1.diff","patch_url":"https://github.com/gogapp/gatekeeper/pull/1.patch","issue_url":"https://api.github.com/repos/gogapp/gatekeeper/issues/1","number":1,"state":"open","locked":false,"title":"lib: Implementing Space saving algorithm in Gatekeeper","user":{"login":"gogapp","id":17125516,"node_id":"MDQ6VXNlcjE3MTI1NTE2","avatar_url":"https://avatars2.githubusercontent.com/u/17125516?v=4","gravatar_id":"","url":"https://api.github.com/users/gogapp","html_url":"https://github.com/gogapp","followers_url":"https://api.github.com/users/gogapp/followers","following_url":"https://api.github.com/users/gogapp/following{/other_user}","gists_url":"https://api.github.com/users/gogapp/gists{/gist_id}","starred_url":"https://api.github.com/users/gogapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogapp/subscriptions","organizations_url":"https://api.github.com/users/gogapp/orgs","repos_url":"https://api.github.com/users/gogapp/repos","events_url":"https://api.github.com/users/gogapp/events{/privacy}","received_events_url":"https://api.github.com/users/gogapp/received_events","type":"User","site_admin":false},"body":"This patch implements the space saving algorithm in Gatekeeper","created_at":"2018-06-18T17:15:24Z","updated_at":"2018-07-22T04:19:34Z","closed_at":null,"merged_at":null,"merge_commit_sha":"79da2360f04651648a1e96a9d802fd74f476a2aa","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1/commits","review_comments_url":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1/comments","review_comment_url":"https://api.github.com/repos/gogapp/gatekeeper/pulls/comments{/number}","comments_url":"https://api.github.com/repos/gogapp/gatekeeper/issues/1/comments","statuses_url":"https://api.github.com/repos/gogapp/gatekeeper/statuses/5b985ee6c951adcd61e610d6056a068f606cc4b9","head":{"label":"gogapp:space_saving","ref":"space_saving","sha":"5b985ee6c951adcd61e610d6056a068f606cc4b9","user":{"login":"gogapp","id":17125516,"node_id":"MDQ6VXNlcjE3MTI1NTE2","avatar_url":"https://avatars2.githubusercontent.com/u/17125516?v=4","gravatar_id":"","url":"https://api.github.com/users/gogapp","html_url":"https://github.com/gogapp","followers_url":"https://api.github.com/users/gogapp/followers","following_url":"https://api.github.com/users/gogapp/following{/other_user}","gists_url":"https://api.github.com/users/gogapp/gists{/gist_id}","starred_url":"https://api.github.com/users/gogapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogapp/subscriptions","organizations_url":"https://api.github.com/users/gogapp/orgs","repos_url":"https://api.github.com/users/gogapp/repos","events_url":"https://api.github.com/users/gogapp/events{/privacy}","received_events_url":"https://api.github.com/users/gogapp/received_events","type":"User","site_admin":false},"repo":{"id":135919711,"node_id":"MDEwOlJlcG9zaXRvcnkxMzU5MTk3MTE=","name":"gatekeeper","full_name":"gogapp/gatekeeper","owner":{"login":"gogapp","id":17125516,"node_id":"MDQ6VXNlcjE3MTI1NTE2","avatar_url":"https://avatars2.githubusercontent.com/u/17125516?v=4","gravatar_id":"","url":"https://api.github.com/users/gogapp","html_url":"https://github.com/gogapp","followers_url":"https://api.github.com/users/gogapp/followers","following_url":"https://api.github.com/users/gogapp/following{/other_user}","gists_url":"https://api.github.com/users/gogapp/gists{/gist_id}","starred_url":"https://api.github.com/users/gogapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogapp/subscriptions","organizations_url":"https://api.github.com/users/gogapp/orgs","repos_url":"https://api.github.com/users/gogapp/repos","events_url":"https://api.github.com/users/gogapp/events{/privacy}","received_events_url":"https://api.github.com/users/gogapp/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gogapp/gatekeeper","description":"First open source DDoS protection system","fork":true,"url":"https://api.github.com/repos/gogapp/gatekeeper","forks_url":"https://api.github.com/repos/gogapp/gatekeeper/forks","keys_url":"https://api.github.com/repos/gogapp/gatekeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gogapp/gatekeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gogapp/gatekeeper/teams","hooks_url":"https://api.github.com/repos/gogapp/gatekeeper/hooks","issue_events_url":"https://api.github.com/repos/gogapp/gatekeeper/issues/events{/number}","events_url":"https://api.github.com/repos/gogapp/gatekeeper/events","assignees_url":"https://api.github.com/repos/gogapp/gatekeeper/assignees{/user}","branches_url":"https://api.github.com/repos/gogapp/gatekeeper/branches{/branch}","tags_url":"https://api.github.com/repos/gogapp/gatekeeper/tags","blobs_url":"https://api.github.com/repos/gogapp/gatekeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gogapp/gatekeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gogapp/gatekeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/gogapp/gatekeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gogapp/gatekeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/gogapp/gatekeeper/languages","stargazers_url":"https://api.github.com/repos/gogapp/gatekeeper/stargazers","contributors_url":"https://api.github.com/repos/gogapp/gatekeeper/contributors","subscribers_url":"https://api.github.com/repos/gogapp/gatekeeper/subscribers","subscription_url":"https://api.github.com/repos/gogapp/gatekeeper/subscription","commits_url":"https://api.github.com/repos/gogapp/gatekeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/gogapp/gatekeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/gogapp/gatekeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/gogapp/gatekeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/gogapp/gatekeeper/contents/{+path}","compare_url":"https://api.github.com/repos/gogapp/gatekeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gogapp/gatekeeper/merges","archive_url":"https://api.github.com/repos/gogapp/gatekeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gogapp/gatekeeper/downloads","issues_url":"https://api.github.com/repos/gogapp/gatekeeper/issues{/number}","pulls_url":"https://api.github.com/repos/gogapp/gatekeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/gogapp/gatekeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/gogapp/gatekeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gogapp/gatekeeper/labels{/name}","releases_url":"https://api.github.com/repos/gogapp/gatekeeper/releases{/id}","deployments_url":"https://api.github.com/repos/gogapp/gatekeeper/deployments","created_at":"2018-06-03T16:10:53Z","updated_at":"2018-06-03T16:31:54Z","pushed_at":"2018-07-09T17:49:18Z","git_url":"git://github.com/gogapp/gatekeeper.git","ssh_url":"git@github.com:gogapp/gatekeeper.git","clone_url":"https://github.com/gogapp/gatekeeper.git","svn_url":"https://github.com/gogapp/gatekeeper","homepage":"","size":523,"stargazers_count":2,"watchers_count":2,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"base":{"label":"gogapp:master","ref":"master","sha":"80a665bc282e3deb3d8d6a212e9aad6360e7864f","user":{"login":"gogapp","id":17125516,"node_id":"MDQ6VXNlcjE3MTI1NTE2","avatar_url":"https://avatars2.githubusercontent.com/u/17125516?v=4","gravatar_id":"","url":"https://api.github.com/users/gogapp","html_url":"https://github.com/gogapp","followers_url":"https://api.github.com/users/gogapp/followers","following_url":"https://api.github.com/users/gogapp/following{/other_user}","gists_url":"https://api.github.com/users/gogapp/gists{/gist_id}","starred_url":"https://api.github.com/users/gogapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogapp/subscriptions","organizations_url":"https://api.github.com/users/gogapp/orgs","repos_url":"https://api.github.com/users/gogapp/repos","events_url":"https://api.github.com/users/gogapp/events{/privacy}","received_events_url":"https://api.github.com/users/gogapp/received_events","type":"User","site_admin":false},"repo":{"id":135919711,"node_id":"MDEwOlJlcG9zaXRvcnkxMzU5MTk3MTE=","name":"gatekeeper","full_name":"gogapp/gatekeeper","owner":{"login":"gogapp","id":17125516,"node_id":"MDQ6VXNlcjE3MTI1NTE2","avatar_url":"https://avatars2.githubusercontent.com/u/17125516?v=4","gravatar_id":"","url":"https://api.github.com/users/gogapp","html_url":"https://github.com/gogapp","followers_url":"https://api.github.com/users/gogapp/followers","following_url":"https://api.github.com/users/gogapp/following{/other_user}","gists_url":"https://api.github.com/users/gogapp/gists{/gist_id}","starred_url":"https://api.github.com/users/gogapp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gogapp/subscriptions","organizations_url":"https://api.github.com/users/gogapp/orgs","repos_url":"https://api.github.com/users/gogapp/repos","events_url":"https://api.github.com/users/gogapp/events{/privacy}","received_events_url":"https://api.github.com/users/gogapp/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/gogapp/gatekeeper","description":"First open source DDoS protection system","fork":true,"url":"https://api.github.com/repos/gogapp/gatekeeper","forks_url":"https://api.github.com/repos/gogapp/gatekeeper/forks","keys_url":"https://api.github.com/repos/gogapp/gatekeeper/keys{/key_id}","collaborators_url":"https://api.github.com/repos/gogapp/gatekeeper/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/gogapp/gatekeeper/teams","hooks_url":"https://api.github.com/repos/gogapp/gatekeeper/hooks","issue_events_url":"https://api.github.com/repos/gogapp/gatekeeper/issues/events{/number}","events_url":"https://api.github.com/repos/gogapp/gatekeeper/events","assignees_url":"https://api.github.com/repos/gogapp/gatekeeper/assignees{/user}","branches_url":"https://api.github.com/repos/gogapp/gatekeeper/branches{/branch}","tags_url":"https://api.github.com/repos/gogapp/gatekeeper/tags","blobs_url":"https://api.github.com/repos/gogapp/gatekeeper/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/gogapp/gatekeeper/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/gogapp/gatekeeper/git/refs{/sha}","trees_url":"https://api.github.com/repos/gogapp/gatekeeper/git/trees{/sha}","statuses_url":"https://api.github.com/repos/gogapp/gatekeeper/statuses/{sha}","languages_url":"https://api.github.com/repos/gogapp/gatekeeper/languages","stargazers_url":"https://api.github.com/repos/gogapp/gatekeeper/stargazers","contributors_url":"https://api.github.com/repos/gogapp/gatekeeper/contributors","subscribers_url":"https://api.github.com/repos/gogapp/gatekeeper/subscribers","subscription_url":"https://api.github.com/repos/gogapp/gatekeeper/subscription","commits_url":"https://api.github.com/repos/gogapp/gatekeeper/commits{/sha}","git_commits_url":"https://api.github.com/repos/gogapp/gatekeeper/git/commits{/sha}","comments_url":"https://api.github.com/repos/gogapp/gatekeeper/comments{/number}","issue_comment_url":"https://api.github.com/repos/gogapp/gatekeeper/issues/comments{/number}","contents_url":"https://api.github.com/repos/gogapp/gatekeeper/contents/{+path}","compare_url":"https://api.github.com/repos/gogapp/gatekeeper/compare/{base}...{head}","merges_url":"https://api.github.com/repos/gogapp/gatekeeper/merges","archive_url":"https://api.github.com/repos/gogapp/gatekeeper/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/gogapp/gatekeeper/downloads","issues_url":"https://api.github.com/repos/gogapp/gatekeeper/issues{/number}","pulls_url":"https://api.github.com/repos/gogapp/gatekeeper/pulls{/number}","milestones_url":"https://api.github.com/repos/gogapp/gatekeeper/milestones{/number}","notifications_url":"https://api.github.com/repos/gogapp/gatekeeper/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/gogapp/gatekeeper/labels{/name}","releases_url":"https://api.github.com/repos/gogapp/gatekeeper/releases{/id}","deployments_url":"https://api.github.com/repos/gogapp/gatekeeper/deployments","created_at":"2018-06-03T16:10:53Z","updated_at":"2018-06-03T16:31:54Z","pushed_at":"2018-07-09T17:49:18Z","git_url":"git://github.com/gogapp/gatekeeper.git","ssh_url":"git@github.com:gogapp/gatekeeper.git","clone_url":"https://github.com/gogapp/gatekeeper.git","svn_url":"https://github.com/gogapp/gatekeeper","homepage":"","size":523,"stargazers_count":2,"watchers_count":2,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"open_issues_count":1,"license":{"key":"gpl-3.0","name":"GNU General Public License v3.0","spdx_id":"GPL-3.0","url":"https://api.github.com/licenses/gpl-3.0","node_id":"MDc6TGljZW5zZTk="},"forks":0,"open_issues":1,"watchers":2,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1"},"html":{"href":"https://github.com/gogapp/gatekeeper/pull/1"},"issue":{"href":"https://api.github.com/repos/gogapp/gatekeeper/issues/1"},"comments":{"href":"https://api.github.com/repos/gogapp/gatekeeper/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/gogapp/gatekeeper/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/gogapp/gatekeeper/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/gogapp/gatekeeper/statuses/5b985ee6c951adcd61e610d6056a068f606cc4b9"}},"author_association":"OWNER"}}
{"actor":{"display_login":"mengxiang0811"}}