{"action":"created","comment":{"url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/comments/74983097","id":74983097,"diff_hunk":"@@ -0,0 +1,115 @@\n+package keyserver\n+\n+import (\n+\t\"encoding/json\"\n+\t\"io\"\n+\t\"log\"\n+\t\"net\"\n+\t\"time\"\n+\n+\t. \"github.com/coniks-sys/coniks-go/protocol\"\n+)\n+\n+func (server *ConiksServer) listenForRequests(ln net.Listener, handler func(msg []byte) ([]byte, error)) {\n+\tdefer ln.Close()\n+\tgo func() {\n+\t\t<-server.stop\n+\t\tln.Close()\n+\t}()\n+\n+\tfor {\n+\t\tconn, err := ln.Accept()\n+\t\tif err != nil {\n+\t\t\tselect {\n+\t\t\tcase <-server.stop:\n+\t\t\t\treturn\n+\t\t\tdefault:\n+\t\t\t\tlog.Printf(\"accept client: %s\", err)\n+\t\t\t\tcontinue\n+\t\t\t}\n+\t\t}\n+\t\tserver.waitStop.Add(1)\n+\t\tgo func() {\n+\t\t\tserver.acceptClient(conn, handler)\n+\t\t\tserver.waitStop.Done()\n+\t\t}()\n+\t}\n+}\n+\n+func (server *ConiksServer) acceptClient(conn net.Conn, handler func(msg []byte) ([]byte, error)) {\n+\tdefer conn.Close()\n+\tclosed := make(chan struct{})\n+\tdefer close(closed)\n+\tgo func() {\n+\t\tselect {\n+\t\tcase <-server.stop:\n+\t\t\tconn.Close()\n+\t\tcase <-closed:\n+\t\t}\n+\t}()\n+\n+\tconn.SetDeadline(time.Now().Add(5 * time.Second))\n+\n+\t// handle request\n+\tbuf := make([]byte, 4096)\n+\tfor {\n+\t\tn, err := conn.Read(buf)\n+\t\tif err != nil {\n+\t\t\tselect {\n+\t\t\tcase <-server.stop:\n+\t\t\t\treturn\n+\t\t\tdefault:\n+\t\t\t\tif err != io.EOF {\n+\t\t\t\t\tlog.Printf(\"client read %v: %v\", conn.RemoteAddr(), err)\n+\t\t\t\t}\n+\t\t\t\treturn\n+\t\t\t}\n+\t\t}\n+\n+\t\tres, err := handler(buf[:n])\n+\t\tif err != nil {\n+\t\t\tlog.Printf(\"client handle %v: %v\", conn.RemoteAddr(), err)\n+\t\t}\n+\n+\t\tn, err = conn.Write([]byte(res))\n+\t\tif err != nil {\n+\t\t\tselect {\n+\t\t\tcase <-server.stop:\n+\t\t\t\treturn\n+\t\t\tdefault:\n+\t\t\t\tlog.Printf(\"client write %v: %v\", conn.RemoteAddr(), err)\n+\t\t\t\treturn\n+\t\t\t}\n+\t\t}\n+\t}\n+}\n+\n+func malformedClientMsg() []byte {\n+\tres, err := MarshalErrorResponse(ErrorMalformedClientMessage)\n+\tif err != nil {\n+\t\tpanic(err)\n+\t}\n+\treturn res\n+}\n+\n+func (server *ConiksServer) makeHandler(acceptableTypes map[int]bool) func(msg []byte) ([]byte, error) {\n+\treturn func(msg []byte) ([]byte, error) {\n+\t\t// get request message\n+\t\treq, err := UnmarshalRequest(msg)\n+\t\tif err != nil {\n+\t\t\treturn malformedClientMsg(), err\n+\t\t}\n+","path":"keyserver/listener.go","position":102,"original_position":102,"commit_id":"cfe5e95b9cc2bd0403f69f6313d65fec1bb35319","original_commit_id":"cfe5e95b9cc2bd0403f69f6313d65fec1bb35319","user":{"login":"arlolra","id":123708,"avatar_url":"https://avatars.githubusercontent.com/u/123708?v=3","gravatar_id":"","url":"https://api.github.com/users/arlolra","html_url":"https://github.com/arlolra","followers_url":"https://api.github.com/users/arlolra/followers","following_url":"https://api.github.com/users/arlolra/following{/other_user}","gists_url":"https://api.github.com/users/arlolra/gists{/gist_id}","starred_url":"https://api.github.com/users/arlolra/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arlolra/subscriptions","organizations_url":"https://api.github.com/users/arlolra/orgs","repos_url":"https://api.github.com/users/arlolra/repos","events_url":"https://api.github.com/users/arlolra/events{/privacy}","received_events_url":"https://api.github.com/users/arlolra/received_events","type":"User","site_admin":false},"body":"Maybe hoist the type check,\r\n\r\n```\r\nif !acceptableTypes[req.Type] {\r\n  log.Printf(\"unacceptable message type: %q\", req.Type)\r\n  return malformedClientMsg(), ErrorMalformedClientMessage.Error()\r\n}\r\n```\r\n\r\nThen you can keep the switch on req.Type and the default error.","created_at":"2016-08-16T17:40:21Z","updated_at":"2016-08-16T17:40:21Z","html_url":"https://github.com/coniks-sys/coniks-go/pull/71#discussion_r74983097","pull_request_url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71","_links":{"self":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/comments/74983097"},"html":{"href":"https://github.com/coniks-sys/coniks-go/pull/71#discussion_r74983097"},"pull_request":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71"}}},"pull_request":{"url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71","id":81337619,"html_url":"https://github.com/coniks-sys/coniks-go/pull/71","diff_url":"https://github.com/coniks-sys/coniks-go/pull/71.diff","patch_url":"https://github.com/coniks-sys/coniks-go/pull/71.patch","issue_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues/71","number":71,"state":"open","locked":false,"title":"Implement reference key server","user":{"login":"c633","id":5112602,"avatar_url":"https://avatars.githubusercontent.com/u/5112602?v=3","gravatar_id":"","url":"https://api.github.com/users/c633","html_url":"https://github.com/c633","followers_url":"https://api.github.com/users/c633/followers","following_url":"https://api.github.com/users/c633/following{/other_user}","gists_url":"https://api.github.com/users/c633/gists{/gist_id}","starred_url":"https://api.github.com/users/c633/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/c633/subscriptions","organizations_url":"https://api.github.com/users/c633/orgs","repos_url":"https://api.github.com/users/c633/repos","events_url":"https://api.github.com/users/c633/events{/privacy}","received_events_url":"https://api.github.com/users/c633/received_events","type":"User","site_admin":false},"body":"* Implement registration function","created_at":"2016-08-15T16:33:43Z","updated_at":"2016-08-16T17:40:21Z","closed_at":null,"merged_at":null,"merge_commit_sha":"57e98702cf5cd4faf126542e2a13f3e31b98bb78","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71/commits","review_comments_url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71/comments","review_comment_url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues/71/comments","statuses_url":"https://api.github.com/repos/coniks-sys/coniks-go/statuses/cfe5e95b9cc2bd0403f69f6313d65fec1bb35319","head":{"label":"coniks-sys:registration","ref":"registration","sha":"cfe5e95b9cc2bd0403f69f6313d65fec1bb35319","user":{"login":"coniks-sys","id":11236504,"avatar_url":"https://avatars.githubusercontent.com/u/11236504?v=3","gravatar_id":"","url":"https://api.github.com/users/coniks-sys","html_url":"https://github.com/coniks-sys","followers_url":"https://api.github.com/users/coniks-sys/followers","following_url":"https://api.github.com/users/coniks-sys/following{/other_user}","gists_url":"https://api.github.com/users/coniks-sys/gists{/gist_id}","starred_url":"https://api.github.com/users/coniks-sys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coniks-sys/subscriptions","organizations_url":"https://api.github.com/users/coniks-sys/orgs","repos_url":"https://api.github.com/users/coniks-sys/repos","events_url":"https://api.github.com/users/coniks-sys/events{/privacy}","received_events_url":"https://api.github.com/users/coniks-sys/received_events","type":"Organization","site_admin":false},"repo":{"id":60117979,"name":"coniks-go","full_name":"coniks-sys/coniks-go","owner":{"login":"coniks-sys","id":11236504,"avatar_url":"https://avatars.githubusercontent.com/u/11236504?v=3","gravatar_id":"","url":"https://api.github.com/users/coniks-sys","html_url":"https://github.com/coniks-sys","followers_url":"https://api.github.com/users/coniks-sys/followers","following_url":"https://api.github.com/users/coniks-sys/following{/other_user}","gists_url":"https://api.github.com/users/coniks-sys/gists{/gist_id}","starred_url":"https://api.github.com/users/coniks-sys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coniks-sys/subscriptions","organizations_url":"https://api.github.com/users/coniks-sys/orgs","repos_url":"https://api.github.com/users/coniks-sys/repos","events_url":"https://api.github.com/users/coniks-sys/events{/privacy}","received_events_url":"https://api.github.com/users/coniks-sys/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coniks-sys/coniks-go","description":"A CONIKS implementation in Golang","fork":false,"url":"https://api.github.com/repos/coniks-sys/coniks-go","forks_url":"https://api.github.com/repos/coniks-sys/coniks-go/forks","keys_url":"https://api.github.com/repos/coniks-sys/coniks-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coniks-sys/coniks-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coniks-sys/coniks-go/teams","hooks_url":"https://api.github.com/repos/coniks-sys/coniks-go/hooks","issue_events_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues/events{/number}","events_url":"https://api.github.com/repos/coniks-sys/coniks-go/events","assignees_url":"https://api.github.com/repos/coniks-sys/coniks-go/assignees{/user}","branches_url":"https://api.github.com/repos/coniks-sys/coniks-go/branches{/branch}","tags_url":"https://api.github.com/repos/coniks-sys/coniks-go/tags","blobs_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coniks-sys/coniks-go/statuses/{sha}","languages_url":"https://api.github.com/repos/coniks-sys/coniks-go/languages","stargazers_url":"https://api.github.com/repos/coniks-sys/coniks-go/stargazers","contributors_url":"https://api.github.com/repos/coniks-sys/coniks-go/contributors","subscribers_url":"https://api.github.com/repos/coniks-sys/coniks-go/subscribers","subscription_url":"https://api.github.com/repos/coniks-sys/coniks-go/subscription","commits_url":"https://api.github.com/repos/coniks-sys/coniks-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/coniks-sys/coniks-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/coniks-sys/coniks-go/contents/{+path}","compare_url":"https://api.github.com/repos/coniks-sys/coniks-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coniks-sys/coniks-go/merges","archive_url":"https://api.github.com/repos/coniks-sys/coniks-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coniks-sys/coniks-go/downloads","issues_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues{/number}","pulls_url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls{/number}","milestones_url":"https://api.github.com/repos/coniks-sys/coniks-go/milestones{/number}","notifications_url":"https://api.github.com/repos/coniks-sys/coniks-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coniks-sys/coniks-go/labels{/name}","releases_url":"https://api.github.com/repos/coniks-sys/coniks-go/releases{/id}","deployments_url":"https://api.github.com/repos/coniks-sys/coniks-go/deployments","created_at":"2016-05-31T19:37:35Z","updated_at":"2016-08-12T01:48:06Z","pushed_at":"2016-08-16T17:32:58Z","git_url":"git://github.com/coniks-sys/coniks-go.git","ssh_url":"git@github.com:coniks-sys/coniks-go.git","clone_url":"https://github.com/coniks-sys/coniks-go.git","svn_url":"https://github.com/coniks-sys/coniks-go","homepage":"http://coniks.org","size":343,"stargazers_count":9,"watchers_count":9,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":23,"forks":0,"open_issues":23,"watchers":9,"default_branch":"master"}},"base":{"label":"coniks-sys:master","ref":"master","sha":"57413362b0ee76d3218ceb720c7bebc221adb6f1","user":{"login":"coniks-sys","id":11236504,"avatar_url":"https://avatars.githubusercontent.com/u/11236504?v=3","gravatar_id":"","url":"https://api.github.com/users/coniks-sys","html_url":"https://github.com/coniks-sys","followers_url":"https://api.github.com/users/coniks-sys/followers","following_url":"https://api.github.com/users/coniks-sys/following{/other_user}","gists_url":"https://api.github.com/users/coniks-sys/gists{/gist_id}","starred_url":"https://api.github.com/users/coniks-sys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coniks-sys/subscriptions","organizations_url":"https://api.github.com/users/coniks-sys/orgs","repos_url":"https://api.github.com/users/coniks-sys/repos","events_url":"https://api.github.com/users/coniks-sys/events{/privacy}","received_events_url":"https://api.github.com/users/coniks-sys/received_events","type":"Organization","site_admin":false},"repo":{"id":60117979,"name":"coniks-go","full_name":"coniks-sys/coniks-go","owner":{"login":"coniks-sys","id":11236504,"avatar_url":"https://avatars.githubusercontent.com/u/11236504?v=3","gravatar_id":"","url":"https://api.github.com/users/coniks-sys","html_url":"https://github.com/coniks-sys","followers_url":"https://api.github.com/users/coniks-sys/followers","following_url":"https://api.github.com/users/coniks-sys/following{/other_user}","gists_url":"https://api.github.com/users/coniks-sys/gists{/gist_id}","starred_url":"https://api.github.com/users/coniks-sys/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coniks-sys/subscriptions","organizations_url":"https://api.github.com/users/coniks-sys/orgs","repos_url":"https://api.github.com/users/coniks-sys/repos","events_url":"https://api.github.com/users/coniks-sys/events{/privacy}","received_events_url":"https://api.github.com/users/coniks-sys/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coniks-sys/coniks-go","description":"A CONIKS implementation in Golang","fork":false,"url":"https://api.github.com/repos/coniks-sys/coniks-go","forks_url":"https://api.github.com/repos/coniks-sys/coniks-go/forks","keys_url":"https://api.github.com/repos/coniks-sys/coniks-go/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coniks-sys/coniks-go/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coniks-sys/coniks-go/teams","hooks_url":"https://api.github.com/repos/coniks-sys/coniks-go/hooks","issue_events_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues/events{/number}","events_url":"https://api.github.com/repos/coniks-sys/coniks-go/events","assignees_url":"https://api.github.com/repos/coniks-sys/coniks-go/assignees{/user}","branches_url":"https://api.github.com/repos/coniks-sys/coniks-go/branches{/branch}","tags_url":"https://api.github.com/repos/coniks-sys/coniks-go/tags","blobs_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/refs{/sha}","trees_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coniks-sys/coniks-go/statuses/{sha}","languages_url":"https://api.github.com/repos/coniks-sys/coniks-go/languages","stargazers_url":"https://api.github.com/repos/coniks-sys/coniks-go/stargazers","contributors_url":"https://api.github.com/repos/coniks-sys/coniks-go/contributors","subscribers_url":"https://api.github.com/repos/coniks-sys/coniks-go/subscribers","subscription_url":"https://api.github.com/repos/coniks-sys/coniks-go/subscription","commits_url":"https://api.github.com/repos/coniks-sys/coniks-go/commits{/sha}","git_commits_url":"https://api.github.com/repos/coniks-sys/coniks-go/git/commits{/sha}","comments_url":"https://api.github.com/repos/coniks-sys/coniks-go/comments{/number}","issue_comment_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues/comments{/number}","contents_url":"https://api.github.com/repos/coniks-sys/coniks-go/contents/{+path}","compare_url":"https://api.github.com/repos/coniks-sys/coniks-go/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coniks-sys/coniks-go/merges","archive_url":"https://api.github.com/repos/coniks-sys/coniks-go/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coniks-sys/coniks-go/downloads","issues_url":"https://api.github.com/repos/coniks-sys/coniks-go/issues{/number}","pulls_url":"https://api.github.com/repos/coniks-sys/coniks-go/pulls{/number}","milestones_url":"https://api.github.com/repos/coniks-sys/coniks-go/milestones{/number}","notifications_url":"https://api.github.com/repos/coniks-sys/coniks-go/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coniks-sys/coniks-go/labels{/name}","releases_url":"https://api.github.com/repos/coniks-sys/coniks-go/releases{/id}","deployments_url":"https://api.github.com/repos/coniks-sys/coniks-go/deployments","created_at":"2016-05-31T19:37:35Z","updated_at":"2016-08-12T01:48:06Z","pushed_at":"2016-08-16T17:32:58Z","git_url":"git://github.com/coniks-sys/coniks-go.git","ssh_url":"git@github.com:coniks-sys/coniks-go.git","clone_url":"https://github.com/coniks-sys/coniks-go.git","svn_url":"https://github.com/coniks-sys/coniks-go","homepage":"http://coniks.org","size":343,"stargazers_count":9,"watchers_count":9,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":23,"forks":0,"open_issues":23,"watchers":9,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71"},"html":{"href":"https://github.com/coniks-sys/coniks-go/pull/71"},"issue":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/issues/71"},"comments":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/issues/71/comments"},"review_comments":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71/comments"},"review_comment":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/pulls/71/commits"},"statuses":{"href":"https://api.github.com/repos/coniks-sys/coniks-go/statuses/cfe5e95b9cc2bd0403f69f6313d65fec1bb35319"}}}}
{"actor":{"display_login":"arlolra"}}