{"action":"created","comment":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/comments/39614616","id":39614616,"diff_hunk":"@@ -0,0 +1,469 @@\n+// Copyright 2015 PingCAP, Inc.\n+//\n+// Licensed under the Apache License, Version 2.0 (the \"License\");\n+// you may not use this file except in compliance with the License.\n+// You may obtain a copy of the License at\n+//\n+//     http://www.apache.org/licenses/LICENSE-2.0\n+//\n+// Unless required by applicable law or agreed to in writing, software\n+// distributed under the License is distributed on an \"AS IS\" BASIS,\n+// See the License for the specific language governing permissions and\n+// limitations under the License.\n+\n+package server\n+\n+import (\n+\t\"bytes\"\n+\t\"crypto/sha1\"\n+\t\"encoding/binary\"\n+\t\"fmt\"\n+\t\"io\"\n+\t\"net\"\n+\t\"runtime\"\n+\t\"strings\"\n+\n+\t\"github.com/juju/errors\"\n+\t\"github.com/ngaut/log\"\n+\tmysql \"github.com/pingcap/tidb/mysqldef\"\n+\t\"github.com/pingcap/tidb/util/arena\"\n+\t\"github.com/pingcap/tidb/util/errors2\"\n+\t\"github.com/pingcap/tidb/util/hack\"\n+)\n+\n+var defaultCapability = mysql.ClientLongPassword | mysql.ClientLongFlag |\n+\tmysql.ClientConnectWithDB | mysql.ClientProtocol41 |\n+\tmysql.ClientTransactions | mysql.ClientSecureConnection | mysql.ClientFoundRows\n+\n+type clientConn struct {\n+\tpkg          *packetIO\n+\tconn         net.Conn\n+\tserver       *Server\n+\tcapability   uint32\n+\tconnectionID uint32\n+\tcollation    uint8\n+\tcharset      string\n+\tuser         string\n+\tdbname       string\n+\tsalt         []byte\n+\talloc        arena.Allocator\n+\tlastCmd      string\n+\tctx          IContext\n+}\n+\n+func (cc *clientConn) String() string {\n+\treturn fmt.Sprintf(\"conn: %s, status: %d, charset: %s, user: %s, lastInsertId: %d\",\n+\t\tcc.conn.RemoteAddr(), cc.ctx.Status(), cc.charset, cc.user, cc.ctx.LastInsertID(),\n+\t)\n+}\n+\n+func (cc *clientConn) handshake() error {\n+\tif err := cc.writeInitialHandshake(); err != nil {\n+\t\treturn errors.Trace(err)\n+\t}\n+\tif err := cc.readHandshakeResponse(); err != nil {\n+\t\tcc.writeError(err)\n+\t\treturn errors.Trace(err)\n+\t}\n+\tdata := cc.alloc.AllocWithLen(4, 32)\n+\tdata = append(data, mysql.OKHeader)\n+\tdata = append(data, 0, 0)\n+\tif cc.capability&mysql.ClientProtocol41 > 0 {\n+\t\tdata = append(data, dumpUint16(mysql.ServerStatusAutocommit)...)\n+\t\tdata = append(data, 0, 0)\n+\t}\n+\n+\terr := cc.writePacket(data)\n+\tcc.pkg.sequence = 0\n+\tif err != nil {\n+\t\treturn errors.Trace(err)\n+\t}\n+\n+\treturn errors.Trace(cc.flush())\n+}\n+\n+func (cc *clientConn) Close() error {\n+\tcc.server.rwlock.Lock()\n+\tdelete(cc.server.clients, cc.connectionID)\n+\tcc.server.rwlock.Unlock()\n+\tcc.conn.Close()\n+\treturn cc.ctx.Close()\n+}\n+\n+func (cc *clientConn) writeInitialHandshake() error {\n+\tdata := make([]byte, 4, 128)\n+\n+\t//min version 10\n+\tdata = append(data, 10)\n+\t//server version[00]\n+\tdata = append(data, mysql.ServerVersion...)\n+\tdata = append(data, 0)\n+\t//connection id\n+\tdata = append(data, byte(cc.connectionID), byte(cc.connectionID>>8), byte(cc.connectionID>>16), byte(cc.connectionID>>24))\n+\t//auth-plugin-data-part-1\n+\tdata = append(data, cc.salt[0:8]...)\n+\t//filter [00]\n+\tdata = append(data, 0)\n+\t//capability flag lower 2 bytes, using default capability here\n+\tdata = append(data, byte(defaultCapability), byte(defaultCapability>>8))\n+\t//charset, utf-8 default\n+\tdata = append(data, uint8(mysql.DefaultCollationID))\n+\t//status\n+\tdata = append(data, dumpUint16(mysql.ServerStatusAutocommit)...)\n+\t//below 13 byte may not be used\n+\t//capability flag upper 2 bytes, using default capability here\n+\tdata = append(data, byte(defaultCapability>>16), byte(defaultCapability>>24))\n+\t//filter [0x15], for wireshark dump, value is 0x15\n+\tdata = append(data, 0x15)\n+\t//reserved 10 [00]\n+\tdata = append(data, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)\n+\t//auth-plugin-data-part-2\n+\tdata = append(data, cc.salt[8:]...)\n+\t//filter [00]\n+\tdata = append(data, 0)\n+\terr := cc.writePacket(data)\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\treturn cc.flush()\n+}\n+\n+func (cc *clientConn) readPacket() ([]byte, error) {\n+\treturn cc.pkg.readPacket()\n+}\n+\n+func (cc *clientConn) writePacket(data []byte) error {\n+\treturn cc.pkg.writePacket(data)\n+}\n+\n+func calcPassword(scramble, password []byte) []byte {\n+\tif len(password) == 0 {\n+\t\treturn nil","path":"tidb-server/server/conn.go","position":141,"original_position":141,"commit_id":"a78a36a7481c035615da3bdfbbc34644634c0965","original_commit_id":"a78a36a7481c035615da3bdfbbc34644634c0965","user":{"login":"qiuyesuifeng","id":1953644,"avatar_url":"https://avatars.githubusercontent.com/u/1953644?v=3","gravatar_id":"","url":"https://api.github.com/users/qiuyesuifeng","html_url":"https://github.com/qiuyesuifeng","followers_url":"https://api.github.com/users/qiuyesuifeng/followers","following_url":"https://api.github.com/users/qiuyesuifeng/following{/other_user}","gists_url":"https://api.github.com/users/qiuyesuifeng/gists{/gist_id}","starred_url":"https://api.github.com/users/qiuyesuifeng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/qiuyesuifeng/subscriptions","organizations_url":"https://api.github.com/users/qiuyesuifeng/orgs","repos_url":"https://api.github.com/users/qiuyesuifeng/repos","events_url":"https://api.github.com/users/qiuyesuifeng/events{/privacy}","received_events_url":"https://api.github.com/users/qiuyesuifeng/received_events","type":"User","site_admin":false},"body":"Here return nil or []byte{} ?","created_at":"2015-09-16T10:32:23Z","updated_at":"2015-09-16T10:32:23Z","html_url":"https://github.com/pingcap/tidb/pull/170#discussion_r39614616","pull_request_url":"https://api.github.com/repos/pingcap/tidb/pulls/170","_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments/39614616"},"html":{"href":"https://github.com/pingcap/tidb/pull/170#discussion_r39614616"},"pull_request":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/170"}}},"pull_request":{"url":"https://api.github.com/repos/pingcap/tidb/pulls/170","id":45149076,"html_url":"https://github.com/pingcap/tidb/pull/170","diff_url":"https://github.com/pingcap/tidb/pull/170.diff","patch_url":"https://github.com/pingcap/tidb/pull/170.patch","issue_url":"https://api.github.com/repos/pingcap/tidb/issues/170","number":170,"state":"open","locked":false,"title":"TiDB MySQL protocol server","user":{"login":"coocood","id":891222,"avatar_url":"https://avatars.githubusercontent.com/u/891222?v=3","gravatar_id":"","url":"https://api.github.com/users/coocood","html_url":"https://github.com/coocood","followers_url":"https://api.github.com/users/coocood/followers","following_url":"https://api.github.com/users/coocood/following{/other_user}","gists_url":"https://api.github.com/users/coocood/gists{/gist_id}","starred_url":"https://api.github.com/users/coocood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coocood/subscriptions","organizations_url":"https://api.github.com/users/coocood/orgs","repos_url":"https://api.github.com/users/coocood/repos","events_url":"https://api.github.com/users/coocood/events{/privacy}","received_events_url":"https://api.github.com/users/coocood/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-16T09:27:44Z","updated_at":"2015-09-16T10:32:23Z","closed_at":null,"merged_at":null,"merge_commit_sha":"a3e84dce049eb3583854d57a323e092fd5e43ae4","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/pingcap/tidb/pulls/170/commits","review_comments_url":"https://api.github.com/repos/pingcap/tidb/pulls/170/comments","review_comment_url":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}","comments_url":"https://api.github.com/repos/pingcap/tidb/issues/170/comments","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/a78a36a7481c035615da3bdfbbc34644634c0965","head":{"label":"pingcap:coocood/tidb-server","ref":"coocood/tidb-server","sha":"a78a36a7481c035615da3bdfbbc34644634c0965","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-09-16T10:16:11Z","pushed_at":"2015-09-16T10:10:29Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":5369,"stargazers_count":1980,"watchers_count":1980,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":171,"mirror_url":null,"open_issues_count":22,"forks":171,"open_issues":22,"watchers":1980,"default_branch":"master"}},"base":{"label":"pingcap:master","ref":"master","sha":"e2d0b02acbaf66884ca74691835a20c4956416d1","user":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"repo":{"id":41986369,"name":"tidb","full_name":"pingcap/tidb","owner":{"login":"pingcap","id":11855343,"avatar_url":"https://avatars.githubusercontent.com/u/11855343?v=3","gravatar_id":"","url":"https://api.github.com/users/pingcap","html_url":"https://github.com/pingcap","followers_url":"https://api.github.com/users/pingcap/followers","following_url":"https://api.github.com/users/pingcap/following{/other_user}","gists_url":"https://api.github.com/users/pingcap/gists{/gist_id}","starred_url":"https://api.github.com/users/pingcap/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pingcap/subscriptions","organizations_url":"https://api.github.com/users/pingcap/orgs","repos_url":"https://api.github.com/users/pingcap/repos","events_url":"https://api.github.com/users/pingcap/events{/privacy}","received_events_url":"https://api.github.com/users/pingcap/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/pingcap/tidb","description":"TiDB is a distributed SQL database compatible with MySQL protocol.","fork":false,"url":"https://api.github.com/repos/pingcap/tidb","forks_url":"https://api.github.com/repos/pingcap/tidb/forks","keys_url":"https://api.github.com/repos/pingcap/tidb/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pingcap/tidb/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pingcap/tidb/teams","hooks_url":"https://api.github.com/repos/pingcap/tidb/hooks","issue_events_url":"https://api.github.com/repos/pingcap/tidb/issues/events{/number}","events_url":"https://api.github.com/repos/pingcap/tidb/events","assignees_url":"https://api.github.com/repos/pingcap/tidb/assignees{/user}","branches_url":"https://api.github.com/repos/pingcap/tidb/branches{/branch}","tags_url":"https://api.github.com/repos/pingcap/tidb/tags","blobs_url":"https://api.github.com/repos/pingcap/tidb/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pingcap/tidb/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pingcap/tidb/git/refs{/sha}","trees_url":"https://api.github.com/repos/pingcap/tidb/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pingcap/tidb/statuses/{sha}","languages_url":"https://api.github.com/repos/pingcap/tidb/languages","stargazers_url":"https://api.github.com/repos/pingcap/tidb/stargazers","contributors_url":"https://api.github.com/repos/pingcap/tidb/contributors","subscribers_url":"https://api.github.com/repos/pingcap/tidb/subscribers","subscription_url":"https://api.github.com/repos/pingcap/tidb/subscription","commits_url":"https://api.github.com/repos/pingcap/tidb/commits{/sha}","git_commits_url":"https://api.github.com/repos/pingcap/tidb/git/commits{/sha}","comments_url":"https://api.github.com/repos/pingcap/tidb/comments{/number}","issue_comment_url":"https://api.github.com/repos/pingcap/tidb/issues/comments{/number}","contents_url":"https://api.github.com/repos/pingcap/tidb/contents/{+path}","compare_url":"https://api.github.com/repos/pingcap/tidb/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pingcap/tidb/merges","archive_url":"https://api.github.com/repos/pingcap/tidb/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pingcap/tidb/downloads","issues_url":"https://api.github.com/repos/pingcap/tidb/issues{/number}","pulls_url":"https://api.github.com/repos/pingcap/tidb/pulls{/number}","milestones_url":"https://api.github.com/repos/pingcap/tidb/milestones{/number}","notifications_url":"https://api.github.com/repos/pingcap/tidb/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pingcap/tidb/labels{/name}","releases_url":"https://api.github.com/repos/pingcap/tidb/releases{/id}","created_at":"2015-09-06T04:01:52Z","updated_at":"2015-09-16T10:16:11Z","pushed_at":"2015-09-16T10:10:29Z","git_url":"git://github.com/pingcap/tidb.git","ssh_url":"git@github.com:pingcap/tidb.git","clone_url":"https://github.com/pingcap/tidb.git","svn_url":"https://github.com/pingcap/tidb","homepage":"","size":5369,"stargazers_count":1980,"watchers_count":1980,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":171,"mirror_url":null,"open_issues_count":22,"forks":171,"open_issues":22,"watchers":1980,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/170"},"html":{"href":"https://github.com/pingcap/tidb/pull/170"},"issue":{"href":"https://api.github.com/repos/pingcap/tidb/issues/170"},"comments":{"href":"https://api.github.com/repos/pingcap/tidb/issues/170/comments"},"review_comments":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/170/comments"},"review_comment":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/pingcap/tidb/pulls/170/commits"},"statuses":{"href":"https://api.github.com/repos/pingcap/tidb/statuses/a78a36a7481c035615da3bdfbbc34644634c0965"}}}}