Beispiel #1
0
    def dispatch(self, message, incomingmessageid):
        """
        Unwrappes the message and tries to deliver directly, or if not possible through another routing hop.
        """
##        print "\tRouting Dispatcher: Received something to pass on."
        from g4dslogging import getDefaultLogger, COMMUNICATION_INCOMING_MSG_DETAILS
        getDefaultLogger().newMessage(COMMUNICATION_INCOMING_MSG_DETAILS, '-- Control Msg - SS: Routing Engine')

        from messagewrapper import getControlMessageWrapper
        action, sucess, args, unwrapped = getControlMessageWrapper().unwrapSSRoutingMessage(message)
        destination = args['destination']
        protocol = args['protocol']
        community = args['community']

        from authorisationcontroller import getAuthorisationController
        from messagehandler import getMessageContextController
        sourceCommunity = getMessageContextController().getValue(incomingmessageid, 'communityid')
##        # let's check, whether the sender of this message is allowed to route into the community
##        if not getAuthorisationController().validate(getMessageContextController().getValue(incomingmessageid, 'senderid'), 
##            sourceCommunity, 'g4ds.routing.route'):
##            return
        
        from communitymanager import getMemberManager
        # check first, whether we are the final receipient
        if getMemberManager().getLocalMember().getId() == destination:
            # great stuff - pass it to the global dispatcher
            from messagehandler import getGlobalDispatcher
            getGlobalDispatcher().dispatch(protocol, unwrapped)
        else:
            args = {}
            args['destination'] = destination
            args['protocol'] = protocol
            args['community'] = community
            from messagewrapper import getControlMessageWrapper
            wrapped, doc, element = getControlMessageWrapper().wrapSSRoutingMessage('1', args = args, data = unwrapped)
            from g4dsconfigurationcontroller import getOutgoingControlMessagesHandler, CONTROL_ROUTER
            # check, whether we can reach the dest community directly
            try:
                getMemberManager().getLocalMember().getCommunityIds().index(community)
                # great to know; but are we allowed this action?
                if not getAuthorisationController().validate(getMemberManager().getLocalMember().getId(), community, 'g4ds.routing.route'):
                    raise ValueError('I am in the dest community; but I am not allowed to route into it. Let us try to find somebody else.')
                # unfortunately, we can only check the dest tc with the access control - let's check for scr / dest combination additionally
                for gw in getMemberManager().getLocalMember().getGateways():
                    if gw.getSourceCommunityId() == sourceCommunity and gw.getDestinationCommunityId() == community:
                        getOutgoingControlMessagesHandler().sendMessage(destination, CONTROL_ROUTER, "Routing message", wrapped, communityid = community)
                raise ValueError('I am in the dest community; but I am not allowed to route into it. Let us try to find somebody else.')
            except ValueError, msg:
                # ok - looks like we can only pass it on to the next hop
                gateway_member_id, peercommunity, hops = getRoutingTableManager().getNexthopForCommunity(community)
                # are we allowed this action then?
                if not getAuthorisationController().validate(getMemberManager().getLocalMember().getId(), peercommunity, 'g4ds.routing.route'):
                    return
                # ah, fair enough - is it also allowed for the combination src TC / dst TC?
                for gw in getMemberManager().getLocalMember().getGateways():
                    if gw.getSourceCommunityId() == sourceCommunity and gw.getDestinationCommunityId() == peercommunity:
                        getOutgoingControlMessagesHandler().sendMessage(gateway_member_id, CONTROL_ROUTER, "Routing message", wrapped, communityid = peercommunity)
Beispiel #2
0
def testFullCommunication():
    from messagehandler import getGlobalOutgoingMessageHandler
    outgoing = getGlobalOutgoingMessageHandler()

    from serviceintegrator import getServiceIntegrator
    getServiceIntegrator().sendMessage("M854612", "S10001", "IOIDS", "<ioids>test it app</ioids>")
    import g4dsconfigurationcontroller
    g4dsconfigurationcontroller.getOutgoingControlMessagesHandler().sendMessage(
    "M854612", g4dsconfigurationcontroller.CONTROL_SUBSYSTEM_MEMBERS, 
        "Member managing", "<routing><gateway><add>bla</add></gateway></routing>")
    
    g4dsconfigurationcontroller.getOutgoingControlMessagesHandler().sendMessage(
    "M854612", g4dsconfigurationcontroller.CONTROL_ROUTER, 
        "Forward message", "<routing><gateway><add>bla</add></gateway></routing>")
    # just for testing purpose the old version, where we directly connect to the global outing message handler and we
    # have to define an endpoint. Actually, the service integrator should be used and only a member id should be 
    # provided. Endpoints are assembled automatically.
    #outgoing.sendServiceMessage("E393454", "S10002", "PLAIN TEST",  "plain old logging :)")      # "E770313"
    raw_input("waiting :)")
Beispiel #3
0
    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)