Changeset 11681


Ignore:
Timestamp:
Jan 15, 2011, 5:10:54 PM (11 years ago)
Author:
jch
Message:

Make the peer-socket-tos preference more user-friendly.

Possible values are now the strings default, lowcost, throughput etc.
Numeric values are used for non-standard values.

Location:
trunk/libtransmission
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/session.c

    r11676 r11681  
    258258#endif
    259259
     260static int
     261parse_tos(const char *string)
     262{
     263    char *p;
     264    int value;
     265
     266    if(strcasecmp(string, "") == 0 || strcasecmp(string, "default") == 0)
     267        return 0;
     268    else if(strcasecmp(string, "lowcost") == 0 ||
     269            strcasecmp(string, "mincost") == 0)
     270        return 0x10;
     271    else if(strcasecmp(string, "throughput") == 0)
     272        return 0x08;
     273    else if(strcasecmp(string, "reliability") == 0)
     274        return 0x04;
     275    else if(strcasecmp(string, "lowdelay") == 0)
     276        return 0x02;
     277
     278    value = strtol(string, &p, 0);
     279    if(p == NULL || p == string)
     280        return 0;
     281
     282    return value;
     283}
     284
     285static const char *
     286format_tos(int value)
     287{
     288    static char buf[8];
     289    switch(value) {
     290    case 0: return "default";
     291    case 0x10: return "lowcost";
     292    case 0x08: return "throughput";
     293    case 0x04: return "reliability";
     294    case 0x02: return "lowdelay";
     295    default:
     296        snprintf(buf, 8, "%d", value);
     297        return buf;
     298    }
     299}
     300
    260301void
    261302tr_sessionGetDefaultSettings( const char * configDir UNUSED, tr_benc * d )
     
    286327    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW,     49152 );
    287328    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH,    65535 );
    288     tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_SOCKET_TOS,          atoi( TR_DEFAULT_PEER_SOCKET_TOS_STR ) );
     329    tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_SOCKET_TOS,          TR_DEFAULT_PEER_SOCKET_TOS_STR );
    289330    tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED,              TRUE );
    290331    tr_bencDictAddBool( d, TR_PREFS_KEY_PORT_FORWARDING,          TRUE );
     
    349390    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_LOW,     s->randomPortLow );
    350391    tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_PORT_RANDOM_HIGH,    s->randomPortHigh );
    351     tr_bencDictAddInt ( d, TR_PREFS_KEY_PEER_SOCKET_TOS,          s->peerSocketTOS );
     392    tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_SOCKET_TOS,          format_tos(s->peerSocketTOS) );
    352393    tr_bencDictAddStr ( d, TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM, s->peer_congestion_algorithm );
    353394    tr_bencDictAddBool( d, TR_PREFS_KEY_PEX_ENABLED,              s->isPexEnabled );
     
    719760    if( tr_bencDictFindInt( settings, TR_PREFS_KEY_ENCRYPTION, &i ) )
    720761        tr_sessionSetEncryption( session, i );
    721     if( tr_bencDictFindInt( settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &i ) )
    722         session->peerSocketTOS = i;
     762    if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PEER_SOCKET_TOS, &str ) )
     763        session->peerSocketTOS = parse_tos( str );
    723764    if( tr_bencDictFindStr( settings, TR_PREFS_KEY_PEER_CONGESTION_ALGORITHM, &str ) )
    724765        session->peer_congestion_algorithm = tr_strdup(str);
  • trunk/libtransmission/transmission.h

    r11627 r11681  
    145145#define TR_DEFAULT_RPC_URL_STR       "/transmission/"
    146146#define TR_DEFAULT_PEER_PORT_STR              "51413"
    147 #define TR_DEFAULT_PEER_SOCKET_TOS_STR            "0"
     147#define TR_DEFAULT_PEER_SOCKET_TOS_STR      "default"
    148148#define TR_DEFAULT_PEER_LIMIT_GLOBAL_STR        "240"
    149149#define TR_DEFAULT_PEER_LIMIT_TORRENT_STR        "60"
Note: See TracChangeset for help on using the changeset viewer.