123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384(*****************************************************************************)(* *)(* MIT License *)(* Copyright (c) 2022 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. *)(* *)(*****************************************************************************)openCommunication.Distributed_wrappermoduleMake(D:Enriched_processwithtype'aio='aLwt.t):sigtypenode={name:string;ip:string;port:int}type'amaster_task:=workers:Distributed.Process_id.tlist->'aD.tvalrun:self_node:node->nodes:nodelist->'amaster_task->'aend=structtypenode={name:string;ip:string;port:int}letmaster_config~ip~port~nodes=D.Remote{D.Remote_config.node_name="master";D.Remote_config.local_port=port;D.Remote_config.connection_backlog=10;D.Remote_config.node_ip=ip;D.Remote_config.remote_nodes=nodes;}letmaster_procm~ret()=letopenDinlet*nodes=get_remote_nodesinlet*pid_to_send_to=get_self_pidin(* Dummy worker process in the master *)(* FIXME: why do we need this? *)let*()=register"worker"(fun_pid()->D.return())in(* spawn and monitor a process on the remote node atomically *)let*remote_pids=mapM(funn->let+pid,_ref=spawn~monitor:truen(Registered"worker")pid_to_send_toinpid)nodesinlet+r=m~workers:remote_pidsinret:=Somer;()letrun~self_node~nodesm=letlogs_level=Option.bind(Sys.getenv_opt"DP_LOGS")(funs->Result.get_ok@@Logs.level_of_strings)inLogs.Src.set_levelLogger.log_srclogs_level;Logs.set_reporter@@Logger.lwt_reporter();letret=refNoneinLwt.Exception_filter.(sethandle_all_except_runtime);Lwt_main.run(D.run_node~process:(master_procm~ret)(master_config~ip:self_node.ip~port:self_node.port~nodes:(List.map(funn->(n.ip,n.port,n.name))nodes)));Option.get!retend