Esempio n. 1
0
    def __init__(self):
        self.admins = watched.WatchedDict()  # {managerId: AdminModel}

        self._listeners = []
        self._reconnectHandlerIds = {}  # managerId => [disconnect, id..]
        self._startSet = startset.StartSet(self.admins.has_key,
                                           errors.AlreadyConnectingError,
                                           errors.AlreadyConnectedError)
Esempio n. 2
0
    def start(self, component):
        self.watchable_keycards = watched.WatchedDict(
        )  # keycard id -> Keycard
        self.contexts = {}  # keycard id -> {algorithm name -> result}
        self.algorithms = util.OrderedDict()  # name -> algorithm

        def add_entry(entry, algorithm):
            name = entry['type']
            if name in self.algorithms:
                suffix = 1
                while ('%s-%d' % (name, suffix)) in self.algorithms:
                    suffix += 1
                name = '%s-%d' % (name, suffix)

            assert name not in self.algorithms
            self.algorithms[name] = algorithm
            return name

        # get all algorithm plugs this component has, put them into
        # self.algorithms with unique names
        entries = component.config['plugs'].get(base.BOUNCER_ALGORITHM_SOCKET,
                                                [])
        algorithms = component.plugs.get(base.BOUNCER_ALGORITHM_SOCKET, [])

        if not algorithms:
            m = messages.Error(T_(
                N_("The multibouncerplug requires at least one bouncer "
                   "algorithm plug to be present")),
                               mid='no-algorithm')
            component.addMessage(m)
            raise errors.ComponentSetupHandledError()

        for entry, algorithm in zip(entries, algorithms):
            # add the algorithm to the algorithms dictionary
            name = add_entry(entry, algorithm)
            # provide the algorithm with the keycard store
            algorithm.set_keycard_store(self.watchable_keycards)
            # provide the algorithm with an expiry function crafted especially
            # for it (containing its unique name)
            expire = lambda ids: self.algorithm_expire_keycard_ids(ids, name)
            algorithm.set_expire_function(expire)

        self.debug("configured with algorithms %r", self.algorithms.keys())

        # create the algorithm combinator
        props = self.args['properties']
        self.combinator = combinator.AlgorithmCombinator(self.algorithms)

        if 'combination' in props and combinator.pyparsing is None:
            m = messages.Error(T_(
                N_("To use the 'combination' property you need to "
                   "have the 'pyparsing' module installed.\n")),
                               mid='missing-pyparsing')
            documentation.messageAddPythonInstall(m, 'pyparsing')
            component.addMessage(m)
            raise errors.ComponentSetupHandledError()

        # get the combination specification, defaulting to implicit AND
        spec = props.get('combination', ' and '.join(self.algorithms.keys()))
        self.debug("using combination %s", spec)
        try:
            self.combinator.create_combination(spec)
        except combinator.ParseException, e:
            m = messages.Error(T_(N_("Invalid algorithms combination: %s"),
                                  str(e)),
                               mid='wrong-combination')

            component.addMessage(m)
            raise errors.ComponentSetupHandledError()
Esempio n. 3
0
 def init(self):
     self.watchable_keycards = watched.WatchedDict(
     )  # keycard id -> Keycard
     self.contexts = {}  # keycard id -> {algorithm name -> bool result}
     self.algorithms = util.OrderedDict()  # name -> algorithm instance
     self.combinator = None