Use defaultdict to for findHashId result

This commit is contained in:
shortcutme 2019-02-24 02:28:42 +01:00
parent 174e8d3c19
commit 9d849a16ec
No known key found for this signature in database
GPG Key ID: 5B63BAE6CB9613AE
1 changed files with 2 additions and 3 deletions

View File

@ -2,6 +2,7 @@ import logging
import time
import sys
import itertools
import collections
import gevent
@ -311,7 +312,7 @@ class Peer(object):
if not res or "error" in res or type(res) is not dict:
return False
back = {}
back = collections.defaultdict(list)
for ip_type in ["ipv4", "ipv6", "onion"]:
if ip_type == "ipv4":
@ -319,8 +320,6 @@ class Peer(object):
else:
key = "peers_%s" % ip_type
for hash, peers in res.get(key, {}).items()[0:30]:
if hash not in back:
back[hash] = []
if ip_type == "onion":
unpacker_func = helper.unpackOnionAddress
else: