Пример #1
0
 def doRequestService(self, arg):
     """
     Action method.
     """
     service_info = {
         'needed_bytes': self.needed_bytes,
         'customer_id': global_id.UrlToGlobalID(self.customer_idurl),
     }
     my_customer_key_id = my_id.getGlobalID(key_alias='customer')
     if my_keys.is_key_registered(my_customer_key_id):
         service_info['customer_public_key'] = my_keys.get_key_info(
             key_id=my_customer_key_id,
             include_private=False,
         )
     if self.key_id:
         service_info['key_id'] = self.key_id
     if self.customer_idurl == my_id.getLocalIDURL():
         service_info['ecc_map'] = eccmap.Current().name
     request = p2p_service.SendRequestService(
         remote_idurl=self.supplier_idurl,
         service_name='service_supplier',
         json_payload=service_info,
         callbacks={
             commands.Ack(): self._supplier_acked,
             commands.Fail(): self._supplier_failed,
         },
     )
     self.request_packet_id = request.PacketID
Пример #2
0
 def _do_prepare_service_request_params(self,
                                        possible_broker_idurl,
                                        desired_broker_position=-1,
                                        action='queue-connect'):
     queue_id = global_id.MakeGlobalQueueID(
         queue_alias=self.group_queue_alias,
         owner_id=self.group_creator_id,
         supplier_id=global_id.idurl2glob(possible_broker_idurl),
     )
     group_key_info = my_keys.get_key_info(self.group_key_id,
                                           include_private=False,
                                           include_signature=True)
     service_request_params = {
         'action':
         action,
         'queue_id':
         queue_id,
         'consumer_id':
         self.member_id,
         'producer_id':
         self.member_id,
         'group_key':
         group_key_info,
         'last_sequence_id':
         self.last_sequence_id,
         'archive_folder_path':
         groups.get_archive_folder_path(self.group_key_id),
     }
     if desired_broker_position >= 0:
         service_request_params['position'] = desired_broker_position
     if _Debug:
         lg.args(_DebugLevel, service_request_params=service_request_params)
     return service_request_params
Пример #3
0
 def doRequestService(self, *args, **kwargs):
     """
     Action method.
     """
     service_info = {
         'needed_bytes': self.needed_bytes,
         'customer_id': global_id.UrlToGlobalID(self.customer_idurl),
     }
     my_customer_key_id = my_id.getGlobalID(key_alias='customer')
     if my_keys.is_key_registered(my_customer_key_id):
         service_info['customer_public_key'] = my_keys.get_key_info(
             key_id=my_customer_key_id,
             include_private=False,
         )
     if self.key_id:
         service_info['key_id'] = self.key_id
     self._last_known_ecc_map = kwargs.get('ecc_map')
     if self._last_known_ecc_map is not None:
         service_info['ecc_map'] = self._last_known_ecc_map
     self._last_known_family_position = kwargs.get('family_position')
     if self._last_known_family_position is not None:
         service_info['position'] = self._last_known_family_position
     self._last_known_family_snapshot = kwargs.get('family_snapshot')
     if self._last_known_family_snapshot is not None:
         service_info['family_snapshot'] = self._last_known_family_snapshot
     request = p2p_service.SendRequestService(
         remote_idurl=self.supplier_idurl,
         service_name='service_supplier',
         json_payload=service_info,
         callbacks={
             commands.Ack(): self._supplier_acked,
             commands.Fail(): self._supplier_failed,
         },
     )
     self.request_packet_id = request.PacketID
Пример #4
0
 def doCancelService(self, *args, **kwargs):
     """
     Action method.
     """
     service_info = {}
     my_customer_key_id = my_id.getGlobalID(key_alias='customer')
     if my_keys.is_key_registered(my_customer_key_id):
         service_info['customer_public_key'] = my_keys.get_key_info(
             key_id=my_customer_key_id,
             include_private=False,
             include_signature=False,
             generate_signature=False,
         )
     ecc_map = kwargs.get('ecc_map')
     if ecc_map:
         service_info['ecc_map'] = ecc_map
     request = p2p_service.SendCancelService(
         remote_idurl=self.supplier_idurl,
         service_name='service_supplier',
         json_payload=service_info,
         callbacks={
             commands.Ack(): self._supplier_service_acked,
             commands.Fail(): self._supplier_service_failed,
         },
     )
     self.request_packet_id = request.PacketID
Пример #5
0
 def _do_request_supplier_service(self, ecc_map, family_position,
                                  family_snapshot):
     if _Debug:
         lg.args(_DebugLevel,
                 supplier_idurl=self.supplier_idurl,
                 ecc_map=ecc_map,
                 family_position=family_position,
                 family_snapshot=family_snapshot)
     if not self.supplier_idurl:
         lg.warn(
             'supplier idurl is empty, SKIP sending supplier_service request'
         )
         return
     service_info = {
         'needed_bytes': self.needed_bytes,
         'customer_id': global_id.UrlToGlobalID(self.customer_idurl),
     }
     my_customer_key_id = my_id.getGlobalID(key_alias='customer')
     if my_keys.is_key_registered(my_customer_key_id):
         service_info['customer_public_key'] = my_keys.get_key_info(
             key_id=my_customer_key_id,
             include_private=False,
             include_signature=True,
             generate_signature=True,
         )
     else:
         lg.warn('my own customer key is not registered: %r' %
                 my_customer_key_id)
     if self.key_id:
         service_info['key_id'] = self.key_id
     self._last_known_ecc_map = ecc_map
     if self._last_known_ecc_map is not None:
         service_info['ecc_map'] = self._last_known_ecc_map
     self._last_known_family_position = family_position
     if self._last_known_family_position is not None:
         service_info['position'] = self._last_known_family_position
     self._last_known_family_snapshot = family_snapshot
     if self._last_known_family_snapshot is not None:
         service_info['family_snapshot'] = id_url.to_bin_list(
             self._last_known_family_snapshot)
     request = p2p_service.SendRequestService(
         remote_idurl=self.supplier_idurl,
         service_name='service_supplier',
         json_payload=service_info,
         callbacks={
             commands.Ack(): self._supplier_service_acked,
             commands.Fail(): self._supplier_service_failed,
         },
     )
     self.request_packet_id = request.PacketID
Пример #6
0
 def _on_my_dht_relations_discovered(self, dht_result):
     from p2p import p2p_service
     from contacts import contactsdb
     from userid import my_id
     from userid import id_url
     from crypt import my_keys
     from logs import lg
     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')
         return
     if id_url.is_some_empty(contactsdb.suppliers()):
         lg.warn(
             'some of my suppliers are not hired yet, skip doing any changes'
         )
         return
     suppliers_to_be_dismissed = set()
     dht_suppliers = id_url.to_bin_list(dht_result['suppliers'])
     # clean up old suppliers
     for idurl in dht_suppliers:
         if not idurl:
             continue
         if not contactsdb.is_supplier(idurl):
             lg.warn('dht relation with %r is not valid anymore' % idurl)
             suppliers_to_be_dismissed.add(idurl)
     for supplier_idurl in suppliers_to_be_dismissed:
         service_info = {}
         my_customer_key_id = my_id.getGlobalID(key_alias='customer')
         if my_keys.is_key_registered(my_customer_key_id):
             service_info['customer_public_key'] = my_keys.get_key_info(
                 key_id=my_customer_key_id,
                 include_private=False,
                 include_signature=False,
                 generate_signature=False,
             )
         p2p_service.SendCancelService(
             remote_idurl=supplier_idurl,
             service_name='service_supplier',
             json_payload=service_info,
         )
     if suppliers_to_be_dismissed:
         lg.info(
             'found %d suppliers to be cleaned and sent CancelService() packets'
             % len(suppliers_to_be_dismissed))
Пример #7
0
    def test_signed_key(self):
        try:
            bpio.rmdir_recursive('/tmp/.bitdust_test_signed_key')
        except Exception:
            pass
        lg.set_debug_level(30)
        settings.init(base_dir='/tmp/.bitdust_test_signed_key')
        self.my_current_key = None
        try:
            os.makedirs('/tmp/.bitdust_test_signed_key/metadata/')
        except:
            pass
        fout = open('/tmp/_some_priv_key', 'w')
        fout.write(_some_priv_key)
        fout.close()
        fout = open(settings.LocalIdentityFilename(), 'w')
        fout.write(_some_identity_xml)
        fout.close()
        self.assertTrue(key.LoadMyKey(keyfilename='/tmp/_some_priv_key'))
        self.assertTrue(my_id.loadLocalIdentity())

        key_id = '[email protected]_8084'
        my_keys.erase_key(key_id, keys_folder='/tmp/')
        my_keys.register_key(key_id, _sample_private_key, keys_folder='/tmp/')
        is_valid = my_keys.validate_key(my_keys.key_obj(key_id))
        self.assertTrue(is_valid)
        my_keys.sign_key(key_id)
        signed_key_info = my_keys.get_key_info(key_id,
                                               include_private=True,
                                               include_signature=True)
        self.assertTrue(my_keys.verify_key_info_signature(signed_key_info))

        key.ForgetMyKey()
        my_id.forgetLocalIdentity()
        settings.shutdown()
        os.remove('/tmp/_some_priv_key')
        bpio.rmdir_recursive('/tmp/.bitdust_test_signed_key')
Пример #8
0
 def doRequestService(self, arg):
     """
     Action method.
     """
     service_info = {
         'needed_bytes': self.needed_bytes,
     }
     try:
         service_info['customer_public_key'] = my_keys.get_key_info(
             key_id=customer_state.customer_key_id(),
             include_private=False,
         )
     except:
         pass
     request = p2p_service.SendRequestService(
         remote_idurl=self.supplier_idurl,
         service_name='service_supplier',
         json_payload=service_info,
         callbacks={
             commands.Ack(): self._supplier_acked,
             commands.Fail(): self._supplier_failed,
         },
     )
     self.request_packet_id = request.PacketID