Example #1
0
def generate_rules(param):
    '''
      Converts a param of the suitable type (see default_blacklist.yaml)
      into a dictionary of Rule types.

      @return all rules as gateway_msgs.msg.Rule objects in our usual keyed dictionary format
      @rtype type keyed dictionary of Rule lists
    '''
    rules = utils.create_empty_connection_type_dictionary()
    for value in param:
        rule = Rule()
        rule.name = value['name']
        # maybe also check for '' here?
        pattern = re.compile("None", re.IGNORECASE)
        if pattern.match(value['node']):
            rule.node = ''  # ROS Message fields should not be None, maybe not a problem here though, see below
        else:
            rule.node = value['node']
        rule.type = value['type']
        rules[rule.type].append(rule)
    return rules
def generate_rules(param):
    '''
      Converts a param of the suitable type (see default_blacklist.yaml)
      into a dictionary of Rule types.

      @return all rules as gateway_msgs.msg.Rule objects in our usual keyed dictionary format
      @rtype type keyed dictionary of Rule lists
    '''
    rules = utils.create_empty_connection_type_dictionary()
    for value in param:
        rule = Rule()
        rule.name = value['name']
        # maybe also check for '' here?
        pattern = re.compile("None", re.IGNORECASE)
        if pattern.match(value['node']):
            rule.node = ''  # ROS Message fields should not be None, maybe not a problem here though, see below
        else:
            rule.node = value['node']
        rule.type = value['type']
        rules[rule.type].append(rule)
    return rules
    def advertise_all(self, blacklist):
        '''
          Allow all rules apart from the ones in the provided blacklist +
          default blacklist

          @param blacklist : list of Rule objects
          @type list : list of Rule objects

          @return failure if already advertising all, success otherwise
          @rtype bool
        '''
        rospy.loginfo("Gateway : received a request advertise everything!")
        self.lock.acquire()

        # Check if advertise all already enabled
        if self.advertise_all_enabled:
            self.lock.release()
            return False
        self.advertise_all_enabled = True

        # generate watchlist
        self.watchlist = utils.create_empty_connection_type_dictionary(
        )  # easy hack for getting a clean watchlist
        for connection_type in utils.connection_types:
            allow_all_rule = Rule()
            allow_all_rule.name = '.*'
            allow_all_rule.type = connection_type
            allow_all_rule.node = '.*'
            self.watchlist[connection_type].append(allow_all_rule)

        # generate blacklist (while making sure only unique rules get added)
        self.blacklist = copy.deepcopy(self._default_blacklist)
        for rule in blacklist:
            if not publicRuleExists(rule, self.blacklist[rule.type]):
                self.blacklist[rule.type].append(rule)

        self.lock.release()
        return True
    def advertise_all(self, blacklist):
        '''
          Allow all rules apart from the ones in the provided blacklist +
          default blacklist

          @param blacklist : list of Rule objects
          @type list : list of Rule objects

          @return failure if already advertising all, success otherwise
          @rtype bool
        '''
        rospy.loginfo("Gateway : received a request advertise everything!")
        self.lock.acquire()

        # Check if advertise all already enabled
        if self.advertise_all_enabled:
            self.lock.release()
            return False
        self.advertise_all_enabled = True

        # generate watchlist
        self.watchlist = utils.create_empty_connection_type_dictionary()  # easy hack for getting a clean watchlist
        for connection_type in utils.connection_types:
            allow_all_rule = Rule()
            allow_all_rule.name = '.*'
            allow_all_rule.type = connection_type
            allow_all_rule.node = '.*'
            self.watchlist[connection_type].append(allow_all_rule)

        # generate blacklist (while making sure only unique rules get added)
        self.blacklist = copy.deepcopy(self._default_blacklist)
        for rule in blacklist:
            if not publicRuleExists(rule, self.blacklist[rule.type]):
                self.blacklist[rule.type].append(rule)

        self.lock.release()
        return True