Example #1
0
static void
connection_succeeded (void * vdata)
{
  tr_torrent * tor;
  struct connection_succeeded_data * data = vdata;
  struct tr_webseed * w = data->webseed;

  if (++w->active_transfers >= w->retry_challenge && w->retry_challenge)
    /* the server seems to be accepting more connections now */
    w->consecutive_failures = w->retry_tickcount = w->retry_challenge = 0;

  if (data->real_url && (tor = tr_torrentFindFromId (w->session, w->torrent_id)))
    {
      uint64_t file_offset;
      tr_file_index_t file_index;

      tr_ioFindFileLocation (tor, data->piece_index, data->piece_offset,
                             &file_index, &file_offset);
      tr_free (w->file_urls[file_index]);
      w->file_urls[file_index] = data->real_url;
      data->real_url = NULL;
    }

  tr_free (data->real_url);
  tr_free (data);
}
Example #2
0
static void
write_block_func (void * vdata)
{
  struct write_block_data * data = vdata;
  struct tr_webseed * w = data->webseed;
  struct evbuffer * buf = data->content;
  struct tr_torrent * tor;

  tor = tr_torrentFindFromId (data->session, data->torrent_id);
  if (tor != NULL)
    {
      const uint32_t block_size = tor->blockSize;
      uint32_t len = evbuffer_get_length (buf);
      const uint32_t offset_end = data->block_offset + len;
      tr_cache * cache = data->session->cache;
      const tr_piece_index_t piece = data->piece_index;

      while (len > 0)
        {
          const uint32_t bytes_this_pass = MIN (len, block_size);
          tr_cacheWriteBlock (cache, tor, piece, offset_end - len, bytes_this_pass, buf);
          len -= bytes_this_pass;
        }

      fire_client_got_blocks (tor, w, data->block_index, data->count);
    }

  evbuffer_free (buf);
  tr_free (data);
}
Example #3
0
static void
startMovingNextTorrent( struct relocate_dialog_data * data )
{
    char * str;
    const int id = GPOINTER_TO_INT( data->torrent_ids->data );

    tr_session * session = tr_core_session( data->core );

    tr_torrent * tor = tr_torrentFindFromId( session, id );
    if( tor != NULL )
        tr_torrentSetLocation( tor, previousLocation, data->do_move, NULL, &data->done );

    data->torrent_ids = g_slist_delete_link( data->torrent_ids,
                                             data->torrent_ids );

    str = g_strdup_printf( _( "Moving \"%s\"" ), tr_torrentInfo(tor)->name );
    gtk_message_dialog_set_markup( GTK_MESSAGE_DIALOG( data->message_dialog ), str );
    g_free( str );
}
static void
webseed_free( struct tr_webseed * w )
{
    tr_torrent * tor = tr_torrentFindFromId( w->session, w->torrent_id );
    const tr_info * inf = tr_torrentInfo( tor );
    tr_file_index_t i;

    for( i=0; i<inf->fileCount; ++i )
        tr_free( w->file_urls[i] );
    tr_free( w->file_urls );

    /* webseed destruct */
    event_free( w->timer );
    tr_bandwidthDestruct( &w->bandwidth );
    tr_free( w->base_url );

    /* parent class destruct */
    tr_peerDestruct( tor, &w->parent );

    tr_free( w );
}
Example #5
0
static size_t
writeFunc (void * ptr, size_t size, size_t nmemb, void * vtask)
{
  const size_t byteCount = size * nmemb;
  struct tr_web_task * task = vtask;

  /* webseed downloads should be speed limited */
  if (task->torrentId != -1)
    {
      tr_torrent * tor = tr_torrentFindFromId (task->session, task->torrentId);

      if (tor && !tr_bandwidthClamp (&tor->bandwidth, TR_DOWN, nmemb))
        {
          tr_list_append (&paused_easy_handles, task->curl_easy);
          return CURL_WRITEFUNC_PAUSE;
        }
    }

  evbuffer_add (task->response, ptr, byteCount);
  dbgmsg ("wrote %"TR_PRIuSIZE" bytes to task %p's buffer", byteCount, (void*)task);
  return byteCount;
}
Example #6
0
static tr_torrent * getTorrent( struct tracker_page * page )
{
    return tr_torrentFindFromId( page->session, page->torrentId );
}