mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-01-11 23:49:41 -05:00
Deterministic peer id from seed for bob
This commit is contained in:
parent
0a21040e08
commit
f18d01dfaf
@ -167,6 +167,7 @@ async fn main() -> Result<()> {
|
||||
db,
|
||||
alice_peer_id,
|
||||
alice_addr,
|
||||
&seed,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@ -243,6 +244,7 @@ async fn main() -> Result<()> {
|
||||
db,
|
||||
alice_peer_id,
|
||||
alice_addr,
|
||||
&seed,
|
||||
)
|
||||
.await?;
|
||||
}
|
||||
@ -319,8 +321,9 @@ async fn bob_swap(
|
||||
db: Database,
|
||||
alice_peer_id: PeerId,
|
||||
alice_addr: Multiaddr,
|
||||
seed: &Seed,
|
||||
) -> Result<BobState> {
|
||||
let bob_behaviour = bob::Behaviour::default();
|
||||
let bob_behaviour = bob::Behaviour::new(network::Seed::new(seed.bytes()));
|
||||
let bob_transport = build(bob_behaviour.identity())?;
|
||||
|
||||
let (event_loop, handle) =
|
||||
|
@ -12,7 +12,7 @@ use crate::{
|
||||
network::{
|
||||
peer_tracker::{self, PeerTracker},
|
||||
transport::SwapTransport,
|
||||
TokioExecutor,
|
||||
Seed, TokioExecutor,
|
||||
},
|
||||
protocol::{alice, bob},
|
||||
SwapAmounts,
|
||||
@ -124,6 +124,20 @@ pub struct Behaviour {
|
||||
}
|
||||
|
||||
impl Behaviour {
|
||||
pub fn new(seed: Seed) -> Self {
|
||||
let identity = seed.derive_libp2p_identity();
|
||||
|
||||
Self {
|
||||
pt: PeerTracker::default(),
|
||||
amounts: Amounts::default(),
|
||||
message0: message0::Behaviour::default(),
|
||||
message1: message1::Behaviour::default(),
|
||||
message2: message2::Behaviour::default(),
|
||||
message3: message3::Behaviour::default(),
|
||||
identity,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn identity(&self) -> Keypair {
|
||||
self.identity.clone()
|
||||
}
|
||||
|
@ -192,7 +192,8 @@ pub fn init_bob_event_loop(
|
||||
alice_peer_id: PeerId,
|
||||
alice_addr: Multiaddr,
|
||||
) -> (bob::event_loop::EventLoop, bob::event_loop::EventLoopHandle) {
|
||||
let bob_behaviour = bob::Behaviour::default();
|
||||
let seed = Seed::random().unwrap();
|
||||
let bob_behaviour = bob::Behaviour::new(network::Seed::new(seed.bytes()));
|
||||
let bob_transport = build(bob_behaviour.identity()).unwrap();
|
||||
bob::event_loop::EventLoop::new(bob_transport, bob_behaviour, alice_peer_id, alice_addr)
|
||||
.unwrap()
|
||||
|
Loading…
Reference in New Issue
Block a user