Esempio n. 1
0
    def _process_reject(self,data):
        payload = protocol.get_payload(data)
        varint_tuple = protocol.read_var_int(payload)

        size_message = varint_tuple[0]
        varint_size = varint_tuple[1]
        message_rejected = payload[varint_size:varint_size+size_message]
        code = struct.unpack('B',payload[varint_size+size_message:varint_size+size_message+1])[0]
        
        payload = payload[varint_size+size_message+1:]

        varint_tuple = protocol.read_var_int(payload)
        size_reason = varint_tuple[0]
        varint_size=varint_tuple[1]
        reason = payload[varint_size:varint_size+size_reason]
        data = payload[varint_size+size_reason:]

        if message_rejected == 'tx':
            pass

        msg='{} rejected, reason: {}, code: {}, data: {}'.format(message_rejected,reason,code,data)
        logging.error(msg)      
Esempio n. 2
0
 def _process_addr(self,data):
     payload         =   protocol.get_payload(data)
     varint_tuple    =   protocol.read_var_int(payload)
     num_ips         =   varint_tuple[0]
     varint_size     =   varint_tuple[1]
     ip_data         =   payload[varint_size:] 
     for i in range(0,num_ips):
         begin_index=i*30
         end_index=begin_index+30
         timestamp = struct.unpack('<I',ip_data[begin_index:begin_index+4])[0]
         services = struct.unpack('<Q',ip_data[begin_index+4:begin_index+12])[0]
         ipv6= struct.unpack('16c',ip_data[begin_index+12:begin_index+28])[0]
         ipv4= struct.unpack('4c',ip_data[begin_index+24:begin_index+28])[0]
         port=struct.unpack('!H',ip_data[begin_index+28:begin_index+30])[0]
         self.peer_address_list.append(socket.inet_ntop(socket.AF_INET,ip_data[begin_index+24:begin_index+28])) 
Esempio n. 3
0
 def _process_inv(self,data):
     payload         =   protocol.get_payload(data)
     varint_tuple    =   protocol.read_var_int(payload)
     num_invs        =   varint_tuple[0]
     varint_size     =   varint_tuple[1]
     inv_data        =   payload[varint_size:]
     for i in range(0,num_invs):
         begin_index=i*36
         end_index=begin_index+36
         inv_type = struct.unpack('<I',inv_data[begin_index:begin_index+4])[0]
         inv_hash = struct.unpack('32c',inv_data[begin_index+4:begin_index+36])
         if(inv_type ==0):#error
             pass
         elif(inv_type==1):#tx
             self._process_inv_tx(inv_hash)
         elif(inv_type==2):#block
             self._process_inv_block(inv_hash)
         else:
             print("unknown inv")
Esempio n. 4
0
 def _process_inv(self,data):
     payload         =   protocol.get_payload(data)
     varint_tuple    =   protocol.read_var_int(payload)
     num_invs        =   varint_tuple[0]
     varint_size     =   varint_tuple[1]
     inv_data        =   payload[varint_size:]
     for i in range(0,num_invs):
         begin_index=i*36
         end_index=begin_index+36
         inv_type = struct.unpack('<I',inv_data[begin_index:begin_index+4])[0]
         inv_hash = struct.unpack('32c',inv_data[begin_index+4:begin_index+36])
         if not protocol.is_valid_inv_type(inv_type,self.crypto):
             logging.error("unknown inv {} found".format(inv_type))
         if inv_type == 1:#tx
             self._process_inv_tx(inv_hash)
         elif inv_type == 2:#block
             self._process_inv_block(inv_hash)
         elif inv_type == 3:#filtered block
             pass
Esempio n. 5
0
 def _process_get_data(self,data):
     payload         =   protocol.get_payload(data)
     varint_tuple    =   protocol.read_var_int(payload)
     num_invs        =   varint_tuple[0]
     varint_size     =   varint_tuple[1]
     inv_data        =   payload[varint_size:]         
     for i in range(0,num_invs):
         begin_index=i*36
         end_index=begin_index+36
         inv_type = struct.unpack('<I',inv_data[begin_index:begin_index+4])[0]
         inv_hash = struct.unpack('32c',inv_data[begin_index+4:begin_index+36])
         if(inv_type ==0):#error
             pass
         elif(inv_type==1):#tx
             tx_hash=''.join(inv_hash) #convert tuple to string
             self._send_tx(tx_hash)
         elif(inv_type==2):#block
             pass 
         else:
             logging.error("unknown inv {} found".format(inv_type))