/[gentoo-src]/bittorrent/bt_daemon.py
Gentoo

Diff of /bittorrent/bt_daemon.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.2 Revision 1.3
1#!/usr/bin/python -O 1#!/usr/bin/python -O
2# $Id: bt_daemon.py,v 1.3 2004/05/02 01:41:19 carpaski Exp $
2 3
3# Greatly modified by carpaski@gentoo.org 4# Greatly modified by carpaski@gentoo.org
4# btdownloadheadless written by Bram Cohen 5# btdownloadheadless written by Bram Cohen
5# see LICENSE.txt for license information 6# see LICENSE.txt for license information
6 7
7import os 8import os
8os.nice(5) 9os.nice(5)
9 10
10# This is 2^x ... put the x below -- Chunk size for sha1 -- 18 == 256k 11# This is 2^x ... put the x below -- Chunk size for sha1 -- 18 == 256k
11piece_size_pow2 = 18 12piece_size_pow2 = 18
12MAX_STARTING_THREADS = 15 13MAX_STARTING_THREADS = 10
13LOOP_MOD = 4320 # Rotating value (for logs) 14LOOP_MOD = 4320 # Rotating value (for logs)
14ROTATE_LOGS = 0 # Make one log or roate into loop_mod logs 15ROTATE_LOGS = 0 # Make one log or roate into loop_mod logs
15cycle_sleep = 20 16cycle_sleep = 20
16spawn_thread_delay = 0 17spawn_thread_delay = 0
17debug = 0 18debug = 0
257 max_down_rate = threads[t][1].downRate 258 max_down_rate = threads[t][1].downRate
258 max_down_file = threads[t][1].file[:] 259 max_down_file = threads[t][1].file[:]
259 260
260 if os.path.exists(".stats"): 261 if os.path.exists(".stats"):
261 if ROTATE_LOGS: 262 if ROTATE_LOGS:
262 filename = "bt_daemon-%d-%4d.stats" % (os.getpid(),loop_val) 263 filename = "bt_daemon-%d-%04d.stats" % (os.getpid(),loop_val)
263 makenew = 1 264 makenew = 1
264 else: 265 else:
265 filename = "bt_daemon-%d.stats" % (os.getpid()) 266 filename = "bt_daemon-%d.stats" % (os.getpid())
266 makenew = 0 267 makenew = 0
267 writemsg("",filename,overwrite=makenew) 268 writemsg("",filename,overwrite=makenew)
269 writemsg("Seeding: %d" % (completed) ,filename) 270 writemsg("Seeding: %d" % (completed) ,filename)
270 writemsg("Fetching: %d(%d)" % (fetching,stalled) ,filename) 271 writemsg("Fetching: %d(%d)" % (fetching,stalled) ,filename)
271 writemsg("Total up: %.3f MB" % (totalup) ,filename) 272 writemsg("Total up: %.3f MB" % (totalup) ,filename)
272 writemsg("UpRate: %.2f k/s" % (rateup) ,filename) 273 writemsg("UpRate: %.2f k/s" % (rateup) ,filename)
273 writemsg("UpMaxNow: %.2f k/s '%s'" % (max_up_rate,max_up_file) ,filename) 274 writemsg("UpMaxNow: %.2f k/s '%s'" % (max_up_rate,max_up_file) ,filename)
274 writemsg("UpAbsMax: %.2f k/s" % (absmax_upRate) ,filename) 275 writemsg("UpAbsMax: %.2f k/s '%s'" % (absmax_upRate,absmax_upFile) ,filename)
275 writemsg("DownRate: %.2f k/s" % (ratedown) ,filename) 276 writemsg("DownRate: %.2f k/s" % (ratedown) ,filename)
276 writemsg("DownBest: %.2f k/s '%s'" % (max_down_rate,max_down_file) ,filename) 277 writemsg("DownBest: %.2f k/s '%s'" % (max_down_rate,max_down_file) ,filename)
277 writemsg("",filename) 278 writemsg("",filename)
278 279
279 for t in torrents: 280 for t in torrents:
282 print "Starting torrent [%s]: %s" % (ctime(),t) 283 print "Starting torrent [%s]: %s" % (ctime(),t)
283 h = HeadlessDisplayer() 284 h = HeadlessDisplayer()
284 try: 285 try:
285 if not os.path.isdir(file_base+"/"+os.path.dirname(t)): 286 if not os.path.isdir(file_base+"/"+os.path.dirname(t)):
286 os.makedirs(file_base+"/"+os.path.dirname(t)) 287 os.makedirs(file_base+"/"+os.path.dirname(t))
288 download_args = [
289 # responsefile -> Torrent filename
290 '--responsefile', torrent_base+"/"+t+".torrent",
291 # saveas -> Real filename
292 '--saveas', file_base+"/"+t,
293 # max_slice_length -> How much we can get in a single request
294 '--max_slice_length', "65536",
295 # timeout_check_interval -> Time between timeout checks
296 '--timeout_check_interval', '30',
297 # timeout -> How long until we time out a connection
298 '--timeout', '120',
299 # minport -> Lowest port allowed for files
300 '--minport', '6881',
301 # maxport -> Highest port allowed for files
302 '--maxport', '7881',
303 # request_backlog -> How many requests per pipe do we hold
304 '--request_backlog', '20',
305 # download_slice_size -> How much do we request?
306 '--download_slice_size', '65536',
307 # max_uploads -> How many do we serve out?
308 '--max_uploads', '20',
309 # check_hashes -> Do we check the on-disk files before joining?
310 '--check_hashes', '0'
311 ]
287 t_thread = Thread(target=download,name="BitTorrent::"+t,args=(['--responsefile', torrent_base+"/"+t+".torrent", '--saveas', file_base+"/"+t], h.chooseFile, h.display, h.finished, h.error, Event(), cols)) 312 t_thread = Thread(target=download,name="BitTorrent::"+t,args=(download_args, h.chooseFile, h.display, h.finished, h.error, Event(), cols))
288 threads[t] = [t_thread,h] 313 threads[t] = [t_thread,h]
289 t_thread.start() 314 t_thread.start()
290 sleep(spawn_thread_delay) 315 sleep(spawn_thread_delay)
291 except Exception, e: 316 except Exception, e:
292 print "Failed to start thread: %s" % (t) 317 print "Failed to start thread: %s" % (t)

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.20