Ticket #3779: transmission.patch

File transmission.patch, 11.0 KB (added by TeNtaLGONAmY, 4 years ago)

Patch that includes seed-time

  • libtransmission/quark.c

     
    346346  { "tag", 3 },
    347347  { "tier", 4 },
    348348  { "time-checked", 12 },
     349  { "time-seeding-limit", 18 },
     350  { "time-seeding-limit-enabled", 26 },
    349351  { "torrent-added", 13 },
    350352  { "torrent-added-notification-command", 34 },
    351353  { "torrent-added-notification-enabled", 34 },
  • libtransmission/quark.h

     
    348348  TR_KEY_tag,
    349349  TR_KEY_tier,
    350350  TR_KEY_time_checked,
     351  TR_KEY_time_seeding_limit,
     352  TR_KEY_time_seeding_limit_enabled,
    351353  TR_KEY_torrent_added,
    352354  TR_KEY_torrent_added_notification_command,
    353355  TR_KEY_torrent_added_notification_enabled,
  • libtransmission/session.c

     
    403403  tr_variantDictAddInt  (d, TR_KEY_encryption,                   s->encryptionMode);
    404404  tr_variantDictAddInt  (d, TR_KEY_idle_seeding_limit,           tr_sessionGetIdleLimit (s));
    405405  tr_variantDictAddBool (d, TR_KEY_idle_seeding_limit_enabled,   tr_sessionIsIdleLimited (s));
     406  tr_variantDictAddInt  (d, TR_KEY_time_seeding_limit,           tr_sessionGetSeedTimeLimit (s));
     407  tr_variantDictAddBool (d, TR_KEY_time_seeding_limit_enabled,   tr_sessionIsSeedTimeLimited (s));
    406408  tr_variantDictAddStr  (d, TR_KEY_incomplete_dir,               tr_sessionGetIncompleteDir (s));
    407409  tr_variantDictAddBool (d, TR_KEY_incomplete_dir_enabled,       tr_sessionIsIncompleteDirEnabled (s));
    408410  tr_variantDictAddInt  (d, TR_KEY_message_level,                tr_logGetLevel ());
     
    905907  if (tr_variantDictFindBool (settings, TR_KEY_idle_seeding_limit_enabled, &boolVal))
    906908    tr_sessionSetIdleLimited (session, boolVal);
    907909
     910  if (tr_variantDictFindInt (settings, TR_KEY_time_seeding_limit, &i))
     911    tr_sessionSetSeedTimeLimit (session, i);
     912  if (tr_variantDictFindBool (settings, TR_KEY_time_seeding_limit_enabled, &boolVal))
     913    tr_sessionSetSeedTimeLimited (session, boolVal);
     914
    908915  /**
    909916  ***  Turtle Mode
    910917  **/
     
    12401247
    12411248/***
    12421249****
     1250***/
     1251
     1252void
     1253tr_sessionSetSeedTimeLimited (tr_session * session, bool isLimited)
     1254{
     1255  assert (tr_isSession (session));
     1256
     1257  session->isSeedTimeLimited = isLimited;
     1258}
     1259
     1260void
     1261tr_sessionSetSeedTimeLimit (tr_session * session, uint16_t seedTimeMinutes)
     1262{
     1263  assert (tr_isSession (session));
     1264
     1265  session->seedTimeLimitMinutes = seedTimeMinutes;
     1266}
     1267
     1268bool
     1269tr_sessionIsSeedTimeLimited (const tr_session  * session)
     1270{
     1271  assert (tr_isSession (session));
     1272
     1273  return session->isSeedTimeLimited;
     1274}
     1275
     1276uint16_t
     1277tr_sessionGetSeedTimeLimit (const tr_session * session)
     1278{
     1279  assert (tr_isSession (session));
     1280
     1281  return session->seedTimeLimitMinutes;
     1282}
     1283
     1284/***
     1285****
    12431286****  SPEED LIMITS
    12441287****
    12451288***/
  • libtransmission/session.h

     
    111111    bool                         isIncompleteFileNamingEnabled;
    112112    bool                         isRatioLimited;
    113113    bool                         isIdleLimited;
     114    bool                         isSeedTimeLimited;
    114115    bool                         isIncompleteDirEnabled;
    115116    bool                         pauseAddedTorrent;
    116117    bool                         deleteSourceTorrent;
     
    218219    float                        desiredRatio;
    219220
    220221    uint16_t                     idleLimitMinutes;
     222    uint16_t                     seedTimeLimitMinutes;
    221223
    222224    struct tr_bindinfo         * public_ipv4;
    223225    struct tr_bindinfo         * public_ipv6;
  • libtransmission/torrent.c

     
    480480    && difftime (tr_time (), MAX (tor->startDate, tor->activityDate)) >= idleMinutes * 60u;
    481481}
    482482
     483static bool
     484tr_torrentIsSeedTimeLimitDone (tr_torrent * tor)
     485{
     486  return
     487    tor->doneDate != 0 &&
     488    tr_sessionIsSeedTimeLimited (tor->session) &&
     489    difftime (tr_time (), tor->doneDate) >= tr_sessionGetSeedTimeLimit (tor->session) * 60u;
     490}
     491
    483492/***
    484493****
    485494***/
     
    515524      if (tor->idle_limit_hit_func != NULL)
    516525        tor->idle_limit_hit_func (tor, tor->idle_limit_hit_func_user_data);
    517526    }
     527  else if (tr_torrentIsSeedTimeLimitDone (tor))
     528    {
     529      tr_logAddTorInfo (tor, "%s", "Seeding time limit reached; pausing torrent");
     530 
     531      tor->isStopping = true;
     532      tor->finishedSeedingByTime = true;
     533 
     534      /* maybe notify the client */
     535      if (tor->seed_time_limit_hit_func != NULL)
     536        tor->seed_time_limit_hit_func (tor, tor->seed_time_limit_hit_func_user_data);
     537    }
    518538}
    519539
    520540/***
     
    887907  tor->error = TR_STAT_OK;
    888908
    889909  tor->finishedSeedingByIdle = false;
     910  tor->finishedSeedingByTime = false;
    890911
    891912  tr_peerMgrAddTorrent (session->peerMgr, tor);
    892913
     
    13751396
    13761397  /* s->haveValid is here to make sure a torrent isn't marked 'finished'
    13771398   * when the user hits "uncheck all" prior to starting the torrent... */
    1378   s->finished = tor->finishedSeedingByIdle || (seedRatioApplies && !seedRatioBytesLeft && s->haveValid);
     1399  s->finished = tor->finishedSeedingByIdle || tor->finishedSeedingByTime || (seedRatioApplies && !seedRatioBytesLeft && s->haveValid);
    13791400
    13801401  if (!seedRatioApplies || s->finished)
    13811402    s->seedRatioPercentDone = 1;
     
    16461667  tor->startDate = tor->anyDate = now;
    16471668  tr_torrentClearError (tor);
    16481669  tor->finishedSeedingByIdle = false;
     1670  tor->finishedSeedingByTime = false;
    16491671
    16501672  tr_torrentResetTransferStats (tor);
    16511673  tr_announcerTorrentStarted (tor);
     
    20762098  tr_torrentSetIdleLimitHitCallback (torrent, NULL, NULL);
    20772099}
    20782100
     2101void
     2102tr_torrentSetSeedTimeLimitHitCallback (tr_torrent                          * tor,
     2103                                       tr_torrent_seed_time_limit_hit_func   func,
     2104                                       void                                * user_data)
     2105{
     2106  assert (tr_isTorrent (tor));
     2107
     2108  tor->seed_time_limit_hit_func = func;
     2109  tor->seed_time_limit_hit_func_user_data = user_data;
     2110}
     2111
     2112void
     2113tr_torrentClearSeedTimeLimitHitCallback (tr_torrent * torrent)
     2114{
     2115    tr_torrentSetSeedTimeLimitHitCallback (torrent, NULL, NULL);
     2116}
     2117
    20792118#ifndef _WIN32
    20802119
    20812120static void
  • libtransmission/torrent.h

     
    237237    tr_torrent_idle_limit_hit_func    idle_limit_hit_func;
    238238    void                            * idle_limit_hit_func_user_data;
    239239
     240    tr_torrent_seed_time_limit_hit_func   seed_time_limit_hit_func;
     241    void                                * seed_time_limit_hit_func_user_data;
     242
    240243    void * queue_started_user_data;
    241244    void (* queue_started_callback)(tr_torrent *, void * queue_started_user_data);
    242245
     
    272275    uint16_t                   idleLimitMinutes;
    273276    tr_idlelimit               idleLimitMode;
    274277    bool                       finishedSeedingByIdle;
     278    bool                       finishedSeedingByTime;
    275279};
    276280
    277281static inline tr_torrent*
  • libtransmission/transmission.h

     
    645645void       tr_sessionSetIdleLimit (tr_session *, uint16_t idleMinutes);
    646646uint16_t   tr_sessionGetIdleLimit (const tr_session *);
    647647
     648void       tr_sessionSetSeedTimeLimited (tr_session *, bool isLimited);
     649bool       tr_sessionIsSeedTimeLimited (const tr_session *);
     650
     651void       tr_sessionSetSeedTimeLimit (tr_session *, uint16_t seedTimeMinutes);
     652uint16_t   tr_sessionGetSeedTimeLimit (const tr_session *);
     653
    648654void       tr_sessionSetPeerLimit (tr_session *, uint16_t maxGlobalPeers);
    649655uint16_t   tr_sessionGetPeerLimit (const tr_session *);
    650656
     
    14071413typedef void (*tr_torrent_idle_limit_hit_func)(tr_torrent   * torrent,
    14081414                                               void         * user_data);
    14091415
     1416typedef void (*tr_torrent_seed_time_limit_hit_func)(tr_torrent   * torrent,
     1417                                                    void         * user_data);
    14101418
     1419
    14111420/**
    14121421 * Register to be notified whenever a torrent's "completeness"
    14131422 * changes. This will be called, for example, when a torrent
     
    14711480
    14721481void tr_torrentClearIdleLimitHitCallback (tr_torrent * torrent);
    14731482
     1483void tr_torrentSetSeedTimeLimitHitCallback (
     1484     tr_torrent                          * torrent,
     1485     tr_torrent_seed_time_limit_hit_func   func,
     1486     void                                * user_data);
    14741487
     1488void tr_torrentClearSeedTimeLimitHitCallback (tr_torrent * torrent);
     1489
     1490
    14751491/**
    14761492 * MANUAL ANNOUNCE
    14771493 *
  • macosx/Torrent.m

     
    5454- (void) completenessChange: (tr_completeness) status wasRunning: (BOOL) wasRunning;
    5555- (void) ratioLimitHit;
    5656- (void) idleLimitHit;
     57- (void) seedTimeLimitHit;
    5758- (void) metadataRetrieved;
    5859- (void)renameFinished: (BOOL) success nodes: (NSArray *) nodes completionHandler: (void (^)(BOOL)) completionHandler oldPath: (NSString *) oldPath newName: (NSString *) newName;
    5960
     
    9293    });
    9394}
    9495
     96void seedTimeLimitHitCallback(tr_torrent * torrent, void * torrentData)
     97{
     98    dispatch_async(dispatch_get_main_queue(), ^{
     99        [(Torrent *)torrentData seedTimeLimitHit];
     100    });
     101}
     102
    95103void metadataCallback(tr_torrent * torrent, void * torrentData)
    96104{
    97105    dispatch_async(dispatch_get_main_queue(), ^{
     
    17151723    tr_torrentSetCompletenessCallback(fHandle, completenessChangeCallback, self);
    17161724    tr_torrentSetRatioLimitHitCallback(fHandle, ratioLimitHitCallback, self);
    17171725    tr_torrentSetIdleLimitHitCallback(fHandle, idleLimitHitCallback, self);
     1726    tr_torrentSetSeedTimeLimitHitCallback(fHandle, seedTimeLimitHitCallback, self);
    17181727    tr_torrentSetMetadataCallback(fHandle, metadataCallback, self);
    17191728   
    17201729    fHashString = [[NSString alloc] initWithUTF8String: fInfo->hashString];
     
    19001909    [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedSeeding" object: self];
    19011910}
    19021911
     1912- (void) seedTimeLimitHit
     1913{
     1914    fStat = tr_torrentStat(fHandle);
     1915   
     1916    [[NSNotificationCenter defaultCenter] postNotificationName: @"TorrentFinishedSeeding" object: self];
     1917}
     1918
    19031919- (void) metadataRetrieved
    19041920{
    19051921    fStat = tr_torrentStat(fHandle);