|
|
|
@ -18,7 +18,8 @@ from debug import logger
|
|
|
|
|
from proxy import Proxy
|
|
|
|
|
from singleton import Singleton
|
|
|
|
|
from tcp import (
|
|
|
|
|
TCPServer, Socks5BMConnection, Socks4aBMConnection, TCPConnection)
|
|
|
|
|
bootstrap, Socks4aBMConnection, Socks5BMConnection,
|
|
|
|
|
TCPConnection, TCPServer)
|
|
|
|
|
from udp import UDPSocket
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -159,7 +160,28 @@ class BMConnectionPool(object):
|
|
|
|
|
udpSocket = UDPSocket(host=bind, announcing=True)
|
|
|
|
|
self.udpSockets[udpSocket.listening.host] = udpSocket
|
|
|
|
|
|
|
|
|
|
def loop(self): # pylint: disable=too-many-branches, too-many-statements
|
|
|
|
|
def startBootstrappers(self):
|
|
|
|
|
"""Run the process of resolving bootstrap hostnames"""
|
|
|
|
|
proxy_type = BMConfigParser().safeGet(
|
|
|
|
|
'bitmessagesettings', 'socksproxytype')
|
|
|
|
|
# A plugins may be added here
|
|
|
|
|
if not proxy_type or proxy_type == 'none':
|
|
|
|
|
connection_base = TCPConnection
|
|
|
|
|
elif proxy_type == 'SOCKS5':
|
|
|
|
|
connection_base = Socks5BMConnection
|
|
|
|
|
elif proxy_type == 'SOCKS4a':
|
|
|
|
|
connection_base = Socks4aBMConnection # FIXME: I cannot test
|
|
|
|
|
else:
|
|
|
|
|
# This should never happen because socksproxytype setting
|
|
|
|
|
# is handled in bitmessagemain before starting the connectionpool
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
bootstrapper = bootstrap(connection_base)
|
|
|
|
|
port = helper_random.randomchoice([8080, 8444])
|
|
|
|
|
hostname = 'bootstrap%s.bitmessage.org' % port
|
|
|
|
|
self.addConnection(bootstrapper(hostname, port))
|
|
|
|
|
|
|
|
|
|
def loop(self): # pylint: disable=too-many-branches,too-many-statements
|
|
|
|
|
"""Main Connectionpool's loop"""
|
|
|
|
|
# defaults to empty loop if outbound connections are maxed
|
|
|
|
|
spawnConnections = False
|
|
|
|
@ -184,7 +206,8 @@ class BMConnectionPool(object):
|
|
|
|
|
# pylint: disable=too-many-nested-blocks
|
|
|
|
|
if spawnConnections:
|
|
|
|
|
if not knownnodes.knownNodesActual:
|
|
|
|
|
knownnodes.dns()
|
|
|
|
|
self.startBootstrappers()
|
|
|
|
|
knownnodes.knownNodesActual = True
|
|
|
|
|
if not self.bootstrapped:
|
|
|
|
|
self.bootstrapped = True
|
|
|
|
|
Proxy.proxy = (
|
|
|
|
|