def got_have(self, piece, connection=None): if DEBUG: print >>sys.stderr,"PiecePickerStreaming: got_have:",piece self.maxhave = max(self.maxhave,piece) PiecePicker.got_have( self, piece, connection ) if self.transporter: self.transporter.got_have( piece ) if self.is_interesting(piece): self.peer_connections[connection]["interesting"][piece] = 1
def got_have(self, piece, connection=None): # if DEBUG: # print >>sys.stderr,"PiecePickerStreaming: got_have:",piece self.maxhave = max(self.maxhave,piece) PiecePicker.got_have( self, piece, connection ) if self.transporter: self.transporter.got_have( piece ) if self.is_interesting(piece): self.peer_connections[connection]["interesting"][piece] = 1
def got_have(self, piece, connection=None): # if DEBUG: # print >>sys.stderr,"PiecePickerStreaming: got_have:",piece self.maxhave = max(self.maxhave,piece) # Arno, 2010-04-15: STBSPEED Disabled, does nothing but stats. #if self.transporter: # self.transporter.got_have( piece ) PiecePicker.got_have(self,piece,connection) if self.is_interesting(piece): self.peer_connections[connection]["interesting"][piece] = 1
def complete(self, piece): if DEBUG: print >>sys.stderr,"PiecePickerStreaming: complete:",piece PiecePicker.complete( self, piece ) if self.transporter: self.transporter.complete( piece ) try: del self.outstanding[piece] except: pass # don't consider this piece anymore for d in self.peer_connections.itervalues(): d["interesting"].pop(piece,0)
def complete(self, piece): # if DEBUG: # print >>sys.stderr,"PiecePickerStreaming: complete:",piece PiecePicker.complete( self, piece ) if self.transporter: self.transporter.complete( piece ) for request in self.outstanding_requests.keys(): if request[0] == piece: del self.outstanding_requests[request] # don't consider this piece anymore for d in self.peer_connections.itervalues(): d["interesting"].pop(piece,0)
def complete(self, piece): # if DEBUG: # print >>sys.stderr,"PiecePickerStreaming: complete:",piece PiecePicker.complete(self, piece) if self.transporter: self.transporter.complete(piece) for request in self.outstanding_requests.keys(): if request[0] == piece: del self.outstanding_requests[request] # don't consider this piece anymore for d in self.peer_connections.itervalues(): d["interesting"].pop(piece, 0)
def next(self, haves, wantfunc, sdownload, complete_first=False, slowpieces=[], willrequest=True, connection=None): def newwantfunc(piece): #print >>sys.stderr,"S",self.streaming_piece_filter( piece ),"!sP",not (piece in slowpieces),"w",wantfunc( piece ) return not (piece in slowpieces) and wantfunc(piece) # fallback: original piece picker p = PiecePicker.next(self, haves, newwantfunc, sdownload, complete_first, slowpieces=slowpieces, willrequest=willrequest, connection=connection) if DEBUGPP and self.videostatus.prebuffering: print >> sys.stderr, "PiecePickerStreaming: original PP.next returns", p if p is None and not self.videostatus.live_streaming: # When the file we selected from a multi-file torrent is complete, # we won't request anymore pieces, so the normal way of detecting # we're done is not working and we won't tell the video player # we're playable. Do it here instead. self.transporter.notify_playable() return p
def get_valid_range_iterator(self): if self.videostatus.live_streaming and self.videostatus.get_live_startpos() is None: # Not hooked in, so cannot provide a sensible download range #print >>sys.stderr,"PiecePickerStreaming: Not hooked in, valid range set to total" return PiecePicker.get_valid_range_iterator(self) #print >>sys.stderr,"PiecePickerStreaming: Live hooked in, or VOD, valid range set to subset" first,last = self.videostatus.download_range() return self.videostatus.generate_range((first,last))
def get_valid_range_iterator(self): if self.videostatus.live_streaming and self.videostatus.get_live_startpos() is None: # Not hooked in, so cannot provide a sensible download range #print >>sys.stderr,time.asctime(),'-', "PiecePickerStreaming: Not hooked in, valid range set to total" return PiecePicker.get_valid_range_iterator(self) #print >>sys.stderr,time.asctime(),'-', "PiecePickerStreaming: Live hooked in, or VOD, valid range set to subset" first,last = self.videostatus.download_range() return self.videostatus.generate_range((first,last))
def __init__(self, numpieces, rarest_first_cutoff = 1, rarest_first_priority_cutoff = 3, priority_step = 20, piecesize = 0): PiecePicker.__init__( self, numpieces, rarest_first_cutoff, rarest_first_priority_cutoff, priority_step) # maximum existing piece number, to avoid scanning beyond it in next() self.maxhave = 0 # some statistics self.stats = {} self.stats["high"] = 0 self.stats["mid"] = 0 self.stats["low"] = 0 # playback module self.transporter = None # self.outstanding_requests contains (piece-id, begin, # length):timestamp pairs for each outstanding request. self.outstanding_requests = {} # The playing_delay and buffering_delay give three values # (min, max, offeset) in seconds. # # The min tells how long before the cancel policy is allowed # to kick in. We can not expect to receive a piece instantly, # so we have to wait this time before having a download speed # estimation. # # The max tells how long before we cancel the request. The # request may also be canceled because the chunk will not be # completed given the current download speed. # # The offset gives a grace period that is taken into account # when choosing to cancel a request. For instance, when the # peer download speed is too low to receive the chunk within 10 # seconds, a grace offset of 15 would ensure that the chunk is # NOT canceled (useful while buffering) self.playing_delay = (5, 20, -0.5) self.buffering_delay = (7.5, 30, 10) # Arno, 2010-04-20: STBSPEED: is_interesting is now a variable. self.is_interesting = self.is_interesting_normal
def __init__(self, numpieces, rarest_first_cutoff=1, rarest_first_priority_cutoff=3, priority_step=20, piecesize=0): PiecePicker.__init__(self, numpieces, rarest_first_cutoff, rarest_first_priority_cutoff, priority_step) # maximum existing piece number, to avoid scanning beyond it in next() self.maxhave = 0 # some statistics self.stats = {} self.stats["high"] = 0 self.stats["mid"] = 0 self.stats["low"] = 0 # playback module self.transporter = None # self.outstanding_requests contains (piece-id, begin, # length):timestamp pairs for each outstanding request. self.outstanding_requests = {} # The playing_delay and buffering_delay give three values # (min, max, offeset) in seconds. # # The min tells how long before the cancel policy is allowed # to kick in. We can not expect to receive a piece instantly, # so we have to wait this time before having a download speed # estimation. # # The max tells how long before we cancel the request. The # request may also be canceled because the chunk will not be # completed given the current download speed. # # The offset gives a grace period that is taken into account # when choosing to cancel a request. For instance, when the # peer download speed is to low to receive the chunk within 10 # seconds, a grace offset of 15 would ensure that the chunk is # NOT canceled (usefull while buffering) self.playing_delay = (5, 20, -0.5) self.buffering_delay = (7.5, 30, 10)
def __init__(self, numpieces, rarest_first_cutoff = 1, rarest_first_priority_cutoff = 3, priority_step = 20, helper = None, rate_predictor = None, piecesize = 0): PiecePicker.__init__( self, numpieces, rarest_first_cutoff, rarest_first_priority_cutoff, priority_step, helper, rate_predictor ) self.videostatus = None # maximum existing piece number, to avoid scanning beyond it in next() self.maxhave = 0 # some statistics self.stats = {} self.stats["high"] = 0 self.stats["mid"] = 0 self.stats["low"] = 0 # playback module self.transporter = None # video speed in bytes/s self.outstanding = {} # Piece timeout policy parameters """ minprebufspeed = 10.0 # KB/s self.PIECETIME = piecesize/(minprebufspeed*1024.0) self.MAXDLTIME=2.0*self.PIECETIME self.MAXDLTIME_NONPREBUF=4.0*self.PIECETIME """ # Works for 32KB pieces, like vuze.com self.PIECETIME = 10.0 self.MAXDLTIME = 20.0 self.MAXDLTIME_NONPREBUF=30.0 """
def next(self, haves, wantfunc, sdownload, complete_first = False, slowpieces=[], willrequest=True,connection=None): def newwantfunc( piece ): #print >>sys.stderr,"S",self.streaming_piece_filter( piece ),"!sP",not (piece in slowpieces),"w",wantfunc( piece ) return not (piece in slowpieces) and wantfunc( piece ) # fallback: original piece picker p = PiecePicker.next(self, haves, newwantfunc, sdownload, complete_first, slowpieces=slowpieces, willrequest=willrequest,connection=connection) if DEBUGPP and self.videostatus.prebuffering: print >>sys.stderr,"PiecePickerStreaming: original PP.next returns",p if p is None and not self.videostatus.live_streaming: # When the file we selected from a multi-file torrent is complete, # we won't request anymore pieces, so the normal way of detecting # we're done is not working and we won't tell the video player # we're playable. Do it here instead. self.transporter.notify_playable() return p
def requested(self, *request): self.outstanding_requests[request] = time.time() return PiecePicker.requested(self, *request)
def lost_peer(self, connection): PiecePicker.lost_peer( self, connection )
def lost_have(self, piece): PiecePicker.lost_have( self, piece )
def got_peer(self, connection): PiecePicker.got_peer( self, connection ) self.peer_connections[connection]["interesting"] = {}
def got_seed(self): self.maxhave = self.numpieces PiecePicker.got_seed( self )