{"action":"created","issue":{"url":"https://api.github.com/repos/sabnzbd/sabnzbd/issues/264","labels_url":"https://api.github.com/repos/sabnzbd/sabnzbd/issues/264/labels{/name}","comments_url":"https://api.github.com/repos/sabnzbd/sabnzbd/issues/264/comments","events_url":"https://api.github.com/repos/sabnzbd/sabnzbd/issues/264/events","html_url":"https://github.com/sabnzbd/sabnzbd/issues/264","id":97981689,"number":264,"title":"Feature: Happy Eyeballs (RFC6555) and Fastest Server/IP","user":{"login":"sanderjo","id":1273502,"avatar_url":"https://avatars.githubusercontent.com/u/1273502?v=3","gravatar_id":"","url":"https://api.github.com/users/sanderjo","html_url":"https://github.com/sanderjo","followers_url":"https://api.github.com/users/sanderjo/followers","following_url":"https://api.github.com/users/sanderjo/following{/other_user}","gists_url":"https://api.github.com/users/sanderjo/gists{/gist_id}","starred_url":"https://api.github.com/users/sanderjo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sanderjo/subscriptions","organizations_url":"https://api.github.com/users/sanderjo/orgs","repos_url":"https://api.github.com/users/sanderjo/repos","events_url":"https://api.github.com/users/sanderjo/events{/privacy}","received_events_url":"https://api.github.com/users/sanderjo/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-07-29T17:00:24Z","updated_at":"2015-07-31T07:17:50Z","closed_at":null,"body":"Triggered by https://forums.sabnzbd.org/viewtopic.php?f=2&t=19193, I wanted to implement \"Happy Eyeballs\" (RFC6555) for NNTP(S) connections in SABnzbd. Wikipedia tells: \"Happy Eyeballs (also called Fast Fallback) is an algorithm published by the IETF which can make dual-stack applications (those that understand both IPv4 and IPv6) more responsive to users, avoiding the usual problems faced by users with imperfect IPv6 connections or setups.\"\r\n\r\nFirst I created a python module 'happyeyeballs'. That code finds the fastest IP address for a (news)server, no matter if it's IPv4 or IPv6. It does this by checking the connect() to each IP address. So this is also good news for IPv4-only newsservers.\r\n(My implementation is not pure HappyEyeballs as my implementation does not give a time advantage to IPv6, and does checking of all IP addresses.)\r\n\r\nThe hook into SABnzbd.py was easy: sabnzbd/downloader.py has this function:\r\n\r\n```\r\n    @property\r\n    def hostip(self):\r\n        \"\"\" Return a random entry from the possible IPs\r\n        \"\"\"\r\n        if cfg.randomize_server_ip() and self.info and len(self.info) > 1:\r\n            rnd = random.randint(0, len(self.info)-1)\r\n            ip = self.info[rnd][4][0]\r\n            logging.debug('For server %s, using IP %s' % (self.host, ip))\r\n        else:\r\n            ip = self.host\r\n        return ip\r\n```\r\nSo, in my SAB code, with cfg.randomize_server_ip()==2, the HappyEyeballs / fastest IP is chosen.\r\n\r\nI will send a pull request so this can be included in 0.8.0 Alpha.\r\n\r\nExample output of code of the bare happyeyeballs code:\r\n\r\n```\r\n$ ./test-nntp-server.py newszilla.xs4all.nl\r\nChecking newszilla.xs4all.nl 119 SSL: False DEBUG: True\r\nAddress is  2001:888:0:18::119\r\nConnecting took: 0.995 msec\r\nAddress is  194.109.6.166\r\nConnecting took: 0.95 msec\r\nFastest server is 194.109.6.166\r\n194.109.6.166\r\n```\r\n\r\n```\r\nChecking block.cheapnews.eu 443 SSL: True DEBUG: True\r\n\r\nAddress is  2a02:d28:10:1b:0:431:ff02:165\r\nConnecting took: 3.461 msec\r\n\r\nAddress is  78.152.55.165\r\nConnecting took: 2.381 msec\r\n\r\nFastest server is 78.152.55.165\r\n78.152.55.165\r\n```\r\n\r\n```\r\n$ ./test-nntp-server.py sslreader.eweka.nl\r\nChecking sslreader.eweka.nl 119 SSL: False DEBUG: True\r\nAddress is  81.171.92.219\r\nConnecting took: 1.004 msec\r\nAddress is  81.171.92.233\r\nConnecting took: 0.894 msec\r\nAddress is  81.171.92.205\r\nConnecting took: 0.615 msec\r\nFastest server is 81.171.92.205\r\n81.171.92.205\r\n\r\n```\r\n\r\n\r\n\r\n"},"comment":{"url":"https://api.github.com/repos/sabnzbd/sabnzbd/issues/comments/126590323","html_url":"https://github.com/sabnzbd/sabnzbd/issues/264#issuecomment-126590323","issue_url":"https://api.github.com/repos/sabnzbd/sabnzbd/issues/264","id":126590323,"user":{"login":"thezoggy","id":500882,"avatar_url":"https://avatars.githubusercontent.com/u/500882?v=3","gravatar_id":"","url":"https://api.github.com/users/thezoggy","html_url":"https://github.com/thezoggy","followers_url":"https://api.github.com/users/thezoggy/followers","following_url":"https://api.github.com/users/thezoggy/following{/other_user}","gists_url":"https://api.github.com/users/thezoggy/gists{/gist_id}","starred_url":"https://api.github.com/users/thezoggy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thezoggy/subscriptions","organizations_url":"https://api.github.com/users/thezoggy/orgs","repos_url":"https://api.github.com/users/thezoggy/repos","events_url":"https://api.github.com/users/thezoggy/events{/privacy}","received_events_url":"https://api.github.com/users/thezoggy/received_events","type":"User","site_admin":false},"created_at":"2015-07-31T07:17:50Z","updated_at":"2015-07-31T07:17:50Z","body":"Quickest Response? First Response? might be better since not everyone probably knows latency.. and also for translation support"}}