summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062/dns/server.py
blob: d4e31090ef4c00447e16e62c72c6734b482cf471 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python2

""" A recursive DNS server

This module provides a recursive DNS server. You will have to implement this
server using the algorithm described in section 4.3.2 of RFC 1034.
"""

from threading import Thread


class RequestHandler(Thread):
    """ A handler for requests to the DNS server """

    def __init__(self):
        """ Initialize the handler thread """
        super(RequestHandler, self).__init__()
        self.daemon = True

    def run(self):
        """ Run the handler thread """
        # TODO: Handle DNS request
        pass


class Server(object):
    """ A recursive DNS server """

    def __init__(self, port, caching, ttl):
        """ Initialize the server

        Args:
            port (int): port that server is listening on
            caching (bool): server uses resolver with caching if true
            ttl (int): ttl for records (if > 0) of cache
        """
        self.caching = caching
        self.ttl = ttl
        self.port = port
        self.done = False
        # TODO: create socket

    def serve(self):
        """ Start serving request """
        # TODO: start listening
        while not self.done:
            # TODO: receive request and open handler
            pass

    def shutdown(self):
        """ Shutdown the server """
        self.done = True
        # TODO: shutdown socket