/[mldonkey]/mldonkey/src/networks/bittorrent/bTTracker.ml
ViewVC logotype

Diff of /mldonkey/src/networks/bittorrent/bTTracker.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.16 by spiralvoice, Thu Aug 4 22:00:23 2005 UTC revision 1.17 by spiralvoice, Sun Aug 7 12:57:22 2005 UTC
# Line 62  torrents/: for BitTorrent Line 62  torrents/: for BitTorrent
62  let lprintf_nl () =  let lprintf_nl () =
63    lprintf "%s[bTTrack] "    lprintf "%s[bTTrack] "
64      (log_time ()); lprintf_nl2      (log_time ()); lprintf_nl2
65          
66  open Http_server  open Http_server
67    
68  type tracker_peer = {  type tracker_peer = {
# Line 188  let reply_has_tracker r info_hash peer_i Line 188  let reply_has_tracker r info_hash peer_i
188            {            {
189              peer_id = peer_id;              peer_id = peer_id;
190              peer_ip = peer_ip;              peer_ip = peer_ip;
191              peer_port = peer_port;                          peer_port = peer_port;
192              peer_key = peer_key;              peer_key = peer_key;
193              peer_active = last_time ();              peer_active = last_time ();
194            } in            } in
# Line 371  let http_handler t r = Line 371  let http_handler t r =
371          with e -> ())          with e -> ())
372    
373      | "scrape" ->      | "scrape" ->
374          let files_tracked = ref [] in          let files_tracked = ref [] in
375          let log_tracked_files = ref "" in          let log_tracked_files = ref "" in
376          (* build the answer *)          (* build the answer *)
377          Hashtbl.iter (fun info_hash tracker ->          Hashtbl.iter (fun info_hash tracker ->
# Line 385  let http_handler t r = Line 385  let http_handler t r =
385                       ];                       ];
386                   ]) :: !files_tracked;                   ]) :: !files_tracked;
387              if !verbose_msg_servers then begin              if !verbose_msg_servers then begin
388                  let next_file = (Printf.sprintf "[BT]: f: %s d: %d c: %d i: %d\n"                  let next_file = (Printf.sprintf "[BT]: f: %s d: %d c: %d i: %d\n"
389                    (Sha1.to_hexa info_hash) tracker.tracker_downloaded tracker.tracker_complete tracker.tracker_incomplete) in                    (Sha1.to_hexa info_hash) tracker.tracker_downloaded tracker.tracker_complete tracker.tracker_incomplete) in
390                  log_tracked_files := !log_tracked_files ^ next_file                  log_tracked_files := !log_tracked_files ^ next_file
391                end                end
# Line 447  in sub-directories in former versions. * Line 447  in sub-directories in former versions. *
447        match e with        match e with
448          Not_found ->          Not_found ->
449            r.reply_head <- "404 Not Found"            r.reply_head <- "404 Not Found"
450        | _ ->        | _ ->
451            let message =            let message =
452              Dictionary [              Dictionary [
453                String "failure reason", String (Printexc2.to_string e);                String "failure reason", String (Printexc2.to_string e);
# Line 486  let udp_handler sock event = Line 486  let udp_handler sock event =
486    match event with    match event with
487      UdpSocket.READ_DONE ->      UdpSocket.READ_DONE ->
488  (*      lprintf "G2: udp read_packets...\n"; *)  (*      lprintf "G2: udp read_packets...\n"; *)
489        UdpSocket.read_packets sock (fun p ->        UdpSocket.read_packets sock (fun p ->
490            try            try
491  (*            lprintf "G2: udp one packet...\n"; *)  (*            lprintf "G2: udp one packet...\n"; *)
492              let pbuf = p.UdpSocket.udp_content in              let pbuf = p.UdpSocket.udp_content in
# Line 503  let udp_handler sock event = Line 503  let udp_handler sock event =
503  (*            BTProtocol.udp_client_handler ip port buf *)  (*            BTProtocol.udp_client_handler ip port buf *)
504            with e ->            with e ->
505                lprintf "Error %s in udp_handler\n"                lprintf "Error %s in udp_handler\n"
506                  (Printexc2.to_string e);                  (Printexc2.to_string e);
507        ) ;        ) ;
508    | _ -> ()    | _ -> ()
509    
# Line 615  let _ = Line 615  let _ =
615  UDP tracker protocol  UDP tracker protocol
616    
617  Structures  Structures
618  Before announcing or scraping, you have to obtain a connection ID.  Before announcing or scraping, you have to obtain a connection ID.
619    
620  Choose a (random) transaction ID.  Choose a (random) transaction ID.
621  Fill the connect input structure.  Fill the connect input structure.
622  Send the packet.  Send the packet.
623  connect input Offset Size Name Value    connect input Offset Size Name Value
624  0 64-bit integer connection_id 0x41727101980    0 64-bit integer connection_id 0x41727101980
625  8 32-bit integer action 0    8 32-bit integer action 0
626  12 32-bit integer transaction_id    12 32-bit integer transaction_id
627  16    16
628    
629  Receive the packet.  Receive the packet.
630  Check whether the packet is at least 16 bytes.  Check whether the packet is at least 16 bytes.
631  Check whether the transaction ID is equal to the one you chose.  Check whether the transaction ID is equal to the one you chose.
632  Check whether the action is connect.  Check whether the action is connect.
633  Store the connection ID for future use.  Store the connection ID for future use.
634  connect output Offset Size Name Value    connect output Offset Size Name Value
635  0 32-bit integer action 0    0 32-bit integer action 0
636  4 32-bit integer transaction_id    4 32-bit integer transaction_id
637  8 64-bit integer connection_id    8 64-bit integer connection_id
638  16    16
639    
640  Choose a (random) transaction ID.  Choose a (random) transaction ID.
641  Fill the announce input structure.  Fill the announce input structure.
642  Send the packet.  Send the packet.
643  announce input Offset Size Name Value    announce input Offset Size Name Value
644  0 64-bit integer connection_id    0 64-bit integer connection_id
645  8 32-bit integer action 1    8 32-bit integer action 1
646  12 32-bit integer transaction_id    12 32-bit integer transaction_id
647  16 20-byte string info_hash    16 20-byte string info_hash
648  36 20-byte string peer_id    36 20-byte string peer_id
649  56 64-bit integer downloaded    56 64-bit integer downloaded
650  64 64-bit integer left    64 64-bit integer left
651  72 64-bit integer uploaded    72 64-bit integer uploaded
652  80 32-bit integer event    80 32-bit integer event
653  84 32-bit integer IP address 0    84 32-bit integer IP address 0
654  88 32-bit integer key    88 32-bit integer key
655  92 32-bit integer num_want -1    92 32-bit integer num_want -1
656  96 16-bit integer port    96 16-bit integer port
657  98    98
658    
659  Receive the packet.  Receive the packet.
660  Check whether the packet is at least 20 bytes.  Check whether the packet is at least 20 bytes.
661  Check whether the transaction ID is equal to the one you chose.  Check whether the transaction ID is equal to the one you chose.
662  Check whether the action is announce.  Check whether the action is announce.
663  Do not announce again until interval seconds have passed or an event has happened.  Do not announce again until interval seconds have passed or an event has happened.
664  announce output Offset Size Name Value    announce output Offset Size Name Value
665  0 32-bit integer action 1    0 32-bit integer action 1
666  4 32-bit integer transaction_id    4 32-bit integer transaction_id
667  8 32-bit integer interval    8 32-bit integer interval
668  12 32-bit integer leechers    12 32-bit integer leechers
669  16 32-bit integer seeders    16 32-bit integer seeders
670  20 + 6 * n 32-bit integer IP address    20 + 6 * n 32-bit integer IP address
671  24 + 6 * n 16-bit integer TCP port    24 + 6 * n 16-bit integer TCP port
672  20 + 6 * N    20 + 6 * N
673    
674  Up to about 74 torrents can be scraped at once. A full scrape can't be done with this protocol.  Up to about 74 torrents can be scraped at once. A full scrape can't be done with this protocol.
675    
676  Choose a (random) transaction ID.  Choose a (random) transaction ID.
677  Fill the scrape input structure.  Fill the scrape input structure.
678  Send the packet.  Send the packet.
679  scrape input Offset Size Name Value    scrape input Offset Size Name Value
680  0 64-bit integer connection_id    0 64-bit integer connection_id
681  8 32-bit integer action 2    8 32-bit integer action 2
682  12 32-bit integer transaction_id    12 32-bit integer transaction_id
683  16 + 20 * n 20-byte string info_hash    16 + 20 * n 20-byte string info_hash
684  16 + 20 * N    16 + 20 * N
685    
686  Receive the packet.  Receive the packet.
687  Check whether the packet is at least 8 bytes.  Check whether the packet is at least 8 bytes.
688  Check whether the transaction ID is equal to the one you chose.  Check whether the transaction ID is equal to the one you chose.
689  Check whether the action is scrape.  Check whether the action is scrape.
690  scrape output Offset Size Name Value    scrape output Offset Size Name Value
691  0 32-bit integer action 2    0 32-bit integer action 2
692  4 32-bit integer transaction_id    4 32-bit integer transaction_id
693  8 + 12 * n 32-bit integer seeders    8 + 12 * n 32-bit integer seeders
694  12 + 12 * n 32-bit integer completed    12 + 12 * n 32-bit integer completed
695  16 + 12 * n 32-bit integer leechers    16 + 12 * n 32-bit integer leechers
696  8 + 12 * N    8 + 12 * N
697    
698  If the tracker encounters an error, it might send an error packet.  If the tracker encounters an error, it might send an error packet.
699    
700  Receive the packet.  Receive the packet.
701  Check whether the packet is at least 8 bytes.  Check whether the packet is at least 8 bytes.
702  Check whether the transaction ID is equal to the one you chose.  Check whether the transaction ID is equal to the one you chose.
703  error output Offset Size Name Value    error output Offset Size Name Value
704  0 32-bit integer action 3    0 32-bit integer action 3
705  4 32-bit integer transaction_id    4 32-bit integer transaction_id
706  8 string message    8 string message
707    
708  If the tracker requires authentication, an authentication structure has to be appended to every packet you send to the tracker. The hash is the first 8 bytes of sha1(input + username + sha1(password)). authenticate input Offset Size Name    If the tracker requires authentication, an authentication structure has to be appended to every packet you send to the tracker. The hash is the first 8 bytes of sha1(input + username + sha1(password)). authenticate input Offset Size Name
709  0 8-byte zero-padded string username    0 8-byte zero-padded string username
710  8 8-byte string hash    8 8-byte string hash
711  16    16
712    
713    
714    
715  --------------------------------------------------------------------------------  --------------------------------------------------------------------------------
716    
717  Actions  Actions
718  0: connect  0: connect
719  1: announce  1: announce
720  2: scrape  2: scrape
721  3: error  3: error
722    
723  --------------------------------------------------------------------------------  --------------------------------------------------------------------------------
724    
725  Events  Events
 0: none  
 1: completed  
 2: started  
 3: stopped  
 *)  
726    0: none
727    1: completed
728    2: started
729    3: stopped
730    *)

Legend:
Removed from v.1.16  
changed lines
  Added in v.1.17

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26