The changes in #1325 are buggy. Implementing it properly.
This commit is contained in:
parent
b2c8b77938
commit
ef54bcaf82
|
@ -40,8 +40,8 @@ def dns():
|
||||||
port, exc_info=True
|
port, exc_info=True
|
||||||
)
|
)
|
||||||
elif proxy_type == 'SOCKS5':
|
elif proxy_type == 'SOCKS5':
|
||||||
knownnodes.addKnownNode(1, state.Peer('quzwelsuziwqgpt2.onion', 8444))
|
knownnodes.createDefaultKnownNodes(onion=True)
|
||||||
logger.debug("Adding quzwelsuziwqgpt2.onion:8444 to knownNodes.")
|
logger.debug('Adding default onion knownNodes.')
|
||||||
for port in [8080, 8444]:
|
for port in [8080, 8444]:
|
||||||
logger.debug("Resolving %i through SOCKS...", port)
|
logger.debug("Resolving %i through SOCKS...", port)
|
||||||
address_family = socket.AF_INET
|
address_family = socket.AF_INET
|
||||||
|
|
|
@ -21,6 +21,8 @@ knownNodesTrimAmount = 2000
|
||||||
# forget a node after rating is this low
|
# forget a node after rating is this low
|
||||||
knownNodesForgetRating = -0.5
|
knownNodesForgetRating = -0.5
|
||||||
|
|
||||||
|
knownNodesActual = False
|
||||||
|
|
||||||
DEFAULT_NODES = (
|
DEFAULT_NODES = (
|
||||||
state.Peer('5.45.99.75', 8444),
|
state.Peer('5.45.99.75', 8444),
|
||||||
state.Peer('75.167.159.54', 8444),
|
state.Peer('75.167.159.54', 8444),
|
||||||
|
@ -33,6 +35,10 @@ DEFAULT_NODES = (
|
||||||
state.Peer('178.11.46.221', 8444)
|
state.Peer('178.11.46.221', 8444)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
DEFAULT_NODES_ONION = (
|
||||||
|
state.Peer('quzwelsuziwqgpt2.onion', 8444),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def json_serialize_knownnodes(output):
|
def json_serialize_knownnodes(output):
|
||||||
"""
|
"""
|
||||||
|
@ -52,10 +58,19 @@ def json_deserialize_knownnodes(source):
|
||||||
"""
|
"""
|
||||||
Read JSON from source and make knownnodes dict
|
Read JSON from source and make knownnodes dict
|
||||||
"""
|
"""
|
||||||
|
global knownNodesActual # pylint: disable=global-statement
|
||||||
for node in json.load(source):
|
for node in json.load(source):
|
||||||
peer = node['peer']
|
peer = node['peer']
|
||||||
peer['host'] = str(peer['host'])
|
info = node['info']
|
||||||
knownNodes[node['stream']][state.Peer(**peer)] = node['info']
|
peer = state.Peer(str(peer['host']), peer.get('port', 8444))
|
||||||
|
knownNodes[node['stream']][peer] = info
|
||||||
|
|
||||||
|
if (
|
||||||
|
not (knownNodesActual or info.get('is_self')) and
|
||||||
|
peer not in DEFAULT_NODES and
|
||||||
|
peer not in DEFAULT_NODES_ONION
|
||||||
|
):
|
||||||
|
knownNodesActual = True
|
||||||
|
|
||||||
|
|
||||||
def pickle_deserialize_old_knownnodes(source):
|
def pickle_deserialize_old_knownnodes(source):
|
||||||
|
@ -88,9 +103,10 @@ def addKnownNode(stream, peer, lastseen=None, is_self=False):
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
def createDefaultKnownNodes():
|
def createDefaultKnownNodes(onion=False):
|
||||||
for peer in DEFAULT_NODES:
|
past = time.time() - 2418600 # 28 days - 10 min
|
||||||
addKnownNode(1, peer)
|
for peer in DEFAULT_NODES_ONION if onion else DEFAULT_NODES:
|
||||||
|
addKnownNode(1, peer, past)
|
||||||
saveKnownNodes()
|
saveKnownNodes()
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,7 +131,9 @@ def readKnownNodes():
|
||||||
if onionhostname and ".onion" in onionhostname:
|
if onionhostname and ".onion" in onionhostname:
|
||||||
onionport = config.safeGetInt('bitmessagesettings', 'onionport')
|
onionport = config.safeGetInt('bitmessagesettings', 'onionport')
|
||||||
if onionport:
|
if onionport:
|
||||||
addKnownNode(1, state.Peer(onionhostname, onionport), is_self=True)
|
self_peer = state.Peer(onionhostname, onionport)
|
||||||
|
addKnownNode(1, self_peer, is_self=True)
|
||||||
|
state.ownAddresses[self_peer] = True
|
||||||
|
|
||||||
|
|
||||||
def increaseRating(peer):
|
def increaseRating(peer):
|
||||||
|
@ -166,13 +184,20 @@ def cleanupKnownNodes():
|
||||||
now = int(time.time())
|
now = int(time.time())
|
||||||
needToWriteKnownNodesToDisk = False
|
needToWriteKnownNodesToDisk = False
|
||||||
dns_done = False
|
dns_done = False
|
||||||
|
spawnConnections = not BMConfigParser().safeGetBoolean(
|
||||||
|
'bitmessagesettings', 'dontconnect'
|
||||||
|
) and BMConfigParser().safeGetBoolean(
|
||||||
|
'bitmessagesettings', 'sendoutgoingconnections')
|
||||||
|
|
||||||
with knownNodesLock:
|
with knownNodesLock:
|
||||||
for stream in knownNodes:
|
for stream in knownNodes:
|
||||||
|
if stream not in state.streamsInWhichIAmParticipating:
|
||||||
|
continue
|
||||||
keys = knownNodes[stream].keys()
|
keys = knownNodes[stream].keys()
|
||||||
if len(keys) <= 1 and not dns_done: # leave at least one node
|
if len(keys) <= 1: # leave at least one node
|
||||||
dns()
|
if not dns_done and spawnConnections:
|
||||||
dns_done = True
|
dns()
|
||||||
|
dns_done = True
|
||||||
continue
|
continue
|
||||||
for node in keys:
|
for node in keys:
|
||||||
try:
|
try:
|
||||||
|
|
|
@ -8,7 +8,7 @@ import re
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from debug import logger
|
from debug import logger
|
||||||
import helper_bootstrap
|
import helper_bootstrap
|
||||||
from knownnodes import knownNodes
|
import knownnodes
|
||||||
from network.proxy import Proxy
|
from network.proxy import Proxy
|
||||||
from network.tcp import TCPServer, Socks5BMConnection, Socks4aBMConnection, TCPConnection
|
from network.tcp import TCPServer, Socks5BMConnection, Socks4aBMConnection, TCPConnection
|
||||||
from network.udp import UDPSocket
|
from network.udp import UDPSocket
|
||||||
|
@ -19,6 +19,7 @@ from singleton import Singleton
|
||||||
import state
|
import state
|
||||||
import helper_random
|
import helper_random
|
||||||
|
|
||||||
|
|
||||||
@Singleton
|
@Singleton
|
||||||
class BMConnectionPool(object):
|
class BMConnectionPool(object):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
@ -139,7 +140,7 @@ class BMConnectionPool(object):
|
||||||
acceptConnections = False
|
acceptConnections = False
|
||||||
|
|
||||||
if spawnConnections:
|
if spawnConnections:
|
||||||
if not any([knownNodes.iteritems()]):
|
if not knownnodes.knownNodesActual:
|
||||||
helper_bootstrap.dns()
|
helper_bootstrap.dns()
|
||||||
if not self.bootstrapped:
|
if not self.bootstrapped:
|
||||||
self.bootstrapped = True
|
self.bootstrapped = True
|
||||||
|
|
Reference in New Issue
Block a user