fix(examples/file-sharing): set Kademlia Mode::Server

Explicitly set `libp2p-kad` `Kademlia::set_mode` to `Mode::Server` to reduce complexity of example, i.e. not having to explicitly set external addresses.

Pull-Request: #4197.
This commit is contained in:
Max Inden 2023-08-01 15:53:38 +02:00 committed by GitHub
parent c86b665a65
commit fbf35e14cb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -7,7 +7,8 @@ use libp2p::{
core::Multiaddr, core::Multiaddr,
identity, identity,
kad::{ kad::{
record::store::MemoryStore, GetProvidersOk, Kademlia, KademliaEvent, QueryId, QueryResult, self, record::store::MemoryStore, GetProvidersOk, Kademlia, KademliaEvent, QueryId,
QueryResult,
}, },
multiaddr::Protocol, multiaddr::Protocol,
noise, noise,
@ -52,7 +53,7 @@ pub(crate) async fn new(
// Build the Swarm, connecting the lower layer transport logic with the // Build the Swarm, connecting the lower layer transport logic with the
// higher layer network behaviour logic. // higher layer network behaviour logic.
let swarm = SwarmBuilder::with_async_std_executor( let mut swarm = SwarmBuilder::with_async_std_executor(
transport, transport,
ComposedBehaviour { ComposedBehaviour {
kademlia: Kademlia::new(peer_id, MemoryStore::new(peer_id)), kademlia: Kademlia::new(peer_id, MemoryStore::new(peer_id)),
@ -68,6 +69,11 @@ pub(crate) async fn new(
) )
.build(); .build();
swarm
.behaviour_mut()
.kademlia
.set_mode(Some(kad::Mode::Server));
let (command_sender, command_receiver) = mpsc::channel(0); let (command_sender, command_receiver) = mpsc::channel(0);
let (event_sender, event_receiver) = mpsc::channel(0); let (event_sender, event_receiver) = mpsc::channel(0);