def installEndPoints(i, localMemberId, tcId): """ Add the local endpoints as defined in the config file in the protocols folder. """ _printAction (i, "Initialise protocols and their endpoints", 1) from protocolcontroller import getProtocolController from communicationmanager import getProtocolManager from communicationmanager import Protocol from communicationmanager import getEndpointManager from communicationmanager import Endpoint from protocols.config import endpoints # these are actually addesses, not really endpoints from securitymanager import getCredentialManager from securitymanager import getAlgorithmManager for protocolName in getProtocolController().getOpenProtocols(): _printAction (i+1, "Add Protocol '" + protocolName + "'") ## protocol = Protocol(None, protocolName) ## getProtocolManager().addProtocol(protocol) protocol = getProtocolManager().getProtocolByNameAndInsert(protocolName) _finishActionLine() _printAction (i+1, "Add Endpoints for protocol '" + protocolName + "'", 1) address = endpoints[protocolName] for credential in getCredentialManager().getCredentialsForMember(localMemberId): algName = getAlgorithmManager().getAlgorithm(credential.getAlgorithmId()).getName() _printAction (i+2, "Add Endpoint for protocol '" + protocolName + "' and Algorithm '" + algName + "'") endpoint = Endpoint (None, localMemberId, tcId, protocol.getId(), address, credential.getId()) getEndpointManager().addEndpoint(endpoint) _finishActionLine() _printAction (i, "Finished protocols and endpoints") _finishActionLine()
def testCommunicationManager(): protMan = communicationmanager.getProtocolManager() print protMan prot1 = protMan.getProtocols()[0] print prot1 endpMan = communicationmanager.getEndpointManager() print endpMan endp1 = endpMan.getEndpoints()[0] print endp1
def testUpdatingAndDeletingOnManager(): from communitymanager import getMemberManager, Member from communicationmanager import getEndpointManager, Endpoint, getProtocolManager from securitymanager import getCredentialManager, Credential, getAlgorithmManager m = Member('123','kk test', '<mdl/>','1.0.0.0','2005-07-08') #m.addCommunity('C760394') getMemberManager().updateMember(m, 1) alg = getAlgorithmManager().getAlgorithmByNameAndInsert('nikos alg') getEndpointManager().removeEndpointsForMember(m.getId()) c = Credential(None, alg.getId(),'','key5','123') getCredentialManager().removeCredentialsForMember(m.getId()) getCredentialManager().addCredential(c) protocol = getProtocolManager().getProtocolByNameAndInsert('soap') e = Endpoint(None, '123', 'C426009', protocol.getId(), 'http://localhost', c.getId()) getEndpointManager().addEndpoint(e)
def _assembleRoutingMessage(self, message, endpoint): final_destination = endpoint.getMemberId() community = endpoint.getCommunityId() from communicationmanager import getProtocolManager protocolname = getProtocolManager().getProtocol(endpoint.getProtocolId()).getName() gateway_member_id, peercommunity, hops = getRoutingTableManager().getNexthopForCommunity(endpoint.getCommunityId()) args = {} args['destination'] = final_destination args['protocol'] = protocolname args['community'] = community from messagewrapper import getControlMessageWrapper wrapped, tmp, tmp1 = getControlMessageWrapper().wrapSSRoutingMessage('1', args = args, data = message) from g4dslogging import getDefaultLogger, COMMUNICATION_OUTGOING_MSG_DETAILS getDefaultLogger().newMessage(COMMUNICATION_OUTGOING_MSG_DETAILS, '-- Routing details: Gateway (%s | %s)' %(gateway_member_id, peercommunity)) getDefaultLogger().newMessage(COMMUNICATION_OUTGOING_MSG_DETAILS, '-- Size of Data %d chars' %(len(message))) from g4dsconfigurationcontroller import getOutgoingControlMessagesHandler, CONTROL_ROUTER getOutgoingControlMessagesHandler().sendMessage(gateway_member_id, CONTROL_ROUTER, "Routing message", wrapped, communityid = peercommunity)
def sendMessage(self, message, endpoint): """ Tries to deliver a message directly, if impossible via wrapping into routing message. All messages should be passed here and not be sent from anywhere else. The routing engine looks, whether the given endpoint may be reached directly from the local node. If this is possible, the message is sent off directly. If, however, this is not possible, the message is wrapped into a routing message and gateways are tried to identify for passing the message through the topology. """ # check, whether I am in the community of the given endpoint, if not - we need to attempt to route this message tc = endpoint.getCommunityId() from communitymanager import getMemberManager local = getMemberManager().getLocalMember() ## try: ## local.getCommunityIds().index(tc) from communicationmanager import getProtocolManager, getEndpointManager if len(getEndpointManager().getEndpointsForMember(local.getId(), tc)): from g4dslogging import getDefaultLogger, COMMUNICATION_OUTGOING_MSG, COMMUNICATION_OUTGOING_MSG_DETAILS getDefaultLogger().newMessage(COMMUNICATION_OUTGOING_MSG, 'New outgoing message - direct delivery (%s | %s)' %(endpoint.getMemberId(), tc)) getDefaultLogger().newMessage(COMMUNICATION_OUTGOING_MSG_DETAILS, '-- Endpoint %s' %(str(endpoint))) getDefaultLogger().newMessage(COMMUNICATION_OUTGOING_MSG_DETAILS, '-- Size of Data %d chars' %(len(message))) protocol = getProtocolManager().getProtocol(endpoint.getProtocolId()) from protocolcontroller import getProtocolController protocol = getProtocolController().getOpenProtocol(protocol.getName()) from socket import error from errorhandling import G4dsCommunicationException try: protocol.sendMessage(endpoint.getAddress(), message) except error, msg: raise G4dsCommunicationException('Sending Message: %s' %(msg))