Skip to content

Commit

Permalink
Implement and use From trait for kad mode setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
aterentic-ethernal committed Dec 20, 2023
1 parent 25e7c86 commit cb5fbc0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
16 changes: 6 additions & 10 deletions src/network/p2p.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,17 +201,13 @@ pub fn init(
.with_swarm_config(|c| c.with_idle_connection_timeout(cfg.connection_idle_timeout))
.build();

if is_fat_client {
swarm
.behaviour_mut()
.kademlia
.set_mode(Some(KademliaMode::Server.to_kad_mode()));
let kad_mode = if is_fat_client {
KademliaMode::Server.into()
} else {
swarm
.behaviour_mut()
.kademlia
.set_mode(Some(cfg.kademlia_mode.to_kad_mode()));
}
cfg.kademlia_mode.into()
};

swarm.behaviour_mut().kademlia.set_mode(Some(kad_mode));

// create sender channel for Event Loop Commands
let (command_sender, command_receiver) = mpsc::channel(10000);
Expand Down
6 changes: 3 additions & 3 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ pub enum KademliaMode {
Server,
}

impl KademliaMode {
pub fn to_kad_mode(self) -> KadMode {
match self {
impl From<KademliaMode> for KadMode {
fn from(value: KademliaMode) -> Self {
match value {
KademliaMode::Client => KadMode::Client,
KademliaMode::Server => KadMode::Server,
}
Expand Down

0 comments on commit cb5fbc0

Please sign in to comment.