merge master

This commit is contained in:
Evan Feenstra
2022-06-09 19:26:28 -07:00
2 changed files with 60 additions and 7 deletions

48
broker/src/init.rs Normal file
View File

@@ -0,0 +1,48 @@
use crate::ChannelRequest;
use sphinx_key_parser as parser;
use sphinx_key_parser::MsgDriver;
use tokio::sync::{mpsc, oneshot};
use vls_protocol::model::Secret;
use vls_protocol::{msgs, serde_bolt::WireString};
use vls_proxy::util::{read_allowlist, read_integration_test_seed};
pub async fn connect(tx: mpsc::Sender<ChannelRequest>) {
let init_msg_2 = crate::init::make_init_msg().expect("could make init msg");
let (reply_tx, reply_rx) = oneshot::channel();
// Send a request to the MQTT handler to send to signer
let request = ChannelRequest {
message: init_msg_2,
reply_tx,
};
let _ = tx.send(request).await;
let res = reply_rx.await.expect("couldnt receive");
let reply = parser::response_from_bytes(res.reply, 0).expect("could parse init receive");
println!("REPLY {:?}", reply);
}
pub fn make_init_msg() -> anyhow::Result<Vec<u8>> {
let allowlist = read_allowlist()
.into_iter()
.map(|s| WireString(s.as_bytes().to_vec()))
.collect::<Vec<_>>();
let seed = read_integration_test_seed()
.map(|s| Secret(s))
.or(Some(Secret([1; 32])));
// FIXME remove this
log::info!("allowlist {:?} seed {:?}", allowlist, seed);
let init = msgs::HsmdInit2 {
derivation_style: 0,
network_name: WireString("testnet".as_bytes().to_vec()),
dev_seed: seed,
dev_allowlist: allowlist,
};
let sequence = 0;
let mut md = MsgDriver::new_empty();
msgs::write_serial_request_header(&mut md, sequence, 0)?;
msgs::write(&mut md, init)?;
Ok(md.bytes())
// msgs::read_serial_response_header(&mut serial, sequence)?;
// let init_reply: msgs::HsmdInit2Reply = msgs::read_message(&mut serial)?;
// log::info!("init reply {:?}", init_reply);
// Ok(())
}

View File

@@ -1,3 +1,4 @@
mod init;
mod mqtt; mod mqtt;
mod run_test; mod run_test;
mod unix_fd; mod unix_fd;
@@ -58,13 +59,17 @@ fn main() -> anyhow::Result<()> {
run_test::run_test(); run_test::run_test();
} else { } else {
let (tx, rx) = mpsc::channel(1000); let (tx, rx) = mpsc::channel(1000);
let (status_tx, status_rx) = mpsc::channel(1000); let (status_tx, _status_rx) = mpsc::channel(1000);
let _runtime = start_broker(rx, status_tx, "sphinx-1"); let runtime = start_broker(rx, status_tx, "sphinx-1");
// listen to reqs from CLN runtime.block_on(async {
let conn = UnixConnection::new(parent_fd); init::connect(tx.clone()).await;
let client = UnixClient::new(conn); // listen to reqs from CLN
let mut signer_loop = SignerLoop::new(client, tx); let conn = UnixConnection::new(parent_fd);
signer_loop.start(); let client = UnixClient::new(conn);
// TODO pass status_rx into SignerLoop
let mut signer_loop = SignerLoop::new(client, tx);
signer_loop.start();
})
} }
Ok(()) Ok(())