Skip to content

Commit

Permalink
fix: add-peer also dials the peer (#5727)
Browse files Browse the repository at this point in the history
Description
---
add-peer also dials the peer

Motivation and Context
---
Saves you having to do a separate dial peer command after adding

How Has This Been Tested?
---
Manually 

What process can a PR reviewer use to test or verify this change?
---

<!-- Checklist -->
<!-- 1. Is the title of your PR in the form that would make nice release
notes? The title, excluding the conventional commit
tag, will be included exactly as is in the CHANGELOG, so please think
about it carefully. -->


Breaking Changes
---

- [x] None
- [ ] Requires data directory on base node to be deleted
- [ ] Requires hard fork
- [ ] Other - Please specify

<!-- Does this include a breaking change? If so, include this line as a
footer -->
<!-- BREAKING CHANGE: Description what the user should do, e.g. delete a
database, resync the chain -->
  • Loading branch information
sdbondi authored Sep 3, 2023
1 parent c0f87ec commit cc8573a
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions applications/minotari_node/src/commands/command/add_peer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

use anyhow::{anyhow, Error};
use anyhow::Error;
use async_trait::async_trait;
use clap::Parser;
use minotari_app_utilities::utilities::UniPublicKey;
Expand All @@ -45,22 +45,24 @@ pub struct ArgsAddPeer {
impl HandleCommand<ArgsAddPeer> for CommandContext {
async fn handle_command(&mut self, args: ArgsAddPeer) -> Result<(), Error> {
let public_key = args.public_key.into();
let peer_manager = self.comms.peer_manager();
if peer_manager.exists(&public_key).await {
return Err(anyhow!("Peer with public key '{}' already exists", public_key));
if *self.comms.node_identity().public_key() == public_key {
return Err(Error::msg("Cannot add self as peer"));
}
let peer_manager = self.comms.peer_manager();
let node_id = NodeId::from_public_key(&public_key);
let peer = Peer::new(
public_key,
node_id.clone(),
MultiaddressesWithStats::from_addresses_with_source(vec![args.address], &PeerAddressSource::Config),
PeerFlags::empty(),
PeerFeatures::empty(),
PeerFeatures::COMMUNICATION_NODE,
vec![],
String::new(),
);
// If the peer exists, this will merge the given address
peer_manager.add_peer(peer).await?;
println!("Peer with node id '{}'was added to the base node.", node_id);
println!("Peer with node id '{}' was added to the base node.", node_id);
self.dial_peer(node_id).await?;
Ok(())
}
}

0 comments on commit cc8573a

Please sign in to comment.