# Path: neubot/runner_hosts.py
# RUNNER_HOSTS = RunnerHosts()
# 
# Path: neubot/utils_net.py
# INPROGRESS = [ 0, errno.EINPROGRESS, errno.EWOULDBLOCK, errno.EAGAIN ]
# COMPARE_AF = {
#     socket.AF_INET: 1,
#     socket.AF_INET6: 2,
# }
# def format_epnt(epnt):
# def format_epnt_web100(epnt):
# def format_ainfo(ainfo):
# def addrinfo_key(ainfo):
# def listen(epnt, prefer_ipv6):
# def connect(epnt, prefer_ipv6):
# def isconnected(endpoint, sock):
# def __strip_ipv4mapped_prefix(function):
# def __strip_ipv4mapped_prefix1(result):
# def getpeername(sock):
# def getsockname(sock):


from neubot.runner_hosts import RUNNER_HOSTS
from neubot import utils_net
# other components can ask it the URI for negotiating and
# running a test.
#



class RunnerTests(object):

    ''' Implements list of available tests '''

    # Adapted from rendezvous/client.py

    def __init__(self):
        ''' Initialize list of available tests '''
        self.avail = {}
        self.last = None

    def update(self, avail):
        ''' Update the list of available tests '''
        # For now just trust what the rendezvous passes us
        self.avail = avail

    def test_to_negotiate_uri(self, test):
        ''' Map test to its negotiate URI '''
        if test in self.avail:
            # Do not cache results (see runner_hosts comment on that)
            result = self.avail[test][0]
            self.avail.clear()
            return result
        else:

# Path: neubot/runner_hosts.py
# RUNNER_HOSTS = RunnerHosts()
# 
# Path: neubot/utils_net.py
# INPROGRESS = [ 0, errno.EINPROGRESS, errno.EWOULDBLOCK, errno.EAGAIN ]
# COMPARE_AF = {
#     socket.AF_INET: 1,
#     socket.AF_INET6: 2,
# }
# def format_epnt(epnt):
# def format_epnt_web100(epnt):
# def format_ainfo(ainfo):
# def addrinfo_key(ainfo):
# def listen(epnt, prefer_ipv6):
# def connect(epnt, prefer_ipv6):
# def isconnected(endpoint, sock):
# def __strip_ipv4mapped_prefix(function):
# def __strip_ipv4mapped_prefix1(result):
# def getpeername(sock):
# def getsockname(sock):


# Path: neubot/runner_tests.py
from neubot.runner_hosts import RUNNER_HOSTS
from neubot import utils_net

# other components can ask it the URI for negotiating and
# running a test.
#



class RunnerTests(object):

    ''' Implements list of available tests '''

    # Adapted from rendezvous/client.py

    def __init__(self):
        ''' Initialize list of available tests '''
        self.avail = {}
        self.last = None

    def update(self, avail):
        ''' Update the list of available tests '''
        # For now just trust what the rendezvous passes us
        self.avail = avail

    def test_to_negotiate_uri(self, test):
        ''' Map test to its negotiate URI '''
        if test in self.avail:
            # Do not cache results (see runner_hosts comment on that)
            result = self.avail[test][0]
            self.avail.clear()
            return result
        else:

            fqdn = RUNNER_HOSTS.get_random_static_host()