本文整理汇总了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 )