Skip to content

Commit

Permalink
set mode to server by default
Browse files Browse the repository at this point in the history
  • Loading branch information
melekes committed Jul 26, 2023
1 parent 01ba6d2 commit 7d4e8e2
Showing 1 changed file with 5 additions and 12 deletions.
17 changes: 5 additions & 12 deletions client/network/src/discovery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ use ip_network::IpNetwork;
use libp2p::{
core::{Endpoint, Multiaddr},
kad::{
self,
record::store::{MemoryStore, RecordStore},
GetClosestPeersError, GetRecordOk, Kademlia, KademliaBucketInserts, KademliaConfig,
KademliaEvent, QueryId, QueryResult, Quorum, Record, RecordKey,
Expand Down Expand Up @@ -222,6 +223,9 @@ impl DiscoveryConfig {

let store = MemoryStore::new(local_peer_id);
let mut kad = Kademlia::with_config(local_peer_id, store, config);
// Enable server mode so that the node can accept incoming queries even if it does not
// have an external address just yet.
kad.set_mode(Some(kad::Mode::Server));

for (peer_id, addr) in &permanent_addresses {
kad.add_address(peer_id, addr.clone());
Expand Down Expand Up @@ -990,7 +994,7 @@ mod tests {
upgrade,
},
identity::Keypair,
kad, noise,
noise,
swarm::{Executor, Swarm, SwarmBuilder, SwarmEvent},
yamux, Multiaddr,
};
Expand Down Expand Up @@ -1045,17 +1049,6 @@ mod tests {
)
.build();

// Set the Kademlia mode to server so that it can accept incoming requests.
//
// Note: the server mode is set automatically when the node learns its external
// address, but that does not happen in tests => hence we set it manually.
swarm
.behaviour_mut()
.kademlia
.as_mut()
.unwrap()
.set_mode(Some(kad::Mode::Server));

let listen_addr: Multiaddr =
format!("/memory/{}", rand::random::<u64>()).parse().unwrap();

Expand Down

0 comments on commit 7d4e8e2

Please sign in to comment.