def __init__(self, ports, key=None, debug=False): """Initializes the sender object with a list of sockets containing one socket for each port in the ports list. Args: ports: A list of integer port number values for the sender. key: A base64 format string key to be used for MAC tag generation. Default value = None. debug: A boolean value indicating debug mode. Raises: TypeError: Error when key is not a string value, or when ports is not a list of integers. """ try: if type(ports) != list: raise TypeError("invalid ports: list expected") elif key != None and type(key) != str: raise TypeError("invalid key: str expected") self.host, self.ports = mysocket.gethostname(), ports self.sock = [] self.key = key self.debug = debug for port in ports: self.sock.append(mysocket()) self.sock[-1].bind((self.host, port)) print "Sender socket (%s, %d) initiated" % (self.host, port) except: if debug == True: raise else: secureFail() sys.exit()
def __init__(self, ports, key=None, debug=False): """Initializes the receiver object with a list of sockets containing one socket for each port in the ports list. Args: ports: A list of integer port number values for the receiver. key: A base64 format string key to be used for MAC tag generation. Default value = None. debug: A boolean value indicating debug mode. Raises: TypeError: Error when key is not a string value, or when ports is not a list of integers. """ try: if type(ports) != list: raise TypeError("invalid ports: list expected") elif key != None and type(key) != str: raise TypeError("invalid key: str expected") self.host, self.ports = mysocket.gethostname(), ports self.sock = [] self.key = key self.debug = debug for port in ports: self.sock.append(mysocket()) self.sock[-1].bind((self.host, port)) print "Receiver socket (%s, %d) initiated" % (self.host, port) except: if debug == True: raise else: secureFail() sys.exit()
def __init__(self, port, debug=False): """Initializes the node object with a socket object using the port number specified by the argument port. Args: port: An integer port number for the node. debug: A boolean value indicating debug mode. Raises: TypeError: Error when port is not an integer. """ try: if type(port) not in [int, long]: raise TypeError("invalid port: int or long expected") self.host, self.port = mysocket.gethostname(), port self.sock = mysocket() self.sock.bind((self.host, self.port)) self.share = None self.debug = debug print "Node (%s, %d) initiated" % (self.host, self.port) except: if debug == True: raise else: secureFail() sys.exit()
try: fp = open("sender.txt", "r") dictStr = fp.read() fp.close() senderDict = message.strToList(dictStr) ports = senderDict["ports"] msg = senderDict["msg"] n = senderDict["n"] k = senderDict["k"] prime = senderDict["prime"] key = senderDict["key"] mode = senderDict["mode"] nodePorts = senderDict["nodes"] addr = mysocket.gethostname() nodes = [(addr, portNum) for portNum in nodePorts] s = sender(ports, key, args.debug) shares, genTime = s.sendShares(msg, n, k, prime, nodes, mode) print "Time taken to generate shares:", genTime print "-" * 50 except SystemExit: pass except: if args.debug == True: raise else: secureFail()
try: fp = open("receiver.txt", "r") dictStr = fp.read() fp.close() recvrDict = message.strToList(dictStr) ports = recvrDict['ports'] t = recvrDict['t'] k = recvrDict['k'] prime = recvrDict['prime'] key = recvrDict['key'] mode = recvrDict['mode'] buf = recvrDict['buffer'] nodePorts = recvrDict['nodes'] addr = mysocket.gethostname() nodes = [(addr, portNum) for portNum in nodePorts] r = receiver(ports, key, args.debug) secret, faultyNodes, reconTime = r.reconstructSecret( nodes, buf, k, t, prime, mode) if len(faultyNodes) == 0: faultyNodes = None endTime = time() print "-" * 50 print "Reconstructed message:", secret print "Faulty nodes:", faultyNodes print "-" * 50 print "Time taken to reconstruct secret :", reconTime print "-" * 50