{"action":"created","comment":{"url":"https://api.github.com/repos/keybase/kbfs/pulls/comments/144940200","pull_request_review_id":69667280,"id":144940200,"diff_hunk":"@@ -0,0 +1,116 @@\n+package libkbfs\n+\n+import (\n+\t\"io\"\n+\t\"net\"\n+\n+\t\"github.com/keybase/client/go/libkb\"\n+\t\"github.com/keybase/client/go/logger\"\n+\t\"github.com/keybase/go-framed-msgpack-rpc/rpc\"\n+)\n+\n+// KBFSService represents a running KBFS service.\n+type KBFSService struct {\n+\tlog    logger.Logger\n+\tkbCtx  Context\n+\tstopCh chan struct{}\n+}\n+\n+// NewKBFSService creates a new KBFSService.\n+func NewKBFSService(kbCtx Context, log logger.Logger) (*KBFSService, error) {\n+\tl, err := kbCtx.BindToKBFSSocket()\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\tk := &KBFSService{\n+\t\tlog:   log,\n+\t\tkbCtx: kbCtx,\n+\t}\n+\tk.Run(l)\n+\treturn k, nil\n+}\n+\n+// Run starts listening on the passed-in listener.\n+func (k *KBFSService) Run(l net.Listener) {\n+\tgo k.listenLoop(l)\n+}\n+\n+// registerProtocols registers protocols for this KBFSService.\n+func (k *KBFSService) registerProtocols(\n+\tsrv *rpc.Server, xp rpc.Transporter) error {\n+\t// TODO: fill in with actual protocols.\n+\tprotocols := []rpc.Protocol{}\n+\tfor _, proto := range protocols {\n+\t\tif err := srv.Register(proto); err != nil {\n+\t\t\treturn err\n+\t\t}\n+\t}\n+\treturn nil\n+}\n+\n+// handle creates a server on an established connection.\n+func (k *KBFSService) handle(c net.Conn) {\n+\txp := rpc.NewTransport(c, k.kbCtx.NewRPCLogFactory(), libkb.WrapError)\n+\n+\tserver := rpc.NewServer(xp, libkb.WrapError)\n+\n+\terr := k.registerProtocols(server, xp)\n+\n+\tif err != nil {\n+\t\tk.log.Warning(\"RegisterProtocols error: %s\", err)\n+\t\treturn\n+\t}\n+\n+\t// Run the server, then wait for it or this KBFSService to finish. If\n+\t// KBFSService finishes first, close the connection.\n+\tserverCh := server.Run()\n+\tgo func() {\n+\t\tselect {\n+\t\tcase <-k.stopCh:\n+\t\tcase <-serverCh:\n+\t\t}\n+\t\tc.Close()\n+\t}()\n+\t<-serverCh\n+\n+\t// err is always non-nil.\n+\terr = server.Err()\n+\tif err != io.EOF {\n+\t\tk.log.Warning(\"Run error: %s\", err)\n+\t}\n+\n+\tk.log.Debug(\"handle() complete\")\n+}\n+\n+// listenLoop listens on a passed-in listener and calls `handle` for any\n+// connection that is established on the listener.\n+func (k *KBFSService) listenLoop(l net.Listener) error {\n+\tgo func() {\n+\t\t<-k.stopCh\n+\t\tl.Close()\n+\t}()\n+\tdefer l.Close()\n+\tfor {\n+\t\tc, err := l.Accept()\n+\t\tif err != nil {\n+\n+\t\t\tif libkb.IsSocketClosedError(err) {\n+\t\t\t\terr = nil\n+\t\t\t}\n+\n+\t\t\tk.log.Debug(\"listenLoop() done, error: %+v\", err)\n+\t\t\treturn err\n+\t\t}\n+\t\tgo k.handle(c)\n+\t}\n+}\n+\n+// Shutdown shuts down this KBFSService.\n+func (k *KBFSService) Shutdown() <-chan struct{} {\n+\tselect {\n+\tcase <-k.stopCh:\n+\tdefault:\n+\t\tclose(k.stopCh)\n+\t}\n+\treturn k.stopCh","path":"libkbfs/kbfs_service.go","position":115,"original_position":115,"commit_id":"8d3f87f19eebcd2f5ee18a88525e40072316d408","original_commit_id":"8d3f87f19eebcd2f5ee18a88525e40072316d408","user":{"login":"jzila","id":59594,"avatar_url":"https://avatars1.githubusercontent.com/u/59594?v=4","gravatar_id":"","url":"https://api.github.com/users/jzila","html_url":"https://github.com/jzila","followers_url":"https://api.github.com/users/jzila/followers","following_url":"https://api.github.com/users/jzila/following{/other_user}","gists_url":"https://api.github.com/users/jzila/gists{/gist_id}","starred_url":"https://api.github.com/users/jzila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jzila/subscriptions","organizations_url":"https://api.github.com/users/jzila/orgs","repos_url":"https://api.github.com/users/jzila/repos","events_url":"https://api.github.com/users/jzila/events{/privacy}","received_events_url":"https://api.github.com/users/jzila/received_events","type":"User","site_admin":false},"body":"Heh, copy-paste bug. Fixing.","created_at":"2017-10-16T19:11:07Z","updated_at":"2017-10-16T19:11:07Z","html_url":"https://github.com/keybase/kbfs/pull/1181#discussion_r144940200","pull_request_url":"https://api.github.com/repos/keybase/kbfs/pulls/1181","author_association":"CONTRIBUTOR","_links":{"self":{"href":"https://api.github.com/repos/keybase/kbfs/pulls/comments/144940200"},"html":{"href":"https://github.com/keybase/kbfs/pull/1181#discussion_r144940200"},"pull_request":{"href":"https://api.github.com/repos/keybase/kbfs/pulls/1181"}},"in_reply_to_id":144706862},"pull_request":{"url":"https://api.github.com/repos/keybase/kbfs/pulls/1181","id":141420219,"html_url":"https://github.com/keybase/kbfs/pull/1181","diff_url":"https://github.com/keybase/kbfs/pull/1181.diff","patch_url":"https://github.com/keybase/kbfs/pull/1181.patch","issue_url":"https://api.github.com/repos/keybase/kbfs/issues/1181","number":1181,"state":"open","locked":false,"title":"[KBFS-2336] KBFS Service","user":{"login":"jzila","id":59594,"avatar_url":"https://avatars1.githubusercontent.com/u/59594?v=4","gravatar_id":"","url":"https://api.github.com/users/jzila","html_url":"https://github.com/jzila","followers_url":"https://api.github.com/users/jzila/followers","following_url":"https://api.github.com/users/jzila/following{/other_user}","gists_url":"https://api.github.com/users/jzila/gists{/gist_id}","starred_url":"https://api.github.com/users/jzila/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jzila/subscriptions","organizations_url":"https://api.github.com/users/jzila/orgs","repos_url":"https://api.github.com/users/jzila/repos","events_url":"https://api.github.com/users/jzila/events{/privacy}","received_events_url":"https://api.github.com/users/jzila/received_events","type":"User","site_admin":false},"body":"Create a KBFS Service to allow applications to connect to it.\r\n\r\nProtocols coming in a later PR.","created_at":"2017-09-15T23:35:31Z","updated_at":"2017-10-16T19:11:07Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ca8e730a36d859137b32c198d8921746eac7b5d3","assignee":null,"assignees":[],"requested_reviewers":[{"login":"songgao","id":255797,"avatar_url":"https://avatars3.githubusercontent.com/u/255797?v=4","gravatar_id":"","url":"https://api.github.com/users/songgao","html_url":"https://github.com/songgao","followers_url":"https://api.github.com/users/songgao/followers","following_url":"https://api.github.com/users/songgao/following{/other_user}","gists_url":"https://api.github.com/users/songgao/gists{/gist_id}","starred_url":"https://api.github.com/users/songgao/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/songgao/subscriptions","organizations_url":"https://api.github.com/users/songgao/orgs","repos_url":"https://api.github.com/users/songgao/repos","events_url":"https://api.github.com/users/songgao/events{/privacy}","received_events_url":"https://api.github.com/users/songgao/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/keybase/kbfs/pulls/1181/commits","review_comments_url":"https://api.github.com/repos/keybase/kbfs/pulls/1181/comments","review_comment_url":"https://api.github.com/repos/keybase/kbfs/pulls/comments{/number}","comments_url":"https://api.github.com/repos/keybase/kbfs/issues/1181/comments","statuses_url":"https://api.github.com/repos/keybase/kbfs/statuses/8d3f87f19eebcd2f5ee18a88525e40072316d408","head":{"label":"keybase:jzila/KBFS-2336-kbfs-service","ref":"jzila/KBFS-2336-kbfs-service","sha":"8d3f87f19eebcd2f5ee18a88525e40072316d408","user":{"login":"keybase","id":5400834,"avatar_url":"https://avatars2.githubusercontent.com/u/5400834?v=4","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"repo":{"id":59787605,"name":"kbfs","full_name":"keybase/kbfs","owner":{"login":"keybase","id":5400834,"avatar_url":"https://avatars2.githubusercontent.com/u/5400834?v=4","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/keybase/kbfs","description":"Keybase Filesystem (KBFS)","fork":false,"url":"https://api.github.com/repos/keybase/kbfs","forks_url":"https://api.github.com/repos/keybase/kbfs/forks","keys_url":"https://api.github.com/repos/keybase/kbfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/keybase/kbfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/keybase/kbfs/teams","hooks_url":"https://api.github.com/repos/keybase/kbfs/hooks","issue_events_url":"https://api.github.com/repos/keybase/kbfs/issues/events{/number}","events_url":"https://api.github.com/repos/keybase/kbfs/events","assignees_url":"https://api.github.com/repos/keybase/kbfs/assignees{/user}","branches_url":"https://api.github.com/repos/keybase/kbfs/branches{/branch}","tags_url":"https://api.github.com/repos/keybase/kbfs/tags","blobs_url":"https://api.github.com/repos/keybase/kbfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/keybase/kbfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/keybase/kbfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/keybase/kbfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/keybase/kbfs/statuses/{sha}","languages_url":"https://api.github.com/repos/keybase/kbfs/languages","stargazers_url":"https://api.github.com/repos/keybase/kbfs/stargazers","contributors_url":"https://api.github.com/repos/keybase/kbfs/contributors","subscribers_url":"https://api.github.com/repos/keybase/kbfs/subscribers","subscription_url":"https://api.github.com/repos/keybase/kbfs/subscription","commits_url":"https://api.github.com/repos/keybase/kbfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/keybase/kbfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/keybase/kbfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/keybase/kbfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/keybase/kbfs/contents/{+path}","compare_url":"https://api.github.com/repos/keybase/kbfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/keybase/kbfs/merges","archive_url":"https://api.github.com/repos/keybase/kbfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/keybase/kbfs/downloads","issues_url":"https://api.github.com/repos/keybase/kbfs/issues{/number}","pulls_url":"https://api.github.com/repos/keybase/kbfs/pulls{/number}","milestones_url":"https://api.github.com/repos/keybase/kbfs/milestones{/number}","notifications_url":"https://api.github.com/repos/keybase/kbfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/keybase/kbfs/labels{/name}","releases_url":"https://api.github.com/repos/keybase/kbfs/releases{/id}","deployments_url":"https://api.github.com/repos/keybase/kbfs/deployments","created_at":"2016-05-26T22:37:42Z","updated_at":"2017-10-16T19:04:51Z","pushed_at":"2017-10-16T18:38:26Z","git_url":"git://github.com/keybase/kbfs.git","ssh_url":"git@github.com:keybase/kbfs.git","clone_url":"https://github.com/keybase/kbfs.git","svn_url":"https://github.com/keybase/kbfs","homepage":"https://keybase.io/docs/kbfs","size":46129,"stargazers_count":726,"watchers_count":726,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":67,"mirror_url":null,"open_issues_count":41,"forks":67,"open_issues":41,"watchers":726,"default_branch":"master"}},"base":{"label":"keybase:master","ref":"master","sha":"6a1eb1e862807b32ced28037b39ba02bcfbcd9a2","user":{"login":"keybase","id":5400834,"avatar_url":"https://avatars2.githubusercontent.com/u/5400834?v=4","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"repo":{"id":59787605,"name":"kbfs","full_name":"keybase/kbfs","owner":{"login":"keybase","id":5400834,"avatar_url":"https://avatars2.githubusercontent.com/u/5400834?v=4","gravatar_id":"","url":"https://api.github.com/users/keybase","html_url":"https://github.com/keybase","followers_url":"https://api.github.com/users/keybase/followers","following_url":"https://api.github.com/users/keybase/following{/other_user}","gists_url":"https://api.github.com/users/keybase/gists{/gist_id}","starred_url":"https://api.github.com/users/keybase/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/keybase/subscriptions","organizations_url":"https://api.github.com/users/keybase/orgs","repos_url":"https://api.github.com/users/keybase/repos","events_url":"https://api.github.com/users/keybase/events{/privacy}","received_events_url":"https://api.github.com/users/keybase/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/keybase/kbfs","description":"Keybase Filesystem (KBFS)","fork":false,"url":"https://api.github.com/repos/keybase/kbfs","forks_url":"https://api.github.com/repos/keybase/kbfs/forks","keys_url":"https://api.github.com/repos/keybase/kbfs/keys{/key_id}","collaborators_url":"https://api.github.com/repos/keybase/kbfs/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/keybase/kbfs/teams","hooks_url":"https://api.github.com/repos/keybase/kbfs/hooks","issue_events_url":"https://api.github.com/repos/keybase/kbfs/issues/events{/number}","events_url":"https://api.github.com/repos/keybase/kbfs/events","assignees_url":"https://api.github.com/repos/keybase/kbfs/assignees{/user}","branches_url":"https://api.github.com/repos/keybase/kbfs/branches{/branch}","tags_url":"https://api.github.com/repos/keybase/kbfs/tags","blobs_url":"https://api.github.com/repos/keybase/kbfs/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/keybase/kbfs/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/keybase/kbfs/git/refs{/sha}","trees_url":"https://api.github.com/repos/keybase/kbfs/git/trees{/sha}","statuses_url":"https://api.github.com/repos/keybase/kbfs/statuses/{sha}","languages_url":"https://api.github.com/repos/keybase/kbfs/languages","stargazers_url":"https://api.github.com/repos/keybase/kbfs/stargazers","contributors_url":"https://api.github.com/repos/keybase/kbfs/contributors","subscribers_url":"https://api.github.com/repos/keybase/kbfs/subscribers","subscription_url":"https://api.github.com/repos/keybase/kbfs/subscription","commits_url":"https://api.github.com/repos/keybase/kbfs/commits{/sha}","git_commits_url":"https://api.github.com/repos/keybase/kbfs/git/commits{/sha}","comments_url":"https://api.github.com/repos/keybase/kbfs/comments{/number}","issue_comment_url":"https://api.github.com/repos/keybase/kbfs/issues/comments{/number}","contents_url":"https://api.github.com/repos/keybase/kbfs/contents/{+path}","compare_url":"https://api.github.com/repos/keybase/kbfs/compare/{base}...{head}","merges_url":"https://api.github.com/repos/keybase/kbfs/merges","archive_url":"https://api.github.com/repos/keybase/kbfs/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/keybase/kbfs/downloads","issues_url":"https://api.github.com/repos/keybase/kbfs/issues{/number}","pulls_url":"https://api.github.com/repos/keybase/kbfs/pulls{/number}","milestones_url":"https://api.github.com/repos/keybase/kbfs/milestones{/number}","notifications_url":"https://api.github.com/repos/keybase/kbfs/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/keybase/kbfs/labels{/name}","releases_url":"https://api.github.com/repos/keybase/kbfs/releases{/id}","deployments_url":"https://api.github.com/repos/keybase/kbfs/deployments","created_at":"2016-05-26T22:37:42Z","updated_at":"2017-10-16T19:04:51Z","pushed_at":"2017-10-16T18:38:26Z","git_url":"git://github.com/keybase/kbfs.git","ssh_url":"git@github.com:keybase/kbfs.git","clone_url":"https://github.com/keybase/kbfs.git","svn_url":"https://github.com/keybase/kbfs","homepage":"https://keybase.io/docs/kbfs","size":46129,"stargazers_count":726,"watchers_count":726,"language":"Go","has_issues":true,"has_projects":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":67,"mirror_url":null,"open_issues_count":41,"forks":67,"open_issues":41,"watchers":726,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/keybase/kbfs/pulls/1181"},"html":{"href":"https://github.com/keybase/kbfs/pull/1181"},"issue":{"href":"https://api.github.com/repos/keybase/kbfs/issues/1181"},"comments":{"href":"https://api.github.com/repos/keybase/kbfs/issues/1181/comments"},"review_comments":{"href":"https://api.github.com/repos/keybase/kbfs/pulls/1181/comments"},"review_comment":{"href":"https://api.github.com/repos/keybase/kbfs/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/keybase/kbfs/pulls/1181/commits"},"statuses":{"href":"https://api.github.com/repos/keybase/kbfs/statuses/8d3f87f19eebcd2f5ee18a88525e40072316d408"}},"author_association":"CONTRIBUTOR"}}
{"actor":{"display_login":"jzila"}}