1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
8 PortPair = collections.namedtuple('PortPair', ['local_port', 'remote_port'])
9 PortPairs = collections.namedtuple('PortPairs', ['http', 'https', 'dns'])
12 class ForwarderFactory(object):
14 def Create(self, port_pairs):
15 """Creates a forwarder that maps remote (device) <-> local (host) ports.
18 port_pairs: A PortPairs instance that consists of a PortPair mapping
19 for each protocol. http is required. https and dns may be None.
21 raise NotImplementedError()
28 def does_forwarder_override_dns(self):
32 class Forwarder(object):
34 def __init__(self, port_pairs):
35 assert port_pairs.http, 'HTTP port mapping is required.'
36 self._port_pairs = PortPairs(*[
37 PortPair(p.local_port, p.remote_port or p.local_port)
38 if p else None for p in port_pairs])
42 return self._port_pairs.http.remote_port
50 return self._port_pairs
54 assert self.host_ip and self.host_port
55 return 'http://%s:%i' % (self.host_ip, self.host_port)
58 self._port_pairs = None