def doRestoreMyIdentity(self, arg):
     """
     Action method.
     """
     modified = my_id.rebuildLocalIdentity()
     if not modified:
         lg.warn('my identity was not modified')
     config.conf().setData('services/proxy-transport/my-original-identity', '') 
 def doModifyMyIdentity(self, arg):
     """
     Action method.
     """
     config.conf().setData('services/proxy-transport/my-original-identity', 
                           my_id.getLocalIdentity().serialize())
     modified = my_id.rebuildLocalIdentity()
     if not modified:
         lg.warn('my identity was not modified')
 def _reset_my_original_identity(self):
     from userid import my_id
     from main.config import conf
     conf().setData('services/proxy-transport/my-original-identity', '')
     conf().setString('services/proxy-transport/current-router', '')
     my_id.rebuildLocalIdentity()
示例#4
0
 def doRebuildMyIdentity(self, *args, **kwargs):
     """
     Action method.
     """
     min_servers = max(
         settings.MinimumIdentitySources(),
         config.conf().getInt('services/identity-propagate/min-servers') or settings.MinimumIdentitySources(),
     )
     max_servers = min(
         settings.MaximumIdentitySources(),
         config.conf().getInt('services/identity-propagate/max-servers') or settings.MaximumIdentitySources(),
     )
     current_sources = my_id.getLocalIdentity().getSources(as_originals=True)
     current_contacts = list(my_id.getLocalIdentity().getContacts())
     new_sources = []
     new_idurl = strng.to_bin(args[0])
     if _Debug:
         lg.args(_DebugLevel, current_sources=current_sources, alive_idurls=self.alive_idurls, new_idurl=new_idurl, )
     # first get rid of "dead" sources
     for current_idurl in current_sources:
         if current_idurl not in self.alive_idurls:
             continue
         if strng.to_bin(current_idurl) in new_sources:
             continue
         new_sources.append(strng.to_bin(current_idurl))
     if self.force and len(new_sources) == len(current_sources):
         # do not increase number of identity sources, only rotate them
         new_sources.pop(0)
     # and add new "good" source to the end of the list
     if new_idurl and new_idurl not in new_sources:
         new_sources.append(new_idurl)
     if _Debug:
         lg.args(_DebugLevel, new_sources=new_sources, min_servers=min_servers, max_servers=max_servers)
     if len(new_sources) > max_servers:
         all_new_sources = list(new_sources)
         new_sources = new_sources[max(0, len(new_sources) - max_servers):]
         lg.warn('skip %d identity sources, require maximum %d sources' % (
             len(all_new_sources)-len(new_sources), max_servers, ))
     if len(new_sources) < min_servers:
         additional_sources = self.possible_sources[:min_servers-len(new_sources)]
         if additional_sources:
             lg.warn('additional sources to be used: %r' % additional_sources)
             new_sources.extend(additional_sources)
     unique_sources = []
     for idurl_bin in new_sources:
         if strng.to_bin(idurl_bin) not in unique_sources:
             unique_sources.append(strng.to_bin(idurl_bin))
     if len(unique_sources) < min_servers:
         lg.warn('not enough identity sources, need to rotate again')
         self.automat('need-more-sources')
         return
     contacts_changed = False
     id_changed = my_id.rebuildLocalIdentity(
         new_sources=unique_sources,
         new_revision=self.new_revision,
     )
     new_contacts = my_id.getLocalIdentity().getContacts()
     if len(current_contacts) != len(new_contacts):
         contacts_changed = True
     if not contacts_changed:
         for pos in range(len(current_contacts)):
             if current_contacts[pos] != new_contacts[pos]:
                 contacts_changed = True
                 break
     self.rotated = True
     if _Debug:
         lg.args(_DebugLevel, new_sources=new_sources, contacts_changed=contacts_changed, id_changed=id_changed)
     self.automat('my-id-updated', (contacts_changed, id_changed))