def start_as_peer(args, node_type=None): print_prologue() # apply default configure values port = args.port or conf.PORT_PEER radio_station_target = f"{conf.IP_RADIOSTATION}:{conf.PORT_RADIOSTATION}" amqp_target = args.amqp_target or conf.AMQP_TARGET amqp_key = args.amqp_key or conf.AMQP_KEY if conf.CHANNEL_BUILTIN: if not amqp_key or amqp_key == conf.AMQP_KEY_DEFAULT: amqp_key = f"{util.get_private_ip()}:{port}" command_arguments.add_raw_command(command_arguments.Type.AMQPKey, amqp_key) check_port_available(int(port)) if node_type is None: node_type = conf.NodeType.CommunityNode elif node_type == conf.NodeType.CitizenNode and not args.radio_station_target: util.exit_and_msg(f"citizen node needs subscribing peer target input") if args.radio_station_target: try: parse_result: ParseResult = urlparse(args.radio_station_target) if conf.SUBSCRIBE_USE_HTTPS: if not parse_result.scheme: parse_result = urlparse( f"https://{args.radio_station_target}") else: if not parse_result.scheme: parse_result = urlparse( f"http://{args.radio_station_target}") if not parse_result.port: parse_result = urlparse( f"http://{args.radio_station_target}:{conf.PORT_RADIOSTATION}" ) radio_station_target = parse_result.netloc except Exception as e: util.exit_and_msg( f"'-r' or '--radio_station_target' option requires " f"[IP Address of Radio Station]:[PORT number of Radio Station], " f"or just [IP Address of Radio Station] format. error({e})") # run peer service with parameters logging.info(f"loopchain peer run with: port({port}) " f"radio station target({radio_station_target})") PeerService(radio_station_target=radio_station_target, node_type=node_type).serve(port=port, agent_pin=args.agent_pin, amqp_target=amqp_target, amqp_key=amqp_key) print_eplilogue()
def main(argv): logging.info("Peer main got argv(list): " + str(argv)) try: opts, args = getopt.getopt(argv, "dhr:p:c:", ["help", "radio_station_ip=", "radio_station_port=", "port=", "score=", "cert=" ]) except getopt.GetoptError as e: logging.error(e) usage() sys.exit(1) # default option values port = conf.PORT_PEER radio_station_ip = conf.IP_RADIOSTATION radio_station_port = conf.PORT_RADIOSTATION score = conf.DEFAULT_SCORE_PACKAGE cert = None pw = None # apply option values for opt, arg in opts: if (opt == "-r") or (opt == "--radio_station_ip"): radio_station_ip = arg elif (opt == "-p") or (opt == "--port"): port = arg elif (opt == "-c") or (opt == "--score"): score = arg elif opt == "--cert": cert = arg elif opt == "-d": util.set_log_level_debug() elif (opt == "-h") or (opt == "--help"): usage() return # run peer service with parameters logging.info("\nTry Peer Service run with: \nport(" + str(port) + ") \nRadio Station(" + radio_station_ip + ":" + str(radio_station_port) + ") \nScore(" + score + ") \n") # check Port Using if util.check_port_using(conf.IP_PEER, int(port)): logging.error('Peer Service Port is Using '+str(port)) return ObjectManager().peer_service = PeerService(None, radio_station_ip, radio_station_port, cert, pw) logging.info("loopchain peer_service is: " + str(ObjectManager().peer_service)) ObjectManager().peer_service.serve(port, score)
def run_peer_server(port, rs_port=conf.PORT_RADIOSTATION, group_id=None, score=None, event_for_init=None): ObjectManager().peer_service = PeerService(group_id, conf.IP_RADIOSTATION, rs_port) if score is not None: ObjectManager().peer_service.set_chain_code(score) conf.DEFAULT_SCORE_REPOSITORY_PATH = \ os.path.join(os.path.dirname(__file__), '..', '..', 'resources', 'test_score_repository') try: ObjectManager().peer_service.serve(port, conf.DEFAULT_SCORE_PACKAGE, event_for_init=event_for_init) except FileNotFoundError: logging.debug("Score Load Fail") except TimeoutError as e: logging.exception(e)
def start_as_peer(args): print_prologue() # apply default configure values port = args.port or conf.PORT_PEER amqp_target = args.amqp_target or conf.AMQP_TARGET amqp_key = args.amqp_key or conf.AMQP_KEY if conf.CHANNEL_BUILTIN: if not amqp_key or amqp_key == conf.AMQP_KEY_DEFAULT: amqp_key = f"{utils.get_private_ip()}:{port}" command_arguments.add_raw_command(command_arguments.Type.AMQPKey, amqp_key) check_port_available(int(port)) PeerService().serve(port=port, agent_pin=args.agent_pin, amqp_target=amqp_target, amqp_key=amqp_key) print_epilogue()
def main(argv): # logging.debug("Peer main got argv(list): " + str(argv)) try: opts, args = getopt.getopt(argv, "dhr:p:c:o:a:", [ "help", "radio_station_target=", "port=", "score=", "public=", "private=", "password="******"configure_file_path=" ]) except getopt.GetoptError as e: logging.error(e) usage() sys.exit(1) # apply json configure values for opt, arg in opts: if (opt == "-o") or (opt == "--configure_file_path"): conf.Configure().load_configure_json(arg) # apply default configure values port = conf.PORT_PEER radio_station_ip = conf.IP_RADIOSTATION radio_station_port = conf.PORT_RADIOSTATION radio_station_ip_sub = conf.IP_RADIOSTATION radio_station_port_sub = conf.PORT_RADIOSTATION score = conf.DEFAULT_SCORE_PACKAGE public = conf.PUBLIC_PATH private = conf.PRIVATE_PATH pw = conf.DEFAULT_PW # Parse command line arguments. for opt, arg in opts: if (opt == "-r") or (opt == "--radio_station_target"): try: if ':' in arg: target_list = util.parse_target_list(arg) if len(target_list) == 2: radio_station_ip, radio_station_port = target_list[0] radio_station_ip_sub, radio_station_port_sub = target_list[ 1] else: radio_station_ip, radio_station_port = target_list[0] # util.logger.spam(f"peer " # f"radio_station_ip({radio_station_ip}) " # f"radio_station_port({radio_station_port}) " # f"radio_station_ip_sub({radio_station_ip_sub}) " # f"radio_station_port_sub({radio_station_port_sub})") elif len(arg.split('.')) == 4: radio_station_ip = arg else: raise Exception("Invalid IP format") except Exception as e: util.exit_and_msg( f"'-r' or '--radio_station_target' option requires " f"[IP Address of Radio Station]:[PORT number of Radio Station], " f"or just [IP Address of Radio Station] format. error({e})" ) elif (opt == "-p") or (opt == "--port"): port = arg elif (opt == "-c") or (opt == "--score"): score = arg elif (opt == "-a") or (opt == "--password"): pw = arg elif opt == "--public": public = arg elif opt == "--private": private = arg elif opt == "-d": util.set_log_level_debug() elif (opt == "-h") or (opt == "--help"): usage() return # run peer service with parameters logging.info(f"loopchain peer run with: port({port}) " f"radio station({radio_station_ip}:{radio_station_port}) " f"score({score})") # check Port Using if util.check_port_using(conf.IP_PEER, int(port)): util.exit_and_msg('Peer Service Port is Using ' + str(port)) # str password to bytes if isinstance(pw, str): pw = pw.encode() ObjectManager().peer_service = PeerService( radio_station_ip=radio_station_ip, radio_station_port=radio_station_port, public_path=public, private_path=private, cert_pass=pw) # logging.debug("loopchain peer_service is: " + str(ObjectManager().peer_service)) ObjectManager().peer_service.serve(port, score)
def start_as_peer(args, node_type=None): print_prologue() # apply default configure values port = args.port or conf.PORT_PEER radio_station_ip = conf.IP_RADIOSTATION radio_station_port = conf.PORT_RADIOSTATION radio_station_ip_sub = conf.IP_RADIOSTATION radio_station_port_sub = conf.PORT_RADIOSTATION amqp_target = args.amqp_target or conf.AMQP_TARGET amqp_key = args.amqp_key or conf.AMQP_KEY if conf.CHANNEL_BUILTIN: if not amqp_key or amqp_key == conf.AMQP_KEY_DEFAULT: amqp_key = f"{util.get_private_ip()}:{port}" command_arguments.add_raw_command(command_arguments.Type.AMQPKey, amqp_key) check_port_available(int(port)) if node_type is None: node_type = conf.NodeType.CommunityNode elif node_type == conf.NodeType.CitizenNode and not args.radio_station_target: util.exit_and_msg(f"citizen node needs subscribing peer target input") if args.radio_station_target: try: is_set_https = False if "https://" in args.radio_station_target: is_set_https = True args.radio_station_target = args.radio_station_target.split( "https://")[1] util.logger.spam( f"args.radio_station_target({args.radio_station_target})") elif ':' in args.radio_station_target: target_list = util.parse_target_list(args.radio_station_target) if len(target_list) == 2: radio_station_ip, radio_station_port = target_list[0] radio_station_ip_sub, radio_station_port_sub = target_list[ 1] else: radio_station_ip, radio_station_port = target_list[0] # util.logger.spam(f"peer " # f"radio_station_ip({radio_station_ip}) " # f"radio_station_port({radio_station_port}) " # f"radio_station_ip_sub({radio_station_ip_sub}) " # f"radio_station_port_sub({radio_station_port_sub})") elif len(args.radio_station_target.split('.')) == 4: radio_station_ip = args.radio_station_target elif len(args.radio_station_target.split('.')) >= 2: is_set_https = True else: raise Exception("Invalid IP format") if is_set_https: radio_station_ip = args.radio_station_target radio_station_port = 443 util.logger.spam( f"start_as_peer:radio_station_ip {radio_station_ip}") except Exception as e: util.exit_and_msg( f"'-r' or '--radio_station_target' option requires " f"[IP Address of Radio Station]:[PORT number of Radio Station], " f"or just [IP Address of Radio Station] format. error({e})") # run peer service with parameters logging.info(f"loopchain peer run with: port({port}) " f"radio station({radio_station_ip}:{radio_station_port})") PeerService(radio_station_ip=radio_station_ip, radio_station_port=radio_station_port, node_type=node_type).serve(port=port, agent_pin=args.agent_pin, amqp_target=amqp_target, amqp_key=amqp_key) print_eplilogue()