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

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

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

revision 1.19 by spiralvoice, Wed Jul 27 20:06:16 2005 UTC revision 1.20 by spiralvoice, Thu Aug 4 22:00:23 2005 UTC
# Line 321  module TcpMessages = struct Line 321  module TcpMessages = struct
321        s        s
322    end    end
323    
324    (*************************************************************************)
325    (*                                                                       *)
326    (*                         UdpMessages                                   *)
327    (*                                                                       *)
328    (*************************************************************************)
329    (*  
330    
331    
332    
333    
334    module UdpMessages = struct
335        
336        type t =
337          PingReq of int * string * string
338        | SupernodePongReq of int * string * string
339        | NodePongReq of int * string
340        | UnknownReq of int * string
341        let extract_string s pos =
342          let end_pos = String.index_from s pos '\000' in
343          String.sub s pos (end_pos - pos), pos + 1
344        
345        let parse p =
346          match int_of_char p.[0] with
347          | 0x27 ->
348              let min_enc_type = get_int p 1 in
349              let unknown = String.sub p 5 1 in
350              let netname, pos = extract_string p 6 in
351              
352              PingReq (min_enc_type, unknown, netname)
353          | 0x28 ->
354              
355              let min_enc_type = get_int p 1 in
356              let unknown = String.sub p 5 6 in
357              let netname, pos = extract_string p 11 in
358              SupernodePongReq (min_enc_type, unknown, netname)
359          
360          | 0x29 ->
361              let min_enc_type = get_int p 1 in
362              let unknown = String.sub p 5 (String.length p - 5) in
363              NodePongReq (min_enc_type, unknown)
364          | n -> UnknownReq (n, p)
365        
366        let write p =
367          let b = Buffer.create 100 in
368          begin
369            match p with
370            | PingReq (min_enc_type, unknown, netname) ->
371                buf_int8 b 0x27;
372                buf_int b min_enc_type;
373                Buffer.add_string b unknown;
374                Buffer.add_string b netname;
375                buf_int8 b 0x00
376            | SupernodePongReq (min_enc_type, unknown, netname) ->
377                buf_int8 b 0x28;
378                buf_int b min_enc_type;
379                Buffer.add_string b unknown;
380                Buffer.add_string b netname;
381                buf_int8 b 0x00
382            | NodePongReq (min_enc_type, unknown) ->
383                buf_int8 b 0x29;
384                buf_int b min_enc_type;
385                Buffer.add_string b unknown
386            | UnknownReq (opcode, unknown) ->
387                Buffer.add_string b unknown;
388          end;
389          Buffer.contents b
390        
391        let to_string p =
392          let b = Buffer.create 100 in
393          begin
394            match p with
395            | PingReq (min_enc_type, unknown, netname) ->
396                Printf.bprintf b "Ping (%d, " min_enc_type;
397                bprint_ints b unknown;
398                Printf.bprintf b ", %s)" netname
399            | SupernodePongReq (min_enc_type, unknown, netname) ->
400                Printf.bprintf b "SupernodePong (%d, " min_enc_type;
401                bprint_ints b unknown;
402                Printf.bprintf b ", %s)" netname
403            | NodePongReq (min_enc_type, unknown) ->
404                Printf.bprintf b "NodePong (%d, " min_enc_type;
405                bprint_ints b unknown;
406                Printf.bprintf b ")"
407            | UnknownReq (opcode, unknown) ->
408                Printf.bprintf b "Unknown \n    ";
409                bprint_ints b unknown;
410                Printf.bprintf b  "\n    ";
411                bprint_chars b unknown;
412                Printf.bprintf b "\n"
413          end;
414          Buffer.contents b
415    
416        let udp_send t ip port ping msg =
417          
418          if !verbose_udp then begin
419              lprintf "Message UDP to %s:%d\n%s\n" (Ip.to_string ip) port
420                (to_string msg);
421            end;
422          
423          try
424            let s = write msg in
425            UdpSocket.write t ping s ip port
426          with e ->
427              lprintf "FT: Exception %s in udp_send\n" (Printexc2.to_string e)          
428      end
429    *)
430    
431    
432    
433  exception Wait_for_more of string  exception Wait_for_more of string
434    
435  let bt_handler parse_fun handler c sock =  let bt_handler parse_fun handler c sock =
436    try    try
437      let b = TcpBufferedSocket.buf sock in      let b = TcpBufferedSocket.buf sock in

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.20

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