本文整理汇总了Python中BaseLib.Core.BitTornado.BT1.PiecePicker.PiecePicker类的典型用法代码示例。如果您正苦于以下问题:Python PiecePicker类的具体用法?Python PiecePicker怎么用?Python PiecePicker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PiecePicker类的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: got_have
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) and connection:
self.peer_connections[connection]["interesting"][piece] = 1
示例2: got_have
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
示例3: complete
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)
示例4: __init__
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
)
# 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)
示例5: get_valid_range_iterator
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))
示例6: next
def next(self, haves, wantfunc, sdownload, complete_first = False, helper_con = False, slowpieces=[], willrequest=True,connection=None,proxyhave=None):
def newwantfunc( piece ):
#print >>sys.stderr,time.asctime(),'-', "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, helper_con, slowpieces=slowpieces, willrequest=willrequest,connection=connection)
if DEBUGPP and self.videostatus.prebuffering:
print >>sys.stderr,time.asctime(),'-', "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
示例7: requested
def requested(self, *request):
self.outstanding_requests[request] = time.time()
return PiecePicker.requested(self, *request)
示例8: lost_peer
def lost_peer(self, connection):
PiecePicker.lost_peer(self, connection)
示例9: got_peer
def got_peer(self, connection):
PiecePicker.got_peer(self, connection)
self.peer_connections[connection]["interesting"] = {}
示例10: lost_have
def lost_have(self, piece):
PiecePicker.lost_have(self, piece)
示例11: got_seed
def got_seed(self):
self.maxhave = self.numpieces
PiecePicker.got_seed(self)