当前位置: 首页>>代码示例>>Python>>正文


Python Status.getChunkToSend方法代码示例

本文整理汇总了Python中status.Status.getChunkToSend方法的典型用法代码示例。如果您正苦于以下问题:Python Status.getChunkToSend方法的具体用法?Python Status.getChunkToSend怎么用?Python Status.getChunkToSend使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在status.Status的用法示例。


在下文中一共展示了Status.getChunkToSend方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Peer

# 需要导入模块: from status import Status [as 别名]
# 或者: from status.Status import getChunkToSend [as 别名]

#.........这里部分代码省略.........
                    result = self.sender.sendMessage( peer[0], peer[1], 'goodbye' )
                    if not result:
                        logging.error( 'Failed to send goodbye message to: ' + p )
                self.joined = False     # mark self as unjoined
                self.rQueue = Queue()   # Create new Queue to throw away pending requets
                if self.shutdownFlag:
                    self.rQueue.put( 'shutdown' )
                for p in self.activePeers:
                    # clear peer from status
                    self.status.removePeer( p )
                self.activePeers = {}           

            elif command == 'remove':
                fName = package['filename']
                context = { 'type': 'remove' }
                for p in self.activePeers:
                    peer = self.getPeerTuple( p )
                    result = self.sender.sendData( peer[0], peer[1], context, fName )
                    if not result:
                        logging.error( 'Failed to send delete message to: ' + p )
                self.status.removeFile( fName )

            else:
                logging.error( 'Invalid command: ' + command )

        else:
            logging.error( 'Invalid packageType; package ignored' )


    def shareChunks( self ):
        """Send out a chunk to each registered peer"""
        for p in self.activePeers:
            peer = self.getPeerTuple( p )
            context, data = self.status.getChunkToSend( p ) 
            if data is None:
                continue # no chunks to share with that peer

            context['type'] = 'chunk'
            if self.sender.sendData( peer[0], peer[1], context, data ):
                self.status.markChunkSent( p,context['filename'], context['chunkNum'] )
                self.activePeers[ p ] = 0
            else:
                logging.error( 'Failed to send packet to: ' + p )
                # increment number of failures
                self.activePeers[ p ] += 1
            
            # Remove any peers that failed too many times
            self.checkPeerFailures()


    def massQuery( self ):
        """Send out query message to all peers to get updated status"""
        for p in self.activePeers:
            if p in self.waitingQueries:
                # Still waiting for reply from last query; skip
                continue

            peer = self.getPeerTuple( p )
            if self.sender.sendMessage( peer[0], peer[1], 'query' ):
                self.activePeers[ p ] = 0
                self.waitingQueries.append( p )
            else : 
                logging.error( 'Failed to send query meessage to: ' + p )
                self.activePeers[ p ] += 1

        # Remove any peers that failed too many times
开发者ID:Arreth,项目名称:ECE454P1,代码行数:70,代码来源:peer.py


注:本文中的status.Status.getChunkToSend方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。