{"action":"created","comment":{"url":"https://api.github.com/repos/chihaya/chihaya/pulls/comments/77011689","id":77011689,"diff_hunk":"@@ -99,41 +103,69 @@ func ParseAnnounce(r Request, allowIPSpoofing bool) (*bittorrent.AnnounceRequest\n \n // handleOptionalParameters parses the optional parameters as described in BEP\n // 41 and updates an announce with the values parsed.\n-func handleOptionalParameters(packet []byte) (params bittorrent.Params, err error) {\n-\tif len(packet) <= 98 {\n-\t\treturn\n+func handleOptionalParameters(packet []byte) (bittorrent.Params, error) {\n+\tif len(packet) == 0 {\n+\t\treturn emptyURLData, nil\n \t}\n \n-\toptionStartIndex := 98\n-\tfor optionStartIndex < len(packet)-1 {\n-\t\toption := packet[optionStartIndex]\n+\tvar buf bytes.Buffer\n+\n+\tfor i := 0; i < len(packet); {\n+\t\toption := packet[i]\n \t\tswitch option {\n \t\tcase optionEndOfOptions:\n-\t\t\treturn\n-\n+\t\t\treturn parseURLData(buf.String())\n \t\tcase optionNOP:\n-\t\t\toptionStartIndex++\n-\n+\t\t\ti++\n \t\tcase optionURLData:\n-\t\t\tif optionStartIndex+1 > len(packet)-1 {\n-\t\t\t\treturn params, errMalformedPacket\n+\t\t\tif i+1 >= len(packet) {\n+\t\t\t\treturn nil, errMalformedPacket\n \t\t\t}\n \n-\t\t\tlength := int(packet[optionStartIndex+1])\n-\t\t\tif optionStartIndex+1+length > len(packet)-1 {\n-\t\t\t\treturn params, errMalformedPacket\n+\t\t\tlength := int(packet[i+1])\n+\t\t\tif i+2+length > len(packet) {\n+\t\t\t\treturn nil, errMalformedPacket\n \t\t\t}\n \n-\t\t\t// TODO(chihaya): Actually parse the URL Data as described in BEP 41\n-\t\t\t// into something that fulfills the bittorrent.Params interface.\n+\t\t\tn, err := buf.Write(packet[i+2 : i+2+length])","path":"frontend/udp/parser.go","position":84,"original_position":84,"commit_id":"bdbd1be4755e6b2b272b1713bdc8eb92dc7b4184","original_commit_id":"bdbd1be4755e6b2b272b1713bdc8eb92dc7b4184","user":{"login":"mrd0ll4r","id":15063379,"avatar_url":"https://avatars.githubusercontent.com/u/15063379?v=3","gravatar_id":"","url":"https://api.github.com/users/mrd0ll4r","html_url":"https://github.com/mrd0ll4r","followers_url":"https://api.github.com/users/mrd0ll4r/followers","following_url":"https://api.github.com/users/mrd0ll4r/following{/other_user}","gists_url":"https://api.github.com/users/mrd0ll4r/gists{/gist_id}","starred_url":"https://api.github.com/users/mrd0ll4r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrd0ll4r/subscriptions","organizations_url":"https://api.github.com/users/mrd0ll4r/orgs","repos_url":"https://api.github.com/users/mrd0ll4r/repos","events_url":"https://api.github.com/users/mrd0ll4r/events{/privacy}","received_events_url":"https://api.github.com/users/mrd0ll4r/received_events","type":"User","site_admin":false},"body":"To concatenate multiple URLData blocks. Then again I don't know how often you'd have multiple blocks of URLData anyways, so using them as strings and concatenating in the improbable case might be the better choice.\r\n\r\nWe could pool the buffers?","created_at":"2016-08-31T15:37:57Z","updated_at":"2016-08-31T15:37:57Z","html_url":"https://github.com/chihaya/chihaya/pull/203#discussion_r77011689","pull_request_url":"https://api.github.com/repos/chihaya/chihaya/pulls/203","_links":{"self":{"href":"https://api.github.com/repos/chihaya/chihaya/pulls/comments/77011689"},"html":{"href":"https://github.com/chihaya/chihaya/pull/203#discussion_r77011689"},"pull_request":{"href":"https://api.github.com/repos/chihaya/chihaya/pulls/203"}}},"pull_request":{"url":"https://api.github.com/repos/chihaya/chihaya/pulls/203","id":83380043,"html_url":"https://github.com/chihaya/chihaya/pull/203","diff_url":"https://github.com/chihaya/chihaya/pull/203.diff","patch_url":"https://github.com/chihaya/chihaya/pull/203.patch","issue_url":"https://api.github.com/repos/chihaya/chihaya/issues/203","number":203,"state":"open","locked":false,"title":"udp: implement bep41","user":{"login":"mrd0ll4r","id":15063379,"avatar_url":"https://avatars.githubusercontent.com/u/15063379?v=3","gravatar_id":"","url":"https://api.github.com/users/mrd0ll4r","html_url":"https://github.com/mrd0ll4r","followers_url":"https://api.github.com/users/mrd0ll4r/followers","following_url":"https://api.github.com/users/mrd0ll4r/following{/other_user}","gists_url":"https://api.github.com/users/mrd0ll4r/gists{/gist_id}","starred_url":"https://api.github.com/users/mrd0ll4r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrd0ll4r/subscriptions","organizations_url":"https://api.github.com/users/mrd0ll4r/orgs","repos_url":"https://api.github.com/users/mrd0ll4r/repos","events_url":"https://api.github.com/users/mrd0ll4r/events{/privacy}","received_events_url":"https://api.github.com/users/mrd0ll4r/received_events","type":"User","site_admin":false},"body":"I was thinking if we should maybe put the path in the `Params` as well (under some predefined key) - opinions?","created_at":"2016-08-31T02:43:06Z","updated_at":"2016-08-31T15:37:57Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0ca55d549ac76ff94ae74be3832a8afc472e6cdf","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/chihaya/chihaya/pulls/203/commits","review_comments_url":"https://api.github.com/repos/chihaya/chihaya/pulls/203/comments","review_comment_url":"https://api.github.com/repos/chihaya/chihaya/pulls/comments{/number}","comments_url":"https://api.github.com/repos/chihaya/chihaya/issues/203/comments","statuses_url":"https://api.github.com/repos/chihaya/chihaya/statuses/bdbd1be4755e6b2b272b1713bdc8eb92dc7b4184","head":{"label":"mrd0ll4r:refactor-bep41","ref":"refactor-bep41","sha":"bdbd1be4755e6b2b272b1713bdc8eb92dc7b4184","user":{"login":"mrd0ll4r","id":15063379,"avatar_url":"https://avatars.githubusercontent.com/u/15063379?v=3","gravatar_id":"","url":"https://api.github.com/users/mrd0ll4r","html_url":"https://github.com/mrd0ll4r","followers_url":"https://api.github.com/users/mrd0ll4r/followers","following_url":"https://api.github.com/users/mrd0ll4r/following{/other_user}","gists_url":"https://api.github.com/users/mrd0ll4r/gists{/gist_id}","starred_url":"https://api.github.com/users/mrd0ll4r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrd0ll4r/subscriptions","organizations_url":"https://api.github.com/users/mrd0ll4r/orgs","repos_url":"https://api.github.com/users/mrd0ll4r/repos","events_url":"https://api.github.com/users/mrd0ll4r/events{/privacy}","received_events_url":"https://api.github.com/users/mrd0ll4r/received_events","type":"User","site_admin":false},"repo":{"id":44922097,"name":"chihaya","full_name":"mrd0ll4r/chihaya","owner":{"login":"mrd0ll4r","id":15063379,"avatar_url":"https://avatars.githubusercontent.com/u/15063379?v=3","gravatar_id":"","url":"https://api.github.com/users/mrd0ll4r","html_url":"https://github.com/mrd0ll4r","followers_url":"https://api.github.com/users/mrd0ll4r/followers","following_url":"https://api.github.com/users/mrd0ll4r/following{/other_user}","gists_url":"https://api.github.com/users/mrd0ll4r/gists{/gist_id}","starred_url":"https://api.github.com/users/mrd0ll4r/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mrd0ll4r/subscriptions","organizations_url":"https://api.github.com/users/mrd0ll4r/orgs","repos_url":"https://api.github.com/users/mrd0ll4r/repos","events_url":"https://api.github.com/users/mrd0ll4r/events{/privacy}","received_events_url":"https://api.github.com/users/mrd0ll4r/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/mrd0ll4r/chihaya","description":"This is my personal fork of chihaya, a high-performance BitTorrent tracker in Go.","fork":true,"url":"https://api.github.com/repos/mrd0ll4r/chihaya","forks_url":"https://api.github.com/repos/mrd0ll4r/chihaya/forks","keys_url":"https://api.github.com/repos/mrd0ll4r/chihaya/keys{/key_id}","collaborators_url":"https://api.github.com/repos/mrd0ll4r/chihaya/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/mrd0ll4r/chihaya/teams","hooks_url":"https://api.github.com/repos/mrd0ll4r/chihaya/hooks","issue_events_url":"https://api.github.com/repos/mrd0ll4r/chihaya/issues/events{/number}","events_url":"https://api.github.com/repos/mrd0ll4r/chihaya/events","assignees_url":"https://api.github.com/repos/mrd0ll4r/chihaya/assignees{/user}","branches_url":"https://api.github.com/repos/mrd0ll4r/chihaya/branches{/branch}","tags_url":"https://api.github.com/repos/mrd0ll4r/chihaya/tags","blobs_url":"https://api.github.com/repos/mrd0ll4r/chihaya/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/mrd0ll4r/chihaya/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/mrd0ll4r/chihaya/git/refs{/sha}","trees_url":"https://api.github.com/repos/mrd0ll4r/chihaya/git/trees{/sha}","statuses_url":"https://api.github.com/repos/mrd0ll4r/chihaya/statuses/{sha}","languages_url":"https://api.github.com/repos/mrd0ll4r/chihaya/languages","stargazers_url":"https://api.github.com/repos/mrd0ll4r/chihaya/stargazers","contributors_url":"https://api.github.com/repos/mrd0ll4r/chihaya/contributors","subscribers_url":"https://api.github.com/repos/mrd0ll4r/chihaya/subscribers","subscription_url":"https://api.github.com/repos/mrd0ll4r/chihaya/subscription","commits_url":"https://api.github.com/repos/mrd0ll4r/chihaya/commits{/sha}","git_commits_url":"https://api.github.com/repos/mrd0ll4r/chihaya/git/commits{/sha}","comments_url":"https://api.github.com/repos/mrd0ll4r/chihaya/comments{/number}","issue_comment_url":"https://api.github.com/repos/mrd0ll4r/chihaya/issues/comments{/number}","contents_url":"https://api.github.com/repos/mrd0ll4r/chihaya/contents/{+path}","compare_url":"https://api.github.com/repos/mrd0ll4r/chihaya/compare/{base}...{head}","merges_url":"https://api.github.com/repos/mrd0ll4r/chihaya/merges","archive_url":"https://api.github.com/repos/mrd0ll4r/chihaya/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/mrd0ll4r/chihaya/downloads","issues_url":"https://api.github.com/repos/mrd0ll4r/chihaya/issues{/number}","pulls_url":"https://api.github.com/repos/mrd0ll4r/chihaya/pulls{/number}","milestones_url":"https://api.github.com/repos/mrd0ll4r/chihaya/milestones{/number}","notifications_url":"https://api.github.com/repos/mrd0ll4r/chihaya/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/mrd0ll4r/chihaya/labels{/name}","releases_url":"https://api.github.com/repos/mrd0ll4r/chihaya/releases{/id}","deployments_url":"https://api.github.com/repos/mrd0ll4r/chihaya/deployments","created_at":"2015-10-25T17:59:14Z","updated_at":"2016-02-13T11:39:28Z","pushed_at":"2016-08-31T02:42:49Z","git_url":"git://github.com/mrd0ll4r/chihaya.git","ssh_url":"git@github.com:mrd0ll4r/chihaya.git","clone_url":"https://github.com/mrd0ll4r/chihaya.git","svn_url":"https://github.com/mrd0ll4r/chihaya","homepage":"","size":3013,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"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":"chihaya:refactor","ref":"refactor","sha":"b5bf6b8acd0b8c60fe89477312dbd4a6d57a07df","user":{"login":"chihaya","id":6076200,"avatar_url":"https://avatars.githubusercontent.com/u/6076200?v=3","gravatar_id":"","url":"https://api.github.com/users/chihaya","html_url":"https://github.com/chihaya","followers_url":"https://api.github.com/users/chihaya/followers","following_url":"https://api.github.com/users/chihaya/following{/other_user}","gists_url":"https://api.github.com/users/chihaya/gists{/gist_id}","starred_url":"https://api.github.com/users/chihaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chihaya/subscriptions","organizations_url":"https://api.github.com/users/chihaya/orgs","repos_url":"https://api.github.com/users/chihaya/repos","events_url":"https://api.github.com/users/chihaya/events{/privacy}","received_events_url":"https://api.github.com/users/chihaya/received_events","type":"Organization","site_admin":false},"repo":{"id":7399031,"name":"chihaya","full_name":"chihaya/chihaya","owner":{"login":"chihaya","id":6076200,"avatar_url":"https://avatars.githubusercontent.com/u/6076200?v=3","gravatar_id":"","url":"https://api.github.com/users/chihaya","html_url":"https://github.com/chihaya","followers_url":"https://api.github.com/users/chihaya/followers","following_url":"https://api.github.com/users/chihaya/following{/other_user}","gists_url":"https://api.github.com/users/chihaya/gists{/gist_id}","starred_url":"https://api.github.com/users/chihaya/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chihaya/subscriptions","organizations_url":"https://api.github.com/users/chihaya/orgs","repos_url":"https://api.github.com/users/chihaya/repos","events_url":"https://api.github.com/users/chihaya/events{/privacy}","received_events_url":"https://api.github.com/users/chihaya/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/chihaya/chihaya","description":"A flexible BitTorrent tracker in Go.","fork":false,"url":"https://api.github.com/repos/chihaya/chihaya","forks_url":"https://api.github.com/repos/chihaya/chihaya/forks","keys_url":"https://api.github.com/repos/chihaya/chihaya/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chihaya/chihaya/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chihaya/chihaya/teams","hooks_url":"https://api.github.com/repos/chihaya/chihaya/hooks","issue_events_url":"https://api.github.com/repos/chihaya/chihaya/issues/events{/number}","events_url":"https://api.github.com/repos/chihaya/chihaya/events","assignees_url":"https://api.github.com/repos/chihaya/chihaya/assignees{/user}","branches_url":"https://api.github.com/repos/chihaya/chihaya/branches{/branch}","tags_url":"https://api.github.com/repos/chihaya/chihaya/tags","blobs_url":"https://api.github.com/repos/chihaya/chihaya/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chihaya/chihaya/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chihaya/chihaya/git/refs{/sha}","trees_url":"https://api.github.com/repos/chihaya/chihaya/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chihaya/chihaya/statuses/{sha}","languages_url":"https://api.github.com/repos/chihaya/chihaya/languages","stargazers_url":"https://api.github.com/repos/chihaya/chihaya/stargazers","contributors_url":"https://api.github.com/repos/chihaya/chihaya/contributors","subscribers_url":"https://api.github.com/repos/chihaya/chihaya/subscribers","subscription_url":"https://api.github.com/repos/chihaya/chihaya/subscription","commits_url":"https://api.github.com/repos/chihaya/chihaya/commits{/sha}","git_commits_url":"https://api.github.com/repos/chihaya/chihaya/git/commits{/sha}","comments_url":"https://api.github.com/repos/chihaya/chihaya/comments{/number}","issue_comment_url":"https://api.github.com/repos/chihaya/chihaya/issues/comments{/number}","contents_url":"https://api.github.com/repos/chihaya/chihaya/contents/{+path}","compare_url":"https://api.github.com/repos/chihaya/chihaya/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chihaya/chihaya/merges","archive_url":"https://api.github.com/repos/chihaya/chihaya/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chihaya/chihaya/downloads","issues_url":"https://api.github.com/repos/chihaya/chihaya/issues{/number}","pulls_url":"https://api.github.com/repos/chihaya/chihaya/pulls{/number}","milestones_url":"https://api.github.com/repos/chihaya/chihaya/milestones{/number}","notifications_url":"https://api.github.com/repos/chihaya/chihaya/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chihaya/chihaya/labels{/name}","releases_url":"https://api.github.com/repos/chihaya/chihaya/releases{/id}","deployments_url":"https://api.github.com/repos/chihaya/chihaya/deployments","created_at":"2013-01-01T21:08:47Z","updated_at":"2016-08-31T13:03:03Z","pushed_at":"2016-08-31T02:43:06Z","git_url":"git://github.com/chihaya/chihaya.git","ssh_url":"git@github.com:chihaya/chihaya.git","clone_url":"https://github.com/chihaya/chihaya.git","svn_url":"https://github.com/chihaya/chihaya","homepage":"","size":6192,"stargazers_count":425,"watchers_count":425,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":47,"mirror_url":null,"open_issues_count":27,"forks":47,"open_issues":27,"watchers":425,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/chihaya/chihaya/pulls/203"},"html":{"href":"https://github.com/chihaya/chihaya/pull/203"},"issue":{"href":"https://api.github.com/repos/chihaya/chihaya/issues/203"},"comments":{"href":"https://api.github.com/repos/chihaya/chihaya/issues/203/comments"},"review_comments":{"href":"https://api.github.com/repos/chihaya/chihaya/pulls/203/comments"},"review_comment":{"href":"https://api.github.com/repos/chihaya/chihaya/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/chihaya/chihaya/pulls/203/commits"},"statuses":{"href":"https://api.github.com/repos/chihaya/chihaya/statuses/bdbd1be4755e6b2b272b1713bdc8eb92dc7b4184"}}}}
{"actor":{"display_login":"mrd0ll4r"}}