def handle_read(self): TLSDispatcher.handle_read(self) if self.isOutbound and self.fullyEstablished: for s in self.streams: try: with knownnodes.knownNodesLock: knownnodes.knownNodes[s][self.destination]["lastseen"] = time.time() except KeyError: pass receiveDataQueue.put(self.destination)
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)
def handle_read(self): try: (recdata, addr) = self.socket.recvfrom(self._buf_len) except socket.error as e: logger.error("socket error: %s", e) return self.destination = Peer(*addr) encodedAddr = protocol.encodeHost(addr[0]) self.local = bool(protocol.checkIPAddress(encodedAddr, True)) # overwrite the old buffer to avoid mixing data and so that # self.local works correctly self.read_buf[0:] = recdata self.bm_proto_reset() receiveDataQueue.put(self.listening)
def tls_handshake(self): """Perform TLS handshake and handle its stages""" # wait for flush if self.write_buf: return False # Perform the handshake. try: # print "handshaking (internal)" self.sslSocket.do_handshake() except ssl.SSLError as err: # print "%s:%i: handshake fail" % ( # self.destination.host, self.destination.port) self.want_read = self.want_write = False if err.args[0] == ssl.SSL_ERROR_WANT_READ: # print "want read" self.want_read = True if err.args[0] == ssl.SSL_ERROR_WANT_WRITE: # print "want write" self.want_write = True if not (self.want_write or self.want_read): raise except socket.error as err: # pylint: disable=protected-access if err.errno in asyncore._DISCONNECTED: self.handle_close() else: raise else: if sys.version_info >= (2, 7, 9): self.tlsVersion = self.sslSocket.version() logger.debug( '%s:%i: TLS handshake success, TLS protocol version: %s', self.destination.host, self.destination.port, self.tlsVersion) else: self.tlsVersion = "TLSv1" logger.debug('%s:%i: TLS handshake success', self.destination.host, self.destination.port) # The handshake has completed, so remove this channel and... self.del_channel() self.set_socket(self.sslSocket) self.tlsDone = True self.bm_proto_reset() self.set_state("connection_fully_established") receiveDataQueue.put(self.destination) return False
def handle_read(self): try: (recdata, addr) = self.socket.recvfrom(AdvancedDispatcher._buf_len) except socket.error as e: logger.error("socket error: %s", str(e)) return self.destination = state.Peer(addr[0], addr[1]) encodedAddr = protocol.encodeHost(addr[0]) # if protocol.checkIPAddress(encodedAddr, True): # self.local = True # else: # self.local = False # overwrite the old buffer to avoid mixing data and so that self.local works correctly self.read_buf[0:] = recdata self.bm_proto_reset() receiveDataQueue.put(self.listening)
def handle_read(self): try: (recdata, addr) = self.socket.recvfrom(AdvancedDispatcher._buf_len) except socket.error as e: logger.error("socket error: %s", str(e)) return self.destination = state.Peer(addr[0], addr[1]) encodedAddr = protocol.encodeHost(addr[0]) if protocol.checkIPAddress(encodedAddr, True): self.local = True else: self.local = False # overwrite the old buffer to avoid mixing data and so that self.local works correctly self.read_buf[0:] = recdata self.bm_proto_reset() receiveDataQueue.put(self.listening)
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)
def tls_handshake(self): # wait for flush if self.write_buf: return False # Perform the handshake. try: #print "handshaking (internal)" self.sslSocket.do_handshake() except ssl.SSLError as err: #print "%s:%i: handshake fail" % (self.destination.host, self.destination.port) self.want_read = self.want_write = False if err.args[0] == ssl.SSL_ERROR_WANT_READ: #print "want read" self.want_read = True if err.args[0] == ssl.SSL_ERROR_WANT_WRITE: #print "want write" self.want_write = True if not (self.want_write or self.want_read): raise except socket.error as err: if err.errno in asyncore._DISCONNECTED: self.handle_close() else: raise else: if sys.version_info >= (2, 7, 9): self.tlsVersion = self.sslSocket.version() logger.debug("%s:%i: TLS handshake success, TLS protocol version: %s", self.destination.host, self.destination.port, self.sslSocket.version()) else: self.tlsVersion = "TLSv1" logger.debug("%s:%i: TLS handshake success", self.destination.host, self.destination.port) # The handshake has completed, so remove this channel and... self.del_channel() self.set_socket(self.sslSocket) self.tlsDone = True self.bm_proto_reset() self.set_state("connection_fully_established") receiveDataQueue.put(self.destination) return False
def handle_read(self): """Callback for reading from a socket""" TLSDispatcher.handle_read(self) receiveDataQueue.put(self.destination)