def _do_save_customer_suppliers(id_cached_result, ret): if my_id.getIDURL() != id_url.field(ret['customer_idurl']): contactsdb.set_suppliers(ret['suppliers'], customer_idurl=ret['customer_idurl']) contactsdb.save_suppliers(customer_idurl=ret['customer_idurl']) if ret.get('ecc_map'): for supplier_idurl in ret['suppliers']: if supplier_idurl and id_url.is_cached(supplier_idurl): contactsdb.add_supplier_meta_info( supplier_idurl=supplier_idurl, info={ 'ecc_map': ret['ecc_map'], }, customer_idurl=ret['customer_idurl'], ) else: if _Debug: lg.out( _DebugLevel, 'dht_relations._do_save_customer_suppliers SKIP processing my own suppliers' ) if _Debug: lg.out( _DebugLevel, 'dht_relations._do_save_customer_suppliers OK for %r returned %d suppliers' % ( ret['customer_idurl'], len(ret['suppliers']), )) result.callback(ret) return ret
def write_customer_suppliers( customer_idurl, suppliers_list, ecc_map=None, revision=None, publisher_idurl=None, ): if customer_idurl == my_id.getLocalIDURL(): lg.warn( 'skip writing my own suppliers list which suppose to be written to DHT' ) else: contactsdb.set_suppliers(suppliers_list, customer_idurl=customer_idurl) contactsdb.save_suppliers(customer_idurl=customer_idurl) return dht_records.set_suppliers( customer_idurl=customer_idurl, suppliers_list=suppliers_list, ecc_map=ecc_map, revision=revision, publisher_idurl=publisher_idurl, )
def _do_verify(dht_value): try: _ecc_map = dht_value['ecc_map'] _customer_idurl = strng.to_bin(dht_value['customer_idurl']) _publisher_idurl = dht_value.get('publisher_idurl') _suppliers_list = list(map(strng.to_bin, dht_value['suppliers'])) _revision = dht_value.get('revision') _timestamp = dht_value.get('timestamp') except: lg.exc() result.callback(None) return None ret = { 'suppliers': _suppliers_list, 'ecc_map': _ecc_map, 'customer_idurl': _customer_idurl, 'revision': _revision, 'publisher_idurl': _publisher_idurl, 'timestamp': _timestamp, } if customer_idurl == my_id.getLocalIDURL(): if _Debug: lg.out( _DebugLevel, 'dht_relations.read_customer_suppliers skip caching my own suppliers list received from DHT: %s' % ret) else: contactsdb.set_suppliers(_suppliers_list, customer_idurl=customer_idurl) contactsdb.save_suppliers(customer_idurl=customer_idurl) if _Debug: lg.out( _DebugLevel, 'dht_relations.read_customer_suppliers %r returned %r' % ( customer_idurl, ret, )) result.callback(ret) return None
def _on_my_dht_relations_discovered(self, dht_result): if not (dht_result and isinstance(dht_result, dict) and len(dht_result.get('suppliers', [])) > 0): lg.warn('no dht records found for my customer family') self.automat('suppliers-read-failed') return dht_suppliers = id_url.to_bin_list(dht_result['suppliers']) dht_ecc_map = dht_result.get('ecc_map', settings.DefaultEccMapName()) try: dht_desired_suppliers_number = eccmap.GetEccMapSuppliersNumber( dht_ecc_map) except: lg.exc() dht_desired_suppliers_number = eccmap.GetEccMapSuppliersNumber( settings.DefaultEccMapName()) settings.config.conf().setInt('services/customer/suppliers-number', dht_desired_suppliers_number) contactsdb.set_suppliers(dht_suppliers) contactsdb.save_suppliers() lg.info('found and restored list of %d suppliers from DHT' % dht_desired_suppliers_number) self.automat('suppliers-read-ok')