mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-04-28 13:17:56 +00:00
Make libp2p compile for wasm32-unkown-unknown (#2412)
* Make libp2p compile for wasm32-unkown-unknown * Fix tests * Add some crates
This commit is contained in:
committed by
Gavin Wood
parent
ebbd6c8ec4
commit
0b6490854d
@@ -20,9 +20,11 @@ use libp2p::NetworkBehaviour;
|
||||
use libp2p::core::{Multiaddr, PeerId, ProtocolsHandler, PublicKey};
|
||||
use libp2p::core::swarm::{ConnectedPoint, NetworkBehaviour, NetworkBehaviourAction};
|
||||
use libp2p::core::swarm::{NetworkBehaviourEventProcess, PollParameters};
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
use libp2p::core::swarm::toggle::Toggle;
|
||||
use libp2p::identify::{Identify, IdentifyEvent, protocol::IdentifyInfo};
|
||||
use libp2p::kad::{Kademlia, KademliaOut};
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
use libp2p::mdns::{Mdns, MdnsEvent};
|
||||
use libp2p::multiaddr::Protocol;
|
||||
use libp2p::ping::{Ping, PingConfig, PingEvent, PingSuccess};
|
||||
@@ -45,6 +47,7 @@ pub struct Behaviour<TMessage, TSubstream> {
|
||||
/// Periodically identifies the remote and responds to incoming requests.
|
||||
identify: Identify<TSubstream>,
|
||||
/// Discovers nodes on the local network.
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
mdns: Toggle<Mdns<TSubstream>>,
|
||||
|
||||
/// Queue of events to produce for the outside.
|
||||
@@ -74,6 +77,11 @@ impl<TMessage, TSubstream> Behaviour<TMessage, TSubstream> {
|
||||
kademlia.add_connected_address(peer_id, addr.clone());
|
||||
}
|
||||
|
||||
if enable_mdns {
|
||||
#[cfg(target_os = "unknown")]
|
||||
warn!(target: "sub-libp2p", "mDNS is not available on this platform");
|
||||
}
|
||||
|
||||
let clock = Clock::new();
|
||||
Behaviour {
|
||||
ping: Ping::new(PingConfig::new()),
|
||||
@@ -87,6 +95,7 @@ impl<TMessage, TSubstream> Behaviour<TMessage, TSubstream> {
|
||||
local_peer_id: local_public_key.into_peer_id(),
|
||||
},
|
||||
identify,
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
mdns: if enable_mdns {
|
||||
match Mdns::new() {
|
||||
Ok(mdns) => Some(mdns).into(),
|
||||
@@ -304,6 +313,7 @@ impl<TMessage, TSubstream> NetworkBehaviourEventProcess<PingEvent> for Behaviour
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
impl<TMessage, TSubstream> NetworkBehaviourEventProcess<MdnsEvent> for Behaviour<TMessage, TSubstream> {
|
||||
fn inject_event(&mut self, event: MdnsEvent) {
|
||||
match event {
|
||||
|
||||
@@ -17,8 +17,10 @@
|
||||
use futures::prelude::*;
|
||||
use libp2p::{
|
||||
InboundUpgradeExt, OutboundUpgradeExt, PeerId, Transport,
|
||||
mplex, identity, secio, yamux, tcp, dns, websocket, bandwidth
|
||||
mplex, identity, secio, yamux, websocket, bandwidth
|
||||
};
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
use libp2p::{tcp, dns};
|
||||
use libp2p::core::{self, transport::boxed::Boxed, muxing::StreamMuxerBox};
|
||||
use std::{io, sync::Arc, time::Duration, usize};
|
||||
|
||||
@@ -35,9 +37,15 @@ pub fn build_transport(
|
||||
mplex_config.max_buffer_len_behaviour(mplex::MaxBufferBehaviour::Block);
|
||||
mplex_config.max_buffer_len(usize::MAX);
|
||||
|
||||
let transport = tcp::TcpConfig::new();
|
||||
let transport = websocket::WsConfig::new(transport.clone()).or_transport(transport);
|
||||
let transport = dns::DnsConfig::new(transport);
|
||||
#[cfg(not(target_os = "unknown"))]
|
||||
let transport = {
|
||||
let transport = tcp::TcpConfig::new();
|
||||
let transport = websocket::WsConfig::new(transport.clone()).or_transport(transport);
|
||||
dns::DnsConfig::new(transport)
|
||||
};
|
||||
#[cfg(target_os = "unknown")]
|
||||
let transport = websocket::BrowserWsConfig::new();
|
||||
|
||||
let (transport, sinks) = bandwidth::BandwidthLogging::new(transport, Duration::from_secs(5));
|
||||
|
||||
// TODO: rework the transport creation (https://github.com/libp2p/rust-libp2p/issues/783)
|
||||
|
||||
Reference in New Issue
Block a user