123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116(*****************************************************************************)(* *)(* Open Source License *)(* Copyright (c) 2020 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. *)(* *)(*****************************************************************************)letnext_name=ref1letfresh_name()=letindex=!next_nameinincrnext_name;"cluster"^string_of_intindexletcreate?path?namecount?rpc_localarguments=letname=matchnamewithNone->fresh_name()|Somename->nameinList.map(funi->Node.create?path~name:(name^"."^string_of_inti)?rpc_localarguments)(range1count)letsymmetric_add_peerab=Node.add_peerab;Node.add_peerbaletmeta_connectconnectab=List.iter(funa->List.iter(connecta)b)aletrecmeta_cliqueconnect=function|[]->()|head::tail->List.iter(connecthead)tail;meta_cliqueconnecttailletrecmeta_clique_lwtconnect=function|[]->unit|head::tail->let*()=Lwt_list.iter_s(connecthead)tailinmeta_clique_lwtconnecttailletmeta_ringconnectnodes=matchnodeswith|[]->()|first::_->letrecloop=function|[]->(* We checked that the list was not empty already. *)assertfalse|[last]->connectlastfirst|a::(b::_astail)->connectab;looptailinloopnodesletmeta_starconnectcenterother_nodes=List.iter(connectcenter)other_nodesletconnect=meta_connectsymmetric_add_peerletclique=meta_cliquesymmetric_add_peerletring=meta_ringsymmetric_add_peerletstar=meta_starsymmetric_add_peerletstart?(public=false)?event_level?event_sections_levels?(wait_connections=false)nodes=letstart_nodenode=let*()=Node.identity_generatenodeinletn=Node.get_peersnode|>List.lengthinlet*()=Node.config_initnode[]inlet*()=Node.run?event_level?event_sections_levelsnode(ifpublicthen[]else[Private_mode])inletwaiter=let*()=ifwait_connectionsthen(Node.on_eventnode(fun{name;_}->matchnamewith|"disconnection.v0"->Log.debug"The topology of the test has changed"|_->());Node.wait_for_connectionsnoden)elseunitinNode.wait_for_readynodeinwaiterinLwt_list.iter_pstart_nodenodes