{"action":"created","comment":{"url":"https://api.github.com/repos/coreos/torus/pulls/comments/65780832","id":65780832,"diff_hunk":"@@ -0,0 +1,315 @@\n+package nbd\n+\n+import (\n+\t\"encoding/binary\"\n+\t\"errors\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"net\"\n+\t\"sync\"\n+\t\"time\"\n+\n+\t\"github.com/coreos/pkg/capnslog\"\n+)\n+\n+var clog = capnslog.NewPackageLogger(\"github.com/coreos/torus\", \"nbd\")\n+\n+const (\n+\tnbdMagic       uint64 = 0x4e42444d41474943\n+\tnbdOpts        uint64 = 0x49484156454F5054\n+\tnbdRequestSize        = (4 + 4 + 8 + 8 + 4)\n+\n+\tnbdFlagFixedNewStyle = 0x1\n+\n+\t// options\n+\tnbdOptExportName = 0x1\n+\tnbdOptAbort      = 0x2\n+\tnbdOptList       = 0x3\n+\n+\t// option replies\n+\tnbdRepAck      = 0x1\n+\tnbdRepServer   = 0x2\n+\tnbdRepErrUnsup = 0x80000001\n+\n+\tioKeepAlive = 10 * time.Second\n+)\n+\n+type DeviceFinder interface {\n+\tFindDevice(name string) (Device, error)\n+\tListDevices() ([]string, error)\n+}\n+\n+type NBDServer struct {\n+\tl      *net.TCPListener\n+\tfinder DeviceFinder\n+}\n+\n+func NewNBDServer(addr string, finder DeviceFinder) (*NBDServer, error) {\n+\ttcpaddr, err := net.ResolveTCPAddr(\"tcp\", addr)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tln, err := net.ListenTCP(\"tcp\", tcpaddr)\n+\tif err != nil {\n+\t\treturn nil, err\n+\t}\n+\n+\tns := &NBDServer{\n+\t\tl:      ln,\n+\t\tfinder: finder,\n+\t}\n+\n+\treturn ns, nil\n+}\n+\n+func (s *NBDServer) Serve() error {\n+\tfor {\n+\t\tc, err := s.l.AcceptTCP()\n+\t\tif err != nil {\n+\t\t\treturn err\n+\t\t}\n+\n+\t\tc.SetKeepAlive(true)\n+\t\tc.SetKeepAlivePeriod(ioKeepAlive)\n+\n+\t\tconn := &NBDConn{\n+\t\t\tc:      c,\n+\t\t\tfinder: s.finder,\n+\t\t\texport: \"<none>\",\n+\t\t}\n+\n+\t\tgo func() {\n+\t\t\tif err := conn.handler(); err != nil {\n+\t\t\t\tconn.errorf(\"handler error: %v\", err)\n+\t\t\t}\n+\t\t\tconn.Close()\n+\t\t}()\n+\t}\n+}\n+\n+func (s *NBDServer) Close() error {\n+\treturn s.l.Close()\n+}\n+\n+type option struct {\n+\topt  uint32\n+\tdata []byte\n+}\n+\n+type NBDConn struct {\n+\tc      *net.TCPConn","path":"internal/nbd/nbdserver.go","position":101,"original_position":101,"commit_id":"19eaa1eca6d6df8ca0b8c79942bbeb2ba5bff04e","original_commit_id":"19eaa1eca6d6df8ca0b8c79942bbeb2ba5bff04e","user":{"login":"xiang90","id":4479947,"avatar_url":"https://avatars.githubusercontent.com/u/4479947?v=3","gravatar_id":"","url":"https://api.github.com/users/xiang90","html_url":"https://github.com/xiang90","followers_url":"https://api.github.com/users/xiang90/followers","following_url":"https://api.github.com/users/xiang90/following{/other_user}","gists_url":"https://api.github.com/users/xiang90/gists{/gist_id}","starred_url":"https://api.github.com/users/xiang90/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/xiang90/subscriptions","organizations_url":"https://api.github.com/users/xiang90/orgs","repos_url":"https://api.github.com/users/xiang90/repos","events_url":"https://api.github.com/users/xiang90/events{/privacy}","received_events_url":"https://api.github.com/users/xiang90/received_events","type":"User","site_admin":false},"body":"i know that. we already set keep alive before putting this into ndbconn. not a big deal anyway. it is up to you. probably we will only have tcp ndb conn in foreseeable future...","created_at":"2016-06-03T21:48:35Z","updated_at":"2016-06-03T21:48:35Z","html_url":"https://github.com/coreos/torus/pull/202#discussion_r65780832","pull_request_url":"https://api.github.com/repos/coreos/torus/pulls/202","_links":{"self":{"href":"https://api.github.com/repos/coreos/torus/pulls/comments/65780832"},"html":{"href":"https://github.com/coreos/torus/pull/202#discussion_r65780832"},"pull_request":{"href":"https://api.github.com/repos/coreos/torus/pulls/202"}}},"pull_request":{"url":"https://api.github.com/repos/coreos/torus/pulls/202","id":72427154,"html_url":"https://github.com/coreos/torus/pull/202","diff_url":"https://github.com/coreos/torus/pull/202.diff","patch_url":"https://github.com/coreos/torus/pull/202.patch","issue_url":"https://api.github.com/repos/coreos/torus/issues/202","number":202,"state":"open","locked":false,"title":"cmd/torusblk: implemenet NBD TCP server","user":{"login":"mischief","id":1487996,"avatar_url":"https://avatars.githubusercontent.com/u/1487996?v=3","gravatar_id":"","url":"https://api.github.com/users/mischief","html_url":"https://github.com/mischief","followers_url":"https://api.github.com/users/mischief/followers","following_url":"https://api.github.com/users/mischief/following{/other_user}","gists_url":"https://api.github.com/users/mischief/gists{/gist_id}","starred_url":"https://api.github.com/users/mischief/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mischief/subscriptions","organizations_url":"https://api.github.com/users/mischief/orgs","repos_url":"https://api.github.com/users/mischief/repos","events_url":"https://api.github.com/users/mischief/events{/privacy}","received_events_url":"https://api.github.com/users/mischief/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-06-02T22:20:57Z","updated_at":"2016-06-03T21:48:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"22807c3f452beaa46ecfbfba6ed1735ef43f6b4f","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coreos/torus/pulls/202/commits","review_comments_url":"https://api.github.com/repos/coreos/torus/pulls/202/comments","review_comment_url":"https://api.github.com/repos/coreos/torus/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coreos/torus/issues/202/comments","statuses_url":"https://api.github.com/repos/coreos/torus/statuses/19eaa1eca6d6df8ca0b8c79942bbeb2ba5bff04e","head":{"label":"mischief:nbdserver","ref":"nbdserver","sha":"19eaa1eca6d6df8ca0b8c79942bbeb2ba5bff04e","user":{"login":"mischief","id":1487996,"avatar_url":"https://avatars.githubusercontent.com/u/1487996?v=3","gravatar_id":"","url":"https://api.github.com/users/mischief","html_url":"https://github.com/mischief","followers_url":"https://api.github.com/users/mischief/followers","following_url":"https://api.github.com/users/mischief/following{/other_user}","gists_url":"https://api.github.com/users/mischief/gists{/gist_id}","starred_url":"https://api.github.com/users/mischief/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mischief/subscriptions","organizations_url":"https://api.github.com/users/mischief/orgs","repos_url":"https://api.github.com/users/mischief/repos","events_url":"https://api.github.com/users/mischief/events{/privacy}","received_events_url":"https://api.github.com/users/mischief/received_events","type":"User","site_admin":false},"repo":{"id":60211704,"name":"torus","full_name":"mischief/torus","owner":{"login":"mischief","id":1487996,"avatar_url":"https://avatars.githubusercontent.com/u/1487996?v=3","gravatar_id":"","url":"https://api.github.com/users/mischief","html_url":"https://github.com/mischief","followers_url":"https://api.github.com/users/mischief/followers","following_url":"https://api.github.com/users/mischief/following{/other_user}","gists_url":"https://api.github.com/users/mischief/gists{/gist_id}","starred_url":"https://api.github.com/users/mischief/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mischief/subscriptions","organizations_url":"https://api.github.com/users/mischief/orgs","repos_url":"https://api.github.com/users/mischief/repos","events_url":"https://api.github.com/users/mischief/events{/privacy}","received_events_url":"https://api.github.com/users/mischief/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mischief/torus","description":"Torus Distributed Storage","fork":true,"url":"https://api.github.com/repos/mischief/torus","forks_url":"https://api.github.com/repos/mischief/torus/forks","keys_url":"https://api.github.com/repos/mischief/torus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mischief/torus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mischief/torus/teams","hooks_url":"https://api.github.com/repos/mischief/torus/hooks","issue_events_url":"https://api.github.com/repos/mischief/torus/issues/events{/number}","events_url":"https://api.github.com/repos/mischief/torus/events","assignees_url":"https://api.github.com/repos/mischief/torus/assignees{/user}","branches_url":"https://api.github.com/repos/mischief/torus/branches{/branch}","tags_url":"https://api.github.com/repos/mischief/torus/tags","blobs_url":"https://api.github.com/repos/mischief/torus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mischief/torus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mischief/torus/git/refs{/sha}","trees_url":"https://api.github.com/repos/mischief/torus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mischief/torus/statuses/{sha}","languages_url":"https://api.github.com/repos/mischief/torus/languages","stargazers_url":"https://api.github.com/repos/mischief/torus/stargazers","contributors_url":"https://api.github.com/repos/mischief/torus/contributors","subscribers_url":"https://api.github.com/repos/mischief/torus/subscribers","subscription_url":"https://api.github.com/repos/mischief/torus/subscription","commits_url":"https://api.github.com/repos/mischief/torus/commits{/sha}","git_commits_url":"https://api.github.com/repos/mischief/torus/git/commits{/sha}","comments_url":"https://api.github.com/repos/mischief/torus/comments{/number}","issue_comment_url":"https://api.github.com/repos/mischief/torus/issues/comments{/number}","contents_url":"https://api.github.com/repos/mischief/torus/contents/{+path}","compare_url":"https://api.github.com/repos/mischief/torus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mischief/torus/merges","archive_url":"https://api.github.com/repos/mischief/torus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mischief/torus/downloads","issues_url":"https://api.github.com/repos/mischief/torus/issues{/number}","pulls_url":"https://api.github.com/repos/mischief/torus/pulls{/number}","milestones_url":"https://api.github.com/repos/mischief/torus/milestones{/number}","notifications_url":"https://api.github.com/repos/mischief/torus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mischief/torus/labels{/name}","releases_url":"https://api.github.com/repos/mischief/torus/releases{/id}","deployments_url":"https://api.github.com/repos/mischief/torus/deployments","created_at":"2016-06-01T21:22:53Z","updated_at":"2016-06-01T21:22:54Z","pushed_at":"2016-06-03T20:35:47Z","git_url":"git://github.com/mischief/torus.git","ssh_url":"git@github.com:mischief/torus.git","clone_url":"https://github.com/mischief/torus.git","svn_url":"https://github.com/mischief/torus","homepage":"","size":959,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"coreos:master","ref":"master","sha":"04ffbb3d95aa8798f6db7b44b066010edb19da6c","user":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"repo":{"id":44835354,"name":"torus","full_name":"coreos/torus","owner":{"login":"coreos","id":3730757,"avatar_url":"https://avatars.githubusercontent.com/u/3730757?v=3","gravatar_id":"","url":"https://api.github.com/users/coreos","html_url":"https://github.com/coreos","followers_url":"https://api.github.com/users/coreos/followers","following_url":"https://api.github.com/users/coreos/following{/other_user}","gists_url":"https://api.github.com/users/coreos/gists{/gist_id}","starred_url":"https://api.github.com/users/coreos/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coreos/subscriptions","organizations_url":"https://api.github.com/users/coreos/orgs","repos_url":"https://api.github.com/users/coreos/repos","events_url":"https://api.github.com/users/coreos/events{/privacy}","received_events_url":"https://api.github.com/users/coreos/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coreos/torus","description":"Torus Distributed Storage","fork":false,"url":"https://api.github.com/repos/coreos/torus","forks_url":"https://api.github.com/repos/coreos/torus/forks","keys_url":"https://api.github.com/repos/coreos/torus/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coreos/torus/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coreos/torus/teams","hooks_url":"https://api.github.com/repos/coreos/torus/hooks","issue_events_url":"https://api.github.com/repos/coreos/torus/issues/events{/number}","events_url":"https://api.github.com/repos/coreos/torus/events","assignees_url":"https://api.github.com/repos/coreos/torus/assignees{/user}","branches_url":"https://api.github.com/repos/coreos/torus/branches{/branch}","tags_url":"https://api.github.com/repos/coreos/torus/tags","blobs_url":"https://api.github.com/repos/coreos/torus/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coreos/torus/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coreos/torus/git/refs{/sha}","trees_url":"https://api.github.com/repos/coreos/torus/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coreos/torus/statuses/{sha}","languages_url":"https://api.github.com/repos/coreos/torus/languages","stargazers_url":"https://api.github.com/repos/coreos/torus/stargazers","contributors_url":"https://api.github.com/repos/coreos/torus/contributors","subscribers_url":"https://api.github.com/repos/coreos/torus/subscribers","subscription_url":"https://api.github.com/repos/coreos/torus/subscription","commits_url":"https://api.github.com/repos/coreos/torus/commits{/sha}","git_commits_url":"https://api.github.com/repos/coreos/torus/git/commits{/sha}","comments_url":"https://api.github.com/repos/coreos/torus/comments{/number}","issue_comment_url":"https://api.github.com/repos/coreos/torus/issues/comments{/number}","contents_url":"https://api.github.com/repos/coreos/torus/contents/{+path}","compare_url":"https://api.github.com/repos/coreos/torus/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coreos/torus/merges","archive_url":"https://api.github.com/repos/coreos/torus/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coreos/torus/downloads","issues_url":"https://api.github.com/repos/coreos/torus/issues{/number}","pulls_url":"https://api.github.com/repos/coreos/torus/pulls{/number}","milestones_url":"https://api.github.com/repos/coreos/torus/milestones{/number}","notifications_url":"https://api.github.com/repos/coreos/torus/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coreos/torus/labels{/name}","releases_url":"https://api.github.com/repos/coreos/torus/releases{/id}","deployments_url":"https://api.github.com/repos/coreos/torus/deployments","created_at":"2015-10-23T19:56:21Z","updated_at":"2016-06-03T21:10:29Z","pushed_at":"2016-06-03T21:15:51Z","git_url":"git://github.com/coreos/torus.git","ssh_url":"git@github.com:coreos/torus.git","clone_url":"https://github.com/coreos/torus.git","svn_url":"https://github.com/coreos/torus","homepage":"","size":1006,"stargazers_count":818,"watchers_count":818,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":42,"mirror_url":null,"open_issues_count":52,"forks":42,"open_issues":52,"watchers":818,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coreos/torus/pulls/202"},"html":{"href":"https://github.com/coreos/torus/pull/202"},"issue":{"href":"https://api.github.com/repos/coreos/torus/issues/202"},"comments":{"href":"https://api.github.com/repos/coreos/torus/issues/202/comments"},"review_comments":{"href":"https://api.github.com/repos/coreos/torus/pulls/202/comments"},"review_comment":{"href":"https://api.github.com/repos/coreos/torus/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coreos/torus/pulls/202/commits"},"statuses":{"href":"https://api.github.com/repos/coreos/torus/statuses/19eaa1eca6d6df8ca0b8c79942bbeb2ba5bff04e"}}}}
{"actor":{"display_login":"xiang90"}}