def clientInit(peer)
      # We connected to a peer
      # Send handshake
      torrentData = @torrentData[peer.infoHash]
      if ! torrentData
        @logger.warn "No tracker client found for peer #{peer}. Closing connection."
        close
        return
      end
      trackerclient = torrentData.trackerClient

      @logger.info "Connected to peer #{peer}. Sending handshake."
      msg = PeerHandshake.new
      msg.peerId = trackerclient.peerId
      msg.infoHash = peer.infoHash
      msg.serializeTo currentIo
      peer.state = :handshaking
      @reactor.scheduleTimer(@handshakeTimeout, [:handshake_timeout, peer], false)
      @logger.debug "Done sending handshake."

      # Send bitfield
      sendBitfield(currentIo, torrentData.blockState.completePieceBitfield) if torrentData.blockState

      setReadRateLimit(torrentData.downRateLimit) if torrentData.downRateLimit
      setWriteRateLimit(torrentData.upRateLimit) if torrentData.upRateLimit
    end
def clientInit(peer)
      # We connected to a peer
      # Send handshake
      torrentData = @torrentData[peer.infoHash]
      if ! torrentData
        @logger.warn "No tracker client found for peer #{peer}. Closing connection."
        close
        return
      end
      trackerclient = torrentData.trackerClient

      @logger.info "Connected to peer #{peer}. Sending handshake."
      msg = PeerHandshake.new
      msg.peerId = trackerclient.peerId
      msg.infoHash = peer.infoHash
      msg.serializeTo currentIo
      peer.state = :handshaking
      @reactor.scheduleTimer(@handshakeTimeout, [:handshake_timeout, peer], false)
      @logger.debug "Done sending handshake."

      # Send bitfield
      sendBitfield(currentIo, torrentData.blockState.completePieceBitfield) if torrentData.blockState

      setReadRateLimit(torrentData.downRateLimit) if torrentData.downRateLimit
      setWriteRateLimit(torrentData.upRateLimit) if torrentData.upRateLimit
    end
Reactor method called when we have connected to a peer.