Added trusted_peer and listen_for_connections options

This commit is contained in:
TheKysek 2017-01-14 13:42:15 +01:00
parent 55aa240d74
commit b5fce64619
3 changed files with 45 additions and 38 deletions

View File

@ -47,16 +47,17 @@ def main():
shared.core_nodes = {tuple(row) for row in reader} shared.core_nodes = {tuple(row) for row in reader}
shared.node_pool.update(shared.core_nodes) shared.node_pool.update(shared.core_nodes)
try: if not shared.trusted_peer:
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80): try:
shared.unchecked_node_pool.add((item[4][0], 8080)) for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80):
logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method') shared.unchecked_node_pool.add((item[4][0], 8080))
for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80): logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method')
shared.unchecked_node_pool.add((item[4][0], 8444)) for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80):
logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method') shared.unchecked_node_pool.add((item[4][0], 8444))
except Exception as e: logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method')
logging.error('Error during DNS bootstrap') except Exception as e:
logging.error(e) logging.error('Error during DNS bootstrap')
logging.error(e)
manager = Manager() manager = Manager()
manager.clean_objects() manager.clean_objects()
@ -69,25 +70,26 @@ def main():
listener_ipv4 = None listener_ipv4 = None
listener_ipv6 = None listener_ipv6 = None
if socket.has_ipv6: if not shared.listen_for_connections:
try: if socket.has_ipv6:
listener_ipv6 = Listener('', shared.listening_port, family=socket.AF_INET6) try:
listener_ipv6.start() listener_ipv6 = Listener('', shared.listening_port, family=socket.AF_INET6)
except Exception as e: listener_ipv6.start()
logging.warning('Error while starting IPv6 listener') except Exception as e:
logging.warning(e) logging.warning('Error while starting IPv6 listener')
logging.warning(e)
try: try:
listener_ipv4 = Listener('', shared.listening_port) listener_ipv4 = Listener('', shared.listening_port)
listener_ipv4.start() listener_ipv4.start()
except Exception as e: except Exception as e:
if listener_ipv6: if listener_ipv6:
logging.warning('Error while starting IPv4 listener. ' logging.warning('Error while starting IPv4 listener. '
'However the IPv6 one seems to be working and will probably accept IPv4 connections.') 'However the IPv6 one seems to be working and will probably accept IPv4 connections.')
else: else:
logging.error('Error while starting IPv4 listener.' logging.error('Error while starting IPv4 listener.'
'You will not receive incoming connections. Please check your port configuration') 'You will not receive incoming connections. Please check your port configuration')
logging.error(e) logging.error(e)
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -63,8 +63,10 @@ class Manager(threading.Thread):
hosts.add(c.host) hosts.add(c.host)
if not c.server: if not c.server:
outgoing_connections += 1 outgoing_connections += 1
if outgoing_connections < shared.outgoing_connections and shared.send_outgoing_connections: to_connect = set()
to_connect = set() if shared.trusted_peer:
to_connect.add(shared.trusted_peer)
if outgoing_connections < shared.outgoing_connections and shared.send_outgoing_connections and not shared.trusted_peer:
if len(shared.unchecked_node_pool) > 16: if len(shared.unchecked_node_pool) > 16:
to_connect.update(random.sample(shared.unchecked_node_pool, 16)) to_connect.update(random.sample(shared.unchecked_node_pool, 16))
else: else:
@ -74,14 +76,14 @@ class Manager(threading.Thread):
to_connect.update(random.sample(shared.node_pool, 8)) to_connect.update(random.sample(shared.node_pool, 8))
else: else:
to_connect.update(shared.node_pool) to_connect.update(shared.node_pool)
for addr in to_connect: for addr in to_connect:
if addr[0] in hosts: if addr[0] in hosts:
continue continue
c = Connection(addr[0], addr[1]) c = Connection(addr[0], addr[1])
c.start() c.start()
hosts.add(c.host) hosts.add(c.host)
with shared.connections_lock: with shared.connections_lock:
shared.connections.add(c) shared.connections.add(c)
shared.hosts = hosts shared.hosts = hosts
@staticmethod @staticmethod

View File

@ -6,8 +6,11 @@ import threading
listening_port = 8444 listening_port = 8444
send_outgoing_connections = True send_outgoing_connections = True
listen_for_connections = True
data_directory = 'minode_data/' data_directory = 'minode_data/'
source_directory = os.path.dirname(os.path.realpath(__file__)) source_directory = os.path.dirname(os.path.realpath(__file__))
trusted_peer = None
# trusted_peer = ('127.0.0.1', 8444)
log_level = logging.DEBUG log_level = logging.DEBUG