| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2010 Google Inc. All Rights Reserved. | 2 # Copyright 2010 Google Inc. All Rights Reserved. |
| 3 # | 3 # |
| 4 # Licensed under the Apache License, Version 2.0 (the "License"); | 4 # Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 # you may not use this file except in compliance with the License. | 5 # you may not use this file except in compliance with the License. |
| 6 # You may obtain a copy of the License at | 6 # You may obtain a copy of the License at |
| 7 # | 7 # |
| 8 # http://www.apache.org/licenses/LICENSE-2.0 | 8 # http://www.apache.org/licenses/LICENSE-2.0 |
| 9 # | 9 # |
| 10 # Unless required by applicable law or agreed to in writing, software | 10 # Unless required by applicable law or agreed to in writing, software |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 host=host, port=options.port, **options.shaping_http) | 144 host=host, port=options.port, **options.shaping_http) |
| 145 if options.ssl: | 145 if options.ssl: |
| 146 server_manager.Append( | 146 server_manager.Append( |
| 147 httpproxy.HttpsProxyServer, | 147 httpproxy.HttpsProxyServer, |
| 148 archive_fetch, custom_handlers, options.certfile, | 148 archive_fetch, custom_handlers, options.certfile, |
| 149 host=host, port=options.ssl_port, **options.shaping_http) | 149 host=host, port=options.ssl_port, **options.shaping_http) |
| 150 | 150 |
| 151 | 151 |
| 152 def AddTrafficShaper(server_manager, options, host): | 152 def AddTrafficShaper(server_manager, options, host): |
| 153 if options.shaping_dummynet: | 153 if options.shaping_dummynet: |
| 154 ssl_port = options.ssl_shaping_port if options.ssl else None | 154 server_manager.AppendTrafficShaper( |
| 155 kwargs = dict( | 155 trafficshaper.TrafficShaper, host=host, |
| 156 host=host, port=options.shaping_port, ssl_port=ssl_port, | |
| 157 dns_port=options.dns_shaping_port, | |
| 158 use_loopback=not options.server_mode and host == '127.0.0.1', | 156 use_loopback=not options.server_mode and host == '127.0.0.1', |
| 159 **options.shaping_dummynet) | 157 **options.shaping_dummynet) |
| 160 if not options.dns_forwarding: | |
| 161 kwargs['dns_port'] = None | |
| 162 server_manager.Append(trafficshaper.TrafficShaper, **kwargs) | |
| 163 | 158 |
| 164 | 159 |
| 165 class OptionsWrapper(object): | 160 class OptionsWrapper(object): |
| 166 """Add checks, updates, and methods to option values. | 161 """Add checks, updates, and methods to option values. |
| 167 | 162 |
| 168 Example: | 163 Example: |
| 169 options, args = option_parser.parse_args() | 164 options, args = option_parser.parse_args() |
| 170 options = OptionsWrapper(options, option_parser) # run checks and updates | 165 options = OptionsWrapper(options, option_parser) # run checks and updates |
| 171 if options.record and options.HasTrafficShaping(): | 166 if options.record and options.HasTrafficShaping(): |
| 172 [...] | 167 [...] |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 return kwargs | 238 return kwargs |
| 244 | 239 |
| 245 def _MassageValues(self): | 240 def _MassageValues(self): |
| 246 """Set options that depend on the values of other options.""" | 241 """Set options that depend on the values of other options.""" |
| 247 if self.append and not self.record: | 242 if self.append and not self.record: |
| 248 self._options.record = True | 243 self._options.record = True |
| 249 if self.net: | 244 if self.net: |
| 250 self._options.down, self._options.up, self._options.delay_ms = \ | 245 self._options.down, self._options.up, self._options.delay_ms = \ |
| 251 net_configs.GetNetConfig(self.net) | 246 net_configs.GetNetConfig(self.net) |
| 252 self._nondefaults.update(['down', 'up', 'delay_ms']) | 247 self._nondefaults.update(['down', 'up', 'delay_ms']) |
| 253 if not self.shaping_port: | |
| 254 self._options.shaping_port = self.port | |
| 255 if not self.ssl_shaping_port: | |
| 256 self._options.ssl_shaping_port = self.ssl_port | |
| 257 if not self.dns_shaping_port: | |
| 258 self._options.dns_shaping_port = self.dns_port | |
| 259 if not self.ssl: | 248 if not self.ssl: |
| 260 self._options.certfile = None | 249 self._options.certfile = None |
| 261 self.shaping_dns = self._ShapingKeywordArgs('dns') | 250 self.shaping_dns = self._ShapingKeywordArgs('dns') |
| 262 self.shaping_http = self._ShapingKeywordArgs('http') | 251 self.shaping_http = self._ShapingKeywordArgs('http') |
| 263 self.shaping_dummynet = self._ShapingKeywordArgs('dummynet') | 252 self.shaping_dummynet = self._ShapingKeywordArgs('dummynet') |
| 264 | 253 |
| 265 def __getattr__(self, name): | 254 def __getattr__(self, name): |
| 266 """Make the original option values available.""" | 255 """Make the original option values available.""" |
| 267 return getattr(self._options, name) | 256 return getattr(self._options, name) |
| 268 | 257 |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 type='int', | 496 type='int', |
| 508 help='Port number to listen on.') | 497 help='Port number to listen on.') |
| 509 harness_group.add_option('--ssl_port', default=443, | 498 harness_group.add_option('--ssl_port', default=443, |
| 510 action='store', | 499 action='store', |
| 511 type='int', | 500 type='int', |
| 512 help='SSL port number to listen on.') | 501 help='SSL port number to listen on.') |
| 513 harness_group.add_option('--dns_port', default=53, | 502 harness_group.add_option('--dns_port', default=53, |
| 514 action='store', | 503 action='store', |
| 515 type='int', | 504 type='int', |
| 516 help='DNS port number to listen on.') | 505 help='DNS port number to listen on.') |
| 517 harness_group.add_option('--shaping_port', default=None, | |
| 518 action='store', | |
| 519 type='int', | |
| 520 help='Port on which to apply traffic shaping. Defaults to the ' | |
| 521 'listen port (--port)') | |
| 522 harness_group.add_option('--ssl_shaping_port', default=None, | |
| 523 action='store', | |
| 524 type='int', | |
| 525 help='SSL port on which to apply traffic shaping. Defaults to the ' | |
| 526 'SSL listen port (--ssl_port)') | |
| 527 harness_group.add_option('--dns_shaping_port', default=None, | |
| 528 action='store', | |
| 529 type='int', | |
| 530 help='DNS port on which to apply traffic shaping. Defaults to the ' | |
| 531 'DNS listen port (--dns_port)') | |
| 532 harness_group.add_option('-c', '--certfile', default=None, | 506 harness_group.add_option('-c', '--certfile', default=None, |
| 533 action='store', | 507 action='store', |
| 534 type='string', | 508 type='string', |
| 535 help='Certificate file to use with SSL (gets auto-generated if needed).') | 509 help='Certificate file to use with SSL (gets auto-generated if needed).') |
| 536 harness_group.add_option('--no-ssl', default=True, | 510 harness_group.add_option('--no-ssl', default=True, |
| 537 action='store_false', | 511 action='store_false', |
| 538 dest='ssl', | 512 dest='ssl', |
| 539 help='Do not setup an SSL proxy.') | 513 help='Do not setup an SSL proxy.') |
| 540 option_parser.add_option_group(harness_group) | 514 option_parser.add_option_group(harness_group) |
| 541 harness_group.add_option('--no-admin-check', default=True, | 515 harness_group.add_option('--no-admin-check', default=True, |
| (...skipping 17 matching lines...) Expand all Loading... |
| 559 elif len(args) != 1: | 533 elif len(args) != 1: |
| 560 option_parser.error('Must specify a replay_file') | 534 option_parser.error('Must specify a replay_file') |
| 561 else: | 535 else: |
| 562 replay_filename = args[0] | 536 replay_filename = args[0] |
| 563 | 537 |
| 564 return replay(options, replay_filename) | 538 return replay(options, replay_filename) |
| 565 | 539 |
| 566 | 540 |
| 567 if __name__ == '__main__': | 541 if __name__ == '__main__': |
| 568 sys.exit(main()) | 542 sys.exit(main()) |
| OLD | NEW |