-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed the whole structure, src contains all the interfaces and core that contains modules that shouldn't be executed, removed every config.json read, every parameter is either and argument or a constant if the user shouldn't modify it, added a lot of options, when running a single channel, added a subparser for Server.py when running the channel locally, updated README.md in src, fixed an issue in channel related to noise and eve, removed some ugly path insertions please note: some changes are made automatically while refactoring FTP is not compatible with the new structure, no plans to adapt it for now,
- Loading branch information
Showing
24 changed files
with
377 additions
and
408 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
This file was deleted.
Oops, something went wrong.
Empty file.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Empty file.
File renamed without changes.
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,34 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Wed May 12 21:31:42 2021 | ||
@author: Alberto Di Meglio | ||
""" | ||
|
||
import os | ||
import argparse | ||
import core | ||
|
||
|
||
def run_channel(host: str = '', port: str = '5000', noise: float = 0.0, eve: bool = False): | ||
# clean up | ||
_ = os.system('clear') | ||
|
||
# instantiate a receiver channel | ||
theChannel = core.channel.public_channel(host, port, noise, eve) | ||
|
||
# initiate the channel and listen for connections | ||
theChannel.initiate_channel() | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = argparse.ArgumentParser(description='Channel for Quantumacy') | ||
parser.add_argument('--host', default='', type=str, | ||
help='Bind socket to this host (default: %(default)s)') | ||
parser.add_argument('--port', default='5000', type=str, | ||
help='Bind socket to this port (default: %(default)s)') | ||
parser.add_argument('-n', '--noise', default=0.0, type=float, | ||
help='Set a noise value for channel, type a float number in [0,1] (default: %(default)s)') | ||
parser.add_argument('-e', '--eve', action='store_true', help='Add an eavesdropper to the channel') | ||
args = parser.parse_args() | ||
run_channel(args.host, args.port, args.noise, args.eve) |
104 changes: 50 additions & 54 deletions
104
QKDSimkit/Server_Client_wrapper/Client.py → QKDSimkit/src/Client.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 |
---|---|---|
@@ -1,54 +1,50 @@ | ||
import http.client | ||
import urllib.parse | ||
import sys | ||
import argparse | ||
import os | ||
|
||
this_file_dir = os.path.dirname(os.path.realpath(__file__)) | ||
sys.path.insert(0, this_file_dir + "/../..") | ||
|
||
from QKDSimkit.QKDSimClients.utils import hash_token, decrypt | ||
from QKDSimkit.QKDSimClients.QKD_Bob import import_key | ||
|
||
|
||
def get_key(alice_address, channel_address, token, number, size): | ||
hashed = hash_token(token) | ||
params = urllib.parse.urlencode({'hashed': hashed}) | ||
conn = http.client.HTTPConnection(f"{alice_address}") | ||
conn.request("GET", f"/hello?{params}") | ||
r = conn.getresponse() | ||
if r.status != 200: | ||
return r.status | ||
data = r.read().decode() | ||
proof = decrypt(token, data) | ||
conn.close() | ||
hash_proof = hash_token(proof) | ||
params = urllib.parse.urlencode({'number': number, 'size': size, 'hashed': hashed, 'hash_proof': hash_proof}) | ||
conn.close() | ||
conn1 = http.client.HTTPConnection(f"{alice_address}") | ||
conn1.request("GET", f"/proof?{params}") | ||
r = conn1.getresponse() | ||
if r.status == 200: | ||
key_list = [] | ||
for n in range(number): | ||
key_list.append(import_key(channel_address=channel_address, ID=hashed, size=size).decode()) | ||
return key_list | ||
else: | ||
return r.status | ||
|
||
|
||
def manage_args(): | ||
parser = argparse.ArgumentParser(description='Client for Quantumacy') | ||
parser.add_argument('alice_address', type=str, help='Address of server/Alice [host:port]') | ||
parser.add_argument('channel_address', type=str, help='Address of channel [host:port]') | ||
parser.add_argument('-t', '--token', default='7KHuKtJ1ZsV21DknPbcsOZIXfmH1_MnKdOIGymsQ5aA=', type=str, | ||
help='Auth token, for development purposes a default token is provided') | ||
parser.add_argument('-n', '--number', default=1, type=int, help="Number of keys (default: %(default)s)") | ||
parser.add_argument('-s', '--size', default=256, type=int, help="Size of keys (default: %(default)s)") | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == '__main__': | ||
args = manage_args() | ||
l = get_key(args.alice_address, args.channel_address, args.token, args.number, args.size) | ||
print(l) | ||
import http.client | ||
import urllib.parse | ||
import argparse | ||
import core | ||
|
||
|
||
def get_key(alice_address, channel_address, token, number, size): | ||
hashed = core.utils.hash_token(token) | ||
params = urllib.parse.urlencode({'hashed': hashed}) | ||
conn = http.client.HTTPConnection(f"{alice_address}") | ||
conn.request("GET", f"/hello?{params}") | ||
r = conn.getresponse() | ||
if r.status != 200: | ||
return r.status | ||
data = r.read().decode() | ||
proof = core.utils.decrypt(token, data) | ||
conn.close() | ||
hash_proof = core.utils.hash_token(proof) | ||
params = urllib.parse.urlencode({'number': number, 'size': size, 'hashed': hashed, 'hash_proof': hash_proof}) | ||
conn.close() | ||
conn1 = http.client.HTTPConnection(f"{alice_address}") | ||
conn1.request("GET", f"/proof?{params}") | ||
r = conn1.getresponse() | ||
if r.status == 200: | ||
key_list = [] | ||
for n in range(number): | ||
res = core.bob.import_key(channel_address=channel_address, ID=hashed, size=size) | ||
if res == -1: | ||
print("Can't exchange a safe key") | ||
if isinstance(res, bytearray): | ||
key_list.append(res.decode()) | ||
return key_list | ||
else: | ||
return r.status | ||
|
||
|
||
def manage_args(): | ||
parser = argparse.ArgumentParser(description='Client for Quantumacy') | ||
parser.add_argument('alice_address', type=str, help='Address of server/Alice [host:port]') | ||
parser.add_argument('channel_address', type=str, help='Address of channel [host:port]') | ||
parser.add_argument('-t', '--token', default='7KHuKtJ1ZsV21DknPbcsOZIXfmH1_MnKdOIGymsQ5aA=', type=str, | ||
help='Auth token, for development purposes a default token is provided') | ||
parser.add_argument('-n', '--number', default=1, type=int, help="Number of keys (default: %(default)s)") | ||
parser.add_argument('-s', '--size', default=256, type=int, help="Size of keys (default: %(default)s)") | ||
return parser.parse_args() | ||
|
||
|
||
if __name__ == '__main__': | ||
args = manage_args() | ||
l = get_key(args.alice_address, args.channel_address, args.token, args.number, args.size) |
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
Oops, something went wrong.