Browse Source

Merge #567

567: Improve naming of noise protocol parameters r=klochowicz a=klochowicz



Co-authored-by: Mariusz Klochowicz <mariusz@klochowicz.com>
new-http-api
bors[bot] 3 years ago
committed by GitHub
parent
commit
f4d56bcf67
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 19
      daemon/src/connection.rs
  2. 4
      daemon/src/lib.rs
  3. 7
      daemon/src/maker.rs
  4. 5
      daemon/src/seed.rs
  5. 6
      daemon/src/taker.rs
  6. 20
      daemon/tests/harness/mod.rs

19
daemon/src/connection.rs

@ -20,7 +20,7 @@ pub struct Actor {
status_sender: watch::Sender<ConnectionStatus>,
send_to_maker: Box<dyn MessageChannel<wire::TakerToMaker>>,
send_to_maker_ctx: xtra::Context<send_to_socket::Actor<wire::TakerToMaker>>,
noise_static_sk: x25519_dalek::StaticSecret,
identity_sk: x25519_dalek::StaticSecret,
maker_to_taker: Box<dyn MessageChannel<wire::MakerToTaker>>,
/// Max duration since the last heartbeat until we die.
timeout: Duration,
@ -28,7 +28,7 @@ pub struct Actor {
}
pub struct Connect {
pub maker_noise_static_pk: x25519_dalek::PublicKey,
pub maker_identity_pk: x25519_dalek::PublicKey,
pub maker_addr: SocketAddr,
}
@ -49,7 +49,7 @@ impl Actor {
pub fn new(
status_sender: watch::Sender<ConnectionStatus>,
maker_to_taker: Box<dyn MessageChannel<wire::MakerToTaker>>,
noise_static_sk: x25519_dalek::StaticSecret,
identity_sk: x25519_dalek::StaticSecret,
timeout: Duration,
) -> Self {
let (send_to_maker_addr, send_to_maker_ctx) = xtra::Context::new(None);
@ -58,7 +58,7 @@ impl Actor {
status_sender,
send_to_maker: Box::new(send_to_maker_addr),
send_to_maker_ctx,
noise_static_sk,
identity_sk,
maker_to_taker,
timeout,
connected_state: None,
@ -79,19 +79,16 @@ impl Actor {
&mut self,
Connect {
maker_addr,
maker_noise_static_pk,
maker_identity_pk,
}: Connect,
ctx: &mut xtra::Context<Self>,
) -> Result<()> {
let (read, write, noise) = {
let socket = tokio::net::TcpSocket::new_v4().expect("Be able to create a socket");
let mut connection = socket.connect(maker_addr).await?;
let noise = noise::initiator_handshake(
&mut connection,
&self.noise_static_sk,
&maker_noise_static_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)))
};

4
daemon/src/lib.rs

@ -186,7 +186,7 @@ where
db: SqlitePool,
wallet_addr: Address<W>,
oracle_pk: schnorrsig::PublicKey,
noise_static_sk: x25519_dalek::StaticSecret,
identity_sk: x25519_dalek::StaticSecret,
oracle_constructor: impl FnOnce(Vec<Cfd>, Box<dyn StrongMessageChannel<Attestation>>) -> O,
monitor_constructor: impl FnOnce(Box<dyn StrongMessageChannel<monitor::Event>>, Vec<Cfd>) -> F,
n_payouts: usize,
@ -228,7 +228,7 @@ where
tokio::spawn(connection_actor_ctx.run(connection::Actor::new(
maker_online_status_feed_sender,
Box::new(cfd_actor_addr.clone()),
noise_static_sk,
identity_sk,
HEARTBEAT_INTERVAL * 2,
)));

7
daemon/src/maker.rs

@ -192,14 +192,13 @@ async fn main() -> Result<()> {
let auth_password = seed.derive_auth_password::<auth::Password>();
let noise_static_sk = seed.derive_noise_static_secret();
let noise_static_pk = x25519_dalek::PublicKey::from(&noise_static_sk);
let (identity_pk, identity_sk) = seed.derive_identity();
tracing::info!(
"Authentication details: username='{}' password='{}', noise_public_key='{}'",
MAKER_USERNAME,
auth_password,
hex::encode(noise_static_pk.to_bytes())
hex::encode(identity_pk.to_bytes())
);
// TODO: Actually fetch it from Olivia
@ -262,7 +261,7 @@ async fn main() -> Result<()> {
monitor::Actor::new(electrum, channel, cfds)
}
},
|channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1, noise_static_sk),
|channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1, identity_sk),
time::Duration::hours(opts.settlement_time_interval_hours as i64),
N_PAYOUTS,
)

5
daemon/src/seed.rs

@ -66,14 +66,15 @@ impl Seed {
P::from(password)
}
pub fn derive_noise_static_secret(&self) -> x25519_dalek::StaticSecret {
pub fn derive_identity(&self) -> (x25519_dalek::PublicKey, x25519_dalek::StaticSecret) {
let mut secret = [0u8; 32];
Hkdf::<Sha256>::new(None, &self.0)
.expand(b"NOISE_STATIC_SECRET", &mut secret)
.expect("okm array is of correct length");
x25519_dalek::StaticSecret::from(secret)
let identity_sk = x25519_dalek::StaticSecret::from(secret);
(x25519_dalek::PublicKey::from(&identity_sk), identity_sk)
}
}

6
daemon/src/taker.rs

@ -166,7 +166,7 @@ async fn main() -> Result<()> {
let bitcoin_network = opts.network.bitcoin_network();
let ext_priv_key = seed.derive_extended_priv_key(bitcoin_network)?;
let noise_static_sk = seed.derive_noise_static_secret();
let (_, identity_sk) = seed.derive_identity();
let wallet = wallet::Actor::new(
opts.network.electrum(),
@ -241,7 +241,7 @@ async fn main() -> Result<()> {
db.clone(),
wallet.clone(),
oracle,
noise_static_sk,
identity_sk,
|cfds, channel| oracle::Actor::new(cfds, channel, ANNOUNCEMENT_LOOKAHEAD),
{
|channel, cfds| {
@ -255,7 +255,7 @@ async fn main() -> Result<()> {
while connection_actor_addr
.send(connection::Connect {
maker_noise_static_pk: opts.maker_id,
maker_identity_pk: opts.maker_id,
maker_addr: opts.maker,
})
.await?

20
daemon/tests/harness/mod.rs

@ -33,7 +33,7 @@ pub async fn start_both() -> (Maker, Taker) {
.unwrap();
let maker = Maker::start(oracle_pk).await;
let taker = Taker::start(oracle_pk, maker.listen_addr, maker.noise_static_pk).await;
let taker = Taker::start(oracle_pk, maker.listen_addr, maker.identity_pk).await;
(maker, taker)
}
@ -51,7 +51,7 @@ pub struct Maker {
pub inc_conn_actor_addr: xtra::Address<maker_inc_connections::Actor>,
pub listen_addr: SocketAddr,
pub mocks: mocks::Mocks,
pub noise_static_pk: x25519_dalek::PublicKey,
pub identity_pk: x25519_dalek::PublicKey,
}
impl Maker {
@ -67,9 +67,7 @@ impl Maker {
let settlement_time_interval_hours = time::Duration::hours(24);
let seed = Seed::default();
let noise_static_sk = seed.derive_noise_static_secret();
let noise_static_pk = x25519_dalek::PublicKey::from(&noise_static_sk);
let (identity_pk, identity_sk) = seed.derive_identity();
let maker = daemon::MakerActorSystem::new(
db,
@ -77,9 +75,7 @@ impl Maker {
oracle_pk,
|_, _| oracle,
|_, _| async { Ok(monitor) },
|channel0, channel1| {
maker_inc_connections::Actor::new(channel0, channel1, noise_static_sk)
},
|channel0, channel1| maker_inc_connections::Actor::new(channel0, channel1, identity_sk),
settlement_time_interval_hours,
N_PAYOUTS_FOR_TEST,
)
@ -110,7 +106,7 @@ impl Maker {
cfd_feed: maker.cfd_feed_receiver,
inc_conn_actor_addr: maker.inc_conn_addr,
listen_addr: address,
noise_static_pk,
identity_pk,
mocks,
}
}
@ -158,7 +154,7 @@ impl Taker {
) -> Self {
let seed = Seed::default();
let noise_static_sk = seed.derive_noise_static_secret();
let (_, identity_sk) = seed.derive_identity();
let db = in_memory_db().await;
@ -172,7 +168,7 @@ impl Taker {
db,
wallet_addr,
oracle_pk,
noise_static_sk,
identity_sk,
|_, _| oracle,
|_, _| async { Ok(monitor) },
N_PAYOUTS_FOR_TEST,
@ -183,7 +179,7 @@ impl Taker {
taker
.connection_actor_addr
.send(Connect {
maker_noise_static_pk: maker_noise_pub_key,
maker_identity_pk: maker_noise_pub_key,
maker_addr: maker_address,
})
.await

Loading…
Cancel
Save