Code refactoring

This commit is contained in:
mirai 2023-03-08 18:59:38 +03:00
parent 0f066d367f
commit a8f296c0f1
11 changed files with 88 additions and 67 deletions

19
LICENSE Normal file
View File

@ -0,0 +1,19 @@
Copyright (c) 2022-2023
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -13,70 +13,15 @@
All you need it's to run web-server and connect to them via client All you need it's to run web-server and connect to them via client
# Server run # Run
## Linux ### Create and activate virtual environment python
For linux its required to have python3.10
``` ```
chmod +x run_server.sh python main.py
``` ```
``` # How crypting works?
./run_server.sh <port>
```
## Windows
```
python -m venv venv
```
```
venv/scripts/Activate
```
```
pip install -r requirements.txt
```
```
sanic server.server.app -H 0.0.0.0 -p <port>
```
# Client run
## Linux
For linux its required to have python3.10
```
chmod +x run_client.sh
```
```
./run_client.sh
```
## Windows
```
python -m venv venv
```
```
venv/scripts/Activate
```
```
pip install -r requirements.txt
```
```
python client/client.py
```
## How crypting works?
* Client making priv key * Client making priv key
* Server making symmetric key * Server making symmetric key

48
cmd_chat/__init__.py Normal file
View File

@ -0,0 +1,48 @@
import asyncio
from cmd_chat.server.server import app
from cmd_chat.client.client import Client
async def run_server(
ip: str,
port: int
) -> None:
app.run(
host=ip,
port=port,
dev=False
)
async def run_client(
username: str,
server: str,
port: int
) -> None:
Client(
server = server,
port = port,
username = username
).run()
async def run() -> None:
action: int = int(input("Choose action:\n1. Run server\n2. Run client\nAction: "))
if action == 1:
await run_server(
input("IP: "),
int(input("PORT: "))
)
if action == 2:
await run_client(
input("USERNAME: "),
input("IP: "),
int(input("PORT: "))
)
if __name__ == '__main__':
asyncio.run(
run()
)

View File

@ -2,11 +2,12 @@ import os
import time import time
import platform import platform
import threading import threading
from colorama import init from colorama import init
from colorama import Fore
from websocket import create_connection from websocket import create_connection
from core.crypto import RSAService
from config import ( from cmd_chat.client.core.crypto import RSAService
from cmd_chat.client.config import (
COLORS COLORS
) )

View File

@ -2,7 +2,8 @@ import os
import rsa import rsa
import requests import requests
from cryptography.fernet import Fernet from cryptography.fernet import Fernet
from core.abs.abs_crypto import CryptoService
from cmd_chat.client.core.abs.abs_crypto import CryptoService
class RSAService(CryptoService): class RSAService(CryptoService):

View File

@ -6,8 +6,8 @@ from cryptography.fernet import Fernet
from sanic.response import HTTPResponse from sanic.response import HTTPResponse
from sanic import Sanic, Request, response, Websocket from sanic import Sanic, Request, response, Websocket
from server.models import Message from cmd_chat.server.models import Message
from server.services import ( from cmd_chat.server.services import (
_get_bytes_and_serialize, _get_bytes_and_serialize,
_check_ws_for_close_status, _check_ws_for_close_status,
_generate_new_message, _generate_new_message,

View File

@ -1,5 +1,5 @@
from sanic import Sanic, Request, response, Websocket from sanic import Websocket
from server.models import Message from cmd_chat.server.models import Message
async def _get_bytes_and_serialize( async def _get_bytes_and_serialize(

7
main.py Normal file
View File

@ -0,0 +1,7 @@
from cmd_chat import run
import asyncio
if __name__ == '__main__':
asyncio.run(
run()
)