Esempio n. 1
0
 def _do_open_known_shares(self):
     from crypt import my_keys
     from access import shared_access_coordinator
     from storage import backup_fs
     known_offline_shares = []
     for key_id in my_keys.known_keys():
         if not key_id.startswith('share_'):
             continue
         active_share = shared_access_coordinator.get_active_share(key_id)
         if active_share:
             continue
         known_offline_shares.append(key_id)
     to_be_opened = []
     for pathID, localPath, itemInfo in backup_fs.IterateIDs():
         if not itemInfo.key_id:
             continue
         if itemInfo.key_id in to_be_opened:
             continue
         if itemInfo.key_id not in known_offline_shares:
             continue
         to_be_opened.append(itemInfo.key_id)
     for key_id in to_be_opened:
         active_share = shared_access_coordinator.SharedAccessCoordinator(
             key_id,
             log_events=True,
             publish_events=False,
         )
         active_share.automat('restart')
Esempio n. 2
0
 def doInit(self, *args, **kwargs):
     """
     Action method.
     """
     self._do_block_rebuilding()
     self.known_suppliers = [
         _f
         for _f in contactsdb.suppliers(customer_idurl=self.customer_idurl)
         if _f
     ]
     if not self.EccMap:
         if self.customer_idurl == my_id.getIDURL():
             self.EccMap = eccmap.Current()
             lg.info('ECC map %r set from local for my own suppliers' %
                     self.EccMap)
     if not self.EccMap:
         known_eccmap_dict = {}
         for supplier_idurl in self.known_suppliers:
             known_ecc_map = contactsdb.get_supplier_meta_info(
                 supplier_idurl=supplier_idurl,
                 customer_idurl=self.customer_idurl,
             ).get('ecc_map', None)
             if known_ecc_map:
                 if known_ecc_map not in known_eccmap_dict:
                     known_eccmap_dict[known_ecc_map] = 0
                 known_eccmap_dict[known_ecc_map] += 1
         if known_eccmap_dict:
             all_known_eccmaps = list(known_eccmap_dict.items())
             all_known_eccmaps.sort(key=lambda i: i[1], reverse=True)
             self.EccMap = eccmap.eccmap(all_known_eccmaps[0][0])
             lg.info('ECC map %r recognized from suppliers meta info' %
                     self.EccMap)
         else:
             known_ecc_map = None
             if driver.is_on('service_shared_data'):
                 from access import shared_access_coordinator
                 active_share = shared_access_coordinator.get_active_share(
                     self.key_id)
                 if active_share:
                     known_ecc_map = active_share.known_ecc_map
             if known_ecc_map:
                 self.EccMap = eccmap.eccmap(known_ecc_map)
                 lg.info('ECC map %r recognized from active share %r' % (
                     self.EccMap,
                     active_share,
                 ))
             else:
                 num_suppliers = len(self.known_suppliers)
                 if num_suppliers not in eccmap.GetPossibleSuppliersCount():
                     num_suppliers = settings.DefaultDesiredSuppliers()
                 self.EccMap = eccmap.eccmap(
                     eccmap.GetEccMapName(num_suppliers))
                 lg.warn(
                     'no meta info found, guessed ECC map %r from %d known suppliers'
                     % (self.EccMap, len(self.known_suppliers)))
     self.max_errors = eccmap.GetCorrectableErrors(
         self.EccMap.NumSuppliers())
     if data_receiver.A():
         data_receiver.A().addStateChangedCallback(
             self._on_data_receiver_state_changed)
Esempio n. 3
0
 def _on_my_list_files_refreshed(self, evt):
     from access import shared_access_coordinator
     from customer import supplier_connector
     from p2p import p2p_service
     from p2p import commands
     for key_id in shared_access_coordinator.list_active_shares():
         cur_share = shared_access_coordinator.get_active_share(key_id)
         if not cur_share:
             continue
         if cur_share.state != 'CONNECTED':
             continue
         for supplier_idurl in cur_share.known_suppliers_list:
             sc = supplier_connector.by_idurl(
                 supplier_idurl,
                 customer_idurl=cur_share.customer_idurl,
             )
             if sc is not None and sc.state == 'CONNECTED':
                 p2p_service.SendListFiles(
                     target_supplier=supplier_idurl,
                     customer_idurl=cur_share.customer_idurl,
                     key_id=cur_share.key_id,
                     callbacks={
                         commands.Files():
                         lambda r, i: self._on_list_files_response(
                             r, i, cur_share.customer_idurl, supplier_idurl,
                             cur_share.key_id),
                         commands.Fail():
                         lambda r, i: self._on_list_files_failed(
                             r, i, cur_share.customer_idurl, supplier_idurl,
                             cur_share.key_id),
                     })
Esempio n. 4
0
 def _do_open_known_shares(self):
     from crypt import my_keys
     from main import listeners
     from access import shared_access_coordinator
     from storage import backup_fs
     known_offline_shares = []
     for key_id in my_keys.known_keys():
         if not key_id.startswith('share_'):
             continue
         active_share = shared_access_coordinator.get_active_share(key_id)
         if active_share:
             continue
         known_offline_shares.append(key_id)
     to_be_opened = []
     for _, _, itemInfo in backup_fs.IterateIDs():
         if not itemInfo.key_id:
             continue
         if itemInfo.key_id in to_be_opened:
             continue
         if itemInfo.key_id not in known_offline_shares:
             continue
         to_be_opened.append(itemInfo.key_id)
     for key_id in to_be_opened:
         active_share = shared_access_coordinator.SharedAccessCoordinator(key_id, log_events=True, publish_events=False, )
         active_share.automat('restart')
         if listeners.is_populate_requered('shared_file'):
             listeners.populate_later().remove('shared_file')
             backup_fs.populate_shared_files(key_id=key_id)
Esempio n. 5
0
 def _on_key_erased(self, evt):
     from access import shared_access_coordinator
     active_share = shared_access_coordinator.get_active_share(
         evt.data['key_id'])
     if active_share:
         active_share.automat('shutdown')