예제 #1
0
 def broadcast(self,tx):
     tx=tx.decode('hex')
     tx_hash=protocol.dhash(tx) #need to hash here
     # we only broadcast if tx is new 
     if tx_hash not in self.broadcast_tx_dict:
         self.broadcast_tx_dict[tx_hash]=tx
         data =  protocol.pack_var_int(1) 
         data += struct.pack('<I32s',1,tx_hash) #MSG_TX
         self._send_packet('inv',data)
         return True
         # we will receive getdata (make sure we have hash) 
         # and process_data will call _send_tx when inv message 
         # received 
     return False
예제 #2
0
 def broadcast(self,tx):
     tx=tx.decode('hex')
     tx_hash=protocol.dhash(tx) #need to hash here
     # we only broadcast if tx is new 
     if tx_hash not in self.broadcast_tx_dict:
         self.broadcast_tx_dict[tx_hash]=tx
         data =  protocol.pack_var_int(1) 
         data += struct.pack('<I32s',1,tx_hash) #MSG_TX
         self._send_packet('inv',data)
         return True
         # we will receive getdata (make sure we have hash) 
         # and process_data will call _send_tx when inv message 
         # received 
     return False
예제 #3
0
 def _send_packet(self,command, payload):
     lc = len(command)
     assert (lc < 12)
     cmd = command + ('\x00' * (12 - lc))
     h = protocol.dhash (payload)
     checksum, = struct.unpack ('<I', h[:4])
     packet = struct.pack ('<4s12sII',
         self.msg_magic_bytes,cmd,len(payload),checksum) + payload
     try:
         self.my_socket.send (packet)
     except IOError as e:
         print("Send packet I/O error({0}): {1}".format(e.errno, e.strerror))
         return False
     return True
예제 #4
0
 def _send_packet(self, command, payload):
     lc = len(command)
     assert (lc < 12)
     cmd = command + ('\x00' * (12 - lc))
     h = protocol.dhash (payload)
     checksum, = struct.unpack ('<I', h[:4])
     packet = struct.pack ('<4s12sII',
         self.msg_magic_bytes,cmd,len(payload),checksum) + payload
     try:
         self.my_socket.send(packet)
     except IOError as e:
         logging.warn("Send packet to {0} I/O error({1}): {2}".format(self.address,e.errno, e.strerror))
         return False
     return True