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 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))
def testTcp(): from protocolcontroller import getProtocolController tcp = getProtocolController().getOpenProtocol('tcpsocket') print (tcp.sendMessage('192.168.1.120:2000', 'h'*50000)) raw_input()
_finishActionLine() except G4dsException, msg: _finishActionLine(SUCESS_NEG) _printAction(2, str(msg)) _finishActionLine(SUCESS_NEG) _printAction(1, "Loading Keys") from algorithmcontroller import getAlgorithmController getAlgorithmController().loadKeys() # initialise with their private keys from the personal credential manager _finishActionLine() _printAction(1, "Start up protocols and listeners") from protocolcontroller import getProtocolController import socket try: getProtocolController() # start listening on all endpoints _finishActionLine() except socket.error, msg: _finishActionLine(SUCESS_NEG) _printAction(2, str(msg)) _finishActionLine(SUCESS_NEG) _printAction(1, "Load up permission policies into memory") from authorisationcontroller import getAuthorisationController ## getAuthorisationController() try: getAuthorisationController() # start listening on all endpoints _finishActionLine() ## except Exception, msg: except KeyError, msg: _finishActionLine(SUCESS_NEG)