From 401c95cdb6f15246267db82b3849c274c187d570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gerg=C3=B6=20Barany?= Date: Thu, 1 Aug 2013 12:31:40 +0200 Subject: [PATCH] Correct handling of old knownnodes.dat format at import. --- src/defaultKnownNodes.py | 9 +++++++-- src/helper_bootstrap.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/src/defaultKnownNodes.py b/src/defaultKnownNodes.py index 2308e375..52e31fff 100644 --- a/src/defaultKnownNodes.py +++ b/src/defaultKnownNodes.py @@ -49,10 +49,15 @@ def readDefaultKnownNodes(appdata): pickleFile = open(appdata + 'knownnodes.dat', 'rb') knownNodes = pickle.load(pickleFile) pickleFile.close() - knownNodes for stream, storedValue in knownNodes.items(): for host,value in storedValue.items(): - port, storedtime = storedValue[host] + try: + # Old knownNodes format. + port, storedtime = value + except: + # New knownNodes format. + host, port = host + storedtime = value print host, '\t', port, '\t', unicode(strftime('%a, %d %b %Y %I:%M %p',localtime(storedtime)),'utf-8') if __name__ == "__main__": diff --git a/src/helper_bootstrap.py b/src/helper_bootstrap.py index e3767df5..f0cae8f2 100644 --- a/src/helper_bootstrap.py +++ b/src/helper_bootstrap.py @@ -9,8 +9,20 @@ def knownNodes(): # 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') - shared.knownNodes = pickle.load(pickleFile) + loadedKnownNodes = pickle.load(pickleFile) pickleFile.close() + # 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 except: shared.knownNodes = defaultKnownNodes.createDefaultKnownNodes(shared.appdata) if shared.config.getint('bitmessagesettings', 'settingsversion') > 6: