---
# System prepended metadata

title: DHT Layer Implementation

---

# DHT Layer Implementation
## CHORD Part 1 
### 環境的docker file
```
# Docker file for chord-part-1
# the file should be under /CHORD-PART-1
# BUILD: docker build -t chord .
# RUN: docker run -it chord bash
# ------
# TEST: ./chord 127.0.0.1 5057 & ./chord 127.0.0.1 5058 &
#  python3 test_script.py

FROM python:3.11

RUN apt-get update
RUN apt-get install -y cmake
RUN git clone https://github.com/rpclib/rpclib.git
ADD chord /chord/   
WORKDIR /rpclib
RUN mkdir build
WORKDIR /rpclib/build
RUN cmake ..
RUN cmake --build .
RUN make install
WORKDIR /chord
RUN pip install msgpack-rpc-python
RUN make
CMD ["bash"]
```

## 小問題(歡迎大家回答qq)
* only for mac ==


| hash     | port | 
| -------- | -------- | 
| 333544 | 4293 |
| 269021740 | 5874 |
| 537473465 | 9135 |
| 806280514 | 7880 |
| 1075856109 | 9932 |
| 1344651111 | 9764 |
| 1613211590 | 3002 |
| 1882420401 | 6223 |
| 2150884890 | 3518 |
| 2420490939 | 8426 |
| 2689676953 | 8163 |
| 2958582553 | 3181 |
| 3229990463 | 2297 |
| 3498543655 | 3313 |
| 3767749111 | 4214 |
| 4036395821 | 9726 |


## 測資發想區
### find_successor
(可以的話也可以同時檢查prev)
1. 不**join**, 單獨測個別的**find_successor**, 應該等於自己的id
2. 全**join**, 且固定的**find_successor**應該全部指向同一個node(需注意時間間隔)
3. 全**join**, 檢查每個node的**find_successor**是不是下一個(需注意時間間隔)
4. 全**join**, 在exit一些node後檢查每個人的**find_successor**(需注意時間間隔)

### 測資bash
```
#!/bin/bash

# Run several chord commands
for port in 5057 5058 9543 8982 5838 4323 5814 8359 8826 9909 3708 8226 8739 6551 6141 3766 5902 9359
do
    ./chord 127.0.0.1 $port &
done
# Wait for a few seconds to let the nodes stabilize
sleep 1

# Run the Python script
python3 test_script_0.py
python3 test_script_1.py
python3 test_script_2.py
```
