def handle_hkey_type(hkey): if isinstance(hkey, int): hkey = guid_int_to_bts(hkey) return hkey elif isinstance(hkey, bytes): return hkey else: raise ValueError('ErtDHTSQLite: hkey should binary or int')
def to_host_port_dict(self): d = {} for bucket in self.buckets: for peer in bucket: if len(peer) == 4: host, port = peer[0], peer[1] host_port = '%s:%d' % (host, port) d[host_port] = (host, port, guid_int_to_bts(peer[2])) return d
def find_node(self, id, rpc_id, socket=None, peer_id=None, peer_info=None, lock=None): id_bts = kadmini_codec.guid_int_to_bts(id) rpc_id_bts = kadmini_codec.guid_int_to_bts(rpc_id) message = { "message_type": "find_node", "id": id_bts, "rpc_id": rpc_id_bts } self._sendmessage(message, socket, peer_id=peer_id, peer_info=peer_info, lock=lock)
def found_value(self, id, value, rpc_id, socket=None, peer_id=None, peer_info=None, lock=None): # print('SEND FOUND_VALUE') id_bts = kadmini_codec.guid_int_to_bts(id) rpc_id_bts = kadmini_codec.guid_int_to_bts(rpc_id) message = { "message_type": "found_value", "id": id_bts, "value": value, "rpc_id": rpc_id_bts } self._sendmessage(message, socket, peer_id=peer_id, peer_info=peer_info, lock=lock)
def store(self, key, value, socket=None, peer_id=None, peer_info=None, lock=None, signature=None): key_bts = kadmini_codec.guid_int_to_bts(key) message = {"message_type": "store", "id": key_bts, "value": value} if signature: message['signature'] = signature self._sendmessage(message, socket, peer_id=peer_id, peer_info=peer_info, lock=lock)
def insert(self, peer): if peer.id != self.id: bucket_number = largest_differing_bit(self.id, peer.id) peer_triple = peer.astriple() with self.lock: bucket = self.buckets[bucket_number] if peer_triple in bucket: bucket.pop(bucket.index(peer_triple)) elif len(bucket) >= self.bucket_size: bucket.pop(0) bucket.append(peer_triple) host = peer_triple[0] port = peer_triple[1] guid = peer_triple[2] host_port = '%s:%d' % (host, port) if host_port not in self.host_port__host_port_binguid: self.host_port__host_port_binguid[host_port] = ( host, port, guid_int_to_bts(guid)) self.host_port__host_port_hexguid[host_port] = ( host, port, guid_int_to_hex(guid))
dl = None try: ert_profile_ctl = main_profile( http_webdir=http_webdir, files_dir_name=config.static_files, cdn_host=boot_cdn_host, cdn_port=boot_cdn_port, shared_profile_instance_id=args.shared_profile_instance_id) ert = ert_profile_ctl if args.upnp_attempt: upnp.punch_port(udp_port, udp_port, args.if_name) hex_guid, bin_guid = ert_profile_ctl.rsa_guid_hex_bin int_guid = kadmini_codec.guid_bts_to_int(bin_guid) bts_2 = kadmini_codec.guid_int_to_bts(int_guid) hex2_guid = kadmini_codec.guid_int_to_hex(int_guid) assert hex2_guid == hex_guid # storage_handle = store_handler.DHTStoreHandlerOne( dht_sqlite_file=ert.dht_fb_fn, pubkeys_sqlite_file=ert.dht_ref_pubkeys_fn, ) # local_ip = upnp.get_my_ip() # todo from toolkit.tools import get_ip_address local_ip = get_ip_address(args.if_name) ip = local_ip ert_profile_ctl.my_wan_ip = ip