本文整理汇总了Python中Messages.decodeShortHandshake方法的典型用法代码示例。如果您正苦于以下问题:Python Messages.decodeShortHandshake方法的具体用法?Python Messages.decodeShortHandshake怎么用?Python Messages.decodeShortHandshake使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Messages
的用法示例。
在下文中一共展示了Messages.decodeShortHandshake方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _gotShortHandshake
# 需要导入模块: import Messages [as 别名]
# 或者: from Messages import decodeShortHandshake [as 别名]
def _gotShortHandshake(self, connId, connSet):
success = False
data = ''.join(connSet['inBuffer'])
connSet['inBuffer'] = [data]
#decode handshake
length, proto, reserved, infohash = Messages.decodeShortHandshake(data)
if not proto.lower()=='bittorrent protocol':
#invalid handshake, close conn
self._closeConn(connId, 'received invalid handshake')
elif not infohash in self.torrents:
#invalid handshake, close conn
self._closeConn(connId, 'received handshake with unknown infohash')
else:
#valid handshake
connSet['torrentIdent'] = self.torrents[infohash]
if self.peerPool.establishedConnection(connSet['torrentIdent'], connSet['sock'].getpeername()):
#no connection to this address exists up to now
success = True
connSet['added'] = True
self.log.info("Conn %d: Got valid handshake, sending response", connId)
connSet['sock'].send(Messages.generateHandshake(infohash, self.peerId))
else:
#we already have a connection to this address
self._closeConn(connId, 'we already have a connection to this address')
return success