341 |
try |
try |
342 |
handler sock p; |
handler sock p; |
343 |
with e -> |
with e -> |
344 |
lprintf "Exception %s in BTProtocol.parse_fun while handling peer_id\n" |
lprintf_nl "Exception %s in BTProtocol.parse_fun while handling peer_id" |
345 |
(Printexc2.to_string e); |
(Printexc2.to_string e); |
346 |
dump payload; |
dump payload; |
347 |
buf_used b b.len; |
buf_used b b.len; |
359 |
if msg_len < 0 then |
if msg_len < 0 then |
360 |
begin |
begin |
361 |
let (ip,port) = (TcpBufferedSocket.peer_addr sock) in |
let (ip,port) = (TcpBufferedSocket.peer_addr sock) in |
362 |
lprintf "BT: Unknown message from %s:%d dropped!! peerid:%b data_len:%i msg_len:%i software: %s\n" |
lprintf_nl "BT: Unknown message from %s:%d dropped!! peerid:%b data_len:%i msg_len:%i software: %s" |
363 |
(Ip.to_string ip) port c.client_received_peer_id b.len msg_len c.client_software; |
(Ip.to_string ip) port c.client_received_peer_id b.len msg_len c.client_software; |
364 |
dump (String.sub b.buf b.pos (min b.len 30)); |
dump (String.sub b.buf b.pos (min b.len 30)); |
365 |
buf_used b b.len; |
buf_used b b.len; |
370 |
trying to waste our bandwidth ? *) |
trying to waste our bandwidth ? *) |
371 |
begin |
begin |
372 |
let (ip,port) = (TcpBufferedSocket.peer_addr sock) in |
let (ip,port) = (TcpBufferedSocket.peer_addr sock) in |
373 |
lprintf "btprotocol.bt_handler: closed connection from %s:%d because of too much data!! data_len:%i msg_len:%i software: %s\n" |
lprintf_nl "btprotocol.bt_handler: closed connection from %s:%d because of too much data!! data_len:%i msg_len:%i software: %s" |
374 |
(Ip.to_string ip) port b.len msg_len c.client_software; |
(Ip.to_string ip) port b.len msg_len c.client_software; |
375 |
dump (String.sub b.buf b.pos (min b.len 30)); |
dump (String.sub b.buf b.pos (min b.len 30)); |
376 |
buf_used b b.len; |
buf_used b b.len; |
394 |
(* lprintf "Parsed, calling handler\n"; *) |
(* lprintf "Parsed, calling handler\n"; *) |
395 |
handler sock p |
handler sock p |
396 |
with e -> |
with e -> |
397 |
lprintf "Exception %s in BTProtocol.parse_fun while handling message with opcode: %d\n" |
lprintf_nl "Exception %s in BTProtocol.parse_fun while handling message with opcode: %d" |
398 |
(Printexc2.to_string e) opcode; |
(Printexc2.to_string e) opcode; |
399 |
dump payload; |
dump payload; |
400 |
else |
else |
407 |
with |
with |
408 |
| Wait_for_more s -> |
| Wait_for_more s -> |
409 |
if closed sock && s <> "after_peer_id" then |
if closed sock && s <> "after_peer_id" then |
410 |
lprintf "bt_handler: Socket was closed while waiting for more data in %s\n" s |
lprintf_nl "bt_handler: Socket was closed while waiting for more data in %s" s |
411 |
| e -> |
| e -> |
412 |
lprintf "Exception %s in bt_handler\n" |
lprintf_nl "Exception %s in bt_handler" |
413 |
(Printexc2.to_string e) |
(Printexc2.to_string e) |
414 |
|
|
|
|
|
415 |
let handlers info gconn = |
let handlers info gconn = |
416 |
let rec iter_read sock nread = |
let rec iter_read sock nread = |
417 |
(* lprintf "iter_read %d\n" nread; *) |
(* lprintf "iter_read %d\n" nread; *) |
436 |
end |
end |
437 |
else if (TcpBufferedSocket.closed sock) then |
else if (TcpBufferedSocket.closed sock) then |
438 |
let (ip,port) = (TcpBufferedSocket.peer_addr sock) in |
let (ip,port) = (TcpBufferedSocket.peer_addr sock) in |
439 |
lprintf "bt-handshake: closed sock from %s:%d b.len:%i slen:%i\n" |
lprintf_nl "bt-handshake: closed sock from %s:%d b.len:%i slen:%i" |
440 |
(Ip.to_string ip) port b.len slen; |
(Ip.to_string ip) port b.len slen; |
441 |
|
|
442 |
| Reader h -> |
| Reader h -> |
443 |
h gconn sock |
h gconn sock |
444 |
in |
in |
445 |
iter_read |
iter_read |
446 |
|
|
447 |
let set_bt_sock sock info ghandler = |
let set_bt_sock sock info ghandler = |
448 |
let gconn = { |
let gconn = { |
449 |
gconn_handler = ghandler; |
gconn_handler = ghandler; |
468 |
set_lifetime sock 30. |
set_lifetime sock 30. |
469 |
(* TcpBufferedSocket.close sock "write done" *) |
(* TcpBufferedSocket.close sock "write done" *) |
470 |
| refill :: _ -> refill sock) |
| refill :: _ -> refill sock) |
471 |
|
|
|
|
|
472 |
|
|
473 |
(* |
(* |
474 |
No payload: |
No payload: |
501 |
try |
try |
502 |
let s = TcpMessages.write msg in |
let s = TcpMessages.write msg in |
503 |
if !verbose_msg_clients then begin |
if !verbose_msg_clients then begin |
504 |
lprintf "send message: %s\n" (TcpMessages.to_string msg); |
lprintf_nl "send message: %s" (TcpMessages.to_string msg); |
505 |
end; |
end; |
506 |
(* dump s; *) |
(* dump s; *) |
507 |
write_string sock s |
write_string sock s |
508 |
with e -> |
with e -> |
509 |
lprintf "CLIENT : Error %s in send_client\n" |
lprintf_nl "CLIENT : Error %s in send_client" |
510 |
(Printexc2.to_string e) |
(Printexc2.to_string e) |
511 |
) |
) |
512 |
|
|