summaryrefslogtreecommitdiff
path: root/proxy.py
diff options
context:
space:
mode:
Diffstat (limited to 'proxy.py')
-rw-r--r--proxy.py22
1 files changed, 12 insertions, 10 deletions
diff --git a/proxy.py b/proxy.py
index 93c1994..77356f5 100644
--- a/proxy.py
+++ b/proxy.py
@@ -22,7 +22,7 @@ BLOCKSIZE_STEP = 512 * KB
class Fetcher(asynchat.async_chat):
def __init__(self, reader, endpoint, url, header, range):
self.reader = reader
- self.proxy = ENDPOINTS(endpoint)
+ self.proxy = ENDPOINTS[endpoint]
self.url = url
self.header = header
self.range = range
@@ -56,7 +56,7 @@ class Fetcher(asynchat.async_chat):
self.pos += len(data)
if self.pos >= self.range[1]:
self.stop_time = time.time()
- self.start_fetcher(endpoint, self.time())
+ self.reader.start_fetcher(self.endpoint, self.time())
print self, "finished"
self.close_when_done()
elif self.state ==1: #header
@@ -92,9 +92,11 @@ class MultipleProxyReader(object):
self.write_pos = 0
self.buffer = ""
self.blocks = dict()
+ self.endpoints_time = []
+ self.endpoints_blocksize = []
for i in range(0,len(ENDPOINTS)):
- self.endpoints_time.append(1)
+ self.endpoints_time.append(BLOCKSIZE_FETCH/(200*KB))
self.endpoints_blocksize.append(BLOCKSIZE_FETCH)
for i in range(0,len(ENDPOINTS)):
@@ -125,20 +127,20 @@ class MultipleProxyReader(object):
self.find_next_data()
self.endpoints_time[endpoint] = time
- if max(self.endpoints_times[endpoint]) == time:
- self.endpoint_blocksize[endpoint] += BLOCKSIZE_STEP
- elif min(self.endpoints_times[endpoint]) == time:
- self.endpoint_blocksize[endpoint] -= BLOCKSIZE_STEP
+ if max(self.endpoints_time) == time:
+ self.endpoints_blocksize[endpoint] += BLOCKSIZE_STEP
+ elif min(self.endpoints_time) == time:
+ self.endpoints_blocksize[endpoint] -= BLOCKSIZE_STEP
if self.fetch_pos +1 <self.content_length:
print self, "start new fetcher"
start = self.fetch_pos
- if self.fetch_pos+self.endpoint_blocksize[endpoint] < self.content_length:
- self.fetch_pos += self.endpoint_blocksize[endpoint]
+ if self.fetch_pos+self.endpoints_blocksize[endpoint] < self.content_length:
+ self.fetch_pos += self.endpoints_blocksize[endpoint]
else:
self.fetch_pos = self.content_length
range = (start, self.fetch_pos-1)
- Fetcher(self, ENDPOINTS[endpoint], self.url, self.header, range)
+ Fetcher(self, endpoint, self.url, self.header, range)
def find_next_data(self):
if self.channel.is_closed: