summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062/DOCUMENTATION.md
blob: 1c10a6ab70fbd2268784f6c47730282bb729f1ef (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
54
55
56
57
58
59
60
61
62
63
64
# Python DNS server

## General

We craft DNS messages using the methods provided by the framework in
`dns.message`.

Concurrency is done using the `threading` module. For every incoming request a
new `RequestHandler` is fired up, which will respond to the request. Responses
can be matched to the query by verifying the identifier.

Transaction IDs are generated using `random`'s `randint` function.

## Cache

### Storage
We store the cache in JSON format to a file on the disk, using the `json`
module. In addition to the standard fields we also save a `timestamp`, from
which we can deduce when the cache record should be invalidated.

### Invalidation
Entries are removed from the cache if the following holds:

	min(cache TTL, record TTL) + record timestamp < current timestamp

Therefore, records will be removed if it is invalid according to either its own
TTL, or the global TTL of the cache.

This is checked for all records in the cache in the `remove_old` method, which
is called before looking up records or saving the data to the disk.

## Resolver

We follow the algorithm in RFC 1034; 5.3.3. This is implemented by keeping a
list of hints that we may ask, and asking them for the information we need. We
analyse the response, and do one of the following:

 * Return the answer, if the response contains it
 * Add new hints, if the response contains delegations to other name servers
 * Restart with a new query, if the response contains relevant CNAME entries

We start with a list of root servers as hints. We query our hints with
recursion disabled.

## Server

We follow the algorithm in RFC 1034; 4.3.2. We first check our own zone and
otherwise use the DNS resolver.

Relevant flags are passed on the resolver.

## Used modules

 * `argparse`, for parsing command line arguments
 * `copy`, for general purpose
 * `json`, for saving the cache on the disk in JSON format
 * `random`, for identifier generation
 * `re`, for general purpose
 * `socket`, for UDP sockets
 * `struct`, for general purpose
 * `sys`, for general purpose
 * `threading`, for concurrency in the server
 * `time`, for TTL-related functionality
 * `unittest`, for the tests