mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-12 08:20:26 -04:00
Deterministic peer id from seed for bob
This commit is contained in:
parent
0e09c08af5
commit
d80cc393cf
3 changed files with 11 additions and 5 deletions
|
@ -5,7 +5,7 @@ use crate::{
|
||||||
network::{
|
network::{
|
||||||
peer_tracker::{self, PeerTracker},
|
peer_tracker::{self, PeerTracker},
|
||||||
transport::SwapTransport,
|
transport::SwapTransport,
|
||||||
TokioExecutor,
|
Seed, TokioExecutor,
|
||||||
},
|
},
|
||||||
SwapAmounts,
|
SwapAmounts,
|
||||||
};
|
};
|
||||||
|
@ -121,8 +121,8 @@ pub struct Behaviour {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Behaviour {
|
impl Behaviour {
|
||||||
pub fn identity(&self) -> Keypair {
|
pub fn identity(&self, seed: Seed) -> Keypair {
|
||||||
self.identity.clone()
|
seed.derive_libp2p_identity()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn peer_id(&self) -> PeerId {
|
pub fn peer_id(&self) -> PeerId {
|
||||||
|
|
|
@ -170,6 +170,7 @@ async fn main() -> Result<()> {
|
||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
alice_addr,
|
||||||
config,
|
config,
|
||||||
|
&seed,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
@ -247,6 +248,7 @@ async fn main() -> Result<()> {
|
||||||
alice_peer_id,
|
alice_peer_id,
|
||||||
alice_addr,
|
alice_addr,
|
||||||
config,
|
config,
|
||||||
|
&seed,
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
|
@ -325,9 +327,12 @@ async fn bob_swap(
|
||||||
alice_peer_id: PeerId,
|
alice_peer_id: PeerId,
|
||||||
alice_addr: Multiaddr,
|
alice_addr: Multiaddr,
|
||||||
config: Config,
|
config: Config,
|
||||||
|
seed: &Seed,
|
||||||
) -> Result<BobState> {
|
) -> Result<BobState> {
|
||||||
let bob_behaviour = bob::Behaviour::default();
|
let bob_behaviour = bob::Behaviour::default();
|
||||||
let bob_transport = build(bob_behaviour.identity())?;
|
|
||||||
|
let identity = bob_behaviour.identity(network::Seed::new(seed.bytes()));
|
||||||
|
let bob_transport = build(identity)?;
|
||||||
|
|
||||||
let (event_loop, handle) =
|
let (event_loop, handle) =
|
||||||
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)?;
|
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)?;
|
||||||
|
|
|
@ -188,8 +188,9 @@ pub fn init_bob_event_loop(
|
||||||
alice_peer_id: PeerId,
|
alice_peer_id: PeerId,
|
||||||
alice_addr: Multiaddr,
|
alice_addr: Multiaddr,
|
||||||
) -> (bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle) {
|
) -> (bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle) {
|
||||||
|
let seed = Seed::random().unwrap();
|
||||||
let bob_behaviour = bob::Behaviour::default();
|
let bob_behaviour = bob::Behaviour::default();
|
||||||
let bob_transport = build(bob_behaviour.identity()).unwrap();
|
let bob_transport = build(bob_behaviour.identity(network::Seed::new(seed.bytes()))).unwrap();
|
||||||
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)
|
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue