def _decodeCouples_ActorMemberGroup(self, actor, target, targettype): """ Sub routine for L{_decodeCouples}. """ from errorhandling import G4dsDependencyException retList = [] if actor == '*' or actor[0] == 'C' or actor[0] == 'S': # simple (independent group) actorlist = self._decodeGroup('membergroup', actor) targetlist = self._determineIndependantTargets(targettype, target) for a in actorlist: for t in targetlist: retList.append((a,t)) return retList elif actor == 'authorities_community': # check targets as well targetList = self._determineIndependantTargets(targettype, target) from communitymanager import getCommunityManager for cid in getCommunityManager().getCommunityIds(): c = getCommunityManager().getCommunity(cid) try: targetList.index(cid) for mid in c.getAuthorities(): retList.append((mid, cid)) except ValueError, msg: pass # alright, this community is not in our target list return retList
def _decodeGroup(self, type, wildcard): """ Processes wildcard information in one group. @param type: Type of role; either actor, action or target @type type: C{String} @param wildcard: Wildcard string as given in the XML description (most likely a star) @type wildcard: C{String} """ from errorhandling import G4dsDependencyException retList = [] if type == 'membergroup': from communitymanager import getMemberManager if wildcard == '*': # all members - easy stuff return getMemberManager().getMemberIds() elif wildcard[0] == 'C': # here we want all the members of a certain community from communitymanager import getCommunityManager return getCommunityManager().getCommunity(wildcard).getMembers() elif wildcard[0] == 'S': # all the members of a service from servicerepository import getServiceManager return getServiceManager().getService(wildcard).getMembers() elif type == 'communitygroup': from communitymanager import getCommunityManager if wildcard == '*': # that should be all communities then return getCommunityManager().getCommunityIds() elif type == 'servicegroup': from servicerepository import getServiceManager if wildcard == '*': # all the services here return getServiceManager().getServiceIds() else: raise G4dsDependencyException('Policy error - unknown group type "%s".' %(type)) return retList
def recalculateRoutingTable(self): """ Creates routing entries from the scratch by processing gateway information. The values for directly reachable communities are applied. Furthermore, communities, which may be reached through one community only (1 hop) are put into as well. The rest should be sorted out be the dynamic routing faciliites. """ numberOfEntries = 0 tmpList = [] # we have to maintain this list with new entries; just in case # the routing table was not flushed beforehand # first process directly reachable communities - cost = 1 from communitymanager import getMemberManager, getCommunityManager for communityid in getMemberManager().getLocalMember().getCommunityIds(): # everybody can route into its own community ...that's just important to pass it on to any gw within the community entry = RoutingTableEntry(None, communityid, communityid, getMemberManager().getLocalMember().getId(), communityid, 1) getRoutingTableManager().addEntry(entry) numberOfEntries += 1 tmpList.append(entry) # get all the gateways of the directly connected communities for communityid in getMemberManager().getLocalMember().getCommunityIds(): comm = getCommunityManager().getCommunity(communityid) for gw in comm.getSourceGateways(): # if it's myself, I can reach it directly (cost 1) if gw.getMemberId() == getMemberManager().getLocalMember().getId(): entry = RoutingTableEntry(None, communityid, gw.getDestinationCommunityId(), gw.getMemberId(), communityid, 1) getRoutingTableManager().addEntry(entry) numberOfEntries += 1 tmpList.append(entry) # now get all the entries with cost 2 # what do we do: We check the available entries with cost 1 and have a look, which (source) gateways are # available for them (for their destination gateway) for item in tmpList: srcTC = item.getDestinationTC() # the destination tc of the hop 1 entry will be the src tc of the hop 2 entry comm = getCommunityManager().getCommunity(srcTC) for gw in comm.getSourceGateways(): entry = RoutingTableEntry(None, item.getSourceTC(), gw.getDestinationCommunityId(), gw.getMemberId(), srcTC, 2) getRoutingTableManager().addEntry(entry) numberOfEntries += 1 from g4dslogging import getDefaultLogger, ROUTING_TABLE_UPDATED_MANUALLY getDefaultLogger().newMessage(ROUTING_TABLE_UPDATED_MANUALLY, 'Routing table recalculated - added %d entries.' %(numberOfEntries)) return numberOfEntries
def updateNow(self, timeout = 60): """ Performs the actual updating process. """ from g4dsconfigurationcontroller import getRoutingController from communitymanager import getMemberManager, getCommunityManager peerList = {} # the dict here is a bit chicky - but the simpliest way to avoid duplicates # get the ids of connected gateways and download their routing tables for communityid in getMemberManager().getLocalMember().getCommunityIds(): comm = getCommunityManager().getCommunity(communityid) for gw in comm.getSourceGateways(): if gw.getMemberId() != getMemberManager().getLocalMember().getId(): peerList[gw.getMemberId()] = None peerList = peerList.keys() for peerId in peerList: routesRemote = getRoutingController().downloadRoutingTable(peerId, timeout = timeout) from routingtablemanager import getRoutingTableManager import thread thread.start_new_thread(getRoutingTableManager().applyRoutingTableFromNode, (peerId, routesRemote)) from g4dslogging import getDefaultLogger, ROUTING_TABLE_UPDATED getDefaultLogger().newMessage(ROUTING_TABLE_UPDATED, 'Routing table updated')
def testCommunityManager(): cm = communitymanager.getCommunityManager() mm = communitymanager.getMemberManager() ## c = communitymanager.Community(None,"Community F","pas de comment","<tcdl/>","0.9.9","2005-06-28") ## m = communitymanager.Member(None, "Member F", "<mdl>Member F description file</mdl>","0.9.9", "2005-06-28") ## ## cm.addCommunity(c) ## mm.addMember(m) ## ## c2 = cm.getCommunity('C10001') ## ## c.addMember(m.getId()) ## m.addCommunity(c.getId()) ## c2.addMember(m.getId()) ## m.addCommunity(c2.getId()) ## c2.addAuthority(m.getId()) ## m.addAuthorityRole(c2.getId()) ## c.addAuthority(m.getId()) ## m.addAuthorityRole(c.getId()) ## communitymanager.CommunityGateway(m.getId(), c.getId(), c2.getId(), 1, 1) ## print cm, "\n", mm ## printCommunities() ## printMembers() ## print "" ## from communitymanager_db import CM_DB ## db = CM_DB() ## db.addProtocolToCommunity('C001', 'P906688') ## print db.getProtocolsForCommunity('C001') community = cm.getCommunity('C001') from communicationmanager import getProtocolManager ## prot = getProtocolManager().getProtocolByNameAndInsert('soap') ## community.addProtocol(prot.getId()) print community.getProtocols() from securitymanager import getAlgorithmManager alg = getAlgorithmManager().getAlgorithmByNameAndInsert('rsa') community.addAlgorithm(alg.getId()) print community.getAlgorithms()
def printCommunities(): for commid in communitymanager.getCommunityManager().getCommunityIds(): comm = communitymanager.getCommunityManager().getCommunity(commid) print comm
targetList = self._determineIndependantTargets(targettype, target) from communitymanager import getMemberManager for mid in getMemberManager().getMemberIds(): try: targetList.index(mid) retList.append((mid, mid)) except ValueError, msg: pass # ok, this is not in our target list return retList elif actor == 'gateways_community': # check targets as well targetList = self._determineIndependantTargets(targettype, target) # assemble list of all gateways gws = [] from communitymanager import getCommunityManager for cid in getCommunityManager().getCommunityIds(): for gw in getCommunityManager().getCommunity(cid).getSourceGateways(): gws.append(gw) for gw in gws: mid = gw.getMemberId() sid = gw.getSourceCommunityId() did = gw.getDestinationCommunityId() try: targetList.index(did) # we only check the dest tc here; the src is left to the user retList.append((mid, did)) except ValueError, msg: pass # alright, this dest tc is not in our target list return retList else: raise G4dsDependencyException('Policy error - unrecognised actor string (%s) for actor type "membergroup".' %(actor)) return retList