123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2019 Nomadic Labs, <contact@nomadic-labs.com> *)(* *)(* Permission is hereby granted, free of charge, to any person obtaining a *)(* copy of this software and associated documentation files (the "Software"),*)(* to deal in the Software without restriction, including without limitation *)(* the rights to use, copy, modify, merge, publish, distribute, sublicense, *)(* and/or sell copies of the Software, and to permit persons to whom the *)(* Software is furnished to do so, subject to the following conditions: *)(* *)(* The above copyright notice and this permission notice shall be included *)(* in all copies or substantial portions of the Software. *)(* *)(* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR*)(* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *)(* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *)(* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER*)(* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *)(* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *)(* DEALINGS IN THE SOFTWARE. *)(* *)(*****************************************************************************)openError_monadtypeerror_code=inttypet=|No_motive|Too_many_connections|Already_connected|Unknown_chain_name|Deprecated_distributed_db_version|Deprecated_p2p_version|Unknown_motiveoferror_codeletppppfmotive=matchmotivewith|No_motive->Format.fprintfppf"No motive"|Too_many_connections->Format.fprintfppf"Too many connections"|Already_connected->Format.fprintfppf"Already connected/connecting"|Unknown_chain_name->Format.fprintfppf"Unknown chain name"|Deprecated_distributed_db_version->Format.fprintfppf"Running a deprecated distributed db version"|Deprecated_p2p_version->Format.fprintfppf"Running a deprecated p2p layer version"|Unknown_motiveerror_code->Format.fprintfppf"Rejected for unknown reason, code (%i)"error_codeletpp_shortppfmotive=matchmotivewith|No_motive->Format.fprintfppf"No motive"|Too_many_connections->Format.fprintfppf"Too many connections"|Already_connected->Format.fprintfppf"Already connected"|Unknown_chain_name->Format.fprintfppf"Unknown chain name"|Deprecated_distributed_db_version->Format.fprintfppf"Deprecated ddb version"|Deprecated_p2p_version->Format.fprintfppf"Deprecated p2p version"|Unknown_motiveerror_code->Format.fprintfppf"unknown code (%i)"error_codeletencoding=letopenData_encodinginconv(function|No_motive->0|Too_many_connections->1|Unknown_chain_name->2|Deprecated_p2p_version->3|Deprecated_distributed_db_version->4|Already_connected->5|Unknown_motiveerror_code->error_code)(function|0->No_motive|1->Too_many_connections|2->Unknown_chain_name|3->Deprecated_p2p_version|4->Deprecated_distributed_db_version|5->Already_connected|error_code->Unknown_motiveerror_code)Data_encoding.int16typeerror+=Rejectingof{motive:t}let()=(* Rejecting socket connection with motive *)register_error_kind`Permanent~id:"node.p2p_socket.rejecting_incoming"~title:"Rejecting socket connection"~description:"Rejecting peer connection with motive."~pp:(funppfmotive->Format.fprintfppf"Rejecting peer connection. Cause : %a."ppmotive)Data_encoding.(obj1(req"motive"encoding))(functionRejecting{motive}->Somemotive|_->None)(funmotive->Rejecting{motive})letrejectingmotive=Result_syntax.tzfail(Rejecting{motive})