Added trusted_peer and listen_for_connections options
This commit is contained in:
parent
55aa240d74
commit
b5fce64619
58
src/main.py
58
src/main.py
|
@ -47,16 +47,17 @@ def main():
|
|||
shared.core_nodes = {tuple(row) for row in reader}
|
||||
shared.node_pool.update(shared.core_nodes)
|
||||
|
||||
try:
|
||||
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80):
|
||||
shared.unchecked_node_pool.add((item[4][0], 8080))
|
||||
logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method')
|
||||
for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80):
|
||||
shared.unchecked_node_pool.add((item[4][0], 8444))
|
||||
logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method')
|
||||
except Exception as e:
|
||||
logging.error('Error during DNS bootstrap')
|
||||
logging.error(e)
|
||||
if not shared.trusted_peer:
|
||||
try:
|
||||
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80):
|
||||
shared.unchecked_node_pool.add((item[4][0], 8080))
|
||||
logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method')
|
||||
for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80):
|
||||
shared.unchecked_node_pool.add((item[4][0], 8444))
|
||||
logging.debug('Adding ' + item[4][0] + ' to unchecked_node_pool based on DNS bootstrap method')
|
||||
except Exception as e:
|
||||
logging.error('Error during DNS bootstrap')
|
||||
logging.error(e)
|
||||
|
||||
manager = Manager()
|
||||
manager.clean_objects()
|
||||
|
@ -69,25 +70,26 @@ def main():
|
|||
listener_ipv4 = None
|
||||
listener_ipv6 = None
|
||||
|
||||
if socket.has_ipv6:
|
||||
try:
|
||||
listener_ipv6 = Listener('', shared.listening_port, family=socket.AF_INET6)
|
||||
listener_ipv6.start()
|
||||
except Exception as e:
|
||||
logging.warning('Error while starting IPv6 listener')
|
||||
logging.warning(e)
|
||||
if not shared.listen_for_connections:
|
||||
if socket.has_ipv6:
|
||||
try:
|
||||
listener_ipv6 = Listener('', shared.listening_port, family=socket.AF_INET6)
|
||||
listener_ipv6.start()
|
||||
except Exception as e:
|
||||
logging.warning('Error while starting IPv6 listener')
|
||||
logging.warning(e)
|
||||
|
||||
try:
|
||||
listener_ipv4 = Listener('', shared.listening_port)
|
||||
listener_ipv4.start()
|
||||
except Exception as e:
|
||||
if listener_ipv6:
|
||||
logging.warning('Error while starting IPv4 listener. '
|
||||
'However the IPv6 one seems to be working and will probably accept IPv4 connections.')
|
||||
else:
|
||||
logging.error('Error while starting IPv4 listener.'
|
||||
'You will not receive incoming connections. Please check your port configuration')
|
||||
logging.error(e)
|
||||
try:
|
||||
listener_ipv4 = Listener('', shared.listening_port)
|
||||
listener_ipv4.start()
|
||||
except Exception as e:
|
||||
if listener_ipv6:
|
||||
logging.warning('Error while starting IPv4 listener. '
|
||||
'However the IPv6 one seems to be working and will probably accept IPv4 connections.')
|
||||
else:
|
||||
logging.error('Error while starting IPv4 listener.'
|
||||
'You will not receive incoming connections. Please check your port configuration')
|
||||
logging.error(e)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
|
|
@ -63,8 +63,10 @@ class Manager(threading.Thread):
|
|||
hosts.add(c.host)
|
||||
if not c.server:
|
||||
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:
|
||||
to_connect.update(random.sample(shared.unchecked_node_pool, 16))
|
||||
else:
|
||||
|
@ -74,14 +76,14 @@ class Manager(threading.Thread):
|
|||
to_connect.update(random.sample(shared.node_pool, 8))
|
||||
else:
|
||||
to_connect.update(shared.node_pool)
|
||||
for addr in to_connect:
|
||||
if addr[0] in hosts:
|
||||
continue
|
||||
c = Connection(addr[0], addr[1])
|
||||
c.start()
|
||||
hosts.add(c.host)
|
||||
with shared.connections_lock:
|
||||
shared.connections.add(c)
|
||||
for addr in to_connect:
|
||||
if addr[0] in hosts:
|
||||
continue
|
||||
c = Connection(addr[0], addr[1])
|
||||
c.start()
|
||||
hosts.add(c.host)
|
||||
with shared.connections_lock:
|
||||
shared.connections.add(c)
|
||||
shared.hosts = hosts
|
||||
|
||||
@staticmethod
|
||||
|
|
|
@ -6,8 +6,11 @@ import threading
|
|||
|
||||
listening_port = 8444
|
||||
send_outgoing_connections = True
|
||||
listen_for_connections = True
|
||||
data_directory = 'minode_data/'
|
||||
source_directory = os.path.dirname(os.path.realpath(__file__))
|
||||
trusted_peer = None
|
||||
# trusted_peer = ('127.0.0.1', 8444)
|
||||
|
||||
log_level = logging.DEBUG
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user