Esempio n. 1
0
 def broadcaster():
     # Give Receiver time to setup
     time.sleep(1)
     # Setup Broadcaster
     bcast = Broadcast()
     # Broadcast message
     bcast.broadcast("Broadcasting end")
    def __init__(self, port = 5000, miner = True, unitTests = False):
        """Init the blockchain.
        """
        # Initialize the properties.
        self._master_chain = []
        self._branch_list = []
        self._last_hash = None
        self._pending_transactions = []
        self._difficulty = 4
        self._miner = miner

        #Block confirmation request
        self._blocks_to_confirm = []
        self._block_to_mine = None
        
        self._confirm_block = False #Incoming Block confirmation flag
        self._block_added = False #Incoming block added flag

        #ip = get('https://api.ipify.org').text
        ip = "127.0.0.1"
        self._ip = "{}:{}".format(ip,port)
        

        if unitTests :
            self._add_genesis_block()
       
        self.broadcast = Broadcast(set(), self._ip)

        #Creating mining thread
        if self._miner:
            print("Create mining thread")
            mining_thread = threading.Thread(target = self.mine,daemon=True)
            mining_thread.start()
Esempio n. 3
0
    def __init__(self, host):
        self.blockchain = []
        self.current_id_count = 0
        self.host = host
        self.wallet = Wallet()
        self.current_block = ''
        self.broadcast = Broadcast(host)

        # We need to store all the transactions not in a mined block
        # if we add them directly to the current block we have
        # a problem if while mining we get a transaction
        # We trigger the miner only when we have > BLOCK_CAPACITY pending transactions
        self.pending_transactions = []

        # Transactions that we have not received all the inputs for
        self.orphan_transactions = {}

        # Here we store information for every node, as its id, its address (ip:port)
        # its public key, its balance and it's UTXOs
        self.ring = {}

        # The miner subprocess PID
        # If it is None the subprocess is not running
        self.miner_pid = None

        # The lock prevents multiple request threads to attempt
        # starting the miner
        self.miner_lock = threading.Lock()

        # Block receiver lock
        # We have to stop receiving blocks while running consensus
        # in order not to interfere with the process
        self.block_receiver_lock = threading.Lock()
    def __init__(self, handle):
        """Constructor
        """
        # initialize activity
        activity.Activity.__init__(self, handle)

        # debug msg
        logging.debug("Starting Classroom Broadcast Activity")

        # UI
        self.loadUI()

        # create broadcast component
        self._broadcast = Broadcast(self)
        self._broadcast.loadUI();

        # Show UI
        self.showUI()

        # Show status
        self._broadcast.showStatus()
    def __init__(self, _id, faulty):
        self.id = _id
        self.__read_conf(self)
        self.blockchain = Blockchain(self.genesis_time, self.pure,
                                     self.depth_cancel_block != -1)
        self.current_block = self.blockchain.get_last()
        self.hash = Hash(self)

        self.stop_mining = None
        self.nonce_list = []
        self.transaction_list = []
        if self.pure:
            if self.malicious:
                self.state = MaliciousPureBlockchain(self)
            else:
                self.state = PureBlockchain(self)
        else:
            if self.malicious:
                self.state = MaliciousMining(self)
            else:
                self.state = Mining(self)
        self.broadcast = Broadcast(self)
        self.reinforcement_pom = ReinforcementPOM(self)
        self.faulty = faulty
        self.already_found = 0
        #flag to know that it's start of a new mining that we later use for the condition
        # for obtaining a block to mine on top of //line 94
        self.start = True
        self.res_loggerM = self.setup_logger(
            'results_loggerM' + str(self.id),
            'results_logfileM' + str(self.id) + '.log')
        self.res_loggerH = self.setup_logger(
            'results_loggerH' + str(self.id),
            'results_logfileH' + str(self.id) + '.log')
        self.counter = 0
        self.t = dt.datetime.now()
Esempio n. 6
0
    def do_broadcast(self, _args):
        """
Interact with broadcast receivers on the device
        """
        subconsole = Broadcast(self.session)
        subconsole.cmdloop()
Esempio n. 7
0
 def _setUpTestDb(self):
     Broadcast()