OLD | NEW |
1 # Copyright 2016 The Chromium Authors. All rights reserved. | 1 # Copyright 2016 The Chromium Authors. All rights reserved. |
2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Start and stop tsproxy.""" | 5 """Start and stop tsproxy.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import re | 9 import re |
10 import subprocess | 10 import subprocess |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 | 106 |
107 def UpdateOutboundPorts(self, http_port, https_port, timeout=5): | 107 def UpdateOutboundPorts(self, http_port, https_port, timeout=5): |
108 assert http_port and https_port | 108 assert http_port and https_port |
109 assert http_port != https_port | 109 assert http_port != https_port |
110 assert isinstance(http_port, int) and isinstance(https_port, int) | 110 assert isinstance(http_port, int) and isinstance(https_port, int) |
111 assert 1 <= http_port <= 65535 | 111 assert 1 <= http_port <= 65535 |
112 assert 1 <= https_port <= 65535 | 112 assert 1 <= https_port <= 65535 |
113 self._IssueCommand('set mapports 443:%i,*:%i' % (https_port, http_port), | 113 self._IssueCommand('set mapports 443:%i,*:%i' % (https_port, http_port), |
114 timeout) | 114 timeout) |
115 | 115 |
| 116 def UpdateTrafficSettings(self, round_trip_latency_ms=0, |
| 117 download_bandwidth_kbps=0, upload_bandwidth_kbps=0, timeout=5): |
| 118 self._IssueCommand('set rtt %s' % round_trip_latency_ms, timeout) |
| 119 self._IssueCommand('set inkbps %s' % download_bandwidth_kbps, timeout) |
| 120 self._IssueCommand('set outkbps %s' % upload_bandwidth_kbps, timeout) |
| 121 |
116 def StopServer(self): | 122 def StopServer(self): |
117 """Stop TsProxy Server.""" | 123 """Stop TsProxy Server.""" |
118 if not self._is_running: | 124 if not self._is_running: |
119 logging.warning('Attempting to stop TsProxy server that is not running.') | 125 logging.warning('Attempting to stop TsProxy server that is not running.') |
120 return | 126 return |
121 if self._proc: | 127 if self._proc: |
122 self._proc.terminate() | 128 self._proc.terminate() |
123 self._proc.wait() | 129 self._proc.wait() |
124 err = self._proc.stderr.read() | 130 err = self._proc.stderr.read() |
125 self._proc = None | 131 self._proc = None |
126 self._port = None | 132 self._port = None |
127 self._is_running = False | 133 self._is_running = False |
128 return err | 134 return err |
129 | 135 |
130 def __enter__(self): | 136 def __enter__(self): |
131 """Add support for with-statement.""" | 137 """Add support for with-statement.""" |
132 self.StartServer() | 138 self.StartServer() |
133 return self | 139 return self |
134 | 140 |
135 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): | 141 def __exit__(self, unused_exc_type, unused_exc_val, unused_exc_tb): |
136 """Add support for with-statement.""" | 142 """Add support for with-statement.""" |
137 self.StopServer() | 143 self.StopServer() |
OLD | NEW |