summaryrefslogtreecommitdiff
path: root/project2/proj2_s4498062/DOCUMENTATION.md
diff options
context:
space:
mode:
Diffstat (limited to 'project2/proj2_s4498062/DOCUMENTATION.md')
-rw-r--r--project2/proj2_s4498062/DOCUMENTATION.md64
1 files changed, 64 insertions, 0 deletions
diff --git a/project2/proj2_s4498062/DOCUMENTATION.md b/project2/proj2_s4498062/DOCUMENTATION.md
new file mode 100644
index 0000000..1c10a6a
--- /dev/null
+++ b/project2/proj2_s4498062/DOCUMENTATION.md
@@ -0,0 +1,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