123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354(*****************************************************************************)(* *)(* SPDX-License-Identifier: MIT *)(* Copyright (c) 2023 Nomadic Labs, <contact@nomadic-labs.com> *)(* *)(*****************************************************************************)typeread_write=Read|Writetypet=|Connection_lostofread_write|Connection_closed_by_peerofread_write|Connection_closed_by_unexpected_errorof(read_write*string)|TCP_connection_refused|TCP_connection_unreachable|TCP_connection_canceled|TCP_connection_failed_unexpected_errorofstring|Scheduled_pop_unexpected_erroroftztrace|Scheduled_push_unexpected_erroroftztrace|IO_scheduler_closed|IO_scheduler_shutdown|Accept_write_erroroftztrace|Ack_read_erroroftztrace|Authentication_rejected_no_common_protocol|Authentication_rejectedofP2p_rejection.t|Authentication_rejected_by_peerofP2p_rejection.t|Authentication_rejected_erroroftztrace|Incoming_connection_too_many|Incoming_connection_banned|Unexpected_peer_id|IP_manually_banned|Peer_id_manually_banned|Pool_destroyed|Peer_swapped|Explicit_RPC|Maintenance_too_many|Userofstring|Unknown_reasonletencoding=letopenData_encodinginletencoding_read_write=union[case(Tag0x01)~title:"Read"(constant"Read")(functionRead->Some()|_->None)(fun()->Read);case(Tag0x02)~title:"Write"(constant"Write")(functionWrite->Some()|_->None)(fun()->Write);]inunion[case(Tag0x01)~title:"Connection_lost"(obj2(req"reason"(constant"Connection_lost"))(req"while"encoding_read_write))(functionConnection_lostrw->Some((),rw)|_->None)(fun((),rw)->Connection_lostrw);case(Tag0x02)~title:"Connection_closed_by_peer"(obj2(req"reason"(constant"Connection_closed_by_peer"))(req"while"encoding_read_write))(functionConnection_closed_by_peerrw->Some((),rw)|_->None)(fun((),rw)->Connection_closed_by_peerrw);case(Tag0x03)~title:"Connection_closed_by_unexpected_error"(obj3(req"reason"(constant"Connection_closed_by_unexpected_error"))(req"while"encoding_read_write)(req"error"string))(function|Connection_closed_by_unexpected_error(rw,err)->Some((),rw,err)|_->None)(fun((),rw,err)->Connection_closed_by_unexpected_error(rw,err));case(Tag0x04)~title:"TCP_connection_refused"(constant"TCP_connection_refused")(functionTCP_connection_refused->Some()|_->None)(fun()->TCP_connection_refused);case(Tag0x05)~title:"TCP_connection_unreachable"(constant"TCP_connection_unreachable")(functionTCP_connection_unreachable->Some()|_->None)(fun()->TCP_connection_unreachable);case(Tag0x06)~title:"TCP_connection_canceled"(constant"TCP_connection_canceled")(functionTCP_connection_canceled->Some()|_->None)(fun()->TCP_connection_canceled);case(Tag0x07)~title:"TCP_connection_failed_unexpected_error"(obj2(req"reason"(constant"TCP_connection_failed_unexpected_error"))(req"error"string))(function|TCP_connection_failed_unexpected_errorexn->Some((),exn)|_->None)(fun((),exn)->TCP_connection_failed_unexpected_errorexn);case(Tag0x08)~title:"Scheduled_pop_unexpected_error"(obj2(req"reason"(constant"Scheduled_pop_unexpected_error"))(req"trace"Error_monad.trace_encoding))(function|Scheduled_pop_unexpected_errortrace->Some((),trace)|_->None)(fun((),trace)->Scheduled_pop_unexpected_errortrace);case(Tag0x09)~title:"Scheduled_push_unexpected_error"(obj2(req"reason"(constant"Scheduled_push_unexpected_error"))(req"trace"Error_monad.trace_encoding))(function|Scheduled_push_unexpected_errortrace->Some((),trace)|_->None)(fun((),trace)->Scheduled_push_unexpected_errortrace);case(Tag0x10)~title:"IO_scheduler_closed"(constant"IO_scheduler_closed")(functionIO_scheduler_closed->Some()|_->None)(fun()->IO_scheduler_closed);case(Tag0x11)~title:"IO_scheduler_shutdown"(constant"IO_scheduler_shutdown")(functionIO_scheduler_shutdown->Some()|_->None)(fun()->IO_scheduler_shutdown);case(Tag0x12)~title:"Accept_write_error"(obj2(req"reason"(constant"Accept_write_error"))(req"trace"Error_monad.trace_encoding))(functionAccept_write_errortrace->Some((),trace)|_->None)(fun((),trace)->Accept_write_errortrace);case(Tag0x13)~title:"Ack_read_error"(obj2(req"reason"(constant"Ack_read_error"))(req""Error_monad.trace_encoding))(functionAck_read_errortrace->Some((),trace)|_->None)(fun((),trace)->Ack_read_errortrace);case(Tag0x14)~title:"Authentication_rejected_no_common_protocol"(constant"Authentication_rejected_no_common_protocol")(function|Authentication_rejected_no_common_protocol->Some()|_->None)(fun()->Authentication_rejected_no_common_protocol);case(Tag0x15)~title:"Authentication_rejected"(obj2(req"reason"(constant"Authentication_rejected"))(req""P2p_rejection.encoding))(function|Authentication_rejectedmotive->Some((),motive)|_->None)(fun((),motive)->Authentication_rejectedmotive);case(Tag0x16)~title:"Authentication_rejected_by_peer"(obj2(req"reason"(constant"Authentication_rejected_by_peer"))(req""P2p_rejection.encoding))(function|Authentication_rejected_by_peermotive->Some((),motive)|_->None)(fun((),motive)->Authentication_rejected_by_peermotive);case(Tag0x17)~title:"Authentication_rejected_error"(obj2(req"reason"(constant"Authentication_rejected_error"))(req""Error_monad.trace_encoding))(function|Authentication_rejected_errorerr->Some((),err)|_->None)(fun((),err)->Authentication_rejected_errorerr);case(Tag0x18)~title:"Incoming_connection_too_many"(constant"Incoming_connection_too_many")(functionIncoming_connection_too_many->Some()|_->None)(fun()->Incoming_connection_too_many);case(Tag0x19)~title:"Incoming_connection_banned"(constant"Incoming_connection_banned")(functionIncoming_connection_banned->Some()|_->None)(fun()->Incoming_connection_banned);case(Tag0x20)~title:"Unexpected_peer_id"(constant"Unexpected_peer_id")(functionUnexpected_peer_id->Some()|_->None)(fun()->Unexpected_peer_id);case(Tag0x21)~title:"IP_manually_banned"(constant"IP_manually_banned")(functionIP_manually_banned->Some()|_->None)(fun()->IP_manually_banned);case(Tag0x22)~title:"Peer_id_manually_banned"(constant"Peer_id_manually_banned")(functionPeer_id_manually_banned->Some()|_->None)(fun()->Peer_id_manually_banned);case(Tag0x23)~title:"Pool_destroyed"(constant"Pool_destroyed")(functionPool_destroyed->Some()|_->None)(fun()->Pool_destroyed);case(Tag0x24)~title:"Peer_swapped"(constant"Peer_swapped")(functionPeer_swapped->Some()|_->None)(fun()->Peer_swapped);case(Tag0x25)~title:"Explicit_RPC"(constant"Explicit_RPC")(functionExplicit_RPC->Some()|_->None)(fun()->Explicit_RPC);case(Tag0x26)~title:"Maintenance_too_many"(constant"Maintenance_too_many")(functionMaintenance_too_many->Some()|_->None)(fun()->Maintenance_too_many);case(Tag0x27)~title:"User"(obj2(req"reason"(constant"User"))(req""string))(functionUserreason->Some((),reason)|_->None)(fun((),reason)->Userreason);case(Tag0x28)~title:"Unknown_reason"(constant"Unknown_reason")(functionUnknown_reason->Some()|_->None)(fun()->Unknown_reason);]letppfmt=letpp_read_writefmt=function|Read->Format.fprintffmt"receiving"|Write->Format.fprintffmt"sending"infunction|Connection_lostrw->Format.fprintffmt"connection lost while %a data"pp_read_writerw|Connection_closed_by_peerrw->Format.fprintffmt"connection closed by peer while %a data"pp_read_writerw|Connection_closed_by_unexpected_error(rw,exn)->Format.fprintffmt"connection closed by unexpected error while %a data: %s"pp_read_writerwexn|TCP_connection_refused->Format.fprintffmt"TCP connection refused"|TCP_connection_unreachable->Format.fprintffmt"TCP connection, peer unreachable"|TCP_connection_canceled->Format.fprintffmt"TCP connection cancelled"|TCP_connection_failed_unexpected_errorex->Format.fprintffmt"TCP connection failed with unexpected error, %s"ex|Scheduled_pop_unexpected_errortrace->Format.fprintffmt"unexpected error when poping on scheduled connection, %a"Error_monad.pp_print_top_error_of_tracetrace|Scheduled_push_unexpected_errortrace->Format.fprintffmt"unexpected error when pushing on scheduled connection, %a"Error_monad.pp_print_top_error_of_tracetrace|IO_scheduler_closed->Format.fprintffmt"IO scheduler is closed"|IO_scheduler_shutdown->Format.fprintffmt"IO scheduler is shutting down"|Accept_write_errortrace->Format.fprintffmt"error when sending accept, %a"Error_monad.pp_print_top_error_of_tracetrace|Ack_read_errortrace->Format.fprintffmt"error when receiving ack, %a"Error_monad.pp_print_top_error_of_tracetrace|Authentication_rejected_no_common_protocol->Format.fprintffmt"authentication rejected by us: no common protocol"|Authentication_rejectedmotive->Format.fprintffmt"authentication rejected by us with motive: %a"P2p_rejection.pp_shortmotive|Authentication_rejected_by_peermotive->Format.fprintffmt"authentication rejected by peer with motive: %a"P2p_rejection.pp_shortmotive|Authentication_rejected_errorerr->Format.fprintffmt"authentication has been rejected from error: %a"Error_monad.pp_print_top_error_of_traceerr|Incoming_connection_too_many->Format.fprintffmt"incoming connection not accepted: too many incoming connections"|Incoming_connection_banned->Format.fprintffmt"incoming connection not accepted: point is banned"|Unexpected_peer_id->Format.fprintffmt"unexpected peer id"|IP_manually_banned->Format.fprintffmt"IP manually banned"|Peer_id_manually_banned->Format.fprintffmt"peer_id manually banned"|Pool_destroyed->Format.fprintffmt"pool destroyed"|Peer_swapped->Format.fprintffmt"peer has been swapped"|Explicit_RPC->Format.fprintffmt"disconnected using a RPC"|Maintenance_too_many->Format.fprintffmt"maintenance detected too many connections"|Userreason->Format.fprintffmt"%s"reason|Unknown_reason->Format.fprintffmt"connection canceled without reason"