From c73517e261d1e66b03fb7b676698a626c4c15324 Mon Sep 17 00:00:00 2001 From: moparisthebest Date: Fri, 29 Dec 2023 02:21:21 -0500 Subject: [PATCH] POC that connects to TCP localhost through changed tokio-xmpp --- Cargo.lock | 179 ++++++++++++++++++---------------------------------- Cargo.toml | 17 ++++- src/main.rs | 42 ++++++++++-- 3 files changed, 112 insertions(+), 126 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 560bdfe..6caa9f8 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,7 +40,7 @@ checksum = "5fd55a5ba1179988837d24ab4c7cc8ed6efdeff578ede0416b4225a5fca35bd0" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -51,7 +51,7 @@ checksum = "fdf6721fb0140e4f897002dd086c06f6c27775df19cfe1fccb21181a48fd2c98" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -206,14 +206,14 @@ dependencies = [ [[package]] name = "enum-as-inner" -version = "0.5.1" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c9720bba047d567ffc8a3cba48bf19126600e249ab7f128e9233e6376976a116" +checksum = "5ffccbb6966c05b32ef8fbac435df276c4ae4d3dc55a8cd0eb9745e6c12f546a" dependencies = [ "heck", "proc-macro2", "quote", - "syn 1.0.109", + "syn", ] [[package]] @@ -316,7 +316,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -394,6 +394,51 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d77f7ec81a6d05a3abb01ab6eb7590f6083d08449fe5a1c8b1e620283546ccb7" +[[package]] +name = "hickory-proto" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "091a6fbccf4860009355e3efc52ff4acf37a63489aad7435372d44ceeb6fbbcf" +dependencies = [ + "async-trait", + "cfg-if", + "data-encoding", + "enum-as-inner", + "futures-channel", + "futures-io", + "futures-util", + "idna 0.4.0", + "ipnet", + "once_cell", + "rand", + "thiserror", + "tinyvec", + "tokio", + "tracing", + "url", +] + +[[package]] +name = "hickory-resolver" +version = "0.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "35b8f021164e6a984c9030023544c57789c51760065cd510572fedcfb04164e8" +dependencies = [ + "cfg-if", + "futures-util", + "hickory-proto", + "ipconfig", + "lru-cache", + "once_cell", + "parking_lot", + "rand", + "resolv-conf", + "smallvec", + "thiserror", + "tokio", + "tracing", +] + [[package]] name = "hmac" version = "0.12.1" @@ -420,17 +465,6 @@ version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4" -[[package]] -name = "idna" -version = "0.2.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "418a0a6fab821475f634efe3ccc45c013f742efe03d853e8d3355d5cb850ecf8" -dependencies = [ - "matches", - "unicode-bidi", - "unicode-normalization", -] - [[package]] name = "idna" version = "0.4.0" @@ -493,8 +527,7 @@ dependencies = [ [[package]] name = "jid" version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a52cacd869b804660986b10aa2076c3a4b6da644c7198f9fd0b613f4a7b249" +source = "git+https://gitlab.com/moparisthebest/xmpp-rs?branch=task/async-client-any-stream#bb3dd1910e14d123b5a608d42a4bf6a2e77c2101" dependencies = [ "memchr", "minidom", @@ -531,12 +564,6 @@ dependencies = [ "xmpp-parsers", ] -[[package]] -name = "lazy_static" -version = "1.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" - [[package]] name = "libc" version = "0.2.151" @@ -597,12 +624,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ffbee8634e0d45d258acb448e7eaab3fce7a0a467395d4d9f228e3c1f01fb2e4" -[[package]] -name = "matches" -version = "0.1.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2532096657941c2fea9c289d370a250971c689d4f143798ff67113ec042024a5" - [[package]] name = "memchr" version = "2.7.1" @@ -612,8 +633,7 @@ checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149" [[package]] name = "minidom" version = "0.15.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f45614075738ce1b77a1768912a60c0227525971b03e09122a05b8a34a2a6278" +source = "git+https://gitlab.com/moparisthebest/xmpp-rs?branch=task/async-client-any-stream#bb3dd1910e14d123b5a608d42a4bf6a2e77c2101" dependencies = [ "rxml", ] @@ -867,15 +887,6 @@ version = "0.1.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" -[[package]] -name = "rustc_version" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" -dependencies = [ - "semver", -] - [[package]] name = "rustix" version = "0.38.28" @@ -933,8 +944,7 @@ checksum = "22a197350ece202f19a166d1ad6d9d6de145e1d2a8ef47db299abe164dbd7530" [[package]] name = "sasl" version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "27a9f72398d92896188b100e5224a4f190c9abe5273b98cb1b5a61505be3143e" +source = "git+https://gitlab.com/moparisthebest/xmpp-rs?branch=task/async-client-any-stream#bb3dd1910e14d123b5a608d42a4bf6a2e77c2101" dependencies = [ "base64", "getrandom", @@ -960,12 +970,6 @@ dependencies = [ "untrusted", ] -[[package]] -name = "semver" -version = "1.0.20" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "836fa6a3e1e547f9a2c4040802ec865b5d85f4014efe00555d7090a3dcaa1090" - [[package]] name = "serde" version = "1.0.193" @@ -983,7 +987,7 @@ checksum = "43576ca501357b9b071ac53cdc7da8ef0cbd9493d8df094cd821777ea6e894d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -1103,17 +1107,6 @@ version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "81cdd64d312baedb58e21336b31bc043b77e01cc99033ce76ef539f78e965ebc" -[[package]] -name = "syn" -version = "1.0.109" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" -dependencies = [ - "proc-macro2", - "quote", - "unicode-ident", -] - [[package]] name = "syn" version = "2.0.43" @@ -1151,7 +1144,7 @@ checksum = "e7fbe9b594d6568a6a1443250a7e67d80b74e1e96f6d1715e1e21cc1888291d3" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -1194,7 +1187,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -1235,24 +1228,21 @@ dependencies = [ [[package]] name = "tokio-xmpp" version = "3.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d5f8badad7d8859131f2eccd1447c5f3cca6171429fe172acfed4acb1f2f62c3" +source = "git+https://gitlab.com/moparisthebest/xmpp-rs?branch=task/async-client-any-stream#bb3dd1910e14d123b5a608d42a4bf6a2e77c2101" dependencies = [ "bytes", "futures", + "hickory-resolver", "idna 0.4.0", "log", "minidom", "rand", - "rustc_version", "rxml", "sasl", "tokio", "tokio-rustls", "tokio-stream", "tokio-util", - "trust-dns-proto", - "trust-dns-resolver", "webpki-roots", "xmpp-parsers", ] @@ -1310,7 +1300,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.43", + "syn", ] [[package]] @@ -1322,51 +1312,6 @@ dependencies = [ "once_cell", ] -[[package]] -name = "trust-dns-proto" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f7f83d1e4a0e4358ac54c5c3681e5d7da5efc5a7a632c90bb6d6669ddd9bc26" -dependencies = [ - "async-trait", - "cfg-if", - "data-encoding", - "enum-as-inner", - "futures-channel", - "futures-io", - "futures-util", - "idna 0.2.3", - "ipnet", - "lazy_static", - "rand", - "smallvec", - "thiserror", - "tinyvec", - "tokio", - "tracing", - "url", -] - -[[package]] -name = "trust-dns-resolver" -version = "0.22.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "aff21aa4dcefb0a1afbfac26deb0adc93888c7d295fb63ab273ef276ba2b7cfe" -dependencies = [ - "cfg-if", - "futures-util", - "ipconfig", - "lazy_static", - "lru-cache", - "parking_lot", - "resolv-conf", - "smallvec", - "thiserror", - "tokio", - "tracing", - "trust-dns-proto", -] - [[package]] name = "typenum" version = "1.17.0" @@ -1620,8 +1565,7 @@ dependencies = [ [[package]] name = "xmpp-parsers" version = "0.20.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c0905d294e6e7f7668f4b3ca9c4a6343fd85355d21c44d2f1c8b1c027394048e" +source = "git+https://gitlab.com/moparisthebest/xmpp-rs?branch=task/async-client-any-stream#bb3dd1910e14d123b5a608d42a4bf6a2e77c2101" dependencies = [ "base64", "blake2", @@ -1629,7 +1573,6 @@ dependencies = [ "digest", "jid", "minidom", - "rustc_version", "sha1", "sha2", "sha3", diff --git a/Cargo.toml b/Cargo.toml index ad828a9..16b5e03 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -25,10 +25,7 @@ toml = "0.8" serde_derive = "1.0" serde = { version = "1.0", features = ["derive"] } dirs = "5.0.1" -minidom = "0.15" -tokio-xmpp = { version = "3.5.0", default-features = false, features = ["tls-rust"] } tokio = { version = "1", features = ["net", "rt", "rt-multi-thread", "macros", "io-util", "io-std"] } -xmpp-parsers = "0.20" die = "0.2.0" anyhow = "1.0" log = "0.4" @@ -36,5 +33,19 @@ env_logger = "0.10" rand = "0.8.5" async-recursion = "1.0.5" +# from xmpp-rs +minidom = "0.15" +tokio-xmpp = { version = "3.5.0", default-features = false, features = ["tls-rust"] } +xmpp-parsers = "0.20" + [profile.release] strip = true + +[patch.crates-io] +# minidom = { path = "../xmpp-rs/minidom" } +# tokio-xmpp = { path = "../xmpp-rs/tokio-xmpp" } +# xmpp-parsers = { path = "../xmpp-rs/parsers" } +minidom = { git = "https://gitlab.com/moparisthebest/xmpp-rs", branch = "task/async-client-any-stream" } +tokio-xmpp = { git = "https://gitlab.com/moparisthebest/xmpp-rs", branch = "task/async-client-any-stream" } +xmpp-parsers = { git = "https://gitlab.com/moparisthebest/xmpp-rs", branch = "task/async-client-any-stream" } + diff --git a/src/main.rs b/src/main.rs index b7505f9..e7987f9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,11 @@ use futures::stream::StreamExt; use log::{info, trace}; use serde_derive::Deserialize; use std::{convert::TryFrom, fs::File, io::Read, iter::Iterator, path::Path, str::FromStr}; -use tokio::io::{self, AsyncBufReadExt, BufReader}; -use tokio_xmpp::{AsyncClient as Client, Event}; +use tokio::{ + io::{self, AsyncBufReadExt, BufReader}, + net::TcpStream, +}; +use tokio_xmpp::{AsyncClient as Client, AsyncServerConnector, Event}; use xmpp_parsers::{ message::{Body, Message, MessageType}, muc::Muc, @@ -48,6 +51,22 @@ impl Context { } } +#[derive(Debug, Clone)] +struct TcpServerConfig(String); + +impl tokio_xmpp::AsyncServerConnector for TcpServerConfig { + async fn connect(&self, jid: &Jid) -> Result { + let stream: Box = + Box::new(TcpStream::connect(&self.0).await?); + tokio_xmpp::xmpp_stream::XMPPStream::start( + stream, + jid.clone(), + xmpp_parsers::ns::JABBER_CLIENT.to_owned(), + ) + .await + } +} + #[tokio::main] async fn main() { let mut args = Args::default(); @@ -93,7 +112,12 @@ async fn main() { let context = Context::new(bare_me, contact); - let mut client = Client::new(context.bare_me.clone(), &cfg.password); + let client_cfg = tokio_xmpp::AsyncConfig { + jid: context.bare_me.clone().into(), + password: cfg.password, + server: TcpServerConfig("127.0.0.1:15270".to_owned()), + }; + let mut client = Client::new_with_config(client_cfg); client.set_reconnect(true); // after calling this the program can only exit with die!(), not the normal way, see comment below @@ -133,7 +157,11 @@ async fn main() { die!(exit_code) } -async fn handle_xmpp(event: Option, client: &mut Client, context: &Context) -> Result<()> { +async fn handle_xmpp( + event: Option, + client: &mut Client, + context: &Context, +) -> Result<()> { // println!("event: {event:?}"); match event { Some(Event::Online { .. }) => { @@ -227,7 +255,11 @@ async fn handle_xmpp_element(element: Element, context: &Context) -> Result<()> } /// true to quit, false otherwise -async fn handle_line(line: String, client: &mut Client, context: &Context) -> Result { +async fn handle_line( + line: String, + client: &mut Client, + context: &Context, +) -> Result { let line = line.trim(); match line { "/quit" => return Ok(true),