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'
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'
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)