P2p: add error for invalid authentification

This commit is contained in:
Grégoire Henry 2017-01-23 09:18:56 +01:00
parent ce986c4a9c
commit 52fab9528c
2 changed files with 7 additions and 2 deletions

View File

@ -32,6 +32,7 @@ type error += Rejected
type error += Decoding_error type error += Decoding_error
type error += Myself of Id_point.t type error += Myself of Id_point.t
type error += Not_enough_proof_of_work of Gid.t type error += Not_enough_proof_of_work of Gid.t
type error += Invalid_auth
module Crypto = struct module Crypto = struct
@ -336,9 +337,12 @@ let accept
Lwt_utils.protect begin fun () -> Lwt_utils.protect begin fun () ->
Ack.write fd cryptobox_data Ack >>=? fun () -> Ack.write fd cryptobox_data Ack >>=? fun () ->
Ack.read fd cryptobox_data Ack.read fd cryptobox_data
end ~on_error:begin fun _ -> end ~on_error:begin fun err ->
P2p_io_scheduler.close fd >>= fun _ -> P2p_io_scheduler.close fd >>= fun _ ->
fail Rejected match err with
| [ P2p_io_scheduler.Connection_closed ] -> fail Rejected
| [ Decipher_error ] -> fail Invalid_auth
| err -> Lwt.return (Error err)
end >>=? fun accepted -> end >>=? fun accepted ->
fail_unless accepted Rejected >>=? fun () -> fail_unless accepted Rejected >>=? fun () ->
let canceler = Canceler.create () in let canceler = Canceler.create () in

View File

@ -26,6 +26,7 @@ type error += Decoding_error
type error += Rejected type error += Rejected
type error += Myself of Id_point.t type error += Myself of Id_point.t
type error += Not_enough_proof_of_work of Gid.t type error += Not_enough_proof_of_work of Gid.t
type error += Invalid_auth
type authenticated_fd type authenticated_fd
(** Type of a connection that successfully passed the authentication (** Type of a connection that successfully passed the authentication