當前位置: 首頁>>代碼示例>>Python>>正文


Python Status.updatePeer方法代碼示例

本文整理匯總了Python中status.Status.updatePeer方法的典型用法代碼示例。如果您正苦於以下問題:Python Status.updatePeer方法的具體用法?Python Status.updatePeer怎麽用?Python Status.updatePeer使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在status.Status的用法示例。


在下文中一共展示了Status.updatePeer方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: Peer

# 需要導入模塊: from status import Status [as 別名]
# 或者: from status.Status import updatePeer [as 別名]

#.........這裏部分代碼省略.........
        self.shutdownFlag = False
        self.start()


    def shutdown( self ):
        """Stop peer's thread to allow for program termination"""
        logging.info( 'Shutting down Peer' )
        self.shutdownFlag = True
        self.leave()
        self.rQueue.put( 'shutdown' )
        super( Peer, self ).join() # wait for thread to finish
        self.status.shutdown()


    def processRequest( self, package ):
        """Process request from peer's request queue"""
        if package == None: 
            logging.error( 'Invalid request; ignored' )
            return

        if package['packageType'] == 'message':
            # Handle message request
            context = package['context']
            msgType = context['type']
            source = ( context['host'], context['port'] )
            sourceKey = self.getPeerKey( source[0], source[1] )

            if 'data' in package:
                data = package['data']

            if msgType == 'status':
                # Check if peer is registered
                if sourceKey in self.activePeers:
                    self.status.updatePeer( sourceKey, data )
                else:
                    self.activePeers[ sourceKey ] = 0
                    self.status.registerPeer( sourceKey, data )

                # Reply if peer requested
                if context['reply']:
                    self.sendStatus( source, False )

                # Remove from list of outstanding queries
                if sourceKey in self.waitingQueries:
                    self.waitingQueries.remove( sourceKey )

            elif msgType == 'chunk':
                filepath = os.path.join( os.getcwd(), self.filesDir, context['filename'] )
                self.status.saveChunk( sourceKey, context['filename'], filepath,\
                    context['filesize'], context['chunkNum'], data )
                
            elif msgType == 'query':
                self.sendStatus( source, False )

            elif msgType == 'goodbye':
                logging.info( 'Processing goodbye request from: ' + sourceKey )
                del self.activePeers[ sourceKey ]
                self.status.removePeer( sourceKey )

            elif msgType == 'remove':
                logging.info( 'Processing remove file: ' + data + ' from: ' + sourceKey )
                # Data is the filename
                if self.status.checkForFile( data ):
                    self.status.removeFile( data )
                # Remove actual file on filesystem
                filepath = os.path.join( os.getcwd(), self.filesDir, data )
開發者ID:Arreth,項目名稱:ECE454P1,代碼行數:70,代碼來源:peer.py


注:本文中的status.Status.updatePeer方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。