Browse Source

Use identity more consistently

feature/reconnect-button
Daniel Karzel 3 years ago
parent
commit
302c1be86b
No known key found for this signature in database GPG Key ID: 30C3FC2E438ADB6E
  1. 19
      daemon/src/connection.rs
  2. 4
      daemon/src/model.rs
  3. 4
      daemon/src/taker.rs
  4. 4
      daemon/tests/happy_path.rs
  5. 15
      daemon/tests/harness/mod.rs

19
daemon/src/connection.rs

@ -1,6 +1,6 @@
use crate::address_map::{AddressMap, Stopping};
use crate::model::cfd::OrderId;
use crate::model::{Price, Timestamp, Usd};
use crate::model::{Identity, Price, Timestamp, Usd};
use crate::tokio_ext::FutureExt;
use crate::wire::EncryptedJsonCodec;
use crate::{collab_settlement_taker, log_error, noise, send_to_socket, setup_taker, wire, Tasks};
@ -41,7 +41,7 @@ pub struct Actor {
}
pub struct Connect {
pub maker_identity_pk: x25519_dalek::PublicKey,
pub maker_identity: Identity,
pub maker_addr: SocketAddr,
}
@ -168,7 +168,7 @@ impl Actor {
&mut self,
Connect {
maker_addr,
maker_identity_pk,
maker_identity,
}: Connect,
ctx: &mut xtra::Context<Self>,
) -> Result<()> {
@ -186,9 +186,12 @@ impl Actor {
)
})?
.with_context(|| format!("Failed to connect to {}", maker_addr))?;
let noise =
noise::initiator_handshake(&mut connection, &self.identity_sk, &maker_identity_pk)
.await?;
let noise = noise::initiator_handshake(
&mut connection,
&self.identity_sk,
&maker_identity.pk(),
)
.await?;
let (read, write) = connection.into_split();
(read, write, Arc::new(Mutex::new(noise)))
@ -318,7 +321,7 @@ impl xtra::Actor for Actor {}
pub async fn connect(
mut maker_online_status_feed_receiver: watch::Receiver<ConnectionStatus>,
connection_actor_addr: xtra::Address<Actor>,
maker_identity_pk: x25519_dalek::PublicKey,
maker_identity: Identity,
maker_addresses: Vec<SocketAddr>,
) {
loop {
@ -327,7 +330,7 @@ pub async fn connect(
'connect: loop {
for address in &maker_addresses {
let connect_msg = Connect {
maker_identity_pk,
maker_identity,
maker_addr: *address,
};

4
daemon/src/model.rs

@ -395,6 +395,10 @@ impl Identity {
pub fn new(key: x25519_dalek::PublicKey) -> Self {
Self(key)
}
pub fn pk(&self) -> x25519_dalek::PublicKey {
self.0
}
}
impl Serialize for Identity {

4
daemon/src/taker.rs

@ -6,7 +6,7 @@ use clap::{Parser, Subcommand};
use daemon::connection::connect;
use daemon::db::load_all_cfds;
use daemon::model::cfd::Role;
use daemon::model::WalletInfo;
use daemon::model::{Identity, WalletInfo};
use daemon::seed::Seed;
use daemon::tokio_ext::FutureExt;
use daemon::{
@ -274,7 +274,7 @@ async fn main() -> Result<()> {
tasks.add(connect(
maker_online_status_feed_receiver.clone(),
connection_actor_addr,
opts.maker_id,
Identity::new(opts.maker_id),
possible_addresses,
));

4
daemon/tests/happy_path.rs

@ -177,7 +177,7 @@ async fn taker_notices_lack_of_maker() {
let taker_config = TakerConfig::default().with_heartbeat_timeout(short_interval * 2);
let mut taker = Taker::start(&taker_config, maker.listen_addr, maker.identity_pk).await;
let mut taker = Taker::start(&taker_config, maker.listen_addr, maker.identity).await;
assert_eq!(
ConnectionStatus::Online,
@ -237,7 +237,7 @@ async fn start_from_open_cfd_state() -> (Maker, Taker, OrderId) {
let mut taker = Taker::start(
&TakerConfig::default().with_heartbeat_timeout(heartbeat_interval * 2),
maker.listen_addr,
maker.identity_pk,
maker.identity,
)
.await;

15
daemon/tests/harness/mod.rs

@ -44,12 +44,7 @@ fn oracle_pk() -> schnorrsig::PublicKey {
pub async fn start_both() -> (Maker, Taker) {
let maker_listener = tokio::net::TcpListener::bind("127.0.0.1:0").await.unwrap();
let maker = Maker::start(&MakerConfig::default(), maker_listener).await;
let taker = Taker::start(
&TakerConfig::default(),
maker.listen_addr,
maker.identity_pk,
)
.await;
let taker = Taker::start(&TakerConfig::default(), maker.listen_addr, maker.identity).await;
(maker, taker)
}
@ -115,7 +110,7 @@ pub struct Maker {
pub mocks: mocks::Mocks,
pub feeds: Feeds,
pub listen_addr: SocketAddr,
pub identity_pk: x25519_dalek::PublicKey,
pub identity: model::Identity,
_tasks: Tasks,
}
@ -195,7 +190,7 @@ impl Maker {
Self {
system: maker,
feeds,
identity_pk,
identity: model::Identity::new(identity_pk),
listen_addr: address,
mocks,
_tasks: tasks,
@ -266,7 +261,7 @@ impl Taker {
pub async fn start(
config: &TakerConfig,
maker_address: SocketAddr,
maker_noise_pub_key: x25519_dalek::PublicKey,
maker_identity: model::Identity,
) -> Self {
let (identity_pk, identity_sk) = config.seed.derive_identity();
@ -306,7 +301,7 @@ impl Taker {
tasks.add(connect(
taker.maker_online_status_feed_receiver.clone(),
taker.connection_actor_addr.clone(),
maker_noise_pub_key,
maker_identity,
vec![maker_address],
));

Loading…
Cancel
Save