18 from gateway_msgs.msg
import Rule
29 Checks that the public rule doesn't already exist in the list of public 30 rules (which can represent the public interface or the rules themselves). 31 We only need to compare the name/node as they uniquely identify the 34 @param public_rule : the rule to search for 37 @param public_rules : list of Rule (public, watchlist or blacklist) 38 @type list : list of Rule objects 40 @return True if the public rule exists, False otherwise 43 for rule
in public_rules:
44 if rule.name == public_rule.name
and \
45 rule.node == public_rule.node:
57 The public interface is the set of rules 58 (pubs/subs/services/actions) that are exposed and made available for 59 freely sharing with a multimaster system. 62 * list of currently available rules to be shared 63 * list of rules and filters that will be watched 64 and shared if they become available 67 def __init__(self, default_rule_blacklist, default_rules):
69 Initialises the public interface 71 @param default_rule_blacklist : connection type keyed dictionary of rules 72 @type str keyed dictionary of gateway_msgs.msg.Rule[] 74 @param default_rules : connection type keyed dictionary of rules 75 @type str keyed dictionary of gateway_msgs.msg.Rule[] 79 self.
watchlist = utils.create_empty_connection_type_dictionary()
89 self.
public = utils.create_empty_connection_type_dictionary()
93 self.
lock = threading.Lock()
96 for connection_type
in utils.connection_types:
97 for rule
in default_rules[connection_type]:
106 Watch for a new public rule, as described for by the incoming message. 108 @param rule : a rule msg from the advertise call 111 @return the rule if added, or None if the rule exists already 120 rospy.loginfo(
"Gateway : adding rule to public watchlist %s" % utils.format_rule(rule))
125 Attempt to remove a watchlist rule from the public interface. Be a 126 bit careful looking for a rule to remove, depending on the node name, 127 which can be set (exact rule/node name match) or None in which case all 128 nodes of that kind of advertisement will match. 130 @param rule : a rule to unadvertise 133 @return the list of rules removed 137 rospy.loginfo(
"Gateway : (req) unadvertise %s" % utils.format_rule(rule))
154 for existing_rule
in self.
watchlist[rule.type]:
155 if (existing_rule.name == rule.name):
156 existing_rules.append(existing_rule)
157 for rule
in existing_rules:
158 self.
watchlist[rule.type].remove(existing_rule)
160 return existing_rules
164 Allow all rules apart from the ones in the provided blacklist + 167 @param blacklist : list of Rule objects 168 @type list : list of Rule objects 170 @return failure if already advertising all, success otherwise 173 rospy.loginfo(
"Gateway : received a request advertise everything!")
183 self.
watchlist = utils.create_empty_connection_type_dictionary()
184 for connection_type
in utils.connection_types:
185 allow_all_rule = Rule()
186 allow_all_rule.name =
'.*' 187 allow_all_rule.type = connection_type
188 allow_all_rule.node =
'.*' 189 self.
watchlist[connection_type].append(allow_all_rule)
193 for rule
in blacklist:
202 Disallow the allow all mode, if enabled. If allow all mode is not 203 enabled, remove everything from the public interface 205 rospy.loginfo(
"Gateway : received a request to remove all advertisements!")
212 self.
watchlist = utils.create_empty_connection_type_dictionary()
223 List of all rules with connection information that is being published. 225 @return dictionary of utils.Connections keyed by type. 231 List of all rules currently being advertised. 233 @return list of all connections posted on hubs 234 @rtype list of gateway_msgs.msg.Rule 238 for connection_type
in utils.connection_types:
239 l.extend([connection.rule
for connection
in self.
public[connection_type]])
246 for connection_type
in utils.connection_types:
247 l.extend(self.
watchlist[connection_type])
254 for connection_type
in utils.connection_types:
255 l.extend(self.
blacklist[connection_type])
265 Match a given rule/rule against a given rule list 267 @param rules : the rules against which to match 268 @type dict of list of Rule objects 269 @param rule : the given rule/rule to match 271 @return the list of rules matched, None if no rules found 272 @rtype list of Rules || None 275 for r
in rules[rule.type]:
276 name_match_result = re.match(r.name, rule.name)
277 if name_match_result
and name_match_result.group() == rule.name:
279 node_match_result = re.match(r.node, rule.node)
280 if node_match_result
and node_match_result.group() == rule.node:
290 Determines whether a given rule should be allowed given the 291 status of the current watchlist and blacklist 293 @param rule : the given rule/rule to match 295 @return whether rule is allowed 307 if matched_rules
and not matched_blacklisted_rules:
313 Given a rule, determines if the rule is allowed. If it is 314 allowed, then returns the corresponding Rule object 316 @param rules : the given rules to match 318 @return The generated Rule if allowed, None if no match 325 def update(self, connections, generate_advertisement_connection_details):
327 Checks a list of rules and determines which ones should be 328 added/removed to the public interface. Modifies the public interface 329 accordingly, and returns the list of rules to the gateway for 332 @param rules: the list of rules available locally 333 @type dict of lists of Rule objects 335 @param generate_advertisement_connection_details : function from LocalMaster 336 that generates Connection.type_info and Connection.xmlrpc_uri 337 @type method (see LocalMaster.generate_advertisement_connection_details) 339 @return: new public connections, as well as connections to be removed 340 @rtype: utils.Connection[], utils.Connection[] 343 permitted_connections = utils.create_empty_connection_type_dictionary()
344 new_public = utils.create_empty_connection_type_dictionary()
345 removed_public = utils.create_empty_connection_type_dictionary()
346 for connection_type
in utils.connection_types:
347 for connection
in connections[connection_type]:
350 permitted_connections[connection_type].append(connection)
353 for connection_type
in utils.connection_types:
354 for connection
in permitted_connections[connection_type]:
355 if not connection.inConnectionList(self.
public[connection_type]):
356 new_connection = generate_advertisement_connection_details(
357 connection.rule.type, connection.rule.name, connection.rule.node)
360 if new_connection
is not None:
361 new_public[connection_type].append(new_connection)
362 self.
public[connection_type].append(new_connection)
364 removed_public[connection_type][:] = [
365 x
for x
in self.
public[connection_type]
if not x.inConnectionList(
366 permitted_connections[connection_type])]
367 self.
public[connection_type][:] = [
368 x
for x
in self.
public[connection_type]
if not x.inConnectionList(removed_public[connection_type])]
371 return new_public, removed_public
def publicRuleExists(public_rule, public_rules)
Functions.
def add_rule(self, rule)
Public Interfaces.
def remove_rule(self, rule)
def _allowRule(self, rule)
def advertise_all(self, blacklist)
def _generatePublic(self, rule)
def unadvertise_all(self)
def _matchAgainstRuleList(self, rules, rule)
Filter.
def update(self, connections, generate_advertisement_connection_details)
def __init__(self, default_rule_blacklist, default_rules)
def getConnections(self)
List Accessors.