Exemplo n.º 1
0
    def test_get_channel_info_by_peer_target(self):
        # GIVEN
        default_CHANNEL_MANAGE_DATA_PATH = conf.CHANNEL_MANAGE_DATA_PATH
        conf.CHANNEL_MANAGE_DATA_PATH = os.path.join(conf.LOOPCHAIN_ROOT_PATH,
                                                     "testcase/unittest/channel_manage_data_for_test.json")
        admin_manager = AdminManager("station")
        peer_target1 = '1.1.1.1:1111'
        peer_target2 = '2.2.2.2:2222'
        peer_target3 = '3.3.3.3:3333'
        peer_target4 = '4.4.4.4:4444'

        channel1 = 'loopchain_default'
        channel2 = 'loopchain_test'

        # WHEN
        channel_infos1 = json.loads(admin_manager.get_channel_infos_by_peer_target(peer_target1))
        channel_infos2 = json.loads(admin_manager.get_channel_infos_by_peer_target(peer_target2))
        channel_infos3 = json.loads(admin_manager.get_channel_infos_by_peer_target(peer_target3))
        channel_infos4 = json.loads(admin_manager.get_channel_infos_by_peer_target(peer_target4))

        # THEN
        self.assertEqual(list(channel_infos1.keys()), [channel1, channel2])
        self.assertEqual(list(channel_infos2.keys()), [channel1])
        self.assertEqual(list(channel_infos3.keys()), [channel2])
        self.assertEqual(list(channel_infos4.keys()), [])

        # CLEAR
        conf.CHANNEL_MANAGE_DATA_PATH = default_CHANNEL_MANAGE_DATA_PATH
Exemplo n.º 2
0
def menu4_1(params=None):
    admin_manager = AdminManager("demotool")

    print("\nInput Peer Target [IP]:[port] (default '' -> 127.0.0.1:7100, [port] -> 127.0.0.1:[port])")
    choice = input(" >>  ")
    if choice == "":
        choice = "127.0.0.1:7100"
    elif choice.find(':') == -1:
        choice = "127.0.0.1:" + choice

    select_channel_index = 0
    select_channel_string = ""
    for channel in admin_manager.get_channel_list():
        if select_channel_index != 0:
            select_channel_string += ", "
        select_channel_string += f"{select_channel_index}: {admin_manager.get_channel_list()[select_channel_index]}"
        select_channel_index += 1

    print(f"Select Channel ({select_channel_string})")
    channel_choice = input(" >>  ")
    try:
        test_globals["channel_name"] = admin_manager.get_channel_list()[int(channel_choice)]
    except Exception as e:
        print(f"wrong channel number! Now use default channel({admin_manager.get_channel_list()[0]})\n")
        test_globals["channel_name"] = admin_manager.get_channel_list()[0]

    print("your input: " + choice)
    channel = grpc.insecure_channel(choice)
    peer_stub = loopchain_pb2_grpc.PeerServiceStub(channel)
    response = peer_stub.GetStatus(loopchain_pb2.StatusRequest(request="hello"), conf.GRPC_TIMEOUT)
    print("Peer Status: " + str(response))
    menu4(peer_stub)
Exemplo n.º 3
0
def menu6():
    print("\ndump current data to json")
    current_data = AdminManager("station").json_data
    channel_manage_data_path = conf.CHANNEL_MANAGE_DATA_PATH

    AdminManager("station").save_channel_manage_data(current_data)
    print(
        f"current channel manage data is now up to date in {channel_manage_data_path}"
    )

    print("0. Back")
    choice = input(" >>  ")

    if choice == '0':
        menu_actions['main_menu']()
    return
Exemplo n.º 4
0
def menu3():
    print("\nGet all channel manage info")
    AdminManager("station").get_all_channel_info()
    print("0. Back")
    choice = input(" >>  ")

    if choice == '0':
        menu_actions['main_menu']()
    return
Exemplo n.º 5
0
    def __init__(self,
                 radio_station_ip=None,
                 cert_path=None,
                 cert_pass=None,
                 rand_seed=None):
        """RadioStation Init

        :param radio_station_ip: radioStation Ip
        :param cert_path: RadioStation 인증서 디렉토리 경로
        :param cert_pass: RadioStation private key password
        """
        logger_preset = loggers.get_preset()
        logger_preset.peer_id = "RadioStation"
        logger_preset.update_logger()

        if radio_station_ip is None:
            radio_station_ip = conf.IP_RADIOSTATION
        logging.info("Set RadioStationService IP: " + radio_station_ip)
        if cert_path is not None:
            logging.info("CA Certificate Path : " + cert_path)

        self.__admin_manager = AdminManager("station")
        self.__channel_manager = None
        self.__rest_service = None
        self.__timer_service = TimerService()

        # RS has two status (active, standby) active means enable outer service
        # standby means stop outer service and heartbeat to the other RS (active)
        self.__is_active = False

        # 인증 클래스
        self.__ca = CertificateAuthorization()

        if cert_path is not None:
            # 인증서 로드
            self.__ca.load_pki(cert_path, cert_pass)

        logging.info("Current RadioStation SECURITY_MODE : " +
                     str(self.__ca.is_secure))

        self.p2p_inner_server = None
        self.p2p_outer_server = None

        # gRPC service for Radiostation
        self.__outer_service = OuterService()
        self.__admin_service = AdminService(self.__admin_manager)

        # {group_id:[ {peer_id:IP} ] }로 구성된 dictionary
        self.peer_groups = {conf.ALL_GROUP_ID: []}

        # Peer의 보안을 담당
        self.auth = {}

        ObjectManager().rs_service = self
Exemplo n.º 6
0
def menu5():
    print("\nAdd channel")
    print("Enter the new channel name:")
    new_channel = input(" >>  ")
    AdminManager("station").add_channel(new_channel)

    print("0. Back")
    choice = input(" >>  ")

    if choice == '0':
        menu_actions['main_menu']()
    return
    def test_get_channel_info_by_peer_target(self):
        # GIVEN
        default_CHANNEL_MANAGE_DATA_PATH = conf.CHANNEL_MANAGE_DATA_PATH
        default_ENABLE_CHANNEL_AUTH = conf.ENABLE_CHANNEL_AUTH
        conf.CHANNEL_MANAGE_DATA_PATH = os.path.join(
            conf.LOOPCHAIN_ROOT_PATH,
            "testcase/unittest/channel_manage_data_for_test.json")
        conf.ENABLE_CHANNEL_AUTH = True

        peer_target1 = '111.123.123.123:7100'
        peer_target2 = '222.123.123.123:7200'
        peer_target3 = '333.123.123.123:7300'
        peer_target4 = '444.123.123.123:7400'

        channel1 = 'kofia_certificate'
        channel2 = 'kofia_fine'

        # WHEN
        channel_infos1 = json.loads(
            AdminManager("station").get_channel_infos_by_peer_target(
                peer_target1))
        channel_infos2 = json.loads(
            AdminManager("station").get_channel_infos_by_peer_target(
                peer_target2))
        channel_infos3 = json.loads(
            AdminManager("station").get_channel_infos_by_peer_target(
                peer_target3))
        channel_infos4 = json.loads(
            AdminManager("station").get_channel_infos_by_peer_target(
                peer_target4))

        # THEN
        self.assertEqual(list(channel_infos1.keys()), [channel1, channel2])
        self.assertEqual(list(channel_infos2.keys()), [channel1])
        self.assertEqual(list(channel_infos3.keys()), [channel2])
        self.assertEqual(list(channel_infos4.keys()), [])

        # CLEAR
        conf.CHANNEL_MANAGE_DATA_PATH = default_CHANNEL_MANAGE_DATA_PATH
        conf.ENABLE_CHANNEL_AUTH = default_ENABLE_CHANNEL_AUTH
    def test_add_peer_target(self):
        # GIVEN
        default_CHANNEL_MANAGE_DATA_PATH = conf.CHANNEL_MANAGE_DATA_PATH
        conf.CHANNEL_MANAGE_DATA_PATH = os.path.join(
            conf.LOOPCHAIN_ROOT_PATH,
            "testcase/unittest/channel_manage_data_for_test.json")
        choice = 'Y'
        i = 0
        new_peer_target = '9.9.9.9:9999'
        default_data = AdminManager("station").json_data
        channel_list = AdminManager("station").get_channel_list()
        peer_target_list = default_data[channel_list[0]]["peers"]

        # WHEN
        modified_data = AdminManager("station").add_peer_target(
            choice, new_peer_target, peer_target_list, i)

        # THEN
        self.assertNotEqual(default_data, modified_data)

        # CLEAR
        conf.CHANNEL_MANAGE_DATA_PATH = default_CHANNEL_MANAGE_DATA_PATH
Exemplo n.º 9
0
    def test_add_peer_target(self):
        # GIVEN
        default_CHANNEL_MANAGE_DATA_PATH = conf.CHANNEL_MANAGE_DATA_PATH
        conf.CHANNEL_MANAGE_DATA_PATH = os.path.join(conf.LOOPCHAIN_ROOT_PATH,
                                                     "testcase/unittest/channel_manage_data_for_test.json")
        admin_manager = AdminManager("station")
        i = 0
        new_peer_target = '9.9.9.9:9999'
        loaded_data = admin_manager.json_data
        channel_list = list(loaded_data)
        peer_target_list = loaded_data[channel_list[0]]["peers"]

        # WHEN
        modified_data = admin_manager.add_peer_target(
            loaded_data, channel_list, new_peer_target, peer_target_list, i)
        second_peer_target_list = modified_data[channel_list[0]]["peers"]

        # THEN
        self.assertEqual(len(second_peer_target_list), 3)

        # CLEAR
        conf.CHANNEL_MANAGE_DATA_PATH = default_CHANNEL_MANAGE_DATA_PATH
Exemplo n.º 10
0
    def test_get_all_channel_info(self):
        # GIVEN
        default_CHANNEL_MANAGE_DATA_PATH = conf.CHANNEL_MANAGE_DATA_PATH
        conf.CHANNEL_MANAGE_DATA_PATH = os.path.join(conf.LOOPCHAIN_ROOT_PATH,
                                                     "testcase/unittest/channel_manage_data_for_test.json")
        # WHEN
        all_channel_info = AdminManager("station").get_all_channel_info()

        # THEN
        self.assertTrue(isinstance(all_channel_info, str))

        # CLEAR
        conf.CHANNEL_MANAGE_DATA_PATH = default_CHANNEL_MANAGE_DATA_PATH
Exemplo n.º 11
0
    def test_delete_peer_target(self):
        # GIVEN
        default_CHANNEL_MANAGE_DATA_PATH = conf.CHANNEL_MANAGE_DATA_PATH
        conf.CHANNEL_MANAGE_DATA_PATH = os.path.join(conf.LOOPCHAIN_ROOT_PATH,
                                                     "testcase/unittest/channel_manage_data_for_test.json")
        admin_manager = AdminManager("station")
        i = 0
        remove_peer_target = '2.2.2.2:2222'
        loaded_data = admin_manager.json_data
        filtered_channel_infos = admin_manager.get_channel_infos_by_peer_target(remove_peer_target)
        filtered_list = list(json.loads(filtered_channel_infos))

        # WHEN
        modified_data = admin_manager.delete_peer_target(
            loaded_data, remove_peer_target, filtered_list, i)
        second_peer_target_list = modified_data[filtered_list[0]]["peers"]

        # THEN
        self.assertEqual(len(second_peer_target_list), 1)

        # CLEAR
        conf.CHANNEL_MANAGE_DATA_PATH = default_CHANNEL_MANAGE_DATA_PATH
Exemplo n.º 12
0
    def __init__(self, radio_station_ip=None, cert_path=None, cert_pass=None, rand_seed=None):
        """RadioStation Init

        :param radio_station_ip: radioStation Ip
        :param cert_path: RadioStation 인증서 디렉토리 경로
        :param cert_pass: RadioStation private key password
        """
        if radio_station_ip is None:
            radio_station_ip = conf.IP_RADIOSTATION
        logging.info("Set RadioStationService IP: " + radio_station_ip)
        if cert_path is not None:
            logging.info("CA Certificate Path : " + cert_path)

        self.__common_service = CommonService(loopchain_pb2)
        self.__admin_manager = AdminManager("station")
        self.__channel_manager = None
        self.__rest_service = None

        # RS has two status (active, standby) active means enable outer service
        # standby means stop outer service and heartbeat to the other RS (active)
        self.__is_active = False

        # 인증 클래스
        self.__ca = CertificateAuthorization()

        if cert_path is not None:
            # 인증서 로드
            self.__ca.load_pki(cert_path, cert_pass)

        if conf.ENABLE_KMS:
            if rand_seed is None:
                util.exit_and_msg("KMS needs input random seed \n"
                                  "you can put seed -s --seed")
            self.__random_table = self.__create_random_table(rand_seed)

        logging.info("Current RadioStation SECURITY_MODE : " + str(self.__ca.is_secure))

        # gRPC service for Radiostation
        self.__outer_service = OuterService()
        self.__admin_service = AdminService()

        # {group_id:[ {peer_id:IP} ] }로 구성된 dictionary
        self.peer_groups = {conf.ALL_GROUP_ID: []}

        # Peer의 보안을 담당
        self.auth = {}

        ObjectManager().rs_service = self
Exemplo n.º 13
0
def menu4():
    print("\nAdd peer")
    print("Enter the peer target in the following format:")
    print("IP Address of Radio Station:PORT number of Radio Station")
    new_peer_target = input(" >>  ")
    AdminManager("station").ui_add_peer_target(new_peer_target)

    print("1. Add additional peer")
    print("0. Back")
    choice = input(" >>  ")

    if choice == '1':
        menu4()
    elif choice == '0':
        menu_actions['main_menu']()
    return