Changeset 9816


Ignore:
Timestamp:
Dec 24, 2009, 1:02:54 AM (12 years ago)
Author:
charles
Message:

(trunk libT) #2632 "Add streaming capability to libtransmission (but not the Transmission GUI clients)" -- implemented

Location:
trunk/libtransmission
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r9793 r9816  
    1212
    1313#include <assert.h>
    14 #include <errno.h>
    1514#include <string.h> /* memcpy, memcmp, strstr */
    1615#include <stdlib.h> /* qsort */
    17 #include <limits.h> /* INT_MAX */
    1816
    1917#include <event.h>
     
    155153{
    156154    tr_piece_index_t index;
    157     int16_t salt;
     155    tr_piece_index_t salt;
    158156    int16_t requestCount;
    159157};
     
    779777
    780778    /* tertiary key: random */
    781     return a->salt - b->salt;
     779    if( a->salt < b->salt ) return -1;
     780    if( a->salt > b->salt ) return 1;
     781
     782    /* okay, they're equal */
     783    return 0;
    782784}
    783785
     
    858860        const tr_torrent * tor = t->tor;
    859861        const tr_info * inf = tr_torrentInfo( tor );
     862        const tr_bool isStreaming = tr_torrentIsStreaming( tor );
    860863        struct weighted_piece * pieces;
    861864        int pieceCount;
     
    873876            piece->index = pool[i];
    874877            piece->requestCount = 0;
    875             piece->salt = tr_cryptoWeakRandInt( 255 );
     878            piece->salt = isStreaming ? piece->index
     879                                      : (tr_piece_index_t)tr_cryptoWeakRandInt( 4096 );
    876880        }
    877881
  • trunk/libtransmission/resume.c

    r9784 r9816  
    4343#define KEY_SPEEDLIMIT_UP       "speed-limit-up"
    4444#define KEY_SPEEDLIMIT_DOWN     "speed-limit-down"
     45#define KEY_STREAMING           "streaming"
    4546#define KEY_RATIOLIMIT          "ratio-limit"
    4647#define KEY_UPLOADED            "uploaded"
     
    504505    tr_tordbg( tor, "Saving .resume file for \"%s\"", tr_torrentName( tor ) );
    505506
    506     tr_bencInitDict( &top, 33 ); /* arbitrary "big enough" number */
     507    tr_bencInitDict( &top, 34 ); /* arbitrary "big enough" number */
    507508    tr_bencDictAddInt( &top, KEY_ACTIVITY_DATE, tor->activityDate );
    508509    tr_bencDictAddInt( &top, KEY_ADDED_DATE, tor->addedDate );
     
    517518    tr_bencDictAddInt( &top, KEY_BANDWIDTH_PRIORITY, tr_torrentGetPriority( tor ) );
    518519    tr_bencDictAddBool( &top, KEY_PAUSED, !tor->isRunning );
     520    tr_bencDictAddBool( &top, KEY_STREAMING, tr_torrentIsStreaming( tor ) );
    519521    savePeers( &top, tor );
    520522    saveFilePriorities( &top, tor );
     
    610612    }
    611613
     614    if( ( fieldsToLoad & TR_FR_STREAMING )
     615      && tr_bencDictFindBool( &top, KEY_STREAMING, &boolVal ) )
     616    {
     617        tor->isStreaming = boolVal;
     618        fieldsLoaded |= TR_FR_STREAMING;
     619    }
     620
    612621    if( ( fieldsToLoad & TR_FR_ADDED_DATE )
    613622      && tr_bencDictFindInt( &top, KEY_ADDED_DATE, &i ) )
  • trunk/libtransmission/resume.h

    r9671 r9816  
    3636    TR_FR_DONE_DATE           = ( 1 << 14 ),
    3737    TR_FR_ACTIVITY_DATE       = ( 1 << 15 ),
    38     TR_FR_RATIOLIMIT          = ( 1 << 16 )
     38    TR_FR_RATIOLIMIT          = ( 1 << 16 ),
     39    TR_FR_STREAMING           = ( 1 << 17 )
    3940};
    4041
  • trunk/libtransmission/torrent.c

    r9725 r9816  
    18911891***/
    18921892
     1893tr_bool
     1894tr_torrentIsStreaming( const tr_torrent * tor )
     1895{
     1896    assert( tr_isTorrent( tor ) );
     1897    assert( tr_isBool( tor->isStreaming ) );
     1898
     1899    return tor->isStreaming;
     1900}
     1901
     1902void
     1903tr_torrentSetStreaming( tr_torrent * tor, tr_bool isStreaming )
     1904{
     1905    assert( tr_isTorrent( tor ) );
     1906    assert( tr_isBool( isStreaming ) );
     1907
     1908    tor->isStreaming = isStreaming;
     1909}
     1910
     1911/***
     1912****
     1913***/
     1914
    18931915void
    18941916tr_torrentSetPeerLimit( tr_torrent * tor,
  • trunk/libtransmission/torrent.h

    r9681 r9816  
    227227    void                             * ratio_limit_hit_func_user_data;
    228228
     229    tr_bool                    isStreaming;
    229230    tr_bool                    isRunning;
    230231    tr_bool                    isDeleting;
  • trunk/libtransmission/transmission.h

    r9793 r9816  
    708708uint16_t   tr_sessionGetPeerLimitPerTorrent( const tr_session * );
    709709
    710 tr_priority_t   tr_torrentGetPriority( const tr_torrent * );
    711 void            tr_torrentSetPriority( tr_torrent *, tr_priority_t );
    712 
    713710
    714711/**
     
    10751072tr_bool  tr_torrentUsesSessionLimits  ( const tr_torrent * );
    10761073
     1074
     1075tr_priority_t   tr_torrentGetPriority( const tr_torrent * );
     1076void            tr_torrentSetPriority( tr_torrent *, tr_priority_t );
     1077
     1078tr_bool         tr_torrentIsStreaming( const tr_torrent * );
     1079void            tr_torrentSetStreaming( tr_torrent *, tr_bool );
    10771080
    10781081/****
Note: See TracChangeset for help on using the changeset viewer.