(self,
                         fingerprint,
                         pubkey,
                         address,
                         satellite,
                         rx_type,
                         antenna,
                         lnb,
                         attempts=5)
Complete the registration procedure after receiver locking

        Sends the registration request to the Monitoring API and waits for the
        validation code sent over satellite through a Satellite API message.

        Args:
            fingerprint      : User GnuPG fingerprint
            pubkey           : User GnuPG public key
            address          : User address
            satellite        : Satellite covering the user location
            rx_type          : Receiver type (vendor and model)
            antenna          : Antenna type and size
            lnb              : LNB model
            attempts         : Maximum number of registration attempts
Complete the registration procedure after receiver locking
Complete the registration procedure after receiver locking
def _register_thread(self,
                         fingerprint,
                         pubkey,
                         address,
                         satellite,
                         rx_type,
                         antenna,
                         lnb,
                         attempts=5):
        """Complete the registration procedure after receiver locking

        Sends the registration request to the Monitoring API and waits for the
        validation code sent over satellite through a Satellite API message.

        Args:
            fingerprint      : User GnuPG fingerprint
            pubkey           : User GnuPG public key
            address          : User address
            satellite        : Satellite covering the user location
            rx_type          : Receiver type (vendor and model)
            antenna          : Antenna type and size
            lnb              : LNB model
            attempts         : Maximum number of registration attempts

        """
        logger.info(
            "Waiting for Rx lock to initiate the registration with the "
            "monitoring server")
        self.rx_lock_event.wait()

        logger.info("Receiver locked. Ready to initiate the registration with "
                    "the monitoring server.")
        logger.info("Launching the API listener to receive the verification "
                    "code sent over satellite")

        # Run the API listener loop
        #
        # Note the validation code is:
        # - Encrypted to us (the Monitoring API encrypts using our public key)
        # - Sent as a raw (non-encapsulated) API message
        # - Sent over the API channel dedicated for authentication messages
        download_dir = None  # Don't save messages
        interface = config.get_net_if(self.user_info)
        recv_queue = queue.Queue()  # save API donwloads on this queue
        listen_loop = ApiListener(recv_queue=recv_queue)
        listen_thread = threading.Thread(target=listen_loop.run,
                                         daemon=True,
                                         args=(self.gpg, download_dir,
                                               defs.api_dst_addr, interface),
                                         kwargs={
                                             'channel': ApiChannel.AUTH.value,
                                             'plaintext': False,
                                             'save_raw': True,
                                             'no_save': True
                                         })
        listen_thread.start()

        failure = False
        while (attempts > 0):
            rv = requests.post(account_endpoint,
                               json={
                                   'fingerprint': fingerprint,
                                   'publickey': pubkey,
                                   'city': address,
                                   'satellite': satellite,
                                   'receiver_type': rx_type,
                                   'antenna': antenna,
                                   'lnb': lnb
                               })

            if (rv.status_code != requests.codes.ok):
                logger.error("Failed to register receiver with the monitoring "
                             "server")
                logger.error("{} ({})".format(rv.reason, rv.status_code))

                # If the initial registration call fails, declare failure right
                # away and break the loop. The problem likely won't go away if
                # we try again (e.g., a server error or invalid pubkey).
                failure = True
                break

            uuid = rv.json()['uuid']
            verified = rv.json()['verified']

            if (verified):
                logger.info("Receiver already registered and verified")
                self._save_credentials(uuid, fingerprint)
                break

            try:
                validation_key = recv_queue.get(timeout=10)
                recv_queue.task_done()
            except queue.Empty:
                logger.warning("Failed to receive the verification code. "
                               "Trying again...")
                attempts -= 1
                continue

            rv = requests.patch(account_endpoint,
                                json={
                                    'uuid': uuid,
                                    'validation_key': validation_key.decode()
                                })

            if (rv.status_code != requests.codes.ok):
                logger.error("Verification failed")
                logger.error("{} ({})".format(rv.reason, rv.status_code))
                attempts -= 1
                if (attempts > 0):
                    logger.warning("Trying again...")
                    time.sleep(1)
            else:
                logger.info("Functional receiver successfully validated")
                logger.info("Ready to report Rx metrics to the monitoring "
                            "server")
                self._save_credentials(uuid, fingerprint)
                break

        if (attempts == 0):
            logger.error("Maximum number of registration attempts " "reached")
            logger.error("Please check if your receiver is running properly "
                         "and restart the application to try again")
            failure = True

        self.registration_running = False
        self.registration_failure = failure

        # Stop the API listener
        listen_loop.stop()
        listen_thread.join()
def _register_thread ( self , fingerprint , pubkey , address , satellite , rx_type , antenna , lnb , attempts = 5 ) : logger . info ( "Waiting for Rx lock to initiate the registration with the " "monitoring server" ) self . rx_lock_event . wait ( ) logger . info ( "Receiver locked. Ready to initiate the registration with " "the monitoring server." ) logger . info ( "Launching the API listener to receive the verification " "code sent over satellite" ) # Run the API listener loop # # Note the validation code is: # - Encrypted to us (the Monitoring API encrypts using our public key) # - Sent as a raw (non-encapsulated) API message # - Sent over the API channel dedicated for authentication messages download_dir = None # Don't save messages interface = config . get_net_if ( self . user_info ) recv_queue = queue . Queue ( ) # save API donwloads on this queue listen_loop = ApiListener ( recv_queue = recv_queue ) listen_thread = threading . Thread ( target = listen_loop . run , daemon = True , args = ( self . gpg , download_dir , defs . api_dst_addr , interface ) , kwargs = { 'channel' : ApiChannel . AUTH . value , 'plaintext' : False , 'save_raw' : True , 'no_save' : True } ) listen_thread . start ( ) failure = False while ( attempts > 0 ) : rv = requests . post ( account_endpoint , json = { 'fingerprint' : fingerprint , 'publickey' : pubkey , 'city' : address , 'satellite' : satellite , 'receiver_type' : rx_type , 'antenna' : antenna , 'lnb' : lnb } ) if ( rv . status_code != requests . codes . ok ) : logger . error ( "Failed to register receiver with the monitoring " "server" ) logger . error ( "{} ({})" . format ( rv . reason , rv . status_code ) ) # If the initial registration call fails, declare failure right # away and break the loop. The problem likely won't go away if # we try again (e.g., a server error or invalid pubkey). failure = True break uuid = rv . json ( ) [ 'uuid' ] verified = rv . json ( ) [ 'verified' ] if ( verified ) : logger . info ( "Receiver already registered and verified" ) self . _save_credentials ( uuid , fingerprint ) break try : validation_key = recv_queue . get ( timeout = 10 ) recv_queue . task_done ( ) except queue . Empty : logger . warning ( "Failed to receive the verification code. " "Trying again..." ) attempts -= 1 continue rv = requests . patch ( account_endpoint , json = { 'uuid' : uuid , 'validation_key' : validation_key . decode ( ) } ) if ( rv . status_code != requests . codes . ok ) : logger . error ( "Verification failed" ) logger . error ( "{} ({})" . format ( rv . reason , rv . status_code ) ) attempts -= 1 if ( attempts > 0 ) : logger . warning ( "Trying again..." ) time . sleep ( 1 ) else : logger . info ( "Functional receiver successfully validated" ) logger . info ( "Ready to report Rx metrics to the monitoring " "server" ) self . _save_credentials ( uuid , fingerprint ) break if ( attempts == 0 ) : logger . error ( "Maximum number of registration attempts " "reached" ) logger . error ( "Please check if your receiver is running properly " "and restart the application to try again" ) failure = True self . registration_running = False self . registration_failure = failure # Stop the API listener listen_loop . stop ( ) listen_thread . join ( )