def start(self): from customer import supplier_connector from contacts import contactsdb for supplier_idurl in contactsdb.suppliers(): if supplier_idurl and not supplier_connector.by_idurl( supplier_idurl): supplier_connector.create(supplier_idurl) return True
def start(self): from contacts import contactsdb from crypt import my_keys from customer import supplier_connector from userid import my_id from logs import lg customer_key_id = my_id.getGlobalID(key_alias='customer') if not my_keys.is_key_registered(customer_key_id): lg.warn('customer key was not found, generate new key: %s' % customer_key_id) my_keys.generate_key(customer_key_id) for supplier_idurl in contactsdb.suppliers(): if supplier_idurl and not supplier_connector.by_idurl(supplier_idurl, customer_idurl=my_id.getLocalID()): supplier_connector.create(supplier_idurl, customer_idurl=my_id.getLocalID()) # TODO: read from dht and connect to other suppliers - from other customers who shared data to me return True
def doConnectSuppliers(self, *args, **kwargs): """ Action method. """ from customer import supplier_connector from p2p import online_status self.connect_list = [] my_current_family = contactsdb.suppliers() for pos, supplier_idurl in enumerate(my_current_family): if not supplier_idurl: continue if self.configs[0] and pos >= self.configs[0]: continue sc = supplier_connector.by_idurl(supplier_idurl) if sc is None: sc = supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=my_id.getIDURL(), ) else: sc.needed_bytes = None sc.do_calculate_needed_bytes() sc.set_callback('fire_hire', self._on_supplier_connector_state_changed) self.connect_list.append(supplier_idurl) sc.automat( 'connect', family_position=pos, ecc_map=eccmap.Current().name, family_snapshot=id_url.to_bin_list(my_current_family), ) online_status.add_online_status_listener_callback( idurl=supplier_idurl, callback_method=self._on_supplier_online_status_state_changed, )
def _do_connect_with_supplier(self, supplier_idurl): if _Debug: lg.args(_DebugLevel, supplier_idurl=supplier_idurl, customer_idurl=self.customer_idurl) sc = supplier_connector.by_idurl(supplier_idurl, customer_idurl=self.customer_idurl) if sc is None: sc = supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=self.customer_idurl, needed_bytes= 0, # we only want to read the data at the moment - requesting 0 bytes from the supplier key_id=self.key_id, queue_subscribe=False, ) if sc.state in [ 'CONNECTED', 'QUEUE?', ]: self.automat('supplier-connected', supplier_idurl) else: sc.set_callback('shared_access_coordinator', self._on_supplier_connector_state_changed) sc.automat('connect')
def doSupplierConnect(self, *args, **kwargs): """ Action method. """ from customer import supplier_connector from customer import fire_hire from raid import eccmap position = self.family_position if position is None or position == -1: lg.warn('position for new supplier is unknown, will "guess"') current_suppliers = list(contactsdb.suppliers()) for i in range(len(current_suppliers)): supplier_idurl = current_suppliers[i].to_bin() if not supplier_idurl: position = i break if id_url.is_in(supplier_idurl, fire_hire.A().dismiss_list, as_field=False): position = i break sc = supplier_connector.by_idurl(self.target_idurl) if not sc: sc = supplier_connector.create( supplier_idurl=self.target_idurl, customer_idurl=my_id.getIDURL(), ) sc.set_callback('supplier_finder', self._supplier_connector_state) sc.automat( 'connect', family_position=position, ecc_map=(self.ecc_map or eccmap.Current().name), family_snapshot=self.family_snapshot, )
def doConnectCustomerSuppliers(self, *args, **kwargs): """ Action method. """ try: self.known_suppliers_list = [ _f for _f in args[0]['suppliers'] if _f ] except: lg.exc() return self.known_ecc_map = args[0].get('ecc_map') for supplier_idurl in self.known_suppliers_list: sc = supplier_connector.by_idurl( supplier_idurl, customer_idurl=self.customer_idurl) if sc is None: sc = supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=self.customer_idurl, # we only want to read the data at the moment, # so requesting 0 bytes from that supplier needed_bytes=0, key_id=self.key_id, queue_subscribe=False, ) if sc.state in [ 'CONNECTED', 'QUEUE?', ]: self.automat('supplier-connected', supplier_idurl) else: sc.set_callback('shared_access_coordinator', self._on_supplier_connector_state_changed) sc.automat('connect')
def doSupplierConnect(self, *args, **kwargs): """ Action method. """ from customer import supplier_connector from customer import fire_hire from raid import eccmap position = self.family_position if not position: lg.warn('position for new supplier is unknown, will "guess"') current_suppliers = list(contactsdb.suppliers()) for i in range(len(current_suppliers)): if not current_suppliers[i].strip(): position = i break if current_suppliers[i] in fire_hire.A().dismiss_list: position = i break sc = supplier_connector.by_idurl(self.target_idurl) if not sc: sc = supplier_connector.create( supplier_idurl=self.target_idurl, customer_idurl=my_id.getLocalID(), ) sc.automat( 'connect', family_position=position, ecc_map=(self.ecc_map or eccmap.Current().name), family_snapshot=self.family_snapshot, ) sc.set_callback('supplier_finder', self._supplier_connector_state)
def doConnectSuppliers(self, *args, **kwargs): """ Action method. """ self.connect_list = [] my_current_family = list(contactsdb.suppliers()) for pos, supplier_idurl in enumerate(my_current_family): if not supplier_idurl: continue sc = supplier_connector.by_idurl(supplier_idurl) if sc is None: sc = supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=my_id.getLocalID(), ) sc.set_callback('fire_hire', self._on_supplier_connector_state_changed) self.connect_list.append(supplier_idurl) sc.automat( 'connect', family_position=pos, ecc_map=eccmap.Current().name, family_snapshot=my_current_family, ) supplier_contact_status = contact_status.getInstance( supplier_idurl) if supplier_contact_status: supplier_contact_status.addStateChangedCallback( self._on_supplier_contact_status_state_changed, newstate='OFFLINE', )
def start(self): from contacts import contactsdb from customer import supplier_connector from userid import my_id from main import events for _, supplier_idurl in enumerate(contactsdb.suppliers()): if supplier_idurl and not supplier_connector.by_idurl( supplier_idurl, customer_idurl=my_id.getLocalID()): supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=my_id.getLocalID(), ) events.add_subscriber(self._on_my_keys_synchronized, 'my-keys-synchronized') events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') # TODO: read from dht and connect to other suppliers - from other customers who shared data to me return True
def doSupplierConnect(self, arg): """ Action method. """ from customer import supplier_connector sc = supplier_connector.by_idurl(self.target_idurl) if not sc: sc = supplier_connector.create(self.target_idurl, customer_idurl=my_id.getLocalID()) sc.automat('connect') sc.set_callback('supplier_finder', self._supplier_connector_state)
def doConnectSuppliers(self, arg): """ Action method. """ self.connect_list = [] for supplier_idurl in contactsdb.suppliers(): if supplier_idurl == '': continue sc = supplier_connector.by_idurl(supplier_idurl) if sc is None: sc = supplier_connector.create(supplier_idurl) sc.set_callback('fire_hire', self._supplier_connector_state_changed) self.connect_list.append(supplier_idurl) sc.automat('connect')
def doConnectCustomerSuppliers(self, arg): """ Action method. """ self.suppliers_list.extend(filter(None, arg)) for supplier_idurl in self.suppliers_list: sc = supplier_connector.by_idurl( supplier_idurl, customer_idurl=self.customer_idurl) if sc is None: sc = supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=self.customer_idurl, # we only want to read the data at the moment, # so requesting 0 bytes from that supplier needed_bytes=0, ) sc.set_callback('shared_access_coordinator', self._on_supplier_connector_state_changed) sc.automat('connect')
def doConnectSuppliers(self, arg): """ Action method. """ self.connect_list = [] for supplier_idurl in contactsdb.suppliers(): if supplier_idurl == '': continue sc = supplier_connector.by_idurl(supplier_idurl) if sc is None: sc = supplier_connector.create(supplier_idurl) sc.set_callback('fire_hire', self._on_supplier_connector_state_changed) self.connect_list.append(supplier_idurl) sc.automat('connect') supplier_contact_status = contact_status.getInstance(supplier_idurl) if supplier_contact_status: supplier_contact_status.addStateChangedCallback( self._on_supplier_contact_status_state_changed, newstate='OFFLINE', )
def doConnectCustomerSuppliers(self, arg): """ Action method. """ self.known_suppliers_list = [_f for _f in arg if _f] for supplier_idurl in self.known_suppliers_list: sc = supplier_connector.by_idurl( supplier_idurl, customer_idurl=self.customer_idurl) if sc is None: sc = supplier_connector.create( supplier_idurl=supplier_idurl, customer_idurl=self.customer_idurl, # we only want to read the data at the moment, # so requesting 0 bytes from that supplier needed_bytes=0, key_id=self.key_id, queue_subscribe=False, ) sc.set_callback('shared_access_coordinator', self._on_supplier_connector_state_changed) sc.automat('connect')