'A function to convert peer_info libtorrent object into dictionary
This data is used to identify peers with combination of several flags'

@staticmethod
def create_peerlist_data(peer_info):

    peer_dict = {'id': peer_info.pid.to_bytes().encode('hex'), 'extended_version': peer_info.client, 'ip': peer_info.ip[0], 'port': peer_info.ip[1], 'optimistic': bool((peer_info.flags & 2048)), 'direction': ('L' if bool((peer_info.flags & peer_info.local_connection)) else 'R'), 'uprate': peer_info.payload_up_speed, 'uinterested': bool((peer_info.flags & peer_info.remote_interested)), 'uchoked': bool((peer_info.flags & peer_info.remote_choked)), 'uhasqueries': (peer_info.upload_queue_length > 0), 'uflushed': (peer_info.used_send_buffer > 0), 'downrate': peer_info.payload_down_speed, 'dinterested': bool((peer_info.flags & peer_info.interesting)), 'dchoked': bool((peer_info.flags & peer_info.choked)), 'snubbed': bool((peer_info.flags & 4096)), 'utotal': peer_info.total_upload, 'dtotal': peer_info.total_download, 'completed': peer_info.progress, 'have': peer_info.pieces, 'speed': peer_info.remote_dl_rate, 'country': peer_info.country, 'connection_type': peer_info.connection_type, 'seed': bool((peer_info.flags & peer_info.seed)), 'upload_only': bool((peer_info.flags & peer_info.upload_only)), 'rstate': peer_info.read_state, 'wstate': peer_info.write_state}
    return peer_dict
