Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 1 | # Copyright (c) 2010 The Chromium OS 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. |
| 4 | |
| 5 | import logging, threading, time, utils |
| 6 | |
| 7 | class LocalDns(object): |
| 8 | """a wrapper around miniFakeDns that handles managing running the server |
| 9 | in a separate thread. |
| 10 | """ |
| 11 | |
Chris Masone | 7d04f57 | 2010-05-30 18:07:11 -0700 | [diff] [blame] | 12 | def __init__(self, fake_ip="127.0.0.1", local_port=53): |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 13 | import miniFakeDns # So we don't need to install it in the chroot. |
Chris Masone | 7d04f57 | 2010-05-30 18:07:11 -0700 | [diff] [blame] | 14 | self._dns = miniFakeDns.DNSServer(fake_ip="127.0.0.1", port=local_port) |
Chris Masone | f7ae525 | 2010-04-21 08:21:25 -0700 | [diff] [blame] | 15 | self._stopper = threading.Event() |
| 16 | self._thread = threading.Thread(target=self._dns.run, |
| 17 | args=(self._stopper,)) |
| 18 | |
| 19 | |
| 20 | def run(self): |
| 21 | self._thread.start() |
| 22 | |
| 23 | |
| 24 | def stop(self): |
| 25 | self._stopper.set() |
| 26 | self._thread.join() |