Example #1
0
 def save(self, info_hash, content):
     ok, msg = dht_bencode.decode(content)
     if not ok:
         return
     info = msg['info']['name'].decode('utf-8')
     sql = "update dht_info set dht_info.detail_info='%s' where dht_info.info_hash='%s'" % (info, info_hash)
     self.cur.execute(sql)
Example #2
0
 def save(self, info_hash, content):
     ok, msg = dht_bencode.decode(content)
     if not ok:
         return
     info = msg['info']['name'].decode('utf-8')
     sql = "update dht_info set dht_info.detail_info='%s' where dht_info.info_hash='%s'" % (
         info, info_hash)
     self.cur.execute(sql)
Example #3
0
 def run(self):
     while self.is_working:
         try:
             # 等待接收网络消息
             data, address = self.sock.recvfrom(65536)
             # 对消息进行解析以便处理应答
             ok, msg = dht_bencode.decode(data)
             if not ok: continue
             if msg['y'] == 'r':
                 self.__handle_response(msg, address)
             elif msg['y'] == 'q':
                 self.handle_request[msg['q']](msg, address)
         except Exception as e:
             pass
Example #4
0
 def run(self):
     while self.is_working:
         try:
             # 等待接收网络消息
             data, address = self.sock.recvfrom(65536)
             # 对消息进行解析以便处理应答
             ok, msg = dht_bencode.decode(data)
             if not ok: continue
             if msg['y'] == 'r':
                 self.__handle_response(msg, address)
             elif msg['y'] == 'q':
                 self.handle_request[msg['q']](msg, address)
         except Exception as e:
             pass