Esempio n. 1
0
    def createNewNetwork(self, localip, localport, username):
        logging.info("Creating a new network")
        localip = str(localip.get())
        localport = str(localport.get())
        username = str(username.get())
        localport = str(localport)
        """Initialize DHT"""
        initialization = DHT()

        self.encryption.generate_keys()

        # Create a user object, set all user variables to the data gathered in the form
        user = User()
        user.ip = localip
        user.port = localport
        user.username = username
        user.publicKey = self.encryption.getPublicKey().decode("utf-8")
        user.nodeid = self.Utils.generateID(user.username)

        # Convert our user to json format so we can save it to file
        userAsJSON = json.dumps(user.toDict())
        # Register username in a local file so we know who we are
        file = open("User.json", "w+")
        file.write(str(userAsJSON))
        file.close()

        initialization = DHT()
        initialization.fingerTable.nodeid = user.toDict()
        initialization.writeDHTInformation()
Esempio n. 2
0
    def connectToExistingNetwork(self, bootstrapIP, bootstrapPort, localIP,
                                 localPort, username):
        global listbox
        bootstrapIP = str(bootstrapIP.get())
        bootstrapPort = str(bootstrapPort.get())
        localIP = str(localIP.get())
        localPort = str(localPort.get())
        username = str(username.get())
        """
        General data sanitation from the UI into things that our twisted application can understand
        Encoding as bytes for transfer
        """
        bootstrapPort = int(bootstrapPort)
        """Create our encryption keys"""
        self.encryption.generate_keys()
        logger.info("public key")
        logger.info(self.encryption.public_key)
        logger.info("Encryption public key")
        logger.info(self.encryption.getPublicKey())
        logger.info("Encryption private key")
        logger.info(self.encryption.getPrivateKey())
        """Initialize DHT"""
        initialization = DHT()

        user = User()
        user.ip = localIP
        user.port = localPort
        user.username = username
        user.publicKey = self.encryption.getPublicKey().decode("utf-8")
        user.nodeid = self.Utils.generateID(user.username)
        initialization.fingerTable.nodeid = user.toDict()
        initialization.writeDHTInformation()

        user.publicKey = self.encryption.getPublicKey().decode("utf-8")
        """Register username in a local file so we know who we are"""
        file = open("User.json", "w+")
        userstr = json.dumps(user.toDict())
        file.write(str(userstr))
        logger.info("Models Dict" + userstr)

        logging.info("BOOTSTRAP TIME START")

        reactor.connectTCP(bootstrapIP, bootstrapPort,
                           DHTRegistration(userstr))