Browse Source

ffpb: properly handle not-found node in peers_repo

Helge Jung 9 years ago
parent
commit
e23059d665
1 changed files with 12 additions and 11 deletions
  1. 12 11
      modules/ffpb.py

+ 12 - 11
modules/ffpb.py

@@ -129,25 +129,26 @@ def ffpb_findnode(name):
 			return node
 
 	# still not found -> try peers_repo
-	peer_name = None
-	peer_mac = None
-
 	if not peers_repo is None:
+		peer_name = None
+		peer_mac = None
+		peer_file = None
+
 		for b in peers_repo.heads.master.commit.tree.blobs:
 			if b.name.lower() == name.lower():
 				peer_name = b.name
 				peer_file = b.abspath
 				break
 
-	if os.path.exists(peer_file):
-		peerfile = open(peer_file, "r")
-		for line in peerfile:
-			if line.startswith("# MAC:"):
-				peer_mac = line[6:].strip()
-		peerfile.close()
+		if (not peer_file is None) and os.path.exists(peer_file):
+			peerfile = open(peer_file, "r")
+			for line in peerfile:
+				if line.startswith("# MAC:"):
+					peer_mac = line[6:].strip()
+			peerfile.close()
 
-	if not (peer_mac is None):
-		return { "hostname": peer_name, "network": { "addresses": [ mac2ipv6(peer_mac, "fdca:ffee:ff12:132:") ], "mac": peer_mac } }
+		if not (peer_mac is None):
+			return { "hostname": peer_name, "network": { "addresses": [ mac2ipv6(peer_mac, "fdca:ffee:ff12:132:") ], "mac": peer_mac } }
 
 	return None