{"action":"created","comment":{"url":"https://api.github.com/repos/syncthing/syncthing/pulls/comments/45544616","id":45544616,"diff_hunk":"@@ -176,42 +177,46 @@ type dynamicAnnouncement struct {\n \t}\n }\n \n-// relayAddressesSortedByLatency adds local latency to the relay, and sorts them\n-// by sum latency, and returns the addresses.\n-func relayAddressesSortedByLatency(input []string) []string {\n-\trelays := make(relayList, len(input))\n-\tfor i, relay := range input {\n-\t\tif latency, err := osutil.GetLatencyForURL(relay); err == nil {\n-\t\t\trelays[i] = relayWithLatency{relay, int(latency / time.Millisecond)}\n-\t\t} else {\n-\t\t\trelays[i] = relayWithLatency{relay, int(time.Hour / time.Millisecond)}\n+// relayAddressesOrder checks the latency to each relay, rounds latency down to\n+// the closest 30ms, and puts them in buckets of 50ms latency ranges. Then\n+// shuffles each bucket, and returns all addresses starting with the ones from\n+// the lowest latency bucket, ending with the highest latency buceket.\n+func relayAddressesOrder(input []string) []string {\n+\tbuckets := make(map[int][]string)\n+\n+\tfor _, relay := range input {\n+\t\tlatency, err := osutil.GetLatencyForURL(relay)\n+\t\tif err != nil {\n+\t\t\tlatency = time.Hour\n \t\t}\n-\t}\n \n-\tsort.Sort(relays)\n+\t\tid := int(latency/time.Millisecond) % 50","path":"lib/relay/client/dynamic.go","position":45,"original_position":45,"commit_id":"aa2dd7f38e0304891b97070c1da8ccc3ff33cc88","original_commit_id":"aa2dd7f38e0304891b97070c1da8ccc3ff33cc88","user":{"login":"calmh","id":125426,"avatar_url":"https://avatars.githubusercontent.com/u/125426?v=3","gravatar_id":"","url":"https://api.github.com/users/calmh","html_url":"https://github.com/calmh","followers_url":"https://api.github.com/users/calmh/followers","following_url":"https://api.github.com/users/calmh/following{/other_user}","gists_url":"https://api.github.com/users/calmh/gists{/gist_id}","starred_url":"https://api.github.com/users/calmh/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/calmh/subscriptions","organizations_url":"https://api.github.com/users/calmh/orgs","repos_url":"https://api.github.com/users/calmh/repos","events_url":"https://api.github.com/users/calmh/events{/privacy}","received_events_url":"https://api.github.com/users/calmh/received_events","type":"User","site_admin":false},"body":"Relays with latencies of 1 ms, 51 ms and 1001 ms will all end up in bucket 1?","created_at":"2015-11-21T10:53:55Z","updated_at":"2015-11-21T10:53:55Z","html_url":"https://github.com/syncthing/syncthing/pull/2498#discussion_r45544616","pull_request_url":"https://api.github.com/repos/syncthing/syncthing/pulls/2498","_links":{"self":{"href":"https://api.github.com/repos/syncthing/syncthing/pulls/comments/45544616"},"html":{"href":"https://github.com/syncthing/syncthing/pull/2498#discussion_r45544616"},"pull_request":{"href":"https://api.github.com/repos/syncthing/syncthing/pulls/2498"}}},"pull_request":{"url":"https://api.github.com/repos/syncthing/syncthing/pulls/2498","id":51424316,"html_url":"https://github.com/syncthing/syncthing/pull/2498","diff_url":"https://github.com/syncthing/syncthing/pull/2498.diff","patch_url":"https://github.com/syncthing/syncthing/pull/2498.patch","issue_url":"https://api.github.com/repos/syncthing/syncthing/issues/2498","number":2498,"state":"open","locked":false,"title":"Change the way relays are chosen, add RelayFull message.","user":{"login":"AudriusButkevicius","id":1144861,"avatar_url":"https://avatars.githubusercontent.com/u/1144861?v=3","gravatar_id":"","url":"https://api.github.com/users/AudriusButkevicius","html_url":"https://github.com/AudriusButkevicius","followers_url":"https://api.github.com/users/AudriusButkevicius/followers","following_url":"https://api.github.com/users/AudriusButkevicius/following{/other_user}","gists_url":"https://api.github.com/users/AudriusButkevicius/gists{/gist_id}","starred_url":"https://api.github.com/users/AudriusButkevicius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AudriusButkevicius/subscriptions","organizations_url":"https://api.github.com/users/AudriusButkevicius/orgs","repos_url":"https://api.github.com/users/AudriusButkevicius/repos","events_url":"https://api.github.com/users/AudriusButkevicius/events{/privacy}","received_events_url":"https://api.github.com/users/AudriusButkevicius/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-11-20T23:59:45Z","updated_at":"2015-11-21T10:53:55Z","closed_at":null,"merged_at":null,"merge_commit_sha":"8d6d0819d049ed5ded56904d27fe1b4e17a333aa","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/syncthing/syncthing/pulls/2498/commits","review_comments_url":"https://api.github.com/repos/syncthing/syncthing/pulls/2498/comments","review_comment_url":"https://api.github.com/repos/syncthing/syncthing/pulls/comments{/number}","comments_url":"https://api.github.com/repos/syncthing/syncthing/issues/2498/comments","statuses_url":"https://api.github.com/repos/syncthing/syncthing/statuses/aa2dd7f38e0304891b97070c1da8ccc3ff33cc88","head":{"label":"AudriusButkevicius:relaystuff","ref":"relaystuff","sha":"aa2dd7f38e0304891b97070c1da8ccc3ff33cc88","user":{"login":"AudriusButkevicius","id":1144861,"avatar_url":"https://avatars.githubusercontent.com/u/1144861?v=3","gravatar_id":"","url":"https://api.github.com/users/AudriusButkevicius","html_url":"https://github.com/AudriusButkevicius","followers_url":"https://api.github.com/users/AudriusButkevicius/followers","following_url":"https://api.github.com/users/AudriusButkevicius/following{/other_user}","gists_url":"https://api.github.com/users/AudriusButkevicius/gists{/gist_id}","starred_url":"https://api.github.com/users/AudriusButkevicius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AudriusButkevicius/subscriptions","organizations_url":"https://api.github.com/users/AudriusButkevicius/orgs","repos_url":"https://api.github.com/users/AudriusButkevicius/repos","events_url":"https://api.github.com/users/AudriusButkevicius/events{/privacy}","received_events_url":"https://api.github.com/users/AudriusButkevicius/received_events","type":"User","site_admin":false},"repo":{"id":22119752,"name":"syncthing","full_name":"AudriusButkevicius/syncthing","owner":{"login":"AudriusButkevicius","id":1144861,"avatar_url":"https://avatars.githubusercontent.com/u/1144861?v=3","gravatar_id":"","url":"https://api.github.com/users/AudriusButkevicius","html_url":"https://github.com/AudriusButkevicius","followers_url":"https://api.github.com/users/AudriusButkevicius/followers","following_url":"https://api.github.com/users/AudriusButkevicius/following{/other_user}","gists_url":"https://api.github.com/users/AudriusButkevicius/gists{/gist_id}","starred_url":"https://api.github.com/users/AudriusButkevicius/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/AudriusButkevicius/subscriptions","organizations_url":"https://api.github.com/users/AudriusButkevicius/orgs","repos_url":"https://api.github.com/users/AudriusButkevicius/repos","events_url":"https://api.github.com/users/AudriusButkevicius/events{/privacy}","received_events_url":"https://api.github.com/users/AudriusButkevicius/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/AudriusButkevicius/syncthing","description":"Open Source Continuous File Synchronization","fork":true,"url":"https://api.github.com/repos/AudriusButkevicius/syncthing","forks_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/forks","keys_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/teams","hooks_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/hooks","issue_events_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/issues/events{/number}","events_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/events","assignees_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/assignees{/user}","branches_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/branches{/branch}","tags_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/tags","blobs_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/git/refs{/sha}","trees_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/statuses/{sha}","languages_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/languages","stargazers_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/stargazers","contributors_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/contributors","subscribers_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/subscribers","subscription_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/subscription","commits_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/commits{/sha}","git_commits_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/git/commits{/sha}","comments_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/comments{/number}","issue_comment_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/issues/comments{/number}","contents_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/contents/{+path}","compare_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/merges","archive_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/downloads","issues_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/issues{/number}","pulls_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/pulls{/number}","milestones_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/milestones{/number}","notifications_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/labels{/name}","releases_url":"https://api.github.com/repos/AudriusButkevicius/syncthing/releases{/id}","created_at":"2014-07-22T20:36:14Z","updated_at":"2015-03-30T20:58:54Z","pushed_at":"2015-11-21T03:14:01Z","git_url":"git://github.com/AudriusButkevicius/syncthing.git","ssh_url":"git@github.com:AudriusButkevicius/syncthing.git","clone_url":"https://github.com/AudriusButkevicius/syncthing.git","svn_url":"https://github.com/AudriusButkevicius/syncthing","homepage":"http://discourse.syncthing.net/","size":57507,"stargazers_count":1,"watchers_count":1,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":1,"default_branch":"master"}},"base":{"label":"syncthing:master","ref":"master","sha":"945ddc240351c8fe02642ec85846a6352756eb23","user":{"login":"syncthing","id":7628018,"avatar_url":"https://avatars.githubusercontent.com/u/7628018?v=3","gravatar_id":"","url":"https://api.github.com/users/syncthing","html_url":"https://github.com/syncthing","followers_url":"https://api.github.com/users/syncthing/followers","following_url":"https://api.github.com/users/syncthing/following{/other_user}","gists_url":"https://api.github.com/users/syncthing/gists{/gist_id}","starred_url":"https://api.github.com/users/syncthing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syncthing/subscriptions","organizations_url":"https://api.github.com/users/syncthing/orgs","repos_url":"https://api.github.com/users/syncthing/repos","events_url":"https://api.github.com/users/syncthing/events{/privacy}","received_events_url":"https://api.github.com/users/syncthing/received_events","type":"Organization","site_admin":false},"repo":{"id":14712850,"name":"syncthing","full_name":"syncthing/syncthing","owner":{"login":"syncthing","id":7628018,"avatar_url":"https://avatars.githubusercontent.com/u/7628018?v=3","gravatar_id":"","url":"https://api.github.com/users/syncthing","html_url":"https://github.com/syncthing","followers_url":"https://api.github.com/users/syncthing/followers","following_url":"https://api.github.com/users/syncthing/following{/other_user}","gists_url":"https://api.github.com/users/syncthing/gists{/gist_id}","starred_url":"https://api.github.com/users/syncthing/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/syncthing/subscriptions","organizations_url":"https://api.github.com/users/syncthing/orgs","repos_url":"https://api.github.com/users/syncthing/repos","events_url":"https://api.github.com/users/syncthing/events{/privacy}","received_events_url":"https://api.github.com/users/syncthing/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/syncthing/syncthing","description":"Open Source Continuous File Synchronization","fork":false,"url":"https://api.github.com/repos/syncthing/syncthing","forks_url":"https://api.github.com/repos/syncthing/syncthing/forks","keys_url":"https://api.github.com/repos/syncthing/syncthing/keys{/key_id}","collaborators_url":"https://api.github.com/repos/syncthing/syncthing/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/syncthing/syncthing/teams","hooks_url":"https://api.github.com/repos/syncthing/syncthing/hooks","issue_events_url":"https://api.github.com/repos/syncthing/syncthing/issues/events{/number}","events_url":"https://api.github.com/repos/syncthing/syncthing/events","assignees_url":"https://api.github.com/repos/syncthing/syncthing/assignees{/user}","branches_url":"https://api.github.com/repos/syncthing/syncthing/branches{/branch}","tags_url":"https://api.github.com/repos/syncthing/syncthing/tags","blobs_url":"https://api.github.com/repos/syncthing/syncthing/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/syncthing/syncthing/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/syncthing/syncthing/git/refs{/sha}","trees_url":"https://api.github.com/repos/syncthing/syncthing/git/trees{/sha}","statuses_url":"https://api.github.com/repos/syncthing/syncthing/statuses/{sha}","languages_url":"https://api.github.com/repos/syncthing/syncthing/languages","stargazers_url":"https://api.github.com/repos/syncthing/syncthing/stargazers","contributors_url":"https://api.github.com/repos/syncthing/syncthing/contributors","subscribers_url":"https://api.github.com/repos/syncthing/syncthing/subscribers","subscription_url":"https://api.github.com/repos/syncthing/syncthing/subscription","commits_url":"https://api.github.com/repos/syncthing/syncthing/commits{/sha}","git_commits_url":"https://api.github.com/repos/syncthing/syncthing/git/commits{/sha}","comments_url":"https://api.github.com/repos/syncthing/syncthing/comments{/number}","issue_comment_url":"https://api.github.com/repos/syncthing/syncthing/issues/comments{/number}","contents_url":"https://api.github.com/repos/syncthing/syncthing/contents/{+path}","compare_url":"https://api.github.com/repos/syncthing/syncthing/compare/{base}...{head}","merges_url":"https://api.github.com/repos/syncthing/syncthing/merges","archive_url":"https://api.github.com/repos/syncthing/syncthing/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/syncthing/syncthing/downloads","issues_url":"https://api.github.com/repos/syncthing/syncthing/issues{/number}","pulls_url":"https://api.github.com/repos/syncthing/syncthing/pulls{/number}","milestones_url":"https://api.github.com/repos/syncthing/syncthing/milestones{/number}","notifications_url":"https://api.github.com/repos/syncthing/syncthing/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/syncthing/syncthing/labels{/name}","releases_url":"https://api.github.com/repos/syncthing/syncthing/releases{/id}","created_at":"2013-11-26T09:48:21Z","updated_at":"2015-11-20T21:06:57Z","pushed_at":"2015-11-21T08:52:47Z","git_url":"git://github.com/syncthing/syncthing.git","ssh_url":"git@github.com:syncthing/syncthing.git","clone_url":"https://github.com/syncthing/syncthing.git","svn_url":"https://github.com/syncthing/syncthing","homepage":"http://forum.syncthing.net/","size":63270,"stargazers_count":10392,"watchers_count":10392,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":765,"mirror_url":null,"open_issues_count":174,"forks":765,"open_issues":174,"watchers":10392,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/syncthing/syncthing/pulls/2498"},"html":{"href":"https://github.com/syncthing/syncthing/pull/2498"},"issue":{"href":"https://api.github.com/repos/syncthing/syncthing/issues/2498"},"comments":{"href":"https://api.github.com/repos/syncthing/syncthing/issues/2498/comments"},"review_comments":{"href":"https://api.github.com/repos/syncthing/syncthing/pulls/2498/comments"},"review_comment":{"href":"https://api.github.com/repos/syncthing/syncthing/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/syncthing/syncthing/pulls/2498/commits"},"statuses":{"href":"https://api.github.com/repos/syncthing/syncthing/statuses/aa2dd7f38e0304891b97070c1da8ccc3ff33cc88"}}}}