コード例 #1
0
    def start(self):
        from logs import lg
        from main import events
        from contacts import contactsdb
        from supplier import family_member
        from transport import callback
        # TODO: check all imports.! my_id must be loaded latest as possible!
        from userid import my_id
        
        callback.append_inbox_callback(self._on_inbox_packet_received)
        
        for customer_idurl in contactsdb.customers():
            if not customer_idurl:
                continue
            if customer_idurl == my_id.getLocalIDURL():
                lg.warn('skipping my own identity')
                continue
            fm = family_member.by_customer_idurl(customer_idurl)
            if not fm:
                fm = family_member.create_family(customer_idurl)
            fm.automat('init')
            local_customer_meta_info = contactsdb.get_customer_meta_info(customer_idurl)
            fm.automat('family-join', {
                'supplier_idurl': my_id.getLocalIDURL(),
                'ecc_map': local_customer_meta_info.get('ecc_map'),
                'position': local_customer_meta_info.get('position', -1),
                'family_snapshot': local_customer_meta_info.get('family_snapshot'),
            })

        events.add_subscriber(self._on_existing_customer_accepted, 'existing-customer-accepted')
        events.add_subscriber(self._on_new_customer_accepted, 'new-customer-accepted')
        events.add_subscriber(self._on_existing_customer_terminated, 'existing-customer-terminated')
        return True
コード例 #2
0
 def _on_new_customer_accepted(self, evt):
     from logs import lg
     from userid import my_id
     from supplier import family_member
     customer_idurl = evt.data['idurl']
     fm = family_member.by_customer_idurl(customer_idurl)
     if not fm:
         fm = family_member.create_family(customer_idurl)
         fm.automat('init')
     else:
         lg.warn('family_member() instance already exists, but new customer just accepted %s' % customer_idurl)
     fm.automat('family-join', {
         'supplier_idurl': my_id.getLocalIDURL(),
         'ecc_map': evt.data.get('ecc_map'),
         'position': evt.data.get('position', -1),
         'family_snapshot': evt.data.get('family_snapshot'),
     })
コード例 #3
0
 def _on_new_customer_accepted(self, evt):
     from twisted.internet import reactor  # @UnresolvedImport
     from logs import lg
     from userid import my_id
     from userid import id_url
     from supplier import family_member
     customer_idurl = evt.data['idurl']
     fm = family_member.by_customer_idurl(customer_idurl)
     if not fm:
         fm = family_member.create_family(customer_idurl)
         fm.automat('init')
     else:
         lg.warn(
             'family_member() instance already exists, but new customer just accepted %s'
             % customer_idurl)
     reactor.callLater(0, fm.automat, 'family-join', {  # @UndefinedVariable
         'supplier_idurl': my_id.getLocalID().to_bin(),
         'ecc_map': evt.data.get('ecc_map'),
         'position': evt.data.get('position', -1),
         'family_snapshot': id_url.to_bin_list(evt.data.get('family_snapshot')),
     })
コード例 #4
0
 def start(self):
     from twisted.internet import reactor  # @UnresolvedImport
     from logs import lg
     from main import events
     from contacts import contactsdb
     from userid import id_url
     from supplier import family_member
     from transport import callback
     from userid import my_id
     callback.append_inbox_callback(self._on_inbox_packet_received)
     for customer_idurl in contactsdb.customers():
         if not customer_idurl:
             continue
         if not id_url.is_cached(customer_idurl):
             continue
         if customer_idurl == my_id.getLocalID():
             lg.warn('skipping my own identity')
             continue
         fm = family_member.by_customer_idurl(customer_idurl)
         if not fm:
             fm = family_member.create_family(customer_idurl)
         fm.automat('init')
         local_customer_meta_info = contactsdb.get_customer_meta_info(
             customer_idurl)
         reactor.callLater(0, fm.automat, 'family-join', {  # @UndefinedVariable
             'supplier_idurl': my_id.getLocalID().to_bin(),
             'ecc_map': local_customer_meta_info.get('ecc_map'),
             'position': local_customer_meta_info.get('position', -1),
             'family_snapshot': id_url.to_bin_list(local_customer_meta_info.get('family_snapshot')),
         })
     events.add_subscriber(self._on_identity_url_changed,
                           'identity-url-changed')
     events.add_subscriber(self._on_existing_customer_accepted,
                           'existing-customer-accepted')
     events.add_subscriber(self._on_new_customer_accepted,
                           'new-customer-accepted')
     events.add_subscriber(self._on_existing_customer_terminated,
                           'existing-customer-terminated')
     return True