Changeset 13933


Ignore:
Timestamp:
Feb 2, 2013, 1:42:50 PM (8 years ago)
Author:
jordan
Message:

(libT) recycle the peer id used for public torrents after N hours of use

Location:
trunk/libtransmission
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/announcer.c

    r13901 r13933  
    906906static tr_announce_request *
    907907announce_request_new (const tr_announcer  * announcer,
    908                       const tr_torrent    * tor,
     908                      tr_torrent          * tor,
    909909                      const tr_tier       * tier,
    910910                      tr_announce_event     event)
     
    915915    req->tracker_id_str = tr_strdup (tier->currentTracker->tracker_id_str);
    916916    memcpy (req->info_hash, tor->info.hash, SHA_DIGEST_LENGTH);
    917     memcpy (req->peer_id, tor->peer_id, PEER_ID_LEN);
     917    memcpy (req->peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN);
    918918    req->up = tier->byteCounts[TR_ANN_UP];
    919919    req->down = tier->byteCounts[TR_ANN_DOWN];
     
    12101210    fprintf (stderr, "ANNOUNCE: event %s isPartialSeed %d port %d key %d numwant %d"
    12111211                     " up %"PRIu64" down %"PRIu64" corrupt %"PRIu64" left %"PRIu64
    1212                      " url [%s] tracker_id_str [%s] peer_id [%8.8s]\n",
     1212                     " url [%s] tracker_id_str [%s] peer_id [%20.20s]\n",
    12131213             tr_announce_event_get_string (request->event),
    12141214             (int)request->partial_seed,
     
    12411241    tr_announce_request * req;
    12421242    struct announce_data * data;
    1243     const tr_torrent * tor = tier->tor;
     1243    tr_torrent * tor = tier->tor;
    12441244    const time_t now = tr_time ();
    12451245
  • trunk/libtransmission/handshake.c

    r13932 r13933  
    194194  uint8_t * walk = buf;
    195195  const uint8_t * torrentHash = tr_cryptoGetTorrentHash (handshake->crypto);
    196   const tr_torrent * tor = tr_torrentFindFromHash (handshake->session, torrentHash);
    197   const uint8_t * peer_id = tor->peer_id;
     196  tr_torrent * tor = tr_torrentFindFromHash (handshake->session, torrentHash);
     197  const unsigned char * peer_id = tr_torrentGetPeerId (tor);
    198198
    199199  memcpy (walk, HANDSHAKE_NAME, HANDSHAKE_NAME_LEN);
     
    236236  uint8_t reserved[HANDSHAKE_FLAGS_LEN];
    237237  uint8_t hash[SHA_DIGEST_LENGTH];
    238   const tr_torrent * tor;
    239   const uint8_t * tor_peer_id;
     238  tr_torrent * tor;
    240239  uint8_t peer_id[PEER_ID_LEN];
    241240
     
    273272
    274273  tor = tr_torrentFindFromHash (handshake->session, hash);
    275   tor_peer_id = tor->peer_id;
    276   if (!memcmp (peer_id, tor_peer_id, PEER_ID_LEN))
     274  if (!memcmp (peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN))
    277275    {
    278276      dbgmsg (handshake, "streuth!  we've connected to ourselves.");
     
    704702  /* if we've somehow connected to ourselves, don't keep the connection */
    705703  tor = tr_torrentFindFromHash (handshake->session, tr_peerIoGetTorrentHash (handshake->io));
    706   connected_to_self = (tor != NULL) && !memcmp (peer_id, tor->peer_id, PEER_ID_LEN);
     704  connected_to_self = (tor != NULL) && !memcmp (peer_id, tr_torrentGetPeerId(tor), PEER_ID_LEN);
    707705
    708706  return tr_handshakeDone (handshake, !connected_to_self);
  • trunk/libtransmission/quark.c

    r13816 r13933  
    209209  { "pausedTorrentCount", 18 },
    210210  { "peer-congestion-algorithm", 25 },
     211  { "peer-id-ttl-hours", 17 },
    211212  { "peer-limit", 10 },
    212213  { "peer-limit-global", 17 },
  • trunk/libtransmission/quark.h

    r13816 r13933  
    219219  TR_KEY_pausedTorrentCount,
    220220  TR_KEY_peer_congestion_algorithm,
     221  TR_KEY_peer_id_ttl_hours,
    221222  TR_KEY_peer_limit,
    222223  TR_KEY_peer_limit_global,
  • trunk/libtransmission/session.c

    r13932 r13933  
    309309    assert (tr_variantIsDict (d));
    310310
    311     tr_variantDictReserve (d, 62);
     311    tr_variantDictReserve (d, 63);
    312312    tr_variantDictAddBool (d, TR_KEY_blocklist_enabled,               false);
    313313    tr_variantDictAddStr  (d, TR_KEY_blocklist_url,                   "http://www.example.com/blocklist");
     
    338338    tr_variantDictAddInt  (d, TR_KEY_preallocation,                   TR_PREALLOCATE_SPARSE);
    339339    tr_variantDictAddBool (d, TR_KEY_prefetch_enabled,                DEFAULT_PREFETCH_ENABLED);
     340    tr_variantDictAddInt  (d, TR_KEY_peer_id_ttl_hours,               6);
    340341    tr_variantDictAddBool (d, TR_KEY_queue_stalled_enabled,           true);
    341342    tr_variantDictAddInt  (d, TR_KEY_queue_stalled_minutes,           30);
     
    409410  tr_variantDictAddInt  (d, TR_KEY_preallocation,                s->preallocationMode);
    410411  tr_variantDictAddInt  (d, TR_KEY_prefetch_enabled,             s->isPrefetchEnabled);
     412  tr_variantDictAddInt  (d, TR_KEY_peer_id_ttl_hours,            s->peer_id_ttl_hours);
    411413  tr_variantDictAddBool (d, TR_KEY_queue_stalled_enabled,        tr_sessionGetQueueStalledEnabled (s));
    412414  tr_variantDictAddInt  (d, TR_KEY_queue_stalled_minutes,        tr_sessionGetQueueStalledMinutes (s));
     
    800802    if (tr_variantDictFindBool (settings, TR_KEY_trash_original_torrent_files, &boolVal))
    801803        tr_sessionSetDeleteSource (session, boolVal);
     804    if (tr_variantDictFindInt (settings, TR_KEY_peer_id_ttl_hours, &i))
     805        session->peer_id_ttl_hours = i;
    802806
    803807    /* torrent queues */
  • trunk/libtransmission/session.h

    r13932 r13933  
    119119    bool                         scrapePausedTorrents;
    120120
     121    uint8_t                      peer_id_ttl_hours;
     122
    121123    tr_variant                   removedTorrents;
    122124
  • trunk/libtransmission/torrent.c

    r13924 r13933  
    176176
    177177/***
     178****
     179***/
     180
     181static void
     182tr_torrentUnsetPeerId (tr_torrent * tor)
     183{
     184  /* triggers a rebuild next time tr_torrentGetPeerId() is called */
     185  *tor->peer_id = '\0';
     186}
     187
     188static int
     189peerIdTTL (const tr_torrent * tor)
     190{
     191  int ttl;
     192
     193  if (!tor->peer_id_creation_time)
     194    ttl = 0;
     195  else
     196    ttl = (int)difftime(tor->peer_id_creation_time+(tor->session->peer_id_ttl_hours*3600), tr_time());
     197
     198  return ttl;
     199}
     200
     201const unsigned char *
     202tr_torrentGetPeerId (tr_torrent * tor)
     203{
     204  bool needs_new_peer_id = false;
     205
     206  if (!*tor->peer_id)
     207    needs_new_peer_id = true;
     208
     209  if (!needs_new_peer_id)
     210    if (!tr_torrentIsPrivate (tor))
     211      if (peerIdTTL (tor) <= 0)
     212        needs_new_peer_id = true;
     213
     214  if (needs_new_peer_id)
     215    {
     216      tr_peerIdInit (tor->peer_id);
     217      tor->peer_id_creation_time = tr_time ();
     218    }
     219
     220  return tor->peer_id;
     221}
     222/***
    178223****  PER-TORRENT UL / DL SPEEDS
    179224***/
     
    821866    tor->queuePosition = session->torrentCount;
    822867
    823     tr_peerIdInit (tor->peer_id);
    824 
    825868    tr_sha1 (tor->obfuscatedHash, "req2", 4,
    826869             tor->info.hash, SHA_DIGEST_LENGTH,
     
    16611704     * change the peerid. It would help sometimes if a stopped event
    16621705     * was missed to ensure that we didn't think someone was cheating. */
    1663     tr_peerIdInit (tor->peer_id);
    1664     tor->isRunning = 1;
     1706    tr_torrentUnsetPeerId (tor);
     1707    tor->isRunning = true;
    16651708    tr_torrentSetDirty (tor);
    16661709    tr_runInEventThread (tor->session, torrentStartImpl, tor);
  • trunk/libtransmission/torrent.h

    r13890 r13933  
    160160     * and in the handshake are expected to match.
    161161     */
    162     uint8_t peer_id[PEER_ID_LEN+1];
     162    unsigned char peer_id[PEER_ID_LEN+1];
     163
     164    time_t peer_id_creation_time;
    163165
    164166    /* Where the files will be when it's complete */
     
    436438bool tr_torrentIsStalled (const tr_torrent * tor);
    437439
     440const unsigned char * tr_torrentGetPeerId (tr_torrent * tor);
     441
     442
    438443static inline bool
    439444tr_torrentIsQueued (const tr_torrent * tor)
Note: See TracChangeset for help on using the changeset viewer.