コード例 #1
0
ファイル: router.py プロジェクト: rvdmei/crossbar
    def __init__(self, factory, realm, options=None, store=None, mqtt_payload_format=None):
        """

        :param factory: The router factory this router was created by.
        :type factory: Object that implements :class:`autobahn.wamp.interfaces.IRouterFactory`..
        :param realm: The realm this router is working for.
        :type realm: str
        :param options: Router options.
        :type options: Instance of :class:`crossbar.router.RouterOptions`.
        :param mqtt_payload_format: The format that MQTT messages on this realm are in.
        :type mqtt_payload_format: str
        """
        self._factory = factory
        self._options = options or RouterOptions()
        self._store = store
        self._realm = realm
        self.realm = realm.config[u'name']

        self._trace_traffic = False
        self._trace_traffic_roles_include = None
        self._trace_traffic_roles_exclude = [u'trusted']

        # map: session_id -> session
        self._session_id_to_session = {}

        self._broker = self.broker(self, self._options)
        self._dealer = self.dealer(self, self._options)
        self._attached = 0

        self._mqtt_payload_format = mqtt_payload_format

        self._roles = {
            u'trusted': RouterTrustedRole(self, u'trusted')
        }
コード例 #2
0
ファイル: broker.py プロジェクト: joebos/crossbar
    def __init__(self, router, options=None):
        """

        :param router: The router this dealer is part of.
        :type router: Object that implements :class:`crossbar.router.interfaces.IRouter`.
        :param options: Router options.
        :type options: Instance of :class:`crossbar.router.types.RouterOptions`.
        """
        self._router = router
        self._options = options or RouterOptions()

        # subscription map managed by this broker
        self._subscription_map = UriObservationMap()

        # map: session -> set of subscriptions (needed for detach)
        self._session_to_subscriptions = {}

        # check all topic URIs with strict rules
        self._option_uri_strict = self._options.uri_check == RouterOptions.URI_CHECK_STRICT

        # supported features from "WAMP Advanced Profile"
        self._role_features = role.RoleBrokerFeatures(
            publisher_identification=True,
            pattern_based_subscription=True,
            subscription_meta_api=True,
            subscriber_blackwhite_listing=True,
            publisher_exclusion=True,
            subscription_revocation=True)
コード例 #3
0
    def __init__(self, factory, realm, options=None, store=None):
        """

        :param factory: The router factory this router was created by.
        :type factory: Object that implements :class:`autobahn.wamp.interfaces.IRouterFactory`..
        :param realm: The realm this router is working for.
        :type realm: str
        :param options: Router options.
        :type options: Instance of :class:`autobahn.wamp.types.RouterOptions`.
        """
        self._factory = factory
        self._options = options or RouterOptions()
        self._store = store
        self._realm = realm
        self.realm = realm.config['name']

        self._trace_traffic = False
        self._trace_traffic_roles_include = None
        self._trace_traffic_roles_exclude = [u'trusted']

        # map: session_id -> session
        self._session_id_to_session = {}

        self._broker = self.broker(self, self._options)
        self._dealer = self.dealer(self, self._options)
        self._attached = 0

        self._roles = {"trusted": RouterTrustedRole(self, "trusted")}
コード例 #4
0
    def __init__(self, router, options=None):
        """

        :param router: The router this dealer is part of.
        :type router: Object that implements :class:`crossbar.router.interfaces.IRouter`.
        :param options: Router options.
        :type options: Instance of :class:`crossbar.router.types.RouterOptions`.
        """
        self._router = router
        self._options = options or RouterOptions()

        # generator for WAMP request IDs
        self._request_id_gen = util.IdGenerator()

        # registration map managed by this dealer
        self._registration_map = UriObservationMap(ordered=True)

        # map: session -> set of registrations (needed for detach)
        self._session_to_registrations = {}

        # pending callee invocation requests
        self._invocations = {}

        # check all procedure URIs with strict rules
        self._option_uri_strict = self._options.uri_check == RouterOptions.URI_CHECK_STRICT

        # supported features from "WAMP Advanced Profile"
        self._role_features = role.RoleDealerFeatures(
            caller_identification=True,
            pattern_based_registration=True,
            session_meta_api=True,
            registration_meta_api=True,
            shared_registration=True,
            progressive_call_results=True,
            registration_revocation=True)
コード例 #5
0
ファイル: router.py プロジェクト: yankos/crossbar
    def __init__(self,
                 node_id: str,
                 worker_id: str,
                 worker,
                 options: Optional[RouterOptions] = None):
        """

        :param node_id: Node (management) ID.
        :param worker_id: (Router) worker (management) ID.
        :param worker: Router worker.
        :param options: Default router options.
        """
        self._node_id = node_id
        self._worker_id = worker_id
        self._worker = worker
        self._routers: Dict[str, Router] = {}
        self._options = options or RouterOptions(
            uri_check=RouterOptions.URI_CHECK_LOOSE)
        # XXX this should get passed in from somewhere
        from twisted.internet import reactor
        self._reactor = reactor

        from crossbar.worker.router import RouterController
        from crossbar.worker.proxy import ProxyController
        assert worker is None or isinstance(
            worker, RouterController) or isinstance(worker, ProxyController)
コード例 #6
0
    def __init__(self, router, options=None):
        """

        :param router: The router this dealer is part of.
        :type router: Object that implements :class:`crossbar.router.interfaces.IRouter`.
        :param options: Router options.
        :type options: Instance of :class:`crossbar.router.types.RouterOptions`.
        """
        self._router = router
        self._options = options or RouterOptions()

        # generator for WAMP request IDs
        self._request_id_gen = util.IdGenerator()

        # registration map managed by this dealer
        self._registration_map = UriObservationMap(ordered=True)

        # map: session -> set of registrations (needed for detach)
        self._session_to_registrations = {}

        # map: session -> in-flight invocations
        self._callee_to_invocations = {}
        # BEWARE: this map must be kept up-to-date along with the
        # _invocations map below! Use the helper methods
        # _add_invoke_request and _remove_invoke_request

        # map: session -> in-flight invocations
        self._caller_to_invocations = {}

        # careful here: the 'request' IDs are unique per-session
        # (only) so we map from (session_id, call) tuples to in-flight invocations
        # map: (session_id, call) -> in-flight invocations
        self._invocations_by_call = {}

        # pending callee invocation requests
        self._invocations = {}

        # check all procedure URIs with strict rules
        self._option_uri_strict = self._options.uri_check == RouterOptions.URI_CHECK_STRICT

        # supported features from "WAMP Advanced Profile"
        self._role_features = role.RoleDealerFeatures(caller_identification=True,
                                                      pattern_based_registration=True,
                                                      session_meta_api=True,
                                                      registration_meta_api=True,
                                                      shared_registration=True,
                                                      progressive_call_results=True,
                                                      registration_revocation=True,
                                                      payload_transparency=True,
                                                      testament_meta_api=True,
                                                      payload_encryption_cryptobox=True,
                                                      call_canceling=True)

        # store for call queues
        if self._router._store:
            self._call_store = self._router._store.call_store
        else:
            self._call_store = None
コード例 #7
0
ファイル: router.py プロジェクト: rvdmei/crossbar
    def __init__(self, options=None):
        """

        :param options: Default router options.
        :type options: Instance of :class:`crossbar.router.RouterOptions`.
        """
        self._routers = {}
        self._options = options or RouterOptions(uri_check=RouterOptions.URI_CHECK_LOOSE)
        self._auto_create_realms = False
コード例 #8
0
ファイル: router.py プロジェクト: roeste/crossbar
    def start_realm(self, realm):
        """
        Starts a realm on this router.

        :param realm: The realm to start.
        :type realm: instance of :class:`crossbar.worker.router.RouterRealm`.

        :returns: The router instance for the started realm.
        :rtype: instance of :class:`crossbar.router.session.CrossbarRouter`
        """
        self.log.debug("CrossbarRouterFactory.start_realm(realm = {realm})",
                       realm=realm)

        # get name of realm (an URI in general)
        #
        uri = realm.config['name']
        assert (uri not in self._routers)

        # if configuration of realm contains a "store" item, set up a
        # realm store as appropriate ..
        store = None
        if 'store' in realm.config:
            store_config = realm.config['store']

            if store_config['type'] == 'lmdb':
                # if LMDB is available, and a realm store / database is configured,
                # create an LMDB environment
                if not HAS_LMDB:
                    raise Exception("LDMB not available")
                store = LmdbRealmStore(store_config)

            elif store_config['type'] == 'memory':
                store = MemoryRealmStore(store_config)
            else:
                raise Exception('logic error')

        # now create a router for the realm
        #
        options = RouterOptions(
            uri_check=self._options.uri_check,
            event_dispatching_chunk_size=self._options.
            event_dispatching_chunk_size,
        )
        for arg in ['uri_check', 'event_dispatching_chunk_size']:
            if arg in realm.config.get('options', {}):
                setattr(options, arg, realm.config['options'][arg])

        router = Router(self, realm, options, store=store)

        self._routers[uri] = router
        self.log.debug("Router created for realm '{uri}'", uri=uri)

        return router
コード例 #9
0
ファイル: router.py プロジェクト: bb4242/crossbar
    def __init__(self, node_id, options=None):
        """

        :param options: Default router options.
        :type options: Instance of :class:`autobahn.wamp.types.RouterOptions`.
        """
        assert (type(node_id) == six.text_type)
        self._node_id = node_id
        self._routers = {}
        self._options = options or RouterOptions(
            uri_check=RouterOptions.URI_CHECK_LOOSE)
        self._auto_create_realms = False
コード例 #10
0
ファイル: router.py プロジェクト: yankos/crossbar
    def __init__(self,
                 factory,
                 realm,
                 options: Optional[RouterOptions] = None,
                 store: Optional[IRealmStore] = None,
                 inventory: Optional[IInventory] = None):
        """

        :param factory: The router factory this router was created by.
        :type factory: Object that implements :class:`autobahn.wamp.interfaces.IRouterFactory`.

        :param realm: The realm this router is working for.
        :type realm: Instance of :class:`crossbar.worker.router.RouterRealm`.

        :param options: Router options.
        :param store: Router realm store to use (optional).
        """
        self._factory = factory
        self._realm = realm
        self._options = options or RouterOptions()
        self._store: Optional[IRealmStore] = store
        self._inventory: Optional[IInventory] = inventory

        self.realm = realm.config['name']

        self._trace_traffic = False
        self._trace_traffic_roles_include = None
        self._trace_traffic_roles_exclude = ['trusted']

        # map: session_id -> session
        self._session_id_to_session: Dict[int, ISession] = {}

        # map: authid -> set(session)
        self._authid_to_sessions: Dict[str, Set[ISession]] = {}

        # map: authrole -> set(session)
        self._authrole_to_sessions: Dict[str, Set[ISession]] = {}

        # map: (realm, authrole, uri, action) -> authorization
        self._authorization_cache: Dict[Tuple[str, str, str, str],
                                        Dict[str, Any]] = {}

        self._broker = self.broker(self, factory._reactor, self._options)
        self._dealer = self.dealer(self, factory._reactor, self._options)
        self._attached = 0

        self._roles = {'trusted': RouterTrustedRole(self, 'trusted')}

        # FIXME: this was previously just checking for existence of
        # self._factory._worker._maybe_trace_tx_msg / _maybe_trace_rx_msg
        self._is_traced = False

        self.reset_stats()
コード例 #11
0
    def __init__(self, node_id, worker, options=None):
        """

        :param options: Default router options.
        :type options: Instance of :class:`crossbar.router.RouterOptions`.
        """
        self._node_id = node_id
        self._worker = worker
        self._routers = {}
        self._options = options or RouterOptions(uri_check=RouterOptions.URI_CHECK_LOOSE)
        # XXX this should get passed in from .. somewhere
        from twisted.internet import reactor
        self._reactor = reactor
コード例 #12
0
    def __init__(self, router, reactor, options=None):
        """

        :param router: The router this dealer is part of.
        :type router: Object that implements :class:`crossbar.router.interfaces.IRouter`.

        :param options: Router options.
        :type options: Instance of :class:`crossbar.router.types.RouterOptions`.
        """
        self._router = router
        self._reactor = reactor
        self._options = options or RouterOptions()

        # generator for WAMP request IDs
        self._request_id_gen = util.IdGenerator()

        # subscription map managed by this broker
        self._subscription_map = UriObservationMap()

        # map: session -> set of subscriptions (needed for detach)
        self._session_to_subscriptions = {}

        # check all topic URIs with strict rules
        self._option_uri_strict = self._options.uri_check == RouterOptions.URI_CHECK_STRICT

        # supported features from "WAMP Advanced Profile"
        self._role_features = role.RoleBrokerFeatures(
            publisher_identification=True,
            pattern_based_subscription=True,
            session_meta_api=True,
            subscription_meta_api=True,
            subscriber_blackwhite_listing=True,
            publisher_exclusion=True,
            subscription_revocation=True,
            event_retention=True,
            payload_transparency=True,
            payload_encryption_cryptobox=True)

        # store for event history
        if self._router._store:
            self._event_store = self._router._store.event_store
        else:
            self._event_store = None

        # if there is a store, let the store attach itself to all the subscriptions
        # it is configured to track
        if self._event_store:
            self._event_store.attach_subscription_map(self._subscription_map)
コード例 #13
0
    def start_realm(self, realm):
        """
        Starts a realm on this router.

        :param realm: The realm to start.
        :type realm: instance of :class:`crossbar.worker.router.RouterRealm`.

        :returns: The router instance for the started realm.
        :rtype: instance of :class:`crossbar.router.session.CrossbarRouter`
        """
        self.log.debug("CrossbarRouterFactory.start_realm(realm = {realm})",
                       realm=realm)

        # get name of realm (an URI in general)
        #
        uri = realm.config['name']
        assert (uri not in self._routers)

        # if configuration of realm contains a "store" item, set up a
        # realm store as appropriate ..
        store = None
        if 'store' in realm.config:
            psn = self._worker.personality
            store = psn.create_realm_store(psn, self, realm.config['store'])
            self.log.info('Initialized realm store {rsk} for realm "{realm}"',
                          rsk=store.__class__,
                          realm=uri)

        # now create a router for the realm
        #
        options = RouterOptions(
            uri_check=self._options.uri_check,
            event_dispatching_chunk_size=self._options.
            event_dispatching_chunk_size,
        )
        for arg in ['uri_check', 'event_dispatching_chunk_size']:
            if arg in realm.config.get('options', {}):
                setattr(options, arg, realm.config['options'][arg])

        router = Router(self, realm, options, store=store)

        self._routers[uri] = router
        self.log.info('{klass}.start_realm: router created for realm "{uri}"',
                      klass=self.__class__.__name__,
                      uri=uri)

        return router
コード例 #14
0
    def __init__(self, factory, realm, options=None, store=None):
        """

        :param factory: The router factory this router was created by.
        :type factory: Object that implements :class:`autobahn.wamp.interfaces.IRouterFactory`..

        :param realm: The realm this router is working for.
        :type realm: str

        :param options: Router options.
        :type options: Instance of :class:`crossbar.router.RouterOptions`.
        """
        self._factory = factory
        self._options = options or RouterOptions()
        self._store = store
        self._realm = realm
        self.realm = realm.config[u'name']

        self._trace_traffic = False
        self._trace_traffic_roles_include = None
        self._trace_traffic_roles_exclude = [u'trusted']

        # map: session_id -> session
        self._session_id_to_session = {}
        # map: authid -> set(session)
        self._authid_to_sessions = {}
        # map: authrole -> set(session)
        self._authrole_to_sessions = {}

        self._broker = self.broker(self, factory._reactor, self._options)
        self._dealer = self.dealer(self, factory._reactor, self._options)
        self._attached = 0

        self._roles = {
            u'trusted': RouterTrustedRole(self, u'trusted')
        }

        # FIXME: this was previsouly just checking for existence of
        # self._factory._worker._maybe_trace_tx_msg / _maybe_trace_rx_msg
        self._is_traced = False

        self.reset_stats()
コード例 #15
0
ファイル: router.py プロジェクト: ynohtna/crossbar
    def __init__(self,
                 node_id: str,
                 worker_id: str,
                 worker,
                 options: Optional[RouterOptions] = None):
        """

        :param node_id: Node (management) ID.
        :param worker_id: (Router) worker (management) ID.
        :param worker: Router worker.
        :param options: Default router options.
        """
        self._node_id = node_id
        self._worker_id = worker_id
        self._worker = worker
        self._routers = {}
        self._options = options or RouterOptions(
            uri_check=RouterOptions.URI_CHECK_LOOSE)
        # XXX this should get passed in from .. somewhere
        from twisted.internet import reactor
        self._reactor = reactor
コード例 #16
0
ファイル: router.py プロジェクト: yankos/crossbar
    def start_realm(self, realm: RouterRealm) -> Router:
        """
        Starts a realm on this router.

        :param realm: The realm to start.
        :returns: The router instance for the started realm.
        :rtype: instance of :class:`crossbar.router.session.CrossbarRouter`
        """
        # extract name (URI in general) of realm from realm configuration
        assert 'name' in realm.config
        uri = realm.config['name']
        assert type(uri) == str
        self.log.info('{func}: realm={realm} with URI "{uri}"',
                      func=hltype(self.start_realm),
                      realm=realm,
                      uri=hlval(uri))

        if realm in self._routers:
            raise RuntimeError(
                'router for realm "{}" already running'.format(uri))

        # setup optional store for realm persistence features
        store: Optional[IRealmStore] = None
        if 'store' in realm.config and realm.config['store']:
            # the worker's node personality
            psn = self._worker.personality
            store = psn.create_realm_store(psn, self, realm.config['store'])
            self.log.info(
                '{func}: initialized realm store {store_class} for realm "{realm}"',
                func=hltype(self.start_realm),
                store_class=hlval(store.__class__, color='green'),
                realm=hlval(uri))

        # setup optional inventory for realm API catalogs
        inventory: Optional[IInventory] = None
        if 'inventory' in realm.config and realm.config['inventory']:
            # the worker's node personality
            psn = self._worker.personality
            inventory = psn.create_realm_inventory(psn, self,
                                                   realm.config['inventory'])
            assert inventory
            self.log.info(
                '{func}: initialized realm inventory <{inventory_type}> for realm "{realm}", '
                'loaded {total_count} types, from config:\n{config}',
                func=hltype(self.start_realm),
                inventory_type=hlval(inventory.type, color='green'),
                total_count=hlval(inventory.repo.total_count),
                realm=hlval(uri),
                config=pformat(realm.config['inventory']))

        # setup realm options
        options = RouterOptions(
            uri_check=self._options.uri_check,
            event_dispatching_chunk_size=self._options.
            event_dispatching_chunk_size,
        )
        for arg in ['uri_check', 'event_dispatching_chunk_size']:
            if arg in realm.config.get('options', {}):
                setattr(options, arg, realm.config['options'][arg])

        # now create a router for the realm
        router = self.router(self,
                             realm,
                             options,
                             store=store,
                             inventory=inventory)
        self._routers[uri] = router

        return router