def _outbox_packet_sent(self, pkt_out): from p2p import commands from contacts import contactsdb from supplier import customer_assistant if pkt_out.outpacket.Command == commands.Identity(): if contactsdb.is_customer(pkt_out.outpacket.RemoteID): ca = customer_assistant.by_idurl(pkt_out.outpacket.RemoteID) if ca: ca.automat('propagate', pkt_out)
def _on_inbox_packet_received(self, newpacket, info, status, error_message): from p2p import commands from contacts import contactsdb from supplier import customer_assistant if newpacket.Command in [commands.Ack(), commands.Fail()]: if contactsdb.is_customer(newpacket.OwnerID): ca = customer_assistant.by_idurl(newpacket.OwnerID) if ca: ca.automat(newpacket.Command.lower(), newpacket) return True return False
def start(self): from supplier import customer_assistant from contacts import contactsdb from transport import callback for customer_idurl in contactsdb.customers(): if customer_idurl and not customer_assistant.by_idurl(customer_idurl): ca = customer_assistant.create(customer_idurl) ca.automat('init') callback.add_outbox_callback(self._on_outbox_packet_sent) callback.append_inbox_callback(self._on_inbox_packet_received) return True
def _on_outbox_packet_sent(self, pkt_out): from twisted.internet import reactor # @UnresolvedImport from p2p import commands from contacts import contactsdb from supplier import customer_assistant if pkt_out.outpacket.Command == commands.Identity(): if contactsdb.is_customer(pkt_out.outpacket.RemoteID): ca = customer_assistant.by_idurl(pkt_out.outpacket.RemoteID) if ca: reactor.callLater(0, ca.automat, 'propagate', pkt_out) # @UndefinedVariable return False
def _on_inbox_packet_received(self, newpacket, info, status, error_message): from twisted.internet import reactor # @UnresolvedImport from p2p import commands from contacts import contactsdb from supplier import customer_assistant if newpacket.Command in [commands.Ack(), commands.Fail()]: if contactsdb.is_customer(newpacket.OwnerID): ca = customer_assistant.by_idurl(newpacket.OwnerID) if ca: reactor.callLater(0, ca.automat, newpacket.Command.lower(), newpacket) # @UndefinedVariable return True return False
def start(self): from twisted.internet import reactor # @UnresolvedImport from userid import id_url from main import events from supplier import customer_assistant from contacts import contactsdb from transport import callback for customer_idurl in contactsdb.customers(): if id_url.is_cached(customer_idurl): if customer_idurl and not customer_assistant.by_idurl( customer_idurl): ca = customer_assistant.create(customer_idurl) reactor.callLater(0, ca.automat, 'init') # @UndefinedVariable events.add_subscriber(self._on_identity_url_changed, 'identity-url-changed') callback.add_outbox_callback(self._on_outbox_packet_sent) callback.append_inbox_callback(self._on_inbox_packet_received) return True