broker to new rumqttd (not working)

This commit is contained in:
Evan Feenstra
2023-02-20 11:51:32 -08:00
parent b91ea599fd
commit 80215821ce
7 changed files with 80 additions and 63 deletions

89
Cargo.lock generated
View File

@@ -55,14 +55,9 @@ dependencies = [
[[package]] [[package]]
name = "ahash" name = "ahash"
version = "0.7.6" version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fcb51a0695d8f838b1ee009b3fbf66bda078cd64590202a864a8f3e8c4315c47" checksum = "e8fd72866655d1904d6b0997d0b07ba561047d070fbe29de039031c641b61217"
dependencies = [
"getrandom",
"once_cell",
"version_check",
]
[[package]] [[package]]
name = "aho-corasick" name = "aho-corasick"
@@ -298,7 +293,7 @@ dependencies = [
[[package]] [[package]]
name = "bolt-derive" name = "bolt-derive"
version = "0.1.0" version = "0.1.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#7afb0cdedb38750cc2086ce0e05dc41d93158e70" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#9112828c14ecff3bc86bd5e23a1016210de16e85"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -939,11 +934,12 @@ dependencies = [
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.11.2" version = "0.8.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ab5ef0d4909ef3724cc8cce6ccc8572c5c817592e9285f5464f8e86f8bd3726e" checksum = "e91b62f79061a0bc2e046024cb7ba44b08419ed238ecbd9adbd787434b9e8c25"
dependencies = [ dependencies = [
"ahash", "ahash",
"autocfg",
] ]
[[package]] [[package]]
@@ -1207,16 +1203,18 @@ checksum = "fc7fcc620a3bff7cdd7a365be3376c97191aeaccc2a603e600951e452615bf89"
[[package]] [[package]]
name = "lightning" name = "lightning"
version = "0.0.110" version = "0.0.113"
source = "git+https://github.com/lightningdevkit/rust-lightning.git?rev=ea5b62fff69847941434fb51562e302eb4e7ff4b#ea5b62fff69847941434fb51562e302eb4e7ff4b" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "087add70f81d2fdc6d4409bc0cef69e11ad366ef1d0068550159bd22b3ac8664"
dependencies = [ dependencies = [
"bitcoin", "bitcoin",
] ]
[[package]] [[package]]
name = "lightning-invoice" name = "lightning-invoice"
version = "0.18.0" version = "0.21.0"
source = "git+https://github.com/lightningdevkit/rust-lightning.git?rev=ea5b62fff69847941434fb51562e302eb4e7ff4b#ea5b62fff69847941434fb51562e302eb4e7ff4b" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e9680857590c3529cf8c7d32b04501f215f2bf1e029fdfa22f4112f66c1741e4"
dependencies = [ dependencies = [
"bech32", "bech32",
"bitcoin_hashes 0.11.0", "bitcoin_hashes 0.11.0",
@@ -1225,21 +1223,6 @@ dependencies = [
"secp256k1", "secp256k1",
] ]
[[package]]
name = "lightning-signer-core"
version = "0.1.0-5"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#7afb0cdedb38750cc2086ce0e05dc41d93158e70"
dependencies = [
"anyhow",
"bitcoin",
"hashbrown 0.11.2",
"itertools",
"lightning",
"lightning-invoice",
"log",
"scopeguard",
]
[[package]] [[package]]
name = "link-cplusplus" name = "link-cplusplus"
version = "1.0.7" version = "1.0.7"
@@ -2162,10 +2145,11 @@ dependencies = [
[[package]] [[package]]
name = "serde_bolt" name = "serde_bolt"
version = "0.2.0" version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "704720009634ab092146c0b01eb578ae8b9d88eef028398752965fd766eb38bd" checksum = "fd5fb14792b8d139f641e6d0e1a19eb0e3c47ec8629a2dc4e75fcbd7d77f46a8"
dependencies = [ dependencies = [
"hex",
"serde", "serde",
"serde_derive", "serde_derive",
] ]
@@ -2297,8 +2281,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-auther" name = "sphinx-auther"
version = "0.1.12" version = "0.1.12"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/stakwork/sphinx-rs.git#fb621dce1ef8bf8ca8bc7dbfbafdbd6a4fb8d293"
checksum = "33bd24149ede6f4ec091326eacf550cfa3fc00492d4e627a045c1bd690255362"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64", "base64",
@@ -2310,7 +2293,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-crypter" name = "sphinx-crypter"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git#0f9fcc1416ec0c977d8b307c89983ed7baa3ffa8" source = "git+https://github.com/stakwork/sphinx-rs.git#fb621dce1ef8bf8ca8bc7dbfbafdbd6a4fb8d293"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"chacha20poly1305", "chacha20poly1305",
@@ -2321,10 +2304,10 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-glyph" name = "sphinx-glyph"
version = "0.1.2" version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "git+https://github.com/stakwork/sphinx-rs.git#fb621dce1ef8bf8ca8bc7dbfbafdbd6a4fb8d293"
checksum = "62fadd6d488d0e5d824acfc3e8a74599429836c9422503c2dfc84418a19bae24"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hex",
"rmp-serde", "rmp-serde",
"serde", "serde",
"serde_json", "serde_json",
@@ -2360,7 +2343,7 @@ dependencies = [
[[package]] [[package]]
name = "sphinx-signer" name = "sphinx-signer"
version = "0.1.0" version = "0.1.0"
source = "git+https://github.com/stakwork/sphinx-rs.git#0f9fcc1416ec0c977d8b307c89983ed7baa3ffa8" source = "git+https://github.com/stakwork/sphinx-rs.git#fb621dce1ef8bf8ca8bc7dbfbafdbd6a4fb8d293"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"bip39", "bip39",
@@ -2824,26 +2807,48 @@ version = "0.9.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
[[package]]
name = "vls-core"
version = "0.1.0-5"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#9112828c14ecff3bc86bd5e23a1016210de16e85"
dependencies = [
"anyhow",
"bitcoin",
"bolt-derive",
"hashbrown 0.8.2",
"hex",
"itertools",
"lightning",
"lightning-invoice",
"log",
"scopeguard",
"serde",
"serde_bolt",
"serde_derive",
"serde_with",
]
[[package]] [[package]]
name = "vls-persist" name = "vls-persist"
version = "0.1.0" version = "0.1.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#7afb0cdedb38750cc2086ce0e05dc41d93158e70" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#9112828c14ecff3bc86bd5e23a1016210de16e85"
dependencies = [ dependencies = [
"hex", "hex",
"lightning-signer-core",
"log", "log",
"serde", "serde",
"serde_json", "serde_json",
"serde_with", "serde_with",
"vls-core",
] ]
[[package]] [[package]]
name = "vls-protocol" name = "vls-protocol"
version = "0.1.0" version = "0.1.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#7afb0cdedb38750cc2086ce0e05dc41d93158e70" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#9112828c14ecff3bc86bd5e23a1016210de16e85"
dependencies = [ dependencies = [
"as-any", "as-any",
"bolt-derive", "bolt-derive",
"hex",
"log", "log",
"serde", "serde",
"serde_bolt", "serde_bolt",
@@ -2853,12 +2858,12 @@ dependencies = [
[[package]] [[package]]
name = "vls-protocol-signer" name = "vls-protocol-signer"
version = "0.1.0" version = "0.1.0"
source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#7afb0cdedb38750cc2086ce0e05dc41d93158e70" source = "git+https://gitlab.com/lightning-signer/validating-lightning-signer.git#9112828c14ecff3bc86bd5e23a1016210de16e85"
dependencies = [ dependencies = [
"bit-vec", "bit-vec",
"lightning-signer-core",
"log", "log",
"serde", "serde",
"vls-core",
"vls-protocol", "vls-protocol",
] ]

View File

@@ -1,3 +1,3 @@
[toolchain] [toolchain]
channel = "nightly" channel = "stable"

View File

@@ -1,4 +1,4 @@
#![feature(once_cell)] // #![feature(once_cell)]
mod chain_tracker; mod chain_tracker;
mod error_log; mod error_log;
mod mqtt; mod mqtt;

View File

@@ -6,6 +6,8 @@ use rumqttd::{Alert, AlertEvent, Broker, Config, Notification};
use sphinx_signer::sphinx_glyph::topics; use sphinx_signer::sphinx_glyph::topics;
use std::time::Duration; use std::time::Duration;
// pub const INTERNAL_CONTROL: &str = "INTERNAL_CONTROL";
// must get a reply within this time, or disconnects // must get a reply within this time, or disconnects
const REPLY_TIMEOUT_MS: u64 = 10000; const REPLY_TIMEOUT_MS: u64 = 10000;
@@ -20,13 +22,13 @@ pub fn start_broker(
let client_id = expected_client_id.to_string(); let client_id = expected_client_id.to_string();
let mut broker = Broker::new(conf); let mut broker = Broker::new(conf);
let mut alerts = broker let mut alerts = broker.alerts(vec![
.alerts(vec![ // "/alerts/error/+".to_string(),
// "/alerts/error/+".to_string(), "/alerts/event/connect/+".to_string(),
"/alerts/event/connect/+".to_string(), "/alerts/event/disconnect/+".to_string(),
"/alerts/event/disconnect/+".to_string(), ])?;
])?;
let (mut link_tx, mut link_rx) = broker.link("localclient")?; let (mut link_tx, mut link_rx) = broker.link("localclient")?;
std::thread::spawn(move || { std::thread::spawn(move || {
broker.start().expect("could not start broker"); broker.start().expect("could not start broker");
}); });
@@ -51,29 +53,32 @@ pub fn start_broker(
} }
_ => (), _ => (),
} }
tokio::time::sleep(Duration::from_millis(40)).await;
} }
}); });
// msg forwarding // msg forwarding
let (msg_tx, mut msg_rx): (mpsc::Sender<Vec<u8>>, mpsc::Receiver<Vec<u8>>) = let (msg_tx, mut msg_rx): (mpsc::Sender<Vec<u8>>, mpsc::Receiver<Vec<u8>>) =
mpsc::channel(1000); mpsc::channel(1000);
// link_tx.subscribe(INTERNAL_CONTROL)?;
link_tx.subscribe(topics::VLS_RETURN)?; link_tx.subscribe(topics::VLS_RETURN)?;
link_tx.subscribe(topics::CONTROL_RETURN)?; link_tx.subscribe(topics::CONTROL_RETURN)?;
link_tx.subscribe(topics::ERROR)?; link_tx.subscribe(topics::ERROR)?;
let _sub_task = tokio::spawn(async move { let _sub_task = tokio::spawn(async move {
println!("ummm....");
while let Ok(message) = link_rx.recv() { while let Ok(message) = link_rx.recv() {
println!("GOT A MSG ON LINK RX");
if let Some(n) = message { if let Some(n) = message {
match n { match n {
Notification::Forward(f) => { Notification::Forward(f) => {
println!("GOT A FORWARDED MSG! FORWARD!"); println!("GOT A FORWARDED MSG! FORWARD! {:?}", f.publish.topic);
if f.publish.topic == topics::ERROR { if f.publish.topic == topics::ERROR {
let _ = error_sender.send(f.publish.topic.to_vec()); let _ = error_sender.send(f.publish.topic.to_vec());
} else { } else {
println!("send now on msg_tx {:?}", f.publish.payload.to_vec());
if let Err(e) = msg_tx.send(f.publish.payload.to_vec()).await { if let Err(e) = msg_tx.send(f.publish.payload.to_vec()).await {
log::error!("failed to pub to msg_tx! {:?}", e); log::error!("failed to pub to msg_tx! {:?}", e);
} }
println!("sent on msg_tx");
} }
} }
_ => (), _ => (),
@@ -81,19 +86,22 @@ pub fn start_broker(
} }
} }
}); });
let _relay_task = tokio::spawn(async move { let _relay_task = tokio::spawn(async move {
while let Some(msg) = receiver.recv().await { while let Some(msg) = receiver.recv().await {
println!("YO YO YO got a receiver msg! {:?}", msg);
if let Err(e) = link_tx.publish(msg.topic, msg.message) { if let Err(e) = link_tx.publish(msg.topic, msg.message) {
log::error!("failed to pub to link_tx! {:?}", e); log::error!("failed to pub to link_tx! {:?}", e);
} }
println!("PUBBED TO LINKTX....");
// let rep = msg_rx.recv().await;
// println!("REPPPP {:?}", rep);
match timeout(Duration::from_millis(REPLY_TIMEOUT_MS), msg_rx.recv()).await { match timeout(Duration::from_millis(REPLY_TIMEOUT_MS), msg_rx.recv()).await {
Ok(reply) => { Ok(rep) => {
println!("send on channelreply!"); println!("GOT A REPLY {:?}", rep);
if let Err(_) = msg.reply_tx.send(ChannelReply { if let Some(reply) = rep {
reply: reply.unwrap(), if let Err(_) = msg.reply_tx.send(ChannelReply { reply }) {
}) { log::warn!("could not send on reply_tx");
log::warn!("could not send on reply_tx"); }
} }
} }
Err(e) => { Err(e) => {
@@ -118,9 +126,10 @@ fn config(settings: Settings) -> Config {
use std::net::{Ipv4Addr, SocketAddrV4}; use std::net::{Ipv4Addr, SocketAddrV4};
let router = rumqttd::RouterConfig { let router = rumqttd::RouterConfig {
instant_ack: true, instant_ack: true,
max_segment_size: 10240, max_segment_size: 104857600,
max_segment_count: 10, max_segment_count: 10,
max_connections: 10001, max_connections: 10010,
max_read_len: 10240,
..Default::default() ..Default::default()
}; };
let mut servers = HashMap::new(); let mut servers = HashMap::new();

View File

@@ -22,7 +22,6 @@ pub async fn control(sender: &State<Sender<ChannelRequest>>, msg: &str) -> Resul
if message.len() < 65 { if message.len() < 65 {
return Err(Error::Fail); return Err(Error::Fail);
} }
println!("/control?<msg> got hit!");
let (request, reply_rx) = ChannelRequest::new(topics::CONTROL, message); let (request, reply_rx) = ChannelRequest::new(topics::CONTROL, message);
// send to ESP // send to ESP
let _ = sender.send(request).await.map_err(|_| Error::Fail)?; let _ = sender.send(request).await.map_err(|_| Error::Fail)?;

View File

@@ -6,7 +6,9 @@ edition = "2018"
[dependencies] [dependencies]
sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git" } sphinx-signer = { git = "https://github.com/stakwork/sphinx-rs.git" }
# sphinx-signer = { path = "../../sphinx-rs/signer" }
sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git" } sphinx-crypter = { git = "https://github.com/stakwork/sphinx-rs.git" }
# sphinx-crypter = { path = "../../sphinx-rs/crypter" }
anyhow = {version = "1", features = ["backtrace"]} anyhow = {version = "1", features = ["backtrace"]}
log = "0.4" log = "0.4"
rumqttc = "0.12.0" rumqttc = "0.12.0"

View File

@@ -108,8 +108,10 @@ async fn run_main(
loop { loop {
match eventloop.poll().await { match eventloop.poll().await {
Ok(event) => { Ok(event) => {
println!("{:?}", event);
let dummy_peer = PubKey([0; 33]); let dummy_peer = PubKey([0; 33]);
if let Some((topic, msg_bytes)) = incoming_bytes(event) { if let Some((topic, msg_bytes)) = incoming_bytes(event) {
println!("MSG BYTES {:}", msg_bytes.len());
match topic.as_str() { match topic.as_str() {
topics::VLS => { topics::VLS => {
match sphinx_signer::root::handle( match sphinx_signer::root::handle(