A system of three servers that illustrate simplified DNS service.
Built with Python, Flask, and Docker
1. User Server (US):
- running on port 8080
- accepts
GET
HTTP requests at path
/fibonacci?hostname={FS_HOSTNAME}&fs_port={FS_PORT}&number={N}&as_ip={AS_IP}&as_port={AS_PORT}
- if any parameters are missing, US returns HTTP code
400
, indicating bad request. - if request succeed, US returns HTTP code
200
with fibonacci number of sequence numberN
. - US need to query AS to learn IP address of
FS_HOSTNAME
.
2. Fibonacci Server (FS):
- running on port 9090
- provides Fibonacci number for a given sequence number
N
. - 2.1 Registration to AS
- accepts a
PUT
HTTP request at path/register
where request body contains following JSON object.{ "hostbane": "{FS_HOSTNAME}" "ip": "{FS_IP}" "as_ip": "{AS_IP}" "as_port": "{AS_PORT}" }
- then register it with AS via UDP on port 53533, using following DNS registration request:
TYPE=A NAME=FS_NAME VALUE=FS_IP TTL=10
- if the registration succeed, returns a HTTP response with HTTP code
201
- accepts a
- 2.2 Calculate Fibonacci Number
- accepts
GET
HTTP request at path/fibonacci?number={N}
, and returns Fibonacci number for sequence numberN
- if it succeed, returns HTTP code
200
. - if
N
is not an integer, returns400
indicating bad format.
- accepts
3. Authoritative Server (AS)
- accept UDP connection on port 53533 and register Type A DNS record into database.
- respond to DNS query on port 53533. Check the following sample request and response:
request:response:TYPE=A NAME=FS_NAME
TYPE=A NAME=FS_NAME VALUE=FS_IP TTL=10
-
Preparation:
- FS registers its hostname with AS
- AS creates a DNS record for FS and response a result indicating success or failure.
-
Main function:
- User (browser) visit:
http://{SERVER_IP}:{PORT}/fibonacci?hostname={FS_HOSTNAME}&number={N}&as_ip={AS_IP}
- US parses
FS_HOSTNAME
from query string and then query AS for corresponding IP address - AS returns corresponding IP address of
FS_HOSTNAME
to US - US requests
http://{FS_IP}/fibonacci?number={N}
- FS returns answer for the fibonacci number with
200
code - US returns the result to user (browser).
- User (browser) visit:
These instructions will get you a copy of the project up and running on your local machine.
- python, flask
- docker
- clone the project to your local machine
- built the image of each server:
docker build -t {user}/{server_name}:latest .
- create a Docker network:
docker network create {netwrk_name}
- run each container:
docker run --network {netwrk_name} --name {container_name} -p {port}:{port}/udp -it {user}/{server_name}:latest
- learn the IP address of containers:
docker inspect {netwrk_name}
PUT
a registration request to FS- change variables in
test.py
accordingly and run it