Changeset 3245


Ignore:
Timestamp:
Oct 1, 2007, 3:24:52 AM (15 years ago)
Author:
charles
Message:

more experimenting with how to get good peers

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gtk/torrent-inspector.c

    r3178 r3245  
    235235  PEER_COL_CLIENT,
    236236  PEER_COL_PROGRESS,
    237   PEER_COL_IS_CONNECTED,
    238237  PEER_COL_IS_ENCRYPTED,
    239238  PEER_COL_IS_DOWNLOADING,
     
    251250  N_("Progress"),
    252251  " ",
    253   " ",
    254252  N_("Downloading"),
    255253  N_("DL Rate"),
     
    287285                      PEER_COL_IS_ENCRYPTED, peer->isEncrypted,
    288286                      PEER_COL_PROGRESS, (int)(100.0*peer->progress + 0.5),
    289                       PEER_COL_IS_CONNECTED, peer->isConnected,
    290287                      PEER_COL_IS_DOWNLOADING, peer->isDownloading,
    291288                      PEER_COL_DOWNLOAD_RATE, peer->downloadFromRate,
     
    316313                                         G_TYPE_STRING,  /* client */
    317314                                         G_TYPE_INT,     /* progress [0..100] */
    318                                          G_TYPE_BOOLEAN, /* isConnected */
    319315                                         G_TYPE_BOOLEAN, /* isEncrypted */
    320316                                         G_TYPE_BOOLEAN, /* isDownloading */
     
    329325  tr_torrentPeersFree( peers, 0 );
    330326  return GTK_TREE_MODEL (m);
    331 }
    332 
    333 static void
    334 render_connection (GtkTreeViewColumn  * column UNUSED,
    335                    GtkCellRenderer    * renderer,
    336                    GtkTreeModel       * tree_model,
    337                    GtkTreeIter        * iter,
    338                    gpointer             data UNUSED)
    339 {
    340   gboolean is_connected = FALSE;
    341   gtk_tree_model_get (tree_model, iter, PEER_COL_IS_CONNECTED, &is_connected,
    342                                         -1 );
    343   g_object_set (renderer, "xalign", (gfloat)0.0,
    344                           "yalign", (gfloat)0.5,
    345                           "stock-id", ( is_connected ? GTK_STOCK_CONNECT : GTK_STOCK_DISCONNECT ),
    346                           NULL);
    347327}
    348328
     
    406386               gpointer              data UNUSED)
    407387{
    408   gboolean is_connected = FALSE;
    409388  char * client = NULL;
    410   gtk_tree_model_get (tree_model, iter, PEER_COL_IS_CONNECTED,  &is_connected,
    411                                         PEER_COL_CLIENT, &client,
     389  gtk_tree_model_get (tree_model, iter, PEER_COL_CLIENT, &client,
    412390                                        -1);
    413   if (!is_connected)
    414     *client = '\0';
    415   g_object_set (renderer, "text", client, NULL);
     391  g_object_set (renderer, "text", (client ? client : ""), NULL);
    416392  g_free (client);
    417393}
     
    515491
    516492  /* TODO: make this configurable? */
    517   int view_columns[] = { PEER_COL_IS_CONNECTED,
    518                          PEER_COL_IS_ENCRYPTED,
     493  int view_columns[] = { PEER_COL_IS_ENCRYPTED,
    519494                         PEER_COL_ADDRESS,
    520495                         PEER_COL_CLIENT,
     
    568543        gtk_tree_view_column_set_fixed_width (c, 20);
    569544        gtk_tree_view_column_set_cell_data_func (c, r, render_encrypted,
    570                                                  NULL, NULL);
    571         break;
    572 
    573       case PEER_COL_IS_CONNECTED:
    574         resizable = FALSE;
    575         r = gtk_cell_renderer_pixbuf_new ();
    576         c = gtk_tree_view_column_new_with_attributes (t, r, NULL);
    577         gtk_tree_view_column_set_sizing (c, GTK_TREE_VIEW_COLUMN_FIXED);
    578         gtk_tree_view_column_set_fixed_width (c, 20);
    579         gtk_tree_view_column_set_cell_data_func (c, r, render_connection,
    580545                                                 NULL, NULL);
    581546        break;
  • trunk/libtransmission/peer-mgr.c

    r3243 r3245  
    6262    /* this is arbitrary and, hopefully, temporary until we come up
    6363     * with a better idea for managing the connection limits */
    64     MAX_CONNECTED_PEERS_PER_TORRENT = 100,
     64    MAX_CONNECTED_PEERS_PER_TORRENT = 60,
    6565};
    6666
     
    142142torrentIsLocked( const Torrent * t )
    143143{
    144     return t!=NULL && t->manager!=NULL && t->manager->lockThread!=0;
     144    return ( t != NULL )
     145        && ( t->manager != NULL )
     146        && ( t->manager->lockThread != 0 )
     147        && ( t->manager->lockThread == pthread_self( ) );
    145148}
    146149
     
    15141517{
    15151518    int i, insize, outsize;
    1516     const int seeding = tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE;
    15171519    tr_peer ** peers = (tr_peer**) tr_ptrArrayPeek( t->peers, &insize );
    15181520    struct tr_connection * ret = tr_new( struct tr_connection, insize );
     1521    const int clientIsSeed = tr_cpGetStatus( t->tor->completion ) != TR_CP_INCOMPLETE;
    15191522    const time_t now = time( NULL );
    15201523
     
    15241527    {
    15251528        tr_peer * peer = peers[i];
     1529        int isWeak;
     1530        const int peerIsSeed = peer->progress >= 1.0;
    15261531        const struct peer_atom * atom = getExistingAtom( t, &peer->in_addr );
    1527         const double throughput = seeding ? tr_peerIoGetRateToPeer( peer->io )
    1528                                           : tr_peerIoGetRateToClient( peer->io );
    1529 
    1530         if( ( now - atom->time ) < LAISSEZ_FAIRE_PERIOD_SECS )
    1531             continue;
    1532 
    1533         if( throughput >= 2 )
    1534             continue;
    1535 
    1536         ret[outsize].peer = peer;
    1537         ret[outsize].throughput = throughput;
    1538         ++outsize;
     1532        const double throughput = (2*tr_peerIoGetRateToPeer( peer->io ))
     1533                                + tr_peerIoGetRateToClient( peer->io );
     1534
     1535        /* if we're both seeds, give a little bit of time for
     1536         * a mutual pex -- peer-msgs initiates a pex exchange
     1537         * on startup -- and then disconnect */
     1538        if( peerIsSeed && clientIsSeed && (now-atom->time >= 30) )
     1539            isWeak = TRUE;
     1540        else if( ( now - atom->time ) < LAISSEZ_FAIRE_PERIOD_SECS )
     1541            isWeak = FALSE;
     1542        else if( throughput >= 5 )
     1543            isWeak = FALSE;
     1544        else
     1545            isWeak = TRUE;
     1546
     1547        if( isWeak )
     1548        {
     1549            ret[outsize].peer = peer;
     1550            ret[outsize].throughput = throughput;
     1551            ++outsize;
     1552        }
    15391553    }
    15401554
     
    16041618    struct tr_connection * connections;
    16051619    int i, nCandidates, nConnections, nCull, nAdd;
     1620    int peerCount;
    16061621
    16071622    torrentLock( t );
     
    16271642
    16281643    /* add some new ones */
    1629     nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - nConnections;
     1644    peerCount = tr_ptrArraySize( t->peers );
     1645    nAdd = MAX_CONNECTED_PEERS_PER_TORRENT - peerCount;
    16301646    for( i=0; i<nAdd && i<nCandidates; ++i ) {
    16311647        struct peer_atom * atom = candidates[i];
Note: See TracChangeset for help on using the changeset viewer.