-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:slavashell/dht-messenger into main
- Loading branch information
Showing
5 changed files
with
109 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
FROM python:3.8-slim | ||
|
||
ENV PYTHONUNBUFFERED=1 | ||
|
||
COPY requirements.txt / | ||
RUN pip install -r requirements.txt | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,34 @@ | ||
# dht-messenger | ||
# dht-messenger | ||
|
||
Простой мессенджер на базе DHT Kademlia. | ||
|
||
Все сообщения распределённо хранятся на нодах участников сети, при этом система переживает выходы участников и перераспределяет нагрузку при добавлении новых. | ||
|
||
# Приницип работы | ||
|
||
Допустим Bob и Alice хотят обмениваться сообщениями: | ||
1. Bob и Alice обмениваются своими публичными ключами pkbob и pkalice | ||
2. Alice хочет отправить первое зашифрованное сообщение - она кладет его на адрес `h(pkalice, pkbob)` | ||
4. Alice добавляет в сообщение адрес её следующего сообщения | ||
5. `1st message = (key=h(pkalice, pkbob), encrypt(message(text1, next_key=h(key, text1), ts=t1)))` | ||
6. Alice отправляет второе сообщение по сгенерированному адресу | ||
7. `2nd message = (key=next_key, encrypt(message(text2, next_key=h(next_key, text2), ts=t2)))` | ||
8. Образуется цепочка сообщений Alice, которую могут читать как Alice, так и Bob | ||
9. Bob аналогично пишет сообщения в цепочку, начиная с адреса `h(pkbob, pkalice)` | ||
10. Для восстановления диалога Alice или Bob считывают обе цепочки, начиная с генезисных ключей, и мержат по timestamp-ам | ||
|
||
|
||
# Развертывание | ||
1. Поднимае dht ноду на сервере до которого смогут достучаться остальные участники сети. | ||
|
||
``` | ||
cd messenger | ||
uvicorn server:app | ||
``` | ||
|
||
2. Подключаемся к ноде консольным клиентом | ||
|
||
``` | ||
cd app | ||
python3 app.py | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import logging | ||
import asyncio | ||
|
||
from node import DHTServer | ||
|
||
handler = logging.StreamHandler() | ||
formatter = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s") | ||
handler.setFormatter(formatter) | ||
log = logging.getLogger("kademlia") | ||
log.addHandler(handler) | ||
log.setLevel(logging.DEBUG) | ||
|
||
server = DHTServer() | ||
|
||
|
||
def create_bootstrap_node(): | ||
loop = asyncio.get_event_loop() | ||
loop.set_debug(True) | ||
|
||
loop.run_until_complete(server.listen(8468)) | ||
server.ping_neighbors() | ||
try: | ||
loop.run_forever() | ||
except KeyboardInterrupt: | ||
pass | ||
finally: | ||
server.stop() | ||
loop.close() | ||
|
||
|
||
def main(): | ||
create_bootstrap_node() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters