| Index: telemetry/telemetry/internal/forwarders/__init__.py
|
| diff --git a/telemetry/telemetry/internal/forwarders/__init__.py b/telemetry/telemetry/internal/forwarders/__init__.py
|
| index b11fbfeee761c930fa2016820168ed742546d1d3..45f92392028306132e4c369c1dfad9b604b18442 100644
|
| --- a/telemetry/telemetry/internal/forwarders/__init__.py
|
| +++ b/telemetry/telemetry/internal/forwarders/__init__.py
|
| @@ -8,15 +8,36 @@
|
| PortPair = collections.namedtuple('PortPair', ['local_port', 'remote_port'])
|
| PortSet = collections.namedtuple('PortSet', ['http', 'https', 'dns'])
|
|
|
| +class PortPairs(collections.namedtuple('PortPairs', ['http', 'https', 'dns'])):
|
| + __slots__ = ()
|
| +
|
| + @classmethod
|
| + def Zip(cls, local_ports, remote_ports):
|
| + """Zip a pair of PortSet's into a single PortPairs object."""
|
| + with_dns = local_ports.dns is not None and remote_ports.dns is not None
|
| + return cls(
|
| + PortPair(local_ports.http, remote_ports.http),
|
| + PortPair(local_ports.https, remote_ports.https),
|
| + PortPair(local_ports.dns, remote_ports.dns) if with_dns else None)
|
| +
|
| + @property
|
| + def local_ports(self):
|
| + """Return a tuple of local ports only."""
|
| + return PortSet(*[p.local_port if p is not None else None for p in self])
|
| +
|
| + @property
|
| + def remote_ports(self):
|
| + """Return a tuple of remote ports only."""
|
| + return PortSet(*[p.remote_port if p is not None else None for p in self])
|
|
|
|
|
| class ForwarderFactory(object):
|
|
|
| - def Create(self, port_pair):
|
| + def Create(self, port_pairs):
|
| """Creates a forwarder that maps remote (device) <-> local (host) ports.
|
|
|
| Args:
|
| - port_pair: A PortPairs instance that consists of a PortPair mapping
|
| + port_pairs: A PortPairs instance that consists of a PortPair mapping
|
| for each protocol. http is required. https and dns may be None.
|
| """
|
| raise NotImplementedError()
|
| @@ -28,22 +49,22 @@
|
|
|
| class Forwarder(object):
|
|
|
| - def __init__(self, port_pair):
|
| - assert port_pair, 'Port mapping is required.'
|
| - self._port_pair = port_pair
|
| + def __init__(self, port_pairs):
|
| + assert port_pairs.http, 'HTTP port mapping is required.'
|
| + self._port_pairs = port_pairs
|
| self._forwarding = True
|
|
|
| @property
|
| def host_port(self):
|
| - return self._port_pair.remote_port
|
| + return self._port_pairs.http.remote_port
|
|
|
| @property
|
| def host_ip(self):
|
| return '127.0.0.1'
|
|
|
| @property
|
| - def port_pair(self):
|
| - return self._port_pair
|
| + def port_pairs(self):
|
| + return self._port_pairs
|
|
|
| @property
|
| def url(self):
|
| @@ -51,5 +72,5 @@
|
| return 'http://%s:%i' % (self.host_ip, self.host_port)
|
|
|
| def Close(self):
|
| - self._port_pair = None
|
| + self._port_pairs = None
|
| self._forwarding = False
|
|
|