mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-12 00:10:49 -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::{
|
||||
peer_tracker::{self, PeerTracker},
|
||||
transport::SwapTransport,
|
||||
TokioExecutor,
|
||||
Seed, TokioExecutor,
|
||||
},
|
||||
SwapAmounts,
|
||||
};
|
||||
|
@ -121,8 +121,8 @@ pub struct Behaviour {
|
|||
}
|
||||
|
||||
impl Behaviour {
|
||||
pub fn identity(&self) -> Keypair {
|
||||
self.identity.clone()
|
||||
pub fn identity(&self, seed: Seed) -> Keypair {
|
||||
seed.derive_libp2p_identity()
|
||||
}
|
||||
|
||||
pub fn peer_id(&self) -> PeerId {
|
||||
|
|
|
@ -170,6 +170,7 @@ async fn main() -> Result<()> {
|
|||
alice_peer_id,
|
||||
alice_addr,
|
||||
config,
|
||||
&seed,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
@ -247,6 +248,7 @@ async fn main() -> Result<()> {
|
|||
alice_peer_id,
|
||||
alice_addr,
|
||||
config,
|
||||
&seed,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
|
@ -325,9 +327,12 @@ async fn bob_swap(
|
|||
alice_peer_id: PeerId,
|
||||
alice_addr: Multiaddr,
|
||||
config: Config,
|
||||
seed: &Seed,
|
||||
) -> Result<BobState> {
|
||||
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) =
|
||||
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_addr: Multiaddr,
|
||||
) -> (bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle) {
|
||||
let seed = Seed::random().unwrap();
|
||||
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)
|
||||
.unwrap()
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue