{"action":"created","comment":{"url":"https://api.github.com/repos/awslabs/s2n/pulls/comments/312579608","pull_request_review_id":273269906,"id":312579608,"node_id":"MDI0OlB1bGxSZXF1ZXN0UmV2aWV3Q29tbWVudDMxMjU3OTYwOA==","diff_hunk":"@@ -441,6 +444,52 @@ int s2n_conn_set_handshake_no_client_cert(struct s2n_connection *conn) {\n     return 0;\n }\n \n+const char *s2n_connection_get_handshake_type_name(struct s2n_connection *conn) \n+{\n+    notnull_check_ptr(conn);\n+\n+    int handshake_type = conn->handshake.handshake_type;\n+\n+    if (handshake_type_str[handshake_type][0] != '\\0') {\n+        return handshake_type_str[handshake_type];\n+    }\n+\n+    /* Compute handshake_type_str[handshake_type] */\n+    char *p = handshake_type_str[handshake_type];\n+    char *end = p + sizeof(handshake_type_str[0]);\n+    if (handshake_type > INITIAL) {","path":"tls/s2n_handshake_io.c","position":34,"original_position":34,"commit_id":"77b71b7e19adcb467321d6f231adf6399139afa1","original_commit_id":"5b3396cf91f5c992aafac246bc74e6402f167fdf","user":{"login":"fatrat1117","id":5492193,"node_id":"MDQ6VXNlcjU0OTIxOTM=","avatar_url":"https://avatars1.githubusercontent.com/u/5492193?v=4","gravatar_id":"","url":"https://api.github.com/users/fatrat1117","html_url":"https://github.com/fatrat1117","followers_url":"https://api.github.com/users/fatrat1117/followers","following_url":"https://api.github.com/users/fatrat1117/following{/other_user}","gists_url":"https://api.github.com/users/fatrat1117/gists{/gist_id}","starred_url":"https://api.github.com/users/fatrat1117/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatrat1117/subscriptions","organizations_url":"https://api.github.com/users/fatrat1117/orgs","repos_url":"https://api.github.com/users/fatrat1117/repos","events_url":"https://api.github.com/users/fatrat1117/events{/privacy}","received_events_url":"https://api.github.com/users/fatrat1117/received_events","type":"User","site_admin":false},"body":"> instead of a list of if statements, have you considered keeping both the handshake types and string representations in an array, then calculate the string representation by iterating through the array and comparing bitwise?\r\nI like your idea to eliminate if statements. I did not feel very strong about this though. \r\n\r\nThere are pro and cons:\r\nMy approach:\r\nPros:\r\nSimple and faster. Space complexity for those ifs O(1). \r\nCons:\r\nMaybe we think it will be too many ifs but how many bits will be there in future. Currently, only 7 bits up to 0x40. I think 7 ifs is fine.  \r\n\r\nThe proposed approach:\r\nPros: \r\nCode could be shorter but the code example is wrong...\r\nCons:\r\n1st example: two array, space complexity O(n).\r\n2nd example: one array using 0x40 as an array index... space complexity O(n * n)\r\nWhat do we gain here if we do not have cache?\r\n\r\n> \r\n> eg.\r\n> \r\n> ```c\r\n> int handshake_types[] = { INITIAL, NEGOTIATED, FULL_HANDSHAKE...}\r\n> char* handshake_type_names[] = { \"INITIAL\", \"NEGOTIATED\", \"FULL_HANDSHAKE\"...}\r\n> ```\r\n> \r\nin c, we use const char* to represent const string\r\n```c\r\nconst char* handshake_type_names[] = { \"INITIAL\", \"NEGOTIATED\", \"FULL_HANDSHAKE\"...}\r\n```\r\n\r\n>\r\n> or\r\n> \r\n> ```c\r\n> handshake_type_names[][] = { [INITIAL] = \"INITIAL\", [NEGOTIATED] = \"NEGOTIATED\"... }\r\n> ```\r\n> \r\nWe might want a good reason for wasted spaces.\r\n\r\n> then\r\n> \r\n> ```c\r\n> for (int i = 0; i < size; i++) {\r\n>    if (handshake_type >> (i - 1) & 1) ...\r\n> }\r\n> ```\r\nThis won't work as right shift 0 >> -1 & 1 will not compile... Plus, you still need to handle INITIAL(0x0) separately. ","created_at":"2019-08-09T17:32:28Z","updated_at":"2019-08-09T17:32:28Z","html_url":"https://github.com/awslabs/s2n/pull/1133#discussion_r312579608","pull_request_url":"https://api.github.com/repos/awslabs/s2n/pulls/1133","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/awslabs/s2n/pulls/comments/312579608"},"html":{"href":"https://github.com/awslabs/s2n/pull/1133#discussion_r312579608"},"pull_request":{"href":"https://api.github.com/repos/awslabs/s2n/pulls/1133"}},"in_reply_to_id":312312551},"pull_request":{"url":"https://api.github.com/repos/awslabs/s2n/pulls/1133","id":305271322,"node_id":"MDExOlB1bGxSZXF1ZXN0MzA1MjcxMzIy","html_url":"https://github.com/awslabs/s2n/pull/1133","diff_url":"https://github.com/awslabs/s2n/pull/1133.diff","patch_url":"https://github.com/awslabs/s2n/pull/1133.patch","issue_url":"https://api.github.com/repos/awslabs/s2n/issues/1133","number":1133,"state":"open","locked":false,"title":"Add 2 new APIs to get handshake type","user":{"login":"fatrat1117","id":5492193,"node_id":"MDQ6VXNlcjU0OTIxOTM=","avatar_url":"https://avatars1.githubusercontent.com/u/5492193?v=4","gravatar_id":"","url":"https://api.github.com/users/fatrat1117","html_url":"https://github.com/fatrat1117","followers_url":"https://api.github.com/users/fatrat1117/followers","following_url":"https://api.github.com/users/fatrat1117/following{/other_user}","gists_url":"https://api.github.com/users/fatrat1117/gists{/gist_id}","starred_url":"https://api.github.com/users/fatrat1117/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatrat1117/subscriptions","organizations_url":"https://api.github.com/users/fatrat1117/orgs","repos_url":"https://api.github.com/users/fatrat1117/repos","events_url":"https://api.github.com/users/fatrat1117/events{/privacy}","received_events_url":"https://api.github.com/users/fatrat1117/received_events","type":"User","site_admin":false},"body":"**Issue # (if available):** \r\n\r\n**Description of changes:** \r\nAdd 2 new APIs to get handshake type.\r\n\r\nBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.\r\n","created_at":"2019-08-07T18:36:55Z","updated_at":"2019-08-09T17:32:28Z","closed_at":null,"merged_at":null,"merge_commit_sha":"85ab25f5708f5790801a787ad3b91ac9efdd71cb","assignee":null,"assignees":[],"requested_reviewers":[],"requested_teams":[],"labels":[],"milestone":null,"commits_url":"https://api.github.com/repos/awslabs/s2n/pulls/1133/commits","review_comments_url":"https://api.github.com/repos/awslabs/s2n/pulls/1133/comments","review_comment_url":"https://api.github.com/repos/awslabs/s2n/pulls/comments{/number}","comments_url":"https://api.github.com/repos/awslabs/s2n/issues/1133/comments","statuses_url":"https://api.github.com/repos/awslabs/s2n/statuses/77b71b7e19adcb467321d6f231adf6399139afa1","head":{"label":"fatrat1117:handshake_type","ref":"handshake_type","sha":"77b71b7e19adcb467321d6f231adf6399139afa1","user":{"login":"fatrat1117","id":5492193,"node_id":"MDQ6VXNlcjU0OTIxOTM=","avatar_url":"https://avatars1.githubusercontent.com/u/5492193?v=4","gravatar_id":"","url":"https://api.github.com/users/fatrat1117","html_url":"https://github.com/fatrat1117","followers_url":"https://api.github.com/users/fatrat1117/followers","following_url":"https://api.github.com/users/fatrat1117/following{/other_user}","gists_url":"https://api.github.com/users/fatrat1117/gists{/gist_id}","starred_url":"https://api.github.com/users/fatrat1117/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatrat1117/subscriptions","organizations_url":"https://api.github.com/users/fatrat1117/orgs","repos_url":"https://api.github.com/users/fatrat1117/repos","events_url":"https://api.github.com/users/fatrat1117/events{/privacy}","received_events_url":"https://api.github.com/users/fatrat1117/received_events","type":"User","site_admin":false},"repo":{"id":141476967,"node_id":"MDEwOlJlcG9zaXRvcnkxNDE0NzY5Njc=","name":"s2n","full_name":"fatrat1117/s2n","private":false,"owner":{"login":"fatrat1117","id":5492193,"node_id":"MDQ6VXNlcjU0OTIxOTM=","avatar_url":"https://avatars1.githubusercontent.com/u/5492193?v=4","gravatar_id":"","url":"https://api.github.com/users/fatrat1117","html_url":"https://github.com/fatrat1117","followers_url":"https://api.github.com/users/fatrat1117/followers","following_url":"https://api.github.com/users/fatrat1117/following{/other_user}","gists_url":"https://api.github.com/users/fatrat1117/gists{/gist_id}","starred_url":"https://api.github.com/users/fatrat1117/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fatrat1117/subscriptions","organizations_url":"https://api.github.com/users/fatrat1117/orgs","repos_url":"https://api.github.com/users/fatrat1117/repos","events_url":"https://api.github.com/users/fatrat1117/events{/privacy}","received_events_url":"https://api.github.com/users/fatrat1117/received_events","type":"User","site_admin":false},"html_url":"https://github.com/fatrat1117/s2n","description":"s2n : an implementation of the TLS/SSL protocols","fork":true,"url":"https://api.github.com/repos/fatrat1117/s2n","forks_url":"https://api.github.com/repos/fatrat1117/s2n/forks","keys_url":"https://api.github.com/repos/fatrat1117/s2n/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fatrat1117/s2n/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fatrat1117/s2n/teams","hooks_url":"https://api.github.com/repos/fatrat1117/s2n/hooks","issue_events_url":"https://api.github.com/repos/fatrat1117/s2n/issues/events{/number}","events_url":"https://api.github.com/repos/fatrat1117/s2n/events","assignees_url":"https://api.github.com/repos/fatrat1117/s2n/assignees{/user}","branches_url":"https://api.github.com/repos/fatrat1117/s2n/branches{/branch}","tags_url":"https://api.github.com/repos/fatrat1117/s2n/tags","blobs_url":"https://api.github.com/repos/fatrat1117/s2n/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fatrat1117/s2n/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fatrat1117/s2n/git/refs{/sha}","trees_url":"https://api.github.com/repos/fatrat1117/s2n/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fatrat1117/s2n/statuses/{sha}","languages_url":"https://api.github.com/repos/fatrat1117/s2n/languages","stargazers_url":"https://api.github.com/repos/fatrat1117/s2n/stargazers","contributors_url":"https://api.github.com/repos/fatrat1117/s2n/contributors","subscribers_url":"https://api.github.com/repos/fatrat1117/s2n/subscribers","subscription_url":"https://api.github.com/repos/fatrat1117/s2n/subscription","commits_url":"https://api.github.com/repos/fatrat1117/s2n/commits{/sha}","git_commits_url":"https://api.github.com/repos/fatrat1117/s2n/git/commits{/sha}","comments_url":"https://api.github.com/repos/fatrat1117/s2n/comments{/number}","issue_comment_url":"https://api.github.com/repos/fatrat1117/s2n/issues/comments{/number}","contents_url":"https://api.github.com/repos/fatrat1117/s2n/contents/{+path}","compare_url":"https://api.github.com/repos/fatrat1117/s2n/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fatrat1117/s2n/merges","archive_url":"https://api.github.com/repos/fatrat1117/s2n/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fatrat1117/s2n/downloads","issues_url":"https://api.github.com/repos/fatrat1117/s2n/issues{/number}","pulls_url":"https://api.github.com/repos/fatrat1117/s2n/pulls{/number}","milestones_url":"https://api.github.com/repos/fatrat1117/s2n/milestones{/number}","notifications_url":"https://api.github.com/repos/fatrat1117/s2n/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fatrat1117/s2n/labels{/name}","releases_url":"https://api.github.com/repos/fatrat1117/s2n/releases{/id}","deployments_url":"https://api.github.com/repos/fatrat1117/s2n/deployments","created_at":"2018-07-18T18:52:08Z","updated_at":"2019-05-14T21:30:50Z","pushed_at":"2019-08-08T23:12:04Z","git_url":"git://github.com/fatrat1117/s2n.git","ssh_url":"git@github.com:fatrat1117/s2n.git","clone_url":"https://github.com/fatrat1117/s2n.git","svn_url":"https://github.com/fatrat1117/s2n","homepage":"","size":6877,"stargazers_count":0,"watchers_count":0,"language":"C","has_issues":false,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":0,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"awslabs:master","ref":"master","sha":"44b8e43b0683e8f36a63cc3875c1b053b842f63d","user":{"login":"awslabs","id":3299148,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyOTkxNDg=","avatar_url":"https://avatars0.githubusercontent.com/u/3299148?v=4","gravatar_id":"","url":"https://api.github.com/users/awslabs","html_url":"https://github.com/awslabs","followers_url":"https://api.github.com/users/awslabs/followers","following_url":"https://api.github.com/users/awslabs/following{/other_user}","gists_url":"https://api.github.com/users/awslabs/gists{/gist_id}","starred_url":"https://api.github.com/users/awslabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awslabs/subscriptions","organizations_url":"https://api.github.com/users/awslabs/orgs","repos_url":"https://api.github.com/users/awslabs/repos","events_url":"https://api.github.com/users/awslabs/events{/privacy}","received_events_url":"https://api.github.com/users/awslabs/received_events","type":"Organization","site_admin":false},"repo":{"id":21287076,"node_id":"MDEwOlJlcG9zaXRvcnkyMTI4NzA3Ng==","name":"s2n","full_name":"awslabs/s2n","private":false,"owner":{"login":"awslabs","id":3299148,"node_id":"MDEyOk9yZ2FuaXphdGlvbjMyOTkxNDg=","avatar_url":"https://avatars0.githubusercontent.com/u/3299148?v=4","gravatar_id":"","url":"https://api.github.com/users/awslabs","html_url":"https://github.com/awslabs","followers_url":"https://api.github.com/users/awslabs/followers","following_url":"https://api.github.com/users/awslabs/following{/other_user}","gists_url":"https://api.github.com/users/awslabs/gists{/gist_id}","starred_url":"https://api.github.com/users/awslabs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/awslabs/subscriptions","organizations_url":"https://api.github.com/users/awslabs/orgs","repos_url":"https://api.github.com/users/awslabs/repos","events_url":"https://api.github.com/users/awslabs/events{/privacy}","received_events_url":"https://api.github.com/users/awslabs/received_events","type":"Organization","site_admin":false},"html_url":"https://github.com/awslabs/s2n","description":"s2n : an implementation of the TLS/SSL protocols","fork":false,"url":"https://api.github.com/repos/awslabs/s2n","forks_url":"https://api.github.com/repos/awslabs/s2n/forks","keys_url":"https://api.github.com/repos/awslabs/s2n/keys{/key_id}","collaborators_url":"https://api.github.com/repos/awslabs/s2n/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/awslabs/s2n/teams","hooks_url":"https://api.github.com/repos/awslabs/s2n/hooks","issue_events_url":"https://api.github.com/repos/awslabs/s2n/issues/events{/number}","events_url":"https://api.github.com/repos/awslabs/s2n/events","assignees_url":"https://api.github.com/repos/awslabs/s2n/assignees{/user}","branches_url":"https://api.github.com/repos/awslabs/s2n/branches{/branch}","tags_url":"https://api.github.com/repos/awslabs/s2n/tags","blobs_url":"https://api.github.com/repos/awslabs/s2n/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/awslabs/s2n/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/awslabs/s2n/git/refs{/sha}","trees_url":"https://api.github.com/repos/awslabs/s2n/git/trees{/sha}","statuses_url":"https://api.github.com/repos/awslabs/s2n/statuses/{sha}","languages_url":"https://api.github.com/repos/awslabs/s2n/languages","stargazers_url":"https://api.github.com/repos/awslabs/s2n/stargazers","contributors_url":"https://api.github.com/repos/awslabs/s2n/contributors","subscribers_url":"https://api.github.com/repos/awslabs/s2n/subscribers","subscription_url":"https://api.github.com/repos/awslabs/s2n/subscription","commits_url":"https://api.github.com/repos/awslabs/s2n/commits{/sha}","git_commits_url":"https://api.github.com/repos/awslabs/s2n/git/commits{/sha}","comments_url":"https://api.github.com/repos/awslabs/s2n/comments{/number}","issue_comment_url":"https://api.github.com/repos/awslabs/s2n/issues/comments{/number}","contents_url":"https://api.github.com/repos/awslabs/s2n/contents/{+path}","compare_url":"https://api.github.com/repos/awslabs/s2n/compare/{base}...{head}","merges_url":"https://api.github.com/repos/awslabs/s2n/merges","archive_url":"https://api.github.com/repos/awslabs/s2n/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/awslabs/s2n/downloads","issues_url":"https://api.github.com/repos/awslabs/s2n/issues{/number}","pulls_url":"https://api.github.com/repos/awslabs/s2n/pulls{/number}","milestones_url":"https://api.github.com/repos/awslabs/s2n/milestones{/number}","notifications_url":"https://api.github.com/repos/awslabs/s2n/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/awslabs/s2n/labels{/name}","releases_url":"https://api.github.com/repos/awslabs/s2n/releases{/id}","deployments_url":"https://api.github.com/repos/awslabs/s2n/deployments","created_at":"2014-06-27T19:37:59Z","updated_at":"2019-08-08T12:09:49Z","pushed_at":"2019-08-08T23:12:06Z","git_url":"git://github.com/awslabs/s2n.git","ssh_url":"git@github.com:awslabs/s2n.git","clone_url":"https://github.com/awslabs/s2n.git","svn_url":"https://github.com/awslabs/s2n","homepage":"","size":6851,"stargazers_count":3486,"watchers_count":3486,"language":"C","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":408,"mirror_url":null,"archived":false,"disabled":false,"open_issues_count":206,"license":{"key":"apache-2.0","name":"Apache License 2.0","spdx_id":"Apache-2.0","url":"https://api.github.com/licenses/apache-2.0","node_id":"MDc6TGljZW5zZTI="},"forks":408,"open_issues":206,"watchers":3486,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/awslabs/s2n/pulls/1133"},"html":{"href":"https://github.com/awslabs/s2n/pull/1133"},"issue":{"href":"https://api.github.com/repos/awslabs/s2n/issues/1133"},"comments":{"href":"https://api.github.com/repos/awslabs/s2n/issues/1133/comments"},"review_comments":{"href":"https://api.github.com/repos/awslabs/s2n/pulls/1133/comments"},"review_comment":{"href":"https://api.github.com/repos/awslabs/s2n/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/awslabs/s2n/pulls/1133/commits"},"statuses":{"href":"https://api.github.com/repos/awslabs/s2n/statuses/77b71b7e19adcb467321d6f231adf6399139afa1"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"fatrat1117"}}