| 29 | |
| 30 | |
| 31 | class XDCCRequest: |
| 32 | def __init__(self, bucket=None, options={}): |
| 33 | self.proxies = options.get('proxies', {}) |
| 34 | self.bucket = bucket |
| 35 | |
| 36 | self.fh = None |
| 37 | self.dccsock = None |
| 38 | |
| 39 | self.filesize = 0 |
| 40 | self.received = 0 |
| 41 | self.speeds = [0.0, 0.0, 0.0] |
| 42 | |
| 43 | self.sleep = 0.000 |
| 44 | self.last_recv_size = 0 |
| 45 | self.send_64bits_ack = False |
| 46 | |
| 47 | self.abort = False |
| 48 | |
| 49 | self.status_notify = None |
| 50 | |
| 51 | def createSocket(self): |
| 52 | # proxytype = None |
| 53 | # proxy = None |
| 54 | # if self.proxies.has_key("socks5"): |
| 55 | # proxytype = socks.PROXY_TYPE_SOCKS5 |
| 56 | # proxy = self.proxies["socks5"] |
| 57 | # elif self.proxies.has_key("socks4"): |
| 58 | # proxytype = socks.PROXY_TYPE_SOCKS4 |
| 59 | # proxy = self.proxies["socks4"] |
| 60 | # if proxytype: |
| 61 | # sock = socks.socksocket() |
| 62 | # t = _parse_proxy(proxy) |
| 63 | # sock.setproxy(proxytype, addr=t[3].split(":")[0], port=int(t[3].split(":")[1]), username=t[1], password=t[2]) |
| 64 | # else: |
| 65 | # sock = socket.socket() |
| 66 | # return sock |
| 67 | |
| 68 | sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) |
| 69 | # sock.setsockopt(socket.SOL_SOCKET, socket.SO_RCVBUF, 16384) |
| 70 | |
| 71 | return sock |
| 72 | |
| 73 | def _write_func(self, buf): |
| 74 | size = len(buf) |
| 75 | |
| 76 | self.received += size |
| 77 | |
| 78 | self.fh.write(buf) |
| 79 | |
| 80 | if self.bucket: |
| 81 | time.sleep(self.bucket.consumed(size)) |
| 82 | |
| 83 | else: |
| 84 | # Avoid small buffers, increasing sleep time slowly if buffer size gets smaller |
| 85 | # otherwise reduce sleep time percentequal (values are based on tests) |
| 86 | # So in general cpu time is saved without reducing bandwidth too much |
| 87 | |
| 88 | if size < self.last_recv_size: |