Asyncore update

- better error handling
- bug fixes
- remove some debug output
This commit is contained in:
Peter Šurda 2017-05-24 21:15:36 +02:00
parent bafdd6a93a
commit fa56ab3e6f
Signed by untrusted user: PeterSurda
GPG Key ID: 0C5F50C0B5F37D87
3 changed files with 17 additions and 12 deletions

View File

@ -57,6 +57,7 @@ import warnings
import os
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
ENOTCONN, ESHUTDOWN, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
ECONNREFUSED, \
errorcode
try:
from errno import WSAEWOULDBLOCK
@ -65,7 +66,7 @@ except:
from ssl import SSLError, SSL_ERROR_WANT_READ, SSL_ERROR_WANT_WRITE
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
EBADF))
EBADF, ECONNREFUSED))
OP_READ = 1
OP_WRITE = 2
@ -530,7 +531,7 @@ class dispatcher:
except TypeError:
return None
except socket.error as why:
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN):
if why.args[0] in (EWOULDBLOCK, ECONNABORTED, EAGAIN, ENOTCONN):
return None
else:
raise
@ -547,11 +548,11 @@ class dispatcher:
else:
raise
except socket.error as why:
if why.errno in (errno.EAGAIN, errno.EWOULDBLOCK) or \
if why.args[0] in (EAGAIN, EWOULDBLOCK) or \
(sys.platform.startswith('win') and \
err.errno == errno.WSAEWOULDBLOCK):
err.errno == WSAEWOULDBLOCK):
return 0
elif why.errno in _DISCONNECTED:
elif why.args[0] in _DISCONNECTED:
self.handle_close()
return 0
else:
@ -574,11 +575,11 @@ class dispatcher:
raise
except socket.error as why:
# winsock sometimes raises ENOTCONN
if why.errno in (errno.EAGAIN, errno.EWOULDBLOCK) or \
if why.args[0] in (EAGAIN, EWOULDBLOCK) or \
(sys.platform.startswith('win') and \
err.errno == errno.WSAEWOULDBLOCK):
err.errno == WSAEWOULDBLOCK):
return b''
if why.errno in _DISCONNECTED:
if why.args[0] in _DISCONNECTED:
self.handle_close()
return b''
else:

View File

@ -289,7 +289,7 @@ class BMConnection(TLSDispatcher, BMQueues):
# print "skipping getdata"
# return True
for i in items:
print "received getdata request for item %s" % (hexlify(i))
#print "received getdata request for item %s" % (hexlify(i))
#logger.debug('received getdata request for item:' + hexlify(i))
#if i in ObjUploadQueue.streamElems(1):
if False:
@ -309,7 +309,8 @@ class BMConnection(TLSDispatcher, BMQueues):
logger.error("Too many items in inv message!")
raise BMProtoExcessiveDataError()
else:
print "items in inv: %i" % (len(items))
pass
#print "items in inv: %i" % (len(items))
startTime = time.time()
#advertisedSet = set()
@ -609,7 +610,10 @@ class BMConnection(TLSDispatcher, BMQueues):
else:
print "%s:%i: closing, %s" % (self.destination.host, self.destination.port, reason)
network.connectionpool.BMConnectionPool().removeConnection(self)
try:
asyncore.dispatcher.close(self)
except AttributeError:
pass
class Socks5BMConnection(Socks5Connection, BMConnection):

View File

@ -110,7 +110,7 @@ class TLSDispatcher(AdvancedDispatcher):
if not (self.want_write or self.want_read):
raise
else:
print "%s:%i: handshake success" % (self.destination.host, self.destination.port)
print "%s:%i: TLS handshake success%s" % (self.destination.host, self.destination.port, ", TLS protocol version: %s" % (self.sslSocket.version()) if sys.version_info >= (2, 7, 9) else "")
# The handshake has completed, so remove this channel and...
self.del_channel()
self.set_socket(self.sslSocket)