123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2023 Nomadic Labs, <contact@nomadic-labs.com> *)(* Copyright (c) 2023 Functori, <contact@functori.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. *)(* *)(*****************************************************************************)openGossipsub_intfmoduleTypes=Tezos_dal_node_services.TypesmoduleValidate_message_hook=struct(* FIXME: https://gitlab.com/tezos/tezos/-/issues/5674
Refactor gossipsub integration to avoid this mutable hook in the lib. *)letcheck_message=ref(fun?message:_~message_id:_()->Format.eprintf"Gs interface: messages validatation function is not set@.";`Unknown)letsetfunc=check_message:=funcendletmessage_valid?message~message_id()=!Validate_message_hook.check_message?message~message_id()moduleAutomaton_config:AUTOMATON_CONFIGwithtypeTime.t=Types.Time.tandtypeSpan.t=Types.Span.tandtypeSubconfig.Peer.t=Types.Peer.tandtypeSubconfig.Topic.t=Types.Topic.tandtypeSubconfig.Message_id.t=Types.Message_id.tandtypeSubconfig.Message.t=Types.Message.t=structmoduleSpan=Types.SpanmoduleTime=Types.TimemoduleSubconfig=structmodulePeer=Types.PeermoduleTopic=Types.TopicmoduleMessage_id=Types.Message_idmoduleMessage=structincludeTypes.Messageletvalid=message_validendendendmoduleMonad=structtype'at='aLwt.tlet(let*)=Lwt.bindletreturn=Lwt.returnletsleep(span:Types.Span.t)=Lwt_unix.sleep@@Types.Span.to_float_sspanend(** Instantiate the worker functor *)moduleWorker_config:Gossipsub_intf.WORKER_CONFIGURATIONwithtypeGS.Topic.t=Types.Topic.tandtypeGS.Message_id.t=Types.Message_id.tandtypeGS.Message.t=Types.Message.tandtypeGS.Peer.t=Types.Peer.tandtypeGS.Span.t=Types.Span.tandtypeGS.Time.t=Types.Time.tandtype'aMonad.t='aLwt.t=structmoduleGS=Tezos_gossipsub.Automaton(Automaton_config)moduleMonad=Monad(* TODO: https://gitlab.com/tezos/tezos/-/issues/5596
Use Seq_s instead of Lwt_stream to implement module Stream. *)moduleStream=structtype'at={stream:'aLwt_stream.t;pusher:'aoption->unit;mutablelength:int;(* The [length] field counts the number of elements in the stream. It
is incremented on calls to {!push}, decremented on succesful calls to
{!get}, and reset on calls to {!get_available}. *)}letempty()=letstream,pusher=Lwt_stream.create()in{stream;pusher;length=0}letpushet=t.pusher(Somee);t.length<-t.length+1letpopt=letopenLwt_syntaxinlet*r=Lwt_stream.gett.streaminmatchrwith|Somer->t.length<-t.length-1;Lwt.returnr|None->Stdlib.failwith"Invariant: None values are never pushed in the stream"letget_availablet=t.length<-0;Lwt_stream.get_availablet.streamletlengtht=t.lengthendendmoduleWorker_instance=Tezos_gossipsub.Worker(Worker_config)