parent
845b6f2a42
commit
5d0a26ca7e
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2021 hornet
|
Copyright (c) 2021 hornetfighter515
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|
7
requirements.txt
Normal file
7
requirements.txt
Normal 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
|
|
@ -26,7 +26,6 @@ def on_open(ws):
|
||||||
_thread.start_new_thread(run, ())
|
_thread.start_new_thread(run, ())
|
||||||
|
|
||||||
def open_socket(url, port):
|
def open_socket(url, port):
|
||||||
websocket.enableTrace(True)
|
|
||||||
ws = websocket.WebSocketApp(f"ws://{url}:{port}",
|
ws = websocket.WebSocketApp(f"ws://{url}:{port}",
|
||||||
on_open=on_open,
|
on_open=on_open,
|
||||||
on_message=on_message,
|
on_message=on_message,
|
||||||
|
|
3
src/client/config.yml
Normal file
3
src/client/config.yml
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
ws:
|
||||||
|
url: localhost
|
||||||
|
port: 6873
|
|
@ -8,10 +8,7 @@ https://www.geeksforgeeks.org/how-to-encrypt-and-decrypt-strings-in-python/
|
||||||
|
|
||||||
import rsa
|
import rsa
|
||||||
|
|
||||||
class encrypt_decrypt():
|
class EncryptDecrypt():
|
||||||
|
|
||||||
# the message we want to encrypt
|
|
||||||
message = "Hello World"
|
|
||||||
|
|
||||||
def make_keys(key_length):
|
def make_keys(key_length):
|
||||||
publicKey, privateKey = ""
|
publicKey, privateKey = ""
|
0
src/client/protocol.yml
Normal file
0
src/client/protocol.yml
Normal 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
7
src/hub/config.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
ws:
|
||||||
|
ext:
|
||||||
|
url: localhost
|
||||||
|
port: 6873
|
||||||
|
int:
|
||||||
|
url: localhost
|
||||||
|
port: 6872
|
|
@ -6,17 +6,31 @@ Creates hub for distributed IoT
|
||||||
"""
|
"""
|
||||||
|
|
||||||
from websocket_server import WebsocketServer
|
from websocket_server import WebsocketServer
|
||||||
|
import time
|
||||||
|
|
||||||
def new_client(client, server):
|
class Serv():
|
||||||
print("Client has joined")
|
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):
|
def _log_prefix(self):
|
||||||
print(message)
|
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)
|
if __name__ == "__main__":
|
||||||
ext_server.set_fn_message_received(message_received)
|
import yaml
|
||||||
ext_server.set_fn_new_client(new_client)
|
with open('config.yml', 'r') as f:
|
||||||
ext_server.run_forever()
|
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
7
src/hub/test_config.yml
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
ws:
|
||||||
|
ext:
|
||||||
|
url: localhost
|
||||||
|
port: 6873
|
||||||
|
int:
|
||||||
|
url: localhost
|
||||||
|
port: 6872
|
|
@ -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))
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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()
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user