added transaction validation, close connection, and beautified inc msgs
This commit is contained in:
parent
3804a7448b
commit
3b2d4f7fbf
@ -10,6 +10,10 @@ import socket
|
||||
import pickle
|
||||
import select
|
||||
|
||||
import os
|
||||
from dotenv import load_dotenv
|
||||
load_dotenv()
|
||||
|
||||
BUFFER_SIZE = 1024
|
||||
|
||||
def newServerSocket(ip_addr, port):
|
||||
@ -54,12 +58,21 @@ def connection(ip, port, db):
|
||||
continue
|
||||
|
||||
if type(item) == Tx:
|
||||
print()
|
||||
print(f"{utilityHelper.blinkMessage('Received transaction from peer')}")
|
||||
print(">>: ")
|
||||
|
||||
if item.is_valid():
|
||||
utilityHelper.addFile("../data/transaction_pool.dat", item)
|
||||
continue
|
||||
|
||||
print(f"{utilityHelper.errorMessage('Received transaction is not valid')}")
|
||||
|
||||
if type(item) == TxBlock:
|
||||
print()
|
||||
print(f"{utilityHelper.blinkMessage('Received block from peer')}")
|
||||
print(">>: ")
|
||||
|
||||
valid, exit = blockHelper.socketBlock(item)
|
||||
|
||||
if not valid:
|
||||
@ -67,8 +80,8 @@ def connection(ip, port, db):
|
||||
continue
|
||||
|
||||
if exit:
|
||||
print(f"{utilityHelper.errorMessage('Closing connection and application')}")
|
||||
exit()
|
||||
print()
|
||||
utilityHelper.closeConnection(os.getenv("PEER_IP"), int(os.getenv("PEER_PORT")))
|
||||
continue
|
||||
continue
|
||||
|
||||
@ -77,12 +90,16 @@ def connection(ip, port, db):
|
||||
match item[0]:
|
||||
|
||||
case "USER CREATE":
|
||||
print()
|
||||
print(f"{utilityHelper.blinkMessage('Received user from peer')}")
|
||||
print(">>: ")
|
||||
db.createUser(item[1], item[2], item[3], item[4])
|
||||
continue
|
||||
|
||||
case "USER DELETE":
|
||||
print()
|
||||
print(f"{utilityHelper.blinkMessage('Peer deleted user')}")
|
||||
print(">>: ")
|
||||
db.deleteUser(item[1])
|
||||
continue
|
||||
|
||||
@ -105,5 +122,5 @@ def connection(ip, port, db):
|
||||
if type(item) == str:
|
||||
match item:
|
||||
case "EXIT":
|
||||
exit()
|
||||
utilityHelper.close()
|
||||
continue
|
Loading…
x
Reference in New Issue
Block a user