Skip to content

Commit

Permalink
- Working on test_seeding.py. Problem with concept: TorrentDef inf do…
Browse files Browse the repository at this point in the history
…esn't

  require source files to be in a specific dir. Download class expects them
  in dest_dir/XXX.



git-svn-id: https://svn.tribler.org/abc/branches/arno/d07-09-21-fastgui-from-mb-r5526@6095 001aeff7-3401-0410-a489-f7902fc005dd
  • Loading branch information
arno committed Nov 9, 2007
1 parent d5d0aa4 commit 2179791
Show file tree
Hide file tree
Showing 13 changed files with 551 additions and 122 deletions.
9 changes: 6 additions & 3 deletions BitTornado/BT1/Connecter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@
True = 1
False = 0

DEBUG = False
DEBUG_NORMAL_MSGS = False
DEBUG = True
DEBUG_NORMAL_MSGS = True

UNAUTH_PERMID_PERIOD = 3600

Expand Down Expand Up @@ -472,9 +472,12 @@ def __init__(self, make_upload, downloader, choker, numpieces,
self.round = 0
self.mylistenport = mylistenport
self.infohash = infohash
self.overlay_enabled = 1
self.overlay_enabled = 0
if 'overlay' in self.config:
self.overlay_enabled = self.config['overlay']

print >>sys.stderr,"connecter: Enabling/Disabling overlay",self.overlay_enabled

self.ut_pex_enabled = 0
if 'ut_pex_max_addrs_from_peer' in self.config:
self.ut_pex_max_addrs_from_peer = self.config['ut_pex_max_addrs_from_peer']
Expand Down
13 changes: 9 additions & 4 deletions BitTornado/BT1/Encrypter.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
True = 1
False = 0

DEBUG = False
DEBUG = True

if sys.platform == 'win32':
# On windows XP SP2 we can't initiate more than 10 conns/second
Expand Down Expand Up @@ -209,12 +209,17 @@ def read_peer_id(self, s):
else: # locat init with remote id
if s != self.id:
if DEBUG:
print >>sys.stderr,"Encoder.Connection: s != self.id, returning None"
print >>sys.stderr,"Encoder.Connection: read_peer_id: s != self.id, returning None"
return None
self.complete = self.Encoder.got_id(self)

if DEBUG:
print >>sys.stderr,"Encoder.Connection: read_peer_id: complete is",self.complete


if not self.complete:
if DEBUG:
print >>sys.stderr,"Encoder.Connection: self not complete!!!, returning None"
print >>sys.stderr,"Encoder.Connection: read_peer_id: self not complete!!!, returning None"
return None
if self.locally_initiated:
self.connection.write(self.Encoder.my_id)
Expand Down Expand Up @@ -251,7 +256,7 @@ def _auto_close(self):
def close(self):
if DEBUG:
print >>sys.stderr,"encoder: closing connection",self.get_ip()
##print_stack()
print_stack()
if not self.closed:
self.connection.close()
self.sever()
Expand Down
2 changes: 1 addition & 1 deletion BitTornado/BT1/Rerequester.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def getpid():
True = 1
False = 0

DEBUG = False
DEBUG = True
DEBUG_DHT = False

mapbase64 = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz.-'
Expand Down
10 changes: 7 additions & 3 deletions BitTornado/BT1/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
True = 1
False = 0

DEBUG=False
DEBUG=True

from Tribler.API.defaults import trackerdefaults

Expand Down Expand Up @@ -294,12 +294,12 @@ def huphandler(signum, frame, self = self):
self.Filter = Filter(rawserver.add_task)

aggregator = config['tracker_aggregator']
if aggregator == '0':
if aggregator == 0:
self.is_aggregator = False
self.aggregator_key = None
else:
self.is_aggregator = True
if aggregator == '1':
if aggregator == 1:
self.aggregator_key = None
else:
self.aggregator_key = aggregator
Expand Down Expand Up @@ -805,6 +805,7 @@ def params(key, default = None, l = paramslist):
rsize = self.add_data(infohash, event, ip, paramslist)

except ValueError, e:
print_exc()
return (400, 'Bad Request', {'Content-Type': 'text/plain'},
'you sent me garbage - ' + str(e))

Expand Down Expand Up @@ -908,6 +909,9 @@ def parse_allowed(self,source=None):
( self.allowed, self.allowed_dir_files, self.allowed_dir_blocked,
added, garbage2 ) = r

print >>sys.stderr,"tracker: parse_allowed: Found new",`added`


self.state['allowed'] = self.allowed
self.state['allowed_dir_files'] = self.allowed_dir_files

Expand Down
2 changes: 1 addition & 1 deletion BitTornado/SocketHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
True = 1
False = 0

DEBUG = False
DEBUG = True

all = POLLIN | POLLOUT

Expand Down
2 changes: 2 additions & 0 deletions BitTornado/zurllib.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from gzip import GzipFile
from StringIO import StringIO
from __init__ import product_name, version_short
from traceback import print_exc

VERSION = product_name+'/'+version_short
MAX_REDIRECTS = 10
Expand Down Expand Up @@ -58,6 +59,7 @@ def _open(self, url):
'Accept-Encoding': 'gzip' } )
self.response = self.connection.getresponse()
except HTTPException, e:
print_exc()
raise IOError, ('http error', str(e))
status = self.response.status
if status in (301, 302):
Expand Down
23 changes: 17 additions & 6 deletions Tribler/API/Impl/DownloadImpl.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import sys
import os
import copy
import binascii
from threading import currentThread
from traceback import print_exc,print_stack

Expand Down Expand Up @@ -39,24 +40,34 @@ def setup(self,dcfg=None,pstate=None,lmcreatedcallback=None,lmvodplayablecallbac
infohash = self.tdef.get_infohash()
metainfo = self.tdef.get_metainfo()
usingitracker = False
if metainfo['announce'] == itrackerurl:

print >>sys.stderr,"Download: setup: internal tracker?",metainfo['announce'],itrackerurl,"#"

if itrackerurl.endswith('/'):
slashless = itrackerurl[:-1]
else:
slashless = itrackerurl
if metainfo['announce'] == itrackerurl or metainfo['announce'] == slashless:
usingitracker = True
elif 'announce-list' in metainfo:
for tier in metainfo['announce-list']:
if itrackerurl in tier:
if itrackerurl in tier or slashless in tier:
usingitracker = True
break

if usingitracker:
print >>sys.stderr,"Download: setup: Using internal tracker"
# Copy .torrent to state_dir/itracker so the tracker thread
# finds it and accepts peer registrations for it.
#
trackerdir = os.path.join(self.sessconfig['state_dir'],STATEDIR_ITRACKER_DIR)
trackerdir = self.session.get_internal_tracker_dir()
basename = binascii.hexlify(infohash)+'.torrent' # ignore .tribe stuff, not vital
filename = os.path.join(trackerdir,basename)
self.tdef.save(filename)
# Bring to attention of Tracker thread
session.lm.tracker_rescan_dir()
self.session.lm.tracker_rescan_dir()
else:
print >>sys.stderr,"Download: setup: Not using internal tracker"

# Copy dlconfig, from default if not specified
if dcfg is None:
Expand All @@ -66,7 +77,7 @@ def setup(self,dcfg=None,pstate=None,lmcreatedcallback=None,lmvodplayablecallbac
self.dlconfig = copy.copy(cdcfg.dlconfig)

# TODO: copy sessconfig into dlconfig?

print >>sys.stderr,"Download: setup: overlay present",('overlay' in self.dlconfig)

self.set_filepieceranges()

Expand Down Expand Up @@ -278,7 +289,7 @@ def network_get_persistent_state(self):
# Reset unpicklable params
dlconfig['vod_usercallback'] = None
dlconfig['dlmode'] = DLMODE_NORMAL # no callback, no VOD
pstate['dscfg'] = DownloadStartupConfig(dlconfig=dlconfig)
pstate['dlconfig'] = dlconfig

pstate['dlstate'] = {}
ds = self.network_get_state(None,False,sessioncalling=True)
Expand Down
7 changes: 5 additions & 2 deletions Tribler/API/Impl/maketorrent.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
from Tribler.unicode import str2unicode
from Tribler.API.Impl.miscutils import parse_playtime_to_secs

from Tribler.API.defaults import tdefdictdefaults

ignore = [] # Arno: was ['core', 'CVS']

DEBUG = True
Expand Down Expand Up @@ -411,16 +413,17 @@ def copy_metainfo_to_input(metainfo,input):
input[key] = metainfo['info'][key]

# Note: don't know inpath, set to outpath
if 'length' in metainfo:
if 'length' in metainfo['info']:
outpath = metainfo['info']['name']
if 'playtime' in metainfo['info']:
playtime = metainfo['info']['playtime']
else:
playtime = None
length = metainfo['length']
length = metainfo['info']['length']
d = {'inpath':outpath,'outpath':outpath,'playtime':playtime,'length':length}
input['files'].append(d)
else: # multi-file torrent
files = metainfo['files']
for file in files:
outpath = pathlist2filename(file['path'])
if 'playtime' in file:
Expand Down
19 changes: 7 additions & 12 deletions Tribler/API/launchmanycore.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def __init__(self,session,sesslock):
#self.mypref_db = MyPreferenceDBHandler()

# add task for tracker checking
if not config['torrent_checking']:
if config['torrent_checking']:
self.rawserver.add_task(self.torrent_checking, self.torrent_checking_period)


Expand All @@ -164,8 +164,6 @@ def add(self,tdef,dscfg,pstate=None):
pstate = self.load_download_pstate_noexc(infohash)
if pstate is not None:
print >>sys.stderr,"tlm: add: pstate is",dlstatus_strings[pstate['dlstate']['status']],pstate['dlstate']['progress']
# Override saved DownloadStartupConfig, just in case
pstate['dscfg'] = dscfg

# Store in list of Downloads, always.
self.downloads[d.get_def().get_infohash()] = d
Expand Down Expand Up @@ -248,7 +246,7 @@ def rawserver_keepalive(self):
#
def tracker_rescan_dir(self):
if self.internaltracker is not None:
self.internaltracker.parse_allowed(source='TorrentMaker')
self.internaltracker.parse_allowed(source='Session')

def set_activity(self,type):
pass # TODO Jelle
Expand Down Expand Up @@ -357,10 +355,11 @@ def resume_download(self,filename):
pstate = self.load_download_pstate(filename)

print >>sys.stderr,"tlm: load_checkpoint: pstate is",dlstatus_strings[pstate['dlstate']['status']],pstate['dlstate']['progress']
tdef = triblerAPI.TorrentDef._create(pstate['metainfo'])
tdef = triblerAPI.TorrentDef.load_from_dict(pstate['metainfo'])

# Activate
self.add(tdef,pstate['dscfg'],pstate)
dscfg = DownloadStartupConfig(dlconfig=pstate['dlconfig'])
self.add(tdef,dscfg,pstate)
except Exception,e:
# TODO: remove saved checkpoint?
self.rawserver_nonfatalerrorfunc(e)
Expand Down Expand Up @@ -545,12 +544,8 @@ def __init__(self,infohash,metainfo,kvconfig,multihandler,listenport,videoanalys

self.logmsgs = []

"""
class BT1Download:
def __init__(self, statusfunc, finfunc, errorfunc, excfunc, doneflag,
config, response, infohash, id, rawserver, port, play_video,
videoinfo, progressinf, videoanalyserpath, appdataobj = None, dht = None):
"""
print >>sys.stderr,"SingleDownload: __init__: overlay present",('overlay' in kvconfig)

self.dow = BT1Download(self.hashcheckprogressfunc,
self.finishedfunc,
self.fatalerrorfunc,
Expand Down
3 changes: 2 additions & 1 deletion test/API/test_api.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@
PYTHONPATH=../..:"$PYTHONPATH"
export PYTHONPATH

python test_tdef.py
#python test_tdef.py
python test_seeding.py

Loading

0 comments on commit 2179791

Please sign in to comment.