A Chord-inspired distributed hash table implementation in C++ using TCP sockets. Multiple name server nodes form a ring topology, partitioning a key space of 0--1024 and supporting dynamic node entry/exit with automatic data migration.
- Chord-like ring topology: Nodes are organized in a logical ring ordered by ID
- Key range partitioning: Key space [0, 1024] is divided among active nodes
- Insert, lookup, and delete: Operations are routed around the ring to the responsible node
- Dynamic node entry/exit: Nodes can join or leave at runtime with automatic key range rebalancing and data migration
- Ring traversal tracking: Reports which nodes were traversed during operations
- Thread pool concurrency: Background threads handle incoming messages while the main thread processes user commands
- Thread-safe message queue: Producer-consumer queue for inter-thread communication
bnserver(Bootstrap Name Server) -- The initial node that owns the full key range [0, 1024]. Serves as the entry point for new nodes joining the ring. Also handles user commands (insert, lookup, delete) and forwards them around the ring as needed.nameserver-- A regular name server node. Joins the ring via the bootstrap server, receives its key range and migrated data, then participates in routing and storage.
Nodes communicate using #-delimited text messages over TCP sockets. Message types include: entry, exit, insert, lookup, delete, traversal, pass_back, and handshake messages for ring restructuring (successor_entry, predecessor_exit, etc.).
make # builds both nameserver and bnserver
make clean # removes binariesRequires a C++ compiler with C++17 and pthread support.
-
Start the bootstrap server with its config file:
./bnserver config/bsconfig.txt
-
In separate terminals, start name server nodes:
./nameserver config/ns1config.txt ./nameserver config/ns2config.txt
-
On each name server, type
entryto join the ring. -
On the bootstrap server, issue commands:
insert <key> <value>-- Insert a key-value pairlookup <key>-- Look up a value by keydelete <key>-- Delete a key-value pairinfo-- Display this node's range, neighbors, and stored data
-
On a name server, type
exitto leave the ring (data is migrated to successor).
Bootstrap config (config/bsconfig.txt):
<id>
<port>
<key> <value>
<key> <value>
...
Name server config (config/ns1config.txt):
<id>
<port>
<bootstrap_ip> <bootstrap_port>