2013-06-21 00:55:04 +02:00
|
|
|
import shared
|
|
|
|
import socket
|
|
|
|
import defaultKnownNodes
|
|
|
|
import pickle
|
2013-06-21 21:44:28 +02:00
|
|
|
import time
|
2013-06-21 00:55:04 +02:00
|
|
|
|
2015-11-18 16:22:17 +01:00
|
|
|
from debug import logger
|
|
|
|
|
2013-06-21 00:55:04 +02:00
|
|
|
def knownNodes():
|
|
|
|
try:
|
|
|
|
# We shouldn't have to use the shared.knownNodesLock because this had
|
|
|
|
# better be the only thread accessing knownNodes right now.
|
|
|
|
pickleFile = open(shared.appdata + 'knownnodes.dat', 'rb')
|
2013-08-01 12:31:40 +02:00
|
|
|
loadedKnownNodes = pickle.load(pickleFile)
|
2013-06-21 00:55:04 +02:00
|
|
|
pickleFile.close()
|
2013-08-01 12:31:40 +02:00
|
|
|
# The old format of storing knownNodes was as a 'host: (port, time)'
|
|
|
|
# mapping. The new format is as 'Peer: time' pairs. If we loaded
|
|
|
|
# data in the old format, transform it to the new style.
|
|
|
|
for stream, nodes in loadedKnownNodes.items():
|
|
|
|
shared.knownNodes[stream] = {}
|
|
|
|
for node_tuple in nodes.items():
|
|
|
|
try:
|
|
|
|
host, (port, time) = node_tuple
|
|
|
|
peer = shared.Peer(host, port)
|
|
|
|
except:
|
|
|
|
peer, time = node_tuple
|
|
|
|
shared.knownNodes[stream][peer] = time
|
2013-06-21 00:55:04 +02:00
|
|
|
except:
|
2013-07-24 18:43:51 +02:00
|
|
|
shared.knownNodes = defaultKnownNodes.createDefaultKnownNodes(shared.appdata)
|
2014-09-03 01:25:03 +02:00
|
|
|
if shared.config.getint('bitmessagesettings', 'settingsversion') > 10:
|
2015-11-18 16:22:17 +01:00
|
|
|
logger.error('Bitmessage cannot read future versions of the keys file (keys.dat). Run the newer version of Bitmessage.')
|
2013-06-21 00:55:04 +02:00
|
|
|
raise SystemExit
|
|
|
|
|
|
|
|
def dns():
|
|
|
|
# DNS bootstrap. This could be programmed to use the SOCKS proxy to do the
|
|
|
|
# DNS lookup some day but for now we will just rely on the entries in
|
|
|
|
# defaultKnownNodes.py. Hopefully either they are up to date or the user
|
|
|
|
# has run Bitmessage recently without SOCKS turned on and received good
|
|
|
|
# bootstrap nodes using that method.
|
2013-07-24 18:43:51 +02:00
|
|
|
with shared.printLock:
|
|
|
|
if shared.config.get('bitmessagesettings', 'socksproxytype') == 'none':
|
|
|
|
try:
|
|
|
|
for item in socket.getaddrinfo('bootstrap8080.bitmessage.org', 80):
|
2015-11-18 16:22:17 +01:00
|
|
|
logger.info('Adding ' + item[4][0] + ' to knownNodes based on DNS bootstrap method')
|
2013-07-30 22:23:18 +02:00
|
|
|
shared.knownNodes[1][shared.Peer(item[4][0], 8080)] = int(time.time())
|
2013-07-24 18:43:51 +02:00
|
|
|
except:
|
2015-11-18 16:22:17 +01:00
|
|
|
logger.error('bootstrap8080.bitmessage.org DNS bootstrapping failed.')
|
2013-07-24 18:43:51 +02:00
|
|
|
try:
|
|
|
|
for item in socket.getaddrinfo('bootstrap8444.bitmessage.org', 80):
|
2015-11-18 16:22:17 +01:00
|
|
|
logger.info ('Adding ' + item[4][0] + ' to knownNodes based on DNS bootstrap method')
|
2013-07-30 22:23:18 +02:00
|
|
|
shared.knownNodes[1][shared.Peer(item[4][0], 8444)] = int(time.time())
|
2013-07-24 18:43:51 +02:00
|
|
|
except:
|
2015-11-18 16:22:17 +01:00
|
|
|
logger.error('bootstrap8444.bitmessage.org DNS bootstrapping failed.')
|
2013-07-24 18:43:51 +02:00
|
|
|
else:
|
2015-11-18 16:22:17 +01:00
|
|
|
logger.info('DNS bootstrap skipped because SOCKS is used.')
|
2013-07-24 18:43:51 +02:00
|
|
|
|