9982-getdata 1 import logging
9982-getdata 2 import time
9982-getdata 3 import hashlib
9982-getdata 4 import binascii
9982-getdata 5 from message import Message
9982-getdata 6 from message import BROADCAST
9982-getdata 7
9982-getdata 8
9982-getdata 9 class Broadcast(Message):
9982-getdata 10 def __init__(self, message, state):
9982-getdata 11 message['command'] = BROADCAST
9982-getdata 12 message['bounces'] = 0
9982-getdata 13 super(Broadcast, self).__init__(message, state)
9982-getdata 14
9982-getdata 15 def send(self):
9982-getdata 16 if not self.speaker:
9982-getdata 17 logging.error("aborting message send due speaker not being set")
9982-getdata 18 return
9982-getdata 19
9982-getdata 20
9982-getdata 21 self.timestamp = int(time.time())
9982-getdata 22
9982-getdata 23 target_peer = None
9982-getdata 24
9982-getdata 25 self.message_bytes = self.get_message_bytes(target_peer)
9982-getdata 26 self.message_hash = hashlib.sha256(self.message_bytes).digest()
9982-getdata 27
9982-getdata 28 self.long_buffer.intern(self)
9982-getdata 29
9982-getdata 30 self.state.update_broadcast_self_chain(self.message_hash)
9982-getdata 31 self.state.update_net_chain(self.message_hash)
9982-getdata 32 for peer in self.state.get_keyed_peers(exclude_addressless=True):
9982-getdata 33 signed_packet_bytes = self.pack(peer, self.command, self.bounces, self.message_bytes)
9982-getdata 34 peer.send(signed_packet_bytes)
9982-getdata 35 self.log_outgoing(peer)
9982-getdata 36
9982-getdata 37
9982-getdata 38 def retry(self, requesting_peer):
9982-getdata 39 signed_packet_bytes = self.pack(requesting_peer, self.command, self.bounces, self.message_bytes)
9982-getdata 40 requesting_peer.send(signed_packet_bytes)
9982-getdata 41 self.log_outgoing(requesting_peer)
9982-getdata 42
9982-getdata 43 def forward(self):
9982-getdata 44 if not self.speaker:
9982-getdata 45 logging.error("aborting message send due speaker not being set")
9982-getdata 46 return
9982-getdata 47
9982-getdata 48 reporting_peer_ids = map(lambda p: p.peer_id, self.reporting_peers)
9982-getdata 49 for peer in self.state.get_keyed_peers(exclude_addressless=True, exclude_ids=reporting_peer_ids):
9982-getdata 50
9982-getdata 51 if self.peer and (peer.peer_id == self.peer.peer_id):
9982-getdata 52 continue
9982-getdata 53
9982-getdata 54 signed_packet_bytes = Message.pack(peer, self.command, self.bounces, self.message_bytes)
9982-getdata 55 peer.send(signed_packet_bytes)
9982-getdata 56 self.log_outgoing(peer)