示例#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)
示例#2
0
    def dispatch(self, protocol, message):
        """
        Passes messages to the GlobalDispatcher in the messagehandler module.
        
        @param protocol: Name of the protocol, which has been identified as carrier for the message
        @type protocol: C{String}
        @param message: Message itself
        @type message: C{String}
        """
        from messagehandler import getGlobalDispatcher

        getGlobalDispatcher().dispatch(protocol, message)