Skip to content

Commit 274ec8b

Browse files
committedFeb 24, 2016
fix bug
1 parent b57ebb7 commit 274ec8b

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed
 

‎fetchMetadata.py

+4-5
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ def recv_piece(s, timeout=5):
106106

107107
def fetch_metadata(nid, infohash, address, timeout=5):
108108
try:
109-
print("in fetch_metadata")
110109
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
111110
s.settimeout(timeout)
112111
s.connect(address)
@@ -117,15 +116,14 @@ def fetch_metadata(nid, infohash, address, timeout=5):
117116

118117
# verification
119118
if not check_handshake_response(msg, infohash):
120-
print("error in check handshake")
121119
return
122120

123121
# advertize to support ut_metadata(BEP-09)
124122
ext_handshake(s)
125123
msg = s.recv(4096)
126124

127125
ut_metadata, metadata_size = decode_ext_handshake_msg(msg)
128-
print("ut_metadata", ut_metadata, "metadata_size", metadata_size)
126+
#print("ut_metadata", ut_metadata, "metadata_size", metadata_size)
129127

130128
metadata = []
131129
piece_tot = int(ceil(metadata_size / (1024 * 16)))
@@ -138,8 +136,9 @@ def fetch_metadata(nid, infohash, address, timeout=5):
138136
print(bencodepy.decode(metadata)[b"name"].decode(), "size", len(metadata))
139137

140138
except socket.timeout:
141-
print("timeout")
139+
pass
142140
except Exception as e:
143-
print(e)
141+
#print(e)
142+
pass
144143
finally:
145144
s.close()

‎main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def run(self):
2121
def fetch(self):
2222
for i in range(100):
2323
if self.que.qsize() == 0:
24-
time.sleep(1)
24+
sleep(1)
2525
continue
2626
r = self.que.get()
2727
t = Thread(target=fetch_metadata, args=(r[0], r[1], r[2]))
@@ -31,7 +31,7 @@ def fetch(self):
3131
def log(self, nid, infohash, name, address):
3232
#print("%s %s" % (codecs.encode(infohash, "hex_codec").decode(), name.decode()))
3333
#fetch_metadata(nid, infohash, address)
34-
Queue.put([nid, infohash, address])
34+
self.que.put([nid, infohash, address])
3535

3636

3737
if __name__ == "__main__":

0 commit comments

Comments
 (0)
Please sign in to comment.