fn process_ban_peer<'a, I: Iterator<Item = &'a str>>(&mut self, mut args: I, must_ban: bool) {
        let node_key = match args.next().and_then(parse_emoji_id_or_public_key_or_node_id) {
            Some(v) => v,
            None => {
                println!("Please enter a valid destination public key or emoji id");
                println!(
                    "ban-peer/unban-peer [hex public key or emoji id] (length of time to ban the peer for in seconds)"
                );
                return;
            },
        };

        match &node_key {
            Either::Left(public_key) => {
                if let Some(wni) = self.wallet_node_identity.clone() {
                    if wni.public_key() == public_key {
                        println!("Cannot ban our own wallet");
                        return;
                    }
                }

                if self.base_node_identity.public_key() == public_key {
                    println!("Cannot ban our own node");
                    return;
                }
            },
            Either::Right(node_id) => {
                if let Some(wni) = self.wallet_node_identity.clone() {
                    if wni.node_id() == node_id {
                        println!("Cannot ban our own wallet");
                        return;
                    }
                }
                if self.base_node_identity.node_id() == node_id {
                    println!("Cannot ban our own node");
                    return;
                }
            },
        }

        let mut connectivity = self.connectivity.clone();
        let wallet_connectivity = self.wallet_connectivity.clone();
        let peer_manager = self.peer_manager.clone();
        let wallet_peer_manager = self.wallet_peer_manager.clone();

        let duration = args
            .next()
            .and_then(|s| s.parse::<u64>().ok())
            .map(Duration::from_secs)
            .unwrap_or_else(|| Duration::from_secs(std::u64::MAX));

        self.executor.spawn(async move {
            let node_id = match node_key {
                Either::Left(public_key) => match peer_manager.find_by_public_key(&public_key).await {
                    Ok(peer) => peer.node_id,
                    Err(err) if err.is_peer_not_found() => {
                        println!("Peer not found in base node");
                        return;
                    },
                    Err(err) => {
                        println!("Failed to ban peer: {:?}", err);
                        error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                        return;
                    },
                },
                Either::Right(node_id) => node_id,
            };

            if must_ban {
                match connectivity
                    .ban_peer(node_id.clone(), duration, "UI manual ban".to_string())
                    .await
                {
                    Ok(_) => println!("Peer was banned in base node."),
                    Err(err) => {
                        println!("Failed to ban peer: {:?}", err);
                        error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                    },
                }

                if let Some(mut wallet_connectivity) = wallet_connectivity {
                    match wallet_connectivity
                        .ban_peer(node_id, duration, "UI manual ban".to_string())
                        .await
                    {
                        Ok(_) => println!("Peer was banned in wallet."),
                        Err(err) => {
                            println!("Failed to ban peer: {:?}", err);
                            error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                        },
                    }
                }
            } else {
                match peer_manager.unban_peer(&node_id).await {
                    Ok(_) => {
                        println!("Peer ban was removed from base node.");
                    },
                    Err(err) if err.is_peer_not_found() => {
                        println!("Peer not found in base node");
                    },
                    Err(err) => {
                        println!("Failed to ban peer: {:?}", err);
                        error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                    },
                }

                if let Some(wallet_peer_manager) = wallet_peer_manager {
                    match wallet_peer_manager.unban_peer(&node_id).await {
                        Ok(_) => {
                            println!("Peer ban was removed from wallet.");
                        },
                        Err(err) if err.is_peer_not_found() => {
                            println!("Peer not found in wallet");
                        },
                        Err(err) => {
                            println!("Failed to ban peer: {:?}", err);
                            error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                        },
                    }
                }
            }
        });
    }
/// Function to process the ban-peer command
Function to process the ban-peer command
Function to process the ban - peer command
fn process_ban_peer<'a, I: Iterator<Item = &'a str>>(&mut self, mut args: I, must_ban: bool) {
        let node_key = match args.next().and_then(parse_emoji_id_or_public_key_or_node_id) {
            Some(v) => v,
            None => {
                println!("Please enter a valid destination public key or emoji id");
                println!(
                    "ban-peer/unban-peer [hex public key or emoji id] (length of time to ban the peer for in seconds)"
                );
                return;
            },
        };
        match &node_key {
            Either::Left(public_key) => {
                if let Some(wni) = self.wallet_node_identity.clone() {
                    if wni.public_key() == public_key {
                        println!("Cannot ban our own wallet");
                        return;
                    }
                }
                if self.base_node_identity.public_key() == public_key {
                    println!("Cannot ban our own node");
                    return;
                }
            },
            Either::Right(node_id) => {
                if let Some(wni) = self.wallet_node_identity.clone() {
                    if wni.node_id() == node_id {
                        println!("Cannot ban our own wallet");
                        return;
                    }
                }
                if self.base_node_identity.node_id() == node_id {
                    println!("Cannot ban our own node");
                    return;
                }
            },
        }
        let mut connectivity = self.connectivity.clone();
        let wallet_connectivity = self.wallet_connectivity.clone();
        let peer_manager = self.peer_manager.clone();
        let wallet_peer_manager = self.wallet_peer_manager.clone();
        let duration = args
            .next()
            .and_then(|s| s.parse::<u64>().ok())
            .map(Duration::from_secs)
            .unwrap_or_else(|| Duration::from_secs(std::u64::MAX));
        self.executor.spawn(async move {
            let node_id = match node_key {
                Either::Left(public_key) => match peer_manager.find_by_public_key(&public_key).await {
                    Ok(peer) => peer.node_id,
                    Err(err) if err.is_peer_not_found() => {
                        println!("Peer not found in base node");
                        return;
                    },
                    Err(err) => {
                        println!("Failed to ban peer: {:?}", err);
                        error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                        return;
                    },
                },
                Either::Right(node_id) => node_id,
            };
            if must_ban {
                match connectivity
                    .ban_peer(node_id.clone(), duration, "UI manual ban".to_string())
                    .await
                {
                    Ok(_) => println!("Peer was banned in base node."),
                    Err(err) => {
                        println!("Failed to ban peer: {:?}", err);
                        error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                    },
                }
                if let Some(mut wallet_connectivity) = wallet_connectivity {
                    match wallet_connectivity
                        .ban_peer(node_id, duration, "UI manual ban".to_string())
                        .await
                    {
                        Ok(_) => println!("Peer was banned in wallet."),
                        Err(err) => {
                            println!("Failed to ban peer: {:?}", err);
                            error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                        },
                    }
                }
            } else {
                match peer_manager.unban_peer(&node_id).await {
                    Ok(_) => {
                        println!("Peer ban was removed from base node.");
                    },
                    Err(err) if err.is_peer_not_found() => {
                        println!("Peer not found in base node");
                    },
                    Err(err) => {
                        println!("Failed to ban peer: {:?}", err);
                        error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                    },
                }
                if let Some(wallet_peer_manager) = wallet_peer_manager {
                    match wallet_peer_manager.unban_peer(&node_id).await {
                        Ok(_) => {
                            println!("Peer ban was removed from wallet.");
                        },
                        Err(err) if err.is_peer_not_found() => {
                            println!("Peer not found in wallet");
                        },
                        Err(err) => {
                            println!("Failed to ban peer: {:?}", err);
                            error!(target: LOG_TARGET, "Could not ban peer: {:?}", err);
                        },
                    }
                }
            }
        });
    }
fn process_ban_peer < ' a , I : Iterator < Item = & ' a str > > ( & mut self , mut args : I , must_ban : bool ) { let node_key = match args . next ( ) . and_then ( parse_emoji_id_or_public_key_or_node_id ) { Some ( v ) => v , None => { println ! ( " " ) ; println ! ( " " ) ; return ; } , } ; match & node_key { Either :: Left ( public_key ) => { if let Some ( wni ) = self . wallet_node_identity . clone ( ) { if wni . public_key ( ) == public_key { println ! ( " " ) ; return ; } } if self . base_node_identity . public_key ( ) == public_key { println ! ( " " ) ; return ; } } , Either :: Right ( node_id ) => { if let Some ( wni ) = self . wallet_node_identity . clone ( ) { if wni . node_id ( ) == node_id { println ! ( " " ) ; return ; } } if self . base_node_identity . node_id ( ) == node_id { println ! ( " " ) ; return ; } } , } let mut connectivity = self . connectivity . clone ( ) ; let wallet_connectivity = self . wallet_connectivity . clone ( ) ; let peer_manager = self . peer_manager . clone ( ) ; let wallet_peer_manager = self . wallet_peer_manager . clone ( ) ; let duration = args . next ( ) . and_then ( | s | s . parse :: < u64 > ( ) . ok ( ) ) . map ( Duration :: from_secs ) . unwrap_or_else ( | | Duration :: from_secs ( std :: u64 :: MAX ) ) ; self . executor . spawn ( async move { let node_id = match node_key { Either :: Left ( public_key ) => match peer_manager . find_by_public_key ( & public_key ) . await { Ok ( peer ) => peer . node_id , Err ( err ) if err . is_peer_not_found ( ) => { println ! ( " " ) ; return ; } , Err ( err ) => { println ! ( " " err ) ; error ! ( target LOG_TARGET " " err ) ; return ; } , } , Either :: Right ( node_id ) => node_id , } ; if must_ban { match connectivity . ban_peer ( node_id . clone ( ) , duration , " " . to_string ( ) ) . await { Ok ( _ ) => println ! ( " " ) , Err ( err ) => { println ! ( " " err ) ; error ! ( target LOG_TARGET " " err ) ; } , } if let Some ( mut wallet_connectivity ) = wallet_connectivity { match wallet_connectivity . ban_peer ( node_id , duration , " " . to_string ( ) ) . await { Ok ( _ ) => println ! ( " " ) , Err ( err ) => { println ! ( " " err ) ; error ! ( target LOG_TARGET " " err ) ; } , } } } else { match peer_manager . unban_peer ( & node_id ) . await { Ok ( _ ) => { println ! ( " " ) ; } , Err ( err ) if err . is_peer_not_found ( ) => { println ! ( " " ) ; } , Err ( err ) => { println ! ( " " err ) ; error ! ( target LOG_TARGET " " err ) ; } , } if let Some ( wallet_peer_manager ) = wallet_peer_manager { match wallet_peer_manager . unban_peer ( & node_id ) . await { Ok ( _ ) => { println ! ( " " ) ; } , Err ( err ) if err . is_peer_not_found ( ) => { println ! ( " " ) ; } , Err ( err ) => { println ! ( " " err ) ; error ! ( target LOG_TARGET " " err ) ; } , } } } } ) ; }
Function to process the ban-peer command
Function to process the ban - peer command
&mut self
args
I
must_ban
bool
&mut self
args
I
must_ban
bool