Beispiel #1
0
    def _gotFullHandshake(self, connId, connSet):
        data = "".join(connSet["inBuffer"])

        # decode handshake
        length, proto, reserved, infohash, remotePeerId = Messages.decodeHandshake(data)

        if not proto.lower() == "bittorrent protocol":
            # invalid handshake, close conn
            self._failedConn(connId, "received invalid handshake")

        elif not infohash == self.torrents[connSet["torrentIdent"]]["infohash"]:
            # invalid infohash
            self._failedConn(connId, "received handshake with wrong infohash")

        else:
            # valid handshake
            if not self.peerPool.establishedConnection(connSet["torrentIdent"], connSet["sock"].getpeername()):
                # we already have a connection to this address
                self._failedConn(connId, "we already have a connection to this address")

            else:
                # no connection to this address exists up to now
                self.log.info("Conn %i: Got valid handshake, established connections", connId)

                # add to handler
                self.connHandler.addConnection(connSet["torrentIdent"], connSet["sock"], "out", remotePeerId)

                # remove from local structures
                self._removeConn(connId)
 def _gotFullHandshake(self, connId, connSet):
     self.log.info("Conn %i: Got complete handshake, connection established", connId)
     data = ''.join(connSet['inBuffer'])
     
     #decode handshake
     length, proto, reserved, infohash, remotePeerId = Messages.decodeHandshake(data)
     
     #add to handler
     self.connHandler.addConnection(self.torrents[infohash], connSet['sock'], 'in', remotePeerId)
     
     #remove from local structures
     self.allConns.remove(connId)
     del self.conns[connId]