예제 #1
0
class Radius:

    def __init__(self):
        self._fcc = FeedCtrlConnection()
        self._hostID = self._fcc.get_host_master_id()

    def calculate_radius(self):
        radius = self._fcc.get_radius()
        self.__check_trusted(self._hostID, radius, 'MASTER')

    def __check_trusted(self, master_id, radius, prev_app_name, step=1, ):
        if radius and step is not None:
            if radius < 1 or step > radius:
                return
            trusted = self._fcc.get_trusted(master_id)
            if not len(trusted) == 0:
                for trusted_id in trusted:
                    application_name = self._fcc.get_application_name(trusted_id)
                    master = None
                    if application_name == 'MASTER':
                        master = trusted_id
                        if master != self._hostID:
                            self._fcc.set_feed_ids_radius(master, step)
                    elif application_name == prev_app_name or prev_app_name == 'MASTER':
                        master = self._fcc.get_master_id_from_feed(trusted_id)
                        if master != self._hostID:
                            self._fcc.set_feed_ids_radius(master, step)
                    else:
                        return
                    self.__check_trusted(master, radius, application_name, step + 1)
            else:
                return
예제 #2
0
class UiFunctionHandler:
    def __init__(self):
        self._fcc = FeedCtrlConnection()
        # try catch or if None??
        lastEvent = self._fcc.get_my_last_event()
        if lastEvent is not None:
            self._ecf = EventFactory(lastEvent)
            self._eventCreationWrapper = EventCreationWrapper(self._ecf)
        else:
            self._ecf = EventFactory()
            self._eventCreationWrapper = EventCreationWrapper(self._ecf)
            _firstEvent = self._eventCreationWrapper.create_MASTER()
            _secondEvent = self._eventCreationWrapper.create_radius(1)
            _thirdEvent = self._eventCreationWrapper.create_name('Anon')
            self._fcc.add_event(_firstEvent)
            self._fcc.add_event(_secondEvent)
            self._fcc.add_event(_thirdEvent)
        self._masterID = self._fcc.get_host_master_id()

    def get_host_master_id(self):
        # returns the host masterID
        return self._masterID

    def get_master_ids(self):
        # return list of masterIDs from FeedCtrlConnection
        return self._fcc.get_all_master_ids()

    def get_all_master_ids_feed_ids(self, masterID):
        # return a list of feed_ids which belong to the given masterID
        return self._fcc.get_all_master_ids_feed_ids(masterID)

    def get_radius_list(self):
        # return a list of feed_ids which are inside the radius
        return self._fcc.get_feed_ids_in_radius()

    def get_trusted(self):
        # return a list of trusted feed_ids
        return self._fcc.get_trusted(self._masterID)

    def set_trusted(self, feed_id, state):
        # sets a feed to trusted or untrusted (event)
        if state:
            new_event = self._eventCreationWrapper.create_trust(feed_id)
        else:
            new_event = self._eventCreationWrapper.create_block(feed_id)

        self._fcc.add_event(new_event)

    def get_blocked(self):
        # return a list of blocked feed_ids
        return self._fcc.get_blocked(self._masterID)

    def get_radius(self):
        # return the current radius
        return self._fcc.get_radius()

    def set_radius(self, radius):
        # sets the new radius
        # calls calcRadius() to recalculate the new Elements, which are in the radius
        self._fcc.set_feed_ids_radius(self._masterID, radius)

    def get_username(self, masterID):
        # return username from given masterID
        return self._fcc.get_username(masterID)

    def set_username(self, name):

        new_event = self._eventCreationWrapper.create_name(name)
        self._fcc.add_event(new_event)

    def get_application(self, feed_id):
        # return application name from given feed_id
        return self._fcc.get_application_name(feed_id)