mirror of
https://github.com/ap-pauloafonso/ratio-spoof.git
synced 2026-04-21 00:22:05 +00:00
first test succeded
This commit is contained in:
parent
6ead5e6655
commit
0bcff57016
1 changed files with 33 additions and 37 deletions
|
|
@ -16,6 +16,7 @@ import datetime
|
||||||
import threading
|
import threading
|
||||||
import urllib.request
|
import urllib.request
|
||||||
import http.client
|
import http.client
|
||||||
|
import logging
|
||||||
|
|
||||||
|
|
||||||
def human_readable_size(size, decimal_places=2):
|
def human_readable_size(size, decimal_places=2):
|
||||||
|
|
@ -51,8 +52,9 @@ class RatioSpoofState():
|
||||||
self.info_hash_urlencoded = info_hash_urlencoded
|
self.info_hash_urlencoded = info_hash_urlencoded
|
||||||
self.announce_history_deq = deque(maxlen=10)
|
self.announce_history_deq = deque(maxlen=10)
|
||||||
self.deq_count = 0
|
self.deq_count = 0
|
||||||
|
self.numwant = 200
|
||||||
self.__add_announce(current_downloaded, current_uploaded ,next_announce_left_b(current_downloaded, total_size))
|
self.__add_announce(current_downloaded, current_uploaded ,next_announce_left_b(current_downloaded, total_size))
|
||||||
#threading.Thread(target = (lambda: self.__print_state())).start()
|
threading.Thread(target = (lambda: self.__print_state())).start()
|
||||||
threading.Thread(target = (lambda: self.__decrease_timer())).start()
|
threading.Thread(target = (lambda: self.__decrease_timer())).start()
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -65,6 +67,8 @@ class RatioSpoofState():
|
||||||
current_downloaded = self.announce_history_deq[-1]['downloaded']
|
current_downloaded = self.announce_history_deq[-1]['downloaded']
|
||||||
if(self.announce_history_deq[-1]['downloaded'] < self.total_size):
|
if(self.announce_history_deq[-1]['downloaded'] < self.total_size):
|
||||||
current_downloaded = next_announce_total_b(self.download_speed,self.announce_history_deq[-1]['downloaded'], self.piece_size, self.announce_rate, self.total_size)
|
current_downloaded = next_announce_total_b(self.download_speed,self.announce_history_deq[-1]['downloaded'], self.piece_size, self.announce_rate, self.total_size)
|
||||||
|
else:
|
||||||
|
self.numwant = 0
|
||||||
current_uploaded = next_announce_total_b(self.upload_speed,self.announce_history_deq[-1]['uploaded'], self.piece_size, self.announce_rate)
|
current_uploaded = next_announce_total_b(self.upload_speed,self.announce_history_deq[-1]['uploaded'], self.piece_size, self.announce_rate)
|
||||||
current_left = next_announce_left_b(current_downloaded, self.total_size)
|
current_left = next_announce_left_b(current_downloaded, self.total_size)
|
||||||
self.__add_announce(current_downloaded,current_uploaded,current_left)
|
self.__add_announce(current_downloaded,current_uploaded,current_left)
|
||||||
|
|
@ -72,25 +76,18 @@ class RatioSpoofState():
|
||||||
def announce(self, event = None):
|
def announce(self, event = None):
|
||||||
last_announce_data = self.announce_history_deq[-1]
|
last_announce_data = self.announce_history_deq[-1]
|
||||||
query_dict = build_query_string(self, last_announce_data, event)
|
query_dict = build_query_string(self, last_announce_data, event)
|
||||||
success = False
|
|
||||||
print(len(self.announce_info['list_of_lists']))
|
|
||||||
if (len(self.announce_info['list_of_lists']) > 0):
|
if (len(self.announce_info['list_of_lists']) > 0):
|
||||||
for tier_list in self.announce_info['list_of_lists']:
|
for tier_list in self.announce_info['list_of_lists']:
|
||||||
for item in tier_list:
|
for item in tier_list:
|
||||||
print(item)
|
return tracker_announce_request(item, query_dict)
|
||||||
return tracker_announce_request(item, query_dict)
|
|
||||||
success = True
|
|
||||||
break
|
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
url = self.announce_info['main']
|
url = self.announce_info['main']
|
||||||
ret = tracker_announce_request(url, query_dict)
|
return tracker_announce_request(url, query_dict)
|
||||||
success = True
|
|
||||||
return ret
|
raise Exception('Connection error with the tracker')
|
||||||
|
|
||||||
print('passou por aqui 22')
|
|
||||||
if success == False : raise Exception('Connection error with the tracker')
|
|
||||||
|
|
||||||
def __decrease_timer(self):
|
def __decrease_timer(self):
|
||||||
while True:
|
while True:
|
||||||
|
|
@ -136,7 +133,7 @@ def t_piecesize_b(data):
|
||||||
def next_announce_total_b(kb_speed, b_current, b_piece_size,s_time, b_total_limit = None):
|
def next_announce_total_b(kb_speed, b_current, b_piece_size,s_time, b_total_limit = None):
|
||||||
total = b_current + (kb_speed *1024 *s_time)
|
total = b_current + (kb_speed *1024 *s_time)
|
||||||
closest_piece_number = int(total / b_piece_size)
|
closest_piece_number = int(total / b_piece_size)
|
||||||
closest_piece_number = closest_piece_number + random.randint(-10,10)
|
closest_piece_number = closest_piece_number + random.randint(1,10)
|
||||||
next_announce = closest_piece_number *b_piece_size
|
next_announce = closest_piece_number *b_piece_size
|
||||||
if(b_total_limit is not None and next_announce > b_total_limit):
|
if(b_total_limit is not None and next_announce > b_total_limit):
|
||||||
return b_total_limit
|
return b_total_limit
|
||||||
|
|
@ -168,32 +165,33 @@ def build_announce_info(data):
|
||||||
raise Exception('No tcp/http tracker url found')
|
raise Exception('No tcp/http tracker url found')
|
||||||
return announce_info
|
return announce_info
|
||||||
|
|
||||||
def tracker_announce_request(url, query_dict):
|
def tracker_announce_request(url, query_string):
|
||||||
request = urllib.request.Request(url = f'{url}?{urllib.parse.urlencode(query_dict)}', headers= {'User-Agent' :'qBittorrent/4.0.3', 'Accept-Encoding':'gzip'})
|
request = urllib.request.Request(url = f'{url}?{query_string}', headers= {'User-Agent' :'qBittorrent/4.0.3', 'Accept-Encoding':'gzip'})
|
||||||
print(request.full_url)
|
response = urllib.request.urlopen(request).read()
|
||||||
print('tool')
|
decoded_response = bencode_parser.decode(response)
|
||||||
return 30
|
return decoded_response['interval']
|
||||||
#response = urllib.request.urlopen(request)
|
|
||||||
#return response.read()
|
|
||||||
|
|
||||||
def build_query_string(state:RatioSpoofState, curent_info, event):
|
def build_query_string(state:RatioSpoofState, curent_info, event):
|
||||||
query = {
|
query = {
|
||||||
'info_hash': state.info_hash_urlencoded,
|
|
||||||
'peer_id':state.peer_id,
|
'peer_id':state.peer_id,
|
||||||
'port':str(8999),
|
'port':8999,
|
||||||
'uploaded':str(curent_info['uploaded']),
|
'uploaded':curent_info['uploaded'],
|
||||||
'downloaded':str(curent_info['downloaded']),
|
'downloaded':curent_info['downloaded'],
|
||||||
'left':str(curent_info['left']),
|
'left':curent_info['left'],
|
||||||
'corrupt': str(0),
|
'corrupt': 0,
|
||||||
'key':str(state.key),
|
'key':state.key,
|
||||||
'event':event,
|
'event':event,
|
||||||
'numwant':str(200),
|
'numwant':state.numwant,
|
||||||
'compact':str(1),
|
'compact':1,
|
||||||
'no_peer_id': str(1),
|
'no_peer_id': 1,
|
||||||
'supportcrypto':str(1),
|
'supportcrypto':1,
|
||||||
'redundant':str(0)
|
'redundant':0
|
||||||
}
|
}
|
||||||
return urllib.parse.quote_plus(json.dumps(query))
|
|
||||||
|
if(event == None):
|
||||||
|
del(query['event'])
|
||||||
|
return f'info_hash={state.info_hash_urlencoded}&' + urllib.parse.urlencode(query)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -230,8 +228,6 @@ def read_file(f, args_downalod, args_upload):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
http.client.HTTPConnection.debuglevel = 1
|
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-t', required=True, metavar=('(TORRENT_PATH)'), help='path .torrent file' , type=argparse.FileType('rb'))
|
parser.add_argument('-t', required=True, metavar=('(TORRENT_PATH)'), help='path .torrent file' , type=argparse.FileType('rb'))
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue