Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 412169 | Differences between
and this patch

Collapse All | Expand All

(-)src/daemon/common/commonTypes.ml.orig (-1 / +2 lines)
Lines 117-123 Link Here
117
  | "md5" ->  Md5 (Md5.of_string rem)
117
  | "md5" ->  Md5 (Md5.of_string rem)
118
  | "sig2dat" -> Md5Ext (Md5Ext.of_base32 rem)
118
  | "sig2dat" -> Md5Ext (Md5Ext.of_base32 rem)
119
  | "bt" | "bittorrent" | "btih" -> 
119
  | "bt" | "bittorrent" | "btih" -> 
120
      BTUrl (Sha1.of_string rem)
120
      BTUrl (Sha1.of_hexa rem) (* TODO i changed from of_string to of_hexa, because its more common, but both are legal I think.
121
                               that is, both base32 and base64 are supposed to work*)
121
  | "filetp" -> FileTP (Md4.of_string rem)
122
  | "filetp" -> FileTP (Md4.of_string rem)
122
  | _ -> raise (Illegal_urn (s ^ " at " ^ sign ^ " is not known"))
123
  | _ -> raise (Illegal_urn (s ^ " at " ^ sign ^ " is not known"))
123
124
(-)src/networks/bittorrent/bTClients.ml.orig (-3 / +241 lines)
Lines 63-70 Link Here
63
open BTComplexOptions
63
open BTComplexOptions
64
open BTChooser
64
open BTChooser
65
open BTStats
65
open BTStats
66
open TcpMessages
67
66
67
68
open TcpMessages
69
open Bencode
70
open Str
68
module VB = VerificationBitmap
71
module VB = VerificationBitmap
69
72
70
let http_ok = "HTTP 200 OK"
73
let http_ok = "HTTP 200 OK"
Lines 100-105 Link Here
100
open BTUdpTracker
103
open BTUdpTracker
101
open UdpSocket
104
open UdpSocket
102
105
106
107
(* some stupid temporary copypasta because i couldnt figure out how to import from btinteractive *)
108
(* let hack_op_file_cancel file = *)
109
(*   CommonSwarming.remove_swarmer file.file_swarmer; *)
110
(*   file.file_swarmer <- None; *)
111
(*    (\* forward declarations turned out difficult. wtf?*\) *)
112
(*   (\* file_stop file;*\) *)
113
(*   remove_file file; *)
114
(*   (\*disconnect_clients file;*\) *)
115
(*   (\*remove_all_clients file;*\) *)
116
(*   if Sys.file_exists file.file_torrent_diskname then Sys.remove file.file_torrent_diskname *)
117
118
let load_torrent_string s user group =
119
  if !verbose then lprintf_nl "load_torrent_string";
120
  let file_id, torrent = BTTorrent.decode_torrent s in
121
122
  (* Save the torrent, because we later want to put
123
     it in the seeded directory. *)
124
  let torrent_diskname = CommonFile.concat_file downloads_directory (torrent.torrent_name ^ ".torrent") in
125
  if Sys.file_exists torrent_diskname then
126
    begin
127
      if !verbose then lprintf_nl "load_torrent_string: %s already exists, ignoring" torrent_diskname;
128
      raise (Torrent_already_exists torrent.torrent_name)
129
    end;
130
  File.from_string torrent_diskname s;
131
132
  if !verbose then
133
    lprintf_nl "Starting torrent download with diskname: %s"
134
        torrent_diskname;
135
  let file = new_download file_id torrent torrent_diskname user group in
136
  (* talk_to_tracker file true; TODO stupid fwd declaration issue. OTOH bep9 torrents arent tracker based anyway*)
137
  CommonInteractive.start_download (file_find (file_num file));
138
  file
139
140
let load_torrent_file filename user group =
141
  if !verbose then
142
    lprintf_nl "load_torrent_file %s" filename;
143
  let s = File.to_string filename in
144
  (* Delete the torrent if it is in the downloads dir. because it gets saved
145
     again under the torrent name and we don't want to clutter up this dir. .*)
146
  if Sys.file_exists filename
147
      && (Filename.dirname filename) = downloads_directory then
148
    Sys.remove filename;
149
  ignore (load_torrent_string s user group)
150
(* end copypasta *)
151
152
153
103
let string_of_event = function
154
let string_of_event = function
104
  | READ_DONE -> "READ_DONE"
155
  | READ_DONE -> "READ_DONE"
105
  | WRITE_DONE -> "WRITE_DONE"
156
  | WRITE_DONE -> "WRITE_DONE"
Lines 540-545 Link Here
540
let reserved () =
591
let reserved () =
541
  let s = String.make 8 '\x00' in
592
  let s = String.make 8 '\x00' in
542
  s.[7] <- (match !bt_dht with None -> '\x00' | Some _ -> '\x01');
593
  s.[7] <- (match !bt_dht with None -> '\x00' | Some _ -> '\x01');
594
  s.[5] <- '\x10'; (* TODO bep9, bep10, notify clients about extended*)
543
  s
595
  s
544
596
545
(** handshake *)
597
(** handshake *)
Lines 569-574 Link Here
569
*)
621
*)
570
622
571
let send_bitfield c =
623
let send_bitfield c =
624
  if c.client_file.file_metadata_downloading then
625
    lprintf_nl "dont send bitmap, we are in metadata state"
626
  else
572
  send_client c (BitField
627
  send_client c (BitField
573
      (
628
      (
574
      match c.client_file.file_swarmer with
629
      match c.client_file.file_swarmer with
Lines 607-612 Link Here
607
662
608
  c.client_azureus_messaging_protocol <- has_bit 0 0x80
663
  c.client_azureus_messaging_protocol <- has_bit 0 0x80
609
664
665
let send_extended_handshake c file =
666
  let module B = Bencode in
667
  let msg = (B.encode (B.Dictionary [(* "e",B.Int 0L; *)
668
                                     "m", (B.Dictionary ["ut_metadata", B.Int 1L]);
669
                                     (* "metadata_size", B.Int (-1L) *)])) in begin
670
    lprintf_file_nl (as_file file) "send extended handshake msg %s" msg;
671
    send_client c (Extended (Int64.to_int 0L, msg));
672
  end
673
674
let send_extended_piece_request c piece file =                                                                     
675
  let module B = Bencode in
676
  let msg = (B.encode (B.Dictionary ["msg_type", B.Int 0L; (* 0 is request subtype*)
677
                                     "piece", B.Int piece; ])) in begin
678
    lprintf_file_nl (as_file file) "send extended request for piece:%Ld msgid:%Ld msg:%s" piece c.client_ut_metadata_msg msg;
679
    send_client c (Extended (Int64.to_int c.client_ut_metadata_msg, msg));
680
  end
681
682
                                                                     
610
let show_client c =
683
let show_client c =
611
  let (ip,port) = c.client_host in
684
  let (ip,port) = c.client_host in
612
  Printf.sprintf "%s:%d %S" (Ip.to_string ip) port (brand_to_string c.client_brand)
685
  Printf.sprintf "%s:%d %S" (Ip.to_string ip) port (brand_to_string c.client_brand)
Lines 705-710 Link Here
705
      begin
778
      begin
706
        c.client_incoming <- true;
779
        c.client_incoming <- true;
707
        send_init !!client_uid file_id sock;
780
        send_init !!client_uid file_id sock;
781
782
        send_extended_handshake c file;
708
      end;
783
      end;
709
    connection_ok c.client_connection_control;
784
    connection_ok c.client_connection_control;
710
    if !verbose_msg_clients then
785
    if !verbose_msg_clients then
Lines 968-974 Link Here
968
  @param msg The message sent by the client
1043
  @param msg The message sent by the client
969
*)
1044
*)
970
and client_to_client c sock msg =
1045
and client_to_client c sock msg =
971
  if !verbose_msg_clients then begin
1046
  (* if !verbose_msg_clients then begin *)
972
      let (ip,port) = (TcpBufferedSocket.peer_addr sock) in
1047
      let (ip,port) = (TcpBufferedSocket.peer_addr sock) in
973
      let (timeout, next) = get_rtimeout sock in
1048
      let (timeout, next) = get_rtimeout sock in
974
      lprintf_nl "CLIENT %d(%s:%d): (%d, %d,%d) Received %s"
1049
      lprintf_nl "CLIENT %d(%s:%d): (%d, %d,%d) Received %s"
Lines 977-983 Link Here
977
      (int_of_float timeout)
1052
      (int_of_float timeout)
978
      (int_of_float next)
1053
      (int_of_float next)
979
      (TcpMessages.to_string msg);
1054
      (TcpMessages.to_string msg);
980
    end;
1055
    (* end; *)
981
1056
982
  let file = c.client_file in
1057
  let file = c.client_file in
983
1058
Lines 1079-1084 Link Here
1079
1154
1080
    | BitField p ->
1155
    | BitField p ->
1081
        (*A bitfield is a summary of what a client have*)
1156
        (*A bitfield is a summary of what a client have*)
1157
      lprintf_file_nl (as_file file) "Bitfield message,  metadata state %B" c.client_file.file_metadata_downloading ;
1158
      if c.client_file.file_metadata_downloading then
1159
        lprintf_file_nl (as_file file) "ignoring Bitfield message, we are in metadata state"
1160
      else
1161
1082
        begin
1162
        begin
1083
          match c.client_file.file_swarmer with
1163
          match c.client_file.file_swarmer with
1084
            None -> ()
1164
            None -> ()
Lines 1125-1130 Link Here
1125
1205
1126
    | Have n ->
1206
    | Have n ->
1127
        (* A client can send a "Have" without sending a Bitfield *)
1207
        (* A client can send a "Have" without sending a Bitfield *)
1208
        if c.client_file.file_metadata_downloading then
1209
          lprintf_file_nl (as_file file)  "ignoring Have message, we are in metadata state"
1210
        else
1128
        begin
1211
        begin
1129
          match c.client_file.file_swarmer with
1212
          match c.client_file.file_swarmer with
1130
            None -> ()
1213
            None -> ()
Lines 1247-1252 Link Here
1247
          if !verbose_msg_clients then
1330
          if !verbose_msg_clients then
1248
            lprintf_file_nl (as_file file) "Error: received cancel request but client has no slot"
1331
            lprintf_file_nl (as_file file) "Error: received cancel request but client has no slot"
1249
1332
1333
    | Extended (extmsg, payload) ->
1334
      
1335
      (* extmsg: 0 handshake, N other message previously declared in handshake.
1336
         atm ignore extended messages if were not currently in metadata state.
1337
         TODO when were not in metadata state we should be friendly and answer metadata requests
1338
      *)
1339
      if file.file_metadata_downloading then begin
1340
        (* since we got at least one extended handshake from the peer, it should be okay to
1341
           send a handshake back now. we need to send it so the remote client knows how
1342
           to send us messages back.
1343
           this should of course be moved but I dont know where yet.
1344
           also we shouldnt send more than one handshake of course...
1345
        *)
1346
        lprintf_file_nl (as_file file) "Got extended msg: %d %s" extmsg payload;
1347
1348
        match extmsg with
1349
            0x0 ->
1350
            lprintf_file_nl (as_file file) "Got extended handshake ";
1351
            let dict = Bencode.decode payload in begin
1352
              match dict with
1353
                  Dictionary list ->
1354
                    List.iter (fun (key,value) ->
1355
                      match key, value with
1356
                          "metadata_size", Int n ->
1357
                            lprintf_file_nl (as_file file) "Got metadata size %Ld" n;
1358
                            c.client_file.file_metadata_size <- n;
1359
                        | "m", Dictionary  mdict ->
1360
                          lprintf_file_nl (as_file file) "Got meta dict ";
1361
                          List.iter (fun (key,value) ->
1362
                            match key, value with
1363
                                "ut_metadata", Int n ->
1364
                                  lprintf_file_nl (as_file file) "ut_metadata is %Ld " n;
1365
                                  c.client_ut_metadata_msg <- n;
1366
                              | _ -> ();
1367
                          ) mdict;
1368
1369
                        | _ -> () ;
1370
                    ) list;
1371
                    (* okay so now we know what to ask for, so ask for metadata now
1372
                       since metadata can be larger than 16k which is the limit, the transfer needs to be chunked, so
1373
                       it is not really right to make the query here. but its a start.
1374
                       also im just asking for piece 0.
1375
                       (we should also check that we actually got the metadata info before proceeding)
1376
                    *)
1377
                    
1378
1379
                    send_extended_handshake c file;
1380
                    send_extended_piece_request c c.client_file.file_metadata_piece file;
1381
                |_ -> () ;
1382
            end;
1383
          | 0x01 -> (* ut_metadata is 1 because we asked it to be 1 in the handshake
1384
                       the msg_type is probably
1385
                       1 for data,
1386
                       but could be 0 for request(unlikely since we didnt advertise we had the meta)
1387
                       2 for reject, also unlikely since peers shouldnt advertise if they dont have(but will need handling in the end)
1388
1389
                       {'msg_type': 1, 'piece': 0, 'total_size': 3425}
1390
                       after the dict comes the actual piece
1391
                       
1392
                    *)
1393
            lprintf_file_nl (as_file file) "Got extended ut_metadata message ";
1394
            let dict = Bencode.decode payload in
1395
            let msgtype = ref 0L in begin
1396
              begin
1397
                match dict with
1398
                    Dictionary list ->
1399
                      List.iter (fun (key,value) ->
1400
                        match key, value with
1401
                            "msg_type", Int n ->
1402
                              lprintf_file_nl (as_file file) "msg_type %Ld" n;
1403
                              msgtype := n;
1404
                          | "piece", Int n ->
1405
                            lprintf_file_nl (as_file file) "piece %Ld" n;
1406
                            file.file_metadata_piece <- n;
1407
                          | "total_size", Int n ->
1408
                            lprintf_file_nl (as_file file) "total_size %Ld" n; (* should always be the same as received in the initial handshake i suppose *)
1409
                          |_ -> () ;
1410
                      ) list;
1411
                  |_ -> () ;
1412
              end;
1413
              match !msgtype with
1414
                  1L ->
1415
                    let last_piece_index = (Int64.div file.file_metadata_size 16384L) in
1416
                    lprintf_file_nl (as_file file) "handling metadata piece %Ld of %Ld"
1417
                      file.file_metadata_piece
1418
                      last_piece_index;
1419
                        (* store the metadata piece in memory *)
1420
                    file.file_metadata_chunks.(1 + (Int64.to_int file.file_metadata_piece)) <- payload;
1421
                        (* possibly write metadata to disk *)
1422
                    if file.file_metadata_piece >=
1423
                      (Int64.div file.file_metadata_size 16384L) then begin
1424
                        lprintf_file_nl (as_file file) "this was the last piece ";
1425
                            (* here we should simply delete the current download, and wait for mld to pick up the new torrent file *)
1426
                            (* the entire payload is currently in the array, TODO *)
1427
                        let newtorrentfile = (Printf.sprintf "/tmp/BT-%s.torrent"
1428
                                                      (Sha1.to_string file.file_id)) in
1429
                        let fd = Unix32.create_rw  newtorrentfile  in
1430
                        let fileindex = ref 0L in
1431
                        begin
1432
                          (* the ee is so we can use the same method to find the
1433
                             start of the payload for the real payloads as well as the synthetic ones
1434
                             *)
1435
                          file.file_metadata_chunks.(0) <- "eed4:info";
1436
                          file.file_metadata_chunks.(2 + Int64.to_int last_piece_index) <- "eee";
1437
                          try
1438
                            Array.iteri (fun index chunk ->
1439
                            (* regexp ee is a fugly way to find the end of the 1st dict before the real payload *)
1440
                              let metaindex = (2 + (Str.search_forward  (Str.regexp_string "ee") chunk 0 )) in
1441
                              let chunklength = ((String.length chunk) - metaindex) in
1442
                              Unix32.write fd !fileindex chunk
1443
                                metaindex 
1444
                                chunklength;
1445
                              fileindex := Int64.add !fileindex  (Int64.of_int chunklength);
1446
                              ();
1447
                            ) file.file_metadata_chunks;
1448
                          with e -> begin
1449
                            (* TODO ignoring errors for now, the array isnt really set up right anyway yet *)
1450
                            lprintf_file_nl (as_file file) "Error %s saving metadata"
1451
                              (Printexc2.to_string e)
1452
                          end;
1453
                          (* Yay, now the new torrent is on disk! amazing! However, now we need to kill the dummy torrent
1454
                             and restart it with the fresh real torrent *)
1455
1456
                          (* it seems we need to use the dynamic interface... *)
1457
                          lprintf_file_nl (as_file file) "cancelling metadata download ";
1458
                          let owner = file.file_file.impl_file_owner in
1459
                          let group = file.file_file.impl_file_group in begin
1460
                            CommonInteractive.file_cancel (as_file file) owner ;
1461
                            (* hack_op_file_cancel c.client_file;   *)
1462
                            lprintf_file_nl (as_file file) "starting download from metadata torrent %s" newtorrentfile  ;
1463
                            load_torrent_file newtorrentfile owner group;
1464
                          end;
1465
                        end;
1466
                        
1467
                      end
1468
                    else begin
1469
                          (* now ask for the next metadata piece, if any *)
1470
                      let module B = Bencode in
1471
                      let nextpiece = (Int64.succ file.file_metadata_piece) in begin
1472
                        lprintf_file_nl (as_file file) "asking for the next piece %Ld" nextpiece;
1473
                        send_extended_piece_request c nextpiece file;
1474
                      end;
1475
                    end;
1476
                |_ ->
1477
                  lprintf_file_nl (as_file file) "unmatched extended subtype" ;
1478
            end;
1479
1480
            
1481
          | _ ->
1482
            lprintf_file_nl (as_file file) "Got extended other msg ";
1483
      end;
1484
1250
    | DHT_Port port ->
1485
    | DHT_Port port ->
1251
        match !bt_dht with
1486
        match !bt_dht with
1252
        | None ->
1487
        | None ->
Lines 1261-1266 Link Here
1261
            BT_DHT.update dht Kademlia.Good id addr
1496
            BT_DHT.update dht Kademlia.Good id addr
1262
          end
1497
          end
1263
1498
1499
1264
  with e ->
1500
  with e ->
1265
      lprintf_file_nl (as_file file) "Error %s while handling MESSAGE: %s" (Printexc2.to_string e) (TcpMessages.to_string msg)
1501
      lprintf_file_nl (as_file file) "Error %s while handling MESSAGE: %s" (Printexc2.to_string e) (TcpMessages.to_string msg)
1266
1502
Lines 1332-1337 Link Here
1332
                    lprintf_file_nl (as_file file) "READY TO DOWNLOAD FILE";
1568
                    lprintf_file_nl (as_file file) "READY TO DOWNLOAD FILE";
1333
1569
1334
                  send_init !!client_uid file.file_id sock;
1570
                  send_init !!client_uid file.file_id sock;
1571
                  send_extended_handshake c file;
1572
1335
(* Fabrice: Initialize the client bitmap and uploader fields to <> None *)
1573
(* Fabrice: Initialize the client bitmap and uploader fields to <> None *)
1336
                  update_client_bitmap c;
1574
                  update_client_bitmap c;
1337
(*              (try get_from_client sock c with _ -> ());*)
1575
(*              (try get_from_client sock c with _ -> ());*)
(-)src/networks/bittorrent/bTGlobals.ml.orig (-3 / +8 lines)
Lines 272-278 Link Here
272
          file.file_trackers <-  t :: file.file_trackers)
272
          file.file_trackers <-  t :: file.file_trackers)
273
  file_trackers
273
  file_trackers
274
274
275
let new_file file_id t torrent_diskname file_temp file_state user group =
275
let new_file  ?(metadata = false) file_id t torrent_diskname file_temp file_state user group =
276
  try
276
  try
277
    Hashtbl.find files_by_uid file_id
277
    Hashtbl.find files_by_uid file_id
278
  with Not_found ->
278
  with Not_found ->
Lines 302-307 Link Here
302
          file_session_uploaded = Int64.zero;
302
          file_session_uploaded = Int64.zero;
303
          file_session_downloaded = Int64.zero;
303
          file_session_downloaded = Int64.zero;
304
          file_last_dht_announce = 0;
304
          file_last_dht_announce = 0;
305
          file_metadata_size = 0L;
306
          file_metadata_piece = 0L;
307
          file_metadata_downloading = metadata;
308
          file_metadata_chunks = Array.make 20 "";
305
          file_private = t.torrent_private;
309
          file_private = t.torrent_private;
306
        } and file_impl =  {
310
        } and file_impl =  {
307
          (dummy_file_impl ()) with
311
          (dummy_file_impl ()) with
Lines 354-363 Link Here
354
      must_share_file file;
358
      must_share_file file;
355
      file
359
      file
356
360
357
let new_download file_id t torrent_diskname user =
361
let new_download ?(metadata = false)  file_id t torrent_diskname user =
358
  let file_temp = Filename.concat !!DO.temp_directory
362
  let file_temp = Filename.concat !!DO.temp_directory
359
      (Printf.sprintf "BT-%s" (Sha1.to_string file_id)) in
363
      (Printf.sprintf "BT-%s" (Sha1.to_string file_id)) in
360
  new_file file_id t torrent_diskname file_temp FileDownloading user
364
  new_file ~metadata:metadata file_id t torrent_diskname file_temp FileDownloading user
361
365
362
let ft_by_num = Hashtbl.create 13
366
let ft_by_num = Hashtbl.create 13
363
let ft_counter = ref 0
367
let ft_counter = ref 0
Lines 866-871 Link Here
866
          client_cache_extension = false;
870
          client_cache_extension = false;
867
          client_fast_extension = false;
871
          client_fast_extension = false;
868
          client_utorrent_extension = false;
872
          client_utorrent_extension = false;
873
          client_ut_metadata_msg = -1L;
869
          client_azureus_messaging_protocol = false;
874
          client_azureus_messaging_protocol = false;
870
        } and impl = {
875
        } and impl = {
871
          dummy_client_impl with
876
          dummy_client_impl with
(-)src/networks/bittorrent/bTInteractive.ml.orig (-2 / +70 lines)
Lines 322-328 Link Here
322
  if !bt_dht <> None then
322
  if !bt_dht <> None then
323
    emit (_s"Last DHT announce") ~desc:(_s"Last time this torrent was announced in DHT")
323
    emit (_s"Last DHT announce") ~desc:(_s"Last time this torrent was announced in DHT")
324
      (string_of_date file.file_last_dht_announce);
324
      (string_of_date file.file_last_dht_announce);
325
325
  emit (_s"Metadata downloading")     (if file.file_metadata_downloading then _s "yes" else _s "no");
326
  
326
  let rec print_first_tracker l =
327
  let rec print_first_tracker l =
327
    match l with
328
    match l with
328
      | [] -> ()
329
      | [] -> ()
Lines 837-843 Link Here
837
  List.iter (fun file ->
838
  List.iter (fun file ->
838
      (* if !verbose_share then lprintf_nl "Checking torrent share for %s" file.file_torrent_diskname; *)
839
      (* if !verbose_share then lprintf_nl "Checking torrent share for %s" file.file_torrent_diskname; *)
839
      if not (Sys.file_exists file.file_torrent_diskname) &&
840
      if not (Sys.file_exists file.file_torrent_diskname) &&
840
        file_state file = FileShared then
841
        file_state file = FileShared &&
842
        not (file.file_metadata_downloading ) then
841
        begin
843
        begin
842
          if !verbose_share then lprintf_nl "Removing torrent share for %s" file.file_torrent_diskname;
844
          if !verbose_share then lprintf_nl "Removing torrent share for %s" file.file_torrent_diskname;
843
          BTClients.file_stop file;
845
          BTClients.file_stop file;
Lines 1251-1256 Link Here
1251
      _s ""
1253
      _s ""
1252
     ),  "<url|file> :\t\t\tstart BT download";
1254
     ),  "<url|file> :\t\t\tstart BT download";
1253
1255
1256
    "startbthash", "Network/Bittorrent", Arg_one (fun hashstr o ->
1257
      begin
1258
        let torrent =          {
1259
            torrent_name = hashstr;
1260
            torrent_filename = hashstr;
1261
            torrent_name_utf8 = hashstr;
1262
            torrent_comment = "";
1263
            torrent_pieces = Array.of_list [];  
1264
            torrent_piece_size = 1L;  
1265
            torrent_files = []; 
1266
            torrent_length = 1L;
1267
            torrent_created_by = ""; 
1268
            torrent_creation_date = 1000000L;
1269
            torrent_modified_by = ""; 
1270
            torrent_encoding = ""; 
1271
            torrent_private = false; 
1272
            torrent_announce = "";
1273
            torrent_announce_list = [];
1274
        }  in
1275
        let hash = (Sha1.of_hexa  hashstr) in
1276
        new_download ~metadata:true hash torrent "" o.conn_user.ui_user o.conn_user.ui_user.user_default_group;
1277
        ();
1278
1279
      end;
1280
      _s ""
1281
    ),  "<hash> :\t\t\tstart BT download using a hash DEBUG will go away";
1282
1283
    "startbtmagnet", "Network/Bittorrent", Arg_one (fun magneturl o ->
1284
      begin
1285
        let exn_catch f x = try `Ok (f x) with exn -> `Exn exn in
1286
        match exn_catch parse_magnet_url magneturl with
1287
          | `Exn _ -> "Not a magnet url", false
1288
          | `Ok magnet ->
1289
            if !verbose then
1290
              lprintf_nl "Got magnet url %S" magneturl;
1291
            List.iter (fun(v) -> lprintf_nl "magnet %s" (string_of_uid v)) magnet#uids ;
1292
            match List2.filter_map (function BTUrl btih -> Some btih | _ -> None) magnet#uids with
1293
              | [] -> "No btih found in magnet url", false;
1294
              | btih::_ ->
1295
                lprintf_nl "Got btih %S" (Sha1.to_string btih);
1296
                let hashstr = (Sha1.to_string btih) in 
1297
                let torrent =          {
1298
                  torrent_name = hashstr; (*magnet#name*)
1299
                  torrent_filename = hashstr;
1300
                  torrent_name_utf8 = hashstr;
1301
                  torrent_comment = "";
1302
                  torrent_pieces = Array.of_list [];  
1303
                  torrent_piece_size = 1L;  
1304
                  torrent_files = []; 
1305
                  torrent_length = 1L;
1306
                  torrent_created_by = ""; 
1307
                  torrent_creation_date = 1000000L;
1308
                  torrent_modified_by = ""; 
1309
                  torrent_encoding = ""; 
1310
                  torrent_private = false; 
1311
                  torrent_announce = "";
1312
                  torrent_announce_list = [];
1313
                }  in
1314
                new_download ~metadata:true btih torrent "" o.conn_user.ui_user o.conn_user.ui_user.user_default_group;
1315
                magnet#name, true; 
1316
      end;
1317
      _s ""
1318
    ),  "<magneturl> :\t\t\tstart BT download using a bt magnet url DEBUG will go away";
1319
    
1320
1321
    
1254
    "stop_all_bt", "Network/Bittorrent", Arg_none (fun o ->
1322
    "stop_all_bt", "Network/Bittorrent", Arg_none (fun o ->
1255
      List.iter (fun file -> BTClients.file_stop file ) !current_files;
1323
      List.iter (fun file -> BTClients.file_stop file ) !current_files;
1256
      let buf = o.conn_buf in
1324
      let buf = o.conn_buf in
(-)src/networks/bittorrent/bTProtocol.ml.orig (-3 / +11 lines)
Lines 217-226 Link Here
217
    * 9 - DHT port announcement
217
    * 9 - DHT port announcement
218
          int16: UDP port
218
          int16: UDP port
219
219
220
    * 20 - extended TODO
220
Choke/unchoke every 10 seconds
221
Choke/unchoke every 10 seconds
221
*)
222
*)
222
223
223
224
open String
224
open BasicSocket
225
open BasicSocket
225
open CommonTypes
226
open CommonTypes
226
open Printf2
227
open Printf2
Lines 251-256 Link Here
251
    mutable gconn_close_on_write : bool;
252
    mutable gconn_close_on_write : bool;
252
  }
253
  }
253
254
255
256
    
254
module TcpMessages = struct
257
module TcpMessages = struct
255
258
256
    type msg =
259
    type msg =
Lines 266-274 Link Here
266
    | Ping
269
    | Ping
267
    | PeerID of string
270
    | PeerID of string
268
    | DHT_Port of int
271
    | DHT_Port of int
269
272
    | Extended of int * string
273
        
270
    let to_string msg =
274
    let to_string msg =
271
      match msg with
275
      match
276
        msg with
272
      | Choke -> "Choke"
277
      | Choke -> "Choke"
273
      | Unchoke -> "Unchoke"
278
      | Unchoke -> "Unchoke"
274
      | Interested -> "Interested"
279
      | Interested -> "Interested"
Lines 284-289 Link Here
284
      | Ping -> "Ping"
289
      | Ping -> "Ping"
285
      | PeerID s ->  Printf.sprintf  "PeerID [%s]" (String.escaped s)
290
      | PeerID s ->  Printf.sprintf  "PeerID [%s]" (String.escaped s)
286
      | DHT_Port n -> Printf.sprintf "DHT_Port %d" n
291
      | DHT_Port n -> Printf.sprintf "DHT_Port %d" n
292
      | Extended (n, s) -> Printf.sprintf  "Extended [%d %s]" n (String.escaped s)
287
293
288
    let parsing opcode m =
294
    let parsing opcode m =
289
        match opcode with
295
        match opcode with
Lines 297-302 Link Here
297
        | 7 -> Piece (get_int m 0, get_uint64_32 m 4, m, 8, String.length m - 8)
303
        | 7 -> Piece (get_int m 0, get_uint64_32 m 4, m, 8, String.length m - 8)
298
        | 8 -> Cancel (get_int m 0, get_uint64_32 m 4, get_uint64_32 m 8)
304
        | 8 -> Cancel (get_int m 0, get_uint64_32 m 4, get_uint64_32 m 8)
299
        | 9 -> DHT_Port (get_int16 m 0)
305
        | 9 -> DHT_Port (get_int16 m 0)
306
        | 20 -> Extended (get_int8 m 0, (String.sub m 1 ((String.length m) - 1)))
300
        | -1 -> PeerID m
307
        | -1 -> PeerID m
301
        | _ -> raise Not_found
308
        | _ -> raise Not_found
302
309
Lines 325-330 Link Here
325
        | PeerID _ -> ()
332
        | PeerID _ -> ()
326
        | Ping -> ()
333
        | Ping -> ()
327
        | DHT_Port n -> buf_int8 buf 9; buf_int16 buf n
334
        | DHT_Port n -> buf_int8 buf 9; buf_int16 buf n
335
        | Extended (n, string) -> buf_int8 buf 20; buf_int8 buf n; Buffer.add_string buf string
328
      end;
336
      end;
329
      let s = Buffer.contents buf in
337
      let s = Buffer.contents buf in
330
      str_int s 0 (String.length s - 4);
338
      str_int s 0 (String.length s - 4);
(-)src/networks/bittorrent/bTTypes.ml.orig (+9 lines)
Lines 287-292 Link Here
287
    mutable client_cache_extension : bool;
287
    mutable client_cache_extension : bool;
288
    mutable client_fast_extension : bool;
288
    mutable client_fast_extension : bool;
289
    mutable client_utorrent_extension : bool;
289
    mutable client_utorrent_extension : bool;
290
291
    mutable client_ut_metadata_msg : int64;
292
    
290
    mutable client_azureus_messaging_protocol : bool;
293
    mutable client_azureus_messaging_protocol : bool;
291
294
292
  }
295
  }
Lines 335-340 Link Here
335
    mutable file_session_downloaded : int64;
338
    mutable file_session_downloaded : int64;
336
    (** DHT specific *)
339
    (** DHT specific *)
337
    mutable file_last_dht_announce : int;
340
    mutable file_last_dht_announce : int;
341
342
    mutable file_metadata_size : int64;
343
    mutable file_metadata_piece : int64;
344
    mutable file_metadata_downloading : bool;
345
    mutable file_metadata_chunks : string array;
346
    
338
    file_private : bool;
347
    file_private : bool;
339
  }
348
  }
340
349

Return to bug 412169