Beispiel #1
0
    def __init__(self, config=None, reactor=None, personality=None):
        # base ctor
        WorkerController.__init__(self, config=config, reactor=reactor, personality=personality)

        # factory for producing (per-realm) routers
        self._router_factory = self.router_factory_class(None, self)

        # factory for producing router sessions
        self._router_session_factory = RouterSessionFactory(self._router_factory)

        # map: realm ID -> RouterRealm
        self.realms = {}

        # map: realm URI -> realm ID
        self.realm_to_id = {}

        # map: component ID -> RouterComponent
        self.components = {}

        # "global" shared between all components
        self.components_shared = {
            u'reactor': reactor
        }

        # map: transport ID -> RouterTransport
        self.transports = {}
Beispiel #2
0
    def __init__(self, config=None, reactor=None, personality=None):
        # base ctor
        WorkerController.__init__(self,
                                  config=config,
                                  reactor=reactor,
                                  personality=personality)

        # factory for producing (per-realm) routers
        self._router_factory = self.router_factory_class(None, self)

        # factory for producing router sessions
        self._router_session_factory = RouterSessionFactory(
            self._router_factory)

        # map: realm ID -> RouterRealm
        self.realms = {}

        # map: realm URI -> realm ID
        self.realm_to_id = {}

        # map: component ID -> RouterComponent
        self.components = {}

        # "global" shared between all components
        self.components_shared = {u'reactor': reactor}

        # map: transport ID -> RouterTransport
        self.transports = {}
Beispiel #3
0
    def __init__(self, config=None, reactor=None, personality=None):
        # base ctor
        WorkerController.__init__(self, config=config, reactor=reactor, personality=personality)

        # map: component ID -> ContainerComponent
        self.components = {}

        # when shall we exit?
        self._exit_mode = (config.extra.shutdown or self.SHUTDOWN_MANUAL)

        # "global" shared between all components
        self.components_shared = {
            u'reactor': reactor
        }
Beispiel #4
0
    def __init__(self, config=None, reactor=None, personality=None):
        # base ctor
        WorkerController.__init__(self, config=config, reactor=reactor, personality=personality)

        # map: component ID -> ContainerComponent
        self.components = {}

        # when shall we exit?
        self._exit_mode = (config.extra.shutdown or self.SHUTDOWN_MANUAL)

        # "global" shared between all components
        self.components_shared = {
            u'reactor': reactor
        }
Beispiel #5
0
    def __init__(self, config=None, reactor=None, personality=None):
        # WorkerController derives of NativeProcess, which will set self._reactor
        WorkerController.__init__(self, config=config, reactor=reactor, personality=personality)

        worker_options_extra = dict(config.extra.extra)
        self._database_config = worker_options_extra['database']
        self._blockchain_config = worker_options_extra['blockchain']
        self._ipfs_files_directory = worker_options_extra.get('ipfs_files_directory', './.ipfs_files')

        # xbrmm worker status
        self._status = None

        # map of market makers by ID
        self._makers = {}
        self._maker_adr2id = {}

        # open xbrmm worker database, containing a replicate of xbr on-chain data (other than
        # channels, which are market specific and stored in the market maker database of the maker of that market)
        self._dbpath = os.path.abspath(
            self._database_config.get('dbpath', './.xbrmm-{}-db'.format(config.extra.worker)))
        self._db = zlmdb.Database(dbpath=self._dbpath,
                                  maxsize=self._database_config.get('maxsize', 2**30),
                                  readonly=False,
                                  sync=True)
        self._db.__enter__()

        # generic database object metadata
        self._meta = cfxdb.meta.Schema.attach(self._db)

        # xbr database schema
        self._xbr = cfxdb.xbr.Schema.attach(self._db)

        # xbr market maker schema
        self._xbrmm = cfxdb.xbrmm.Schema.attach(self._db)

        # event object too coordinate exit of blockchain monitor background check
        self._run_monitor = None

        # blockchain gateway configuration
        self._bc_gw_config = self._blockchain_config['gateway']
        self.log.info('Initializing Web3 from blockchain gateway configuration\n\n{gateway}\n',
                      gateway=pformat(self._bc_gw_config))
        self._w3 = make_w3(self._bc_gw_config)
        xbr.setProvider(self._w3)

        self._chain_id = self._blockchain_config.get('chain_id', 1)
        self.log.info('Using chain ID {chain_id}', chain_id=hlid(self._chain_id))

        # To be initiated once cbdir variable gets available
        self._ipfs_files_dir = os.path.join(config.extra.cbdir, self._ipfs_files_directory)
Beispiel #6
0
    def onJoin(self, details):
        """
        Called when worker process has joined the node's management realm.
        """
        yield WorkerController.onJoin(self, details, publish_ready=False)

        # WorkerController.publish_ready()
        yield self.publish_ready()
Beispiel #7
0
    def onJoin(self, details):
        """
        Called when worker process has joined the node's management realm.
        """
        yield WorkerController.onJoin(self, details, publish_ready=False)

        # WorkerController.publish_ready()
        yield self.publish_ready()
Beispiel #8
0
    def onJoin(self, details):
        """
        Called when worker process has joined the node's management realm.
        """
        self.log.info('Container worker "{worker_id}" session {session_id} initializing ..', worker_id=self._worker_id, session_id=details.session)
        yield WorkerController.onJoin(self, details, publish_ready=False)

        self.log.info('Container worker "{worker_id}" session ready', worker_id=self._worker_id)

        # WorkerController.publish_ready()
        yield self.publish_ready()
Beispiel #9
0
    def onJoin(self, details):
        """
        Called when worker process has joined the node's management realm.
        """
        self.log.info('Container worker "{worker_id}" session {session_id} initializing ..', worker_id=self._worker_id, session_id=details.session)
        yield WorkerController.onJoin(self, details, publish_ready=False)

        self.log.info('Container worker "{worker_id}" session ready', worker_id=self._worker_id)

        # WorkerController.publish_ready()
        yield self.publish_ready()
Beispiel #10
0
    def onJoin(self, details, publish_ready=True):
        """
        Called when worker process has joined the node's management realm.
        """
        self.log.info('Router worker session for "{worker_id}" joined realm "{realm}" on node router {method}',
                      realm=self._realm,
                      worker_id=self._worker_id,
                      session_id=details.session,
                      method=hltype(RouterController.onJoin))

        yield WorkerController.onJoin(self, details, publish_ready=False)

        # WorkerController.publish_ready()
        self.publish_ready()

        self.log.info('Router worker session for "{worker_id}" ready',
                      worker_id=self._worker_id)
Beispiel #11
0
    def onJoin(self, details, publish_ready=True):
        """
        Called when worker process has joined the node's management realm.
        """
        self.log.info('Router worker session for "{worker_id}" joined realm "{realm}" on node router {method}',
                      realm=self._realm,
                      worker_id=self._worker_id,
                      session_id=details.session,
                      method=hltype(RouterController.onJoin))

        yield WorkerController.onJoin(self, details, publish_ready=False)

        # WorkerController.publish_ready()
        self.publish_ready()

        self.log.info('Router worker session for "{worker_id}" ready',
                      worker_id=self._worker_id)
Beispiel #12
0
    def onJoin(self, details):
        self.log.info('HostMonitor connected (monitors available: {monitors})',
                      monitors=sorted(MONITORS.keys()))

        yield WorkerController.onJoin(self, details, publish_ready=False)

        # register monitor procedures
        dl = []
        for monitor in self._monitors.values():
            d = self.register(monitor.get,
                              u'{}.get_{}'.format(self._prefix, monitor.ID))
            dl.append(d)
        res = yield DeferredList(dl, fireOnOneErrback=True)
        print(res)
        self.log.info('HostMonitor {pcnt} procedures registered',
                      pcnt=len(res))

        # signal this worker is done with setup and ready
        yield self.publish_ready()
Beispiel #13
0
    def onJoin(self, details, publish_ready=True):
        self.log.info(
            'XBR Markets Worker starting (realm={realm}, prefix="{prefix}", session={session}, authid={authid}, authrole={authrole})',
            realm=hlid(details.realm),
            prefix=hlid(self._uri_prefix),
            session=hlid(details.session),
            authid=hlid(details.authid),
            authrole=hlid(details.authrole))
        self.log.info('XBR Markets Worker configuration:\n\n{config}', config=pformat(self.config.extra))

        self._status = self.STATUS_STARTING

        yield WorkerController.onJoin(self, details, publish_ready=False)

        # any special session setup for the market maker goes here ..

        # start blockchain monitor is running on a background thread which exits once this gets False
        self._run_monitor = threading.Event()
        self._stop_monitor = False

        # FIXME: check self.xbr.blocks for latest block already processed
        # initially begin scanning the blockchain with this block, and subsequently scan from the last
        # processed and locally persisted block record in the database
        if 'from_block' in self._blockchain_config:
            scan_from_block = self._blockchain_config['from_block']
            self.log.info('Initial scanning of blockchain beginning with block {scan_from_block} from configuration',
                          scan_from_block=scan_from_block)
        else:
            scan_from_block = 1
            self.log.info('Initial scanning of blockchain from block 1 (!)')

        # monitor/pull blockchain from a background thread
        self._monitor_blockchain_thread = self._reactor.callInThread(self._monitor_blockchain, self._bc_gw_config,
                                                                     scan_from_block)
        self._status = self.STATUS_RUNNING

        yield self.publish_ready()

        self.log.info('XBR Markets Worker ready!')
Beispiel #14
0
 def __init__(self, config=None, reactor=None, personality=None):
     # base ctor
     WorkerController.__init__(self, config=config, reactor=reactor, personality=personality)
Beispiel #15
0
 def __init__(self, config=None, reactor=None, personality=None):
     # base ctor
     WorkerController.__init__(self,
                               config=config,
                               reactor=reactor,
                               personality=personality)