def report_periodic_vod_stats(self,playing_dslist): #print >>sys.stderr, time.asctime(),'-', "VOD Stats" self.counter += 1 if self.counter%self.interval == 0: event_reporter = get_reporter_instance() for ds in playing_dslist: dw = ds.get_download() b64_infohash = b64encode(dw.get_def().get_infohash()) vod_stats = ds.get_vod_stats() #if vod_stats_has_key("prebuf"): event_reporter.add_event(b64_infohash, "prebufp:%d" % vod_stats['prebuf']) # prebuffering time that was needed if vod_stats.has_key("stall"): event_reporter.add_event(b64_infohash, "stall:%d" % vod_stats['stall']) # time the player stalled if vod_stats.has_key("late"): event_reporter.add_event(b64_infohash, "late:%d" % vod_stats['late']) # number of pieces arrived after they were due if vod_stats.has_key("dropped"): event_reporter.add_event(b64_infohash, "dropped:%d" % vod_stats['dropped']) # number of pieces lost if vod_stats.has_key("pos"): event_reporter.add_event(b64_infohash, "pos:%d" % vod_stats['pos']) # playback position
def __init__(self, infohash, storage, picker, backlog, max_rate_period, numpieces, chunksize, measurefunc, snub_time, kickbans_ok, kickfunc, banfunc, scheduler = None): self.infohash = infohash self.b64_infohash = b64encode(infohash) self.storage = storage self.picker = picker self.backlog = backlog self.max_rate_period = max_rate_period self.measurefunc = measurefunc self.totalmeasure = Measure(max_rate_period*storage.piece_length/storage.request_size) self.numpieces = numpieces self.chunksize = chunksize self.snub_time = snub_time self.kickfunc = kickfunc self.banfunc = banfunc self.disconnectedseeds = {} self.downloads = [] self.perip = {} self.gotbaddata = {} self.kicked = {} self.banned = {} self.kickbans_ok = kickbans_ok self.kickbans_halted = False self.super_seeding = False self.endgamemode = False self.endgame_queued_pieces = [] self.all_requests = [] self.discarded = 0L self.download_rate = 0 # self.download_rate = 25000 # 25K/s test rate self.bytes_requested = 0 self.last_time = clock() self.queued_out = {} self.requeueing = False self.paused = False self.scheduler = scheduler # hack: we should not import this since it is not part of the # core nor should we import here, but otherwise we will get # import errors # # _event_reporter stores events that are logged somewhere... from Tribler.Core.Statistics.StatusReporter import get_reporter_instance self._event_reporter = get_reporter_instance() # check periodicaly self.scheduler(self.dlr_periodic_check, 1)
def run(self): if self.upnp_type > 0: self.upnp_wrap = UPnPWrapper.getInstance() self.upnp_wrap.register(self.locally_guessed_ext_ip) from Tribler.Core.Statistics.StatusReporter import get_reporter_instance reporter = get_reporter_instance() if self.upnp_wrap.test(self.upnp_type): reporter.add_event("UPnP", "Init'ed") try: shownerror=False # Get external IP address from firewall if self.upnp_type != 1: # Mode 1 doesn't support getting the IP address" ret = self.upnp_wrap.get_ext_ip() if ret == None: shownerror=True self.error_func(self.upnp_type,self.listen_port,0) else: self.got_ext_ip_func(ret) # Do open_port irrespective of whether get_ext_ip() # succeeds, UPnP mode 1 doesn't support get_ext_ip() # get_ext_ip() must be done first to ensure we have the # right IP ASAP. # Open TCP listen port on firewall ret = self.upnp_wrap.open(self.listen_port,iproto='TCP') if ret == False and not shownerror: self.error_func(self.upnp_type,self.listen_port,0) # Open UDP listen port on firewall ret = self.upnp_wrap.open(self.listen_port,iproto='UDP') if ret == False and not shownerror: self.error_func(self.upnp_type,self.listen_port,0,listenproto='UDP') reporter.add_event("UPnP", "UDP:%d" % ret) except UPnPError,e: self.error_func(self.upnp_type,self.listen_port,1,e) else: reporter.add_event("UPnP", "Init failed") if self.upnp_type != 3: self.error_func(self.upnp_type,self.listen_port,2) elif DEBUG: print >>sys.stderr,time.asctime(),'-', "upnp: thread: Initialization failed, but didn't report error because UPnP mode 3 is now enabled by default"
def __init__(self, rawserver, port = 0): self.rawserver = rawserver self.socket = rawserver.create_udpsocket(port, "0.0.0.0") self.connections = {} self.known_peers = {} self.nat_type = UDPHandler.NAT_UNKNOWN self.filter_type = UDPHandler.FILTER_UNKNOWN self.max_connections = 100 self.connect_threshold = 75 self.recv_unsolicited = 0 self.recv_connect_total = 0 self.recv_address = 0 self.recv_different_address = 0 self.sendqueue = deque([]) self.last_connect = 0 self.last_info_dump = time.time() self.natfw_version = 1 self.keepalive_intvl = 100 self.done = False self.reporter = None rawserver.start_listening_udp(self.socket, self) # Contact NATSwarm tracker peer after 5 seconds if port == 9473: self.tracker = True # Tracker needs a known ID, so set it to all zero self.id = "\0\0\0\0" # Tracker should accept many more connections than other nodes self.max_connections = 1000 rawserver.add_task(self.check_for_timeouts, 10) else: self.tracker = False # Create a 4 byte random ID self.id = (chr(random.getrandbits(8)) + chr(random.getrandbits(8)) + chr(random.getrandbits(8)) + chr(random.getrandbits(8))) if DEBUG: debug("My ID: %s" % self.id.encode('hex')) rawserver.add_task(self.bootstrap, 5) TimeoutFinder.TimeoutFinder(rawserver, False, self.timeout_report) TimeoutFinder.TimeoutFinder(rawserver, True, self.timeout_report) from Tribler.Core.Statistics.StatusReporter import get_reporter_instance if not DEBUG: self.reporter = get_reporter_instance() if self.reporter: my_wan_ip = None if sys.platform == 'win32': try: import os for line in os.popen("netstat -nr").readlines(): words = line.split() if words[0] == '0.0.0.0': my_wan_ip = words[3] break except: pass else: my_wan_ip = guessip.get_my_wan_ip() if my_wan_ip == None: my_wan_ip = 'Unknown' self.reporter.add_event("UDPPuncture", "ID:%s;IP:%s" % (self.id.encode('hex'), my_wan_ip))
def OnInitBase(self): """ To be wrapped in a OnInit() method that returns True/False """ # Normal startup # Read config state_dir = Session.get_default_state_dir('.'+self.appname) self.utility = UtilityStub(self.installdir,state_dir) self.utility.app = self print >>sys.stderr,time.asctime(),'-', self.utility.lang.get('build') self.iconpath = os.path.join(self.installdir,LIBRARYNAME,'Images',self.appname+'Icon.ico') self.logopath = os.path.join(self.installdir,LIBRARYNAME,'Images',self.appname+'Logo.png') # Start server for instance2instance communication self.i2is = Instance2InstanceServer(self.i2iport,self,timeout=(24.0*3600.0)) # The playerconfig contains all config parameters that are not # saved by checkpointing the Session or its Downloads. self.load_playerconfig(state_dir) # Install systray icon # Note: setting this makes the program not exit when the videoFrame # is being closed. self.tbicon = PlayerTaskBarIcon(self,self.iconpath) # Start Tribler Session cfgfilename = Session.get_default_config_filename(state_dir) if DEBUG: print >>sys.stderr,time.asctime(),'-', "main: Session config",cfgfilename try: self.sconfig = SessionStartupConfig.load(cfgfilename) print >>sys.stderr,time.asctime(),'-', "main: Session saved port",self.sconfig.get_listen_port(),cfgfilename except: print_exc() self.sconfig = SessionStartupConfig() self.sconfig.set_install_dir(self.installdir) self.sconfig.set_state_dir(state_dir) self.sconfig.set_listen_port(self.sport) self.configure_session() self.s = Session(self.sconfig) self.s.set_download_states_callback(self.sesscb_states_callback) # self.reporter = Reporter( self.sconfig ) if RATELIMITADSL: self.ratelimiter = UserDefinedMaxAlwaysOtherwiseEquallyDividedRateManager() self.ratelimiter.set_global_max_speed(DOWNLOAD,DOWNLOADSPEED) self.ratelimiter.set_global_max_speed(UPLOAD,90) # Arno: For extra robustness, ignore any errors related to restarting try: # Load all other downloads in cache, but in STOPPED state self.s.load_checkpoint(initialdlstatus=DLSTATUS_STOPPED) except: print_exc() # Start remote control self.i2is.start() # report client version from Tribler.Core.Statistics.StatusReporter import get_reporter_instance reporter = get_reporter_instance() reporter.add_event("client-startup", "version:" + self.utility.lang.get("version")) reporter.add_event("client-startup", "build:" + self.utility.lang.get("build")) reporter.add_event("client-startup", "build_date:" + self.utility.lang.get("build_date"))
def __init__(self,infohash,metainfo,kvconfig,multihandler,get_extip_func,listenport,videoanalyserpath,vodfileindex,set_error_func,pstate,lmvodeventcallback,lmhashcheckcompletecallback): self.dow = None self.set_error_func = set_error_func self.videoinfo = None self.videostatus = None self.lmvodeventcallback = lmvodeventcallback self.lmhashcheckcompletecallback = lmhashcheckcompletecallback self.logmsgs = [] self._hashcheckfunc = None self._getstatsfunc = None self.infohash = infohash self.b64_infohash = b64encode(infohash) try: self.dldoneflag = Event() self.dlrawserver = multihandler.newRawServer(infohash,self.dldoneflag) self.lmvodeventcallback = lmvodeventcallback if pstate is not None: self.hashcheckfrac = pstate['dlstate']['progress'] else: self.hashcheckfrac = 0.0 self.peerid = createPeerID() # LOGGING from Tribler.Core.Statistics.StatusReporter import get_reporter_instance event_reporter = get_reporter_instance() event_reporter.add_event(self.b64_infohash, "peerid:%s" % b64encode(self.peerid)) #print >>sys.stderr,time.asctime(),'-', "SingleDownload: __init__: My peer ID is",`peerid` self.dow = BT1Download(self.hashcheckprogressfunc, self.finishedfunc, self.fatalerrorfunc, self.nonfatalerrorfunc, self.logerrorfunc, self.dldoneflag, kvconfig, metainfo, infohash, self.peerid, self.dlrawserver, get_extip_func, listenport, videoanalyserpath ) file = self.dow.saveAs(self.save_as) #if DEBUG: # print >>sys.stderr,time.asctime(),'-', "SingleDownload: dow.saveAs returned",file # Set local filename in vodfileindex if vodfileindex is not None: # Ric: for SVC the index is a list of indexes index = vodfileindex['index'] if type(index) == ListType: svc = len(index) > 1 else: svc = False if svc: outpathindex = self.dow.get_dest(index[0]) else: if index == -1: index = 0 outpathindex = self.dow.get_dest(index) vodfileindex['outpath'] = outpathindex self.videoinfo = vodfileindex if 'live' in metainfo['info']: authparams = metainfo['info']['live'] else: authparams = None if svc: self.videostatus = SVCVideoStatus(metainfo['info']['piece length'],self.dow.files,vodfileindex,authparams) else: self.videostatus = VideoStatus(metainfo['info']['piece length'],self.dow.files,vodfileindex,authparams) self.videoinfo['status'] = self.videostatus self.dow.set_videoinfo(vodfileindex,self.videostatus) #if DEBUG: # print >>sys.stderr,time.asctime(),'-', "SingleDownload: setting vodfileindex",vodfileindex # RePEX: Start in RePEX mode if kvconfig['initialdlstatus'] == DLSTATUS_REPEXING: if pstate is not None and pstate.has_key('dlstate'): swarmcache = pstate['dlstate'].get('swarmcache',{}) else: swarmcache = {} self.repexer = RePEXer(self.infohash, swarmcache) else: self.repexer = None if pstate is None: resumedata = None else: # Restarting download resumedata=pstate['engineresumedata'] self._hashcheckfunc = self.dow.initFiles(resumedata=resumedata) except Exception,e: self.fatalerrorfunc(e)
def __init__(self, connecter, raw_server, my_id, max_len, schedulefunc, keepalive_delay, download_id, measurefunc, config): self.raw_server = raw_server self.connecter = connecter self.my_id = my_id self.max_len = max_len self.schedulefunc = schedulefunc self.keepalive_delay = keepalive_delay self.download_id = download_id self.measurefunc = measurefunc self.config = config self.connections = {} self.banned = {} self.to_connect = Set() self.trackertime = 0 self.paused = False if self.config['max_connections'] == 0: self.max_connections = 2 ** 30 else: self.max_connections = self.config['max_connections'] """ In r529 there was a problem when a single Windows client would connect to our text-based seeder (i.e. btlaunchmany) with no other clients present. Apparently both the seeder and client would connect to eachother simultaneously, but not end up with a good connection, halting the client. Arno, 2006-03-10: Reappears in ~r890, fixed in r892. It appears to be a problem of writing to a nonblocking socket before it signalled it is ready for writing, although the evidence is inconclusive. Arno: 2006-12-15: Reappears in r2319. There is some weird socket problem here. Using Python 2.4.4 doesn't solve it. The problem I see here is that as soon as we register at the tracker, the single seeder tries to connect to us. He succeeds, but after a short while the connection appears to be closed by him. We then wind up with no connection at all and have to wait until we recontact the tracker. My workaround is to refuse these initial connections from the seeder and wait until I've started connecting to peers based on the info I got from the tracker before accepting remote connections. Arno: 2007-02-16: I think I finally found it. The Tribler tracker (BitTornado/BT1/track.py) will do a NAT check (BitTornado/BT1/NATCheck) by default, which consists of initiating a connection and then closing it after a good BT handshake was received. The solution now is to make sure we check IP and port to identify existing connections. I already added that 2006-12-15, so I just removed the restriction on initial connections, which are superfluous. """ self.rerequest = None # 2fastbt_ self.toofast_banned = {} self.coordinator_ip = None # _2fastbt # hack: we should not import this since it is not part of the # core nor should we import here, but otherwise we will get # import errors # # _event_reporter stores events that are logged somewhere... from Tribler.Core.Statistics.StatusReporter import get_reporter_instance self._event_reporter = get_reporter_instance() # the addresses that have already been reported self._known_addresses = {} schedulefunc(self.send_keepalives, keepalive_delay) # RePEX: added repexer field. # Note: perhaps call it observer in the future and make the # download engine more observable? self.repexer = None