Пример #1
0
def send_config(client, config_obj):
    for domain_id_str, conf in config_obj.items():
        domain_id = bbclib.convert_idstring_to_bytes(domain_id_str)

        client.domain_setup(domain_id, conf['module'])
        dat = wait_check_result_msg_type(
            client.callback, bbclib.ServiceMessageType.RESPONSE_SETUP_DOMAIN)
        assert dat[KeyType.status] == ESUCCESS

        for nd, info in conf['static_nodes'].items():
            node_id, ipv4, ipv6, port = nd, info[0], info[1], info[2]
            client.set_domain_static_node(
                domain_id, bbclib.convert_idstring_to_bytes(node_id), ipv4,
                ipv6, port)
            dat = wait_check_result_msg_type(
                client.callback,
                bbclib.ServiceMessageType.RESPONSE_SET_STATIC_NODE)
            assert dat[KeyType.status] == ESUCCESS

        for asset_group_id_str, info in conf['asset_group_ids'].items():
            asset_group_id = bbclib.convert_idstring_to_bytes(
                asset_group_id_str)
            client.register_asset_group(
                domain_id=domain_id,
                asset_group_id=asset_group_id,
                storage_type=info['storage_type'],
                storage_path=info['storage_path'],
                advertise_in_domain0=info['advertise_in_domain0'])
            dat = wait_check_result_msg_type(
                client.callback,
                bbclib.ServiceMessageType.RESPONSE_SETUP_ASSET_GROUP)
            assert dat[KeyType.status] == ESUCCESS
Пример #2
0
def get_mynodeinfo(client):
    conf = json.loads(get_config(client))
    mynode_conf = {}
    for domain_id_str in conf['domains'].keys():
        domain_id = bbclib.convert_idstring_to_bytes(domain_id_str)
        client.get_domain_peerlist(domain_id)
        results = client.callback.synchronize()
        if results is None:
            continue
        node_id_str = bbclib.convert_id_to_string(results[0][0])
        mynode_conf.setdefault(domain_id_str,
                               dict())[node_id_str] = (results[0][1],
                                                       results[0][2],
                                                       results[0][3])
    print("## {'domain_id': {'node_id': (IPv4, IPv6, port)}}")
    print(mynode_conf)
Пример #3
0
    def create_domain(self,
                      domain_id=ZEROS,
                      network_module=None,
                      get_new_node_id=False):
        """
        Create domain and register user in the domain

        :param domain_id:
        :param network_module: string of module script file
        :param get_new_node_id: If True, the node_id is newly created again
        :return:
        """
        if domain_id in self.domains:
            return False

        nw_module = None
        if network_module is not None:
            if isinstance(network_module, bytes):
                network_module = network_module.decode()
            nw_module = __import__(network_module)

        if nw_module is None:
            return None

        conf = self.config.get_domain_config(domain_id, create_if_new=True)
        if 'node_id' not in conf or get_new_node_id:
            node_id = bbclib.get_random_id()
            conf['node_id'] = bbclib.convert_id_to_string(node_id)
            self.config.update_config()
        else:
            node_id = bbclib.convert_idstring_to_bytes(conf.get('node_id'))

        self.domains[domain_id] = nw_module.NetworkDomain(
            network=self,
            config=self.config,
            domain_id=domain_id,
            node_id=node_id,
            loglevel=self.logger.level,
            logname=self.logname)
        if domain_id != bbclib.domain_global_0:
            self.core.ledger_manager.add_domain(domain_id)
        return True
Пример #4
0
        addr = parsed_args.ip6address
        v4flag = False
    port = parsed_args.port

    bbcclient = bbc_app.BBcAppClient(host=addr, port=port, loglevel="all")
    bbcclient.set_user_id(user_id)

    if parsed_args.start or parsed_args.stop:
        bbcclient.manipulate_ledger_subsystem(parsed_args.start)
        dat = wait_check_result_msg_type(
            bbcclient.callback, bbclib.MsgType.RESPONSE_MANIP_LEDGER_SUBSYS)
        print("Done")
        sys.exit(0)

    if parsed_args.asset_group_id is not None and parsed_args.transaction_id is not None:
        asset_group_id = bbclib.convert_idstring_to_bytes(
            parsed_args.asset_group_id)
        transaction_id = bbclib.convert_idstring_to_bytes(
            parsed_args.transaction_id)

        bbcclient.domain_setup(domain_id)
        bbcclient.callback.synchronize()

        bbcclient.set_asset_group_id(asset_group_id)
        bbcclient.register_asset_group(domain_id=domain_id,
                                       asset_group_id=asset_group_id)
        bbcclient.callback.synchronize()
        bbcclient.register_to_core()

        if parsed_args.verify:
            print("--> Try to verify")
            bbcclient.verify_in_ledger_subsystem(asset_group_id,
Пример #5
0
    def __init__(self,
                 config,
                 core=None,
                 p2p_port=None,
                 use_global=True,
                 loglevel="all",
                 logname=None):
        self.core = core
        self.logger = logger.get_logger(key="bbc_network",
                                        level=loglevel,
                                        logname=logname)
        self.logname = logname
        self.config = config
        self.use_global = use_global
        conf = self.config.get_config()
        self.domains = dict()
        self.asset_groups_to_advertise = set()
        self.ip_address, self.ip6_address = check_my_IPaddresses()
        if p2p_port is not None:
            conf['network']['p2p_port'] = p2p_port
            self.config.update_config()
        self.port = conf['network']['p2p_port']
        self.socket_udp = None
        self.socket_udp6 = None
        if not self.setup_udp_socket():
            self.logger.error("** Fail to setup UDP socket **")
            return
        self.listen_socket = None
        self.listen_socket6 = None
        self.max_connections = conf['network']['max_connections']
        if not self.setup_tcp_server():
            self.logger.error("** Fail to setup TCP server **")
            return

        if 'domains' not in conf:
            return
        for dm in conf['domains'].keys():
            domain_id = bbclib.convert_idstring_to_bytes(dm)
            if not self.use_global and domain_id == bbclib.domain_global_0:
                continue
            c = conf['domains'][dm]
            nw_module = c.get('module', 'simple_cluster')
            self.create_domain(domain_id=domain_id, network_module=nw_module)
            if 'special_domain' in c:
                c.pop('storage_type', None)
                c.pop('storage_path', None)
            else:
                self.core.ledger_manager.add_domain(domain_id)
                for asset_group_id_str, info in c['asset_group_ids'].items():
                    asset_group_id = bbclib.convert_idstring_to_bytes(
                        asset_group_id_str)
                    self.core.asset_group_setup(
                        domain_id, asset_group_id,
                        c.get('storage_type', StorageType.FILESYSTEM),
                        c.get('storage_path', None),
                        c.get('advertise_in_domain0', False))
            for nd, info in c['static_nodes'].items():
                node_id, ipv4, ipv6, port = bbclib.convert_idstring_to_bytes(
                    nd), info[0], info[1], info[2]
                self.add_static_node_to_domain(domain_id, node_id, ipv4, ipv6,
                                               port)
            for nd, info in c['peer_list'].items():
                node_id, ipv4, ipv6, port = bbclib.convert_idstring_to_bytes(
                    nd), info[0], info[1], info[2]
                self.domains[domain_id].add_peer_node_ip46(
                    node_id, ipv4, ipv6, port)
Пример #6
0
    if parsed_args.id:
        value = bbclib.get_new_id(parsed_args.id, include_timestamp=False)
        print(bbclib.convert_id_to_string(value))
        sys.exit(0)
    if parsed_args.timebaseid:
        value = bbclib.get_new_id(parsed_args.id, include_timestamp=True)
        print(bbclib.convert_id_to_string(value))
        sys.exit(0)

    if parsed_args.ip4address:
        addr = parsed_args.ip4address
    if parsed_args.ip6address:
        addr = parsed_args.ip6address
    port = parsed_args.port
    bbcclient = bbc_app.BBcAppClient(host=addr, port=port, loglevel="all")

    domain_id = bbclib.convert_idstring_to_bytes(parsed_args.domain_id)

    if parsed_args.ping_to_neighbors:
        print("ping to all neighbor bbc_cores")
        bbcclient.ping_to_all_neighbors(domain_id)
        time.sleep(1)
        sys.exit(0)

    bbcclient.domain_setup(domain_id, "simple_cluster")
    dat = wait_check_result_msg_type(bbcclient.callback,
                                     bbclib.MsgType.RESPONSE_SETUP_DOMAIN)
    assert dat[KeyType.status] == ESUCCESS

    sys.exit(0)
Пример #7
0
    def create_domain(self, domain_id=ZEROS, config=None):
        """
        Create domain and register user in the domain

        :param domain_id:
        :param config: config for the domain
        :return:
        """
        if domain_id in self.domains:
            return False

        conf = self.config.get_domain_config(domain_id, create_if_new=True)
        if config is not None:
            conf.update(config)
        if 'node_id' not in conf:
            node_id = bbclib.get_random_id()
            conf['node_id'] = bbclib.convert_id_to_string(node_id)
            self.config.update_config()
        else:
            node_id = bbclib.convert_idstring_to_bytes(conf.get('node_id'))

        self.domains[domain_id] = dict()
        self.domains[domain_id]['node_id'] = node_id
        self.domains[domain_id]['name'] = node_id.hex()[:4]
        self.domains[domain_id]['neighbor'] = NeighborInfo(
            network=self,
            domain_id=domain_id,
            node_id=node_id,
            my_info=self.get_my_socket_info(node_id))
        self.domains[domain_id]['topology'] = TopologyManagerBase(
            network=self,
            domain_id=domain_id,
            node_id=node_id,
            logname=self.logname,
            loglevel=self.loglevel)
        self.domains[domain_id]['user'] = UserMessageRouting(
            self, domain_id, logname=self.logname, loglevel=self.loglevel)
        self.get_domain_keypair(domain_id)

        workingdir = self.config.get_config()['workingdir']
        if domain_id == ZEROS:
            self.domains[domain_id]['data'] = DataHandlerDomain0(
                self,
                domain_id=domain_id,
                logname=self.logname,
                loglevel=self.loglevel)
            self.domain0manager = Domain0Manager(self,
                                                 node_id=node_id,
                                                 logname=self.logname,
                                                 loglevel=self.loglevel)
        else:
            self.domains[domain_id]['data'] = DataHandler(
                self,
                config=conf,
                workingdir=workingdir,
                domain_id=domain_id,
                logname=self.logname,
                loglevel=self.loglevel)

        self.domains[domain_id]['repair'] = RepairManager(
            self,
            domain_id,
            workingdir=workingdir,
            logname=self.logname,
            loglevel=self.loglevel)

        if self.domain0manager is not None:
            self.domain0manager.update_domain_belong_to()
            for dm in self.domains.keys():
                if dm != ZEROS:
                    self.domains[dm]['neighbor'].my_info.update(domain0=True)
            self.domains[domain_id]['topology'].update_refresh_timer_entry(1)
        self.stats.update_stats_increment("network", "num_domains", 1)
        return True