예제 #1
0
 def writable(self):
     try:
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             return self.want_write
         return AdvancedDispatcher.writable(self)
     except AttributeError:
         return AdvancedDispatcher.writable(self)
예제 #2
0
 def writable(self):
     try:
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             return self.want_write
         return AdvancedDispatcher.writable(self)
     except AttributeError:
         return AdvancedDispatcher.writable(self)
예제 #3
0
 def handle_write(self):  # pylint: disable=inconsistent-return-statements
     """
     Handle writes for sockets during TLS handshake. Requires special
     treatment as during the handshake, buffers must remain empty
     and normal writes must be ignored.
     """
     try:
         # wait for write buffer flush
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             # logger.debug(
             #    "%s:%i TLS handshaking (write)", self.destination.host,
             #        self.destination.port)
             self.tls_handshake()
         else:
             # logger.debug(
             #    "%s:%i Not TLS handshaking (write)", self.destination.host,
             #        self.destination.port)
             return AdvancedDispatcher.handle_write(self)
     except AttributeError:
         return AdvancedDispatcher.handle_write(self)
     except ssl.SSLError as err:
         if err.errno == ssl.SSL_ERROR_WANT_WRITE:
             return 0
         elif err.errno in _DISCONNECTED_SSL:
             self.handle_close()
             return 0
         logger.info("SSL Error: %s", str(err))
         self.handle_close()
         return
예제 #4
0
 def writable(self):
     """Handle writable checks for TLS-enabled sockets"""
     try:
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             return self.want_write
         return AdvancedDispatcher.writable(self)
     except AttributeError:
         return AdvancedDispatcher.writable(self)
예제 #5
0
 def __init__(self, host='127.0.0.1', port=8444):
     if not hasattr(self, '_map'):
         AdvancedDispatcher.__init__(self)
     self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
     self.set_reuse_addr()
     self.bind((host, port))
     self.destination = state.Peer(host, port)
     self.listen(5)
예제 #6
0
 def __init__(self, address=None, sock=None):
     # pylint: disable=unused-argument, super-init-not-called
     AdvancedDispatcher.__init__(self, sock)
     self.isOutbound = False
     # packet/connection from a local IP
     self.local = False
     self.pendingUpload = RandomTrackingDict()
     # canonical identifier of network group
     self.network_group = None
예제 #7
0
 def readable(self):
     try:
         # during TLS handshake, and after flushing write buffer, return status of last handshake attempt
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             #print "tls readable, %r" % (self.want_read)
             return self.want_read
         # prior to TLS handshake, receiveDataThread should emulate synchronous behaviour
         elif not self.fullyEstablished and (self.expectBytes == 0 or not self.write_buf_empty()):
             return False
         return AdvancedDispatcher.readable(self)
     except AttributeError:
         return AdvancedDispatcher.readable(self)
예제 #8
0
 def handle_close(self, reason=None):
     self.set_state("close")
     if reason is None:
         try:
             logger.debug("%s:%i: closing", self.destination.host,
                          self.destination.port)
         except AttributeError:
             logger.debug("Disconnected socket closing")
     else:
         logger.debug("%s:%i: closing, %s", self.destination.host,
                      self.destination.port, reason)
     AdvancedDispatcher.handle_close(self)
예제 #9
0
 def handle_close(self):
     self.set_state("close")
     if not (self.accepting or self.connecting or self.connected):
         # already disconnected
         return
     try:
         logger.debug("%s:%i: closing, %s", self.destination.host, self.destination.port, self.close_reason)
     except AttributeError:
         try:
             logger.debug("%s:%i: closing", self.destination.host, self.destination.port)
         except AttributeError:
             logger.debug("Disconnected socket closing")
     AdvancedDispatcher.handle_close(self)
예제 #10
0
 def handle_close(self):
     self.set_state("close")
     if not (self.accepting or self.connecting or self.connected):
         # already disconnected
         return
     try:
         logger.debug("%s:%i: closing, %s", self.destination.host, self.destination.port, self.close_reason)
     except AttributeError:
         try:
             logger.debug("%s:%i: closing", self.destination.host, self.destination.port)
         except AttributeError:
             logger.debug("Disconnected socket closing")
     AdvancedDispatcher.handle_close(self)
예제 #11
0
 def handle_connect(self):
     try:
         AdvancedDispatcher.handle_connect(self)
     except socket.error as e:
         if e.errno in asyncore._DISCONNECTED:
             logger.debug("%s:%i: Connection failed: %s" % (self.destination.host, self.destination.port, str(e)))
             return
     self.nodeid = randomBytes(8)
     self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
             network.connectionpool.BMConnectionPool().streams, False, nodeid=self.nodeid))
     #print "%s:%i: Sending version"  % (self.destination.host, self.destination.port)
     self.connectedAt = time.time()
     receiveDataQueue.put(self.destination)
예제 #12
0
 def readable(self):
     try:
         # during TLS handshake, and after flushing write buffer, return status of last handshake attempt
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             #print "tls readable, %r" % (self.want_read)
             return self.want_read
         # prior to TLS handshake, receiveDataThread should emulate synchronous behaviour
         elif not self.fullyEstablished and (self.expectBytes == 0
                                             or not self.write_buf_empty()):
             return False
         return AdvancedDispatcher.readable(self)
     except AttributeError:
         return AdvancedDispatcher.readable(self)
예제 #13
0
 def handle_connect(self):
     try:
         AdvancedDispatcher.handle_connect(self)
     except socket.error as e:
         if e.errno in asyncore._DISCONNECTED:
             logger.debug("%s:%i: Connection failed: %s" % (self.destination.host, self.destination.port, str(e)))
             return
     self.nodeid = randomBytes(8)
     self.append_write_buf(protocol.assembleVersionMessage(self.destination.host, self.destination.port, \
             network.connectionpool.BMConnectionPool().streams, False, nodeid=self.nodeid))
     #print "%s:%i: Sending version"  % (self.destination.host, self.destination.port)
     self.connectedAt = time.time()
     receiveDataQueue.put(self.destination)
예제 #14
0
 def handle_close(self):
     """Handle close"""
     self.set_state("close")
     if not (self.accepting or self.connecting or self.connected):
         # already disconnected
         return
     try:
         logger.debug('%s:%i: closing, %s', self.destination.host,
                      self.destination.port, self.close_reason)
     except AttributeError:
         try:
             logger.debug('%(host)s:%(port)i: closing',
                          self.destination._asdict())
         except AttributeError:
             logger.debug('Disconnected socket closing')
     AdvancedDispatcher.handle_close(self)
예제 #15
0
 def handle_connect(self):
     """Callback for TCP connection being established."""
     try:
         AdvancedDispatcher.handle_connect(self)
     except socket.error as e:
         # pylint: disable=protected-access
         if e.errno in asyncore._DISCONNECTED:
             logger.debug(
                 '%s:%i: Connection failed: %s',
                 self.destination.host, self.destination.port, e)
             return
     self.nodeid = randomBytes(8)
     self.append_write_buf(
         protocol.assembleVersionMessage(
             self.destination.host, self.destination.port,
             connectionpool.BMConnectionPool().streams,
             False, nodeid=self.nodeid))
     self.connectedAt = time.time()
     receiveDataQueue.put(self.destination)
예제 #16
0
 def handle_write(self):
     try:
         # wait for write buffer flush
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             #logger.debug("%s:%i TLS handshaking (write)", self.destination.host, self.destination.port)
             self.tls_handshake()
         else:
             #logger.debug("%s:%i Not TLS handshaking (write)", self.destination.host, self.destination.port)
             return AdvancedDispatcher.handle_write(self)
     except AttributeError:
         return AdvancedDispatcher.handle_write(self)
     except ssl.SSLError as err:
         if err.errno == ssl.SSL_ERROR_WANT_WRITE:
             return 0
         elif err.errno in _DISCONNECTED_SSL:
             self.handle_close()
             return 0
         logger.info("SSL Error: %s", str(err))
         self.handle_close()
         return
예제 #17
0
 def handle_read(self):
     try:
         # wait for write buffer flush
         if self.tlsStarted and not self.tlsDone and not self.write_buf:
             #logger.debug("%s:%i TLS handshaking (read)", self.destination.host, self.destination.port)
             self.tls_handshake()
         else:
             #logger.debug("%s:%i Not TLS handshaking (read)", self.destination.host, self.destination.port)
             return AdvancedDispatcher.handle_read(self)
     except AttributeError:
         return AdvancedDispatcher.handle_read(self)
     except ssl.SSLError as err:
         if err.errno == ssl.SSL_ERROR_WANT_READ:
             return
         elif err.errno in _DISCONNECTED_SSL:
             self.handle_close()
             return
         logger.info("SSL Error: %s", str(err))
         self.handle_close()
         return
예제 #18
0
 def __init__(self, host='127.0.0.1', port=8444):
     if not hasattr(self, '_map'):
         AdvancedDispatcher.__init__(self)
     self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
     self.set_reuse_addr()
     for attempt in range(50):
         try:
             if attempt > 0:
                 port = random.randint(32767, 65535)
             self.bind((host, port))
         except socket.error as e:
             if e.errno in (asyncore.EADDRINUSE, asyncore.WSAEADDRINUSE):
                 continue
         else:
             if attempt > 0:
                 BMConfigParser().set("bitmessagesettings", "port", str(port))
                 BMConfigParser().save()
             break
     self.destination = state.Peer(host, port)
     self.bound = True
     self.listen(5)
예제 #19
0
 def __init__(self, host='127.0.0.1', port=8444):
     if not hasattr(self, '_map'):
         AdvancedDispatcher.__init__(self)
     self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
     self.set_reuse_addr()
     for attempt in range(50):
         try:
             if attempt > 0:
                 port = random.randint(32767, 65535)
             self.bind((host, port))
         except socket.error as e:
             if e.errno in (asyncore.EADDRINUSE, asyncore.WSAEADDRINUSE):
                 continue
         else:
             if attempt > 0:
                 BMConfigParser().set("bitmessagesettings", "port", str(port))
                 BMConfigParser().save()
             break
     self.destination = state.Peer(host, port)
     self.bound = True
     self.listen(5)
예제 #20
0
 def __init__(self, address=None, sock=None):
     AdvancedDispatcher.__init__(self, sock)
     self.isOutbound = False
     # packet/connection from a local IP
     self.local = False
     self.pendingUpload = RandomTrackingDict()
예제 #21
0
 def __init__(self, address=None, sock=None):
     AdvancedDispatcher.__init__(self, sock)
     self.isOutbound = False
예제 #22
0
 def __init__(self, address=None, sock=None):
     AdvancedDispatcher.__init__(self, sock)
     self.isOutbound = False
     # packet/connection from a local IP
     self.local = False
예제 #23
0
 def __init__(self, address=None, sock=None):
     AdvancedDispatcher.__init__(self, sock)
     self.isOutbound = False
     # packet/connection from a local IP
     self.local = False