Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source
Source file RPC_server.ml
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2018 Dynamic Ledger Solutions, Inc. <contact@tezos.com> *)(* Copyright (c) 2021 Tocqueville Group, Inc. <marcin.pastudzki@tqtezos.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. *)(* *)(*****************************************************************************)typecors=Resto_cohttp.Cors.t={allowed_headers:stringlist;allowed_origins:stringlist;}moduleRPC_logging=Internal_event.Legacy_logging.Make(structletname="rpc_http_event"end)includeResto_cohttp_server.Server.Make(Tezos_rpc.Encoding)(RPC_logging)moduleAcl=structincludeResto_acl.Acltypeendpoint=P2p_point.Id.addr_port_idtypepolicy=(endpoint*t)listletsecure=Deny_all{except=List.mapparse["GET /chains/*/blocks";"GET /chains/*/blocks/*";"GET /chains/*/blocks/*/context/**";"GET /chains/*/blocks/*/hash";"GET /chains/*/blocks/*/header";"GET /chains/*/blocks/*/header/**";"GET /chains/*/blocks/*/helpers/current_level";"GET /chains/*/blocks/*/live_blocks";"GET /chains/*/blocks/*/metadata";"GET /chains/*/blocks/*/metadata_hash";"GET /chains/*/blocks/*/minimal_valid_time";"GET /chains/*/blocks/*/operation_hashes";"GET /chains/*/blocks/*/operation_hashes/**";"GET /chains/*/blocks/*/operation_metadata_hash";"GET /chains/*/blocks/*/operations";"GET /chains/*/blocks/*/operations/**";"GET /chains/*/blocks/*/operations_metadata_hash";"GET /chains/*/blocks/*/protocols";"GET /chains/*/blocks/*/required_endorsements";"GET /chains/*/blocks/*/votes/**";"GET /chains/*/chain_id";"GET /chains/*/checkpoint";"GET /chains/*/invalid_blocks";"GET /chains/*/invalid_blocks/*";"GET /chains/*/is_bootstrapped";"GET /chains/*/mempool/filter";"GET /chains/*/mempool/monitor_operations";"GET /chains/*/mempool/pending_operations";"GET /config/network/user_activated_protocol_overrides";"GET /config/network/user_activated_upgrades";"GET /describe/**";"GET /errors";"GET /monitor/**";"GET /network/greylist/ips";"GET /network/greylist/peers";"GET /network/self";"GET /network/self";"GET /network/stat";"GET /network/version";"GET /network/versions";"GET /protocols";"GET /protocols/*";"GET /protocols/*/environment";"GET /version";"POST /chains/*/blocks/*/context/contracts/*/big_map_get";"POST /chains/*/blocks/*/endorsing_power";"POST /injection/operation";];}letallow_all=Allow_all{except=[]}letdefault(address:P2p_addr.t)=letopenIpaddrinifV6.scopeaddress=Interfacethenallow_allelsesecureletempty_policy=[]letmatch_address_and_portpoint1point2=letopenP2p_point.Idinpoint1.addr=point2.addr&&point1.port=point2.portletrecput_policy(addr,acl)=function|[]->[(addr,acl)]|(a,_)::policywhenmatch_address_and_portaddra->(addr,acl)::policy|entry::policy->entry::put_policy(addr,acl)policy(* FIXME (https://gitlab.com/tezos/tezos/-/issues/1320).
Use resto functions instead.
*)letmeth_to_string=function|Any->""|Exact`GET->"GET"|Exact`PUT->"PUT"|Exact`POST->"POST"|Exact`PATCH->"PATCH"|Exact`DELETE->"DELETE"letescaped_asterisk_seq=String.to_seq"%2A"letchunk_to_string=function|Wildcard->"*"|Literall->lets=Uri.pct_encodelinifString.containss'*'then(* slow path *)String.of_seq(Seq.flat_map(function'*'->escaped_asterisk_seq|c->Seq.returnc)(String.to_seqs))elsesletchunk_list_to_stringl="/"^String.concat"/"(List.mapchunk_to_stringl)letpath_to_string=function|FollowedByAnySuffixl->chunk_list_to_stringl^"/**"|Exactl->chunk_list_to_stringlletmatcher_to_string{meth;path}=meth_to_stringmeth^path_to_string pathletmatcher_encoding:matcherData_encoding.t=letopenData_encodinginconvmatcher_to_stringparsestringletendpoint_encoding:endpointData_encoding.t=letopenData_encodinginletopenP2p_point.Idinletparsestr=matchparse_addr_port_idstrwith|Okendpoint->endpoint|Errore->raise(Invalid_argument(Format.sprintf"%s in address"(string_of_parsing_errore)))inconvaddr_port_id_to_stringparsestringletpolicy_typep=ifp=securethen"Secure"elseifp=allow_allthen"AllowAll"else"Custom"letpolicy_encoding:(endpoint*t)listData_encoding.t=letopenData_encodinginlist@@union[case~title:"Whitelist"(Tag0)(obj2(req"address"endpoint_encoding)(req"whitelist"@@listmatcher_encoding))(function|addr,Deny_all{except}->Some(addr,except)|_->None)(fun(addr,except)->(addr,Deny_all{except}));case~title:"Blacklist"(Tag1)(obj2(req"address"endpoint_encoding)(req"blacklist"@@listmatcher_encoding))(function|addr,Allow_all{except}->Some(addr,except)|_->None)(fun(addr,except)->(addr,Allow_all{except}));]letpolicy_to_stringpolicy=letopenData_encodinginJson.constructpolicy_encodingpolicy|>Json.to_stringletfind_policypolicy(address,port)=letmatch_addrsearched_portsearched_addr(endpoint,acl)=letopenP2p_point.Idinmatch(endpoint.addr=searched_addr,endpoint.port,searched_port)with|true,None,_->Someacl|true,Someport,Somesearched_portwhenport=searched_port->Someacl|_->NoneinList.find_map(match_addrportaddress)policyletacl_type=functionAllow_all_->`Blacklist|Deny_all_->`WhitelistmoduleInternal_for_test=structtypenonrecendpoint=endpointletrecresolve_domain_namesresolve=letopenLwt_syntaxinfunction|[]->return_nil|(endpoint,acl)::remainder->letopenP2p_point.Idinlet*resolved=resolveendpointinletresolved=List.map(fun(ip_addr,_)->({endpointwithaddr=Format.asprintf"%a"Ipaddr.V6.ppip_addr;},acl))resolvedinlet+rem=resolve_domain_namesresolveremainderinresolved@remendletresolve_domain_names=letopenP2p_point.Idinletresolveendpoint=letservice=Option.fold~none:""~some:Int.to_stringendpoint.portinLwt_utils_unix.getaddrinfo~node:endpoint.addr~service~passive:falseinInternal_for_test.resolve_domain_namesresolveend