def test_01_start(self):
     print("\n-----", sys._getframe().f_code.co_name, "-----")
     key_exchange_manager.KeyExchangeManager.KEY_EXCHANGE_INVOKE_MAX_BACKOFF = 1
     key_exchange_manager.KeyExchangeManager.KEY_EXCHANGE_RETRY_INTERVAL = 3
     key_exchange_manager.KeyExchangeManager.KEY_REFRESH_INTERVAL = 15
     key_exchange_manager.KeyExchangeManager.KEY_OBSOLETE_TIMER = 4
     TopologyManagerBase.NEIGHBOR_LIST_REFRESH_INTERVAL = 15
     dummycore = DummyCore()
     keyconfig = {
         'use': True,
         'directory': ".bbc1-domainkeys",
         'obsolete_timeout': 3,
     }
     global networkings, nodes, conf
     for i, nw in enumerate(networkings):
         if os.path.exists(".bbc1-%d"%i):
             shutil.rmtree(".bbc1-%d"%i)
         config = bbc_config.BBcConfig(directory=".bbc1-%d"%i)
         conf = config.get_config()
         conf["domain_key"].update(keyconfig)
         networkings[i] = bbc_network.BBcNetwork(core=dummycore, config=config, p2p_port=6641+i, loglevel=LOGLEVEL)
         networkings[i].create_domain(domain_id=domain_id)
         nodes[i] = networkings[i].domains[domain_id]['neighbor'].my_node_id
         assert nodes[i] is not None
         assert networkings[i].ip_address != ''
         print("IPv4: %s, IPv6 %s, port: %d" % (networkings[i].ip_address, networkings[i].ip6_address,
                                                networkings[i].port))
Ejemplo n.º 2
0
 def __init__(self, workingdir=".bbc1", configfile=None):
     self.config = bbc_config.BBcConfig(workingdir, configfile,
                                        None).get_config()
     self.handlers = dict()
     for domain_id_str, conf in self.config['domains'].items():
         if 'db' not in conf:
             continue
         dh = NewDataHandler(domain_id_str=domain_id_str,
                             config=conf,
                             workingdir=workingdir)
         self.handlers[domain_id_str] = dh
Ejemplo n.º 3
0
Archivo: setup.py Proyecto: y-sira/bbc1
def setup_config(args):

    prevdir = os.getcwd()
    dirpath = os.path.dirname(os.path.realpath(__file__))
    os.chdir(dirpath)
    os.chdir('..')

    bbcConfig = bbc_config.BBcConfig(args.workingdir, args.config)
    config = bbcConfig.get_config()

    isUpdated = False

    if not 'ethereum' in config:
        config['ethereum'] = {
            'chain_id': args.networkid,
            'port': args.port,
            'log': args.log,
            'account': '',
            'passphrase': '',
            'contract_address': '',
        }
        isUpdated = True

    elif config['ethereum']['chain_id'] != args.networkid:
        config['ethereum']['chain_id'] = args.networkid
        isUpdated = True

    elif config['ethereum']['port'] != args.port:
        config['ethereum']['port'] = args.port
        isUpdated = True

    elif config['ethereum']['log'] != args.log:
        config['ethereum']['log'] = args.log
        isUpdated = True

    if isUpdated:
        bbcConfig.update_config()

    os.chdir(prevdir)

    return bbcConfig
Ejemplo n.º 4
0
    def test_01_start(self):
        print("\n-----", sys._getframe().f_code.co_name, "-----")

        TopologyManagerBase.NEIGHBOR_LIST_REFRESH_INTERVAL = 15
        dummycore = DummyCore()
        global networkings, nodes, conf
        for i, nw in enumerate(networkings):
            if os.path.exists(".bbc1-%d" % i):
                shutil.rmtree(".bbc1-%d" % i)
            config = bbc_config.BBcConfig(directory=".bbc1-%d" % i)
            networkings[i] = bbc_network.BBcNetwork(core=dummycore,
                                                    config=config,
                                                    p2p_port=6641 + i,
                                                    loglevel=LOGLEVEL)
            networkings[i].create_domain(domain_id=domain_id)
            nodes[i] = networkings[i].domains[domain_id]['neighbor'].my_node_id
            assert nodes[i] is not None
            assert networkings[i].ip_address != ''
            print("IPv4: %s, IPv6 %s, port: %d" %
                  (networkings[i].ip_address, networkings[i].ip6_address,
                   networkings[i].port))
Ejemplo n.º 5
0
def setup_config(workingdir, filename, networkid, port, log):

    prevdir = chdir_to_core_path()

    bbcConfig = bbc_config.BBcConfig(workingdir,
            os.path.join(workingdir, filename))
    config = bbcConfig.get_config()

    isUpdated = False

    if not 'ethereum' in config:
        config['ethereum'] = {
            'chain_id': networkid,
            'port': port,
            'log': log,
            'account': '',
            'passphrase': '',
            'contract_address': '',
        }
        isUpdated = True

    elif config['ethereum']['chain_id'] != networkid:
        config['ethereum']['chain_id'] = networkid
        isUpdated = True

    elif config['ethereum']['port'] != port:
        config['ethereum']['port'] = port
        isUpdated = True

    elif config['ethereum']['log'] != log:
        config['ethereum']['log'] = log
        isUpdated = True

    if isUpdated:
        bbcConfig.update_config()

    os.chdir(prevdir)

    return bbcConfig
Ejemplo n.º 6
0
 def test_01_start(self):
     print("\n-----", sys._getframe().f_code.co_name, "-----")
     global dummy_cores, networkings, nodes
     user_message_routing.UserMessageRouting.REFRESH_FORWARDING_LIST_INTERVAL = 10  # for testing
     for i, nw in enumerate(networkings):
         if os.path.exists(".bbc1-%d" % i):
             shutil.rmtree(".bbc1-%d" % i)
         dummy_cores[i] = DummyCore(9000 + i)
         config = bbc_config.BBcConfig(directory=".bbc1-%d" % i)
         networkings[i] = bbc_network.BBcNetwork(core=dummy_cores[i],
                                                 config=config,
                                                 p2p_port=6641 + i,
                                                 loglevel=LOGLEVEL)
         dummy_cores[i].networking = networkings[i]
         networkings[i].create_domain(domain_id=domain_id)
         user_routings[i] = networkings[i].domains[domain_id]['user']
         nodes[i] = networkings[i].domains[domain_id]['neighbor'].my_node_id
         assert nodes[i] is not None
         assert networkings[i].ip_address != ''
         print("IPv4: %s, IPv6 %s, port: %d" %
               (networkings[i].ip_address, networkings[i].ip6_address,
                networkings[i].port))
Ejemplo n.º 7
0
 def test_01_start(self):
     print("-----", sys._getframe().f_code.co_name, "-----")
     dummycore = DummyCore()
     from bbc1.core import simple_cluster
     simple_cluster.FORWARD_CACHE_SIZE = 5
     global networkings, nodes, conf
     for i, nw in enumerate(networkings):
         config = bbc_config.BBcConfig(directory=".bbc1-%d" % i)
         networkings[i] = bbc_network.BBcNetwork(core=dummycore,
                                                 config=config,
                                                 p2p_port=6641 + i,
                                                 loglevel=LOGLEVEL)
         networkings[i].create_domain(network_module="simple_cluster",
                                      domain_id=domain_id)
         nodes[i] = networkings[i].domains[domain_id].node_id
         assert nodes[i] is not None
         assert networkings[i].ip_address != ''
         print("IPv4: %s, IPv6 %s, port: %d" %
               (networkings[i].ip_address, networkings[i].ip6_address,
                networkings[i].port))
     for i in range(core_nodes):
         networkings[i].register_user_id(domain_id, asset_group_id,
                                         users[i])
Ejemplo n.º 8
0
    def _config_tree(self, args):

        prevdir = os.getcwd()
        os.chdir(os.path.dirname(os.path.realpath(__file__)))

        bbcConfig = bbc_config.BBcConfig(args.workingdir,
                os.path.join(args.workingdir, args.config))
        config = bbcConfig.get_domain_config(self.domain_id)

        config['use_ledger_subsystem'] = True
        if 'ledger_subsystem' not in config:
            config['ledger_subsystem'] = {
                'subsystem': self.name.lower(),
                'max_transactions': 0,
                'max_seconds': 0
            }
        config['ledger_subsystem']['max_transactions'] = args.transactions
        config['ledger_subsystem']['max_seconds'] = args.seconds

        bbcConfig.update_config()
        os.chdir(prevdir)
        print("You may want to restart bbc_core.py"
                " (with '--ledgersubsystem').")
Ejemplo n.º 9
0
def setup_config(working_dir, file_name, network_name):
    """Sets Ethereum brownie configuration.

    Args:
        working_dir (str): The working directory of BBc-1 core.
        file_name (str): The file name of BBc-1 core configuration file.
        network_name (str): The name of the brownie network.

    """

    prevdir = chdir_to_core_path()

    bbcConfig = bbc_config.BBcConfig(working_dir,
                                     os.path.join(working_dir, file_name))
    config = bbcConfig.get_config()

    isUpdated = False

    if not 'ethereum' in config or not 'network' in config['ethereum']:
        config['ethereum'] = {
            'network': network_name,
            'private_key': '',
            'contract_address': '',
            'web3_infura_project_id': '',
        }
        isUpdated = True

    elif config['ethereum']['network'] != network_name:
        config['ethereum']['network'] = network_name
        isUpdated = True

    if isUpdated:
        bbcConfig.update_config()

    os.chdir(prevdir)

    return bbcConfig
Ejemplo n.º 10
0
# -*- coding: utf-8 -*-
import pytest

import sys
sys.path.extend(["../"])
from bbc1.common import bbclib
from bbc1.core import bbc_ledger, bbc_config
from bbc1.core.bbc_ledger import ResourceType

config = bbc_config.BBcConfig()
ledger_manager =bbc_ledger.BBcLedger(config=config)

user_id = bbclib.get_new_id("destination_id_test1")
domain_id = bbclib.get_new_id("test_domain")
asset_group_id = bbclib.get_new_id("asset_group_1")
keypair1 = bbclib.KeyPair()
keypair1.generate()

transaction1 = bbclib.make_transaction_for_base_asset(asset_group_id=asset_group_id)
transaction1.digest()
print("**** transaction_id:", transaction1.transaction_id)


class TestBBcLedger(object):

    def test_01_open(self):
        print("-----", sys._getframe().f_code.co_name, "-----")
        ledger_manager.add_domain(domain_id)
        ledger_manager.open_db(domain_id, 'transaction_db')
        ledger_manager.close_db(domain_id, 'transaction_db')
Ejemplo n.º 11
0
    def verify(self, certificate):

        print("certificate id: {0}".format(certificate.id))

        if self.is_verbose:
            print("xml: {0}".format(
                ET.tostring(certificate.document.root,
                            encoding='utf-8').decode('utf-8')))

        try:
            dic = self.get_verification_dict(certificate)

        except ValueError as error:
            print("Failed: {0}".format(str(error)))
            return

        except KeyError as error:
            print("Failed: algorithm {0} not supported".format(str(error)))
            return

        if dic is None:
            print("Failed: not registered.")
            return

        if dic == {}:
            print("Failed: ledger subsystem is not enabled.")
            return

        if dic[b'result'] == False:
            print("Failed: document digest is not found.")
            return

        spec = dic[b'spec']
        if spec[b'subsystem'] != b'ethereum':
            print("Failed: not stored in an Ethereum subsystem.")
            return

        if self.is_test:
            return

        subtree = dic[b'subtree']

        bbcConfig = bbc_config.BBcConfig(
            self.workingdir,
            os.path.join(self.workingdir, bbc_config.DEFAULT_CONFIG_FILE))
        config = bbcConfig.get_config()

        prevdir = os.getcwd()
        os.chdir(bbc1.__path__[0] + '/core/ethereum')

        eth = bbc_ethereum.BBcEthereum(
            config['ethereum']['network'],
            config['ethereum']['private_key'],
            contract_address=spec[b'contract_address'].decode('utf-8'))

        os.chdir(prevdir)

        digest = self.registry.get_document_digest(
            certificate.document.document_id)

        block_no = eth.verify(digest, subtree)

        if block_no <= 0:
            print("Failed: document digest is not found.")

        else:
            block = network.web3.eth.getBlock(block_no)
            print("Verified at: block {0}".format(block_no))
            print("Date-Time: {0}".format(
                datetime.datetime.fromtimestamp(block['timestamp'])))