Ejemplo n.º 1
0
 def fire(self, eventtype, **attrs):
     if (eventtype in self.listeners):
         e = Event()
         e.source = self
         for k, v in attrs.iteritems():
             setattr(e, k, v)
         for fn in self.listeners[eventtype]:
             reactor.call(fn, e)
Ejemplo n.º 2
0
 def set_error(self, exc):
     self.completed = True
     self.success = False
     self.error = exc
     if self.callback:
         reactor.call(self.callback, *self.callback_args, error=self.error, result=self.result)
     else:
         print self.error
Ejemplo n.º 3
0
 def fire(self, eventtype, **attrs):
     if (eventtype in self.listeners):
         e = Event()
         e.source = self
         for k, v in attrs.iteritems():
             setattr(e, k, v)
         for fn in self.listeners[eventtype]:
             reactor.call(fn, e)
Ejemplo n.º 4
0
 def set_result(self, result):
     self.completed = True
     self.success = True
     self.result = result
     if self.callback:
         reactor.call(self.callback,
                      *self.callback_args,
                      error=self.error,
                      result=self.result)
Ejemplo n.º 5
0
 def set_error(self, exc):
     self.completed = True
     self.success = False
     self.error = exc
     if self.callback:
         reactor.call(self.callback,
                      *self.callback_args,
                      error=self.error,
                      result=self.result)
     else:
         print self.error
Ejemplo n.º 6
0
 def __init__(self, node, bootstrapper, addr_pool, min_addrpool_size=10):
     self.bootstrapper = bootstrapper
     self.addr_pool = addr_pool
     self.min_addrpool_size = min_addrpool_size
     self.bootstrapper.subscribe(self.bootstrapper.EVT_FOUND_PEER, self.on_bootstrapped_peer)
 
     self.node = node
     self.node.subscribe((VersionExchangeService.EVT_MESSAGE, MSG_ADDR), self.on_addr)
     self.node.subscribe(VersionExchangeService.EVT_VERSION_EXCHANGED, self.on_version_exchanged)
     self.node.subscribe(Node.EVT_DISCONNECTED, self.on_disconnected)
     
     reactor.call(self.check_addrpool)
Ejemplo n.º 7
0
 def _process_incomming_buffer(self):
     cursor = 0
     #while cursor < len(self.incommingbuffer):
     try:
         msg, cursor = self.msg_serializer.deserialize(self.incommingbuffer, cursor)
     except MissingDataException:
         #print traceback.format_exc()
         #self.log.warning("Read Incomplete")
         #print "cursor = %d:%s" % (cursor, traceback.format_exc())
         return
     self.incommingbuffer = self.incommingbuffer[cursor:]
     self.fire(self.EVT_NEW_MESSAGE, handler=self, message=msg)
     #self.on_message(msg)
     #call again for the rest of the message
     reactor.call(self._process_incomming_buffer)
Ejemplo n.º 8
0
 def _process_incomming_buffer(self):
     cursor = 0
     # while cursor < len(self.incommingbuffer):
     try:
         msg, cursor = self.msg_serializer.deserialize(self.incommingbuffer, cursor)
     except MissingDataException:
         # print traceback.format_exc()
         # self.log.warning("Read Incomplete")
         # print "cursor = %d:%s" % (cursor, traceback.format_exc())
         return
     self.incommingbuffer = self.incommingbuffer[cursor:]
     self.fire(self.EVT_NEW_MESSAGE, handler=self, message=msg)
     # self.on_message(msg)
     # call again for the rest of the message
     reactor.call(self._process_incomming_buffer)
Ejemplo n.º 9
0
    def __init__(self, node, bootstrapper, addr_pool, min_addrpool_size=10):
        self.bootstrapper = bootstrapper
        self.addr_pool = addr_pool
        self.min_addrpool_size = min_addrpool_size
        self.bootstrapper.subscribe(self.bootstrapper.EVT_FOUND_PEER,
                                    self.on_bootstrapped_peer)

        self.node = node
        self.node.subscribe((VersionExchangeService.EVT_MESSAGE, MSG_ADDR),
                            self.on_addr)
        self.node.subscribe(VersionExchangeService.EVT_VERSION_EXCHANGED,
                            self.on_version_exchanged)
        self.node.subscribe(Node.EVT_DISCONNECTED, self.on_disconnected)

        reactor.call(self.check_addrpool)
Ejemplo n.º 10
0
def process_coroutines(gen, future, result=None, error=None):
    """
    Note: in case of error, the error contains "(exception, traceback_string)"
    """
    try:
        if error:
            exc, tbstr = error
            result = gen.throw(exc)
        else:
            result = gen.send(result)
    except StopIteration as e:
        future.set_result(result)
        return
    except Exception as e:
        print traceback.format_exc()
        future.set_error( (e, traceback.format_exc()) )
        return
    if type(result) is Future:
        result.set_callback(process_coroutines, (gen, future))
    else:
        reactor.call(process_coroutines, gen, future, result=result)
Ejemplo n.º 11
0
def process_coroutines(gen, future, result=None, error=None):
    """
    Note: in case of error, the error contains "(exception, traceback_string)"
    """
    try:
        if error:
            exc, tbstr = error
            result = gen.throw(exc)
        else:
            result = gen.send(result)
    except StopIteration as e:
        future.set_result(result)
        return
    except Exception as e:
        print traceback.format_exc()
        future.set_error((e, traceback.format_exc()))
        return
    if type(result) is Future:
        result.set_callback(process_coroutines, (gen, future))
    else:
        reactor.call(process_coroutines, gen, future, result=result)
Ejemplo n.º 12
0
 def get_passphrase(self):
     reactor.call(self.open)
     self.future = Future()
     return self.future
Ejemplo n.º 13
0
 def new_method(*args):
     future = Future()
     gen = method(*args)
     reactor.call(process_coroutines, gen, future)
     return future
Ejemplo n.º 14
0
 def set_result(self, result):
     self.completed = True
     self.success = True
     self.result = result
     if self.callback:
         reactor.call(self.callback, *self.callback_args, error=self.error, result=self.result)
Ejemplo n.º 15
0
 def new_method(*args):
     future = Future()
     gen = method(*args)
     reactor.call(process_coroutines, gen, future)
     return future
Ejemplo n.º 16
0
 def get_passphrase(self):
     reactor.call(self.open)
     self.future = Future()
     return self.future