Changeset 3899
- Timestamp:
- Nov 20, 2007, 3:01:59 AM (15 years ago)
- Location:
- branches/0.9x
- Files:
-
- 23 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/0.9x/daemon/client.c
r3175 r3899 492 492 493 493 req->str = dircpy; 494 495 return 0; 496 } 497 498 int 499 client_crypto( const char * mode ) 500 { 501 struct req * req; 502 char * modecpy; 503 504 modecpy = strdup( mode ); 505 if( NULL == modecpy ) 506 { 507 mallocmsg( strlen( mode ) ); 508 return -1; 509 } 510 511 req = addreq( IPC_MSG_CRYPTO, -1, NULL ); 512 if( NULL == req ) 513 { 514 free( modecpy ); 515 return -1; 516 } 517 518 req->str = modecpy; 494 519 495 520 return 0; … … 801 826 buf = ipc_mkint( con->ipc, &buflen, req->id, -1, req->num ); 802 827 break; 828 case IPC_MSG_CRYPTO: 803 829 case IPC_MSG_DIR: 804 830 buf = ipc_mkstr( con->ipc, &buflen, req->id, -1, req->str ); -
branches/0.9x/daemon/client.h
r1708 r3899 65 65 int client_uplimit ( int ); 66 66 int client_dir ( const char * ); 67 int client_crypto ( const char * ); 67 68 int client_start ( size_t, const int * ); 68 69 int client_stop ( size_t, const int * ); -
branches/0.9x/daemon/remote.c
r3401 r3899 73 73 char dir[MAXPATHLEN]; 74 74 int pex; 75 const char * crypto; 75 76 }; 76 77 … … 175 176 ( '\0' != o.dir[0] && 0 > client_dir ( o.dir ) ) || 176 177 ( !SLIST_EMPTY( &o.files ) && 0 > client_addfiles ( &o.files ) ) || 178 ( o.crypto && 0 > client_crypto ( o.crypto ) ) || 177 179 ( o.startall && 0 > client_start ( 0, NULL ) ) || 178 180 ( o.stopall && 0 > client_stop ( 0, NULL ) ) || … … 230 232 "\n" 231 233 " -a --add <torrent> Add a torrent\n" 234 " -c --encryption preferred Prefer peers to use encryption\n" 235 " -c --encryption required Require encryption for all peers\n" 232 236 " -d --download-limit <int> Max download rate in KiB/s\n" 233 237 " -D --download-unlimited No download rate limit\n" … … 261 265 readargs( int argc, char ** argv, struct opts * opts ) 262 266 { 263 char optstr[] = "a: d:DeEf:hilmMp:qr:s:S:t:u:Ux";267 char optstr[] = "a:c:d:DeEf:hilmMp:qr:s:S:t:u:Ux"; 264 268 struct option longopts[] = 265 269 { 266 270 { "add", required_argument, NULL, 'a' }, 271 { "encryption", required_argument, NULL, 'c' }, 267 272 { "download-limit", required_argument, NULL, 'd' }, 268 273 { "download-unlimited", no_argument, NULL, 'D' }, … … 307 312 return -1; 308 313 } 314 break; 315 case 'c': 316 if(!strcasecmp(optarg, "preferred")) 317 opts->crypto = "preferred"; 318 else if(!strcasecmp(optarg, "required")) 319 opts->crypto = "required"; 320 else 321 usage("invalid encryption mode: %s", optarg); 309 322 break; 310 323 case 'd': -
branches/0.9x/daemon/server.c
r3579 r3899 105 105 0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOMAP, intmsg ) || 106 106 0 > ipc_addmsg( gl_tree, IPC_MSG_AUTOSTART, intmsg ) || 107 0 > ipc_addmsg( gl_tree, IPC_MSG_CRYPTO, strmsg ) || 107 108 0 > ipc_addmsg( gl_tree, IPC_MSG_DOWNLIMIT, intmsg ) || 108 109 0 > ipc_addmsg( gl_tree, IPC_MSG_DIR, strmsg ) || 109 110 0 > ipc_addmsg( gl_tree, IPC_MSG_GETAUTOMAP, prefmsg ) || 110 111 0 > ipc_addmsg( gl_tree, IPC_MSG_GETAUTOSTART, prefmsg ) || 112 0 > ipc_addmsg( gl_tree, IPC_MSG_GETCRYPTO, prefmsg ) || 111 113 0 > ipc_addmsg( gl_tree, IPC_MSG_GETDOWNLIMIT, prefmsg ) || 112 114 0 > ipc_addmsg( gl_tree, IPC_MSG_GETDIR, prefmsg ) || … … 636 638 switch( id ) 637 639 { 640 case IPC_MSG_CRYPTO: 641 if(!strcasecmp(val->val.s.s, "preferred")) 642 torrent_set_encryption(TR_ENCRYPTION_PREFERRED); 643 else if(!strcasecmp(val->val.s.s, "required")) 644 torrent_set_encryption(TR_ENCRYPTION_REQUIRED); 645 else 646 { 647 msgresp(client, tag, IPC_MSG_BAD); 648 return; 649 } 650 break; 638 651 case IPC_MSG_DIR: 639 652 torrent_set_directory( val->val.s.s ); … … 903 916 uint8_t * buf; 904 917 size_t buflen; 918 const char * strval; 905 919 906 920 switch( id ) … … 913 927 buf = ipc_mkint( client->ipc, &buflen, IPC_MSG_AUTOSTART, tag, 914 928 torrent_get_autostart() ); 929 break; 930 case IPC_MSG_GETCRYPTO: 931 switch(torrent_get_encryption()) 932 { 933 case TR_ENCRYPTION_PREFERRED: 934 strval = "preferred"; 935 break; 936 case TR_ENCRYPTION_REQUIRED: 937 strval = "required"; 938 break; 939 default: 940 assert(0); 941 return; 942 } 943 buf = ipc_mkstr(client->ipc, &buflen, IPC_MSG_CRYPTO, tag, strval); 915 944 break; 916 945 case IPC_MSG_GETDIR: -
branches/0.9x/daemon/torrents.c
r3579 r3899 98 98 static int gl_downlimit = -1; 99 99 static char gl_dir[MAXPATHLEN]; 100 static tr_encryption_mode gl_crypto = TR_ENCRYPTION_PREFERRED; 100 101 101 102 RB_GENERATE_STATIC( tortree, tor, idlinks, toridcmp ) … … 466 467 { 467 468 return gl_dir; 469 } 470 471 void 472 torrent_set_encryption(tr_encryption_mode mode) 473 { 474 tr_setEncryptionMode(gl_handle, mode); 475 gl_crypto = mode; 476 savestate(); 477 } 478 479 tr_encryption_mode 480 torrent_get_encryption(void) 481 { 482 return tr_getEncryptionMode(gl_handle); 468 483 } 469 484 … … 738 753 } 739 754 755 str = tr_bencDictFind( &top, "encryption-mode" ); 756 if( NULL != str && TYPE_STR == str->type ) 757 { 758 if(!strcasecmp(str->val.s.s, "preferred")) 759 gl_crypto = TR_ENCRYPTION_PREFERRED; 760 else if(!strcasecmp(str->val.s.s, "required")) 761 gl_crypto = TR_ENCRYPTION_REQUIRED; 762 } 763 764 tr_setEncryptionMode(gl_handle, gl_crypto); 765 740 766 list = tr_bencDictFind( &top, "torrents" ); 741 767 if( NULL == list || TYPE_LIST != list->type ) … … 795 821 796 822 tr_bencInit( &top, TYPE_DICT ); 797 if( tr_bencDictReserve( &top, 8) )823 if( tr_bencDictReserve( &top, 9 ) ) 798 824 { 799 825 nomem: … … 810 836 tr_bencInitStr( tr_bencDictAdd( &top, "default-directory" ), 811 837 gl_dir, -1, 1 ); 838 if(TR_ENCRYPTION_REQUIRED == gl_crypto) 839 tr_bencInitStr(tr_bencDictAdd(&top, "encryption-mode"), "required", -1, 1); 840 else 841 tr_bencInitStr(tr_bencDictAdd(&top, "encryption-mode"), "preferred", -1, 1); 812 842 list = tr_bencDictAdd( &top, "torrents" ); 813 843 tr_bencInit( list, TYPE_LIST ); … … 849 879 } 850 880 851 buf = ( uint8_t * )tr_bencSave Malloc( &top, &len );881 buf = ( uint8_t * )tr_bencSave( &top, &len ); 852 882 SAFEBENCFREE( &top ); 853 883 if( NULL == buf ) -
branches/0.9x/daemon/torrents.h
r3111 r3899 58 58 void torrent_set_directory ( const char * ); 59 59 const char * torrent_get_directory ( void ); 60 void torrent_set_encryption ( tr_encryption_mode ); 61 tr_encryption_mode torrent_get_encryption ( void ); 60 62 61 63 #endif /* TR_DAEMON_TORRENTS_H */ -
branches/0.9x/gtk/actions.c
r3392 r3899 58 58 { "toggle-main-window", NULL, 59 59 N_("Show _Main Window"), NULL, NULL, G_CALLBACK(action_cb), TRUE }, 60 { "toggle- debug-window", NULL,61 N_("Show _Debug Window"), NULL, NULL, G_CALLBACK(action_cb), FALSE }60 { "toggle-message-log", NULL, 61 N_("Show Message _Log"), NULL, NULL, G_CALLBACK(action_cb), FALSE } 62 62 }; 63 63 … … 72 72 N_("_Start"), "<control>S", NULL, G_CALLBACK(action_cb) }, 73 73 { "verify-torrent", NULL, 74 N_("_Verify Local Files"), NULL, NULL, G_CALLBACK(action_cb) },74 N_("_Verify Local Data"), NULL, NULL, G_CALLBACK(action_cb) }, 75 75 { "pause-torrent", GTK_STOCK_MEDIA_PAUSE, 76 76 N_("_Pause"), "<control>P", NULL, G_CALLBACK(action_cb) }, -
branches/0.9x/gtk/main.c
r3586 r3899 111 111 }; 112 112 113 struct exitdata { 114 struct cbdata * cbdata; 115 time_t started; 116 guint timer; 117 }; 118 119 #define CBDATA_PTR "callback-data-pointer" 113 #define CBDATA_PTR "callback-data-pointer" 120 114 121 115 static GtkUIManager * myUIManager = NULL; … … 134 128 static void 135 129 wannaquit( void * vdata ); 136 static gboolean137 exitcheck(gpointer gdata);138 130 static void 139 131 setupdrag(GtkWidget *widget, struct cbdata *data); … … 256 248 257 249 /* initialize gtk */ 250 g_thread_init( NULL ); 258 251 gtk_init_with_args( &argc, &argv, _("[torrent files]"), entries, domain, NULL ); 259 252 myUIManager = gtk_ui_manager_new (); … … 413 406 } 414 407 408 static gpointer 409 quitThreadFunc( gpointer gdata ) 410 { 411 struct cbdata * cbdata = gdata; 412 413 tr_close( tr_core_handle( cbdata->core ) ); 414 415 /* shutdown the gui */ 416 if( cbdata->prefs ) 417 gtk_widget_destroy( GTK_WIDGET( cbdata->prefs ) ); 418 if( cbdata->wind ) 419 gtk_widget_destroy( GTK_WIDGET( cbdata->wind ) ); 420 g_object_unref( cbdata->core ); 421 if( cbdata->icon ) 422 g_object_unref( cbdata->icon ); 423 if( cbdata->errqueue ) { 424 g_list_foreach( cbdata->errqueue, (GFunc)g_free, NULL ); 425 g_list_free( cbdata->errqueue ); 426 } 427 g_free( cbdata ); 428 429 /* exit the gtk main loop */ 430 gtk_main_quit( ); 431 return NULL; 432 } 433 415 434 static void 416 435 wannaquit( void * vdata ) 417 436 { 418 struct cbdata * data; 419 struct exitdata *edata; 420 421 data = vdata; 422 if( data->closing ) 423 { 424 return; 425 } 426 data->closing = TRUE; 427 428 /* stop the update timer */ 429 if(0 < data->timer) 430 g_source_remove(data->timer); 431 data->timer = 0; 432 433 /* pause torrents and stop nat traversal */ 434 tr_core_shutdown( data->core ); 435 436 /* set things up to wait for torrents to stop */ 437 edata = g_new0(struct exitdata, 1); 438 edata->cbdata = data; 439 edata->started = time(NULL); 440 /* check if torrents are still running */ 441 if(exitcheck(edata)) { 442 /* yes, start the exit timer and disable widgets */ 443 edata->timer = g_timeout_add(EXIT_CHECK_INTERVAL, exitcheck, edata); 444 if( NULL != data->wind ) 445 { 446 gtk_widget_set_sensitive( GTK_WIDGET( data->wind ), FALSE ); 447 } 448 } 449 } 450 451 static gboolean 452 exitcheck( gpointer gdata ) 453 { 454 struct exitdata * edata; 455 struct cbdata * cbdata; 456 457 edata = gdata; 458 cbdata = edata->cbdata; 459 460 /* keep waiting until we're ready to quit or we hit the exit timeout */ 461 if( time( NULL ) - edata->started < TRACKER_EXIT_TIMEOUT ) 462 { 463 if( !tr_core_quiescent( cbdata->core ) ) 464 { 465 updatemodel( cbdata ); 466 return TRUE; 467 } 468 } 469 470 /* exit otherwise */ 471 if( 0 < edata->timer ) 472 { 473 g_source_remove( edata->timer ); 474 } 475 g_free( edata ); 476 /* note that cbdata->prefs holds a reference to cbdata->core, and 477 it's destruction may trigger callbacks that use cbdata->core */ 478 if( NULL != cbdata->prefs ) 479 { 480 gtk_widget_destroy( GTK_WIDGET( cbdata->prefs ) ); 481 } 482 if( NULL != cbdata->wind ) 483 { 484 gtk_widget_destroy( GTK_WIDGET( cbdata->wind ) ); 485 } 486 g_object_unref( cbdata->core ); 487 if( NULL != cbdata->icon ) 488 { 489 g_object_unref( cbdata->icon ); 490 } 491 g_assert( 0 == cbdata->timer ); 492 if( NULL != cbdata->errqueue ) 493 { 494 g_list_foreach( cbdata->errqueue, (GFunc) g_free, NULL ); 495 g_list_free( cbdata->errqueue ); 496 } 497 g_free( cbdata ); 498 gtk_main_quit(); 499 500 return FALSE; 437 struct cbdata * cbdata = vdata; 438 439 /* stop the update timer */ 440 if( cbdata->timer ) { 441 g_source_remove( cbdata->timer ); 442 cbdata->timer = 0; 443 } 444 445 /* clear the UI */ 446 gtk_list_store_clear( GTK_LIST_STORE( tr_core_model( cbdata->core ) ) ); 447 gtk_widget_set_sensitive( GTK_WIDGET( cbdata->wind ), FALSE ); 448 449 /* shut down libT */ 450 g_thread_create( quitThreadFunc, vdata, TRUE, NULL ); 501 451 } 502 452 … … 895 845 msgwinclosed() 896 846 { 897 action_toggle( "toggle- debug-window", FALSE );847 action_toggle( "toggle-message-log", FALSE ); 898 848 return FALSE; 899 849 } … … 989 939 } 990 940 } 991 else if (!strcmp (action_name, "toggle- debug-window"))941 else if (!strcmp (action_name, "toggle-message-log")) 992 942 { 993 943 if( !data->msgwin ) … … 1000 950 else 1001 951 { 1002 action_toggle("toggle- debug-window", FALSE);952 action_toggle("toggle-message-log", FALSE); 1003 953 gtk_widget_destroy( data->msgwin ); 1004 954 data->msgwin = NULL; -
branches/0.9x/gtk/msgwin.c
r3401 r3899 188 188 { 189 189 GtkWindow * window = GTK_WINDOW( gtk_widget_get_toplevel( w ) ); 190 GtkWidget * d = gtk_file_chooser_dialog_new( _("Save DebugLog"), window,190 GtkWidget * d = gtk_file_chooser_dialog_new( _("Save Log"), window, 191 191 GTK_FILE_CHOOSER_ACTION_SAVE, 192 192 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, … … 230 230 231 231 win = gtk_window_new( GTK_WINDOW_TOPLEVEL ); 232 gtk_window_set_title( GTK_WINDOW( win ), _( " Debug Window" ) );232 gtk_window_set_title( GTK_WINDOW( win ), _( "Message Log" ) ); 233 233 gtk_window_set_default_size( GTK_WINDOW( win ), 600, 400 ); 234 gtk_window_set_role( GTK_WINDOW( win ), " debug-window" );234 gtk_window_set_role( GTK_WINDOW( win ), "message-log" ); 235 235 vbox = gtk_vbox_new( FALSE, 0 ); 236 236 -
branches/0.9x/gtk/torrent-inspector.c
r3470 r3899 37 37 #include "util.h" 38 38 39 #define UPDATE_INTERVAL_MSEC 150039 #define UPDATE_INTERVAL_MSEC 2000 40 40 41 41 /**** … … 240 240 PEER_COL_IS_UPLOADING, 241 241 PEER_COL_UPLOAD_RATE, 242 PEER_COL_STATUS, 242 243 N_PEER_COLS 243 244 }; … … 253 254 N_("DL Rate"), 254 255 N_("Uploading"), 255 N_("UL Rate") 256 N_("UL Rate"), 257 N_("Status") 256 258 }; 257 259 … … 289 291 PEER_COL_IS_UPLOADING, peer->isUploading, 290 292 PEER_COL_UPLOAD_RATE, peer->uploadToRate, 293 PEER_COL_STATUS, peer->status, 291 294 -1); 292 295 } … … 317 320 G_TYPE_FLOAT, /* downloadFromRate */ 318 321 G_TYPE_BOOLEAN, /* isUploading */ 319 G_TYPE_FLOAT); /* uploadToRate */ 322 G_TYPE_FLOAT, /* uploadToRate */ 323 G_TYPE_INT ); /* tr_peer_status */ 320 324 321 325 int n_peers = 0; … … 341 345 "stock-id", (is_encrypted ? "transmission-lock" : NULL), 342 346 NULL); 347 } 348 349 static void 350 render_status( GtkTreeViewColumn * column UNUSED, 351 GtkCellRenderer * renderer, 352 GtkTreeModel * tree_model, 353 GtkTreeIter * iter, 354 gpointer data UNUSED ) 355 { 356 int status; 357 const char * text; 358 gtk_tree_model_get( tree_model, iter, PEER_COL_STATUS, &status, -1 ); 359 switch( status ) 360 { 361 case TR_PEER_STATUS_HANDSHAKE: text = _( "Handshaking" ); break; 362 case TR_PEER_STATUS_PEER_IS_CHOKED: text = _( "Peer is Choked" ); break; 363 case TR_PEER_STATUS_CLIENT_IS_CHOKED: text = _( "Choked" ); break; 364 case TR_PEER_STATUS_CLIENT_IS_INTERESTED: text = _( "Choked & Interested" ); break; 365 case TR_PEER_STATUS_READY: text = _( "Ready" ); break; 366 case TR_PEER_STATUS_REQUEST_SENT: text = _( "Request Sent" ); break; 367 case TR_PEER_STATUS_ACTIVE : text = _( "Active" ); break; 368 case TR_PEER_STATUS_ACTIVE_AND_CHOKED: text = _( "Active & Choked" ); break; 369 default: text = "BUG"; break; 370 } 371 g_object_set (renderer, "text", text, NULL); 343 372 } 344 373 … … 478 507 fmtpeercount (p->completed_lb, stat->completedFromTracker ); 479 508 480 free (peers);509 free( peers ); 481 510 } 482 511 … … 496 525 PEER_COL_IS_ENCRYPTED, 497 526 PEER_COL_UPLOAD_RATE, 498 PEER_COL_DOWNLOAD_RATE }; 527 PEER_COL_DOWNLOAD_RATE 528 #if 0 529 , PEER_COL_STATUS 530 #endif 531 }; 499 532 500 533 m = peer_model_new (tor); … … 569 602 NULL, NULL); 570 603 break; 604 605 case PEER_COL_STATUS: 606 r = gtk_cell_renderer_text_new( ); 607 c = gtk_tree_view_column_new_with_attributes (t, r, "text", col, NULL); 608 gtk_tree_view_column_set_cell_data_func (c, r, render_status, NULL, NULL); 609 break; 610 571 611 572 612 default: … … 779 819 { 780 820 GtkWidget * state_lb; 781 GtkWidget * corrupt_dl_lb;782 GtkWidget * valid_dl_lb;821 GtkWidget * progress_lb; 822 GtkWidget * have_lb; 783 823 GtkWidget * dl_lb; 784 824 GtkWidget * ul_lb; 825 GtkWidget * failed_lb; 785 826 GtkWidget * ratio_lb; 786 827 GtkWidget * err_lb; 787 GtkWidget * remaining_lb;788 828 GtkWidget * swarm_lb; 789 829 GtkWidget * date_added_lb; … … 799 839 Activity * a = (Activity*) g_object_get_data (G_OBJECT(top), "activity-data"); 800 840 const tr_stat * stat = tr_torrent_stat( a->gtor ); 801 char *pch ;841 char *pch, *pch2, *pch3; 802 842 803 843 pch = tr_torrent_status_str( a->gtor ); … … 805 845 g_free (pch); 806 846 807 pch = readablesize (stat->corruptEver);808 gtk_label_set_text (GTK_LABEL(a-> corrupt_dl_lb), pch);847 pch = g_strdup_printf( "%.1f%% (%.1f%% selected)", stat->percentComplete*100.0, stat->percentDone*100.0 ); 848 gtk_label_set_text (GTK_LABEL(a->progress_lb), pch); 809 849 g_free (pch); 810 850 811 pch = readablesize (stat->haveValid); 812 gtk_label_set_text (GTK_LABEL(a->valid_dl_lb), pch); 813 g_free (pch); 851 pch = readablesize( stat->haveValid + stat->haveUnchecked ); 852 pch2 = readablesize( stat->haveValid ); 853 pch3 = g_strdup_printf( _("%s (%s verified)"), pch, pch2 ); 854 gtk_label_set_text( GTK_LABEL( a->have_lb ), pch3 ); 855 g_free( pch3 ); 856 g_free( pch2 ); 857 g_free( pch ); 814 858 815 859 pch = readablesize (stat->downloadedEver); … … 821 865 g_free (pch); 822 866 823 pch = ratiostr (stat->downloadedEver, stat->uploadedEver); 867 pch = readablesize (stat->corruptEver); 868 gtk_label_set_text (GTK_LABEL(a->failed_lb), pch); 869 g_free (pch); 870 871 pch = g_strdup_printf( "%.1f", stat->ratio ); 824 872 gtk_label_set_text (GTK_LABEL(a->ratio_lb), pch); 825 873 g_free (pch); … … 827 875 pch = readablespeed (stat->swarmspeed); 828 876 gtk_label_set_text (GTK_LABEL(a->swarm_lb), pch); 829 g_free (pch);830 831 pch = readablesize (stat->leftUntilDone);832 gtk_label_set_text (GTK_LABEL(a->remaining_lb), pch);833 877 g_free (pch); 834 878 … … 870 914 hig_workarea_add_row (t, &row, name, l, NULL); 871 915 872 g_snprintf (name, sizeof(name), namefmt, _(" Corrupt DL"));873 l = a-> corrupt_dl_lb = gtk_label_new (NULL);916 g_snprintf (name, sizeof(name), namefmt, _("Progress")); 917 l = a->progress_lb = gtk_label_new (NULL); 874 918 hig_workarea_add_row (t, &row, name, l, NULL); 875 919 876 g_snprintf (name, sizeof(name), namefmt, _(" Valid DL"));877 l = a-> valid_dl_lb = gtk_label_new (NULL);920 g_snprintf (name, sizeof(name), namefmt, _("Have") ); 921 l = a->have_lb = gtk_label_new (NULL); 878 922 hig_workarea_add_row (t, &row, name, l, NULL); 879 923 … … 886 930 hig_workarea_add_row (t, &row, name, l, NULL); 887 931 932 g_snprintf (name, sizeof(name), namefmt, _("Failed DL")); 933 l = a->failed_lb = gtk_label_new (NULL); 934 hig_workarea_add_row (t, &row, name, l, NULL); 935 888 936 g_snprintf (name, sizeof(name), namefmt, _("Ratio")); 889 937 l = a->ratio_lb = gtk_label_new (NULL); 890 hig_workarea_add_row (t, &row, name, l, NULL);891 892 g_snprintf (name, sizeof(name), namefmt, _("Remaining"));893 l = a->remaining_lb = gtk_label_new (NULL);894 938 hig_workarea_add_row (t, &row, name, l, NULL); 895 939 -
branches/0.9x/gtk/tr_core.c
r3573 r3899 123 123 TrCore * self = (TrCore *) obj; 124 124 GObjectClass * parent; 125 GtkTreeIter iter;126 TrTorrent * tor;127 125 128 126 if( self->disposed ) 129 {130 127 return; 131 } 128 132 129 self->disposed = TRUE; 133 134 130 pref_save( NULL ); 135 136 #ifdef REFDBG137 fprintf( stderr, "core %p dispose\n", self );138 #endif139 140 /* sever all remaining torrents in the model */141 if( gtk_tree_model_get_iter_first( self->model, &iter ) ) do142 {143 gtk_tree_model_get( self->model, &iter, MC_TORRENT, &tor, -1 );144 tr_torrent_sever( tor );145 g_object_unref( tor );146 }147 while( gtk_tree_model_iter_next( self->model, &iter ) );148 g_object_unref( self->model );149 150 #ifdef REFDBG151 fprintf( stderr, "core %p dead\n", self );152 #endif153 154 /* close the libtransmission instance */155 tr_close( self->handle );156 157 /* Chain up to the parent class */158 131 parent = g_type_class_peek( g_type_parent( TR_CORE_TYPE ) ); 159 132 parent->dispose( obj ); … … 297 270 /* leechers, completedFromTracker, downloaded, uploaded */ 298 271 G_TYPE_INT, G_TYPE_INT, G_TYPE_UINT64, G_TYPE_UINT64, 299 /* left,TrTorrent object, ID for IPC */300 G_TYPE_ UINT64, TR_TORRENT_TYPE, G_TYPE_INT,272 /* ratio, left, TrTorrent object, ID for IPC */ 273 G_TYPE_FLOAT, G_TYPE_UINT64, TR_TORRENT_TYPE, G_TYPE_INT, 301 274 }; 302 275 … … 372 345 373 346 return self->disposed ? NULL : self->handle; 374 }375 376 void377 tr_core_shutdown( TrCore * self )378 {379 GtkTreeIter iter;380 381 TR_IS_CORE( self );382 383 if( self->disposed )384 return;385 386 g_assert( !self->quitting );387 self->quitting = TRUE;388 389 /* try to stop all the torrents nicely */390 if ( gtk_tree_model_get_iter_first( self->model, &iter) ) do {391 TrTorrent * tor;392 gtk_tree_model_get( self->model, &iter, MC_TORRENT, &tor, -1 );393 tr_torrent_sever( tor );394 g_object_unref( tor );395 } while( gtk_list_store_remove( GTK_LIST_STORE(self->model), &iter ) );396 397 /* shut down nat traversal */398 tr_natTraversalEnable( self->handle, 0 );399 }400 401 gboolean402 tr_core_quiescent( TrCore * self )403 {404 const tr_handle_status * hstat;405 406 TR_IS_CORE( self );407 g_assert( self->quitting );408 409 if( self->disposed )410 return TRUE;411 412 if ( tr_torrentCount( self->handle ) != 0 )413 return FALSE;414 415 hstat = tr_handleStatus( self->handle );416 return TR_NAT_TRAVERSAL_DISABLED == hstat->natTraversalStatus;417 347 } 418 348 … … 633 563 MC_DOWN, st->downloadedEver, 634 564 MC_UP, st->uploadedEver, 565 MC_RATIO, st->ratio, 635 566 MC_LEFT, st->leftUntilDone, 636 567 -1 ); -
branches/0.9x/gtk/tr_core.h
r3449 r3899 110 110 tr_core_handle( TrCore * self ); 111 111 112 /* Try to politely stop all torrents and nat traversal */113 void114 tr_core_shutdown( TrCore * self );115 116 /* Returns true if the shutdown has completed */117 gboolean118 tr_core_quiescent( TrCore * self );119 120 112 /* Load saved state, return number of torrents added. May trigger one 121 113 or more "error" signals with TR_CORE_ERR_ADD_TORRENT */ … … 190 182 MC_PROG_C, MC_PROG_D, MC_DRATE, MC_URATE, MC_ETA, MC_PEERS, 191 183 MC_UPEERS, MC_DPEERS, MC_SEED, MC_LEECH, MC_DONE, 192 MC_DOWN, MC_UP, MC_ LEFT, MC_TORRENT, MC_ID,184 MC_DOWN, MC_UP, MC_RATIO, MC_LEFT, MC_TORRENT, MC_ID, 193 185 MC_ROW_COUNT 194 186 }; -
branches/0.9x/gtk/tr_torrent.c
r3605 r3899 300 300 case TR_STATUS_CHECK_WAIT: 301 301 prog = st->recheckProgress * 100.0; /* [0...100] */ 302 top = g_strdup_printf( _("Waiting to verify local files(%.1f%% tested)"), prog );302 top = g_strdup_printf( _("Waiting to verify local data (%.1f%% tested)"), prog ); 303 303 break; 304 304 305 305 case TR_STATUS_CHECK: 306 306 prog = st->recheckProgress * 100.0; /* [0...100] */ 307 top = g_strdup_printf( _("Verifying local files(%.1f%% tested)"), prog );307 top = g_strdup_printf( _("Verifying local data (%.1f%% tested)"), prog ); 308 308 break; 309 309 -
branches/0.9x/gtk/tr_window.c
r3449 r3899 120 120 { 121 121 char * dlstr, * ulstr, * str, * marked; 122 gfloat prog, dl, ul ;122 gfloat prog, dl, ul, ratio; 123 123 guint64 down, up; 124 124 125 125 gtk_tree_model_get( model, iter, MC_PROG_D, &prog, MC_DRATE, &dl, 126 MC_URATE, &ul, MC_DOWN, &down, MC_UP, &up, -1 );126 MC_URATE, &ul, MC_DOWN, &down, MC_UP, &up, MC_RATIO, &ratio, -1 ); 127 127 prog = MAX( prog, 0.0 ); 128 128 prog = MIN( prog, 1.0 ); … … 131 131 if( 1.0 == prog ) 132 132 { 133 dlstr = ratiostr( down, up);133 dlstr = g_strdup_printf( "%.1f", ratio ); 134 134 str = g_strdup_printf( _("Ratio: %s\nUL: %s"), dlstr, ulstr ); 135 135 } -
branches/0.9x/gtk/ui.h
r3436 r3899 23 23 " </menu>\n" 24 24 " <menu action='help-menu'>\n" 25 " <menuitem action='toggle- debug-window'/>\n"25 " <menuitem action='toggle-message-log'/>\n" 26 26 " <separator/>\n" 27 27 " <menuitem action='show-about-dialog'/>\n" … … 53 53 " <separator/>\n" 54 54 " <menuitem action='toggle-main-window'/>\n" 55 " <menuitem action='toggle- debug-window'/>\n"55 " <menuitem action='toggle-message-log'/>\n" 56 56 " <menuitem action='show-about-dialog'/>\n" 57 57 " <separator/>\n" -
branches/0.9x/gtk/util.c
r3647 r3899 122 122 } 123 123 124 char *125 ratiostr(guint64 down, guint64 up) {126 double ratio;127 128 if(0 == up && 0 == down)129 return g_strdup(_("N/A"));130 131 if(0 == down)132 /* this is a UTF-8 infinity symbol */133 return g_strdup("\xE2\x88\x9E");134 135 ratio = (double)up / (double)down;136 137 return g_strdup_printf("%.*f", BESTDECIMAL(ratio), ratio);138 }139 140 124 gboolean 141 125 mkdir_p(const char *name, mode_t mode) -
branches/0.9x/gtk/util.h
r3380 r3899 63 63 char * 64 64 rfc822date (guint64 epoch_msec); 65 66 /* returns a string representing the download ratio.67 the string must be g_free()d */68 char *69 ratiostr(guint64 down, guint64 up);70 65 71 66 /* create a directory and any missing parent directories */ -
branches/0.9x/libtransmission/crypto.c
r3567 r3899 11 11 */ 12 12 13 #include <sys/types.h> /* for event.h, as well as netinet/in.h on some platforms */ 13 14 #include <assert.h> 14 15 #include <inttypes.h> /* uint8_t */ 15 16 #include <string.h> /* memcpy */ 16 17 #include <stdarg.h> 17 18 #include <sys/types.h> /* for event.h, as well as netinet/in.h on some platforms */19 18 #include <netinet/in.h> /* struct in_addr */ 20 19 -
branches/0.9x/libtransmission/ratecontrol.c
r3614 r3899 23 23 *****************************************************************************/ 24 24 25 #include <string.h> 25 #include <string.h> /* memset */ 26 26 27 27 #include "transmission.h" 28 28 #include "platform.h" 29 29 #include "ratecontrol.h" 30 #include "shared.h"31 30 #include "utils.h" 32 31 33 32 #define GRANULARITY_MSEC 250 34 #define SHORT_INTERVAL_MSEC 300035 #define LONG_INTERVAL_MSEC 2000033 #define SHORT_INTERVAL_MSEC 4000 34 #define LONG_INTERVAL_MSEC 8000 36 35 #define HISTORY_SIZE (LONG_INTERVAL_MSEC / GRANULARITY_MSEC) 37 36 38 typedef struct 37 struct tr_transfer 39 38 { 40 39 uint64_t date; 41 40 uint64_t size; 42 } 43 tr_transfer_t; 41 }; 44 42 45 43 struct tr_ratecontrol … … 48 46 int limit; 49 47 int newest; 50 tr_transfer_ttransfers[HISTORY_SIZE];48 struct tr_transfer transfers[HISTORY_SIZE]; 51 49 }; 52 50 … … 97 95 ***/ 98 96 99 int100 tr_rcCanTransfer( const tr_ratecontrol * r )101 {102 int ret;103 104 if( r == NULL )105 ret = 0;106 else {107 tr_lockLock( (tr_lock*)r->lock );108 ret = rateForInterval( r, SHORT_INTERVAL_MSEC ) < r->limit;109 tr_lockUnlock( (tr_lock*)r->lock );110 }111 112 return ret;113 }114 115 97 size_t 116 98 tr_rcBytesLeft( const tr_ratecontrol * r ) … … 120 102 if( r != NULL ) 121 103 { 122 float cur, max; 123 size_t kb; 104 float cur, max, kb; 124 105 125 106 tr_lockLock( (tr_lock*)r->lock ); … … 128 109 max = r->limit; 129 110 kb = max>cur ? max-cur : 0; 130 bytes = kb * 1024u;111 bytes = (size_t)(kb * 1024); 131 112 132 113 tr_lockUnlock( (tr_lock*)r->lock ); … … 183 164 tr_lockLock( (tr_lock*)r->lock ); 184 165 r->newest = 0; 185 memset( r->transfers, 0, sizeof( tr_transfer_t) * HISTORY_SIZE );166 memset( r->transfers, 0, sizeof(struct tr_transfer) * HISTORY_SIZE ); 186 167 tr_lockUnlock( (tr_lock*)r->lock ); 187 168 } -
branches/0.9x/libtransmission/ratecontrol.h
r3614 r3899 31 31 void tr_rcSetLimit( tr_ratecontrol *, int ); 32 32 int tr_rcGetLimit( const tr_ratecontrol * ); 33 int tr_rcCanTransfer( const tr_ratecontrol * );34 33 size_t tr_rcBytesLeft( const tr_ratecontrol * ); 35 34 void tr_rcTransferred( tr_ratecontrol *, size_t byteCount ); -
branches/0.9x/libtransmission/tracker.c
r3827 r3899 18 18 #include <libgen.h> /* basename */ 19 19 20 #include <sys/queue.h> /* libevent needs this */ 21 #include <sys/types.h> /* libevent needs this */ 20 #include <sys/queue.h> /* evhttp.h needs this */ 22 21 #include <event.h> 23 22 #include <evhttp.h> … … 626 625 627 626 evbuffer_add_printf( buf, "%s" 628 "% sinfo_hash=%s"627 "%cinfo_hash=%s" 629 628 "&peer_id=%s" 630 629 "&port=%d" … … 641 640 "%s%s", 642 641 ann, 643 ( strchr(ann, '?') == NULL ? "?" : "&" ),642 strchr(ann, '?') ? '&' : '?', 644 643 t->escaped, 645 644 t->peer_id, … … 715 714 const char * warning; 716 715 tr_tracker * t; 717 int err = 0;718 716 int responseCode; 719 717 … … 799 797 tr_bencFree( &benc ); 800 798 } 801 else802 {803 tr_inf( "Bad response for torrent '%s' on request '%s' "804 "... trying again in 30 seconds",805 t->name, t->lastRequest );806 807 err = 1;808 }809 799 810 800 if (( warning = updateAddresses( t, req ) )) { … … 851 841 else if( 500<=responseCode && responseCode<=599 ) 852 842 { 853 dbgmsg( t, " got a 5xx error... retrying in 15 seconds." );843 dbgmsg( t, "Got a 5xx error... retrying in 15 seconds." ); 854 844 855 845 /* Response status codes beginning with the digit "5" indicate … … 864 854 else 865 855 { 866 dbgmsg( t, " unhandled condition... retrying in 120 seconds." );856 dbgmsg( t, "Invalid response from tracker... retrying in 120 seconds." ); 867 857 868 858 /* WTF did we get?? */ -
branches/0.9x/libtransmission/utils.c
r3897 r3899 824 824 825 825 tr_bitfield* 826 tr_bitfield And( tr_bitfield * a, const tr_bitfield * b )826 tr_bitfieldOr( tr_bitfield * a, const tr_bitfield * b ) 827 827 { 828 828 uint8_t *ait; … … 832 832 833 833 for( ait=a->bits, bit=b->bits, aend=ait+a->len; ait!=aend; ++ait, ++bit ) 834 *ait &= *bit;834 *ait |= *bit; 835 835 836 836 return a; -
branches/0.9x/libtransmission/utils.h
r3649 r3899 174 174 size_t tr_bitfieldCountTrueBits( const tr_bitfield* ); 175 175 176 tr_bitfield* tr_bitfield And( tr_bitfield*, const tr_bitfield* );176 tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* ); 177 177 178 178 #endif
Note: See TracChangeset
for help on using the changeset viewer.