示例#1
0
    def __init__(self, updates, sender=None, recipients=None):
        """
        Constructor
        """
        if not recipients:
            recipients = connections.getNeighbors()
        super(GossipNetworkStatusMessage, self).__init__(
            updates, sender, recipients)

        self._gossipttl = config.GOSSIPTTL
        self._code = 'G'
示例#2
0
    def __init__(self, updates, sender=None, recipients=None):
        """
        Constructor
        """
        if not recipients:
            recipients = connections.getNeighbors()
        super(GossipNetworkStatusMessage,
              self).__init__(updates, sender, recipients)

        self._gossipttl = config.GOSSIPTTL
        self._code = 'G'
示例#3
0
    def gossip(self):
        """
        Gossip procedure. This is basic. Hope to improve later.
        """
        if connections.connectToNeighbors():
            debug("Connections in process. deferred gossip", info=True)
            return

        # Get my neighbors
        recipients = connections.getNeighbors()

        if len(recipients) > 0:
            shortids = []
            for uid in recipients:
                shortids.append(connections.lookupNode(uid).getShortUid())
            debug("Gossipping with: [ " + " ][ ".join(shortids) + " ]", 
                info=True)
        else:
            debug("No neighbors to gossip with this interval.", 
                error=True, threshold=1)
            return

        # Put all messages in a list.
        gossipMessages = []

        # Get a vector clock message
        vcMessage = message.VectorMessage.createVectorClockMessage()
        vcMessage.setRecipients(recipients)
        gossipMessages.append(vcMessage)

        # Put in each aggreggation. Tae out for now.

        for aggName in aggregation.STATISTICS:
            agg = aggregation.STATISTICS[aggName]
            aggMessage = message.AggregateMessage.createAggregateMessage(agg)
            aggMessage.setRecipients(recipients)
            gossipMessages.append(aggMessage)
        """
        agg = random.choice(aggregation.STATISTICS.values())      
        aggMessage = message.AggregateMessage.createAggregateMessage(agg)
        aggMessage.setRecipients(recipients)
        gossipMessages.append(aggMessage)
        """
        # Get a network message
        gossipmsg = gossipPrepare()
        while gossipmsg:
            gossipmsg.setRecipients(recipients)
            toAppend = copy.deepcopy(gossipmsg)
            gossipMessages.append(toAppend)
            gossipmsg = gossipPrepare()

        debug("There are " \
            + str(len(gossipMessages)) + " to send.", threshold=2, info=True)

        # Send out the messages
        for msg in gossipMessages:
            try:
                msg.send()
            except ConnectionError as ce:
                debug(ce.__str__(), error=True)
            except GeneralError as ge:
                debug(ge.__str__(), error=True)
示例#4
0
文件: gossip.py 项目: magicbill/Hiss
    def gossip(self):
        """
        Gossip procedure. This is basic. Hope to improve later.
        """
        if connections.connectToNeighbors():
            debug("Connections in process. deferred gossip", info=True)
            return

        # Get my neighbors
        recipients = connections.getNeighbors()

        if len(recipients) > 0:
            shortids = []
            for uid in recipients:
                shortids.append(connections.lookupNode(uid).getShortUid())
            debug("Gossipping with: [ " + " ][ ".join(shortids) + " ]",
                  info=True)
        else:
            debug("No neighbors to gossip with this interval.",
                  error=True,
                  threshold=1)
            return

        # Put all messages in a list.
        gossipMessages = []

        # Get a vector clock message
        vcMessage = message.VectorMessage.createVectorClockMessage()
        vcMessage.setRecipients(recipients)
        gossipMessages.append(vcMessage)

        # Put in each aggreggation. Tae out for now.

        for aggName in aggregation.STATISTICS:
            agg = aggregation.STATISTICS[aggName]
            aggMessage = message.AggregateMessage.createAggregateMessage(agg)
            aggMessage.setRecipients(recipients)
            gossipMessages.append(aggMessage)
        """
        agg = random.choice(aggregation.STATISTICS.values())      
        aggMessage = message.AggregateMessage.createAggregateMessage(agg)
        aggMessage.setRecipients(recipients)
        gossipMessages.append(aggMessage)
        """
        # Get a network message
        gossipmsg = gossipPrepare()
        while gossipmsg:
            gossipmsg.setRecipients(recipients)
            toAppend = copy.deepcopy(gossipmsg)
            gossipMessages.append(toAppend)
            gossipmsg = gossipPrepare()

        debug("There are " \
            + str(len(gossipMessages)) + " to send.", threshold=2, info=True)

        # Send out the messages
        for msg in gossipMessages:
            try:
                msg.send()
            except ConnectionError as ce:
                debug(ce.__str__(), error=True)
            except GeneralError as ge:
                debug(ge.__str__(), error=True)