Moved a bunch of files (#3)

Removed dumb stuff. Added nicer logging.
This commit is contained in:
hornet 2021-11-16 01:02:14 +00:00 committed by GitHub
parent 845b6f2a42
commit 5d0a26ca7e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 49 additions and 120 deletions

View File

@ -1,6 +1,6 @@
MIT License
Copyright (c) 2021 hornet
Copyright (c) 2021 hornetfighter515
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

7
requirements.txt Normal file
View File

@ -0,0 +1,7 @@
gevent==21.8.0
greenlet==1.1.2
PyYAML==6.0
websocket-client==1.2.1
websocket-server==0.6.0
zope.event==4.5.0
zope.interface==5.4.0

View File

@ -26,7 +26,6 @@ def on_open(ws):
_thread.start_new_thread(run, ())
def open_socket(url, port):
websocket.enableTrace(True)
ws = websocket.WebSocketApp(f"ws://{url}:{port}",
on_open=on_open,
on_message=on_message,

3
src/client/config.yml Normal file
View File

@ -0,0 +1,3 @@
ws:
url: localhost
port: 6873

View File

@ -8,10 +8,7 @@ https://www.geeksforgeeks.org/how-to-encrypt-and-decrypt-strings-in-python/
import rsa
class encrypt_decrypt():
# the message we want to encrypt
message = "Hello World"
class EncryptDecrypt():
def make_keys(key_length):
publicKey, privateKey = ""

0
src/client/protocol.yml Normal file
View File

View File

@ -1,43 +0,0 @@
import websocket
import _thread
import ssl
import json
def on_message(ws, message):
print(f"<< {message}")
def on_error(ws, error):
print(error)
def on_close(ws, close_status_code, close_msg):
print(f"### closed. reason: {close_msg} ###")
def on_open(ws):
def run(*args):
running = True
uname = input('input username:')
msg = {
"user":uname,
"content":None
}
ws.send(json.dumps(msg))
while running:
outbound = input(">")
if outbound == 'q':
running = False
else:
msg = {
"user":uname,
"content":outbound
}
ws.send(json.dumps(msg))
ws.close()
_thread.start_new_thread(run, ())
if __name__ == "__main__":
ws = websocket.WebSocketApp("wss://hornetfighter.com:9443",
on_open=on_open,
on_message=on_message,
on_error=on_error,
on_close=on_close)
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})

7
src/hub/config.yml Normal file
View File

@ -0,0 +1,7 @@
ws:
ext:
url: localhost
port: 6873
int:
url: localhost
port: 6872

View File

@ -6,17 +6,31 @@ Creates hub for distributed IoT
"""
from websocket_server import WebsocketServer
import time
def new_client(client, server):
print("Client has joined")
class Serv():
def __init__(self, host, port):
self.host = host
self.port = port
self.ws_s = WebsocketServer(host=host, port=port)
self.ws_s.set_fn_message_received(self.message_received)
self.ws_s.set_fn_new_client(self.new_client)
self.ws_s.run_forever()
def message_received(client, server, message):
print(message)
def _log_prefix(self):
return str(time.time()) + ' [' + self.host + ':' + str(self.port) + '] '
int_server = WebsocketServer(host='127.0.0.1', port=6872)
def new_client(self, client, server):
print(self._log_prefix() + 'Client joined.')
def message_received(self, client, server, message):
# figure out how to identify clients...
print(self._log_prefix() + message )
ext_server = WebsocketServer(host='127.0.0.1', port=6873)
ext_server.set_fn_message_received(message_received)
ext_server.set_fn_new_client(new_client)
ext_server.run_forever()
if __name__ == "__main__":
import yaml
with open('config.yml', 'r') as f:
conf = yaml.safe_load(f)
ws_conf = conf['ws']
ext_server = Serv(ws_conf['ext']['url'], ws_conf['ext']['port'])

7
src/hub/test_config.yml Normal file
View File

@ -0,0 +1,7 @@
ws:
ext:
url: localhost
port: 6873
int:
url: localhost
port: 6872

View File

@ -1,25 +0,0 @@
"""
A client to send an encrypted message to another client
@author hornetfighter515, Lachezar Todorov
"""
import encrypt_decrypt
import websock.alice
import websock.bob
import asyncio
def main():
message = "Hello World"
key_length = 512
#Bob's keys
publicKey, privateKey = encrypt_decrypt.encrypt_decrypt.make_keys(key_length)
asyncio.run(websock.alice.Alice.messageEncrypt("ws://localhost:8765", publicKey, message))
asyncio.run(websock.bob.Bob.messageDecrypt(privateKey))

View File

@ -1,37 +0,0 @@
"""
A file that makes a bunch of sockets
@author Lachezar Todorov
"""
class WebSockestServerExternal():
def __init__(self):
self.wsl = [10]
self.count = 0
#start session
def login(self, name):
self.wsl[self.count] = name
self.count += 1
self.printing()
#exit session
def logout(self, name):
for name in self.wsl:
if name == name:
index = self.wsl.index(name)
self.wsl[index] = ""
self.printing()
#print out the list
def printing(self):
for name in self.wsl:
print(name)
WebSockestServerExternal()
#alice.login()
#alice.logout()