proxy flake8 fixes
This commit is contained in:
parent
fa6ef4f933
commit
253cec15c4
|
@ -1,3 +1,7 @@
|
||||||
|
"""
|
||||||
|
src/network/httpd.py
|
||||||
|
=======================
|
||||||
|
"""
|
||||||
import asyncore
|
import asyncore
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
@ -5,25 +9,26 @@ from tls import TLSHandshake
|
||||||
|
|
||||||
|
|
||||||
class HTTPRequestHandler(asyncore.dispatcher):
|
class HTTPRequestHandler(asyncore.dispatcher):
|
||||||
|
"""Handling HTTP request"""
|
||||||
response = """HTTP/1.0 200 OK\r
|
response = """HTTP/1.0 200 OK\r
|
||||||
Date: Sun, 23 Oct 2016 18:02:00 GMT\r
|
Date: Sun, 23 Oct 2016 18:02:00 GMT\r
|
||||||
Content-Type: text/html; charset=UTF-8\r
|
Content-Type: text/html; charset=UTF-8\r
|
||||||
Content-Encoding: UTF-8\r
|
Content-Encoding: UTF-8\r
|
||||||
Content-Length: 136\r
|
Content-Length: 136\r
|
||||||
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT\r
|
Last-Modified: Wed, 08 Jan 2003 23:11:55 GMT\r
|
||||||
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)\r
|
Server: Apache/1.3.3.7 (Unix) (Red-Hat/Linux)\r
|
||||||
ETag: "3f80f-1b6-3e1cb03b"\r
|
ETag: "3f80f-1b6-3e1cb03b"\r
|
||||||
Accept-Ranges: bytes\r
|
Accept-Ranges: bytes\r
|
||||||
Connection: close\r
|
Connection: close\r
|
||||||
\r
|
\r
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
<title>An Example Page</title>
|
<title>An Example Page</title>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
Hello World, this is a very simple HTML document.
|
Hello World, this is a very simple HTML document.
|
||||||
</body>
|
</body>
|
||||||
</html>"""
|
</html>"""
|
||||||
|
|
||||||
def __init__(self, sock):
|
def __init__(self, sock):
|
||||||
if not hasattr(self, '_map'):
|
if not hasattr(self, '_map'):
|
||||||
|
@ -63,10 +68,11 @@ Connection: close\r
|
||||||
|
|
||||||
|
|
||||||
class HTTPSRequestHandler(HTTPRequestHandler, TLSHandshake):
|
class HTTPSRequestHandler(HTTPRequestHandler, TLSHandshake):
|
||||||
|
"""Handling HTTPS request"""
|
||||||
def __init__(self, sock):
|
def __init__(self, sock):
|
||||||
if not hasattr(self, '_map'):
|
if not hasattr(self, '_map'):
|
||||||
asyncore.dispatcher.__init__(self, sock)
|
asyncore.dispatcher.__init__(self, sock) # pylint: disable=non-parent-init-called
|
||||||
# self.tlsDone = False
|
# self.tlsDone = False
|
||||||
TLSHandshake.__init__(
|
TLSHandshake.__init__(
|
||||||
self,
|
self,
|
||||||
sock=sock,
|
sock=sock,
|
||||||
|
@ -87,8 +93,7 @@ class HTTPSRequestHandler(HTTPRequestHandler, TLSHandshake):
|
||||||
def readable(self):
|
def readable(self):
|
||||||
if self.tlsDone:
|
if self.tlsDone:
|
||||||
return HTTPRequestHandler.readable(self)
|
return HTTPRequestHandler.readable(self)
|
||||||
else:
|
return TLSHandshake.readable(self)
|
||||||
return TLSHandshake.readable(self)
|
|
||||||
|
|
||||||
def handle_read(self):
|
def handle_read(self):
|
||||||
if self.tlsDone:
|
if self.tlsDone:
|
||||||
|
@ -99,8 +104,7 @@ class HTTPSRequestHandler(HTTPRequestHandler, TLSHandshake):
|
||||||
def writable(self):
|
def writable(self):
|
||||||
if self.tlsDone:
|
if self.tlsDone:
|
||||||
return HTTPRequestHandler.writable(self)
|
return HTTPRequestHandler.writable(self)
|
||||||
else:
|
return TLSHandshake.writable(self)
|
||||||
return TLSHandshake.writable(self)
|
|
||||||
|
|
||||||
def handle_write(self):
|
def handle_write(self):
|
||||||
if self.tlsDone:
|
if self.tlsDone:
|
||||||
|
@ -110,6 +114,7 @@ class HTTPSRequestHandler(HTTPRequestHandler, TLSHandshake):
|
||||||
|
|
||||||
|
|
||||||
class HTTPServer(asyncore.dispatcher):
|
class HTTPServer(asyncore.dispatcher):
|
||||||
|
"""Handling HTTP Server"""
|
||||||
port = 12345
|
port = 12345
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -125,14 +130,15 @@ class HTTPServer(asyncore.dispatcher):
|
||||||
pair = self.accept()
|
pair = self.accept()
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
sock, addr = pair
|
sock, addr = pair
|
||||||
# print 'Incoming connection from %s' % repr(addr)
|
# print 'Incoming connection from %s' % repr(addr)
|
||||||
self.connections += 1
|
self.connections += 1
|
||||||
# if self.connections % 1000 == 0:
|
# if self.connections % 1000 == 0:
|
||||||
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
||||||
HTTPRequestHandler(sock)
|
HTTPRequestHandler(sock)
|
||||||
|
|
||||||
|
|
||||||
class HTTPSServer(HTTPServer):
|
class HTTPSServer(HTTPServer):
|
||||||
|
"""Handling HTTPS Server"""
|
||||||
port = 12345
|
port = 12345
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -143,10 +149,10 @@ class HTTPSServer(HTTPServer):
|
||||||
pair = self.accept()
|
pair = self.accept()
|
||||||
if pair is not None:
|
if pair is not None:
|
||||||
sock, addr = pair
|
sock, addr = pair
|
||||||
# print 'Incoming connection from %s' % repr(addr)
|
# print 'Incoming connection from %s' % repr(addr)
|
||||||
self.connections += 1
|
self.connections += 1
|
||||||
# if self.connections % 1000 == 0:
|
# if self.connections % 1000 == 0:
|
||||||
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
# print "Processed %i connections, active %i" % (self.connections, len(asyncore.socket_map))
|
||||||
HTTPSRequestHandler(sock)
|
HTTPSRequestHandler(sock)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,7 +36,7 @@ def handleExpiredDandelion(expired):
|
||||||
|
|
||||||
|
|
||||||
class InvThread(StoppableThread):
|
class InvThread(StoppableThread):
|
||||||
"""A thread to manage inventory"""
|
"""A thread to send inv annoucements."""
|
||||||
|
|
||||||
name = "InvBroadcaster"
|
name = "InvBroadcaster"
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
|
"""
|
||||||
|
src/network/proxy.py
|
||||||
|
====================
|
||||||
|
"""
|
||||||
|
# pylint: disable=protected-access
|
||||||
import socket
|
import socket
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
@ -56,7 +61,7 @@ class Proxy(AdvancedDispatcher):
|
||||||
def proxy(self, address):
|
def proxy(self, address):
|
||||||
"""Set proxy IP and port"""
|
"""Set proxy IP and port"""
|
||||||
if (not isinstance(address, tuple) or len(address) < 2 or
|
if (not isinstance(address, tuple) or len(address) < 2 or
|
||||||
not isinstance(address[0], str) or
|
not isinstance(address[0], str) or
|
||||||
not isinstance(address[1], int)):
|
not isinstance(address[1], int)):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
self.__class__._proxy = address
|
self.__class__._proxy = address
|
||||||
|
@ -83,8 +88,8 @@ class Proxy(AdvancedDispatcher):
|
||||||
def onion_proxy(self, address):
|
def onion_proxy(self, address):
|
||||||
"""Set onion proxy address"""
|
"""Set onion proxy address"""
|
||||||
if address is not None and (
|
if address is not None and (
|
||||||
not isinstance(address, tuple) or len(address) < 2 or
|
not isinstance(address, tuple) or len(address) < 2 or
|
||||||
not isinstance(address[0], str) or
|
not isinstance(address[0], str) or
|
||||||
not isinstance(address[1], int)):
|
not isinstance(address[1], int)):
|
||||||
raise ValueError
|
raise ValueError
|
||||||
self.__class__._onion_proxy = address
|
self.__class__._onion_proxy = address
|
||||||
|
@ -106,6 +111,7 @@ class Proxy(AdvancedDispatcher):
|
||||||
self.destination = address
|
self.destination = address
|
||||||
self.isOutbound = True
|
self.isOutbound = True
|
||||||
self.fullyEstablished = False
|
self.fullyEstablished = False
|
||||||
|
self.connectedAt = 0
|
||||||
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||||
if BMConfigParser().safeGetBoolean(
|
if BMConfigParser().safeGetBoolean(
|
||||||
"bitmessagesettings", "socksauthentication"):
|
"bitmessagesettings", "socksauthentication"):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user