def network(summary, price, debug): if debug: _debug = True xprint('Node', 'deb', 'Entering the cli network command...') storing = Storing() networking = Networking() net_pub = networking.network_pub() if net_pub: storing.network_pub(net_pub) else: xprint('Node', 'err', 'Error: Cannot reach the RRC network.') xprint('Node', 'warn', 'Warning: Requests to the network will most likely fail.') xprint('Node', 'inf', 'Tip: Please check that you have a reliable internet connexion.') return session = storing.hook("Node") current_node = session.query(Instance).first() storing.release("Node") if current_node is None: xprint('Node', 'err', 'Error: You must configure the node before using this command features.') xprint('Node', 'inf', 'Tip: rrc node --config') return else: if summary: response = networking.network_summary() if response: xprint('Node', 'deb', ' Network summary\n') xprint(json.dumps(response, sort_keys=True, indent=4)) if price: response = networking.network_price() if response: xprint('Node', 'deb', 'RRC Network >> Price\n') xprint(json.dumps(response, sort_keys=True, indent=4))
def contract(queu, show, page, submit, cancel, clean, debug): if debug: _debug = True xprint('Node', 'deb', 'Entering the cli contract command...') storing = Storing() networking = Networking() computing = Computing() networking.link_storage(storing) computing.link_storage(storing) session = storing.hook("Node") current_node = session.query(Instance).first() current_node.status = "stopping" session.commit() if not current_node.localhost: networking.connect() storing.connect() storing.release("Node") if queu: xprint('Node', 'deb', 'Pretty Table of the queu.') computing.queu() elif show: xprint('Node', 'deb', 'Showing a specific contract.') computing.show(show) elif submit: xprint('Node', 'deb', 'Submitting a contract.') computing.submit(submit) elif cancel: xprint('Node', 'deb', 'Requesting node to cancel a contract.') computing.cancel(cancel) elif clean: # Submit only work in localhost. or online when the components are off the network. xprint('Node', 'warn', 'You are about to erase all your workload.') sure = input("Do you really want to proceed: (y)es | (n)o ? ") if sure.lower() == "y": session = storing.hook("Node") current_queu = session.query(Queu).all() current_contracts = session.query(Contract).all() for qu in current_queu: session.delete(qu) for cnt in current_contracts: session.delete(cnt) session.commit() storing.release("Node") elif sure.lower() == "n": xprint('Node', 'warn', 'Well understood. Cheers!') else: xprint('Node', 'warn', 'Warning: Unknown answer. (y)es/(n)o.') else: xprint('Node', 'deb', 'Pretty Table of the contracts.') computing.contracts(page)
def node(config, summary, start, stop, network, debug): if debug: _debug = True xprint('Node', 'deb', 'RRC Node >> Entering the cli node command...') storing = Storing() networking = Networking() computing = Computing() networking.link_storage(storing) computing.link_storage(storing) net_pub = networking.network_pub() session = storing.hook("Node") current_node = session.query(Instance).first() if current_node and not current_node.localhost: networking.connect() storing.connect() storing.release("Node") if net_pub: storing.network_pub(net_pub) else: xprint('Node', 'err', 'Error: Cannot reach the RRC network.') xprint('Node', 'warn', 'Warning: Requests to the network will most likely fail.') xprint( 'Node', 'inf', 'Tip: Please check that you have a reliable internet connexion.') if summary: session = storing.hook("Node") instance = session.query(Instance).first() if instance: xprint('Node', 'inf', '\n{0}'.format(instance)) else: xprint( 'Node', 'err', 'Error: You must configure the node before using this command features.' ) xprint('Node', 'inf', 'Tip: rrc node --config') storing.release("Node") if config: # Check if the owner is sure to reconfigure teh node again before continuing. xprint('Node', 'warn', 'Warning: The following action will reset your current setup.') go_on = input("Are you sure about this: y(es) | n(o) ? ") counter = 0 while go_on.lower() not in ["y", "n"]: counter += 1 xprint( 'Node', 'warn', 'Warning: Unknown answer. (y)es/(n)o. Attempt({0}/5)'.format( counter)) go_on = input("Are you sure about this: y(es) | n(o) ? ") if counter == 5: break if counter == 5: xprint('Node', 'warn', 'Warning: Maximum attempts reached. Cheers!') return else: if go_on.lower() == "n": xprint('Node', 'warn', 'Well understood. Cheers!') return storing.generate_rsa() storing.rsa_private() storing.rsa_public() session = storing.hook("Node") current_node = session.query(Instance).first() if current_node: session.delete(current_node) current_node = Instance(version=version, identifier=storing.signature_node(), session="unknown", localhost=True, status="config", rewards=0.0) session.add(current_node) session.commit() current_owner = session.query(Owner).first() if current_owner: response = networking.node_configure(current_owner.email) if response: xprint('Node', 'inf', 'Network Handshake success!') else: xprint( 'Node', 'err', 'Error: Could not achieve a proper handshake with the RRC network.' ) xprint( 'Node', 'warn', 'Warning: You will not be able to call network commands [\'summary\', \'price\']' ) else: xprint('Node', 'warn', 'Warning: No owner setup for this node.') xprint('Node', 'inf', 'Tip: rrc owner --setup.') xprint( 'Node', 'warn', 'Warning: You will not be able to call network commands [\'summary\', \'price\']' ) xprint( 'Node', 'inf', 'Tip: Setup the node owner if you plan to reach the network.' ) storing.release("Node") else: session = storing.hook("Node") current_node = session.query(Instance).first() if current_node is None: storing.release("Node") xprint( 'Node', 'err', 'Error: You must configure the node before using this command features.' ) xprint('Node', 'inf', 'Tip: rrc node --config.') xprint( 'Node', 'warn', 'Warning: You will not be able to call network commands [\'summary\', \'price\']' ) xprint( 'Node', 'inf', 'Tip: Setup the node owner if you plan to reach the network.') return else: storing.rsa_private() storing.rsa_public() current_owner = session.query(Owner).first() if current_owner: response = networking.node_configure(current_owner.email) if response: xprint('Node', 'inf', 'Network Handshake success!') else: xprint( 'Node', 'err', 'Error: Could not achieve a proper handshake with the RRC network.' ) xprint( 'Node', 'warn', 'Warning: You will not be able to call network commands [\'summary\', \'price\']' ) else: xprint('Node', 'warn', 'Warning: No owner setup for this node.') xprint('Node', 'inf', 'Tip: rrc owner --setup.') xprint( 'Node', 'warn', 'Warning: You will not be able to call network commands [\'summary\', \'price\']' ) xprint( 'Node', 'inf', 'Tip: Setup the node owner if you plan to reach the network.' ) storing.release("Node") if network: session = storing.hook("Node") current_node = session.query(Instance).first() history = session.query(History).all() if current_node: if len(history) > 0 and current_node.localhost: storing.release("Node") xprint( 'Node', 'err', 'Error: Previous localhost configuration found on the system.' ) xprint('Node', 'inf', 'Tip: Reconfigure the node with --network to proceed.') overwride = input( "Unless you want to erase the current configuration: (y)es | (n)o ? " ) if overwride.lower() == "y": current_node.localhost = False for hst in history: session.detele(hst) for qu in session.query(Queu).all(): session.delete(qu) for cnt in session.query(Contract).all(): session.delete(cnt) for lg in session.query(Log).all(): session.delete(lg) session.commit() elif overwride.lower() == "n": storing.release("Node") xprint('Node', 'warn', 'Well understood. Cheers!') return else: storing.release("Node") xprint('Node', 'warn', 'Warning: Unknown answer. (y)es/(n)o.') return else: current_node.localhost = False session.commit() storing.release("Node") session = storing.hook("Node") current_owner = session.query(Owner).first() if current_owner is None: storing.release("Node") xprint('Node', 'err', 'Error: No owner setup for this node.') xprint('Node', 'inf', 'Tip: Please setup the node owner before attempting (1).') xprint('Node', 'inf', 'Tip: to configure the it over the RRC network (2).') xprint('Node', 'inf', 'Tip: rrc owner --setup.') xprint( 'Node', 'warn', 'Warning: You will not be able to call network commands [\'summary\', \'price\']' ) xprint( 'Node', 'inf', 'Tip: Setup the node owner if you plan to reach the network.') return else: storing.release("Node") networking.connect() storing.connect() else: session = storing.hook("Node") current_node = session.query(Instance).first() history = session.query(History).all() if len(history) > 0 and not current_node.localhost: storing.release("Node") xprint( 'Node', 'err', 'Error: Previous non localhost configuration found on the system.' ) xprint('Node', 'inf', 'Tip: Reconfigure the node without --network to proceed.') overwride = input( "Unless you want to erase the current configuration: (y)es | (n)o ? " ) if overwride.lower() == "y": current_node.localhost = True for hst in history: session.detele(hst) for qu in session.query(Queu).all(): session.delete(qu) for cnt in session.query(Contract).all(): session.delete(cnt) for lg in session.query(Log).all(): session.delete(lg) session.commit() storing.release("Node") else: storing.release("Node") xprint('Node', 'warn', 'Well understood. Cheers!') return else: if not current_node.localhost: networking.connect() storing.connect() xprint('Node', 'deb', 'Network Connected!') storing.release("Node") if start: if networking.connected(): session = storing.hook("Node") instance_owner = session.query(Owner).first() owner = None if instance_owner is None: xprint('Node', 'err', 'Error: No owner setup found for this node.') xprint( 'Node', 'inf', 'Tip: Please setup the node owner before attempting (1).') xprint('Node', 'inf', 'Tip: to configure the it over the RRC network (2).') xprint( 'Node', 'warn', 'Warning: You will not be able to call network commands [\'summary\', \'price\']' ) xprint( 'Node', 'inf', 'Tip: Setup the node owner if you plan to reach the network.' ) storing.release("Node") return else: owner = instance_owner.email storing.release("Node") xprint( 'Node', 'warn', 'Warning: Node Owner [{0}] credentials required here.'.format( instance_owner.email)) password1 = getpass.getpass('password on CoRR: ') password2 = getpass.getpass('again on CoRR: ') counter = 0 while password1 != password2: counter += 1 xprint( 'Node', 'err', 'Error: Password Mismatch! Attempt({0})'.format(counter)) password1 = getpass.getpass('password on CoRR: ') password2 = getpass.getpass('again on CoRR: ') if counter == 5: break if counter == 5: xprint('Node', 'warn', 'Warning: Maximum attempts reached. Cheers!') return else: # network. response = networking.node_network(instance_owner.email, password1) response = {} response["node"] = {} response["node"][ "session"] = "f268471e598bf5acd768871b169d274b025bf8b62eb388585d27ac00911f036b" response["owner"] = {} response["owner"]["fname"] = "Faical Yannick" response["owner"]["lname"] = "Congo" response["owner"]["rewards"] = 1000 if response == None: xprint('Node', 'err', 'Error: could not sign in the RRC network.') else: session = storing.hook("Node") instance_owner = session.query(Owner).first() instance_owner.fname = response['owner']['fname'] instance_owner.lname = response['owner']['lname'] instance_owner.rewards = response['owner']['rewards'] current_node = session.query(Instance).first() current_node.session = response['node']['session'] session.commit() current_node = session.query(Instance).first() # if current_node.component_networking: # storing.release("Node") # xprint('Node', 'warn', 'Warning: Running networking component found!') # xprint('Node', 'inf', 'Info: Only one networking component allowed to run at a time.') # else: current_node.status = "running" session.commit() storing.release("Node") # Launch the network daemon. xprint('Node', 'inf', 'Networking component starting up...') pid1 = networking.start() # Save pid into current_node component networking. xprint('Node', 'warn', pid1) # Launch the computing daemon. xprint('Node', 'inf', 'Computing component starting up...') pid2 = computing.start() # Save pid into current_node component computing. xprint('Node', 'warn', pid2) else: # Localhost. # Launch the computing Thread. # Configure computing. session = storing.hook("Node") current_node = session.query(Instance).first() # if current_node.component_computing: # storing.release("Node") # xprint('Node', 'warn', 'Warning: Running computing component found!') # xprint('Node', 'inf', 'Info: Only one computing component allowed to run at a time.') # else: current_node.status = "running" session.commit() storing.release("Node") # Launch the computing daemon. xprint('Node', 'inf', 'Computing component starting up...') pid = computing.start() if stop: xprint('Node', 'warn', 'You are about to stop this RRC node.') sure = input("Do you really want to proceed: (y)es | (n)o ? ") if sure.lower() == "y": session = storing.hook("Node") current_node = session.query(Instance).first() status = current_node.status session.commit() storing.release("Node") if status != "stopped": session = storing.hook("Node") current_node = session.query(Instance).first() current_node.status = "stopping" session.commit() if not current_node.localhost: networking.connect() storing.connect() storing.release("Node") session = storing.hook("Node") current_node = session.query(Instance).first() current_node.status = "stopped" session.commit() storing.release("Node") xprint('Node', 'inf', 'This RRC Node stopped') elif sure.lower() == "n": xprint('Node', 'warn', 'Well understood. Cheers!') else: xprint('Node', 'warn', 'Warning: Unknown answer. (y)es/(n)o.')
def block(debug, clean): # show the lask block in the blockchain for now. if debug: _debug = True storing = Storing() networking = Networking() computing = Computing() networking.link_storage(storing) computing.link_storage(storing) net_pub = networking.network_pub() session = storing.hook("Node") current_node = session.query(Instance).first() if current_node and not current_node.localhost: networking.connect() storing.connect() storing.release("Node") # To hide for production. # Never allow this even in localhost dev test. if clean: sure = input("Do you really want to proceed: (y)es | (n)o ? ") if sure.lower() == "y": session = storing.hook("Node") blks = session.query(Block).all() for blk in blks: session.delete(blk) session.commit() storing.release("Node") xprint("Node", "warn", "All Blocks removed.") elif sure.lower() == "n": xprint('Node', 'warn', 'Well understood. Cheers!') else: xprint('Node', 'warn', 'Warning: Unknown answer. (y)es/(n)o.') else: storing = Storing() networking = Networking() computing = Computing() networking.link_storage(storing) computing.link_storage(storing) net_pub = networking.network_pub() session = storing.hook("Node") current_node = session.query(Instance).first() if current_node and not current_node.localhost: networking.connect() storing.connect() storing.release("Node") if networking.connected(): xprint( "Node", "warn", "Warning: We do not support showing the last block from the network for now." ) else: session = storing.hook("Node") last_blk = session.query(Block).filter(Block.last == True).first() if last_blk: xprint("Node", "inf", "Last Block: \n{0}".format(last_blk)) else: xprint("Node", "inf", "The blockchain is currently empty.") storing.release("Node")