fn build_nodes<TMsg>(num: usize, base_port: u16) -> Vec<substrate_network_libp2p::Service<TMsg>>
	where TMsg: CustomMessage + Send + 'static
{
	let mut result: Vec<substrate_network_libp2p::Service<_>> = Vec::with_capacity(num);
	let mut first_addr = None::<Multiaddr>;

	for index in 0 .. num {
		let mut boot_nodes = Vec::new();

		if let Some(first_addr) = first_addr.as_ref() {
			boot_nodes.push(first_addr.clone()
				.with(Protocol::P2p(result[0].peer_id().clone().into()))
				.to_string());
		}

		let config = substrate_network_libp2p::NetworkConfiguration {
			listen_addresses: vec![build_multiaddr![Ip4([127, 0, 0, 1]), Tcp(base_port + index as u16)]],
			boot_nodes,
			..substrate_network_libp2p::NetworkConfiguration::default()
		};

		if first_addr.is_none() {
			first_addr = Some(config.listen_addresses.iter().next().unwrap().clone());
		}

		let proto = substrate_network_libp2p::RegisteredProtocol::new(&b"tst"[..], &[1]);
		result.push(substrate_network_libp2p::start_service(config, proto).unwrap().0);
	}

	result
}
/// Builds two services. The second one and further have the first one as its bootstrap node.
/// This is to be used only for testing, and a panic will happen if something goes wrong.
Builds two services. The second one and further have the first one as its bootstrap node.
This is to be used only for testing, and a panic will happen if something goes wrong.
Builds two services . The second one and further have the first one as its bootstrap node . This is to be used only for testing and a panic will happen if something goes wrong .
fn build_nodes<TMsg>(num: usize, base_port: u16) -> Vec<substrate_network_libp2p::Service<TMsg>>
	where TMsg: CustomMessage + Send + 'static
{
	let mut result: Vec<substrate_network_libp2p::Service<_>> = Vec::with_capacity(num);
	let mut first_addr = None::<Multiaddr>;
	for index in 0 .. num {
		let mut boot_nodes = Vec::new();
		if let Some(first_addr) = first_addr.as_ref() {
			boot_nodes.push(first_addr.clone()
				.with(Protocol::P2p(result[0].peer_id().clone().into()))
				.to_string());
		}
		let config = substrate_network_libp2p::NetworkConfiguration {
			listen_addresses: vec![build_multiaddr![Ip4([127, 0, 0, 1]), Tcp(base_port + index as u16)]],
			boot_nodes,
			..substrate_network_libp2p::NetworkConfiguration::default()
		};
		if first_addr.is_none() {
			first_addr = Some(config.listen_addresses.iter().next().unwrap().clone());
		}
		let proto = substrate_network_libp2p::RegisteredProtocol::new(&b"tst"[..], &[1]);
		result.push(substrate_network_libp2p::start_service(config, proto).unwrap().0);
	}
	result
}
fn build_nodes < TMsg > ( num : usize , base_port : u16 ) -> Vec < substrate_network_libp2p :: Service < TMsg > > where TMsg : CustomMessage + Send + ' static { let mut result : Vec < substrate_network_libp2p :: Service < _ > > = Vec :: with_capacity ( num ) ; let mut first_addr = None :: < Multiaddr > ; for index in 0 .. num { let mut boot_nodes = Vec :: new ( ) ; if let Some ( first_addr ) = first_addr . as_ref ( ) { boot_nodes . push ( first_addr . clone ( ) . with ( Protocol :: P2p ( result [ 0 ] . peer_id ( ) . clone ( ) . into ( ) ) ) . to_string ( ) ) ; } let config = substrate_network_libp2p :: NetworkConfiguration { listen_addresses : vec ! [ build_multiaddr [ Ip4 ( [ 127 0 0 1 ] ) Tcp ( base_port index as u16 ) ] ] , boot_nodes , .. substrate_network_libp2p :: NetworkConfiguration :: default ( ) } ; if first_addr . is_none ( ) { first_addr = Some ( config . listen_addresses . iter ( ) . next ( ) . unwrap ( ) . clone ( ) ) ; } let proto = substrate_network_libp2p :: RegisteredProtocol :: new ( & b" " [ .. ] , & [ 1 ] ) ; result . push ( substrate_network_libp2p :: start_service ( config , proto ) . unwrap ( ) . 0 ) ; } result }
Builds two services.
Builds two services .
num
usize
base_port
u16
num
usize
base_port
u16