def main(argv): logging.info("RadioStation main got argv(list): " + str(argv)) try: opts, args = getopt.getopt(argv, "dhp:", ["help", "port=", "cert="]) except getopt.GetoptError as e: logging.error(e) usage() sys.exit(1) port = conf.PORT_RADIOSTATION cert = None pw = None # apply option values for opt, arg in opts: if opt == "-d": util.set_log_level_debug() elif (opt == "-p") or (opt == "--port"): port = arg elif opt == "--cert": cert = arg elif (opt == "-h") or (opt == "--help"): usage() return # Check Port is Using if util.check_port_using(conf.IP_RADIOSTATION, int(port)): logging.error('RadioStation Service Port is Using ' + str(port)) return RadioStationService(conf.IP_RADIOSTATION, cert, pw).serve(port)
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 main(argv): logging.info("RadioStation main got argv(list): " + str(argv)) try: opts, args = getopt.getopt( argv, "dhp:o:s:", ["help", "port=", "cert=", "configure_file_path=", "seed="]) 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_RADIOSTATION cert = None pw = None seed = None # apply option values for opt, arg in opts: if opt == "-d": util.set_log_level_debug() elif (opt == "-p") or (opt == "--port"): port = arg elif opt == "--cert": cert = arg elif (opt == "-s") or (opt == "--seed"): try: seed = int(arg) except ValueError as e: util.exit_and_msg(f"seed or s opt must be int \n" f"intput value : {arg}") elif (opt == "-h") or (opt == "--help"): usage() return # Check Port is Using if util.check_port_using(conf.IP_RADIOSTATION, int(port)): logging.error('RadioStation Service Port is Using ' + str(port)) return RadioStationService(conf.IP_RADIOSTATION, cert, pw, seed).serve(port)
def load_score_container_each(self, channel_name: str, score_package: str, container_port: int, peer_target: str): """create score container and save score_info and score_stub :param channel_name: channel name :param score_package: load score package name :param container_port: score container port :return: """ score_info = None retry_times = 1 while score_info is None: if util.check_port_using(conf.IP_PEER, container_port) is False: util.logger.spam( f"channel_manager:load_score_container_each init ScoreService port({container_port})" ) self.__score_containers[channel_name] = ScoreService( container_port) self.__score_stubs[ channel_name] = StubManager.get_stub_manager_to_server( conf.IP_PEER + ':' + str(container_port), loopchain_pb2_grpc.ContainerStub, is_allow_null_stub=True) score_info = self.__load_score( score_package, self.get_score_container_stub(channel_name), peer_target) if score_info is not None or retry_times >= conf.SCORE_LOAD_RETRY_TIMES: break else: util.logger.spam( f"channel_manager:load_score_container_each score_info load fail retry({retry_times})" ) retry_times += 1 time.sleep(conf.SCORE_LOAD_RETRY_INTERVAL) if score_info is None: return False self.__score_infos[channel_name] = score_info return True
def check_port_available(port): # Check Port is Using if util.check_port_using(int(port)): util.exit_and_msg(f"not available port({port})")
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)