Remove passing alice peer id

The usage of the peer id is incorrect as we do not even check it when
dialing. For now, we can ignore it.
We can then re-introduce it and use it properly at a later stage.
This commit is contained in:
Franck Royer 2020-12-10 14:59:09 +11:00
parent bbe454d269
commit 11cea9ba69
No known key found for this signature in database
GPG key ID: A82ED75A8DFC50A4
4 changed files with 27 additions and 44 deletions

View file

@ -130,7 +130,7 @@ async fn main() -> Result<()> {
}
Options::BuyXmr {
alice_addr,
alice_peer_id,
alice_peer_id: _,
bitcoind_url,
bitcoin_wallet_name,
monero_wallet_rpc_url,
@ -182,7 +182,6 @@ async fn main() -> Result<()> {
let bob_state = BobState::Started {
state0,
amounts,
peer_id: alice_peer_id,
addr: alice_addr,
};

View file

@ -1,6 +1,6 @@
use crate::{bob::event_loop::EventLoopHandle, SwapAmounts};
use anyhow::Result;
use libp2p::core::Multiaddr;
use libp2p::{core::Multiaddr, PeerId};
use rand::{CryptoRng, RngCore};
use std::sync::Arc;
use xmr_btc::bob::State2;
@ -12,32 +12,34 @@ pub async fn negotiate<R>(
addr: Multiaddr,
mut rng: R,
bitcoin_wallet: Arc<crate::bitcoin::Wallet>,
) -> Result<State2>
) -> Result<(State2, PeerId)>
where
R: RngCore + CryptoRng + Send,
{
tracing::trace!("Starting negotiate");
swarm.dial_alice(addr).await?;
let alice = swarm.recv_conn_established().await?;
swarm.request_amounts(alice.clone(), amounts.btc).await?;
let alice_peer_id = swarm.recv_conn_established().await?;
swarm
.send_message0(alice.clone(), state0.next_message(&mut rng))
.request_amounts(alice_peer_id.clone(), amounts.btc)
.await?;
swarm
.send_message0(alice_peer_id.clone(), state0.next_message(&mut rng))
.await?;
let msg0 = swarm.recv_message0().await?;
let state1 = state0.receive(bitcoin_wallet.as_ref(), msg0).await?;
swarm
.send_message1(alice.clone(), state1.next_message())
.send_message1(alice_peer_id.clone(), state1.next_message())
.await?;
let msg1 = swarm.recv_message1().await?;
let state2 = state1.receive(msg1)?;
swarm
.send_message2(alice.clone(), state2.next_message())
.send_message2(alice_peer_id.clone(), state2.next_message())
.await?;
Ok(state2)
Ok((state2, alice_peer_id))
}

View file

@ -21,7 +21,6 @@ pub enum BobState {
Started {
state0: bob::State0,
amounts: SwapAmounts,
peer_id: PeerId,
addr: Multiaddr,
},
Negotiated(bob::State2, PeerId),
@ -121,10 +120,9 @@ where
BobState::Started {
state0,
amounts,
peer_id,
addr,
} => {
let state2 = negotiate(
let (state2, alice_peer_id) = negotiate(
state0,
amounts,
&mut event_loop_handle,
@ -134,7 +132,7 @@ where
)
.await?;
run_until(
BobState::Negotiated(state2, peer_id),
BobState::Negotiated(state2, alice_peer_id),
is_target_state,
event_loop_handle,
db,